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;
}
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();
}
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());
}
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);
}
}
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);
}
}
}
Aggregations