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