@Test public void testAddDependencies() throws IOException { RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class); InputStream testJsonIS = getClass().getClassLoader(). getResourceAsStream(TEST_RCO_DATA_FILE); ObjectMapper mapper = new ObjectMapper(); Map<String,Object> testData = mapper.readValue(testJsonIS, new TypeReference<Map<String,Object>>() {}); rco.addDependencies(testData); mapper.setVisibility(JsonMethod.ALL, JsonAutoDetect.Visibility.ANY); String dump = mapper.writeValueAsString(rco.getDependencies()); List<String> parts = Arrays.asList(dump.substring(1, 522).split(Pattern.quote("],"))); assertEquals(3, parts.size()); assertTrue(parts.contains("\"RoleCommandPair{role=SECONDARY_NAMENODE, cmd=UPGRADE}\":[{\"role\":{\"name\":\"NAMENODE\"},\"cmd\":\"UPGRADE\"}")); assertTrue(parts.contains("\"RoleCommandPair{role=SECONDARY_NAMENODE, cmd=START}\":[{\"role\":{\"name\":\"NAMENODE\"},\"cmd\":\"START\"}")); boolean datanodeCommandExists = false; for (String part : parts) { if (part.contains("RoleCommandPair{role=DATANODE, cmd=STOP}")) { datanodeCommandExists = true; String[] parts2 = part.split(Pattern.quote(":[")); assertEquals(2, parts2.length); assertEquals("\"RoleCommandPair{role=DATANODE, cmd=STOP}\"", parts2[0]); List<String> components = Arrays.asList(new String[]{"\"role\":{\"name\":\"HBASE_MASTER\"},\"cmd\":\"STOP\"", "\"role\":{\"name\":\"RESOURCEMANAGER\"},\"cmd\":\"STOP\"", "\"role\":{\"name\":\"TASKTRACKER\"},\"cmd\":\"STOP\"", "\"role\":{\"name\":\"NODEMANAGER\"},\"cmd\":\"STOP\"", "\"role\":{\"name\":\"HISTORYSERVER\"},\"cmd\":\"STOP\"", "\"role\":{\"name\":\"JOBTRACKER\"},\"cmd\":\"STOP\""}); Assert.assertTrue(CollectionPresentationUtils.isStringPermutationOfCollection(parts2[1], components, "},{", 1, 1)); } } assertTrue(datanodeCommandExists); }
void addDependencies(Map<String, Object> jsonSection) { if(jsonSection == null) { return; } for (Object blockedObj : jsonSection.keySet()) { String blocked = (String) blockedObj; if (COMMENT_STR.equals(blocked)) { continue; } ArrayList<String> blockers = (ArrayList<String>) jsonSection.get(blocked); for (String blocker : blockers) { String [] blockedTuple = blocked.split("-"); String blockedRole = blockedTuple[0]; String blockedCommand = blockedTuple[1]; boolean overrideExisting = blockedTuple.length == 3; String [] blockerTuple = blocker.split("-"); String blockerRole = blockerTuple[0]; String blockerCommand = blockerTuple[1]; addDependency(Role.valueOf(blockedRole), RoleCommand.valueOf(blockedCommand), Role.valueOf(blockerRole), RoleCommand.valueOf(blockerCommand), overrideExisting); } } }
RoleCommandOrder implements Cloneable { void addDependencies(Map<String, Object> jsonSection) { if(jsonSection == null) { return; } for (Object blockedObj : jsonSection.keySet()) { String blocked = (String) blockedObj; if (COMMENT_STR.equals(blocked)) { continue; } ArrayList<String> blockers = (ArrayList<String>) jsonSection.get(blocked); for (String blocker : blockers) { String [] blockedTuple = blocked.split("-"); String blockedRole = blockedTuple[0]; String blockedCommand = blockedTuple[1]; boolean overrideExisting = blockedTuple.length == 3; String [] blockerTuple = blocker.split("-"); String blockerRole = blockerTuple[0]; String blockerCommand = blockerTuple[1]; addDependency(Role.valueOf(blockedRole), RoleCommand.valueOf(blockedCommand), Role.valueOf(blockerRole), RoleCommand.valueOf(blockerCommand), overrideExisting); } } } }
RoleCommandOrder implements Cloneable { void addDependencies(Map<String, Object> jsonSection) { if(jsonSection == null) { return; } for (Object blockedObj : jsonSection.keySet()) { String blocked = (String) blockedObj; if (COMMENT_STR.equals(blocked)) { continue; } ArrayList<String> blockers = (ArrayList<String>) jsonSection.get(blocked); for (String blocker : blockers) { String [] blockedTuple = blocked.split("-"); String blockedRole = blockedTuple[0]; String blockedCommand = blockedTuple[1]; boolean overrideExisting = blockedTuple.length == 3; String [] blockerTuple = blocker.split("-"); String blockerRole = blockerTuple[0]; String blockerCommand = blockerTuple[1]; addDependency(Role.valueOf(blockedRole), RoleCommand.valueOf(blockedCommand), Role.valueOf(blockerRole), RoleCommand.valueOf(blockerCommand), overrideExisting); } } }  }
RoleCommandOrder implements Cloneable { void addDependencies(Map<String, Object> jsonSection) { if(jsonSection == null) { return; } for (Object blockedObj : jsonSection.keySet()) { String blocked = (String) blockedObj; if (COMMENT_STR.equals(blocked)) { continue; } ArrayList<String> blockers = (ArrayList<String>) jsonSection.get(blocked); for (String blocker : blockers) { String [] blockedTuple = blocked.split("-"); String blockedRole = blockedTuple[0]; String blockedCommand = blockedTuple[1]; boolean overrideExisting = blockedTuple.length == 3; String [] blockerTuple = blocker.split("-"); String blockerRole = blockerTuple[0]; String blockerCommand = blockerTuple[1]; addDependency(Role.valueOf(blockedRole), RoleCommand.valueOf(blockedCommand), Role.valueOf(blockerRole), RoleCommand.valueOf(blockerCommand), overrideExisting); } } }  @SuppressWarnings("unchecked") void initialize(Cluster cluster, LinkedHashSet<String> sectionKeys); int order(RoleGraphNode rgn1, RoleGraphNode rgn2); Set<Service> getTransitiveServices(Service service, RoleCommand cmd); int compareDeps(RoleCommandOrder rco); LinkedHashSet<String> getSectionKeys(); Map<RoleCommandPair, Set<RoleCommandPair>> getDependencies(); @Override Object clone(); }
RoleCommandOrder implements Cloneable { void addDependencies(Map<String, Object> jsonSection) { if(jsonSection == null) { return; } for (Object blockedObj : jsonSection.keySet()) { String blocked = (String) blockedObj; if (COMMENT_STR.equals(blocked)) { continue; } ArrayList<String> blockers = (ArrayList<String>) jsonSection.get(blocked); for (String blocker : blockers) { String [] blockedTuple = blocked.split("-"); String blockedRole = blockedTuple[0]; String blockedCommand = blockedTuple[1]; boolean overrideExisting = blockedTuple.length == 3; String [] blockerTuple = blocker.split("-"); String blockerRole = blockerTuple[0]; String blockerCommand = blockerTuple[1]; addDependency(Role.valueOf(blockedRole), RoleCommand.valueOf(blockedCommand), Role.valueOf(blockerRole), RoleCommand.valueOf(blockerCommand), overrideExisting); } } }  @SuppressWarnings("unchecked") void initialize(Cluster cluster, LinkedHashSet<String> sectionKeys); int order(RoleGraphNode rgn1, RoleGraphNode rgn2); Set<Service> getTransitiveServices(Service service, RoleCommand cmd); int compareDeps(RoleCommandOrder rco); LinkedHashSet<String> getSectionKeys(); Map<RoleCommandPair, Set<RoleCommandPair>> getDependencies(); @Override Object clone(); final static String GLUSTERFS_DEPS_KEY; final static String NO_GLUSTERFS_DEPS_KEY; final static String NAMENODE_HA_DEPS_KEY; final static String RESOURCEMANAGER_HA_DEPS_KEY; final static String COMMENT_STR; }