@Test public void testActionIsExecutedOnAllRelevantNodes() throws Exception { T action = newClusterActionInstance(EMPTYSET, EMPTYSET); DryRun dryRun = getDryRunForAction(action).reset(); action.execute(clusterSpec, cluster); List<StatementOnNode> executions = dryRun.getTotallyOrderedExecutions(); assertThat(executions.size(), is(2)); }
public Cluster execute(ClusterSpec clusterSpec, Cluster cluster) throws IOException, InterruptedException { if (clusterSpec.getInstanceTemplates().size() == 0) { throw new IllegalArgumentException("No instance templates specified."); } Map<InstanceTemplate, ClusterActionEvent> eventMap = Maps.newHashMap(); Cluster newCluster = cluster; for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) { if (shouldIgnoreInstanceTemplate(instanceTemplate)) { continue; } StatementBuilder statementBuilder = new StatementBuilder(); ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec); FirewallManager firewallManager = new FirewallManager( computeServiceContext, clusterSpec, newCluster); VelocityEngine velocityEngine = TemplateUtils.newVelocityEngine(); ClusterActionEvent event = new ClusterActionEvent(getAction(), clusterSpec, instanceTemplate, newCluster, statementBuilder, getCompute(), firewallManager, velocityEngine); eventMap.put(instanceTemplate, event); eventSpecificActions(instanceTemplate, event); for (String role : instanceTemplate.getRoles()) { if (roleIsInTarget(role)) { safeGetActionHandler(role).beforeAction(event); } } newCluster = event.getCluster(); } doAction(eventMap); newCluster = Iterables.get(eventMap.values(), 0).getCluster(); for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) { if (shouldIgnoreInstanceTemplate(instanceTemplate)) { continue; } ClusterActionEvent event = eventMap.get(instanceTemplate); for (String role : instanceTemplate.getRoles()) { if (roleIsInTarget(role)) { event.setCluster(newCluster); safeGetActionHandler(role).afterAction(event); newCluster = event.getCluster(); } } } return newCluster; }
ScriptBasedClusterAction extends ClusterAction { public Cluster execute(ClusterSpec clusterSpec, Cluster cluster) throws IOException, InterruptedException { if (clusterSpec.getInstanceTemplates().size() == 0) { throw new IllegalArgumentException("No instance templates specified."); } Map<InstanceTemplate, ClusterActionEvent> eventMap = Maps.newHashMap(); Cluster newCluster = cluster; for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) { if (shouldIgnoreInstanceTemplate(instanceTemplate)) { continue; } StatementBuilder statementBuilder = new StatementBuilder(); ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec); FirewallManager firewallManager = new FirewallManager( computeServiceContext, clusterSpec, newCluster); VelocityEngine velocityEngine = TemplateUtils.newVelocityEngine(); ClusterActionEvent event = new ClusterActionEvent(getAction(), clusterSpec, instanceTemplate, newCluster, statementBuilder, getCompute(), firewallManager, velocityEngine); eventMap.put(instanceTemplate, event); eventSpecificActions(instanceTemplate, event); for (String role : instanceTemplate.getRoles()) { if (roleIsInTarget(role)) { safeGetActionHandler(role).beforeAction(event); } } newCluster = event.getCluster(); } doAction(eventMap); newCluster = Iterables.get(eventMap.values(), 0).getCluster(); for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) { if (shouldIgnoreInstanceTemplate(instanceTemplate)) { continue; } ClusterActionEvent event = eventMap.get(instanceTemplate); for (String role : instanceTemplate.getRoles()) { if (roleIsInTarget(role)) { event.setCluster(newCluster); safeGetActionHandler(role).afterAction(event); newCluster = event.getCluster(); } } } return newCluster; } }
ScriptBasedClusterAction extends ClusterAction { public Cluster execute(ClusterSpec clusterSpec, Cluster cluster) throws IOException, InterruptedException { if (clusterSpec.getInstanceTemplates().size() == 0) { throw new IllegalArgumentException("No instance templates specified."); } Map<InstanceTemplate, ClusterActionEvent> eventMap = Maps.newHashMap(); Cluster newCluster = cluster; for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) { if (shouldIgnoreInstanceTemplate(instanceTemplate)) { continue; } StatementBuilder statementBuilder = new StatementBuilder(); ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec); FirewallManager firewallManager = new FirewallManager( computeServiceContext, clusterSpec, newCluster); VelocityEngine velocityEngine = TemplateUtils.newVelocityEngine(); ClusterActionEvent event = new ClusterActionEvent(getAction(), clusterSpec, instanceTemplate, newCluster, statementBuilder, getCompute(), firewallManager, velocityEngine); eventMap.put(instanceTemplate, event); eventSpecificActions(instanceTemplate, event); for (String role : instanceTemplate.getRoles()) { if (roleIsInTarget(role)) { safeGetActionHandler(role).beforeAction(event); } } newCluster = event.getCluster(); } doAction(eventMap); newCluster = Iterables.get(eventMap.values(), 0).getCluster(); for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) { if (shouldIgnoreInstanceTemplate(instanceTemplate)) { continue; } ClusterActionEvent event = eventMap.get(instanceTemplate); for (String role : instanceTemplate.getRoles()) { if (roleIsInTarget(role)) { event.setCluster(newCluster); safeGetActionHandler(role).afterAction(event); newCluster = event.getCluster(); } } } return newCluster; } protected  ScriptBasedClusterAction(
      Function<ClusterSpec, ComputeServiceContext> getCompute,
      LoadingCache<String, ClusterActionHandler> handlerMap
  ); protected  ScriptBasedClusterAction(
      Function<ClusterSpec, ComputeServiceContext> getCompute,
      LoadingCache<String, ClusterActionHandler> handlerMap,
      Set<String> targetRoles,
      Set<String> targetInstanceIds
  ); }
ScriptBasedClusterAction extends ClusterAction { public Cluster execute(ClusterSpec clusterSpec, Cluster cluster) throws IOException, InterruptedException { if (clusterSpec.getInstanceTemplates().size() == 0) { throw new IllegalArgumentException("No instance templates specified."); } Map<InstanceTemplate, ClusterActionEvent> eventMap = Maps.newHashMap(); Cluster newCluster = cluster; for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) { if (shouldIgnoreInstanceTemplate(instanceTemplate)) { continue; } StatementBuilder statementBuilder = new StatementBuilder(); ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec); FirewallManager firewallManager = new FirewallManager( computeServiceContext, clusterSpec, newCluster); VelocityEngine velocityEngine = TemplateUtils.newVelocityEngine(); ClusterActionEvent event = new ClusterActionEvent(getAction(), clusterSpec, instanceTemplate, newCluster, statementBuilder, getCompute(), firewallManager, velocityEngine); eventMap.put(instanceTemplate, event); eventSpecificActions(instanceTemplate, event); for (String role : instanceTemplate.getRoles()) { if (roleIsInTarget(role)) { safeGetActionHandler(role).beforeAction(event); } } newCluster = event.getCluster(); } doAction(eventMap); newCluster = Iterables.get(eventMap.values(), 0).getCluster(); for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) { if (shouldIgnoreInstanceTemplate(instanceTemplate)) { continue; } ClusterActionEvent event = eventMap.get(instanceTemplate); for (String role : instanceTemplate.getRoles()) { if (roleIsInTarget(role)) { event.setCluster(newCluster); safeGetActionHandler(role).afterAction(event); newCluster = event.getCluster(); } } } return newCluster; } protected  ScriptBasedClusterAction(
      Function<ClusterSpec, ComputeServiceContext> getCompute,
      LoadingCache<String, ClusterActionHandler> handlerMap
  ); protected  ScriptBasedClusterAction(
      Function<ClusterSpec, ComputeServiceContext> getCompute,
      LoadingCache<String, ClusterActionHandler> handlerMap,
      Set<String> targetRoles,
      Set<String> targetInstanceIds
  ); Cluster execute(ClusterSpec clusterSpec, Cluster cluster); ListenableFuture<ExecResponse> runStatementOnInstanceInCluster(StatementBuilder statementBuilder,
      Instance instance, ClusterSpec clusterSpec, RunScriptOptions options); }
ScriptBasedClusterAction extends ClusterAction { public Cluster execute(ClusterSpec clusterSpec, Cluster cluster) throws IOException, InterruptedException { if (clusterSpec.getInstanceTemplates().size() == 0) { throw new IllegalArgumentException("No instance templates specified."); } Map<InstanceTemplate, ClusterActionEvent> eventMap = Maps.newHashMap(); Cluster newCluster = cluster; for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) { if (shouldIgnoreInstanceTemplate(instanceTemplate)) { continue; } StatementBuilder statementBuilder = new StatementBuilder(); ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec); FirewallManager firewallManager = new FirewallManager( computeServiceContext, clusterSpec, newCluster); VelocityEngine velocityEngine = TemplateUtils.newVelocityEngine(); ClusterActionEvent event = new ClusterActionEvent(getAction(), clusterSpec, instanceTemplate, newCluster, statementBuilder, getCompute(), firewallManager, velocityEngine); eventMap.put(instanceTemplate, event); eventSpecificActions(instanceTemplate, event); for (String role : instanceTemplate.getRoles()) { if (roleIsInTarget(role)) { safeGetActionHandler(role).beforeAction(event); } } newCluster = event.getCluster(); } doAction(eventMap); newCluster = Iterables.get(eventMap.values(), 0).getCluster(); for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) { if (shouldIgnoreInstanceTemplate(instanceTemplate)) { continue; } ClusterActionEvent event = eventMap.get(instanceTemplate); for (String role : instanceTemplate.getRoles()) { if (roleIsInTarget(role)) { event.setCluster(newCluster); safeGetActionHandler(role).afterAction(event); newCluster = event.getCluster(); } } } return newCluster; } protected  ScriptBasedClusterAction(
      Function<ClusterSpec, ComputeServiceContext> getCompute,
      LoadingCache<String, ClusterActionHandler> handlerMap
  ); protected  ScriptBasedClusterAction(
      Function<ClusterSpec, ComputeServiceContext> getCompute,
      LoadingCache<String, ClusterActionHandler> handlerMap,
      Set<String> targetRoles,
      Set<String> targetInstanceIds
  ); Cluster execute(ClusterSpec clusterSpec, Cluster cluster); ListenableFuture<ExecResponse> runStatementOnInstanceInCluster(StatementBuilder statementBuilder,
      Instance instance, ClusterSpec clusterSpec, RunScriptOptions options);  }