use of org.eclipse.hono.util.AdapterInstanceStatus in project hono by eclipse.
the class CacheBasedDeviceConnectionInfo method checkAdapterInstanceId.
private String checkAdapterInstanceId(final String adapterInstanceId, final String tenantId, final String deviceId, final Span span) {
if (adapterInstanceId != null) {
final AdapterInstanceStatus status = adapterInstanceStatusProvider.getStatus(adapterInstanceId);
if (status == AdapterInstanceStatus.DEAD) {
LOG.debug("ignoring found adapter instance id, belongs to already terminated container [tenant: {}, device-id: {}, adapter-instance-id: {}]", tenantId, deviceId, adapterInstanceId);
span.log("ignoring found adapter instance id [" + adapterInstanceId + "], belongs to already terminated container");
cache.remove(getAdapterInstanceEntryKey(tenantId, deviceId), adapterInstanceId).onSuccess(removed -> {
if (removed) {
LOG.debug("removed entry with obsolete adapter instance id '{}' [tenant: {}, device-id: {}]", adapterInstanceId, tenantId, deviceId);
}
}).onFailure(thr -> LOG.debug("error removing entry with obsolete adapter instance id '{}' [tenant: {}, device-id: {}]", adapterInstanceId, tenantId, deviceId, thr));
return null;
} else if (status == AdapterInstanceStatus.SUSPECTED_DEAD) {
LOG.debug("ignoring found adapter instance id, belongs to container with state 'SUSPECTED_DEAD' [tenant: {}, device-id: {}, adapter-instance-id: {}]", tenantId, deviceId, adapterInstanceId);
span.log("ignoring found adapter instance id [" + adapterInstanceId + "], belongs to container with state 'SUSPECTED_DEAD'");
return null;
}
}
return adapterInstanceId;
}
use of org.eclipse.hono.util.AdapterInstanceStatus in project hono by eclipse.
the class KubernetesBasedAdapterInstanceStatusService method getDeadAdapterInstances.
@Override
public Future<Set<String>> getDeadAdapterInstances(final Collection<String> adapterInstanceIds) {
Objects.requireNonNull(adapterInstanceIds);
if (active.get() != 1) {
return Future.failedFuture("service not active");
}
boolean needPodListRefresh = false;
final Set<String> resultSet = new HashSet<>();
for (final String adapterInstanceId : adapterInstanceIds) {
final AdapterInstanceStatus status = getStatus(adapterInstanceId);
if (status == AdapterInstanceStatus.DEAD) {
resultSet.add(adapterInstanceId);
} else if (status == AdapterInstanceStatus.SUSPECTED_DEAD) {
needPodListRefresh = true;
// don't break out of loop here - let getStatus() be invoked for all, filling suspectedContainerIds if needed
}
}
if (needPodListRefresh) {
final Promise<Set<String>> resultPromise = Promise.promise();
final Handler<Promise<Set<String>>> resultProvider = promise -> {
try {
// get current pod list so that SUSPECTED_DEAD entries can be resolved
refreshContainerLists(client.pods().inNamespace(namespace).list().getItems());
final Set<String> deadAdapterInstances = adapterInstanceIds.stream().filter(id -> getStatus(id) == AdapterInstanceStatus.DEAD).collect(Collectors.toSet());
promise.complete(deadAdapterInstances);
} catch (final Exception e) {
promise.fail(e);
}
};
Optional.ofNullable(Vertx.currentContext()).ifPresentOrElse(ctx -> ctx.executeBlocking(resultProvider, false, resultPromise), () -> resultProvider.handle(resultPromise));
return resultPromise.future();
} else {
return Future.succeededFuture(resultSet);
}
}
Aggregations