Search in sources :

Example 1 with StackGresDbOpsSpec

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);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresDbOpsSpec(io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec) DbOpsScanner(io.stackgres.common.resource.DbOpsScanner) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with StackGresDbOpsSpec

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;
}
Also used : StackGresDbOpsSpec(io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec) DbOpsSpec(io.stackgres.apiweb.dto.dbops.DbOpsSpec)

Example 3 with StackGresDbOpsSpec

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;
}
Also used : RequiredResourceGenerator(io.stackgres.operator.conciliation.RequiredResourceGenerator) ResourceGenerator(io.stackgres.operator.conciliation.ResourceGenerator) Logger(org.slf4j.Logger) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) RequiredResourceGenerator(io.stackgres.operator.conciliation.RequiredResourceGenerator) Inject(javax.inject.Inject) List(java.util.List) ResourceGenerationDiscoverer(io.stackgres.operator.conciliation.ResourceGenerationDiscoverer) ResourceGenerator(io.stackgres.operator.conciliation.ResourceGenerator) DecoratorDiscoverer(io.stackgres.operator.conciliation.factory.DecoratorDiscoverer) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) CustomResourceFinder(io.stackgres.common.resource.CustomResourceFinder) ApplicationScoped(javax.enterprise.context.ApplicationScoped) StackGresDbOpsSpec(io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec) Decorator(io.stackgres.operator.conciliation.factory.Decorator) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StackGresDbOpsSpec(io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec) Decorator(io.stackgres.operator.conciliation.factory.Decorator) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster)

Example 4 with StackGresDbOpsSpec

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();
}
Also used : StackGresContext(io.stackgres.common.StackGresContext) StackGresDbOpsRestart(io.stackgres.common.crd.sgdbops.StackGresDbOpsRestart) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) LoggerFactory(org.slf4j.LoggerFactory) DbOpsRestartStatus(io.stackgres.common.crd.sgdbops.DbOpsRestartStatus) InvalidCluster(io.stackgres.jobs.dbops.clusterrestart.InvalidCluster) Function(java.util.function.Function) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) RestartEvent(io.stackgres.jobs.dbops.clusterrestart.RestartEvent) ArrayList(java.util.ArrayList) Uni(io.smallrye.mutiny.Uni) Inject(javax.inject.Inject) ImmutableClusterRestartState(io.stackgres.jobs.dbops.clusterrestart.ImmutableClusterRestartState) ImmutableList(com.google.common.collect.ImmutableList) Duration(java.time.Duration) Map(java.util.Map) ClusterDbOpsRestartStatus(io.stackgres.common.crd.sgcluster.ClusterDbOpsRestartStatus) CustomResourceFinder(io.stackgres.common.resource.CustomResourceFinder) StackGresDbOpsSpec(io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) REDUCED_IMPACT_METHOD(io.stackgres.jobs.dbops.clusterrestart.ClusterRestartImpl.REDUCED_IMPACT_METHOD) RestartReasons(io.stackgres.common.ClusterPendingRestartUtil.RestartReasons) Logger(org.slf4j.Logger) EventEmitter(io.stackgres.common.event.EventEmitter) ClusterRestart(io.stackgres.jobs.dbops.clusterrestart.ClusterRestart) ClusterRestartStateHandlerImpl(io.stackgres.jobs.dbops.clusterrestart.ClusterRestartStateHandlerImpl) LabelFactoryForCluster(io.stackgres.common.LabelFactoryForCluster) Pod(io.fabric8.kubernetes.api.model.Pod) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) ClusterRestartState(io.stackgres.jobs.dbops.clusterrestart.ClusterRestartState) List(java.util.List) CustomResourceScheduler(io.stackgres.common.resource.CustomResourceScheduler) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ResourceScanner(io.stackgres.common.resource.ResourceScanner) Optional(java.util.Optional) ResourceFinder(io.stackgres.common.resource.ResourceFinder) NotNull(org.jetbrains.annotations.NotNull) ClusterPendingRestartUtil(io.stackgres.common.ClusterPendingRestartUtil) Pod(io.fabric8.kubernetes.api.model.Pod) StackGresDbOpsSpec(io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec) DbOpsRestartStatus(io.stackgres.common.crd.sgdbops.DbOpsRestartStatus) ClusterDbOpsRestartStatus(io.stackgres.common.crd.sgcluster.ClusterDbOpsRestartStatus)

Example 5 with StackGresDbOpsSpec

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;
}
Also used : StackGresDbOpsSpec(io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec)

Aggregations

StackGresDbOpsSpec (io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec)5 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)3 StackGresDbOps (io.stackgres.common.crd.sgdbops.StackGresDbOps)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)2 CustomResourceFinder (io.stackgres.common.resource.CustomResourceFinder)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 ImmutableList (com.google.common.collect.ImmutableList)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)1 Uni (io.smallrye.mutiny.Uni)1 DbOpsSpec (io.stackgres.apiweb.dto.dbops.DbOpsSpec)1 ClusterPendingRestartUtil (io.stackgres.common.ClusterPendingRestartUtil)1 RestartReasons (io.stackgres.common.ClusterPendingRestartUtil.RestartReasons)1 LabelFactoryForCluster (io.stackgres.common.LabelFactoryForCluster)1 StackGresContext (io.stackgres.common.StackGresContext)1 ClusterDbOpsRestartStatus (io.stackgres.common.crd.sgcluster.ClusterDbOpsRestartStatus)1