Example usage for com.amazonaws.services.elasticloadbalancing.model Instance getInstanceId

List of usage examples for com.amazonaws.services.elasticloadbalancing.model Instance getInstanceId

Introduction

In this page you can find the example usage for com.amazonaws.services.elasticloadbalancing.model Instance getInstanceId.

Prototype


public String getInstanceId() 

Source Link

Document

The instance ID.

Usage

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.ElbDetail.java

License:Open Source License

private void buildUI(DescribeLoadBalancersResult detail) {

    JTabbedPane tabs = new JTabbedPane();

    tabs.add("Load Balancer", primaryScrollPane);

    final JTable healthCheckTable = new JTable(healthCheckTableModel);
    JScrollPane healthCheckScrollPane = new JScrollPane(healthCheckTable);
    tabs.add("Health Check", healthCheckScrollPane);

    final JTable listenersTable = new JTable(listenersTableModel);
    JScrollPane listenersScrollPane = new JScrollPane(listenersTable);
    tabs.add("Listeners", listenersScrollPane);

    this.add(tabs, BorderLayout.CENTER);

    List<LoadBalancerDescription> elbs = detail.getLoadBalancerDescriptions();
    if (!elbs.isEmpty()) {

        LoadBalancerDescription elb = elbs.get(0);

        if (!elb.getAvailabilityZones().isEmpty()) {

            StringBuilder azs = new StringBuilder();
            for (String az : elb.getAvailabilityZones()) {
                azs.append(az).append(", ");
            }//ww w  . j  a v  a2 s  .c  om

            primaryTableModel.addRow(new Object[] { "Availability Zones", azs.toString() });
        }

        if (elb.getCanonicalHostedZoneName() != null) {
            primaryTableModel
                    .addRow(new Object[] { "Canonical Hosted Zone name", elb.getCanonicalHostedZoneName() });
        }
        if (elb.getCanonicalHostedZoneNameID() != null) {
            primaryTableModel.addRow(
                    new Object[] { "Canonical Hosted Zone name Id", elb.getCanonicalHostedZoneNameID() });
        }
        if (elb.getCreatedTime() != null) {
            primaryTableModel.addRow(new Object[] { "Created", elb.getCreatedTime() });
        }
        if (elb.getDNSName() != null) {
            primaryTableModel.addRow(new Object[] { "DNS Name", elb.getDNSName() });
        }

        if (!elb.getInstances().isEmpty()) {

            StringBuilder instances = new StringBuilder();
            for (Instance instance : elb.getInstances()) {
                instances.append(instance.getInstanceId()).append(", ");
            }

            primaryTableModel.addRow(new Object[] { "Instances", instances.toString() });
        }

        if (elb.getLoadBalancerName() != null) {
            primaryTableModel.addRow(new Object[] { "Load Balander Name", elb.getLoadBalancerName() });
        }
        if (elb.getScheme() != null) {
            primaryTableModel.addRow(new Object[] { "Scheme", elb.getScheme() });
        }

        if (!elb.getSecurityGroups().isEmpty()) {

            StringBuilder sgs = new StringBuilder();
            for (String sg : elb.getSecurityGroups()) {
                sgs.append(sg).append(", ");
            }

            primaryTableModel.addRow(new Object[] { "Security Groups", sgs.toString() });
        }

        if (elb.getSourceSecurityGroup() != null) {
            primaryTableModel.addRow(
                    new Object[] { "Source Security Group", elb.getSourceSecurityGroup().getGroupName() });
        }

        if (!elb.getSubnets().isEmpty()) {

            StringBuilder subnets = new StringBuilder();
            for (String subnet : elb.getSubnets()) {
                subnets.append(subnet).append(", ");
            }

            primaryTableModel.addRow(new Object[] { "Subnets", subnets.toString() });
        }

        if (elb.getVPCId() != null) {
            primaryTableModel.addRow(new Object[] { "VPC Id", elb.getVPCId() });
        }

        /**
         * Health Check
         */

        healthCheckTableModel.addColumn("Property");
        healthCheckTableModel.addColumn("Value");

        HealthCheck healthCheck = elb.getHealthCheck();
        if (healthCheck.getHealthyThreshold() != null) {
            healthCheckTableModel.addRow(new Object[] { "Threshold", healthCheck.getHealthyThreshold() });
        }
        if (healthCheck.getInterval() != null) {
            healthCheckTableModel.addRow(new Object[] { "Interval", healthCheck.getInterval() });
        }
        if (healthCheck.getTarget() != null) {
            healthCheckTableModel.addRow(new Object[] { "Target", healthCheck.getTarget() });
        }
        if (healthCheck.getTimeout() != null) {
            healthCheckTableModel.addRow(new Object[] { "Timeout", healthCheck.getTimeout() });
        }
        if (healthCheck.getUnhealthyThreshold() != null) {
            healthCheckTableModel
                    .addRow(new Object[] { "Unhealth Threshold", healthCheck.getUnhealthyThreshold() });
        }

        /**
         * Listeners
         */

        listenersTableModel.addColumn("Instance Port");
        listenersTableModel.addColumn("Instance Protocol");
        listenersTableModel.addColumn("Load Balancer Port");
        listenersTableModel.addColumn("Load Balancer Protocol");
        listenersTableModel.addColumn("SSL Certificate Id");

        List<ListenerDescription> listenerDescriptions = elb.getListenerDescriptions();
        for (ListenerDescription description : listenerDescriptions) {

            Listener listener = description.getListener();

            String ssl = "";
            if (listener.getSSLCertificateId() != null) {
                ssl = listener.getSSLCertificateId();
            }

            listenersTableModel
                    .addRow(new Object[] { listener.getInstancePort(), listener.getInstanceProtocol(),
                            listener.getLoadBalancerPort(), listener.getProtocol(), ssl });
        }
    }
}

From source file:com.mentation.alfonso.aws.ElasticLoadBalancer.java

License:Apache License

public boolean attachInstance(String instanceId) {
    Instance instance = new Instance(instanceId);

    List<Instance> instances = new ArrayList<>();
    instances.add(instance);/* w ww  .j  a v a 2s. c o  m*/

    System.out
            .println("Attempting to attach instance " + instance.getInstanceId() + " to " + getName() + " ELB");

    RegisterInstancesWithLoadBalancerRequest registerInstancesWithLoadBalancerRequest = new RegisterInstancesWithLoadBalancerRequest(
            _name, instances);

    RegisterInstancesWithLoadBalancerResult result = _elbClient
            .registerInstancesWithLoadBalancer(registerInstancesWithLoadBalancerRequest);

    if (result.getInstances().contains(instance)) {
        _instance = instance;
        return true;
    }

    return false;
}

From source file:com.mentation.alfonso.aws.ElasticLoadBalancer.java

License:Apache License

public boolean detachInstance() {
    List<Instance> instances = new ArrayList<>();
    instances.add(_instance);/*from   ww w  .  j a  v  a 2 s  .c o m*/
    System.out.println("Attempt to deregister " + _instance.getInstanceId());

    DeregisterInstancesFromLoadBalancerRequest deregisterInstancesFromLoadBalancerRequest = new DeregisterInstancesFromLoadBalancerRequest(
            _name, instances);

    DeregisterInstancesFromLoadBalancerResult deregisterInstancesFromLoadBalancerResult = _elbClient
            .deregisterInstancesFromLoadBalancer(deregisterInstancesFromLoadBalancerRequest);

    System.out.println(deregisterInstancesFromLoadBalancerResult.getInstances());

    for (Instance instance : deregisterInstancesFromLoadBalancerResult.getInstances()) {
        if (instance.getInstanceId().equals(_instance.getInstanceId())) {
            return false;
        }
    }

    _instance = null;

    return true;
}

From source file:com.mentation.alfonso.aws.ElasticLoadBalancer.java

License:Apache License

public String getInstanceId() {
    Instance inst = _instance;

    return inst == null ? "" : inst.getInstanceId();
}

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>() {
    };/*from   w ww .  ja v  a2  s.c o m*/
    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);
    }
}

From source file:com.netflix.simianarmy.aws.janitor.crawler.ELBJanitorCrawler.java

License:Apache License

private List<Resource> getELBResources(String... elbNames) {
    List<Resource> resources = new LinkedList<Resource>();
    AWSClient awsClient = getAWSClient();

    for (LoadBalancerDescription elb : awsClient.describeElasticLoadBalancers(elbNames)) {
        Resource resource = new AWSResource().withId(elb.getLoadBalancerName())
                .withRegion(getAWSClient().region()).withResourceType(AWSResourceType.ELB)
                .withLaunchTime(elb.getCreatedTime());
        resource.setOwnerEmail(getOwnerEmailForResource(resource));
        resources.add(resource);//  w w w.j  a  v  a 2  s  .  co  m
        List<Instance> instances = elb.getInstances();
        if (instances == null || instances.size() == 0) {
            resource.setAdditionalField("instanceCount", "0");
            resource.setDescription("instances=none");
            LOGGER.debug(String.format("No instances found for ELB %s", resource.getId()));
        } else {
            resource.setAdditionalField("instanceCount", "" + instances.size());
            ArrayList<String> instanceList = new ArrayList<String>(instances.size());
            LOGGER.debug(String.format("Found %d instances for ELB %s", instances.size(), resource.getId()));
            for (Instance instance : instances) {
                String instanceId = instance.getInstanceId();
                instanceList.add(instanceId);
            }
            String instancesStr = StringUtils.join(instanceList, ",");
            resource.setDescription(String.format("instances=%s", instances));
            LOGGER.debug(String.format("Resource ELB %s has instances %s", resource.getId(), instancesStr));
        }

        for (TagDescription tagDescription : awsClient.describeElasticLoadBalancerTags(resource.getId())) {
            for (Tag tag : tagDescription.getTags()) {
                LOGGER.debug(String.format("Adding tag %s = %s to resource %s", tag.getKey(), tag.getValue(),
                        resource.getId()));
                resource.setTag(tag.getKey(), tag.getValue());
            }
        }
    }

    Map<String, List<String>> elbtoASGMap = buildELBtoASGMap();
    for (Resource resource : resources) {
        List<String> asgList = elbtoASGMap.get(resource.getId());
        if (asgList != null && asgList.size() > 0) {
            resource.setAdditionalField("referencedASGCount", "" + asgList.size());
            String asgStr = StringUtils.join(asgList, ",");
            resource.setDescription(resource.getDescription() + ", ASGS=" + asgStr);
            LOGGER.debug(String.format("Resource ELB %s is referenced by ASGs %s", resource.getId(), asgStr));
        } else {
            resource.setAdditionalField("referencedASGCount", "0");
            resource.setDescription(resource.getDescription() + ", ASGS=none");
            LOGGER.debug(String.format("No ASGs found for ELB %s", resource.getId()));
        }
    }

    return resources;
}

From source file:com.swap.aws.elb.client.AWSHelper.java

License:Apache License

public Instance getInstanceByIP(String ip) {
    DescribeInstancesRequest request = new DescribeInstancesRequest();

    //      List<Filter> filters = new ArrayList<Filter>();
    ///*from  w w  w  .j av a  2  s .com*/
    //      List<String> ips = new ArrayList<String>();
    //      ips.add(ip);
    //      
    //      Filter ipFilter = new Filter("ip-address", ips);
    //      filters.add(ipFilter);

    //      List<String> zones = new ArrayList<String>();
    //      zones.add("us-east-1c");
    //      Filter zoneFilter = new Filter("availability-zone", zones);
    //      filters.add(zoneFilter);

    //request.setFilters(filters);

    AmazonElasticLoadBalancingClient lbClient = new AmazonElasticLoadBalancingClient(awsCredentials,
            clientConfiguration);

    AmazonEC2Client cl = new AmazonEC2Client(awsCredentials);

    DescribeInstancesResult result = cl.describeInstances(request);

    List<Reservation> reservations = result.getReservations();

    for (Reservation reservation : reservations) {
        List<com.amazonaws.services.ec2.model.Instance> instances = reservation.getInstances();

        for (com.amazonaws.services.ec2.model.Instance instance : instances) {

            System.out.println(instance.getInstanceId());

            //return transformInstace(instance);
        }
    }

    return null;

}

From source file:com.swap.aws.elb.client.AWSHelper.java

License:Apache License

public Instance transformInstace(com.amazonaws.services.ec2.model.Instance ec2Instance) {
    Instance elbInstance = new Instance();
    elbInstance.setInstanceId(ec2Instance.getInstanceId());
    return elbInstance;
}

From source file:org.apache.stratos.aws.extension.AWSHelper.java

License:Apache License

/**
 * Attaches provided instances to the load balancer. Useful when new
 * instances get added to the cluster with which this load balancer is
 * associated.//  www  .  j ava2s  .  co m
 *
 * @param loadBalancerName
 * @param instances        to attached to the load balancer
 * @param region           of the load balancer
 */
public void registerInstancesToLoadBalancer(String loadBalancerName, List<Instance> instances, String region) {

    log.info("Registering following instance(s) to load balancer " + loadBalancerName);

    for (Instance instance : instances) {
        log.info(instance.getInstanceId());
    }

    RegisterInstancesWithLoadBalancerRequest registerInstancesWithLoadBalancerRequest = new RegisterInstancesWithLoadBalancerRequest(
            loadBalancerName, instances);

    RegisterInstancesWithLoadBalancerResult registerInstancesWithLBRes = null;

    try {
        elbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));

        registerInstancesWithLBRes = elbClient
                .registerInstancesWithLoadBalancer(registerInstancesWithLoadBalancerRequest);

    } catch (AmazonClientException e) {
        log.error("Could not register instances to load balancer " + loadBalancerName, e);
    }

    if (registerInstancesWithLBRes != null && registerInstancesWithLBRes.getInstances().size() > 0) {
        log.info("Total instances attached to the LB " + loadBalancerName + " : "
                + registerInstancesWithLBRes.getInstances().size());

    } else {
        log.warn("No instances attached to the LB " + loadBalancerName);
    }
}

From source file:org.apache.stratos.aws.extension.AWSHelper.java

License:Apache License

/**
 * Detaches provided instances from the load balancer, associated with some
 * cluster. Useful when instances are removed from the cluster with which
 * this load balancer is associated.//from  ww w  . ja  v  a  2  s.c  om
 *
 * @param loadBalancerName
 * @param instances        to be de-registered from load balancer
 * @param region           of the load balancer
 */
public void deregisterInstancesFromLoadBalancer(String loadBalancerName, List<Instance> instances,
        String region) {

    log.info("De-registering following instance(s) from load balancer " + loadBalancerName);

    for (Instance instance : instances) {
        log.info(instance.getInstanceId());
    }

    DeregisterInstancesFromLoadBalancerRequest deregisterInstancesFromLoadBalancerRequest = new DeregisterInstancesFromLoadBalancerRequest(
            loadBalancerName, instances);

    try {
        elbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));

        elbClient.deregisterInstancesFromLoadBalancer(deregisterInstancesFromLoadBalancerRequest);

    } catch (AmazonClientException e) {
        log.error("Could not de-register instances from load balancer " + loadBalancerName, e);
    }
}