use of org.apache.whirr.service.FirewallManager in project whirr by apache.
the class FirewallManagerTest method setUpClass.
@Before
public void setUpClass() throws Exception {
clusterSpec = getTestClusterSpec();
context = ComputeCache.INSTANCE.apply(clusterSpec);
/* create a dummy instance for testing */
instances = Sets.newHashSet(new Cluster.Instance(new Credentials("dummy", "dummy"), Sets.newHashSet("dummy-role"), "50.0.0.1", "10.0.0.1", region + "/i-dummy", null));
manager = new FirewallManager(context, clusterSpec, new Cluster(instances));
}
use of org.apache.whirr.service.FirewallManager in project whirr by apache.
the class ScriptBasedClusterAction method execute.
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)) {
// skip execution if this group of instances is not in target
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);
}
}
// cluster may have been updated by handler
newCluster = event.getCluster();
}
doAction(eventMap);
// cluster may have been updated by action
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);
// cluster may have been updated by handler
newCluster = event.getCluster();
}
}
}
return newCluster;
}
Aggregations