Search in sources :

Example 1 with RegistryCreate

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);
}
Also used : TenantManagerClient(io.apicurio.multitenant.client.TenantManagerClient) RegistryCreate(org.bf2.srs.fleetmanager.rest.publicapi.beans.RegistryCreate) AccountInfo(org.bf2.srs.fleetmanager.spi.common.model.AccountInfo) UpdateRegistryTenantRequest(io.apicurio.multitenant.api.datamodel.UpdateRegistryTenantRequest) Test(org.junit.jupiter.api.Test)

Example 2 with RegistryCreate

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;
        }
    });
}
Also used : TenantManagerClient(io.apicurio.multitenant.client.TenantManagerClient) Registry(org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry) RegistryCreate(org.bf2.srs.fleetmanager.rest.publicapi.beans.RegistryCreate) AccountInfo(org.bf2.srs.fleetmanager.spi.common.model.AccountInfo) UpdateRegistryTenantRequest(io.apicurio.multitenant.api.datamodel.UpdateRegistryTenantRequest) Test(org.junit.jupiter.api.Test)

Example 3 with RegistryCreate

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);
}
Also used : TenantManagerClient(io.apicurio.multitenant.client.TenantManagerClient) RegistryDeploymentCreateRest(org.bf2.srs.fleetmanager.rest.privateapi.beans.RegistryDeploymentCreateRest) TenantResource(io.apicurio.multitenant.api.datamodel.TenantResource) Registry(org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry) RegistryCreate(org.bf2.srs.fleetmanager.rest.publicapi.beans.RegistryCreate) AccountInfo(org.bf2.srs.fleetmanager.spi.common.model.AccountInfo) Test(org.junit.jupiter.api.Test)

Example 4 with RegistryCreate

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);
}
Also used : TooManyInstancesException(org.bf2.srs.fleetmanager.spi.common.TooManyInstancesException) EvalInstancesNotAllowedException(org.bf2.srs.fleetmanager.spi.common.EvalInstancesNotAllowedException) ResourceType(org.bf2.srs.fleetmanager.spi.common.model.ResourceType) TooManyEvalInstancesForUserException(org.bf2.srs.fleetmanager.spi.common.TooManyEvalInstancesForUserException) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) RegistryInstanceTypeValueDto(org.bf2.srs.fleetmanager.rest.service.model.RegistryInstanceTypeValueDto) AccountInfo(org.bf2.srs.fleetmanager.spi.common.model.AccountInfo) Audited(org.bf2.srs.fleetmanager.common.operation.auditing.Audited)

Aggregations

AccountInfo (org.bf2.srs.fleetmanager.spi.common.model.AccountInfo)4 TenantManagerClient (io.apicurio.multitenant.client.TenantManagerClient)3 RegistryCreate (org.bf2.srs.fleetmanager.rest.publicapi.beans.RegistryCreate)3 Test (org.junit.jupiter.api.Test)3 UpdateRegistryTenantRequest (io.apicurio.multitenant.api.datamodel.UpdateRegistryTenantRequest)2 Registry (org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry)2 TenantResource (io.apicurio.multitenant.api.datamodel.TenantResource)1 Audited (org.bf2.srs.fleetmanager.common.operation.auditing.Audited)1 RegistryDeploymentCreateRest (org.bf2.srs.fleetmanager.rest.privateapi.beans.RegistryDeploymentCreateRest)1 RegistryInstanceTypeValueDto (org.bf2.srs.fleetmanager.rest.service.model.RegistryInstanceTypeValueDto)1 EvalInstancesNotAllowedException (org.bf2.srs.fleetmanager.spi.common.EvalInstancesNotAllowedException)1 TooManyEvalInstancesForUserException (org.bf2.srs.fleetmanager.spi.common.TooManyEvalInstancesForUserException)1 TooManyInstancesException (org.bf2.srs.fleetmanager.spi.common.TooManyInstancesException)1 ResourceType (org.bf2.srs.fleetmanager.spi.common.model.ResourceType)1 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)1