Search in sources :

Example 6 with Conditions

use of org.bf2.cos.fleetshard.api.Conditions in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorSteps method connector_has_conditions.

@Then("the connector has conditions:")
public void connector_has_conditions(DataTable table) {
    final List<Map<String, String>> rows = table.asMaps(String.class, String.class);
    final ManagedConnector connector = connector();
    assertThat(rows).allMatch(row -> hasCondition(connector, row));
}
Also used : ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) HashMap(java.util.HashMap) Map(java.util.Map) Then(io.cucumber.java.en.Then)

Example 7 with Conditions

use of org.bf2.cos.fleetshard.api.Conditions in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorStatusExtractorTest method extractFromConnectorStatus.

/*
     * Test that if the status sub resource is provided and the phase is
     * "monitor", then the status extractor compute the phase according
     * to the reported deployment status
     */
@ParameterizedTest
@MethodSource
void extractFromConnectorStatus(String statusDesiredState, String connectorPhase, ConnectorState expectedState, List<Condition> conditions) {
    var status = ConnectorStatusExtractor.extract(new ManagedConnectorBuilder().withSpec(new ManagedConnectorSpecBuilder().withOperatorSelector(new OperatorSelectorBuilder().withId("1").build()).build()).withStatus(new ManagedConnectorStatusBuilder().withPhase(ManagedConnectorStatus.PhaseType.Monitor).withDeployment(new DeploymentSpecBuilder().withDeploymentResourceVersion(1L).withDesiredState(statusDesiredState).build()).withConnectorStatus(new ConnectorStatusSpecBuilder().withPhase(connectorPhase).withConditions(conditions).build()).build()).build());
    var v1Conditions = conditions.stream().map(ConnectorStatusExtractor::toMetaV1Condition).collect(Collectors.toList());
    assertThat(status.getPhase()).isEqualTo(expectedState);
    assertThat(status.getConditions()).hasSameSizeAs(conditions).hasSameElementsAs(v1Conditions);
    assertThat(status.getResourceVersion()).isEqualTo(1L);
    assertThat(status).extracting(ConnectorDeploymentStatus::getOperators).extracting(ConnectorDeploymentStatusOperators::getAssigned).hasAllNullFieldsOrProperties();
    assertThat(status).extracting(ConnectorDeploymentStatus::getOperators).extracting(ConnectorDeploymentStatusOperators::getAvailable).hasAllNullFieldsOrProperties();
}
Also used : DeploymentSpecBuilder(org.bf2.cos.fleetshard.api.DeploymentSpecBuilder) ManagedConnectorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorBuilder) ManagedConnectorStatusBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorStatusBuilder) ManagedConnectorSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder) ConnectorStatusSpecBuilder(org.bf2.cos.fleetshard.api.ConnectorStatusSpecBuilder) ConnectorDeploymentStatus(org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus) OperatorSelectorBuilder(org.bf2.cos.fleetshard.api.OperatorSelectorBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with Conditions

use of org.bf2.cos.fleetshard.api.Conditions in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaController method updateManagedKafkaStatus.

/**
 * Extract from the current KafkaInstance overall status (Kafka, Canary and AdminServer)
 * a corresponding list of ManagedKafkaCondition(s) to set on the ManagedKafka status
 *
 * @param managedKafka ManagedKafka instance
 */
private void updateManagedKafkaStatus(ManagedKafka managedKafka) {
    // add status if not already available on the ManagedKafka resource
    ManagedKafkaStatus status = Objects.requireNonNullElse(managedKafka.getStatus(), new ManagedKafkaStatusBuilder().build());
    status.setUpdatedTimestamp(ConditionUtils.iso8601Now());
    managedKafka.setStatus(status);
    // add conditions if not already available
    List<ManagedKafkaCondition> managedKafkaConditions = managedKafka.getStatus().getConditions();
    if (managedKafkaConditions == null) {
        managedKafkaConditions = new ArrayList<>();
        status.setConditions(managedKafkaConditions);
    }
    Optional<ManagedKafkaCondition> optReady = ConditionUtils.findManagedKafkaCondition(managedKafkaConditions, ManagedKafkaCondition.Type.Ready);
    ManagedKafkaCondition ready = null;
    if (optReady.isPresent()) {
        ready = optReady.get();
    } else {
        ready = ConditionUtils.buildCondition(ManagedKafkaCondition.Type.Ready, Status.Unknown);
        managedKafkaConditions.add(ready);
    }
    // a not valid ManagedKafka skips the handling of it, so the status will report an error condition
    OperandReadiness readiness = this.validity(managedKafka).orElse(kafkaInstance.getReadiness(managedKafka));
    ConditionUtils.updateConditionStatus(ready, readiness.getStatus(), readiness.getReason(), readiness.getMessage());
    // routes should always be set on the CR status, even if it's just an empty list
    status.setRoutes(List.of());
    int replicas = kafkaCluster.getReplicas(managedKafka);
    if (ingressControllerManagerInstance.isResolvable()) {
        IngressControllerManager ingressControllerManager = ingressControllerManagerInstance.get();
        List<ManagedKafkaRoute> routes = ingressControllerManager.getManagedKafkaRoutesFor(managedKafka);
        // expect route for each broker + 1 for bootstrap URL + 1 for Admin API server
        int expectedNumRoutes = replicas + NUM_NON_BROKER_ROUTES;
        if (routes.size() >= expectedNumRoutes && routes.stream().noneMatch(r -> "".equals(r.getRouter()))) {
            status.setRoutes(routes);
        }
    }
    if (Status.True.equals(readiness.getStatus())) {
        status.setCapacity(new ManagedKafkaCapacityBuilder(managedKafka.getSpec().getCapacity()).withMaxDataRetentionSize(kafkaInstance.getKafkaCluster().calculateRetentionSize(managedKafka)).build());
        // the versions in the status are updated incrementally copying the spec only when each stage ends
        VersionsBuilder versionsBuilder = status.getVersions() != null ? new VersionsBuilder(status.getVersions()) : new VersionsBuilder(managedKafka.getSpec().getVersions());
        if (!Reason.StrimziUpdating.equals(readiness.getReason()) && !this.strimziManager.hasStrimziChanged(managedKafka)) {
            versionsBuilder.withStrimzi(managedKafka.getSpec().getVersions().getStrimzi());
        }
        if (!Reason.KafkaUpdating.equals(readiness.getReason()) && !this.kafkaManager.hasKafkaVersionChanged(managedKafka)) {
            versionsBuilder.withKafka(managedKafka.getSpec().getVersions().getKafka());
        }
        if (!Reason.KafkaIbpUpdating.equals(readiness.getReason()) && !this.kafkaManager.hasKafkaIbpVersionChanged(managedKafka)) {
            String kafkaIbp = managedKafka.getSpec().getVersions().getKafkaIbp() != null ? managedKafka.getSpec().getVersions().getKafkaIbp() : AbstractKafkaCluster.getKafkaIbpVersion(managedKafka.getSpec().getVersions().getKafka());
            versionsBuilder.withKafkaIbp(kafkaIbp);
        }
        status.setVersions(versionsBuilder.build());
        status.setAdminServerURI(kafkaInstance.getAdminServer().uri(managedKafka));
        status.setServiceAccounts(managedKafka.getSpec().getServiceAccounts());
    }
}
Also used : DeleteControl(io.javaoperatorsdk.operator.api.DeleteControl) ManagedKafkaResourceClient(org.bf2.common.ManagedKafkaResourceClient) Context(io.javaoperatorsdk.operator.api.Context) Status(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status) Timed(io.micrometer.core.annotation.Timed) StrimziVersionStatus(org.bf2.operator.resources.v1alpha1.StrimziVersionStatus) Logger(org.jboss.logging.Logger) StrimziManager(org.bf2.operator.managers.StrimziManager) ManagedKafkaRoute(org.bf2.operator.resources.v1alpha1.ManagedKafkaRoute) ResourceEventSource(org.bf2.operator.events.ResourceEventSource) ArrayList(java.util.ArrayList) Controller(io.javaoperatorsdk.operator.api.Controller) VersionsBuilder(org.bf2.operator.resources.v1alpha1.VersionsBuilder) Inject(javax.inject.Inject) KafkaInstance(org.bf2.operator.operands.KafkaInstance) ManagedKafkaStatus(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus) UpdateControl(io.javaoperatorsdk.operator.api.UpdateControl) AbstractKafkaCluster(org.bf2.operator.operands.AbstractKafkaCluster) KafkaManager(org.bf2.operator.managers.KafkaManager) Instance(javax.enterprise.inject.Instance) NDC(org.jboss.logging.NDC) KafkaInstanceConfiguration(org.bf2.operator.operands.KafkaInstanceConfiguration) ManagedKafkaStatusBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder) IngressControllerManager(org.bf2.operator.managers.IngressControllerManager) ConditionUtils(org.bf2.common.ConditionUtils) Reason(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Reason) Objects(java.util.Objects) List(java.util.List) Counted(io.micrometer.core.annotation.Counted) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) OperandReadiness(org.bf2.operator.operands.OperandReadiness) ManagedKafkaCapacityBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaCapacityBuilder) Optional(java.util.Optional) ResourceController(io.javaoperatorsdk.operator.api.ResourceController) EventSourceManager(io.javaoperatorsdk.operator.processing.event.EventSourceManager) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaCapacityBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaCapacityBuilder) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) VersionsBuilder(org.bf2.operator.resources.v1alpha1.VersionsBuilder) IngressControllerManager(org.bf2.operator.managers.IngressControllerManager) ManagedKafkaStatusBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder) ManagedKafkaRoute(org.bf2.operator.resources.v1alpha1.ManagedKafkaRoute) ManagedKafkaStatus(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus) OperandReadiness(org.bf2.operator.operands.OperandReadiness)

Example 9 with Conditions

use of org.bf2.cos.fleetshard.api.Conditions 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)

Aggregations

Namespace (io.fabric8.kubernetes.api.model.Namespace)2 Timed (io.micrometer.core.annotation.Timed)2 ArrayList (java.util.ArrayList)2 Objects (java.util.Objects)2 ConnectorDeploymentStatus (org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)2 ConnectorNamespace (org.bf2.cos.fleet.manager.model.ConnectorNamespace)2 ConnectorStatusSpecBuilder (org.bf2.cos.fleetshard.api.ConnectorStatusSpecBuilder)2 DeploymentSpecBuilder (org.bf2.cos.fleetshard.api.DeploymentSpecBuilder)2 ManagedConnectorBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorBuilder)2 ManagedConnectorSpecBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder)2 ManagedConnectorStatusBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorStatusBuilder)2 OperatorSelectorBuilder (org.bf2.cos.fleetshard.api.OperatorSelectorBuilder)2 ManagedKafkaCondition (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition)2 Then (io.cucumber.java.en.Then)1 Context (io.javaoperatorsdk.operator.api.Context)1 Controller (io.javaoperatorsdk.operator.api.Controller)1 DeleteControl (io.javaoperatorsdk.operator.api.DeleteControl)1 ResourceController (io.javaoperatorsdk.operator.api.ResourceController)1 UpdateControl (io.javaoperatorsdk.operator.api.UpdateControl)1 EventSourceManager (io.javaoperatorsdk.operator.processing.event.EventSourceManager)1