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/12/20 05:09:51 UTC
[2/4] Refactoring cartridge agent product to package new standalone
cartridge agent component
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-publisher/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-publisher/src/main/resources/log4j.properties b/products/cartridge-agent/modules/event-publisher/src/main/resources/log4j.properties
deleted file mode 100644
index 4c4e610..0000000
--- a/products/cartridge-agent/modules/event-publisher/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-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/2f3d9021/products/cartridge-agent/modules/event-publisher/src/main/templates/member-activated-event.json.template
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-publisher/src/main/templates/member-activated-event.json.template b/products/cartridge-agent/modules/event-publisher/src/main/templates/member-activated-event.json.template
deleted file mode 100644
index e2b2371..0000000
--- a/products/cartridge-agent/modules/event-publisher/src/main/templates/member-activated-event.json.template
+++ /dev/null
@@ -1 +0,0 @@
-{"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/2f3d9021/products/cartridge-agent/modules/event-publisher/src/main/templates/member-started-event.json.template
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-publisher/src/main/templates/member-started-event.json.template b/products/cartridge-agent/modules/event-publisher/src/main/templates/member-started-event.json.template
deleted file mode 100644
index e2b2371..0000000
--- a/products/cartridge-agent/modules/event-publisher/src/main/templates/member-started-event.json.template
+++ /dev/null
@@ -1 +0,0 @@
-{"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/2f3d9021/products/cartridge-agent/modules/event-subscriber/pom.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/pom.xml b/products/cartridge-agent/modules/event-subscriber/pom.xml
deleted file mode 100644
index 0093976..0000000
--- a/products/cartridge-agent/modules/event-subscriber/pom.xml
+++ /dev/null
@@ -1,125 +0,0 @@
-<?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/maven-v4_0_0.xsd">
-
- <parent>
- <groupId>org.apache.stratos</groupId>
- <artifactId>cartidge-agent</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>apache-stratos-event-subscriber</artifactId>
- <name>Apache Stratos - Event Subscriber</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>
- <dependency>
- <groupId>org.apache.stratos</groupId>
- <artifactId>org.apache.stratos.deployment.synchronizer</artifactId>
- <version>4.0.0-SNAPSHOT</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.subscriber.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>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/assembly/bin.xml b/products/cartridge-agent/modules/event-subscriber/src/main/assembly/bin.xml
deleted file mode 100644
index 9552ad8..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/assembly/bin.xml
+++ /dev/null
@@ -1,71 +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>
- <fileMode>0755</fileMode>
- <includes>
- <include>event-subscriber.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>
- <fileSet>
- <directory>${project.basedir}/src/main/resources</directory>
- <outputDirectory>/conf</outputDirectory>
- <fileMode>0600</fileMode>
- <includes>
- <include>jndi.properties</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/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/bin/event-subscriber.sh
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/bin/event-subscriber.sh b/products/cartridge-agent/modules/event-subscriber/src/main/bin/event-subscriber.sh
deleted file mode 100644
index 6c05fbc..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/bin/event-subscriber.sh
+++ /dev/null
@@ -1,28 +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.
-#
-# --------------------------------------------------------------
-
-echo "Starting event subscriber..."
-lib_path=./../lib/
-class_path=`echo ${lib_path}/*.jar | tr ' ' ':'`
-
-java -cp "${class_path}" org.apache.stratos.cartridge.agent.event.subscriber.Main ../conf /opt/apache-stratos-cartridge-agent/payload/launch-params
-echo "Event subscriber completed"
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/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
deleted file mode 100644
index 9c772e3..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/ArtifactListener.java
+++ /dev/null
@@ -1,121 +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.event.subscriber;
-
-import javax.crypto.Cipher;
-import javax.crypto.SecretKey;
-import javax.crypto.spec.SecretKeySpec;
-import javax.jms.Message;
-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;
-import org.apache.stratos.deployment.synchronizer.git.impl.GitBasedArtifactRepository;
-import org.apache.stratos.messaging.broker.publish.EventPublisher;
-import org.apache.stratos.messaging.event.artifact.synchronization.ArtifactUpdatedEvent;
-import org.apache.stratos.messaging.event.instance.status.InstanceActivatedEvent;
-import org.apache.stratos.messaging.util.Constants;
-import org.apache.stratos.messaging.util.Util;
-
-
-public class ArtifactListener implements MessageListener{
-
- private static final Log log = LogFactory.getLog(ArtifactListener.class);
-
- @Override
- public void onMessage(Message message) {
-
- // If cluster id of the node is equal to that of message's, invoke the script
- TextMessage receivedMessage = (TextMessage) message;
- log.info(" Message received on artifact update ");
- String json = null;
- try {
- json = receivedMessage.getText();
- } catch (Exception e) {
- log.error("Exception is occurred " + e.getMessage(), e);
- }
-
- ArtifactUpdatedEvent event = (ArtifactUpdatedEvent) Util.jsonToObject(json, ArtifactUpdatedEvent.class);
- String clusterIdInPayload = LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.CLUSTER_ID);
- String localRepoPath = LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.APP_PATH);
- String clusterIdInMessage = event.getClusterId();
- String repoURL = event.getRepoURL();
- String repoPassword = decryptPassword(event.getRepoPassword());
- String repoUsername = event.getRepoUserName();
- String tenantId = event.getTenantId();
-
- log.info("cluster id in payload " + clusterIdInPayload);
- log.info("cluster id in message " + 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);
- repoInformation.setRepoUrl(repoURL);
- repoInformation.setRepoPath(localRepoPath);
- repoInformation.setTenantId(tenantId);
- boolean cloneExists = GitBasedArtifactRepository.cloneExists(repoInformation);
- GitBasedArtifactRepository.checkout(repoInformation);
- if(!cloneExists){
- // send member activated event
- log.info("Sending member activated event");
- // Send member activated event
- 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 publisher = new EventPublisher(Constants.INSTANCE_STATUS_TOPIC);
- publisher.publish(instanceActivatedEvent);
- log.info("Member activated event is sent");
- }
- }
-
- }
-
-
- private String decryptPassword(String repoUserPassword) {
-
- String decryptPassword = "";
- String secret = LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.CARTRIDGE_KEY);
- SecretKey key;
- Cipher cipher;
- Base64 coder;
- key = new SecretKeySpec(secret.getBytes(), "AES");
- try {
- cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE");
- coder = new Base64();
- byte[] encrypted = coder.decode(repoUserPassword.getBytes());
- cipher.init(Cipher.DECRYPT_MODE, key);
- byte[] decrypted = cipher.doFinal(encrypted);
- decryptPassword = new String(decrypted);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return decryptPassword;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/CartridgeAgentConstants.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/CartridgeAgentConstants.java b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/CartridgeAgentConstants.java
deleted file mode 100644
index 8a1e7d3..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/CartridgeAgentConstants.java
+++ /dev/null
@@ -1,41 +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.event.subscriber;
-
-import java.io.Serializable;
-
-public class CartridgeAgentConstants implements Serializable{
-
- public static final String JNDI_PROPERTIES_DIR = "jndi.properties.dir";
- public static final String PARAM_FILE_PATH = "param.file.path";
-
- public static final String CARTRIDGE_KEY = "CARTRIDGE_KEY";
- public static final String APP_PATH = "APP_PATH";
- public static final String SERVICE_NAME = "SERVICE_NAME";
- public static final String CLUSTER_ID = "CLUSTER_ID";
- public static final String NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID";
- public static final String PARTITION_ID = "PARTITION_ID";
- public static final String MEMBER_ID = "MEMBER_ID";
- public static final String PORTS = "PORTS";
- public static final String CEP_PORT = "CEP_PORT";
- public static final String CEP_IP = "CEP_IP";
- public static final String MB_PORT = "MB_PORT";
- public static final String MB_IP = "MB_IP";
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/EventSubscriber.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/EventSubscriber.java b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/EventSubscriber.java
deleted file mode 100644
index bef15e5..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/EventSubscriber.java
+++ /dev/null
@@ -1,108 +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.event.subscriber;
-
-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 EventSubscriber {
- private static final Log log = LogFactory.getLog(EventSubscriber.class);
-
- private TopicConnection topicConnection;
- private TopicSession topicSession;
- private Topic topic;
- private String mbIpAddress;
- private int mbPort;
- private String topicName;
-
- public EventSubscriber(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(EventSubscriber.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/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/EventSubscriberClient.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/EventSubscriberClient.java b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/EventSubscriberClient.java
deleted file mode 100644
index 6ee1794..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/EventSubscriberClient.java
+++ /dev/null
@@ -1,103 +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.event.subscriber;
-
-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 EventSubscriberClient {
- private static final Log log = LogFactory.getLog(EventSubscriberClient.class);
-
- private String mbIpAddress;
- private int mbPort;
- private String eventClassName;
- private String jsonFilePath;
-
- public EventSubscriberClient(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 {
- EventSubscriber publisher = new EventSubscriber(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/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/LaunchParamsUtil.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/LaunchParamsUtil.java b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/LaunchParamsUtil.java
deleted file mode 100644
index 164116d..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/LaunchParamsUtil.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.event.subscriber;
-
-import java.io.File;
-import java.util.Scanner;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class LaunchParamsUtil {
-
- private static final Log log = LogFactory.getLog(LaunchParamsUtil.class);
-
- public static String readParamValueFromPayload(String param) {
- String paramValue = null;
- // read launch params
- File file = new File(System.getProperty(CartridgeAgentConstants.PARAM_FILE_PATH));
-
- try {
- Scanner scanner = new Scanner(file);
-
- while (scanner.hasNextLine()) {
- String line = scanner.nextLine();
- String[] params = line.split(",");
- for (String string : params) {
- String[] var = string.split("=");
- if(param.equals(var[0])){
- paramValue = var[1];
- }
- }
- }
- scanner.close();
- } catch (Exception e) {
- //e.printStackTrace();
- log.error("Exception is occurred in reading file. ", e);
- }
-
- return paramValue;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/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
deleted file mode 100644
index fdcd1c2..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/Main.java
+++ /dev/null
@@ -1,211 +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.event.subscriber;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.commons.lang3.StringUtils;
-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;
-
-/**
- * Event publisher main class.
- */
-public class Main {
-
- private static final Log log = LogFactory.getLog(Main.class);
-
- public static void main(String[] args) {
-
- log.info("Strating cartridge agent event subscriber");
-
- System.setProperty(CartridgeAgentConstants.JNDI_PROPERTIES_DIR, args[0]);
- System.setProperty(CartridgeAgentConstants.PARAM_FILE_PATH, args[1]);
-
- //initialting the subscriber
- TopicSubscriber subscriber = new TopicSubscriber(Constants.ARTIFACT_SYNCHRONIZATION_TOPIC);
- subscriber.setMessageListener(new ArtifactListener());
- Thread tsubscriber = new Thread(subscriber);
- tsubscriber.start();
-
- //
- try {
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- log.info("Publishing instance started event");
- // Send member activated event
- InstanceStartedEvent event = new InstanceStartedEvent(
- 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 publisher = new EventPublisher(Constants.INSTANCE_STATUS_TOPIC);
- publisher.publish(event);
- log.info("Instance started event is published");
-
- String repoURL = LaunchParamsUtil
- .readParamValueFromPayload("GIT_REPO");
-
-
- log.info("waiting for all ports to be active");
- waitForPortsTobeActive();
- log.info("All ports active");
-
- if ("null".equals(repoURL) || repoURL == null) {
- log.info("No git repo found 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 activated event published");
- }
-
- // Start periodical file checker task
- // TODO -- start this thread only if this node configured as a commit true node
- ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
- scheduler.scheduleWithFixedDelay(new RepositoryFileListener(), 0, 10, TimeUnit.SECONDS);
-
- // Invoke Health publisher
- //pushd $health_publisher_path/bin
- //echo "Executing: health-publisher.sh"
- //sh health-publisher.sh $MEMBER_ID $CEP_IP $CEP_PORT $PORTS $CLUSTER_ID
- //echo "Health stat published" | tee -a $LOG
- //popd
-
- // /opt/apache-stratos-cartridge-agent/health-publisher/bin/health-publisher.sh
-
- log.info("Executing health publisher ..");
- Process proc;
- try {
-
- String command =
- "/opt/apache-stratos-cartridge-agent/health-publisher/bin/health-publisher.sh "+
- LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.MEMBER_ID) + " " +
- LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.CEP_IP) + " " +
- LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.CEP_PORT) + " " +
- getPorts(LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.PORTS)) + " " +
- LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.NETWORK_PARTITION_ID) + " " +
- LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.PARTITION_ID) + " " +
- " /";
- proc = Runtime.getRuntime().exec(command);
- log.info("executing health publisher command.. :" + command);
- proc.waitFor();
- log.info("Health publisher executed");
- }catch (Exception e) {
- log.error(" Exception occurred in executing health publisher", e);
- }
-
-
- }
-
- /*
- * Return ports split by comma
- */
- private static String getPorts(String readParamValueFromPayload) {
- String portString = readParamValueFromPayload.trim();
- return portString.replace("|", ",");
- }
-
- private static void waitForPortsTobeActive() {
- long portCheckTimeOut = 1000 * 60 * 10;
- String portCheckTimeOutStr = System.getProperty("port.check.timeout");
- if (StringUtils.isNotBlank(portCheckTimeOutStr)) {
- portCheckTimeOut = Integer.parseInt(portCheckTimeOutStr);
- }
- if (log.isInfoEnabled()) {
- log.info("Port check timeout: " + portCheckTimeOut);
- }
-
- String ports = LaunchParamsUtil.readParamValueFromPayload(CartridgeAgentConstants.PORTS);
- if (StringUtils.isBlank(ports)) {
- throw new RuntimeException("No ports found");
- }
- ports = ports.replace("|", ",");
- String[] portsArray = ports.split(",");
-
- long startTime = System.currentTimeMillis();
- boolean active = false;
- while (!active) {
- for (String port : portsArray) {
- Socket socket = null;
- try {
- if (log.isInfoEnabled()) {
- log.info("Checking port " + port);
- }
- SocketAddress httpSockaddr = new InetSocketAddress("localhost", Integer.parseInt(port));
- socket = new Socket();
- socket.connect(httpSockaddr, 5000);
- active = true;
- if (log.isInfoEnabled()) {
- log.info(String.format("Port %s is active", port));
- }
- } catch (Exception e) {
- active = false;
- if (log.isInfoEnabled()) {
- log.info(String.format("Port %s is not active", port));
- }
- break;
- } finally {
- if (socket != null) {
- try {
- socket.close();
- } catch (IOException e) {
- }
- }
- }
- }
- long endTime = System.currentTimeMillis();
- long duration = endTime - startTime;
- if (duration > portCheckTimeOut) {
- return;
- }
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/RepositoryFileListener.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/RepositoryFileListener.java b/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/RepositoryFileListener.java
deleted file mode 100644
index 6068630..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/java/org/apache/stratos/cartridge/agent/event/subscriber/RepositoryFileListener.java
+++ /dev/null
@@ -1,38 +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.event.subscriber;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.deployment.synchronizer.git.impl.GitBasedArtifactRepository;
-
-public class RepositoryFileListener implements Runnable {
-
- private static final Log log = LogFactory.getLog(RepositoryFileListener.class);
-
- @Override
- public void run() {
-
- log.info(" Executing file listener ");
- boolean commitStatus = GitBasedArtifactRepository.commit();
- log.info(" Commit status : " + commitStatus);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/resources/jndi.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/resources/jndi.properties b/products/cartridge-agent/modules/event-subscriber/src/main/resources/jndi.properties
deleted file mode 100644
index c928585..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/resources/jndi.properties
+++ /dev/null
@@ -1,23 +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
-java.naming.provider.url=repository/conf/jndi.properties
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/resources/log4j.properties b/products/cartridge-agent/modules/event-subscriber/src/main/resources/log4j.properties
deleted file mode 100644
index 9b416b5..0000000
--- a/products/cartridge-agent/modules/event-subscriber/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-event-subscriber.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.subscriber=DEBUG
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/templates/member-activated-event.json.template
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/templates/member-activated-event.json.template b/products/cartridge-agent/modules/event-subscriber/src/main/templates/member-activated-event.json.template
deleted file mode 100644
index e2b2371..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/templates/member-activated-event.json.template
+++ /dev/null
@@ -1 +0,0 @@
-{"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/2f3d9021/products/cartridge-agent/modules/event-subscriber/src/main/templates/member-started-event.json.template
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/event-subscriber/src/main/templates/member-started-event.json.template b/products/cartridge-agent/modules/event-subscriber/src/main/templates/member-started-event.json.template
deleted file mode 100644
index e2b2371..0000000
--- a/products/cartridge-agent/modules/event-subscriber/src/main/templates/member-started-event.json.template
+++ /dev/null
@@ -1 +0,0 @@
-{"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/2f3d9021/products/cartridge-agent/modules/health-stats/pom.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/health-stats/pom.xml b/products/cartridge-agent/modules/health-stats/pom.xml
deleted file mode 100644
index 16a8179..0000000
--- a/products/cartridge-agent/modules/health-stats/pom.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?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/maven-v4_0_0.xsd">
-
- <parent>
- <groupId>org.apache.stratos</groupId>
- <artifactId>cartidge-agent</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>apache-stratos-health-publisher</artifactId>
- <name>Apache Stratos - Health 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>
- <dependency>
- <groupId>org.apache.stratos</groupId>
- <artifactId>org.apache.stratos.messaging</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.thrift</groupId>
- <artifactId>libthrift</artifactId>
- <version>0.9.1</version>
- </dependency>
- <dependency>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>org.wso2.carbon.databridge.agent.thrift</artifactId>
- <version>4.2.0</version>
- </dependency>
- <dependency>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>org.wso2.carbon.databridge.commons.thrift</artifactId>
- <version>4.2.0</version>
- </dependency>
- <dependency>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>org.wso2.carbon.databridge.commons</artifactId>
- <version>4.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/2f3d9021/products/cartridge-agent/modules/health-stats/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/health-stats/src/main/assembly/bin.xml b/products/cartridge-agent/modules/health-stats/src/main/assembly/bin.xml
deleted file mode 100644
index 99a9dae..0000000
--- a/products/cartridge-agent/modules/health-stats/src/main/assembly/bin.xml
+++ /dev/null
@@ -1,62 +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>
- <fileMode>0755</fileMode>
- <includes>
- <include>health-publisher.sh</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${project.basedir}/src/main/security</directory>
- <outputDirectory>/security</outputDirectory>
- <fileMode>0600</fileMode>
- <includes>
- <include>client-truststore.jks</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/2f3d9021/products/cartridge-agent/modules/health-stats/src/main/bin/health-publisher.sh
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/health-stats/src/main/bin/health-publisher.sh b/products/cartridge-agent/modules/health-stats/src/main/bin/health-publisher.sh
deleted file mode 100755
index 8d3bee1..0000000
--- a/products/cartridge-agent/modules/health-stats/src/main/bin/health-publisher.sh
+++ /dev/null
@@ -1,34 +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.
-#
-# --------------------------------------------------------------
-
-echo "Starting health publisher..."
-
-script_path=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)`"`
-lib_path=${script_path}/../lib/
-
-class_path=${lib_path}andes-client-0.13.wso2v8.jar:${lib_path}ant-1.7.0.jar:${lib_path}ant-1.7.0.wso2v1.jar:${lib_path}ant-launcher-1.7.0.jar:${lib_path}apache-stratos-health-publisher-4.0.0-SNAPSHOT.jar:${lib_path}axiom-1.2.11.wso2v4.jar:${lib_path}axiom-api-1.2.11.jar:${lib_path}axiom-impl-1.2.11.jar:${lib_path}axis2-1.6.1.wso2v10.jar:${lib_path}commons-cli-1.0.jar:${lib_path}commons-codec-1.8.jar:${lib_path}commons-fileupload-1.2.0.wso2v1.jar:${lib_path}commons-fileupload-1.2.jar:${lib_path}commons-httpclient-3.1.0.wso2v2.jar:${lib_path}commons-httpclient-3.1.jar:${lib_path}commons-io-2.0.jar:${lib_path}commons-lang-1.0.jar:${lib_path}commons-lang3-3.1.jar:${lib_path}commons-logging-1.1.1.jar:${lib_path}commons-pool-1.5.0.wso2v1.jar:${lib_path}commons-pool-1.5.jar:${lib_path}dom4j-1.6.1.jar:${lib_path}geronimo-activation_1.1_spec-1.0.2.jar:${lib_path}geronimo-javamail_1.4_spec-1.6.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}geronimo-stax-api_1.0_spec-1.0.1.jar:${lib_path}gson-2.2.4.jar:${lib_path}httpclient-4.1.1-wso2v1.jar:${lib_path}httpclient-4.2.5.jar:${lib_path}httpcore-4.1.0-wso2v1.jar:${lib_path}httpcore-4.2.4.jar:${lib_path}icu4j-2.6.1.jar:${lib_path}javax.servlet-3.0.0.v201112011016.jar:${lib_path}jaxen-1.1.1.jar:${lib_path}jdom-1.0.jar:${lib_path}jline-0.9.94.jar:${lib_path}json-2.0.0.wso2v1.jar:${lib_path}junit-3.8.1.jar:${lib_path}libthrift-0.7.wso2v1.jar:${lib_path}libthrift-0.9.1.jar:${lib_path}log4j-1.2.13.jar:${lib_path}not-yet-commons-ssl-0.3.9.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.eclipse.osgi-3.8.1.v20120830-144521.jar:${lib_path}org.eclipse.osgi.services-3.3.100.v20120522-1822.jar:${lib_path}org.wso2.carbon.base-4.2.0.jar:${lib_path}org.wso2.carbon.core.common-4.2.0.jar:${lib_path}org.wso2.carbon.databridge.agent.thrift-4.2.0.jar:${lib_path}org.wso2.carbon.databridge.commons-4.2.0.jar:
${lib_path}org.wso2.carbon.databridge.commons.thrift-4.2.0.jar:${lib_path}org.wso2.carbon.logging-4.1.0.jar:${lib_path}org.wso2.carbon.queuing-4.2.0.jar:${lib_path}org.wso2.carbon.registry.api-4.2.0.jar:${lib_path}org.wso2.carbon.securevault-4.2.0.jar:${lib_path}org.wso2.carbon.user.api-4.2.0.jar:${lib_path}org.wso2.carbon.utils-4.2.0.jar:${lib_path}org.wso2.securevault-1.0.0-wso2v2.jar:${lib_path}slf4j-1.5.10.wso2v1.jar:${lib_path}slf4j-api-1.7.5.jar:${lib_path}slf4j-log4j12-1.7.5.jar:${lib_path}smack-3.0.4.wso2v1.jar:${lib_path}smackx-3.0.4.wso2v1.jar:${lib_path}wstx-asl-3.2.9.jar:${lib_path}xalan-2.6.0.jar:${lib_path}xercesImpl-2.6.2.jar:${lib_path}xml-apis-1.3.02.jar:${lib_path}xmlParserAPIs-2.6.2.jar:${lib_path}xom-1.0.jar
-
-
-java -cp $class_path -Dmember.id=$1 -Dkey.file.path=$script_path/../security/client-truststore.jks -Dthrift.receiver.ip=$2 -Dthrift.receiver.port=$3 -Dopen.ports=$4 -Dcluster.id=$5 -Dnetwork.partition.id=$6 -Dpartition.id=$7 org.apache.stratos.cartridge.agent.health.publisher.Main $*
-
-echo "Health publisher completed"
-
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/HealthPublisher.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/HealthPublisher.java b/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/HealthPublisher.java
deleted file mode 100644
index bc34bcd..0000000
--- a/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/HealthPublisher.java
+++ /dev/null
@@ -1,139 +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.health.publisher;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.databridge.agent.thrift.Agent;
-import org.wso2.carbon.databridge.agent.thrift.AsyncDataPublisher;
-import org.wso2.carbon.databridge.agent.thrift.conf.AgentConfiguration;
-import org.wso2.carbon.databridge.agent.thrift.exception.AgentException;
-import org.wso2.carbon.databridge.commons.Event;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Observable;
-import java.util.Observer;
-
-public class HealthPublisher implements Observer {
-
- private static final Log log = LogFactory.getLog(HealthPublisher.class);
- private static final String DATA_STREAM_NAME = "cartridge_agent_health_stats";
- private static final String VERSION = "1.0.0";
- private AsyncDataPublisher asyncDataPublisher;
-
- public HealthPublisher() {
- try {
- //TODO read following from a config file
- String ip = System.getProperty("thrift.receiver.ip");
- String port = System.getProperty("thrift.receiver.port");
- String keyFilePath = System.getProperty("key.file.path");
-
- AgentConfiguration agentConfiguration = new AgentConfiguration();
-
- // TODO get following from somewhere, without hard-coding.
- System.setProperty("javax.net.ssl.trustStore", keyFilePath);
- System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
-
- Agent agent = new Agent(agentConfiguration);
-
- //Using Asynchronous data publisher
- asyncDataPublisher = new AsyncDataPublisher("tcp://" + ip + ":" + port + "", "admin", "admin", agent);
- String streamDefinition = "{" +
- " 'name':'" + DATA_STREAM_NAME + "'," +
- " 'version':'" + VERSION + "'," +
- " 'nickName': 'health stats'," +
- " 'description': 'health stats'," +
- " 'metaData':[]," +
- " 'payloadData':[" +
- " {'name':'cluster_id','type':'STRING'}," +
- " {'name':'network_partition_id','type':'STRING'}," +
- " {'name':'member_id','type':'STRING'}," +
- " {'name':'partition_id','type':'STRING'}," +
- " {'name':'health_description','type':'STRING'}," +
- " {'name':'value','type':'DOUBLE'}" +
- " ]" +
- "}";
- asyncDataPublisher.addStreamDefinition(streamDefinition, DATA_STREAM_NAME, VERSION);
-
- } catch (NullPointerException e) {
- if (log.isErrorEnabled()) {
- log.error("Get null values", e);
- }
- }
- }
-
- public void update(Observable arg0, Object arg1) {
- if (arg1 != null && arg1 instanceof Map<?, ?>) {
- Map<String, Double> stats = (Map<String, Double>) arg1;
- publishEvents(stats);
- }
- }
-
- public void update(Object healthStatObj) {
- if (healthStatObj != null && healthStatObj instanceof Map<?, ?>) {
- Map<String, Double> stats = (Map<String, Double>) healthStatObj;
- publishEvents(stats);
- }
- }
-
- private void publishEvents(Map<String, Double> stats) {
-
- String memberID = System.getProperty("member.id");
- if(memberID == null) {
- throw new RuntimeException("member.id system property was not found");
- }
- String clusterID = System.getProperty("cluster.id");
- if(clusterID == null) {
- throw new RuntimeException("cluster.id system property was not found");
- }
- String networkPartitionId = System.getProperty("network.partition.id");
- if(networkPartitionId == null) {
- throw new RuntimeException("network.partition.id system property was not found");
- }
- String partitionId = System.getProperty("partition.id");
- if (partitionId == null){
- throw new RuntimeException("partition.id system property was not found");
- }
-
- for (Map.Entry<String, Double> entry : stats.entrySet()) {
-
- Object[] payload = new Object[]{clusterID, networkPartitionId, memberID, partitionId, entry.getKey(),
- entry.getValue()};
- Event event = eventObject(null, null, payload, new HashMap<String, String>());
- try {
- asyncDataPublisher.publish(DATA_STREAM_NAME, VERSION, event);
- } catch (AgentException e) {
- log.error("Failed to publish health stats. ", e);
- }
-
- }
- }
-
- private static Event eventObject(Object[] correlationData, Object[] metaData,
- Object[] payLoadData, HashMap<String, String> map) {
- Event event = new Event();
- event.setCorrelationData(correlationData);
- event.setMetaData(metaData);
- event.setPayloadData(payLoadData);
- event.setArbitraryDataMap(map);
- return event;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/HealthPublisherClient.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/HealthPublisherClient.java b/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/HealthPublisherClient.java
deleted file mode 100644
index 26fedca..0000000
--- a/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/HealthPublisherClient.java
+++ /dev/null
@@ -1,92 +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.health.publisher;
-
-import java.io.*;
-import java.lang.Double;
-import java.lang.Integer;
-import java.lang.Runtime;
-import java.lang.System;
-import java.util.HashMap;
-import java.util.Map;
-import java.lang.management.ManagementFactory;
-import java.net.*;
-
-public class HealthPublisherClient {
-
- private static final int MB = 1024 * 1024;
-
- public Object getHealthStats() {
-
- Runtime runtime = Runtime.getRuntime();
-
- Map<String, Double> statsMap = new HashMap<String, Double>();
-
- double totalMemory = (double)(runtime.totalMemory() / MB);
- double usedMemory = (double)((totalMemory - (runtime.freeMemory() / MB) ));
- double memoryConsumption = (usedMemory / totalMemory) * 100;
-
- statsMap.put("memory_consumption", memoryConsumption);
- statsMap.put("load_average", (double)ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage());
-
- // This section checks open ports in the vm
- boolean isOpen = checkOpenPorts();
-
- if ( !isOpen ) {
- statsMap.put("port_not_open", 0.0);
- }
-
- Object statObj = (Object)statsMap;
-
- return statObj;
- }
-
- public void run() {
- try {
- HealthPublisher publisher = new HealthPublisher();
-
- while (true) {
- Object healthStatObj = getHealthStats();
- publisher.update(healthStatObj);
-
- Thread.sleep(10000);
- }
- } catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- }
-
- private boolean checkOpenPorts() {
- int portNumber = 0;
- String ports = System.getProperty("open.ports");
- String[] portsArray = ports.split(",");
-
- for (int i = 0; i < portsArray.length; i++) {
- try {
- portNumber = Integer.parseInt(portsArray[i].trim());
- Socket ServerSok = new Socket("127.0.0.1", portNumber);
- ServerSok.close();
- } catch (Exception e) {
- return false;
- }
- }
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/Main.java
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/Main.java b/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/Main.java
deleted file mode 100644
index 98c6224..0000000
--- a/products/cartridge-agent/modules/health-stats/src/main/java/org/apache/stratos/cartridge/agent/health/publisher/Main.java
+++ /dev/null
@@ -1,53 +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.health.publisher;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Health 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("Health publisher started");
- }
-
- System.out.println("This is health stat publisher module");
-
- HealthPublisherClient client = new HealthPublisherClient();
- client.run();
-
- System.exit(0);
-
- } catch (Exception e) {
- if (log.isErrorEnabled()) {
- log.error("Could not publish health stats", e);
- }
- }
-
- System.exit(-1);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/health-stats/src/main/resources/jndi.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/health-stats/src/main/resources/jndi.properties b/products/cartridge-agent/modules/health-stats/src/main/resources/jndi.properties
deleted file mode 100644
index c928585..0000000
--- a/products/cartridge-agent/modules/health-stats/src/main/resources/jndi.properties
+++ /dev/null
@@ -1,23 +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
-java.naming.provider.url=repository/conf/jndi.properties
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/health-stats/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/health-stats/src/main/resources/log4j.properties b/products/cartridge-agent/modules/health-stats/src/main/resources/log4j.properties
deleted file mode 100644
index 4c4e610..0000000
--- a/products/cartridge-agent/modules/health-stats/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-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/2f3d9021/products/cartridge-agent/modules/health-stats/src/main/security/client-truststore.jks
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/health-stats/src/main/security/client-truststore.jks b/products/cartridge-agent/modules/health-stats/src/main/security/client-truststore.jks
deleted file mode 100644
index be441f3..0000000
Binary files a/products/cartridge-agent/modules/health-stats/src/main/security/client-truststore.jks and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2f3d9021/products/cartridge-agent/modules/scripts/ec2/load-balancer/cartridge-agent.sh
----------------------------------------------------------------------
diff --git a/products/cartridge-agent/modules/scripts/ec2/load-balancer/cartridge-agent.sh b/products/cartridge-agent/modules/scripts/ec2/load-balancer/cartridge-agent.sh
new file mode 100644
index 0000000..e463a69
--- /dev/null
+++ b/products/cartridge-agent/modules/scripts/ec2/load-balancer/cartridge-agent.sh
@@ -0,0 +1,89 @@
+#!/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
+event_subscriber_path=/opt/apache-stratos-cartridge-agent/event-subscriber # Event subscriber home
+health_publisher_path=/opt/apache-stratos-cartridge-agent/health-publisher # Health publisher home
+
+# ---------------------------------------------
+# Download payload
+# ---------------------------------------------
+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/launch-params
+ echo "payload copied" | 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
+
+#---------------------------
+# Starting load balancer
+#---------------------------
+pushd $instance_path/load-balancer/
+sh start-load-balancer.sh $MB_IP $MB_PORT $CEP_IP $CEP_PORT $LB_CLUSTER_ID $NETWORK_PARTITION_ID &
+popd
+
+#---------------------------
+# Starting topic subscriber
+#---------------------------
+# change mb ip port in conf/jndi.properties
+pushd $event_subscriber_path
+cp -f templates/jndi.properties.template conf/jndi.properties.tmp
+cat conf/jndi.properties.tmp | sed -e "s@MB-IP@$MB_IP@g" > conf/jndi.properties
+cp -f conf/jndi.properties conf/jndi.properties.tmp
+cat conf/jndi.properties.tmp | sed -e "s@MB-PORT@$MB_PORT@g" > conf/jndi.properties
+rm -f conf/jndi.properties.tmp
+popd
+
+pushd $event_subscriber_path/bin
+echo "Executing: event-subscriber.sh "
+sh event-subscriber.sh &
+echo "Event subscribed" | tee -a $LOG
+popd
+
+pushd $health_publisher_path/bin
+echo "Executing: health-publisher.sh"
+sh health-publisher.sh $MEMBER_ID $CEP_IP $CEP_PORT $PORTS $CLUSTER_ID $NETWORK_PARTITION_ID
+echo "Health stat published" | tee -a $LOG
+popd