Search in sources :

Example 1 with StackGresDbOpsStatus

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

Example 2 with StackGresDbOpsStatus

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

Example 3 with StackGresDbOpsStatus

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));
}
Also used : StackGresDbOpsStatus(io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus) Instant(java.time.Instant) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) DbOpsStatusCondition(io.stackgres.common.crd.sgdbops.DbOpsStatusCondition) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 4 with StackGresDbOpsStatus

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());
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresDbOpsStatus(io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with StackGresDbOpsStatus

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);
}
Also used : StackGresDbOpsStatus(io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

StackGresDbOpsStatus (io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus)7 StackGresDbOps (io.stackgres.common.crd.sgdbops.StackGresDbOps)4 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)2 DbOpsStatusCondition (io.stackgres.common.crd.sgdbops.DbOpsStatusCondition)2 Instant (java.time.Instant)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 TimeoutException (io.smallrye.mutiny.TimeoutException)1 Uni (io.smallrye.mutiny.Uni)1 Infrastructure (io.smallrye.mutiny.infrastructure.Infrastructure)1 DbOpsStatus (io.stackgres.apiweb.dto.dbops.DbOpsStatus)1 StackGresDbOpsCondition (io.stackgres.common.crd.sgdbops.StackGresDbOpsCondition)1 StackGresDbOpsRestartStatus (io.stackgres.common.crd.sgdbops.StackGresDbOpsRestartStatus)1 StackGresDbOpsSecurityUpgradeStatus (io.stackgres.common.crd.sgdbops.StackGresDbOpsSecurityUpgradeStatus)1 CustomResourceFinder (io.stackgres.common.resource.CustomResourceFinder)1 CustomResourceScheduler (io.stackgres.common.resource.CustomResourceScheduler)1 JobsProperty (io.stackgres.jobs.app.JobsProperty)1 DBOPS_LOCK_POLL_INTERVAL (io.stackgres.jobs.app.JobsProperty.DBOPS_LOCK_POLL_INTERVAL)1 DBOPS_LOCK_TIMEOUT (io.stackgres.jobs.app.JobsProperty.DBOPS_LOCK_TIMEOUT)1 ClusterRestartState (io.stackgres.jobs.dbops.clusterrestart.ClusterRestartState)1