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

Commit 4862b29

Browse files
committed
refine logs and fixing some issues mentioned by imesh
1 parent 1250412 commit 4862b29

File tree

11 files changed

+86
-80
lines changed

11 files changed

+86
-80
lines changed

components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/event/receivers/LoadBalancerCommonTopologyEventReceiver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ private org.apache.stratos.load.balancer.common.domain.Member transformMember(Me
440440
member.addPort(transformPort(port));
441441
}
442442
}
443-
if(messagingMember.getInstanceId() != null){
443+
if (messagingMember.getInstanceId() != null) {
444444
member.setInstanceId(messagingMember.getInstanceId());
445445
}
446446
return member;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Apache Stratos GCE Extension
2+
3+
Apache Stratos GCE extension is a load balancer extension for Google Compute Engine Load balancer.
4+
It is an executable program which can manage Google Compute Engine Load balancing according to the topology,
5+
composite application model and tenant application signups information received from Stratos via
6+
the message broker.
7+
8+
## How it works
9+
1. Wait for the complete topology event message to initialize the topology.
10+
2. Configure and create relevant forwarding rules, target pools and health checks in GCE.
11+
3. Listen to topology, application, application signup events.
12+
4. Reconfigure the load balancer with the new topology configuration.
13+
14+
## Installation
15+
Please refer bellow document for information on the installation process.
16+
17+
https://docs.google.com/document/d/1a2ZptPScpjuavfpxVu1R1GC7R95jjzHo3L372zL2bRY/edit

extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ properties="-Djndi.properties.dir=${script_path}/../conf
3131
-Dstats.socket.file.path=/tmp/haproxy-stats.socket
3232
-Djavax.net.ssl.trustStore=${script_path}/../security/client-truststore.jks
3333
-Djavax.net.ssl.trustStorePassword=wso2carbon
34-
-Dthrift.client.config.file.path=${script_path}/../conf/thrift-client-config.xml"
34+
-Dthrift.client.config.file.path=${script_path}/../conf/thrift-client-config.xml
35+
-Dlog4j.properties.file.path=${script_path}/../conf/log4j.properties"
3536

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

3940
java -cp "${class_path}" ${properties} ${debug} org.apache.stratos.gce.extension.Main $*

extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
<iaasProperties>
1010
<projectName>MyFirstProject</projectName>
11-
<projectId>gold-access-96509</projectId>
11+
<projectId>gold-access-xxxx</projectId>
1212
<regionName>europe-west1</regionName>
13-
<keyFilePath>/home/sanjaya/keys/p12key-donwloaded.p12</keyFilePath>
14-
<gceAccountId>164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com</gceAccountId>
13+
<keyFilePath>path-to-key-file/keyfile.p12</keyFilePath>
14+
<gceAccountId>xxxxxxxxxxxxx.gserviceaccount.com</gceAccountId>
1515
<networkName>default</networkName>
1616
</iaasProperties>
1717

extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
24+
import org.apache.stratos.gce.extension.config.Constants;
2425
import org.apache.stratos.gce.extension.config.GCEClusterConfigurationHolder;
2526
import org.apache.stratos.gce.extension.config.GCEContext;
2627
import org.apache.stratos.gce.extension.util.GCEOperations;
@@ -32,11 +33,12 @@
3233
import java.security.GeneralSecurityException;
3334
import java.util.*;
3435

36+
/**
37+
* All the methods in Stratos load balancer API have been implemented in this class
38+
*/
3539
public class GCELoadBalancer implements LoadBalancer {
3640

3741
private static final Log log = LogFactory.getLog(GCELoadBalancer.class);
38-
//PROTOCOL should be TCP or UDP
39-
private static final String PROTOCOL = "TCP";
4042
private GCEOperations gceOperations;
4143
/**
4244
* One configuration object per cluster will be created
@@ -48,7 +50,6 @@ public class GCELoadBalancer implements LoadBalancer {
4850
public GCELoadBalancer() throws IOException, GeneralSecurityException {
4951
gceOperations = new GCEOperations();
5052
clusterToLoadBalancerConfigurationMap = new HashMap<String, GCEClusterConfigurationHolder>();
51-
5253
}
5354

5455
/**
@@ -60,7 +61,7 @@ public GCELoadBalancer() throws IOException, GeneralSecurityException {
6061
*/
6162
@Override
6263
public boolean configure(Topology topology) throws LoadBalancerExtensionException {
63-
log.info("Complete topology received. Configuring Load balancer ");
64+
log.info("Complete topology received. Configuring Load balancer...");
6465

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

7475
if (log.isDebugEnabled()) {
75-
log.debug("Reconfiguring the existing cluster: " + cluster.getClusterId());
76+
log.debug("Reconfiguring the existing cluster: " + cluster.getClusterId() + "...");
7677
}
7778

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

8384
//if the cluster contains at least one member
8485
if (!cluster.getMembers().isEmpty()) {
85-
//that cluster contains at least one member
86-
8786
if (log.isDebugEnabled()) {
8887
log.debug("Cluster " + cluster.getClusterId() + " has one or more members");
8988
}
9089
activeClusterIdList.add(cluster.getClusterId());
90+
if (log.isDebugEnabled()){
91+
log.debug("Cluster " + cluster.getClusterId() + " was added to active cluster id list");
92+
}
9193

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

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

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

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

144145
//remove them from configuration holder
145146
for (String memberId : membersToBeRemovedFromTargetPool) {
@@ -151,12 +152,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio
151152
gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool,
152153
gceClusterConfigurationHolder.getTargetPoolName());
153154
}
154-
155155
}
156-
157156
} else {
158157
//doesn't have a GCEClusterConfigurationHolder object. So crate a new one and add to hash map
159-
160158
log.info("Found a new cluster: " + cluster.getClusterId());
161159

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

212210
clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), gceClusterConfigurationHolder);
213211
createConfigurationForCluster(cluster.getClusterId());
214-
215212
}
216213
}
217-
218214
}
219215
}
220216

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

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

259-
log.info("Creating configuration for cluster");
255+
log.info("Creating configuration for cluster " + clusterId + "...");
260256

261257
GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId);
262258

@@ -278,9 +274,8 @@ private void createConfigurationForCluster(String clusterId) throws LoadBalancer
278274
//if the ip list is empty
279275
if (ipList.isEmpty()) {
280276
log.warn("Ip list is null");
281-
//set all ports to be opened
282-
portRange = "1-65535";
283-
277+
//set all default port range
278+
portRange = Constants.DEFAULT_PORT_RANGE;
284279
}
285280
//else if ip list has only one value
286281
else if (ipList.size() == 1) {
@@ -300,8 +295,8 @@ else if (ipList.size() == 1) {
300295

301296
//create the forwarding rule
302297
gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(),
303-
gceClusterConfigurationHolder.getTargetPoolName(), PROTOCOL, portRange);
304-
log.info("Created configuration for cluster");
298+
gceClusterConfigurationHolder.getTargetPoolName(), Constants.PROTOCOL, portRange);
299+
log.info("Created configuration for cluster" + clusterId);
305300
}
306301

307302
@Override
@@ -314,7 +309,7 @@ public void start() throws LoadBalancerExtensionException {
314309
@Override
315310
public void stop() throws LoadBalancerExtensionException {
316311

317-
log.info("GCE Load Balancer is stopping");
312+
log.info("GCE Load Balancer is stopping...");
318313

319314
//iterate through hash map and remove all
320315
Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator();
@@ -331,10 +326,7 @@ public void stop() throws LoadBalancerExtensionException {
331326
*/
332327
@Override
333328
public void reload() throws LoadBalancerExtensionException {
334-
335329
//nothing to do here
336-
log.info("Configuration reloaded");
337-
338330
}
339331

340332
/**
@@ -350,41 +342,42 @@ private String targetPoolNameCreator(String clusterId) {
350342
String targetPoolName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" +
351343
clusterId.trim().toLowerCase().replace(".", "-");
352344
//length should be les than 62 characters
353-
if (targetPoolName.length() >= 62) {
354-
targetPoolName = targetPoolName.substring(0, 62);
345+
if (targetPoolName.length() >= Constants.MAX_NAME_LENGTH) {
346+
targetPoolName = targetPoolName.substring(0, Constants.MAX_NAME_LENGTH);
355347
}
356348
return targetPoolName;
357349
}
358350

359351
/**
360352
* Create a valid forwarding rule name
361353
*
362-
* @param clusterID - Id of the cluster
354+
* @param clusterId - Id of the cluster
363355
* @return - a proper name for forwarding rule
364356
*/
365-
private String forwardingRuleNameCreator(String clusterID) {
366-
String forwardingRuleName = GCEContext.getInstance().getNamePrefix()
367-
+ "-fr-" + clusterID.trim().toLowerCase().replace(".", "-");
357+
private String forwardingRuleNameCreator(String clusterId) {
358+
String forwardingRuleName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" +
359+
clusterId.trim().toLowerCase().replace(".", "-");
360+
368361
//length should be les than 62 characters
369-
if (forwardingRuleName.length() >= 62) {
370-
forwardingRuleName = forwardingRuleName.substring(0, 62);
362+
if (forwardingRuleName.length() >= Constants.MAX_NAME_LENGTH) {
363+
forwardingRuleName = forwardingRuleName.substring(0, Constants.MAX_NAME_LENGTH);
371364
}
372365
return forwardingRuleName;
373366
}
374367

375368
/**
376369
* create a valid health check name
377370
*
378-
* @param clusterID - id of the cluster
371+
* @param clusterId - id of the cluster
379372
* @return - a proper name for health check
380373
*/
381-
private String healthCheckNameCreator(String clusterID) {
382-
String healthCheckName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-hc-" +
383-
clusterID.trim().toLowerCase().replace(".", "-");
374+
private String healthCheckNameCreator(String clusterId) {
375+
String healthCheckName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" +
376+
clusterId.trim().toLowerCase().replace(".", "-");
384377

385-
//length should be les than 62 characters
386-
if (healthCheckName.length() >= 62) {
387-
healthCheckName = healthCheckName.substring(0, 62);
378+
//length should be less than 62 characters
379+
if (healthCheckName.length() >= Constants.MAX_NAME_LENGTH) {
380+
healthCheckName = healthCheckName.substring(0, Constants.MAX_NAME_LENGTH);
388381
}
389382
return healthCheckName;
390383
}

extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public GCEStatisticsReader(TopologyProvider topologyProvider) {
3636
this.topologyProvider = topologyProvider;
3737
this.clusterInstanceId = System.getProperty(StratosConstants.
3838
CLUSTER_INSTANCE_ID, StratosConstants.NOT_DEFINED);
39-
4039
}
4140

4241
@Override
@@ -46,7 +45,7 @@ public String getClusterInstanceId() {
4645

4746
@Override
4847
public int getInFlightRequestCount(String clusterId) {
49-
//There is no way in GCE API to get in flight request count!
48+
// That is not possible to read the request count via the GCE API at the moment
5049
return 0;
5150
}
5251
}

extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public static void main(String[] args) {
5353
GCEConfigParser.parse(documentElement);
5454

5555
// Configure log4j properties
56-
PropertyConfigurator.configure(getFilePathOfConfigFile(GCEContext.getInstance().getLog4jPropertiesFileName()));
57-
56+
PropertyConfigurator.configure(System.getProperty("log4j.properties.file.path"));
5857
if (log.isInfoEnabled()) {
5958
log.info("GCE extension started");
6059
}

extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,11 @@ public class Constants {
5353
//other properties
5454
public static final String OPERATION_TIMEOUT = "operationTimeout";
5555
public static final String NAME_PREFIX = "namePrefix";
56-
public static final String LOG4J_PROPERTIES_FILE_NAME = "log4jPropertiesFileName";
56+
57+
//PROTOCOL should be TCP or UDP
58+
public static final String PROTOCOL = "TCP";
59+
//set all ports to be opened if the application does not have any port defined
60+
public static final String DEFAULT_PORT_RANGE="1-65535";
61+
//maximum length the name which allowed by GCE API
62+
public static final int MAX_NAME_LENGTH = 62;
5763
}

extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public class GCEContext {
5252
//other properties
5353
private String namePrefix;
5454
private String operationTimeout;
55-
private String log4jPropertiesFileName;
5655

5756
//private constructor
5857
private GCEContext() {
@@ -69,14 +68,6 @@ public static GCEContext getInstance() {
6968
return context;
7069
}
7170

72-
public String getLog4jPropertiesFileName() {
73-
return log4jPropertiesFileName;
74-
}
75-
76-
public void setLog4jPropertiesFileName(String log4jPropertiesFileName) {
77-
this.log4jPropertiesFileName = log4jPropertiesFileName;
78-
}
79-
8071
public void validate() throws LoadBalancerExtensionException {
8172
validateProperty(Boolean.toString(cepStatsPublisherEnabled));
8273
validateProperty(namePrefix);
@@ -233,5 +224,4 @@ public void setThriftReceiverIp(String thriftReceiverIp) {
233224
public void setThriftReceiverPort(String thriftReceiverPort) {
234225
this.thriftReceiverPort = thriftReceiverPort;
235226
}
236-
237227
}

extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
import javax.xml.namespace.QName;
3232

33+
/**
34+
* parse the gce-configuration.xml
35+
*/
3336
public class GCEConfigParser {
3437
private static final Log log = LogFactory.getLog(GCEConfigParser.class);
3538
private static GCEContext gceContext;
@@ -239,8 +242,6 @@ private static void extractOtherProperties(OMElement documentElement) {
239242
OMElement operationTimeoutElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.
240243
OPERATION_TIMEOUT);
241244
OMElement namePrefixElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.NAME_PREFIX);
242-
OMElement log4jPropertiesFileNameElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.
243-
LOG4J_PROPERTIES_FILE_NAME);
244245

245246
//set extracted properties to gceContext object
246247
if (operationTimeoutElement != null) {
@@ -256,12 +257,5 @@ private static void extractOtherProperties(OMElement documentElement) {
256257
log.debug("Name prefix: " + namePrefixElement.getText());
257258
}
258259
}
259-
260-
if (log4jPropertiesFileNameElement != null) {
261-
gceContext.setLog4jPropertiesFileName(log4jPropertiesFileNameElement.getText());
262-
if (log.isDebugEnabled()) {
263-
log.debug("log4j properties file name: " + log4jPropertiesFileNameElement.getText());
264-
}
265-
}
266260
}
267261
}

0 commit comments

Comments
 (0)