use of org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException 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();
}
}
use of org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException 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());
}
}
use of org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class FileQuotaPlansService method reconcile.
private void reconcile() {
log.info("Performing quota plan reconciliation");
var allRegistries = storage.getAllRegistries();
var updatedCount = 0;
for (RegistryData registry : allRegistries) {
var tid = registry.getId();
var tmc = Utils.createTenantManagerConfig(registry.getRegistryDeployment());
try {
var tenant = tmClient.getTenantById(tmc, tid).orElseThrow();
Map<String, Long> tenantLimits = new HashMap<>();
for (TenantLimit resource : tenant.getResources()) {
tenantLimits.put(resource.getType(), resource.getLimit());
}
var targetPlan = determineQuotaPlan(registry.getOrgId());
var requiresUpdate = false;
// Compare limits
for (TenantLimit targetLimit : targetPlan.getResources()) {
var v = tenantLimits.get(targetLimit.getType());
if (v == null || !v.equals(targetLimit.getLimit())) {
requiresUpdate = true;
break;
}
}
if (requiresUpdate) {
UpdateTenantRequest utr = UpdateTenantRequest.builder().id(tid).status(tenant.getStatus()).resources(targetPlan.getResources()).build();
tmClient.updateTenant(tmc, utr);
updatedCount++;
}
} catch (TenantManagerServiceException | NoSuchElementException | TenantNotFoundServiceException e) {
log.warn("Could not get or update tenant " + tid + " during quota plan reconciliation", e);
}
}
log.info("Quota plan reconciliation successful. Updated {} out of {} tenants", updatedCount, allRegistries.size());
}
use of org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class MigrationService method runMigration.
public void runMigration() throws TenantManagerServiceException {
if (deleteAll.isPresent() && deleteAll.get()) {
log.warn("Removing all data first");
TenantManagerConfig tm = TenantManagerConfig.builder().tenantManagerUrl("http://tenant-manager:8585").registryDeploymentUrl("https://service-registry-stage.apps.app-sre-stage-0.k3s7.p1.openshiftapps.com").build();
for (Tenant t : tenantManagerClient.getAllTenants(tm)) {
log.warn("Deleting tenant '{}'", t.getId());
try {
tenantManagerClient.deleteTenant(tm, t.getId());
} catch (TenantNotFoundServiceException ex) {
log.warn("Could not delete tenant '{}'. Tenant does not exist and may have been already deleted.", t.getId());
}
}
CleanResult cleanResult = flyway.clean();
log.info("Database clean result: " + "flywayVersion = '{}', " + "database = '{}', " + "schemasCleaned = '{}', " + "schemasDropped = '{}', " + "warnings = '{}'.", cleanResult.flywayVersion, cleanResult.database, cleanResult.schemasCleaned, cleanResult.schemasDropped, cleanResult.warnings);
}
MigrateResult migrateResult = flyway.migrate();
log.info("Database migrate result: " + "flywayVersion = '{}', " + "database = '{}', " + "initialSchemaVersion = '{}', " + "targetSchemaVersion = '{}', " + "migrations = '{}', " + "warnings = '{}'.", migrateResult.flywayVersion, migrateResult.database, migrateResult.initialSchemaVersion, migrateResult.targetSchemaVersion, migrateResult.migrations, migrateResult.warnings);
}
Aggregations