Search in sources :

Example 6 with Audited

use of org.bf2.srs.fleetmanager.common.operation.auditing.Audited in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class RegistryServiceImpl method deleteRegistry.

@Override
@Audited(extractParameters = { "0", KEY_REGISTRY_ID })
@CheckDeletePermissions
public void deleteRegistry(String registryId) throws RegistryNotFoundException, RegistryStorageConflictException {
    try {
        // Verify preconditions - Registry exists
        storage.getRegistryById(registryId).orElseThrow(() -> new RegistryNotFoundException(registryId));
        tasks.submit(StartDeprovisionRegistryTask.builder().registryId(registryId).build());
    } catch (NumberFormatException ex) {
        throw new RegistryNotFoundException(registryId);
    }
}
Also used : RegistryNotFoundException(org.bf2.srs.fleetmanager.storage.RegistryNotFoundException) Audited(org.bf2.srs.fleetmanager.common.operation.auditing.Audited) CheckDeletePermissions(org.bf2.srs.fleetmanager.auth.interceptor.CheckDeletePermissions)

Example 7 with Audited

use of org.bf2.srs.fleetmanager.common.operation.auditing.Audited 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

Audited (org.bf2.srs.fleetmanager.common.operation.auditing.Audited)7 Timed (io.micrometer.core.annotation.Timed)4 AccountManagementSystemClientException (org.bf2.srs.fleetmanager.spi.ams.impl.exception.AccountManagementSystemClientException)2 Retry (org.eclipse.microprofile.faulttolerance.Retry)2 NewRegistryTenantRequest (io.apicurio.multitenant.api.datamodel.NewRegistryTenantRequest)1 RegistryTenant (io.apicurio.multitenant.api.datamodel.RegistryTenant)1 TenantResource (io.apicurio.multitenant.api.datamodel.TenantResource)1 TenantManagerClientException (io.apicurio.multitenant.client.exception.TenantManagerClientException)1 AroundInvoke (javax.interceptor.AroundInvoke)1 CheckDeletePermissions (org.bf2.srs.fleetmanager.auth.interceptor.CheckDeletePermissions)1 RetryUnwrap (org.bf2.srs.fleetmanager.common.operation.faulttolerance.RetryUnwrap)1 RetryWrap (org.bf2.srs.fleetmanager.common.operation.faulttolerance.RetryWrap)1 AuditingEvent (org.bf2.srs.fleetmanager.operation.auditing.AuditingEvent)1 RegistryInstanceTypeValueDto (org.bf2.srs.fleetmanager.rest.service.model.RegistryInstanceTypeValueDto)1 ResourceLimitReachedException (org.bf2.srs.fleetmanager.spi.ams.ResourceLimitReachedException)1 TermsRequiredException (org.bf2.srs.fleetmanager.spi.ams.TermsRequiredException)1 ClusterAuthorization (org.bf2.srs.fleetmanager.spi.ams.impl.model.request.ClusterAuthorization)1 TermsReview (org.bf2.srs.fleetmanager.spi.ams.impl.model.request.TermsReview)1 ClusterAuthorizationResponse (org.bf2.srs.fleetmanager.spi.ams.impl.model.response.ClusterAuthorizationResponse)1 Organization (org.bf2.srs.fleetmanager.spi.ams.impl.model.response.Organization)1