Example usage for com.amazonaws.services.elasticloadbalancing.model Listener setSSLCertificateId

List of usage examples for com.amazonaws.services.elasticloadbalancing.model Listener setSSLCertificateId

Introduction

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

Prototype


public void setSSLCertificateId(String sSLCertificateId) 

Source Link

Document

The Amazon Resource Name (ARN) of the server certificate.

Usage

From source file:com.urbancode.terraform.tasks.aws.LoadBalancerTask.java

License:Apache License

@Override
public void create() throws EnvironmentCreationException {
    if (DNSName == null) {
        if (elbClient == null) {
            elbClient = context.fetchELBClient();
        }//from  w  w w  .j av  a2  s  .  c o  m

        String uuid = context.getEnvironment().fetchSuffix();
        fullName = loadBalancerName + ("-" + uuid);
        log.debug("Security Group " + loadBalancerName + " has fullname " + fullName);

        String stickyPolicyName = "StickyPolicy";
        long defaultCookieExp = 60000;

        // get amazon ids
        List<String> subnetIds = null;
        List<String> availZones = null;
        List<String> secGroupIds = null;
        try {

            if (subnetName != null && !subnetName.isEmpty()) {
                subnetIds = resolveSubnetIds(subnetName);
            } else {
                log.warn("No subnets specified on load balancer " + fullName);
                if (zones != null && !zones.isEmpty()) {
                    availZones = resolveZones(zones);
                } else {
                    log.warn("No zones specified on load balancer " + fullName);
                    throw new EnvironmentCreationException(
                            "Must specify either zones or " + "subnets on load balancer " + fullName);
                }
            }

            secGroupIds = resolveSecGroupIds(getSecRefs());

            List<Listener> listeners = new ArrayList<Listener>();
            if (getListeners() != null) {
                for (ListenerTask task : getListeners()) {
                    Listener tmp = new Listener(task.getProtocol(), task.getLoadBalancerPort(),
                            task.getInstancePort());
                    if (task.isSecure()) {
                        tmp.setSSLCertificateId(task.getCertId());
                    }
                    listeners.add(tmp);
                }
            } else {
                log.warn("No listeners specified for LoadBalancer: " + fullName
                        + "\nThis load balancer is not configured to balance any " + "instances.");
            }

            // launch the load balancer
            DNSName = helper.launchLoadBalancer(fullName, subnetIds, secGroupIds, listeners, availZones,
                    elbClient);

            // configure sticky sessions
            helper.createStickyPolicy(fullName, stickyPolicyName, getAppCookieName(), defaultCookieExp,
                    elbClient);

            // configure the HealthChecks on the instances for them to be registered
            if (getHealthCheck() != null) {
                String hcTarget = getHealthCheck().getProtocol() + ":" + getHealthCheck().getPort()
                        + getHealthCheck().getPath();
                int health = getHealthCheck().getHealthyCount();
                int unhealth = getHealthCheck().getUnhealthyCount();
                int interval = getHealthCheck().getInterval();
                int timeout = getHealthCheck().getTimeout();
                helper.setupHealthCheck(fullName, hcTarget, health, unhealth, interval, timeout, elbClient);
            } else {
                log.warn("No HealthCheck specified for load balancer " + fullName
                        + "\nYou may not be able to reach the instances behind this " + "load balancer.");
            }
        } catch (Exception e) {
            log.error("Could not create load balancer " + fullName + " completely");
            throw new EnvironmentCreationException("Could not start load balancer " + fullName, e);
        } finally {
            elbClient = null;
        }
    }
}

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

License:Apache License

/**
 * Returns the Listeners required for the service. Listeners are derived
 * from the proxy port, port and protocol values of the service.
 *
 * @param service// w  ww .  java  2s  .com
 * @return list of listeners required for the service
 */
public List<Listener> getRequiredListeners(Member member) throws LoadBalancerExtensionException {
    List<Listener> listeners = new ArrayList<Listener>();

    Collection<Port> ports = member.getPorts();

    for (Port port : ports) {
        int instancePort = port.getValue();
        int proxyPort = port.getProxy();
        String protocol = port.getProtocol().toUpperCase();
        String instanceProtocol = protocol;

        Listener listener = new Listener(protocol, proxyPort, instancePort);
        listener.setInstanceProtocol(instanceProtocol);
        if ("HTTPS".equalsIgnoreCase(protocol) || "SSL".equalsIgnoreCase(protocol)) {
            // if the SSL certificate is not configured in the aws.properties file, can't continue
            if (getSslCertificateId() == null || getSslCertificateId().isEmpty()) {
                String errorMsg = "Required property " + Constants.LOAD_BALANCER_SSL_CERTIFICATE_ID
                        + " not provided in configuration";
                log.error(errorMsg);
                throw new LoadBalancerExtensionException(errorMsg);
            }
            // TODO: make debug?
            if (log.isInfoEnabled()) {
                log.info("Listener protocol = " + protocol + ", hence setting the SSL Certificate Id: "
                        + getSslCertificateId());
            }
            listener.setSSLCertificateId(getSslCertificateId());
        }

        listeners.add(listener);
    }

    return listeners;
}