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;
}
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();
}
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;
}
Aggregations