use of org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry 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.rest.publicapi.beans.Registry 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.rest.publicapi.beans.Registry in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class CheckDeletePermissionsInterceptor method intercept.
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
if (isResolvable(securityIdentity)) {
final AccountInfo accountInfo = authService.extractAccountInfo();
final Optional<RegistryData> registry = storage.getRegistryById(context.getParameters()[0].toString());
if (userCanDeleteInstance(accountInfo, registry)) {
return context.proceed();
}
} else {
return context.proceed();
}
log.info("Attempt to delete registry instance without the proper permissions");
throw new ForbiddenException();
}
use of org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RegistryDeploymentServiceImpl method init.
@Override
public void init() throws IOException, RegistryDeploymentStorageConflictException, RegistryDeploymentNotFoundException {
if (deploymentsConfigFile.isEmpty()) {
return;
}
log.info("Loading registry deployments config file from {}", deploymentsConfigFile.get().getAbsolutePath());
YAMLMapper mapper = new YAMLMapper();
RegistryDeploymentsConfigList deploymentsConfigList = mapper.readValue(deploymentsConfigFile.get(), RegistryDeploymentsConfigList.class);
List<RegistryDeploymentCreate> staticDeployments = deploymentsConfigList.getDeployments();
Set<String> names = new HashSet<>();
List<String> duplicatedNames = staticDeployments.stream().map(d -> {
Set<ConstraintViolation<RegistryDeploymentCreate>> errors = validator.validate(d);
if (!errors.isEmpty()) {
throw new ConstraintViolationException(errors);
}
return d;
}).filter(d -> !names.add(d.getName())).map(d -> d.getName()).collect(Collectors.toList());
if (!duplicatedNames.isEmpty()) {
throw new IllegalArgumentException("Error in static deployments config, duplicated deployments name: " + duplicatedNames.toString());
}
Map<String, RegistryDeploymentData> currentDeployments = storage.getAllRegistryDeployments().stream().collect(Collectors.toMap(d -> d.getName(), d -> d));
for (RegistryDeploymentCreate dep : staticDeployments) {
RegistryDeploymentData deploymentData = currentDeployments.get(dep.getName());
if (deploymentData == null) {
// deployment is new
deploymentData = convertRegistryDeployment.convert(dep);
} else {
if (deploymentData.getRegistryDeploymentUrl().equals(dep.getRegistryDeploymentUrl()) && deploymentData.getTenantManagerUrl().equals(dep.getTenantManagerUrl())) {
// no changes in the deployment
continue;
}
deploymentData.setRegistryDeploymentUrl(dep.getRegistryDeploymentUrl());
deploymentData.setTenantManagerUrl(dep.getTenantManagerUrl());
}
createOrUpdateRegistryDeployment(deploymentData);
}
}
use of org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class QuotaPlanIT method testQuotaPlan.
@Test
void testQuotaPlan() throws Exception {
var alice = new AccountInfo("alice", "alice", false, 1L);
var registry1 = new RegistryCreate();
registry1.setName("registry-basic");
var registry1Result = FleetManagerApi.createRegistry(registry1, alice);
assertNotEquals(RegistryStatusValue.failed, registry1Result.getStatus());
Awaitility.await("registry available").atMost(30, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS).until(() -> {
var reg = FleetManagerApi.getRegistry(registry1Result.getId(), alice);
return reg.getStatus().equals(RegistryStatusValue.ready);
});
var bob = new AccountInfo("bob", "bob", false, 2L);
var registry2 = new RegistryCreate();
registry2.setName("registry-premium");
var registry2Result = FleetManagerApi.createRegistry(registry2, bob);
assertNotEquals(RegistryStatusValue.failed, registry2Result.getStatus());
Awaitility.await("registry available").atMost(30, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS).until(() -> {
var reg = FleetManagerApi.getRegistry(registry2Result.getId(), bob);
return reg.getStatus().equals(RegistryStatusValue.ready);
});
TenantManagerClient tenantManager = Utils.createTenantManagerClient();
// basic
var tenant = tenantManager.getTenant(registry1Result.getId());
var resources = tenant.getResources();
Long l = null;
for (var r : resources) {
if (r.getType() == ResourceType.MAX_TOTAL_SCHEMAS_COUNT) {
l = r.getLimit();
}
}
assertNotNull(l);
assertEquals(10, l);
// premium
tenant = tenantManager.getTenant(registry2Result.getId());
resources = tenant.getResources();
l = null;
for (var r : resources) {
if (r.getType() == ResourceType.MAX_TOTAL_SCHEMAS_COUNT) {
l = r.getLimit();
}
}
assertNotNull(l);
assertEquals(100, l);
// Update the limit value and recheck after forced reconciliation
for (var r : resources) {
if (r.getType() == ResourceType.MAX_TOTAL_SCHEMAS_COUNT) {
r.setLimit(-1L);
}
}
var ur = new UpdateRegistryTenantRequest();
ur.setResources(resources);
tenantManager.updateTenant(registry2Result.getId(), ur);
// Check updated
tenant = tenantManager.getTenant(registry2Result.getId());
resources = tenant.getResources();
l = null;
for (var r : resources) {
if (r.getType() == ResourceType.MAX_TOTAL_SCHEMAS_COUNT) {
l = r.getLimit();
}
}
assertNotNull(l);
assertEquals(-1, l);
// Restart fleet manager(s) so the quota plan is reconciled
TestInfraManager.getInstance().restartFleetManager();
tenant = tenantManager.getTenant(registry2Result.getId());
resources = tenant.getResources();
l = null;
for (var r : resources) {
if (r.getType() == ResourceType.MAX_TOTAL_SCHEMAS_COUNT) {
l = r.getLimit();
}
}
assertNotNull(l);
assertEquals(100, l);
// Delete
FleetManagerApi.deleteRegistry(registry1Result.getId(), alice);
FleetManagerApi.deleteRegistry(registry2Result.getId(), bob);
}
Aggregations