use of org.bf2.srs.fleetmanager.rest.publicapi.beans.RegistryCreate 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);
}
use of org.bf2.srs.fleetmanager.rest.publicapi.beans.RegistryCreate in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RegistryDeprovisioningIT method testDeprovisionRegistryBasic.
@Test
void testDeprovisionRegistryBasic() {
FleetManagerApi.verifyApiIsSecured();
var alice = new AccountInfo("testDeprovisionRegistry", "alice", false, 10L);
var registry1 = new RegistryCreate();
registry1.setName("registry1");
var createdRegistry1 = FleetManagerApi.createRegistry(registry1, alice);
assertNotEquals(RegistryStatusValue.failed, createdRegistry1.getStatus());
Awaitility.await("registry1 available").atMost(30, SECONDS).pollInterval(5, SECONDS).until(() -> {
var reg = FleetManagerApi.getRegistry(createdRegistry1.getId(), alice);
return reg.getStatus().equals(RegistryStatusValue.ready);
});
Registry registry = FleetManagerApi.getRegistry(createdRegistry1.getId(), alice);
TenantManagerClient tenantManager = Utils.createTenantManagerClient();
var internalTenant = tenantManager.getTenant(registry.getId());
assertEquals(TenantStatusValue.READY, internalTenant.getStatus());
FleetManagerApi.deleteRegistry(createdRegistry1.getId(), alice);
// We don't have to wait for the status to be RegistryStatusValueRest.deleting, since that happens almost immediately now.
Awaitility.await("registry1 deleting initiated").atMost(5, SECONDS).pollInterval(1, SECONDS).until(() -> {
var tenant1 = tenantManager.getTenant(registry.getId());
return TenantStatusValue.TO_BE_DELETED.equals(tenant1.getStatus());
});
var req = new UpdateRegistryTenantRequest();
req.setStatus(TenantStatusValue.DELETED);
tenantManager.updateTenant(registry.getId(), req);
Awaitility.await("registry1 deleted").atMost(5, SECONDS).pollInterval(1, SECONDS).until(() -> {
try {
FleetManagerApi.verifyRegistryNotExists(createdRegistry1.getId(), alice);
return true;
} catch (AssertionError ex) {
return false;
}
});
}
use of org.bf2.srs.fleetmanager.rest.publicapi.beans.RegistryCreate in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RegistryProvisioningIT method testProvisionRegistry.
@Test
void testProvisionRegistry() {
FleetManagerApi.verifyApiIsSecured();
var alice = new AccountInfo("testProvisionRegistry", "alice", false, 10L);
// verify static deployments config file feature
var deployment = new RegistryDeploymentCreateRest();
deployment.setName("test-deployment");
deployment.setTenantManagerUrl(infra.getTenantManagerUri());
deployment.setRegistryDeploymentUrl("http://registry-test");
FleetManagerApi.verifyCreateDeploymentNotAllowed(deployment, alice);
var registry1 = new RegistryCreate();
registry1.setName("test-registry-1");
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);
});
Registry registry = FleetManagerApi.getRegistry(registry1Result.getId(), alice);
TenantManagerClient tenantManager = Utils.createTenantManagerClient();
var internalTenant = tenantManager.getTenant(registry.getId());
var resources = internalTenant.getResources();
TenantResource maxTotalSchemas = null;
for (var r : resources) {
if (r.getType() == ResourceType.MAX_TOTAL_SCHEMAS_COUNT) {
maxTotalSchemas = r;
}
}
assertNotNull(maxTotalSchemas);
assertEquals(10, maxTotalSchemas.getLimit());
// TODO e2e test check limits are applied
// Delete
FleetManagerApi.deleteRegistry(registry1Result.getId(), alice);
}
use of org.bf2.srs.fleetmanager.rest.publicapi.beans.RegistryCreate in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RegistryServiceImpl method createRegistry.
@Audited
@Override
public RegistryDto createRegistry(RegistryCreateDto registryCreate) throws RegistryStorageConflictException, TermsRequiredException, ResourceLimitReachedException, EvalInstancesNotAllowedException, TooManyEvalInstancesForUserException, TooManyInstancesException, AccountManagementServiceException {
final AccountInfo accountInfo = authService.extractAccountInfo();
// Make sure we have more instances available (max capacity not yet reached).
long instanceCount = storage.getRegistryCountTotal();
if (instanceCount >= maxInstances) {
throw new TooManyInstancesException();
}
// Figure out if we are going to create a standard or eval instance.
ResourceType resourceType = evalInstancesOnlyEnabled ? ResourceType.REGISTRY_INSTANCE_EVAL : accountManagementService.determineAllowedResourceType(accountInfo);
if (resourceType == ResourceType.REGISTRY_INSTANCE_EVAL) {
// Are eval instances allowed?
if (!evalInstancesEnabled) {
throw new EvalInstancesNotAllowedException();
}
// Limit the # of eval instances per user. Need to check storage for list of eval registry instances.
List<RegistryData> registriesByOwner = storage.getRegistriesByOwner(accountInfo.getAccountUsername());
int evalInstanceCount = 0;
for (RegistryData registryData : registriesByOwner) {
// TODO Perform a dedicated query
if (RegistryInstanceTypeValueDto.EVAL.value().equals(registryData.getInstanceType())) {
evalInstanceCount++;
}
}
if (evalInstanceCount >= maxEvalInstancesPerUser) {
throw new TooManyEvalInstancesForUserException();
}
}
// Try to consume some quota from AMS for the appropriate resource type (standard or eval). If successful
// we'll get back a subscriptionId - if not we'll throw an exception.
String subscriptionId = accountManagementService.createResource(accountInfo, resourceType);
// Convert to registry data and persist it in the DB.
RegistryInstanceTypeValueDto instanceType = resourceTypeToInstanceType(resourceType);
RegistryData registryData = convertRegistry.convert(registryCreate, subscriptionId, accountInfo.getAccountUsername(), accountInfo.getOrganizationId(), accountInfo.getAccountId(), instanceType);
// Generate the ID
registryData.setId(UUID.randomUUID().toString());
storage.createOrUpdateRegistry(registryData);
tasks.submit(ScheduleRegistryTask.builder().registryId(registryData.getId()).build());
return convertRegistry.convert(registryData);
}
Aggregations