use of org.bf2.cos.fleetshard.api.OperatorSelectorBuilder 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, String 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();
}
use of org.bf2.cos.fleetshard.api.OperatorSelectorBuilder in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class ConnectorStatusUpdaterTest method statusIsUpdated.
@Test
void statusIsUpdated() {
final String clusterUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/" + config.cluster().id();
final String statusUrl = clusterUrl + "/deployments/" + DEPLOYMENT_ID + "/status";
final Condition condition = new Condition(null, uid(), null, uid(), uid(), uid());
final Operator operator = new Operator(uid(), "operator-type", "1.2.3");
final ManagedConnector connector = new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().withName(Connectors.generateConnectorId(DEPLOYMENT_ID)).withNamespace(ns).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).addToLabels(LABEL_CONNECTOR_ID, CONNECTOR_ID).addToLabels(LABEL_DEPLOYMENT_ID, DEPLOYMENT_ID).build()).withSpec(new ManagedConnectorSpecBuilder().withClusterId(config.cluster().id()).withConnectorId(CONNECTOR_ID).withDeploymentId(DEPLOYMENT_ID).withOperatorSelector(new OperatorSelectorBuilder().withId(operator.getId()).build()).build()).build();
kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).create(connector);
connector.getStatus().setConnectorStatus(new ConnectorStatusSpecBuilder().withPhase(DESIRED_STATE_READY).withConditions(condition).withAssignedOperator(operator).build());
kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).withName(connector.getMetadata().getName()).replaceStatus(connector);
untilAsserted(() -> {
server.verify(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(matchingJsonPath("$.operators.assigned[?(@.version == '" + operator.getVersion() + "')]")).withRequestBody(matchingJsonPath("$.operators.assigned[?(@.type == '" + operator.getType() + "')]")).withRequestBody(matchingJsonPath("$.operators.assigned[?(@.id == '" + operator.getId() + "')]")).withRequestBody(matchingJsonPath("$[?($.phase == 'ready')]")));
});
}
use of org.bf2.cos.fleetshard.api.OperatorSelectorBuilder in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class ConnectorDeletedTest method statusIsUpdated.
@Test
void statusIsUpdated() {
final String clusterUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/" + config.cluster().id();
final String statusUrl = clusterUrl + "/deployments/" + DEPLOYMENT_ID + "/status";
final Condition condition = new Condition(null, uid(), null, uid(), uid(), uid());
final Operator operator = new Operator(uid(), "operator-type", "1.2.3");
final ManagedConnector connector = new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().withName(Connectors.generateConnectorId(DEPLOYMENT_ID)).withNamespace(ns).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).addToLabels(LABEL_CONNECTOR_ID, CONNECTOR_ID).addToLabels(LABEL_DEPLOYMENT_ID, DEPLOYMENT_ID).build()).withSpec(new ManagedConnectorSpecBuilder().withClusterId(config.cluster().id()).withConnectorId(CONNECTOR_ID).withDeploymentId(DEPLOYMENT_ID).withOperatorSelector(new OperatorSelectorBuilder().withId(operator.getId()).build()).build()).build();
kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).create(connector);
connector.getStatus().setConnectorStatus(new ConnectorStatusSpecBuilder().withPhase(DESIRED_STATE_READY).withConditions(condition).withAssignedOperator(operator).build());
kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).withName(connector.getMetadata().getName()).replaceStatus(connector);
untilAsserted(() -> {
server.verify(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(matchingJsonPath("$[?($.phase == 'ready')]")));
});
connector.getStatus().setConnectorStatus(new ConnectorStatusSpecBuilder().withPhase(DESIRED_STATE_DELETED).withConditions(condition).withAssignedOperator(operator).build());
kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).withName(connector.getMetadata().getName()).replaceStatus(connector);
untilAsserted(() -> {
server.verify(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(matchingJsonPath("$[?($.phase == 'deleted')]")));
});
untilAsserted(() -> {
assertThat(kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).withName(connector.getMetadata().getName()).get()).isNull();
});
}
use of org.bf2.cos.fleetshard.api.OperatorSelectorBuilder in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class ConnectorSteps method a_connector.
@Given("^a Connector with:$")
public void a_connector(Map<String, String> options) {
Map<String, String> entry = ctx.resolvePlaceholders(options);
final Long drv = Long.parseLong(entry.getOrDefault(ConnectorContext.COS_DEPLOYMENT_RESOURCE_VERSION, "1"));
final Long crv = Long.parseLong(entry.getOrDefault(ConnectorContext.COS_CONNECTOR_RESOURCE_VERSION, "1"));
final String connectorId = entry.getOrDefault(ConnectorContext.COS_CONNECTOR_ID, uid());
final String deploymentId = entry.getOrDefault(ConnectorContext.COS_DEPLOYMENT_ID, uid());
final String clusterId = ctx.clusterId();
var connector = new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().addToLabels(Resources.LABEL_CLUSTER_ID, clusterId).addToLabels(Resources.LABEL_CONNECTOR_ID, connectorId).addToLabels(Resources.LABEL_DEPLOYMENT_ID, deploymentId).addToLabels(Resources.LABEL_OPERATOR_TYPE, entry.get(ConnectorContext.OPERATOR_TYPE)).withName(Connectors.generateConnectorId(deploymentId)).build()).withSpec(new ManagedConnectorSpecBuilder().withClusterId(clusterId).withConnectorId(connectorId).withDeploymentId(deploymentId).withDeployment(new DeploymentSpecBuilder().withConnectorResourceVersion(crv).withConnectorTypeId(entry.get(ConnectorContext.CONNECTOR_TYPE_ID)).withDeploymentResourceVersion(drv).withNewSchemaRegistry(SCHEMA_REGISTRY_ID, SCHEMA_REGISTRY_URL).withKafka(new KafkaSpecBuilder().withUrl(entry.getOrDefault(COS_KAFKA_BOOTSTRAP, KAFKA_URL)).build()).withDesiredState(entry.get(ConnectorContext.DESIRED_STATE)).withSecret(Connectors.generateConnectorId(deploymentId) + "-" + drv).build()).withOperatorSelector(new OperatorSelectorBuilder().withId(entry.get(ConnectorContext.OPERATOR_ID)).withType(entry.get(ConnectorContext.OPERATOR_TYPE)).withVersion(entry.get(ConnectorContext.OPERATOR_VERSION)).build()).build()).build();
var secret = new SecretBuilder().withMetadata(new ObjectMetaBuilder().addToLabels(Resources.LABEL_OPERATOR_TYPE, entry.get(ConnectorContext.OPERATOR_TYPE)).withName(connector.getMetadata().getName() + "-" + connector.getSpec().getDeployment().getDeploymentResourceVersion()).build()).withData(new HashMap<>()).addToData(Secrets.SECRET_ENTRY_SERVICE_ACCOUNT, Secrets.toBase64(Serialization.asJson(Serialization.jsonMapper().createObjectNode().put("client_id", entry.getOrDefault(COS_KAFKA_CLIENT_ID, ctx.getPlaceholderValue(COS_KAFKA_CLIENT_ID))).put("client_secret", Secrets.toBase64(entry.getOrDefault(COS_KAFKA_CLIENT_SECRET, uid())))))).build();
ctx.connector(connector);
ctx.secret(secret);
}
use of org.bf2.cos.fleetshard.api.OperatorSelectorBuilder in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class ConnectorStatusExtractorTest method errorIfNoOperatorId.
@Test
void errorIfNoOperatorId() {
var status = ConnectorStatusExtractor.extract(new ManagedConnectorBuilder().withSpec(new ManagedConnectorSpecBuilder().withOperatorSelector(new OperatorSelectorBuilder().build()).build()).withStatus(new ManagedConnectorStatusBuilder().withPhase(ManagedConnectorStatus.PhaseType.Monitor).withDeployment(new DeploymentSpecBuilder().withDeploymentResourceVersion(1L).withDesiredState(DESIRED_STATE_READY).build()).build()).build());
assertThat(status.getPhase()).isEqualTo(ConnectorState.FAILED);
assertThat(status.getConditions()).anySatisfy(c -> {
assertThat(c.getType()).isEqualTo(Conditions.TYPE_READY);
assertThat(c.getStatus()).isEqualTo(Conditions.STATUS_FALSE);
assertThat(c.getReason()).isEqualTo(Conditions.NO_ASSIGNABLE_OPERATOR_REASON);
});
assertThat(status.getResourceVersion()).isEqualTo(1L);
}
Aggregations