Search in sources :

Example 1 with QuotaCostList

use of org.bf2.srs.fleetmanager.spi.ams.impl.model.response.QuotaCostList in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class AccountManagementServiceImpl method determineAllowedResourceType.

@Timed(value = Constants.AMS_DETERMINE_ALLOWED_INSTANCE_TIMER, description = Constants.AMS_TIMER_DESCRIPTION)
@Audited
@Timeout(FaultToleranceConstants.TIMEOUT_MS)
@RetryUnwrap
// 3 retries, 200ms jitter
@Retry(retryOn = { RetryWrapperException.class })
@RetryWrap
@Override
public ResourceType determineAllowedResourceType(AccountInfo accountInfo) throws AccountManagementServiceException {
    try {
        Organization organization = restClient.getOrganizationByExternalId(accountInfo.getOrganizationId());
        String orgId = organization.getId();
        // Check QuotaCostList for a RHOSR entry with "allowed" quota > 0.  If found, then
        // return "Standard" as the resource type to create.
        QuotaCostList quotaCostList = restClient.getQuotaCostList(orgId, true);
        if (quotaCostList.getSize() > 0) {
            for (QuotaCost quotaCost : quotaCostList.getItems()) {
                // We only care about QuotaCost with "allowed" > 0 and with at least one related resource.
                if (quotaCost.getAllowed() != null && quotaCost.getAllowed() > 0 && quotaCost.getRelated_resources() != null && !quotaCost.getRelated_resources().isEmpty() && isRhosrStandardQuota(quotaCost)) {
                    return ResourceType.REGISTRY_INSTANCE_STANDARD;
                }
            }
        }
        // Default to only allow eval.
        return ResourceType.REGISTRY_INSTANCE_EVAL;
    } catch (AccountManagementSystemClientException ex) {
        ExceptionConvert.convert(ex);
        // Never returns
        return null;
    }
}
Also used : Organization(org.bf2.srs.fleetmanager.spi.ams.impl.model.response.Organization) QuotaCostList(org.bf2.srs.fleetmanager.spi.ams.impl.model.response.QuotaCostList) QuotaCost(org.bf2.srs.fleetmanager.spi.ams.impl.model.response.QuotaCost) AccountManagementSystemClientException(org.bf2.srs.fleetmanager.spi.ams.impl.exception.AccountManagementSystemClientException) Audited(org.bf2.srs.fleetmanager.common.operation.auditing.Audited) Timed(io.micrometer.core.annotation.Timed) Timeout(org.eclipse.microprofile.faulttolerance.Timeout) Retry(org.eclipse.microprofile.faulttolerance.Retry) RetryUnwrap(org.bf2.srs.fleetmanager.common.operation.faulttolerance.RetryUnwrap) RetryWrap(org.bf2.srs.fleetmanager.common.operation.faulttolerance.RetryWrap)

Example 2 with QuotaCostList

use of org.bf2.srs.fleetmanager.spi.ams.impl.model.response.QuotaCostList in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class AccountManagementSystemRestClient method getQuotaCostList.

public QuotaCostList getQuotaCostList(String orgId, boolean fetchRelatedResources) {
    Map<String, List<String>> queryParams = new HashMap<>();
    queryParams.put("fetchRelatedResources", Collections.singletonList(String.valueOf(fetchRelatedResources)));
    QuotaCostList rval = this.client.sendRequest(new Request.RequestBuilder<QuotaCostList>().operation(Operation.GET).path(Paths.QUOTA_COST_PATH).pathParams(Collections.singletonList(orgId)).queryParams(queryParams).responseType(new TypeReference<QuotaCostList>() {
    }).build());
    return rval;
}
Also used : HashMap(java.util.HashMap) QuotaCostList(org.bf2.srs.fleetmanager.spi.ams.impl.model.response.QuotaCostList) Request(io.apicurio.rest.client.request.Request) QuotaCostList(org.bf2.srs.fleetmanager.spi.ams.impl.model.response.QuotaCostList) List(java.util.List) OrganizationList(org.bf2.srs.fleetmanager.spi.ams.impl.model.response.OrganizationList)

Example 3 with QuotaCostList

use of org.bf2.srs.fleetmanager.spi.ams.impl.model.response.QuotaCostList in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class AccountManagementSystemRestClientTest method getQuotaCostList.

@Test
public void getQuotaCostList() {
    final QuotaCostList quotaCostList = accountManagementSystemRestClient.getQuotaCostList("1pcZDw72EPhdanw4pJEnrudOnyj", true);
    Assertions.assertNotNull(quotaCostList);
    Assertions.assertEquals(20, quotaCostList.getTotal());
    Assertions.assertNotNull(quotaCostList.getItems());
    Assertions.assertFalse(quotaCostList.getItems().isEmpty());
    Assertions.assertEquals(20, quotaCostList.getItems().size());
    Assertions.assertEquals("add-on|addon-cluster-logging-operator", quotaCostList.getItems().get(0).getQuota_id());
}
Also used : QuotaCostList(org.bf2.srs.fleetmanager.spi.ams.impl.model.response.QuotaCostList) Test(org.junit.jupiter.api.Test)

Aggregations

QuotaCostList (org.bf2.srs.fleetmanager.spi.ams.impl.model.response.QuotaCostList)3 Request (io.apicurio.rest.client.request.Request)1 Timed (io.micrometer.core.annotation.Timed)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Audited (org.bf2.srs.fleetmanager.common.operation.auditing.Audited)1 RetryUnwrap (org.bf2.srs.fleetmanager.common.operation.faulttolerance.RetryUnwrap)1 RetryWrap (org.bf2.srs.fleetmanager.common.operation.faulttolerance.RetryWrap)1 AccountManagementSystemClientException (org.bf2.srs.fleetmanager.spi.ams.impl.exception.AccountManagementSystemClientException)1 Organization (org.bf2.srs.fleetmanager.spi.ams.impl.model.response.Organization)1 OrganizationList (org.bf2.srs.fleetmanager.spi.ams.impl.model.response.OrganizationList)1 QuotaCost (org.bf2.srs.fleetmanager.spi.ams.impl.model.response.QuotaCost)1 Retry (org.eclipse.microprofile.faulttolerance.Retry)1 Timeout (org.eclipse.microprofile.faulttolerance.Timeout)1 Test (org.junit.jupiter.api.Test)1