public void scanService(String id) {
try {
Optional<String> scid = getSwarmClusterId();
if (scid.isPresent()) {
logger.info("performing targeted scan of service={}", id);
JsonNode it = getRestClient().getService(id);
ObjectNode n = flattenService(it);
n.put("swarmClusterId", scid.get());
dockerScanner.getNeoRxClient().execCypher(
"merge (x:DockerService {serviceId:{serviceId}}) set x+={props}, x.updateTs=timestamp() return x",
"serviceId", n.get("serviceId").asText(), "props", n).forEach(actual -> {
try {
removeDockerLabels("DockerService", "serviceId", n.get("serviceId").asText(), n,
actual);
} catch (Exception e) {
logger.warn("problem removing labels: " + e.toString());
}
});
dockerScanner.getNeoRxClient().execCypher(
"match (swarm:DockerSwarm {swarmClusterId:{swarmClusterId}}),(service:DockerService{serviceId:{serviceId}}) merge (swarm)-[x:CONTAINS]->(service) set x.updateTs=timestamp()",
"swarmClusterId", scid.get(), "serviceId", n.path("serviceId").asText());
}
} catch (RuntimeException e) {
if (isNotFound(e)) {
deleteService(id);
return;
}
throw e;
}
}