use of org.bf2.srs.fleetmanager.spi.tenants.model.CreateTenantRequest in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class ProvisionRegistryTenantWorker method execute.
@Transactional
@Override
public void execute(Task aTask, WorkerContext ctl) throws RegistryStorageConflictException, TenantManagerServiceException {
// TODO Split along failure points?
ProvisionRegistryTenantTask task = (ProvisionRegistryTenantTask) aTask;
Optional<RegistryData> registryOptional = storage.getRegistryById(task.getRegistryId());
// NOTE: Failure point 1
if (registryOptional.isEmpty()) {
ctl.retry();
}
RegistryData registry = registryOptional.get();
RegistryDeploymentData registryDeployment = registry.getRegistryDeployment();
// NOTE: Failure point 2
if (registryDeployment == null) {
// Either the schedule task didn't run yet, or we are in trouble
ctl.retry();
}
String registryUrl = registryDeployment.getRegistryDeploymentUrl();
// New approach: configure the deployment URL with a replacement like: https://TENANT_ID.shrd.sr.openshift.com
if (registryUrl.contains("TENANT_ID")) {
registryUrl = registryUrl.replace("TENANT_ID", registry.getId());
} else {
// Old approach: configure the deployment URL without a replacement, and just add "/t/TENANT_ID" to the end of it.
if (!registryUrl.endsWith("/")) {
registryUrl += "/";
}
registryUrl += "t/" + registry.getId();
}
registry.setRegistryUrl(registryUrl);
// Avoid accidentally creating orphan tenants
if (task.getRegistryTenantId() == null) {
CreateTenantRequest tenantRequest = CreateTenantRequest.builder().tenantId(registry.getId()).createdBy(registry.getOwner()).organizationId(registry.getOrgId()).resources(plansService.determineQuotaPlan(registry.getOrgId()).getResources()).build();
TenantManagerConfig tenantManager = Utils.createTenantManagerConfig(registryDeployment);
// NOTE: Failure point 4
tmClient.createTenant(tenantManager, tenantRequest);
task.setRegistryTenantId(registry.getId());
}
// Add expiration task if this is an eval instance
if (isEvalInstance(registry.getInstanceType())) {
var expiration = Instant.now().plus(Duration.ofSeconds(evalLifetimeSeconds));
log.debug("Scheduling an expiration task for the eval instance {} to be executed at {}", registry, expiration);
ctl.delay(() -> tasks.submit(EvalInstanceExpirationRegistryTask.builder().registryId(registry.getId()).schedule(TaskSchedule.builder().firstExecuteAt(expiration).build()).build()));
}
// NOTE: Failure point 5
registry.setStatus(RegistryStatusValueDto.READY.value());
storage.createOrUpdateRegistry(registry);
// TODO This task is (temporarily) not used. Enable when needed.
// Update status to available in the heartbeat task, which should run ASAP
// ctl.delay(() -> tasks.submit(RegistryHeartbeatTask.builder().registryId(registry.getId()).build()));
}
use of org.bf2.srs.fleetmanager.spi.tenants.model.CreateTenantRequest in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RestClientTenantManagerServiceImpl method createTenant.
@Timed(value = Constants.TENANT_MANAGER_CREATE_TENANT_TIMER, description = Constants.TENANT_MANAGER_DESCRIPTION)
@Audited
// 3 retries, 200ms jitter
@Retry(retryOn = { TenantManagerServiceException.class })
@Override
public Tenant createTenant(TenantManagerConfig tm, CreateTenantRequest tenantRequest) throws TenantManagerServiceException {
try {
var client = getClient(tm);
NewRegistryTenantRequest req = new NewRegistryTenantRequest();
req.setOrganizationId(tenantRequest.getOrganizationId());
req.setTenantId(tenantRequest.getTenantId());
req.setCreatedBy(tenantRequest.getCreatedBy());
req.setResources(Optional.ofNullable(tenantRequest.getResources()).stream().flatMap(Collection::stream).map(r -> {
TenantResource tr = new TenantResource();
tr.setType(ResourceType.fromValue(r.getType()));
tr.setLimit(r.getLimit());
return tr;
}).collect(Collectors.toList()));
RegistryTenant tenant = client.createTenant(req);
return convert(tenant);
} catch (TenantManagerClientException ex) {
throw ExceptionConvert.convert(ex);
}
}
use of org.bf2.srs.fleetmanager.spi.tenants.model.CreateTenantRequest in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class MockTenantManagerService method createTenant.
@Timed(value = Constants.TENANT_MANAGER_CREATE_TENANT_TIMER, description = Constants.TENANT_MANAGER_DESCRIPTION)
@Audited
@Override
public Tenant createTenant(TenantManagerConfig tm, CreateTenantRequest req) {
requireNonNull(tm);
requireNonNull(req);
Tenant tenant = Tenant.builder().id(req.getTenantId()).build();
init(tm);
testData.get(tm).put(tenant.getId(), tenant);
return tenant;
}
Aggregations