stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [09/32] stratos git commit: Changes to read AWS credentials from config file.
Date Fri, 09 Oct 2015 14:35:22 GMT
Changes to read AWS credentials from config file.


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

Branch: refs/heads/gsoc-projects-2015
Commit: 313db960f35607180a5e8cdb70ac761a1ace1dbe
Parents: 31f5a72
Author: swapnilpatilRajaram <swapnil.patil@students.iiit.ac.in>
Authored: Thu Jun 18 15:36:17 2015 +0000
Committer: swapnilpatilRajaram <swapnil.patil@students.iiit.ac.in>
Committed: Thu Jun 18 15:36:17 2015 +0000

----------------------------------------------------------------------
 .../load-balancer/aws-extension/INSTALL.md      |  8 +++--
 extensions/load-balancer/aws-extension/pom.xml  |  2 +-
 .../aws-extension/src/main/assembly/bin.xml     |  1 +
 .../aws-extension/src/main/bin/aws-extension.sh |  1 +
 .../src/main/conf/aws-credentials.conf          |  2 ++
 .../apache/stratos/aws/extension/AWSHelper.java | 35 +++++++++++++++++++-
 .../stratos/aws/extension/AWSLoadBalancer.java  |  7 ++--
 .../apache/stratos/aws/extension/Constants.java |  5 ++-
 8 files changed, 53 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/313db960/extensions/load-balancer/aws-extension/INSTALL.md
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/aws-extension/INSTALL.md b/extensions/load-balancer/aws-extension/INSTALL.md
index 444f619..0ab671f 100644
--- a/extensions/load-balancer/aws-extension/INSTALL.md
+++ b/extensions/load-balancer/aws-extension/INSTALL.md
@@ -24,7 +24,9 @@ below steps to proceed with the installation:
 
 1. Extract org.apache.stratos.aws.extension-<version>.zip to a desired location: <aws-extension-home>.
 
-2. Open <aws-extension-home>/bin/aws-extension.sh file in a text editor and update
following system properties:
+2. Open <aws-extension-home>/conf/aws-credentials.conf file in text editor and update
AWS access key and secret key information.
+
+3. Open <aws-extension-home>/bin/aws-extension.sh file in a text editor and update
following system properties:
    ```
    # Enable/disable cep statistics publisher:
    -Dcep.stats.publisher.enabled=false
@@ -35,9 +37,9 @@ below steps to proceed with the installation:
    -Dnetwork.partition.id=network-partition-1
    ```
 
-3. Open <aws-extension-home>/conf/jndi.properties file in a text editor and update
message broker information:
+4. Open <aws-extension-home>/conf/jndi.properties file in a text editor and update
message broker information:
    ```
    java.naming.provider.url=tcp://localhost:61616
    ```
-4. Run <aws-extension-home>/bin/aws-extension.sh as the root user.
+5. Run <aws-extension-home>/bin/aws-extension.sh as the root user.
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/313db960/extensions/load-balancer/aws-extension/pom.xml
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/aws-extension/pom.xml b/extensions/load-balancer/aws-extension/pom.xml
index 68f0ad1..282c8ce 100644
--- a/extensions/load-balancer/aws-extension/pom.xml
+++ b/extensions/load-balancer/aws-extension/pom.xml
@@ -69,7 +69,7 @@
         <dependency>
           <groupId>com.amazonaws</groupId>
           <artifactId>aws-java-sdk</artifactId>
-          <version>1.9.24</version>
+          <version>1.8.8</version>
         </dependency>
     </dependencies>
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/313db960/extensions/load-balancer/aws-extension/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/aws-extension/src/main/assembly/bin.xml b/extensions/load-balancer/aws-extension/src/main/assembly/bin.xml
index b6c924b..036ad1c 100644
--- a/extensions/load-balancer/aws-extension/src/main/assembly/bin.xml
+++ b/extensions/load-balancer/aws-extension/src/main/assembly/bin.xml
@@ -41,6 +41,7 @@
                 <include>jndi.properties</include>
                 <include>log4j.properties</include>
                 <include>thrift-client-config.xml</include>
+                <include>aws-credentials.conf</include>
             </includes>
         </fileSet>
         <fileSet>

http://git-wip-us.apache.org/repos/asf/stratos/blob/313db960/extensions/load-balancer/aws-extension/src/main/bin/aws-extension.sh
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/aws-extension/src/main/bin/aws-extension.sh b/extensions/load-balancer/aws-extension/src/main/bin/aws-extension.sh
index 6c6c2e7..4451ace 100755
--- a/extensions/load-balancer/aws-extension/src/main/bin/aws-extension.sh
+++ b/extensions/load-balancer/aws-extension/src/main/bin/aws-extension.sh
@@ -26,6 +26,7 @@ lib_path=${script_path}/../lib/
 class_path=`echo ${lib_path}/*.jar | tr ' ' ':'`
 properties="-Djndi.properties.dir=${script_path}/../conf
             -Dlog4j.properties.file.path=${script_path}/../conf/log4j.properties
+            -Daws.credentials.file=${script_path}/../conf/aws-credentials.conf
             -Djavax.net.ssl.trustStore=${script_path}/../security/client-truststore.jks
             -Djavax.net.ssl.trustStorePassword=wso2carbon
             -Dthrift.client.config.file.path=${script_path}/../conf/thrift-client-config.xml

http://git-wip-us.apache.org/repos/asf/stratos/blob/313db960/extensions/load-balancer/aws-extension/src/main/conf/aws-credentials.conf
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/aws-extension/src/main/conf/aws-credentials.conf b/extensions/load-balancer/aws-extension/src/main/conf/aws-credentials.conf
new file mode 100644
index 0000000..d9d296c
--- /dev/null
+++ b/extensions/load-balancer/aws-extension/src/main/conf/aws-credentials.conf
@@ -0,0 +1,2 @@
+access-key=
+secret-key=
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/313db960/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
index 16ac7ae..a9af51d 100644
--- a/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
+++ b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
@@ -19,14 +19,19 @@
 
 package org.apache.stratos.aws.extension;
 
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Properties;
 import java.util.Set;
 
 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 com.amazonaws.ClientConfiguration;
 import com.amazonaws.auth.BasicAWSCredentials;
@@ -43,10 +48,38 @@ public class AWSHelper {
 
 	private static final Log log = LogFactory.getLog(AWSHelper.class);
 
-	public AWSHelper() {
+	public AWSHelper() throws LoadBalancerExtensionException {
 		// Read values for awsAccessKey, awsSecretKey etc. from config file
 		// Throw a proper exception / log warning if cant read credentials ?
 
+		String awsCredentialsFile = System
+				.getProperty(Constants.AWS_CREDENTIALS_FILE);
+
+		Properties properties = new Properties();
+
+		InputStream inputStream = null;
+
+		try {
+			inputStream = new FileInputStream(awsCredentialsFile);
+
+			properties.load(inputStream);
+
+			this.awsAccessKey = properties
+					.getProperty(Constants.AWS_ACCESS_KEY);
+			this.awsSecretKey = properties
+					.getProperty(Constants.AWS_SECRET_KEY);
+		} catch (IOException e) {
+			log.error("Error reading aws configuration file.");
+			throw new LoadBalancerExtensionException(
+					"Error reading aws configuration file.", e);
+		} finally {
+			try {
+				inputStream.close();
+			} catch (Exception e) {
+				log.warn("Failed to close input stream to aws configuration file.");
+			}
+		}
+
 		awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
 		clientConfiguration = new ClientConfiguration();
 	}

http://git-wip-us.apache.org/repos/asf/stratos/blob/313db960/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSLoadBalancer.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSLoadBalancer.java
b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSLoadBalancer.java
index b3656b4..c2e9e45 100644
--- a/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSLoadBalancer.java
+++ b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSLoadBalancer.java
@@ -42,7 +42,7 @@ public class AWSLoadBalancer implements LoadBalancer {
 
 	private AWSHelper awsHelper;
 
-	public AWSLoadBalancer() {
+	public AWSLoadBalancer() throws LoadBalancerExtensionException {
 		clusterIdToLoadBalancerMap = new HashMap<String, String>();
 		awsHelper = new AWSHelper();
 	}
@@ -50,6 +50,8 @@ public class AWSLoadBalancer implements LoadBalancer {
 	public boolean configure(Topology topology)
 			throws LoadBalancerExtensionException {
 
+		log.info("AWS load balancer extension re-configured.");
+
 		for (Service service : topology.getServices()) {
 
 			List<Listener> listenersForThisService = awsHelper
@@ -190,11 +192,12 @@ public class AWSLoadBalancer implements LoadBalancer {
 
 	public void start() throws LoadBalancerExtensionException {
 
-		log.info("Started AWS load balancer extension.");
+		log.info("AWS load balancer extension started.");
 	}
 
 	public void reload() throws LoadBalancerExtensionException {
 		// Check what is appropriate to do here.
+		log.info("AWS load balancer extension reloaded.");
 	}
 
 	public void stop() throws LoadBalancerExtensionException {

http://git-wip-us.apache.org/repos/asf/stratos/blob/313db960/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
index 0e501f2..71c7ef7 100644
--- a/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
+++ b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
@@ -20,7 +20,7 @@
 package org.apache.stratos.aws.extension;
 
 /**
- * HA proxy extension constants.
+ * AWS proxy extension constants.
  */
 public class Constants {
     public static final String CEP_STATS_PUBLISHER_ENABLED = "cep.stats.publisher.enabled";
@@ -29,4 +29,7 @@ public class Constants {
     public static final String NETWORK_PARTITION_ID = "network.partition.id";
     public static final String CLUSTER_ID = "cluster.id";
     public static final String SERVICE_NAME = "service.name";
+    public static final String AWS_CREDENTIALS_FILE="aws.credentials.file";
+    public static final String AWS_ACCESS_KEY = "access-key";
+    public static final String AWS_SECRET_KEY = "secret-key";
 }


Mime
View raw message