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;
}
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");
});
}
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);
}
}
}
Aggregations