use of org.bf2.srs.fleetmanager.execution.impl.tasks.ScheduleRegistryTask in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class ScheduleRegistryWorker method execute.
@Transactional
@Override
public void execute(Task aTask, WorkerContext ctl) throws RegistryStorageConflictException {
ScheduleRegistryTask task = (ScheduleRegistryTask) aTask;
Optional<RegistryData> registryOptional = storage.getRegistryById(task.getRegistryId());
if (registryOptional.isEmpty()) {
// NOTE: Failure point 1
ctl.retry();
}
RegistryData registry = registryOptional.get();
List<RegistryDeploymentData> eligibleRegistryDeployments = storage.getAllRegistryDeployments().stream().filter(rd -> RegistryDeploymentStatusValue.of(rd.getStatus().getValue()) == RegistryDeploymentStatusValue.AVAILABLE).collect(toList());
if (eligibleRegistryDeployments.isEmpty()) {
// NOTE: Failure point 2
// TODO How to report it better?
log.warn("Could not schedule registry with ID {}. No deployments are available.", registry.getId());
// We can wait here longer, somebody needs to create a deployment
ctl.retry(100);
}
// Schedule to a random registry deployment
// TODO Improve & use a specific scheduling strategy
RegistryDeploymentData registryDeployment = eligibleRegistryDeployments.get(ThreadLocalRandom.current().nextInt(eligibleRegistryDeployments.size()));
// TODO only available
log.info("Scheduling {} to {}.", registry, registryDeployment);
registry.setRegistryDeployment(registryDeployment);
registry.setStatus(RegistryStatusValueDto.PROVISIONING.value());
// NOTE: Failure point 3
storage.createOrUpdateRegistry(registry);
ctl.delay(() -> tasks.submit(ProvisionRegistryTenantTask.builder().registryId(registry.getId()).build()));
}
use of org.bf2.srs.fleetmanager.execution.impl.tasks.ScheduleRegistryTask 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