@Test public void testTransitiveServices() throws AmbariException { ClusterImpl cluster = createMock(ClusterImpl.class); Service hdfsService = createMock(Service.class); ServiceComponent namenode = createMock(ServiceComponent.class); expect(namenode.getName()).andReturn("NAMENODE").anyTimes(); Map<String,ServiceComponent> hdfsComponents = Collections.singletonMap("NAMENODE", namenode); expect(hdfsService.getServiceComponents()).andReturn(hdfsComponents).anyTimes(); Service hbaseService = createMock(Service.class); expect(cluster.getService("HBASE")).andReturn(hbaseService).atLeastOnce(); expect(cluster.getClusterId()).andReturn(1L); expect(hbaseService.getCluster()).andReturn(cluster).anyTimes(); ServiceComponent hbaseMaster = createMock(ServiceComponent.class); expect(hbaseMaster.getName()).andReturn("HBASE_MASTER").anyTimes(); Map<String, ServiceComponent> hbaseComponents = Collections.singletonMap( "HBASE_MASTER", hbaseMaster); expect(hbaseService.getServiceComponents()).andReturn(hbaseComponents).anyTimes(); Map<String, Service> installedServices = new HashMap<String, Service>(); installedServices.put("HDFS", hdfsService); installedServices.put("HBASE", hbaseService); expect(cluster.getServices()).andReturn(installedServices).atLeastOnce(); expect(cluster.getService("HDFS")).andReturn(hdfsService).atLeastOnce(); expect(cluster.getService("GLUSTERFS")).andReturn(null); expect(cluster.getService("YARN")).andReturn(null); expect(hdfsService.getServiceComponent("JOURNALNODE")).andReturn(null); expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.5")); replay(cluster, hdfsService, hbaseService, hbaseMaster, namenode); RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster); Set<Service> transitiveServices = rco.getTransitiveServices( cluster.getService("HBASE"), RoleCommand.START); Assert.assertNotNull(transitiveServices); Assert.assertFalse(transitiveServices.isEmpty()); Assert.assertEquals(1, transitiveServices.size()); Assert.assertTrue(transitiveServices.contains(hdfsService)); }
public Set<Service> getTransitiveServices(Service service, RoleCommand cmd) throws AmbariException { Set<Service> transitiveServices = new HashSet<Service>(); Cluster cluster = service.getCluster(); Set<RoleCommandPair> allDeps = new HashSet<RoleCommandPair>(); for (ServiceComponent sc : service.getServiceComponents().values()) { RoleCommandPair rcp = new RoleCommandPair(Role.valueOf(sc.getName()), cmd); Set<RoleCommandPair> deps = dependencies.get(rcp); if (deps != null) { allDeps.addAll(deps); } } for (Service s : cluster.getServices().values()) { for (RoleCommandPair rcp : allDeps) { ServiceComponent sc = s.getServiceComponents().get(rcp.getRole().toString()); if (sc != null) { transitiveServices.add(s); break; } } } return transitiveServices; }
RoleCommandOrder implements Cloneable { public Set<Service> getTransitiveServices(Service service, RoleCommand cmd) throws AmbariException { Set<Service> transitiveServices = new HashSet<Service>(); Cluster cluster = service.getCluster(); Set<RoleCommandPair> allDeps = new HashSet<RoleCommandPair>(); for (ServiceComponent sc : service.getServiceComponents().values()) { RoleCommandPair rcp = new RoleCommandPair(Role.valueOf(sc.getName()), cmd); Set<RoleCommandPair> deps = dependencies.get(rcp); if (deps != null) { allDeps.addAll(deps); } } for (Service s : cluster.getServices().values()) { for (RoleCommandPair rcp : allDeps) { ServiceComponent sc = s.getServiceComponents().get(rcp.getRole().toString()); if (sc != null) { transitiveServices.add(s); break; } } } return transitiveServices; } }
RoleCommandOrder implements Cloneable { public Set<Service> getTransitiveServices(Service service, RoleCommand cmd) throws AmbariException { Set<Service> transitiveServices = new HashSet<Service>(); Cluster cluster = service.getCluster(); Set<RoleCommandPair> allDeps = new HashSet<RoleCommandPair>(); for (ServiceComponent sc : service.getServiceComponents().values()) { RoleCommandPair rcp = new RoleCommandPair(Role.valueOf(sc.getName()), cmd); Set<RoleCommandPair> deps = dependencies.get(rcp); if (deps != null) { allDeps.addAll(deps); } } for (Service s : cluster.getServices().values()) { for (RoleCommandPair rcp : allDeps) { ServiceComponent sc = s.getServiceComponents().get(rcp.getRole().toString()); if (sc != null) { transitiveServices.add(s); break; } } } return transitiveServices; }  }
RoleCommandOrder implements Cloneable { public Set<Service> getTransitiveServices(Service service, RoleCommand cmd) throws AmbariException { Set<Service> transitiveServices = new HashSet<Service>(); Cluster cluster = service.getCluster(); Set<RoleCommandPair> allDeps = new HashSet<RoleCommandPair>(); for (ServiceComponent sc : service.getServiceComponents().values()) { RoleCommandPair rcp = new RoleCommandPair(Role.valueOf(sc.getName()), cmd); Set<RoleCommandPair> deps = dependencies.get(rcp); if (deps != null) { allDeps.addAll(deps); } } for (Service s : cluster.getServices().values()) { for (RoleCommandPair rcp : allDeps) { ServiceComponent sc = s.getServiceComponents().get(rcp.getRole().toString()); if (sc != null) { transitiveServices.add(s); break; } } } return transitiveServices; }  @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 { public Set<Service> getTransitiveServices(Service service, RoleCommand cmd) throws AmbariException { Set<Service> transitiveServices = new HashSet<Service>(); Cluster cluster = service.getCluster(); Set<RoleCommandPair> allDeps = new HashSet<RoleCommandPair>(); for (ServiceComponent sc : service.getServiceComponents().values()) { RoleCommandPair rcp = new RoleCommandPair(Role.valueOf(sc.getName()), cmd); Set<RoleCommandPair> deps = dependencies.get(rcp); if (deps != null) { allDeps.addAll(deps); } } for (Service s : cluster.getServices().values()) { for (RoleCommandPair rcp : allDeps) { ServiceComponent sc = s.getServiceComponents().get(rcp.getRole().toString()); if (sc != null) { transitiveServices.add(s); break; } } } return transitiveServices; }  @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; }