Search in sources :

Example 11 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ControlPlaneTest method testManagedKafkaStatusComparison.

@Test
public void testManagedKafkaStatusComparison() {
    ManagedKafkaStatus status = null;
    assertFalse(ControlPlane.statusChanged(status, status));
    status = new ManagedKafkaStatus();
    assertFalse(ControlPlane.statusChanged(status, null));
    assertFalse(ControlPlane.statusChanged(status, status));
    assertTrue(ControlPlane.statusChanged(null, status));
    ManagedKafkaStatus newStatus = new ManagedKafkaStatusBuilder().withUpdatedTimestamp("2020-01-01").build();
    assertTrue(ControlPlane.statusChanged(status, newStatus));
    assertTrue(ControlPlane.statusChanged(newStatus, status));
    status.setConditions(new ArrayList<>());
    status.setUpdatedTimestamp("2021-01-01");
    assertTrue(ControlPlane.statusChanged(newStatus, status));
    newStatus.setUpdatedTimestamp("2022-01-01");
    assertTrue(ControlPlane.statusChanged(status, newStatus));
}
Also used : ManagedKafkaStatusBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder) ManagedKafkaStatus(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus) Test(org.junit.jupiter.api.Test)

Example 12 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class MockControlPlane method updateKafkaClustersStatus.

@Override
public void updateKafkaClustersStatus(@PathParam(value = "id") String id, Map<String, ManagedKafkaStatus> statusMap) {
    log.infof("control plane:: updateKafkaClustersStatus <- Received from cluster %s, %s", id, statusMap);
    // clean up the deleted
    statusMap.forEach((k, v) -> {
        log.infof("control plane:: Status of %s received", k);
        ManagedKafka mk = this.kafkas.get(k);
        if (mk != null) {
            if (mk.getSpec().isDeleted() && isDeleted(v)) {
                log.infof("control plane:: Removing cluster %s as it is deleted", mk.getId());
                this.kafkas.remove(k);
                this.kafkaStatus.remove(k);
            } else {
                this.kafkaStatus.put(k, v);
            }
        }
    });
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka)

Example 13 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class DeprovisionRegistryWorker method finallyExecute.

@Transactional
@Override
public void finallyExecute(Task aTask, WorkerContext ctl, Optional<Exception> error) throws RegistryNotFoundException, RegistryStorageConflictException {
    DeprovisionRegistryTask task = (DeprovisionRegistryTask) aTask;
    Optional<RegistryData> registry = storage.getRegistryById(task.getRegistryId());
    if (registry.isPresent()) {
        var reg = registry.get();
        // Failure - Could not delete tenant or update status
        // Try updating status to failed, otherwise user can retry.
        reg.setStatus(RegistryStatusValueDto.FAILED.value());
        // TODO Add failed_reason
        storage.createOrUpdateRegistry(reg);
        log.warn("Failed to deprovision Registry: {}", registry);
    } else {
        // SUCCESS
        log.debug("Registry (ID = {}) has been deleted.", task.getRegistryId());
    }
}
Also used : DeprovisionRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.DeprovisionRegistryTask) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) Transactional(javax.transaction.Transactional)

Example 14 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class DeprovisionRegistryWorker method execute.

@Transactional
@Override
public void execute(Task aTask, WorkerContext ctl) throws RegistryStorageConflictException, RegistryNotFoundException, AccountManagementServiceException, TenantManagerServiceException {
    var task = (DeprovisionRegistryTask) aTask;
    var registryOptional = storage.getRegistryById(task.getRegistryId());
    if (registryOptional.isPresent()) {
        // FAILURE POINT 1
        var registry = registryOptional.get();
        RegistryDeploymentData registryDeployment = registry.getRegistryDeployment();
        // FAILURE POINT 2
        if (task.getRegistryTenantId() == null) {
            final var tenantId = registry.getId();
            TenantManagerConfig tenantManagerConfig = Utils.createTenantManagerConfig(registryDeployment);
            try {
                tms.deleteTenant(tenantManagerConfig, tenantId);
                log.debug("Tenant id='{}' delete request send.", tenantId);
            } catch (TenantNotFoundServiceException ex) {
                log.info("Tenant id='{}' does not exist (already deleted?).", tenantId);
            }
            task.setRegistryTenantId(tenantId);
        }
        /* Return AMS entitlement
             * FAILURE POINT 3
             * Recovery: We recover by setting the registry status to failed so we don't lose information
             *   and the process can be initiated again.
             * Reentrancy: If the registry was already returned, (i.e. failed in #3)
             *   we need to continue without raising an error, otherwise we will keep retrying.
             */
        if (!task.isAmsSuccess()) {
            final String subscriptionId = registry.getSubscriptionId();
            // TODO Workaround: Remove this once we have RHOSRTrial working.
            if (subscriptionId != null && RegistryInstanceTypeValueDto.of(registry.getInstanceType()) != RegistryInstanceTypeValueDto.EVAL) {
                try {
                    ams.deleteSubscription(subscriptionId);
                } catch (SubscriptionNotFoundServiceException ex) {
                    log.info("Subscription ID '{}' for tenant ID '{}' does not exist (already deleted?).", subscriptionId, task.getRegistryTenantId());
                }
            } else {
                log.debug("Deleting an eval instance {} without calling AMS.", registry.getId());
            }
            task.setAmsSuccess(true);
            log.debug("Subscription (id='{}') for Registry (id='{}') deleted.", subscriptionId, registry.getId());
        }
        /* Delete the registry from DB
             * FAILURE POINT 4
             * Recovery: We set the status to failed so it can be retried.
             * Reentrancy: This is the last step, so nothing to do.
             */
        storage.deleteRegistry(registry.getId());
    } else {
        log.warn("Registry id='{}' not found. Stopping.", task.getRegistryId());
        ctl.stop();
    }
}
Also used : DeprovisionRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.DeprovisionRegistryTask) TenantNotFoundServiceException(org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException) SubscriptionNotFoundServiceException(org.bf2.srs.fleetmanager.spi.ams.SubscriptionNotFoundServiceException) RegistryDeploymentData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData) TenantManagerConfig(org.bf2.srs.fleetmanager.spi.tenants.model.TenantManagerConfig) Transactional(javax.transaction.Transactional)

Example 15 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class StartDeprovisionRegistryWorker method finallyExecute.

@Transactional
@Override
public void finallyExecute(Task aTask, WorkerContext ctl, Optional<Exception> error) throws RegistryNotFoundException, RegistryStorageConflictException {
    StartDeprovisionRegistryTask task = (StartDeprovisionRegistryTask) aTask;
    Optional<RegistryData> registryOptional = storage.getRegistryById(task.getRegistryId());
    if (registryOptional.isPresent()) {
        var registry = registryOptional.get();
        // SUCCESS STATE
        if (RegistryStatusValueDto.DEPROVISIONING_DELETING.value().equals(registry.getStatus()))
            return;
        // FAILURE
        // Nothing to do, user can retry
        log.warn("Failed to start deprovisioning of Registry '{}'. Check the status to see if the instance is stuck.", registry);
    } else {
        log.warn("Could not find Registry (ID = {}).", task.getRegistryId());
    }
}
Also used : StartDeprovisionRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.StartDeprovisionRegistryTask) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) Transactional(javax.transaction.Transactional)

Aggregations

Test (org.junit.jupiter.api.Test)14 ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)12 Objects (java.util.Objects)11 QuarkusTest (io.quarkus.test.junit.QuarkusTest)9 ManagedConnectorBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorBuilder)7 ManagedConnectorSpecBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder)7 Map (java.util.Map)6 Inject (javax.inject.Inject)6 OperatorSelectorBuilder (org.bf2.cos.fleetshard.api.OperatorSelectorBuilder)6 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)5 List (java.util.List)5 ConnectorDeploymentStatus (org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)5 Status (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status)5 Quantity (io.fabric8.kubernetes.api.model.Quantity)4 KafkaConnectorBuilder (io.strimzi.api.kafka.model.KafkaConnectorBuilder)4 Transactional (javax.transaction.Transactional)4 ManagedKafkaCondition (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition)4 ManagedKafkaStatus (org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus)4