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);
}
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;
}
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();
});
}
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;
}
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");
}
Aggregations