Search in sources :

Example 6 with Connectors

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

the class ConnectorTestSupport method fleetShard.

public static FleetShardClient fleetShard(String clusterId, Collection<ManagedConnector> connectors, Collection<Secret> secrets) {
    Map<String, ManagedConnector> allConnectors = connectors.stream().collect(Collectors.toMap(e -> e.getMetadata().getName(), Function.identity()));
    Map<String, Secret> allSecrets = secrets.stream().collect(Collectors.toMap(e -> e.getMetadata().getName(), Function.identity()));
    FleetShardClient answer = Mockito.mock(FleetShardClient.class);
    when(answer.getClusterId()).thenAnswer(invocation -> clusterId);
    when(answer.getConnector(any(ConnectorDeployment.class))).thenAnswer(invocation -> {
        return lookupConnector(allConnectors.values(), clusterId, invocation.getArgument(0));
    });
    when(answer.getSecret(any(ConnectorDeployment.class))).thenAnswer(invocation -> {
        return lookupSecret(allSecrets.values(), clusterId, invocation.getArgument(0));
    });
    when(answer.createConnector(any(ManagedConnector.class))).thenAnswer(invocation -> {
        var arg = invocation.getArgument(0, ManagedConnector.class);
        allConnectors.put(arg.getMetadata().getName(), arg);
        return arg;
    });
    when(answer.createSecret(any(Secret.class))).thenAnswer(invocation -> {
        var arg = invocation.getArgument(0, Secret.class);
        allSecrets.put(arg.getMetadata().getName(), arg);
        return arg;
    });
    when(answer.getOrCreateManagedConnectorCluster()).thenAnswer(invocation -> {
        return new ManagedConnectorClusterBuilder().withMetadata(new ObjectMetaBuilder().withName(Clusters.CONNECTOR_CLUSTER_PREFIX + "-" + clusterId).addToLabels(Resources.LABEL_CLUSTER_ID, clusterId).build()).withSpec(new ManagedConnectorClusterSpecBuilder().withClusterId(clusterId).build()).build();
    });
    return answer;
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ManagedConnectorClusterBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorClusterBuilder) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Connectors(org.bf2.cos.fleetshard.support.resources.Connectors) Secrets(org.bf2.cos.fleetshard.support.resources.Secrets) Secrets.toBase64(org.bf2.cos.fleetshard.support.resources.Secrets.toBase64) ConnectorDeploymentSpec(org.bf2.cos.fleet.manager.model.ConnectorDeploymentSpec) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Resources.uid(org.bf2.cos.fleetshard.support.resources.Resources.uid) Serialization(io.fabric8.kubernetes.client.utils.Serialization) Map(java.util.Map) FleetShardClient(org.bf2.cos.fleetshard.sync.client.FleetShardClient) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConnectorDeploymentAllOfMetadata(org.bf2.cos.fleet.manager.model.ConnectorDeploymentAllOfMetadata) ServiceAccount(org.bf2.cos.fleet.manager.model.ServiceAccount) ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) Clusters(org.bf2.cos.fleetshard.support.resources.Clusters) ConnectorDesiredState(org.bf2.cos.fleet.manager.model.ConnectorDesiredState) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) SchemaRegistryConnectionSettings(org.bf2.cos.fleet.manager.model.SchemaRegistryConnectionSettings) Collection(java.util.Collection) KafkaConnectionSettings(org.bf2.cos.fleet.manager.model.KafkaConnectionSettings) UUID(java.util.UUID) FleetShardSyncConfig(org.bf2.cos.fleetshard.sync.FleetShardSyncConfig) Mockito.when(org.mockito.Mockito.when) ConnectorDeployment(org.bf2.cos.fleet.manager.model.ConnectorDeployment) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) FleetManagerClient(org.bf2.cos.fleetshard.sync.client.FleetManagerClient) Optional(java.util.Optional) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) Secret(io.fabric8.kubernetes.api.model.Secret) ManagedConnectorCluster(org.bf2.cos.fleetshard.api.ManagedConnectorCluster) ManagedConnectorClusterSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorClusterSpecBuilder) Collections(java.util.Collections) Resources(org.bf2.cos.fleetshard.support.resources.Resources) Secret(io.fabric8.kubernetes.api.model.Secret) FleetShardClient(org.bf2.cos.fleetshard.sync.client.FleetShardClient) ConnectorDeployment(org.bf2.cos.fleet.manager.model.ConnectorDeployment) ManagedConnectorClusterBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorClusterBuilder) ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) ManagedConnectorClusterSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorClusterSpecBuilder)

Example 7 with Connectors

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

the class NamespaceProvisionerTest method nameIsSanitized.

@Test
void nameIsSanitized() {
    // 
    // Given that no resources associated to the provided deployment exist
    // 
    final ConnectorNamespace namespace = new ConnectorNamespace();
    namespace.id(uid());
    namespace.name("--eval");
    ConnectorNamespaceTenant tenant = new ConnectorNamespaceTenant().id(uid()).kind(ConnectorNamespaceTenantKind.ORGANISATION);
    namespace.setStatus(new ConnectorNamespaceStatus1().state(ConnectorNamespaceState.READY).connectorsDeployed(0));
    namespace.setTenant(tenant);
    namespace.setExpiration(new Date().toString());
    final List<ManagedConnector> connectors = List.of();
    final List<Secret> secrets = List.of();
    final FleetShardClient fleetShard = ConnectorTestSupport.fleetShard(CLUSTER_ID, connectors, secrets);
    final FleetManagerClient fleetManager = ConnectorTestSupport.fleetManagerClient();
    final FleetShardSyncConfig config = ConnectorTestSupport.config();
    final MeterRegistry registry = Mockito.mock(MeterRegistry.class);
    final ConnectorNamespaceProvisioner provisioner = new ConnectorNamespaceProvisioner(config, fleetShard, fleetManager, registry);
    final ArgumentCaptor<Namespace> nc = ArgumentCaptor.forClass(Namespace.class);
    // 
    // When deployment is applied
    // 
    provisioner.provision(namespace);
    verify(fleetShard).createNamespace(nc.capture());
    // 
    // Then resources must be created according to the deployment
    // 
    assertThat(nc.getValue()).satisfies(val -> {
        assertThat(val.getMetadata().getLabels()).containsEntry(LABEL_KUBERNETES_NAME, "a--eval");
    });
}
Also used : FleetShardClient(org.bf2.cos.fleetshard.sync.client.FleetShardClient) ConnectorNamespace(org.bf2.cos.fleet.manager.model.ConnectorNamespace) ConnectorNamespaceStatus1(org.bf2.cos.fleet.manager.model.ConnectorNamespaceStatus1) ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) ConnectorNamespaceProvisioner(org.bf2.cos.fleetshard.sync.resources.ConnectorNamespaceProvisioner) Date(java.util.Date) ConnectorNamespace(org.bf2.cos.fleet.manager.model.ConnectorNamespace) Namespace(io.fabric8.kubernetes.api.model.Namespace) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Secret(io.fabric8.kubernetes.api.model.Secret) FleetManagerClient(org.bf2.cos.fleetshard.sync.client.FleetManagerClient) FleetShardSyncConfig(org.bf2.cos.fleetshard.sync.FleetShardSyncConfig) ConnectorNamespaceTenant(org.bf2.cos.fleet.manager.model.ConnectorNamespaceTenant) Test(org.junit.jupiter.api.Test)

Example 8 with Connectors

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

the class ConnectorDeploymentSync method run.

private void run() {
    try {
        while (!executor.isShutdown()) {
            final long timeout = config.connectors().provisioner().queueTimeout().toMillis();
            queue.poll(timeout, TimeUnit.MILLISECONDS, deployments -> {
                LOGGER.debug("connectors to deploy: {}", deployments.size());
                for (ConnectorDeployment deployment : deployments) {
                    provisioner.provision(deployment);
                }
            });
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        LOGGER.debug("interrupted, message: {}", e.getMessage());
    } catch (Exception e) {
        LOGGER.debug("{}", e.getMessage(), e);
    } finally {
        if (!executor.isShutdown()) {
            future = executor.submit(this::run);
        }
    }
}
Also used : ConnectorDeployment(org.bf2.cos.fleet.manager.model.ConnectorDeployment)

Aggregations

FleetShardSyncConfig (org.bf2.cos.fleetshard.sync.FleetShardSyncConfig)7 ConnectorDeployment (org.bf2.cos.fleet.manager.model.ConnectorDeployment)6 ManagedConnector (org.bf2.cos.fleetshard.api.ManagedConnector)6 Secret (io.fabric8.kubernetes.api.model.Secret)5 FleetManagerClient (org.bf2.cos.fleetshard.sync.client.FleetManagerClient)5 FleetShardClient (org.bf2.cos.fleetshard.sync.client.FleetShardClient)5 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)3 ConnectorDeploymentProvisioner (org.bf2.cos.fleetshard.sync.resources.ConnectorDeploymentProvisioner)3 Test (org.junit.jupiter.api.Test)3 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 Serialization (io.fabric8.kubernetes.client.utils.Serialization)2 Collection (java.util.Collection)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 ConnectorNamespace (org.bf2.cos.fleet.manager.model.ConnectorNamespace)2 ManagedConnectorBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorBuilder)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1