use of io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus in project stackgres by ongres.
the class SecurityUpgradeJob method reportFailure.
private void reportFailure(StackGresDbOps dbOps, Throwable ex) {
String message = ex.getMessage();
String dbOpsName = dbOps.getMetadata().getName();
String namespace = dbOps.getMetadata().getNamespace();
dbOpsFinder.findByNameAndNamespace(dbOpsName, namespace).ifPresent(savedDbOps -> {
if (savedDbOps.getStatus() == null) {
savedDbOps.setStatus(new StackGresDbOpsStatus());
}
if (savedDbOps.getStatus().getSecurityUpgrade() == null) {
savedDbOps.getStatus().setSecurityUpgrade(new StackGresDbOpsSecurityUpgradeStatus());
}
savedDbOps.getStatus().getSecurityUpgrade().setFailure(message);
dbOpsScheduler.update(savedDbOps);
});
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus in project stackgres by ongres.
the class DbOpsTransformer method getResourceStatus.
private DbOpsStatus getResourceStatus(StackGresDbOpsStatus source) {
if (source == null) {
return null;
}
DbOpsStatus transformation = new DbOpsStatus();
transformation.setConditions(source.getConditions().stream().map(this::getResourceCondition).collect(Collectors.toList()));
transformation.setOpRetries(source.getOpRetries());
transformation.setOpStarted(source.getOpStarted());
transformation.setBenchmark(getResourceBenchmarkStatus(source.getBenchmark()));
transformation.setMajorVersionUpgrade(getResourceMajorVersionUpgradeStatus(source.getMajorVersionUpgrade()));
transformation.setRestart(getResourceRestartStatus(source.getRestart()));
transformation.setMinorVersionUpgrade(getResourceMinorVersionUpgradeStatus(source.getMinorVersionUpgrade()));
transformation.setSecurityUpgrade(getResourceSecurityUpgradeStatus(source.getSecurityUpgrade()));
return transformation;
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus in project stackgres by ongres.
the class DbOpLauncherImplTest method givenAValidDbOpsRetry_shouldSetRunningConditionsBeforeExecutingTheJob.
@Test
void givenAValidDbOpsRetry_shouldSetRunningConditionsBeforeExecutingTheJob() {
ArgumentCaptor<StackGresDbOps> captor = ArgumentCaptor.forClass(StackGresDbOps.class);
when(securityUpgradeJob.runJob(captor.capture(), any())).thenAnswer(invocation -> getClusterRestartStateUni());
Instant previousOpStarted = Instant.now();
dbOps.setStatus(new StackGresDbOpsStatus());
dbOps.getStatus().setOpStarted(previousOpStarted.toString());
dbOps.getStatus().setOpRetries(0);
dbOps.getStatus().setConditions(Seq.of(DbOpsStatusCondition.DB_OPS_FALSE_RUNNING, DbOpsStatusCondition.DB_OPS_FALSE_COMPLETED, DbOpsStatusCondition.DB_OPS_FAILED).map(DbOpsStatusCondition::getCondition).peek(condition -> condition.setLastTransitionTime(previousOpStarted.toString())).toList());
mockKubeDb.addOrReplaceDbOps(dbOps);
dbOpLauncher.launchDbOp(randomDbOpsName, namespace);
StackGresDbOps captured = captor.getValue();
assertNotNull(captured.getStatus().getOpStarted());
assertTrue(Instant.parse(captured.getStatus().getOpStarted()).isBefore(Instant.now()));
assertEquals(1, captured.getStatus().getOpRetries());
var conditions = captured.getStatus().getConditions();
assertNotNull(conditions);
assertEquals(3, conditions.size());
assertTrue(() -> conditions.stream().anyMatch(DbOpsStatusCondition.DB_OPS_RUNNING::isCondition));
assertTrue(() -> conditions.stream().anyMatch(DbOpsStatusCondition.DB_OPS_FALSE_COMPLETED::isCondition));
assertTrue(() -> conditions.stream().anyMatch(DbOpsStatusCondition.DB_OPS_FALSE_FAILED::isCondition));
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus in project stackgres by ongres.
the class ClusterStateHandlerTest method setUp.
@BeforeEach
public void setUp() {
namespace = StringUtils.getRandomNamespace();
clusterName = StringUtils.getRandomClusterName();
dbOps = JsonUtil.readFromJson("stackgres_dbops/dbops_securityupgrade.json", StackGresDbOps.class);
cluster = JsonUtil.readFromJson("stackgres_cluster/default.json", StackGresCluster.class);
dbOps.getMetadata().setName(dbOpsName);
dbOps.getMetadata().setNamespace(namespace);
dbOps.getSpec().setSgCluster(clusterName);
dbOps.setStatus(new StackGresDbOpsStatus());
dbOps.getStatus().setOpRetries(0);
dbOps.getStatus().setOpStarted(Instant.now().toString());
dbOps.getSpec().setOp("securityUpgrade");
cluster.getMetadata().setName(clusterName);
cluster.getMetadata().setNamespace(namespace);
cluster = kubeDb.addOrReplaceCluster(cluster);
dbOps = kubeDb.addOrReplaceDbOps(dbOps);
lenient().doNothing().when(eventEmitter).sendEvent(any(), any(), any());
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus in project stackgres by ongres.
the class DatabaseOperationEventEmitterImplTest method setUp.
@BeforeEach
void setUp() {
namespace = StringUtils.getRandomNamespace();
clusterName = StringUtils.getRandomClusterName();
dbOps = JsonUtil.readFromJson("stackgres_dbops/dbops_securityupgrade.json", StackGresDbOps.class);
dbOps.getMetadata().setName(dbOpsName);
dbOps.getMetadata().setNamespace(namespace);
dbOps.getSpec().setSgCluster(clusterName);
dbOps.setStatus(new StackGresDbOpsStatus());
dbOps.getStatus().setOpRetries(0);
dbOps.getStatus().setOpStarted(Instant.now().toString());
dbOps.getSpec().setOp("securityUpgrade");
dbOps = kubeDb.addOrReplaceDbOps(dbOps);
}
Aggregations