Updated Branches:
  refs/heads/master 08b6427d7 -> 12adc174d

Fixing cartridge agent issue in sending instance activated event. Added puppet 
agent conf files


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

Branch: refs/heads/master
Commit: 12adc174dfc5e2f35bdc21dd5e65caf1dfe66b52
Parents: 08b6427
Author: Sajith Kariyawasam <[email protected]>
Authored: Wed Dec 18 18:53:30 2013 +0530
Committer: Sajith Kariyawasam <[email protected]>
Committed: Wed Dec 18 18:53:30 2013 +0530

----------------------------------------------------------------------
 .../event/subscriber/ArtifactListener.java      |  6 +-
 .../cartridge/agent/event/subscriber/Main.java  | 22 +++++
 tools/puppet/agent/etc/rc.local                 | 26 ++++++
 tools/puppet/agent/root/bin/ec2_init.sh         | 95 ++++++++++++++++++++
 tools/puppet/agent/ruby/stratos_sendinfo.rb     | 30 +++++++
 5 files changed, 177 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/12adc174/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 8ea6431..9c772e3 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
@@ -27,6 +27,7 @@ import javax.jms.MessageListener;
 import javax.jms.TextMessage;
 
 import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.deployment.synchronizer.RepositoryInformation;
@@ -66,8 +67,9 @@ public class ArtifactListener implements MessageListener{
                
                log.info("cluster id in payload " + clusterIdInPayload);
                log.info("cluster id in message " + clusterIdInMessage);
-               
-               if(clusterIdInPayload != null && 
clusterIdInPayload.equals(clusterIdInMessage)) {                       
+               log.info("repo url " + repoURL);
+                               
+               if( StringUtils.isNotEmpty(repoURL) && clusterIdInPayload != 
null && clusterIdInPayload.equals(clusterIdInMessage)) {                   
                RepositoryInformation repoInformation = new 
RepositoryInformation();
                repoInformation.setRepoUsername(repoUsername);
                repoInformation.setRepoPassword(repoPassword);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/12adc174/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 805808f..a47538a 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
@@ -27,6 +27,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.messaging.broker.publish.EventPublisher;
 import org.apache.stratos.messaging.broker.subscribe.TopicSubscriber;
+import 
org.apache.stratos.messaging.event.instance.status.InstanceActivatedEvent;
 import org.apache.stratos.messaging.event.instance.status.InstanceStartedEvent;
 import org.apache.stratos.messaging.util.Constants;
 
@@ -69,6 +70,27 @@ public class Main {
                publisher.publish(event);
                log.info("Member started event is sent");               
 
+               String repoURL =LaunchParamsUtil
+                       .readParamValueFromPayload("REPO_URL");
+               
+               if ("null".equals(repoURL) || repoURL == null) {
+                       log.info(" No git repo for this cartridge ");
+                       InstanceActivatedEvent instanceActivatedEvent = new 
InstanceActivatedEvent(
+                                       LaunchParamsUtil
+                                                       
.readParamValueFromPayload(CartridgeAgentConstants.SERVICE_NAME),
+                                       LaunchParamsUtil
+                                                       
.readParamValueFromPayload(CartridgeAgentConstants.CLUSTER_ID),
+                                       LaunchParamsUtil
+                                                       
.readParamValueFromPayload(CartridgeAgentConstants.NETWORK_PARTITION_ID),
+                                       LaunchParamsUtil
+                                                       
.readParamValueFromPayload(CartridgeAgentConstants.PARTITION_ID),
+                                       LaunchParamsUtil
+                                                       
.readParamValueFromPayload(CartridgeAgentConstants.MEMBER_ID));
+                       EventPublisher instanceStatusPublisher = new 
EventPublisher(
+                                       Constants.INSTANCE_STATUS_TOPIC);
+                       instanceStatusPublisher.publish(instanceActivatedEvent);
+                       log.info(" Instance status published. No git repo ");
+               }
                
                // Start periodical file checker task
                // TODO -- start this thread only if this node configured as a 
commit true node

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/12adc174/tools/puppet/agent/etc/rc.local
----------------------------------------------------------------------
diff --git a/tools/puppet/agent/etc/rc.local b/tools/puppet/agent/etc/rc.local
new file mode 100644
index 0000000..4f4291d
--- /dev/null
+++ b/tools/puppet/agent/etc/rc.local
@@ -0,0 +1,26 @@
+#!/bin/bash
+# --------------------------------------------------------------
+#
+# 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.
+#
+# --------------------------------------------------------------
+
+/root/bin/ec2_init.sh > /tmp/puppet_log
+
+exit 0
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/12adc174/tools/puppet/agent/root/bin/ec2_init.sh
----------------------------------------------------------------------
diff --git a/tools/puppet/agent/root/bin/ec2_init.sh 
b/tools/puppet/agent/root/bin/ec2_init.sh
new file mode 100644
index 0000000..1896629
--- /dev/null
+++ b/tools/puppet/agent/root/bin/ec2_init.sh
@@ -0,0 +1,95 @@
+#!/bin/bash
+# --------------------------------------------------------------
+#
+# 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.
+#
+# --------------------------------------------------------------
+
+MKDIR=`which mkdir`
+UNZIP=`which unzip`
+ECHO=`which echo`
+FIND=`which find`
+GREP=`which grep`
+RM=`which rm`
+XARGS=`which xargs`
+SED=`which sed`
+CUT=`which cut`
+AWK=`which awk`
+IFCONFIG=`which ifconfig`
+HOSTNAME=`which hostname`
+SLEEP=`which sleep`
+TR=`which tr`
+HEAD=`which head`
+WGET=`which wget`
+PUPPETD=`which puppetd`
+
+COMMAND="${PUPPETD} -vt"
+IP=`${IFCONFIG} eth0 | ${GREP} -e "inet addr" | ${AWK} '{print $2}' | ${CUT} 
-d ':' -f 2`
+
+HOSTSFILE=/etc/hosts
+HOSTNAMEFILE=/etc/hostname
+
+read_master() {
+    ${COMMAND}
+}
+
+
+DATE=`date +%d%m%y%S`
+RANDOMNUMBER="`${TR} -c -d 0-9 < /dev/urandom | ${HEAD} -c 4`${DATE}"
+
+if [ ! -d /tmp/payload ]; then
+
+    ## Clean old poop
+    ${ECHO} "Removing all existing certificates .."
+    #${FIND} /var/lib/puppet -type f -print0 | ${XARGS} -0r ${RM}
+
+    ${MKDIR} -p /tmp/payload
+    ${WGET} http://169.254.169.254/latest/user-data -O 
/tmp/payload/launch-params
+
+    cd /tmp/payload
+    SERVICE_NAME=`sed 's/,/\n/g' launch-params | grep SERVICE_NAME | cut -d 
"=" -f 2`
+    DEPLOYMENT=`sed 's/,/\n/g' launch-params | grep DEPLOYMENT | cut -d "=" -f 
2`
+    INSTANCE_HOSTNAME=`sed 's/,/\n/g' launch-params | grep HOSTNAME | cut -d 
"=" -f 2`
+    PUPPET_IP=`sed 's/,/\n/g' launch-params | grep PUPPET_IP | cut -d "=" -f 2`
+    HOST="${RANDOMNUMBER}.${DEPLOYMENT}.${SERVICE_NAME}"
+    ${ECHO} -e "\nNew hostname ${HOST}\n"
+
+    ## Set the hostname
+    ${HOSTNAME} ${HOST}
+    ${ECHO} "${HOST}" > ${HOSTNAMEFILE}
+    ${ECHO} "${PUPPET_IP}  demo.stratos.org" >> ${HOSTSFILE} 
+    /etc/init.d/hostname start
+
+#   ## Enable and restart Puppet
+#   ${SED} -i /etc/default/puppet -e 's/START=no/START=yes/'
+    /etc/init.d/puppet stop
+
+    ${SLEEP} 5
+    
+    ${PUPPETD} --enable
+    
+    read_master
+
+#   ${SLEEP} 15m
+
+    ${PUPPETD} --disable
+
+    #${ECHO} "* * * * * root /root/bin/cron-hosts.sh" >> /etc/crontab
+fi
+
+# END

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/12adc174/tools/puppet/agent/ruby/stratos_sendinfo.rb
----------------------------------------------------------------------
diff --git a/tools/puppet/agent/ruby/stratos_sendinfo.rb 
b/tools/puppet/agent/ruby/stratos_sendinfo.rb
new file mode 100644
index 0000000..1ab3a9b
--- /dev/null
+++ b/tools/puppet/agent/ruby/stratos_sendinfo.rb
@@ -0,0 +1,30 @@
+# --------------------------------------------------------------
+#
+# 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.
+#
+# --------------------------------------------------------------
+
+
+configs = File.read("/tmp/payload/launch-params").split(",").map(&:strip)
+
+configs.each { |x| key_value_pair = x.split("=").map(&:strip)
+        Facter.add("stratos_instance_data_" + key_value_pair[0].to_s){
+                 setcode { key_value_pair[1].to_s
+                }
+        }
+ }

Reply via email to