stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [21/32] stratos git commit: 1. Removed the logic to detach instances from load balancer. 2. Used readable constant values 3. Used format string for endpoint url. 4. Mentioned load balancer name length in exception message.
Date Fri, 09 Oct 2015 14:35:34 GMT
1. Removed the logic to detach instances from load balancer. 2. Used readable constant values
3. Used format string for endpoint url. 4. Mentioned load balancer name length in exception
message.


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

Branch: refs/heads/gsoc-projects-2015
Commit: d22721baae7ddac9dacebb1921c641e6bf7f2427
Parents: 1855fdd
Author: swapnilpatilRajaram <swapnil.patil@students.iiit.ac.in>
Authored: Sat Aug 1 16:55:02 2015 +0000
Committer: swapnilpatilRajaram <swapnil.patil@students.iiit.ac.in>
Committed: Sat Aug 1 16:55:02 2015 +0000

----------------------------------------------------------------------
 .../apache/stratos/aws/extension/AWSHelper.java | 36 ++++++++------------
 .../stratos/aws/extension/AWSLoadBalancer.java  | 16 ---------
 .../apache/stratos/aws/extension/Constants.java |  5 +++
 3 files changed, 20 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/d22721ba/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 e3f75a6..50177bd 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
@@ -92,7 +92,7 @@ public class AWSHelper {
 
 			this.lbPrefix = properties.getProperty(Constants.LB_PREFIX);
 
-			if (this.lbPrefix.isEmpty() || this.lbPrefix.length() > 25) {
+			if (this.lbPrefix.isEmpty() || this.lbPrefix.length() > Constants.LOAD_BALANCER_PREFIX_MAX_LENGTH)
{
 				throw new LoadBalancerExtensionException(
 						"Invalid load balancer prefix.");
 			}
@@ -104,7 +104,7 @@ public class AWSHelper {
 					.getProperty(Constants.LOAD_BALANCER_SECURITY_GROUP_NAME);
 
 			if (this.lbSecurityGroupName.isEmpty()
-					|| this.lbSecurityGroupName.length() > 255) {
+					|| this.lbSecurityGroupName.length() > Constants.SECURITY_GROUP_NAME_MAX_LENGTH)
{
 				throw new LoadBalancerExtensionException(
 						"Invalid load balancer security group name.");
 			}
@@ -173,8 +173,7 @@ public class AWSHelper {
 
 			createLoadBalancerRequest.setSecurityGroups(securityGroups);
 
-			lbClient.setEndpoint("elasticloadbalancing." + region
-					+ ".amazonaws.com");
+			lbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));
 
 			CreateLoadBalancerResult clbResult = lbClient
 					.createLoadBalancer(createLoadBalancerRequest);
@@ -204,8 +203,7 @@ public class AWSHelper {
 		deleteLoadBalancerRequest.setLoadBalancerName(loadBalancerName);
 
 		try {
-			lbClient.setEndpoint("elasticloadbalancing." + region
-					+ ".amazonaws.com");
+			lbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));
 
 			lbClient.deleteLoadBalancer(deleteLoadBalancerRequest);
 			return;
@@ -235,8 +233,7 @@ public class AWSHelper {
 				loadBalancerName, instances);
 
 		try {
-			lbClient.setEndpoint("elasticloadbalancing." + region
-					+ ".amazonaws.com");
+			lbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));
 
 			RegisterInstancesWithLoadBalancerResult result = lbClient
 					.registerInstancesWithLoadBalancer(registerInstancesWithLoadBalancerRequest);
@@ -267,8 +264,7 @@ public class AWSHelper {
 				loadBalancerName, instances);
 
 		try {
-			lbClient.setEndpoint("elasticloadbalancing." + region
-					+ ".amazonaws.com");
+			lbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));
 
 			DeregisterInstancesFromLoadBalancerResult result = lbClient
 					.deregisterInstancesFromLoadBalancer(deregisterInstancesFromLoadBalancerRequest);
@@ -299,23 +295,21 @@ public class AWSHelper {
 				loadBalancers);
 
 		try {
-			lbClient.setEndpoint("elasticloadbalancing." + region
-					+ ".amazonaws.com");
+			lbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));
 
 			DescribeLoadBalancersResult result = lbClient
 					.describeLoadBalancers(describeLoadBalancersRequest);
 
-			if (result.getLoadBalancerDescriptions() == null
-					|| result.getLoadBalancerDescriptions().size() == 0)
-				return null;
-			else
+			if (result.getLoadBalancerDescriptions() != null
+					&& result.getLoadBalancerDescriptions().size() > 0)
 				return result.getLoadBalancerDescriptions().get(0);
 		} catch (Exception e) {
 			log.error("Could not find description of load balancer "
 					+ loadBalancerName);
 			e.printStackTrace();
-			return null;
 		}
+
+		return null;
 	}
 
 	/**
@@ -399,7 +393,7 @@ public class AWSHelper {
 		createSecurityGroupRequest.setDescription(description);
 
 		try {
-			ec2Client.setEndpoint("ec2." + region + ".amazonaws.com");
+			ec2Client.setEndpoint(Constants.EC2_ENDPOINT_URL_FORMAT);
 
 			CreateSecurityGroupResult createSecurityGroupResult = ec2Client
 					.createSecurityGroup(createSecurityGroupRequest);
@@ -429,7 +423,7 @@ public class AWSHelper {
 		authorizeSecurityGroupIngressRequest.setIpProtocol("tcp");
 
 		try {
-			ec2Client.setEndpoint("ec2." + region + ".amazonaws.com");
+			ec2Client.setEndpoint(Constants.EC2_ENDPOINT_URL_FORMAT);
 
 			ec2Client
 					.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);
@@ -501,9 +495,9 @@ public class AWSHelper {
 
 		name = lbPrefix + getNextLBSequence();
 
-		if (name.length() > 32)
+		if (name.length() > Constants.LOAD_BALANCER_NAME_MAX_LENGTH)
 			throw new LoadBalancerExtensionException(
-					"Load balanacer name length exceeded");
+					"Load balanacer name length (32 characters) exceeded");
 
 		return name;
 	}

http://git-wip-us.apache.org/repos/asf/stratos/blob/d22721ba/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 231c582..717e7f8 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
@@ -84,7 +84,6 @@ public class AWSLoadBalancer implements LoadBalancer {
 							activeClusters.add(cluster.getClusterId());
 
 							List<Instance> instancesToAddToLoadBalancer = new ArrayList<Instance>();
-							List<Instance> awsInstancesInCluster = new ArrayList<Instance>();
 
 							for (Member member : clusterMembers) {
 								// if instance id of member is not in
@@ -101,27 +100,12 @@ public class AWSLoadBalancer implements LoadBalancer {
 										awsHelper.getAWSInstanceName(member
 												.getInstanceId()));
 
-								awsInstancesInCluster.add(instance);
-
 								if (attachedInstances == null
 										|| !attachedInstances.contains(instance)) {
 									instancesToAddToLoadBalancer.add(instance);
 								}
 							}
 
-							List<Instance> instancesToRemoveFromLoadBalancer = new ArrayList<Instance>();
-
-							for (Instance instance : attachedInstances) {
-								if (!awsInstancesInCluster.contains(instance)) {
-									instancesToRemoveFromLoadBalancer.add(instance);
-								}
-							}
-
-							if (instancesToRemoveFromLoadBalancer.size() > 0)
-								awsHelper.deregisterInstancesFromLoadBalancer(
-										loadBalancerName,
-										instancesToRemoveFromLoadBalancer, region);
-
 							if (instancesToAddToLoadBalancer.size() > 0)
 								awsHelper.registerInstancesToLoadBalancer(
 										loadBalancerName,

http://git-wip-us.apache.org/repos/asf/stratos/blob/d22721ba/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 f3ffb94..0c1752d 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
@@ -35,4 +35,9 @@ public class Constants {
     public static final String LB_PREFIX = "load-balancer-prefix";
     public static final String LOAD_BALANCER_SECURITY_GROUP_NAME = "load-balancer-security-group-name";
     public static final String LOAD_BALANCER_SECURITY_GROUP_DESCRIPTION = "Security group
for load balancers created for Apache Stratos.";
+    public static final int LOAD_BALANCER_NAME_MAX_LENGTH = 32;
+    public static final int LOAD_BALANCER_PREFIX_MAX_LENGTH = 25;
+    public static final int SECURITY_GROUP_NAME_MAX_LENGTH = 255;
+    public static final String ELB_ENDPOINT_URL_FORMAT = "elasticloadbalancing.%s.amazonaws.com";
+    public static final String EC2_ENDPOINT_URL_FORMAT = "ec2.%s.amazonaws.com";
 }


Mime
View raw message