Search in sources :

Example 1 with StackGresDbOpsRestart

use of io.stackgres.common.crd.sgdbops.StackGresDbOpsRestart in project stackgres by ongres.

the class DbOpsTransformer method getCustomResourceRestart.

private StackGresDbOpsRestart getCustomResourceRestart(DbOpsRestart source) {
    if (source == null) {
        return null;
    }
    StackGresDbOpsRestart transformation = new StackGresDbOpsRestart();
    transformation.setMethod(source.getMethod());
    transformation.setRestartPrimaryFirst(source.getRestartPrimaryFirst());
    transformation.setOnlyPendingRestart(source.getOnlyPendingRestart());
    return transformation;
}
Also used : StackGresDbOpsRestart(io.stackgres.common.crd.sgdbops.StackGresDbOpsRestart)

Example 2 with StackGresDbOpsRestart

use of io.stackgres.common.crd.sgdbops.StackGresDbOpsRestart 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 3 with StackGresDbOpsRestart

use of io.stackgres.common.crd.sgdbops.StackGresDbOpsRestart in project stackgres by ongres.

the class DbOpsTransformer method getResourceRestart.

private DbOpsRestart getResourceRestart(StackGresDbOpsRestart source) {
    if (source == null) {
        return null;
    }
    DbOpsRestart transformation = new DbOpsRestart();
    transformation.setMethod(source.getMethod());
    transformation.setRestartPrimaryFirst(source.getRestartPrimaryFirst());
    transformation.setOnlyPendingRestart(source.getOnlyPendingRestart());
    return transformation;
}
Also used : DbOpsRestart(io.stackgres.apiweb.dto.dbops.DbOpsRestart) StackGresDbOpsRestart(io.stackgres.common.crd.sgdbops.StackGresDbOpsRestart)

Aggregations

StackGresDbOpsRestart (io.stackgres.common.crd.sgdbops.StackGresDbOpsRestart)3 ImmutableList (com.google.common.collect.ImmutableList)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)1 Uni (io.smallrye.mutiny.Uni)1 DbOpsRestart (io.stackgres.apiweb.dto.dbops.DbOpsRestart)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 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)1 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)1 DbOpsRestartStatus (io.stackgres.common.crd.sgdbops.DbOpsRestartStatus)1 StackGresDbOps (io.stackgres.common.crd.sgdbops.StackGresDbOps)1 StackGresDbOpsSpec (io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec)1 EventEmitter (io.stackgres.common.event.EventEmitter)1 CustomResourceFinder (io.stackgres.common.resource.CustomResourceFinder)1