You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2013/10/28 09:25:59 UTC

[1/2] git commit: Re-designed cartridge agent product by dividing it to two modules: catridge-agent (scripts) and catridge-agent-event-publisher

Updated Branches:
  refs/heads/master 6d2513384 -> 8351106f1


Re-designed cartridge agent product by dividing it to two modules: catridge-agent (scripts) and catridge-agent-event-publisher


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

Branch: refs/heads/master
Commit: c2cbf4dc42fb8584a46aa241115fb9abe8337f6c
Parents: 859d6d7
Author: Imesh Gunaratne <im...@apache.org>
Authored: Mon Oct 28 13:55:11 2013 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Mon Oct 28 13:55:11 2013 +0530

----------------------------------------------------------------------
 products/cartridge-agent/README.txt             |  27 ---
 .../cartridge-agent-event-publisher/pom.xml     | 118 ++++++++++
 .../src/main/assembly/bin.xml                   |  63 ++++++
 .../src/main/bin/event-publisher.sh             |  29 +++
 .../agent/event/publisher/EventPublisher.java   | 108 +++++++++
 .../event/publisher/EventPublisherClient.java   | 102 +++++++++
 .../cartridge/agent/event/publisher/Main.java   |  67 ++++++
 .../src/main/resources/jndi.properties          |  22 ++
 .../src/main/resources/log4j.properties         |  37 ++++
 .../member-activated-event.json.template        |   1 +
 .../member-started-event.json.template          |   1 +
 .../cartridge-agent/ec2/php/cartridge-agent.sh  | 221 +++++++++++++++++++
 .../ec2/php/get-launch-params.rb                |  54 +++++
 .../cartridge-agent/ec2/php/healthcheck.sh      |  33 +++
 products/cartridge-agent/pom.xml                |  97 +-------
 .../src/main/assembly/assembly.xml              |  54 -----
 .../src/main/bin/cartridge-agent.sh             |  83 -------
 .../src/main/bin/get-launch-params.rb           |  52 -----
 .../src/main/bin/user-data.json.template        |   1 -
 .../stratos/cartridge/agent/CartridgeAgent.java | 147 ------------
 .../stratos/cartridge/agent/EventPublisher.java | 109 ---------
 .../apache/stratos/cartridge/agent/Main.java    |  58 -----
 .../stratos/cartridge/agent/UserData.java       |  91 --------
 .../src/main/resources/jndi.properties          |  22 --
 .../src/main/resources/log4j.properties         |  37 ----
 25 files changed, 868 insertions(+), 766 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/README.txt
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/README.txt b/products/cartridge-agent/README.txt
deleted file mode 100644
index 2903eac..0000000
--- a/products/cartridge-agent/README.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# 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.
-#
-
-Apache Stratos Cartridge Agent
-------------------------------
-
-How to use:
-1. Extract the cartridge agent binary package to a directory inside the cartridge image.
-2. Read the payload and set following environment variables:
-   $service-name $cluster-id $member-id $ip-address $port
-3. Execute cartridge-agent.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent-event-publisher/pom.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent-event-publisher/pom.xml b/products/cartridge-agent/modules/cartridge-agent-event-publisher/pom.xml
new file mode 100644
index 0000000..490c632
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent-event-publisher/pom.xml
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>stratos-products-parent</artifactId>
+        <groupId>org.apache.stratos</groupId>
+        <version>4.0.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>apache-stratos-cartridge-agent-event-publisher</artifactId>
+    <name>Apache Stratos - Cartridge Agent Event Publisher</name>
+
+    <repositories>
+        <repository>
+            <id>wso2-nexus</id>
+            <name>WSO2 internal Repository</name>
+            <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
+            <releases>
+                <enabled>true</enabled>
+                <updatePolicy>daily</updatePolicy>
+                <checksumPolicy>ignore</checksumPolicy>
+            </releases>
+        </repository>
+    </repositories>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.wso2.andes.wso2</groupId>
+            <artifactId>andes-client</artifactId>
+            <version>0.13.wso2v8</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs.wso2</groupId>
+            <artifactId>geronimo-jms_1.1_spec</artifactId>
+            <version>1.1.0.wso2v1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>1.7.5</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.2.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.stratos</groupId>
+            <artifactId>org.apache.stratos.messaging</artifactId>
+            <version>4.0.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.0</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>2.4</version>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <mainClass>org.apache.stratos.cartridge.agent.event.publisher.Main</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+            <plugin>
+            <artifactId>maven-assembly-plugin</artifactId>
+            <version>2.2.1</version>
+            <configuration>
+                <descriptors>
+                    <descriptor>src/main/assembly/bin.xml</descriptor>
+                </descriptors>
+                <archiverConfig>
+                    <fileMode>420</fileMode>
+                    <directoryMode>493</directoryMode>
+                    <defaultDirectoryMode>493</defaultDirectoryMode>
+                </archiverConfig>
+            </configuration>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>attached</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/assembly/bin.xml b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/assembly/bin.xml
new file mode 100644
index 0000000..93f860f
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/assembly/bin.xml
@@ -0,0 +1,63 @@
+<!--
+  ~ 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.
+  -->
+
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+    <id>bin</id>
+    <formats>
+        <format>zip</format>
+    </formats>
+    <fileSets>
+        <fileSet>
+            <directory>${project.basedir}/src/main/bin</directory>
+            <outputDirectory>/bin</outputDirectory>
+            <fileMode>0755</fileMode>
+            <includes>
+                <include>event-publisher.sh</include>
+            </includes>
+        </fileSet>
+        <fileSet>
+            <directory>${project.basedir}/src/main/templates</directory>
+            <outputDirectory>/templates</outputDirectory>
+            <fileMode>0600</fileMode>
+            <includes>
+                <include>member-started-event.json.template</include>
+                <include>member-activated-event.json.template</include>
+            </includes>
+        </fileSet>
+        <fileSet>
+            <directory>${project.basedir}</directory>
+            <outputDirectory>/</outputDirectory>
+            <fileMode>0600</fileMode>
+            <includes>
+                <include>README*</include>
+                <include>LICENSE*</include>
+                <include>NOTICE*</include>
+            </includes>
+        </fileSet>
+    </fileSets>
+    <dependencySets>
+        <dependencySet>
+            <outputDirectory>/lib</outputDirectory>
+            <useProjectArtifact>true</useProjectArtifact>
+            <scope>runtime</scope>
+        </dependencySet>
+    </dependencySets>
+</assembly>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/bin/event-publisher.sh
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/bin/event-publisher.sh b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/bin/event-publisher.sh
new file mode 100755
index 0000000..12e0da4
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/bin/event-publisher.sh
@@ -0,0 +1,29 @@
+#!/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.
+#
+# --------------------------------------------------------------
+
+echo "Starting event publisher..."
+lib_path=./../lib/
+class_path=${lib_path}commons-io-2.0.jar:${lib_path}andes-client-0.13.wso2v8.jar:${lib_path}apache-stratos-cartridge-agent-event-publisher-4.0.0-SNAPSHOT.jar:${lib_path}commons-codec-1.8.jar:${lib_path}commons-logging-1.1.1.jar:${lib_path}geronimo-jms_1.1_spec-1.1.0.wso2v1.jar:${lib_path}geronimo-jms_1.1_spec-1.1.jar:${lib_path}gson-2.2.4.jar:${lib_path}log4j-1.2.13.jar:${lib_path}org.apache.log4j-1.2.13.v200706111418.jar:${lib_path}org.apache.stratos.messaging-4.0.0-SNAPSHOT.jar:${lib_path}org.wso2.carbon.logging-4.1.0.jar:${lib_path}slf4j-api-1.7.5.jar:${lib_path}slf4j-log4j12-1.7.5.jar
+
+java -cp $class_path org.apache.stratos.cartridge.agent.event.publisher.Main $*
+echo "Event publisher completed"
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisher.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisher.java b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisher.java
new file mode 100644
index 0000000..8136670
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisher.java
@@ -0,0 +1,108 @@
+/*
+ * 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.publisher;
+
+import com.google.gson.Gson;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.event.Event;
+import org.apache.stratos.messaging.util.Constants;
+
+import javax.jms.*;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * A generic topic publisher.
+ */
+public class EventPublisher {
+    private static final Log log = LogFactory.getLog(EventPublisher.class);
+
+    private TopicConnection topicConnection;
+    private TopicSession topicSession;
+    private Topic topic;
+    private String mbIpAddress;
+    private int mbPort;
+    private String topicName;
+
+    public EventPublisher(String mbIpAddress, int mbPort, String topicName) {
+        this.mbIpAddress = mbIpAddress;
+        this.mbPort = mbPort;
+        this.topicName = topicName;
+    }
+
+    private Properties getProperties() throws IOException {
+        Properties properties = new Properties();
+        properties.load(EventPublisher.class.getClassLoader().getResourceAsStream("jndi.properties"));
+
+        // Set message broker ip and port
+        String connectionFactoryName = properties.get("connectionfactoryName").toString();
+        String key = "connectionfactory." + connectionFactoryName;
+        String connectionFactoryStr = (String) properties.get(key);
+        connectionFactoryStr = connectionFactoryStr.replace("MB-IP-ADDRESS", mbIpAddress);
+        connectionFactoryStr = connectionFactoryStr.replace("MB-PORT", String.valueOf(mbPort));
+        properties.setProperty(key, connectionFactoryStr);
+
+        return properties;
+    }
+
+    public void connect() throws NamingException, JMSException, IOException {
+        // Prepare JNDI properties
+        Properties properties = getProperties();
+        InitialContext ctx = new InitialContext(properties);
+
+        // Lookup connection factory
+        String connectionFactoryName = properties.get("connectionfactoryName").toString();
+        TopicConnectionFactory connectionFactory = (TopicConnectionFactory) ctx.lookup(connectionFactoryName);
+        topicConnection = connectionFactory.createTopicConnection();
+        topicConnection.start();
+        topicSession = topicConnection.createTopicSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+        // Create topic
+        topic = topicSession.createTopic(topicName);
+    }
+
+    public void publish(Event event) throws NamingException, JMSException, IOException {
+        Gson gson = new Gson();
+        String json = gson.toJson(event);
+        publish(json, event.getClass().getName());
+    }
+
+    private void publish(String message, String eventClassName) throws NamingException, JMSException, IOException {
+        TextMessage textMessage = topicSession.createTextMessage((String) message);
+        textMessage.setStringProperty(Constants.EVENT_CLASS_NAME, eventClassName);
+        javax.jms.TopicPublisher topicPublisher = topicSession.createPublisher(topic);
+        topicPublisher.publish(textMessage);
+
+        if (log.isDebugEnabled()) {
+            log.debug(String.format("Message published: [topic] %s [header] %s [body] %s", topicName, eventClassName, message));
+        }
+    }
+
+    public void close() throws JMSException {
+        // Clean up resources
+        if (topicSession != null)
+            topicSession.close();
+        if (topicConnection != null)
+            topicConnection.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisherClient.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisherClient.java b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisherClient.java
new file mode 100644
index 0000000..dcc0c83
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/EventPublisherClient.java
@@ -0,0 +1,102 @@
+/*
+ * 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.publisher;
+
+import com.google.gson.Gson;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.event.Event;
+
+import javax.jms.JMSException;
+import javax.naming.NamingException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * Cartridge agent lifecycle implementation.
+ */
+public class EventPublisherClient {
+    private static final Log log = LogFactory.getLog(EventPublisherClient.class);
+
+    private String mbIpAddress;
+    private int mbPort;
+    private String eventClassName;
+    private String jsonFilePath;
+
+    public EventPublisherClient(String mbIpAddress, int mbPort, String eventClassName, String jsonFilePath) {
+        this.mbIpAddress = mbIpAddress;
+        this.mbPort = mbPort;
+        this.eventClassName = eventClassName;
+        this.jsonFilePath = jsonFilePath;
+    }
+
+    private Event jsonToEvent(String jsonFilePath) {
+        FileInputStream fileInputStream = null;
+        try {
+            fileInputStream = new FileInputStream(new File(jsonFilePath));
+            String json = IOUtils.toString(fileInputStream, "UTF-8");
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Json: %s", json));
+            }
+            Class eventClass = Class.forName(eventClassName);
+            return (Event) new Gson().fromJson(json, eventClass);
+        } catch (FileNotFoundException e) {
+            if (log.isErrorEnabled()) {
+                log.error(e);
+            }
+            throw new RuntimeException(String.format("Could not find json file %s", jsonFilePath));
+        } catch (ClassNotFoundException e) {
+            if (log.isErrorEnabled()) {
+                log.error(e);
+            }
+            throw new RuntimeException(String.format("Event class name %s is not valid", eventClassName));
+        } catch (Exception e) {
+            if (log.isErrorEnabled()) {
+                log.error(e);
+            }
+            throw new RuntimeException(String.format("Could not read json file %s", jsonFilePath));
+        }
+    }
+
+    public void run() throws JMSException, NamingException, IOException {
+        if (log.isInfoEnabled()) {
+            log.info("\nEvent publisher started");
+        }
+        Event event = jsonToEvent(jsonFilePath);
+        publishEvent(event);
+    }
+
+
+    private void publishEvent(Event event) throws JMSException, NamingException, IOException {
+        EventPublisher publisher = new EventPublisher(mbIpAddress, mbPort, org.apache.stratos.messaging.util.Constants.INSTANCE_STATUS_TOPIC);
+        try {
+            publisher.connect();
+            publisher.publish(event);
+            if (log.isInfoEnabled()) {
+                log.info(String.format("Event %s published", eventClassName));
+            }
+        } finally {
+            publisher.close();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/Main.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/Main.java b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/Main.java
new file mode 100644
index 0000000..818bfbb
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/java/org/apache/stratos/cartridge/agent/event/publisher/Main.java
@@ -0,0 +1,67 @@
+/*
+ * 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.publisher;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Event publisher main class.
+ */
+public class Main {
+    private static final Log log = LogFactory.getLog(Main.class);
+
+    public static void main(String[] args) {
+        try {
+            if (log.isInfoEnabled()) {
+                log.info("Event publisher started");
+            }
+            if ((args != null) && (args.length == 4)) {
+                EventPublisherClient client = new EventPublisherClient(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");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/resources/jndi.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/resources/jndi.properties b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/resources/jndi.properties
new file mode 100644
index 0000000..d3b29bc
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/resources/jndi.properties
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+
+connectionfactoryName=topicConnectionfactory
+connectionfactory.topicConnectionfactory=amqp://admin:admin@carbon/carbon?brokerlist='tcp://MB-IP-ADDRESS:MB-PORT'
+java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/resources/log4j.properties b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/resources/log4j.properties
new file mode 100644
index 0000000..4c4e610
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/resources/log4j.properties
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+
+# Set root logger level and appenders
+log4j.rootLogger=INFO, CONSOLE_APPENDER, FILE_APPENDER
+
+# CONSOLE_APPENDER is set to be a ConsoleAppender.
+log4j.appender.CONSOLE_APPENDER=org.apache.log4j.ConsoleAppender
+
+# The standard error log where all the warnings, errors and fatal errors will be logged
+log4j.appender.FILE_APPENDER=org.apache.log4j.FileAppender
+log4j.appender.FILE_APPENDER.File=/var/log/apache-stratos/cartridge-agent-event-publisher.log
+log4j.appender.FILE_APPENDER.layout=org.apache.log4j.PatternLayout
+log4j.appender.FILE_APPENDER.layout.ConversionPattern=%d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n
+log4j.appender.FILE_APPENDER.threshold=DEBUG
+
+# CONSOLE_APPENDER uses PatternLayout.
+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.cartridge.agent.event.publisher=DEBUG
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/templates/member-activated-event.json.template
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/templates/member-activated-event.json.template b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/templates/member-activated-event.json.template
new file mode 100644
index 0000000..e2b2371
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/templates/member-activated-event.json.template
@@ -0,0 +1 @@
+{"serviceName":"SERVICE_NAME","clusterId":"CLUSTER_ID","memberId":"MEMBER_ID"}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/templates/member-started-event.json.template
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/templates/member-started-event.json.template b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/templates/member-started-event.json.template
new file mode 100644
index 0000000..e2b2371
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent-event-publisher/src/main/templates/member-started-event.json.template
@@ -0,0 +1 @@
+{"serviceName":"SERVICE_NAME","clusterId":"CLUSTER_ID","memberId":"MEMBER_ID"}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/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
new file mode 100755
index 0000000..4b2449d
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent/ec2/php/cartridge-agent.sh
@@ -0,0 +1,221 @@
+#!/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.
+#
+# --------------------------------------------------------------
+
+# This script will be called from /etc/rc.local when the cartridge
+# instance is spawned. It will initiate all the tasks that needs to 
+# be run to bring the cartridge instance to operational state.
+
+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
+
+# ---------------------------------------------
+# Download payload.zip
+# ---------------------------------------------
+if [ ! -d ${instance_path}/payload ]; then
+    echo "creating payload directory... " | tee -a $LOG
+    mkdir ${instance_path}/payload
+    echo "payload directory created" | tee -a $LOG
+    wget http://169.254.169.254/latest/user-data -O ${instance_path}/payload/payload.zip    
+    echo "payload copied"  | tee -a $LOG
+    unzip -d ${instance_path}/payload ${instance_path}/payload/payload.zip
+    echo "unzipped" | tee -a $LOG
+
+    for i in `/usr/bin/ruby ${instance_path}/get-launch-params.rb`
+    do
+        # Add double quotes on both sides of the value
+        value=`echo "${i}" | sed -e s@=@=\"@g`
+        value=${value}"\""
+        if [[ ${value} == PORTS* ]]; then
+            # Replace port separator | with ,
+            value=`echo ${value} | sed -e s@'|'@,@g`
+        fi
+        echo "writing to launch.params ${value}" | tee -a $LOG
+        echo "export" ${value} >> ${instance_path}/launch.params
+    done    
+fi
+
+source ${instance_path}/launch.params
+
+# ---------------------------------------------
+# 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
+popd
+echo "Event published" | tee -a $LOG
+
+
+# -----------------------------------------------------
+# Generate git.sh
+# -----------------------------------------------------
+echo "Creating repoinfo request  " | tee -a $LOG
+echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://org.apache.axis2/xsd\">
+   <soapenv:Header/>
+   <soapenv:Body>
+      <xsd:getRepositoryCredentials>
+         <xsd:tenantId>${TENANT_ID}</xsd:tenantId>
+         <xsd:cartridgeType>${SERVICE_NAME}</xsd:cartridgeType>
+         <xsd:alias>${CARTRIDGE_ALIAS}</xsd:alias>
+      </xsd:getRepositoryCredentials>
+   </soapenv:Body>
+</soapenv:Envelope>" > ${instance_path}/repoinforequest.xml
+
+echo "Repoinfo request created " | tee -a $LOG
+
+
+echo "Generating git.sh..." | tee -a $LOG
+# If repo is available do a git pull, else clone
+echo "#!/bin/bash
+if [ -d \"${APP_PATH}/.git\" ]; then
+   cd ${APP_PATH}
+    
+   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
+   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\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+   git config --global --bool --add http.sslVerify false
+   sudo git pull
+   rm ~/.netrc
+   sudo rm /root/.netrc
+
+   sudo chown -R www-data:www-data ${APP_PATH}/www
+   if [ -f \"${APP_PATH}/sql/alter.sql\" ]; then
+ 	mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} < ${APP_PATH}/sql/alter.sql
+   fi
+else
+   sudo rm -f ${APP_PATH}/index.html
+   curl -X POST -H \"Content-Type: text/xml\" -H \"SOAPAction: urn:getRepositoryCredentials\" -d @/opt/repoinforequest.xml --silent  \"${REPO_INFO_EPR}\" --insecure > /tmp/git.xml
+   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\`
+   rm /tmp/git1.xml
+   rm /tmp/git.xml
+   url=\`echo \$repo |sed 's/http.*\/\///g' |sed 's/\:.*//g' |sed 's/\/.*//g'\`
+   echo \"machine \${url} login \${username} password \${password}\" > ~/.netrc
+   sudo echo \"machine \${url} login \${username} password \${password}\" > /root/.netrc
+   chmod 600 ~/.netrc
+   sudo chmod 600 /root/.netrc
+   git config --global --bool --add http.sslVerify false
+   sudo git clone \${repo} ${APP_PATH}
+   rm ~/.netrc
+   sudo rm /root/.netrc
+ 
+
+   if [ -f \"${APP_PATH}/sql/init.sql\" ]; then
+       mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} < ${APP_PATH}/sql/init.sql
+   fi
+   echo \"SetEnv STRATOS_MYSQL_USER ${MYSQL_USER}
+   SetEnv STRATOS_MYSQL_HOST ${MYSQL_HOST}
+   SetEnv STRATOS_MYSQL_PASSWORD ${MYSQL_PASSWORD}
+   \" > /tmp/.htaccess
+   sudo mv /tmp/.htaccess ${APP_PATH}/
+   sudo chown -R www-data:www-data ${APP_PATH}/www
+    
+fi" > ${instance_path}/git.sh
+echo "File created.." | tee -a $LOG
+chmod 755 ${instance_path}/git.sh
+
+
+# -----------------------------------------------------
+# 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
+popd
+echo "Event published" | tee -a $LOG
+
+# -----------------------------------------------------
+# Git clone
+# -----------------------------------------------------
+echo "running git clone..." | tee -a $LOG
+sh ${instance_path}/git.sh
+echo "git clone done" | tee -a $LOG
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent/ec2/php/get-launch-params.rb
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent/ec2/php/get-launch-params.rb b/products/cartridge-agent/modules/cartridge-agent/ec2/php/get-launch-params.rb
new file mode 100644
index 0000000..0631b2b
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent/ec2/php/get-launch-params.rb
@@ -0,0 +1,54 @@
+#! /usr/bin/ruby
+# --------------------------------------------------------------
+#
+# 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.
+#
+# --------------------------------------------------------------
+
+### get-launch-params.rb
+
+# The following script obtains the launch parameters from 
+# the file /tmp/payload/launch-params, then parses out the 
+# parameters for this instance by using the launch index
+# of this particular EC2 instance.
+#
+# Pass the command the -e flag to output the instance 
+# parameters as exports of shell variables. Any other 
+# arguments are ignored.
+
+def get_launch_params(launch_params_file)
+  IO.readlines launch_params_file
+end
+
+export_stmt = ""
+
+launch_params = get_launch_params(
+  "/opt/apache-stratos-cartridge-agent/payload/launch-params")
+
+if launch_params.length > 0
+  instance_params_str = launch_params[0]
+
+  instance_params = instance_params_str.split(',')
+
+  export_stmt = "export " if ARGV.length > 0 && ARGV.include?("-e")
+
+  instance_params.each { |param|
+    puts export_stmt + param
+  }
+
+end

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/modules/cartridge-agent/ec2/php/healthcheck.sh
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/cartridge-agent/ec2/php/healthcheck.sh b/products/cartridge-agent/modules/cartridge-agent/ec2/php/healthcheck.sh
new file mode 100644
index 0000000..04a96d1
--- /dev/null
+++ b/products/cartridge-agent/modules/cartridge-agent/ec2/php/healthcheck.sh
@@ -0,0 +1,33 @@
+#!/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.
+#
+# --------------------------------------------------------------
+
+
+var=`nc -z localhost 80; echo $?`;
+if [ $var -eq 0 ]
+then
+    echo "port 80 is available" > /dev/null 2>&1
+else
+    echo "port 80 is not available" > /dev/null 2>&1
+    /etc/init.d/apache2 restart
+fi
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/pom.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/pom.xml b/products/cartridge-agent/pom.xml
index c746182..a83e310 100644
--- a/products/cartridge-agent/pom.xml
+++ b/products/cartridge-agent/pom.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="ISO-8859-1"?>
 <!--
   ~ Licensed to the Apache Software Foundation (ASF) under one
   ~ or more contributor license agreements.  See the NOTICE file
@@ -17,97 +17,24 @@
   ~ specific language governing permissions and limitations
   ~ under the License.
   -->
-
 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
     <parent>
-        <artifactId>stratos-products-parent</artifactId>
         <groupId>org.apache.stratos</groupId>
+        <artifactId>stratos-products-parent</artifactId>
         <version>4.0.0-SNAPSHOT</version>
     </parent>
-    <modelVersion>4.0.0</modelVersion>
 
-    <artifactId>apache-stratos-cartridge-agent</artifactId>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>catridge-agent</artifactId>
+    <packaging>pom</packaging>
     <name>Apache Stratos - Cartridge Agent</name>
+    <url>http://apache.org</url>
 
-    <repositories>
-        <repository>
-            <id>wso2-nexus</id>
-            <name>WSO2 internal Repository</name>
-            <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
-            <releases>
-                <enabled>true</enabled>
-                <updatePolicy>daily</updatePolicy>
-                <checksumPolicy>ignore</checksumPolicy>
-            </releases>
-        </repository>
-    </repositories>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.wso2.andes.wso2</groupId>
-            <artifactId>andes-client</artifactId>
-            <version>0.13.wso2v8</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.geronimo.specs.wso2</groupId>
-            <artifactId>geronimo-jms_1.1_spec</artifactId>
-            <version>1.1.0.wso2v1</version>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-log4j12</artifactId>
-            <version>1.7.5</version>
-        </dependency>
-        <dependency>
-            <groupId>com.google.code.gson</groupId>
-            <artifactId>gson</artifactId>
-            <version>2.2.4</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.stratos</groupId>
-            <artifactId>org.apache.stratos.messaging</artifactId>
-            <version>4.0.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>2.0</version>
-        </dependency>
-    </dependencies>
+    <modules>
+        <module>modules/cartridge-agent-event-publisher</module>
+    </modules>
+</project>
 
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-jar-plugin</artifactId>
-                <version>2.4</version>
-                <configuration>
-                    <archive>
-                        <manifest>
-                            <mainClass>org.apache.stratos.cartridge.agent.Main</mainClass>
-                        </manifest>
-                    </archive>
-                </configuration>
-            </plugin>
-            <plugin>
-            <artifactId>maven-assembly-plugin</artifactId>
-            <version>2.2.1</version>
-            <configuration>
-                <descriptors>
-                    <descriptor>src/main/assembly/assembly.xml</descriptor>
-                </descriptors>
-            </configuration>
-                <executions>
-                    <execution>
-                        <phase>package</phase>
-                        <goals>
-                            <goal>single</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/src/main/assembly/assembly.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/src/main/assembly/assembly.xml b/products/cartridge-agent/src/main/assembly/assembly.xml
deleted file mode 100644
index f77e6be..0000000
--- a/products/cartridge-agent/src/main/assembly/assembly.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<!--
-  ~ 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.
-  -->
-
-<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
-          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
-    <id>bin</id>
-    <formats>
-        <format>zip</format>
-    </formats>
-    <fileSets>
-        <fileSet>
-            <directory>${project.basedir}/src/main/bin</directory>
-            <outputDirectory>/bin</outputDirectory>
-            <includes>
-                <include>cartridge-agent.sh</include>
-                <include>get-launch-params.rb</include>
-                <include>user-data.json.template</include>
-            </includes>
-        </fileSet>
-        <fileSet>
-            <directory>${project.basedir}</directory>
-            <outputDirectory>/</outputDirectory>
-            <includes>
-                <include>README*</include>
-                <include>LICENSE*</include>
-                <include>NOTICE*</include>
-            </includes>
-        </fileSet>
-    </fileSets>
-    <dependencySets>
-        <dependencySet>
-            <outputDirectory>/lib</outputDirectory>
-            <useProjectArtifact>true</useProjectArtifact>
-            <scope>runtime</scope>
-        </dependencySet>
-    </dependencySets>
-</assembly>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/src/main/bin/cartridge-agent.sh
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/src/main/bin/cartridge-agent.sh b/products/cartridge-agent/src/main/bin/cartridge-agent.sh
deleted file mode 100755
index 73a6aae..0000000
--- a/products/cartridge-agent/src/main/bin/cartridge-agent.sh
+++ /dev/null
@@ -1,83 +0,0 @@
-#!/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.
-#
-
-set -e
-log_path=/var/log/apache-stratos
-export LOG=$log_path/cartridge-agent-sh.log
-instance_path=/opt
-
-if [ ! -d $log_path ]; then
-    mkdir -p $log_path
-fi
-
-echo "Starting cartridge-agent.sh..." | tee -a $LOG
-
-if [ ! -d ${instance_path}/payload ]; then
-    echo "creating payload dir... " | tee -a $LOG
-    mkdir ${instance_path}/payload
-    echo "payload directory created " | tee -a $LOG
-fi
-
-# Fetch user data from payload
-wget http://169.254.169.254/latest/user-data -O ${instance_path}/payload/user-data.txt
-echo "user-data.txt received"  | tee -a $LOG
-
-for i in `/usr/bin/ruby get-launch-params.rb`
-do
-    echo "writing user-data parameter $i to user-data.params" | tee -a $LOG
-    value=`echo "${i}" | sed -e s@=@=\"@g`
-    value=$value"\""
-    echo "export" $value >> user-data.params
-done
-source user-data.params
-echo "user-data.params exported" | tee -a $LOG
-
-echo "Generating user-data.json..." | tee -a $LOG
-# Replace port separator '|' with ','
-PORTS=`echo $PORTS | sed -e s@'|'@,@g`
-
-cp -f user-data.json.template user-data.json.tmp
-cat user-data.json.tmp | sed -e "s@SERVICE_NAME@$SERVICE_NAME@g" > user-data.json
-cp -f user-data.json user-data.json.tmp
-cat user-data.json.tmp | sed -e "s@CLUSTER_ID@$CLUSTER_ID@g" > user-data.json
-cp -f user-data.json user-data.json.tmp
-cat user-data.json.tmp | sed -e "s@MEMBER_ID@$MEMBER_ID@g" > user-data.json
-cp -f user-data.json user-data.json.tmp
-cat user-data.json.tmp | sed -e "s@HOST_IP_ADDRESS@$IP_ADDRESS@g" > user-data.json
-cp -f user-data.json user-data.json.tmp
-cat user-data.json.tmp | sed -e "s@PORT_LIST@$PORTS@g" > user-data.json
-cp -f user-data.json user-data.json.tmp
-cat user-data.json.tmp | sed -e "s@MB_IP_ADDRESS@$MB_IP@g" > user-data.json
-cp -f user-data.json user-data.json.tmp
-cat user-data.json.tmp | sed -e "s@MB_PORT@$MB_PORT@g" > user-data.json
-
-echo "user-data.json generated" | tee -a $LOG
-
-echo "Starting Cartridge Agent..." | tee -a $LOG
-lib_path=./../lib/
-class_path=${lib_path}commons-io-2.0.jar:${lib_path}andes-client-0.13.wso2v8.jar:${lib_path}apache-stratos-cartridge-agent-4.0.0-SNAPSHOT.jar:${lib_path}commons-codec-1.8.jar:${lib_path}commons-logging-1.1.1.jar:${lib_path}geronimo-jms_1.1_spec-1.1.0.wso2v1.jar:${lib_path}geronimo-jms_1.1_spec-1.1.jar:${lib_path}gson-2.2.4.jar:${lib_path}log4j-1.2.13.jar:${lib_path}org.apache.log4j-1.2.13.v200706111418.jar:${lib_path}org.apache.stratos.messaging-4.0.0-SNAPSHOT.jar:${lib_path}org.wso2.carbon.logging-4.1.0.jar:${lib_path}slf4j-api-1.7.5.jar:${lib_path}slf4j-log4j12-1.7.5.jar
-
-json_path=`pwd`/user-data.json
-java -cp $class_path org.apache.stratos.cartridge.agent.Main $json_path
-echo "Cartridge Agent started" | tee -a $LOG
-
-#TODO 1. Configure required server components
-#TODO 2. Download application artifacts
-#TODO 3. Deploy application artifacts
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/src/main/bin/get-launch-params.rb
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/src/main/bin/get-launch-params.rb b/products/cartridge-agent/src/main/bin/get-launch-params.rb
deleted file mode 100644
index d1767cb..0000000
--- a/products/cartridge-agent/src/main/bin/get-launch-params.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-#! /usr/bin/ruby
-# ----------------------------------------------------------------------------
-# 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.
-# ----------------------------------------------------------------------------
-
-### get-launch-params.rb
-
-# The following script obtains the launch parameters from 
-# the file /tmp/payload/launch-params, then parses out the 
-# parameters for this instance by using the launch index
-# of this particular EC2 instance.
-#
-# Pass the command the -e flag to output the instance 
-# parameters as exports of shell variables. Any other 
-# arguments are ignored.
-
-def get_launch_params(launch_params_file)
-  IO.readlines launch_params_file
-end
-
-export_stmt = ""
-
-launch_params = get_launch_params(
-  "/opt/payload/user-data.txt")
-
-if launch_params.length > 0
-  instance_params_str = launch_params[0]
-
-  instance_params = instance_params_str.split(',')
-
-  export_stmt = "export " if ARGV.length > 0 && ARGV.include?("-e")
-
-  instance_params.each { |param|
-    puts export_stmt + param
-  }
-end
-

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/src/main/bin/user-data.json.template
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/src/main/bin/user-data.json.template b/products/cartridge-agent/src/main/bin/user-data.json.template
deleted file mode 100644
index 712c2a6..0000000
--- a/products/cartridge-agent/src/main/bin/user-data.json.template
+++ /dev/null
@@ -1 +0,0 @@
-{"serviceName":"SERVICE_NAME","clusterId":"CLUSTER_ID","memberId":"MEMBER_ID","ipAddress":"HOST_IP_ADDRESS","ports":[PORT_LIST],"mbIpAddress":"MB_IP_ADDRESS","mbPort":MB_PORT}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java b/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java
deleted file mode 100644
index 047dd92..0000000
--- a/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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;
-
-import com.google.gson.Gson;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.event.Event;
-import org.apache.stratos.messaging.event.instance.status.MemberActivatedEvent;
-import org.apache.stratos.messaging.event.instance.status.MemberStartedEvent;
-
-import javax.jms.JMSException;
-import javax.naming.NamingException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.SocketAddress;
-
-/**
- * Cartridge agent lifecycle implementation.
- */
-public class CartridgeAgent implements Runnable {
-    private static final Log log = LogFactory.getLog(CartridgeAgent.class);
-
-    private UserData userData;
-
-    public CartridgeAgent(String userDataFilePath) {
-        this.userData = extractUserData(userDataFilePath);
-    }
-
-    private UserData extractUserData(String userDataFilePath) {
-        FileInputStream fileInputStream = null;
-        try {
-            fileInputStream = new FileInputStream(new File(userDataFilePath));
-        } catch (FileNotFoundException e) {
-            throw new RuntimeException("Could not find user data file");
-        }
-
-        try {
-            String json = IOUtils.toString(fileInputStream, "UTF-8");
-            if(log.isDebugEnabled()){
-                log.debug(String.format("User data json: %s", json));
-            }
-            return new Gson().fromJson(json, UserData.class);
-        } catch (IOException e) {
-            if(log.isErrorEnabled()) {
-                log.error(e);
-            }
-        }
-        throw new RuntimeException("Could not read user data file");
-    }
-
-    @Override
-    public void run() {
-        try {
-            if (log.isInfoEnabled()) {
-                log.info("\nCartridge agent started");
-            }
-            publishMemberStartedEvent(userData);
-
-            // Wait for the application to become active
-            while (!isApplicationActive(userData)) {
-                Thread.sleep(1000);
-            }
-
-            publishMemberActivatedEvent(userData);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    private boolean isApplicationActive(UserData userData) {
-        try {
-            for(int port : userData.getPorts()) {
-                if (log.isInfoEnabled()) {
-                    log.info(String.format("Trying to connect to application socket: %s %d", userData.getIpAddress(), port));
-                }
-
-                SocketAddress httpSockaddr = new InetSocketAddress(userData.getIpAddress(), port);
-                Socket socket = new Socket();
-                socket.connect(httpSockaddr, 1000);
-
-                if (log.isInfoEnabled()) {
-                    log.info(String.format("Successfully connected to socket: %s %d", userData.getIpAddress(), port));
-                }
-            }
-            if (log.isInfoEnabled()) {
-                log.info("Application is active");
-            }
-            return true;
-        } catch (IOException e) {
-        }
-        if (log.isInfoEnabled()) {
-            log.info("All sockets are still not active");
-        }
-        return false;
-    }
-
-    private void publishMemberStartedEvent(UserData userData) throws JMSException, NamingException, IOException, InterruptedException {
-        MemberStartedEvent event = new MemberStartedEvent();
-        event.setServiceName(userData.getServiceName());
-        event.setClusterId(userData.getClusterId());
-        event.setMemberId(userData.getMemberId());
-        publishEvent(event);
-    }
-
-    private void publishMemberActivatedEvent(UserData userData) throws JMSException, NamingException, IOException, InterruptedException {
-        MemberActivatedEvent event = new MemberActivatedEvent();
-        event.setServiceName(userData.getServiceName());
-        event.setClusterId(userData.getClusterId());
-        event.setMemberId(userData.getMemberId());
-        publishEvent(event);
-    }
-
-    private void publishEvent(Event event) throws JMSException, NamingException, IOException, InterruptedException {
-        EventPublisher publisher = new EventPublisher(userData.getMbIpAddress(), userData.getMbPort(), org.apache.stratos.messaging.util.Constants.INSTANCE_STATUS_TOPIC);
-        try {
-            publisher.connect();
-            publisher.publish(event);
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            publisher.close();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/EventPublisher.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/EventPublisher.java b/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/EventPublisher.java
deleted file mode 100644
index c09b7c7..0000000
--- a/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/EventPublisher.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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;
-
-import com.google.gson.Gson;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.event.Event;
-import org.apache.stratos.messaging.util.Constants;
-
-import javax.jms.*;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Properties;
-
-/**
- * A generic topic publisher.
- */
-public class EventPublisher {
-    private static final Log log = LogFactory.getLog(EventPublisher.class);
-
-    private TopicConnection topicConnection;
-    private TopicSession topicSession;
-    private Topic topic;
-    private String mbIpAddress;
-    private int mbPort;
-    private String topicName;
-
-    public EventPublisher(String mbIpAddress, int mbPort, String topicName) {
-        this.mbIpAddress = mbIpAddress;
-        this.mbPort = mbPort;
-        this.topicName = topicName;
-    }
-
-    private Properties getProperties() throws IOException {
-        Properties properties = new Properties();
-        properties.load(EventPublisher.class.getClassLoader().getResourceAsStream("jndi.properties"));
-
-        // Set message broker ip and port
-        String connectionFactoryName = properties.get("connectionfactoryName").toString();
-        String key = "connectionfactory." + connectionFactoryName;
-        String connectionFactoryStr = (String) properties.get(key);
-        connectionFactoryStr = connectionFactoryStr.replace("MB-IP-ADDRESS", mbIpAddress);
-        connectionFactoryStr = connectionFactoryStr.replace("MB-PORT", String.valueOf(mbPort));
-        properties.setProperty(key, connectionFactoryStr);
-
-        return properties;
-    }
-
-    public void connect() throws NamingException, JMSException, IOException {
-        // Prepare JNDI properties
-        Properties properties = getProperties();
-        InitialContext ctx = new InitialContext(properties);
-
-        // Lookup connection factory
-        String connectionFactoryName = properties.get("connectionfactoryName").toString();
-        TopicConnectionFactory connectionFactory = (TopicConnectionFactory) ctx.lookup(connectionFactoryName);
-        topicConnection = connectionFactory.createTopicConnection();
-        topicConnection.start();
-        topicSession = topicConnection.createTopicSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-
-        // Create topic
-        topic = topicSession.createTopic(topicName);
-    }
-
-    public void publish(Event event) throws NamingException, JMSException, IOException {
-        Gson gson = new Gson();
-        String json = gson.toJson(event);
-        publish(json, event.getClass().getName());
-    }
-
-    private void publish(String message, String eventClassName) throws NamingException, JMSException, IOException {
-            TextMessage textMessage = topicSession.createTextMessage((String) message);
-            textMessage.setStringProperty(Constants.EVENT_CLASS_NAME, eventClassName);
-            javax.jms.TopicPublisher topicPublisher = topicSession.createPublisher(topic);
-            topicPublisher.publish(textMessage);
-
-        if(log.isDebugEnabled()) {
-            log.debug(String.format("Message published: [topic] %s [header] %s [body] %s", topicName, eventClassName, message));
-        }
-    }
-
-    public void close() throws JMSException {
-        // Clean up resources
-        if (topicSession != null)
-            topicSession.close();
-        if (topicConnection != null)
-            topicConnection.close();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/Main.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/Main.java b/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/Main.java
deleted file mode 100644
index 2236885..0000000
--- a/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/Main.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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;
-
-import com.google.gson.Gson;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Cartridge agent main class.
- */
-public class Main {
-    private static final Log log = LogFactory.getLog(Main.class);
-
-    public static void main(String[] args) {
-        try {
-            if ((args != null) && (args.length == 1)) {
-                Runnable runnable = new CartridgeAgent(args[0]);
-                Thread thread = new Thread(runnable);
-                thread.start();
-            } else {
-                printInvalidArgs();
-            }
-        } catch (Exception e) {
-            printInvalidArgs();
-        }
-    }
-
-    private static void printInvalidArgs() {
-        if (log.isErrorEnabled()) {
-            log.error("Arguments are not valid. Cartridge agent could not be started.");
-            log.error("Expected: user-data-file-path");
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/UserData.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/UserData.java b/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/UserData.java
deleted file mode 100644
index dc2e00b..0000000
--- a/products/cartridge-agent/src/main/java/org/apache/stratos/cartridge/agent/UserData.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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;
-
-import java.util.List;
-
-/**
- * User data definition.
- */
-public class UserData {
-    private String serviceName;
-    private String clusterId;
-    private String memberId;
-    private String ipAddress;
-    private List<Integer> ports;
-    private String mbIpAddress;
-    private int mbPort;
-
-    public String getServiceName() {
-        return serviceName;
-    }
-
-    public void setServiceName(String serviceName) {
-        this.serviceName = serviceName;
-    }
-
-    public String getClusterId() {
-        return clusterId;
-    }
-
-    public void setClusterId(String clusterId) {
-        this.clusterId = clusterId;
-    }
-
-    public String getMemberId() {
-        return memberId;
-    }
-
-    public void setMemberId(String memberId) {
-        this.memberId = memberId;
-    }
-
-    public String getIpAddress() {
-        return ipAddress;
-    }
-
-    public void setIpAddress(String ipAddress) {
-        this.ipAddress = ipAddress;
-    }
-
-    public List<Integer> getPorts() {
-        return ports;
-    }
-
-    public void setPorts(List<Integer> ports) {
-        this.ports = ports;
-    }
-
-    public String getMbIpAddress() {
-        return mbIpAddress;
-    }
-
-    public void setMbIpAddress(String mbIpAddress) {
-        this.mbIpAddress = mbIpAddress;
-    }
-
-    public int getMbPort() {
-        return mbPort;
-    }
-
-    public void setMbPort(int mbPort) {
-        this.mbPort = mbPort;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/src/main/resources/jndi.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/src/main/resources/jndi.properties b/products/cartridge-agent/src/main/resources/jndi.properties
deleted file mode 100644
index d3b29bc..0000000
--- a/products/cartridge-agent/src/main/resources/jndi.properties
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# 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.
-#
-
-connectionfactoryName=topicConnectionfactory
-connectionfactory.topicConnectionfactory=amqp://admin:admin@carbon/carbon?brokerlist='tcp://MB-IP-ADDRESS:MB-PORT'
-java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c2cbf4dc/products/cartridge-agent/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/src/main/resources/log4j.properties b/products/cartridge-agent/src/main/resources/log4j.properties
deleted file mode 100644
index be7cf20..0000000
--- a/products/cartridge-agent/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,37 +0,0 @@
-#
-# 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.
-#
-
-# Set root logger level and appenders
-log4j.rootLogger=INFO, CONSOLE_APPENDER, FILE_APPENDER
-
-# CONSOLE_APPENDER is set to be a ConsoleAppender.
-log4j.appender.CONSOLE_APPENDER=org.apache.log4j.ConsoleAppender
-
-# The standard error log where all the warnings, errors and fatal errors will be logged
-log4j.appender.FILE_APPENDER=org.apache.log4j.FileAppender
-log4j.appender.FILE_APPENDER.File=/var/log/apache-stratos/cartridge-agent.log
-log4j.appender.FILE_APPENDER.layout=org.apache.log4j.PatternLayout
-log4j.appender.FILE_APPENDER.layout.ConversionPattern=%d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n
-log4j.appender.FILE_APPENDER.threshold=DEBUG
-
-# CONSOLE_APPENDER uses PatternLayout.
-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.cartridge.agent=DEBUG
\ No newline at end of file


[2/2] git commit: Merge remote-tracking branch 'origin/master'

Posted by im...@apache.org.
Merge remote-tracking branch 'origin/master'


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

Branch: refs/heads/master
Commit: 8351106f1b34c7306cff6c04325506c10f4a5673
Parents: c2cbf4d 6d25133
Author: Imesh Gunaratne <im...@apache.org>
Authored: Mon Oct 28 13:55:52 2013 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Mon Oct 28 13:55:52 2013 +0530

----------------------------------------------------------------------
 .../cloud/controller/iaases/AWSEC2Iaas.java     | 17 ++++------
 .../controller/iaases/OpenstackNovaIaas.java    | 19 +++++------
 .../impl/CloudControllerServiceImpl.java        | 30 ++---------------
 .../util/CloudControllerConstants.java          |  7 ++--
 .../cloud/controller/util/ServiceContext.java   | 35 +++++++++++++-------
 5 files changed, 43 insertions(+), 65 deletions(-)
----------------------------------------------------------------------