Ejemplo n.º 1
0
 public void createAutoScalingGroup(
     String name, String launchConfigurationName, String loadBalancerName) {
   CreateAutoScalingGroupRequest scalingGroupRequest = new CreateAutoScalingGroupRequest();
   scalingGroupRequest.setAutoScalingGroupName(name);
   scalingGroupRequest.setLaunchConfigurationName(launchConfigurationName);
   //		scalingGroupRequest.setLoadBalancerNames(Arrays
   //				.asList(loadBalancerName));
   scalingGroupRequest.setMaxSize(3);
   scalingGroupRequest.setMinSize(1);
   scalingGroupRequest.setAvailabilityZones(Arrays.asList("us-east-1a", "us-east-1b"));
   scalingClient.createAutoScalingGroup(scalingGroupRequest);
 }
  public static void setUpAutoScaling() {

    System.out.println("Setting up autoscale group..");

    CreateAutoScalingGroupRequest scaleRequest = new CreateAutoScalingGroupRequest();

    scaleRequest.setAutoScalingGroupName("ProjectTwoAutoScaleGroup");
    scaleRequest.setLaunchConfigurationName("ProjectTwoLaunchConfiguration");

    // Start with one instance
    scaleRequest.setMinSize(1);
    scaleRequest.setMaxSize(10);

    // Same zone
    List<String> zones = new ArrayList<String>(1);
    zones.add("us-east-1c");
    scaleRequest.setAvailabilityZones(zones);

    // Choose ELB
    List<String> loadBalancerName = new ArrayList<String>();
    loadBalancerName.add("projecttwoelb");
    scaleRequest.setLoadBalancerNames(loadBalancerName);

    scaleRequest.setHealthCheckType("ELB");
    scaleRequest.setHealthCheckGracePeriod(100);
    scaleRequest.setDefaultCooldown(60);

    // Adding tags
    Collection<com.amazonaws.services.autoscaling.model.Tag> tags =
        new ArrayList<com.amazonaws.services.autoscaling.model.Tag>();

    com.amazonaws.services.autoscaling.model.Tag tag =
        new com.amazonaws.services.autoscaling.model.Tag();
    tag.setKey("Project");
    tag.setValue("2.1");
    tags.add(tag);

    scaleRequest.setTags(tags);

    scaleClient.createAutoScalingGroup(scaleRequest);

    System.out.println("Autoscale group set up successfully..");
    System.out.println("Setting up autoscale policies..");

    setUpPolicies();
  }
Ejemplo n.º 3
0
  private static void setupAutoScale(
      AmazonAutoScalingClient autoScale,
      AmazonCloudWatchClient cloudWatch,
      String keyName,
      String zone,
      String securityGroup,
      String imageId) {

    List<LaunchConfiguration> launchList =
        autoScale.describeLaunchConfigurations().getLaunchConfigurations();
    for (LaunchConfiguration ll : launchList)
      if (ll.getLaunchConfigurationName().equalsIgnoreCase("On DemandAWS")) {
        System.out.println("Using Launch Configuration " + ll.getLaunchConfigurationName());
        return;
      }

    CreateLaunchConfigurationRequest launchConfig = new CreateLaunchConfigurationRequest();
    launchConfig.setImageId(imageId);
    launchConfig.setKeyName(keyName);
    launchConfig.setInstanceType("t1.micro");
    List<String> securityGroups = new ArrayList<String>();
    securityGroups.add(securityGroup);
    launchConfig.setSecurityGroups(securityGroups);
    launchConfig.setLaunchConfigurationName("On DemandAWS");
    autoScale.createLaunchConfiguration(launchConfig);

    CreateAutoScalingGroupRequest autoReq = new CreateAutoScalingGroupRequest();
    autoReq.setLaunchConfigurationName("On DemandAWS");
    List<String> availabilityZones = new ArrayList<String>();
    availabilityZones.add(zone);
    autoReq.setAvailabilityZones(availabilityZones);
    autoReq.setMinSize(1);
    autoReq.setMaxSize(1);
    autoReq.setAutoScalingGroupName("OnDemand ASGroup");
    autoScale.createAutoScalingGroup(autoReq);

    System.out.println("Using Launch Configuration On DemandAWS created");
  }