Search in sources :

Example 1 with RegistryNotFoundException

use of org.bf2.srs.fleetmanager.storage.RegistryNotFoundException in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class DeprovisionRegistryWorker method finallyExecute.

@Transactional
@Override
public void finallyExecute(Task aTask, WorkerContext ctl, Optional<Exception> error) throws RegistryNotFoundException, RegistryStorageConflictException {
    DeprovisionRegistryTask task = (DeprovisionRegistryTask) aTask;
    Optional<RegistryData> registry = storage.getRegistryById(task.getRegistryId());
    if (registry.isPresent()) {
        var reg = registry.get();
        // Failure - Could not delete tenant or update status
        // Try updating status to failed, otherwise user can retry.
        reg.setStatus(RegistryStatusValueDto.FAILED.value());
        // TODO Add failed_reason
        storage.createOrUpdateRegistry(reg);
        log.warn("Failed to deprovision Registry: {}", registry);
    } else {
        // SUCCESS
        log.debug("Registry (ID = {}) has been deleted.", task.getRegistryId());
    }
}
Also used : DeprovisionRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.DeprovisionRegistryTask) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) Transactional(javax.transaction.Transactional)

Example 2 with RegistryNotFoundException

use of org.bf2.srs.fleetmanager.storage.RegistryNotFoundException in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class DeprovisionRegistryWorker method execute.

@Transactional
@Override
public void execute(Task aTask, WorkerContext ctl) throws RegistryStorageConflictException, RegistryNotFoundException, AccountManagementServiceException, TenantManagerServiceException {
    var task = (DeprovisionRegistryTask) aTask;
    var registryOptional = storage.getRegistryById(task.getRegistryId());
    if (registryOptional.isPresent()) {
        // FAILURE POINT 1
        var registry = registryOptional.get();
        RegistryDeploymentData registryDeployment = registry.getRegistryDeployment();
        // FAILURE POINT 2
        if (task.getRegistryTenantId() == null) {
            final var tenantId = registry.getId();
            TenantManagerConfig tenantManagerConfig = Utils.createTenantManagerConfig(registryDeployment);
            try {
                tms.deleteTenant(tenantManagerConfig, tenantId);
                log.debug("Tenant id='{}' delete request send.", tenantId);
            } catch (TenantNotFoundServiceException ex) {
                log.info("Tenant id='{}' does not exist (already deleted?).", tenantId);
            }
            task.setRegistryTenantId(tenantId);
        }
        /* Return AMS entitlement
             * FAILURE POINT 3
             * Recovery: We recover by setting the registry status to failed so we don't lose information
             *   and the process can be initiated again.
             * Reentrancy: If the registry was already returned, (i.e. failed in #3)
             *   we need to continue without raising an error, otherwise we will keep retrying.
             */
        if (!task.isAmsSuccess()) {
            final String subscriptionId = registry.getSubscriptionId();
            // TODO Workaround: Remove this once we have RHOSRTrial working.
            if (subscriptionId != null && RegistryInstanceTypeValueDto.of(registry.getInstanceType()) != RegistryInstanceTypeValueDto.EVAL) {
                try {
                    ams.deleteSubscription(subscriptionId);
                } catch (SubscriptionNotFoundServiceException ex) {
                    log.info("Subscription ID '{}' for tenant ID '{}' does not exist (already deleted?).", subscriptionId, task.getRegistryTenantId());
                }
            } else {
                log.debug("Deleting an eval instance {} without calling AMS.", registry.getId());
            }
            task.setAmsSuccess(true);
            log.debug("Subscription (id='{}') for Registry (id='{}') deleted.", subscriptionId, registry.getId());
        }
        /* Delete the registry from DB
             * FAILURE POINT 4
             * Recovery: We set the status to failed so it can be retried.
             * Reentrancy: This is the last step, so nothing to do.
             */
        storage.deleteRegistry(registry.getId());
    } else {
        log.warn("Registry id='{}' not found. Stopping.", task.getRegistryId());
        ctl.stop();
    }
}
Also used : DeprovisionRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.DeprovisionRegistryTask) TenantNotFoundServiceException(org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException) SubscriptionNotFoundServiceException(org.bf2.srs.fleetmanager.spi.ams.SubscriptionNotFoundServiceException) RegistryDeploymentData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData) TenantManagerConfig(org.bf2.srs.fleetmanager.spi.tenants.model.TenantManagerConfig) Transactional(javax.transaction.Transactional)

Example 3 with RegistryNotFoundException

use of org.bf2.srs.fleetmanager.storage.RegistryNotFoundException 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 4 with RegistryNotFoundException

use of org.bf2.srs.fleetmanager.storage.RegistryNotFoundException in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class ProvisionRegistryTenantWorker method finallyExecute.

@Transactional
@Override
public void finallyExecute(Task aTask, WorkerContext ctl, Optional<Exception> error) throws RegistryNotFoundException, RegistryStorageConflictException, SubscriptionNotFoundServiceException, AccountManagementServiceException, TenantManagerServiceException {
    ProvisionRegistryTenantTask task = (ProvisionRegistryTenantTask) aTask;
    RegistryData registry = storage.getRegistryById(task.getRegistryId()).orElse(null);
    RegistryDeploymentData registryDeployment = null;
    if (registry != null)
        registryDeployment = registry.getRegistryDeployment();
    // SUCCESS STATE
    if (registry != null && registry.getRegistryUrl() != null)
        return;
    // Cleanup orphan susbcription, if it's null, it's not needed since it will likely be an eval instance
    if (registry != null && registryDeployment != null && registry.getSubscriptionId() != null) {
        accountManagementService.deleteSubscription(registry.getSubscriptionId());
    }
    // Cleanup orphan tenant
    if (registry != null && registryDeployment != null && task.getRegistryTenantId() != null) {
        try {
            tmClient.deleteTenant(Utils.createTenantManagerConfig(registryDeployment), registry.getId());
        } catch (TenantNotFoundServiceException e) {
            log.warn("Could not delete tenant '{}'. Tenant does not exist and may have been already deleted.", registry.getId());
        }
    }
    // Remove registry entity
    if (registry != null) {
        storage.deleteRegistry(registry.getId());
    }
}
Also used : TenantNotFoundServiceException(org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException) ProvisionRegistryTenantTask(org.bf2.srs.fleetmanager.execution.impl.tasks.ProvisionRegistryTenantTask) RegistryDeploymentData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) Transactional(javax.transaction.Transactional)

Example 5 with RegistryNotFoundException

use of org.bf2.srs.fleetmanager.storage.RegistryNotFoundException in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class RegistryServiceImpl method deleteRegistry.

@Override
@Audited(extractParameters = { "0", KEY_REGISTRY_ID })
@CheckDeletePermissions
public void deleteRegistry(String registryId) throws RegistryNotFoundException, RegistryStorageConflictException {
    try {
        // Verify preconditions - Registry exists
        storage.getRegistryById(registryId).orElseThrow(() -> new RegistryNotFoundException(registryId));
        tasks.submit(StartDeprovisionRegistryTask.builder().registryId(registryId).build());
    } catch (NumberFormatException ex) {
        throw new RegistryNotFoundException(registryId);
    }
}
Also used : RegistryNotFoundException(org.bf2.srs.fleetmanager.storage.RegistryNotFoundException) Audited(org.bf2.srs.fleetmanager.common.operation.auditing.Audited) CheckDeletePermissions(org.bf2.srs.fleetmanager.auth.interceptor.CheckDeletePermissions)

Aggregations

Transactional (javax.transaction.Transactional)4 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)4 DeprovisionRegistryTask (org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.DeprovisionRegistryTask)2 TenantNotFoundServiceException (org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException)2 RegistryDeploymentData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData)2 CheckDeletePermissions (org.bf2.srs.fleetmanager.auth.interceptor.CheckDeletePermissions)1 Audited (org.bf2.srs.fleetmanager.common.operation.auditing.Audited)1 ProvisionRegistryTenantTask (org.bf2.srs.fleetmanager.execution.impl.tasks.ProvisionRegistryTenantTask)1 ScheduleRegistryTask (org.bf2.srs.fleetmanager.execution.impl.tasks.ScheduleRegistryTask)1 StartDeprovisionRegistryTask (org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.StartDeprovisionRegistryTask)1 SubscriptionNotFoundServiceException (org.bf2.srs.fleetmanager.spi.ams.SubscriptionNotFoundServiceException)1 TenantManagerConfig (org.bf2.srs.fleetmanager.spi.tenants.model.TenantManagerConfig)1 RegistryNotFoundException (org.bf2.srs.fleetmanager.storage.RegistryNotFoundException)1