Example usage for com.amazonaws.services.elasticloadbalancing.model LoadBalancerDescription getLoadBalancerName

List of usage examples for com.amazonaws.services.elasticloadbalancing.model LoadBalancerDescription getLoadBalancerName

Introduction

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

Prototype


public String getLoadBalancerName() 

Source Link

Document

The name of the load balancer.

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(", ");
            }//w  ww .j  a v  a  2  s . c  o  m

            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.kixeye.chassis.bootstrap.aws.ServerInstanceContext.java

License:Apache License

private ListenerDescription getExhibitorListenerDescription(LoadBalancerDescription loadBalancer) {
    for (ListenerDescription listenerDescription : loadBalancer.getListenerDescriptions()) {
        if (listenerDescription.getListener().getProtocol().toLowerCase().equals("http")) {
            return listenerDescription;
        }//www .  ja v a 2 s. co m
    }

    throw new BootstrapException(
            "Unable to find any listeners which supports http on ELB " + loadBalancer.getLoadBalancerName());
}

From source file:com.kixeye.chassis.bootstrap.aws.ZookeeperElbFilter.java

License:Apache License

@Override
public boolean accept(LoadBalancerDescription loadBalancer) {

    String[] pieces = loadBalancer.getLoadBalancerName().split("-");

    if (pieces.length < 2) {
        return false;
    }//from ww w . j ava2  s  .com
    // match ENV-Zoo* (Cloud Formation naming scheme)
    if (pieces[0].equalsIgnoreCase(environment) && pieces[1].startsWith("Zoo")) {
        return true;
    }
    // match exhibitor-ENV-internal (Original naming scheme)
    if (pieces.length == 3 && pieces[0].equalsIgnoreCase("exhibitor") && pieces[1].equalsIgnoreCase(environment)
            && pieces[2].equalsIgnoreCase("internal")) {
        return true;
    }

    return false;

}

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

License:Apache License

public DescribeLoadBalancersResult describeLoadBalancers(DescribeLoadBalancersRequest request) {
    TypeReference<List<LoadBalancerDescription>> ref = new TypeReference<List<LoadBalancerDescription>>() {
    };//  w  ww  . ja v  a2s .c o m
    String url = config.url() + "/api/v2/aws/loadBalancers;_expand";
    try {
        List<LoadBalancerDescription> loadBalancerDescriptions = parse(ref, doGet(url));

        List<String> names = request.getLoadBalancerNames();
        if (shouldFilter(names)) {
            List<LoadBalancerDescription> lbs = new ArrayList<LoadBalancerDescription>();
            for (LoadBalancerDescription lb : loadBalancerDescriptions) {
                if (matches(names, lb.getLoadBalancerName()))
                    lbs.add(lb);
            }
            loadBalancerDescriptions = lbs;
        }

        return new DescribeLoadBalancersResult().withLoadBalancerDescriptions(loadBalancerDescriptions);
    } 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);/*  ww w. jav  a  2s .  com*/
        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.netflix.simianarmy.resources.chaos.ChaosMonkeyResource.java

License:Apache License

@Path("/Gorilla")
@GET//from  w  w  w  .  ja  va  2s. c o m
public Response getELB(@Context UriInfo uriInfo) throws IOException {

    String elbName = "";
    for (Map.Entry<String, List<String>> pair : uriInfo.getQueryParameters().entrySet()) {
        if (pair.getValue().isEmpty()) {
            continue;
        }
        if (pair.getKey().equals("elbName")) {
            elbName = pair.getValue().get(0);
        }
    }

    AWSClient client;
    client = new AWSClient(Region.US_WEST_2);
    LOGGER.info(String.format("Get instances and AZ of ELB '%s'", elbName));

    List<LoadBalancerDescription> elbDescriptionList = client.describeElasticLoadBalancers(elbName);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JsonGenerator gen = JSON_FACTORY.createJsonGenerator(baos, JsonEncoding.UTF8);

    for (LoadBalancerDescription elbDescription : elbDescriptionList) {

        gen.writeStartObject();
        gen.writeStringField("load_balancer_name", elbDescription.getLoadBalancerName());

        //          Find and add availability zones instances attached to ELB
        StringBuilder sbuild = new StringBuilder();
        List<String> AZList = elbDescription.getAvailabilityZones();
        for (int i = 0; i < AZList.size(); i++) {
            sbuild.append(AZList.get(i));
            if (i != AZList.size() - 1)
                sbuild.append(",");
        }

        gen.writeStringField("availability_zones", sbuild.toString());

        //          Find and add ec2 instances attached to ELB
        sbuild = new StringBuilder();
        List<Instance> InstanceList = elbDescription.getInstances();
        for (int i = 0; i < InstanceList.size(); i++) {
            sbuild.append(InstanceList.get(i).getInstanceId());
            if (i != InstanceList.size() - 1)
                sbuild.append(",");
        }
        gen.writeStringField("ec2_instances", sbuild.toString());

        gen.writeEndObject();
    }
    gen.close();
    return Response.status(Response.Status.OK).entity(baos.toString("UTF-8")).build();

}

From source file:com.netflix.spinnaker.clouddriver.aws.deploy.handlers.MigrateLoadBalancerStrategy.java

License:Apache License

public LoadBalancerAttributes getLoadBalancerAttributes(LoadBalancerDescription sourceLoadBalancer,
        AmazonElasticLoadBalancing sourceClient) {
    LoadBalancerAttributes sourceAttributes = sourceClient
            .describeLoadBalancerAttributes(new DescribeLoadBalancerAttributesRequest()
                    .withLoadBalancerName(sourceLoadBalancer.getLoadBalancerName()))
            .getLoadBalancerAttributes();
    if (sourceLoadBalancer.getListenerDescriptions().stream()
            .anyMatch(l -> l.getListener().getInstancePort() == 0)) {
        sourceAttributes.setCrossZoneLoadBalancing(new CrossZoneLoadBalancing().withEnabled(true));
    }//from  ww w  . java  2 s . c om
    return sourceAttributes;
}

From source file:com.netflix.spinnaker.clouddriver.aws.deploy.handlers.MigrateLoadBalancerStrategy.java

License:Apache License

/**
 * Applies any listener policies from the source load balancer to the target load balancer.
 *
 * Since policy names are unique to each load balancer, two policies with the same name in different load balancers
 * may contain different policy attributes. For the sake of simplicity, we assume that policies with the same name
 * are structurally the same, and do not attempt to reconcile any differences between attributes.
 *
 * We will, however, attempt to override the policies applied to a given listener if it's different, e.g., if the
 * source load balancer has policy "a" on port 7000, and the target load balancer has policy "b" on port 7000, we
 * will:/*  www.j  a  v  a  2 s.  c  om*/
 *   1. create policy "a" if it doesn't exist on the target load balancer, then
 *   2. update the target load balancer so port 7000 will have only policy "a"
 */
public void applyListenerPolicies(AmazonElasticLoadBalancing sourceClient,
        AmazonElasticLoadBalancing targetClient, LoadBalancerDescription source, String loadBalancerName) {
    Set<String> policiesToRetrieve = new HashSet<>();
    Map<String, String> policyNameMap = new HashMap<>();
    source.getListenerDescriptions().forEach(d -> policiesToRetrieve.addAll(d.getPolicyNames()));
    List<PolicyDescription> sourcePolicies = sourceClient
            .describeLoadBalancerPolicies(new DescribeLoadBalancerPoliciesRequest()
                    .withLoadBalancerName(source.getLoadBalancerName()).withPolicyNames(policiesToRetrieve))
            .getPolicyDescriptions();
    List<PolicyDescription> targetPolicies = targetClient
            .describeLoadBalancerPolicies(
                    new DescribeLoadBalancerPoliciesRequest().withLoadBalancerName(loadBalancerName))
            .getPolicyDescriptions();

    sourcePolicies.forEach(p -> {
        Optional<PolicyDescription> match = targetPolicies.stream().filter(
                tp -> tp.getPolicyAttributeDescriptions().size() == p.getPolicyAttributeDescriptions().size()
                        && tp.getPolicyAttributeDescriptions().containsAll(p.getPolicyAttributeDescriptions()))
                .findFirst();

        if (match.isPresent()) {
            policyNameMap.put(p.getPolicyName(), match.get().getPolicyName());
        } else {
            String policyName = p.getPolicyName();
            if (policyName.startsWith("ELBSample-") || policyName.startsWith("ELBSecurityPolicy-")) {
                policyName = "migrated-" + policyName;
            }
            policyNameMap.put(p.getPolicyName(), policyName);
            CreateLoadBalancerPolicyRequest request = new CreateLoadBalancerPolicyRequest()
                    .withPolicyName(policyName).withLoadBalancerName(loadBalancerName)
                    .withPolicyTypeName(p.getPolicyTypeName());
            // only copy policy attributes if this is not a pre-defined policy
            // (as defined by the presence of 'Reference-Security-Policy'
            Optional<PolicyAttributeDescription> referencePolicy = p.getPolicyAttributeDescriptions().stream()
                    .filter(d -> d.getAttributeName().equals("Reference-Security-Policy")).findFirst();
            if (referencePolicy.isPresent()) {
                request.withPolicyAttributes(new PolicyAttribute(referencePolicy.get().getAttributeName(),
                        referencePolicy.get().getAttributeValue()));
            } else {
                request.withPolicyAttributes(p.getPolicyAttributeDescriptions().stream()
                        .map(d -> new PolicyAttribute(d.getAttributeName(), d.getAttributeValue()))
                        .collect(Collectors.toList()));
            }
            targetClient.createLoadBalancerPolicy(request);
        }
    });
    source.getListenerDescriptions().forEach(l -> targetClient.setLoadBalancerPoliciesOfListener(
            new SetLoadBalancerPoliciesOfListenerRequest().withLoadBalancerName(loadBalancerName)
                    .withLoadBalancerPort(l.getListener().getLoadBalancerPort()).withPolicyNames(
                            l.getPolicyNames().stream().map(policyNameMap::get).collect(Collectors.toList()))));
}

From source file:com.proofpoint.discovery.elb.ElasticLoadBalancerUpdater.java

License:Apache License

public void update() throws Exception {
    for (LoadBalancerDescription loadBalancer : elbClient.describeLoadBalancers()
            .getLoadBalancerDescriptions()) {
        // split ELB name into parts
        String elbName = loadBalancer.getLoadBalancerName();
        List<String> parts = copyOf(Splitter.on('-').split(elbName).iterator());
        if (parts.size() != 3 && parts.size() != 4) {
            log.debug("ignoring load balancer: %s", elbName);
            continue;
        }/*from w w  w.  j  a  va 2 s .co  m*/
        String environment = parts.get(0);
        String type = parts.get(1);
        String pool = parts.get(2);
        log.debug("found load balancer: %s", elbName);

        // check against environment
        if (!environment.equals(nodeInfo.getEnvironment())) {
            continue;
        }

        // look for services in discovery
        ServiceDescriptors services = discoveryClient.getServices(type, pool).get(1, TimeUnit.SECONDS);

        // map services to instances
        Set<String> instances = newHashSet();
        for (ServiceDescriptor descriptor : services.getServiceDescriptors()) {
            String instanceId = extractEc2InstanceId(descriptor.getLocation());
            if (instanceId == null) {
                log.warn("invalid EC2 location: %s", descriptor.getLocation());
                continue;
            }

            // verify load balancer listeners against the service announcement
            boolean valid = true;
            for (Listener listener : transform(loadBalancer.getListenerDescriptions(), GET_LISTENER)) {
                if (!serviceExistsForListener(listener, descriptor.getProperties())) {
                    valid = false;
                    log.warn("load balancer %s listener %s does not match service %s", elbName, listener,
                            descriptor);
                }
            }
            if (valid) {
                instances.add(instanceId);
            }
        }

        // get registered instances
        Set<String> registeredInstances = newHashSet(transform(loadBalancer.getInstances(), GET_INSTANCE_ID));

        // add new instances to load balancer
        Collection<String> addInstances = difference(instances, registeredInstances);
        if (!addInstances.isEmpty()) {
            registerInstances(elbName, addInstances);
        }

        // remove missing instances from load balancer
        Collection<String> removeInstances = difference(registeredInstances, instances);
        if (!removeInstances.isEmpty()) {
            deregisterInstances(elbName, removeInstances);
        }
    }
}

From source file:com.zotoh.cloudapi.aws.ElasticLoadBalancer.java

License:Open Source License

private LoadBalancer toELB(LoadBalancerDescription desc) {
    LoadBalancer b = null;/*from   w  w  w .  ja v a2  s  .  c o  m*/
    if (desc != null) {
        ProviderContext x = _svc.getCloud().getContext();
        b = new LoadBalancer();

        b.setCreationTimestamp(desc.getCreatedTime().getTime());
        b.setProviderRegionId(x.getRegionId());
        b.setAddressType(LoadBalancerAddressType.DNS);
        b.setCurrentState(LoadBalancerState.ACTIVE);
        b.setProviderOwnerId(x.getAccountNumber());
        b.setName(desc.getLoadBalancerName());
        b.setDescription(b.getName());
        b.setProviderLoadBalancerId(b.getName());
        b.setAddress(desc.getDNSName());

        // zones
        {
            List<String> lst = desc.getAvailabilityZones();
            if (!isNil(lst)) {
                b.setProviderDataCenterIds(lst.toArray(new String[0]));
            }
        }
        // servers
        {
            List<Instance> lst = desc.getInstances();
            List<String> s = LT();
            if (!isNil(lst))
                for (int i = 0; i < lst.size(); ++i) {
                    s.add(lst.get(i).getInstanceId());
                }
            b.setProviderServerIds(s.toArray(new String[0]));
        }
        // listeners/ports
        {
            List<ListenerDescription> lst = desc.getListenerDescriptions();
            List<LbListener> rc = LT();
            int[] pports;
            if (lst != null)
                for (int i = 0; i < lst.size(); ++i) {
                    rc.add(toLis(lst.get(i)));
                }
            b.setListeners(rc.toArray(new LbListener[0]));
            pports = new int[rc.size()];
            for (int i = 0; i < pports.length; ++i) {
                pports[i] = rc.get(i).getPublicPort();
            }
            b.setPublicPorts(pports);
        }

        // unsupported
        desc.getHealthCheck();
        desc.getPolicies();
        desc.getSourceSecurityGroup();
        desc.getCanonicalHostedZoneName();
    }

    return b;
}