Search in sources :

Example 1 with StartDeprovisionRegistryTask

use of org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.StartDeprovisionRegistryTask in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class StartDeprovisionRegistryWorker method finallyExecute.

@Transactional
@Override
public void finallyExecute(Task aTask, WorkerContext ctl, Optional<Exception> error) throws RegistryNotFoundException, RegistryStorageConflictException {
    StartDeprovisionRegistryTask task = (StartDeprovisionRegistryTask) aTask;
    Optional<RegistryData> registryOptional = storage.getRegistryById(task.getRegistryId());
    if (registryOptional.isPresent()) {
        var registry = registryOptional.get();
        // SUCCESS STATE
        if (RegistryStatusValueDto.DEPROVISIONING_DELETING.value().equals(registry.getStatus()))
            return;
        // FAILURE
        // Nothing to do, user can retry
        log.warn("Failed to start deprovisioning of Registry '{}'. Check the status to see if the instance is stuck.", registry);
    } else {
        log.warn("Could not find Registry (ID = {}).", task.getRegistryId());
    }
}
Also used : StartDeprovisionRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.StartDeprovisionRegistryTask) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) Transactional(javax.transaction.Transactional)

Example 2 with StartDeprovisionRegistryTask

use of org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.StartDeprovisionRegistryTask in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class StartDeprovisionRegistryWorker method execute.

@Transactional
@Override
public void execute(Task aTask, WorkerContext ctl) throws RegistryStorageConflictException {
    StartDeprovisionRegistryTask task = (StartDeprovisionRegistryTask) aTask;
    Optional<RegistryData> registryOptional = storage.getRegistryById(task.getRegistryId());
    if (registryOptional.isPresent()) {
        // FAILURE POINT 1
        var registry = registryOptional.get();
        var force = Instant.now().isAfter(registry.getCreatedAt().plus(props.getDeprovisionStuckInstanceTimeout()));
        if (force) {
            log.warn("Registry instance '{}' is forced to be deprovisioned.", registry);
        }
        var deprovision = force;
        var status = RegistryStatusValueDto.of(registry.getStatus());
        switch(status) {
            case ACCEPTED:
            case PROVISIONING:
                if (!force) {
                    log.debug("Provisioning in progress. Retrying.");
                    ctl.retry();
                }
                break;
            case READY:
            case FAILED:
                deprovision = true;
                break;
            case REQUESTED_DEPROVISIONING:
            case DEPROVISIONING_DELETING:
                if (!force) {
                    log.debug("Deprovisioning is already in progress. Stopping. Registry = {}", registry);
                    ctl.stop();
                }
                break;
            default:
                throw new IllegalStateException("Unexpected status value: " + status);
        }
        if (deprovision) {
            registry.setStatus(RegistryStatusValueDto.DEPROVISIONING_DELETING.value());
            // FAILURE POINT 2
            storage.createOrUpdateRegistry(registry);
            ctl.delay(() -> tasks.submit(DeprovisionRegistryTask.builder().registryId(registry.getId()).build()));
        }
    } else {
        log.warn("Registry id='{}' not found. Stopping.", task.getRegistryId());
        ctl.stop();
    }
}
Also used : StartDeprovisionRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.StartDeprovisionRegistryTask) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) Transactional(javax.transaction.Transactional)

Aggregations

Transactional (javax.transaction.Transactional)2 StartDeprovisionRegistryTask (org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.StartDeprovisionRegistryTask)2 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)2