use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class ProvisionRegistryTenantWorker method execute.
@Transactional
@Override
public void execute(Task aTask, WorkerContext ctl) throws RegistryStorageConflictException, TenantManagerServiceException {
// TODO Split along failure points?
ProvisionRegistryTenantTask task = (ProvisionRegistryTenantTask) aTask;
Optional<RegistryData> registryOptional = storage.getRegistryById(task.getRegistryId());
// NOTE: Failure point 1
if (registryOptional.isEmpty()) {
ctl.retry();
}
RegistryData registry = registryOptional.get();
RegistryDeploymentData registryDeployment = registry.getRegistryDeployment();
// NOTE: Failure point 2
if (registryDeployment == null) {
// Either the schedule task didn't run yet, or we are in trouble
ctl.retry();
}
String registryUrl = registryDeployment.getRegistryDeploymentUrl();
// New approach: configure the deployment URL with a replacement like: https://TENANT_ID.shrd.sr.openshift.com
if (registryUrl.contains("TENANT_ID")) {
registryUrl = registryUrl.replace("TENANT_ID", registry.getId());
} else {
// Old approach: configure the deployment URL without a replacement, and just add "/t/TENANT_ID" to the end of it.
if (!registryUrl.endsWith("/")) {
registryUrl += "/";
}
registryUrl += "t/" + registry.getId();
}
registry.setRegistryUrl(registryUrl);
// Avoid accidentally creating orphan tenants
if (task.getRegistryTenantId() == null) {
CreateTenantRequest tenantRequest = CreateTenantRequest.builder().tenantId(registry.getId()).createdBy(registry.getOwner()).organizationId(registry.getOrgId()).resources(plansService.determineQuotaPlan(registry.getOrgId()).getResources()).build();
TenantManagerConfig tenantManager = Utils.createTenantManagerConfig(registryDeployment);
// NOTE: Failure point 4
tmClient.createTenant(tenantManager, tenantRequest);
task.setRegistryTenantId(registry.getId());
}
// Add expiration task if this is an eval instance
if (isEvalInstance(registry.getInstanceType())) {
var expiration = Instant.now().plus(Duration.ofSeconds(evalLifetimeSeconds));
log.debug("Scheduling an expiration task for the eval instance {} to be executed at {}", registry, expiration);
ctl.delay(() -> tasks.submit(EvalInstanceExpirationRegistryTask.builder().registryId(registry.getId()).schedule(TaskSchedule.builder().firstExecuteAt(expiration).build()).build()));
}
// NOTE: Failure point 5
registry.setStatus(RegistryStatusValueDto.READY.value());
storage.createOrUpdateRegistry(registry);
// TODO This task is (temporarily) not used. Enable when needed.
// Update status to available in the heartbeat task, which should run ASAP
// ctl.delay(() -> tasks.submit(RegistryHeartbeatTask.builder().registryId(registry.getId()).build()));
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RegistryServiceImpl method getServiceStatus.
@Override
public ServiceStatusDto getServiceStatus() {
long total = storage.getRegistryCountTotal();
ServiceStatusDto status = new ServiceStatusDto();
status.setMaxInstancesReached(total >= maxInstances);
return status;
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class Convert method convert.
public ServiceStatus convert(ServiceStatusDto status) {
ServiceStatus res = new ServiceStatus();
res.setMaxInstancesReached(status.isMaxInstancesReached());
return res;
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status 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.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class DebeziumOperandControllerTest method computeStatus.
@ParameterizedTest
@MethodSource
void computeStatus(String connectorState, String conditionType, String conditionReason, String expectedConnectorState) {
ConnectorStatusSpec status = new ConnectorStatusSpec();
DebeziumOperandSupport.computeStatus(status, new KafkaConnectorBuilder().withStatus(new KafkaConnectorStatusBuilder().addToConditions(new ConditionBuilder().withType(conditionType).withReason(conditionReason).build()).addToConnectorStatus("connector", new org.bf2.cos.fleetshard.operator.debezium.model.KafkaConnectorStatusBuilder().withState(connectorState).build()).build()).build());
assertThat(status.getPhase()).isEqualTo(expectedConnectorState);
assertThat(status.getConditions()).anySatisfy(condition -> {
assertThat(condition).hasFieldOrPropertyWithValue("type", conditionType).hasFieldOrPropertyWithValue("reason", conditionReason);
});
}
Aggregations