public void scanTask(String task) { try { SwarmScanner ss = new SwarmScanner(this); ss.scanTask(task); } catch (RuntimeException e) { maybeThrow(e); } } public void scanNode(String id) {
public void scanNode(String id) { try { SwarmScanner ss = new SwarmScanner(this); ss.scanNode(id); } catch (RuntimeException e) { maybeThrow(e); } } public void scanService(String service) {
public void scanService(String service) { try { SwarmScanner ss = new SwarmScanner(this); ss.scanService(service); } catch (RuntimeException e) { maybeThrow(e); } } public void scan() {
public void scan() { WebTarget wt = SwarmScanner.extractWebTarget(getDockerClient()); JsonNode n = wt.path("/info").request().buildGet().invoke(JsonNode.class); if (n.path("Swarm").path("Cluster").isContainerNode()) { logger.info("talking to a docker swarm manager: {}",wt); SwarmScanner ss = new SwarmScanner(this); ss.scan(); } else { // looks like we are talking to a docker engine. We don't support this yet because we need to figure out // how to ensure that we do not get duplicate entries from the Swarm view of the nodes and the engine's view of itself. logger.info("talking to a docker engine: {}",wt); String engineId = n.get("ID").asText(); JsonLogger.logInfo("x", n); updateEngineInfo(n); } }
+ " \"DesiredState\" : \"shutdown\"\n" + "}"; ObjectNode n = (ObjectNode) mapper.readTree(taskJson); SwarmScanner scanner = new SwarmScanner(null); scanner.swarmClusterId = "abcd123"; JsonNode flattened = scanner.flattenTask(n);
@Test public void testLabels() { // we don't want to use LocalDockerDaemonIntegrationTest because it will only work with a local docker daemon Projector p = getProjector(); SwarmScanner ss = new SwarmScanner(p.createBuilder(DockerScannerBuilder.class).build()); String id = "junit-"+System.currentTimeMillis(); JsonNode actual = p.getNeoRxClient().execCypher("merge (x:DockerService {serviceId:{id}}) set x.label_c='c', x.label_foo='foo', x.junitData=true return x","id",id).blockingFirst(); JsonNode intended = mapper.createObjectNode().put("label_a", "1").put("label_b", "2").put("chinacat","sunflower"); p.getNeoRxClient().execCypher("merge (a:DockerService {serviceId:{id}}) set a+={props} return a","id",id,"props",intended); ss.removeDockerLabels("DockerService","serviceId",id,intended, actual); JsonNode result = p.getNeoRxClient().execCypher("match (x:DockerService {serviceId:{id}}) return x","id",id).blockingFirst(); Assertions.assertThat(result.path("serviceId").asText()).isEqualTo(id); Assertions.assertThat(result.has("label_c")).isFalse(); Assertions.assertThat(result.has("label_foo")).isFalse(); Assertions.assertThat(result.get("label_a").asText()).isEqualTo("1"); } }