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/12/04 13:58:49 UTC
[1/2] git commit: Fixing member started event and artifact update
event conflict issue.
Updated Branches:
refs/heads/master 11480eb55 -> 593451a59
Fixing member started event and artifact update event conflict issue.
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/f6168bcb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/f6168bcb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/f6168bcb
Branch: refs/heads/master
Commit: f6168bcb15bb05ca8cd3cc0c349e93ce40fb32e8
Parents: 6b86f4a
Author: Sajith Kariyawasam <sa...@wso2.com>
Authored: Wed Dec 4 18:27:37 2013 +0530
Committer: Sajith Kariyawasam <sa...@wso2.com>
Committed: Wed Dec 4 18:27:37 2013 +0530
----------------------------------------------------------------------
.../cartridge-agent/ec2/php/cartridge-agent.sh | 75 +-------------------
.../git/impl/GitBasedArtifactRepository.java | 21 ++++++
.../event/subscriber/ArtifactListener.java | 57 ++++++---------
.../subscriber/CartridgeAgentConstants.java | 3 +
.../event/subscriber/LaunchParamsUtil.java | 58 +++++++++++++++
.../cartridge/agent/event/subscriber/Main.java | 22 +++++-
6 files changed, 126 insertions(+), 110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f6168bcb/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 3b47504..fcdabe3 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
@@ -58,6 +58,7 @@ fi
source ${instance_path}/launch.params
+
#---------------------------
# Starting Topic Subscriber
#---------------------------
@@ -77,81 +78,9 @@ echo "Event subscribed" | tee -a $LOG
popd
-# ---------------------------------------------
-# Publish member-started-event
-# ---------------------------------------------
-echo "Generating member-started-event.json..." | tee -a $LOG
-cp -f $event_publisher_path/templates/member-started-event.json.template member-started-event.json.tmp
-cat member-started-event.json.tmp | sed -e "s@SERVICE_NAME@$SERVICE_NAME@g" > member-started-event.json
-cp -f member-started-event.json member-started-event.json.tmp
-cat member-started-event.json.tmp | sed -e "s@CLUSTER_ID@$CLUSTER_ID@g" > member-started-event.json
-cp -f member-started-event.json member-started-event.json.tmp
-cat member-started-event.json.tmp | sed -e "s@MEMBER_ID@$MEMBER_ID@g" > member-started-event.json
-rm -f member-started-event.json.tmp
-echo "member-started-event.json generated" | tee -a $LOG
-
-echo "Publishing member started event..." | tee -a $LOG
-event_class_name=org.apache.stratos.messaging.event.instance.status.MemberStartedEvent
-event_json_path=`pwd`/member-started-event.json
-
-pushd $event_publisher_path/bin
-echo "Executing: event-publisher.sh $MB_IP $MB_PORT $event_class_name $event_json_path"
-sh event-publisher.sh $MB_IP $MB_PORT $event_class_name $event_json_path
-echo "Event published" | tee -a $LOG
-popd
-
-
-# -----------------------------------------------------
-# Publish member-activated-event
-# -----------------------------------------------------
-while true
-do
-var=`nc -z localhost 80; echo $?`;
-if [ $var -eq 0 ]
- then
- echo "Port 80 is available" | tee -a $LOG
- break
- else
- echo "Port 80 is not available" | tee -a $LOG
- fi
- sleep 1
-done
-
-while true
-do
-var=`nc -z localhost 443; echo $?`;
-if [ $var -eq 0 ]
- then
- echo "Port 443 is available" | tee -a $LOG
- break
- else
- echo "Port 443 is not available" | tee -a $LOG
- fi
- sleep 1
-done
-
-echo "Generating member-activated-event.json..." | tee -a $LOG
-cp -f $event_publisher_path/templates/member-activated-event.json.template member-activated-event.json.tmp
-cat member-activated-event.json.tmp | sed -e "s@SERVICE_NAME@$SERVICE_NAME@g" > member-activated-event.json
-cp -f member-activated-event.json member-activated-event.json.tmp
-cat member-activated-event.json.tmp | sed -e "s@CLUSTER_ID@$CLUSTER_ID@g" > member-activated-event.json
-cp -f member-activated-event.json member-activated-event.json.tmp
-cat member-activated-event.json.tmp | sed -e "s@MEMBER_ID@$MEMBER_ID@g" > member-activated-event.json
-rm -f member-activated-event.json.tmp
-echo "member-activated-event.json generated" | tee -a $LOG
-
-echo "Publishing member activated event..." | tee -a $LOG
-event_class_name=org.apache.stratos.messaging.event.instance.status.MemberActivatedEvent
-event_json_path=`pwd`/member-activated-event.json
-
-pushd $event_publisher_path/bin
-echo "Executing: event-publisher.sh $MB_IP $MB_PORT $event_class_name $event_json_path"
-sh event-publisher.sh $MB_IP $MB_PORT $event_class_name $event_json_path
-echo "Event published" | tee -a $LOG
-popd
-
pushd $health_publisher_path/bin
echo "Executing: health-publisher.sh"
sh health-publisher.sh $MEMBER_ID $CEP_IP $CEP_PORT $PORTS $CLUSTER_ID
echo "Health stat published" | tee -a $LOG
popd
+
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f6168bcb/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java b/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
index 98f99ab..7586b41 100644
--- a/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
+++ b/products/cartridge-agent/modules/deployment-synchronizer/src/main/java/org/apache/stratos/deployment/synchronizer/git/impl/GitBasedArtifactRepository.java
@@ -411,6 +411,27 @@ public class GitBasedArtifactRepository /*implements ArtifactRepository*/ {
return pullArtifacts(gitRepoCtx);
}
+
+
+
+ public static boolean cloneExists(RepositoryInformation repositoryInformation) {
+
+ int tenantId = Integer.parseInt(repositoryInformation.getTenantId());
+
+ // if context for tenant is not initialized
+ if(tenantToRepoContextMap.get(tenantId) == null)
+ initGitContext(repositoryInformation);
+
+
+ RepositoryContext gitRepoCtx = retrieveCachedGitContext(tenantId);
+ if(gitRepoCtx == null) {
+ return false;
+ }
+
+ /*if(gitRepoCtx.getTenantId() == GitDeploymentSynchronizerConstants.SUPER_TENANT_ID)
+ return true; */
+ return gitRepoCtx.cloneExists();
+ }
/**
* Pulling if any updates are available in the remote git repository. If basic authentication is required,
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f6168bcb/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 5796726..0de55a6 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
@@ -19,9 +19,6 @@
package org.apache.stratos.cartridge.agent.event.subscriber;
-import java.io.File;
-import java.util.Scanner;
-
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
@@ -32,10 +29,12 @@ import javax.jms.TextMessage;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.deployment.synchronizer.ArtifactRepository;
import org.apache.stratos.deployment.synchronizer.RepositoryInformation;
import org.apache.stratos.deployment.synchronizer.git.impl.GitBasedArtifactRepository;
+import org.apache.stratos.messaging.broker.publish.TopicPublisher;
import org.apache.stratos.messaging.event.artifact.synchronization.ArtifactUpdatedEvent;
+import org.apache.stratos.messaging.event.instance.status.MemberActivatedEvent;
+import org.apache.stratos.messaging.util.Constants;
import org.apache.stratos.messaging.util.Util;
@@ -57,8 +56,8 @@ public class ArtifactListener implements MessageListener{
}
ArtifactUpdatedEvent event = (ArtifactUpdatedEvent) Util.jsonToObject(json, ArtifactUpdatedEvent.class);
- String clusterIdInPayload = readParamValueFromPayload(CartridgeAgentConstants.CLUSTER_ID);
- String localRepoPath = readParamValueFromPayload(CartridgeAgentConstants.APP_PATH);
+ String clusterIdInPayload = LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.CLUSTER_ID);
+ String localRepoPath = LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.APP_PATH);
String clusterIdInMessage = event.getClusterId();
String repoURL = event.getRepoURL();
String repoPassword = decryptPassword(event.getRepoPassword());
@@ -74,44 +73,30 @@ public class ArtifactListener implements MessageListener{
repoInformation.setRepoPassword(repoPassword);
repoInformation.setRepoUrl(repoURL);
repoInformation.setRepoPath(localRepoPath);
- repoInformation.setTenantId(tenantId);
- GitBasedArtifactRepository.checkout(repoInformation);
+ repoInformation.setTenantId(tenantId);
+ boolean cloneExists = GitBasedArtifactRepository.cloneExists(repoInformation);
+ GitBasedArtifactRepository.checkout(repoInformation);
+ if(!cloneExists){
+ // send member activated event
+ log.info("Sending member activated event");
+ // Send member activated event
+ MemberActivatedEvent memberActivatedEvent = new MemberActivatedEvent();
+ memberActivatedEvent.setServiceName(LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.SERVICE_NAME));
+ memberActivatedEvent.setClusterId(LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.CLUSTER_ID));
+ memberActivatedEvent.setMemberId(LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.MEMBER_ID));
+ TopicPublisher publisher = new TopicPublisher(Constants.INSTANCE_STATUS_TOPIC);
+ publisher.publish(memberActivatedEvent);
+ log.info("Member activated event is sent");
+ }
}
}
-
- private String readParamValueFromPayload(String param) {
- String paramValue = null;
- // read launch params
- File file = new File(System.getProperty(CartridgeAgentConstants.PARAM_FILE_PATH));
-
- try {
- Scanner scanner = new Scanner(file);
-
- while (scanner.hasNextLine()) {
- String line = scanner.nextLine();
- String[] params = line.split(",");
- for (String string : params) {
- String[] var = string.split("=");
- if(param.equals(var[0])){
- paramValue = var[1];
- }
- }
- }
- scanner.close();
- } catch (Exception e) {
- //e.printStackTrace();
- log.error("Exception is occurred in reading file. ", e);
- }
-
- return paramValue;
- }
private String decryptPassword(String repoUserPassword) {
String decryptPassword = "";
- String secret = readParamValueFromPayload(CartridgeAgentConstants.CARTRIDGE_KEY);
+ String secret = LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.CARTRIDGE_KEY);
SecretKey key;
Cipher cipher;
Base64 coder;
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f6168bcb/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/CartridgeAgentConstants.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/CartridgeAgentConstants.java b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/CartridgeAgentConstants.java
index 7fceaf3..d3ce926 100644
--- a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/CartridgeAgentConstants.java
+++ b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/CartridgeAgentConstants.java
@@ -29,5 +29,8 @@ public class CartridgeAgentConstants implements Serializable{
public static final String CARTRIDGE_KEY = "CARTRIDGE_KEY";
public static final String CLUSTER_ID = "CLUSTER_ID";
public static final String APP_PATH = "APP_PATH";
+ public static final String SERVICE_NAME = "SERVICE_NAME";
+ public static final String MEMBER_ID = "MEMBER_ID";
+
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f6168bcb/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/LaunchParamsUtil.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/LaunchParamsUtil.java b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/LaunchParamsUtil.java
new file mode 100644
index 0000000..164116d
--- /dev/null
+++ b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/LaunchParamsUtil.java
@@ -0,0 +1,58 @@
+/*
+ * 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.cartridge.agent.event.subscriber;
+
+import java.io.File;
+import java.util.Scanner;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class LaunchParamsUtil {
+
+ private static final Log log = LogFactory.getLog(LaunchParamsUtil.class);
+
+ public static String readParamValueFromPayload(String param) {
+ String paramValue = null;
+ // read launch params
+ File file = new File(System.getProperty(CartridgeAgentConstants.PARAM_FILE_PATH));
+
+ try {
+ Scanner scanner = new Scanner(file);
+
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ String[] params = line.split(",");
+ for (String string : params) {
+ String[] var = string.split("=");
+ if(param.equals(var[0])){
+ paramValue = var[1];
+ }
+ }
+ }
+ scanner.close();
+ } catch (Exception e) {
+ //e.printStackTrace();
+ log.error("Exception is occurred in reading file. ", e);
+ }
+
+ return paramValue;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f6168bcb/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 2c4daa6..e1c680f 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
@@ -25,7 +25,9 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.broker.publish.TopicPublisher;
import org.apache.stratos.messaging.broker.subscribe.TopicSubscriber;
+import org.apache.stratos.messaging.event.instance.status.MemberStartedEvent;
import org.apache.stratos.messaging.util.Constants;
/**
@@ -46,7 +48,25 @@ public class Main {
TopicSubscriber subscriber = new TopicSubscriber(Constants.ARTIFACT_SYNCHRONIZATION_TOPIC);
subscriber.setMessageListener(new ArtifactListener());
Thread tsubscriber = new Thread(subscriber);
- tsubscriber.start();
+ tsubscriber.start();
+
+ //
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ log.info("Sending member started event");
+ // Send member activated event
+ MemberStartedEvent event = new MemberStartedEvent();
+ event.setServiceName(LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.SERVICE_NAME));
+ event.setClusterId(LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.CLUSTER_ID));
+ event.setMemberId(LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.MEMBER_ID));
+ TopicPublisher publisher = new TopicPublisher(Constants.INSTANCE_STATUS_TOPIC);
+ publisher.publish(event);
+ log.info("Member started event is sent");
+
// Start periodical file checker task
// TODO -- start this thread only if this node configured as a commit true node
[2/2] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-stratos
Posted by sa...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/593451a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/593451a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/593451a5
Branch: refs/heads/master
Commit: 593451a5941aa96495a222ff47a1f33ad526a99a
Parents: f6168bc 11480eb
Author: Sajith Kariyawasam <sa...@wso2.com>
Authored: Wed Dec 4 18:28:20 2013 +0530
Committer: Sajith Kariyawasam <sa...@wso2.com>
Committed: Wed Dec 4 18:28:20 2013 +0530
----------------------------------------------------------------------
.../main/java/org/apache/stratos/autoscaler/AutoscalerContext.java | 2 +-
.../java/org/apache/stratos/load/balancer/LoadBalancerContext.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------