ServiceApiUtil { public static List<String> resolveCompsDependency(Service service) { List<String> components = new ArrayList<String>(); for (Component component : service.getComponents()) { int depSize = component.getDependencies().size(); if (!components.contains(component.getName())) { components.add(component.getName()); } if (depSize != 0) { for (String depComp : component.getDependencies()) { if (!components.contains(depComp)) { components.add(0, depComp); } } } } return components; } static  String(String s); @VisibleForTesting static void setJsonSerDeser(JsonSerDeser jsd); @VisibleForTesting static void validateAndResolveService(Service service,
      SliderFileSystem fs, org.apache.hadoop.conf.Configuration conf); static void validateKerberosPrincipal(
      KerberosPrincipal kerberosPrincipal); static void validateNameFormat(String name,
      org.apache.hadoop.conf.Configuration conf); @VisibleForTesting static List<Component> getComponents(SliderFileSystem
      fs, String serviceName); static Service loadService(SliderFileSystem fs, String
      serviceName); static Service loadServiceUpgrade(SliderFileSystem fs,
      String serviceName, String version); static Service loadServiceFrom(SliderFileSystem fs,
      Path appDefPath); static Path getServiceJsonPath(SliderFileSystem fs, String serviceName); static void validateCompResourceSize(
      org.apache.hadoop.yarn.api.records.Resource maxResource,
      Service service); static Collection<Component> sortByDependencies(List<Component>
      components); static void createDirAndPersistApp(SliderFileSystem fs, Path appDir,
      Service service); static Path writeAppDefinition(SliderFileSystem fs, Path appDir,
      Service service); static List<Container> getLiveContainers(Service service,
      List<String> componentInstances); static void validateInstancesUpgrade(List<Container>
      liveContainers); static boolean isUpgradable(Container container); static List<Container> validateAndResolveCompsUpgrade(
      Service liveService, Collection<String> compNames); static List<Container> validateAndResolveCompsStable(
      Service liveService, Collection<String> compNames); static List<String> resolveCompsDependency(Service service); static void checkServiceDependencySatisified(Service service); static JsonSerDeser<Service> jsonSerDeser; static final JsonSerDeser<Container[]> CONTAINER_JSON_SERDE; static final JsonSerDeser<Component[]> COMP_JSON_SERDE; }
@Test public void testResolveCompsDependency() { Service service = createExampleApplication(); List<String> dependencies = new ArrayList<String>(); dependencies.add("compb"); Component compa = createComponent("compa"); compa.setDependencies(dependencies); Component compb = createComponent("compb"); service.addComponent(compa); service.addComponent(compb); List<String> order = ServiceApiUtil.resolveCompsDependency(service); List<String> expected = new ArrayList<String>(); expected.add("compb"); expected.add("compa"); for (int i = 0; i < expected.size(); i++) { Assert.assertEquals("Components are not equal.", expected.get(i), order.get(i)); } }
@Test public void testResolveCompsDependencyReversed() { Service service = createExampleApplication(); List<String> dependencies = new ArrayList<String>(); dependencies.add("compa"); Component compa = createComponent("compa"); Component compb = createComponent("compb"); compb.setDependencies(dependencies); service.addComponent(compa); service.addComponent(compb); List<String> order = ServiceApiUtil.resolveCompsDependency(service); List<String> expected = new ArrayList<String>(); expected.add("compa"); expected.add("compb"); for (int i = 0; i < expected.size(); i++) { Assert.assertEquals("Components are not equal.", expected.get(i), order.get(i)); } }
@Test public void testResolveCompsCircularDependency() { Service service = createExampleApplication(); List<String> dependencies = new ArrayList<String>(); List<String> dependencies2 = new ArrayList<String>(); dependencies.add("compb"); dependencies2.add("compa"); Component compa = createComponent("compa"); compa.setDependencies(dependencies); Component compb = createComponent("compb"); compa.setDependencies(dependencies2); service.addComponent(compa); service.addComponent(compb); List<String> order = ServiceApiUtil.resolveCompsDependency(service); List<String> expected = new ArrayList<String>(); expected.add("compa"); expected.add("compb"); for (int i = 0; i < expected.size(); i++) { Assert.assertEquals("Components are not equal.", expected.get(i), order.get(i)); } }
@Test public void testResolveNoCompsDependency() { Service service = createExampleApplication(); Component compa = createComponent("compa"); Component compb = createComponent("compb"); service.addComponent(compa); service.addComponent(compb); List<String> order = ServiceApiUtil.resolveCompsDependency(service); List<String> expected = new ArrayList<String>(); expected.add("compa"); expected.add("compb"); for (int i = 0; i < expected.size(); i++) { Assert.assertEquals("Components are not equal.", expected.get(i), order.get(i)); } }