Search in sources :

Example 96 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class ControllerIT method deleteTopic.

private void deleteTopic(TestContext context, String topicName, String configMapName) throws InterruptedException, ExecutionException {
    LOGGER.info("Deleting topic {} (ConfigMap {})", topicName, configMapName);
    // Now we can delete the topic
    DeleteTopicsResult dlt = adminClient.deleteTopics(singletonList(topicName));
    dlt.all().get();
    LOGGER.info("Deleted topic {}", topicName);
    // Wait for the configmap to be deleted
    waitFor(context, () -> {
        ConfigMap cm = kubeClient.configMaps().inNamespace(NAMESPACE).withName(configMapName).get();
        LOGGER.info("Polled configmap {}, got {}, waiting for deletion", configMapName, cm);
        return cm == null;
    }, timeout, "Expected the configmap to have been deleted by now");
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 97 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class ControllerIT method waitForEvent.

private void waitForEvent(TestContext context, ConfigMap cm, String expectedMessage, Controller.EventType expectedType) {
    waitFor(context, () -> {
        List<Event> items = kubeClient.events().inNamespace(NAMESPACE).withLabels(cmPredicate.labels()).list().getItems();
        List<Event> filtered = items.stream().filter(evt -> !preExistingEvents.contains(evt.getMetadata().getUid()) && "ConfigMap".equals(evt.getInvolvedObject().getKind()) && cm.getMetadata().getName().equals(evt.getInvolvedObject().getName())).collect(Collectors.toList());
        LOGGER.debug("Waiting for events: {}", filtered.stream().map(evt -> evt.getMessage()).collect(Collectors.toList()));
        if (!filtered.isEmpty()) {
            assertEquals(1, filtered.size());
            Event event = filtered.get(0);
            assertEquals(expectedMessage, event.getMessage());
            assertEquals(expectedType.name, event.getType());
            assertNotNull(event.getInvolvedObject());
            assertEquals("ConfigMap", event.getInvolvedObject().getKind());
            assertEquals(cm.getMetadata().getName(), event.getInvolvedObject().getName());
            return true;
        } else {
            return false;
        }
    }, timeout, "Expected an error event");
}
Also used : TestContext(io.vertx.ext.unit.TestContext) ZookeeperServer(io.debezium.kafka.ZookeeperServer) LoggerFactory(org.slf4j.LoggerFactory) ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) BooleanSupplier(java.util.function.BooleanSupplier) Collections.singletonList(java.util.Collections.singletonList) AdminClient(org.apache.kafka.clients.admin.AdminClient) Locale(java.util.Locale) After(org.junit.After) Map(java.util.Map) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) ClassRule(org.junit.ClassRule) KafkaCluster(io.debezium.kafka.KafkaCluster) AfterClass(org.junit.AfterClass) Event(io.fabric8.kubernetes.api.model.Event) Namespace(io.strimzi.test.Namespace) Set(java.util.Set) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) List(java.util.List) AlterConfigsResult(org.apache.kafka.clients.admin.AlterConfigsResult) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) Async(io.vertx.ext.unit.Async) BeforeClass(org.junit.BeforeClass) NewPartitions(org.apache.kafka.clients.admin.NewPartitions) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ConfigResource(org.apache.kafka.common.config.ConfigResource) KubeClusterResource(io.strimzi.test.k8s.KubeClusterResource) CreateTopicsResult(org.apache.kafka.clients.admin.CreateTopicsResult) Collections.singletonMap(java.util.Collections.singletonMap) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) Vertx(io.vertx.core.Vertx) NewTopic(org.apache.kafka.clients.admin.NewTopic) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) CreatePartitionsResult(org.apache.kafka.clients.admin.CreatePartitionsResult) Field(java.lang.reflect.Field) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ExecutionException(java.util.concurrent.ExecutionException) Ignore(org.junit.Ignore) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assert.assertEquals(org.junit.Assert.assertEquals) Event(io.fabric8.kubernetes.api.model.Event)

Example 98 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class ControllerIT method createTopic.

private String createTopic(TestContext context, String topicName) throws InterruptedException, ExecutionException {
    LOGGER.info("Creating topic {}", topicName);
    // Create a topic
    String configMapName = new TopicName(topicName).asMapName().toString();
    CreateTopicsResult crt = adminClient.createTopics(singletonList(new NewTopic(topicName, 1, (short) 1)));
    crt.all().get();
    // Wait for the configmap to be created
    waitFor(context, () -> {
        ConfigMap cm = kubeClient.configMaps().inNamespace(NAMESPACE).withName(configMapName).get();
        LOGGER.info("Polled configmap {} waiting for creation", configMapName);
        return cm != null;
    }, timeout, "Expected the configmap to have been created by now");
    LOGGER.info("configmap {} has been created", configMapName);
    return configMapName;
}
Also used : CreateTopicsResult(org.apache.kafka.clients.admin.CreateTopicsResult) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) NewTopic(org.apache.kafka.clients.admin.NewTopic)

Example 99 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class MockK8s method assertContains.

public void assertContains(TestContext context, ConfigMap cm) {
    ConfigMap configMap = byName.get(new MapName(cm));
    context.assertEquals(cm, configMap);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap)

Example 100 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8 by fabric8io.

the class CamelState method doCheck.

@Override
protected List<Check> doCheck() {
    MBeanServer server = this.mbeanServer.getService();
    if (server != null) {
        try {
            List<Check> checks = new ArrayList<>();
            Set<ObjectName> contexts = server.queryNames(new ObjectName("org.apache.camel:type=context,*"), null);
            for (ObjectName ctxName : contexts) {
                String state = server.getAttribute(ctxName, "State").toString();
                if (!"Started".equals(state)) {
                    String name = ctxName.getKeyProperty("name");
                    checks.add(new Check("camel-state", "Camel context " + name + " is in state " + state));
                }
            }
            return checks;
        } catch (Exception e) {
            return Collections.singletonList(new Check("camel-state", "Unable to check camel contexts: " + e.toString()));
        }
    }
    return Collections.emptyList();
}
Also used : Check(io.fabric8.karaf.checks.Check) ArrayList(java.util.ArrayList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

Test (org.junit.Test)135 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)58 Async (io.vertx.ext.unit.Async)52 Expectations (mockit.Expectations)34 Probe (io.fabric8.kubernetes.api.model.Probe)33 Reconciliation (io.strimzi.controller.cluster.Reconciliation)24 File (java.io.File)23 Git (org.eclipse.jgit.api.Git)23 GitContext (io.fabric8.api.GitContext)21 IOException (java.io.IOException)21 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)20 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 HashMap (java.util.HashMap)17 LockHandle (io.fabric8.api.LockHandle)15 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)15 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)15 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)15 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (io.fabric8.kubernetes.client.dsl.Resource)14