Example usage for com.amazonaws AmazonClientException AmazonClientException

List of usage examples for com.amazonaws AmazonClientException AmazonClientException

Introduction

In this page you can find the example usage for com.amazonaws AmazonClientException AmazonClientException.

Prototype

public AmazonClientException(String message, Throwable t) 

Source Link

Document

Creates a new AmazonClientException with the specified message, and root cause.

Usage

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

License:Apache License

public DescribeImagesResult describeImages(DescribeImagesRequest request) {
    validateEmpty("ExecutableUsers", request.getExecutableUsers());
    List<Filter> filters = request.getFilters();
    String path = "aws/images";
    if (filters != null && filters.size() > 0) {
        if (filters.size() == 1 && filters.get(0) != null && "is-public".equals(filters.get(0).getName())
                && filters.get(0).getValues() != null && filters.get(0).getValues().size() == 1
                && "false".equals(filters.get(0).getValues().get(0))) {
            path = "view/images";
        } else {//from w  w w  .  ja va2s .  c  o m
            throw new UnsupportedOperationException("filters only support is-public=false");
        }
    }

    TypeReference<List<Image>> ref = new TypeReference<List<Image>>() {
    };
    String url = config.url() + "/api/v2/" + path + ";_expand";
    try {
        List<Image> images = parse(ref, doGet(url));

        List<String> owners = request.getOwners();
        List<String> ids = request.getImageIds();
        if (shouldFilter(owners) || shouldFilter(ids)) {
            List<Image> is = new ArrayList<Image>();
            for (Image i : images) {
                if (matches(owners, i.getOwnerId()) && matches(ids, i.getImageId()))
                    is.add(i);
            }
            images = is;
        }

        return new DescribeImagesResult().withImages(images);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

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

License:Apache License

public DescribeInstancesResult describeInstances(DescribeInstancesRequest request) {
    validateEmpty("Filter", request.getFilters());

    TypeReference<List<Reservation>> ref = new TypeReference<List<Reservation>>() {
    };//from   w  w  w. ja  v  a  2  s.c  o  m
    String url = config.url() + "/api/v2/aws/instances;_expand";
    try {
        List<Reservation> reservations = parse(ref, doGet(url));

        List<String> ids = request.getInstanceIds();
        if (shouldFilter(ids)) {
            List<Reservation> rs = new ArrayList<Reservation>();
            for (Reservation r : reservations) {
                List<Instance> is = new ArrayList<Instance>();
                for (Instance i : r.getInstances()) {
                    if (matches(ids, i.getInstanceId()))
                        is.add(i);
                }
                if (is.size() > 0)
                    rs.add(r.withInstances(is));
            }
            reservations = rs;
        }
        return new DescribeInstancesResult().withReservations(reservations);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

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

License:Apache License

public DescribeReservedInstancesOfferingsResult describeReservedInstancesOfferings(
        DescribeReservedInstancesOfferingsRequest request) {
    validateEmpty("Filter", request.getFilters());
    validateEmpty("AvailabilityZone", request.getAvailabilityZone());
    validateEmpty("IncludeMarketplace", request.getIncludeMarketplace());
    validateEmpty("InstanceTenancy", request.getInstanceTenancy());
    validateEmpty("InstanceType", request.getInstanceType());
    validateEmpty("OfferingType", request.getOfferingType());
    validateEmpty("ProductDescription", request.getProductDescription());

    TypeReference<List<ReservedInstancesOffering>> ref = new TypeReference<List<ReservedInstancesOffering>>() {
    };/*w ww .  ja v a 2s .  c o m*/
    String url = config.url() + "/api/v2/aws/reservedInstancesOfferings;_expand";
    try {
        List<ReservedInstancesOffering> reservedInstancesOfferings = parse(ref, doGet(url));

        List<String> ids = request.getReservedInstancesOfferingIds();
        if (shouldFilter(ids)) {
            List<ReservedInstancesOffering> rs = new ArrayList<ReservedInstancesOffering>();
            for (ReservedInstancesOffering r : reservedInstancesOfferings) {
                if (matches(ids, r.getReservedInstancesOfferingId()))
                    rs.add(r);
            }
            reservedInstancesOfferings = rs;
        }
        return new DescribeReservedInstancesOfferingsResult()
                .withReservedInstancesOfferings(reservedInstancesOfferings);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

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

License:Apache License

public DescribeSecurityGroupsResult describeSecurityGroups(DescribeSecurityGroupsRequest request) {
    validateEmpty("Filter", request.getFilters());

    TypeReference<List<SecurityGroup>> ref = new TypeReference<List<SecurityGroup>>() {
    };//from w w  w.  jav a 2s.c  o m
    String url = config.url() + "/api/v2/aws/securityGroups;_expand";
    try {
        List<SecurityGroup> securityGroups = parse(ref, doGet(url));

        List<String> names = request.getGroupNames();
        List<String> ids = request.getGroupIds();
        if (shouldFilter(names) || shouldFilter(ids)) {
            List<SecurityGroup> sgs = new ArrayList<SecurityGroup>();
            for (SecurityGroup sg : securityGroups) {
                if (matches(names, sg.getGroupName()) && matches(ids, sg.getGroupId()))
                    sgs.add(sg);
            }
            securityGroups = sgs;
        }

        return new DescribeSecurityGroupsResult().withSecurityGroups(securityGroups);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

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

License:Apache License

public DescribeSubnetsResult describeSubnets(DescribeSubnetsRequest request) {
    validateEmpty("Filter", request.getFilters());

    TypeReference<List<Subnet>> ref = new TypeReference<List<Subnet>>() {
    };/*www .jav a  2  s  . co m*/
    String url = config.url() + "/api/v2/aws/subnets;_expand";
    try {
        List<Subnet> subnets = parse(ref, doGet(url));

        List<String> ids = request.getSubnetIds();
        if (shouldFilter(ids)) {
            List<Subnet> ss = new ArrayList<Subnet>();
            for (Subnet s : subnets) {
                if (matches(ids, s.getSubnetId()))
                    ss.add(s);
            }
            subnets = ss;
        }

        return new DescribeSubnetsResult().withSubnets(subnets);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

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

License:Apache License

public DescribeVolumesResult describeVolumes(DescribeVolumesRequest request) {
    validateEmpty("Filter", request.getFilters());

    TypeReference<List<Volume>> ref = new TypeReference<List<Volume>>() {
    };/*w w w .  j  av  a2  s .  c om*/
    String url = config.url() + "/api/v2/aws/volumes;_expand";
    try {
        List<Volume> volumes = parse(ref, doGet(url));

        List<String> ids = request.getVolumeIds();
        if (shouldFilter(ids)) {
            List<Volume> vs = new ArrayList<Volume>();
            for (Volume v : volumes) {
                if (matches(ids, v.getVolumeId()))
                    vs.add(v);
            }
            volumes = vs;
        }

        return new DescribeVolumesResult().withVolumes(volumes);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

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

License:Apache License

public DescribeVpcPeeringConnectionsResult describeVpcPeeringConnections(
        DescribeVpcPeeringConnectionsRequest request) {
    validateEmpty("Filter", request.getFilters());

    TypeReference<List<VpcPeeringConnection>> ref = new TypeReference<List<VpcPeeringConnection>>() {
    };//  ww  w  . j  ava 2 s.com
    String url = config.url() + "/api/v2/aws/vpcPeeringConnections;_expand";
    try {
        List<VpcPeeringConnection> vpcs = parse(ref, doGet(url));

        List<String> ids = request.getVpcPeeringConnectionIds();
        if (shouldFilter(ids)) {
            List<VpcPeeringConnection> vs = new ArrayList<VpcPeeringConnection>();
            for (VpcPeeringConnection v : vpcs) {
                if (matches(ids, v.getVpcPeeringConnectionId()))
                    vs.add(v);
            }
            vpcs = vs;
        }

        return new DescribeVpcPeeringConnectionsResult().withVpcPeeringConnections(vpcs);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

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

License:Apache License

public DescribeVpcsResult describeVpcs(DescribeVpcsRequest request) {
    validateEmpty("Filter", request.getFilters());

    TypeReference<List<Vpc>> ref = new TypeReference<List<Vpc>>() {
    };/*from  w  w w .  j  a v  a 2  s. c o  m*/
    String url = config.url() + "/api/v2/aws/vpcs;_expand";
    try {
        List<Vpc> vpcs = parse(ref, doGet(url));

        List<String> ids = request.getVpcIds();
        if (shouldFilter(ids)) {
            List<Vpc> vs = new ArrayList<Vpc>();
            for (Vpc v : vpcs) {
                if (matches(ids, v.getVpcId()))
                    vs.add(v);
            }
            vpcs = vs;
        }

        return new DescribeVpcsResult().withVpcs(vpcs);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

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

License:Apache License

public DescribeVpcClassicLinkResult describeVpcClassicLink(DescribeVpcClassicLinkRequest request) {
    validateEmpty("Filter", request.getFilters());

    TypeReference<List<VpcClassicLink>> ref = new TypeReference<List<VpcClassicLink>>() {
    };//  www.  j  ava2s.co m
    String url = config.url() + "/api/v2/aws/vpcClassicLinks;_expand";
    try {
        List<VpcClassicLink> vpcs = parse(ref, doGet(url));

        List<String> ids = request.getVpcIds();
        if (shouldFilter(ids)) {
            List<VpcClassicLink> vs = new ArrayList<VpcClassicLink>();
            for (VpcClassicLink v : vpcs) {
                if (matches(ids, v.getVpcId()))
                    vs.add(v);
            }
            vpcs = vs;
        }

        return new DescribeVpcClassicLinkResult().withVpcs(vpcs);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

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

License:Apache License

public DescribeInstanceHealthResult describeInstanceHealth(DescribeInstanceHealthRequest request) {
    validateNotEmpty("LoadBalancerName", request.getLoadBalancerName());

    TypeReference<InstanceStateView> ref = new TypeReference<InstanceStateView>() {
    };/*www  .  j a  va 2s. c om*/
    String loadBalancerName = request.getLoadBalancerName();

    String url = config.url() + "/api/v2/view/loadBalancerInstances/" + loadBalancerName + ";_expand";
    try {
        InstanceStateView instanceStateView = parse(ref, doGet(url));
        List<InstanceState> instanceStates = instanceStateView.getInstances();

        List<Instance> instances = request.getInstances();
        List<String> ids = new ArrayList<String>();
        if (instances != null) {
            for (Instance i : instances)
                ids.add(i.getInstanceId());
        }
        if (shouldFilter(ids)) {
            List<InstanceState> iss = new ArrayList<InstanceState>();
            for (InstanceState is : instanceStates) {
                if (matches(ids, is.getInstanceId()))
                    iss.add(is);
            }
            instanceStates = iss;
        }

        return new DescribeInstanceHealthResult().withInstanceStates(instanceStateView.getInstances());
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}