Search in sources :

Example 1 with ScheduleRegistryTask

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()));
}
Also used : RegistryDeploymentStatusValue(org.bf2.srs.fleetmanager.rest.service.model.RegistryDeploymentStatusValue) Task(org.bf2.srs.fleetmanager.execution.manager.Task) SCHEDULE_REGISTRY_W(org.bf2.srs.fleetmanager.execution.impl.workers.WorkerType.SCHEDULE_REGISTRY_W) Logger(org.slf4j.Logger) Transactional(javax.transaction.Transactional) RegistryDeploymentData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData) LoggerFactory(org.slf4j.LoggerFactory) TaskManager(org.bf2.srs.fleetmanager.execution.manager.TaskManager) RegistryStatusValueDto(org.bf2.srs.fleetmanager.rest.service.model.RegistryStatusValueDto) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) RegistryStorageConflictException(org.bf2.srs.fleetmanager.storage.RegistryStorageConflictException) Inject(javax.inject.Inject) WorkerContext(org.bf2.srs.fleetmanager.execution.manager.WorkerContext) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ProvisionRegistryTenantTask(org.bf2.srs.fleetmanager.execution.impl.tasks.ProvisionRegistryTenantTask) RegistryNotFoundException(org.bf2.srs.fleetmanager.storage.RegistryNotFoundException) SCHEDULE_REGISTRY_T(org.bf2.srs.fleetmanager.execution.impl.tasks.TaskType.SCHEDULE_REGISTRY_T) ResourceStorage(org.bf2.srs.fleetmanager.storage.ResourceStorage) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Optional(java.util.Optional) ScheduleRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.ScheduleRegistryTask) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ScheduleRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.ScheduleRegistryTask) RegistryDeploymentData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) Transactional(javax.transaction.Transactional)

Example 2 with ScheduleRegistryTask

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());
}
Also used : ScheduleRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.ScheduleRegistryTask) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)

Aggregations

ScheduleRegistryTask (org.bf2.srs.fleetmanager.execution.impl.tasks.ScheduleRegistryTask)2 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)2 List (java.util.List)1 Optional (java.util.Optional)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Collectors.toList (java.util.stream.Collectors.toList)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 Transactional (javax.transaction.Transactional)1 ProvisionRegistryTenantTask (org.bf2.srs.fleetmanager.execution.impl.tasks.ProvisionRegistryTenantTask)1 SCHEDULE_REGISTRY_T (org.bf2.srs.fleetmanager.execution.impl.tasks.TaskType.SCHEDULE_REGISTRY_T)1 SCHEDULE_REGISTRY_W (org.bf2.srs.fleetmanager.execution.impl.workers.WorkerType.SCHEDULE_REGISTRY_W)1 Task (org.bf2.srs.fleetmanager.execution.manager.Task)1 TaskManager (org.bf2.srs.fleetmanager.execution.manager.TaskManager)1 WorkerContext (org.bf2.srs.fleetmanager.execution.manager.WorkerContext)1 RegistryDeploymentStatusValue (org.bf2.srs.fleetmanager.rest.service.model.RegistryDeploymentStatusValue)1 RegistryStatusValueDto (org.bf2.srs.fleetmanager.rest.service.model.RegistryStatusValueDto)1 RegistryNotFoundException (org.bf2.srs.fleetmanager.storage.RegistryNotFoundException)1 RegistryStorageConflictException (org.bf2.srs.fleetmanager.storage.RegistryStorageConflictException)1 ResourceStorage (org.bf2.srs.fleetmanager.storage.ResourceStorage)1