Skip to content

Commit

Permalink
Add paginated DB cluster parameter retrieval in refresh method
Browse files Browse the repository at this point in the history
Add string array workaround for marker in AWS RDS API call
  • Loading branch information
Russsnizza committed Sep 23, 2024
1 parent 1cdc8e0 commit fa27010
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/main/java/gyro/aws/rds/DbClusterParameterGroupResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,36 +140,38 @@ public void copyFrom(DBClusterParameterGroup group) {
@Override
protected boolean doRefresh() {
RdsClient client = createClient(RdsClient.class);

if (ObjectUtils.isBlank(getName())) {
throw new GyroException("name is missing, unable to load cluster parameter group.");
}

try {
DescribeDbClusterParameterGroupsResponse response = client.describeDBClusterParameterGroups(
r -> r.dbClusterParameterGroupName(getName())
);

response.dbClusterParameterGroups().forEach(this::copyFrom);

DescribeDbClusterParametersResponse parametersResponse = client.describeDBClusterParameters(
r -> r.dbClusterParameterGroupName(getName())
);

Set<String> names = getParameter().stream().map(DbParameter::getName).collect(Collectors.toSet());
getParameter().clear();
getParameter().addAll(parametersResponse.parameters().stream()
.filter(p -> names.contains(p.parameterName()))
.map(p -> {
DbParameter parameter = new DbParameter();
parameter.setApplyMethod(p.applyMethodAsString());
parameter.setName(p.parameterName());
parameter.setValue(p.parameterValue());
return parameter;
})
.collect(Collectors.toList())
);

String[] marker = {null};
do {
DescribeDbClusterParametersResponse parametersResponse = client.describeDBClusterParameters(
r -> r.dbClusterParameterGroupName(getName()).marker(marker[0])
);

getParameter().addAll(parametersResponse.parameters().stream()
.filter(p -> names.contains(p.parameterName()))
.map(p -> {
DbParameter parameter = new DbParameter();
parameter.setApplyMethod(p.applyMethodAsString());
parameter.setName(p.parameterName());
parameter.setValue(p.parameterValue());
return parameter;
})
.collect(Collectors.toList())
);

marker[0] = parametersResponse.marker();
} while (marker[0] != null);
} catch (DbParameterGroupNotFoundException ex) {
return false;
}
Expand Down

0 comments on commit fa27010

Please sign in to comment.