Search in sources :

Example 6 with Operators

use of org.bf2.cos.fleetshard.support.resources.Operators in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorController method handleMonitor.

private UpdateControl<ManagedConnector> handleMonitor(ManagedConnector connector) {
    operandController.status(connector);
    // 
    // Search for newly installed ManagedOperators
    // 
    final List<Operator> operators = fleetShard.lookupOperators();
    final Operator assignedOperator = connector.getStatus().getConnectorStatus().getAssignedOperator();
    final Operator availableOperator = connector.getStatus().getConnectorStatus().getAvailableOperator();
    final Optional<Operator> selected = available(connector.getSpec().getOperatorSelector(), operators);
    if (selected.isPresent()) {
        Operator selectedInstance = selected.get();
        // if the selected operator does match the operator preciously selected
        if (!Objects.equals(selectedInstance, availableOperator) && !Objects.equals(selectedInstance, assignedOperator)) {
            // and it is not the currently assigned one
            LOGGER.info("deployment (upd): {} -> from:{}, to: {}", connector.getSpec().getDeployment(), assignedOperator, selectedInstance);
            // then we can signal that an upgrade is possible
            connector.getStatus().getConnectorStatus().setAvailableOperator(selectedInstance);
        }
    } else {
        connector.getStatus().getConnectorStatus().setAvailableOperator(new Operator());
    }
    return UpdateControl.updateStatus(connector);
}
Also used : ManagedConnectorOperator(org.bf2.cos.fleetshard.api.ManagedConnectorOperator) Operator(org.bf2.cos.fleetshard.api.Operator)

Example 7 with Operators

use of org.bf2.cos.fleetshard.support.resources.Operators in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class OperatorSelectorUtil method available.

public static Optional<Operator> available(OperatorSelector selector, Collection<Operator> operators) {
    if (operators == null) {
        return Optional.empty();
    }
    if (operators.isEmpty()) {
        return Optional.empty();
    }
    final VersionRange range = new VersionRange(selector.getVersion());
    final Comparator<Operator> cmp = Comparator.comparing(o -> new Version(o.getVersion()));
    return operators.stream().filter(o -> Objects.equals(o.getType(), selector.getType())).filter(o -> versionInRange(range, o)).max(cmp);
}
Also used : Operator(org.bf2.cos.fleetshard.api.Operator) Objects(java.util.Objects) Logger(org.slf4j.Logger) Collection(java.util.Collection) Version(org.bf2.cos.fleetshard.api.Version) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) VersionRange(org.bf2.cos.fleetshard.api.VersionRange) Operator(org.bf2.cos.fleetshard.api.Operator) Comparator(java.util.Comparator) OperatorSelector(org.bf2.cos.fleetshard.api.OperatorSelector) Version(org.bf2.cos.fleetshard.api.Version) VersionRange(org.bf2.cos.fleetshard.api.VersionRange)

Example 8 with Operators

use of org.bf2.cos.fleetshard.support.resources.Operators in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorDeploymentProvisioner method createManagedConnector.

private ManagedConnector createManagedConnector(String uow, ConnectorDeployment deployment, HasMetadata owner) {
    ManagedConnector connector = fleetShard.getConnector(deployment).orElseGet(() -> {
        LOGGER.info("Connector not found (cluster_id: {}, connector_id: {}, deployment_id: {}, resource_version: {}), creating a new one", fleetShard.getClusterId(), deployment.getSpec().getConnectorId(), deployment.getId(), deployment.getMetadata().getResourceVersion());
        return Connectors.newConnector(fleetShard.getClusterId(), deployment.getSpec().getConnectorId(), deployment.getId(), Map.of());
    });
    // TODO: change APIs to include a single operator
    // move operator one level up
    // include full operator info in ConnectorDeployment APIs
    ArrayNode operatorsMeta = deployment.getSpec().getShardMetadata().withArray("operators");
    if (operatorsMeta.size() != 1) {
        throw new IllegalArgumentException("Multiple selectors are not yet supported");
    }
    OperatorSelector operatorSelector = new OperatorSelector(deployment.getSpec().getOperatorId(), operatorsMeta.get(0).requiredAt("/type").asText(), operatorsMeta.get(0).requiredAt("/version").asText());
    if (operatorSelector.getId() == null) {
        final OperatorSelector currentSelector = connector.getSpec().getOperatorSelector();
        // don't select a new operator if previously set.
        if (currentSelector != null && currentSelector.getId() != null) {
            operatorSelector.setId(currentSelector.getId());
        } else {
            OperatorSelectorUtil.assign(operatorSelector, fleetShard.lookupOperators()).map(Operator::getId).ifPresent(operatorSelector::setId);
        }
    }
    if (operatorSelector.getId() != null) {
        Resources.setLabel(connector, Resources.LABEL_OPERATOR_ASSIGNED, operatorSelector.getId());
    }
    if (operatorSelector.getType() != null) {
        Resources.setLabel(connector, Resources.LABEL_OPERATOR_TYPE, operatorSelector.getType());
    }
    if (config != null) {
        config.connectors().labels().forEach((k, v) -> {
            Resources.setLabel(connector, k, v);
        });
        config.connectors().annotations().forEach((k, v) -> {
            Resources.setAnnotation(connector, k, v);
        });
    }
    connector.getMetadata().setOwnerReferences(List.of(new OwnerReferenceBuilder().withApiVersion(owner.getApiVersion()).withKind(owner.getKind()).withName(owner.getMetadata().getName()).withUid(owner.getMetadata().getUid()).withBlockOwnerDeletion(true).build()));
    // add resource version to label
    Resources.setLabel(connector, Resources.LABEL_DEPLOYMENT_RESOURCE_VERSION, "" + deployment.getMetadata().getResourceVersion());
    // add uow
    Resources.setLabel(connector, Resources.LABEL_UOW, uow);
    connector.getSpec().getDeployment().setDeploymentResourceVersion(deployment.getMetadata().getResourceVersion());
    connector.getSpec().getDeployment().setDesiredState(deployment.getSpec().getDesiredState());
    connector.getSpec().getDeployment().setConnectorTypeId(deployment.getSpec().getConnectorTypeId());
    connector.getSpec().getDeployment().setConnectorResourceVersion(deployment.getSpec().getConnectorResourceVersion());
    KafkaConnectionSettings kafkaConnectionSettings = deployment.getSpec().getKafka();
    if (kafkaConnectionSettings != null) {
        connector.getSpec().getDeployment().setKafka(new KafkaSpecBuilder().withId(kafkaConnectionSettings.getId()).withUrl(kafkaConnectionSettings.getUrl()).build());
    }
    SchemaRegistryConnectionSettings schemaRegistryConnectionSettings = deployment.getSpec().getSchemaRegistry();
    if (schemaRegistryConnectionSettings != null) {
        connector.getSpec().getDeployment().setSchemaRegistry(new SchemaRegistrySpecBuilder().withId(schemaRegistryConnectionSettings.getId()).withUrl(schemaRegistryConnectionSettings.getUrl()).build());
    }
    connector.getSpec().getDeployment().setConnectorResourceVersion(deployment.getSpec().getConnectorResourceVersion());
    connector.getSpec().getDeployment().setSecret(Secrets.generateConnectorSecretId(deployment.getId()));
    connector.getSpec().getDeployment().setUnitOfWork(uow);
    connector.getSpec().setOperatorSelector(operatorSelector);
    LOGGER.info("Provisioning connector id={} rv={} - {}/{}: {}", connector.getMetadata().getName(), connector.getSpec().getDeployment().getDeploymentResourceVersion(), fleetShard.getConnectorsNamespace(), connector.getSpec().getConnectorId(), Serialization.asJson(connector.getSpec()));
    try {
        return fleetShard.createConnector(connector);
    } catch (Exception e) {
        LOGGER.warn("", e);
        throw e;
    }
}
Also used : OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) KafkaSpecBuilder(org.bf2.cos.fleetshard.api.KafkaSpecBuilder) SchemaRegistryConnectionSettings(org.bf2.cos.fleet.manager.model.SchemaRegistryConnectionSettings) SchemaRegistrySpecBuilder(org.bf2.cos.fleetshard.api.SchemaRegistrySpecBuilder) ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) OperatorSelector(org.bf2.cos.fleetshard.api.OperatorSelector) KafkaConnectionSettings(org.bf2.cos.fleet.manager.model.KafkaConnectionSettings)

Aggregations

ManagedConnector (org.bf2.cos.fleetshard.api.ManagedConnector)5 Secret (io.fabric8.kubernetes.api.model.Secret)4 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)4 ConnectorDeployment (org.bf2.cos.fleet.manager.model.ConnectorDeployment)4 Operator (org.bf2.cos.fleetshard.api.Operator)3 OperatorSelector (org.bf2.cos.fleetshard.api.OperatorSelector)3 FleetShardSyncConfig (org.bf2.cos.fleetshard.sync.FleetShardSyncConfig)3 FleetManagerClient (org.bf2.cos.fleetshard.sync.client.FleetManagerClient)3 FleetShardClient (org.bf2.cos.fleetshard.sync.client.FleetShardClient)3 ConnectorDeploymentProvisioner (org.bf2.cos.fleetshard.sync.resources.ConnectorDeploymentProvisioner)3 Test (org.junit.jupiter.api.Test)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)2 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 Collection (java.util.Collection)2 KafkaConnectionSettings (org.bf2.cos.fleet.manager.model.KafkaConnectionSettings)2 SchemaRegistryConnectionSettings (org.bf2.cos.fleet.manager.model.SchemaRegistryConnectionSettings)2 ManagedConnectorBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorBuilder)2 Logger (org.slf4j.Logger)2