use of io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec in project stackgres by ongres.
the class ClusterEventResourceTest method setup.
@BeforeAll
public static void setup() {
StackGresDbOps dbOps = new StackGresDbOps();
dbOps.setMetadata(new ObjectMeta());
dbOps.getMetadata().setNamespace("test-namespace");
dbOps.getMetadata().setName("test-operation");
dbOps.getMetadata().setUid("1");
dbOps.setSpec(new StackGresDbOpsSpec());
dbOps.getSpec().setSgCluster("test");
DbOpsScanner dbOpsScanner = Mockito.mock(DbOpsScanner.class);
Mockito.when(dbOpsScanner.getResources(ArgumentMatchers.any())).thenReturn(ImmutableList.of(dbOps));
QuarkusMock.installMockForType(dbOpsScanner, DbOpsScanner.class);
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec in project stackgres by ongres.
the class DbOpsTransformer method getResourceSpec.
private DbOpsSpec getResourceSpec(StackGresDbOpsSpec source) {
DbOpsSpec transformation = new DbOpsSpec();
transformation.setSgCluster(source.getSgCluster());
transformation.setOp(source.getOp());
transformation.setRunAt(source.getRunAt());
transformation.setTimeout(source.getTimeout());
transformation.setMaxRetries(source.getMaxRetries());
transformation.setBenchmark(getResourceBenchmark(source.getBenchmark()));
transformation.setVacuum(getResourceVacuum(source.getVacuum()));
transformation.setRepack(getResourceRepack(source.getRepack()));
transformation.setMajorVersionUpgrade(getResourceMajorVersionUpgrade(source.getMajorVersionUpgrade()));
transformation.setRestart(getResourceRestart(source.getRestart()));
transformation.setMinorVersionUpgrade(getResourceMinorVersionUpgrade(source.getMinorVersionUpgrade()));
transformation.setSecurityUpgrade(getResourceSecurityUpgrade(source.getSecurityUpgrade()));
return transformation;
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec in project stackgres by ongres.
the class DbOpsRequiredResourcesGenerator method getRequiredResources.
@Override
public List<HasMetadata> getRequiredResources(StackGresDbOps config) {
final ObjectMeta metadata = config.getMetadata();
final String dbOpsName = metadata.getName();
final String dbOpsNamespace = metadata.getNamespace();
final StackGresDbOpsSpec spec = config.getSpec();
final StackGresCluster cluster = clusterFinder.findByNameAndNamespace(spec.getSgCluster(), dbOpsNamespace).orElseThrow(() -> new IllegalArgumentException("SGDbOps " + dbOpsNamespace + "/" + dbOpsName + " have a non existent SGCluster " + spec.getSgCluster()));
StackGresDbOpsContext context = ImmutableStackGresDbOpsContext.builder().source(config).cluster(cluster).build();
final List<ResourceGenerator<StackGresDbOpsContext>> resourceGenerators = generators.getResourceGenerators(context);
final List<HasMetadata> resources = resourceGenerators.stream().flatMap(generator -> generator.generateResource(context)).collect(Collectors.toUnmodifiableList());
List<Decorator<StackGresDbOpsContext>> decorators = decoratorDiscoverer.discoverDecorator(context);
decorators.forEach(decorator -> decorator.decorate(context, resources));
return resources;
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec in project stackgres by ongres.
the class AbstractRestartStateHandler method buildClusterRestartState.
protected ClusterRestartState buildClusterRestartState(StackGresDbOps dbOps, StackGresCluster cluster, Optional<StatefulSet> statefulSet, List<Pod> clusterPods) {
DbOpsRestartStatus restartStatus = getDbOpRestartStatus(dbOps);
Map<String, Pod> podsDict = clusterPods.stream().collect(Collectors.toMap(pod -> pod.getMetadata().getName(), Function.identity()));
var initialInstances = Optional.ofNullable(restartStatus.getInitialInstances()).map(instances -> instances.stream().map(podsDict::get).collect(Collectors.toUnmodifiableList())).orElse(clusterPods);
var restartedInstances = Optional.ofNullable(restartStatus.getRestartedInstances()).map(instances -> instances.stream().map(podsDict::get).collect(Collectors.toUnmodifiableList())).orElse(List.of());
var podRestartReasonsMap = clusterPods.stream().collect(Collectors.toUnmodifiableMap(Function.identity(), pod -> getPodRestartReasons(cluster, statefulSet, pod)));
final String method = getRestartMethod(dbOps).orElse(REDUCED_IMPACT_METHOD);
final boolean onlyPendingRestart = Optional.of(dbOps.getSpec()).map(StackGresDbOpsSpec::getRestart).map(StackGresDbOpsRestart::getOnlyPendingRestart).orElse(false);
return ImmutableClusterRestartState.builder().namespace(dbOps.getMetadata().getNamespace()).dbOpsName(dbOps.getMetadata().getName()).dbOpsOperation(dbOps.getSpec().getOp()).clusterName(cluster.getMetadata().getName()).restartMethod(method).isOnlyPendingRestart(onlyPendingRestart).primaryInstance(getPrimaryInstance(clusterPods)).isSwitchoverInitiated(restartStatus.getSwitchoverInitiated() != null).isSwitchoverFinalized(restartStatus.getSwitchoverFinalized() != null).initialInstances(initialInstances).restartedInstances(restartedInstances).totalInstances(clusterPods).podRestartReasonsMap(podRestartReasonsMap).build();
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec in project stackgres by ongres.
the class DbOpsTransformer method getCustomResourceSpec.
private StackGresDbOpsSpec getCustomResourceSpec(DbOpsSpec source) {
if (source == null) {
return null;
}
StackGresDbOpsSpec transformation = new StackGresDbOpsSpec();
transformation.setSgCluster(source.getSgCluster());
transformation.setOp(source.getOp());
transformation.setRunAt(source.getRunAt());
transformation.setTimeout(source.getTimeout());
transformation.setMaxRetries(source.getMaxRetries());
transformation.setBenchmark(getCustomResourceBenchmark(source.getBenchmark()));
transformation.setVacuum(getCustomResourceVacuum(source.getVacuum()));
transformation.setRepack(getCustomResourceRepack(source.getRepack()));
transformation.setMajorVersionUpgrade(getCustomResourceMajorVersionUpgrade(source.getMajorVersionUpgrade()));
transformation.setRestart(getCustomResourceRestart(source.getRestart()));
transformation.setMinorVersionUpgrade(getCustomResourceMinorVersionUpgrade(source.getMinorVersionUpgrade()));
transformation.setSecurityUpgrade(getCustomResourceSecurityUpgrade(source.getSecurityUpgrade()));
return transformation;
}
Aggregations