@Test public void assertSandbox() { when(registryCenter.getDirectly(HANode.FRAMEWORK_ID_NODE)).thenReturn("d8701508-41b7-471e-9b32-61cf824a660d-0000"); MesosStateService service = new MesosStateService(registryCenter); Collection<Map<String, String>> sandbox = service.sandbox("foo_app"); assertThat(sandbox.size(), is(1)); assertThat(sandbox.iterator().next().get("hostname"), is("127.0.0.1")); assertThat(sandbox.iterator().next().get("path"), is("/slaves/d8701508-41b7-471e-9b32-61cf824a660d-S0/" + "frameworks/d8701508-41b7-471e-9b32-61cf824a660d-0000/executors/foo_app@-@d8701508-41b7-471e-9b32-61cf824a660d-S0/runs/53fb4af7-aee2-44f6-9e47-6f418d9f27e1")); }
public Collection<Map<String, String>> sandbox(final String appName) throws JsonParseException { JsonObject state = fetch(stateUrl); List<Map<String, String>> result = new ArrayList<>(); for (JsonObject each : findExecutors(state.getAsJsonArray("frameworks"), appName)) { JsonArray slaves = state.get("slaves").getAsJsonArray(); String slaveHost = null; for (int i = 0; i < slaves.size(); i++) { JsonObject slave = slaves.get(i).getAsJsonObject(); if (each.get("slave_id").getAsString().equals(slave.get("id").getAsString())) { slaveHost = slave.get("pid").getAsString().split("@")[1]; } } Preconditions.checkNotNull(slaveHost); JsonObject slaveState = fetch(String.format("http: String workDir = slaveState.get("flags").getAsJsonObject().get("work_dir").getAsString(); Collection<JsonObject> executorsOnSlave = findExecutors(slaveState.get("frameworks").getAsJsonArray(), appName); for (JsonObject executorOnSlave : executorsOnSlave) { Map<String, String> r = new LinkedHashMap<>(); r.put("hostname", slaveState.get("hostname").getAsString()); r.put("path", executorOnSlave.get("directory").getAsString().replace(workDir, "")); result.add(r); } } return result; }
MesosStateService { public Collection<Map<String, String>> sandbox(final String appName) throws JsonParseException { JsonObject state = fetch(stateUrl); List<Map<String, String>> result = new ArrayList<>(); for (JsonObject each : findExecutors(state.getAsJsonArray("frameworks"), appName)) { JsonArray slaves = state.get("slaves").getAsJsonArray(); String slaveHost = null; for (int i = 0; i < slaves.size(); i++) { JsonObject slave = slaves.get(i).getAsJsonObject(); if (each.get("slave_id").getAsString().equals(slave.get("id").getAsString())) { slaveHost = slave.get("pid").getAsString().split("@")[1]; } } Preconditions.checkNotNull(slaveHost); JsonObject slaveState = fetch(String.format("http: String workDir = slaveState.get("flags").getAsJsonObject().get("work_dir").getAsString(); Collection<JsonObject> executorsOnSlave = findExecutors(slaveState.get("frameworks").getAsJsonArray(), appName); for (JsonObject executorOnSlave : executorsOnSlave) { Map<String, String> r = new LinkedHashMap<>(); r.put("hostname", slaveState.get("hostname").getAsString()); r.put("path", executorOnSlave.get("directory").getAsString().replace(workDir, "")); result.add(r); } } return result; } }
MesosStateService { public Collection<Map<String, String>> sandbox(final String appName) throws JsonParseException { JsonObject state = fetch(stateUrl); List<Map<String, String>> result = new ArrayList<>(); for (JsonObject each : findExecutors(state.getAsJsonArray("frameworks"), appName)) { JsonArray slaves = state.get("slaves").getAsJsonArray(); String slaveHost = null; for (int i = 0; i < slaves.size(); i++) { JsonObject slave = slaves.get(i).getAsJsonObject(); if (each.get("slave_id").getAsString().equals(slave.get("id").getAsString())) { slaveHost = slave.get("pid").getAsString().split("@")[1]; } } Preconditions.checkNotNull(slaveHost); JsonObject slaveState = fetch(String.format("http: String workDir = slaveState.get("flags").getAsJsonObject().get("work_dir").getAsString(); Collection<JsonObject> executorsOnSlave = findExecutors(slaveState.get("frameworks").getAsJsonArray(), appName); for (JsonObject executorOnSlave : executorsOnSlave) { Map<String, String> r = new LinkedHashMap<>(); r.put("hostname", slaveState.get("hostname").getAsString()); r.put("path", executorOnSlave.get("directory").getAsString().replace(workDir, "")); result.add(r); } } return result; } MesosStateService(final CoordinatorRegistryCenter regCenter); }
MesosStateService { public Collection<Map<String, String>> sandbox(final String appName) throws JsonParseException { JsonObject state = fetch(stateUrl); List<Map<String, String>> result = new ArrayList<>(); for (JsonObject each : findExecutors(state.getAsJsonArray("frameworks"), appName)) { JsonArray slaves = state.get("slaves").getAsJsonArray(); String slaveHost = null; for (int i = 0; i < slaves.size(); i++) { JsonObject slave = slaves.get(i).getAsJsonObject(); if (each.get("slave_id").getAsString().equals(slave.get("id").getAsString())) { slaveHost = slave.get("pid").getAsString().split("@")[1]; } } Preconditions.checkNotNull(slaveHost); JsonObject slaveState = fetch(String.format("http: String workDir = slaveState.get("flags").getAsJsonObject().get("work_dir").getAsString(); Collection<JsonObject> executorsOnSlave = findExecutors(slaveState.get("frameworks").getAsJsonArray(), appName); for (JsonObject executorOnSlave : executorsOnSlave) { Map<String, String> r = new LinkedHashMap<>(); r.put("hostname", slaveState.get("hostname").getAsString()); r.put("path", executorOnSlave.get("directory").getAsString().replace(workDir, "")); result.add(r); } } return result; } MesosStateService(final CoordinatorRegistryCenter regCenter); static synchronized void register(final String hostName, final int port); static synchronized void deregister(); Collection<Map<String, String>> sandbox(final String appName); Collection<ExecutorStateInfo> executors(final String appName); Collection<ExecutorStateInfo> executors(); }
MesosStateService { public Collection<Map<String, String>> sandbox(final String appName) throws JsonParseException { JsonObject state = fetch(stateUrl); List<Map<String, String>> result = new ArrayList<>(); for (JsonObject each : findExecutors(state.getAsJsonArray("frameworks"), appName)) { JsonArray slaves = state.get("slaves").getAsJsonArray(); String slaveHost = null; for (int i = 0; i < slaves.size(); i++) { JsonObject slave = slaves.get(i).getAsJsonObject(); if (each.get("slave_id").getAsString().equals(slave.get("id").getAsString())) { slaveHost = slave.get("pid").getAsString().split("@")[1]; } } Preconditions.checkNotNull(slaveHost); JsonObject slaveState = fetch(String.format("http: String workDir = slaveState.get("flags").getAsJsonObject().get("work_dir").getAsString(); Collection<JsonObject> executorsOnSlave = findExecutors(slaveState.get("frameworks").getAsJsonArray(), appName); for (JsonObject executorOnSlave : executorsOnSlave) { Map<String, String> r = new LinkedHashMap<>(); r.put("hostname", slaveState.get("hostname").getAsString()); r.put("path", executorOnSlave.get("directory").getAsString().replace(workDir, "")); result.add(r); } } return result; } MesosStateService(final CoordinatorRegistryCenter regCenter); static synchronized void register(final String hostName, final int port); static synchronized void deregister(); Collection<Map<String, String>> sandbox(final String appName); Collection<ExecutorStateInfo> executors(final String appName); Collection<ExecutorStateInfo> executors();  }