Search in sources :

Example 11 with Registry

use of org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class Convert method convert.

public Registry convert(RegistryDto data) {
    Registry res = new Registry();
    res.setId(data.getId());
    res.setKind(data.getKind());
    res.setHref(data.getHref());
    res.setRegistryUrl(data.getRegistryUrl());
    res.setName(data.getName());
    res.setRegistryDeploymentId(Optional.ofNullable(data.getRegistryDeploymentId()).map(Long::intValue).orElse(// TODO Conversion
    null));
    res.setStatus(convert(data.getStatus()));
    res.setOwner(data.getOwner());
    res.setCreatedAt(convert(data.getCreatedAt()));
    res.setUpdatedAt(convert(data.getUpdatedAt()));
    res.setDescription(data.getDescription());
    res.setInstanceType(convert(data.getInstanceType()));
    res.setBrowserUrl(browserUrl.replace("TENANT_ID", res.getId()));
    return res;
}
Also used : Registry(org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry)

Example 12 with Registry

use of org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class PanacheResourceStorage method createOrUpdateRegistry.

@Override
public boolean createOrUpdateRegistry(RegistryData registry) throws RegistryStorageConflictException {
    requireNonNull(registry);
    Optional<RegistryData> existing = empty();
    if (registry.getId() != null) {
        // TODO investigate using locks, such as optimistic locks
        existing = registryRepository.findByIdOptional(registry.getId());
    }
    try {
        final Instant now = Instant.now();
        if (existing.isEmpty()) {
            registry.setCreatedAt(now);
        }
        registry.setUpdatedAt(now);
        registryRepository.persistAndFlush(registry);
    } catch (PersistenceException ex) {
        if (ex.getCause() instanceof ConstraintViolationException) {
            throw new RegistryStorageConflictException();
        } else {
            throw ex;
        }
    }
    return existing.isEmpty();
}
Also used : Instant(java.time.Instant) PersistenceException(javax.persistence.PersistenceException) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) RegistryStorageConflictException(org.bf2.srs.fleetmanager.storage.RegistryStorageConflictException)

Example 13 with Registry

use of org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry 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 14 with Registry

use of org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class MetricsRecorder method recordCallable.

public <T> T recordCallable(Callable<T> action, String subId, Iterable<Tag> additionalTags) {
    try {
        var answer = Timer.builder(id + subId + ".time").tags(tags).tags(additionalTags).publishPercentiles(0.3, 0.5, 0.95).publishPercentileHistogram().register(registry).recordCallable(action);
        Counter.builder(id + subId + ".count").tags(tags).tags(additionalTags).register(registry).increment();
        return answer;
    } catch (Exception e) {
        Counter.builder(id + subId + ".count.failure").tags(tags).tags(additionalTags).tag("exception", e.getClass().getName()).register(registry).increment();
        throw new WrappedRuntimeException("Failure recording method execution (id: " + id + subId + ")", e);
    }
}
Also used : WrappedRuntimeException(org.bf2.cos.fleetshard.support.exceptions.WrappedRuntimeException) WrappedRuntimeException(org.bf2.cos.fleetshard.support.exceptions.WrappedRuntimeException)

Example 15 with Registry

use of org.bf2.srs.fleetmanager.rest.publicapi.beans.Registry in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorStatusSync method sync.

private void sync() {
    int count = 0;
    try {
        for (ManagedConnector connector : connectorClient.getAllConnectors()) {
            updater.update(connector);
            count++;
        }
    } finally {
        if (count > 0) {
            Counter.builder(config.metrics().baseName() + "." + METRICS_SYNC + ".total").register(registry).increment(count);
        }
    }
}
Also used : ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector)

Aggregations

RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)13 Transactional (javax.transaction.Transactional)8 Test (org.junit.jupiter.api.Test)7 AccountInfo (org.bf2.srs.fleetmanager.spi.common.model.AccountInfo)6 TenantNotFoundServiceException (org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException)5 RegistryDeploymentData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData)5 Secret (io.fabric8.kubernetes.api.model.Secret)4 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)4 ManagedConnector (org.bf2.cos.fleetshard.api.ManagedConnector)4 TenantManagerClient (io.apicurio.multitenant.client.TenantManagerClient)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Optional (java.util.Optional)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)3 Inject (javax.inject.Inject)3 ConnectorDeployment (org.bf2.cos.fleet.manager.model.ConnectorDeployment)3 FleetShardSyncConfig (org.bf2.cos.fleetshard.sync.FleetShardSyncConfig)3 FleetManagerClient (org.bf2.cos.fleetshard.sync.client.FleetManagerClient)3 FleetShardClient (org.bf2.cos.fleetshard.sync.client.FleetShardClient)3