Search in sources :

Example 6 with KafkaConnectorStatus

use of io.strimzi.api.kafka.model.status.KafkaConnectorStatus in project strimzi-kafka-operator by strimzi.

the class CustomResourceStatusIsolatedST method assertKafkaConnectorStatus.

@SuppressWarnings("unchecked")
void assertKafkaConnectorStatus(long expectedObservedGeneration, String connectorStates, String type, List<String> topics) {
    KafkaConnectorStatus kafkaConnectorStatus = KafkaConnectorResource.kafkaConnectorClient().inNamespace(Constants.INFRA_NAMESPACE).withName(CUSTOM_RESOURCE_STATUS_CLUSTER_NAME).get().getStatus();
    assertThat(kafkaConnectorStatus.getObservedGeneration(), is(expectedObservedGeneration));
    Map<String, Object> connectorStatus = kafkaConnectorStatus.getConnectorStatus();
    String currentState = ((LinkedHashMap<String, String>) connectorStatus.get("connector")).get("state");
    assertThat(connectorStates, containsString(currentState));
    assertThat(connectorStatus.get("name"), is(CUSTOM_RESOURCE_STATUS_CLUSTER_NAME));
    assertThat(connectorStatus.get("type"), is(type));
    assertThat(connectorStatus.get("tasks"), notNullValue());
    assertThat(kafkaConnectorStatus.getTopics(), is(topics));
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with KafkaConnectorStatus

use of io.strimzi.api.kafka.model.status.KafkaConnectorStatus in project strimzi by strimzi.

the class AbstractConnectOperator method updateStatus.

public static void updateStatus(Reconciliation reconciliation, Throwable error, KafkaConnector kafkaConnector2, CrdOperator<?, KafkaConnector, ?> connectorOperations) {
    KafkaConnectorStatus status = new KafkaConnectorStatus();
    StatusUtils.setStatusConditionAndObservedGeneration(kafkaConnector2, status, error);
    StatusDiff diff = new StatusDiff(kafkaConnector2.getStatus(), status);
    if (!diff.isEmpty()) {
        KafkaConnector copy = new KafkaConnectorBuilder(kafkaConnector2).build();
        copy.setStatus(status);
        connectorOperations.updateStatusAsync(reconciliation, copy);
    }
}
Also used : StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus)

Example 8 with KafkaConnectorStatus

use of io.strimzi.api.kafka.model.status.KafkaConnectorStatus in project strimzi by strimzi.

the class ConnectIsolatedST method testScaleConnectWithConnectorToZero.

@ParallelNamespaceTest
@Tag(SCALABILITY)
@Tag(CONNECTOR_OPERATOR)
void testScaleConnectWithConnectorToZero(ExtensionContext extensionContext) {
    final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
    final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    final String topicName = mapWithTestTopics.get(extensionContext.getDisplayName());
    final String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3).build());
    resourceManager.createResource(extensionContext, KafkaConnectTemplates.kafkaConnect(extensionContext, clusterName, 2).editMetadata().addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().build());
    resourceManager.createResource(extensionContext, KafkaConnectorTemplates.kafkaConnector(clusterName).editSpec().withClassName("org.apache.kafka.connect.file.FileStreamSinkConnector").addToConfig("file", Constants.DEFAULT_SINK_FILE_PATH).addToConfig("key.converter", "org.apache.kafka.connect.storage.StringConverter").addToConfig("value.converter", "org.apache.kafka.connect.storage.StringConverter").addToConfig("topics", topicName).endSpec().build());
    String connectDeploymentName = KafkaConnectResources.deploymentName(clusterName);
    List<Pod> connectPods = kubeClient(namespaceName).listPodsByPrefixInName(namespaceName, KafkaConnectResources.deploymentName(clusterName));
    assertThat(connectPods.size(), is(2));
    // scale down
    LOGGER.info("Scaling KafkaConnect down to zero");
    KafkaConnectResource.replaceKafkaConnectResourceInSpecificNamespace(clusterName, kafkaConnect -> kafkaConnect.getSpec().setReplicas(0), namespaceName);
    KafkaConnectUtils.waitForConnectReady(namespaceName, clusterName);
    PodUtils.waitForPodsReady(namespaceName, kubeClient(namespaceName).getDeploymentSelectors(namespaceName, connectDeploymentName), 0, true);
    connectPods = kubeClient(namespaceName).listPodsByPrefixInName(namespaceName, connectDeploymentName);
    KafkaConnectStatus connectStatus = KafkaConnectResource.kafkaConnectClient().inNamespace(namespaceName).withName(clusterName).get().getStatus();
    KafkaConnectorStatus connectorStatus = KafkaConnectorResource.kafkaConnectorClient().inNamespace(namespaceName).withName(clusterName).get().getStatus();
    assertThat(connectPods.size(), is(0));
    assertThat(connectStatus.getConditions().get(0).getType(), is(Ready.toString()));
    assertThat(connectorStatus.getConditions().stream().anyMatch(condition -> condition.getType().equals(NotReady.toString())), is(true));
    assertThat(connectorStatus.getConditions().stream().anyMatch(condition -> condition.getMessage().contains("has 0 replicas")), is(true));
}
Also used : KafkaConnectStatus(io.strimzi.api.kafka.model.status.KafkaConnectStatus) Quantity(io.fabric8.kubernetes.api.model.Quantity) SMOKE(io.strimzi.systemtest.Constants.SMOKE) ConfigMapVolumeSourceBuilder(io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder) KubeClusterResource.cmdKubeClient(io.strimzi.test.k8s.KubeClusterResource.cmdKubeClient) Matchers.not(org.hamcrest.Matchers.not) Annotations(io.strimzi.operator.common.Annotations) INFRA_NAMESPACE(io.strimzi.systemtest.Constants.INFRA_NAMESPACE) KafkaUser(io.strimzi.api.kafka.model.KafkaUser) KafkaConnectResource(io.strimzi.systemtest.resources.crd.KafkaConnectResource) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) KafkaListenerAuthenticationTls(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationTls) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) KafkaConnectUtils(io.strimzi.systemtest.utils.kafkaUtils.KafkaConnectUtils) KafkaConnectStatus(io.strimzi.api.kafka.model.status.KafkaConnectStatus) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) Tag(org.junit.jupiter.api.Tag) StUtils(io.strimzi.systemtest.utils.StUtils) SecretVolumeSourceBuilder(io.fabric8.kubernetes.api.model.SecretVolumeSourceBuilder) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ACCEPTANCE(io.strimzi.systemtest.Constants.ACCEPTANCE) IsolatedSuite(io.strimzi.systemtest.annotations.IsolatedSuite) INTERNAL_CLIENTS_USED(io.strimzi.systemtest.Constants.INTERNAL_CLIENTS_USED) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) Base64(java.util.Base64) List(java.util.List) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) Logger(org.apache.logging.log4j.Logger) KafkaTopicTemplates(io.strimzi.systemtest.templates.crd.KafkaTopicTemplates) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus) KafkaConnectorTemplates(io.strimzi.systemtest.templates.crd.KafkaConnectorTemplates) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PasswordSecretSourceBuilder(io.strimzi.api.kafka.model.PasswordSecretSourceBuilder) Secret(io.fabric8.kubernetes.api.model.Secret) Matchers.is(org.hamcrest.Matchers.is) SCALABILITY(io.strimzi.systemtest.Constants.SCALABILITY) Matchers.containsString(org.hamcrest.Matchers.containsString) AbstractST(io.strimzi.systemtest.AbstractST) Environment(io.strimzi.systemtest.Environment) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) KafkaClientsTemplates(io.strimzi.systemtest.templates.crd.KafkaClientsTemplates) KafkaConnectTemplates(io.strimzi.systemtest.templates.crd.KafkaConnectTemplates) CONNECT(io.strimzi.systemtest.Constants.CONNECT) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) HashMap(java.util.HashMap) Crds(io.strimzi.api.kafka.Crds) ExternalKafkaClient(io.strimzi.systemtest.kafkaclients.externalClients.ExternalKafkaClient) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) LinkedHashMap(java.util.LinkedHashMap) KafkaConnectorResource(io.strimzi.systemtest.resources.crd.KafkaConnectorResource) PodUtils(io.strimzi.systemtest.utils.kubeUtils.objects.PodUtils) JsonPathMatchers.hasJsonPath(org.valid4j.matchers.jsonpath.JsonPathMatchers.hasJsonPath) DeploymentStrategy(io.strimzi.api.kafka.model.template.DeploymentStrategy) NotReady(io.strimzi.systemtest.enums.CustomResourceStatus.NotReady) TestUtils(io.strimzi.test.TestUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KafkaListenerAuthenticationScramSha512(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationScramSha512) NODEPORT_SUPPORTED(io.strimzi.systemtest.Constants.NODEPORT_SUPPORTED) KafkaTemplates(io.strimzi.systemtest.templates.crd.KafkaTemplates) Ready(io.strimzi.systemtest.enums.CustomResourceStatus.Ready) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) Constants(io.strimzi.systemtest.Constants) Pod(io.fabric8.kubernetes.api.model.Pod) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) EXTERNAL_CLIENTS_USED(io.strimzi.systemtest.Constants.EXTERNAL_CLIENTS_USED) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KubeClusterResource.kubeClient(io.strimzi.test.k8s.KubeClusterResource.kubeClient) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) SecretKeySelectorBuilder(io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder) KafkaConnectorUtils(io.strimzi.systemtest.utils.kafkaUtils.KafkaConnectorUtils) DeploymentUtils(io.strimzi.systemtest.utils.kubeUtils.controllers.DeploymentUtils) Matchers.hasItem(org.hamcrest.Matchers.hasItem) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) KafkaUserTemplates(io.strimzi.systemtest.templates.crd.KafkaUserTemplates) CONNECTOR_OPERATOR(io.strimzi.systemtest.Constants.CONNECTOR_OPERATOR) CONNECT_COMPONENTS(io.strimzi.systemtest.Constants.CONNECT_COMPONENTS) ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) REGRESSION(io.strimzi.systemtest.Constants.REGRESSION) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) Pod(io.fabric8.kubernetes.api.model.Pod) Matchers.containsString(org.hamcrest.Matchers.containsString) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus) ParallelNamespaceTest(io.strimzi.systemtest.annotations.ParallelNamespaceTest) Tag(org.junit.jupiter.api.Tag)

Example 9 with KafkaConnectorStatus

use of io.strimzi.api.kafka.model.status.KafkaConnectorStatus in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class KafkaConnectorSteps method kctr_and_conditions.

@When("the kctr has conditions:")
public void kctr_and_conditions(DataTable table) {
    kubernetesClient.resources(KafkaConnector.class).inNamespace(ctx.connector().getMetadata().getNamespace()).withName(ctx.connector().getMetadata().getName()).editStatus(resource -> {
        List<Map<String, String>> rows = table.asMaps(String.class, String.class);
        List<Condition> conditions = new ArrayList<>(rows.size());
        for (Map<String, String> columns : rows) {
            conditions.add(new ConditionBuilder().withMessage(columns.get("message")).withReason(columns.get("reason")).withStatus(columns.get("status")).withType(columns.get("type")).withLastTransitionTime(columns.get("lastTransitionTime")).build());
        }
        if (resource.getStatus() == null) {
            resource.setStatus(new KafkaConnectorStatus());
        }
        resource.getStatus().setConditions(conditions);
        return resource;
    });
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) ConditionBuilder(io.strimzi.api.kafka.model.status.ConditionBuilder) ArrayList(java.util.ArrayList) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) HashMap(java.util.HashMap) Map(java.util.Map) KafkaConnectorStatus(io.strimzi.api.kafka.model.status.KafkaConnectorStatus) When(io.cucumber.java.en.When)

Aggregations

KafkaConnectorStatus (io.strimzi.api.kafka.model.status.KafkaConnectorStatus)9 KafkaConnector (io.strimzi.api.kafka.model.KafkaConnector)5 KafkaConnectorBuilder (io.strimzi.api.kafka.model.KafkaConnectorBuilder)4 Condition (io.strimzi.api.kafka.model.status.Condition)3 JsonObject (io.vertx.core.json.JsonObject)3 LinkedHashMap (java.util.LinkedHashMap)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 ConfigMapKeySelectorBuilder (io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder)2 ConfigMapVolumeSourceBuilder (io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 Quantity (io.fabric8.kubernetes.api.model.Quantity)2 ResourceRequirementsBuilder (io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 SecretKeySelectorBuilder (io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder)2 SecretVolumeSourceBuilder (io.fabric8.kubernetes.api.model.SecretVolumeSourceBuilder)2 Crds (io.strimzi.api.kafka.Crds)2 CertSecretSourceBuilder (io.strimzi.api.kafka.model.CertSecretSourceBuilder)2 KafkaConnect (io.strimzi.api.kafka.model.KafkaConnect)2