stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [20/32] stratos git commit: Removed code for listeners update and break statement.
Date Fri, 09 Oct 2015 14:35:33 GMT
Removed code for listeners update and break statement.


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

Branch: refs/heads/gsoc-projects-2015
Commit: 1855fddc46968cd26625531fe11181f211693e54
Parents: f6396ff
Author: swapnilpatilRajaram <swapnil.patil@students.iiit.ac.in>
Authored: Sat Aug 1 13:22:44 2015 +0000
Committer: swapnilpatilRajaram <swapnil.patil@students.iiit.ac.in>
Committed: Sat Aug 1 13:22:44 2015 +0000

----------------------------------------------------------------------
 .../aws/extension/AWSExtensionContext.java      |   2 +-
 .../apache/stratos/aws/extension/AWSHelper.java |  75 --------
 .../stratos/aws/extension/AWSLoadBalancer.java  | 188 +++++++------------
 3 files changed, 69 insertions(+), 196 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/1855fddc/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSExtensionContext.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSExtensionContext.java
b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSExtensionContext.java
index bd55e34..d3da969 100644
--- a/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSExtensionContext.java
+++ b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSExtensionContext.java
@@ -24,7 +24,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
- * HAProxy context to read and store system properties.
+ * AWS Load Balancer context to read and store system properties.
  */
 public class AWSExtensionContext {
     private static final Log log = LogFactory.getLog(AWSExtensionContext.class);

http://git-wip-us.apache.org/repos/asf/stratos/blob/1855fddc/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 f2e742c..e3f75a6 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
@@ -240,7 +240,6 @@ public class AWSHelper {
 
 			RegisterInstancesWithLoadBalancerResult result = lbClient
 					.registerInstancesWithLoadBalancer(registerInstancesWithLoadBalancerRequest);
-			return;
 
 		} catch (Exception e) {
 			log.error("Could not register instances to load balancer "
@@ -273,7 +272,6 @@ public class AWSHelper {
 
 			DeregisterInstancesFromLoadBalancerResult result = lbClient
 					.deregisterInstancesFromLoadBalancer(deregisterInstancesFromLoadBalancerRequest);
-			return;
 
 		} catch (Exception e) {
 			log.error("Could not de-register instances from load balancer "
@@ -351,79 +349,6 @@ public class AWSHelper {
 	}
 
 	/**
-	 * Adds listeners provided to the load balancer. Useful when service
-	 * definition is changed, in particular port mappings. So new listeners need
-	 * to be added.
-	 * 
-	 * @param loadBalancerName
-	 * @param listeners
-	 * @param region
-	 */
-	public void addListenersToLoadBalancer(String loadBalancerName,
-			List<Listener> listeners, String region) {
-		if (listeners.size() == 0)
-			return;
-
-		CreateLoadBalancerListenersRequest createLoadBalancerListenersRequest = new CreateLoadBalancerListenersRequest();
-		createLoadBalancerListenersRequest.setListeners(listeners);
-		createLoadBalancerListenersRequest
-				.setLoadBalancerName(loadBalancerName);
-
-		try {
-			lbClient.setEndpoint("elasticloadbalancing." + region
-					+ ".amazonaws.com");
-
-			lbClient.createLoadBalancerListeners(createLoadBalancerListenersRequest);
-			return;
-
-		} catch (Exception e) {
-			log.error("Could not add listeners to load balancer "
-					+ loadBalancerName);
-			e.printStackTrace();
-		}
-	}
-
-	/**
-	 * Remove listeners provided from the load balancer. Useful when attached
-	 * listeners are no longer required.
-	 * 
-	 * @param loadBalancerName
-	 * @param listeners
-	 * @param region
-	 */
-	public void removeListenersFromLoadBalancer(String loadBalancerName,
-			List<Listener> listeners, String region) {
-		if (listeners.size() == 0)
-			return;
-
-		DeleteLoadBalancerListenersRequest deleteLoadBalancerListenersRequest = new DeleteLoadBalancerListenersRequest();
-		deleteLoadBalancerListenersRequest
-				.setLoadBalancerName(loadBalancerName);
-
-		List<Integer> loadBalancerPorts = new ArrayList<Integer>();
-
-		for (Listener listener : listeners) {
-			loadBalancerPorts.add(listener.getLoadBalancerPort());
-		}
-
-		deleteLoadBalancerListenersRequest
-				.setLoadBalancerPorts(loadBalancerPorts);
-
-		try {
-			lbClient.setEndpoint("elasticloadbalancing." + region
-					+ ".amazonaws.com");
-
-			lbClient.deleteLoadBalancerListeners(deleteLoadBalancerListenersRequest);
-			return;
-
-		} catch (Exception e) {
-			log.error("Could not remove listeners from load balancer "
-					+ loadBalancerName);
-			e.printStackTrace();
-		}
-	}
-
-	/**
 	 * Returns all the listeners attached to the load balancer. Useful while
 	 * deciding if all the listeners are necessary or some should be removed.
 	 * 

http://git-wip-us.apache.org/repos/asf/stratos/blob/1855fddc/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 4eff571..231c582 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
@@ -55,8 +55,6 @@ public class AWSLoadBalancer implements LoadBalancer {
 		log.info("AWS load balancer extension re-configured.");
 
 		try {
-			// Thread.sleep(10000);
-
 			HashSet<String> activeClusters = new HashSet<String>();
 
 			for (Service service : topology.getServices()) {
@@ -84,158 +82,108 @@ public class AWSLoadBalancer implements LoadBalancer {
 
 						if (clusterMembers.size() > 0) {
 							activeClusters.add(cluster.getClusterId());
-						} else {
-							break;
-						}
 
-						List<Instance> instancesToAddToLoadBalancer = new ArrayList<Instance>();
-						List<Instance> awsInstancesInCluster = new ArrayList<Instance>();
+							List<Instance> instancesToAddToLoadBalancer = new ArrayList<Instance>();
+							List<Instance> awsInstancesInCluster = new ArrayList<Instance>();
 
-						for (Member member : clusterMembers) {
-							// if instance id of member is not in
-							// attachedInstances
-							// add this to instancesToAddToLoadBalancer
+							for (Member member : clusterMembers) {
+								// if instance id of member is not in
+								// attachedInstances
+								// add this to instancesToAddToLoadBalancer
 
-							System.out.println("Instance Id : "
-									+ member.getInstanceId());
-							System.out.println("New instance id : "
-									+ awsHelper.getAWSInstanceName(member
-											.getInstanceId()));
+								System.out.println("Instance Id : "
+										+ member.getInstanceId());
+								System.out.println("New instance id : "
+										+ awsHelper.getAWSInstanceName(member
+												.getInstanceId()));
 
-							Instance instance = new Instance(
-									awsHelper.getAWSInstanceName(member
-											.getInstanceId()));
+								Instance instance = new Instance(
+										awsHelper.getAWSInstanceName(member
+												.getInstanceId()));
 
-							awsInstancesInCluster.add(instance);
+								awsInstancesInCluster.add(instance);
 
-							if (attachedInstances == null
-									|| !attachedInstances.contains(instance)) {
-								instancesToAddToLoadBalancer.add(instance);
+								if (attachedInstances == null
+										|| !attachedInstances.contains(instance)) {
+									instancesToAddToLoadBalancer.add(instance);
+								}
 							}
 
-						}
-
-						List<Instance> instancesToRemoveFromLoadBalancer = new ArrayList<Instance>();
+							List<Instance> instancesToRemoveFromLoadBalancer = new ArrayList<Instance>();
 
-						for (Instance instance : attachedInstances) {
-							if (!awsInstancesInCluster.contains(instance)) {
-								instancesToRemoveFromLoadBalancer.add(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,
-									instancesToAddToLoadBalancer, region);
+							if (instancesToRemoveFromLoadBalancer.size() > 0)
+								awsHelper.deregisterInstancesFromLoadBalancer(
+										loadBalancerName,
+										instancesToRemoveFromLoadBalancer, region);
 
-						// 2. Get all the listeners
-						// Add/Remove listeners as necessary
+							if (instancesToAddToLoadBalancer.size() > 0)
+								awsHelper.registerInstancesToLoadBalancer(
+										loadBalancerName,
+										instancesToAddToLoadBalancer, region);
 
-						// Is it really necessary to add/remove listeners from a
-						// lb
-						// to a cluster
-						// Need to add only if a cluster can be used for more
-						// than
-						// one service (because a service my get added later)
-						// or service port mappings may change
-
-						// Need to remove only if ... same for above reason
-
-						List<Listener> attachedListeners = awsHelper
-								.getAttachedListeners(loadBalancerName, region);
-
-						List<Listener> listenersToAddToLoadBalancer = new ArrayList<Listener>();
-
-						List<Listener> listenersForThisCluster = awsHelper
-								.getRequiredListeners(clusterMembers.iterator()
-										.next());
-
-						for (Listener listener : listenersForThisCluster) {
-							if (attachedListeners == null
-									|| !attachedListeners.contains(listener)) {
-								listenersToAddToLoadBalancer.add(listener);
-							}
+							// Update domain mappings
 						}
 
-						List<Listener> listenersToRemoveFromLoadBalancer = new ArrayList<Listener>();
-
-						for (Listener listener : attachedListeners) {
-							if (!listenersForThisCluster.contains(listener)) {
-								listenersToRemoveFromLoadBalancer.add(listener);
-							}
-						}
-
-						if (listenersToRemoveFromLoadBalancer.size() > 0)
-							awsHelper.removeListenersFromLoadBalancer(
-									loadBalancerName,
-									listenersToRemoveFromLoadBalancer, region);
-
-						if (listenersToAddToLoadBalancer.size() > 0)
-							awsHelper.addListenersToLoadBalancer(
-									loadBalancerName,
-									listenersToAddToLoadBalancer, region);
-
-						// Update domain mappings
-
 					} else {
 						// Create a new load balancer for this cluster
 						Collection<Member> clusterMembers = cluster
 								.getMembers();
 
-						if (clusterMembers.size() == 0)
-							break;
+						if (clusterMembers.size() > 0){
 
-						String loadBalancerName = awsHelper
-								.generateLoadBalancerName();
+							String loadBalancerName = awsHelper
+									.generateLoadBalancerName();
 
-						String region = awsHelper.getAWSRegion(clusterMembers
-								.iterator().next().getInstanceId());
+							String region = awsHelper.getAWSRegion(clusterMembers
+									.iterator().next().getInstanceId());
 
-						List<Listener> listenersForThisCluster = awsHelper
-								.getRequiredListeners(clusterMembers.iterator()
-										.next());
+							List<Listener> listenersForThisCluster = awsHelper
+									.getRequiredListeners(clusterMembers.iterator()
+											.next());
 
-						String loadBalancerDNSName = awsHelper
-								.createLoadBalancer(loadBalancerName,
-										listenersForThisCluster, region);
+							String loadBalancerDNSName = awsHelper
+									.createLoadBalancer(loadBalancerName,
+											listenersForThisCluster, region);
 
-						log.info("Load balancer '" + loadBalancerDNSName
-								+ "' created for cluster '"
-								+ cluster.getClusterId());
+							log.info("Load balancer '" + loadBalancerDNSName
+									+ "' created for cluster '"
+									+ cluster.getClusterId());
 
-						// register instances to LB
-						List<Instance> instances = new ArrayList<Instance>();
+							// register instances to LB
+							List<Instance> instances = new ArrayList<Instance>();
 
-						for (Member member : clusterMembers) {
-							String instanceId = member.getInstanceId();
+							for (Member member : clusterMembers) {
+								String instanceId = member.getInstanceId();
 
-							System.out.println("Instance id : " + instanceId);
-							System.out.println("New instance id : "
-									+ awsHelper.getAWSInstanceName(instanceId));
+								System.out.println("Instance id : " + instanceId);
+								System.out.println("New instance id : "
+										+ awsHelper.getAWSInstanceName(instanceId));
 
-							Instance instance = new Instance();
-							instance.setInstanceId(awsHelper
-									.getAWSInstanceName(instanceId));
+								Instance instance = new Instance();
+								instance.setInstanceId(awsHelper
+										.getAWSInstanceName(instanceId));
 
-							instances.add(instance);
-						}
+								instances.add(instance);
+							}
 
-						awsHelper.registerInstancesToLoadBalancer(
-								loadBalancerName, instances, region);
+							awsHelper.registerInstancesToLoadBalancer(
+									loadBalancerName, instances, region);
 
-						// Create domain mappings
+							// Create domain mappings
 
-						LoadBalancerInfo loadBalancerInfo = new LoadBalancerInfo(
-								loadBalancerName, region);
+							LoadBalancerInfo loadBalancerInfo = new LoadBalancerInfo(
+									loadBalancerName, region);
 
-						clusterIdToLoadBalancerMap.put(cluster.getClusterId(),
-								loadBalancerInfo);
-						activeClusters.add(cluster.getClusterId());
+							clusterIdToLoadBalancerMap.put(cluster.getClusterId(),
+									loadBalancerInfo);
+							activeClusters.add(cluster.getClusterId());
+						}
 					}
 				}
 			}


Mime
View raw message