Search in sources :

Example 81 with Result

use of io.fabric8.insight.metrics.model.Result in project strimzi by strimzi.

the class KafkaAssemblyOperator method deleteZk.

private final Future<CompositeFuture> deleteZk(Reconciliation reconciliation) {
    String namespace = reconciliation.namespace();
    String name = reconciliation.assemblyName();
    log.info("{}: delete zookeeper {}", reconciliation, name);
    StatefulSet ss = zkSetOperations.get(namespace, ZookeeperCluster.zookeeperClusterName(name));
    ZookeeperCluster zk = ss == null ? null : ZookeeperCluster.fromAssembly(ss, namespace, name);
    boolean deleteClaims = zk != null && zk.getStorage().type() == Storage.StorageType.PERSISTENT_CLAIM && zk.getStorage().isDeleteClaim();
    List<Future> result = new ArrayList<>(4 + (deleteClaims ? zk.getReplicas() : 0));
    result.add(configMapOperations.reconcile(namespace, ZookeeperCluster.zookeeperMetricsName(name), null));
    result.add(serviceOperations.reconcile(namespace, ZookeeperCluster.zookeeperClusterName(name), null));
    result.add(serviceOperations.reconcile(namespace, ZookeeperCluster.zookeeperHeadlessName(name), null));
    result.add(zkSetOperations.reconcile(namespace, ZookeeperCluster.zookeeperClusterName(name), null));
    if (deleteClaims) {
        for (int i = 0; i < zk.getReplicas(); i++) {
            result.add(pvcOperations.reconcile(namespace, zk.getPersistentVolumeClaimName(i), null));
        }
    }
    return CompositeFuture.join(result);
}
Also used : ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future) ZookeeperCluster(io.strimzi.controller.cluster.model.ZookeeperCluster) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet)

Example 82 with Result

use of io.fabric8.insight.metrics.model.Result in project strimzi by strimzi.

the class StatefulSetOperator method restartPod.

private Future<Void> restartPod(String namespace, String name, Predicate<String> isReady, String podName) {
    Future<Void> result = Future.future();
    log.info("Roll {}/{}: Rolling pod {}", namespace, name, podName);
    Future<Void> deleted = Future.future();
    Future<CompositeFuture> deleteFinished = Future.future();
    Watcher<Pod> watcher = new RollingUpdateWatcher(deleted);
    Watch watch = podOperations.watch(namespace, podName, watcher);
    // Delete the pod
    log.debug("Roll {}/{}: Waiting for pod {} to be deleted", namespace, name, podName);
    Future podReconcileFuture = podOperations.reconcile(namespace, podName, null);
    CompositeFuture.join(podReconcileFuture, deleted).setHandler(deleteResult -> {
        watch.close();
        if (deleteResult.succeeded()) {
            log.debug("Roll {}/{}: Pod {} was deleted", namespace, name, podName);
        }
        deleteFinished.handle(deleteResult);
    });
    deleteFinished.compose(ix -> {
        log.debug("Roll {}/{}: Waiting for new pod {} to get ready", namespace, name, podName);
        Future<Void> readyFuture = Future.future();
        vertx.setPeriodic(1_000, timerId -> {
            p(isReady, podName).setHandler(x -> {
                if (x.succeeded()) {
                    if (x.result()) {
                        vertx.cancelTimer(timerId);
                        readyFuture.complete();
                    }
                // else not ready
                } else {
                    vertx.cancelTimer(timerId);
                    readyFuture.fail(x.cause());
                }
            });
        });
        return readyFuture;
    }).setHandler(result);
    return result;
}
Also used : CompositeFuture(io.vertx.core.CompositeFuture) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) StatefulSetList(io.fabric8.kubernetes.api.model.extensions.StatefulSetList) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) DoneableStatefulSet(io.fabric8.kubernetes.api.model.extensions.DoneableStatefulSet) Logger(org.slf4j.Logger) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Predicate(java.util.function.Predicate) Vertx(io.vertx.core.Vertx) LoggerFactory(org.slf4j.LoggerFactory) Pod(io.fabric8.kubernetes.api.model.Pod) Watcher(io.fabric8.kubernetes.client.Watcher) Watch(io.fabric8.kubernetes.client.Watch) Future(io.vertx.core.Future) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) List(java.util.List) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) Watch(io.fabric8.kubernetes.client.Watch) Future(io.vertx.core.Future) CompositeFuture(io.vertx.core.CompositeFuture)

Example 83 with Result

use of io.fabric8.insight.metrics.model.Result in project strimzi by strimzi.

the class ControllerTest method testOnConfigMapChanged.

@Test
public void testOnConfigMapChanged(TestContext context) {
    Topic kubeTopic = new Topic.Builder(topicName, mapName, 10, (short) 2, map("cleanup.policy", "baz")).build();
    Topic kafkaTopic = new Topic.Builder(topicName, mapName, 10, (short) 2, map("cleanup.policy", "bar")).build();
    Topic privateTopic = kafkaTopic;
    ConfigMap cm = TopicSerialization.toConfigMap(kubeTopic, cmPredicate);
    mockKafka.setCreateTopicResponse(topicName.toString(), null).createTopic(kafkaTopic, ar -> {
    });
    mockKafka.setTopicMetadataResponse(topicName, Utils.getTopicMetadata(kafkaTopic), null);
    mockKafka.setUpdateTopicResponse(topicName -> Future.succeededFuture());
    mockTopicStore.setCreateTopicResponse(topicName, null).create(privateTopic, ar -> {
    });
    mockTopicStore.setUpdateTopicResponse(topicName, null);
    mockK8s.setModifyResponse(mapName, null);
    Async async = context.async(3);
    controller.onConfigMapModified(cm, ar -> {
        assertSucceeded(context, ar);
        context.assertEquals("baz", mockKafka.getTopicState(topicName).getConfig().get("cleanup.policy"));
        mockTopicStore.read(topicName, ar2 -> {
            assertSucceeded(context, ar2);
            context.assertEquals("baz", ar2.result().getConfig().get("cleanup.policy"));
            async.countDown();
        });
        mockK8s.getFromName(mapName, ar2 -> {
            assertSucceeded(context, ar2);
            context.assertEquals("baz", TopicSerialization.fromConfigMap(ar2.result()).getConfig().get("cleanup.policy"));
            async.countDown();
        });
        async.countDown();
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 84 with Result

use of io.fabric8.insight.metrics.model.Result in project strimzi by strimzi.

the class TopicSerialization method topicConfigFromConfigMapString.

@SuppressWarnings("unchecked")
private static Map<String, String> topicConfigFromConfigMapString(ConfigMap cm) {
    Map<String, String> mapData = cm.getData();
    String value = mapData.get(CM_KEY_CONFIG);
    Map<?, ?> result;
    if (value == null || value.isEmpty()) {
        result = Collections.emptyMap();
    } else {
        try {
            ObjectMapper mapper = objectMapper();
            result = mapper.readValue(new StringReader(value) {

                @Override
                public String toString() {
                    return "'config' key of 'data' section of ConfigMap '" + cm.getMetadata().getName() + "' in namespace '" + cm.getMetadata().getNamespace() + "'";
                }
            }, Map.class);
        } catch (IOException e) {
            throw new InvalidConfigMapException(cm, "ConfigMap's 'data' section has invalid key '" + CM_KEY_CONFIG + "': " + (e.getMessage() != null ? e.getMessage() : e.toString()));
        }
    }
    Set<String> supportedConfigs = getSupportedTopicConfigs();
    for (Map.Entry<?, ?> entry : result.entrySet()) {
        Object key = entry.getKey();
        String msg = null;
        if (!(key instanceof String)) {
            msg = "The must be of type String, not of type " + key.getClass();
        }
        Object v = entry.getValue();
        if (v == null) {
            msg = "The value corresponding to the key must have a String value, not null";
        } else if (!(v instanceof String)) {
            msg = "The value corresponding to the key must have a String value, not a value of type " + v.getClass();
        }
        if (!supportedConfigs.contains(key)) {
            msg = "The allowed configs keys are " + supportedConfigs;
        }
        if (msg != null) {
            throw new InvalidConfigMapException(cm, "ConfigMap's 'data' section has invalid key '" + CM_KEY_CONFIG + "': The key '" + key + "' of the topic config is invalid: " + msg);
        }
    }
    return (Map<String, String>) result;
}
Also used : StringReader(java.io.StringReader) IOException(java.io.IOException) HashMap(java.util.HashMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 85 with Result

use of io.fabric8.insight.metrics.model.Result in project vertx-openshift-it by cescoffier.

the class Http2IT method testGRPC.

@Test
public void testGRPC() throws Exception {
    Assertions.assertThat(client).deployments().pods().isPodReadyForPeriod();
    String host = securedUrlForRoute(client.routes().withName("hello").get()).getHost();
    System.out.println("Host: " + host);
    System.out.println("Port: " + 443);
    ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, host, 443).useSsl(options -> options.setSsl(true).setUseAlpn(true).setTrustAll(true)).build();
    GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
    HelloRequest request = HelloRequest.newBuilder().setName("OpenShift").build();
    AtomicReference<String> result = new AtomicReference<>();
    System.out.println("Sending request...");
    stub.sayHello(request, asyncResponse -> {
        System.out.println("Got result");
        if (asyncResponse.succeeded()) {
            System.out.println("Succeeded " + asyncResponse.result().getMessage());
            result.set(asyncResponse.result().getMessage());
        } else {
            asyncResponse.cause().printStackTrace();
        }
    });
    await().atMost(5, TimeUnit.MINUTES).untilAtomic(result, is(notNullValue()));
    assertThat(result.get()).contains("Hello OpenShift");
}
Also used : Awaitility.await(org.awaitility.Awaitility.await) ManagedChannel(io.grpc.ManagedChannel) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) HelloRequest(io.grpc.examples.helloworld.HelloRequest) IOException(java.io.IOException) AtomicReference(java.util.concurrent.atomic.AtomicReference) VertxChannelBuilder(io.vertx.grpc.VertxChannelBuilder) Assertions(io.fabric8.kubernetes.assertions.Assertions) TimeUnit(java.util.concurrent.TimeUnit) Kube.securedUrlForRoute(io.vertx.it.openshift.utils.Kube.securedUrlForRoute) HttpVersion(io.vertx.core.http.HttpVersion) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) Matchers.is(org.hamcrest.Matchers.is) HttpClientOptions(io.vertx.core.http.HttpClientOptions) org.junit(org.junit) Kube.urlForRoute(io.vertx.it.openshift.utils.Kube.urlForRoute) HelloRequest(io.grpc.examples.helloworld.HelloRequest) ManagedChannel(io.grpc.ManagedChannel) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

Test (org.junit.Test)104 Expectations (mockit.Expectations)49 HashMap (java.util.HashMap)32 Map (java.util.Map)24 ArrayList (java.util.ArrayList)23 File (java.io.File)21 GitContext (io.fabric8.api.GitContext)20 IOException (java.io.IOException)20 Exchange (org.apache.camel.Exchange)20 Processor (org.apache.camel.Processor)20 DefaultPullPushPolicy (io.fabric8.git.internal.DefaultPullPushPolicy)18 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)17 Probe (io.fabric8.kubernetes.api.model.Probe)16 PatchResult (io.fabric8.patch.management.PatchResult)13 Properties (java.util.Properties)13 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)11 Patch (io.fabric8.patch.management.Patch)11 PatchException (io.fabric8.patch.management.PatchException)11 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)10 TreeMap (java.util.TreeMap)10