You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ga...@apache.org on 2015/10/10 09:47:16 UTC

[2/4] stratos git commit: Adding the aws lb extension

http://git-wip-us.apache.org/repos/asf/stratos/blob/16034523/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
new file mode 100644
index 0000000..a8164e7
--- /dev/null
+++ b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
@@ -0,0 +1,926 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+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.ClientConfiguration;
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.services.cloudwatch.AmazonCloudWatchClient;
+import com.amazonaws.services.cloudwatch.model.Datapoint;
+import com.amazonaws.services.cloudwatch.model.Dimension;
+import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest;
+import com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult;
+import com.amazonaws.services.ec2.AmazonEC2Client;
+import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest;
+import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest;
+import com.amazonaws.services.ec2.model.CreateSecurityGroupResult;
+import com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest;
+import com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult;
+import com.amazonaws.services.ec2.model.IpPermission;
+import com.amazonaws.services.ec2.model.SecurityGroup;
+import com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingClient;
+import com.amazonaws.services.elasticloadbalancing.model.*;
+
+public class AWSHelper {
+	private String awsAccessKey;
+	private String awsSecretKey;
+	private String lbPrefix;
+	private String lbSecurityGroupName;
+	private String lbSecurityGroupDescription;
+	private String allowedCidrIpForLBSecurityGroup;
+	private int statisticsInterval;
+
+	private AtomicInteger lbSequence;
+
+	private List<String> allowedProtocolsForLBSecurityGroup;
+
+	private ConcurrentHashMap<String, String> regionToSecurityGroupIdMap;
+
+	private BasicAWSCredentials awsCredentials;
+	private ClientConfiguration clientConfiguration;
+
+	AmazonElasticLoadBalancingClient elbClient;
+	AmazonEC2Client ec2Client;
+	private AmazonCloudWatchClient cloudWatchClient;
+
+	private static final Log log = LogFactory.getLog(AWSHelper.class);
+
+	public AWSHelper() throws LoadBalancerExtensionException {
+		// Read values for awsAccessKey, awsSecretKey etc. from config file
+
+		String awsPropertiesFile = System
+				.getProperty(Constants.AWS_PROPERTIES_FILE);
+
+		Properties properties = new Properties();
+
+		InputStream inputStream = null;
+
+		try {
+			inputStream = new FileInputStream(awsPropertiesFile);
+
+			properties.load(inputStream);
+
+			this.awsAccessKey = properties
+					.getProperty(Constants.AWS_ACCESS_KEY);
+			this.awsSecretKey = properties
+					.getProperty(Constants.AWS_SECRET_KEY);
+
+			if (this.awsAccessKey.isEmpty() || this.awsSecretKey.isEmpty()) {
+				throw new LoadBalancerExtensionException(
+						"Invalid AWS credentials.");
+			}
+
+			this.lbPrefix = properties.getProperty(Constants.LB_PREFIX);
+
+			if (this.lbPrefix.isEmpty()
+					|| this.lbPrefix.length() > Constants.LOAD_BALANCER_PREFIX_MAX_LENGTH) {
+				throw new LoadBalancerExtensionException(
+						"Invalid load balancer prefix.");
+			}
+
+			lbSequence = new AtomicInteger(1);
+
+			this.lbSecurityGroupName = properties
+					.getProperty(Constants.LOAD_BALANCER_SECURITY_GROUP_NAME);
+
+			if (this.lbSecurityGroupName.isEmpty()
+					|| this.lbSecurityGroupName.length() > Constants.SECURITY_GROUP_NAME_MAX_LENGTH) {
+				throw new LoadBalancerExtensionException(
+						"Invalid load balancer security group name.");
+			}
+
+			this.allowedCidrIpForLBSecurityGroup = properties
+					.getProperty(Constants.ALLOWED_CIDR_IP_KEY);
+
+			if (this.allowedCidrIpForLBSecurityGroup.isEmpty()) {
+				throw new LoadBalancerExtensionException(
+						"Invalid allowed CIDR IP.");
+			}
+
+			String allowedProtocols = properties
+					.getProperty(Constants.ALLOWED_PROTOCOLS);
+
+			if (allowedProtocols.isEmpty()) {
+				throw new LoadBalancerExtensionException(
+						"Please specify at least one Internet protocol.");
+			}
+
+			String[] protocols = allowedProtocols.split(",");
+
+			this.allowedProtocolsForLBSecurityGroup = new ArrayList<String>();
+
+			for (String protocol : protocols) {
+				this.allowedProtocolsForLBSecurityGroup.add(protocol);
+			}
+
+			String interval = properties
+					.getProperty(Constants.STATISTICS_INTERVAL);
+
+			if (interval == null || interval.isEmpty()) {
+				this.statisticsInterval = Constants.STATISTICS_INTERVAL_MULTIPLE_OF;
+			} else {
+				try {
+					this.statisticsInterval = Integer.parseInt(interval);
+
+					if (this.statisticsInterval
+							% Constants.STATISTICS_INTERVAL_MULTIPLE_OF != 0) {
+						this.statisticsInterval = Constants.STATISTICS_INTERVAL_MULTIPLE_OF;
+					}
+				} catch (NumberFormatException e) {
+					log.warn("Invalid statistics interval. Setting it to 15.");
+					this.statisticsInterval = 15;
+				}
+			}
+
+			this.lbSecurityGroupDescription = Constants.LOAD_BALANCER_SECURITY_GROUP_DESCRIPTION;
+
+			regionToSecurityGroupIdMap = new ConcurrentHashMap<String, String>();
+
+			awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
+			clientConfiguration = new ClientConfiguration();
+
+			elbClient = new AmazonElasticLoadBalancingClient(awsCredentials,
+					clientConfiguration);
+
+			ec2Client = new AmazonEC2Client(awsCredentials, clientConfiguration);
+
+			cloudWatchClient = new AmazonCloudWatchClient(awsCredentials,
+					clientConfiguration);
+
+		} 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.");
+			}
+		}
+	}
+
+	public int getStatisticsInterval() {
+		return statisticsInterval;
+	}
+
+	public int getNextLBSequence() {
+		return lbSequence.getAndIncrement();
+	}
+
+	public String getLbSecurityGroupName() {
+		return lbSecurityGroupName;
+	}
+
+	public List<String> getAllowedProtocolsForLBSecurityGroup() {
+		return allowedProtocolsForLBSecurityGroup;
+	}
+
+	/**
+	 * Creates a load balancer and returns its DNS name. Useful when a new
+	 * cluster is added.
+	 * 
+	 * @param name
+	 *            of the load balancer to be created
+	 * @param listeners
+	 *            to be attached to the load balancer
+	 * @param region
+	 *            in which the load balancer needs to be created
+	 * @return DNS name of newly created load balancer
+	 * @throws LoadBalancerExtensionException
+	 */
+	public String createLoadBalancer(String name, List<Listener> listeners,
+			String region) throws LoadBalancerExtensionException {
+
+		log.info("Creating load balancer " + name);
+
+		CreateLoadBalancerRequest createLoadBalancerRequest = new CreateLoadBalancerRequest(
+				name);
+
+		createLoadBalancerRequest.setListeners(listeners);
+
+		Set<String> availabilityZones = new HashSet<String>();
+		availabilityZones.add(getAvailabilityZoneFromRegion(region));
+
+		createLoadBalancerRequest.setAvailabilityZones(availabilityZones);
+
+		try {
+			String securityGroupId = getSecurityGroupIdForRegion(region);
+
+			List<String> securityGroups = new ArrayList<String>();
+			securityGroups.add(securityGroupId);
+
+			createLoadBalancerRequest.setSecurityGroups(securityGroups);
+
+			elbClient.setEndpoint(String.format(
+					Constants.ELB_ENDPOINT_URL_FORMAT, region));
+
+			CreateLoadBalancerResult clbResult = elbClient
+					.createLoadBalancer(createLoadBalancerRequest);
+
+			return clbResult.getDNSName();
+
+		} catch (AmazonClientException e) {
+			throw new LoadBalancerExtensionException(
+					"Could not create load balancer " + name, e);
+		}
+	}
+
+	/**
+	 * Deletes the load balancer with the name provided. Useful when a cluster,
+	 * with which this load balancer was associated, is removed.
+	 * 
+	 * @param loadBalancerName
+	 *            to be deleted
+	 * @param region
+	 *            of the laod balancer
+	 */
+	public void deleteLoadBalancer(String loadBalancerName, String region) {
+
+		log.info("Deleting load balancer " + loadBalancerName);
+
+		DeleteLoadBalancerRequest deleteLoadBalancerRequest = new DeleteLoadBalancerRequest();
+		deleteLoadBalancerRequest.setLoadBalancerName(loadBalancerName);
+
+		try {
+			elbClient.setEndpoint(String.format(
+					Constants.ELB_ENDPOINT_URL_FORMAT, region));
+
+			elbClient.deleteLoadBalancer(deleteLoadBalancerRequest);
+			log.info("Deleted load balancer " + loadBalancerName);
+		} catch (AmazonClientException e) {
+			log.error("Could not delete load balancer : " + loadBalancerName, e);
+		}
+	}
+
+	/**
+	 * Attaches provided instances to the load balancer. Useful when new
+	 * instances get added to the cluster with which this load balancer is
+	 * associated.
+	 * 
+	 * @param loadBalancerName
+	 * @param instances
+	 *            to attached to the load balancer
+	 * @param region
+	 *            of the load balancer
+	 */
+	public void registerInstancesToLoadBalancer(String loadBalancerName,
+			List<Instance> instances, String region) {
+
+		log.info("Registering following instance(s) to load balancer "
+				+ loadBalancerName);
+
+		for (Instance instance : instances) {
+			log.info(instance.getInstanceId());
+		}
+
+		RegisterInstancesWithLoadBalancerRequest registerInstancesWithLoadBalancerRequest = new RegisterInstancesWithLoadBalancerRequest(
+				loadBalancerName, instances);
+
+		try {
+			elbClient.setEndpoint(String.format(
+					Constants.ELB_ENDPOINT_URL_FORMAT, region));
+
+			elbClient
+					.registerInstancesWithLoadBalancer(registerInstancesWithLoadBalancerRequest);
+
+		} catch (AmazonClientException e) {
+			log.error("Could not register instances to load balancer "
+					+ loadBalancerName, e);
+		}
+	}
+
+	/**
+	 * Detaches provided instances from the load balancer, associated with some
+	 * cluster. Useful when instances are removed from the cluster with which
+	 * this load balancer is associated.
+	 * 
+	 * @param loadBalancerName
+	 * @param instances
+	 *            to be de-registered from load balancer
+	 * @param region
+	 *            of the load balancer
+	 */
+	public void deregisterInstancesFromLoadBalancer(String loadBalancerName,
+			List<Instance> instances, String region) {
+
+		log.info("De-registering following instance(s) from load balancer "
+				+ loadBalancerName);
+
+		for (Instance instance : instances) {
+			log.info(instance.getInstanceId());
+		}
+
+		DeregisterInstancesFromLoadBalancerRequest deregisterInstancesFromLoadBalancerRequest = new DeregisterInstancesFromLoadBalancerRequest(
+				loadBalancerName, instances);
+
+		try {
+			elbClient.setEndpoint(String.format(
+					Constants.ELB_ENDPOINT_URL_FORMAT, region));
+
+			elbClient
+					.deregisterInstancesFromLoadBalancer(deregisterInstancesFromLoadBalancerRequest);
+
+		} catch (AmazonClientException e) {
+			log.error("Could not de-register instances from load balancer "
+					+ loadBalancerName, e);
+		}
+	}
+
+	/**
+	 * Returns description of the load balancer which is helpful in determining
+	 * instances, listeners associated with load balancer
+	 * 
+	 * @param loadBalancerName
+	 * @param region
+	 *            of the load balancer
+	 * @return description of the load balancer
+	 */
+	private LoadBalancerDescription getLoadBalancerDescription(
+			String loadBalancerName, String region) {
+
+		List<String> loadBalancers = new ArrayList<String>();
+		loadBalancers.add(loadBalancerName);
+
+		DescribeLoadBalancersRequest describeLoadBalancersRequest = new DescribeLoadBalancersRequest(
+				loadBalancers);
+
+		try {
+			elbClient.setEndpoint(String.format(
+					Constants.ELB_ENDPOINT_URL_FORMAT, region));
+
+			DescribeLoadBalancersResult result = elbClient
+					.describeLoadBalancers(describeLoadBalancersRequest);
+
+			if (result.getLoadBalancerDescriptions() != null
+					&& result.getLoadBalancerDescriptions().size() > 0)
+				return result.getLoadBalancerDescriptions().get(0);
+		} catch (AmazonClientException e) {
+			log.error("Could not find description of load balancer "
+					+ loadBalancerName, e);
+		}
+
+		return null;
+	}
+
+	/**
+	 * Returns instances attached to the load balancer. Useful when deciding if
+	 * all attached instances are required or some should be detached.
+	 * 
+	 * @param loadBalancerName
+	 * @param region
+	 * @return list of instances attached
+	 */
+	public List<Instance> getAttachedInstances(String loadBalancerName,
+			String region) {
+		try {
+			LoadBalancerDescription lbDescription = getLoadBalancerDescription(
+					loadBalancerName, region);
+
+			if (lbDescription == null) {
+				log.warn("Could not find description of load balancer "
+						+ loadBalancerName);
+				return null;
+			}
+
+			return lbDescription.getInstances();
+
+		} catch (AmazonClientException e) {
+			log.error("Could not find instances attached  load balancer "
+					+ loadBalancerName, e);
+			return null;
+		}
+	}
+
+	/**
+	 * Returns all the listeners attached to the load balancer. Useful while
+	 * deciding if all the listeners are necessary or some should be removed.
+	 * 
+	 * @param loadBalancerName
+	 * @param region
+	 * @return list of instances attached to load balancer
+	 */
+	public List<Listener> getAttachedListeners(String loadBalancerName,
+			String region) {
+		try {
+			LoadBalancerDescription lbDescription = getLoadBalancerDescription(
+					loadBalancerName, region);
+
+			if (lbDescription == null) {
+				log.warn("Could not find description of load balancer "
+						+ loadBalancerName);
+				return null;
+			}
+
+			List<Listener> listeners = new ArrayList<Listener>();
+
+			List<ListenerDescription> listenerDescriptions = lbDescription
+					.getListenerDescriptions();
+
+			for (ListenerDescription listenerDescription : listenerDescriptions) {
+				listeners.add(listenerDescription.getListener());
+			}
+
+			return listeners;
+
+		} catch (AmazonClientException e) {
+			log.error("Could not find description of load balancer "
+					+ loadBalancerName);
+			return null;
+		}
+
+	}
+
+	/**
+	 * Checks if the security group is already present in the given region. If
+	 * yes, then returns its group id. If not, present the returns null.
+	 * 
+	 * @param groupName
+	 *            to be checked for presence.
+	 * @param region
+	 * @return id of the security group
+	 */
+	public String getSecurityGroupId(String groupName, String region) {
+		if (groupName == null || groupName.isEmpty()) {
+			return null;
+		}
+
+		DescribeSecurityGroupsRequest describeSecurityGroupsRequest = new DescribeSecurityGroupsRequest();
+
+		List<String> groupNames = new ArrayList<String>();
+		groupNames.add(groupName);
+
+		describeSecurityGroupsRequest.setGroupNames(groupNames);
+
+		try {
+			ec2Client.setEndpoint(String.format(
+					Constants.EC2_ENDPOINT_URL_FORMAT, region));
+
+			DescribeSecurityGroupsResult describeSecurityGroupsResult = ec2Client
+					.describeSecurityGroups(describeSecurityGroupsRequest);
+
+			List<SecurityGroup> securityGroups = describeSecurityGroupsResult
+					.getSecurityGroups();
+
+			if (securityGroups != null && securityGroups.size() > 0) {
+				return securityGroups.get(0).getGroupId();
+			}
+		} catch (AmazonClientException e) {
+			log.debug("Could not describe security groups.", e);
+		}
+
+		return null;
+	}
+
+	/**
+	 * Creates security group with the given name in the given region
+	 * 
+	 * @param groupName
+	 *            to be created
+	 * @param description
+	 * @param region
+	 *            in which the security group to be created
+	 * @return Id of the security group created
+	 * @throws LoadBalancerExtensionException
+	 */
+	public String createSecurityGroup(String groupName, String description,
+			String region) throws LoadBalancerExtensionException {
+		if (groupName == null || groupName.isEmpty()) {
+			throw new LoadBalancerExtensionException(
+					"Invalid Security Group Name.");
+		}
+
+		CreateSecurityGroupRequest createSecurityGroupRequest = new CreateSecurityGroupRequest();
+		createSecurityGroupRequest.setGroupName(groupName);
+		createSecurityGroupRequest.setDescription(description);
+
+		try {
+			ec2Client.setEndpoint(String.format(
+					Constants.EC2_ENDPOINT_URL_FORMAT, region));
+
+			CreateSecurityGroupResult createSecurityGroupResult = ec2Client
+					.createSecurityGroup(createSecurityGroupRequest);
+
+			return createSecurityGroupResult.getGroupId();
+
+		} catch (AmazonClientException e) {
+			log.error("Could not create security group.", e);
+			throw new LoadBalancerExtensionException(
+					"Could not create security group.", e);
+		}
+
+	}
+
+	/**
+	 * Adds inbound rule to the security group which allows users to access load
+	 * balancer at specified port and using the specified protocol. Port
+	 * specified should be a proxy port mentioned in the port mappings of the
+	 * cartridge.
+	 * 
+	 * @param groupId
+	 *            to which this rule to be added
+	 * @param region
+	 *            of the security group
+	 * @param protocol
+	 *            with which load balancer can be accessed
+	 * @param port
+	 *            at which load balancer can be accessed
+	 * @throws LoadBalancerExtensionException
+	 */
+	public void addInboundRuleToSecurityGroup(String groupId, String region,
+			String protocol, int port) throws LoadBalancerExtensionException {
+		if (groupId == null || groupId.isEmpty()) {
+			throw new LoadBalancerExtensionException(
+					"Invalid security group Id for addInboundRuleToSecurityGroup.");
+		}
+
+		boolean ruleAlreadyPresent = false;
+
+		DescribeSecurityGroupsRequest describeSecurityGroupsRequest = new DescribeSecurityGroupsRequest();
+
+		List<String> groupIds = new ArrayList<String>();
+		groupIds.add(groupId);
+
+		describeSecurityGroupsRequest.setGroupIds(groupIds);
+
+		SecurityGroup secirutyGroup = null;
+
+		try {
+			ec2Client.setEndpoint(String.format(
+					Constants.EC2_ENDPOINT_URL_FORMAT, region));
+
+			DescribeSecurityGroupsResult describeSecurityGroupsResult = ec2Client
+					.describeSecurityGroups(describeSecurityGroupsRequest);
+
+			List<SecurityGroup> securityGroups = describeSecurityGroupsResult
+					.getSecurityGroups();
+
+			if (securityGroups != null && securityGroups.size() > 0) {
+				secirutyGroup = securityGroups.get(0);
+			}
+		} catch (AmazonClientException e) {
+			log.error("Could not describe security groups.", e);
+		}
+
+		if (secirutyGroup != null) {
+			List<IpPermission> existingPermissions = secirutyGroup
+					.getIpPermissions();
+
+			IpPermission neededPermission = new IpPermission();
+			neededPermission.setFromPort(port);
+			neededPermission.setToPort(port);
+			neededPermission.setIpProtocol(protocol);
+
+			Collection<String> ipRanges = new HashSet<String>();
+			ipRanges.add(this.allowedCidrIpForLBSecurityGroup);
+
+			neededPermission.setIpRanges(ipRanges);
+
+			if (existingPermissions.contains(neededPermission)) {
+				ruleAlreadyPresent = true;
+			}
+		}
+
+		if (!ruleAlreadyPresent) {
+			AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest = new AuthorizeSecurityGroupIngressRequest();
+			authorizeSecurityGroupIngressRequest.setGroupId(groupId);
+			authorizeSecurityGroupIngressRequest
+					.setCidrIp(this.allowedCidrIpForLBSecurityGroup);
+			authorizeSecurityGroupIngressRequest.setFromPort(port);
+			authorizeSecurityGroupIngressRequest.setToPort(port);
+			authorizeSecurityGroupIngressRequest.setIpProtocol(protocol);
+
+			try {
+				ec2Client.setEndpoint(String.format(
+						Constants.EC2_ENDPOINT_URL_FORMAT, region));
+
+				ec2Client
+						.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);
+
+			} catch (AmazonClientException e) {
+				throw new LoadBalancerExtensionException(
+						"Could not add inbound rule to security group "
+								+ groupId + ".", e);
+			}
+		}
+	}
+
+	/**
+	 * Returns the security group id for the given region if it is already
+	 * present. If it is not already present then creates a new security group
+	 * in that region.
+	 * 
+	 * @param region
+	 * @return Id of the security group
+	 * @throws LoadBalancerExtensionException
+	 */
+	public String getSecurityGroupIdForRegion(String region)
+			throws LoadBalancerExtensionException {
+		if (region == null)
+			return null;
+
+		if (this.regionToSecurityGroupIdMap.contains(region)) {
+			return this.regionToSecurityGroupIdMap.get(region);
+		} else {
+			// Get the the security group id if it is already present.
+			String securityGroupId = getSecurityGroupId(
+					this.lbSecurityGroupName, region);
+
+			if (securityGroupId == null) {
+				securityGroupId = createSecurityGroup(this.lbSecurityGroupName,
+						this.lbSecurityGroupDescription, region);
+			}
+
+			this.regionToSecurityGroupIdMap.put(region, securityGroupId);
+
+			return securityGroupId;
+		}
+	}
+
+	/**
+	 * Retrieves the total number of requests that were made to the load
+	 * balancer during the given time interval in the past
+	 * 
+	 * @param loadBalancerName
+	 * @param region
+	 * @param timeInterval
+	 *            in seconds which must be multiple of 60
+	 * @return number of requests made
+	 */
+	public int getRequestCount(String loadBalancerName, String region,
+			int timeInterval) {
+		int count = 0;
+
+		try {
+			GetMetricStatisticsRequest request = new GetMetricStatisticsRequest();
+			request.setMetricName(Constants.REQUEST_COUNT_METRIC_NAME);
+			request.setNamespace(Constants.CLOUD_WATCH_NAMESPACE_NAME);
+
+			Date currentTime = new DateTime(DateTimeZone.UTC).toDate();
+			Date pastTime = new DateTime(DateTimeZone.UTC).minusSeconds(
+					timeInterval).toDate();
+
+			request.setStartTime(pastTime);
+			request.setEndTime(currentTime);
+
+			request.setPeriod(timeInterval);
+
+			HashSet<String> statistics = new HashSet<String>();
+			statistics.add(Constants.SUM_STATISTICS_NAME);
+			request.setStatistics(statistics);
+
+			HashSet<Dimension> dimensions = new HashSet<Dimension>();
+			Dimension loadBalancerDimension = new Dimension();
+			loadBalancerDimension
+					.setName(Constants.LOAD_BALANCER_DIMENTION_NAME);
+			loadBalancerDimension.setValue(loadBalancerName);
+			dimensions.add(loadBalancerDimension);
+			request.setDimensions(dimensions);
+
+			cloudWatchClient.setEndpoint(String.format(
+					Constants.CLOUD_WATCH_ENDPOINT_URL_FORMAT, region));
+
+			GetMetricStatisticsResult result = cloudWatchClient
+					.getMetricStatistics(request);
+
+			List<Datapoint> dataPoints = result.getDatapoints();
+
+			if (dataPoints != null && dataPoints.size() > 0) {
+				count = dataPoints.get(0).getSum().intValue();
+			}
+
+		} catch (AmazonClientException e) {
+			log.error(
+					"Could not get request count statistics of load balancer "
+							+ loadBalancerName, e);
+		}
+
+		return count;
+	}
+
+	/**
+	 * Retrieves total number of responses generated by all instances attached
+	 * to the load balancer during the time interval in the past.
+	 * 
+	 * @param loadBalancerName
+	 * @param region
+	 * @param timeInterval
+	 *            in seconds which must be multiple of 60
+	 * @return number of responses generated
+	 */
+	public int getAllResponsesCount(String loadBalancerName, String region,
+			int timeInterval) {
+		int total = 0;
+
+		Date currentTime = new DateTime(DateTimeZone.UTC).toDate();
+		Date pastTime = new DateTime(DateTimeZone.UTC).minusSeconds(
+				timeInterval).toDate();
+
+		total += getResponseCountForMetric(loadBalancerName, region,
+				Constants.HTTP_RESPONSE_2XX, pastTime, currentTime,
+				timeInterval);
+		total += getResponseCountForMetric(loadBalancerName, region,
+				Constants.HTTP_RESPONSE_3XX, pastTime, currentTime,
+				timeInterval);
+		total += getResponseCountForMetric(loadBalancerName, region,
+				Constants.HTTP_RESPONSE_4XX, pastTime, currentTime,
+				timeInterval);
+		total += getResponseCountForMetric(loadBalancerName, region,
+				Constants.HTTP_RESPONSE_5XX, pastTime, currentTime,
+				timeInterval);
+
+		return total;
+	}
+
+	/**
+	 * Retrieves the number of responses generated for a particular response
+	 * code like 2XX, 3XX, 4XX, 5XX
+	 * 
+	 * @param loadBalancerName
+	 * @param region
+	 * @param metricName
+	 *            which is one among HTTPCode_Backend_2XX or
+	 *            HTTPCode_Backend_3XX or HTTPCode_Backend_4XX or
+	 *            HTTPCode_Backend_5XX
+	 * @param startTime
+	 *            of the window to be scanned
+	 * @param endTime
+	 *            of the window to be scanned
+	 * @param timeInterval
+	 *            in seconds
+	 * @return number for response for this metric
+	 */
+	public int getResponseCountForMetric(String loadBalancerName,
+			String region, String metricName, Date startTime, Date endTime,
+			int timeInterval) {
+		int count = 0;
+
+		try {
+			GetMetricStatisticsRequest request = new GetMetricStatisticsRequest();
+			request.setMetricName(metricName);
+			request.setNamespace(Constants.CLOUD_WATCH_NAMESPACE_NAME);
+
+			request.setStartTime(startTime);
+			request.setEndTime(endTime);
+
+			request.setPeriod(timeInterval);
+
+			HashSet<String> statistics = new HashSet<String>();
+			statistics.add(Constants.SUM_STATISTICS_NAME);
+			request.setStatistics(statistics);
+
+			HashSet<Dimension> dimensions = new HashSet<Dimension>();
+			Dimension loadBalancerDimension = new Dimension();
+			loadBalancerDimension
+					.setName(Constants.LOAD_BALANCER_DIMENTION_NAME);
+			loadBalancerDimension.setValue(loadBalancerName);
+			dimensions.add(loadBalancerDimension);
+			request.setDimensions(dimensions);
+
+			cloudWatchClient.setEndpoint(String.format(
+					Constants.CLOUD_WATCH_ENDPOINT_URL_FORMAT, region));
+
+			GetMetricStatisticsResult result = cloudWatchClient
+					.getMetricStatistics(request);
+
+			List<Datapoint> dataPoints = result.getDatapoints();
+
+			if (dataPoints != null && dataPoints.size() > 0) {
+				count = dataPoints.get(0).getSum().intValue();
+			}
+
+		} catch (AmazonClientException e) {
+			log.error("Could not get the statistics for metric " + metricName
+					+ " of load balancer " + loadBalancerName, e);
+		}
+
+		return count;
+	}
+
+	/**
+	 * Returns the Listeners required for the service. Listeners are derived
+	 * from the proxy port, port and protocol values of the service.
+	 * 
+	 * @param service
+	 * @return list of listeners required for the service
+	 */
+	public List<Listener> getRequiredListeners(Member member) {
+		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);
+
+			listeners.add(listener);
+		}
+
+		return listeners;
+	}
+
+	/**
+	 * Constructs name of the load balancer to be associated with the cluster
+	 * 
+	 * @param clusterId
+	 * @return name of the load balancer
+	 * @throws LoadBalancerExtensionException
+	 */
+	public String generateLoadBalancerName()
+			throws LoadBalancerExtensionException {
+		String name = null;
+
+		name = lbPrefix + getNextLBSequence();
+
+		if (name.length() > Constants.LOAD_BALANCER_NAME_MAX_LENGTH)
+			throw new LoadBalancerExtensionException(
+					"Load balanacer name length (32 characters) exceeded");
+
+		return name;
+	}
+
+	/**
+	 * Extract instance id in IaaS side from member instance name
+	 * 
+	 * @param memberInstanceName
+	 * @return instance id in IaaS
+	 */
+	public String getAWSInstanceName(String memberInstanceName) {
+		if (memberInstanceName.contains("/")) {
+			return memberInstanceName
+					.substring(memberInstanceName.indexOf("/") + 1);
+		} else {
+			return memberInstanceName;
+		}
+	}
+
+	/**
+	 * Extract IaaS region from member instance name
+	 * 
+	 * @param memberInstanceName
+	 * @return IaaS region to which member belongs
+	 */
+	public String getAWSRegion(String memberInstanceName) {
+		if (memberInstanceName.contains("/")) {
+			return memberInstanceName.substring(0,
+					memberInstanceName.indexOf("/"));
+		} else {
+			return null;
+		}
+	}
+
+	/**
+	 * Get availability zone from region
+	 * 
+	 * @param region
+	 * @return Availability zone of IaaS
+	 */
+	public String getAvailabilityZoneFromRegion(String region) {
+		if (region != null) {
+			return region + "a";
+		} else
+			return null;
+	}
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/16034523/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSLoadBalancer.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSLoadBalancer.java b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSLoadBalancer.java
new file mode 100644
index 0000000..4621339
--- /dev/null
+++ b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSLoadBalancer.java
@@ -0,0 +1,305 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.aws.extension;
+
+import com.amazonaws.services.elasticloadbalancing.model.Instance;
+import com.amazonaws.services.elasticloadbalancing.model.Listener;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.load.balancer.common.domain.Cluster;
+import org.apache.stratos.load.balancer.common.domain.Member;
+import org.apache.stratos.load.balancer.common.domain.Service;
+import org.apache.stratos.load.balancer.common.domain.Topology;
+import org.apache.stratos.load.balancer.extension.api.LoadBalancer;
+import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class AWSLoadBalancer implements LoadBalancer {
+
+	private static final Log log = LogFactory.getLog(AWSLoadBalancer.class);
+
+	// A map <clusterId, load balancer info> to store load balancer information
+	// against the cluster id
+	private static ConcurrentHashMap<String, LoadBalancerInfo> clusterIdToLoadBalancerMap = new ConcurrentHashMap<String, LoadBalancerInfo>();
+
+	// Object used to invoke methods related to AWS API
+	private AWSHelper awsHelper;
+
+	public AWSLoadBalancer() throws LoadBalancerExtensionException {
+		awsHelper = new AWSHelper();
+	}
+
+	/*
+	 * configure method iterates over topology and configures the AWS load
+	 * balancers needed. Configuration may involve creating a new load balancer
+	 * for a cluster, updating existing load balancers or deleting unwanted load
+	 * balancers.
+	 */
+	public boolean configure(Topology topology)
+			throws LoadBalancerExtensionException {
+
+		log.info("AWS load balancer extension is being reconfigured.");
+
+		HashSet<String> activeClusters = new HashSet<String>();
+
+		for (Service service : topology.getServices()) {
+			for (Cluster cluster : service.getClusters()) {
+				// Check if a load balancer is created for this cluster
+				if (clusterIdToLoadBalancerMap.containsKey(cluster
+						.getClusterId())) {
+					// A load balancer is already present for this cluster
+					// Get the load balancer and update it.
+
+					if (log.isDebugEnabled()) {
+						log.debug("Load balancer for cluster "
+								+ cluster.getClusterId()
+								+ " is already present.");
+					}
+
+					LoadBalancerInfo loadBalancerInfo = clusterIdToLoadBalancerMap
+							.get(cluster.getClusterId());
+
+					String loadBalancerName = loadBalancerInfo.getName();
+					String region = loadBalancerInfo.getRegion();
+
+					// Get all the instances attached
+					// Attach newly added instances to load balancer
+
+					// attachedInstances list is useful in finding out what
+					// all new instances which
+					// should be attached to this load balancer.
+					List<Instance> attachedInstances = awsHelper
+							.getAttachedInstances(loadBalancerName, region);
+
+					// clusterMembers stores all the members of a cluster.
+					Collection<Member> clusterMembers = cluster.getMembers();
+
+					if (clusterMembers.size() > 0) {
+						activeClusters.add(cluster.getClusterId());
+
+						List<Instance> instancesToAddToLoadBalancer = new ArrayList<Instance>();
+
+						for (Member member : clusterMembers) {
+							// if instance id of member is not in
+							// attachedInstances
+							// add this to instancesToAddToLoadBalancer
+							Instance instance = new Instance(
+									awsHelper.getAWSInstanceName(member
+											.getInstanceId()));
+
+							if (attachedInstances == null
+									|| !attachedInstances.contains(instance)) {
+								instancesToAddToLoadBalancer.add(instance);
+
+								if (log.isDebugEnabled()) {
+									log.debug("Instance "
+											+ awsHelper
+													.getAWSInstanceName(member
+															.getInstanceId())
+											+ " needs to be registered to load balancer "
+											+ loadBalancerName);
+								}
+
+							}
+						}
+
+						if (instancesToAddToLoadBalancer.size() > 0)
+							awsHelper.registerInstancesToLoadBalancer(
+									loadBalancerName,
+									instancesToAddToLoadBalancer, region);
+					}
+
+				} else {
+					// Create a new load balancer for this cluster
+					Collection<Member> clusterMembers = cluster.getMembers();
+
+					if (clusterMembers.size() > 0) {
+						// a unique load balancer name with user-defined
+						// prefix and a sequence number.
+						String loadBalancerName = awsHelper
+								.generateLoadBalancerName();
+
+						String region = awsHelper.getAWSRegion(clusterMembers
+								.iterator().next().getInstanceId());
+
+						// list of AWS listeners obtained using port
+						// mappings of one of the members of the cluster.
+						List<Listener> listenersForThisCluster = awsHelper
+								.getRequiredListeners(clusterMembers.iterator()
+										.next());
+
+						// DNS name of load balancer which was created.
+						// This is used in the domain mapping of this
+						// cluster.
+						String loadBalancerDNSName = awsHelper
+								.createLoadBalancer(loadBalancerName,
+										listenersForThisCluster, region);
+
+						// Add the inbound rule the security group of the load
+						// balancer
+						// For each listener, add a new rule with load
+						// balancer port as allowed protocol in the security
+						// group.
+						for (Listener listener : listenersForThisCluster) {
+							int port = listener.getLoadBalancerPort();
+
+							for (String protocol : awsHelper
+									.getAllowedProtocolsForLBSecurityGroup()) {
+								awsHelper
+										.addInboundRuleToSecurityGroup(
+												awsHelper.getSecurityGroupId(
+														awsHelper
+																.getLbSecurityGroupName(),
+														region), region,
+												protocol, port);
+							}
+						}
+
+						log.info("Load balancer '" + loadBalancerDNSName
+								+ "' created for cluster '"
+								+ cluster.getClusterId());
+
+						// Register instances in the cluster to load balancer
+						List<Instance> instances = new ArrayList<Instance>();
+
+						for (Member member : clusterMembers) {
+							String instanceId = member.getInstanceId();
+
+							if (log.isDebugEnabled()) {
+								log.debug("Instance "
+										+ awsHelper
+												.getAWSInstanceName(instanceId)
+										+ " needs to be registered to load balancer "
+										+ loadBalancerName);
+							}
+
+							Instance instance = new Instance();
+							instance.setInstanceId(awsHelper
+									.getAWSInstanceName(instanceId));
+
+							instances.add(instance);
+						}
+
+						awsHelper.registerInstancesToLoadBalancer(
+								loadBalancerName, instances, region);
+
+						LoadBalancerInfo loadBalancerInfo = new LoadBalancerInfo(
+								loadBalancerName, region);
+
+						clusterIdToLoadBalancerMap.put(cluster.getClusterId(),
+								loadBalancerInfo);
+						activeClusters.add(cluster.getClusterId());
+					}
+				}
+			}
+		}
+
+		// Find out clusters which were present earlier but are not now.
+		List<String> clustersToRemoveFromMap = new ArrayList<String>();
+
+		for (String clusterId : clusterIdToLoadBalancerMap.keySet()) {
+			if (!activeClusters.contains(clusterId)) {
+				clustersToRemoveFromMap.add(clusterId);
+
+				if (log.isDebugEnabled()) {
+					log.debug("Load balancer for cluster " + clusterId
+							+ " needs to be removed.");
+				}
+
+			}
+		}
+
+		// Delete load balancers associated with these clusters.
+		for (String clusterId : clustersToRemoveFromMap) {
+			// Remove load balancer for this cluster.
+			awsHelper.deleteLoadBalancer(
+					clusterIdToLoadBalancerMap.get(clusterId).getName(),
+					clusterIdToLoadBalancerMap.get(clusterId).getRegion());
+			clusterIdToLoadBalancerMap.remove(clusterId);
+		}
+
+		activeClusters.clear();
+		log.info("AWS load balancer extension was reconfigured as per the topology.");
+		return true;
+	}
+
+	/*
+	 * start method is called after extension if configured first time. Does
+	 * nothing but logs the message.
+	 */
+	public void start() throws LoadBalancerExtensionException {
+
+		log.info("AWS load balancer extension started.");
+	}
+
+	/*
+	 * reload method is called every time after extension if configured. Does
+	 * nothing but logs the message.
+	 */
+	public void reload() throws LoadBalancerExtensionException {
+		// Check what is appropriate to do here.
+		log.info("AWS load balancer extension reloaded.");
+	}
+
+	/*
+	 * stop method deletes load balancers for all clusters in the topology.
+	 */
+	public void stop() throws LoadBalancerExtensionException {
+		// Remove all load balancers
+		for (LoadBalancerInfo loadBalancerInfo : clusterIdToLoadBalancerMap
+				.values()) {
+			// Remove load balancer
+			awsHelper.deleteLoadBalancer(loadBalancerInfo.getName(),
+					loadBalancerInfo.getRegion());
+		}
+	}
+
+	public static ConcurrentHashMap<String, LoadBalancerInfo> getClusterIdToLoadBalancerMap() {
+		return clusterIdToLoadBalancerMap;
+	}
+}
+
+/**
+ * Used to store load balancer name and the region in which it is created. This
+ * helps in finding region while calling API methods to modify/delete a load
+ * balancer.
+ */
+class LoadBalancerInfo {
+	private String name;
+	private String region;
+
+	public LoadBalancerInfo(String name, String region) {
+		this.name = name;
+		this.region = region;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public String getRegion() {
+		return region;
+	}
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/16034523/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSStatisticsReader.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSStatisticsReader.java b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSStatisticsReader.java
new file mode 100644
index 0000000..55aca3d
--- /dev/null
+++ b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSStatisticsReader.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.aws.extension;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.constants.StratosConstants;
+import org.apache.stratos.load.balancer.common.statistics.LoadBalancerStatisticsReader;
+import org.apache.stratos.load.balancer.common.topology.TopologyProvider;
+import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * AWS statistics reader.
+ */
+public class AWSStatisticsReader implements LoadBalancerStatisticsReader {
+
+	private static final Log log = LogFactory.getLog(AWSStatisticsReader.class);
+
+	private TopologyProvider topologyProvider;
+	private String clusterInstanceId;
+
+	private AWSHelper awsHelper;
+
+	public AWSStatisticsReader(TopologyProvider topologyProvider)
+			throws LoadBalancerExtensionException {
+		this.topologyProvider = topologyProvider;
+		this.clusterInstanceId = System.getProperty(
+				StratosConstants.CLUSTER_INSTANCE_ID,
+				StratosConstants.NOT_DEFINED);
+
+		awsHelper = new AWSHelper();
+	}
+
+	@Override
+	public String getClusterInstanceId() {
+		return clusterInstanceId;
+	}
+
+	@Override
+	public int getInFlightRequestCount(String clusterId) {
+
+		int inFlightRequestCount = 0;
+
+		ConcurrentHashMap<String, LoadBalancerInfo> clusterIdToLoadBalancerMap = AWSLoadBalancer
+				.getClusterIdToLoadBalancerMap();
+
+		// Check if load balancer info is available for this cluster.
+		// If yes, then find difference between total requests made to the load balancer and 
+		// total responses generated by instances attached to it.
+		if (clusterIdToLoadBalancerMap.containsKey(clusterId)) {
+			LoadBalancerInfo loadBalancerInfo = clusterIdToLoadBalancerMap
+					.get(clusterId);
+
+			String loadBalancerName = loadBalancerInfo.getName();
+			String region = loadBalancerInfo.getRegion();
+
+			// In flight request count = total requests - total responses
+			inFlightRequestCount = awsHelper.getRequestCount(loadBalancerName,
+					region, awsHelper.getStatisticsInterval())
+					- awsHelper.getAllResponsesCount(loadBalancerName, region,
+							awsHelper.getStatisticsInterval());
+
+			if (inFlightRequestCount < 0)
+				inFlightRequestCount = 0;
+
+		}
+
+		return inFlightRequestCount;
+	}
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/16034523/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
new file mode 100644
index 0000000..30ada5c
--- /dev/null
+++ b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/Constants.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.aws.extension;
+
+/**
+ * AWS proxy extension constants.
+ */
+public class Constants {
+	public static final String CEP_STATS_PUBLISHER_ENABLED = "cep.stats.publisher.enabled";
+	public static final String THRIFT_RECEIVER_IP = "thrift.receiver.ip";
+	public static final String THRIFT_RECEIVER_PORT = "thrift.receiver.port";
+	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_PROPERTIES_FILE = "aws.properties.file";
+	public static final String AWS_ACCESS_KEY = "access-key";
+	public static final String AWS_SECRET_KEY = "secret-key";
+	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 String ELB_ENDPOINT_URL_FORMAT = "elasticloadbalancing.%s.amazonaws.com";
+	public static final String EC2_ENDPOINT_URL_FORMAT = "ec2.%s.amazonaws.com";
+	public static final String CLOUD_WATCH_ENDPOINT_URL_FORMAT = "monitoring.%s.amazonaws.com";
+	public static final String ALLOWED_CIDR_IP_KEY = "allowed-cidr-ip";
+	public static final String ALLOWED_PROTOCOLS = "allowed-protocols";
+	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 REQUEST_COUNT_METRIC_NAME = "RequestCount";
+	public static final String CLOUD_WATCH_NAMESPACE_NAME = "AWS/ELB";
+	public static final String SUM_STATISTICS_NAME = "Sum";
+	public static final String LOAD_BALANCER_DIMENTION_NAME = "LoadBalancerName";
+	public static final String HTTP_RESPONSE_2XX = "HTTPCode_Backend_2XX";
+	public static final String HTTP_RESPONSE_3XX = "HTTPCode_Backend_3XX";
+	public static final String HTTP_RESPONSE_4XX = "HTTPCode_Backend_4XX";
+	public static final String HTTP_RESPONSE_5XX = "HTTPCode_Backend_5XX";
+	public static final String STATISTICS_INTERVAL = "statistics-interval";
+	public static final int STATISTICS_INTERVAL_MULTIPLE_OF = 60;
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/16034523/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/Main.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/Main.java b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/Main.java
new file mode 100644
index 0000000..73fa971
--- /dev/null
+++ b/extensions/load-balancer/modules/aws-extension/src/main/java/org/apache/stratos/aws/extension/Main.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.aws.extension;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.PropertyConfigurator;
+import org.apache.stratos.common.threading.StratosThreadPool;
+import org.apache.stratos.load.balancer.common.topology.TopologyProvider;
+import org.apache.stratos.load.balancer.extension.api.LoadBalancerExtension;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * AWS extension main class.
+ */
+
+public class Main {
+	private static final Log log = LogFactory.getLog(Main.class);
+	private static ExecutorService executorService;
+
+	public static void main(String[] args) {
+
+		LoadBalancerExtension extension = null;
+		try {
+			// Configure log4j properties
+			PropertyConfigurator.configure(System
+					.getProperty("log4j.properties.file.path"));
+
+			if (log.isInfoEnabled()) {
+				log.info("AWS extension started");
+			}
+
+			executorService = StratosThreadPool.getExecutorService(
+					"aws.extension.thread.pool", 10);
+			// Validate runtime parameters
+			AWSExtensionContext.getInstance().validate();
+			TopologyProvider topologyProvider = new TopologyProvider();
+			AWSStatisticsReader statisticsReader = AWSExtensionContext
+					.getInstance().isCEPStatsPublisherEnabled() ? new AWSStatisticsReader(
+					topologyProvider) : null;
+			extension = new LoadBalancerExtension(new AWSLoadBalancer(),
+					statisticsReader, topologyProvider);
+			extension.setExecutorService(executorService);
+			extension.execute();
+
+			// Add shutdown hook
+			final Thread mainThread = Thread.currentThread();
+			final LoadBalancerExtension finalExtension = extension;
+			Runtime.getRuntime().addShutdownHook(new Thread() {
+				public void run() {
+					try {
+						if (finalExtension != null) {
+							log.info("Shutting aws extension...");
+							finalExtension.stop();
+						}
+						mainThread.join();
+					} catch (Exception e) {
+						log.error(e);
+					}
+				}
+			});
+		} catch (Exception e) {
+			if (log.isErrorEnabled()) {
+				log.error(e);
+			}
+			if (extension != null) {
+				log.info("Shutting aws extension...");
+				extension.stop();
+			}
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/16034523/extensions/load-balancer/modules/aws-extension/src/main/license/LICENSE
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/modules/aws-extension/src/main/license/LICENSE b/extensions/load-balancer/modules/aws-extension/src/main/license/LICENSE
new file mode 100644
index 0000000..5a78fc9
--- /dev/null
+++ b/extensions/load-balancer/modules/aws-extension/src/main/license/LICENSE
@@ -0,0 +1,481 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+===================================================================================
+
+===================================================================================
+The Apache Stratos distribution includes a number of run time dependencies with 
+separate copyright notices and license terms. Your use of the Apache Stratos code
+is subject to the terms and conditions of the following licenses.
+===================================================================================
+
+===============================================================================
+The following components come under Apache Software License 2.0
+===============================================================================
+
+org.wso2.carbon.base-4.2.0.jar
+org.wso2.carbon.bootstrap-4.2.0.jar
+org.wso2.carbon.core-4.2.0.jar
+org.wso2.carbon.core.common-4.2.0.jar
+org.wso2.carbon.databridge.agent.thrift-4.2
+org.wso2.carbon.databridge.commons-4.2.
+org.wso2.carbon.databridge.commons.thrif
+org.wso2.carbon.logging-4.2.0.jar
+org.wso2.carbon.ndatasource.common-4.2.
+org.wso2.carbon.ndatasource.rdbms-4.2.0.j
+org.wso2.carbon.queuing-4.2.0.jar
+org.wso2.carbon.registry.api-4.2.0.jar
+org.wso2.carbon.registry.core-4.2.0.jar
+org.wso2.carbon.registry.xboot-4.2.0.jar
+org.wso2.carbon.securevault-4.2.0.jar
+org.wso2.carbon.user.api-4.2.0.jar
+org.wso2.carbon.user.core-4.2.0.jar
+org.wso2.carbon.user.mgt-4.2.0.jar
+org.wso2.carbon.user.mgt.common-4.2.0.ja
+org.wso2.carbon.utils-4.2.0.jar
+org.wso2.securevault-1.0.0-wso2v2.jar
+abdera-1.0.0.wso2v3.jar
+andes-client-0.13.wso2v8.jar
+annotations-1.3.2.jar
+ant-1.7.0.jar
+ant-launcher-1.7.0.jar
+axiom-1.2.11.wso2v4.jar
+axiom-api-1.2.11.jar
+axiom-impl-1.2.11.jar
+axis2-1.6.1.wso2v10.jar
+commons-cli-1.0.jar
+commons-codec-1.2.jar
+commons-collections-3.2.0.wso2v
+commons-collections-3.2.1.jar
+commons-dbcp-1.4.0.wso2v1.jar
+commons-fileupload-1.2.0.wso2v1
+commons-fileupload-1.2.jar
+commons-httpclient-3.1.0.wso2v2.
+commons-httpclient-3.1.jar
+commons-io-2.0.0.wso2v2.jar
+commons-io-2.0.jar
+commons-lang-2.4.jar
+commons-lang-2.6.0.wso2v1.jar
+commons-lang3-3.1.jar
+commons-logging-1.1.1.jar
+commons-pool-1.5.6.jar
+commons-pool-1.5.6.wso2v1.jar
+compass-2.0.1.wso2v2.jar
+geronimo-activation_1.1_spec-1.0.2.jar
+geronimo-javamail_1.4_spec-1.6.jar
+geronimo-jms_1.1_spec-1.1.jar
+geronimo-stax-api_1.0_spec-1.0.1.jar
+gson-2.2.4.jar
+hazelcast-3.0.1.jar
+hazelcast-3.0.1.wso2v1.jar
+httpclient-4.1.1-wso2v1.jar
+httpclient-4.2.5.jar
+httpcore-4.1.0-wso2v1.jar
+httpcore-4.2.4.jar
+javax.cache.wso2-4.2.0.jar
+java-xmlbuilder-0.6.jar
+javax.servlet-3.0.0.v201112011016.jar
+jdbc-pool-7.0.34.wso2v1.jar
+jdom-1.0.jar
+tomcat-catalina-ha-7.0.34.jar
+tomcat-ha-7.0.34.wso2v1.jar
+tomcat-jdbc-7.0.34.jar
+tomcat-juli-7.0.34.jar
+tomcat-tribes-7.0.34.jar
+tomcat-util-7.0.34.jar
+velocity-1.7.jar
+json-2.0.0.wso2v1.jar
+libthrift-0.7.wso2v1.jar
+libthrift-0.9.1.jar
+log4j-1.2.17.jar
+neethi-2.0.4.wso2v4.jar
+not-yet-commons-ssl-0.3.9.jar
+opencsv-1.8.wso2v1.jar
+org.apache.log4j-1.2.13.v200706111418.jar
+org.apache.stratos.common-4.0.0.jar
+org.apache.stratos.load.balancer.common-4.0.0.jar
+org.apache.stratos.load.balancer.extension.api-4.0.0.jar
+org.apache.stratos.messaging-4.0.0.jar
+poi-3.9.jar
+poi-ooxml-3.9.0.wso2v1.jar
+poi-ooxml-3.9.jar
+poi-ooxml-schemas-3.9.jar
+poi-scratchpad-3.9.0.wso2v1.jar
+poi-scratchpad-3.9.jar
+smack-3.0.4.wso2v1.jar
+smackx-3.0.4.wso2v1.jar
+stax-api-1.0.1.jar
+tomcat-annotations-api-7.0.34.jar
+tomcat-api-7.0.34.jar
+tomcat-catalina-7.0.34.jar
+
+
+===============================================================================
+The following components come under Public Domain License
+===============================================================================
+
+For base64-2.3.8.jar
+
+===============================================================================
+The following components come under BouncyCastle License
+===============================================================================
+
+For bcprov-jdk15-132.jar
+
+Copyright (c) 2000 - 2013 The Legion of the Bouncy Castle Inc. (http://www.bouncycastle.org)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+
+===============================================================================
+The following components are Licensed under BSD license
+===============================================================================
+
+For dom4j-1.6.1.jar, 
+jline-0.9.94.jar, 
+jsch-0.1.49.jar
+jaxen-1.1.1.jar
+
+Copyright (c) 2010 Terence Parr
+All rights reserved.
+
+[The BSD License]
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+   list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+ * Neither the name of JiBX nor the names of its contributors may be used
+   to endorse or promote products derived from this software without specific
+   prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=============================================================================== 
+The following components are licensed under EPL
+=============================================================================== 
+
+For junit-3.8.1.jar,
+org.eclipse.equinox.http.helper-1.1.0.wso2v1.jar,
+org.eclipse.osgi-3.8.1.v20120830-144521.jar,
+org.eclipse.osgi.services-3.3.100.v20120522-1822.jar
+
+Eclipse Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+i) changes to the Program, and
+ii) additions to the Program;
+where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
+b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
+c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
+d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+b) its license agreement:
+i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
+iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+b) a copy of this Agreement must be included with each copy of the Program.
+Contributors may not remove or alter any copyright notices contained within the Program.
+
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Los
 ses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) 
 above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
+
+
+=============================================================================== 
+The following components are licensed under MIT license
+=============================================================================== 
+
+For slf4j-1.5.10.wso2v1.jar,
+slf4j-api-1.7.5.jar,
+slf4j-log4j12-1.7.5.jar
+
+The MIT License (MIT)
+
+Copyright (c) 2004-2013 QOS.ch
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+
+