Search in sources :

Example 6 with OperatorSelectorBuilder

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();
}
Also used : DeploymentSpecBuilder(org.bf2.cos.fleetshard.api.DeploymentSpecBuilder) ManagedConnectorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorBuilder) ManagedConnectorStatusBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorStatusBuilder) ManagedConnectorSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder) ConnectorStatusSpecBuilder(org.bf2.cos.fleetshard.api.ConnectorStatusSpecBuilder) ConnectorDeploymentStatus(org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus) OperatorSelectorBuilder(org.bf2.cos.fleetshard.api.OperatorSelectorBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with OperatorSelectorBuilder

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())));
}
Also used : ManagedConnectorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorBuilder) Objects(java.util.Objects) ManagedConnectorSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder) ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) OperatorSelectorBuilder(org.bf2.cos.fleetshard.api.OperatorSelectorBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 8 with OperatorSelectorBuilder

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")));
    });
}
Also used : DeploymentSpecBuilder(org.bf2.cos.fleetshard.api.DeploymentSpecBuilder) ManagedConnectorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorBuilder) ManagedConnectorSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Namespace(io.fabric8.kubernetes.api.model.Namespace) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) OperatorSelectorBuilder(org.bf2.cos.fleetshard.api.OperatorSelectorBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

ManagedConnectorBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorBuilder)8 ManagedConnectorSpecBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder)8 OperatorSelectorBuilder (org.bf2.cos.fleetshard.api.OperatorSelectorBuilder)8 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)5 DeploymentSpecBuilder (org.bf2.cos.fleetshard.api.DeploymentSpecBuilder)5 Test (org.junit.jupiter.api.Test)5 QuarkusTest (io.quarkus.test.junit.QuarkusTest)4 ConnectorStatusSpecBuilder (org.bf2.cos.fleetshard.api.ConnectorStatusSpecBuilder)4 ManagedConnector (org.bf2.cos.fleetshard.api.ManagedConnector)3 ManagedConnectorStatusBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorStatusBuilder)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Condition (io.fabric8.kubernetes.api.model.Condition)2 ConnectorDeploymentStatus (org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)2 Operator (org.bf2.cos.fleetshard.api.Operator)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Given (io.cucumber.java.en.Given)1 Namespace (io.fabric8.kubernetes.api.model.Namespace)1 NamespaceBuilder (io.fabric8.kubernetes.api.model.NamespaceBuilder)1 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)1 Objects (java.util.Objects)1