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

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

Introduction

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

Prototype


public java.util.List<String> getSecurityGroups() 

Source Link

Document

The security groups for 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(", ");
            }/*from   ww  w.  j av a2 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.netflix.spinnaker.clouddriver.aws.deploy.handlers.MigrateLoadBalancerStrategy.java

License:Apache License

/**
 * Generates a list of security groups that should be applied to the target load balancer
 *
 * @param sourceDescription AWS descriptor of source load balancer
 * @param result            result object of the calling migate operation
 * @return the list of security groups that will be created or added, excluding the elb-specific security group
 *//*from w w w .  j ava2s . co m*/
protected List<MigrateSecurityGroupResult> getTargetSecurityGroups(LoadBalancerDescription sourceDescription,
        MigrateLoadBalancerResult result) {
    sourceDescription.getSecurityGroups().stream()
            .filter(g -> !sourceLookup.getSecurityGroupById(source.getCredentialAccount(), g, source.getVpcId())
                    .isPresent())
            .forEach(m -> result.getWarnings().add(
                    "Skipping creation of security group: " + m + " (could not be found in source location)"));
    List<SecurityGroup> currentGroups = sourceDescription.getSecurityGroups().stream()
            .filter(g -> sourceLookup.getSecurityGroupById(source.getCredentialAccount(), g, source.getVpcId())
                    .isPresent())
            .map(g -> sourceLookup.getSecurityGroupById(source.getCredentialAccount(), g, source.getVpcId())
                    .get().getSecurityGroup())
            .collect(Collectors.toList());

    return sourceDescription.getSecurityGroups().stream()
            .filter(g -> currentGroups.stream().anyMatch(g2 -> g2.getGroupId().equals(g))).map(g -> {
                SecurityGroup match = currentGroups.stream().filter(g3 -> g3.getGroupId().equals(g)).findFirst()
                        .get();
                SecurityGroupLocation sourceLocation = new SecurityGroupLocation();
                sourceLocation.setName(match.getGroupName());
                sourceLocation.setRegion(source.getRegion());
                sourceLocation.setCredentials(source.getCredentials());
                sourceLocation.setVpcId(source.getVpcId());
                return new SecurityGroupMigrator(sourceLookup, targetLookup, migrateSecurityGroupStrategy,
                        sourceLocation, new SecurityGroupLocation(target)).migrate(dryRun);
            }).collect(Collectors.toList());
}

From source file:jp.primecloud.auto.process.aws.AwsLoadBalancerProcess.java

License:Open Source License

public void applySecurityGroups(AwsProcessClient awsProcessClient, Long loadBalancerNo) {
    // ?VPC???// w  ww. j a  v a2s.c  o m
    if (BooleanUtils.isNotTrue(awsProcessClient.getPlatformAws().getVpc())) {
        return;
    }

    AwsLoadBalancer awsLoadBalancer = awsLoadBalancerDao.read(loadBalancerNo);

    // ????SecurityGroup
    LoadBalancerDescription description = awsCommonProcess.describeLoadBalancer(awsProcessClient,
            awsLoadBalancer.getName());
    List<String> groupIds = description.getSecurityGroups();

    // ????SecurityGroup
    List<String> newGroupIds = new ArrayList<String>();
    List<SecurityGroup> securityGroups = awsCommonProcess.describeSecurityGroupsByVpcId(awsProcessClient,
            awsProcessClient.getPlatformAws().getVpcId());
    for (String groupName : StringUtils.split(awsLoadBalancer.getSecurityGroups(), ",")) {
        groupName = groupName.trim();
        for (SecurityGroup securityGroup : securityGroups) {
            if (StringUtils.equals(groupName, securityGroup.getGroupName())) {
                newGroupIds.add(securityGroup.getGroupId());
                break;
            }
        }
    }

    // SecurityGroup??????
    if (groupIds.size() == newGroupIds.size() && groupIds.containsAll(newGroupIds)) {
        return;
    }

    // 
    ApplySecurityGroupsToLoadBalancerRequest request = new ApplySecurityGroupsToLoadBalancerRequest();
    request.withLoadBalancerName(awsLoadBalancer.getName());
    request.withSecurityGroups(newGroupIds);
    awsProcessClient.getElbClient().applySecurityGroupsToLoadBalancer(request);

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-200225", awsLoadBalancer.getName()));
    }

    // 
    processLogger.debug(null, null, "AwsElbSecurityGroupsConfig",
            new Object[] { awsProcessClient.getPlatform().getPlatformName(), awsLoadBalancer.getName() });
}