Ejemplo n.º 1
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");
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof LaunchConfiguration == false) return false;
    LaunchConfiguration other = (LaunchConfiguration) obj;

    if (other.getLaunchConfigurationName() == null ^ this.getLaunchConfigurationName() == null)
      return false;
    if (other.getLaunchConfigurationName() != null
        && other.getLaunchConfigurationName().equals(this.getLaunchConfigurationName()) == false)
      return false;
    if (other.getLaunchConfigurationARN() == null ^ this.getLaunchConfigurationARN() == null)
      return false;
    if (other.getLaunchConfigurationARN() != null
        && other.getLaunchConfigurationARN().equals(this.getLaunchConfigurationARN()) == false)
      return false;
    if (other.getImageId() == null ^ this.getImageId() == null) return false;
    if (other.getImageId() != null && other.getImageId().equals(this.getImageId()) == false)
      return false;
    if (other.getKeyName() == null ^ this.getKeyName() == null) return false;
    if (other.getKeyName() != null && other.getKeyName().equals(this.getKeyName()) == false)
      return false;
    if (other.getSecurityGroups() == null ^ this.getSecurityGroups() == null) return false;
    if (other.getSecurityGroups() != null
        && other.getSecurityGroups().equals(this.getSecurityGroups()) == false) return false;
    if (other.getClassicLinkVPCId() == null ^ this.getClassicLinkVPCId() == null) return false;
    if (other.getClassicLinkVPCId() != null
        && other.getClassicLinkVPCId().equals(this.getClassicLinkVPCId()) == false) return false;
    if (other.getClassicLinkVPCSecurityGroups() == null
        ^ this.getClassicLinkVPCSecurityGroups() == null) return false;
    if (other.getClassicLinkVPCSecurityGroups() != null
        && other.getClassicLinkVPCSecurityGroups().equals(this.getClassicLinkVPCSecurityGroups())
            == false) return false;
    if (other.getUserData() == null ^ this.getUserData() == null) return false;
    if (other.getUserData() != null && other.getUserData().equals(this.getUserData()) == false)
      return false;
    if (other.getInstanceType() == null ^ this.getInstanceType() == null) return false;
    if (other.getInstanceType() != null
        && other.getInstanceType().equals(this.getInstanceType()) == false) return false;
    if (other.getKernelId() == null ^ this.getKernelId() == null) return false;
    if (other.getKernelId() != null && other.getKernelId().equals(this.getKernelId()) == false)
      return false;
    if (other.getRamdiskId() == null ^ this.getRamdiskId() == null) return false;
    if (other.getRamdiskId() != null && other.getRamdiskId().equals(this.getRamdiskId()) == false)
      return false;
    if (other.getBlockDeviceMappings() == null ^ this.getBlockDeviceMappings() == null)
      return false;
    if (other.getBlockDeviceMappings() != null
        && other.getBlockDeviceMappings().equals(this.getBlockDeviceMappings()) == false)
      return false;
    if (other.getInstanceMonitoring() == null ^ this.getInstanceMonitoring() == null) return false;
    if (other.getInstanceMonitoring() != null
        && other.getInstanceMonitoring().equals(this.getInstanceMonitoring()) == false)
      return false;
    if (other.getSpotPrice() == null ^ this.getSpotPrice() == null) return false;
    if (other.getSpotPrice() != null && other.getSpotPrice().equals(this.getSpotPrice()) == false)
      return false;
    if (other.getIamInstanceProfile() == null ^ this.getIamInstanceProfile() == null) return false;
    if (other.getIamInstanceProfile() != null
        && other.getIamInstanceProfile().equals(this.getIamInstanceProfile()) == false)
      return false;
    if (other.getCreatedTime() == null ^ this.getCreatedTime() == null) return false;
    if (other.getCreatedTime() != null
        && other.getCreatedTime().equals(this.getCreatedTime()) == false) return false;
    if (other.getEbsOptimized() == null ^ this.getEbsOptimized() == null) return false;
    if (other.getEbsOptimized() != null
        && other.getEbsOptimized().equals(this.getEbsOptimized()) == false) return false;
    if (other.getAssociatePublicIpAddress() == null ^ this.getAssociatePublicIpAddress() == null)
      return false;
    if (other.getAssociatePublicIpAddress() != null
        && other.getAssociatePublicIpAddress().equals(this.getAssociatePublicIpAddress()) == false)
      return false;
    if (other.getPlacementTenancy() == null ^ this.getPlacementTenancy() == null) return false;
    if (other.getPlacementTenancy() != null
        && other.getPlacementTenancy().equals(this.getPlacementTenancy()) == false) return false;
    return true;
  }