Example usage for com.amazonaws.services.autoscaling.model ScalingPolicy getPolicyName

List of usage examples for com.amazonaws.services.autoscaling.model ScalingPolicy getPolicyName

Introduction

In this page you can find the example usage for com.amazonaws.services.autoscaling.model ScalingPolicy getPolicyName.

Prototype


public String getPolicyName() 

Source Link

Document

The name of the scaling policy.

Usage

From source file:com.eucalyptus.tests.awssdk.CloudCleaner.java

License:Open Source License

@Test
public void clean() throws Exception {
    testInfo(this.getClass().getSimpleName());
    getCloudInfo();/*from ww w  .j  a  v  a 2  s.  c o m*/

    //Terminate All instances
    List<String> instancesToTerminate = new ArrayList<String>();
    DescribeInstancesResult result = ec2.describeInstances();
    List<Reservation> reservations = result.getReservations();
    if (reservations.size() > 0) {
        print("Found instances to terminate");
        for (Reservation reservation : reservations) {
            List<Instance> instances = reservation.getInstances();
            for (Instance instance : instances) {
                print("Terminating: " + instance.getInstanceId());
                instancesToTerminate.add(instance.getInstanceId());
            }
        }
        TerminateInstancesRequest term = new TerminateInstancesRequest();
        term.setInstanceIds(instancesToTerminate);
        ec2.terminateInstances(term);
    } else {
        print("No instances found");
    }

    // delete all keypairs
    if (getKeyPairCount() > 0) {
        print("Found Keypairs to delete");
        DescribeKeyPairsResult describeKeyPairsResult = ec2.describeKeyPairs();
        for (KeyPairInfo keypair : describeKeyPairsResult.getKeyPairs()) {
            deleteKeyPair(keypair.getKeyName());
        }
    } else {
        print("No keypairs found");
    }

    // delete all groups except default group
    List<SecurityGroup> groups = describeSecurityGroups();
    if (groups.size() > 1) {
        print("Found security groups to delete");
        for (SecurityGroup group : groups) {
            if (!group.getGroupName().equals("default")) {
                deleteSecurityGroup(group.getGroupName());
            }
        }
    } else {
        print("No Security Groups found (other than default)");
    }

    // delete all policies
    List<ScalingPolicy> policies = describePolicies();
    if (policies.size() > 0) {
        print("Found Policies to delete");
        for (ScalingPolicy policy : policies) {
            deletePolicy(policy.getPolicyName());
        }
    } else {
        print("No auto scaling policies found");
    }

    // delete launch configs
    List<LaunchConfiguration> lcs = describeLaunchConfigs();
    if (lcs.size() > 0) {
        print("Found Launch Configs to delete");
        for (LaunchConfiguration lc : lcs) {
            deleteLaunchConfig(lc.getLaunchConfigurationName());
        }
    } else {
        print("No launch configs found");
    }

    // delete autoscaling groups
    List<AutoScalingGroup> asGroups = describeAutoScalingGroups();
    if (asGroups.size() > 0) {
        print("Found Auto Scaling Groups to delete");
        for (AutoScalingGroup asg : asGroups) {
            deleteAutoScalingGroup(asg.getAutoScalingGroupName(), true);
        }
    } else {
        print("No auto scaling groups found");
    }

    // delete volumes
    List<Volume> volumes = ec2.describeVolumes().getVolumes();
    if (volumes.size() > 0) {
        print("Found volumes to delete");
        for (Volume vol : volumes) {
            deleteVolume(vol.getVolumeId());
        }
    } else {
        print("No volumes found");
    }

    //delete snapshots
    List<Snapshot> snapshots = ec2.describeSnapshots().getSnapshots();
    if (snapshots.size() > 0) {
        print("Found snapshots to delete");
        for (Snapshot snap : snapshots) {
            deleteSnapshot(snap.getSnapshotId());
        }
    } else {
        print("No volumes found");
    }
}

From source file:com.netflix.edda.EddaAutoScalingClient.java

License:Apache License

public DescribePoliciesResult describePolicies(DescribePoliciesRequest request) {
    TypeReference<List<ScalingPolicy>> ref = new TypeReference<List<ScalingPolicy>>() {
    };/* w  w w  . jav  a 2  s  . c  o  m*/
    String url = config.url() + "/api/v2/aws/scalingPolicies;_expand";
    try {
        List<ScalingPolicy> scalingPolicies = parse(ref, doGet(url));

        String asg = request.getAutoScalingGroupName();
        List<String> names = request.getPolicyNames();
        if (shouldFilter(asg) || shouldFilter(names)) {
            List<ScalingPolicy> sps = new ArrayList<ScalingPolicy>();
            for (ScalingPolicy sp : scalingPolicies) {
                if (matches(asg, sp.getAutoScalingGroupName()) && matches(names, sp.getPolicyName()))
                    sps.add(sp);
            }
            scalingPolicies = sps;
        }

        return new DescribePoliciesResult().withScalingPolicies(scalingPolicies);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

From source file:com.pinterest.arcee.autoscaling.AwsAutoScaleGroupManager.java

License:Apache License

@Override
public Map<String, ScalingPolicyBean> getScalingPoliciesForGroup(String groupName) throws Exception {
    Map<String, ScalingPolicyBean> policyBeans = new HashMap<>();
    try {//from   w  w  w  . ja v  a  2 s .  co m
        DescribePoliciesRequest request = new DescribePoliciesRequest();
        request.setAutoScalingGroupName(groupName);
        DescribePoliciesResult result = aasClient.describePolicies(request);
        List<ScalingPolicy> policySet = result.getScalingPolicies();
        for (ScalingPolicy policy : policySet) {
            ScalingPolicyBean bean = new ScalingPolicyBean();
            bean.setCoolDownTime(policy.getCooldown() / 60);
            bean.setScalingType(policy.getAdjustmentType());
            bean.setPolicyName(policy.getPolicyName());
            bean.setScaleSize(policy.getScalingAdjustment());
            bean.setARN(policy.getPolicyARN());
            policyBeans.put(bean.getPolicyName(), bean);
        }
        return policyBeans;
    } catch (com.amazonaws.AmazonServiceException e) {
        return policyBeans;
    }
}