RoleCommandOrder implements Cloneable { public Map<RoleCommandPair, Set<RoleCommandPair>> getDependencies() { return dependencies; }  @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; }
@Test public void testInitializeAtGLUSTERFSCluster() throws AmbariException { ClusterImpl cluster = createMock(ClusterImpl.class); Service service = createMock(Service.class); expect(cluster.getClusterId()).andReturn(1L); expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6")); expect(cluster.getService("GLUSTERFS")).andReturn(service); expect(cluster.getService("HDFS")).andReturn(null); expect(cluster.getService("YARN")).andReturn(null); replay(cluster); RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster); Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies(); assertTrue("Dependencies are loaded after initialization", deps.size() > 0); verify(cluster); assertFalse(dependenciesContainBlockedRole(deps, Role.DATANODE)); assertFalse(dependenciesContainBlockedRole(deps, Role.NAMENODE)); assertFalse(dependenciesContainBlockedRole(deps, Role.SECONDARY_NAMENODE)); assertFalse(dependenciesContainBlockedRole(deps, Role.JOURNALNODE)); assertFalse(dependenciesContainBlockedRole(deps, Role.NAMENODE_SERVICE_CHECK)); assertFalse(dependenciesContainBlockedRole(deps, Role.HDFS_SERVICE_CHECK)); assertFalse(dependenciesContainBlockedRole(deps, Role.HDFS_CLIENT)); assertFalse(dependenciesContainBlockerRole(deps, Role.SECONDARY_NAMENODE)); assertFalse(dependenciesContainBlockerRole(deps, Role.JOURNALNODE)); assertFalse(dependenciesContainBlockerRole(deps, Role.NAMENODE_SERVICE_CHECK)); assertFalse(dependenciesContainBlockerRole(deps, Role.HDFS_SERVICE_CHECK)); assertFalse(dependenciesContainBlockerRole(deps, Role.HDFS_CLIENT)); assertTrue(dependenciesContainBlockerRole(deps, Role.PEERSTATUS)); }
@Test public void testInitializeAtHDFSCluster() throws AmbariException { ClusterImpl cluster = createMock(ClusterImpl.class); expect(cluster.getService("GLUSTERFS")).andReturn(null); expect(cluster.getClusterId()).andReturn(1L); Service hdfsService = createMock(Service.class); expect(cluster.getService("HDFS")).andReturn(hdfsService).atLeastOnce(); expect(cluster.getService("YARN")).andReturn(null).atLeastOnce(); expect(hdfsService.getServiceComponent("JOURNALNODE")).andReturn(null); expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6")); replay(cluster); replay(hdfsService); RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster); Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies(); assertTrue("Dependencies are loaded after initialization", deps.size() > 0); verify(cluster); verify(hdfsService); assertFalse(dependenciesContainBlockedRole(deps, Role.PEERSTATUS)); assertFalse(dependenciesContainBlockedRole(deps, Role.GLUSTERFS_SERVICE_CHECK)); assertFalse(dependenciesContainBlockedRole(deps, Role.GLUSTERFS_CLIENT)); assertFalse(dependenciesContainBlockerRole(deps, Role.PEERSTATUS)); assertFalse(dependenciesContainBlockerRole(deps, Role.GLUSTERFS_SERVICE_CHECK)); assertFalse(dependenciesContainBlockerRole(deps, Role.GLUSTERFS_CLIENT)); assertTrue(dependenciesContainBlockerRole(deps, Role.DATANODE)); assertFalse(dependenciesContainBlockerRole(deps, Role.JOURNALNODE)); assertFalse(dependenciesContainBlockedRole(deps, Role.ZKFC)); }
@Test public void testInitializeAtHaHDFSCluster() throws AmbariException { ClusterImpl cluster = createMock(ClusterImpl.class); expect(cluster.getService("GLUSTERFS")).andReturn(null); expect(cluster.getClusterId()).andReturn(1L); Service hdfsService = createMock(Service.class); ServiceComponent journalnodeSC = createMock(ServiceComponent.class); expect(cluster.getService("HDFS")).andReturn(hdfsService).atLeastOnce(); expect(cluster.getService("YARN")).andReturn(null); expect(hdfsService.getServiceComponent("JOURNALNODE")).andReturn(journalnodeSC); expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6")); replay(cluster); replay(hdfsService); RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster); Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies(); assertTrue("Dependencies are loaded after initialization", deps.size() > 0); verify(cluster); verify(hdfsService); assertFalse(dependenciesContainBlockedRole(deps, Role.PEERSTATUS)); assertFalse(dependenciesContainBlockedRole(deps, Role.GLUSTERFS_SERVICE_CHECK)); assertFalse(dependenciesContainBlockedRole(deps, Role.GLUSTERFS_CLIENT)); assertFalse(dependenciesContainBlockerRole(deps, Role.PEERSTATUS)); assertFalse(dependenciesContainBlockerRole(deps, Role.GLUSTERFS_SERVICE_CHECK)); assertFalse(dependenciesContainBlockerRole(deps, Role.GLUSTERFS_CLIENT)); assertTrue(dependenciesContainBlockerRole(deps, Role.DATANODE)); assertTrue(dependenciesContainBlockerRole(deps, Role.JOURNALNODE)); assertTrue(dependenciesContainBlockedRole(deps, Role.ZKFC)); }
@Test public void testInitializeAtHaRMCluster() throws AmbariException { ClusterImpl cluster = createMock(ClusterImpl.class); ServiceComponentHost sch1 = createMock(ServiceComponentHostImpl.class); ServiceComponentHost sch2 = createMock(ServiceComponentHostImpl.class); expect(cluster.getService("GLUSTERFS")).andReturn(null); expect(cluster.getClusterId()).andReturn(1L); Map<String, ServiceComponentHost> hostComponents = new HashMap<String, ServiceComponentHost>(); hostComponents.put("1",sch1); hostComponents.put("2",sch2); Service yarnService = createMock(Service.class); ServiceComponent resourcemanagerSC = createMock(ServiceComponent.class); expect(cluster.getService("YARN")).andReturn(yarnService).atLeastOnce(); expect(cluster.getService("HDFS")).andReturn(null); expect(yarnService.getServiceComponent("RESOURCEMANAGER")).andReturn(resourcemanagerSC).anyTimes(); expect(resourcemanagerSC.getServiceComponentHosts()).andReturn(hostComponents).anyTimes(); expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6")); replay(cluster, yarnService, sch1, sch2, resourcemanagerSC); RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster); Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies(); assertTrue("Dependencies are loaded after initialization", deps.size() > 0); verify(cluster, yarnService); assertFalse(dependenciesContainBlockedRole(deps, Role.PEERSTATUS)); assertFalse(dependenciesContainBlockedRole(deps, Role.GLUSTERFS_SERVICE_CHECK)); assertFalse(dependenciesContainBlockedRole(deps, Role.GLUSTERFS_CLIENT)); assertFalse(dependenciesContainBlockerRole(deps, Role.PEERSTATUS)); assertFalse(dependenciesContainBlockerRole(deps, Role.GLUSTERFS_SERVICE_CHECK)); assertFalse(dependenciesContainBlockerRole(deps, Role.GLUSTERFS_CLIENT)); assertTrue(dependenciesContainBlockerRole(deps, Role.DATANODE)); RoleCommandPair rmPair = new RoleCommandPair(Role.RESOURCEMANAGER, RoleCommand.START); Set<RoleCommandPair> rmRoleCommandPairs = deps.get(rmPair); assertNotNull(rmRoleCommandPairs); boolean isZookeeperStartPresent = false; for (RoleCommandPair pair : rmRoleCommandPairs) { if (pair.getCmd() == RoleCommand.START && pair.getRole() == Role.ZOOKEEPER_SERVER) { isZookeeperStartPresent = true; } } assertTrue(isZookeeperStartPresent); }
@Test public void testMissingRestartDependenciesAdded() throws Exception { ClusterImpl cluster = createMock(ClusterImpl.class); ServiceComponentHost sch1 = createMock(ServiceComponentHostImpl.class); ServiceComponentHost sch2 = createMock(ServiceComponentHostImpl.class); expect(cluster.getService("GLUSTERFS")).andReturn(null); expect(cluster.getClusterId()).andReturn(1L); Map<String, ServiceComponentHost> hostComponents = new HashMap<>(); hostComponents.put("1", sch1); hostComponents.put("2", sch2); Service yarnService = createMock(Service.class); ServiceComponent resourcemanagerSC = createMock(ServiceComponent.class); expect(cluster.getService("YARN")).andReturn(yarnService).atLeastOnce(); expect(cluster.getService("HDFS")).andReturn(null); expect(yarnService.getServiceComponent("RESOURCEMANAGER")).andReturn(resourcemanagerSC).anyTimes(); expect(resourcemanagerSC.getServiceComponentHosts()).andReturn(hostComponents).anyTimes(); expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6")); replay(cluster, yarnService, sch1, sch2, resourcemanagerSC); RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster); verify(cluster, yarnService); Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies(); assertNotNull(deps); Map<RoleCommandPair, Set<RoleCommandPair>> startRCOs = new HashMap<>(); Map<RoleCommandPair, Set<RoleCommandPair>> restartRCOs = new HashMap<>(); for (Map.Entry<RoleCommandPair, Set<RoleCommandPair>> dep : deps.entrySet()) { if (dep.getKey().getCmd().equals(RoleCommand.START)) { startRCOs.put(dep.getKey(), dep.getValue()); } if (dep.getKey().getCmd().equals(RoleCommand.RESTART)) { restartRCOs.put(dep.getKey(), dep.getValue()); } } assertFalse(startRCOs.isEmpty()); assertFalse(restartRCOs.isEmpty()); assertEquals(startRCOs.size(), restartRCOs.size()); Map.Entry<RoleCommandPair, Set<RoleCommandPair>> entry = restartRCOs.entrySet().iterator().next(); assertEquals(RoleCommand.RESTART, entry.getKey().getCmd()); for (RoleCommandPair pair : entry.getValue()) { assertEquals(RoleCommand.RESTART, pair.getCmd()); } for (Map.Entry<RoleCommandPair, Set<RoleCommandPair>> startEntry : startRCOs.entrySet()) { assertTrue(restartRCOs.containsKey( new RoleCommandPair(startEntry.getKey().getRole(), RoleCommand.RESTART))); } }