Skip to content

Commit

Permalink
Merge pull request #665 from perfectsense/bugfix/db-cluster-parameter…
Browse files Browse the repository at this point in the history
…-group-does-not-refresh-parameters

The db-cluster-parameter-group does not refresh parameters
  • Loading branch information
harjain99 authored Oct 1, 2024
2 parents 88732e5 + 2786562 commit 192d8be
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/main/java/gyro/aws/rds/DbClusterParameterGroupResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import software.amazon.awssdk.services.rds.model.DescribeDbClusterParameterGroupsResponse;
import software.amazon.awssdk.services.rds.model.DescribeDbClusterParametersResponse;
import software.amazon.awssdk.services.rds.model.Parameter;
import software.amazon.awssdk.services.rds.model.DescribeDbClusterParameterGroupsRequest;
import software.amazon.awssdk.services.rds.model.DescribeDbClusterParametersRequest;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -140,36 +142,43 @@ 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())
DescribeDbClusterParameterGroupsRequest.builder()
.dbClusterParameterGroupName(getName())
.build()
);

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(
DescribeDbClusterParametersRequest.builder()
.dbClusterParameterGroupName(getName())
.marker(marker)
.build()
);

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 = parametersResponse.marker();
} while (marker != null);
} catch (DbParameterGroupNotFoundException ex) {
return false;
}
Expand Down

0 comments on commit 192d8be

Please sign in to comment.