use of io.strimzi.controller.cluster.model.AssemblyType in project strimzi by strimzi.
the class AbstractAssemblyOperator method reconcileAll.
/**
* Reconcile assembly resources in the given namespace having the given selector.
* Reconciliation works by getting the assembly ConfigMaps in the given namespace with the given selector and
* comparing with the corresponding {@linkplain #getResources(String) resource}.
* <ul>
* <li>An assembly will be {@linkplain #createOrUpdate(Reconciliation, ConfigMap, Handler) created} for all ConfigMaps without same-named resources</li>
* <li>An assembly will be {@linkplain #delete(Reconciliation, Handler) deleted} for all resources without same-named ConfigMaps</li>
* </ul>
*
* @param trigger A description of the triggering event (timer or watch), used for logging
* @param namespace The namespace
* @param selector The selector
*/
public final CountDownLatch reconcileAll(String trigger, String namespace, Labels selector) {
Labels selectorWithCluster = selector.withType(assemblyType);
// get ConfigMaps with kind=cluster&type=kafka (or connect, or connect-s2i) for the corresponding cluster type
List<ConfigMap> cms = configMapOperations.list(namespace, selectorWithCluster);
Set<String> cmsNames = cms.stream().map(cm -> cm.getMetadata().getName()).collect(Collectors.toSet());
log.debug("reconcileAll({}, {}): ConfigMaps with labels {}: {}", assemblyType, trigger, selectorWithCluster, cmsNames);
// get resources with kind=cluster&type=kafka (or connect, or connect-s2i)
List<? extends HasMetadata> resources = getResources(namespace);
// now extract the cluster name from those
Set<String> resourceNames = resources.stream().filter(// exclude Cluster CM, which won't have a cluster label
r -> Labels.kind(r) == null).map(Labels::cluster).collect(Collectors.toSet());
log.debug("reconcileAll({}, {}): Other resources with labels {}: {}", assemblyType, trigger, selectorWithCluster, resourceNames);
cmsNames.addAll(resourceNames);
// We use a latch so that callers (specifically, test callers) know when the reconciliation is complete
// Using futures would be more complex for no benefit
CountDownLatch latch = new CountDownLatch(cmsNames.size());
for (String name : cmsNames) {
Reconciliation reconciliation = new Reconciliation(trigger, assemblyType, namespace, name);
reconcileAssembly(reconciliation, result -> {
if (result.succeeded()) {
log.info("{}: Assembly reconciled", reconciliation);
} else {
log.error("{}: Failed to reconcile", reconciliation);
}
latch.countDown();
});
}
return latch;
}
use of io.strimzi.controller.cluster.model.AssemblyType in project strimzi by strimzi.
the class ClusterController method createConfigMapWatch.
private void createConfigMapWatch(Handler<AsyncResult<Watch>> handler) {
getVertx().executeBlocking(future -> {
Watch watch = client.configMaps().inNamespace(namespace).withLabels(selector.toMap()).watch(new Watcher<ConfigMap>() {
@Override
public void eventReceived(Action action, ConfigMap cm) {
Labels labels = Labels.fromResource(cm);
AssemblyType type;
try {
type = labels.type();
} catch (IllegalArgumentException e) {
log.warn("Unknown {} label {} received in Config Map {} in namespace {}", Labels.STRIMZI_TYPE_LABEL, cm.getMetadata().getLabels().get(Labels.STRIMZI_TYPE_LABEL), cm.getMetadata().getName(), namespace);
return;
}
final AbstractAssemblyOperator cluster;
if (type == null) {
log.warn("Missing label {} in Config Map {} in namespace {}", Labels.STRIMZI_TYPE_LABEL, cm.getMetadata().getName(), namespace);
return;
} else {
switch(type) {
case KAFKA:
cluster = kafkaAssemblyOperator;
break;
case CONNECT:
cluster = kafkaConnectAssemblyOperator;
break;
case CONNECT_S2I:
cluster = kafkaConnectS2IAssemblyOperator;
break;
default:
return;
}
}
String name = cm.getMetadata().getName();
switch(action) {
case ADDED:
case DELETED:
case MODIFIED:
Reconciliation reconciliation = new Reconciliation("watch", type, namespace, name);
log.info("{}: ConfigMap {} in namespace {} was {}", reconciliation, name, namespace, action);
cluster.reconcileAssembly(reconciliation, result -> {
if (result.succeeded()) {
log.info("{}: assembly reconciled", reconciliation);
} else {
log.error("{}: Failed to reconcile", reconciliation);
}
});
break;
case ERROR:
log.error("Failed ConfigMap {} in namespace{} ", name, namespace);
reconcileAll("watch error");
break;
default:
log.error("Unknown action: {} in namespace {}", name, namespace);
reconcileAll("watch unknown");
}
}
@Override
public void onClose(KubernetesClientException e) {
if (e != null) {
log.error("Watcher closed with exception in namespace {}", namespace, e);
} else {
log.info("Watcher closed in namespace {}", namespace);
}
recreateConfigMapWatch();
}
});
future.complete(watch);
}, res -> {
if (res.succeeded()) {
log.info("ConfigMap watcher running for labels {}", selector);
handler.handle(Future.succeededFuture((Watch) res.result()));
} else {
log.info("ConfigMap watcher failed to start", res.cause());
handler.handle(Future.failedFuture("ConfigMap watcher failed to start"));
}
});
}
Aggregations