/** * Given a service and action, return a set of {@link ActionOnService} describing what other actions on services must * be performed before the given service and action can be performed. * * @param service Service to check. * @param action Action to check. * @return Set of actions on services that must be performed before the input can be performed. */ public Set<ActionOnService> getDirectDependentActions(String service, ProvisionerAction action) { return clusterDependencies.get(new ActionOnService(action, service)); }
directDependencies.add(new ActionOnService(fromAction, parentServiceName)); } else {
clusterDependencies.putAll(new ActionOnService(actionDependency.getTo(), service.getName()), getDirectActionDependencies(service, actionDependency));
expected.put(new ActionOnService(ProvisionerAction.INITIALIZE, "s2"), new ActionOnService(ProvisionerAction.START, "s1")); expected.put(new ActionOnService(ProvisionerAction.START, "s3"), new ActionOnService(ProvisionerAction.START, "s1")); expected.put(new ActionOnService(ProvisionerAction.START, "s4"), new ActionOnService(ProvisionerAction.START, "s3")); expected.put(new ActionOnService(ProvisionerAction.START, "s4"), new ActionOnService(ProvisionerAction.START, "s5")); expected.put(new ActionOnService(ProvisionerAction.INITIALIZE, "s4"), new ActionOnService(ProvisionerAction.START, "s3")); expected.put(new ActionOnService(ProvisionerAction.INITIALIZE, "s4"), new ActionOnService(ProvisionerAction.START, "s5")); expected.put(new ActionOnService(ProvisionerAction.INITIALIZE, "s6"), new ActionOnService(ProvisionerAction.START, "s5"));
@Test public void testServiceUsesDependency() { ServiceAction sAction = new ServiceAction("shell", TestHelper.actionMapOf(null, null)); Map<ProvisionerAction, ServiceAction> installActions = ImmutableMap.of(ProvisionerAction.INSTALL, sAction); Service s1 = Service.builder().setName("s1").setProvisionerActions(installActions).build(); Service s2 = Service.builder() .setName("s2") .setDependencies( ServiceDependencies.builder().setInstallDependencies( new ServiceStageDependencies(null, ImmutableSet.<String>of("s1", "s3"))).build()) .setProvisionerActions(installActions) .build(); Map<String, Service> serviceMap = Maps.newHashMap(); serviceMap.put(s1.getName(), s1); serviceMap.put(s2.getName(), s2); SetMultimap<ActionOnService, ActionOnService> expected = HashMultimap.create(); // s2 depends on s1 expected.put(new ActionOnService(ProvisionerAction.INSTALL, "s2"), new ActionOnService(ProvisionerAction.INSTALL, "s1")); ServiceDependencyResolver resolver = new ServiceDependencyResolver(Actions.getInstance(), serviceMap); SetMultimap<ActionOnService, ActionOnService> actual = resolver.getClusterDependencies(); Assert.assertEquals(expected, actual); } }
expected.put(new ActionOnService(ProvisionerAction.INSTALL, "s3"), new ActionOnService(ProvisionerAction.INSTALL, "s1")); expected.put(new ActionOnService(ProvisionerAction.INSTALL, "s4"), new ActionOnService(ProvisionerAction.INSTALL, "s3")); expected.put(new ActionOnService(ProvisionerAction.INSTALL, "s4"), new ActionOnService(ProvisionerAction.INSTALL, "s5"));