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, ConnectorState 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 NamespaceReaperWithLeftoversTest method namespaceIsProvisioned.
@Test
void namespaceIsProvisioned() {
final String deploymentId = ConfigProvider.getConfig().getValue("test.deployment.id", String.class);
final String statusUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/" + config.cluster().id() + "/status";
final String namespaceName = fleetShardClient.generateNamespaceId(deploymentId);
given().contentType(MediaType.TEXT_PLAIN).body(0L).post("/test/provisioner/namespaces");
until(() -> fleetShardClient.getNamespace(deploymentId), Objects::nonNull);
server.until(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(jp("$.namespaces.size()", "1")).withRequestBody(jp("$.namespaces[0].phase", Namespaces.PHASE_READY)).withRequestBody(jp("$.namespaces[0].version", "0")).withRequestBody(jp("$.namespaces[0].connectors_deployed", "0")));
final ManagedConnector connector = new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().withName(Connectors.generateConnectorId(deploymentId)).withNamespace(namespaceName).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).addToLabels(LABEL_CONNECTOR_ID, deploymentId).addToLabels(LABEL_DEPLOYMENT_ID, deploymentId).build()).withSpec(new ManagedConnectorSpecBuilder().withClusterId(config.cluster().id()).withConnectorId(deploymentId).withDeploymentId(deploymentId).withOperatorSelector(new OperatorSelectorBuilder().withId(deploymentId).build()).build()).build();
kubernetesClient.resources(ManagedConnector.class).inNamespace(connector.getMetadata().getNamespace()).create(connector);
untilAsserted(() -> {
assertThat(fleetShardClient.getAllConnectors()).isNotEmpty();
assertThat(fleetShardClient.getConnectors(connector.getMetadata().getNamespace())).isNotEmpty();
});
given().contentType(MediaType.TEXT_PLAIN).body(1L).post("/test/provisioner/namespaces");
server.until(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(matchingJsonPath("$.namespaces", WireMock.absent())));
}
use of org.bf2.cos.fleetshard.api.OperatorSelectorBuilder in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class ReSyncTest method namespaceIsProvisioned.
@Test
void namespaceIsProvisioned() {
final String namespacesUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/.*/namespaces";
final String deploymentsUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/.*/deployments";
kubernetesClient.resources(Namespace.class).createOrReplace(new NamespaceBuilder().withMetadata(new ObjectMetaBuilder().withName(Namespaces.generateNamespaceId(DEPLOYMENT_ID)).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).addToAnnotations(ANNOTATION_NAMESPACE_RESOURCE_VERSION, "20").build()).build());
kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).createOrReplace(new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().withName(Connectors.generateConnectorId(DEPLOYMENT_ID)).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).build()).withSpec(new ManagedConnectorSpecBuilder().withDeployment(new DeploymentSpecBuilder().withDeploymentResourceVersion(10L).build()).withClusterId(config.cluster().id()).withConnectorId(CONNECTOR_ID).withDeploymentId(DEPLOYMENT_ID).withOperatorSelector(new OperatorSelectorBuilder().withId(uid()).build()).build()).build());
RestAssured.given().contentType(MediaType.TEXT_PLAIN).post("/test/provisioner/sync");
untilAsserted(() -> {
server.verify(1, getRequestedFor(urlPathMatching(namespacesUrl)).withQueryParam("gt_version", equalTo("0")));
server.verify(1, getRequestedFor(urlPathMatching(deploymentsUrl)).withQueryParam("gt_version", equalTo("0")));
});
RestAssured.given().contentType(MediaType.TEXT_PLAIN).post("/test/provisioner/sync");
untilAsserted(() -> {
server.verify(getRequestedFor(urlPathMatching(namespacesUrl)).withQueryParam("gt_version", equalTo("20")));
server.verify(getRequestedFor(urlPathMatching(deploymentsUrl)).withQueryParam("gt_version", equalTo("10")));
});
untilAsserted(() -> {
RestAssured.given().contentType(MediaType.TEXT_PLAIN).post("/test/provisioner/sync");
server.verify(2, getRequestedFor(urlPathMatching(namespacesUrl)).withQueryParam("gt_version", equalTo("0")));
server.verify(2, getRequestedFor(urlPathMatching(deploymentsUrl)).withQueryParam("gt_version", equalTo("0")));
});
}
Aggregations