stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From isu...@apache.org
Subject stratos git commit: adding proxy support to AWS LB extension
Date Wed, 24 Feb 2016 06:52:45 GMT
Repository: stratos
Updated Branches:
  refs/heads/stratos-4.1.x cbbbf9b0c -> c110d683a


adding proxy support to AWS LB extension

Conflicts:
	extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c110d683
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c110d683
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c110d683

Branch: refs/heads/stratos-4.1.x
Commit: c110d683ad11491f4413312ba2fc2a18460b8a39
Parents: cbbbf9b
Author: Isuru Haththotuwa <isuruh@apache.org>
Authored: Wed Feb 24 11:15:21 2016 +0530
Committer: Isuru Haththotuwa <isuruh@apache.org>
Committed: Wed Feb 24 11:43:03 2016 +0530

----------------------------------------------------------------------
 .../apache/stratos/aws/extension/AWSHelper.java | 83 ++++++++++++++++++++
 .../apache/stratos/aws/extension/Constants.java | 11 +++
 2 files changed, 94 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/c110d683/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
index 85d6811..d403de6 100644
--- a/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
+++ b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
@@ -19,6 +19,24 @@
 
 package org.apache.stratos.aws.extension;
 
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.amazonaws.AmazonServiceException;
+import com.amazonaws.Protocol;
+import com.amazonaws.services.ec2.model.*;
+import com.amazonaws.services.elasticloadbalancing.model.Instance;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.load.balancer.common.domain.*;
+import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+
 import com.amazonaws.AmazonClientException;
 import com.amazonaws.AmazonServiceException;
 import com.amazonaws.ClientConfiguration;
@@ -202,6 +220,7 @@ public class AWSHelper {
 
             awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
             clientConfiguration = new ClientConfiguration();
+            createProxyConfiguration();
 
             elbClient = new AmazonElasticLoadBalancingClient(awsCredentials,
                     clientConfiguration);
@@ -224,6 +243,70 @@ public class AWSHelper {
         }
     }
 
+    private void createProxyConfiguration() {
+
+        if (clientConfiguration == null) {
+            log.error("ClientConfiguration is null, hence unable to apply Proxy Settings");
+            return;
+        }
+
+        if (clientConfiguration.getProtocol() == Protocol.HTTPS) {
+            // use HTTPS proxy settings
+            clientConfiguration.setProxyHost(getSystemProperty(Constants.HTTPS_PROXY_HOST));
+            clientConfiguration.setProxyPort(getSystemPropertyAsInteger(Constants.HTTPS_PROXY_PORT));
+            clientConfiguration.setProxyUsername(getSystemProperty(Constants.HTTPS_PROXY_USERNAME));
+            clientConfiguration.setProxyPassword(getSystemProperty(Constants.HTTPS_PROXY_PASSWORD));
+
+        } else {
+            // use HTTP settings
+            clientConfiguration.setProxyHost(getSystemProperty(Constants.HTTP_PROXY_HOST));
+            clientConfiguration.setProxyPort(getSystemPropertyAsInteger(Constants.HTTP_PROXY_PORT));
+            clientConfiguration.setProxyUsername(getSystemProperty(Constants.HTTP_PROXY_USERNAME));
+            clientConfiguration.setProxyPassword(getSystemProperty(Constants.HTTP_PROXY_PASSWORD));
+        }
+
+        // if proxy workstation and domain are null, need to set empty Strings to overcome
+        // https://forums.aws.amazon.com/thread.jspa?messageID=561113&#561113
+        clientConfiguration.setProxyWorkstation("");
+        clientConfiguration.setProxyDomain("");
+
+        String proxyWorkstation = getSystemProperty(Constants.PROXY_WORKSTATION);
+        if (proxyWorkstation != null) {
+            clientConfiguration.setProxyWorkstation(proxyWorkstation);
+        }
+        String proxyDomain = getSystemProperty(Constants.PROXY_DOMAIN);
+        if (proxyDomain != null) {
+            clientConfiguration.setProxyDomain(proxyDomain);
+        }
+
+        // authenticate preemptively
+        clientConfiguration.setPreemptiveBasicProxyAuth(true);
+        if (getSystemProperty(Constants.PREEMPTIVE_AUTHENTICATION) != null) {
+            clientConfiguration.setPreemptiveBasicProxyAuth(getSystemPropertyAsBoolean(Constants.PREEMPTIVE_AUTHENTICATION));
+        }
+
+        if (log.isDebugEnabled()) {
+            log.debug("Proxy host: '" + clientConfiguration.getProxyHost() + "'");
+            log.debug("Proxy port: '" + clientConfiguration.getProxyPort() + "'");
+            log.debug("Proxy user: '" + clientConfiguration.getProxyUsername() + "'");
+            log.debug("Proxy workstation: '" + clientConfiguration.getProxyWorkstation()
+ "'");
+            log.debug("Proxy domain: '" + clientConfiguration.getProxyDomain() + "'");
+            log.debug("Proxy preemptive auth: '" + clientConfiguration.isPreemptiveBasicProxyAuth()
+ "'");
+        }
+    }
+
+    private String getSystemProperty (String key) {
+        return System.getProperty(key);
+    }
+
+    private Integer getSystemPropertyAsInteger (String key) {
+        return Integer.getInteger(key);
+    }
+
+    private boolean getSystemPropertyAsBoolean (String key) {
+        return Boolean.getBoolean(key);
+    }
+
 	public AWSHelper(String awsAccessKey, String awsSecretKey){
 		this.awsAccessKey=awsAccessKey;
 		this.awsSecretKey=awsSecretKey;

http://git-wip-us.apache.org/repos/asf/stratos/blob/c110d683/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
index 20db2d9..f431c7c 100644
--- a/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
+++ b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
@@ -67,4 +67,15 @@ public class Constants {
 	public static final String LB_SCHEME = "load-balancer-scheme";
 	public static final String LB_SCHEME_INTERNAL = "internal";
 	public static final String EC2_AVAILABILITY_ZONE_PROPERTY = "EC2_AVAILABILITY_ZONE";
+	public static final String HTTPS_PROXY_HOST = "https.proxyHost";
+	public static final String HTTP_PROXY_HOST = "http.proxyHost";
+	public static final String HTTPS_PROXY_PORT = "https.proxyPort";
+	public static final String HTTP_PROXY_PORT = "http.proxyPort";
+	public static final String HTTPS_PROXY_USERNAME = "https.proxyUser";
+	public static final String HTTP_PROXY_USERNAME = "http.proxyUser";
+	public static final String HTTPS_PROXY_PASSWORD = "https.proxyPassword";
+	public static final String HTTP_PROXY_PASSWORD = "http.proxyPassword";
+	public static final String PROXY_WORKSTATION = "proxy.workstation";
+	public static final String PROXY_DOMAIN = "proxy.domain";
+	public static final String PREEMPTIVE_AUTHENTICATION = "preemptive.authentication";
 }


Mime
View raw message