use of org.bf2.srs.fleetmanager.execution.manager.Task 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();
}
}
use of org.bf2.srs.fleetmanager.execution.manager.Task in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class ScheduleRegistryWorker method finallyExecute.
@Override
public void finallyExecute(Task aTask, WorkerContext ctl, Optional<Exception> error) throws RegistryNotFoundException, RegistryStorageConflictException {
ScheduleRegistryTask task = (ScheduleRegistryTask) aTask;
// SUCCESS STATE
Optional<RegistryData> registryOpt = storage.getRegistryById(task.getRegistryId());
if (registryOpt.isPresent() && registryOpt.get().getRegistryDeployment() != null)
return;
// The only thing to handle is if we were able to schedule but storage does not work
// In that case, the only thing to do is to just try deleting the registry.
storage.deleteRegistry(task.getRegistryId());
}
Aggregations