Search in sources :

Example 51 with Status

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

the class StartDeprovisionRegistryWorker method execute.

@Transactional
@Override
public void execute(Task aTask, WorkerContext ctl) throws RegistryStorageConflictException {
    StartDeprovisionRegistryTask task = (StartDeprovisionRegistryTask) aTask;
    Optional<RegistryData> registryOptional = storage.getRegistryById(task.getRegistryId());
    if (registryOptional.isPresent()) {
        // FAILURE POINT 1
        var registry = registryOptional.get();
        var force = Instant.now().isAfter(registry.getCreatedAt().plus(props.getDeprovisionStuckInstanceTimeout()));
        if (force) {
            log.warn("Registry instance '{}' is forced to be deprovisioned.", registry);
        }
        var deprovision = force;
        var status = RegistryStatusValueDto.of(registry.getStatus());
        switch(status) {
            case ACCEPTED:
            case PROVISIONING:
                if (!force) {
                    log.debug("Provisioning in progress. Retrying.");
                    ctl.retry();
                }
                break;
            case READY:
            case FAILED:
                deprovision = true;
                break;
            case REQUESTED_DEPROVISIONING:
            case DEPROVISIONING_DELETING:
                if (!force) {
                    log.debug("Deprovisioning is already in progress. Stopping. Registry = {}", registry);
                    ctl.stop();
                }
                break;
            default:
                throw new IllegalStateException("Unexpected status value: " + status);
        }
        if (deprovision) {
            registry.setStatus(RegistryStatusValueDto.DEPROVISIONING_DELETING.value());
            // FAILURE POINT 2
            storage.createOrUpdateRegistry(registry);
            ctl.delay(() -> tasks.submit(DeprovisionRegistryTask.builder().registryId(registry.getId()).build()));
        }
    } else {
        log.warn("Registry id='{}' not found. Stopping.", task.getRegistryId());
        ctl.stop();
    }
}
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)

Example 52 with Status

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

the class RegistryServiceImpl method getRegistries.

@Override
public RegistryListDto getRegistries(Integer page, Integer size, String orderBy, String search) {
    // Defaults
    var sort = Sort.by("id", Sort.Direction.Ascending);
    page = (page != null) ? page : 1;
    size = (size != null) ? size : 10;
    if (orderBy != null) {
        var order = orderBy.split(" ");
        if (order.length != 2) {
            throw new ValidationException("invalid orderBy");
        }
        if ("asc".equals(order[1])) {
            sort = Sort.by(order[0], Sort.Direction.Ascending);
        } else {
            sort = Sort.by(order[0], Sort.Direction.Descending);
        }
    }
    List<Pair<String, Object>> conditions = new ArrayList<>();
    if (search != null && !search.isEmpty()) {
        var basicQuery = new BasicQuery(search, Arrays.asList("name", "status"));
        conditions.add(Pair.of(basicQuery.getColumn(), basicQuery.getArgument()));
    }
    // list only registries from your organization or the ones the user owns
    if (isResolvable(securityIdentity)) {
        final AccountInfo accountInfo = authService.extractAccountInfo();
        String orgId = accountInfo.getOrganizationId();
        if (orgId != null) {
            conditions.add(Pair.of("orgId", orgId));
        } else {
            conditions.add(Pair.of("ownerId", accountInfo.getAccountId()));
        }
    } else {
        conditions.add(Pair.of("ownerId", OWNER_ID_PLACEHOLDER));
    }
    var query = new SearchQuery(conditions);
    PanacheQuery<RegistryData> itemsQuery = storage.executeRegistrySearchQuery(query, sort);
    var items = itemsQuery.page(Page.of(page - 1, size)).stream().map(convertRegistry::convert).collect(Collectors.toList());
    return RegistryListDto.builder().items(items).page(page).size(size).total(itemsQuery.count()).build();
}
Also used : SearchQuery(org.bf2.srs.fleetmanager.util.SearchQuery) ValidationException(javax.validation.ValidationException) BasicQuery(org.bf2.srs.fleetmanager.util.BasicQuery) ArrayList(java.util.ArrayList) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) AccountInfo(org.bf2.srs.fleetmanager.spi.common.model.AccountInfo) Pair(org.apache.commons.lang3.tuple.Pair)

Example 53 with Status

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

the class ConnectorStatusExtractor method extract.

public static ConnectorDeploymentStatus extract(ManagedConnector connector) {
    ConnectorDeploymentStatus status = new ConnectorDeploymentStatus();
    DeploymentSpec deployment = connector.getSpec().getDeployment();
    if (connector.getStatus() != null && connector.getStatus().getPhase() != null) {
        deployment = connector.getStatus().getDeployment();
    }
    status.setResourceVersion(deployment.getDeploymentResourceVersion());
    if (connector.getSpec().getOperatorSelector() == null || connector.getSpec().getOperatorSelector().getId() == null) {
        status.setPhase(STATE_FAILED);
        status.addConditionsItem(new MetaV1Condition().type(Conditions.TYPE_READY).status(Conditions.STATUS_FALSE).message("No assignable operator").reason(Conditions.NO_ASSIGNABLE_OPERATOR_REASON).lastTransitionTime(Conditions.now()));
        return status;
    }
    if (connector.getStatus() != null && connector.getStatus().getConnectorStatus() != null) {
        status.setOperators(new ConnectorDeploymentStatusOperators().assigned(toConnectorOperator(connector.getStatus().getConnectorStatus().getAssignedOperator())).available(toConnectorOperator(connector.getStatus().getConnectorStatus().getAvailableOperator())));
        if (connector.getStatus().getConnectorStatus() != null) {
            if (connector.getStatus().getConnectorStatus().getPhase() != null) {
                status.setPhase(connector.getStatus().getConnectorStatus().getPhase());
            }
            if (connector.getStatus().getConnectorStatus().getConditions() != null) {
                for (var cond : connector.getStatus().getConnectorStatus().getConditions()) {
                    status.addConditionsItem(toMetaV1Condition(cond));
                }
            }
        }
    }
    if (status.getPhase() == null) {
        if (DESIRED_STATE_DELETED.equals(deployment.getDesiredState())) {
            status.setPhase(STATE_DE_PROVISIONING);
        } else if (DESIRED_STATE_STOPPED.equals(deployment.getDesiredState())) {
            status.setPhase(STATE_DE_PROVISIONING);
        } else {
            status.setPhase(STATE_PROVISIONING);
        }
    }
    return status;
}
Also used : DeploymentSpec(org.bf2.cos.fleetshard.api.DeploymentSpec) ConnectorDeploymentStatusOperators(org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatusOperators) MetaV1Condition(org.bf2.cos.fleet.manager.model.MetaV1Condition) ConnectorDeploymentStatus(org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)

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