use of org.bf2.cos.fleetshard.operator.camel.CamelOperandConfiguration.Health in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class CamelOperandController method doReify.
@SuppressFBWarnings("HARD_CODE_PASSWORD")
@Override
protected List<HasMetadata> doReify(ManagedConnector connector, CamelShardMetadata shardMetadata, ConnectorConfiguration<ObjectNode, ObjectNode> connectorConfiguration, ServiceAccountSpec serviceAccountSpec) {
final Map<String, String> properties = createSecretsData(connector, connectorConfiguration, serviceAccountSpec, configuration);
final ObjectNode errorHandler = createErrorHandler(shardMetadata, connector, connectorConfiguration.getErrorHandlerSpec());
final List<KameletEndpoint> stepDefinitions;
final KameletEndpoint source;
final KameletEndpoint sink;
//
switch(shardMetadata.getConnectorType()) {
case CONNECTOR_TYPE_SOURCE:
source = KameletEndpoint.kamelet(shardMetadata.getKamelets().getAdapter().getName());
source.getProperties().put("id", connector.getSpec().getDeploymentId() + "-source");
configureKameletProperties(source.getProperties(), connectorConfiguration.getConnectorSpec(), shardMetadata.getKamelets().getAdapter());
sink = KameletEndpoint.kamelet(shardMetadata.getKamelets().getKafka().getName());
sink.getProperties().put("id", connector.getSpec().getDeploymentId() + "-sink");
sink.getProperties().put("bootstrapServers", connector.getSpec().getDeployment().getKafka().getUrl());
sink.getProperties().put("user", SA_CLIENT_ID_PLACEHOLDER);
sink.getProperties().put("password", SA_CLIENT_SECRET_PLACEHOLDER);
configureKameletProperties(sink.getProperties(), connectorConfiguration.getConnectorSpec(), shardMetadata.getKamelets().getKafka());
if (hasSchemaRegistry(connector)) {
sink.getProperties().put("registryUrl", connector.getSpec().getDeployment().getSchemaRegistry().getUrl());
}
stepDefinitions = createSteps(connector, connectorConfiguration, shardMetadata, sink);
break;
case CONNECTOR_TYPE_SINK:
source = KameletEndpoint.kamelet(shardMetadata.getKamelets().getKafka().getName());
source.getProperties().put("id", connector.getSpec().getDeploymentId() + "-source");
source.getProperties().put("consumerGroup", connector.getSpec().getDeploymentId());
source.getProperties().put("bootstrapServers", connector.getSpec().getDeployment().getKafka().getUrl());
source.getProperties().put("user", SA_CLIENT_ID_PLACEHOLDER);
source.getProperties().put("password", SA_CLIENT_SECRET_PLACEHOLDER);
configureKameletProperties(source.getProperties(), connectorConfiguration.getConnectorSpec(), shardMetadata.getKamelets().getKafka());
if (hasSchemaRegistry(connector)) {
source.getProperties().put("registryUrl", connector.getSpec().getDeployment().getSchemaRegistry().getUrl());
}
sink = KameletEndpoint.kamelet(shardMetadata.getKamelets().getAdapter().getName());
sink.getProperties().put("id", connector.getSpec().getDeploymentId() + "-sink");
configureKameletProperties(sink.getProperties(), connectorConfiguration.getConnectorSpec(), shardMetadata.getKamelets().getAdapter());
stepDefinitions = createSteps(connector, connectorConfiguration, shardMetadata, source);
break;
default:
throw new IllegalArgumentException("Unknown connector type: " + shardMetadata.getConnectorType());
}
final Secret secret = new Secret();
secret.setMetadata(new ObjectMeta());
secret.getMetadata().setName(connector.getMetadata().getName() + Resources.CONNECTOR_SECRET_SUFFIX);
secret.setData(Map.of(APPLICATION_PROPERTIES, asBytesBase64(properties)));
final ObjectNode integration = createIntegrationSpec(secret.getMetadata().getName(), configuration, Map.of("CONNECTOR_SECRET_NAME", secret.getMetadata().getName(), "CONNECTOR_SECRET_CHECKSUM", Secrets.computeChecksum(secret), "CONNECTOR_ID", connector.getSpec().getConnectorId(), "CONNECTOR_DEPLOYMENT_ID", connector.getSpec().getDeploymentId()));
final KameletBinding binding = new KameletBinding();
binding.setMetadata(new ObjectMeta());
binding.getMetadata().setName(connector.getMetadata().getName());
binding.getMetadata().setAnnotations(new TreeMap<>());
binding.setSpec(new KameletBindingSpec());
binding.getSpec().setSource(source);
binding.getSpec().setSink(sink);
binding.getSpec().setErrorHandler(errorHandler);
binding.getSpec().setSteps(stepDefinitions);
binding.getSpec().setIntegration(integration);
Map<String, String> annotations = binding.getMetadata().getAnnotations();
if (shardMetadata.getAnnotations() != null) {
annotations.putAll(shardMetadata.getAnnotations());
}
if (configuration.labelSelection().enabled()) {
Operator assigned = connector.getStatus().getConnectorStatus().getAssignedOperator();
if (assigned != null && assigned.getId() != null) {
annotations.putIfAbsent(KAMEL_OPERATOR_ID, assigned.getId());
}
}
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_CONTAINER_IMAGE, shardMetadata.getConnectorImage());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_KAMELETS_ENABLED, "false");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_JVM_ENABLED, "false");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_LOGGING_JSON, "false");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_OWNER_TARGET_LABELS, LABELS_TO_TRANSFER);
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_PROMETHEUS_ENABLED, "true");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_PROMETHEUS_POD_MONITOR, "false");
// health check annotations
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_ENABLED, "true");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_PROBE_ENABLED, "true");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_PROBE_ENABLED, "true");
CamelOperandConfiguration.Health health = configuration.health();
if (health != null) {
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_SUCCESS_THRESHOLD, health.readinessSuccessThreshold());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_FAILURE_THRESHOLD, health.readinessFailureThreshold());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_PERIOD, health.readinessPeriodSeconds());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_TIMEOUT, health.readinessTimeoutSeconds());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_SUCCESS_THRESHOLD, health.livenessSuccessThreshold());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_FAILURE_THRESHOLD, health.livenessFailureThreshold());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_PERIOD, health.livenessPeriodSeconds());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_TIMEOUT, health.livenessTimeoutSeconds());
}
if (configuration.connectors() != null) {
if (configuration.connectors().traits() != null) {
annotations.putAll(configuration.connectors().traits());
}
if (configuration.connectors().types() != null) {
final String typeId = connector.getSpec().getDeployment().getConnectorTypeId();
final CamelOperandConfiguration.ConnectorConfiguration typeConfig = configuration.connectors().types().get(typeId);
if (typeConfig != null && typeConfig.traits() != null) {
annotations.putAll(typeConfig.traits());
}
}
}
return List.of(secret, binding);
}
use of org.bf2.cos.fleetshard.operator.camel.CamelOperandConfiguration.Health in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class TestInfraManager method runFleetManager.
private void runFleetManager(Map<String, String> appEnv, String nameSuffix, int port) throws IOException {
appEnv.put("QUARKUS_HTTP_PORT", String.valueOf(port));
String path = getFleetManagerJarPath();
Exec executor = new Exec();
LOGGER.info("Starting srs-fleet-manager app from: {}", path);
CompletableFuture.supplyAsync(() -> {
try {
List<String> cmd = new ArrayList<>();
cmd.add("java");
cmd.addAll(Arrays.asList("-jar", path));
int timeout = executor.execute(cmd, appEnv);
return timeout == 0;
} catch (Exception e) {
LOGGER.error("Failed to start fleet manager (could not find runner JAR).", e);
System.exit(1);
return false;
}
}, runnable -> new Thread(runnable).start());
processes.add(new TestInfraProcess() {
@Override
public String getName() {
return "fleet-manager-" + nameSuffix;
}
@Override
public void close() throws Exception {
executor.stop();
}
@Override
public String getStdOut() {
return executor.stdOut();
}
@Override
public String getStdErr() {
return executor.stdErr();
}
@Override
public boolean isContainer() {
return false;
}
});
try {
Awaitility.await("fleet manager is reachable on port " + port).atMost(90, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(() -> HttpUtils.isReachable("localhost", port, "fleet manager"));
Awaitility.await("fleet manager is ready on port " + port).atMost(90, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(() -> HttpUtils.isReady("http://localhost:" + port, "/q/health/ready", false, "fleet manager"));
} catch (ConditionTimeoutException ex) {
for (String s : executor.stdOut().split("\n")) {
LOGGER.info("[STDOUT] {}", s);
}
for (String s : executor.stdErr().split("\n")) {
LOGGER.info("[STDERR] {}", s);
}
throw ex;
}
}
use of org.bf2.cos.fleetshard.operator.camel.CamelOperandConfiguration.Health in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class TestInfraManager method runTenantManager.
// TODO replace tenant manager with mock?
private void runTenantManager(boolean authEnabled) throws IOException {
Map<String, String> appEnv = new HashMap<>();
if (authEnabled) {
appEnv.put("AUTH_ENABLED", "true");
appEnv.put("KEYCLOAK_URL", getMandatoryEnvVar(MAS_SSO_URL));
appEnv.put("KEYCLOAK_REALM", getMandatoryEnvVar(MAS_SSO_REALM));
appEnv.put("KEYCLOAK_API_CLIENT_ID", getMandatoryEnvVar(MAS_SSO_CLIENT_ID));
}
String datasourceUrl = deployPostgresql("tenant-manager");
appEnv.put("DATASOURCE_URL", datasourceUrl);
appEnv.put("DATASOURCE_USERNAME", "postgres");
appEnv.put("DATASOURCE_PASSWORD", "postgres");
// registry is not deployed in purpose, it may still work
appEnv.put("REGISTRY_ROUTE_URL", "http://localhost:3888");
appEnv.put("LOG_LEVEL", "DEBUG");
String path = getTenantManagerJarPath();
LOGGER.info("Starting Tenant Manager app from: {}", path);
Exec executor = new Exec();
CompletableFuture.supplyAsync(() -> {
try {
List<String> cmd = new ArrayList<>();
cmd.add("java");
cmd.addAll(Arrays.asList("-jar", path));
int timeout = executor.execute(cmd, appEnv);
return timeout == 0;
} catch (Exception e) {
LOGGER.error("Failed to start tenant manager (could not find runner JAR).", e);
System.exit(1);
return false;
}
}, runnable -> new Thread(runnable).start());
processes.add(new TestInfraProcess() {
@Override
public String getName() {
return "tenant-manager";
}
@Override
public void close() throws Exception {
executor.stop();
}
@Override
public String getStdOut() {
return executor.stdOut();
}
@Override
public String getStdErr() {
return executor.stdErr();
}
@Override
public boolean isContainer() {
return false;
}
});
Awaitility.await("Tenant Manager is reachable").atMost(45, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(() -> HttpUtils.isReachable("localhost", 8585, "Tenant Manager"));
Awaitility.await("Tenant Manager is ready").atMost(45, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(() -> HttpUtils.isReady(this.tenantManagerUrl, "/q/health/ready", false, "Tenant Manager"));
}
use of org.bf2.cos.fleetshard.operator.camel.CamelOperandConfiguration.Health in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class CamelOperandController method doReify.
@Override
protected List<HasMetadata> doReify(ManagedConnector connector, CamelShardMetadata shardMetadata, ConnectorConfiguration<ObjectNode> connectorConfiguration, ServiceAccountSpec serviceAccountSpec) {
final Map<String, String> properties = createSecretsData(connector, shardMetadata, connectorConfiguration, serviceAccountSpec, configuration, new TreeMap<>());
final List<ProcessorKamelet> stepDefinitions = createSteps(connector, connectorConfiguration, shardMetadata, properties);
final String source;
final String sink;
switch(shardMetadata.getConnectorType()) {
case CONNECTOR_TYPE_SOURCE:
source = shardMetadata.getKamelets().getAdapter().getName();
sink = shardMetadata.getKamelets().getKafka().getName();
break;
case CONNECTOR_TYPE_SINK:
source = shardMetadata.getKamelets().getKafka().getName();
sink = shardMetadata.getKamelets().getAdapter().getName();
break;
default:
throw new IllegalArgumentException("Unknown connector type: " + shardMetadata.getConnectorType());
}
final Secret secret = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName(connector.getMetadata().getName() + Resources.CONNECTOR_SECRET_SUFFIX).build()).addToData(APPLICATION_PROPERTIES, asBytesBase64(properties)).build();
final KameletBinding binding = new KameletBindingBuilder().withMetadata(new ObjectMetaBuilder().withName(connector.getMetadata().getName()).build()).withSpec(new KameletBindingSpecBuilder().withIntegration(createIntegrationSpec(secret.getMetadata().getName(), configuration, Map.of("CONNECTOR_SECRET_NAME", secret.getMetadata().getName(), "CONNECTOR_SECRET_CHECKSUM", Secrets.computeChecksum(secret), "CONNECTOR_ID", connector.getSpec().getConnectorId(), "CONNECTOR_DEPLOYMENT_ID", connector.getSpec().getDeploymentId()))).withSource(KameletEndpoint.kamelet(source, Map.of("id", connector.getSpec().getDeploymentId() + "-source"))).withSink(KameletEndpoint.kamelet(sink, Map.of("id", connector.getSpec().getDeploymentId() + "-sink"))).withErrorHandler(createErrorHandler(connectorConfiguration.getErrorHandlerSpec())).withSteps(stepDefinitions.stream().map(s -> KameletEndpoint.kamelet(s.getTemplateId(), Map.of("id", s.getId()))).collect(Collectors.toList())).build()).build();
Map<String, String> annotations = KubernetesResourceUtil.getOrCreateAnnotations(binding);
if (shardMetadata.getAnnotations() != null) {
annotations.putAll(shardMetadata.getAnnotations());
}
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_CONTAINER_IMAGE, shardMetadata.getConnectorImage());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_KAMELETS_ENABLED, "false");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_JVM_ENABLED, "false");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_LOGGING_JSON, "false");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_OWNER_TARGET_LABELS, LABELS_TO_TRANSFER);
// health check annotations
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_ENABLED, "true");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_PROBE_ENABLED, "true");
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_PROBE_ENABLED, "true");
Health health = configuration.health();
if (health != null) {
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_SUCCESS_THRESHOLD, health.readinessSuccessThreshold());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_FAILURE_THRESHOLD, health.readinessFailureThreshold());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_PERIOD, health.readinessPeriodSeconds());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_TIMEOUT, health.readinessTimeoutSeconds());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_SUCCESS_THRESHOLD, health.livenessSuccessThreshold());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_FAILURE_THRESHOLD, health.livenessFailureThreshold());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_PERIOD, health.livenessPeriodSeconds());
annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_TIMEOUT, health.livenessTimeoutSeconds());
}
return List.of(secret, binding);
}
Aggregations