Search in sources :

Example 1 with FirewallManager

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));
}
Also used : FirewallManager(org.apache.whirr.service.FirewallManager) Cluster(org.apache.whirr.Cluster) Credentials(org.jclouds.domain.Credentials) Before(org.junit.Before)

Example 2 with FirewallManager

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;
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) FirewallManager(org.apache.whirr.service.FirewallManager) StatementBuilder(org.apache.whirr.service.jclouds.StatementBuilder) Cluster(org.apache.whirr.Cluster) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) ClusterActionEvent(org.apache.whirr.service.ClusterActionEvent) InstanceTemplate(org.apache.whirr.InstanceTemplate)

Aggregations

Cluster (org.apache.whirr.Cluster)2 FirewallManager (org.apache.whirr.service.FirewallManager)2 VelocityEngine (org.apache.velocity.app.VelocityEngine)1 InstanceTemplate (org.apache.whirr.InstanceTemplate)1 ClusterActionEvent (org.apache.whirr.service.ClusterActionEvent)1 StatementBuilder (org.apache.whirr.service.jclouds.StatementBuilder)1 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)1 Credentials (org.jclouds.domain.Credentials)1 Before (org.junit.Before)1