Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
refine logs and fixing some issues mentioned by imesh
Browse files Browse the repository at this point in the history
  • Loading branch information
asankasan committed Aug 13, 2015
1 parent 1250412 commit 4862b29
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ private org.apache.stratos.load.balancer.common.domain.Member transformMember(Me
member.addPort(transformPort(port));
}
}
if(messagingMember.getInstanceId() != null){
if (messagingMember.getInstanceId() != null) {
member.setInstanceId(messagingMember.getInstanceId());
}
return member;
Expand Down
17 changes: 17 additions & 0 deletions extensions/load-balancer/gce-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Apache Stratos GCE Extension

Apache Stratos GCE extension is a load balancer extension for Google Compute Engine Load balancer.
It is an executable program which can manage Google Compute Engine Load balancing according to the topology,
composite application model and tenant application signups information received from Stratos via
the message broker.

## How it works
1. Wait for the complete topology event message to initialize the topology.
2. Configure and create relevant forwarding rules, target pools and health checks in GCE.
3. Listen to topology, application, application signup events.
4. Reconfigure the load balancer with the new topology configuration.

## Installation
Please refer bellow document for information on the installation process.

https://docs.google.com/document/d/1a2ZptPScpjuavfpxVu1R1GC7R95jjzHo3L372zL2bRY/edit
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ properties="-Djndi.properties.dir=${script_path}/../conf
-Dstats.socket.file.path=/tmp/haproxy-stats.socket
-Djavax.net.ssl.trustStore=${script_path}/../security/client-truststore.jks
-Djavax.net.ssl.trustStorePassword=wso2carbon
-Dthrift.client.config.file.path=${script_path}/../conf/thrift-client-config.xml"
-Dthrift.client.config.file.path=${script_path}/../conf/thrift-client-config.xml
-Dlog4j.properties.file.path=${script_path}/../conf/log4j.properties"

# Uncomment below line to enable remote debugging
debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006"
#debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006"

java -cp "${class_path}" ${properties} ${debug} org.apache.stratos.gce.extension.Main $*
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

<iaasProperties>
<projectName>MyFirstProject</projectName>
<projectId>gold-access-96509</projectId>
<projectId>gold-access-xxxx</projectId>
<regionName>europe-west1</regionName>
<keyFilePath>/home/sanjaya/keys/p12key-donwloaded.p12</keyFilePath>
<gceAccountId>164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com</gceAccountId>
<keyFilePath>path-to-key-file/keyfile.p12</keyFilePath>
<gceAccountId>xxxxxxxxxxxxx.gserviceaccount.com</gceAccountId>
<networkName>default</networkName>
</iaasProperties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.gce.extension.config.Constants;
import org.apache.stratos.gce.extension.config.GCEClusterConfigurationHolder;
import org.apache.stratos.gce.extension.config.GCEContext;
import org.apache.stratos.gce.extension.util.GCEOperations;
Expand All @@ -32,11 +33,12 @@
import java.security.GeneralSecurityException;
import java.util.*;

/**
* All the methods in Stratos load balancer API have been implemented in this class
*/
public class GCELoadBalancer implements LoadBalancer {

private static final Log log = LogFactory.getLog(GCELoadBalancer.class);
//PROTOCOL should be TCP or UDP
private static final String PROTOCOL = "TCP";
private GCEOperations gceOperations;
/**
* One configuration object per cluster will be created
Expand All @@ -48,7 +50,6 @@ public class GCELoadBalancer implements LoadBalancer {
public GCELoadBalancer() throws IOException, GeneralSecurityException {
gceOperations = new GCEOperations();
clusterToLoadBalancerConfigurationMap = new HashMap<String, GCEClusterConfigurationHolder>();

}

/**
Expand All @@ -60,7 +61,7 @@ public GCELoadBalancer() throws IOException, GeneralSecurityException {
*/
@Override
public boolean configure(Topology topology) throws LoadBalancerExtensionException {
log.info("Complete topology received. Configuring Load balancer ");
log.info("Complete topology received. Configuring Load balancer...");

//this list is used to hold the current clusters available in topology and which has at least one member.
List<String> activeClusterIdList = new ArrayList<String>();
Expand All @@ -72,7 +73,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio
if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) {

if (log.isDebugEnabled()) {
log.debug("Reconfiguring the existing cluster: " + cluster.getClusterId());
log.debug("Reconfiguring the existing cluster: " + cluster.getClusterId() + "...");
}

//It already has a entry in clusterToLoadBalancerConfigurationMap.
Expand All @@ -82,15 +83,15 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio

//if the cluster contains at least one member
if (!cluster.getMembers().isEmpty()) {
//that cluster contains at least one member

if (log.isDebugEnabled()) {
log.debug("Cluster " + cluster.getClusterId() + " has one or more members");
}
activeClusterIdList.add(cluster.getClusterId());
if (log.isDebugEnabled()){
log.debug("Cluster " + cluster.getClusterId() + " was added to active cluster id list");
}

//***************detect member changes and update**************//

//detect member changes and update
//check for newly created members
List<String> membersToBeAddedToTargetPool = new ArrayList<String>();
for (Member member : cluster.getMembers()) {
Expand All @@ -106,7 +107,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio

if (!membersToBeAddedToTargetPool.isEmpty()) { //we have new members
log.info("New members in cluster" + cluster.getClusterId() + " found. Adding new members " +
"to cluster");
"to cluster...");

//add them to configuration holder
for (String memberId : membersToBeAddedToTargetPool) {
Expand Down Expand Up @@ -139,7 +140,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio
}

if (!membersToBeRemovedFromTargetPool.isEmpty()) { //found terminated members
log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them");
log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them...");

//remove them from configuration holder
for (String memberId : membersToBeRemovedFromTargetPool) {
Expand All @@ -151,12 +152,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio
gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool,
gceClusterConfigurationHolder.getTargetPoolName());
}

}

} else {
//doesn't have a GCEClusterConfigurationHolder object. So crate a new one and add to hash map

log.info("Found a new cluster: " + cluster.getClusterId());

if (cluster.getMembers().isEmpty()) {
Expand Down Expand Up @@ -211,18 +209,16 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio

clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), gceClusterConfigurationHolder);
createConfigurationForCluster(cluster.getClusterId());

}
}

}
}

//if any cluster is removed from the topology or if any cluster does not have at least one member,
//remove those clusters from map and remove the configuration from GCE too
for (String clusterId : clusterToLoadBalancerConfigurationMap.keySet()) {
if (!activeClusterIdList.contains(clusterId)) {
log.info("Removing the configuration for cluster " + clusterId);
log.info("Removing the configuration for cluster " + clusterId + "...");
deleteConfigurationForCluster(clusterId);
clusterToLoadBalancerConfigurationMap.remove(clusterId);
}
Expand All @@ -238,7 +234,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio
*/
private void deleteConfigurationForCluster(String clusterId) throws LoadBalancerExtensionException {

log.info("Deleting configuration for cluster " + clusterId);
log.info("Deleting configuration for cluster " + clusterId + "...");
GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId);
//delete forwarding rule
gceOperations.deleteForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName());
Expand All @@ -256,7 +252,7 @@ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancer
*/
private void createConfigurationForCluster(String clusterId) throws LoadBalancerExtensionException {

log.info("Creating configuration for cluster");
log.info("Creating configuration for cluster " + clusterId + "...");

GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId);

Expand All @@ -278,9 +274,8 @@ private void createConfigurationForCluster(String clusterId) throws LoadBalancer
//if the ip list is empty
if (ipList.isEmpty()) {
log.warn("Ip list is null");
//set all ports to be opened
portRange = "1-65535";

//set all default port range
portRange = Constants.DEFAULT_PORT_RANGE;
}
//else if ip list has only one value
else if (ipList.size() == 1) {
Expand All @@ -300,8 +295,8 @@ else if (ipList.size() == 1) {

//create the forwarding rule
gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(),
gceClusterConfigurationHolder.getTargetPoolName(), PROTOCOL, portRange);
log.info("Created configuration for cluster");
gceClusterConfigurationHolder.getTargetPoolName(), Constants.PROTOCOL, portRange);
log.info("Created configuration for cluster" + clusterId);
}

@Override
Expand All @@ -314,7 +309,7 @@ public void start() throws LoadBalancerExtensionException {
@Override
public void stop() throws LoadBalancerExtensionException {

log.info("GCE Load Balancer is stopping");
log.info("GCE Load Balancer is stopping...");

//iterate through hash map and remove all
Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator();
Expand All @@ -331,10 +326,7 @@ public void stop() throws LoadBalancerExtensionException {
*/
@Override
public void reload() throws LoadBalancerExtensionException {

//nothing to do here
log.info("Configuration reloaded");

}

/**
Expand All @@ -350,41 +342,42 @@ private String targetPoolNameCreator(String clusterId) {
String targetPoolName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" +
clusterId.trim().toLowerCase().replace(".", "-");
//length should be les than 62 characters
if (targetPoolName.length() >= 62) {
targetPoolName = targetPoolName.substring(0, 62);
if (targetPoolName.length() >= Constants.MAX_NAME_LENGTH) {
targetPoolName = targetPoolName.substring(0, Constants.MAX_NAME_LENGTH);
}
return targetPoolName;
}

/**
* Create a valid forwarding rule name
*
* @param clusterID - Id of the cluster
* @param clusterId - Id of the cluster
* @return - a proper name for forwarding rule
*/
private String forwardingRuleNameCreator(String clusterID) {
String forwardingRuleName = GCEContext.getInstance().getNamePrefix()
+ "-fr-" + clusterID.trim().toLowerCase().replace(".", "-");
private String forwardingRuleNameCreator(String clusterId) {
String forwardingRuleName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" +
clusterId.trim().toLowerCase().replace(".", "-");

//length should be les than 62 characters
if (forwardingRuleName.length() >= 62) {
forwardingRuleName = forwardingRuleName.substring(0, 62);
if (forwardingRuleName.length() >= Constants.MAX_NAME_LENGTH) {
forwardingRuleName = forwardingRuleName.substring(0, Constants.MAX_NAME_LENGTH);
}
return forwardingRuleName;
}

/**
* create a valid health check name
*
* @param clusterID - id of the cluster
* @param clusterId - id of the cluster
* @return - a proper name for health check
*/
private String healthCheckNameCreator(String clusterID) {
String healthCheckName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-hc-" +
clusterID.trim().toLowerCase().replace(".", "-");
private String healthCheckNameCreator(String clusterId) {
String healthCheckName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" +
clusterId.trim().toLowerCase().replace(".", "-");

//length should be les than 62 characters
if (healthCheckName.length() >= 62) {
healthCheckName = healthCheckName.substring(0, 62);
//length should be less than 62 characters
if (healthCheckName.length() >= Constants.MAX_NAME_LENGTH) {
healthCheckName = healthCheckName.substring(0, Constants.MAX_NAME_LENGTH);
}
return healthCheckName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public GCEStatisticsReader(TopologyProvider topologyProvider) {
this.topologyProvider = topologyProvider;
this.clusterInstanceId = System.getProperty(StratosConstants.
CLUSTER_INSTANCE_ID, StratosConstants.NOT_DEFINED);

}

@Override
Expand All @@ -46,7 +45,7 @@ public String getClusterInstanceId() {

@Override
public int getInFlightRequestCount(String clusterId) {
//There is no way in GCE API to get in flight request count!
// That is not possible to read the request count via the GCE API at the moment
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public static void main(String[] args) {
GCEConfigParser.parse(documentElement);

// Configure log4j properties
PropertyConfigurator.configure(getFilePathOfConfigFile(GCEContext.getInstance().getLog4jPropertiesFileName()));

PropertyConfigurator.configure(System.getProperty("log4j.properties.file.path"));
if (log.isInfoEnabled()) {
log.info("GCE extension started");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@ public class Constants {
//other properties
public static final String OPERATION_TIMEOUT = "operationTimeout";
public static final String NAME_PREFIX = "namePrefix";
public static final String LOG4J_PROPERTIES_FILE_NAME = "log4jPropertiesFileName";

//PROTOCOL should be TCP or UDP
public static final String PROTOCOL = "TCP";
//set all ports to be opened if the application does not have any port defined
public static final String DEFAULT_PORT_RANGE="1-65535";
//maximum length the name which allowed by GCE API
public static final int MAX_NAME_LENGTH = 62;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class GCEContext {
//other properties
private String namePrefix;
private String operationTimeout;
private String log4jPropertiesFileName;

//private constructor
private GCEContext() {
Expand All @@ -69,14 +68,6 @@ public static GCEContext getInstance() {
return context;
}

public String getLog4jPropertiesFileName() {
return log4jPropertiesFileName;
}

public void setLog4jPropertiesFileName(String log4jPropertiesFileName) {
this.log4jPropertiesFileName = log4jPropertiesFileName;
}

public void validate() throws LoadBalancerExtensionException {
validateProperty(Boolean.toString(cepStatsPublisherEnabled));
validateProperty(namePrefix);
Expand Down Expand Up @@ -233,5 +224,4 @@ public void setThriftReceiverIp(String thriftReceiverIp) {
public void setThriftReceiverPort(String thriftReceiverPort) {
this.thriftReceiverPort = thriftReceiverPort;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

import javax.xml.namespace.QName;

/**
* parse the gce-configuration.xml
*/
public class GCEConfigParser {
private static final Log log = LogFactory.getLog(GCEConfigParser.class);
private static GCEContext gceContext;
Expand Down Expand Up @@ -239,8 +242,6 @@ private static void extractOtherProperties(OMElement documentElement) {
OMElement operationTimeoutElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.
OPERATION_TIMEOUT);
OMElement namePrefixElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.NAME_PREFIX);
OMElement log4jPropertiesFileNameElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.
LOG4J_PROPERTIES_FILE_NAME);

//set extracted properties to gceContext object
if (operationTimeoutElement != null) {
Expand All @@ -256,12 +257,5 @@ private static void extractOtherProperties(OMElement documentElement) {
log.debug("Name prefix: " + namePrefixElement.getText());
}
}

if (log4jPropertiesFileNameElement != null) {
gceContext.setLog4jPropertiesFileName(log4jPropertiesFileNameElement.getText());
if (log.isDebugEnabled()) {
log.debug("log4j properties file name: " + log4jPropertiesFileNameElement.getText());
}
}
}
}
Loading

0 comments on commit 4862b29

Please sign in to comment.