Search in sources :

Example 1 with UpdateTenantRequest

use of org.bf2.srs.fleetmanager.spi.tenants.model.UpdateTenantRequest 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)

Aggregations

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 TenantLimit (org.bf2.srs.fleetmanager.spi.tenants.model.TenantLimit)1 UpdateTenantRequest (org.bf2.srs.fleetmanager.spi.tenants.model.UpdateTenantRequest)1 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)1