Search in sources :

Example 1 with TenantLimit

use of org.bf2.srs.fleetmanager.spi.tenants.model.TenantLimit in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class FileQuotaPlansService method reconcile.

private void reconcile() {
    log.info("Performing quota plan reconciliation");
    var allRegistries = storage.getAllRegistries();
    var updatedCount = 0;
    for (RegistryData registry : allRegistries) {
        var tid = registry.getId();
        var tmc = Utils.createTenantManagerConfig(registry.getRegistryDeployment());
        try {
            var tenant = tmClient.getTenantById(tmc, tid).orElseThrow();
            Map<String, Long> tenantLimits = new HashMap<>();
            for (TenantLimit resource : tenant.getResources()) {
                tenantLimits.put(resource.getType(), resource.getLimit());
            }
            var targetPlan = determineQuotaPlan(registry.getOrgId());
            var requiresUpdate = false;
            // Compare limits
            for (TenantLimit targetLimit : targetPlan.getResources()) {
                var v = tenantLimits.get(targetLimit.getType());
                if (v == null || !v.equals(targetLimit.getLimit())) {
                    requiresUpdate = true;
                    break;
                }
            }
            if (requiresUpdate) {
                UpdateTenantRequest utr = UpdateTenantRequest.builder().id(tid).status(tenant.getStatus()).resources(targetPlan.getResources()).build();
                tmClient.updateTenant(tmc, utr);
                updatedCount++;
            }
        } catch (TenantManagerServiceException | NoSuchElementException | TenantNotFoundServiceException e) {
            log.warn("Could not get or update tenant " + tid + " during quota plan reconciliation", e);
        }
    }
    log.info("Quota plan reconciliation successful. Updated {} out of {} tenants", updatedCount, allRegistries.size());
}
Also used : TenantNotFoundServiceException(org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UpdateTenantRequest(org.bf2.srs.fleetmanager.spi.tenants.model.UpdateTenantRequest) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) TenantLimit(org.bf2.srs.fleetmanager.spi.tenants.model.TenantLimit) TenantManagerServiceException(org.bf2.srs.fleetmanager.spi.tenants.TenantManagerServiceException) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with TenantLimit

use of org.bf2.srs.fleetmanager.spi.tenants.model.TenantLimit in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class RestClientTenantManagerServiceImpl method convertToTenantResource.

private List<TenantResource> convertToTenantResource(List<TenantLimit> data) {
    var res = new ArrayList<TenantResource>();
    for (TenantLimit d : data) {
        var tr = new TenantResource();
        tr.setType(ResourceType.fromValue(d.getType()));
        tr.setLimit(d.getLimit());
        res.add(tr);
    }
    return res;
}
Also used : TenantResource(io.apicurio.multitenant.api.datamodel.TenantResource) ArrayList(java.util.ArrayList) TenantLimit(org.bf2.srs.fleetmanager.spi.tenants.model.TenantLimit)

Aggregations

TenantLimit (org.bf2.srs.fleetmanager.spi.tenants.model.TenantLimit)2 TenantResource (io.apicurio.multitenant.api.datamodel.TenantResource)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NoSuchElementException (java.util.NoSuchElementException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TenantManagerServiceException (org.bf2.srs.fleetmanager.spi.tenants.TenantManagerServiceException)1 TenantNotFoundServiceException (org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException)1 UpdateTenantRequest (org.bf2.srs.fleetmanager.spi.tenants.model.UpdateTenantRequest)1 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)1