Package org.apache.whirr.service

Examples of org.apache.whirr.service.ClusterActionEvent


      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;
View Full Code Here


      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);
      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;
View Full Code Here

  /**
   * Apply the firewall rules specified via configuration.
   */
  protected void eventSpecificActions(Entry<InstanceTemplate, ClusterActionEvent> entry)
      throws IOException {
    ClusterActionEvent event = entry.getValue();
    ClusterSpec clusterSpec = event.getClusterSpec();
   
    Map<String, List<String>> firewallRules = clusterSpec.getFirewallRules();
    for (String role: firewallRules.keySet()) {
      if (!roleIsInTarget(role)) {
        continue;   // skip execution for this role
      }
      Rule rule = Rule.create();
     
      if (role == null) {
        rule.destination(event.getCluster().getInstances());
      } else {
        rule.destination(RolePredicates.role(role));
      }
     
      List<String> ports = firewallRules.get(role);
      rule.ports(Ints.toArray(Collections2.transform(ports, new Function<String,Integer>() {
        @Override
        public Integer apply(String input) {
          return Integer.valueOf(input);
        }
      })));

      event.getFirewallManager().addRule(rule);
    }
  }
View Full Code Here

    Map<InstanceTemplate, ClusterActionEvent> eventMap = Maps.newHashMap();
    Cluster newCluster = cluster;
    for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) {
      StatementBuilder statementBuilder = new StatementBuilder();
      statementBuilder.addStatement(Statements.call("installRunUrl"));
      ClusterActionEvent event = new ClusterActionEvent(getAction(),
          clusterSpec, newCluster, statementBuilder);
      eventMap.put(instanceTemplate, event);
      for (String role : instanceTemplate.getRoles()) {
        ClusterActionHandler handler = handlerMap.get(role);
        if (handler == null) {
          throw new IllegalArgumentException("No handler for role " + role);
        }
        handler.beforeAction(event);
      }
      newCluster = event.getCluster(); // cluster may have been updated by handler
    }
   
    doAction(eventMap);
   
    // cluster may have been updated by action
    newCluster = Iterables.get(eventMap.values(), 0).getCluster();

    for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) {
      for (String role : instanceTemplate.getRoles()) {
        ClusterActionHandler handler = handlerMap.get(role);
        if (handler == null) {
          throw new IllegalArgumentException("No handler for role " + role);
        }
        ClusterActionEvent event = eventMap.get(instanceTemplate);
        event.setCluster(newCluster);
        handler.afterAction(event);
        newCluster = event.getCluster(); // cluster may have been updated by handler
      }
    }
   
    return newCluster;
  }
View Full Code Here

      ComputeServiceContext computServiceContext = getCompute().apply(clusterSpec);
      FirewallManager firewallManager = new FirewallManager(computServiceContext,
          clusterSpec, newCluster);

      ClusterActionEvent event = new ClusterActionEvent(getAction(),
          clusterSpec, newCluster, statementBuilder, getCompute(), firewallManager);

      eventMap.put(instanceTemplate, event);
      for (String role : instanceTemplate.getRoles()) {
        ClusterActionHandler handler = handlerMap.get(role);
        if (handler == null) {
          throw new IllegalArgumentException("No handler for role " + role);
        }
        handler.beforeAction(event);
      }
      newCluster = event.getCluster(); // cluster may have been updated by handler
    }
   
    doAction(eventMap);
   
    // cluster may have been updated by action
    newCluster = Iterables.get(eventMap.values(), 0).getCluster();

    for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) {
      for (String role : instanceTemplate.getRoles()) {
        ClusterActionHandler handler = handlerMap.get(role);
        if (handler == null) {
          throw new IllegalArgumentException("No handler for role " + role);
        }
        ClusterActionEvent event = eventMap.get(instanceTemplate);
        event.setCluster(newCluster);
        handler.afterAction(event);
        newCluster = event.getCluster(); // cluster may have been updated by handler
      }
    }
   
    return newCluster;
  }
View Full Code Here

  /**
   * Apply the firewall rules specified via configuration.
   */
  protected void eventSpecificActions(Entry<InstanceTemplate, ClusterActionEvent> entry)
      throws IOException {
    ClusterActionEvent event = entry.getValue();
    ClusterSpec clusterSpec = event.getClusterSpec();
   
    Map<String, List<String>> firewallRules = clusterSpec.getFirewallRules();
    for (String role: firewallRules.keySet()) {
      Rule rule = Rule.create();
     
      if (role == null) {
        rule.destination(event.getCluster().getInstances());
      } else {
        rule.destination(RolePredicates.role(role));
      }
     
      List<String> ports = firewallRules.get(role);
      rule.ports(Ints.toArray(Collections2.transform(ports, new Function<String,Integer>() {
        @Override
        public Integer apply(String input) {
          return Integer.valueOf(input);
        }
      })));

      event.getFirewallManager().addRule(rule);
    }
  }
View Full Code Here

      ComputeServiceContext computeServiceContext = getCompute().apply(
          clusterSpec);
      FirewallManager firewallManager = new FirewallManager(
          computeServiceContext, clusterSpec, newCluster);

      ClusterActionEvent event = new ClusterActionEvent(getAction(),
          clusterSpec, instanceTemplate, newCluster, statementBuilder,
          getCompute(), firewallManager);

      eventMap.put(instanceTemplate, event);
      for (String role : instanceTemplate.getRoles()) {
        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()) {
      ClusterActionEvent event = eventMap.get(instanceTemplate);
      for (String role : instanceTemplate.getRoles()) {
        event.setCluster(newCluster);
        safeGetActionHandler(role).afterAction(event);

        // cluster may have been updated by handler
        newCluster = event.getCluster();
      }
    }

    return newCluster;
  }
View Full Code Here

    Map<InstanceTemplate, ClusterActionEvent> eventMap = Maps.newHashMap();
    Cluster newCluster = cluster;
    for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) {
      StatementBuilder statementBuilder = new StatementBuilder();
      statementBuilder.addStatement(Statements.call("install_runurl"));
      ClusterActionEvent event = new ClusterActionEvent(getAction(),
          clusterSpec, newCluster, statementBuilder);
      eventMap.put(instanceTemplate, event);
      for (String role : instanceTemplate.getRoles()) {
        ClusterActionHandler handler = handlerMap.get(role);
        if (handler == null) {
          throw new IllegalArgumentException("No handler for role " + role);
        }
        handler.beforeAction(event);
      }
      newCluster = event.getCluster(); // cluster may have been updated by handler
    }
   
    doAction(eventMap);
   
    // cluster may have been updated by action
    newCluster = Iterables.get(eventMap.values(), 0).getCluster();

    for (InstanceTemplate instanceTemplate : clusterSpec.getInstanceTemplates()) {
      for (String role : instanceTemplate.getRoles()) {
        ClusterActionHandler handler = handlerMap.get(role);
        if (handler == null) {
          throw new IllegalArgumentException("No handler for role " + role);
        }
        ClusterActionEvent event = eventMap.get(instanceTemplate);
        event.setCluster(newCluster);
        handler.afterAction(event);
        newCluster = event.getCluster(); // cluster may have been updated by handler
      }
    }
   
    return newCluster;
  }
View Full Code Here

TOP

Related Classes of org.apache.whirr.service.ClusterActionEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.