Search in sources :

Example 1 with StackGresCluster

use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.

the class MinorVersionUpgradeRestartStateHandlerImpl method initRestartStatusValues.

@Override
protected Uni<Void> initRestartStatusValues(ClusterRestartState clusterRestartState, StackGresCluster cluster) {
    return super.initRestartStatusValues(clusterRestartState, cluster).chain(ignore -> Uni.combine().all().unis(getSourcePostgresVersion(cluster), getTargetPostgresVersion(cluster)).asTuple()).chain(versionTuple -> {
        StackGresClusterDbOpsMinorVersionUpgradeStatus restartStatus = cluster.getStatus().getDbOps().getMinorVersionUpgrade();
        restartStatus.setSourcePostgresVersion(versionTuple.getItem1());
        restartStatus.setTargetPostgresVersion(versionTuple.getItem2());
        return Uni.createFrom().voidItem();
    });
}
Also used : StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresDbOpsMinorVersionUpgrade(io.stackgres.common.crd.sgdbops.StackGresDbOpsMinorVersionUpgrade) PatroniApiHandler(io.stackgres.jobs.dbops.clusterrestart.PatroniApiHandler) StackGresClusterDbOpsMinorVersionUpgradeStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsMinorVersionUpgradeStatus) DbOpsRestartStatus(io.stackgres.common.crd.sgdbops.DbOpsRestartStatus) ClusterRestartState(io.stackgres.jobs.dbops.clusterrestart.ClusterRestartState) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) Uni(io.smallrye.mutiny.Uni) AbstractRestartStateHandler(io.stackgres.jobs.dbops.AbstractRestartStateHandler) Inject(javax.inject.Inject) StackGresDbOpsMinorVersionUpgradeStatus(io.stackgres.common.crd.sgdbops.StackGresDbOpsMinorVersionUpgradeStatus) ClusterDbOpsRestartStatus(io.stackgres.common.crd.sgcluster.ClusterDbOpsRestartStatus) Optional(java.util.Optional) StackGresDbOpsStatus(io.stackgres.common.crd.sgdbops.StackGresDbOpsStatus) PatroniInformation(io.stackgres.jobs.dbops.clusterrestart.PatroniInformation) ApplicationScoped(javax.enterprise.context.ApplicationScoped) StateHandler(io.stackgres.jobs.dbops.StateHandler) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StackGresDbOpsSpec(io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec) StackGresClusterDbOpsMinorVersionUpgradeStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsMinorVersionUpgradeStatus)

Example 2 with StackGresCluster

use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.

the class LockAcquirerImplTest method asycRunTaskSuccessfully.

private AtomicBoolean asycRunTaskSuccessfully(int delay) {
    AtomicBoolean taskRan = new AtomicBoolean(false);
    executorService.execute(() -> lockAcquirer.lockRun(lockRequest, (cluster) -> {
        if (delay > 0) {
            sleep(delay);
        }
        StackGresCluster lastPatch = kubeDb.getCluster(clusterName, clusterNamespace);
        final Map<String, String> annotations = lastPatch.getMetadata().getAnnotations();
        assertEquals(lockRequest.getPodName(), annotations.get(LOCK_POD_KEY), "Task ran without Lock!!");
        assertNotNull(annotations.get(LOCK_TIMESTAMP_KEY));
        taskRan.set(true);
    }));
    return taskRan;
}
Also used : LOCK_POD_KEY(io.stackgres.common.StackGresContext.LOCK_POD_KEY) LOCK_TIMESTAMP_KEY(io.stackgres.common.StackGresContext.LOCK_TIMESTAMP_KEY) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Executors(java.util.concurrent.Executors) JsonUtil(io.stackgres.testutil.JsonUtil) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test) StringUtils(io.stackgres.testutil.StringUtils) AfterEach(org.junit.jupiter.api.AfterEach) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ExecutorService(java.util.concurrent.ExecutorService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) Map(java.util.Map)

Example 3 with StackGresCluster

use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.

the class MockKubeDb method introduceReplaceFailures.

public void introduceReplaceFailures(int i, StackGresCluster cluster) {
    StackGresCluster storedCluster = getCustomResource(cluster, StackGresCluster.class);
    int pendingFailures = Optional.ofNullable((Integer) storedCluster.getMetadata().getAdditionalProperties().get(PENDING_FAILURES)).orElse(0) + 1;
    storedCluster.getMetadata().getAdditionalProperties().put(PENDING_FAILURES, pendingFailures);
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster)

Example 4 with StackGresCluster

use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.

the class LockAcquirerImpl method lockRun.

@Override
public void lockRun(LockRequest target, Consumer<StackGresCluster> task) {
    StackGresCluster targetCluster = getCluster(target);
    String clusterId = targetCluster.getMetadata().getNamespace() + "/" + targetCluster.getMetadata().getName();
    LOGGER.info("Acquiring lock for cluster {}", clusterId);
    if (StackGresUtil.isLocked(targetCluster, target.getTimeout()) && !StackGresUtil.isLockedByMe(targetCluster, target.getPodName())) {
        LOGGER.info("Locked cluster {}, waiting for release", clusterId);
        while (StackGresUtil.isLocked(targetCluster, target.getTimeout())) {
            try {
                Thread.sleep(target.getPollInterval() * 1000L);
                targetCluster = getCluster(target);
            } catch (InterruptedException e) {
                LOGGER.error("Interrupted while waiting for lock", e);
            }
        }
    }
    targetCluster = lock(target, targetCluster);
    LOGGER.info("Cluster {} locked", clusterId);
    var lockFuture = EXECUTOR.scheduleAtFixedRate(() -> lock(target), target.getPollInterval(), target.getPollInterval(), TimeUnit.SECONDS);
    try {
        LOGGER.info("Executing locked task");
        task.accept(targetCluster);
    } catch (Exception e) {
        LOGGER.error("Locked task failed", e);
        throw e;
    } finally {
        lockFuture.cancel(true);
        Uni.createFrom().item(() -> getCluster(target)).invoke(StackGresUtil::resetLock).invoke(clusterScheduler::update).onFailure().retry().withBackOff(Duration.ofMillis(5), Duration.ofSeconds(5)).indefinitely().await().indefinitely();
    }
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster)

Example 5 with StackGresCluster

use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.

the class ClusterWatcher method waitUntilIsReady.

@Override
public Uni<StackGresCluster> waitUntilIsReady(String name, String namespace) {
    return Uni.createFrom().emitter(em -> {
        LOGGER.debug("Looking for SGCluster {} in namespace {}", name, namespace);
        StackGresCluster cluster = clusterFinder.findByNameAndNamespace(name, namespace).orElseThrow(() -> {
            LOGGER.debug("SGCluster {} in namespace {} not found", name, namespace);
            return new IllegalStateException("cluster not found");
        });
        scanClusterPods(cluster).chain(() -> getClusterMembers(cluster)).onFailure().retry().withBackOff(Duration.ofMillis(10), Duration.ofSeconds(5)).indefinitely().subscribe().with(members -> em.complete(cluster));
    });
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster)

Aggregations

StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)127 Test (org.junit.jupiter.api.Test)48 Optional (java.util.Optional)32 List (java.util.List)31 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)27 StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)25 ImmutableList (com.google.common.collect.ImmutableList)24 Inject (javax.inject.Inject)22 ArrayList (java.util.ArrayList)19 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)18 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)15 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)15 StackGresComponent (io.stackgres.common.StackGresComponent)15 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)14 ExtensionInstaller (io.stackgres.common.extension.ExtensionManager.ExtensionInstaller)14 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)13 Collectors (java.util.stream.Collectors)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 ExtensionUninstaller (io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller)12 JsonUtil (io.stackgres.testutil.JsonUtil)12