use of io.stackgres.common.crd.sgdbops.DbOpsRestartStatus in project stackgres by ongres.
the class ClusterStateHandlerTest method givenAnUninitializedJobState_itShouldInitializeIt.
@Test
void givenAnUninitializedJobState_itShouldInitializeIt() {
podTestUtil.preparePods(cluster, 0, 1, 2);
var pods = podTestUtil.getClusterPods(cluster);
final String dbOpsName = dbOps.getMetadata().getName();
getRestartStateHandler().restartCluster(dbOps).await().atMost(Duration.ofMillis(50));
var storedDbOps = kubeDb.getDbOps(dbOpsName, namespace);
List<String> expectedInitialInstances = pods.stream().map(Pod::getMetadata).map(ObjectMeta::getName).sorted(String::compareTo).collect(Collectors.toUnmodifiableList());
final DbOpsRestartStatus initializedSecurityUpgradeStatus = getRestartStatus(storedDbOps);
Pod primaryPod = pods.stream().filter(pod -> pod.getMetadata().getName().endsWith("-0")).findAny().get();
assertEquals(primaryPod.getMetadata().getName(), initializedSecurityUpgradeStatus.getPrimaryInstance());
List<String> actualInitialInstances = initializedSecurityUpgradeStatus.getInitialInstances();
assertEquals(expectedInitialInstances, actualInitialInstances);
List<String> actualPendingRestartedInstances = initializedSecurityUpgradeStatus.getPendingToRestartInstances();
assertEquals(expectedInitialInstances, actualPendingRestartedInstances);
assertTrue(() -> initializedSecurityUpgradeStatus.getRestartedInstances() == null || initializedSecurityUpgradeStatus.getRestartedInstances().isEmpty());
assertNull(initializedSecurityUpgradeStatus.getFailure());
assertNull(initializedSecurityUpgradeStatus.getSwitchoverInitiated());
assertEquals(dbOps, storedDbOps, "It should store the DBOps status changes");
}
use of io.stackgres.common.crd.sgdbops.DbOpsRestartStatus 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();
}
Aggregations