stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject git commit: Added logic to disable ha proxy cep statistics publisher if the system property is set and improved system property validation logic
Date Tue, 04 Feb 2014 22:04:30 GMT
Updated Branches:
  refs/heads/master 4221ec8e7 -> b38d87cbd


Added logic to disable ha proxy cep statistics publisher if the system property is set and
improved system property validation logic


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

Branch: refs/heads/master
Commit: b38d87cbdd0ccb3fed6582724349f63e708cb2de
Parents: 4221ec8
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Tue Feb 4 17:04:24 2014 -0500
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Tue Feb 4 17:04:24 2014 -0500

----------------------------------------------------------------------
 .../extension/api/LoadBalancerExtension.java    | 28 +++++++--
 .../src/main/bin/haproxy-extension.sh           |  4 +-
 .../src/main/conf/log4j.properties              |  1 +
 .../stratos/haproxy/extension/Constants.java    | 36 ++++++++++++
 .../haproxy/extension/HAProxyContext.java       | 62 +++++++++++++++-----
 .../apache/stratos/haproxy/extension/Main.java  |  2 +-
 6 files changed, 109 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b38d87cb/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java
b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java
index 9fe5107..8b4ba18 100644
--- a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java
+++ b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java
@@ -44,6 +44,11 @@ public class LoadBalancerExtension implements Runnable {
     private LoadBalancerStatisticsNotifier statisticsNotifier;
     private boolean terminated;
 
+    /**
+     * Load balancer extension constructor.
+     * @param loadBalancer Load balancer instance: Mandatory.
+     * @param statsReader Statistics reader: If null statistics notifier thread will not
be started.
+     */
     public LoadBalancerExtension(LoadBalancer loadBalancer, LoadBalancerStatisticsReader
statsReader) {
         this.loadBalancer = loadBalancer;
         this.statsReader = statsReader;
@@ -61,10 +66,17 @@ public class LoadBalancerExtension implements Runnable {
             Thread topologyReceiverThread = new Thread(topologyReceiver);
             topologyReceiverThread.start();
 
-            // Start stats notifier thread
-            statisticsNotifier = new LoadBalancerStatisticsNotifier(statsReader);
-            Thread statsNotifierThread = new Thread(statisticsNotifier);
-            statsNotifierThread.start();
+            if(statsReader != null) {
+                // Start stats notifier thread
+                statisticsNotifier = new LoadBalancerStatisticsNotifier(statsReader);
+                Thread statsNotifierThread = new Thread(statisticsNotifier);
+                statsNotifierThread.start();
+            }
+            else {
+                if(log.isWarnEnabled()) {
+                    log.warn("Load balancer statistics reader not found");
+                }
+            }
 
             // Keep the thread live until terminated
             while (!terminated);
@@ -147,8 +159,12 @@ public class LoadBalancerExtension implements Runnable {
     }
 
     public void terminate() {
-        topologyReceiver.terminate();
-        statisticsNotifier.terminate();
+        if(topologyReceiver != null) {
+            topologyReceiver.terminate();
+        }
+        if(statisticsNotifier != null) {
+            statisticsNotifier.terminate();
+        }
         terminated = true;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b38d87cb/extensions/load-balancer/haproxy-extension/src/main/bin/haproxy-extension.sh
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/haproxy-extension/src/main/bin/haproxy-extension.sh
b/extensions/load-balancer/haproxy-extension/src/main/bin/haproxy-extension.sh
index 43b7428..82d4f57 100755
--- a/extensions/load-balancer/haproxy-extension/src/main/bin/haproxy-extension.sh
+++ b/extensions/load-balancer/haproxy-extension/src/main/bin/haproxy-extension.sh
@@ -34,11 +34,11 @@ properties="-Djndi.properties.dir=${script_path}/../conf
             -Dlog4j.properties.file.path=${script_path}/../conf/log4j.properties
             -Djavax.net.ssl.trustStore=${script_path}/../security/client-truststore.jks
             -Djavax.net.ssl.trustStorePassword=wso2carbon
+            -Dcep.stats.publisher.enabled=false
             -Dthrift.receiver.ip=localhost
             -Dthrift.receiver.port=7615
             -Dnetwork.partition.id=
-            -Dstratos.messaging.topology.service.filter=
-            -Dcep.stats.publisher.enabled=true"
+            -Dstratos.messaging.topology.member.filter="
 
 # Uncomment below line to enable remote debugging
 #debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b38d87cb/extensions/load-balancer/haproxy-extension/src/main/conf/log4j.properties
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/haproxy-extension/src/main/conf/log4j.properties b/extensions/load-balancer/haproxy-extension/src/main/conf/log4j.properties
index ceec8a7..2f5119c 100644
--- a/extensions/load-balancer/haproxy-extension/src/main/conf/log4j.properties
+++ b/extensions/load-balancer/haproxy-extension/src/main/conf/log4j.properties
@@ -35,5 +35,6 @@ log4j.appender.CONSOLE_APPENDER.layout=org.apache.log4j.PatternLayout
 log4j.appender.CONSOLE_APPENDER.layout.ConversionPattern=[%d{ISO8601}] %5p - [%c{1}] %m%n
 
 log4j.logger.org.apache.stratos.haproxy.extension=INFO
+log4j.logger.org.apache.stratos.load.balancer.extension.api=INFO
 log4j.logger.org.apache.stratos.messaging=INFO
 log4j.logger.org.wso2.andes.client=ERROR
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b38d87cb/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/Constants.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/Constants.java
b/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/Constants.java
new file mode 100644
index 0000000..fe9783c
--- /dev/null
+++ b/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/Constants.java
@@ -0,0 +1,36 @@
+/*
+ * 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.haproxy.extension;
+
+/**
+ * HA proxy extension constants.
+ */
+public class Constants {
+    public static final String EXECUTABLE_FILE_PATH = "executable.file.path";
+    public static final String TEMPLATES_PATH = "templates.path";
+    public static final String TEMPLATES_NAME = "templates.name";
+    public static final String SCRIPTS_PATH = "scripts.path";
+    public static final String CONF_FILE_PATH = "conf.file.path";
+    public static final String STATS_SOCKET_FILE_PATH = "stats.socket.file.path";
+    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";
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b38d87cb/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyContext.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyContext.java
b/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyContext.java
index 25fe7de..bd2bf79 100644
--- a/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyContext.java
+++ b/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyContext.java
@@ -36,22 +36,34 @@ public class HAProxyContext {
     private String scriptsPath;
     private String confFilePath;
     private String statsSocketFilePath;
+    private boolean cepStatsPublisherEnabled;
+    private String thriftReceiverIp;
+    private String thriftReceiverPort;
+    private String networkPartitionId;
 
     private HAProxyContext() {
-        this.executableFilePath = System.getProperty("executable.file.path");
-        this.templatePath = System.getProperty("templates.path");
-        this.templateName = System.getProperty("templates.name");
-        this.scriptsPath = System.getProperty("scripts.path");
-        this.confFilePath = System.getProperty("conf.file.path");
-        this.statsSocketFilePath = System.getProperty("stats.socket.file.path");
+        this.executableFilePath = System.getProperty(Constants.EXECUTABLE_FILE_PATH);
+        this.templatePath = System.getProperty(Constants.TEMPLATES_PATH);
+        this.templateName = System.getProperty(Constants.TEMPLATES_NAME);
+        this.scriptsPath = System.getProperty(Constants.SCRIPTS_PATH);
+        this.confFilePath = System.getProperty(Constants.CONF_FILE_PATH);
+        this.statsSocketFilePath = System.getProperty(Constants.STATS_SOCKET_FILE_PATH);
+        this.cepStatsPublisherEnabled = Boolean.getBoolean(Constants.CEP_STATS_PUBLISHER_ENABLED);
+        this.thriftReceiverIp = System.getProperty(Constants.THRIFT_RECEIVER_IP);
+        this.thriftReceiverPort = System.getProperty(Constants.THRIFT_RECEIVER_PORT);
+        this.networkPartitionId = System.getProperty(Constants.NETWORK_PARTITION_ID);
 
         if (log.isDebugEnabled()) {
-            log.debug("executable.file.path = " + executableFilePath);
-            log.debug("templates.path = " + templatePath);
-            log.debug("templates.name = " + templateName);
-            log.debug("scripts.path = " + scriptsPath);
-            log.debug("conf.file.path = " + confFilePath);
-            log.debug("stats.socket.file.path = " + statsSocketFilePath);
+            log.debug(Constants.EXECUTABLE_FILE_PATH + " = " + executableFilePath);
+            log.debug(Constants.TEMPLATES_PATH + " = " + templatePath);
+            log.debug(Constants.TEMPLATES_NAME + " = " + templateName);
+            log.debug(Constants.SCRIPTS_PATH + " = " + scriptsPath);
+            log.debug(Constants.CONF_FILE_PATH + " = " + confFilePath);
+            log.debug(Constants.STATS_SOCKET_FILE_PATH + " = " + statsSocketFilePath);
+            log.debug(Constants.CEP_STATS_PUBLISHER_ENABLED + " = " + cepStatsPublisherEnabled);
+            log.debug(Constants.THRIFT_RECEIVER_IP + " = " + thriftReceiverIp);
+            log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort);
+            log.debug(Constants.NETWORK_PARTITION_ID + " = " + networkPartitionId);
         }
     }
 
@@ -67,9 +79,25 @@ public class HAProxyContext {
     }
 
     public void validate() {
-        if ((StringUtils.isEmpty(executableFilePath)) || (StringUtils.isEmpty(templatePath))
|| (StringUtils.isEmpty(templateName)) ||
-                (StringUtils.isEmpty(scriptsPath)) || (StringUtils.isEmpty(confFilePath))
|| (StringUtils.isEmpty(statsSocketFilePath))) {
-            throw new RuntimeException("Required system properties were not found: executable.file.path,
templates.path, templates.name, scripts.path, conf.file.path, stats.socket.file.path");
+        validateSystemProperty(Constants.EXECUTABLE_FILE_PATH);
+        validateSystemProperty(Constants.TEMPLATES_PATH);
+        validateSystemProperty(Constants.TEMPLATES_NAME);
+        validateSystemProperty(Constants.SCRIPTS_PATH);
+        validateSystemProperty(Constants.CONF_FILE_PATH);
+        validateSystemProperty(Constants.STATS_SOCKET_FILE_PATH);
+        validateSystemProperty(Constants.CEP_STATS_PUBLISHER_ENABLED);
+
+        if(cepStatsPublisherEnabled) {
+            validateSystemProperty(Constants.THRIFT_RECEIVER_IP);
+            validateSystemProperty(Constants.THRIFT_RECEIVER_PORT);
+            validateSystemProperty(Constants.NETWORK_PARTITION_ID);
+        }
+    }
+
+    private void validateSystemProperty(String propertyName) {
+        String value = System.getProperty(propertyName);
+        if(StringUtils.isEmpty(value)) {
+            throw new RuntimeException("System property was not found: " + propertyName);
         }
     }
 
@@ -96,4 +124,8 @@ public class HAProxyContext {
     public String getStatsSocketFilePath() {
         return statsSocketFilePath;
     }
+
+    public boolean isCEPStatsPublisherEnabled() {
+        return cepStatsPublisherEnabled;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b38d87cb/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/Main.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/Main.java
b/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/Main.java
index d2a8731..270fe89 100644
--- a/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/Main.java
+++ b/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/Main.java
@@ -43,7 +43,7 @@ public class Main {
 
             // Validate runtime parameters
             HAProxyContext.getInstance().validate();
-            extension = new LoadBalancerExtension(new HAProxy(), new HAProxyStatisticsReader());
+            extension = new LoadBalancerExtension(new HAProxy(), (HAProxyContext.getInstance().isCEPStatsPublisherEnabled()
? new HAProxyStatisticsReader() : null));
             Thread thread = new Thread(extension);
             thread.start();
         } catch (Exception e) {


Mime
View raw message