You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by sa...@apache.org on 2013/11/12 05:25:20 UTC
git commit: Modified cartridge agent script to include subscriber for
artifact update events. Cleaned up subscriber code.
Updated Branches:
refs/heads/master 69edd281d -> bc485e9a8
Modified cartridge agent script to include subscriber for artifact update events. Cleaned up subscriber code.
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/bc485e9a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/bc485e9a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/bc485e9a
Branch: refs/heads/master
Commit: bc485e9a816a453b2748156ae8c728f70ff5040f
Parents: 69edd28
Author: Sajith Kariyawasam <sa...@wso2.com>
Authored: Tue Nov 12 09:54:50 2013 +0530
Committer: Sajith Kariyawasam <sa...@wso2.com>
Committed: Tue Nov 12 09:54:50 2013 +0530
----------------------------------------------------------------------
.../cartridge-agent/ec2/php/cartridge-agent.sh | 35 ++++++++++-----
.../event/subscriber/ArtifactListener.java | 20 +++------
.../cartridge/agent/event/subscriber/Main.java | 46 ++------------------
3 files changed, 36 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc485e9a/products/cartridge-agent/modules/cartridge-agent/ec2/php/cartridge-agent.sh
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent/ec2/php/cartridge-agent.sh b/products/cartridge-agent/modules/cartridge-agent/ec2/php/cartridge-agent.sh
index b09e62e..b4019a4 100755
--- a/products/cartridge-agent/modules/cartridge-agent/ec2/php/cartridge-agent.sh
+++ b/products/cartridge-agent/modules/cartridge-agent/ec2/php/cartridge-agent.sh
@@ -28,6 +28,7 @@ set -e # Terminate on any error
export LOG=/var/log/apache-stratos/cartridge-agent.log
instance_path=/opt/apache-stratos-cartridge-agent # Cartridge agent home
event_publisher_path=/opt/apache-stratos-cartridge-agent/event-publisher # Event publisher home
+event_subscriber_path=/opt/apache-stratos-cartridge-agent/event-subscriber # Event subscriber home
# ---------------------------------------------
# Download payload.zip
@@ -57,6 +58,26 @@ fi
source ${instance_path}/launch.params
+
+#---------------------------
+# Starting Topic Subscriber
+#---------------------------
+# change mb ip port in conf/jndi.properties
+pushd $event_subscriber_path/conf
+cp -rf jndi.properties jndi.properties.tmp
+cat jndi.properties.tmp | sed -e "s@MB-PORT@$MB_PORT@g" > jndi.properties
+cp -rf jndi.properties jndi.properties.tmp
+cat jndi.properties.tmp | sed -e "s@MB-IP-ADDRESS@$MB_IP@g" > jndi.properties
+rm -f jndi.properties.tmp
+popd
+
+pushd $event_subscriber_path/bin
+echo "Executing: event-subscriber.sh "
+sh event-subscriber.sh &
+echo "Event subscribed" | tee -a $LOG
+popd
+
+
# ---------------------------------------------
# Publish member-started-event
# ---------------------------------------------
@@ -107,16 +128,10 @@ GIT_SH_LOG=/var/log/apache-stratos/git-sh.log
if [ -d \"${APP_PATH}/.git\" ]; then
cd ${APP_PATH}
echo \"Invoking repo info service...\" | tee -a \$GIT_SH_LOG
- curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @${instance_path}/repoinforequest.xml --silent \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
- echo \"Processing repo info service response...\" | tee -a \$GIT_SH_LOG
- sed '1,5d' /tmp/git.xml > /tmp/git1.xml
- sed '2d' /tmp/git1.xml > /tmp/git.xml
- username=\`xml_grep 'ax29:userName' /tmp/git.xml --text_only\`
- password=\`xml_grep 'ax29:password' /tmp/git.xml --text_only\`
- repo=\`xml_grep 'ax29:url' /tmp/git.xml --text_only\`
+ username=\$1
+ password=\$2
+ repo=\$3
echo \"username=\$username repo=\${repo}\" | tee -a \$GIT_SH_LOG
- rm /tmp/git1.xml
- rm /tmp/git.xml
echo \"Preparing .netrc...\" | tee -a \$GIT_SH_LOG
url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
@@ -139,7 +154,7 @@ if [ -d \"${APP_PATH}/.git\" ]; then
echo \"Changing owner of application path/www to www-data:www-data...\" | tee -a \$GIT_SH_LOG
sudo chown -R www-data:www-data ${APP_PATH}/www
if [ -f \"${APP_PATH}/sql/alter.sql\" ] && [ -n \"${MYSQL_HOST}\" ] && [ -n \"${MYSQL_USER}\" ] && [ -n \"${MYSQL_PASSWORD}\" ]; then
- mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} < ${APP_PATH}/sql/alter.sql
+ mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} < ${APP_PATH}/sql/alter.sql
fi
else
echo \"Removing index.html from application path...\" | tee -a \$GIT_SH_LOG
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc485e9a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/ArtifactListener.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/ArtifactListener.java b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/ArtifactListener.java
index 3238c5f..e5a085b 100644
--- a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/ArtifactListener.java
+++ b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/ArtifactListener.java
@@ -13,7 +13,6 @@ import javax.jms.TextMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.messaging.event.artifact.synchronization.ArtifactUpdatedEvent;
-import org.apache.stratos.messaging.util.Constants;
import org.apache.stratos.messaging.util.Util;
/**
@@ -31,14 +30,13 @@ public class ArtifactListener implements MessageListener{
// If cluster id of the node is equal to that of message's, invoke the script
TextMessage receivedMessage = (TextMessage) message;
- log.info(" ++++++++ artifact listener +++++++++");
- String type = null;
+ log.info(" Message received on artifact update ");
String json = null;
try {
- type = receivedMessage.getStringProperty(Constants.EVENT_CLASS_NAME);
json = receivedMessage.getText();
} catch (Exception e) {
- e.printStackTrace();
+ //e.printStackTrace();
+ log.error("Exception is occurred " + e.getMessage(), e);
}
// if(ArtifactUpdatedEvent.class.getName().equals(type)) {
@@ -48,12 +46,6 @@ public class ArtifactListener implements MessageListener{
String repoURL = event.getRepoURL();
String repoPassword = event.getRepoPassword();
String repoUsername = event.getRepoUserName();
-
- if (log.isDebugEnabled()) {
- log.debug(" cluster id from message " + clusterIdInMessage + " repo details"
- + repoURL + repoUsername + repoPassword);
- }
-
// execute script
if(clusterIdInPayload != null && clusterIdInPayload.equals(clusterIdInMessage)) {
@@ -64,7 +56,8 @@ public class ArtifactListener implements MessageListener{
Process proc = Runtime.getRuntime().exec(command);
proc.waitFor();
} catch (Exception e) {
- e.printStackTrace();
+ //e.printStackTrace();
+ log.error("Exception is occurred in executing script. " + e.getMessage(), e);
}
}
@@ -90,7 +83,8 @@ public class ArtifactListener implements MessageListener{
}
scanner.close();
} catch (Exception e) {
- e.printStackTrace();
+ //e.printStackTrace();
+ log.error("Exception is occurred in reading file. ", e);
}
return clusterId;
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc485e9a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/Main.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/Main.java b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/Main.java
index 2aa16ae..6edff03 100644
--- a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/Main.java
+++ b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/Main.java
@@ -32,52 +32,14 @@ public class Main {
public static void main(String[] args) {
-
- log.info(" ************** in main **************** ");
- log.info(" arg0 : " + args[0]);
-
- System.setProperty("jndi.properties.dir", args[0]);
+ log.info("Strating cartridge agent event subscriber");
+ System.setProperty("jndi.properties.dir", args[0]);
//initialting the subscriber
TopicSubscriber subscriber = new TopicSubscriber(Constants.ARTIFACT_SYNCHRONIZATION_TOPIC);
subscriber.setMessageListener(new ArtifactListener());
Thread tsubscriber = new Thread(subscriber);
- tsubscriber.start();
-
- /* try {
- if (log.isInfoEnabled()) {
- log.info("Event subscriber started");
- }
- if ((args != null) && (args.length == 4)) {
-
- EventSubscriberClient client = new EventSubscriberClient(args[0], Integer.parseInt(args[1]), args[2], args[3]);
- client.run();
- System.exit(0);
- } else {
- printInvalidArgs(args);
- }
- } catch (Exception e) {
- if (log.isErrorEnabled()) {
- log.error("Could not publish event", e);
- }
- printInvalidArgs(args);
- }
- System.exit(-1);*/
- }
-
- private static void printInvalidArgs(String[] args) {
- if (log.isErrorEnabled()) {
- if(args != null) {
- StringBuilder builder = new StringBuilder();
- for(String arg : args) {
- builder.append("[" + arg + "] ");
- }
- log.error(String.format("Arguments %s not valid. Event publisher could not be started.", builder.toString()));
- }
- else {
- log.error("Arguments not found. Event publisher could not be started.");
- }
- log.error("Expected: mb-ip-address mb-port event-class-name event-json-file-path");
- }
+ tsubscriber.start();
}
+
}