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 2014/10/27 15:16:05 UTC

[01/50] [abbrv] git commit: Fixed some issues in publishing to CEP

Repository: stratos
Updated Branches:
  refs/heads/master bfe230a36 -> d82fcc539


Fixed some issues in publishing to CEP


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

Branch: refs/heads/master
Commit: 5e6075506c5dfd62bf8e5a1d9b34a9f265eaf16e
Parents: bfdec31
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Wed Oct 15 13:54:33 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Wed Oct 15 13:54:33 2014 +0530

----------------------------------------------------------------------
 .../cartridge-agent/agent.py                    | 28 +++++++++++--
 .../cartridge-agent/modules/databridge/agent.py | 41 ++++++++++++-------
 .../modules/event/topology/events.py            | 42 ++++++++++++++++++++
 .../modules/healthstatspublisher/healthstats.py |  2 -
 .../publisher/cartridgeagentpublisher.py        |  2 -
 5 files changed, 93 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/5e607550/tools/python-cartridge-agent/cartridge-agent/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/agent.py b/tools/python-cartridge-agent/cartridge-agent/agent.py
index e8acc5f..9f1a972 100644
--- a/tools/python-cartridge-agent/cartridge-agent/agent.py
+++ b/tools/python-cartridge-agent/cartridge-agent/agent.py
@@ -54,7 +54,6 @@ class CartridgeAgent(threading.Thread):
             mb_port)
 
         self.__tenant_context_initialized = False
-        self.__topology_context_initialized = False
 
         self.log_publish_manager = None
 
@@ -198,12 +197,27 @@ class CartridgeAgent(threading.Thread):
         self.__topology_event_subscriber.register_handler("MemberSuspendedEvent", self.on_member_suspended)
         self.__topology_event_subscriber.register_handler("CompleteTopologyEvent", self.on_complete_topology)
         self.__topology_event_subscriber.register_handler("MemberStartedEvent", self.on_member_started)
+        self.__topology_event_subscriber.register_handler("InstanceSpawnedEvent", self.on_instance_spawned)
 
         self.__topology_event_subscriber.start()
         self.log.info("Cartridge Agent topology receiver thread started")
 
+    def on_instance_spawned(self, msg):
+        self.log.debug("Instance spawned event received: %r" % msg.payload)
+        if self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = InstanceSpawnedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_instance_spawned_event(event_obj)
+        except:
+            self.log.exception("Error processing instance spawned event")
+
     def on_member_activated(self, msg):
         self.log.debug("Member activated event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
         event_obj = MemberActivatedEvent.create_from_json(msg.payload)
         try:
             CartridgeAgent.extension_handler.on_member_activated_event(event_obj)
@@ -212,6 +226,9 @@ class CartridgeAgent(threading.Thread):
 
     def on_member_terminated(self, msg):
         self.log.debug("Member terminated event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
         event_obj = MemberTerminatedEvent.create_from_json(msg.payload)
         try:
             CartridgeAgent.extension_handler.on_member_terminated_event(event_obj)
@@ -220,6 +237,9 @@ class CartridgeAgent(threading.Thread):
 
     def on_member_suspended(self, msg):
         self.log.debug("Member suspended event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
         event_obj = MemberSuspendedEvent.create_from_json(msg.payload)
         try:
             CartridgeAgent.extension_handler.on_member_suspended_event(event_obj)
@@ -227,11 +247,10 @@ class CartridgeAgent(threading.Thread):
             self.log.exception("Error processing member suspended event")
 
     def on_complete_topology(self, msg):
-        if not self.__topology_context_initialized:
+        if not self.cartridge_agent_config.initialized:
             self.log.debug("Complete topology event received")
             event_obj = CompleteTopologyEvent.create_from_json(msg.payload)
             TopologyContext.update(event_obj.topology)
-            self.__topology_context_initialized = True
             try:
                 CartridgeAgent.extension_handler.on_complete_topology_event(event_obj)
             except:
@@ -241,6 +260,9 @@ class CartridgeAgent(threading.Thread):
 
     def on_member_started(self, msg):
         self.log.debug("Member started event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
         event_obj = MemberStartedEvent.create_from_json(msg.payload)
         try:
             CartridgeAgent.extension_handler.on_member_started_event(event_obj)

http://git-wip-us.apache.org/repos/asf/stratos/blob/5e607550/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
index 8e59dd3..e5700a0 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
@@ -46,14 +46,14 @@ class StreamDefinition:
         self.payload_data = []
         """:type : list[str]"""
 
-    def add_metadata_attribute(self, name, attr_type):
-        self.meta_data.append({"name": name, "type": attr_type})
+    def add_metadata_attribute(self, attr_name, attr_type):
+        self.meta_data.append({"name": attr_name, "type": attr_type})
 
-    def add_payloaddata_attribute(self, name, attr_type):
-        self.payload_data.append({"name": name, "type": attr_type})
+    def add_payloaddata_attribute(self, attr_name, attr_type):
+        self.payload_data.append({"name": attr_name, "type": attr_type})
 
-    def add_correlationdata_attribute(self, name, attr_type):
-        self.correlation_data.append({"name": name, "type": attr_type})
+    def add_correlationdata_attribute(self, attr_name, attr_type):
+        self.correlation_data.append({"name": attr_name, "type": attr_type})
 
     def __str__(self):
         """
@@ -67,26 +67,26 @@ class StreamDefinition:
         json_str += "\"description\":\"" + self.description + "\","
 
         # add metadata attributes if exists
-        if len(self.meta_data > 0):
+        if len(self.meta_data) > 0:
             json_str += "\"metaData\":["
             for metadatum in self.meta_data:
-                json_str += "{\"name\":\"" + metadatum["name"] + ", \"type\": \"" + metadatum["type"] + "\"},"
+                json_str += "{\"name\":\"" + metadatum["name"] + "\", \"type\": \"" + metadatum["type"] + "\"},"
 
             json_str = json_str[:-1] + "],"
 
         # add correlationdata attributes if exists
-        if len(self.correlation_data > 0):
+        if len(self.correlation_data) > 0:
             json_str += "\"correlationData\":["
             for coredatum in self.correlation_data:
-                json_str += "{\"name\":\"" + coredatum["name"] + ", \"type\": \"" + coredatum["type"] + "\"},"
+                json_str += "{\"name\":\"" + coredatum["name"] + "\", \"type\": \"" + coredatum["type"] + "\"},"
 
             json_str = json_str[:-1] + "],"
 
         # add payloaddata attributes if exists
-        if len(self.payload_data > 0):
+        if len(self.payload_data) > 0:
             json_str += "\"payloadData\":["
             for payloaddatum in self.payload_data:
-                json_str += "{\"name\":\"" + payloaddatum["name"] + ", \"type\": \"" + payloaddatum["type"] + "\"},"
+                json_str += "{\"name\":\"" + payloaddatum["name"] + "\", \"type\": \"" + payloaddatum["type"] + "\"},"
 
             json_str = json_str[:-1] + "],"
 
@@ -129,10 +129,17 @@ class ThriftPublisher:
         :return: ThriftPublisher object
         :rtype: ThriftPublisher
         """
-        self.__publisher = Publisher(ip, port)
+        try:
+            port_number = int(port)
+        except ValueError:
+            raise RuntimeError("Port number for Thrift Publisher is invalid: %r" % port)
+
+        self.__publisher = Publisher(ip, port_number)
+        ThriftPublisher.log.debug("CREATED PUBLISHER.. CONNECTING WITH USERNAME AND PASSWORD %r:%r" % (username, password))
         self.__publisher.connect(username, password)
+        ThriftPublisher.log.debug("Connected THRIFT ")
         self.__publisher.defineStream(str(stream_definition))
-        ThriftPublisher.log.debug("Connected to %r:%r with stream definition %r" % (ip, port, str(stream_definition)))
+        ThriftPublisher.log.debug("DEFINED STREAM to %r:%r with stream definition %r" % (ip, port, str(stream_definition)))
 
     def publish(self, event):
         """
@@ -141,12 +148,15 @@ class ThriftPublisher:
         :param ThriftEvent event: The log event to be published
         :return: void
         """
+        ThriftPublisher.log.debug("ABOUT TO PUBLISH: POPULATING DATA")
         event_bundler = EventBundle()
         ThriftPublisher.assign_attributes(event.metaData, event_bundler)
         ThriftPublisher.assign_attributes(event.correlationData, event_bundler)
         ThriftPublisher.assign_attributes(event.payloadData, event_bundler)
+        ThriftPublisher.log.debug("ABOUT TO PUBLISH")
 
-        self.__publisher.publish(event)
+        self.__publisher.publish(event_bundler)
+        ThriftPublisher.log.debug("PUBLISHED EVENT BUNDLED TO THRIFT MODULE")
 
     def disconnect(self):
         """
@@ -154,6 +164,7 @@ class ThriftPublisher:
         :return: void
         """
         self.__publisher.disconnect()
+        ThriftPublisher.log.debug("DISCONNECTED FROM THRIFT PUBLISHER")
 
     @staticmethod
     def assign_attributes(attributes, event_bundler):

http://git-wip-us.apache.org/repos/asf/stratos/blob/5e607550/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/events.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/events.py
index 8a89c98..52c7c19 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/events.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/events.py
@@ -97,6 +97,7 @@ class MemberTerminatedEvent:
         instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
         instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
         instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        instance.properties = json_obj["properties"] if "properties" in json_obj else None
 
         return instance
 
@@ -234,5 +235,46 @@ class MemberStartedEvent:
         instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
         instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
         instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        instance.properties = json_obj["properties"] if "properties" in json_obj else None
+
+        return instance
+
+
+class InstanceSpawnedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+        self.lb_cluster_id = None
+        """ :type : str  """
+        self.member_public_ip = None
+        """ :type : str  """
+        self.member_ip = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = InstanceSpawnedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        instance.lb_cluster_id = json_obj["lbClusterId"] if "lbClusterId" in json_obj else None
+        instance.member_public_ip = json_obj["memberPublicIp"] if "memberPublicIp" in json_obj else None
+        instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None
+        instance.properties = json_obj["properties"]
 
         return instance
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/5e607550/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py b/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
index 578bceb..5dcad24 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
@@ -93,9 +93,7 @@ class HealthStatisticsPublisher:
             self.ports,
             int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False)))
         cep_active = cartridgeagentutils.check_ports_active(CEPPublisherConfiguration.get_instance().server_ip, self.ports)
-        HealthStatisticsPublisher.log.debug("CHECKED PORTS ACTIVITY")
         if not cep_active:
-            HealthStatisticsPublisher.log.debug("CEP PORTS NOT ACTIVE")
             raise CEPPublisherException("CEP server not active. Health statistics publishing aborted.")
 
         self.stream_definition = HealthStatisticsPublisher.create_stream_definition()

http://git-wip-us.apache.org/repos/asf/stratos/blob/5e607550/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py b/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
index c3225c6..1ce8ffb 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
@@ -86,8 +86,6 @@ def publish_instance_activated_event():
             else:
                 interval = interval_default
 
-            log.debug("interval 3: %r" % interval)
-
             health_stats_publisher = HealthStatisticsPublisherManager(interval)
             log.info("Starting Health statistics publisher with interval %r" % interval_default)
             health_stats_publisher.start()


[45/50] [abbrv] git commit: Fixed issues in git artifact management Git clone Git pull

Posted by im...@apache.org.
Fixed issues in git artifact management
	Git clone
	Git pull

Improved logging format
Removed duplicated parameter APP_PATH


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

Branch: refs/heads/master
Commit: 514a7e38dc5f559ac8024139dbb12ed721682366
Parents: 55e7ea0
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Fri Oct 24 04:14:23 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Fri Oct 24 04:14:23 2014 +0530

----------------------------------------------------------------------
 .../cartridgeagent/agent.conf                   |  1 -
 .../cartridgeagent/logging.ini                  |  2 +-
 .../modules/artifactmgt/git/agentgithandler.py  | 21 ++++++++++-----
 .../modules/event/instance/notifier/events.py   |  2 +-
 .../extensions/defaultextensionhandler.py       | 15 ++++++-----
 .../cartridgeagent/testgit.py                   | 27 ++++++++++++++++++++
 6 files changed, 52 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/514a7e38/tools/python_cartridgeagent/cartridgeagent/agent.conf
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/agent.conf b/tools/python_cartridgeagent/cartridgeagent/agent.conf
index dff3cd7..f3e2afb 100644
--- a/tools/python_cartridgeagent/cartridgeagent/agent.conf
+++ b/tools/python_cartridgeagent/cartridgeagent/agent.conf
@@ -40,7 +40,6 @@ monitoring.server.secure.port         =MONITORING-SERVER-SECURE-PORT
 monitoring.server.admin.username      =MONITORING-SERVER-ADMIN-USERNAME
 monitoring.server.admin.password      =MONITORING-SERVER-ADMIN-PASSWORD
 log.file.paths                        =LOG_FILE_PATHS
-APP_PATH                              =APP-PATH
 super.tenant.repository.path          =/repository/deployment/server/
 tenant.repository.path                =/repository/tenants/
 extension.instance.started            =instance-started.sh

http://git-wip-us.apache.org/repos/asf/stratos/blob/514a7e38/tools/python_cartridgeagent/cartridgeagent/logging.ini
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/logging.ini b/tools/python_cartridgeagent/cartridgeagent/logging.ini
index 3e49a96..d71b541 100644
--- a/tools/python_cartridgeagent/cartridgeagent/logging.ini
+++ b/tools/python_cartridgeagent/cartridgeagent/logging.ini
@@ -20,7 +20,7 @@
 keys=default
 
 [formatter_default]
-format=%(asctime)s:%(levelname)s:%(message)s
+format=[%(asctime)s] %(levelname)s {%(filename)s:%(funcName)s} - %(message)s
 class=logging.Formatter
 
 [handlers]

http://git-wip-us.apache.org/repos/asf/stratos/blob/514a7e38/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
index 6da9c58..d6381a0 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
@@ -19,6 +19,7 @@ from threading import current_thread, Thread
 from git import *
 from gittle import Gittle, GittleAuth  # GitPython and Gittle are both used at the time being for pros and cons of both
 import urllib2
+import os
 
 from ... util.log import LogFactory
 from ... util import cartridgeagentutils, extensionutils, cartridgeagentconstants
@@ -27,6 +28,7 @@ from ... config import cartridgeagentconfiguration
 from ... util.asyncscheduledtask import AbstractAsyncScheduledTask, ScheduledExecutor
 from ... artifactmgt.repositoryinformation import RepositoryInformation
 
+
 class AgentGitHandler:
     """
     Handles all the git artifact management tasks related to a cartridge
@@ -81,7 +83,7 @@ class AgentGitHandler:
         else:
             #subscribing run.. need to clone
             subscribe_run = True
-            repo_context = AgentGitHandler.clone(repo_context)
+            repo_context = AgentGitHandler.clone(repo_info)
 
         return subscribe_run, repo_context
 
@@ -133,13 +135,15 @@ class AgentGitHandler:
     @staticmethod
     def pull(repo_context):
         repo = Repo(repo_context.local_repo_path)
-        from ....agent import CartridgeAgent
-        AgentGitHandler.extension_handler = CartridgeAgent.extension_handler
+        import agent
+        AgentGitHandler.extension_handler = agent.CartridgeAgent.extension_handler
         try:
             repo.git.checkout("master")
             pull_output = repo.git.pull()
             if "Already up-to-date." not in pull_output:
                 AgentGitHandler.log.debug("Artifacts were updated as a result of the pull operation, thread: %r - %r" % (current_thread().getName(), current_thread().ident))
+            else:
+                AgentGitHandler.log.debug("Pull operation: Already up-to-date, thread: %r - %r" % (current_thread().getName(), current_thread().ident))
 
             AgentGitHandler.extension_handler.on_artifact_update_scheduler_event(repo_context.tenant_id)
         except GitCommandError as ex:
@@ -235,9 +239,10 @@ class AgentGitHandler:
         :rtype: GittleAuth
         """
         if repo_context.key_based_auth:
-            pkey = AgentGitHandler.get_private_key()
-            auth = GittleAuth(pkey=pkey)
-        elif repo_context.repo_username.strip() != "" and repo_context.repo_password.strip() != "":
+            private_key = AgentGitHandler.get_private_key()
+            auth = GittleAuth(pkey=private_key)
+        elif repo_context.repo_username is not None and repo_context.repo_username.strip() != "" and \
+                        repo_context.repo_password is not None and repo_context.repo_password.strip() != "":
             auth = GittleAuth(username=repo_context.repo_username, password=repo_context.repo_password)
         else:
             auth = None
@@ -349,7 +354,7 @@ class AgentGitHandler:
                 #"app_path"
                 repo_path += git_local_repo_path
 
-                if super_tenant_repo_path is not None  and super_tenant_repo_path != "":
+                if super_tenant_repo_path is not None and super_tenant_repo_path != "":
                     super_tenant_repo_path = super_tenant_repo_path if super_tenant_repo_path.startswith("/") else "/" + super_tenant_repo_path
                     super_tenant_repo_path = super_tenant_repo_path if super_tenant_repo_path.endswith("/") else  super_tenant_repo_path + "/"
                     #"app_path/repository/deploy/server/"
@@ -495,9 +500,11 @@ class ArtifactUpdateTask(AbstractAsyncScheduledTask):
     def execute_task(self):
         try:
             if self.auto_checkout:
+                self.log.debug("Running checkout job")
                 AgentGitHandler.checkout(self.repo_info)
         except:
             self.log.exception("Auto checkout task failed")
 
         if self.auto_commit:
+            self.log.debug("Running commit job")
             AgentGitHandler.commit(self.repo_info)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/514a7e38/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py
index 024e1e4..eb7be55 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py
@@ -45,7 +45,7 @@ class ArtifactUpdatedEvent:
         instance.repo_username = json_obj["repoUserName"] if "repoUserName" in json_obj else None
         instance.repo_password = json_obj["repoPassword"] if "repoPassword" in json_obj else None
         instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.repo_url = json_obj["repoUrl"] if "repoUrl" in json_obj else ""
+        instance.repo_url = json_obj["repoURL"] if "repoURL" in json_obj else ""
         instance.commit_enabled = json_obj["commitEnabled"] if "commitEnabled" in json_obj else None
 
         return instance

http://git-wip-us.apache.org/repos/asf/stratos/blob/514a7e38/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py b/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
index 8a7ccc0..07107da 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
@@ -99,7 +99,7 @@ class DefaultExtensionHandler(AbstractExtensionHandler):
                 auto_checkout = self.cartridge_agent_config.is_checkout_enabled
 
                 try:
-                    update_interval = len(
+                    update_interval = int(
                         self.cartridge_agent_config.read_property(cartridgeagentconstants.ARTIFACT_UPDATE_INTERVAL, False))
                 except ParameterNotFoundException:
                     self.log.exception("Invalid artifact sync interval specified ")
@@ -110,14 +110,17 @@ class DefaultExtensionHandler(AbstractExtensionHandler):
 
                 self.log.info("Artifact updating task enabled, update interval: %r seconds" % update_interval)
 
-                self.log.info("Auto Commit is turned %r " % "on" if auto_commit else "off")
-                self.log.info("Auto Checkout is turned %r " % "on" if auto_checkout else "off")
+                self.log.info("Auto Commit is turned %r " % ("on" if auto_commit else "off"))
+                self.log.info("Auto Checkout is turned %r " % ("on" if auto_checkout else "off"))
 
-                agentgithandler.AgentGitHandler.schedule_artifact_update_scheduled_task(repo_info, auto_checkout, auto_commit,
-                                                                        update_interval)
+                agentgithandler.AgentGitHandler.schedule_artifact_update_scheduled_task(
+                    repo_info,
+                    auto_checkout,
+                    auto_commit,
+                    update_interval)
 
     def on_artifact_update_scheduler_event(self, tenant_id):
-        env_params = {"STRATOS_ARTIFACT_UPDATED_TENANT_ID": tenant_id, "STRATOS_ARTIFACT_UPDATED_SCHEDULER": True}
+        env_params = {"STRATOS_ARTIFACT_UPDATED_TENANT_ID": str(tenant_id), "STRATOS_ARTIFACT_UPDATED_SCHEDULER": str(True)}
 
         extensionutils.execute_artifacts_updated_extension(env_params)
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/514a7e38/tools/python_cartridgeagent/cartridgeagent/testgit.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/testgit.py b/tools/python_cartridgeagent/cartridgeagent/testgit.py
new file mode 100644
index 0000000..c683b56
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/testgit.py
@@ -0,0 +1,27 @@
+# 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.
+
+
+from modules.extensions.defaultextensionhandler import *
+from modules.event.instance.notifier.events import ArtifactUpdatedEvent
+
+event_msg = '{"clusterId":"php.php.domain","repoPassword":"","repoURL":"https://github.com/chamilad/NeWoice","tenantId":"-1234","commitEnabled":false}'
+event = ArtifactUpdatedEvent.create_from_json(event_msg)
+
+extension_handler = DefaultExtensionHandler()
+extension_handler.on_artifact_updated_event(event)
+


[36/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
deleted file mode 100644
index 953838e..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
+++ /dev/null
@@ -1,405 +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.
-#
-
-from struct import pack, unpack
-
-from TProtocol import *
-
-
-__all__ = ['TCompactProtocol', 'TCompactProtocolFactory']
-
-CLEAR = 0
-FIELD_WRITE = 1
-VALUE_WRITE = 2
-CONTAINER_WRITE = 3
-BOOL_WRITE = 4
-FIELD_READ = 5
-CONTAINER_READ = 6
-VALUE_READ = 7
-BOOL_READ = 8
-
-
-def make_helper(v_from, container):
-  def helper(func):
-    def nested(self, *args, **kwargs):
-      assert self.state in (v_from, container), (self.state, v_from, container)
-      return func(self, *args, **kwargs)
-    return nested
-  return helper
-writer = make_helper(VALUE_WRITE, CONTAINER_WRITE)
-reader = make_helper(VALUE_READ, CONTAINER_READ)
-
-
-def makeZigZag(n, bits):
-  return (n << 1) ^ (n >> (bits - 1))
-
-
-def fromZigZag(n):
-  return (n >> 1) ^ -(n & 1)
-
-
-def writeVarint(trans, n):
-  out = []
-  while True:
-    if n & ~0x7f == 0:
-      out.append(n)
-      break
-    else:
-      out.append((n & 0xff) | 0x80)
-      n = n >> 7
-  trans.write(''.join(map(chr, out)))
-
-
-def readVarint(trans):
-  result = 0
-  shift = 0
-  while True:
-    x = trans.readAll(1)
-    byte = ord(x)
-    result |= (byte & 0x7f) << shift
-    if byte >> 7 == 0:
-      return result
-    shift += 7
-
-
-class CompactType:
-  STOP = 0x00
-  TRUE = 0x01
-  FALSE = 0x02
-  BYTE = 0x03
-  I16 = 0x04
-  I32 = 0x05
-  I64 = 0x06
-  DOUBLE = 0x07
-  BINARY = 0x08
-  LIST = 0x09
-  SET = 0x0A
-  MAP = 0x0B
-  STRUCT = 0x0C
-
-CTYPES = {TType.STOP: CompactType.STOP,
-          TType.BOOL: CompactType.TRUE,  # used for collection
-          TType.BYTE: CompactType.BYTE,
-          TType.I16: CompactType.I16,
-          TType.I32: CompactType.I32,
-          TType.I64: CompactType.I64,
-          TType.DOUBLE: CompactType.DOUBLE,
-          TType.STRING: CompactType.BINARY,
-          TType.STRUCT: CompactType.STRUCT,
-          TType.LIST: CompactType.LIST,
-          TType.SET: CompactType.SET,
-          TType.MAP: CompactType.MAP
-          }
-
-TTYPES = {}
-for k, v in CTYPES.items():
-  TTYPES[v] = k
-TTYPES[CompactType.FALSE] = TType.BOOL
-del k
-del v
-
-
-class TCompactProtocol(TProtocolBase):
-  """Compact implementation of the Thrift protocol driver."""
-
-  PROTOCOL_ID = 0x82
-  VERSION = 1
-  VERSION_MASK = 0x1f
-  TYPE_MASK = 0xe0
-  TYPE_SHIFT_AMOUNT = 5
-
-  def __init__(self, trans):
-    TProtocolBase.__init__(self, trans)
-    self.state = CLEAR
-    self.__last_fid = 0
-    self.__bool_fid = None
-    self.__bool_value = None
-    self.__structs = []
-    self.__containers = []
-
-  def __writeVarint(self, n):
-    writeVarint(self.trans, n)
-
-  def writeMessageBegin(self, name, type, seqid):
-    assert self.state == CLEAR
-    self.__writeUByte(self.PROTOCOL_ID)
-    self.__writeUByte(self.VERSION | (type << self.TYPE_SHIFT_AMOUNT))
-    self.__writeVarint(seqid)
-    self.__writeString(name)
-    self.state = VALUE_WRITE
-
-  def writeMessageEnd(self):
-    assert self.state == VALUE_WRITE
-    self.state = CLEAR
-
-  def writeStructBegin(self, name):
-    assert self.state in (CLEAR, CONTAINER_WRITE, VALUE_WRITE), self.state
-    self.__structs.append((self.state, self.__last_fid))
-    self.state = FIELD_WRITE
-    self.__last_fid = 0
-
-  def writeStructEnd(self):
-    assert self.state == FIELD_WRITE
-    self.state, self.__last_fid = self.__structs.pop()
-
-  def writeFieldStop(self):
-    self.__writeByte(0)
-
-  def __writeFieldHeader(self, type, fid):
-    delta = fid - self.__last_fid
-    if 0 < delta <= 15:
-      self.__writeUByte(delta << 4 | type)
-    else:
-      self.__writeByte(type)
-      self.__writeI16(fid)
-    self.__last_fid = fid
-
-  def writeFieldBegin(self, name, type, fid):
-    assert self.state == FIELD_WRITE, self.state
-    if type == TType.BOOL:
-      self.state = BOOL_WRITE
-      self.__bool_fid = fid
-    else:
-      self.state = VALUE_WRITE
-      self.__writeFieldHeader(CTYPES[type], fid)
-
-  def writeFieldEnd(self):
-    assert self.state in (VALUE_WRITE, BOOL_WRITE), self.state
-    self.state = FIELD_WRITE
-
-  def __writeUByte(self, byte):
-    self.trans.write(pack('!B', byte))
-
-  def __writeByte(self, byte):
-    self.trans.write(pack('!b', byte))
-
-  def __writeI16(self, i16):
-    self.__writeVarint(makeZigZag(i16, 16))
-
-  def __writeSize(self, i32):
-    self.__writeVarint(i32)
-
-  def writeCollectionBegin(self, etype, size):
-    assert self.state in (VALUE_WRITE, CONTAINER_WRITE), self.state
-    if size <= 14:
-      self.__writeUByte(size << 4 | CTYPES[etype])
-    else:
-      self.__writeUByte(0xf0 | CTYPES[etype])
-      self.__writeSize(size)
-    self.__containers.append(self.state)
-    self.state = CONTAINER_WRITE
-  writeSetBegin = writeCollectionBegin
-  writeListBegin = writeCollectionBegin
-
-  def writeMapBegin(self, ktype, vtype, size):
-    assert self.state in (VALUE_WRITE, CONTAINER_WRITE), self.state
-    if size == 0:
-      self.__writeByte(0)
-    else:
-      self.__writeSize(size)
-      self.__writeUByte(CTYPES[ktype] << 4 | CTYPES[vtype])
-    self.__containers.append(self.state)
-    self.state = CONTAINER_WRITE
-
-  def writeCollectionEnd(self):
-    assert self.state == CONTAINER_WRITE, self.state
-    self.state = self.__containers.pop()
-  writeMapEnd = writeCollectionEnd
-  writeSetEnd = writeCollectionEnd
-  writeListEnd = writeCollectionEnd
-
-  def writeBool(self, bool):
-    if self.state == BOOL_WRITE:
-      if bool:
-        ctype = CompactType.TRUE
-      else:
-        ctype = CompactType.FALSE
-      self.__writeFieldHeader(ctype, self.__bool_fid)
-    elif self.state == CONTAINER_WRITE:
-      if bool:
-        self.__writeByte(CompactType.TRUE)
-      else:
-        self.__writeByte(CompactType.FALSE)
-    else:
-      raise AssertionError("Invalid state in compact protocol")
-
-  writeByte = writer(__writeByte)
-  writeI16 = writer(__writeI16)
-
-  @writer
-  def writeI32(self, i32):
-    self.__writeVarint(makeZigZag(i32, 32))
-
-  @writer
-  def writeI64(self, i64):
-    self.__writeVarint(makeZigZag(i64, 64))
-
-  @writer
-  def writeDouble(self, dub):
-    self.trans.write(pack('!d', dub))
-
-  def __writeString(self, s):
-    self.__writeSize(len(s))
-    self.trans.write(s)
-  writeString = writer(__writeString)
-
-  def readFieldBegin(self):
-    assert self.state == FIELD_READ, self.state
-    type = self.__readUByte()
-    if type & 0x0f == TType.STOP:
-      return (None, 0, 0)
-    delta = type >> 4
-    if delta == 0:
-      fid = self.__readI16()
-    else:
-      fid = self.__last_fid + delta
-    self.__last_fid = fid
-    type = type & 0x0f
-    if type == CompactType.TRUE:
-      self.state = BOOL_READ
-      self.__bool_value = True
-    elif type == CompactType.FALSE:
-      self.state = BOOL_READ
-      self.__bool_value = False
-    else:
-      self.state = VALUE_READ
-    return (None, self.__getTType(type), fid)
-
-  def readFieldEnd(self):
-    assert self.state in (VALUE_READ, BOOL_READ), self.state
-    self.state = FIELD_READ
-
-  def __readUByte(self):
-    result, = unpack('!B', self.trans.readAll(1))
-    return result
-
-  def __readByte(self):
-    result, = unpack('!b', self.trans.readAll(1))
-    return result
-
-  def __readVarint(self):
-    return readVarint(self.trans)
-
-  def __readZigZag(self):
-    return fromZigZag(self.__readVarint())
-
-  def __readSize(self):
-    result = self.__readVarint()
-    if result < 0:
-      raise TException("Length < 0")
-    return result
-
-  def readMessageBegin(self):
-    assert self.state == CLEAR
-    proto_id = self.__readUByte()
-    if proto_id != self.PROTOCOL_ID:
-      raise TProtocolException(TProtocolException.BAD_VERSION,
-          'Bad protocol id in the message: %d' % proto_id)
-    ver_type = self.__readUByte()
-    type = (ver_type & self.TYPE_MASK) >> self.TYPE_SHIFT_AMOUNT
-    version = ver_type & self.VERSION_MASK
-    if version != self.VERSION:
-      raise TProtocolException(TProtocolException.BAD_VERSION,
-          'Bad version: %d (expect %d)' % (version, self.VERSION))
-    seqid = self.__readVarint()
-    name = self.__readString()
-    return (name, type, seqid)
-
-  def readMessageEnd(self):
-    assert self.state == CLEAR
-    assert len(self.__structs) == 0
-
-  def readStructBegin(self):
-    assert self.state in (CLEAR, CONTAINER_READ, VALUE_READ), self.state
-    self.__structs.append((self.state, self.__last_fid))
-    self.state = FIELD_READ
-    self.__last_fid = 0
-
-  def readStructEnd(self):
-    assert self.state == FIELD_READ
-    self.state, self.__last_fid = self.__structs.pop()
-
-  def readCollectionBegin(self):
-    assert self.state in (VALUE_READ, CONTAINER_READ), self.state
-    size_type = self.__readUByte()
-    size = size_type >> 4
-    type = self.__getTType(size_type)
-    if size == 15:
-      size = self.__readSize()
-    self.__containers.append(self.state)
-    self.state = CONTAINER_READ
-    return type, size
-  readSetBegin = readCollectionBegin
-  readListBegin = readCollectionBegin
-
-  def readMapBegin(self):
-    assert self.state in (VALUE_READ, CONTAINER_READ), self.state
-    size = self.__readSize()
-    types = 0
-    if size > 0:
-      types = self.__readUByte()
-    vtype = self.__getTType(types)
-    ktype = self.__getTType(types >> 4)
-    self.__containers.append(self.state)
-    self.state = CONTAINER_READ
-    return (ktype, vtype, size)
-
-  def readCollectionEnd(self):
-    assert self.state == CONTAINER_READ, self.state
-    self.state = self.__containers.pop()
-  readSetEnd = readCollectionEnd
-  readListEnd = readCollectionEnd
-  readMapEnd = readCollectionEnd
-
-  def readBool(self):
-    if self.state == BOOL_READ:
-      return self.__bool_value == CompactType.TRUE
-    elif self.state == CONTAINER_READ:
-      return self.__readByte() == CompactType.TRUE
-    else:
-      raise AssertionError("Invalid state in compact protocol: %d" %
-                           self.state)
-
-  readByte = reader(__readByte)
-  __readI16 = __readZigZag
-  readI16 = reader(__readZigZag)
-  readI32 = reader(__readZigZag)
-  readI64 = reader(__readZigZag)
-
-  @reader
-  def readDouble(self):
-    buff = self.trans.readAll(8)
-    val, = unpack('!d', buff)
-    return val
-
-  def __readString(self):
-    len = self.__readSize()
-    return self.trans.readAll(len)
-  readString = reader(__readString)
-
-  def __getTType(self, byte):
-    return TTYPES[byte & 0x0f]
-
-
-class TCompactProtocolFactory:
-  def __init__(self):
-    pass
-
-  def getProtocol(self, trans):
-    return TCompactProtocol(trans)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
deleted file mode 100644
index 7d9d7aa..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
+++ /dev/null
@@ -1,552 +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.
-#
-
-import base64
-import json
-import math
-
-from TProtocol import TType, TProtocolBase, TProtocolException
-
-
-__all__ = ['TJSONProtocol',
-           'TJSONProtocolFactory',
-           'TSimpleJSONProtocol',
-           'TSimpleJSONProtocolFactory']
-
-VERSION = 1
-
-COMMA = ','
-COLON = ':'
-LBRACE = '{'
-RBRACE = '}'
-LBRACKET = '['
-RBRACKET = ']'
-QUOTE = '"'
-BACKSLASH = '\\'
-ZERO = '0'
-
-ESCSEQ = '\\u00'
-ESCAPE_CHAR = '"\\bfnrt'
-ESCAPE_CHAR_VALS = ['"', '\\', '\b', '\f', '\n', '\r', '\t']
-NUMERIC_CHAR = '+-.0123456789Ee'
-
-CTYPES = {TType.BOOL:       'tf',
-          TType.BYTE:       'i8',
-          TType.I16:        'i16',
-          TType.I32:        'i32',
-          TType.I64:        'i64',
-          TType.DOUBLE:     'dbl',
-          TType.STRING:     'str',
-          TType.STRUCT:     'rec',
-          TType.LIST:       'lst',
-          TType.SET:        'set',
-          TType.MAP:        'map'}
-
-JTYPES = {}
-for key in CTYPES.keys():
-  JTYPES[CTYPES[key]] = key
-
-
-class JSONBaseContext(object):
-
-  def __init__(self, protocol):
-    self.protocol = protocol
-    self.first = True
-
-  def doIO(self, function):
-    pass
-  
-  def write(self):
-    pass
-
-  def read(self):
-    pass
-
-  def escapeNum(self):
-    return False
-
-  def __str__(self):
-    return self.__class__.__name__
-
-
-class JSONListContext(JSONBaseContext):
-    
-  def doIO(self, function):
-    if self.first is True:
-      self.first = False
-    else:
-      function(COMMA)
-
-  def write(self):
-    self.doIO(self.protocol.trans.write)
-
-  def read(self):
-    self.doIO(self.protocol.readJSONSyntaxChar)
-
-
-class JSONPairContext(JSONBaseContext):
-  
-  def __init__(self, protocol):
-    super(JSONPairContext, self).__init__(protocol)
-    self.colon = True
-
-  def doIO(self, function):
-    if self.first:
-      self.first = False
-      self.colon = True
-    else:
-      function(COLON if self.colon else COMMA)
-      self.colon = not self.colon
-
-  def write(self):
-    self.doIO(self.protocol.trans.write)
-
-  def read(self):
-    self.doIO(self.protocol.readJSONSyntaxChar)
-
-  def escapeNum(self):
-    return self.colon
-
-  def __str__(self):
-    return '%s, colon=%s' % (self.__class__.__name__, self.colon)
-
-
-class LookaheadReader():
-  hasData = False
-  data = ''
-
-  def __init__(self, protocol):
-    self.protocol = protocol
-
-  def read(self):
-    if self.hasData is True:
-      self.hasData = False
-    else:
-      self.data = self.protocol.trans.read(1)
-    return self.data
-
-  def peek(self):
-    if self.hasData is False:
-      self.data = self.protocol.trans.read(1)
-    self.hasData = True
-    return self.data
-
-class TJSONProtocolBase(TProtocolBase):
-
-  def __init__(self, trans):
-    TProtocolBase.__init__(self, trans)
-    self.resetWriteContext()
-    self.resetReadContext()
-
-  def resetWriteContext(self):
-    self.context = JSONBaseContext(self)
-    self.contextStack = [self.context]
-
-  def resetReadContext(self):
-    self.resetWriteContext()
-    self.reader = LookaheadReader(self)
-
-  def pushContext(self, ctx):
-    self.contextStack.append(ctx)
-    self.context = ctx
-
-  def popContext(self):
-    self.contextStack.pop()
-    if self.contextStack:
-      self.context = self.contextStack[-1]
-    else:
-      self.context = JSONBaseContext(self)
-
-  def writeJSONString(self, string):
-    self.context.write()
-    self.trans.write(json.dumps(string))
-
-  def writeJSONNumber(self, number):
-    self.context.write()
-    jsNumber = str(number)
-    if self.context.escapeNum():
-      jsNumber = "%s%s%s" % (QUOTE, jsNumber,  QUOTE)
-    self.trans.write(jsNumber)
-
-  def writeJSONBase64(self, binary):
-    self.context.write()
-    self.trans.write(QUOTE)
-    self.trans.write(base64.b64encode(binary))
-    self.trans.write(QUOTE)
-
-  def writeJSONObjectStart(self):
-    self.context.write()
-    self.trans.write(LBRACE)
-    self.pushContext(JSONPairContext(self))
-
-  def writeJSONObjectEnd(self):
-    self.popContext()
-    self.trans.write(RBRACE)
-
-  def writeJSONArrayStart(self):
-    self.context.write()
-    self.trans.write(LBRACKET)
-    self.pushContext(JSONListContext(self))
-
-  def writeJSONArrayEnd(self):
-    self.popContext()
-    self.trans.write(RBRACKET)
-
-  def readJSONSyntaxChar(self, character):
-    current = self.reader.read()
-    if character != current:
-      raise TProtocolException(TProtocolException.INVALID_DATA,
-                               "Unexpected character: %s" % current)
-
-  def readJSONString(self, skipContext):
-    string = []
-    if skipContext is False:
-      self.context.read()
-    self.readJSONSyntaxChar(QUOTE)
-    while True:
-      character = self.reader.read()
-      if character == QUOTE:
-        break
-      if character == ESCSEQ[0]:
-        character = self.reader.read()
-        if character == ESCSEQ[1]:
-          self.readJSONSyntaxChar(ZERO)
-          self.readJSONSyntaxChar(ZERO)
-          character = json.JSONDecoder().decode('"\u00%s"' % self.trans.read(2))
-        else:
-          off = ESCAPE_CHAR.find(character)
-          if off == -1:
-            raise TProtocolException(TProtocolException.INVALID_DATA,
-                                     "Expected control char")
-          character = ESCAPE_CHAR_VALS[off]
-      string.append(character)
-    return ''.join(string)
-
-  def isJSONNumeric(self, character):
-    return (True if NUMERIC_CHAR.find(character) != - 1 else False)
-
-  def readJSONQuotes(self):
-    if (self.context.escapeNum()):
-      self.readJSONSyntaxChar(QUOTE)
-
-  def readJSONNumericChars(self):
-    numeric = []
-    while True:
-      character = self.reader.peek()
-      if self.isJSONNumeric(character) is False:
-        break
-      numeric.append(self.reader.read())
-    return ''.join(numeric)
-
-  def readJSONInteger(self):
-    self.context.read()
-    self.readJSONQuotes()
-    numeric = self.readJSONNumericChars()
-    self.readJSONQuotes()
-    try:
-      return int(numeric)
-    except ValueError:
-      raise TProtocolException(TProtocolException.INVALID_DATA,
-                               "Bad data encounted in numeric data")
-
-  def readJSONDouble(self):
-    self.context.read()
-    if self.reader.peek() == QUOTE:
-      string  = self.readJSONString(True)
-      try:
-        double = float(string)
-        if (self.context.escapeNum is False and
-            not math.isinf(double) and
-            not math.isnan(double)):
-          raise TProtocolException(TProtocolException.INVALID_DATA,
-                                   "Numeric data unexpectedly quoted")
-        return double
-      except ValueError:
-        raise TProtocolException(TProtocolException.INVALID_DATA,
-                                 "Bad data encounted in numeric data")
-    else:
-      if self.context.escapeNum() is True:
-        self.readJSONSyntaxChar(QUOTE)
-      try:
-        return float(self.readJSONNumericChars())
-      except ValueError:
-        raise TProtocolException(TProtocolException.INVALID_DATA,
-                                 "Bad data encounted in numeric data")
-
-  def readJSONBase64(self):
-    string = self.readJSONString(False)
-    return base64.b64decode(string)
-
-  def readJSONObjectStart(self):
-    self.context.read()
-    self.readJSONSyntaxChar(LBRACE)
-    self.pushContext(JSONPairContext(self))
-
-  def readJSONObjectEnd(self):
-    self.readJSONSyntaxChar(RBRACE)
-    self.popContext()
-
-  def readJSONArrayStart(self):
-    self.context.read()
-    self.readJSONSyntaxChar(LBRACKET)
-    self.pushContext(JSONListContext(self))
-
-  def readJSONArrayEnd(self):
-    self.readJSONSyntaxChar(RBRACKET)
-    self.popContext()
-
-
-class TJSONProtocol(TJSONProtocolBase):
-
-  def readMessageBegin(self):
-    self.resetReadContext()
-    self.readJSONArrayStart()
-    if self.readJSONInteger() != VERSION:
-      raise TProtocolException(TProtocolException.BAD_VERSION,
-                               "Message contained bad version.")
-    name = self.readJSONString(False)
-    typen = self.readJSONInteger()
-    seqid = self.readJSONInteger()
-    return (name, typen, seqid)
-
-  def readMessageEnd(self):
-    self.readJSONArrayEnd()
-
-  def readStructBegin(self):
-    self.readJSONObjectStart()
-
-  def readStructEnd(self):
-    self.readJSONObjectEnd()
-
-  def readFieldBegin(self):
-    character = self.reader.peek()
-    ttype = 0
-    id = 0
-    if character == RBRACE:
-      ttype = TType.STOP
-    else:
-      id = self.readJSONInteger()
-      self.readJSONObjectStart()
-      ttype = JTYPES[self.readJSONString(False)]
-    return (None, ttype, id)
-
-  def readFieldEnd(self):
-    self.readJSONObjectEnd()
-
-  def readMapBegin(self):
-    self.readJSONArrayStart()
-    keyType = JTYPES[self.readJSONString(False)]
-    valueType = JTYPES[self.readJSONString(False)]
-    size = self.readJSONInteger()
-    self.readJSONObjectStart()
-    return (keyType, valueType, size)
-
-  def readMapEnd(self):
-    self.readJSONObjectEnd()
-    self.readJSONArrayEnd()
-
-  def readCollectionBegin(self):
-    self.readJSONArrayStart()
-    elemType = JTYPES[self.readJSONString(False)]
-    size = self.readJSONInteger()
-    return (elemType, size)
-  readListBegin = readCollectionBegin
-  readSetBegin = readCollectionBegin
-
-  def readCollectionEnd(self):
-    self.readJSONArrayEnd()
-  readSetEnd = readCollectionEnd
-  readListEnd = readCollectionEnd
-
-  def readBool(self):
-    return (False if self.readJSONInteger() == 0 else True)
-
-  def readNumber(self):
-    return self.readJSONInteger()
-  readByte = readNumber
-  readI16 = readNumber
-  readI32 = readNumber
-  readI64 = readNumber
-
-  def readDouble(self):
-    return self.readJSONDouble()
-
-  def readString(self):
-    return self.readJSONString(False)
-
-  def readBinary(self):
-    return self.readJSONBase64()
-
-  def writeMessageBegin(self, name, request_type, seqid):
-    self.resetWriteContext()
-    self.writeJSONArrayStart()
-    self.writeJSONNumber(VERSION)
-    self.writeJSONString(name)
-    self.writeJSONNumber(request_type)
-    self.writeJSONNumber(seqid)
-
-  def writeMessageEnd(self):
-    self.writeJSONArrayEnd()
-
-  def writeStructBegin(self, name):
-    self.writeJSONObjectStart()
-
-  def writeStructEnd(self):
-    self.writeJSONObjectEnd()
-
-  def writeFieldBegin(self, name, ttype, id):
-    self.writeJSONNumber(id)
-    self.writeJSONObjectStart()
-    self.writeJSONString(CTYPES[ttype])
-
-  def writeFieldEnd(self):
-    self.writeJSONObjectEnd()
-
-  def writeFieldStop(self):
-    pass
-
-  def writeMapBegin(self, ktype, vtype, size):
-    self.writeJSONArrayStart()
-    self.writeJSONString(CTYPES[ktype])
-    self.writeJSONString(CTYPES[vtype])
-    self.writeJSONNumber(size)
-    self.writeJSONObjectStart()
-
-  def writeMapEnd(self):
-    self.writeJSONObjectEnd()
-    self.writeJSONArrayEnd()
-    
-  def writeListBegin(self, etype, size):
-    self.writeJSONArrayStart()
-    self.writeJSONString(CTYPES[etype])
-    self.writeJSONNumber(size)
-    
-  def writeListEnd(self):
-    self.writeJSONArrayEnd()
-
-  def writeSetBegin(self, etype, size):
-    self.writeJSONArrayStart()
-    self.writeJSONString(CTYPES[etype])
-    self.writeJSONNumber(size)
-    
-  def writeSetEnd(self):
-    self.writeJSONArrayEnd()
-
-  def writeBool(self, boolean):
-    self.writeJSONNumber(1 if boolean is True else 0)
-
-  def writeInteger(self, integer):
-    self.writeJSONNumber(integer)
-  writeByte = writeInteger
-  writeI16 = writeInteger
-  writeI32 = writeInteger
-  writeI64 = writeInteger
-
-  def writeDouble(self, dbl):
-    self.writeJSONNumber(dbl)
-
-  def writeString(self, string):
-    self.writeJSONString(string)
-    
-  def writeBinary(self, binary):
-    self.writeJSONBase64(binary)
-
-
-class TJSONProtocolFactory:
-
-  def getProtocol(self, trans):
-    return TJSONProtocol(trans)
-
-
-class TSimpleJSONProtocol(TJSONProtocolBase):
-    """Simple, readable, write-only JSON protocol.
-    
-    Useful for interacting with scripting languages.
-    """
-
-    def readMessageBegin(self):
-        raise NotImplementedError()
-    
-    def readMessageEnd(self):
-        raise NotImplementedError()
-    
-    def readStructBegin(self):
-        raise NotImplementedError()
-    
-    def readStructEnd(self):
-        raise NotImplementedError()
-    
-    def writeMessageBegin(self, name, request_type, seqid):
-        self.resetWriteContext()
-    
-    def writeMessageEnd(self):
-        pass
-    
-    def writeStructBegin(self, name):
-        self.writeJSONObjectStart()
-    
-    def writeStructEnd(self):
-        self.writeJSONObjectEnd()
-      
-    def writeFieldBegin(self, name, ttype, fid):
-        self.writeJSONString(name)
-    
-    def writeFieldEnd(self):
-        pass
-    
-    def writeMapBegin(self, ktype, vtype, size):
-        self.writeJSONObjectStart()
-    
-    def writeMapEnd(self):
-        self.writeJSONObjectEnd()
-    
-    def _writeCollectionBegin(self, etype, size):
-        self.writeJSONArrayStart()
-    
-    def _writeCollectionEnd(self):
-        self.writeJSONArrayEnd()
-    writeListBegin = _writeCollectionBegin
-    writeListEnd = _writeCollectionEnd
-    writeSetBegin = _writeCollectionBegin
-    writeSetEnd = _writeCollectionEnd
-
-    def writeInteger(self, integer):
-        self.writeJSONNumber(integer)
-    writeByte = writeInteger
-    writeI16 = writeInteger
-    writeI32 = writeInteger
-    writeI64 = writeInteger
-    
-    def writeBool(self, boolean):
-        self.writeJSONNumber(1 if boolean is True else 0)
-
-    def writeDouble(self, dbl):
-        self.writeJSONNumber(dbl)
-    
-    def writeString(self, string):
-        self.writeJSONString(string)
-      
-    def writeBinary(self, binary):
-        self.writeJSONBase64(binary)
-
-
-class TSimpleJSONProtocolFactory(object):
-
-    def getProtocol(self, trans):
-        return TSimpleJSONProtocol(trans)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py
deleted file mode 100644
index 0154641..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py
+++ /dev/null
@@ -1,406 +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.
-#
-
-from ..Thrift import *
-
-
-class TProtocolException(TException):
-  """Custom Protocol Exception class"""
-
-  UNKNOWN = 0
-  INVALID_DATA = 1
-  NEGATIVE_SIZE = 2
-  SIZE_LIMIT = 3
-  BAD_VERSION = 4
-
-  def __init__(self, type=UNKNOWN, message=None):
-    TException.__init__(self, message)
-    self.type = type
-
-
-class TProtocolBase:
-  """Base class for Thrift protocol driver."""
-
-  def __init__(self, trans):
-    self.trans = trans
-
-  def writeMessageBegin(self, name, ttype, seqid):
-    pass
-
-  def writeMessageEnd(self):
-    pass
-
-  def writeStructBegin(self, name):
-    pass
-
-  def writeStructEnd(self):
-    pass
-
-  def writeFieldBegin(self, name, ttype, fid):
-    pass
-
-  def writeFieldEnd(self):
-    pass
-
-  def writeFieldStop(self):
-    pass
-
-  def writeMapBegin(self, ktype, vtype, size):
-    pass
-
-  def writeMapEnd(self):
-    pass
-
-  def writeListBegin(self, etype, size):
-    pass
-
-  def writeListEnd(self):
-    pass
-
-  def writeSetBegin(self, etype, size):
-    pass
-
-  def writeSetEnd(self):
-    pass
-
-  def writeBool(self, bool_val):
-    pass
-
-  def writeByte(self, byte):
-    pass
-
-  def writeI16(self, i16):
-    pass
-
-  def writeI32(self, i32):
-    pass
-
-  def writeI64(self, i64):
-    pass
-
-  def writeDouble(self, dub):
-    pass
-
-  def writeString(self, str_val):
-    pass
-
-  def readMessageBegin(self):
-    pass
-
-  def readMessageEnd(self):
-    pass
-
-  def readStructBegin(self):
-    pass
-
-  def readStructEnd(self):
-    pass
-
-  def readFieldBegin(self):
-    pass
-
-  def readFieldEnd(self):
-    pass
-
-  def readMapBegin(self):
-    pass
-
-  def readMapEnd(self):
-    pass
-
-  def readListBegin(self):
-    pass
-
-  def readListEnd(self):
-    pass
-
-  def readSetBegin(self):
-    pass
-
-  def readSetEnd(self):
-    pass
-
-  def readBool(self):
-    pass
-
-  def readByte(self):
-    pass
-
-  def readI16(self):
-    pass
-
-  def readI32(self):
-    pass
-
-  def readI64(self):
-    pass
-
-  def readDouble(self):
-    pass
-
-  def readString(self):
-    pass
-
-  def skip(self, ttype):
-    if ttype == TType.STOP:
-      return
-    elif ttype == TType.BOOL:
-      self.readBool()
-    elif ttype == TType.BYTE:
-      self.readByte()
-    elif ttype == TType.I16:
-      self.readI16()
-    elif ttype == TType.I32:
-      self.readI32()
-    elif ttype == TType.I64:
-      self.readI64()
-    elif ttype == TType.DOUBLE:
-      self.readDouble()
-    elif ttype == TType.STRING:
-      self.readString()
-    elif ttype == TType.STRUCT:
-      name = self.readStructBegin()
-      while True:
-        (name, ttype, id) = self.readFieldBegin()
-        if ttype == TType.STOP:
-          break
-        self.skip(ttype)
-        self.readFieldEnd()
-      self.readStructEnd()
-    elif ttype == TType.MAP:
-      (ktype, vtype, size) = self.readMapBegin()
-      for i in xrange(size):
-        self.skip(ktype)
-        self.skip(vtype)
-      self.readMapEnd()
-    elif ttype == TType.SET:
-      (etype, size) = self.readSetBegin()
-      for i in xrange(size):
-        self.skip(etype)
-      self.readSetEnd()
-    elif ttype == TType.LIST:
-      (etype, size) = self.readListBegin()
-      for i in xrange(size):
-        self.skip(etype)
-      self.readListEnd()
-
-  # tuple of: ( 'reader method' name, is_container bool, 'writer_method' name )
-  _TTYPE_HANDLERS = (
-       (None, None, False),  # 0 TType.STOP
-       (None, None, False),  # 1 TType.VOID # TODO: handle void?
-       ('readBool', 'writeBool', False),  # 2 TType.BOOL
-       ('readByte',  'writeByte', False),  # 3 TType.BYTE and I08
-       ('readDouble', 'writeDouble', False),  # 4 TType.DOUBLE
-       (None, None, False),  # 5 undefined
-       ('readI16', 'writeI16', False),  # 6 TType.I16
-       (None, None, False),  # 7 undefined
-       ('readI32', 'writeI32', False),  # 8 TType.I32
-       (None, None, False),  # 9 undefined
-       ('readI64', 'writeI64', False),  # 10 TType.I64
-       ('readString', 'writeString', False),  # 11 TType.STRING and UTF7
-       ('readContainerStruct', 'writeContainerStruct', True),  # 12 *.STRUCT
-       ('readContainerMap', 'writeContainerMap', True),  # 13 TType.MAP
-       ('readContainerSet', 'writeContainerSet', True),  # 14 TType.SET
-       ('readContainerList', 'writeContainerList', True),  # 15 TType.LIST
-       (None, None, False),  # 16 TType.UTF8 # TODO: handle utf8 types?
-       (None, None, False)  # 17 TType.UTF16 # TODO: handle utf16 types?
-      )
-
-  def readFieldByTType(self, ttype, spec):
-    try:
-      (r_handler, w_handler, is_container) = self._TTYPE_HANDLERS[ttype]
-    except IndexError:
-      raise TProtocolException(type=TProtocolException.INVALID_DATA,
-                               message='Invalid field type %d' % (ttype))
-    if r_handler is None:
-      raise TProtocolException(type=TProtocolException.INVALID_DATA,
-                               message='Invalid field type %d' % (ttype))
-    reader = getattr(self, r_handler)
-    if not is_container:
-      return reader()
-    return reader(spec)
-
-  def readContainerList(self, spec):
-    results = []
-    ttype, tspec = spec[0], spec[1]
-    r_handler = self._TTYPE_HANDLERS[ttype][0]
-    reader = getattr(self, r_handler)
-    (list_type, list_len) = self.readListBegin()
-    if tspec is None:
-      # list values are simple types
-      for idx in xrange(list_len):
-        results.append(reader())
-    else:
-      # this is like an inlined readFieldByTType
-      container_reader = self._TTYPE_HANDLERS[list_type][0]
-      val_reader = getattr(self, container_reader)
-      for idx in xrange(list_len):
-        val = val_reader(tspec)
-        results.append(val)
-    self.readListEnd()
-    return results
-
-  def readContainerSet(self, spec):
-    results = set()
-    ttype, tspec = spec[0], spec[1]
-    r_handler = self._TTYPE_HANDLERS[ttype][0]
-    reader = getattr(self, r_handler)
-    (set_type, set_len) = self.readSetBegin()
-    if tspec is None:
-      # set members are simple types
-      for idx in xrange(set_len):
-        results.add(reader())
-    else:
-      container_reader = self._TTYPE_HANDLERS[set_type][0]
-      val_reader = getattr(self, container_reader)
-      for idx in xrange(set_len):
-        results.add(val_reader(tspec))
-    self.readSetEnd()
-    return results
-
-  def readContainerStruct(self, spec):
-    (obj_class, obj_spec) = spec
-    obj = obj_class()
-    obj.read(self)
-    return obj
-
-  def readContainerMap(self, spec):
-    results = dict()
-    key_ttype, key_spec = spec[0], spec[1]
-    val_ttype, val_spec = spec[2], spec[3]
-    (map_ktype, map_vtype, map_len) = self.readMapBegin()
-    # TODO: compare types we just decoded with thrift_spec and
-    # abort/skip if types disagree
-    key_reader = getattr(self, self._TTYPE_HANDLERS[key_ttype][0])
-    val_reader = getattr(self, self._TTYPE_HANDLERS[val_ttype][0])
-    # list values are simple types
-    for idx in xrange(map_len):
-      if key_spec is None:
-        k_val = key_reader()
-      else:
-        k_val = self.readFieldByTType(key_ttype, key_spec)
-      if val_spec is None:
-        v_val = val_reader()
-      else:
-        v_val = self.readFieldByTType(val_ttype, val_spec)
-      # this raises a TypeError with unhashable keys types
-      # i.e. this fails: d=dict(); d[[0,1]] = 2
-      results[k_val] = v_val
-    self.readMapEnd()
-    return results
-
-  def readStruct(self, obj, thrift_spec):
-    self.readStructBegin()
-    while True:
-      (fname, ftype, fid) = self.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      try:
-        field = thrift_spec[fid]
-      except IndexError:
-        self.skip(ftype)
-      else:
-        if field is not None and ftype == field[1]:
-          fname = field[2]
-          fspec = field[3]
-          val = self.readFieldByTType(ftype, fspec)
-          setattr(obj, fname, val)
-        else:
-          self.skip(ftype)
-      self.readFieldEnd()
-    self.readStructEnd()
-
-  def writeContainerStruct(self, val, spec):
-    val.write(self)
-
-  def writeContainerList(self, val, spec):
-    self.writeListBegin(spec[0], len(val))
-    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[spec[0]]
-    e_writer = getattr(self, w_handler)
-    if not is_container:
-      for elem in val:
-        e_writer(elem)
-    else:
-      for elem in val:
-        e_writer(elem, spec[1])
-    self.writeListEnd()
-
-  def writeContainerSet(self, val, spec):
-    self.writeSetBegin(spec[0], len(val))
-    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[spec[0]]
-    e_writer = getattr(self, w_handler)
-    if not is_container:
-      for elem in val:
-        e_writer(elem)
-    else:
-      for elem in val:
-        e_writer(elem, spec[1])
-    self.writeSetEnd()
-
-  def writeContainerMap(self, val, spec):
-    k_type = spec[0]
-    v_type = spec[2]
-    ignore, ktype_name, k_is_container = self._TTYPE_HANDLERS[k_type]
-    ignore, vtype_name, v_is_container = self._TTYPE_HANDLERS[v_type]
-    k_writer = getattr(self, ktype_name)
-    v_writer = getattr(self, vtype_name)
-    self.writeMapBegin(k_type, v_type, len(val))
-    for m_key, m_val in val.iteritems():
-      if not k_is_container:
-        k_writer(m_key)
-      else:
-        k_writer(m_key, spec[1])
-      if not v_is_container:
-        v_writer(m_val)
-      else:
-        v_writer(m_val, spec[3])
-    self.writeMapEnd()
-
-  def writeStruct(self, obj, thrift_spec):
-    self.writeStructBegin(obj.__class__.__name__)
-    for field in thrift_spec:
-      if field is None:
-        continue
-      fname = field[2]
-      val = getattr(obj, fname)
-      if val is None:
-        # skip writing out unset fields
-        continue
-      fid = field[0]
-      ftype = field[1]
-      fspec = field[3]
-      # get the writer method for this value
-      self.writeFieldBegin(fname, ftype, fid)
-      self.writeFieldByTType(ftype, val, fspec)
-      self.writeFieldEnd()
-    self.writeFieldStop()
-    self.writeStructEnd()
-
-  def writeFieldByTType(self, ttype, val, spec):
-    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[ttype]
-    writer = getattr(self, w_handler)
-    if is_container:
-      writer(val, spec)
-    else:
-      writer(val)
-
-
-class TProtocolFactory:
-  def getProtocol(self, trans):
-    pass

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py
deleted file mode 100644
index 7eefb45..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py
+++ /dev/null
@@ -1,20 +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.
-#
-
-__all__ = ['fastbinary', 'TBase', 'TBinaryProtocol', 'TCompactProtocol', 'TJSONProtocol', 'TProtocol']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c
deleted file mode 100644
index 2ce5660..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c
+++ /dev/null
@@ -1,1219 +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.
- */
-
-#include <Python.h>
-#include "cStringIO.h"
-#include <stdint.h>
-#ifndef _WIN32
-# include <stdbool.h>
-# include <netinet/in.h>
-#else
-# include <WinSock2.h>
-# pragma comment (lib, "ws2_32.lib")
-# define BIG_ENDIAN (4321)
-# define LITTLE_ENDIAN (1234)
-# define BYTE_ORDER LITTLE_ENDIAN
-# if defined(_MSC_VER) && _MSC_VER < 1600
-   typedef int _Bool;
-#  define bool _Bool
-#  define false 0 
-#  define true 1
-# endif
-# define inline __inline
-#endif
-
-/* Fix endianness issues on Solaris */
-#if defined (__SVR4) && defined (__sun)
- #if defined(__i386) && !defined(__i386__)
-  #define __i386__
- #endif
-
- #ifndef BIG_ENDIAN
-  #define BIG_ENDIAN (4321)
- #endif
- #ifndef LITTLE_ENDIAN
-  #define LITTLE_ENDIAN (1234)
- #endif
-
- /* I386 is LE, even on Solaris */
- #if !defined(BYTE_ORDER) && defined(__i386__)
-  #define BYTE_ORDER LITTLE_ENDIAN
- #endif
-#endif
-
-// TODO(dreiss): defval appears to be unused.  Look into removing it.
-// TODO(dreiss): Make parse_spec_args recursive, and cache the output
-//               permanently in the object.  (Malloc and orphan.)
-// TODO(dreiss): Why do we need cStringIO for reading, why not just char*?
-//               Can cStringIO let us work with a BufferedTransport?
-// TODO(dreiss): Don't ignore the rv from cwrite (maybe).
-
-/* ====== BEGIN UTILITIES ====== */
-
-#define INIT_OUTBUF_SIZE 128
-
-// Stolen out of TProtocol.h.
-// It would be a huge pain to have both get this from one place.
-typedef enum TType {
-  T_STOP       = 0,
-  T_VOID       = 1,
-  T_BOOL       = 2,
-  T_BYTE       = 3,
-  T_I08        = 3,
-  T_I16        = 6,
-  T_I32        = 8,
-  T_U64        = 9,
-  T_I64        = 10,
-  T_DOUBLE     = 4,
-  T_STRING     = 11,
-  T_UTF7       = 11,
-  T_STRUCT     = 12,
-  T_MAP        = 13,
-  T_SET        = 14,
-  T_LIST       = 15,
-  T_UTF8       = 16,
-  T_UTF16      = 17
-} TType;
-
-#ifndef __BYTE_ORDER
-# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
-#  define __BYTE_ORDER BYTE_ORDER
-#  define __LITTLE_ENDIAN LITTLE_ENDIAN
-#  define __BIG_ENDIAN BIG_ENDIAN
-# else
-#  error "Cannot determine endianness"
-# endif
-#endif
-
-// Same comment as the enum.  Sorry.
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define ntohll(n) (n)
-# define htonll(n) (n)
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-# if defined(__GNUC__) && defined(__GLIBC__)
-#  include <byteswap.h>
-#  define ntohll(n) bswap_64(n)
-#  define htonll(n) bswap_64(n)
-# else /* GNUC & GLIBC */
-#  define ntohll(n) ( (((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32) )
-#  define htonll(n) ( (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32) )
-# endif /* GNUC & GLIBC */
-#else /* __BYTE_ORDER */
-# error "Can't define htonll or ntohll!"
-#endif
-
-// Doing a benchmark shows that interning actually makes a difference, amazingly.
-#define INTERN_STRING(value) _intern_ ## value
-
-#define INT_CONV_ERROR_OCCURRED(v) ( ((v) == -1) && PyErr_Occurred() )
-#define CHECK_RANGE(v, min, max) ( ((v) <= (max)) && ((v) >= (min)) )
-
-// Py_ssize_t was not defined before Python 2.5
-#if (PY_VERSION_HEX < 0x02050000)
-typedef int Py_ssize_t;
-#endif
-
-/**
- * A cache of the spec_args for a set or list,
- * so we don't have to keep calling PyTuple_GET_ITEM.
- */
-typedef struct {
-  TType element_type;
-  PyObject* typeargs;
-} SetListTypeArgs;
-
-/**
- * A cache of the spec_args for a map,
- * so we don't have to keep calling PyTuple_GET_ITEM.
- */
-typedef struct {
-  TType ktag;
-  TType vtag;
-  PyObject* ktypeargs;
-  PyObject* vtypeargs;
-} MapTypeArgs;
-
-/**
- * A cache of the spec_args for a struct,
- * so we don't have to keep calling PyTuple_GET_ITEM.
- */
-typedef struct {
-  PyObject* klass;
-  PyObject* spec;
-} StructTypeArgs;
-
-/**
- * A cache of the item spec from a struct specification,
- * so we don't have to keep calling PyTuple_GET_ITEM.
- */
-typedef struct {
-  int tag;
-  TType type;
-  PyObject* attrname;
-  PyObject* typeargs;
-  PyObject* defval;
-} StructItemSpec;
-
-/**
- * A cache of the two key attributes of a CReadableTransport,
- * so we don't have to keep calling PyObject_GetAttr.
- */
-typedef struct {
-  PyObject* stringiobuf;
-  PyObject* refill_callable;
-} DecodeBuffer;
-
-/** Pointer to interned string to speed up attribute lookup. */
-static PyObject* INTERN_STRING(cstringio_buf);
-/** Pointer to interned string to speed up attribute lookup. */
-static PyObject* INTERN_STRING(cstringio_refill);
-
-static inline bool
-check_ssize_t_32(Py_ssize_t len) {
-  // error from getting the int
-  if (INT_CONV_ERROR_OCCURRED(len)) {
-    return false;
-  }
-  if (!CHECK_RANGE(len, 0, INT32_MAX)) {
-    PyErr_SetString(PyExc_OverflowError, "string size out of range");
-    return false;
-  }
-  return true;
-}
-
-static inline bool
-parse_pyint(PyObject* o, int32_t* ret, int32_t min, int32_t max) {
-  long val = PyInt_AsLong(o);
-
-  if (INT_CONV_ERROR_OCCURRED(val)) {
-    return false;
-  }
-  if (!CHECK_RANGE(val, min, max)) {
-    PyErr_SetString(PyExc_OverflowError, "int out of range");
-    return false;
-  }
-
-  *ret = (int32_t) val;
-  return true;
-}
-
-
-/* --- FUNCTIONS TO PARSE STRUCT SPECIFICATOINS --- */
-
-static bool
-parse_set_list_args(SetListTypeArgs* dest, PyObject* typeargs) {
-  if (PyTuple_Size(typeargs) != 2) {
-    PyErr_SetString(PyExc_TypeError, "expecting tuple of size 2 for list/set type args");
-    return false;
-  }
-
-  dest->element_type = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 0));
-  if (INT_CONV_ERROR_OCCURRED(dest->element_type)) {
-    return false;
-  }
-
-  dest->typeargs = PyTuple_GET_ITEM(typeargs, 1);
-
-  return true;
-}
-
-static bool
-parse_map_args(MapTypeArgs* dest, PyObject* typeargs) {
-  if (PyTuple_Size(typeargs) != 4) {
-    PyErr_SetString(PyExc_TypeError, "expecting 4 arguments for typeargs to map");
-    return false;
-  }
-
-  dest->ktag = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 0));
-  if (INT_CONV_ERROR_OCCURRED(dest->ktag)) {
-    return false;
-  }
-
-  dest->vtag = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 2));
-  if (INT_CONV_ERROR_OCCURRED(dest->vtag)) {
-    return false;
-  }
-
-  dest->ktypeargs = PyTuple_GET_ITEM(typeargs, 1);
-  dest->vtypeargs = PyTuple_GET_ITEM(typeargs, 3);
-
-  return true;
-}
-
-static bool
-parse_struct_args(StructTypeArgs* dest, PyObject* typeargs) {
-  if (PyTuple_Size(typeargs) != 2) {
-    PyErr_SetString(PyExc_TypeError, "expecting tuple of size 2 for struct args");
-    return false;
-  }
-
-  dest->klass = PyTuple_GET_ITEM(typeargs, 0);
-  dest->spec = PyTuple_GET_ITEM(typeargs, 1);
-
-  return true;
-}
-
-static int
-parse_struct_item_spec(StructItemSpec* dest, PyObject* spec_tuple) {
-
-  // i'd like to use ParseArgs here, but it seems to be a bottleneck.
-  if (PyTuple_Size(spec_tuple) != 5) {
-    PyErr_SetString(PyExc_TypeError, "expecting 5 arguments for spec tuple");
-    return false;
-  }
-
-  dest->tag = PyInt_AsLong(PyTuple_GET_ITEM(spec_tuple, 0));
-  if (INT_CONV_ERROR_OCCURRED(dest->tag)) {
-    return false;
-  }
-
-  dest->type = PyInt_AsLong(PyTuple_GET_ITEM(spec_tuple, 1));
-  if (INT_CONV_ERROR_OCCURRED(dest->type)) {
-    return false;
-  }
-
-  dest->attrname = PyTuple_GET_ITEM(spec_tuple, 2);
-  dest->typeargs = PyTuple_GET_ITEM(spec_tuple, 3);
-  dest->defval = PyTuple_GET_ITEM(spec_tuple, 4);
-  return true;
-}
-
-/* ====== END UTILITIES ====== */
-
-
-/* ====== BEGIN WRITING FUNCTIONS ====== */
-
-/* --- LOW-LEVEL WRITING FUNCTIONS --- */
-
-static void writeByte(PyObject* outbuf, int8_t val) {
-  int8_t net = val;
-  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int8_t));
-}
-
-static void writeI16(PyObject* outbuf, int16_t val) {
-  int16_t net = (int16_t)htons(val);
-  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int16_t));
-}
-
-static void writeI32(PyObject* outbuf, int32_t val) {
-  int32_t net = (int32_t)htonl(val);
-  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int32_t));
-}
-
-static void writeI64(PyObject* outbuf, int64_t val) {
-  int64_t net = (int64_t)htonll(val);
-  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int64_t));
-}
-
-static void writeDouble(PyObject* outbuf, double dub) {
-  // Unfortunately, bitwise_cast doesn't work in C.  Bad C!
-  union {
-    double f;
-    int64_t t;
-  } transfer;
-  transfer.f = dub;
-  writeI64(outbuf, transfer.t);
-}
-
-
-/* --- MAIN RECURSIVE OUTPUT FUCNTION -- */
-
-static int
-output_val(PyObject* output, PyObject* value, TType type, PyObject* typeargs) {
-  /*
-   * Refcounting Strategy:
-   *
-   * We assume that elements of the thrift_spec tuple are not going to be
-   * mutated, so we don't ref count those at all. Other than that, we try to
-   * keep a reference to all the user-created objects while we work with them.
-   * output_val assumes that a reference is already held. The *caller* is
-   * responsible for handling references
-   */
-
-  switch (type) {
-
-  case T_BOOL: {
-    int v = PyObject_IsTrue(value);
-    if (v == -1) {
-      return false;
-    }
-
-    writeByte(output, (int8_t) v);
-    break;
-  }
-  case T_I08: {
-    int32_t val;
-
-    if (!parse_pyint(value, &val, INT8_MIN, INT8_MAX)) {
-      return false;
-    }
-
-    writeByte(output, (int8_t) val);
-    break;
-  }
-  case T_I16: {
-    int32_t val;
-
-    if (!parse_pyint(value, &val, INT16_MIN, INT16_MAX)) {
-      return false;
-    }
-
-    writeI16(output, (int16_t) val);
-    break;
-  }
-  case T_I32: {
-    int32_t val;
-
-    if (!parse_pyint(value, &val, INT32_MIN, INT32_MAX)) {
-      return false;
-    }
-
-    writeI32(output, val);
-    break;
-  }
-  case T_I64: {
-    int64_t nval = PyLong_AsLongLong(value);
-
-    if (INT_CONV_ERROR_OCCURRED(nval)) {
-      return false;
-    }
-
-    if (!CHECK_RANGE(nval, INT64_MIN, INT64_MAX)) {
-      PyErr_SetString(PyExc_OverflowError, "int out of range");
-      return false;
-    }
-
-    writeI64(output, nval);
-    break;
-  }
-
-  case T_DOUBLE: {
-    double nval = PyFloat_AsDouble(value);
-    if (nval == -1.0 && PyErr_Occurred()) {
-      return false;
-    }
-
-    writeDouble(output, nval);
-    break;
-  }
-
-  case T_STRING: {
-    Py_ssize_t len = PyString_Size(value);
-
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    writeI32(output, (int32_t) len);
-    PycStringIO->cwrite(output, PyString_AsString(value), (int32_t) len);
-    break;
-  }
-
-  case T_LIST:
-  case T_SET: {
-    Py_ssize_t len;
-    SetListTypeArgs parsedargs;
-    PyObject *item;
-    PyObject *iterator;
-
-    if (!parse_set_list_args(&parsedargs, typeargs)) {
-      return false;
-    }
-
-    len = PyObject_Length(value);
-
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    writeByte(output, parsedargs.element_type);
-    writeI32(output, (int32_t) len);
-
-    iterator =  PyObject_GetIter(value);
-    if (iterator == NULL) {
-      return false;
-    }
-
-    while ((item = PyIter_Next(iterator))) {
-      if (!output_val(output, item, parsedargs.element_type, parsedargs.typeargs)) {
-        Py_DECREF(item);
-        Py_DECREF(iterator);
-        return false;
-      }
-      Py_DECREF(item);
-    }
-
-    Py_DECREF(iterator);
-
-    if (PyErr_Occurred()) {
-      return false;
-    }
-
-    break;
-  }
-
-  case T_MAP: {
-    PyObject *k, *v;
-    Py_ssize_t pos = 0;
-    Py_ssize_t len;
-
-    MapTypeArgs parsedargs;
-
-    len = PyDict_Size(value);
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    if (!parse_map_args(&parsedargs, typeargs)) {
-      return false;
-    }
-
-    writeByte(output, parsedargs.ktag);
-    writeByte(output, parsedargs.vtag);
-    writeI32(output, len);
-
-    // TODO(bmaurer): should support any mapping, not just dicts
-    while (PyDict_Next(value, &pos, &k, &v)) {
-      // TODO(dreiss): Think hard about whether these INCREFs actually
-      //               turn any unsafe scenarios into safe scenarios.
-      Py_INCREF(k);
-      Py_INCREF(v);
-
-      if (!output_val(output, k, parsedargs.ktag, parsedargs.ktypeargs)
-          || !output_val(output, v, parsedargs.vtag, parsedargs.vtypeargs)) {
-        Py_DECREF(k);
-        Py_DECREF(v);
-        return false;
-      }
-      Py_DECREF(k);
-      Py_DECREF(v);
-    }
-    break;
-  }
-
-  // TODO(dreiss): Consider breaking this out as a function
-  //               the way we did for decode_struct.
-  case T_STRUCT: {
-    StructTypeArgs parsedargs;
-    Py_ssize_t nspec;
-    Py_ssize_t i;
-
-    if (!parse_struct_args(&parsedargs, typeargs)) {
-      return false;
-    }
-
-    nspec = PyTuple_Size(parsedargs.spec);
-
-    if (nspec == -1) {
-      return false;
-    }
-
-    for (i = 0; i < nspec; i++) {
-      StructItemSpec parsedspec;
-      PyObject* spec_tuple;
-      PyObject* instval = NULL;
-
-      spec_tuple = PyTuple_GET_ITEM(parsedargs.spec, i);
-      if (spec_tuple == Py_None) {
-        continue;
-      }
-
-      if (!parse_struct_item_spec (&parsedspec, spec_tuple)) {
-        return false;
-      }
-
-      instval = PyObject_GetAttr(value, parsedspec.attrname);
-
-      if (!instval) {
-        return false;
-      }
-
-      if (instval == Py_None) {
-        Py_DECREF(instval);
-        continue;
-      }
-
-      writeByte(output, (int8_t) parsedspec.type);
-      writeI16(output, parsedspec.tag);
-
-      if (!output_val(output, instval, parsedspec.type, parsedspec.typeargs)) {
-        Py_DECREF(instval);
-        return false;
-      }
-
-      Py_DECREF(instval);
-    }
-
-    writeByte(output, (int8_t)T_STOP);
-    break;
-  }
-
-  case T_STOP:
-  case T_VOID:
-  case T_UTF16:
-  case T_UTF8:
-  case T_U64:
-  default:
-    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
-    return false;
-
-  }
-
-  return true;
-}
-
-
-/* --- TOP-LEVEL WRAPPER FOR OUTPUT -- */
-
-static PyObject *
-encode_binary(PyObject *self, PyObject *args) {
-  PyObject* enc_obj;
-  PyObject* type_args;
-  PyObject* buf;
-  PyObject* ret = NULL;
-
-  if (!PyArg_ParseTuple(args, "OO", &enc_obj, &type_args)) {
-    return NULL;
-  }
-
-  buf = PycStringIO->NewOutput(INIT_OUTBUF_SIZE);
-  if (output_val(buf, enc_obj, T_STRUCT, type_args)) {
-    ret = PycStringIO->cgetvalue(buf);
-  }
-
-  Py_DECREF(buf);
-  return ret;
-}
-
-/* ====== END WRITING FUNCTIONS ====== */
-
-
-/* ====== BEGIN READING FUNCTIONS ====== */
-
-/* --- LOW-LEVEL READING FUNCTIONS --- */
-
-static void
-free_decodebuf(DecodeBuffer* d) {
-  Py_XDECREF(d->stringiobuf);
-  Py_XDECREF(d->refill_callable);
-}
-
-static bool
-decode_buffer_from_obj(DecodeBuffer* dest, PyObject* obj) {
-  dest->stringiobuf = PyObject_GetAttr(obj, INTERN_STRING(cstringio_buf));
-  if (!dest->stringiobuf) {
-    return false;
-  }
-
-  if (!PycStringIO_InputCheck(dest->stringiobuf)) {
-    free_decodebuf(dest);
-    PyErr_SetString(PyExc_TypeError, "expecting stringio input");
-    return false;
-  }
-
-  dest->refill_callable = PyObject_GetAttr(obj, INTERN_STRING(cstringio_refill));
-
-  if(!dest->refill_callable) {
-    free_decodebuf(dest);
-    return false;
-  }
-
-  if (!PyCallable_Check(dest->refill_callable)) {
-    free_decodebuf(dest);
-    PyErr_SetString(PyExc_TypeError, "expecting callable");
-    return false;
-  }
-
-  return true;
-}
-
-static bool readBytes(DecodeBuffer* input, char** output, int len) {
-  int read;
-
-  // TODO(dreiss): Don't fear the malloc.  Think about taking a copy of
-  //               the partial read instead of forcing the transport
-  //               to prepend it to its buffer.
-
-  read = PycStringIO->cread(input->stringiobuf, output, len);
-
-  if (read == len) {
-    return true;
-  } else if (read == -1) {
-    return false;
-  } else {
-    PyObject* newiobuf;
-
-    // using building functions as this is a rare codepath
-    newiobuf = PyObject_CallFunction(
-        input->refill_callable, "s#i", *output, read, len, NULL);
-    if (newiobuf == NULL) {
-      return false;
-    }
-
-    // must do this *AFTER* the call so that we don't deref the io buffer
-    Py_CLEAR(input->stringiobuf);
-    input->stringiobuf = newiobuf;
-
-    read = PycStringIO->cread(input->stringiobuf, output, len);
-
-    if (read == len) {
-      return true;
-    } else if (read == -1) {
-      return false;
-    } else {
-      // TODO(dreiss): This could be a valid code path for big binary blobs.
-      PyErr_SetString(PyExc_TypeError,
-          "refill claimed to have refilled the buffer, but didn't!!");
-      return false;
-    }
-  }
-}
-
-static int8_t readByte(DecodeBuffer* input) {
-  char* buf;
-  if (!readBytes(input, &buf, sizeof(int8_t))) {
-    return -1;
-  }
-
-  return *(int8_t*) buf;
-}
-
-static int16_t readI16(DecodeBuffer* input) {
-  char* buf;
-  if (!readBytes(input, &buf, sizeof(int16_t))) {
-    return -1;
-  }
-
-  return (int16_t) ntohs(*(int16_t*) buf);
-}
-
-static int32_t readI32(DecodeBuffer* input) {
-  char* buf;
-  if (!readBytes(input, &buf, sizeof(int32_t))) {
-    return -1;
-  }
-  return (int32_t) ntohl(*(int32_t*) buf);
-}
-
-
-static int64_t readI64(DecodeBuffer* input) {
-  char* buf;
-  if (!readBytes(input, &buf, sizeof(int64_t))) {
-    return -1;
-  }
-
-  return (int64_t) ntohll(*(int64_t*) buf);
-}
-
-static double readDouble(DecodeBuffer* input) {
-  union {
-    int64_t f;
-    double t;
-  } transfer;
-
-  transfer.f = readI64(input);
-  if (transfer.f == -1) {
-    return -1;
-  }
-  return transfer.t;
-}
-
-static bool
-checkTypeByte(DecodeBuffer* input, TType expected) {
-  TType got = readByte(input);
-  if (INT_CONV_ERROR_OCCURRED(got)) {
-    return false;
-  }
-
-  if (expected != got) {
-    PyErr_SetString(PyExc_TypeError, "got wrong ttype while reading field");
-    return false;
-  }
-  return true;
-}
-
-static bool
-skip(DecodeBuffer* input, TType type) {
-#define SKIPBYTES(n) \
-  do { \
-    if (!readBytes(input, &dummy_buf, (n))) { \
-      return false; \
-    } \
-  } while(0)
-
-  char* dummy_buf;
-
-  switch (type) {
-
-  case T_BOOL:
-  case T_I08: SKIPBYTES(1); break;
-  case T_I16: SKIPBYTES(2); break;
-  case T_I32: SKIPBYTES(4); break;
-  case T_I64:
-  case T_DOUBLE: SKIPBYTES(8); break;
-
-  case T_STRING: {
-    // TODO(dreiss): Find out if these check_ssize_t32s are really necessary.
-    int len = readI32(input);
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-    SKIPBYTES(len);
-    break;
-  }
-
-  case T_LIST:
-  case T_SET: {
-    TType etype;
-    int len, i;
-
-    etype = readByte(input);
-    if (etype == -1) {
-      return false;
-    }
-
-    len = readI32(input);
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    for (i = 0; i < len; i++) {
-      if (!skip(input, etype)) {
-        return false;
-      }
-    }
-    break;
-  }
-
-  case T_MAP: {
-    TType ktype, vtype;
-    int len, i;
-
-    ktype = readByte(input);
-    if (ktype == -1) {
-      return false;
-    }
-
-    vtype = readByte(input);
-    if (vtype == -1) {
-      return false;
-    }
-
-    len = readI32(input);
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    for (i = 0; i < len; i++) {
-      if (!(skip(input, ktype) && skip(input, vtype))) {
-        return false;
-      }
-    }
-    break;
-  }
-
-  case T_STRUCT: {
-    while (true) {
-      TType type;
-
-      type = readByte(input);
-      if (type == -1) {
-        return false;
-      }
-
-      if (type == T_STOP)
-        break;
-
-      SKIPBYTES(2); // tag
-      if (!skip(input, type)) {
-        return false;
-      }
-    }
-    break;
-  }
-
-  case T_STOP:
-  case T_VOID:
-  case T_UTF16:
-  case T_UTF8:
-  case T_U64:
-  default:
-    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
-    return false;
-
-  }
-
-  return true;
-
-#undef SKIPBYTES
-}
-
-
-/* --- HELPER FUNCTION FOR DECODE_VAL --- */
-
-static PyObject*
-decode_val(DecodeBuffer* input, TType type, PyObject* typeargs);
-
-static bool
-decode_struct(DecodeBuffer* input, PyObject* output, PyObject* spec_seq) {
-  int spec_seq_len = PyTuple_Size(spec_seq);
-  if (spec_seq_len == -1) {
-    return false;
-  }
-
-  while (true) {
-    TType type;
-    int16_t tag;
-    PyObject* item_spec;
-    PyObject* fieldval = NULL;
-    StructItemSpec parsedspec;
-
-    type = readByte(input);
-    if (type == -1) {
-      return false;
-    }
-    if (type == T_STOP) {
-      break;
-    }
-    tag = readI16(input);
-    if (INT_CONV_ERROR_OCCURRED(tag)) {
-      return false;
-    }
-    if (tag >= 0 && tag < spec_seq_len) {
-      item_spec = PyTuple_GET_ITEM(spec_seq, tag);
-    } else {
-      item_spec = Py_None;
-    }
-
-    if (item_spec == Py_None) {
-      if (!skip(input, type)) {
-        return false;
-      } else {
-        continue;
-      }
-    }
-
-    if (!parse_struct_item_spec(&parsedspec, item_spec)) {
-      return false;
-    }
-    if (parsedspec.type != type) {
-      if (!skip(input, type)) {
-        PyErr_SetString(PyExc_TypeError, "struct field had wrong type while reading and can't be skipped");
-        return false;
-      } else {
-        continue;
-      }
-    }
-
-    fieldval = decode_val(input, parsedspec.type, parsedspec.typeargs);
-    if (fieldval == NULL) {
-      return false;
-    }
-
-    if (PyObject_SetAttr(output, parsedspec.attrname, fieldval) == -1) {
-      Py_DECREF(fieldval);
-      return false;
-    }
-    Py_DECREF(fieldval);
-  }
-  return true;
-}
-
-
-/* --- MAIN RECURSIVE INPUT FUCNTION --- */
-
-// Returns a new reference.
-static PyObject*
-decode_val(DecodeBuffer* input, TType type, PyObject* typeargs) {
-  switch (type) {
-
-  case T_BOOL: {
-    int8_t v = readByte(input);
-    if (INT_CONV_ERROR_OCCURRED(v)) {
-      return NULL;
-    }
-
-    switch (v) {
-    case 0: Py_RETURN_FALSE;
-    case 1: Py_RETURN_TRUE;
-    // Don't laugh.  This is a potentially serious issue.
-    default: PyErr_SetString(PyExc_TypeError, "boolean out of range"); return NULL;
-    }
-    break;
-  }
-  case T_I08: {
-    int8_t v = readByte(input);
-    if (INT_CONV_ERROR_OCCURRED(v)) {
-      return NULL;
-    }
-
-    return PyInt_FromLong(v);
-  }
-  case T_I16: {
-    int16_t v = readI16(input);
-    if (INT_CONV_ERROR_OCCURRED(v)) {
-      return NULL;
-    }
-    return PyInt_FromLong(v);
-  }
-  case T_I32: {
-    int32_t v = readI32(input);
-    if (INT_CONV_ERROR_OCCURRED(v)) {
-      return NULL;
-    }
-    return PyInt_FromLong(v);
-  }
-
-  case T_I64: {
-    int64_t v = readI64(input);
-    if (INT_CONV_ERROR_OCCURRED(v)) {
-      return NULL;
-    }
-    // TODO(dreiss): Find out if we can take this fastpath always when
-    //               sizeof(long) == sizeof(long long).
-    if (CHECK_RANGE(v, LONG_MIN, LONG_MAX)) {
-      return PyInt_FromLong((long) v);
-    }
-
-    return PyLong_FromLongLong(v);
-  }
-
-  case T_DOUBLE: {
-    double v = readDouble(input);
-    if (v == -1.0 && PyErr_Occurred()) {
-      return false;
-    }
-    return PyFloat_FromDouble(v);
-  }
-
-  case T_STRING: {
-    Py_ssize_t len = readI32(input);
-    char* buf;
-    if (!readBytes(input, &buf, len)) {
-      return NULL;
-    }
-
-    return PyString_FromStringAndSize(buf, len);
-  }
-
-  case T_LIST:
-  case T_SET: {
-    SetListTypeArgs parsedargs;
-    int32_t len;
-    PyObject* ret = NULL;
-    int i;
-
-    if (!parse_set_list_args(&parsedargs, typeargs)) {
-      return NULL;
-    }
-
-    if (!checkTypeByte(input, parsedargs.element_type)) {
-      return NULL;
-    }
-
-    len = readI32(input);
-    if (!check_ssize_t_32(len)) {
-      return NULL;
-    }
-
-    ret = PyList_New(len);
-    if (!ret) {
-      return NULL;
-    }
-
-    for (i = 0; i < len; i++) {
-      PyObject* item = decode_val(input, parsedargs.element_type, parsedargs.typeargs);
-      if (!item) {
-        Py_DECREF(ret);
-        return NULL;
-      }
-      PyList_SET_ITEM(ret, i, item);
-    }
-
-    // TODO(dreiss): Consider biting the bullet and making two separate cases
-    //               for list and set, avoiding this post facto conversion.
-    if (type == T_SET) {
-      PyObject* setret;
-#if (PY_VERSION_HEX < 0x02050000)
-      // hack needed for older versions
-      setret = PyObject_CallFunctionObjArgs((PyObject*)&PySet_Type, ret, NULL);
-#else
-      // official version
-      setret = PySet_New(ret);
-#endif
-      Py_DECREF(ret);
-      return setret;
-    }
-    return ret;
-  }
-
-  case T_MAP: {
-    int32_t len;
-    int i;
-    MapTypeArgs parsedargs;
-    PyObject* ret = NULL;
-
-    if (!parse_map_args(&parsedargs, typeargs)) {
-      return NULL;
-    }
-
-    if (!checkTypeByte(input, parsedargs.ktag)) {
-      return NULL;
-    }
-    if (!checkTypeByte(input, parsedargs.vtag)) {
-      return NULL;
-    }
-
-    len = readI32(input);
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    ret = PyDict_New();
-    if (!ret) {
-      goto error;
-    }
-
-    for (i = 0; i < len; i++) {
-      PyObject* k = NULL;
-      PyObject* v = NULL;
-      k = decode_val(input, parsedargs.ktag, parsedargs.ktypeargs);
-      if (k == NULL) {
-        goto loop_error;
-      }
-      v = decode_val(input, parsedargs.vtag, parsedargs.vtypeargs);
-      if (v == NULL) {
-        goto loop_error;
-      }
-      if (PyDict_SetItem(ret, k, v) == -1) {
-        goto loop_error;
-      }
-
-      Py_DECREF(k);
-      Py_DECREF(v);
-      continue;
-
-      // Yuck!  Destructors, anyone?
-      loop_error:
-      Py_XDECREF(k);
-      Py_XDECREF(v);
-      goto error;
-    }
-
-    return ret;
-
-    error:
-    Py_XDECREF(ret);
-    return NULL;
-  }
-
-  case T_STRUCT: {
-    StructTypeArgs parsedargs;
-	PyObject* ret;
-    if (!parse_struct_args(&parsedargs, typeargs)) {
-      return NULL;
-    }
-
-    ret = PyObject_CallObject(parsedargs.klass, NULL);
-    if (!ret) {
-      return NULL;
-    }
-
-    if (!decode_struct(input, ret, parsedargs.spec)) {
-      Py_DECREF(ret);
-      return NULL;
-    }
-
-    return ret;
-  }
-
-  case T_STOP:
-  case T_VOID:
-  case T_UTF16:
-  case T_UTF8:
-  case T_U64:
-  default:
-    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
-    return NULL;
-  }
-}
-
-
-/* --- TOP-LEVEL WRAPPER FOR INPUT -- */
-
-static PyObject*
-decode_binary(PyObject *self, PyObject *args) {
-  PyObject* output_obj = NULL;
-  PyObject* transport = NULL;
-  PyObject* typeargs = NULL;
-  StructTypeArgs parsedargs;
-  DecodeBuffer input = {0, 0};
-  
-  if (!PyArg_ParseTuple(args, "OOO", &output_obj, &transport, &typeargs)) {
-    return NULL;
-  }
-
-  if (!parse_struct_args(&parsedargs, typeargs)) {
-    return NULL;
-  }
-
-  if (!decode_buffer_from_obj(&input, transport)) {
-    return NULL;
-  }
-
-  if (!decode_struct(&input, output_obj, parsedargs.spec)) {
-    free_decodebuf(&input);
-    return NULL;
-  }
-
-  free_decodebuf(&input);
-
-  Py_RETURN_NONE;
-}
-
-/* ====== END READING FUNCTIONS ====== */
-
-
-/* -- PYTHON MODULE SETUP STUFF --- */
-
-static PyMethodDef ThriftFastBinaryMethods[] = {
-
-  {"encode_binary",  encode_binary, METH_VARARGS, ""},
-  {"decode_binary",  decode_binary, METH_VARARGS, ""},
-
-  {NULL, NULL, 0, NULL}        /* Sentinel */
-};
-
-PyMODINIT_FUNC
-initfastbinary(void) {
-#define INIT_INTERN_STRING(value) \
-  do { \
-    INTERN_STRING(value) = PyString_InternFromString(#value); \
-    if(!INTERN_STRING(value)) return; \
-  } while(0)
-
-  INIT_INTERN_STRING(cstringio_buf);
-  INIT_INTERN_STRING(cstringio_refill);
-#undef INIT_INTERN_STRING
-
-  PycString_IMPORT;
-  if (PycStringIO == NULL) return;
-
-  (void) Py_InitModule("thrift.protocol.fastbinary", ThriftFastBinaryMethods);
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py
deleted file mode 100644
index 6ee18dd..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py
+++ /dev/null
@@ -1,87 +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.
-#
-
-import BaseHTTPServer
-
-from ..server import TServer
-from ..transport import TTransport
-
-
-class ResponseException(Exception):
-  """Allows handlers to override the HTTP response
-
-  Normally, THttpServer always sends a 200 response.  If a handler wants
-  to override this behavior (e.g., to simulate a misconfigured or
-  overloaded web server during testing), it can raise a ResponseException.
-  The function passed to the constructor will be called with the
-  RequestHandler as its only argument.
-  """
-  def __init__(self, handler):
-    self.handler = handler
-
-
-class THttpServer(TServer.TServer):
-  """A simple HTTP-based Thrift server
-
-  This class is not very performant, but it is useful (for example) for
-  acting as a mock version of an Apache-based PHP Thrift endpoint.
-  """
-  def __init__(self,
-               processor,
-               server_address,
-               inputProtocolFactory,
-               outputProtocolFactory=None,
-               server_class=BaseHTTPServer.HTTPServer):
-    """Set up protocol factories and HTTP server.
-
-    See BaseHTTPServer for server_address.
-    See TServer for protocol factories.
-    """
-    if outputProtocolFactory is None:
-      outputProtocolFactory = inputProtocolFactory
-
-    TServer.TServer.__init__(self, processor, None, None, None,
-        inputProtocolFactory, outputProtocolFactory)
-
-    thttpserver = self
-
-    class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
-      def do_POST(self):
-        # Don't care about the request path.
-        itrans = TTransport.TFileObjectTransport(self.rfile)
-        otrans = TTransport.TFileObjectTransport(self.wfile)
-        itrans = TTransport.TBufferedTransport(
-          itrans, int(self.headers['Content-Length']))
-        otrans = TTransport.TMemoryBuffer()
-        iprot = thttpserver.inputProtocolFactory.getProtocol(itrans)
-        oprot = thttpserver.outputProtocolFactory.getProtocol(otrans)
-        try:
-          thttpserver.processor.process(iprot, oprot)
-        except ResponseException, exn:
-          exn.handler(self)
-        else:
-          self.send_response(200)
-          self.send_header("content-type", "application/x-thrift")
-          self.end_headers()
-          self.wfile.write(otrans.getvalue())
-
-    self.httpd = server_class(server_address, RequestHander)
-
-  def serve(self):
-    self.httpd.serve_forever()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
deleted file mode 100644
index aa27991..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
+++ /dev/null
@@ -1,346 +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.
-#
-"""Implementation of non-blocking server.
-
-The main idea of the server is to receive and send requests
-only from the main thread.
-
-The thread poool should be sized for concurrent tasks, not
-maximum connections
-"""
-import threading
-import socket
-import Queue
-import select
-import struct
-import logging
-
-from ..transport import TTransport
-from ..protocol.TBinaryProtocol import TBinaryProtocolFactory
-
-__all__ = ['TNonblockingServer']
-
-
-class Worker(threading.Thread):
-    """Worker is a small helper to process incoming connection."""
-
-    def __init__(self, queue):
-        threading.Thread.__init__(self)
-        self.queue = queue
-
-    def run(self):
-        """Process queries from task queue, stop if processor is None."""
-        while True:
-            try:
-                processor, iprot, oprot, otrans, callback = self.queue.get()
-                if processor is None:
-                    break
-                processor.process(iprot, oprot)
-                callback(True, otrans.getvalue())
-            except Exception:
-                logging.exception("Exception while processing request")
-                callback(False, '')
-
-WAIT_LEN = 0
-WAIT_MESSAGE = 1
-WAIT_PROCESS = 2
-SEND_ANSWER = 3
-CLOSED = 4
-
-
-def locked(func):
-    """Decorator which locks self.lock."""
-    def nested(self, *args, **kwargs):
-        self.lock.acquire()
-        try:
-            return func(self, *args, **kwargs)
-        finally:
-            self.lock.release()
-    return nested
-
-
-def socket_exception(func):
-    """Decorator close object on socket.error."""
-    def read(self, *args, **kwargs):
-        try:
-            return func(self, *args, **kwargs)
-        except socket.error:
-            self.close()
-    return read
-
-
-class Connection:
-    """Basic class is represented connection.
-
-    It can be in state:
-        WAIT_LEN --- connection is reading request len.
-        WAIT_MESSAGE --- connection is reading request.
-        WAIT_PROCESS --- connection has just read whole request and
-                         waits for call ready routine.
-        SEND_ANSWER --- connection is sending answer string (including length
-                        of answer).
-        CLOSED --- socket was closed and connection should be deleted.
-    """
-    def __init__(self, new_socket, wake_up):
-        self.socket = new_socket
-        self.socket.setblocking(False)
-        self.status = WAIT_LEN
-        self.len = 0
-        self.message = ''
-        self.lock = threading.Lock()
-        self.wake_up = wake_up
-
-    def _read_len(self):
-        """Reads length of request.
-
-        It's a safer alternative to self.socket.recv(4)
-        """
-        read = self.socket.recv(4 - len(self.message))
-        if len(read) == 0:
-            # if we read 0 bytes and self.message is empty, then
-            # the client closed the connection
-            if len(self.message) != 0:
-                logging.error("can't read frame size from socket")
-            self.close()
-            return
-        self.message += read
-        if len(self.message) == 4:
-            self.len, = struct.unpack('!i', self.message)
-            if self.len < 0:
-                logging.error("negative frame size, it seems client "
-                              "doesn't use FramedTransport")
-                self.close()
-            elif self.len == 0:
-                logging.error("empty frame, it's really strange")
-                self.close()
-            else:
-                self.message = ''
-                self.status = WAIT_MESSAGE
-
-    @socket_exception
-    def read(self):
-        """Reads data from stream and switch state."""
-        assert self.status in (WAIT_LEN, WAIT_MESSAGE)
-        if self.status == WAIT_LEN:
-            self._read_len()
-            # go back to the main loop here for simplicity instead of
-            # falling through, even though there is a good chance that
-            # the message is already available
-        elif self.status == WAIT_MESSAGE:
-            read = self.socket.recv(self.len - len(self.message))
-            if len(read) == 0:
-                logging.error("can't read frame from socket (get %d of "
-                              "%d bytes)" % (len(self.message), self.len))
-                self.close()
-                return
-            self.message += read
-            if len(self.message) == self.len:
-                self.status = WAIT_PROCESS
-
-    @socket_exception
-    def write(self):
-        """Writes data from socket and switch state."""
-        assert self.status == SEND_ANSWER
-        sent = self.socket.send(self.message)
-        if sent == len(self.message):
-            self.status = WAIT_LEN
-            self.message = ''
-            self.len = 0
-        else:
-            self.message = self.message[sent:]
-
-    @locked
-    def ready(self, all_ok, message):
-        """Callback function for switching state and waking up main thread.
-
-        This function is the only function witch can be called asynchronous.
-
-        The ready can switch Connection to three states:
-            WAIT_LEN if request was oneway.
-            SEND_ANSWER if request was processed in normal way.
-            CLOSED if request throws unexpected exception.
-
-        The one wakes up main thread.
-        """
-        assert self.status == WAIT_PROCESS
-        if not all_ok:
-            self.close()
-            self.wake_up()
-            return
-        self.len = ''
-        if len(message) == 0:
-            # it was a oneway request, do not write answer
-            self.message = ''
-            self.status = WAIT_LEN
-        else:
-            self.message = struct.pack('!i', len(message)) + message
-            self.status = SEND_ANSWER
-        self.wake_up()
-
-    @locked
-    def is_writeable(self):
-        """Return True if connection should be added to write list of select"""
-        return self.status == SEND_ANSWER
-
-    # it's not necessary, but...
-    @locked
-    def is_readable(self):
-        """Return True if connection should be added to read list of select"""
-        return self.status in (WAIT_LEN, WAIT_MESSAGE)
-
-    @locked
-    def is_closed(self):
-        """Returns True if connection is closed."""
-        return self.status == CLOSED
-
-    def fileno(self):
-        """Returns the file descriptor of the associated socket."""
-        return self.socket.fileno()
-
-    def close(self):
-        """Closes connection"""
-        self.status = CLOSED
-        self.socket.close()
-
-
-class TNonblockingServer:
-    """Non-blocking server."""
-
-    def __init__(self,
-                 processor,
-                 lsocket,
-                 inputProtocolFactory=None,
-                 outputProtocolFactory=None,
-                 threads=10):
-        self.processor = processor
-        self.socket = lsocket
-        self.in_protocol = inputProtocolFactory or TBinaryProtocolFactory()
-        self.out_protocol = outputProtocolFactory or self.in_protocol
-        self.threads = int(threads)
-        self.clients = {}
-        self.tasks = Queue.Queue()
-        self._read, self._write = socket.socketpair()
-        self.prepared = False
-        self._stop = False
-
-    def setNumThreads(self, num):
-        """Set the number of worker threads that should be created."""
-        # implement ThreadPool interface
-        assert not self.prepared, "Can't change number of threads after start"
-        self.threads = num
-
-    def prepare(self):
-        """Prepares server for serve requests."""
-        if self.prepared:
-            return
-        self.socket.listen()
-        for _ in xrange(self.threads):
-            thread = Worker(self.tasks)
-            thread.setDaemon(True)
-            thread.start()
-        self.prepared = True
-
-    def wake_up(self):
-        """Wake up main thread.
-
-        The server usualy waits in select call in we should terminate one.
-        The simplest way is using socketpair.
-
-        Select always wait to read from the first socket of socketpair.
-
-        In this case, we can just write anything to the second socket from
-        socketpair.
-        """
-        self._write.send('1')
-
-    def stop(self):
-        """Stop the server.
-
-        This method causes the serve() method to return.  stop() may be invoked
-        from within your handler, or from another thread.
-
-        After stop() is called, serve() will return but the server will still
-        be listening on the socket.  serve() may then be called again to resume
-        processing requests.  Alternatively, close() may be called after
-        serve() returns to close the server socket and shutdown all worker
-        threads.
-        """
-        self._stop = True
-        self.wake_up()
-
-    def _select(self):
-        """Does select on open connections."""
-        readable = [self.socket.handle.fileno(), self._read.fileno()]
-        writable = []
-        for i, connection in self.clients.items():
-            if connection.is_readable():
-                readable.append(connection.fileno())
-            if connection.is_writeable():
-                writable.append(connection.fileno())
-            if connection.is_closed():
-                del self.clients[i]
-        return select.select(readable, writable, readable)
-
-    def handle(self):
-        """Handle requests.
-
-        WARNING! You must call prepare() BEFORE calling handle()
-        """
-        assert self.prepared, "You have to call prepare before handle"
-        rset, wset, xset = self._select()
-        for readable in rset:
-            if readable == self._read.fileno():
-                # don't care i just need to clean readable flag
-                self._read.recv(1024)
-            elif readable == self.socket.handle.fileno():
-                client = self.socket.accept().handle
-                self.clients[client.fileno()] = Connection(client,
-                                                           self.wake_up)
-            else:
-                connection = self.clients[readable]
-                connection.read()
-                if connection.status == WAIT_PROCESS:
-                    itransport = TTransport.TMemoryBuffer(connection.message)
-                    otransport = TTransport.TMemoryBuffer()
-                    iprot = self.in_protocol.getProtocol(itransport)
-                    oprot = self.out_protocol.getProtocol(otransport)
-                    self.tasks.put([self.processor, iprot, oprot,
-                                    otransport, connection.ready])
-        for writeable in wset:
-            self.clients[writeable].write()
-        for oob in xset:
-            self.clients[oob].close()
-            del self.clients[oob]
-
-    def close(self):
-        """Closes the server."""
-        for _ in xrange(self.threads):
-            self.tasks.put([None, None, None, None, None])
-        self.socket.close()
-        self.prepared = False
-
-    def serve(self):
-        """Serve requests.
-
-        Serve requests forever, or until stop() is called.
-        """
-        self._stop = False
-        self.prepare()
-        while not self._stop:
-            self.handle()


[19/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
deleted file mode 100644
index 1859d8a..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
+++ /dev/null
@@ -1,202 +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.
-
-from thrift.publisher import *
-from ..util.log import *
-
-
-class StreamDefinition:
-    """
-    Represents a BAM/CEP stream definition
-    """
-
-    STRING = 'STRING'
-    DOUBLE = 'DOUBLE'
-    INT = 'INT'
-    LONG = 'LONG'
-    BOOL = 'BOOL'
-
-    def __init__(self):
-        self.name = None
-        """:type : str"""
-        self.version = None
-        """:type : str"""
-        self.nickname = None
-        """:type : str"""
-        self.description = None
-        """:type : str"""
-        self.meta_data = []
-        """:type : list[str]"""
-        self.correlation_data = []
-        """:type : list[str]"""
-        self.payload_data = []
-        """:type : list[str]"""
-        self.stream_id =  None
-        """ :type : str """
-
-    def add_metadata_attribute(self, attr_name, attr_type):
-        self.meta_data.append({"name": attr_name, "type": attr_type})
-
-    def add_payloaddata_attribute(self, attr_name, attr_type):
-        self.payload_data.append({"name": attr_name, "type": attr_type})
-
-    def add_correlationdata_attribute(self, attr_name, attr_type):
-        self.correlation_data.append({"name": attr_name, "type": attr_type})
-
-    def __str__(self):
-        """
-        To string override
-        """
-
-        json_str = "{"
-        json_str += "\"name\":\"" + self.name + "\","
-        json_str += "\"version\":\"" + self.version + "\","
-        json_str += "\"nickName\":\"" + self.nickname + "\","
-        json_str += "\"description\":\"" + self.description + "\","
-
-        # add metadata attributes if exists
-        if len(self.meta_data) > 0:
-            json_str += "\"metaData\":["
-            for metadatum in self.meta_data:
-                json_str += "{\"name\":\"" + metadatum["name"] + "\", \"type\": \"" + metadatum["type"] + "\"},"
-
-            json_str = json_str[:-1] + "],"
-
-        # add correlationdata attributes if exists
-        if len(self.correlation_data) > 0:
-            json_str += "\"correlationData\":["
-            for coredatum in self.correlation_data:
-                json_str += "{\"name\":\"" + coredatum["name"] + "\", \"type\": \"" + coredatum["type"] + "\"},"
-
-            json_str = json_str[:-1] + "],"
-
-        # add payloaddata attributes if exists
-        if len(self.payload_data) > 0:
-            json_str += "\"payloadData\":["
-            for payloaddatum in self.payload_data:
-                json_str += "{\"name\":\"" + payloaddatum["name"] + "\", \"type\": \"" + payloaddatum["type"] + "\"},"
-
-            json_str = json_str[:-1] + "],"
-
-        json_str = json_str[:-1] + "}"
-
-        return json_str
-
-
-class ThriftEvent:
-    """
-    Represents an event to be published to a BAM/CEP monitoring server
-    """
-    def __init__(self):
-        self.metaData = []
-        """:type : list[str]"""
-        self.correlationData = []
-        """:type : list[str]"""
-        self.payloadData = []
-        """:type : list[str]"""
-
-
-class ThriftPublisher:
-    """
-    Handles publishing events to BAM/CEP through thrift using the provided address and credentials
-    """
-    log = LogFactory().get_log(__name__)
-
-    def __init__(self, ip, port, username, password, stream_definition):
-        """
-        Initializes a ThriftPublisher object.
-
-        At initialization a ThriftPublisher connects and defines a stream definition. A connection
-        should be disconnected after all the publishing has been done.
-
-        :param str ip: IP address of the monitoring server
-        :param str port: Port of the monitoring server
-        :param str username: Username
-        :param str password: Password
-        :param StreamDefinition stream_definition: StreamDefinition object for this particular connection
-        :return: ThriftPublisher object
-        :rtype: ThriftPublisher
-        """
-        try:
-            port_number = int(port)
-        except ValueError:
-            raise RuntimeError("Port number for Thrift Publisher is invalid: %r" % port)
-
-        self.__publisher = Publisher(ip, port_number)
-        self.__publisher.connect(username, password)
-        self.__publisher.defineStream(str(stream_definition))
-
-        self.stream_definition = stream_definition
-        self.stream_id = self.__publisher.streamId
-        self.ip = ip
-        self.port = port
-        self.username = username
-        self.password = password
-
-    def publish(self, event):
-        """
-        Publishes the given event by creating the event bundle from the log event
-
-        :param ThriftEvent event: The log event to be published
-        :return: void
-        """
-        event_bundler = EventBundle()
-        ThriftPublisher.assign_attributes(event.metaData, event_bundler)
-        ThriftPublisher.assign_attributes(event.correlationData, event_bundler)
-        ThriftPublisher.assign_attributes(event.payloadData, event_bundler)
-
-        self.__publisher.publish(event_bundler)
-        self.log.debug("Published event to thrift stream [%r]" % self.stream_id)
-
-    def disconnect(self):
-        """
-        Disconnect the thrift publisher
-        :return: void
-        """
-        self.__publisher.disconnect()
-
-    @staticmethod
-    def assign_attributes(attributes, event_bundler):
-        """
-        Adds the given attributes to the given event bundler according to type of each attribute
-        :param list attributes: attributes to be assigned
-        :param EventBundle event_bundler: Event bundle to assign attributes to
-        :return: void
-        """
-
-        # __intAttributeList = []
-        # __longAttributeList = []
-        # __doubleAttributeList = []
-        # __boolAttributeList = []
-        # __stringAttributeList = []
-
-        if attributes is not None and len(attributes) > 0:
-            for attrib in attributes:
-                if isinstance(attrib, int):
-                    event_bundler.addIntAttribute(attrib)
-                elif isinstance(attrib, long):
-                    event_bundler.addLongAttribute(attrib)
-                elif isinstance(attrib, float):
-                    event_bundler.addDoubleAttribute(attrib)
-                elif isinstance(attrib, bool):
-                    event_bundler.addBoolAttribute(attrib)
-                elif isinstance(attrib, str):
-                    event_bundler.addStringAttribute(attrib)
-                else:
-                    ThriftPublisher.log.error("Undefined attribute type: %r" % attrib)
-        else:
-            ThriftPublisher.log.debug("Empty attribute list")

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/__init__.py
deleted file mode 100644
index adefd8e..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-__all__ = ['ttypes', 'constants']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/constants.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/constants.py
deleted file mode 100644
index 36943ba..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/constants.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/ttypes.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/ttypes.py
deleted file mode 100644
index d76afca..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Data/ttypes.py
+++ /dev/null
@@ -1,320 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
-
-from ...thrift.transport import TTransport
-from ...thrift.protocol import TBinaryProtocol, TProtocol
-try:
-  from ...thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-
-class ThriftAttributeType:
-  INT = 0
-  LONG = 1
-  FLOAT = 2
-  DOUBLE = 3
-  BOOL = 4
-  STRING = 5
-
-  _VALUES_TO_NAMES = {
-    0: "INT",
-    1: "LONG",
-    2: "FLOAT",
-    3: "DOUBLE",
-    4: "BOOL",
-    5: "STRING",
-  }
-
-  _NAMES_TO_VALUES = {
-    "INT": 0,
-    "LONG": 1,
-    "FLOAT": 2,
-    "DOUBLE": 3,
-    "BOOL": 4,
-    "STRING": 5,
-  }
-
-
-class ThriftAttribute:
-  """
-  Attributes:
-   - name
-   - attributeType
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'name', None, None, ), # 1
-    (2, TType.I32, 'attributeType', None, None, ), # 2
-  )
-
-  def __init__(self, name=None, attributeType=None,):
-    self.name = name
-    self.attributeType = attributeType
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.name = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.I32:
-          self.attributeType = iprot.readI32();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftAttribute')
-    if self.name is not None:
-      oprot.writeFieldBegin('name', TType.STRING, 1)
-      oprot.writeString(self.name)
-      oprot.writeFieldEnd()
-    if self.attributeType is not None:
-      oprot.writeFieldBegin('attributeType', TType.I32, 2)
-      oprot.writeI32(self.attributeType)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftEventBundle:
-  """
-  Attributes:
-   - sessionId
-   - eventNum
-   - intAttributeList
-   - longAttributeList
-   - doubleAttributeList
-   - boolAttributeList
-   - stringAttributeList
-   - arbitraryDataMapMap
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.I32, 'eventNum', None, None, ), # 2
-    (3, TType.LIST, 'intAttributeList', (TType.I32,None), None, ), # 3
-    (4, TType.LIST, 'longAttributeList', (TType.I64,None), None, ), # 4
-    (5, TType.LIST, 'doubleAttributeList', (TType.DOUBLE,None), None, ), # 5
-    (6, TType.LIST, 'boolAttributeList', (TType.BOOL,None), None, ), # 6
-    (7, TType.LIST, 'stringAttributeList', (TType.STRING,None), None, ), # 7
-    (8, TType.MAP, 'arbitraryDataMapMap', (TType.I32,None,TType.MAP,(TType.STRING,None,TType.STRING,None)), None, ), # 8
-  )
-
-  def __init__(self, sessionId=None, eventNum=None, intAttributeList=None, longAttributeList=None, doubleAttributeList=None, boolAttributeList=None, stringAttributeList=None, arbitraryDataMapMap=None,):
-    self.sessionId = sessionId
-    self.eventNum = eventNum
-    self.intAttributeList = intAttributeList
-    self.longAttributeList = longAttributeList
-    self.doubleAttributeList = doubleAttributeList
-    self.boolAttributeList = boolAttributeList
-    self.stringAttributeList = stringAttributeList
-    self.arbitraryDataMapMap = arbitraryDataMapMap
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.I32:
-          self.eventNum = iprot.readI32();
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.LIST:
-          self.intAttributeList = []
-          (_etype3, _size0) = iprot.readListBegin()
-          for _i4 in xrange(_size0):
-            _elem5 = iprot.readI32();
-            self.intAttributeList.append(_elem5)
-          iprot.readListEnd()
-        else:
-          iprot.skip(ftype)
-      elif fid == 4:
-        if ftype == TType.LIST:
-          self.longAttributeList = []
-          (_etype9, _size6) = iprot.readListBegin()
-          for _i10 in xrange(_size6):
-            _elem11 = iprot.readI64();
-            self.longAttributeList.append(_elem11)
-          iprot.readListEnd()
-        else:
-          iprot.skip(ftype)
-      elif fid == 5:
-        if ftype == TType.LIST:
-          self.doubleAttributeList = []
-          (_etype15, _size12) = iprot.readListBegin()
-          for _i16 in xrange(_size12):
-            _elem17 = iprot.readDouble();
-            self.doubleAttributeList.append(_elem17)
-          iprot.readListEnd()
-        else:
-          iprot.skip(ftype)
-      elif fid == 6:
-        if ftype == TType.LIST:
-          self.boolAttributeList = []
-          (_etype21, _size18) = iprot.readListBegin()
-          for _i22 in xrange(_size18):
-            _elem23 = iprot.readBool();
-            self.boolAttributeList.append(_elem23)
-          iprot.readListEnd()
-        else:
-          iprot.skip(ftype)
-      elif fid == 7:
-        if ftype == TType.LIST:
-          self.stringAttributeList = []
-          (_etype27, _size24) = iprot.readListBegin()
-          for _i28 in xrange(_size24):
-            _elem29 = iprot.readString();
-            self.stringAttributeList.append(_elem29)
-          iprot.readListEnd()
-        else:
-          iprot.skip(ftype)
-      elif fid == 8:
-        if ftype == TType.MAP:
-          self.arbitraryDataMapMap = {}
-          (_ktype31, _vtype32, _size30 ) = iprot.readMapBegin()
-          for _i34 in xrange(_size30):
-            _key35 = iprot.readI32();
-            _val36 = {}
-            (_ktype38, _vtype39, _size37 ) = iprot.readMapBegin()
-            for _i41 in xrange(_size37):
-              _key42 = iprot.readString();
-              _val43 = iprot.readString();
-              _val36[_key42] = _val43
-            iprot.readMapEnd()
-            self.arbitraryDataMapMap[_key35] = _val36
-          iprot.readMapEnd()
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftEventBundle')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.eventNum is not None:
-      oprot.writeFieldBegin('eventNum', TType.I32, 2)
-      oprot.writeI32(self.eventNum)
-      oprot.writeFieldEnd()
-    if self.intAttributeList is not None:
-      oprot.writeFieldBegin('intAttributeList', TType.LIST, 3)
-      oprot.writeListBegin(TType.I32, len(self.intAttributeList))
-      for iter44 in self.intAttributeList:
-        oprot.writeI32(iter44)
-      oprot.writeListEnd()
-      oprot.writeFieldEnd()
-    if self.longAttributeList is not None:
-      oprot.writeFieldBegin('longAttributeList', TType.LIST, 4)
-      oprot.writeListBegin(TType.I64, len(self.longAttributeList))
-      for iter45 in self.longAttributeList:
-        oprot.writeI64(iter45)
-      oprot.writeListEnd()
-      oprot.writeFieldEnd()
-    if self.doubleAttributeList is not None:
-      oprot.writeFieldBegin('doubleAttributeList', TType.LIST, 5)
-      oprot.writeListBegin(TType.DOUBLE, len(self.doubleAttributeList))
-      for iter46 in self.doubleAttributeList:
-        oprot.writeDouble(iter46)
-      oprot.writeListEnd()
-      oprot.writeFieldEnd()
-    if self.boolAttributeList is not None:
-      oprot.writeFieldBegin('boolAttributeList', TType.LIST, 6)
-      oprot.writeListBegin(TType.BOOL, len(self.boolAttributeList))
-      for iter47 in self.boolAttributeList:
-        oprot.writeBool(iter47)
-      oprot.writeListEnd()
-      oprot.writeFieldEnd()
-    if self.stringAttributeList is not None:
-      oprot.writeFieldBegin('stringAttributeList', TType.LIST, 7)
-      oprot.writeListBegin(TType.STRING, len(self.stringAttributeList))
-      for iter48 in self.stringAttributeList:
-        oprot.writeString(iter48)
-      oprot.writeListEnd()
-      oprot.writeFieldEnd()
-    if self.arbitraryDataMapMap is not None:
-      oprot.writeFieldBegin('arbitraryDataMapMap', TType.MAP, 8)
-      oprot.writeMapBegin(TType.I32, TType.MAP, len(self.arbitraryDataMapMap))
-      for kiter49,viter50 in self.arbitraryDataMapMap.items():
-        oprot.writeI32(kiter49)
-        oprot.writeMapBegin(TType.STRING, TType.STRING, len(viter50))
-        for kiter51,viter52 in viter50.items():
-          oprot.writeString(kiter51)
-          oprot.writeString(viter52)
-        oprot.writeMapEnd()
-      oprot.writeMapEnd()
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/__init__.py
deleted file mode 100644
index adefd8e..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-__all__ = ['ttypes', 'constants']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/constants.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/constants.py
deleted file mode 100644
index 36943ba..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/constants.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/ttypes.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/ttypes.py
deleted file mode 100644
index 9fbb1ce..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/Exception/ttypes.py
+++ /dev/null
@@ -1,473 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
-
-from ...thrift.transport import TTransport
-from ...thrift.protocol import TBinaryProtocol, TProtocol
-try:
-  from ...thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-
-
-class ThriftStreamDefinitionException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftStreamDefinitionException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftNoStreamDefinitionExistException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftNoStreamDefinitionExistException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftDifferentStreamDefinitionAlreadyDefinedException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftDifferentStreamDefinitionAlreadyDefinedException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftMalformedStreamDefinitionException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftMalformedStreamDefinitionException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftUndefinedEventTypeException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftUndefinedEventTypeException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftSessionExpiredException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftSessionExpiredException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftAuthenticationException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftAuthenticationException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
deleted file mode 100755
index 0d18f58..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/usr/bin/env python
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-import sys
-import pprint
-from urlparse import urlparse
-
-from thrift.transport import TTransport
-from thrift.transport import TSocket
-from thrift.transport import THttpClient
-from thrift.protocol import TBinaryProtocol
-from ThriftEventTransmissionService import ThriftEventTransmissionService
-from ThriftEventTransmissionService.ttypes import *
-
-
-if len(sys.argv) <= 1 or sys.argv[1] == '--help':
-  print ''
-  print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
-  print ''
-  print 'Functions:'
-  print '  string defineStream(string sessionId, string streamDefinition)'
-  print '  string findStreamId(string sessionId, string streamName, string streamVersion)'
-  print '  void publish(ThriftEventBundle eventBundle)'
-  print '  bool deleteStreamById(string sessionId, string streamId)'
-  print '  bool deleteStreamByNameVersion(string sessionId, string streamName, string streamVersion)'
-  print ''
-  sys.exit(0)
-
-pp = pprint.PrettyPrinter(indent = 2)
-host = 'localhost'
-port = 9090
-uri = ''
-framed = False
-http = False
-argi = 1
-
-if sys.argv[argi] == '-h':
-  parts = sys.argv[argi+1].split(':')
-  host = parts[0]
-  if len(parts) > 1:
-    port = int(parts[1])
-  argi += 2
-
-if sys.argv[argi] == '-u':
-  url = urlparse(sys.argv[argi+1])
-  parts = url[1].split(':')
-  host = parts[0]
-  if len(parts) > 1:
-    port = int(parts[1])
-  else:
-    port = 80
-  uri = url[2]
-  if url[4]:
-    uri += '?%s' % url[4]
-  http = True
-  argi += 2
-
-if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
-  framed = True
-  argi += 1
-
-cmd = sys.argv[argi]
-args = sys.argv[argi+1:]
-
-if http:
-  transport = THttpClient.THttpClient(host, port, uri)
-else:
-  socket = TSocket.TSocket(host, port)
-  if framed:
-    transport = TTransport.TFramedTransport(socket)
-  else:
-    transport = TTransport.TBufferedTransport(socket)
-protocol = TBinaryProtocol.TBinaryProtocol(transport)
-client = ThriftEventTransmissionService.Client(protocol)
-transport.open()
-
-if cmd == 'defineStream':
-  if len(args) != 2:
-    print 'defineStream requires 2 args'
-    sys.exit(1)
-  pp.pprint(client.defineStream(args[0],args[1],))
-
-elif cmd == 'findStreamId':
-  if len(args) != 3:
-    print 'findStreamId requires 3 args'
-    sys.exit(1)
-  pp.pprint(client.findStreamId(args[0],args[1],args[2],))
-
-elif cmd == 'publish':
-  if len(args) != 1:
-    print 'publish requires 1 args'
-    sys.exit(1)
-  pp.pprint(client.publish(eval(args[0]),))
-
-elif cmd == 'deleteStreamById':
-  if len(args) != 2:
-    print 'deleteStreamById requires 2 args'
-    sys.exit(1)
-  pp.pprint(client.deleteStreamById(args[0],args[1],))
-
-elif cmd == 'deleteStreamByNameVersion':
-  if len(args) != 3:
-    print 'deleteStreamByNameVersion requires 3 args'
-    sys.exit(1)
-  pp.pprint(client.deleteStreamByNameVersion(args[0],args[1],args[2],))
-
-else:
-  print 'Unrecognized method %s' % cmd
-  sys.exit(1)
-
-transport.close()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
deleted file mode 100644
index 4a5a252..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
+++ /dev/null
@@ -1,1143 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ttypes import *
-from ...thrift.Thrift import TProcessor
-from ...thrift.transport import TTransport
-
-try:
-  from ...thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-
-class Iface:
-  def defineStream(self, sessionId, streamDefinition):
-    """
-    Parameters:
-     - sessionId
-     - streamDefinition
-    """
-    pass
-
-  def findStreamId(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    pass
-
-  def publish(self, eventBundle):
-    """
-    Parameters:
-     - eventBundle
-    """
-    pass
-
-  def deleteStreamById(self, sessionId, streamId):
-    """
-    Parameters:
-     - sessionId
-     - streamId
-    """
-    pass
-
-  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    pass
-
-
-class Client(Iface):
-  def __init__(self, iprot, oprot=None):
-    self._iprot = self._oprot = iprot
-    if oprot is not None:
-      self._oprot = oprot
-    self._seqid = 0
-
-  def defineStream(self, sessionId, streamDefinition):
-    """
-    Parameters:
-     - sessionId
-     - streamDefinition
-    """
-    self.send_defineStream(sessionId, streamDefinition)
-    return self.recv_defineStream()
-
-  def send_defineStream(self, sessionId, streamDefinition):
-    self._oprot.writeMessageBegin('defineStream', TMessageType.CALL, self._seqid)
-    args = defineStream_args()
-    args.sessionId = sessionId
-    args.streamDefinition = streamDefinition
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_defineStream(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = defineStream_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.ade is not None:
-      raise result.ade
-    if result.mtd is not None:
-      raise result.mtd
-    if result.tde is not None:
-      raise result.tde
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "defineStream failed: unknown result");
-
-  def findStreamId(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    self.send_findStreamId(sessionId, streamName, streamVersion)
-    return self.recv_findStreamId()
-
-  def send_findStreamId(self, sessionId, streamName, streamVersion):
-    self._oprot.writeMessageBegin('findStreamId', TMessageType.CALL, self._seqid)
-    args = findStreamId_args()
-    args.sessionId = sessionId
-    args.streamName = streamName
-    args.streamVersion = streamVersion
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_findStreamId(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = findStreamId_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.tnde is not None:
-      raise result.tnde
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "findStreamId failed: unknown result");
-
-  def publish(self, eventBundle):
-    """
-    Parameters:
-     - eventBundle
-    """
-    self.send_publish(eventBundle)
-    self.recv_publish()
-
-  def send_publish(self, eventBundle):
-    self._oprot.writeMessageBegin('publish', TMessageType.CALL, self._seqid)
-    args = publish_args()
-    args.eventBundle = eventBundle
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_publish(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = publish_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.ue is not None:
-      raise result.ue
-    if result.se is not None:
-      raise result.se
-    return
-
-  def deleteStreamById(self, sessionId, streamId):
-    """
-    Parameters:
-     - sessionId
-     - streamId
-    """
-    self.send_deleteStreamById(sessionId, streamId)
-    return self.recv_deleteStreamById()
-
-  def send_deleteStreamById(self, sessionId, streamId):
-    self._oprot.writeMessageBegin('deleteStreamById', TMessageType.CALL, self._seqid)
-    args = deleteStreamById_args()
-    args.sessionId = sessionId
-    args.streamId = streamId
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_deleteStreamById(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = deleteStreamById_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamById failed: unknown result");
-
-  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    self.send_deleteStreamByNameVersion(sessionId, streamName, streamVersion)
-    return self.recv_deleteStreamByNameVersion()
-
-  def send_deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    self._oprot.writeMessageBegin('deleteStreamByNameVersion', TMessageType.CALL, self._seqid)
-    args = deleteStreamByNameVersion_args()
-    args.sessionId = sessionId
-    args.streamName = streamName
-    args.streamVersion = streamVersion
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_deleteStreamByNameVersion(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = deleteStreamByNameVersion_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamByNameVersion failed: unknown result");
-
-
-class Processor(Iface, TProcessor):
-  def __init__(self, handler):
-    self._handler = handler
-    self._processMap = {}
-    self._processMap["defineStream"] = Processor.process_defineStream
-    self._processMap["findStreamId"] = Processor.process_findStreamId
-    self._processMap["publish"] = Processor.process_publish
-    self._processMap["deleteStreamById"] = Processor.process_deleteStreamById
-    self._processMap["deleteStreamByNameVersion"] = Processor.process_deleteStreamByNameVersion
-
-  def process(self, iprot, oprot):
-    (name, type, seqid) = iprot.readMessageBegin()
-    if name not in self._processMap:
-      iprot.skip(TType.STRUCT)
-      iprot.readMessageEnd()
-      x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
-      oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
-      x.write(oprot)
-      oprot.writeMessageEnd()
-      oprot.trans.flush()
-      return
-    else:
-      self._processMap[name](self, seqid, iprot, oprot)
-    return True
-
-  def process_defineStream(self, seqid, iprot, oprot):
-    args = defineStream_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = defineStream_result()
-    try:
-      result.success = self._handler.defineStream(args.sessionId, args.streamDefinition)
-    except Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ade:
-      result.ade = ade
-    except Exception.ttypes.ThriftMalformedStreamDefinitionException, mtd:
-      result.mtd = mtd
-    except Exception.ttypes.ThriftStreamDefinitionException, tde:
-      result.tde = tde
-    except Exception.ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("defineStream", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_findStreamId(self, seqid, iprot, oprot):
-    args = findStreamId_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = findStreamId_result()
-    try:
-      result.success = self._handler.findStreamId(args.sessionId, args.streamName, args.streamVersion)
-    except Exception.ttypes.ThriftNoStreamDefinitionExistException, tnde:
-      result.tnde = tnde
-    except Exception.ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("findStreamId", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_publish(self, seqid, iprot, oprot):
-    args = publish_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = publish_result()
-    try:
-      self._handler.publish(args.eventBundle)
-    except Exception.ttypes.ThriftUndefinedEventTypeException, ue:
-      result.ue = ue
-    except Exception.ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("publish", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_deleteStreamById(self, seqid, iprot, oprot):
-    args = deleteStreamById_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = deleteStreamById_result()
-    try:
-      result.success = self._handler.deleteStreamById(args.sessionId, args.streamId)
-    except Exception.ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("deleteStreamById", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_deleteStreamByNameVersion(self, seqid, iprot, oprot):
-    args = deleteStreamByNameVersion_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = deleteStreamByNameVersion_result()
-    try:
-      result.success = self._handler.deleteStreamByNameVersion(args.sessionId, args.streamName, args.streamVersion)
-    except Exception.ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("deleteStreamByNameVersion", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-
-# HELPER FUNCTIONS AND STRUCTURES
-
-class defineStream_args:
-  """
-  Attributes:
-   - sessionId
-   - streamDefinition
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamDefinition', None, None, ), # 2
-  )
-
-  def __init__(self, sessionId=None, streamDefinition=None,):
-    self.sessionId = sessionId
-    self.streamDefinition = streamDefinition
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamDefinition = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('defineStream_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamDefinition is not None:
-      oprot.writeFieldBegin('streamDefinition', TType.STRING, 2)
-      oprot.writeString(self.streamDefinition)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class defineStream_result:
-  """
-  Attributes:
-   - success
-   - ade
-   - mtd
-   - tde
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.STRING, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'ade', (Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'mtd', (Exception.ttypes.ThriftMalformedStreamDefinitionException, Exception.ttypes.ThriftMalformedStreamDefinitionException.thrift_spec), None, ), # 2
-    (3, TType.STRUCT, 'tde', (Exception.ttypes.ThriftStreamDefinitionException, Exception.ttypes.ThriftStreamDefinitionException.thrift_spec), None, ), # 3
-    (4, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 4
-  )
-
-  def __init__(self, success=None, ade=None, mtd=None, tde=None, se=None,):
-    self.success = success
-    self.ade = ade
-    self.mtd = mtd
-    self.tde = tde
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.STRING:
-          self.success = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.ade = Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException()
-          self.ade.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.mtd = Exception.ttypes.ThriftMalformedStreamDefinitionException()
-          self.mtd.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRUCT:
-          self.tde = Exception.ttypes.ThriftStreamDefinitionException()
-          self.tde.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 4:
-        if ftype == TType.STRUCT:
-          self.se = Exception.ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('defineStream_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.STRING, 0)
-      oprot.writeString(self.success)
-      oprot.writeFieldEnd()
-    if self.ade is not None:
-      oprot.writeFieldBegin('ade', TType.STRUCT, 1)
-      self.ade.write(oprot)
-      oprot.writeFieldEnd()
-    if self.mtd is not None:
-      oprot.writeFieldBegin('mtd', TType.STRUCT, 2)
-      self.mtd.write(oprot)
-      oprot.writeFieldEnd()
-    if self.tde is not None:
-      oprot.writeFieldBegin('tde', TType.STRUCT, 3)
-      self.tde.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 4)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class findStreamId_args:
-  """
-  Attributes:
-   - sessionId
-   - streamName
-   - streamVersion
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamName', None, None, ), # 2
-    (3, TType.STRING, 'streamVersion', None, None, ), # 3
-  )
-
-  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
-    self.sessionId = sessionId
-    self.streamName = streamName
-    self.streamVersion = streamVersion
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamName = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRING:
-          self.streamVersion = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('findStreamId_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamName is not None:
-      oprot.writeFieldBegin('streamName', TType.STRING, 2)
-      oprot.writeString(self.streamName)
-      oprot.writeFieldEnd()
-    if self.streamVersion is not None:
-      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
-      oprot.writeString(self.streamVersion)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class findStreamId_result:
-  """
-  Attributes:
-   - success
-   - tnde
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.STRING, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'tnde', (Exception.ttypes.ThriftNoStreamDefinitionExistException, Exception.ttypes.ThriftNoStreamDefinitionExistException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
-  )
-
-  def __init__(self, success=None, tnde=None, se=None,):
-    self.success = success
-    self.tnde = tnde
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.STRING:
-          self.success = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.tnde = Exception.ttypes.ThriftNoStreamDefinitionExistException()
-          self.tnde.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.se = Exception.ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('findStreamId_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.STRING, 0)
-      oprot.writeString(self.success)
-      oprot.writeFieldEnd()
-    if self.tnde is not None:
-      oprot.writeFieldBegin('tnde', TType.STRUCT, 1)
-      self.tnde.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 2)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class publish_args:
-  """
-  Attributes:
-   - eventBundle
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRUCT, 'eventBundle', (Data.ttypes.ThriftEventBundle, Data.ttypes.ThriftEventBundle.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, eventBundle=None,):
-    self.eventBundle = eventBundle
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRUCT:
-          self.eventBundle = Data.ttypes.ThriftEventBundle()
-          self.eventBundle.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('publish_args')
-    if self.eventBundle is not None:
-      oprot.writeFieldBegin('eventBundle', TType.STRUCT, 1)
-      self.eventBundle.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class publish_result:
-  """
-  Attributes:
-   - ue
-   - se
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRUCT, 'ue', (Exception.ttypes.ThriftUndefinedEventTypeException, Exception.ttypes.ThriftUndefinedEventTypeException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
-  )
-
-  def __init__(self, ue=None, se=None,):
-    self.ue = ue
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRUCT:
-          self.ue = Exception.ttypes.ThriftUndefinedEventTypeException()
-          self.ue.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.se = Exception.ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('publish_result')
-    if self.ue is not None:
-      oprot.writeFieldBegin('ue', TType.STRUCT, 1)
-      self.ue.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 2)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamById_args:
-  """
-  Attributes:
-   - sessionId
-   - streamId
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamId', None, None, ), # 2
-  )
-
-  def __init__(self, sessionId=None, streamId=None,):
-    self.sessionId = sessionId
-    self.streamId = streamId
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamById_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamId is not None:
-      oprot.writeFieldBegin('streamId', TType.STRING, 2)
-      oprot.writeString(self.streamId)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamById_result:
-  """
-  Attributes:
-   - success
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.BOOL, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, success=None, se=None,):
-    self.success = success
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.BOOL:
-          self.success = iprot.readBool();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.se = Exception.ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamById_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.BOOL, 0)
-      oprot.writeBool(self.success)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 1)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamByNameVersion_args:
-  """
-  Attributes:
-   - sessionId
-   - streamName
-   - streamVersion
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamName', None, None, ), # 2
-    (3, TType.STRING, 'streamVersion', None, None, ), # 3
-  )
-
-  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
-    self.sessionId = sessionId
-    self.streamName = streamName
-    self.streamVersion = streamVersion
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamName = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRING:
-          self.streamVersion = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamByNameVersion_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamName is not None:
-      oprot.writeFieldBegin('streamName', TType.STRING, 2)
-      oprot.writeString(self.streamName)
-      oprot.writeFieldEnd()
-    if self.streamVersion is not None:
-      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
-      oprot.writeString(self.streamVersion)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamByNameVersion_result:
-  """
-  Attributes:
-   - success
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.BOOL, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, success=None, se=None,):
-    self.success = success
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.BOOL:
-          self.success = iprot.readBool();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.se = Exception.ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamByNameVersion_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.BOOL, 0)
-      oprot.writeBool(self.success)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 1)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
deleted file mode 100644
index 38575a6..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-__all__ = ['ttypes', 'constants', 'ThriftEventTransmissionService']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
deleted file mode 100644
index 36943ba..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
deleted file mode 100644
index 37ac241..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
-from ..Data import ttypes
-from ..Exception import ttypes
-
-
-from ...thrift.transport import TTransport
-from ...thrift.protocol import TBinaryProtocol, TProtocol
-try:
-  from thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
deleted file mode 100755
index 46757bf..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/usr/bin/env python
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-import sys
-import pprint
-from urlparse import urlparse
-
-from thrift.transport import TTransport
-from thrift.transport import TSocket
-from thrift.transport import THttpClient
-from thrift.protocol import TBinaryProtocol
-from ThriftSecureEventTransmissionService import ThriftSecureEventTransmissionService
-from ThriftSecureEventTransmissionService.ttypes import *
-
-
-if len(sys.argv) <= 1 or sys.argv[1] == '--help':
-  print ''
-  print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
-  print ''
-  print 'Functions:'
-  print '  string connect(string userName, string password)'
-  print '  void disconnect(string sessionId)'
-  print '  string defineStream(string sessionId, string streamDefinition)'
-  print '  string findStreamId(string sessionId, string streamName, string streamVersion)'
-  print '  void publish(ThriftEventBundle eventBundle)'
-  print '  bool deleteStreamById(string sessionId, string streamId)'
-  print '  bool deleteStreamByNameVersion(string sessionId, string streamName, string streamVersion)'
-  print ''
-  sys.exit(0)
-
-pp = pprint.PrettyPrinter(indent = 2)
-host = 'localhost'
-port = 9090
-uri = ''
-framed = False
-http = False
-argi = 1
-
-if sys.argv[argi] == '-h':
-  parts = sys.argv[argi+1].split(':')
-  host = parts[0]
-  if len(parts) > 1:
-    port = int(parts[1])
-  argi += 2
-
-if sys.argv[argi] == '-u':
-  url = urlparse(sys.argv[argi+1])
-  parts = url[1].split(':')
-  host = parts[0]
-  if len(parts) > 1:
-    port = int(parts[1])
-  else:
-    port = 80
-  uri = url[2]
-  if url[4]:
-    uri += '?%s' % url[4]
-  http = True
-  argi += 2
-
-if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
-  framed = True
-  argi += 1
-
-cmd = sys.argv[argi]
-args = sys.argv[argi+1:]
-
-if http:
-  transport = THttpClient.THttpClient(host, port, uri)
-else:
-  socket = TSocket.TSocket(host, port)
-  if framed:
-    transport = TTransport.TFramedTransport(socket)
-  else:
-    transport = TTransport.TBufferedTransport(socket)
-protocol = TBinaryProtocol.TBinaryProtocol(transport)
-client = ThriftSecureEventTransmissionService.Client(protocol)
-transport.open()
-
-if cmd == 'connect':
-  if len(args) != 2:
-    print 'connect requires 2 args'
-    sys.exit(1)
-  pp.pprint(client.connect(args[0],args[1],))
-
-elif cmd == 'disconnect':
-  if len(args) != 1:
-    print 'disconnect requires 1 args'
-    sys.exit(1)
-  pp.pprint(client.disconnect(args[0],))
-
-elif cmd == 'defineStream':
-  if len(args) != 2:
-    print 'defineStream requires 2 args'
-    sys.exit(1)
-  pp.pprint(client.defineStream(args[0],args[1],))
-
-elif cmd == 'findStreamId':
-  if len(args) != 3:
-    print 'findStreamId requires 3 args'
-    sys.exit(1)
-  pp.pprint(client.findStreamId(args[0],args[1],args[2],))
-
-elif cmd == 'publish':
-  if len(args) != 1:
-    print 'publish requires 1 args'
-    sys.exit(1)
-  pp.pprint(client.publish(eval(args[0]),))
-
-elif cmd == 'deleteStreamById':
-  if len(args) != 2:
-    print 'deleteStreamById requires 2 args'
-    sys.exit(1)
-  pp.pprint(client.deleteStreamById(args[0],args[1],))
-
-elif cmd == 'deleteStreamByNameVersion':
-  if len(args) != 3:
-    print 'deleteStreamByNameVersion requires 3 args'
-    sys.exit(1)
-  pp.pprint(client.deleteStreamByNameVersion(args[0],args[1],args[2],))
-
-else:
-  print 'Unrecognized method %s' % cmd
-  sys.exit(1)
-
-transport.close()


[18/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
deleted file mode 100644
index b8c13c1..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
+++ /dev/null
@@ -1,1495 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ttypes import *
-from ...thrift.Thrift import TProcessor
-from ...thrift.transport import TTransport
-from ..Exception import ttypes
-from .. import Data
-
-try:
-  from ...thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-
-class Iface:
-  def connect(self, userName, password):
-    """
-    Parameters:
-     - userName
-     - password
-    """
-    pass
-
-  def disconnect(self, sessionId):
-    """
-    Parameters:
-     - sessionId
-    """
-    pass
-
-  def defineStream(self, sessionId, streamDefinition):
-    """
-    Parameters:
-     - sessionId
-     - streamDefinition
-    """
-    pass
-
-  def findStreamId(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    pass
-
-  def publish(self, eventBundle):
-    """
-    Parameters:
-     - eventBundle
-    """
-    pass
-
-  def deleteStreamById(self, sessionId, streamId):
-    """
-    Parameters:
-     - sessionId
-     - streamId
-    """
-    pass
-
-  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    pass
-
-
-class Client(Iface):
-  def __init__(self, iprot, oprot=None):
-    self._iprot = self._oprot = iprot
-    if oprot is not None:
-      self._oprot = oprot
-    self._seqid = 0
-
-  def connect(self, userName, password):
-    """
-    Parameters:
-     - userName
-     - password
-    """
-    self.send_connect(userName, password)
-    return self.recv_connect()
-
-  def send_connect(self, userName, password):
-    self._oprot.writeMessageBegin('connect', TMessageType.CALL, self._seqid)
-    args = connect_args()
-    args.userName = userName
-    args.password = password
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_connect(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = connect_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.ae is not None:
-      raise result.ae
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "connect failed: unknown result");
-
-  def disconnect(self, sessionId):
-    """
-    Parameters:
-     - sessionId
-    """
-    self.send_disconnect(sessionId)
-    self.recv_disconnect()
-
-  def send_disconnect(self, sessionId):
-    self._oprot.writeMessageBegin('disconnect', TMessageType.CALL, self._seqid)
-    args = disconnect_args()
-    args.sessionId = sessionId
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_disconnect(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = disconnect_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    return
-
-  def defineStream(self, sessionId, streamDefinition):
-    """
-    Parameters:
-     - sessionId
-     - streamDefinition
-    """
-    self.send_defineStream(sessionId, streamDefinition)
-    return self.recv_defineStream()
-
-  def send_defineStream(self, sessionId, streamDefinition):
-    self._oprot.writeMessageBegin('defineStream', TMessageType.CALL, self._seqid)
-    args = defineStream_args()
-    args.sessionId = sessionId
-    args.streamDefinition = streamDefinition
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_defineStream(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = defineStream_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.ade is not None:
-      raise result.ade
-    if result.mtd is not None:
-      raise result.mtd
-    if result.tde is not None:
-      raise result.tde
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "defineStream failed: unknown result");
-
-  def findStreamId(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    self.send_findStreamId(sessionId, streamName, streamVersion)
-    return self.recv_findStreamId()
-
-  def send_findStreamId(self, sessionId, streamName, streamVersion):
-    self._oprot.writeMessageBegin('findStreamId', TMessageType.CALL, self._seqid)
-    args = findStreamId_args()
-    args.sessionId = sessionId
-    args.streamName = streamName
-    args.streamVersion = streamVersion
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_findStreamId(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = findStreamId_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.tnde is not None:
-      raise result.tnde
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "findStreamId failed: unknown result");
-
-  def publish(self, eventBundle):
-    """
-    Parameters:
-     - eventBundle
-    """
-    self.send_publish(eventBundle)
-    self.recv_publish()
-
-  def send_publish(self, eventBundle):
-    self._oprot.writeMessageBegin('publish', TMessageType.CALL, self._seqid)
-    args = publish_args()
-    args.eventBundle = eventBundle
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_publish(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = publish_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.ue is not None:
-      raise result.ue
-    if result.se is not None:
-      raise result.se
-    return
-
-  def deleteStreamById(self, sessionId, streamId):
-    """
-    Parameters:
-     - sessionId
-     - streamId
-    """
-    self.send_deleteStreamById(sessionId, streamId)
-    return self.recv_deleteStreamById()
-
-  def send_deleteStreamById(self, sessionId, streamId):
-    self._oprot.writeMessageBegin('deleteStreamById', TMessageType.CALL, self._seqid)
-    args = deleteStreamById_args()
-    args.sessionId = sessionId
-    args.streamId = streamId
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_deleteStreamById(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = deleteStreamById_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamById failed: unknown result");
-
-  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    self.send_deleteStreamByNameVersion(sessionId, streamName, streamVersion)
-    return self.recv_deleteStreamByNameVersion()
-
-  def send_deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    self._oprot.writeMessageBegin('deleteStreamByNameVersion', TMessageType.CALL, self._seqid)
-    args = deleteStreamByNameVersion_args()
-    args.sessionId = sessionId
-    args.streamName = streamName
-    args.streamVersion = streamVersion
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_deleteStreamByNameVersion(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = deleteStreamByNameVersion_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamByNameVersion failed: unknown result");
-
-
-class Processor(Iface, TProcessor):
-  def __init__(self, handler):
-    self._handler = handler
-    self._processMap = {}
-    self._processMap["connect"] = Processor.process_connect
-    self._processMap["disconnect"] = Processor.process_disconnect
-    self._processMap["defineStream"] = Processor.process_defineStream
-    self._processMap["findStreamId"] = Processor.process_findStreamId
-    self._processMap["publish"] = Processor.process_publish
-    self._processMap["deleteStreamById"] = Processor.process_deleteStreamById
-    self._processMap["deleteStreamByNameVersion"] = Processor.process_deleteStreamByNameVersion
-
-  def process(self, iprot, oprot):
-    (name, type, seqid) = iprot.readMessageBegin()
-    if name not in self._processMap:
-      iprot.skip(TType.STRUCT)
-      iprot.readMessageEnd()
-      x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
-      oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
-      x.write(oprot)
-      oprot.writeMessageEnd()
-      oprot.trans.flush()
-      return
-    else:
-      self._processMap[name](self, seqid, iprot, oprot)
-    return True
-
-  def process_connect(self, seqid, iprot, oprot):
-    args = connect_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = connect_result()
-    try:
-      result.success = self._handler.connect(args.userName, args.password)
-    except ttypes.ThriftAuthenticationException, ae:
-      result.ae = ae
-    oprot.writeMessageBegin("connect", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_disconnect(self, seqid, iprot, oprot):
-    args = disconnect_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = disconnect_result()
-    self._handler.disconnect(args.sessionId)
-    oprot.writeMessageBegin("disconnect", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_defineStream(self, seqid, iprot, oprot):
-    args = defineStream_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = defineStream_result()
-    try:
-      result.success = self._handler.defineStream(args.sessionId, args.streamDefinition)
-    except ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ade:
-      result.ade = ade
-    except ttypes.ThriftMalformedStreamDefinitionException, mtd:
-      result.mtd = mtd
-    except ttypes.ThriftStreamDefinitionException, tde:
-      result.tde = tde
-    except ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("defineStream", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_findStreamId(self, seqid, iprot, oprot):
-    args = findStreamId_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = findStreamId_result()
-    try:
-      result.success = self._handler.findStreamId(args.sessionId, args.streamName, args.streamVersion)
-    except ttypes.ThriftNoStreamDefinitionExistException, tnde:
-      result.tnde = tnde
-    except ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("findStreamId", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_publish(self, seqid, iprot, oprot):
-    args = publish_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = publish_result()
-    try:
-      self._handler.publish(args.eventBundle)
-    except ttypes.ThriftUndefinedEventTypeException, ue:
-      result.ue = ue
-    except ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("publish", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_deleteStreamById(self, seqid, iprot, oprot):
-    args = deleteStreamById_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = deleteStreamById_result()
-    try:
-      result.success = self._handler.deleteStreamById(args.sessionId, args.streamId)
-    except ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("deleteStreamById", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_deleteStreamByNameVersion(self, seqid, iprot, oprot):
-    args = deleteStreamByNameVersion_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = deleteStreamByNameVersion_result()
-    try:
-      result.success = self._handler.deleteStreamByNameVersion(args.sessionId, args.streamName, args.streamVersion)
-    except ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("deleteStreamByNameVersion", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-
-# HELPER FUNCTIONS AND STRUCTURES
-
-class connect_args:
-  """
-  Attributes:
-   - userName
-   - password
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'userName', None, None, ), # 1
-    (2, TType.STRING, 'password', None, None, ), # 2
-  )
-
-  def __init__(self, userName=None, password=None,):
-    self.userName = userName
-    self.password = password
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.userName = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.password = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('connect_args')
-    if self.userName is not None:
-      oprot.writeFieldBegin('userName', TType.STRING, 1)
-      oprot.writeString(self.userName)
-      oprot.writeFieldEnd()
-    if self.password is not None:
-      oprot.writeFieldBegin('password', TType.STRING, 2)
-      oprot.writeString(self.password)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class connect_result:
-  """
-  Attributes:
-   - success
-   - ae
-  """
-
-  thrift_spec = (
-    (0, TType.STRING, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'ae', (ttypes.ThriftAuthenticationException, ttypes.ThriftAuthenticationException.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, success=None, ae=None,):
-    self.success = success
-    self.ae = ae
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.STRING:
-          self.success = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.ae = ttypes.ThriftAuthenticationException()
-          self.ae.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('connect_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.STRING, 0)
-      oprot.writeString(self.success)
-      oprot.writeFieldEnd()
-    if self.ae is not None:
-      oprot.writeFieldBegin('ae', TType.STRUCT, 1)
-      self.ae.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class disconnect_args:
-  """
-  Attributes:
-   - sessionId
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-  )
-
-  def __init__(self, sessionId=None,):
-    self.sessionId = sessionId
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('disconnect_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class disconnect_result:
-
-  thrift_spec = (
-  )
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('disconnect_result')
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class defineStream_args:
-  """
-  Attributes:
-   - sessionId
-   - streamDefinition
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamDefinition', None, None, ), # 2
-  )
-
-  def __init__(self, sessionId=None, streamDefinition=None,):
-    self.sessionId = sessionId
-    self.streamDefinition = streamDefinition
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamDefinition = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('defineStream_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamDefinition is not None:
-      oprot.writeFieldBegin('streamDefinition', TType.STRING, 2)
-      oprot.writeString(self.streamDefinition)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class defineStream_result:
-  """
-  Attributes:
-   - success
-   - ade
-   - mtd
-   - tde
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.STRING, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'ade', (ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'mtd', (ttypes.ThriftMalformedStreamDefinitionException, ttypes.ThriftMalformedStreamDefinitionException.thrift_spec), None, ), # 2
-    (3, TType.STRUCT, 'tde', (ttypes.ThriftStreamDefinitionException, ttypes.ThriftStreamDefinitionException.thrift_spec), None, ), # 3
-    (4, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 4
-  )
-
-  def __init__(self, success=None, ade=None, mtd=None, tde=None, se=None,):
-    self.success = success
-    self.ade = ade
-    self.mtd = mtd
-    self.tde = tde
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.STRING:
-          self.success = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.ade = ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException()
-          self.ade.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.mtd = ttypes.ThriftMalformedStreamDefinitionException()
-          self.mtd.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRUCT:
-          self.tde = ttypes.ThriftStreamDefinitionException()
-          self.tde.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 4:
-        if ftype == TType.STRUCT:
-          self.se = ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('defineStream_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.STRING, 0)
-      oprot.writeString(self.success)
-      oprot.writeFieldEnd()
-    if self.ade is not None:
-      oprot.writeFieldBegin('ade', TType.STRUCT, 1)
-      self.ade.write(oprot)
-      oprot.writeFieldEnd()
-    if self.mtd is not None:
-      oprot.writeFieldBegin('mtd', TType.STRUCT, 2)
-      self.mtd.write(oprot)
-      oprot.writeFieldEnd()
-    if self.tde is not None:
-      oprot.writeFieldBegin('tde', TType.STRUCT, 3)
-      self.tde.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 4)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class findStreamId_args:
-  """
-  Attributes:
-   - sessionId
-   - streamName
-   - streamVersion
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamName', None, None, ), # 2
-    (3, TType.STRING, 'streamVersion', None, None, ), # 3
-  )
-
-  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
-    self.sessionId = sessionId
-    self.streamName = streamName
-    self.streamVersion = streamVersion
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamName = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRING:
-          self.streamVersion = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('findStreamId_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamName is not None:
-      oprot.writeFieldBegin('streamName', TType.STRING, 2)
-      oprot.writeString(self.streamName)
-      oprot.writeFieldEnd()
-    if self.streamVersion is not None:
-      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
-      oprot.writeString(self.streamVersion)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class findStreamId_result:
-  """
-  Attributes:
-   - success
-   - tnde
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.STRING, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'tnde', (ttypes.ThriftNoStreamDefinitionExistException, ttypes.ThriftNoStreamDefinitionExistException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
-  )
-
-  def __init__(self, success=None, tnde=None, se=None,):
-    self.success = success
-    self.tnde = tnde
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.STRING:
-          self.success = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.tnde = ttypes.ThriftNoStreamDefinitionExistException()
-          self.tnde.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.se = ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('findStreamId_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.STRING, 0)
-      oprot.writeString(self.success)
-      oprot.writeFieldEnd()
-    if self.tnde is not None:
-      oprot.writeFieldBegin('tnde', TType.STRUCT, 1)
-      self.tnde.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 2)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class publish_args:
-  """
-  Attributes:
-   - eventBundle
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRUCT, 'eventBundle', (Data.ttypes.ThriftEventBundle, Data.ttypes.ThriftEventBundle.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, eventBundle=None,):
-    self.eventBundle = eventBundle
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRUCT:
-          self.eventBundle = Data.ttypes.ThriftEventBundle()
-          self.eventBundle.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('publish_args')
-    if self.eventBundle is not None:
-      oprot.writeFieldBegin('eventBundle', TType.STRUCT, 1)
-      self.eventBundle.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class publish_result:
-  """
-  Attributes:
-   - ue
-   - se
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRUCT, 'ue', (ttypes.ThriftUndefinedEventTypeException, ttypes.ThriftUndefinedEventTypeException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
-  )
-
-  def __init__(self, ue=None, se=None,):
-    self.ue = ue
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRUCT:
-          self.ue = ttypes.ThriftUndefinedEventTypeException()
-          self.ue.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.se = ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('publish_result')
-    if self.ue is not None:
-      oprot.writeFieldBegin('ue', TType.STRUCT, 1)
-      self.ue.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 2)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamById_args:
-  """
-  Attributes:
-   - sessionId
-   - streamId
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamId', None, None, ), # 2
-  )
-
-  def __init__(self, sessionId=None, streamId=None,):
-    self.sessionId = sessionId
-    self.streamId = streamId
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamById_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamId is not None:
-      oprot.writeFieldBegin('streamId', TType.STRING, 2)
-      oprot.writeString(self.streamId)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamById_result:
-  """
-  Attributes:
-   - success
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.BOOL, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, success=None, se=None,):
-    self.success = success
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.BOOL:
-          self.success = iprot.readBool();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.se = ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamById_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.BOOL, 0)
-      oprot.writeBool(self.success)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 1)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamByNameVersion_args:
-  """
-  Attributes:
-   - sessionId
-   - streamName
-   - streamVersion
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamName', None, None, ), # 2
-    (3, TType.STRING, 'streamVersion', None, None, ), # 3
-  )
-
-  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
-    self.sessionId = sessionId
-    self.streamName = streamName
-    self.streamVersion = streamVersion
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamName = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRING:
-          self.streamVersion = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamByNameVersion_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamName is not None:
-      oprot.writeFieldBegin('streamName', TType.STRING, 2)
-      oprot.writeString(self.streamName)
-      oprot.writeFieldEnd()
-    if self.streamVersion is not None:
-      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
-      oprot.writeString(self.streamVersion)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamByNameVersion_result:
-  """
-  Attributes:
-   - success
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.BOOL, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, success=None, se=None,):
-    self.success = success
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.BOOL:
-          self.success = iprot.readBool();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.se = ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamByNameVersion_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.BOOL, 0)
-      oprot.writeBool(self.success)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 1)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
deleted file mode 100644
index c321ae1..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-__all__ = ['ttypes', 'constants', 'ThriftSecureEventTransmissionService']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
deleted file mode 100644
index 36943ba..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
deleted file mode 100644
index 37ac241..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
-from ..Data import ttypes
-from ..Exception import ttypes
-
-
-from ...thrift.transport import TTransport
-from ...thrift.protocol import TBinaryProtocol, TProtocol
-try:
-  from thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/gen/__init__.py
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
deleted file mode 100644
index 325b05d..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
+++ /dev/null
@@ -1,111 +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.
-
-import time
-import sys
-
-sys.path.append("gen")
-
-from gen.ThriftSecureEventTransmissionService import ThriftSecureEventTransmissionService
-from gen.Data.ttypes import ThriftEventBundle
-
-from thrift.transport import TSSLSocket
-from thrift.transport import TTransport
-from thrift.protocol import TBinaryProtocol
-
-
-# Define publisher class
-class Publisher:
-    client = None
-
-    def __init__(self, ip, port):
-        # Make SSL socket
-        self.socket = TSSLSocket.TSSLSocket(ip, port, False)
-        # Buffering is critical. Raw sockets are very slow
-        self.transport = TTransport.TBufferedTransport(self.socket)
-        # Wrap in a protocol
-        self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
-        self.sessionId = None
-        self.streamId = None
-
-    def connect(self, username, password):
-        # Create a client to use the protocol encoder
-        Publisher.client = ThriftSecureEventTransmissionService.Client(self.protocol)
-
-        # Make connection
-        self.socket.open()
-        self.transport.open()
-        self.sessionId = Publisher.client.connect(username, password)
-
-    def defineStream(self, streamDef):
-        # Create Stream Definition
-        self.streamId = Publisher.client.defineStream(self.sessionId, streamDef)
-
-    def publish(self, event):
-        # Build thrift event bundle
-        #event = EventBundle()
-        event.setSessionId(self.sessionId)
-        event.setEventNum(0)
-        event.addStringAttribute(self.streamId)
-        event.addLongAttribute(time.time() * 1000)
-        #event.addStringAttribute(msg)
-        # Publish
-        Publisher.client.publish(event.getEventBundle())
-
-    def disconnect(self):
-        # Disconnect
-        Publisher.client.disconnect(self.sessionId)
-        self.transport.close()
-        self.socket.close()
-
-
-class EventBundle:
-    __sessionId = ""
-    __eventNum = 0
-    __intAttributeList = []
-    __longAttributeList = []
-    __doubleAttributeList = []
-    __boolAttributeList = []
-    __stringAttributeList = []
-    __arbitraryDataMapMap = None
-
-    def setSessionId(self, sessionId):
-        self.__sessionId = sessionId
-
-    def setEventNum(self, num):
-        self.__eventNum = num
-
-    def addIntAttribute(self, attr):
-        self.__intAttributeList.append(attr)
-
-    def addLongAttribute(self, attr):
-        self.__longAttributeList.append(attr)
-
-    def addDoubleAttribute(self, attr):
-        self.__doubleAttributeList.append(attr)
-
-    def addBoolAttribute(self, attr):
-        self.__boolAttributeList.append(attr)
-
-    def addStringAttribute(self, attr):
-        self.__stringAttributeList.append(attr)
-
-    def getEventBundle(self):
-        return ThriftEventBundle(self.__sessionId, self.__eventNum, self.__intAttributeList,
-                                             self.__longAttributeList, self.__doubleAttributeList,
-                                             self.__boolAttributeList, self.__stringAttributeList,
-                                             self.__arbitraryDataMapMap)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TSCons.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TSCons.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TSCons.py
deleted file mode 100644
index da8d283..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TSCons.py
+++ /dev/null
@@ -1,35 +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.
-#
-
-from os import path
-from SCons.Builder import Builder
-
-
-def scons_env(env, add=''):
-  opath = path.dirname(path.abspath('$TARGET'))
-  lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE'
-  cppbuild = Builder(action=lstr)
-  env.Append(BUILDERS={'ThriftCpp': cppbuild})
-
-
-def gen_cpp(env, dir, file):
-  scons_env(env)
-  suffixes = ['_types.h', '_types.cpp']
-  targets = map(lambda s: 'gen-cpp/' + file + s, suffixes)
-  return env.ThriftCpp(targets, dir + file + '.thrift')

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TSerialization.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TSerialization.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TSerialization.py
deleted file mode 100644
index 8a58d89..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TSerialization.py
+++ /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.
-#
-
-from protocol import TBinaryProtocol
-from transport import TTransport
-
-
-def serialize(thrift_object,
-              protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
-    transport = TTransport.TMemoryBuffer()
-    protocol = protocol_factory.getProtocol(transport)
-    thrift_object.write(protocol)
-    return transport.getvalue()
-
-
-def deserialize(base,
-                buf,
-                protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
-    transport = TTransport.TMemoryBuffer(buf)
-    protocol = protocol_factory.getProtocol(transport)
-    base.read(protocol)
-    return base

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TTornado.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TTornado.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TTornado.py
deleted file mode 100644
index 8d9f5ed..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/TTornado.py
+++ /dev/null
@@ -1,153 +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.
-#
-
-from cStringIO import StringIO
-import logging
-import socket
-import struct
-
-from .transport import TTransport
-from .transport.TTransport import TTransportException
-
-from tornado import gen
-from tornado import iostream
-from tornado import netutil
-
-
-class TTornadoStreamTransport(TTransport.TTransportBase):
-    """a framed, buffered transport over a Tornado stream"""
-    def __init__(self, host, port, stream=None):
-        self.host = host
-        self.port = port
-        self.is_queuing_reads = False
-        self.read_queue = []
-        self.__wbuf = StringIO()
-
-        # servers provide a ready-to-go stream
-        self.stream = stream
-        if self.stream is not None:
-            self._set_close_callback()
-
-    # not the same number of parameters as TTransportBase.open
-    def open(self, callback):
-        logging.debug('socket connecting')
-        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
-        self.stream = iostream.IOStream(sock)
-
-        def on_close_in_connect(*_):
-            message = 'could not connect to {}:{}'.format(self.host, self.port)
-            raise TTransportException(
-                type=TTransportException.NOT_OPEN,
-                message=message)
-        self.stream.set_close_callback(on_close_in_connect)
-
-        def finish(*_):
-            self._set_close_callback()
-            callback()
-
-        self.stream.connect((self.host, self.port), callback=finish)
-
-    def _set_close_callback(self):
-        def on_close():
-            raise TTransportException(
-                type=TTransportException.END_OF_FILE,
-                message='socket closed')
-        self.stream.set_close_callback(self.close)
-
-    def close(self):
-        # don't raise if we intend to close
-        self.stream.set_close_callback(None)
-        self.stream.close()
-
-    def read(self, _):
-        # The generated code for Tornado shouldn't do individual reads -- only
-        # frames at a time
-        assert "you're doing it wrong" is True
-
-    @gen.engine
-    def readFrame(self, callback):
-        self.read_queue.append(callback)
-        logging.debug('read queue: %s', self.read_queue)
-
-        if self.is_queuing_reads:
-            # If a read is already in flight, then the while loop below should
-            # pull it from self.read_queue
-            return
-
-        self.is_queuing_reads = True
-        while self.read_queue:
-            next_callback = self.read_queue.pop()
-            result = yield gen.Task(self._readFrameFromStream)
-            next_callback(result)
-        self.is_queuing_reads = False
-
-    @gen.engine
-    def _readFrameFromStream(self, callback):
-        logging.debug('_readFrameFromStream')
-        frame_header = yield gen.Task(self.stream.read_bytes, 4)
-        frame_length, = struct.unpack('!i', frame_header)
-        logging.debug('received frame header, frame length = %i', frame_length)
-        frame = yield gen.Task(self.stream.read_bytes, frame_length)
-        logging.debug('received frame payload')
-        callback(frame)
-
-    def write(self, buf):
-        self.__wbuf.write(buf)
-
-    def flush(self, callback=None):
-        wout = self.__wbuf.getvalue()
-        wsz = len(wout)
-        # reset wbuf before write/flush to preserve state on underlying failure
-        self.__wbuf = StringIO()
-        # N.B.: Doing this string concatenation is WAY cheaper than making
-        # two separate calls to the underlying socket object. Socket writes in
-        # Python turn out to be REALLY expensive, but it seems to do a pretty
-        # good job of managing string buffer operations without excessive copies
-        buf = struct.pack("!i", wsz) + wout
-
-        logging.debug('writing frame length = %i', wsz)
-        self.stream.write(buf, callback)
-
-
-class TTornadoServer(netutil.TCPServer):
-    def __init__(self, processor, iprot_factory, oprot_factory=None,
-                 *args, **kwargs):
-        super(TTornadoServer, self).__init__(*args, **kwargs)
-
-        self._processor = processor
-        self._iprot_factory = iprot_factory
-        self._oprot_factory = (oprot_factory if oprot_factory is not None
-                               else iprot_factory)
-
-    def handle_stream(self, stream, address):
-        try:
-            host, port = address
-            trans = TTornadoStreamTransport(host=host, port=port, stream=stream)
-            oprot = self._oprot_factory.getProtocol(trans)
-
-            def next_pass():
-                if not trans.stream.closed():
-                    self._processor.process(trans, self._iprot_factory, oprot,
-                                            callback=next_pass)
-
-            next_pass()
-
-        except Exception:
-            logging.exception('thrift exception in handle_stream')
-            trans.close()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/Thrift.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/Thrift.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/Thrift.py
deleted file mode 100644
index 9890af7..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/Thrift.py
+++ /dev/null
@@ -1,170 +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.
-#
-
-import sys
-
-
-class TType:
-  STOP   = 0
-  VOID   = 1
-  BOOL   = 2
-  BYTE   = 3
-  I08    = 3
-  DOUBLE = 4
-  I16    = 6
-  I32    = 8
-  I64    = 10
-  STRING = 11
-  UTF7   = 11
-  STRUCT = 12
-  MAP    = 13
-  SET    = 14
-  LIST   = 15
-  UTF8   = 16
-  UTF16  = 17
-
-  _VALUES_TO_NAMES = ('STOP',
-                      'VOID',
-                      'BOOL',
-                      'BYTE',
-                      'DOUBLE',
-                      None,
-                      'I16',
-                      None,
-                      'I32',
-                      None,
-                     'I64',
-                     'STRING',
-                     'STRUCT',
-                     'MAP',
-                     'SET',
-                     'LIST',
-                     'UTF8',
-                     'UTF16')
-
-
-class TMessageType:
-  CALL = 1
-  REPLY = 2
-  EXCEPTION = 3
-  ONEWAY = 4
-
-
-class TProcessor:
-  """Base class for procsessor, which works on two streams."""
-
-  def process(iprot, oprot):
-    pass
-
-
-class TException(Exception):
-  """Base class for all thrift exceptions."""
-
-  # BaseException.message is deprecated in Python v[2.6,3.0)
-  if (2, 6, 0) <= sys.version_info < (3, 0):
-    def _get_message(self):
-      return self._message
-
-    def _set_message(self, message):
-      self._message = message
-    message = property(_get_message, _set_message)
-
-  def __init__(self, message=None):
-    Exception.__init__(self, message)
-    self.message = message
-
-
-class TApplicationException(TException):
-  """Application level thrift exceptions."""
-
-  UNKNOWN = 0
-  UNKNOWN_METHOD = 1
-  INVALID_MESSAGE_TYPE = 2
-  WRONG_METHOD_NAME = 3
-  BAD_SEQUENCE_ID = 4
-  MISSING_RESULT = 5
-  INTERNAL_ERROR = 6
-  PROTOCOL_ERROR = 7
-  INVALID_TRANSFORM = 8
-  INVALID_PROTOCOL = 9
-  UNSUPPORTED_CLIENT_TYPE = 10
-
-  def __init__(self, type=UNKNOWN, message=None):
-    TException.__init__(self, message)
-    self.type = type
-
-  def __str__(self):
-    if self.message:
-      return self.message
-    elif self.type == self.UNKNOWN_METHOD:
-      return 'Unknown method'
-    elif self.type == self.INVALID_MESSAGE_TYPE:
-      return 'Invalid message type'
-    elif self.type == self.WRONG_METHOD_NAME:
-      return 'Wrong method name'
-    elif self.type == self.BAD_SEQUENCE_ID:
-      return 'Bad sequence ID'
-    elif self.type == self.MISSING_RESULT:
-      return 'Missing result'
-    elif self.type == self.INTERNAL_ERROR:
-      return 'Internal error'
-    elif self.type == self.PROTOCOL_ERROR:
-      return 'Protocol error'
-    elif self.type == self.INVALID_TRANSFORM:
-      return 'Invalid transform'
-    elif self.type == self.INVALID_PROTOCOL:
-      return 'Invalid protocol'
-    elif self.type == self.UNSUPPORTED_CLIENT_TYPE:
-      return 'Unsupported client type'
-    else:
-      return 'Default (unknown) TApplicationException'
-
-  def read(self, iprot):
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString()
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.I32:
-          self.type = iprot.readI32()
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    oprot.writeStructBegin('TApplicationException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    if self.type is not None:
-      oprot.writeFieldBegin('type', TType.I32, 2)
-      oprot.writeI32(self.type)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/__init__.py
deleted file mode 100644
index 48d659c..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/__init__.py
+++ /dev/null
@@ -1,20 +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.
-#
-
-__all__ = ['Thrift', 'TSCons']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TBase.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TBase.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TBase.py
deleted file mode 100644
index 61b469b..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TBase.py
+++ /dev/null
@@ -1,81 +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.
-#
-
-from ..Thrift import *
-import TBinaryProtocol
-from ..transport import TTransport
-
-try:
-  import fastbinary
-except:
-  fastbinary = None
-
-
-class TBase(object):
-  __slots__ = []
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, getattr(self, key))
-              for key in self.__slots__]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    if not isinstance(other, self.__class__):
-      return False
-    for attr in self.__slots__:
-      my_val = getattr(self, attr)
-      other_val = getattr(other, attr)
-      if my_val != other_val:
-        return False
-    return True
-
-  def __ne__(self, other):
-    return not (self == other)
-
-  def read(self, iprot):
-    if (iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
-        isinstance(iprot.trans, TTransport.CReadableTransport) and
-        self.thrift_spec is not None and
-        fastbinary is not None):
-      fastbinary.decode_binary(self,
-                               iprot.trans,
-                               (self.__class__, self.thrift_spec))
-      return
-    iprot.readStruct(self, self.thrift_spec)
-
-  def write(self, oprot):
-    if (oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
-        self.thrift_spec is not None and
-        fastbinary is not None):
-      oprot.trans.write(
-        fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStruct(self, self.thrift_spec)
-
-
-class TExceptionBase(Exception):
-  # old style class so python2.4 can raise exceptions derived from this
-  #  This can't inherit from TBase because of that limitation.
-  __slots__ = []
-
-  __repr__ = TBase.__repr__.im_func
-  __eq__ = TBase.__eq__.im_func
-  __ne__ = TBase.__ne__.im_func
-  read = TBase.read.im_func
-  write = TBase.write.im_func

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
deleted file mode 100644
index 2cdc6b5..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
+++ /dev/null
@@ -1,261 +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.
-#
-
-from struct import pack, unpack
-
-from TProtocol import *
-
-
-class TBinaryProtocol(TProtocolBase):
-  """Binary implementation of the Thrift protocol driver."""
-
-  # NastyHaxx. Python 2.4+ on 32-bit machines forces hex constants to be
-  # positive, converting this into a long. If we hardcode the int value
-  # instead it'll stay in 32 bit-land.
-
-  # VERSION_MASK = 0xffff0000
-  VERSION_MASK = -65536
-
-  # VERSION_1 = 0x80010000
-  VERSION_1 = -2147418112
-
-  TYPE_MASK = 0x000000ff
-
-  def __init__(self, trans, strictRead=False, strictWrite=True):
-    TProtocolBase.__init__(self, trans)
-    self.strictRead = strictRead
-    self.strictWrite = strictWrite
-
-  def writeMessageBegin(self, name, type, seqid):
-    if self.strictWrite:
-      self.writeI32(TBinaryProtocol.VERSION_1 | type)
-      self.writeString(name)
-      self.writeI32(seqid)
-    else:
-      self.writeString(name)
-      self.writeByte(type)
-      self.writeI32(seqid)
-
-  def writeMessageEnd(self):
-    pass
-
-  def writeStructBegin(self, name):
-    pass
-
-  def writeStructEnd(self):
-    pass
-
-  def writeFieldBegin(self, name, type, id):
-    self.writeByte(type)
-    self.writeI16(id)
-
-  def writeFieldEnd(self):
-    pass
-
-  def writeFieldStop(self):
-    self.writeByte(TType.STOP)
-
-  def writeMapBegin(self, ktype, vtype, size):
-    self.writeByte(ktype)
-    self.writeByte(vtype)
-    self.writeI32(size)
-
-  def writeMapEnd(self):
-    pass
-
-  def writeListBegin(self, etype, size):
-    self.writeByte(etype)
-    self.writeI32(size)
-
-  def writeListEnd(self):
-    pass
-
-  def writeSetBegin(self, etype, size):
-    self.writeByte(etype)
-    self.writeI32(size)
-
-  def writeSetEnd(self):
-    pass
-
-  def writeBool(self, bool):
-    if bool:
-      self.writeByte(1)
-    else:
-      self.writeByte(0)
-
-  def writeByte(self, byte):
-    buff = pack("!b", byte)
-    self.trans.write(buff)
-
-  def writeI16(self, i16):
-    buff = pack("!h", i16)
-    self.trans.write(buff)
-
-  def writeI32(self, i32):
-    buff = pack("!i", i32)
-    self.trans.write(buff)
-
-  def writeI64(self, i64):
-    buff = pack("!q", i64)
-    self.trans.write(buff)
-
-  def writeDouble(self, dub):
-    buff = pack("!d", dub)
-    self.trans.write(buff)
-
-  def writeString(self, str):
-    self.writeI32(len(str))
-    self.trans.write(str)
-
-  def readMessageBegin(self):
-    sz = self.readI32()
-    if sz < 0:
-      version = sz & TBinaryProtocol.VERSION_MASK
-      if version != TBinaryProtocol.VERSION_1:
-        raise TProtocolException(
-          type=TProtocolException.BAD_VERSION,
-          message='Bad version in readMessageBegin: %d' % (sz))
-      type = sz & TBinaryProtocol.TYPE_MASK
-      name = self.readString()
-      seqid = self.readI32()
-    else:
-      if self.strictRead:
-        raise TProtocolException(type=TProtocolException.BAD_VERSION,
-                                 message='No protocol version header')
-      name = self.trans.readAll(sz)
-      type = self.readByte()
-      seqid = self.readI32()
-    return (name, type, seqid)
-
-  def readMessageEnd(self):
-    pass
-
-  def readStructBegin(self):
-    pass
-
-  def readStructEnd(self):
-    pass
-
-  def readFieldBegin(self):
-    type = self.readByte()
-    if type == TType.STOP:
-      return (None, type, 0)
-    id = self.readI16()
-    return (None, type, id)
-
-  def readFieldEnd(self):
-    pass
-
-  def readMapBegin(self):
-    ktype = self.readByte()
-    vtype = self.readByte()
-    size = self.readI32()
-    return (ktype, vtype, size)
-
-  def readMapEnd(self):
-    pass
-
-  def readListBegin(self):
-    etype = self.readByte()
-    size = self.readI32()
-    return (etype, size)
-
-  def readListEnd(self):
-    pass
-
-  def readSetBegin(self):
-    etype = self.readByte()
-    size = self.readI32()
-    return (etype, size)
-
-  def readSetEnd(self):
-    pass
-
-  def readBool(self):
-    byte = self.readByte()
-    if byte == 0:
-      return False
-    return True
-
-  def readByte(self):
-    buff = self.trans.readAll(1)
-    val, = unpack('!b', buff)
-    return val
-
-  def readI16(self):
-    buff = self.trans.readAll(2)
-    val, = unpack('!h', buff)
-    return val
-
-  def readI32(self):
-    buff = self.trans.readAll(4)
-    val, = unpack('!i', buff)
-    return val
-
-  def readI64(self):
-    buff = self.trans.readAll(8)
-    val, = unpack('!q', buff)
-    return val
-
-  def readDouble(self):
-    buff = self.trans.readAll(8)
-    val, = unpack('!d', buff)
-    return val
-
-  def readString(self):
-    len = self.readI32()
-    str = self.trans.readAll(len)
-    return str
-
-
-class TBinaryProtocolFactory:
-  def __init__(self, strictRead=False, strictWrite=True):
-    self.strictRead = strictRead
-    self.strictWrite = strictWrite
-
-  def getProtocol(self, trans):
-    prot = TBinaryProtocol(trans, self.strictRead, self.strictWrite)
-    return prot
-
-
-class TBinaryProtocolAccelerated(TBinaryProtocol):
-  """C-Accelerated version of TBinaryProtocol.
-
-  This class does not override any of TBinaryProtocol's methods,
-  but the generated code recognizes it directly and will call into
-  our C module to do the encoding, bypassing this object entirely.
-  We inherit from TBinaryProtocol so that the normal TBinaryProtocol
-  encoding can happen if the fastbinary module doesn't work for some
-  reason.  (TODO(dreiss): Make this happen sanely in more cases.)
-
-  In order to take advantage of the C module, just use
-  TBinaryProtocolAccelerated instead of TBinaryProtocol.
-
-  NOTE:  This code was contributed by an external developer.
-         The internal Thrift team has reviewed and tested it,
-         but we cannot guarantee that it is production-ready.
-         Please feel free to report bugs and/or success stories
-         to the public mailing list.
-  """
-  pass
-
-
-class TBinaryProtocolAcceleratedFactory:
-  def getProtocol(self, trans):
-    return TBinaryProtocolAccelerated(trans)


[23/50] [abbrv] git commit: Added test on ScheduledService Fixed issues in the ScheduledService Added abstract class to implement a task for the scheduledservice

Posted by im...@apache.org.
Added test on ScheduledService
Fixed issues in the ScheduledService
Added abstract class to implement a task for the scheduledservice


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

Branch: refs/heads/master
Commit: 4446d24735ff8ff8808ac483927c5cb812ff2314
Parents: b5b6fb3
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Mon Oct 20 15:39:50 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Mon Oct 20 15:39:50 2014 +0530

----------------------------------------------------------------------
 .../modules/util/asyncscheduledtask.py          | 29 +++++++++++++--
 tools/python-cartridge-agent/test/__init__.py   | 16 ++++++++
 tools/python-cartridge-agent/test/asynctest.txt |  2 +-
 tools/python-cartridge-agent/test/test_util.py  | 39 +++++++++++++++-----
 4 files changed, 71 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/4446d247/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py
index 9fdde1e..4ff0416 100644
--- a/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py
@@ -18,29 +18,50 @@
 import time
 from threading import Thread
 
+class AbstractAsyncScheduledTask:
+    """
+    Exposes the contract to follow to implement a scheduled task to be executed by the ScheduledExecutor
+    """
+
+    def execute_task(self):
+        """
+        Override this method and implement the task to be executed by the ScheduledExecutor with a specified
+        interval.
+        """
+        raise NotImplementedError
 
-class AsyncScheduledTask(Thread):
+
+class ScheduledExecutor(Thread):
     """
     Executes a given task with a given interval until being terminated
     """
 
     def __init__(self, delay, task):
+        """
+        Creates a ScheduledExecutor thread to handle interval based repeated execution of a given task of type
+        AbstractAsyncScheduledTask
+        :param int delay: The interval to keep between executions
+        :param AbstractAsyncScheduledTask task: The task to be implemented
+        :return:
+        """
+
         Thread.__init__(self)
         self.delay = delay
         """ :type : int  """
         self.task = task
-        """ :type : Thread  """
+        """ :type : AbstractAsyncScheduledTask  """
         self.terminated = False
         """ :type : bool  """
 
     def run(self):
         """
-        Start the scheuled task with a sleep time of delay in between
+        Start the scheduled task with a sleep time of delay in between
         :return:
         """
         while not self.terminated:
             time.sleep(self.delay)
-            self.task.start()
+            task_thread = Thread(target=self.task.execute_task)
+            task_thread.start()
 
     def terminate(self):
         """

http://git-wip-us.apache.org/repos/asf/stratos/blob/4446d247/tools/python-cartridge-agent/test/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/test/__init__.py b/tools/python-cartridge-agent/test/__init__.py
index e69de29..13a8339 100644
--- a/tools/python-cartridge-agent/test/__init__.py
+++ b/tools/python-cartridge-agent/test/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/4446d247/tools/python-cartridge-agent/test/asynctest.txt
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/test/asynctest.txt b/tools/python-cartridge-agent/test/asynctest.txt
index ffae2e3..623c418 100644
--- a/tools/python-cartridge-agent/test/asynctest.txt
+++ b/tools/python-cartridge-agent/test/asynctest.txt
@@ -1 +1 @@
-1413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793
 552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.293
 61413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.2936141379
 3552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29
 361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.293614137
 93552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.2
 9361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413
 793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.
 29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.2936141
 3793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552
 .29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.293614
 13793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.2936141379355
 2.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361
 413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.293614137935
 52.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.2936
 1413793552.29361413793552.29361413793552.2936
\ No newline at end of file
+1413799652508.8130
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/4446d247/tools/python-cartridge-agent/test/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/test/test_util.py b/tools/python-cartridge-agent/test/test_util.py
index c7ee884..f62b2e8 100644
--- a/tools/python-cartridge-agent/test/test_util.py
+++ b/tools/python-cartridge-agent/test/test_util.py
@@ -1,20 +1,39 @@
-from cartridgeagent.modules.util.asyncscheduledtask import AsyncScheduledTask
-from threading import Thread
-import time
+# 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.
 
-def thread_worker():
-    f = open("asynctest.txt", "w")
-    f.write("%1.4f" % time.time() * 1000)
-    f.close()
+from cartridgeagent.modules.util.asyncscheduledtask import *
+import time
 
 def test_async_task():
-    astask = AsyncScheduledTask(2, Thread(thread_worker()))
+    test_task = TestTask()
+    astask = ScheduledExecutor(2, test_task)
     start_time = time.time() * 1000
-    astask.run()
+    astask.start()
     time.sleep(3)
     astask.terminate()
-    f = open("asynctest.txt")
+    f = open("asynctest.txt", "r")
     end_time = float(f.read())
     assert (end_time - start_time) >= 2 * 1000, "Task was executed before specified delay"
 
 
+class TestTask(AbstractAsyncScheduledTask):
+
+    def execute_task(self):
+        with open("asynctest.txt", "w") as f:
+            f.seek(0)
+            f.truncate()
+            f.write("%1.4f" % (time.time()*1000))


[16/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
deleted file mode 100644
index 74e142c..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
+++ /dev/null
@@ -1,118 +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.
-#
-
-
-import logging
-from multiprocessing import  Process, Value, Condition
-
-from TServer import TServer
-from ..transport.TTransport import TTransportException
-
-
-class TProcessPoolServer(TServer):
-    """Server with a fixed size pool of worker subprocesses to service requests
-
-    Note that if you need shared state between the handlers - it's up to you!
-    Written by Dvir Volk, doat.com
-    """
-    def __init__(self, *args):
-        TServer.__init__(self, *args)
-        self.numWorkers = 10
-        self.workers = []
-        self.isRunning = Value('b', False)
-        self.stopCondition = Condition()
-        self.postForkCallback = None
-
-    def setPostForkCallback(self, callback):
-        if not callable(callback):
-            raise TypeError("This is not a callback!")
-        self.postForkCallback = callback
-
-    def setNumWorkers(self, num):
-        """Set the number of worker threads that should be created"""
-        self.numWorkers = num
-
-    def workerProcess(self):
-        """Loop getting clients from the shared queue and process them"""
-        if self.postForkCallback:
-            self.postForkCallback()
-
-        while self.isRunning.value:
-            try:
-                client = self.serverTransport.accept()
-                self.serveClient(client)
-            except (KeyboardInterrupt, SystemExit):
-                return 0
-            except Exception, x:
-                logging.exception(x)
-
-    def serveClient(self, client):
-        """Process input/output from a client for as long as possible"""
-        itrans = self.inputTransportFactory.getTransport(client)
-        otrans = self.outputTransportFactory.getTransport(client)
-        iprot = self.inputProtocolFactory.getProtocol(itrans)
-        oprot = self.outputProtocolFactory.getProtocol(otrans)
-
-        try:
-            while True:
-                self.processor.process(iprot, oprot)
-        except TTransportException, tx:
-            pass
-        except Exception, x:
-            logging.exception(x)
-
-        itrans.close()
-        otrans.close()
-
-    def serve(self):
-        """Start workers and put into queue"""
-        # this is a shared state that can tell the workers to exit when False
-        self.isRunning.value = True
-
-        # first bind and listen to the port
-        self.serverTransport.listen()
-
-        # fork the children
-        for i in range(self.numWorkers):
-            try:
-                w = Process(target=self.workerProcess)
-                w.daemon = True
-                w.start()
-                self.workers.append(w)
-            except Exception, x:
-                logging.exception(x)
-
-        # wait until the condition is set by stop()
-        while True:
-            self.stopCondition.acquire()
-            try:
-                self.stopCondition.wait()
-                break
-            except (SystemExit, KeyboardInterrupt):
-                break
-            except Exception, x:
-                logging.exception(x)
-
-        self.isRunning.value = False
-
-    def stop(self):
-        self.isRunning.value = False
-        self.stopCondition.acquire()
-        self.stopCondition.notify()
-        self.stopCondition.release()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TServer.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TServer.py
deleted file mode 100644
index 3e44107..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TServer.py
+++ /dev/null
@@ -1,269 +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.
-#
-
-import Queue
-import logging
-import os
-import sys
-import threading
-import traceback
-
-from ..Thrift import TProcessor
-from ..protocol import TBinaryProtocol
-from ..transport import TTransport
-
-
-class TServer:
-  """Base interface for a server, which must have a serve() method.
-
-  Three constructors for all servers:
-  1) (processor, serverTransport)
-  2) (processor, serverTransport, transportFactory, protocolFactory)
-  3) (processor, serverTransport,
-      inputTransportFactory, outputTransportFactory,
-      inputProtocolFactory, outputProtocolFactory)
-  """
-  def __init__(self, *args):
-    if (len(args) == 2):
-      self.__initArgs__(args[0], args[1],
-                        TTransport.TTransportFactoryBase(),
-                        TTransport.TTransportFactoryBase(),
-                        TBinaryProtocol.TBinaryProtocolFactory(),
-                        TBinaryProtocol.TBinaryProtocolFactory())
-    elif (len(args) == 4):
-      self.__initArgs__(args[0], args[1], args[2], args[2], args[3], args[3])
-    elif (len(args) == 6):
-      self.__initArgs__(args[0], args[1], args[2], args[3], args[4], args[5])
-
-  def __initArgs__(self, processor, serverTransport,
-                   inputTransportFactory, outputTransportFactory,
-                   inputProtocolFactory, outputProtocolFactory):
-    self.processor = processor
-    self.serverTransport = serverTransport
-    self.inputTransportFactory = inputTransportFactory
-    self.outputTransportFactory = outputTransportFactory
-    self.inputProtocolFactory = inputProtocolFactory
-    self.outputProtocolFactory = outputProtocolFactory
-
-  def serve(self):
-    pass
-
-
-class TSimpleServer(TServer):
-  """Simple single-threaded server that just pumps around one transport."""
-
-  def __init__(self, *args):
-    TServer.__init__(self, *args)
-
-  def serve(self):
-    self.serverTransport.listen()
-    while True:
-      client = self.serverTransport.accept()
-      itrans = self.inputTransportFactory.getTransport(client)
-      otrans = self.outputTransportFactory.getTransport(client)
-      iprot = self.inputProtocolFactory.getProtocol(itrans)
-      oprot = self.outputProtocolFactory.getProtocol(otrans)
-      try:
-        while True:
-          self.processor.process(iprot, oprot)
-      except TTransport.TTransportException, tx:
-        pass
-      except Exception, x:
-        logging.exception(x)
-
-      itrans.close()
-      otrans.close()
-
-
-class TThreadedServer(TServer):
-  """Threaded server that spawns a new thread per each connection."""
-
-  def __init__(self, *args, **kwargs):
-    TServer.__init__(self, *args)
-    self.daemon = kwargs.get("daemon", False)
-
-  def serve(self):
-    self.serverTransport.listen()
-    while True:
-      try:
-        client = self.serverTransport.accept()
-        t = threading.Thread(target=self.handle, args=(client,))
-        t.setDaemon(self.daemon)
-        t.start()
-      except KeyboardInterrupt:
-        raise
-      except Exception, x:
-        logging.exception(x)
-
-  def handle(self, client):
-    itrans = self.inputTransportFactory.getTransport(client)
-    otrans = self.outputTransportFactory.getTransport(client)
-    iprot = self.inputProtocolFactory.getProtocol(itrans)
-    oprot = self.outputProtocolFactory.getProtocol(otrans)
-    try:
-      while True:
-        self.processor.process(iprot, oprot)
-    except TTransport.TTransportException, tx:
-      pass
-    except Exception, x:
-      logging.exception(x)
-
-    itrans.close()
-    otrans.close()
-
-
-class TThreadPoolServer(TServer):
-  """Server with a fixed size pool of threads which service requests."""
-
-  def __init__(self, *args, **kwargs):
-    TServer.__init__(self, *args)
-    self.clients = Queue.Queue()
-    self.threads = 10
-    self.daemon = kwargs.get("daemon", False)
-
-  def setNumThreads(self, num):
-    """Set the number of worker threads that should be created"""
-    self.threads = num
-
-  def serveThread(self):
-    """Loop around getting clients from the shared queue and process them."""
-    while True:
-      try:
-        client = self.clients.get()
-        self.serveClient(client)
-      except Exception, x:
-        logging.exception(x)
-
-  def serveClient(self, client):
-    """Process input/output from a client for as long as possible"""
-    itrans = self.inputTransportFactory.getTransport(client)
-    otrans = self.outputTransportFactory.getTransport(client)
-    iprot = self.inputProtocolFactory.getProtocol(itrans)
-    oprot = self.outputProtocolFactory.getProtocol(otrans)
-    try:
-      while True:
-        self.processor.process(iprot, oprot)
-    except TTransport.TTransportException, tx:
-      pass
-    except Exception, x:
-      logging.exception(x)
-
-    itrans.close()
-    otrans.close()
-
-  def serve(self):
-    """Start a fixed number of worker threads and put client into a queue"""
-    for i in range(self.threads):
-      try:
-        t = threading.Thread(target=self.serveThread)
-        t.setDaemon(self.daemon)
-        t.start()
-      except Exception, x:
-        logging.exception(x)
-
-    # Pump the socket for clients
-    self.serverTransport.listen()
-    while True:
-      try:
-        client = self.serverTransport.accept()
-        self.clients.put(client)
-      except Exception, x:
-        logging.exception(x)
-
-
-class TForkingServer(TServer):
-  """A Thrift server that forks a new process for each request
-
-  This is more scalable than the threaded server as it does not cause
-  GIL contention.
-
-  Note that this has different semantics from the threading server.
-  Specifically, updates to shared variables will no longer be shared.
-  It will also not work on windows.
-
-  This code is heavily inspired by SocketServer.ForkingMixIn in the
-  Python stdlib.
-  """
-  def __init__(self, *args):
-    TServer.__init__(self, *args)
-    self.children = []
-
-  def serve(self):
-    def try_close(file):
-      try:
-        file.close()
-      except IOError, e:
-        logging.warning(e, exc_info=True)
-
-    self.serverTransport.listen()
-    while True:
-      client = self.serverTransport.accept()
-      try:
-        pid = os.fork()
-
-        if pid:  # parent
-          # add before collect, otherwise you race w/ waitpid
-          self.children.append(pid)
-          self.collect_children()
-
-          # Parent must close socket or the connection may not get
-          # closed promptly
-          itrans = self.inputTransportFactory.getTransport(client)
-          otrans = self.outputTransportFactory.getTransport(client)
-          try_close(itrans)
-          try_close(otrans)
-        else:
-          itrans = self.inputTransportFactory.getTransport(client)
-          otrans = self.outputTransportFactory.getTransport(client)
-
-          iprot = self.inputProtocolFactory.getProtocol(itrans)
-          oprot = self.outputProtocolFactory.getProtocol(otrans)
-
-          ecode = 0
-          try:
-            try:
-              while True:
-                self.processor.process(iprot, oprot)
-            except TTransport.TTransportException, tx:
-              pass
-            except Exception, e:
-              logging.exception(e)
-              ecode = 1
-          finally:
-            try_close(itrans)
-            try_close(otrans)
-
-          os._exit(ecode)
-
-      except TTransport.TTransportException, tx:
-        pass
-      except Exception, x:
-        logging.exception(x)
-
-  def collect_children(self):
-    while self.children:
-      try:
-        pid, status = os.waitpid(0, os.WNOHANG)
-      except os.error:
-        pid = None
-
-      if pid:
-        self.children.remove(pid)
-      else:
-        break

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/__init__.py
deleted file mode 100644
index 1bf6e25..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/__init__.py
+++ /dev/null
@@ -1,20 +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.
-#
-
-__all__ = ['TServer', 'TNonblockingServer']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/THttpClient.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/THttpClient.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/THttpClient.py
deleted file mode 100644
index 9ef9535..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/THttpClient.py
+++ /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.
-#
-
-import httplib
-import os
-import socket
-import sys
-import urllib
-import urlparse
-import warnings
-
-from TTransport import *
-
-
-class THttpClient(TTransportBase):
-  """Http implementation of TTransport base."""
-
-  def __init__(self, uri_or_host, port=None, path=None):
-    """THttpClient supports two different types constructor parameters.
-
-    THttpClient(host, port, path) - deprecated
-    THttpClient(uri)
-
-    Only the second supports https.
-    """
-    if port is not None:
-      warnings.warn(
-        "Please use the THttpClient('http://host:port/path') syntax",
-        DeprecationWarning,
-        stacklevel=2)
-      self.host = uri_or_host
-      self.port = port
-      assert path
-      self.path = path
-      self.scheme = 'http'
-    else:
-      parsed = urlparse.urlparse(uri_or_host)
-      self.scheme = parsed.scheme
-      assert self.scheme in ('http', 'https')
-      if self.scheme == 'http':
-        self.port = parsed.port or httplib.HTTP_PORT
-      elif self.scheme == 'https':
-        self.port = parsed.port or httplib.HTTPS_PORT
-      self.host = parsed.hostname
-      self.path = parsed.path
-      if parsed.query:
-        self.path += '?%s' % parsed.query
-    self.__wbuf = StringIO()
-    self.__http = None
-    self.__timeout = None
-    self.__custom_headers = None
-
-  def open(self):
-    if self.scheme == 'http':
-      self.__http = httplib.HTTP(self.host, self.port)
-    else:
-      self.__http = httplib.HTTPS(self.host, self.port)
-
-  def close(self):
-    self.__http.close()
-    self.__http = None
-
-  def isOpen(self):
-    return self.__http is not None
-
-  def setTimeout(self, ms):
-    if not hasattr(socket, 'getdefaulttimeout'):
-      raise NotImplementedError
-
-    if ms is None:
-      self.__timeout = None
-    else:
-      self.__timeout = ms / 1000.0
-
-  def setCustomHeaders(self, headers):
-    self.__custom_headers = headers
-
-  def read(self, sz):
-    return self.__http.file.read(sz)
-
-  def write(self, buf):
-    self.__wbuf.write(buf)
-
-  def __withTimeout(f):
-    def _f(*args, **kwargs):
-      orig_timeout = socket.getdefaulttimeout()
-      socket.setdefaulttimeout(args[0].__timeout)
-      result = f(*args, **kwargs)
-      socket.setdefaulttimeout(orig_timeout)
-      return result
-    return _f
-
-  def flush(self):
-    if self.isOpen():
-      self.close()
-    self.open()
-
-    # Pull data out of buffer
-    data = self.__wbuf.getvalue()
-    self.__wbuf = StringIO()
-
-    # HTTP request
-    self.__http.putrequest('POST', self.path)
-
-    # Write headers
-    self.__http.putheader('Host', self.host)
-    self.__http.putheader('Content-Type', 'application/x-thrift')
-    self.__http.putheader('Content-Length', str(len(data)))
-
-    if not self.__custom_headers or 'User-Agent' not in self.__custom_headers:
-      user_agent = 'Python/THttpClient'
-      script = os.path.basename(sys.argv[0])
-      if script:
-        user_agent = '%s (%s)' % (user_agent, urllib.quote(script))
-      self.__http.putheader('User-Agent', user_agent)
-
-    if self.__custom_headers:
-        for key, val in self.__custom_headers.iteritems():
-            self.__http.putheader(key, val)
-
-    self.__http.endheaders()
-
-    # Write payload
-    self.__http.send(data)
-
-    # Get reply to flush the request
-    self.code, self.message, self.headers = self.__http.getreply()
-
-  # Decorate if we know how to timeout
-  if hasattr(socket, 'getdefaulttimeout'):
-    flush = __withTimeout(flush)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TSSLSocket.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
deleted file mode 100644
index df35be4..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
+++ /dev/null
@@ -1,214 +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.
-#
-
-import os
-import socket
-import ssl
-
-import TSocket
-from TTransport import TTransportException
-
-
-class TSSLSocket(TSocket.TSocket):
-  """
-  SSL implementation of client-side TSocket
-
-  This class creates outbound sockets wrapped using the
-  python standard ssl module for encrypted connections.
-
-  The protocol used is set using the class variable
-  SSL_VERSION, which must be one of ssl.PROTOCOL_* and
-  defaults to  ssl.PROTOCOL_TLSv1 for greatest security.
-  """
-  SSL_VERSION = ssl.PROTOCOL_TLSv1
-
-  def __init__(self,
-               host='localhost',
-               port=9090,
-               validate=True,
-               ca_certs=None,
-               keyfile=None,
-               certfile=None,
-               unix_socket=None):
-    """Create SSL TSocket
-
-    @param validate: Set to False to disable SSL certificate validation
-    @type validate: bool
-    @param ca_certs: Filename to the Certificate Authority pem file, possibly a
-    file downloaded from: http://curl.haxx.se/ca/cacert.pem  This is passed to
-    the ssl_wrap function as the 'ca_certs' parameter.
-    @type ca_certs: str
-    @param keyfile: The private key
-    @type keyfile: str
-    @param certfile: The cert file
-    @type certfile: str
-    
-    Raises an IOError exception if validate is True and the ca_certs file is
-    None, not present or unreadable.
-    """
-    self.validate = validate
-    self.is_valid = False
-    self.peercert = None
-    if not validate:
-      self.cert_reqs = ssl.CERT_NONE
-    else:
-      self.cert_reqs = ssl.CERT_REQUIRED
-    self.ca_certs = ca_certs
-    self.keyfile = keyfile
-    self.certfile = certfile
-    if validate:
-      if ca_certs is None or not os.access(ca_certs, os.R_OK):
-        raise IOError('Certificate Authority ca_certs file "%s" '
-                      'is not readable, cannot validate SSL '
-                      'certificates.' % (ca_certs))
-    TSocket.TSocket.__init__(self, host, port, unix_socket)
-
-  def open(self):
-    try:
-      res0 = self._resolveAddr()
-      for res in res0:
-        sock_family, sock_type = res[0:2]
-        ip_port = res[4]
-        plain_sock = socket.socket(sock_family, sock_type)
-        self.handle = ssl.wrap_socket(plain_sock,
-                                      ssl_version=self.SSL_VERSION,
-                                      do_handshake_on_connect=True,
-                                      ca_certs=self.ca_certs,
-                                      keyfile=self.keyfile,
-                                      certfile=self.certfile,
-                                      cert_reqs=self.cert_reqs)
-        self.handle.settimeout(self._timeout)
-        try:
-          self.handle.connect(ip_port)
-        except socket.error, e:
-          if res is not res0[-1]:
-            continue
-          else:
-            raise e
-        break
-    except socket.error, e:
-      if self._unix_socket:
-        message = 'Could not connect to secure socket %s: %s' \
-                % (self._unix_socket, e)
-      else:
-        message = 'Could not connect to %s:%d: %s' % (self.host, self.port, e)
-      raise TTransportException(type=TTransportException.NOT_OPEN,
-                                message=message)
-    if self.validate:
-      self._validate_cert()
-
-  def _validate_cert(self):
-    """internal method to validate the peer's SSL certificate, and to check the
-    commonName of the certificate to ensure it matches the hostname we
-    used to make this connection.  Does not support subjectAltName records
-    in certificates.
-
-    raises TTransportException if the certificate fails validation.
-    """
-    cert = self.handle.getpeercert()
-    self.peercert = cert
-    if 'subject' not in cert:
-      raise TTransportException(
-        type=TTransportException.NOT_OPEN,
-        message='No SSL certificate found from %s:%s' % (self.host, self.port))
-    fields = cert['subject']
-    for field in fields:
-      # ensure structure we get back is what we expect
-      if not isinstance(field, tuple):
-        continue
-      cert_pair = field[0]
-      if len(cert_pair) < 2:
-        continue
-      cert_key, cert_value = cert_pair[0:2]
-      if cert_key != 'commonName':
-        continue
-      certhost = cert_value
-      # this check should be performed by some sort of Access Manager
-      if certhost == self.host:
-        # success, cert commonName matches desired hostname
-        self.is_valid = True
-        return
-      else:
-        raise TTransportException(
-          type=TTransportException.UNKNOWN,
-          message='Hostname we connected to "%s" doesn\'t match certificate '
-                  'provided commonName "%s"' % (self.host, certhost))
-    raise TTransportException(
-      type=TTransportException.UNKNOWN,
-      message='Could not validate SSL certificate from '
-              'host "%s".  Cert=%s' % (self.host, cert))
-
-
-class TSSLServerSocket(TSocket.TServerSocket):
-  """SSL implementation of TServerSocket
-
-  This uses the ssl module's wrap_socket() method to provide SSL
-  negotiated encryption.
-  """
-  SSL_VERSION = ssl.PROTOCOL_TLSv1
-
-  def __init__(self,
-               host=None,
-               port=9090,
-               certfile='cert.pem',
-               unix_socket=None):
-    """Initialize a TSSLServerSocket
-
-    @param certfile: filename of the server certificate, defaults to cert.pem
-    @type certfile: str
-    @param host: The hostname or IP to bind the listen socket to,
-                 i.e. 'localhost' for only allowing local network connections.
-                 Pass None to bind to all interfaces.
-    @type host: str
-    @param port: The port to listen on for inbound connections.
-    @type port: int
-    """
-    self.setCertfile(certfile)
-    TSocket.TServerSocket.__init__(self, host, port)
-
-  def setCertfile(self, certfile):
-    """Set or change the server certificate file used to wrap new connections.
-
-    @param certfile: The filename of the server certificate,
-                     i.e. '/etc/certs/server.pem'
-    @type certfile: str
-
-    Raises an IOError exception if the certfile is not present or unreadable.
-    """
-    if not os.access(certfile, os.R_OK):
-      raise IOError('No such certfile found: %s' % (certfile))
-    self.certfile = certfile
-
-  def accept(self):
-    plain_client, addr = self.handle.accept()
-    try:
-      client = ssl.wrap_socket(plain_client, certfile=self.certfile,
-                      server_side=True, ssl_version=self.SSL_VERSION)
-    except ssl.SSLError, ssl_exc:
-      # failed handshake/ssl wrap, close socket to client
-      plain_client.close()
-      # raise ssl_exc
-      # We can't raise the exception, because it kills most TServer derived
-      # serve() methods.
-      # Instead, return None, and let the TServer instance deal with it in
-      # other exception handling.  (but TSimpleServer dies anyway)
-      return None
-    result = TSocket.TSocket()
-    result.setHandle(client)
-    return result

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TSocket.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TSocket.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TSocket.py
deleted file mode 100644
index 9e2b384..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TSocket.py
+++ /dev/null
@@ -1,176 +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.
-#
-
-import errno
-import os
-import socket
-import sys
-
-from TTransport import *
-
-
-class TSocketBase(TTransportBase):
-  def _resolveAddr(self):
-    if self._unix_socket is not None:
-      return [(socket.AF_UNIX, socket.SOCK_STREAM, None, None,
-               self._unix_socket)]
-    else:
-      return socket.getaddrinfo(self.host,
-                                self.port,
-                                socket.AF_UNSPEC,
-                                socket.SOCK_STREAM,
-                                0,
-                                socket.AI_PASSIVE | socket.AI_ADDRCONFIG)
-
-  def close(self):
-    if self.handle:
-      self.handle.close()
-      self.handle = None
-
-
-class TSocket(TSocketBase):
-  """Socket implementation of TTransport base."""
-
-  def __init__(self, host='localhost', port=9090, unix_socket=None):
-    """Initialize a TSocket
-
-    @param host(str)  The host to connect to.
-    @param port(int)  The (TCP) port to connect to.
-    @param unix_socket(str)  The filename of a unix socket to connect to.
-                             (host and port will be ignored.)
-    """
-    self.host = host
-    self.port = port
-    self.handle = None
-    self._unix_socket = unix_socket
-    self._timeout = None
-
-  def setHandle(self, h):
-    self.handle = h
-
-  def isOpen(self):
-    return self.handle is not None
-
-  def setTimeout(self, ms):
-    if ms is None:
-      self._timeout = None
-    else:
-      self._timeout = ms / 1000.0
-
-    if self.handle is not None:
-      self.handle.settimeout(self._timeout)
-
-  def open(self):
-    try:
-      res0 = self._resolveAddr()
-      for res in res0:
-        self.handle = socket.socket(res[0], res[1])
-        self.handle.settimeout(self._timeout)
-        try:
-          self.handle.connect(res[4])
-        except socket.error, e:
-          if res is not res0[-1]:
-            continue
-          else:
-            raise e
-        break
-    except socket.error, e:
-      if self._unix_socket:
-        message = 'Could not connect to socket %s' % self._unix_socket
-      else:
-        message = 'Could not connect to %s:%d' % (self.host, self.port)
-      raise TTransportException(type=TTransportException.NOT_OPEN,
-                                message=message)
-
-  def read(self, sz):
-    try:
-      buff = self.handle.recv(sz)
-    except socket.error, e:
-      if (e.args[0] == errno.ECONNRESET and
-          (sys.platform == 'darwin' or sys.platform.startswith('freebsd'))):
-        # freebsd and Mach don't follow POSIX semantic of recv
-        # and fail with ECONNRESET if peer performed shutdown.
-        # See corresponding comment and code in TSocket::read()
-        # in lib/cpp/src/transport/TSocket.cpp.
-        self.close()
-        # Trigger the check to raise the END_OF_FILE exception below.
-        buff = ''
-      else:
-        raise
-    if len(buff) == 0:
-      raise TTransportException(type=TTransportException.END_OF_FILE,
-                                message='TSocket read 0 bytes')
-    return buff
-
-  def write(self, buff):
-    if not self.handle:
-      raise TTransportException(type=TTransportException.NOT_OPEN,
-                                message='Transport not open')
-    sent = 0
-    have = len(buff)
-    while sent < have:
-      plus = self.handle.send(buff)
-      if plus == 0:
-        raise TTransportException(type=TTransportException.END_OF_FILE,
-                                  message='TSocket sent 0 bytes')
-      sent += plus
-      buff = buff[plus:]
-
-  def flush(self):
-    pass
-
-
-class TServerSocket(TSocketBase, TServerTransportBase):
-  """Socket implementation of TServerTransport base."""
-
-  def __init__(self, host=None, port=9090, unix_socket=None):
-    self.host = host
-    self.port = port
-    self._unix_socket = unix_socket
-    self.handle = None
-
-  def listen(self):
-    res0 = self._resolveAddr()
-    for res in res0:
-      if res[0] is socket.AF_INET6 or res is res0[-1]:
-        break
-
-    # We need remove the old unix socket if the file exists and
-    # nobody is listening on it.
-    if self._unix_socket:
-      tmp = socket.socket(res[0], res[1])
-      try:
-        tmp.connect(res[4])
-      except socket.error, err:
-        eno, message = err.args
-        if eno == errno.ECONNREFUSED:
-          os.unlink(res[4])
-
-    self.handle = socket.socket(res[0], res[1])
-    self.handle.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-    if hasattr(self.handle, 'settimeout'):
-      self.handle.settimeout(None)
-    self.handle.bind(res[4])
-    self.handle.listen(128)
-
-  def accept(self):
-    client, addr = self.handle.accept()
-    result = TSocket()
-    result.setHandle(client)
-    return result

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TTransport.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TTransport.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TTransport.py
deleted file mode 100644
index ed023d5..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TTransport.py
+++ /dev/null
@@ -1,330 +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.
-#
-
-from cStringIO import StringIO
-from struct import pack, unpack
-from ..Thrift import TException
-
-
-class TTransportException(TException):
-  """Custom Transport Exception class"""
-
-  UNKNOWN = 0
-  NOT_OPEN = 1
-  ALREADY_OPEN = 2
-  TIMED_OUT = 3
-  END_OF_FILE = 4
-
-  def __init__(self, type=UNKNOWN, message=None):
-    TException.__init__(self, message)
-    self.type = type
-
-
-class TTransportBase:
-  """Base class for Thrift transport layer."""
-
-  def isOpen(self):
-    pass
-
-  def open(self):
-    pass
-
-  def close(self):
-    pass
-
-  def read(self, sz):
-    pass
-
-  def readAll(self, sz):
-    buff = ''
-    have = 0
-    while (have < sz):
-      chunk = self.read(sz - have)
-      have += len(chunk)
-      buff += chunk
-
-      if len(chunk) == 0:
-        raise EOFError()
-
-    return buff
-
-  def write(self, buf):
-    pass
-
-  def flush(self):
-    pass
-
-
-# This class should be thought of as an interface.
-class CReadableTransport:
-  """base class for transports that are readable from C"""
-
-  # TODO(dreiss): Think about changing this interface to allow us to use
-  #               a (Python, not c) StringIO instead, because it allows
-  #               you to write after reading.
-
-  # NOTE: This is a classic class, so properties will NOT work
-  #       correctly for setting.
-  @property
-  def cstringio_buf(self):
-    """A cStringIO buffer that contains the current chunk we are reading."""
-    pass
-
-  def cstringio_refill(self, partialread, reqlen):
-    """Refills cstringio_buf.
-
-    Returns the currently used buffer (which can but need not be the same as
-    the old cstringio_buf). partialread is what the C code has read from the
-    buffer, and should be inserted into the buffer before any more reads.  The
-    return value must be a new, not borrowed reference.  Something along the
-    lines of self._buf should be fine.
-
-    If reqlen bytes can't be read, throw EOFError.
-    """
-    pass
-
-
-class TServerTransportBase:
-  """Base class for Thrift server transports."""
-
-  def listen(self):
-    pass
-
-  def accept(self):
-    pass
-
-  def close(self):
-    pass
-
-
-class TTransportFactoryBase:
-  """Base class for a Transport Factory"""
-
-  def getTransport(self, trans):
-    return trans
-
-
-class TBufferedTransportFactory:
-  """Factory transport that builds buffered transports"""
-
-  def getTransport(self, trans):
-    buffered = TBufferedTransport(trans)
-    return buffered
-
-
-class TBufferedTransport(TTransportBase, CReadableTransport):
-  """Class that wraps another transport and buffers its I/O.
-
-  The implementation uses a (configurable) fixed-size read buffer
-  but buffers all writes until a flush is performed.
-  """
-  DEFAULT_BUFFER = 4096
-
-  def __init__(self, trans, rbuf_size=DEFAULT_BUFFER):
-    self.__trans = trans
-    self.__wbuf = StringIO()
-    self.__rbuf = StringIO("")
-    self.__rbuf_size = rbuf_size
-
-  def isOpen(self):
-    return self.__trans.isOpen()
-
-  def open(self):
-    return self.__trans.open()
-
-  def close(self):
-    return self.__trans.close()
-
-  def read(self, sz):
-    ret = self.__rbuf.read(sz)
-    if len(ret) != 0:
-      return ret
-
-    self.__rbuf = StringIO(self.__trans.read(max(sz, self.__rbuf_size)))
-    return self.__rbuf.read(sz)
-
-  def write(self, buf):
-    self.__wbuf.write(buf)
-
-  def flush(self):
-    out = self.__wbuf.getvalue()
-    # reset wbuf before write/flush to preserve state on underlying failure
-    self.__wbuf = StringIO()
-    self.__trans.write(out)
-    self.__trans.flush()
-
-  # Implement the CReadableTransport interface.
-  @property
-  def cstringio_buf(self):
-    return self.__rbuf
-
-  def cstringio_refill(self, partialread, reqlen):
-    retstring = partialread
-    if reqlen < self.__rbuf_size:
-      # try to make a read of as much as we can.
-      retstring += self.__trans.read(self.__rbuf_size)
-
-    # but make sure we do read reqlen bytes.
-    if len(retstring) < reqlen:
-      retstring += self.__trans.readAll(reqlen - len(retstring))
-
-    self.__rbuf = StringIO(retstring)
-    return self.__rbuf
-
-
-class TMemoryBuffer(TTransportBase, CReadableTransport):
-  """Wraps a cStringIO object as a TTransport.
-
-  NOTE: Unlike the C++ version of this class, you cannot write to it
-        then immediately read from it.  If you want to read from a
-        TMemoryBuffer, you must either pass a string to the constructor.
-  TODO(dreiss): Make this work like the C++ version.
-  """
-
-  def __init__(self, value=None):
-    """value -- a value to read from for stringio
-
-    If value is set, this will be a transport for reading,
-    otherwise, it is for writing"""
-    if value is not None:
-      self._buffer = StringIO(value)
-    else:
-      self._buffer = StringIO()
-
-  def isOpen(self):
-    return not self._buffer.closed
-
-  def open(self):
-    pass
-
-  def close(self):
-    self._buffer.close()
-
-  def read(self, sz):
-    return self._buffer.read(sz)
-
-  def write(self, buf):
-    self._buffer.write(buf)
-
-  def flush(self):
-    pass
-
-  def getvalue(self):
-    return self._buffer.getvalue()
-
-  # Implement the CReadableTransport interface.
-  @property
-  def cstringio_buf(self):
-    return self._buffer
-
-  def cstringio_refill(self, partialread, reqlen):
-    # only one shot at reading...
-    raise EOFError()
-
-
-class TFramedTransportFactory:
-  """Factory transport that builds framed transports"""
-
-  def getTransport(self, trans):
-    framed = TFramedTransport(trans)
-    return framed
-
-
-class TFramedTransport(TTransportBase, CReadableTransport):
-  """Class that wraps another transport and frames its I/O when writing."""
-
-  def __init__(self, trans,):
-    self.__trans = trans
-    self.__rbuf = StringIO()
-    self.__wbuf = StringIO()
-
-  def isOpen(self):
-    return self.__trans.isOpen()
-
-  def open(self):
-    return self.__trans.open()
-
-  def close(self):
-    return self.__trans.close()
-
-  def read(self, sz):
-    ret = self.__rbuf.read(sz)
-    if len(ret) != 0:
-      return ret
-
-    self.readFrame()
-    return self.__rbuf.read(sz)
-
-  def readFrame(self):
-    buff = self.__trans.readAll(4)
-    sz, = unpack('!i', buff)
-    self.__rbuf = StringIO(self.__trans.readAll(sz))
-
-  def write(self, buf):
-    self.__wbuf.write(buf)
-
-  def flush(self):
-    wout = self.__wbuf.getvalue()
-    wsz = len(wout)
-    # reset wbuf before write/flush to preserve state on underlying failure
-    self.__wbuf = StringIO()
-    # N.B.: Doing this string concatenation is WAY cheaper than making
-    # two separate calls to the underlying socket object. Socket writes in
-    # Python turn out to be REALLY expensive, but it seems to do a pretty
-    # good job of managing string buffer operations without excessive copies
-    buf = pack("!i", wsz) + wout
-    self.__trans.write(buf)
-    self.__trans.flush()
-
-  # Implement the CReadableTransport interface.
-  @property
-  def cstringio_buf(self):
-    return self.__rbuf
-
-  def cstringio_refill(self, prefix, reqlen):
-    # self.__rbuf will already be empty here because fastbinary doesn't
-    # ask for a refill until the previous buffer is empty.  Therefore,
-    # we can start reading new frames immediately.
-    while len(prefix) < reqlen:
-      self.readFrame()
-      prefix += self.__rbuf.getvalue()
-    self.__rbuf = StringIO(prefix)
-    return self.__rbuf
-
-
-class TFileObjectTransport(TTransportBase):
-  """Wraps a file-like object to make it work as a Thrift transport."""
-
-  def __init__(self, fileobj):
-    self.fileobj = fileobj
-
-  def isOpen(self):
-    return True
-
-  def close(self):
-    self.fileobj.close()
-
-  def read(self, sz):
-    return self.fileobj.read(sz)
-
-  def write(self, buf):
-    self.fileobj.write(buf)
-
-  def flush(self):
-    self.fileobj.flush()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TTwisted.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TTwisted.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TTwisted.py
deleted file mode 100644
index 6cdb172..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TTwisted.py
+++ /dev/null
@@ -1,221 +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.
-#
-
-from cStringIO import StringIO
-
-from zope.interface import implements, Interface, Attribute
-from twisted.internet.protocol import Protocol, ServerFactory, ClientFactory, \
-    connectionDone
-from twisted.internet import defer
-from twisted.protocols import basic
-from twisted.python import log
-from twisted.web import server, resource, http
-
-import TTransport
-
-
-class TMessageSenderTransport(TTransport.TTransportBase):
-
-    def __init__(self):
-        self.__wbuf = StringIO()
-
-    def write(self, buf):
-        self.__wbuf.write(buf)
-
-    def flush(self):
-        msg = self.__wbuf.getvalue()
-        self.__wbuf = StringIO()
-        self.sendMessage(msg)
-
-    def sendMessage(self, message):
-        raise NotImplementedError
-
-
-class TCallbackTransport(TMessageSenderTransport):
-
-    def __init__(self, func):
-        TMessageSenderTransport.__init__(self)
-        self.func = func
-
-    def sendMessage(self, message):
-        self.func(message)
-
-
-class ThriftClientProtocol(basic.Int32StringReceiver):
-
-    MAX_LENGTH = 2 ** 31 - 1
-
-    def __init__(self, client_class, iprot_factory, oprot_factory=None):
-        self._client_class = client_class
-        self._iprot_factory = iprot_factory
-        if oprot_factory is None:
-            self._oprot_factory = iprot_factory
-        else:
-            self._oprot_factory = oprot_factory
-
-        self.recv_map = {}
-        self.started = defer.Deferred()
-
-    def dispatch(self, msg):
-        self.sendString(msg)
-
-    def connectionMade(self):
-        tmo = TCallbackTransport(self.dispatch)
-        self.client = self._client_class(tmo, self._oprot_factory)
-        self.started.callback(self.client)
-
-    def connectionLost(self, reason=connectionDone):
-        for k, v in self.client._reqs.iteritems():
-            tex = TTransport.TTransportException(
-                type=TTransport.TTransportException.END_OF_FILE,
-                message='Connection closed')
-            v.errback(tex)
-
-    def stringReceived(self, frame):
-        tr = TTransport.TMemoryBuffer(frame)
-        iprot = self._iprot_factory.getProtocol(tr)
-        (fname, mtype, rseqid) = iprot.readMessageBegin()
-
-        try:
-            method = self.recv_map[fname]
-        except KeyError:
-            method = getattr(self.client, 'recv_' + fname)
-            self.recv_map[fname] = method
-
-        method(iprot, mtype, rseqid)
-
-
-class ThriftServerProtocol(basic.Int32StringReceiver):
-
-    MAX_LENGTH = 2 ** 31 - 1
-
-    def dispatch(self, msg):
-        self.sendString(msg)
-
-    def processError(self, error):
-        self.transport.loseConnection()
-
-    def processOk(self, _, tmo):
-        msg = tmo.getvalue()
-
-        if len(msg) > 0:
-            self.dispatch(msg)
-
-    def stringReceived(self, frame):
-        tmi = TTransport.TMemoryBuffer(frame)
-        tmo = TTransport.TMemoryBuffer()
-
-        iprot = self.factory.iprot_factory.getProtocol(tmi)
-        oprot = self.factory.oprot_factory.getProtocol(tmo)
-
-        d = self.factory.processor.process(iprot, oprot)
-        d.addCallbacks(self.processOk, self.processError,
-            callbackArgs=(tmo,))
-
-
-class IThriftServerFactory(Interface):
-
-    processor = Attribute("Thrift processor")
-
-    iprot_factory = Attribute("Input protocol factory")
-
-    oprot_factory = Attribute("Output protocol factory")
-
-
-class IThriftClientFactory(Interface):
-
-    client_class = Attribute("Thrift client class")
-
-    iprot_factory = Attribute("Input protocol factory")
-
-    oprot_factory = Attribute("Output protocol factory")
-
-
-class ThriftServerFactory(ServerFactory):
-
-    implements(IThriftServerFactory)
-
-    protocol = ThriftServerProtocol
-
-    def __init__(self, processor, iprot_factory, oprot_factory=None):
-        self.processor = processor
-        self.iprot_factory = iprot_factory
-        if oprot_factory is None:
-            self.oprot_factory = iprot_factory
-        else:
-            self.oprot_factory = oprot_factory
-
-
-class ThriftClientFactory(ClientFactory):
-
-    implements(IThriftClientFactory)
-
-    protocol = ThriftClientProtocol
-
-    def __init__(self, client_class, iprot_factory, oprot_factory=None):
-        self.client_class = client_class
-        self.iprot_factory = iprot_factory
-        if oprot_factory is None:
-            self.oprot_factory = iprot_factory
-        else:
-            self.oprot_factory = oprot_factory
-
-    def buildProtocol(self, addr):
-        p = self.protocol(self.client_class, self.iprot_factory,
-            self.oprot_factory)
-        p.factory = self
-        return p
-
-
-class ThriftResource(resource.Resource):
-
-    allowedMethods = ('POST',)
-
-    def __init__(self, processor, inputProtocolFactory,
-        outputProtocolFactory=None):
-        resource.Resource.__init__(self)
-        self.inputProtocolFactory = inputProtocolFactory
-        if outputProtocolFactory is None:
-            self.outputProtocolFactory = inputProtocolFactory
-        else:
-            self.outputProtocolFactory = outputProtocolFactory
-        self.processor = processor
-
-    def getChild(self, path, request):
-        return self
-
-    def _cbProcess(self, _, request, tmo):
-        msg = tmo.getvalue()
-        request.setResponseCode(http.OK)
-        request.setHeader("content-type", "application/x-thrift")
-        request.write(msg)
-        request.finish()
-
-    def render_POST(self, request):
-        request.content.seek(0, 0)
-        data = request.content.read()
-        tmi = TTransport.TMemoryBuffer(data)
-        tmo = TTransport.TMemoryBuffer()
-
-        iprot = self.inputProtocolFactory.getProtocol(tmi)
-        oprot = self.outputProtocolFactory.getProtocol(tmo)
-
-        d = self.processor.process(iprot, oprot)
-        d.addCallback(self._cbProcess, request, tmo)
-        return server.NOT_DONE_YET

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TZlibTransport.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
deleted file mode 100644
index 2bdfd14..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
+++ /dev/null
@@ -1,249 +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.
-#
-
-"""TZlibTransport provides a compressed transport and transport factory
-class, using the python standard library zlib module to implement
-data compression.
-"""
-
-from __future__ import division
-import zlib
-from cStringIO import StringIO
-
-from TTransport import TTransportBase, CReadableTransport
-
-
-class TZlibTransportFactory(object):
-  """Factory transport that builds zlib compressed transports.
-
-  This factory caches the last single client/transport that it was passed
-  and returns the same TZlibTransport object that was created.
-
-  This caching means the TServer class will get the _same_ transport
-  object for both input and output transports from this factory.
-  (For non-threaded scenarios only, since the cache only holds one object)
-
-  The purpose of this caching is to allocate only one TZlibTransport where
-  only one is really needed (since it must have separate read/write buffers),
-  and makes the statistics from getCompSavings() and getCompRatio()
-  easier to understand.
-  """
-  # class scoped cache of last transport given and zlibtransport returned
-  _last_trans = None
-  _last_z = None
-
-  def getTransport(self, trans, compresslevel=9):
-    """Wrap a transport, trans, with the TZlibTransport
-    compressed transport class, returning a new
-    transport to the caller.
-
-    @param compresslevel: The zlib compression level, ranging
-    from 0 (no compression) to 9 (best compression).  Defaults to 9.
-    @type compresslevel: int
-
-    This method returns a TZlibTransport which wraps the
-    passed C{trans} TTransport derived instance.
-    """
-    if trans == self._last_trans:
-      return self._last_z
-    ztrans = TZlibTransport(trans, compresslevel)
-    self._last_trans = trans
-    self._last_z = ztrans
-    return ztrans
-
-
-class TZlibTransport(TTransportBase, CReadableTransport):
-  """Class that wraps a transport with zlib, compressing writes
-  and decompresses reads, using the python standard
-  library zlib module.
-  """
-  # Read buffer size for the python fastbinary C extension,
-  # the TBinaryProtocolAccelerated class.
-  DEFAULT_BUFFSIZE = 4096
-
-  def __init__(self, trans, compresslevel=9):
-    """Create a new TZlibTransport, wrapping C{trans}, another
-    TTransport derived object.
-
-    @param trans: A thrift transport object, i.e. a TSocket() object.
-    @type trans: TTransport
-    @param compresslevel: The zlib compression level, ranging
-    from 0 (no compression) to 9 (best compression).  Default is 9.
-    @type compresslevel: int
-    """
-    self.__trans = trans
-    self.compresslevel = compresslevel
-    self.__rbuf = StringIO()
-    self.__wbuf = StringIO()
-    self._init_zlib()
-    self._init_stats()
-
-  def _reinit_buffers(self):
-    """Internal method to initialize/reset the internal StringIO objects
-    for read and write buffers.
-    """
-    self.__rbuf = StringIO()
-    self.__wbuf = StringIO()
-
-  def _init_stats(self):
-    """Internal method to reset the internal statistics counters
-    for compression ratios and bandwidth savings.
-    """
-    self.bytes_in = 0
-    self.bytes_out = 0
-    self.bytes_in_comp = 0
-    self.bytes_out_comp = 0
-
-  def _init_zlib(self):
-    """Internal method for setting up the zlib compression and
-    decompression objects.
-    """
-    self._zcomp_read = zlib.decompressobj()
-    self._zcomp_write = zlib.compressobj(self.compresslevel)
-
-  def getCompRatio(self):
-    """Get the current measured compression ratios (in,out) from
-    this transport.
-
-    Returns a tuple of:
-    (inbound_compression_ratio, outbound_compression_ratio)
-
-    The compression ratios are computed as:
-        compressed / uncompressed
-
-    E.g., data that compresses by 10x will have a ratio of: 0.10
-    and data that compresses to half of ts original size will
-    have a ratio of 0.5
-
-    None is returned if no bytes have yet been processed in
-    a particular direction.
-    """
-    r_percent, w_percent = (None, None)
-    if self.bytes_in > 0:
-      r_percent = self.bytes_in_comp / self.bytes_in
-    if self.bytes_out > 0:
-      w_percent = self.bytes_out_comp / self.bytes_out
-    return (r_percent, w_percent)
-
-  def getCompSavings(self):
-    """Get the current count of saved bytes due to data
-    compression.
-
-    Returns a tuple of:
-    (inbound_saved_bytes, outbound_saved_bytes)
-
-    Note: if compression is actually expanding your
-    data (only likely with very tiny thrift objects), then
-    the values returned will be negative.
-    """
-    r_saved = self.bytes_in - self.bytes_in_comp
-    w_saved = self.bytes_out - self.bytes_out_comp
-    return (r_saved, w_saved)
-
-  def isOpen(self):
-    """Return the underlying transport's open status"""
-    return self.__trans.isOpen()
-
-  def open(self):
-    """Open the underlying transport"""
-    self._init_stats()
-    return self.__trans.open()
-
-  def listen(self):
-    """Invoke the underlying transport's listen() method"""
-    self.__trans.listen()
-
-  def accept(self):
-    """Accept connections on the underlying transport"""
-    return self.__trans.accept()
-
-  def close(self):
-    """Close the underlying transport,"""
-    self._reinit_buffers()
-    self._init_zlib()
-    return self.__trans.close()
-
-  def read(self, sz):
-    """Read up to sz bytes from the decompressed bytes buffer, and
-    read from the underlying transport if the decompression
-    buffer is empty.
-    """
-    ret = self.__rbuf.read(sz)
-    if len(ret) > 0:
-      return ret
-    # keep reading from transport until something comes back
-    while True:
-      if self.readComp(sz):
-        break
-    ret = self.__rbuf.read(sz)
-    return ret
-
-  def readComp(self, sz):
-    """Read compressed data from the underlying transport, then
-    decompress it and append it to the internal StringIO read buffer
-    """
-    zbuf = self.__trans.read(sz)
-    zbuf = self._zcomp_read.unconsumed_tail + zbuf
-    buf = self._zcomp_read.decompress(zbuf)
-    self.bytes_in += len(zbuf)
-    self.bytes_in_comp += len(buf)
-    old = self.__rbuf.read()
-    self.__rbuf = StringIO(old + buf)
-    if len(old) + len(buf) == 0:
-      return False
-    return True
-
-  def write(self, buf):
-    """Write some bytes, putting them into the internal write
-    buffer for eventual compression.
-    """
-    self.__wbuf.write(buf)
-
-  def flush(self):
-    """Flush any queued up data in the write buffer and ensure the
-    compression buffer is flushed out to the underlying transport
-    """
-    wout = self.__wbuf.getvalue()
-    if len(wout) > 0:
-      zbuf = self._zcomp_write.compress(wout)
-      self.bytes_out += len(wout)
-      self.bytes_out_comp += len(zbuf)
-    else:
-      zbuf = ''
-    ztail = self._zcomp_write.flush(zlib.Z_SYNC_FLUSH)
-    self.bytes_out_comp += len(ztail)
-    if (len(zbuf) + len(ztail)) > 0:
-      self.__wbuf = StringIO()
-      self.__trans.write(zbuf + ztail)
-    self.__trans.flush()
-
-  @property
-  def cstringio_buf(self):
-    """Implement the CReadableTransport interface"""
-    return self.__rbuf
-
-  def cstringio_refill(self, partialread, reqlen):
-    """Implement the CReadableTransport interface for refill"""
-    retstring = partialread
-    if reqlen < self.DEFAULT_BUFFSIZE:
-      retstring += self.read(self.DEFAULT_BUFFSIZE)
-    while len(retstring) < reqlen:
-      retstring += self.read(reqlen - len(retstring))
-    self.__rbuf = StringIO(retstring)
-    return self.__rbuf

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/__init__.py
deleted file mode 100644
index c9596d9..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/transport/__init__.py
+++ /dev/null
@@ -1,20 +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.
-#
-
-__all__ = ['TTransport', 'TSocket', 'THttpClient', 'TZlibTransport']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/__init__.py
deleted file mode 100644
index a595c84..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/__init__.py
+++ /dev/null
@@ -1,18 +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.
-
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/exception/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/exception/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/exception/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/exception/datapublisherexception.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/exception/datapublisherexception.py b/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/exception/datapublisherexception.py
deleted file mode 100644
index fc4bfc9..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/exception/datapublisherexception.py
+++ /dev/null
@@ -1,33 +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.
-
-class DataPublisherException(Exception):
-    """
-    Exception to be used during log publishing operations
-    """
-
-    def __init__(self, msg):
-        super(self,  msg)
-        self.message = msg
-
-    def get_message(self):
-        """
-        The message provided when the exception is raised
-        :return: message
-        :rtype: str
-        """
-        return self.message

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/logpublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/logpublisher.py b/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/logpublisher.py
deleted file mode 100644
index 050dd9e..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/datapublisher/logpublisher.py
+++ /dev/null
@@ -1,273 +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.
-
-import os
-import datetime
-from threading import Thread, current_thread
-
-from ..databridge.agent import *
-from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
-from ..util import cartridgeagentutils, cartridgeagentconstants
-from exception.datapublisherexception import DataPublisherException
-
-
-class LogPublisher(Thread):
-
-    def __init__(self, file_path, stream_definition, tenant_id, alias, date_time, member_id):
-        Thread.__init__(self)
-
-        self.log = LogFactory().get_log(__name__)
-
-        self.file_path = file_path
-        self.thrift_publisher = ThriftPublisher(
-            DataPublisherConfiguration.get_instance().monitoring_server_ip,
-            DataPublisherConfiguration.get_instance().monitoring_server_port,
-            DataPublisherConfiguration.get_instance().admin_username,
-            DataPublisherConfiguration.get_instance().admin_password,
-            stream_definition)
-        self.tenant_id = tenant_id
-        self.alias = alias
-        self.datetime = date_time
-        self.member_id = member_id
-
-        self.terminated = False
-
-    def run(self):
-        if os.path.isfile(self.file_path) and os.access(self.file_path, os.R_OK):
-            self.log.info("Starting log publisher for file: " + self.file_path + ", thread: " + current_thread())
-            # open file and keep reading for new entries
-            read_file = open(self.file_path, "r")
-            read_file.seek(os.stat(self.file_path)[6])  # go to the end of the file
-
-            while not self.terminated:
-                where = read_file.tell()  # where the seeker is in the file
-                line = read_file.readline()   # read the current line
-                if not line:
-                    # no new line entered
-                    time.sleep(1)
-                    read_file.seek(where)  # set seeker
-                else:
-                    # new line detected, create event object
-                    event = ThriftEvent()
-                    event.metaData.append(self.member_id)
-                    event.payloadData.append(self.tenant_id)
-                    event.payloadData.append(self.alias)
-                    event.payloadData.append("")
-                    event.payloadData.append(self.datetime)
-                    event.payloadData.append("")
-                    event.payloadData.append(line)
-                    event.payloadData.append("")
-                    event.payloadData.append("")
-                    event.payloadData.append(self.member_id)
-                    event.payloadData.append("")
-
-                    self.thrift_publisher.publish(event)
-
-            self.thrift_publisher.disconnect()  # dicsonnect the publisher upon being terminated
-        else:
-            raise DataPublisherException("Unable to read the file at path %r" % self.file_path)
-
-    def terminate(self):
-        """
-        Allows the LogPublisher thread to be terminated to stop publishing to BAM/CEP. Allow a minimum of 1 second delay
-        to take effect.
-        """
-        self.terminated = True
-
-
-class LogPublisherManager(Thread):
-    """
-    A log publishing thread management thread which maintains a log publisher for each log file. Also defines a stream
-    definition and the BAM/CEP server information for a single publishing context.
-    """
-
-    @staticmethod
-    def define_stream():
-        """
-        Creates a stream definition for Log Publishing
-        :return: A StreamDefinition object with the required attributes added
-        :rtype : StreamDefinition
-        """
-        # stream definition
-        stream_definition = StreamDefinition()
-        valid_tenant_id = LogPublisherManager.get_valid_tenant_id(CartridgeAgentConfiguration().tenant_id)
-        alias = LogPublisherManager.get_alias(CartridgeAgentConfiguration().cluster_id)
-        stream_name = "logs." + valid_tenant_id + "." \
-                      + alias + "." + LogPublisherManager.get_current_date()
-        stream_version = "1.0.0"
-
-        stream_definition.name = stream_name
-        stream_definition.version = stream_version
-        stream_definition.description = "Apache Stratos Instance Log Publisher"
-        stream_definition.add_metadata_attribute("memberId", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("tenantID", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("serverName", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("appName", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("logTime", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("priority", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("message", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("logger", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("ip", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("instance", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("stacktrace", StreamDefinition.STRING)
-
-        return stream_definition
-
-    def __init__(self, logfile_paths):
-        Thread.__init__(self)
-        self.logfile_paths = logfile_paths
-        self.publishers = {}
-        self.ports = []
-        self.ports.append(DataPublisherConfiguration.get_instance().monitoring_server_port)
-        self.ports.append(DataPublisherConfiguration.get_instance().monitoring_server_secure_port)
-
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-        cartridgeagentutils.wait_until_ports_active(
-            DataPublisherConfiguration.get_instance().monitoring_server_ip,
-            self.ports,
-            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False)))
-
-        ports_active = cartridgeagentutils.check_ports_active(
-            DataPublisherConfiguration.get_instance().monitoring_server_ip,
-            self.ports)
-
-        if not ports_active:
-            raise DataPublisherException("Monitoring server not active, data publishing is aborted")
-
-        self.stream_definition = self.define_stream()
-
-    def run(self):
-        if self.logfile_paths is not None and len(self.logfile_paths):
-            for log_path in self.logfile_paths:
-                # thread for each log file
-                publisher = self.get_publisher(log_path)
-                publisher.start()
-
-    def get_publisher(self, log_path):
-        """
-        Retrieve the publisher for the specified log file path. Creates a new LogPublisher if one is not available
-        :return: The LogPublisher object
-        :rtype : LogPublisher
-        """
-        if log_path not in self.publishers:
-            self.publishers[log_path] = LogPublisher(log_path, self.stream_definition)
-
-        return self.publishers[log_path]
-
-    def terminate_publisher(self, log_path):
-        """
-        Terminates the LogPublisher thread associated with the specified log file
-        """
-        if log_path in self.publishers:
-            self.publishers[log_path].terminate()
-
-    def terminate_all_publishers(self):
-        """
-        Terminates all LogPublisher threads
-        """
-        for publisher in self.publishers:
-            publisher.terminate()
-
-    @staticmethod
-    def get_valid_tenant_id(tenant_id):
-        if tenant_id == cartridgeagentconstants.INVALID_TENANT_ID \
-                or tenant_id == cartridgeagentconstants.SUPER_TENANT_ID:
-            return "0"
-
-        return tenant_id
-
-    @staticmethod
-    def get_alias(cluster_id):
-        try:
-            alias = cluster_id.split("\\.")[0]
-        except:
-            alias = cluster_id
-
-        return alias
-
-    @staticmethod
-    def get_current_date():
-        """
-        Returns the current date formatted as yyyy-MM-dd
-        :return: Formatted date string
-        :rtype : str
-        """
-        return datetime.date.today().strftime(cartridgeagentconstants.DATE_FORMAT)
-
-
-class DataPublisherConfiguration:
-    """
-    A singleton implementation to access configuration information for data publishing to BAM/CEP
-    TODO: perfect singleton impl ex: Borg
-    """
-
-    __instance = None
-    log = LogFactory().get_log(__name__)
-
-    @staticmethod
-    def get_instance():
-        """
-        Singleton instance retriever
-        :return: Instance
-        :rtype : DataPublisherConfiguration
-        """
-        if DataPublisherConfiguration.__instance is None:
-            DataPublisherConfiguration.__instance = DataPublisherConfiguration()
-
-        return DataPublisherConfiguration.__instance
-
-    def __init__(self):
-        self.enabled = False
-        self.monitoring_server_ip = None
-        self.monitoring_server_port = None
-        self.monitoring_server_secure_port = None
-        self.admin_username = None
-        self.admin_password = None
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-        self.read_config()
-
-    def read_config(self):
-        self.enabled = True if self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_PUBLISHER_ENABLED, False).strip().lower() == "true" else False
-        if not self.enabled:
-            DataPublisherConfiguration.log.info("Data Publisher disabled")
-            return
-
-        DataPublisherConfiguration.log.info("Data Publisher enabled")
-
-        self.monitoring_server_ip = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_RECEIVER_IP, False)
-        if self.monitoring_server_ip is None or self.monitoring_server_ip.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_RECEIVER_IP)
-
-        self.monitoring_server_port = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_RECEIVER_PORT, False)
-        if self.monitoring_server_port is None or self.monitoring_server_port.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_RECEIVER_PORT)
-
-        self.monitoring_server_secure_port = self.cartridge_agent_config.read_property("monitoring.server.secure.port", False)
-        if self.monitoring_server_secure_port is None or self.monitoring_server_secure_port.strip() == "":
-            raise RuntimeError("System property not found: monitoring.server.secure.port")
-
-        self.admin_username = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_SERVER_ADMIN_USERNAME, False)
-        if self.admin_username is None or self.admin_username.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_SERVER_ADMIN_USERNAME)
-
-        self.admin_password = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_SERVER_ADMIN_PASSWORD, False)
-        if self.admin_password is None or self.admin_password.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_SERVER_ADMIN_PASSWORD)
-
-        DataPublisherConfiguration.log.info("Data Publisher configuration initialized")

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/event/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/__init__.py
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/notifier/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/notifier/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/notifier/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/notifier/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/notifier/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/notifier/events.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/notifier/events.py
deleted file mode 100644
index 024e1e4..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/notifier/events.py
+++ /dev/null
@@ -1,77 +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.
-
-import json
-
-
-class ArtifactUpdatedEvent:
-    def __init__(self):
-        self.cluster_id = None
-        """ :type : str  """
-        self.status = None
-        """ :type : str  """
-        self.repo_username = None
-        """ :type : str  """
-        self.repo_password = None
-        """ :type : str  """
-        self.repo_url = None
-        """ :type : str  """
-        self.tenant_id = None
-        """ :type : int  """
-        self.commit_enabled = None
-        """ :type : bool  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = ArtifactUpdatedEvent()
-
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.status = json_obj["status"] if "status" in json_obj else None
-        instance.repo_username = json_obj["repoUserName"] if "repoUserName" in json_obj else None
-        instance.repo_password = json_obj["repoPassword"] if "repoPassword" in json_obj else None
-        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.repo_url = json_obj["repoUrl"] if "repoUrl" in json_obj else ""
-        instance.commit_enabled = json_obj["commitEnabled"] if "commitEnabled" in json_obj else None
-
-        return instance
-
-
-class InstanceCleanupClusterEvent:
-    def __init__(self, cluster_id):
-        self.cluster_id = cluster_id
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        c_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-
-        return InstanceCleanupClusterEvent(c_id)
-
-
-class InstanceCleanupMemberEvent:
-    def __init__(self, member_id):
-        self.member_id = member_id
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        m_id = json_obj["memberId"] if "memberId" in json_obj else None
-
-        return InstanceCleanupMemberEvent(m_id)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/status/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/status/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/status/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/status/__init__.py
+++ /dev/null
@@ -1,17 +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.
-


[41/50] [abbrv] git commit: Added failure test case for password decryption Added skeletal tests for other util methods

Posted by im...@apache.org.
Added failure test case for password decryption
Added skeletal tests for other util methods


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

Branch: refs/heads/master
Commit: ebf9e0b53ca8848c66e29879428bd110d9444c8e
Parents: 5493e99
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Tue Oct 21 09:57:19 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Tue Oct 21 09:57:19 2014 +0530

----------------------------------------------------------------------
 tools/python_cartridgeagent/test/test_util.py | 30 ++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/ebf9e0b5/tools/python_cartridgeagent/test/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/test_util.py b/tools/python_cartridgeagent/test/test_util.py
index 63e93cf..2b4186e 100644
--- a/tools/python_cartridgeagent/test/test_util.py
+++ b/tools/python_cartridgeagent/test/test_util.py
@@ -41,7 +41,7 @@ class TestTask(AbstractAsyncScheduledTask):
             f.write("%1.4f" % (time.time()*1000))
 
 
-def test_decrypt_password():
+def test_decrypt_password_success():
     # def mockgetlog(path):
     #     return mocklog
     #
@@ -52,4 +52,30 @@ def test_decrypt_password():
     secret_key = "tvnw63ufg9gh5111"
     encrypted_password= "jP1lZ5xMlpLzu8MbY2Porg=="
 
-    assert cartridgeagentutils.decrypt_password(encrypted_password, secret_key) == plain_password, "Password decryption failed"
\ No newline at end of file
+    assert cartridgeagentutils.decrypt_password(encrypted_password, secret_key) == plain_password, "Password decryption failed"
+
+
+def test_decrypt_password_failure():
+    plain_password = "plaintext"
+    secret_key = "notsecretkeyhere"
+    encrypted_password= "jP1lZ5xMlpLzu8MbY2Porg=="
+    assert cartridgeagentutils.decrypt_password(encrypted_password, secret_key) != plain_password, "Password decrypted for wrong key"
+
+
+def test_create_dir_normal():
+    assert True
+
+def test_create_dir_system_path():
+    assert True
+
+def test_create_dir_existing_dir():
+    assert True
+
+def test_wait_for_ports_activity_normal():
+    assert True
+
+def test_wait_for_ports_activity_non_existent():
+    assert True
+
+def test_wait_for_ports_activity_timeout():
+    assert True
\ No newline at end of file


[14/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py b/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
deleted file mode 100644
index 4ceb948..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
+++ /dev/null
@@ -1,246 +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.
-
-from threading import Thread
-import time
-import psutil
-import os
-
-from abstracthealthstatisticspublisher import *
-from ..databridge.agent import *
-from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
-from ..util import cartridgeagentutils, cartridgeagentconstants
-
-
-class HealthStatisticsPublisherManager(Thread):
-    """
-    Read from an implementation of AbstractHealthStatisticsPublisher the value for memory usage and
-    load average and publishes them as ThriftEvents to a CEP server
-    """
-    STREAM_NAME = "cartridge_agent_health_stats"
-    STREAM_VERSION = "1.0.0"
-    STREAM_NICKNAME = "agent health stats"
-    STREAM_DESCRIPTION = "agent health stats"
-
-    def __init__(self, publish_interval):
-        """
-        Initializes a new HealthStatistsPublisherManager with a given number of seconds as the interval
-        :param int publish_interval: Number of seconds as the interval
-        :return: void
-        """
-        Thread.__init__(self)
-
-        self.log = LogFactory().get_log(__name__)
-
-        self.publish_interval = publish_interval
-        """:type : int"""
-
-        self.terminated = False
-
-        self.publisher = HealthStatisticsPublisher()
-        """:type : HealthStatisticsPublisher"""
-        # TODO: load plugins for the reader
-        self.stats_reader = DefaultHealthStatisticsReader()
-        """:type : AbstractHealthStatisticsReader"""
-
-    def run(self):
-        while not self.terminated:
-            time.sleep(self.publish_interval)
-
-            cartridge_stats = self.stats_reader.stat_cartridge_health()
-            self.log.debug("Publishing memory consumption: %r" % cartridge_stats.memory_usage)
-            self.publisher.publish_memory_usage(cartridge_stats.memory_usage)
-
-            self.log.debug("Publishing load average: %r" % cartridge_stats.load_avg)
-            self.publisher.publish_load_average(cartridge_stats.load_avg)
-
-        self.publisher.publisher.disconnect()
-
-
-class HealthStatisticsPublisher:
-    """
-    Publishes memory usage and load average to thrift server
-    """
-    log = LogFactory().get_log(__name__)
-
-    def __init__(self):
-
-        self.ports = []
-        self.ports.append(CEPPublisherConfiguration.get_instance().server_port)
-
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-        cartridgeagentutils.wait_until_ports_active(
-            CEPPublisherConfiguration.get_instance().server_ip,
-            self.ports,
-            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False)))
-        cep_active = cartridgeagentutils.check_ports_active(CEPPublisherConfiguration.get_instance().server_ip, self.ports)
-        if not cep_active:
-            raise CEPPublisherException("CEP server not active. Health statistics publishing aborted.")
-
-        self.stream_definition = HealthStatisticsPublisher.create_stream_definition()
-        HealthStatisticsPublisher.log.debug("Stream definition created: %r" % str(self.stream_definition))
-        self.publisher = ThriftPublisher(
-            CEPPublisherConfiguration.get_instance().server_ip,
-            CEPPublisherConfiguration.get_instance().server_port,
-            CEPPublisherConfiguration.get_instance().admin_username,
-            CEPPublisherConfiguration.get_instance().admin_password,
-            self.stream_definition)
-
-        HealthStatisticsPublisher.log.debug("HealthStatisticsPublisher initialized")
-
-    @staticmethod
-    def create_stream_definition():
-        """
-        Create a StreamDefinition for publishing to CEP
-        """
-        stream_def = StreamDefinition()
-        stream_def.name = HealthStatisticsPublisherManager.STREAM_NAME
-        stream_def.version = HealthStatisticsPublisherManager.STREAM_VERSION
-        stream_def.nickname = HealthStatisticsPublisherManager.STREAM_NICKNAME
-        stream_def.description = HealthStatisticsPublisherManager.STREAM_DESCRIPTION
-
-        stream_def.add_payloaddata_attribute("cluster_id", StreamDefinition.STRING)
-        stream_def.add_payloaddata_attribute("network_partition_id", StreamDefinition.STRING)
-        stream_def.add_payloaddata_attribute("member_id", StreamDefinition.STRING)
-        stream_def.add_payloaddata_attribute("partition_id", StreamDefinition.STRING)
-        stream_def.add_payloaddata_attribute("health_description", StreamDefinition.STRING)
-        stream_def.add_payloaddata_attribute("value", StreamDefinition.DOUBLE)
-
-        return stream_def
-
-    def publish_memory_usage(self, memory_usage):
-        """
-        Publishes the given memory usage value to the thrift server as a ThriftEvent
-        :param float memory_usage: memory usage
-        """
-
-        event = ThriftEvent()
-        event.payloadData.append(self.cartridge_agent_config.cluster_id)
-        event.payloadData.append(self.cartridge_agent_config.network_partition_id)
-        event.payloadData.append(self.cartridge_agent_config.member_id)
-        event.payloadData.append(self.cartridge_agent_config.partition_id)
-        event.payloadData.append(cartridgeagentconstants.MEMORY_CONSUMPTION)
-        event.payloadData.append(memory_usage)
-
-        HealthStatisticsPublisher.log.debug("Publishing cep event: [stream] %r [version] %r" % (self.stream_definition.name, self.stream_definition.version))
-        self.publisher.publish(event)
-
-    def publish_load_average(self, load_avg):
-        """
-        Publishes the given load average value to the thrift server as a ThriftEvent
-        :param float load_avg: load average value
-        """
-
-        event = ThriftEvent()
-        event.payloadData.append(self.cartridge_agent_config.cluster_id)
-        event.payloadData.append(self.cartridge_agent_config.network_partition_id)
-        event.payloadData.append(self.cartridge_agent_config.member_id)
-        event.payloadData.append(self.cartridge_agent_config.partition_id)
-        event.payloadData.append(cartridgeagentconstants.LOAD_AVERAGE)
-        event.payloadData.append(load_avg)
-
-        HealthStatisticsPublisher.log.debug("Publishing cep event: [stream] %r [version] %r" % (self.stream_definition.name, self.stream_definition.version))
-        self.publisher.publish(event)
-
-
-class DefaultHealthStatisticsReader(AbstractHealthStatisticsReader):
-    """
-    Default implementation of the AbstractHealthStatisticsReader
-    """
-
-    def __init__(self):
-        self.log = LogFactory().get_log(__name__)
-
-    def stat_cartridge_health(self):
-        cartridge_stats = CartridgeHealthStatistics()
-        cartridge_stats.memory_usage = DefaultHealthStatisticsReader.__read_mem_usage()
-        cartridge_stats.load_avg = DefaultHealthStatisticsReader.__read_load_avg()
-
-        self.log.debug("Memory read: %r, CPU read: %r" % (cartridge_stats.memory_usage, cartridge_stats.load_avg))
-        return cartridge_stats
-
-    @staticmethod
-    def __read_mem_usage():
-        return psutil.virtual_memory().percent
-
-    @staticmethod
-    def __read_load_avg():
-        (one, five, fifteen) = os.getloadavg()
-        return one
-
-
-class CEPPublisherConfiguration:
-    """
-    TODO: Extract common functionality
-    """
-
-    __instance = None
-    log = LogFactory().get_log(__name__)
-
-    @staticmethod
-    def get_instance():
-        """
-        Singleton instance retriever
-        :return: Instance
-        :rtype : CEPPublisherConfiguration
-        """
-        if CEPPublisherConfiguration.__instance is None:
-            CEPPublisherConfiguration.__instance = CEPPublisherConfiguration()
-
-        return CEPPublisherConfiguration.__instance
-
-    def __init__(self):
-        self.enabled = False
-        self.server_ip = None
-        self.server_port = None
-        self.admin_username = None
-        self.admin_password = None
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-        self.read_config()
-
-    def read_config(self):
-        self.enabled = True if self.cartridge_agent_config.read_property(
-           cartridgeagentconstants.CEP_PUBLISHER_ENABLED, False).strip().lower() == "true" else False
-        if not self.enabled:
-            CEPPublisherConfiguration.log.info("CEP Publisher disabled")
-            return
-
-        CEPPublisherConfiguration.log.info("CEP Publisher enabled")
-
-        self.server_ip = self.cartridge_agent_config.read_property(
-            cartridgeagentconstants.CEP_RECEIVER_IP, False)
-        if self.server_ip is None or self.server_ip.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_RECEIVER_IP)
-
-        self.server_port = self.cartridge_agent_config.read_property(
-            cartridgeagentconstants.CEP_RECEIVER_PORT, False)
-        if self.server_port is None or self.server_port.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_RECEIVER_PORT)
-
-        self.admin_username = self.cartridge_agent_config.read_property(
-            cartridgeagentconstants.CEP_SERVER_ADMIN_USERNAME, False)
-        if self.admin_username is None or self.admin_username.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_SERVER_ADMIN_USERNAME)
-
-        self.admin_password = self.cartridge_agent_config.read_property(
-            cartridgeagentconstants.CEP_SERVER_ADMIN_PASSWORD, False)
-        if self.admin_password is None or self.admin_password.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_SERVER_ADMIN_PASSWORD)
-
-        CEPPublisherConfiguration.log.info("CEP Publisher configuration initialized")

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/publisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/publisher/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/publisher/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/publisher/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py b/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
deleted file mode 100644
index 1ce8ffb..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
+++ /dev/null
@@ -1,165 +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.
-
-import logging
-
-import paho.mqtt.publish as publish
-
-from .. event.instance.status.events import *
-from .. config.cartridgeagentconfiguration import CartridgeAgentConfiguration
-from .. util import cartridgeagentconstants
-from .. healthstatspublisher.healthstats import *
-from .. healthstatspublisher.abstracthealthstatisticspublisher import *
-
-
-log = LogFactory().get_log(__name__)
-
-started = False
-activated = False
-ready_to_shutdown = False
-maintenance = False
-
-publishers = {}
-""" :type : dict[str, EventPublisher] """
-
-
-def publish_instance_started_event():
-    global started, log
-    if not started:
-        log.info("Publishing instance started event")
-        service_name = CartridgeAgentConfiguration().service_name
-        cluster_id = CartridgeAgentConfiguration().cluster_id
-        network_partition_id = CartridgeAgentConfiguration().network_partition_id
-        parition_id = CartridgeAgentConfiguration().partition_id
-        member_id = CartridgeAgentConfiguration().member_id
-
-        instance_started_event = InstanceStartedEvent(service_name, cluster_id, network_partition_id, parition_id,
-                                                      member_id)
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_STARTED_EVENT)
-        publisher.publish(instance_started_event)
-        started = True
-        log.info("Instance started event published")
-    else:
-        log.warn("Instance already started")
-
-
-def publish_instance_activated_event():
-    global activated, log
-    if not activated:
-        log.info("Publishing instance activated event")
-        service_name = CartridgeAgentConfiguration().service_name
-        cluster_id = CartridgeAgentConfiguration().cluster_id
-        network_partition_id = CartridgeAgentConfiguration().network_partition_id
-        parition_id = CartridgeAgentConfiguration().partition_id
-        member_id = CartridgeAgentConfiguration().member_id
-
-        instance_activated_event = InstanceActivatedEvent(service_name, cluster_id, network_partition_id, parition_id,
-                                                          member_id)
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_ACTIVATED_EVENT)
-        publisher.publish(instance_activated_event)
-
-        log.info("Instance activated event published")
-        log.info("Starting health statistics notifier")
-
-        if CEPPublisherConfiguration.get_instance().enabled:
-            interval_default = 15  # seconds
-            interval = CartridgeAgentConfiguration().read_property("stats.notifier.interval", False)
-            if interval is not None and len(interval) > 0:
-                try:
-                    interval = int(interval)
-                except ValueError:
-                    interval = interval_default
-            else:
-                interval = interval_default
-
-            health_stats_publisher = HealthStatisticsPublisherManager(interval)
-            log.info("Starting Health statistics publisher with interval %r" % interval_default)
-            health_stats_publisher.start()
-        else:
-            log.warn("Statistics publisher is disabled")
-
-        activated = True
-        log.info("Health statistics notifier started")
-    else:
-        log.warn("Instance already activated")
-
-
-def publish_maintenance_mode_event():
-    global maintenance, log
-    if not maintenance:
-        log.info("Publishing instance maintenance mode event")
-
-        service_name = CartridgeAgentConfiguration().service_name
-        cluster_id = CartridgeAgentConfiguration().cluster_id
-        network_partition_id = CartridgeAgentConfiguration().network_partition_id
-        parition_id = CartridgeAgentConfiguration().partition_id
-        member_id = CartridgeAgentConfiguration().member_id
-
-        instance_maintenance_mode_event = InstanceMaintenanceModeEvent(service_name, cluster_id, network_partition_id, parition_id,
-                                                          member_id)
-
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_MAINTENANCE_MODE_EVENT)
-        publisher.publish(instance_maintenance_mode_event)
-
-        maintenance = True
-        log.info("Instance Maintenance mode event published")
-    else:
-        log.warn("Instance already in a Maintenance mode....")
-
-
-def publish_instance_ready_to_shutdown_event():
-    global ready_to_shutdown, log
-    if not ready_to_shutdown:
-        log.info("Publishing instance activated event")
-
-        service_name = CartridgeAgentConfiguration().service_name
-        cluster_id = CartridgeAgentConfiguration().cluster_id
-        network_partition_id = CartridgeAgentConfiguration().network_partition_id
-        parition_id = CartridgeAgentConfiguration().partition_id
-        member_id = CartridgeAgentConfiguration().member_id
-
-        instance_shutdown_event = InstanceReadyToShutdownEvent(service_name, cluster_id, network_partition_id, parition_id,
-                                                          member_id)
-
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_READY_TO_SHUTDOWN_EVENT)
-        publisher.publish(instance_shutdown_event)
-
-        ready_to_shutdown = True
-        log.info("Instance ReadyToShutDown event published")
-    else:
-        log.warn("Instance already in a ReadyToShutDown event....")
-
-
-def get_publisher(topic):
-    if topic not in publishers:
-        publishers[topic] = EventPublisher(topic)
-
-    return publishers[topic]
-
-
-class EventPublisher:
-    """
-    Handles publishing events to topics to the provided message broker
-    """
-    def __init__(self, topic):
-        self.__topic = topic
-
-    def publish(self, event):
-        mb_ip = CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_IP)
-        mb_port = CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_PORT)
-        payload = event.to_json()
-        publish.single(self.__topic, payload, hostname=mb_ip, port=mb_port)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/eventsubscriber.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/eventsubscriber.py b/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/eventsubscriber.py
deleted file mode 100644
index bc026dd..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/eventsubscriber.py
+++ /dev/null
@@ -1,96 +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.
-
-import threading
-import paho.mqtt.client as mqtt
-
-
-class EventSubscriber(threading.Thread):
-    """
-    Provides functionality to subscribe to a given topic on the stratos MB and
-    register event handlers for various events.
-    """
-
-    def __init__(self, topic, ip, port):
-        threading.Thread.__init__(self)
-
-        #{"ArtifactUpdateEvent" : onArtifactUpdateEvent()}
-        self.__event_handlers = {}
-
-        self.log = LogFactory().get_log(__name__)
-
-        self.__mb_client = None
-
-        self.__topic = topic
-
-        self.__subscribed = False
-
-        self.__ip = ip
-        self.__port = port
-
-    def run(self):
-        self.__mb_client = mqtt.Client()
-        self.__mb_client.on_connect = self.on_connect
-        self.__mb_client.on_message = self.on_message
-
-        self.log.debug("Connecting to the message broker with address %r:%r" % (self.__ip, self.__port))
-        self.__mb_client.connect(self.__ip, self.__port, 60)
-        self.__subscribed = True
-        self.__mb_client.loop_forever()
-
-    def register_handler(self, event, handler):
-        """
-        Adds an event handler function mapped to the provided event.
-        :param str event: Name of the event to attach the provided handler
-        :param handler: The handler function
-        :return: void
-        :rtype: void
-        """
-        self.__event_handlers[event] = handler
-        self.log.debug("Registered handler for event %r" % event)
-
-    def on_connect(self, client, userdata, flags, rc):
-        self.log.debug("Connected to message broker.")
-        self.__mb_client.subscribe(self.__topic)
-        self.log.debug("Subscribed to %r" % self.__topic)
-
-    def on_message(self, client, userdata, msg):
-        self.log.debug("Message received: %r:\n%r" % (msg.topic, msg.payload))
-
-        event = msg.topic.rpartition('/')[2]
-
-        if event in self.__event_handlers:
-            handler = self.__event_handlers[event]
-
-            try:
-                self.log.debug("Executing handler for event %r" % event)
-                handler(msg)
-            except:
-                self.log.exception("Error processing %r event" % event)
-        else:
-            self.log.debug("Event handler not found for event : %r" % event)
-
-    def is_subscribed(self):
-        """
-        Checks if this event subscriber is successfully subscribed to the provided topic
-        :return: True if subscribed, False if otherwise
-        :rtype: bool
-        """
-        return self.__subscribed
-
-
-from .. util.log import LogFactory
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/tenant/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/tenant/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/tenant/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/tenant/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/tenant/tenantcontext.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/tenant/tenantcontext.py b/tools/python-cartridge-agent/cartridge-agent/modules/tenant/tenantcontext.py
deleted file mode 100644
index 202bd35..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/tenant/tenantcontext.py
+++ /dev/null
@@ -1,184 +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.
-
-class Tenant:
-    """
-    Object type representing the tenant details of a single tenant
-    """
-
-    def __init__(self, tenant_id,  tenant_domain):
-        self.tenant_id = tenant_id
-        """ :type : int """
-        self.tenant_domain = tenant_domain
-        """ :type : str """
-        self.service_name_subscription_map = {}
-        """ :type : dict[str, Subscription] """
-
-    def get_subscription(self, service_name):
-        """
-        Returns the Subscription object related to the provided service name
-        :param str service_name: service name to be retrieved
-        :return: Subscription of the service or None if the service name doesn't exist
-        :rtype: Subscription
-        """
-        if service_name in self.service_name_subscription_map:
-            return self.service_name_subscription_map[service_name]
-
-        return None
-
-    def is_subscribed(self, service_name):
-        """
-        Checks if the given service name has a subscription from this tenant
-        :param str service_name: name of the service to check
-        :return: True if the tenant is subscribed to the given service name, False if not
-        :rtype: bool
-        """
-        return service_name in self.service_name_subscription_map
-
-    def add_subscription(self, subscription):
-        """
-        Adds a subscription information entry on the subscription list for this tenant
-        :param Subscription subscription: Subscription information to be added
-        :return: void
-        :rtype: void
-        """
-        self.service_name_subscription_map[subscription.service_name] = subscription
-
-    def remove_subscription(self, service_name):
-        """
-        Removes the specified subscription details from the subscription list
-        :param str service_name: The service name of the subscription to be removed
-        :return: void
-        :rtype: void
-        """
-        if service_name in self.service_name_subscription_map:
-            self.service_name_subscription_map.pop(service_name)
-
-
-class Subscription:
-    """
-    Subscription information of a particular subscription to a service
-    """
-
-    def __init__(self, service_name, cluster_ids):
-        self.service_name = service_name
-        """ :type : str """
-        self.cluster_ids = cluster_ids
-        """ :type : list[str]  """
-        self.subscription_domain_map = {}
-        """ :type : dict[str, SubscriptionDomain]  """
-
-    def add_subscription_domain(self, domain_name, application_context):
-        """
-        Adds a subscription domain
-        :param str domain_name:
-        :param str application_context:
-        :return: void
-        :rtype: void
-        """
-        self.subscription_domain_map[domain_name] = SubscriptionDomain(domain_name, application_context)
-
-    def remove_subscription_domain(self, domain_name):
-        """
-        Removes the subscription domain of the specified domain name
-        :param str domain_name:
-        :return: void
-        :rtype: void
-        """
-        if domain_name in self.subscription_domain_map:
-            self.subscription_domain_map.pop(domain_name)
-
-    def subscription_domain_exists(self, domain_name):
-        """
-        Returns the SubscriptionDomain information of the specified domain name
-        :param str domain_name:
-        :return: SubscriptionDomain
-        :rtype: SubscriptionDomain
-        """
-        return domain_name in self.subscription_domain_map
-
-    def get_subscription_domains(self):
-        """
-        Returns the list of subscription domains of this subscription
-        :return: List of SubscriptionDomain objects
-        :rtype: list[SubscriptionDomain]
-        """
-        return self.subscription_domain_map.values()
-
-
-class SubscriptionDomain:
-    """
-    Represents a Subscription Domain
-    """
-
-    def __init__(self, domain_name, application_context):
-        self.domain_name = domain_name
-        """ :type : str  """
-        self.application_context = application_context
-        """ :type : str  """
-
-
-class TenantContext:
-    """
-    Handles and maintains a model of all the information related to tenants within this instance
-    """
-    tenants = {}
-    initialized = False
-    tenant_domains = {"carbon.super": Tenant(-1234, "carbon.super")}
-
-    @staticmethod
-    def add_tenant(tenant):
-        TenantContext.tenants[tenant.tenant_id] = tenant
-        TenantContext.tenant_domains[tenant.tenant_domain] = tenant
-
-    @staticmethod
-    def remove_tenant(tenant_id):
-        if tenant_id in TenantContext.tenants:
-            tenant = TenantContext.get_tenant(tenant_id)
-            TenantContext.tenants.pop(tenant.tenant_id)
-            TenantContext.tenant_domains.pop(tenant.tenant_domain)
-
-    @staticmethod
-    def update(tenants):
-        for tenant in tenants:
-            TenantContext.add_tenant(tenant)
-
-    @staticmethod
-    def get_tenant(tenant_id):
-        """
-        Gets the Tenant object of the provided tenant ID
-        :param int tenant_id:
-        :return: Tenant object of the provided tenant ID
-        :rtype: Tenant
-        """
-        if tenant_id in TenantContext.tenants:
-            return TenantContext.tenants[tenant_id]
-
-        return None
-
-    @staticmethod
-    def get_tenant_by_domain(tenant_domain):
-        """
-        Gets the Tenant object of the provided tenant domain
-        :param str tenant_domain:
-        :return: Tenant object of the provided tenant domain
-        :rtype: str
-        """
-        if tenant_domain in TenantContext.tenant_domains:
-            return TenantContext.tenant_domains[tenant_domain]
-
-        return None
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/topology/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/topology/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/topology/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/topology/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/topology/topologycontext.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/topology/topologycontext.py b/tools/python-cartridge-agent/cartridge-agent/modules/topology/topologycontext.py
deleted file mode 100644
index 5fe2ea4..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/topology/topologycontext.py
+++ /dev/null
@@ -1,454 +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.
-
-from ..util import cartridgeagentconstants
-
-
-class Topology:
-    """
-    Represents the topology provided by the Cloud Controller
-    """
-
-    def __init__(self):
-        self.service_map = {}
-        """ :type : dict[str, Service]  """
-        self.initialized = False
-        """ :type : bool  """
-        self.json_str = None
-        """ :type : str  """
-
-    def get_services(self):
-        """
-        Provides the list of services on the topology
-        :return: The list of Service objects
-        :rtype: list[Service]
-        """
-        return self.service_map.values()
-
-    def get_service(self, service_name):
-        """
-        Provides the service information for the given service name
-        :param str service_name: service name to be retrieved
-        :return: Service object of the service, None if the provided service name is invalid
-        :rtype: Service
-        """
-        if service_name in self.service_map:
-            return self.service_map[service_name]
-
-        return None
-
-    def add_service(self, service):
-        """
-        Adds a service to the list of services on the topology
-
-        :param Service service:
-        :return: void
-        """
-        self.service_map[service.service_name] = service
-
-    def add_services(self, services):
-        """
-
-        :param list[Service] services:
-        :return: void
-        """
-        for service in services:
-            self.add_service(service)
-
-    def remove_service(self, service_name):
-        """
-        Removes the service of the provided service name
-        :param str service_name:
-        :return: void
-        """
-        if service_name in self.service_map:
-            self.service_map.pop(service_name)
-
-    def service_exists(self, service_name):
-        """
-        Checks if the service of the provided service name exists
-        :param str service_name:
-        :return: True if the service exists, False if otherwise
-        :rtype: bool
-        """
-        return service_name in self.service_map
-
-    def clear(self):
-        """
-        Clears the service information list
-        :return: void
-        """
-        self.service_map = {}
-
-    def __str__(self):
-        """
-        to string override
-        :return:
-        """
-        return "Topology [serviceMap= %r , initialized= %r ]" % (self.service_map, self.initialized)
-
-
-class Service:
-    """
-    Represents a service on the topology
-    """
-
-    def __init__(self, service_name, service_type):
-        self.service_name = service_name
-        """ :type : str  """
-        self.service_type = service_type
-        """ :type : str  """
-        self.cluster_id_cluster_map = {}
-        """ :type : dict[str, Cluster]  """
-        self.port_map = {}
-        """ :type : dict[str, Port]  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-
-    def get_clusters(self):
-        """
-        Provides the list of clusters in the particular service
-        :return: The list of Cluster objects
-        :rtype: list[Cluster]
-        """
-        return self.cluster_id_cluster_map.values()
-
-    def add_cluster(self, cluster):
-        """
-        Adds a cluster to the service
-        :param Cluster cluster: the cluster to be added
-        :return: void
-        """
-        self.cluster_id_cluster_map[cluster.cluster_id] = cluster
-
-    def remove_cluster(self, cluster_id):
-        if cluster_id in self.cluster_id_cluster_map:
-            self.cluster_id_cluster_map.pop(cluster_id)
-
-    def cluster_exists(self, cluster_id):
-        """
-        Checks if the cluster with the given cluster id exists for ther service
-        :param str cluster_id:
-        :return: True if the cluster for the given cluster id exists, False if otherwise
-        :rtype: bool
-        """
-        return cluster_id in self.cluster_id_cluster_map
-
-    def get_cluster(self, cluster_id):
-        """
-        Provides the Cluster information for the provided cluster id
-        :param str cluster_id: the cluster id to search for
-        :return: Cluster object for the given cluster id, None if the cluster id is invalid
-        :rtype: Cluster
-        """
-        if cluster_id in self.cluster_id_cluster_map:
-            return self.cluster_id_cluster_map[cluster_id]
-
-        return None
-
-    def get_ports(self):
-        """
-        Returns the list of ports in the particular service
-        :return: The list of Port object
-        :rtype: list[Port]
-        """
-        return self.port_map.values()
-
-    def get_port(self, proxy_port):
-        """
-        Provides the port information for the provided proxy port
-        :param str proxy_port:
-        :return: Port object for the provided port, None if port is invalid
-        :rtype: Port
-        """
-        if proxy_port in self.port_map:
-            return self.port_map[proxy_port]
-
-        return None
-
-    def add_port(self, port):
-        self.port_map[port.proxy] = port
-
-    def add_ports(self, ports):
-        for port in ports:
-            self.add_port(port)
-
-
-class Cluster:
-    """
-    Represents a cluster for a service
-    """
-
-    def __init__(self, service_name="", cluster_id="", deployment_policy_name="", autoscale_policy_name=""):
-        self.service_name = service_name
-        """ :type : str  """
-        self.cluster_id = cluster_id
-        """ :type : str  """
-        self.deployment_policy_name = deployment_policy_name
-        """ :type : str  """
-        self.autoscale_policy_name = autoscale_policy_name
-        """ :type : str  """
-        self.hostnames = []
-        """ :type : list[str]  """
-        self.member_map = {}
-        """ :type : dict[str, Member]  """
-
-        self.tenant_range = None
-        """ :type : str  """
-        self.is_lb_cluster = False
-        """ :type : bool  """
-        self.is_kubernetes_cluster = False
-        """ :type : bool  """
-        self.status = None
-        """ :type : str  """
-        self.load_balancer_algorithm_name = None
-        """ :type : str  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-        self.member_list_json = None
-        """ :type : str  """
-
-    def add_hostname(self, hostname):
-        self.hostnames.append(hostname)
-
-    def set_tenant_range(self, tenant_range):
-        self.validate_tenant_range(tenant_range)
-        self.tenant_range = tenant_range
-
-    def get_members(self):
-        """
-        Provides the list of member information in the cluster
-        :return: The list of Member object
-        :rtype: list[Member]
-        """
-        return self.member_map.values()
-
-    def add_member(self, member):
-        self.member_map[member.member_id] = member
-
-    def remove_member(self, member_id):
-        if self.member_exists(member_id):
-            self.member_map.pop(member_id)
-
-    def get_member(self, member_id):
-        """
-        Provides the member information for the provided member id
-        :param str member_id:
-        :return: Member object for the provided member id, None if member id is invalid
-        :rtype: Member
-        """
-        if self.member_exists(member_id):
-            return self.member_map[member_id]
-
-        return None
-
-    def member_exists(self, member_id):
-        """
-        Checks if the member for the provided member id exists in this cluster
-        :param str member_id: member id to be searched
-        :return: True if the member exists, False if otherwise
-        :rtype: bool
-        """
-        return member_id in self.member_map
-
-    def __str__(self):
-        return "Cluster [serviceName=" + self.service_name + ", clusterId=" + self.cluster_id \
-               + ", autoscalePolicyName=" + self.autoscale_policy_name + ", deploymentPolicyName=" \
-               + self.deployment_policy_name + ", hostNames=" + self.hostnames + ", tenantRange=" + self.tenant_range \
-               + ", isLbCluster=" + self.is_lb_cluster + ", properties=" + self.properties + "]"
-
-    def tenant_id_in_range(self, tenant_id):
-        """
-        Check whether a given tenant id is in tenant range of the cluster.
-        :param str tenant_id: tenant id to be checked
-        :return: True if the tenant id is in tenant id range, False if otherwise
-        :rtype: bool
-        """
-        if self.tenant_range is None:
-            return False
-
-        if self.tenant_range == "*":
-            return True
-        else:
-            arr = self.tenant_range.split(cartridgeagentconstants.TENANT_RANGE_DELIMITER)
-            tenant_start = int(arr[0])
-            if tenant_start <= tenant_id:
-                tenant_end = arr[1]
-                if tenant_end == "*":
-                    return True
-                else:
-                    if tenant_id <= int(tenant_end):
-                        return True
-
-        return False
-
-    def validate_tenant_range(self, tenant_range):
-        """
-        Validates the tenant range to be either '*' or a delimeted range of numbers
-        :param str tenant_range: The tenant range string to be validated
-        :return: void if the provided tenant range is valid, RuntimeError if otherwise
-        :exception: RuntimeError if the tenant range is invalid
-        """
-        valid = False
-        if tenant_range == "*":
-            valid = True
-        else:
-            arr = tenant_range.split(cartridgeagentconstants.TENANT_RANGE_DELIMITER)
-            if len(arr) == 2:
-                if arr[0].isdigit() and arr[1].isdigit():
-                    valid = True
-                elif arr[0].isdigit() and arr[1] == "*":
-                    valid = True
-
-        if not valid:
-            raise RuntimeError("Tenant range %r is not valid" % tenant_range)
-
-
-class Member:
-    """
-    Represents a member on a particular cluster
-    """
-
-    def __init__(self, service_name="", cluster_id="", network_partition_id="", parition_id="", member_id=""):
-        self.service_name = service_name
-        """ :type : str  """
-        self.cluster_id = cluster_id
-        """ :type : str  """
-        self.network_partition_id = network_partition_id
-        """ :type : str  """
-        self.partition_id = parition_id
-        """ :type : str  """
-        self.member_id = member_id
-        """ :type : str  """
-        self.port_map = {}
-        """ :type : dict[str, Port]  """
-
-        self.member_public_ip = None
-        """ :type : str  """
-        self.status = None
-        """ :type : str  """
-        self.member_ip = None
-        """ :type : str  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-        self.lb_cluster_id = None
-        """ :type : str  """
-        self.json_str = None
-        """ :type : str  """
-
-    def is_active(self):
-        """
-        Checks if the member is in active state
-        :return: True if active, False if otherwise
-        :rtype: bool
-        """
-        return self.status == MemberStatus.Activated
-
-    def get_ports(self):
-        """
-        Provides the list of the ports in the member
-        :return: List of Port objects
-        :rtype: list[Port]
-        """
-        return self.port_map.values()
-
-    def get_port(self, proxy):
-        """
-        Provides the port information for the given port id
-        :param str proxy: The port id
-        :return: Port object of the provided port id, None if otherwise
-        :rtype: Port
-        """
-        if proxy in self.port_map:
-            return self.port_map[proxy]
-
-        return None
-
-    def add_port(self, port):
-        self.port_map[port.proxy] = port
-
-    def add_ports(self, ports):
-        for port in ports:
-            self.add_port(port)
-
-
-class Port:
-    """
-    Represents a port on a particular member
-    """
-
-    def __init__(self, protocol, value, proxy):
-        self.protocol = protocol
-        """ :type : str  """
-        self.value = value
-        """ :type : str  """
-        self.proxy = proxy
-        """ :type : str  """
-
-    def __str__(self):
-        return "Port [protocol=%r, value=%r proxy=%r]" % (self.protocol, self.value, self.proxy)
-
-
-class ServiceType:
-    """
-    ServiceType enum
-    """
-    SingleTenant = 1
-    MultiTenant = 2
-
-
-class ClusterStatus:
-    """
-    ClusterStatus enum
-    """
-    Created = 1
-    In_Maintenance = 2
-    Removed = 3
-
-
-class MemberStatus:
-    """
-    MemberStatus enum
-    """
-    Created = 1
-    Starting = 2
-    Activated = 3
-    In_Maintenance = 4
-    ReadyToShutDown = 5
-    Terminated = 6
-    Suspended = 0
-    ShuttingDown = 0
-
-
-class TopologyContext:
-    """
-    Handles and maintains a model of the topology provided by the Cloud Controller
-    """
-    topology = None
-    # TODO: read write locks, Lock() and RLock()
-
-    @staticmethod
-    def get_topology():
-        #TODO: thread-safety missing
-        if TopologyContext.topology is None:
-            TopologyContext.topology = Topology()
-        return TopologyContext.topology
-
-    @staticmethod
-    def update(topology):
-        TopologyContext.topology = topology
-        TopologyContext.topology.initialized = True
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/util/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/util/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/util/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/util/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/util/asyncscheduledtask.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/util/asyncscheduledtask.py b/tools/python-cartridge-agent/cartridge-agent/modules/util/asyncscheduledtask.py
deleted file mode 100644
index 9fdde1e..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/util/asyncscheduledtask.py
+++ /dev/null
@@ -1,50 +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.
-
-import time
-from threading import Thread
-
-
-class AsyncScheduledTask(Thread):
-    """
-    Executes a given task with a given interval until being terminated
-    """
-
-    def __init__(self, delay, task):
-        Thread.__init__(self)
-        self.delay = delay
-        """ :type : int  """
-        self.task = task
-        """ :type : Thread  """
-        self.terminated = False
-        """ :type : bool  """
-
-    def run(self):
-        """
-        Start the scheuled task with a sleep time of delay in between
-        :return:
-        """
-        while not self.terminated:
-            time.sleep(self.delay)
-            self.task.start()
-
-    def terminate(self):
-        """
-        Terminate the scheduled task. Allow a maximum of 'delay' seconds to be terminated.
-        :return: void
-        """
-        self.terminated = True
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentconstants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentconstants.py b/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentconstants.py
deleted file mode 100644
index 70afb30..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentconstants.py
+++ /dev/null
@@ -1,135 +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.
-
-PARAM_FILE_PATH = "param.file.path"
-EXTENSIONS_DIR = "extensions.dir"
-
-MB_IP = "mb.ip"
-MB_PORT = "mb.port"
-
-CARTRIDGE_KEY = "CARTRIDGE_KEY"
-APP_PATH = "APP_PATH"
-SERVICE_GROUP = "SERIVCE_GROUP"
-SERVICE_NAME = "SERVICE_NAME"
-CLUSTER_ID = "CLUSTER_ID"
-LB_CLUSTER_ID = "LB_CLUSTER_ID"
-NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID"
-PARTITION_ID = "PARTITION_ID"
-MEMBER_ID = "MEMBER_ID"
-TENANT_ID = "TENANT_ID"
-REPO_URL = "REPO_URL"
-PORTS = "PORTS"
-DEPLOYMENT = "DEPLOYMENT"
-MANAGER_SERVICE_TYPE = "MANAGER_SERVICE_TYPE"
-WORKER_SERVICE_TYPE = "WORKER_SERVICE_TYPE"
-PERSISTENCE_MAPPING = "PERSISTENCE_MAPPING"
-
-# stratos.sh environment variables keys
-LOG_FILE_PATHS = "LOG_FILE_PATHS"
-MEMORY_CONSUMPTION = "memory_consumption"
-LOAD_AVERAGE = "load_average"
-PORTS_NOT_OPEN = "ports_not_open"
-MULTITENANT = "MULTITENANT"
-CLUSTERING = "CLUSTERING"
-MIN_INSTANCE_COUNT = "MIN_COUNT"
-ENABLE_ARTIFACT_UPDATE = "enable.artifact.update"
-ARTIFACT_UPDATE_INTERVAL = "artifact.update.interval"
-COMMIT_ENABLED = "COMMIT_ENABLED"
-AUTO_COMMIT = "auto.commit"
-AUTO_CHECKOUT = "auto.checkout"
-LISTEN_ADDRESS = "listen.address"
-PROVIDER = "PROVIDER"
-INTERNAL = "internal"
-LB_PRIVATE_IP = "lb.private.ip"
-LB_PUBLIC_IP = "lb.public.ip"
-
-# stratos.sh extension points shell scripts names keys
-INSTANCE_STARTED_SCRIPT = "extension.instance.started"
-START_SERVERS_SCRIPT = "extension.start.servers"
-INSTANCE_ACTIVATED_SCRIPT = "extension.instance.activated"
-ARTIFACTS_UPDATED_SCRIPT = "extension.artifacts.updated"
-CLEAN_UP_SCRIPT = "extension.clean"
-MOUNT_VOLUMES_SCRIPT = "extension.mount.volumes"
-MEMBER_ACTIVATED_SCRIPT = "extension.member.activated"
-MEMBER_TERMINATED_SCRIPT = "extension.member.terminated"
-MEMBER_SUSPENDED_SCRIPT = "extension.member.suspended"
-MEMBER_STARTED_SCRIPT = "extension.member.started"
-COMPLETE_TOPOLOGY_SCRIPT = "extension.complete.topology"
-COMPLETE_TENANT_SCRIPT = "extension.complete.tenant"
-SUBSCRIPTION_DOMAIN_ADDED_SCRIPT = "extension.subscription.domain.added"
-SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT = "extension.subscription.domain.removed"
-ARTIFACTS_COPY_SCRIPT = "extension.artifacts.copy"
-TENANT_SUBSCRIBED_SCRIPT = "extension.tenant.subscribed"
-TENANT_UNSUBSCRIBED_SCRIPT = "extension.tenant.unsubscribed"
-
-SERVICE_GROUP_TOPOLOGY_KEY = "payload_parameter.SERIVCE_GROUP"
-CLUSTERING_TOPOLOGY_KEY = "payload_parameter.CLUSTERING"
-CLUSTERING_PRIMARY_KEY = "PRIMARY"
-
-SUPERTENANT_TEMP_PATH = "/tmp/-1234/"
-
-DEPLOYMENT_MANAGER = "manager"
-DEPLOYMENT_WORKER = "worker"
-DEPLOYMENT_DEFAULT = "default"
-SUPER_TENANT_REPO_PATH = "super.tenant.repository.path"
-TENANT_REPO_PATH = "tenant.repository.path"
-
-# topic names to subscribe
-INSTANCE_NOTIFIER_TOPIC = "instance/#"
-HEALTH_STAT_TOPIC = "health/#"
-TOPOLOGY_TOPIC = "topology/#"
-TENANT_TOPIC = "tenant/#"
-INSTANCE_STATUS_TOPIC = "instance/status/"
-
-#Messaging Model
-TENANT_RANGE_DELIMITER = "-"
-
-INSTANCE_STARTED_EVENT = "InstanceStartedEvent"
-INSTANCE_ACTIVATED_EVENT = "InstanceActivatedEvent"
-INSTANCE_MAINTENANCE_MODE_EVENT = "InstanceMaintenanceModeEvent"
-INSTANCE_READY_TO_SHUTDOWN_EVENT = "InstanceReadyToShutdownEvent"
-
-PUBLISHER_SERVICE_NAME = "publisher"
-APISTORE_SERVICE_NAME = "apistore"
-APIMANAGER_SERVICE_NAME = "apim"
-GATEWAY_SERVICE_NAME = "gatewaymgt"
-GATEWAY_MGT_SERVICE_NAME = "gateway"
-KEY_MANAGER_SERVICE_NAME = "keymanager"
-
-PRIMARY = "PRIMARY"
-MIN_COUNT = "MIN_COUNT"
-
-#multi tenant constants
-INVALID_TENANT_ID = "-1"
-SUPER_TENANT_ID = "-1234"
-
-DATE_FORMAT = "%Y.%m.%d"
-
-PORT_CHECK_TIMEOUT = "port.check.timeout"
-
-CEP_PUBLISHER_ENABLED = "cep.stats.publisher.enabled"
-CEP_RECEIVER_IP = "thrift.receiver.ip"
-CEP_RECEIVER_PORT = "thrift.receiver.port"
-CEP_SERVER_ADMIN_USERNAME = "thrift.server.admin.username"
-CEP_SERVER_ADMIN_PASSWORD = "thrift.server.admin.password"
-
-MONITORING_PUBLISHER_ENABLED = "enable.data.publisher"
-MONITORING_RECEIVER_IP = "monitoring.server.ip"
-MONITORING_RECEIVER_PORT = "monitoring.server.port"
-MONITORING_RECEIVER_SECURE_PORT = "monitoring.server.secure.port"
-MONITORING_SERVER_ADMIN_USERNAME = "monitoring.server.admin.username"
-MONITORING_SERVER_ADMIN_PASSWORD = "monitoring.server.admin.password"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentutils.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentutils.py b/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentutils.py
deleted file mode 100644
index 42a7dd5..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentutils.py
+++ /dev/null
@@ -1,165 +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.
-
-from Crypto.Cipher import AES
-import base64
-import os
-import time
-import socket
-import shutil
-
-from log import LogFactory
-
-unpad = lambda s: s[0:-ord(s[-1])]
-
-log = LogFactory().get_log(__name__)
-
-current_milli_time = lambda: int(round(time.time() * 1000))
-
-
-def decrypt_password(pass_str, secret):
-    """
-    Decrypts the given password using the given secret. The encryption is assumed to be done
-    without IV, in AES.
-    :param str pass_str: Encrypted password string in Base64 encoding
-    :param str secret: The secret string
-    :return: The decrypted password
-    :rtype: str
-    """
-
-    if pass_str is None or pass_str.strip() == "":
-        return pass_str.strip()
-
-    dec_pass = ""
-
-    try:
-        log.debug("Decrypting password")
-        bdecoded_pass = base64.b64decode(pass_str)
-        #secret length should be 16
-        cipher = AES.new(secret, AES.MODE_ECB)
-        dec_pass = unpad(cipher.decrypt(bdecoded_pass))
-    except:
-        log.exception("Exception occurred while decrypting password")
-
-    log.debug("Decrypted PWD: [%r]" % dec_pass)
-    return dec_pass
-
-
-def create_dir(path):
-    """
-    mkdir the provided path
-    :param path: The path to the directory to be made
-    :return: True if mkdir was successful, False if dir already exists
-    :rtype: bool
-    """
-    try:
-        os.mkdir(path)
-        log.info("Successfully created directory [%r]" % path)
-        return True
-    except OSError:
-        log.exception("Directory creating failed in [%r]. Directory already exists. " % path)
-
-    return False
-
-
-def delete_folder_tree(path):
-    """
-    Completely deletes the provided folder
-    :param str path: Full path of the folder
-    :return: void
-    """
-    try:
-        shutil.rmtree(path)
-        log.debug("Directory [%r] deleted." % path)
-    except OSError:
-        log.exception("Deletion of folder path %r failed." % path)
-
-
-def wait_until_ports_active(ip_address, ports, ports_check_timeout=600000):
-    """
-    Blocks until the given list of ports become active
-    :param str ip_address: Ip address of the member to be checked
-    :param list[str] ports: List of ports to be checked
-    :param int ports_check_timeout: The timeout in milliseconds, defaults to 1000*60*10
-    :return: void
-    """
-    if ports_check_timeout is None:
-        ports_check_timeout = 1000 * 60 * 10
-
-    log.debug("Port check timeout: %r" % ports_check_timeout)
-
-    active = False
-    start_time = current_milli_time()
-    while not active:
-        log.info("Waiting for ports to be active: [ip] %r [ports] %r" % (ip_address, ports))
-        active = check_ports_active(ip_address, ports)
-        end_time = current_milli_time()
-        duration = end_time - start_time
-
-        if duration > ports_check_timeout:
-            return
-
-        time.sleep(5)
-
-    log.info("Ports activated: [ip] %r [ports] %r" % (ip_address, ports))
-
-
-def check_ports_active(ip_address, ports):
-    """
-    Checks the given list of port addresses for active state
-    :param str ip_address: Ip address of the member to be checked
-    :param list[str] ports: The list of ports to be checked
-    :return: True if the ports are active, False if at least one is not active
-    :rtype: bool
-    """
-    if len(ports) < 1:
-        raise RuntimeError("No ports found")
-
-    for port in ports:
-        s = socket.socket()
-        s.settimeout(5)
-        try:
-            s.connect((ip_address, int(port)))
-            log.debug("Port %r is active" % port)
-            s.close()
-        except socket.error:
-            log.debug("Print %r is not active" % port)
-            return False
-
-    return True
-
-
-def get_carbon_server_property(property_key):
-    """
-    Reads the carbon.xml file and returns the value for the property key.
-    TODO: Get carbon server xml location
-    :param str property_key: Property key to look for
-    :return: The value of the property, None if the property key is invalid or not present
-    :rtype : str
-    """
-
-    raise NotImplementedError
-
-
-def get_working_dir():
-    """
-    Returns the base directory of the cartridge agent.
-    :return: Base working dir path
-    :rtype : str
-    """
-    #"/path/to/cartridge-agent/modules/util/".split("modules") returns ["/path/to/cartridge-agent/", "/util"]
-    return os.path.abspath(os.path.dirname(__file__)).split("modules")[0]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/util/extensionutils.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/util/extensionutils.py b/tools/python-cartridge-agent/cartridge-agent/modules/util/extensionutils.py
deleted file mode 100644
index 6c58852..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/util/extensionutils.py
+++ /dev/null
@@ -1,494 +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.
-
-import logging
-import os
-import subprocess
-import time
-
-from log import LogFactory
-from .. config import cartridgeagentconfiguration
-
-
-log = LogFactory().get_log(__name__)
-
-cartridge_agent_config = cartridgeagentconfiguration.CartridgeAgentConfiguration()
-
-
-def execute_copy_artifact_extension(source, destination):
-    try:
-        log.debug("Executing artifacts copy extension")
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.ARTIFACTS_COPY_SCRIPT, False)
-        command = prepare_command(script_name)
-
-        output, errors = execute_command(command + " " + source + " " + destination)
-        log.debug("Artifacts copy script returned: %r" % output)
-    except:
-        log.exception("Could not execute artifacts copy extension")
-
-
-def execute_instance_started_extension(env_params):
-    try:
-        log.debug("Executing instance started extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.INSTANCE_STARTED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Instance started script returned: %r" % output)
-    except:
-        log.exception("Could not execute instance started extension")
-
-
-def execute_instance_activated_extension():
-    try:
-        log.debug("Executing instance activated extension")
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.INSTANCE_ACTIVATED_SCRIPT, False)
-        command = prepare_command(script_name)
-
-        output, errors = execute_command(command)
-        log.debug("Instance activated script returned: %r" % output)
-    except:
-        log.exception("Could not execute instance activated extension")
-
-
-def execute_artifacts_updated_extension(env_params):
-    try:
-        log.debug("Executing artifacts updated extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.ARTIFACTS_UPDATED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Artifacts updated script returned: %r" % output)
-    except:
-        log.exception("Could not execute artifacts updated extension")
-
-
-def execute_subscription_domain_added_extension(env_params):
-    try:
-        log.debug("Executing subscription domain added extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.SUBSCRIPTION_DOMAIN_ADDED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Subscription domain added script returned: %r" % output)
-    except:
-        log.exception("Could not execute subscription domain added extension")
-
-
-def execute_subscription_domain_removed_extension(env_params):
-    try:
-        log.debug("Executing subscription domain removed extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Subscription domain removed script returned: %r" % output)
-    except:
-        log.exception("Could not execute subscription domain removed extension")
-
-
-def execute_start_servers_extension(env_params):
-    try:
-        log.debug("Executing start servers extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.START_SERVERS_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Start servers script returned: %r" % output)
-    except:
-        log.exception("Could not execute start servers extension")
-
-
-def execute_complete_topology_extension(env_params):
-    try:
-        log.debug("Executing complete topology extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.COMPLETE_TOPOLOGY_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Complete topology script returned: %r" % output)
-    except:
-        log.exception("Could not execute complete topology extension")
-
-
-def execute_complete_tenant_extension(env_params):
-    try:
-        log.debug("Executing complete tenant extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.COMPLETE_TENANT_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Complete tenant script returned: %r" % output)
-    except:
-        log.exception("Could not execute complete tenant extension")
-
-
-def execute_tenant_subscribed_extension(env_params):
-    try:
-        log.debug("Executing tenant subscribed extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.TENANT_SUBSCRIBED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Tenant subscribed script returned: %r" % output)
-    except:
-        log.exception("Could not execute tenant subscribed extension")
-
-
-def execute_tenant_unsubscribed_extension(env_params):
-    try:
-        log.debug("Executing tenant unsubscribed extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.TENANT_UNSUBSCRIBED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Tenant unsubscribed script returned: %r" % output)
-    except:
-        log.exception("Could not execute tenant unsubscribed extension")
-
-
-def execute_member_terminated_extension(env_params):
-    try:
-        log.debug("Executing member terminated extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.MEMBER_TERMINATED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Member terminated script returned: %r" % output)
-    except:
-        log.exception("Could not execute member terminated extension")
-
-
-def execute_member_suspended_extension(env_params):
-    try:
-        log.debug("Executing member suspended extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.MEMBER_SUSPENDED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Member suspended script returned: %r" % output)
-    except:
-        log.exception("Could not execute member suspended extension")
-
-
-def execute_member_started_extension(env_params):
-    try:
-        log.debug("Executing member started extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.MEMBER_STARTED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Member started script returned: %r" % output)
-    except:
-        log.exception("Could not execute member started extension")
-
-
-def wait_for_complete_topology():
-    while not TopologyContext.topology.initialized:
-        log.info("Waiting for complete topology event...")
-        time.sleep(5)
-
-
-def check_topology_consistency(service_name, cluster_id, member_id):
-    topology = TopologyContext.get_topology()
-    service = topology.get_service(service_name)
-    if service is None:
-        log.error("Service not found in topology [service] %r" % service_name)
-        return False
-
-    cluster = service.get_cluster(cluster_id)
-    if cluster is None:
-        log.error("Cluster id not found in topology [cluster] %r" % cluster_id)
-        return False
-
-    activated_member = cluster.get_member(member_id)
-    if activated_member is None:
-        log.error("Member id not found in topology [member] %r" % member_id)
-        return False
-
-    return True
-
-
-def is_relevant_member_event(service_name, cluster_id, lb_cluster_id):
-    cluster_id_in_payload = cartridge_agent_config.cluster_id
-    if cluster_id_in_payload is None:
-        return False
-
-    topology = TopologyContext.get_topology()
-    if topology is None or not topology.initialized:
-        return False
-
-    if cluster_id_in_payload == cluster_id:
-        return True
-
-    if cluster_id_in_payload == lb_cluster_id:
-        return True
-
-    service_group_in_payload = cartridge_agent_config.service_group
-    if service_group_in_payload is not None:
-        service_properties = topology.get_service(service_name).properties
-        if service_properties is None:
-            return False
-
-        member_service_group = service_properties[cartridgeagentconstants.SERVICE_GROUP_TOPOLOGY_KEY]
-        if member_service_group is not None and member_service_group == service_group_in_payload:
-            if service_name == cartridge_agent_config.service_name:
-                log.debug("Service names are same")
-                return True
-            elif cartridgeagentconstants.APISTORE_SERVICE_NAME == \
-                    cartridge_agent_config.service_name \
-                    and service_name == cartridgeagentconstants.PUBLISHER_SERVICE_NAME:
-                log.debug("Service name in payload is [store]. Serivce name in event is [%r] " % service_name)
-                return True
-            elif cartridgeagentconstants.PUBLISHER_SERVICE_NAME == \
-                    cartridge_agent_config.service_name \
-                    and service_name == cartridgeagentconstants.APISTORE_SERVICE_NAME:
-                log.debug("Service name in payload is [publisher]. Serivce name in event is [%r] " % service_name)
-                return True
-            elif cartridgeagentconstants.DEPLOYMENT_WORKER == \
-                    cartridge_agent_config.deployment \
-                    and service_name == cartridge_agent_config.manager_service_name:
-                log.debug("Deployment is worker. Worker's manager service name & service name in event are same")
-                return True
-            elif cartridgeagentconstants.DEPLOYMENT_MANAGER == \
-                    cartridge_agent_config.deployment  \
-                    and service_name == cartridge_agent_config.worker_service_name:
-                log.debug("Deployment is manager. Manager's worker service name & service name in event are same")
-                return True
-
-    return False
-
-
-def execute_volume_mount_extension(persistance_mappings_payload):
-    try:
-        log.debug("Executing volume mounting extension: [payload] %r" % persistance_mappings_payload)
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.MOUNT_VOLUMES_SCRIPT, False)
-        command = prepare_command(script_name)
-
-        output, errors = execute_command(command + " " + persistance_mappings_payload)
-        log.debug("Volume mount script returned: %r" % output)
-    except:
-        log.exception("Could not execute Volume mount extension")
-
-
-def execute_cleanup_extension():
-    try:
-        log.debug("Executing cleanup extension")
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.CLEAN_UP_SCRIPT, False)
-        command = prepare_command(script_name)
-
-        output, errors = execute_command(command)
-        log.debug("Cleanup script returned: %r" % output)
-    except:
-        log.exception("Could not execute Cleanup extension")
-
-
-def execute_member_activated_extension(env_params):
-    try:
-        log.debug("Executing member activated extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.MEMBER_ACTIVATED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Member activated script returned: %r" % output)
-    except:
-        log.exception("Could not execute member activated extension")
-
-
-def prepare_command(script_name):
-    extensions_dir = cartridge_agent_config.read_property(
-        cartridgeagentconstants.EXTENSIONS_DIR, False)
-    if extensions_dir.strip() == "":
-        raise RuntimeError("System property not found: %r" % cartridgeagentconstants.EXTENSIONS_DIR)
-
-    file_path = extensions_dir + script_name if str(extensions_dir).endswith("/") \
-        else extensions_dir + "/" + script_name
-
-    if os.path.isfile(file_path):
-        return file_path
-
-    raise IOError("Script file not found : %r" % file_path)
-
-
-def clean_process_parameters(params):
-    """
-    Removes any null valued parameters before passing them to the extension scripts
-    :param dict params:
-    :return: cleaned parameters
-    :rtype: dict
-    """
-    for key, value in params.items():
-        if value is None:
-            del params[key]
-
-    return params
-
-
-def add_payload_parameters(env_params):
-    """
-    Adds the common parameters to be used by the extension scripts
-    :param dict[str, str] env_params: Dictionary to be added
-    :return: Dictionary with updated parameters
-    :rtype: dict[str, str]
-    """
-    env_params["STRATOS_APP_PATH"] = cartridge_agent_config.app_path
-    env_params["STRATOS_PARAM_FILE_PATH"] = cartridge_agent_config.read_property(
-        cartridgeagentconstants.PARAM_FILE_PATH, False)
-    env_params["STRATOS_SERVICE_NAME"] = cartridge_agent_config.service_name
-    env_params["STRATOS_TENANT_ID"] = cartridge_agent_config.tenant_id
-    env_params["STRATOS_CARTRIDGE_KEY"] = cartridge_agent_config.cartridge_key
-    env_params["STRATOS_LB_CLUSTER_ID"] = cartridge_agent_config.lb_cluster_id
-    env_params["STRATOS_CLUSTER_ID"] = cartridge_agent_config.cluster_id
-    env_params["STRATOS_NETWORK_PARTITION_ID"] = \
-        cartridge_agent_config.network_partition_id
-    env_params["STRATOS_PARTITION_ID"] = cartridge_agent_config.partition_id
-    env_params["STRATOS_PERSISTENCE_MAPPINGS"] = \
-        cartridge_agent_config.persistence_mappings
-    env_params["STRATOS_REPO_URL"] = cartridge_agent_config.repo_url
-
-    lb_cluster_id_in_payload = cartridge_agent_config.lb_cluster_id
-    member_ips = get_lb_member_ip(lb_cluster_id_in_payload)
-    if member_ips is not None:
-        env_params["STRATOS_LB_IP"] = member_ips[0]
-        env_params["STRATOS_LB_PUBLIC_IP"] = member_ips[1]
-    else:
-        env_params["STRATOS_LB_IP"] = cartridge_agent_config.lb_private_ip
-        env_params["STRATOS_LB_PUBLIC_IP"] = cartridge_agent_config.lb_public_ip
-
-    topology = TopologyContext.get_topology()
-    if topology.initialized:
-        service = topology.get_service(cartridge_agent_config.service_name)
-        cluster = service.get_cluster(cartridge_agent_config.cluster_id)
-        member_id_in_payload = cartridge_agent_config.member_id
-        add_properties(service.properties, env_params, "SERVICE_PROPERTY")
-        add_properties(cluster.properties, env_params, "CLUSTER_PROPERTY")
-        add_properties(cluster.get_member(member_id_in_payload).properties, env_params, "MEMBER_PROPERTY")
-
-    return env_params
-
-
-def add_properties(properties, params, prefix):
-    """
-    Adds the given property list to the parameters list with given prefix in the parameter name
-    :param dict[str, str] properties: service properties
-    :param dict[str, str] params:
-    :param str prefix:
-    :return: dict[str, str]
-    """
-    if properties is None or properties.items() is None:
-        return
-
-    for key in properties:
-        params["STRATOS_" + prefix + "_" + key] = str(properties[key])
-        log.debug("Property added: [key] STRATOS_ " + prefix + "_" + key + "[value] " + properties[key])
-
-
-def get_lb_member_ip(lb_cluster_id):
-    topology = TopologyContext.get_topology()
-    services = topology.get_services()
-
-    for service in services:
-        clusters = service.get_clusters()
-        for cluster in clusters:
-            members = cluster.get_members()
-            for member in members:
-                if member.cluster_id == lb_cluster_id:
-                    return [member.member_ip, member.member_public_ip]
-
-    return None
-
-
-def execute_command(command, env_params=None):
-    """
-    Executes the given command string with given environment parameters
-    :param str command: Command with arguments to be executed
-    :param dict[str, str] env_params: Environment variables to be used
-    :return: output and error string tuple, RuntimeError if errors occur
-    :rtype: tuple
-    :exception: RuntimeError
-    """
-    os_env = os.environ.copy()
-    if env_params is not None:
-        os_env.update(env_params)
-
-    p = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os_env)
-    output, errors = p.communicate()
-    log.debug("output = %r" % output)
-    log.debug("error = %r" % errors)
-    if len(errors) > 0:
-        raise RuntimeError("Command execution failed: \n %r" % errors)
-
-    return output, errors
-
-
-from .. topology.topologycontext import *
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/util/log.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/util/log.py b/tools/python-cartridge-agent/cartridge-agent/modules/util/log.py
deleted file mode 100644
index 9bad214..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/util/log.py
+++ /dev/null
@@ -1,55 +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.
-
-import logging
-import logging.config
-import os
-
-
-class LogFactory(object):
-    """
-    Singleton implementation for handling logging in CartridgeAgent
-    """
-    class __LogFactory:
-        def __init__(self):
-            self.logs = {}
-            logging_conf = os.path.abspath(os.path.dirname(__file__)).split("modules")[0] + "logging.ini"
-            logging.config.fileConfig(logging_conf)
-
-        def get_log(self, name):
-            if name not in self.logs:
-                self.logs[name] = logging.getLogger(name)
-
-            return self.logs[name]
-
-    instance = None
-
-    def __new__(cls, *args, **kwargs):
-        if not LogFactory.instance:
-            LogFactory.instance = LogFactory.__LogFactory()
-
-        return LogFactory.instance
-
-    def get_log(self, name):
-        """
-        Returns a logger class with the specified channel name. Creates a new logger if one doesn't exists for the
-        specified channel
-        :param str name: Channel name
-        :return: The logger class
-        :rtype: RootLogger
-        """
-        return self.instance.get_log(name)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/__init__.py b/tools/python-cartridge-agent/cartridgeagent/__init__.py
new file mode 100644
index 0000000..d216be4
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/__init__.py
@@ -0,0 +1,16 @@
+# 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.
\ No newline at end of file


[06/50] [abbrv] git commit: Cleaned additional log points

Posted by im...@apache.org.
Cleaned additional log points


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

Branch: refs/heads/master
Commit: 3423127e17fe94cbf1318d37ccc06dc526111e39
Parents: 33a1f2b
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Thu Oct 16 15:36:57 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Thu Oct 16 15:36:57 2014 +0530

----------------------------------------------------------------------
 .../cartridge-agent/modules/databridge/agent.py         | 12 +-----------
 .../modules/healthstatspublisher/healthstats.py         |  8 --------
 2 files changed, 1 insertion(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/3423127e/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
index 8146666..1859d8a 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
@@ -137,11 +137,8 @@ class ThriftPublisher:
             raise RuntimeError("Port number for Thrift Publisher is invalid: %r" % port)
 
         self.__publisher = Publisher(ip, port_number)
-        ThriftPublisher.log.debug("CREATED PUBLISHER.. CONNECTING WITH USERNAME AND PASSWORD %r:%r" % (username, password))
         self.__publisher.connect(username, password)
-        ThriftPublisher.log.debug("Connected THRIFT ")
         self.__publisher.defineStream(str(stream_definition))
-        ThriftPublisher.log.debug("DEFINED STREAM to %r:%r with stream definition %r" % (ip, port, str(stream_definition)))
 
         self.stream_definition = stream_definition
         self.stream_id = self.__publisher.streamId
@@ -161,10 +158,9 @@ class ThriftPublisher:
         ThriftPublisher.assign_attributes(event.metaData, event_bundler)
         ThriftPublisher.assign_attributes(event.correlationData, event_bundler)
         ThriftPublisher.assign_attributes(event.payloadData, event_bundler)
-        ThriftPublisher.log.debug("ABOUT TO PUBLISH")
 
         self.__publisher.publish(event_bundler)
-        ThriftPublisher.log.debug("PUBLISHED EVENT BUNDLED TO THRIFT MODULE")
+        self.log.debug("Published event to thrift stream [%r]" % self.stream_id)
 
     def disconnect(self):
         """
@@ -172,7 +168,6 @@ class ThriftPublisher:
         :return: void
         """
         self.__publisher.disconnect()
-        ThriftPublisher.log.debug("DISCONNECTED FROM THRIFT PUBLISHER")
 
     @staticmethod
     def assign_attributes(attributes, event_bundler):
@@ -192,19 +187,14 @@ class ThriftPublisher:
         if attributes is not None and len(attributes) > 0:
             for attrib in attributes:
                 if isinstance(attrib, int):
-                    ThriftPublisher.log.debug("Int : %r" % attrib)
                     event_bundler.addIntAttribute(attrib)
                 elif isinstance(attrib, long):
-                    ThriftPublisher.log.debug("Long : %r" % attrib)
                     event_bundler.addLongAttribute(attrib)
                 elif isinstance(attrib, float):
-                    ThriftPublisher.log.debug("Float : %r" % attrib)
                     event_bundler.addDoubleAttribute(attrib)
                 elif isinstance(attrib, bool):
-                    ThriftPublisher.log.debug("Bool : %r" % attrib)
                     event_bundler.addBoolAttribute(attrib)
                 elif isinstance(attrib, str):
-                    ThriftPublisher.log.debug("Str : %r" % attrib)
                     event_bundler.addStringAttribute(attrib)
                 else:
                     ThriftPublisher.log.error("Undefined attribute type: %r" % attrib)

http://git-wip-us.apache.org/repos/asf/stratos/blob/3423127e/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py b/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
index 5dcad24..4ceb948 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/healthstats.py
@@ -49,8 +49,6 @@ class HealthStatisticsPublisherManager(Thread):
         self.publish_interval = publish_interval
         """:type : int"""
 
-        self.log.debug("Initializing health stat publisher manager with interval %r" % publish_interval)
-
         self.terminated = False
 
         self.publisher = HealthStatisticsPublisher()
@@ -60,8 +58,6 @@ class HealthStatisticsPublisherManager(Thread):
         """:type : AbstractHealthStatisticsReader"""
 
     def run(self):
-        self.log.debug("Pubilsher manager thread started")
-
         while not self.terminated:
             time.sleep(self.publish_interval)
 
@@ -112,7 +108,6 @@ class HealthStatisticsPublisher:
         """
         Create a StreamDefinition for publishing to CEP
         """
-        HealthStatisticsPublisher.log.debug("Creating Stream Definition for CEP publisher")
         stream_def = StreamDefinition()
         stream_def.name = HealthStatisticsPublisherManager.STREAM_NAME
         stream_def.version = HealthStatisticsPublisherManager.STREAM_VERSION
@@ -126,8 +121,6 @@ class HealthStatisticsPublisher:
         stream_def.add_payloaddata_attribute("health_description", StreamDefinition.STRING)
         stream_def.add_payloaddata_attribute("value", StreamDefinition.DOUBLE)
 
-        HealthStatisticsPublisher.log.debug("Created stream definition : %r" % str(stream_def))
-
         return stream_def
 
     def publish_memory_usage(self, memory_usage):
@@ -172,7 +165,6 @@ class DefaultHealthStatisticsReader(AbstractHealthStatisticsReader):
 
     def __init__(self):
         self.log = LogFactory().get_log(__name__)
-        self.log.debug("Stats reader initialized")
 
     def stat_cartridge_health(self):
         cartridge_stats = CartridgeHealthStatistics()


[39/50] [abbrv] git commit: Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
Renamed base module name to python_cartridgeagent
Started decrypt password test


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

Branch: refs/heads/master
Commit: a11df3edce5a219f01da94fd465852de8715936e
Parents: 3527184
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Mon Oct 20 23:34:12 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Mon Oct 20 23:34:12 2014 +0530

----------------------------------------------------------------------
 tools/python-cartridge-agent/__init__.py        |    0
 .../cartridgeagent/__init__.py                  |   16 -
 .../cartridgeagent/agent.conf                   |   62 -
 .../cartridgeagent/agent.py                     |  343 ----
 .../cartridgeagent/logging.ini                  |   52 -
 .../cartridgeagent/modules/__init__.py          |   16 -
 .../modules/artifactmgt/__init__.py             |   17 -
 .../modules/artifactmgt/git/__init__.py         |   17 -
 .../modules/artifactmgt/git/agentgithandler.py  |  503 ------
 .../modules/artifactmgt/git/gitrepository.py    |   51 -
 .../artifactmgt/repositoryinformation.py        |   37 -
 .../cartridgeagent/modules/config/__init__.py   |   17 -
 .../config/cartridgeagentconfiguration.py       |  346 ----
 .../modules/databridge/__init__.py              |   17 -
 .../cartridgeagent/modules/databridge/agent.py  |  202 ---
 .../modules/databridge/thrift/__init__.py       |   17 -
 .../databridge/thrift/gen/Data/__init__.py      |    1 -
 .../databridge/thrift/gen/Data/constants.py     |    8 -
 .../databridge/thrift/gen/Data/ttypes.py        |  320 ----
 .../databridge/thrift/gen/Exception/__init__.py |    1 -
 .../thrift/gen/Exception/constants.py           |    8 -
 .../databridge/thrift/gen/Exception/ttypes.py   |  473 ------
 .../ThriftEventTransmissionService-remote       |  117 --
 .../ThriftEventTransmissionService.py           | 1143 -------------
 .../ThriftEventTransmissionService/__init__.py  |    1 -
 .../ThriftEventTransmissionService/constants.py |    8 -
 .../ThriftEventTransmissionService/ttypes.py    |   21 -
 .../ThriftSecureEventTransmissionService-remote |  131 --
 .../ThriftSecureEventTransmissionService.py     | 1495 ------------------
 .../__init__.py                                 |    1 -
 .../constants.py                                |    8 -
 .../ttypes.py                                   |   21 -
 .../modules/databridge/thrift/gen/__init__.py   |    0
 .../modules/databridge/thrift/publisher.py      |  111 --
 .../modules/databridge/thrift/thrift/TSCons.py  |   35 -
 .../databridge/thrift/thrift/TSerialization.py  |   38 -
 .../databridge/thrift/thrift/TTornado.py        |  153 --
 .../modules/databridge/thrift/thrift/Thrift.py  |  170 --
 .../databridge/thrift/thrift/__init__.py        |   20 -
 .../databridge/thrift/thrift/protocol/TBase.py  |   81 -
 .../thrift/thrift/protocol/TBinaryProtocol.py   |  261 ---
 .../thrift/thrift/protocol/TCompactProtocol.py  |  405 -----
 .../thrift/thrift/protocol/TJSONProtocol.py     |  552 -------
 .../thrift/thrift/protocol/TProtocol.py         |  406 -----
 .../thrift/thrift/protocol/__init__.py          |   20 -
 .../thrift/thrift/protocol/fastbinary.c         | 1219 --------------
 .../thrift/thrift/server/THttpServer.py         |   87 -
 .../thrift/thrift/server/TNonblockingServer.py  |  346 ----
 .../thrift/thrift/server/TProcessPoolServer.py  |  118 --
 .../databridge/thrift/thrift/server/TServer.py  |  269 ----
 .../databridge/thrift/thrift/server/__init__.py |   20 -
 .../thrift/thrift/transport/THttpClient.py      |  147 --
 .../thrift/thrift/transport/TSSLSocket.py       |  214 ---
 .../thrift/thrift/transport/TSocket.py          |  176 ---
 .../thrift/thrift/transport/TTransport.py       |  330 ----
 .../thrift/thrift/transport/TTwisted.py         |  221 ---
 .../thrift/thrift/transport/TZlibTransport.py   |  249 ---
 .../thrift/thrift/transport/__init__.py         |   20 -
 .../modules/datapublisher/__init__.py           |   18 -
 .../modules/datapublisher/exception/__init__.py |   17 -
 .../exception/datapublisherexception.py         |   33 -
 .../modules/datapublisher/logpublisher.py       |  273 ----
 .../cartridgeagent/modules/event/__init__.py    |    0
 .../modules/event/instance/__init__.py          |   16 -
 .../modules/event/instance/notifier/__init__.py |   17 -
 .../modules/event/instance/notifier/events.py   |   77 -
 .../modules/event/instance/status/__init__.py   |   17 -
 .../modules/event/instance/status/events.py     |   98 --
 .../modules/event/tenant/__init__.py            |   16 -
 .../modules/event/tenant/events.py              |  147 --
 .../modules/event/topology/__init__.py          |   17 -
 .../modules/event/topology/events.py            |  280 ----
 .../modules/exception/__init__.py               |   16 -
 .../exception/parameternotfoundexception.py     |   35 -
 .../modules/extensions/__init__.py              |   16 -
 .../extensions/abstractextensionhandler.py      |   78 -
 .../extensions/defaultextensionhandler.py       |  789 ---------
 .../modules/healthstatspublisher/__init__.py    |   16 -
 .../abstracthealthstatisticspublisher.py        |   62 -
 .../modules/healthstatspublisher/healthstats.py |  246 ---
 .../modules/publisher/__init__.py               |   16 -
 .../publisher/cartridgeagentpublisher.py        |  165 --
 .../modules/subscriber/__init__.py              |   17 -
 .../modules/subscriber/eventsubscriber.py       |   96 --
 .../cartridgeagent/modules/tenant/__init__.py   |   16 -
 .../modules/tenant/tenantcontext.py             |  184 ---
 .../cartridgeagent/modules/topology/__init__.py |   16 -
 .../modules/topology/topologycontext.py         |  454 ------
 .../cartridgeagent/modules/util/__init__.py     |   16 -
 .../modules/util/asyncscheduledtask.py          |   71 -
 .../modules/util/cartridgeagentconstants.py     |  135 --
 .../modules/util/cartridgeagentutils.py         |  165 --
 .../modules/util/extensionutils.py              |  494 ------
 .../cartridgeagent/modules/util/log.py          |   55 -
 tools/python-cartridge-agent/test/__init__.py   |   16 -
 tools/python-cartridge-agent/test/asynctest.txt |    1 -
 tools/python-cartridge-agent/test/test_util.py  |   39 -
 tools/python_cartridgeagent/__init__.py         |    0
 .../cartridgeagent/__init__.py                  |   16 +
 .../cartridgeagent/agent.conf                   |   62 +
 .../cartridgeagent/agent.py                     |  343 ++++
 .../cartridgeagent/logging.ini                  |   52 +
 .../cartridgeagent/modules/__init__.py          |   16 +
 .../modules/artifactmgt/__init__.py             |   17 +
 .../modules/artifactmgt/git/__init__.py         |   17 +
 .../modules/artifactmgt/git/agentgithandler.py  |  503 ++++++
 .../modules/artifactmgt/git/gitrepository.py    |   51 +
 .../artifactmgt/repositoryinformation.py        |   37 +
 .../cartridgeagent/modules/config/__init__.py   |   17 +
 .../config/cartridgeagentconfiguration.py       |  346 ++++
 .../modules/databridge/__init__.py              |   17 +
 .../cartridgeagent/modules/databridge/agent.py  |  202 +++
 .../modules/databridge/thrift/__init__.py       |   17 +
 .../databridge/thrift/gen/Data/__init__.py      |    1 +
 .../databridge/thrift/gen/Data/constants.py     |    8 +
 .../databridge/thrift/gen/Data/ttypes.py        |  320 ++++
 .../databridge/thrift/gen/Exception/__init__.py |    1 +
 .../thrift/gen/Exception/constants.py           |    8 +
 .../databridge/thrift/gen/Exception/ttypes.py   |  473 ++++++
 .../ThriftEventTransmissionService-remote       |  117 ++
 .../ThriftEventTransmissionService.py           | 1143 +++++++++++++
 .../ThriftEventTransmissionService/__init__.py  |    1 +
 .../ThriftEventTransmissionService/constants.py |    8 +
 .../ThriftEventTransmissionService/ttypes.py    |   21 +
 .../ThriftSecureEventTransmissionService-remote |  131 ++
 .../ThriftSecureEventTransmissionService.py     | 1495 ++++++++++++++++++
 .../__init__.py                                 |    1 +
 .../constants.py                                |    8 +
 .../ttypes.py                                   |   21 +
 .../modules/databridge/thrift/gen/__init__.py   |    0
 .../modules/databridge/thrift/publisher.py      |  111 ++
 .../modules/databridge/thrift/thrift/TSCons.py  |   35 +
 .../databridge/thrift/thrift/TSerialization.py  |   38 +
 .../databridge/thrift/thrift/TTornado.py        |  153 ++
 .../modules/databridge/thrift/thrift/Thrift.py  |  170 ++
 .../databridge/thrift/thrift/__init__.py        |   20 +
 .../databridge/thrift/thrift/protocol/TBase.py  |   81 +
 .../thrift/thrift/protocol/TBinaryProtocol.py   |  261 +++
 .../thrift/thrift/protocol/TCompactProtocol.py  |  405 +++++
 .../thrift/thrift/protocol/TJSONProtocol.py     |  552 +++++++
 .../thrift/thrift/protocol/TProtocol.py         |  406 +++++
 .../thrift/thrift/protocol/__init__.py          |   20 +
 .../thrift/thrift/protocol/fastbinary.c         | 1219 ++++++++++++++
 .../thrift/thrift/server/THttpServer.py         |   87 +
 .../thrift/thrift/server/TNonblockingServer.py  |  346 ++++
 .../thrift/thrift/server/TProcessPoolServer.py  |  118 ++
 .../databridge/thrift/thrift/server/TServer.py  |  269 ++++
 .../databridge/thrift/thrift/server/__init__.py |   20 +
 .../thrift/thrift/transport/THttpClient.py      |  147 ++
 .../thrift/thrift/transport/TSSLSocket.py       |  214 +++
 .../thrift/thrift/transport/TSocket.py          |  176 +++
 .../thrift/thrift/transport/TTransport.py       |  330 ++++
 .../thrift/thrift/transport/TTwisted.py         |  221 +++
 .../thrift/thrift/transport/TZlibTransport.py   |  249 +++
 .../thrift/thrift/transport/__init__.py         |   20 +
 .../modules/datapublisher/__init__.py           |   18 +
 .../modules/datapublisher/exception/__init__.py |   17 +
 .../exception/datapublisherexception.py         |   33 +
 .../modules/datapublisher/logpublisher.py       |  273 ++++
 .../cartridgeagent/modules/event/__init__.py    |    0
 .../modules/event/instance/__init__.py          |   16 +
 .../modules/event/instance/notifier/__init__.py |   17 +
 .../modules/event/instance/notifier/events.py   |   77 +
 .../modules/event/instance/status/__init__.py   |   17 +
 .../modules/event/instance/status/events.py     |   98 ++
 .../modules/event/tenant/__init__.py            |   16 +
 .../modules/event/tenant/events.py              |  147 ++
 .../modules/event/topology/__init__.py          |   17 +
 .../modules/event/topology/events.py            |  280 ++++
 .../modules/exception/__init__.py               |   16 +
 .../exception/parameternotfoundexception.py     |   35 +
 .../modules/extensions/__init__.py              |   16 +
 .../extensions/abstractextensionhandler.py      |   78 +
 .../extensions/defaultextensionhandler.py       |  789 +++++++++
 .../modules/healthstatspublisher/__init__.py    |   16 +
 .../abstracthealthstatisticspublisher.py        |   62 +
 .../modules/healthstatspublisher/healthstats.py |  246 +++
 .../modules/publisher/__init__.py               |   16 +
 .../publisher/cartridgeagentpublisher.py        |  165 ++
 .../modules/subscriber/__init__.py              |   17 +
 .../modules/subscriber/eventsubscriber.py       |   96 ++
 .../cartridgeagent/modules/tenant/__init__.py   |   16 +
 .../modules/tenant/tenantcontext.py             |  184 +++
 .../cartridgeagent/modules/topology/__init__.py |   16 +
 .../modules/topology/topologycontext.py         |  454 ++++++
 .../cartridgeagent/modules/util/__init__.py     |   16 +
 .../modules/util/asyncscheduledtask.py          |   71 +
 .../modules/util/cartridgeagentconstants.py     |  135 ++
 .../modules/util/cartridgeagentutils.py         |  168 ++
 .../modules/util/extensionutils.py              |  494 ++++++
 .../cartridgeagent/modules/util/log.py          |   55 +
 tools/python_cartridgeagent/test/__init__.py    |   16 +
 tools/python_cartridgeagent/test/asynctest.txt  |    1 +
 tools/python_cartridgeagent/test/test_util.py   |   55 +
 194 files changed, 15397 insertions(+), 15378 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/__init__.py b/tools/python-cartridge-agent/__init__.py
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/__init__.py b/tools/python-cartridge-agent/cartridgeagent/__init__.py
deleted file mode 100644
index d216be4..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/__init__.py
+++ /dev/null
@@ -1,16 +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.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/agent.conf
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/agent.conf b/tools/python-cartridge-agent/cartridgeagent/agent.conf
deleted file mode 100644
index 5c087e9..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/agent.conf
+++ /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.
-
-[agent]
-mb.ip                                 =MB-IP
-mb.port                               =MB-PORT
-listen.address                        =LISTEN_ADDR
-thrift.receiver.ip                    =CEP-IP
-thrift.receiver.port                  =CEP-PORT
-thrift.server.admin.username          =CEP-ADMIN-USERNAME
-thrift.server.admin.password          =CEP-ADMIN-PASSWORD
-param.file.path                       =/mnt/cartridge-agent/payload/launch-params
-extensions.dir                        =/mnt/cartridge-agent/extensions
-cep.stats.publisher.enabled           =ENABLE_HEALTH_PUBLISHER
-lb.private.ip                         =LB_PRIVATE_IP
-lb.public.ip                          =LB_PUBLIC_IP
-enable.artifact.update                =ENABLE_ARTFCT_UPDATE
-auto.commit                           =COMMIT_ENABLED
-auto.checkout                         =CHECKOUT_ENABLED
-artifact.update.interval              =ARTFCT_UPDATE_INT
-port.check.timeout                    =PORT_CHECK_TIMEOUT
-enable.data.publisher                 =ENABLE-DATA-PUBLISHER
-monitoring.server.ip                  =MONITORING-SERVER-IP
-monitoring.server.port                =MONITORING-SERVER-PORT
-monitoring.server.secure.port         =MONITORING-SERVER-SECURE-PORT
-monitoring.server.admin.username      =MONITORING-SERVER-ADMIN-USERNAME
-monitoring.server.admin.password      =MONITORING-SERVER-ADMIN-PASSWORD
-log.file.paths                        =LOG_FILE_PATHS
-APP_PATH                              =APP-PATH
-super.tenant.repository.path          =/repository/deployment/server/
-tenant.repository.path                =/repository/tenants/
-extension.instance.started            =instance-started.sh
-extension.start.servers               =start-servers.sh
-extension.instance.activated          =instance-activated.sh
-extension.artifacts.updated           =artifacts-updated.sh
-extension.clean                       =clean.sh
-extension.mount.volumes               =mount_volumes.sh
-extension.member.started              =member-started.sh
-extension.member.activated            =member-activated.sh
-extension.member.suspended            =member-suspended.sh
-extension.member.terminated           =member-terminated.sh
-extension.complete.topology           =complete-topology.sh
-extension.complete.tenant             =complete-tenant.sh
-extension.subscription.domain.added   =subscription-domain-added.sh
-extension.subscription.domain.removed =subscription-domain-removed.sh
-extension.artifacts.copy              =artifacts-copy.sh
-extension.tenant.subscribed           =tenant-subscribed.sh
-extension.tenant.unsubscribed         =tenant-unsubscribed.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/agent.py b/tools/python-cartridge-agent/cartridgeagent/agent.py
deleted file mode 100644
index 9f1a972..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/agent.py
+++ /dev/null
@@ -1,343 +0,0 @@
-#!/usr/bin/env python
-# 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.
-
-import threading
-
-from modules.exception.parameternotfoundexception import ParameterNotFoundException
-from modules.subscriber import eventsubscriber
-from modules.publisher import cartridgeagentpublisher
-from modules.event.instance.notifier.events import *
-from modules.event.tenant.events import *
-from modules.event.topology.events import *
-from modules.tenant.tenantcontext import *
-from modules.topology.topologycontext import *
-from modules.datapublisher.logpublisher import *
-from modules.config import cartridgeagentconfiguration
-from modules.extensions import defaultextensionhandler
-
-
-class CartridgeAgent(threading.Thread):
-    extension_handler = defaultextensionhandler.DefaultExtensionHandler()
-
-    def __init__(self):
-        threading.Thread.__init__(self)
-
-        mb_ip = cartridgeagentconfiguration.CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_IP)
-        mb_port = cartridgeagentconfiguration.CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_PORT)
-
-        self.__instance_event_subscriber = eventsubscriber.EventSubscriber(
-            cartridgeagentconstants.INSTANCE_NOTIFIER_TOPIC,
-            mb_ip,
-            mb_port)
-        self.__tenant_event_subscriber = eventsubscriber.EventSubscriber(
-            cartridgeagentconstants.TENANT_TOPIC,
-            mb_ip,
-            mb_port)
-        self.__topology_event_subscriber = eventsubscriber.EventSubscriber(
-            cartridgeagentconstants.TOPOLOGY_TOPIC,
-            mb_ip,
-            mb_port)
-
-        self.__tenant_context_initialized = False
-
-        self.log_publish_manager = None
-
-        self.terminated = False
-
-        self.log = LogFactory().get_log(__name__)
-
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-    def run(self):
-        self.log.info("Starting Cartridge Agent...")
-
-        #Check if required prpoerties are set
-        self.validate_required_properties()
-
-        #Start instance notifier listener thread
-        self.subscribe_to_topics_and_register_listeners()
-
-        #Start topology event receiver thread
-        self.register_topology_event_listeners()
-
-        #Start tenant event receiver thread
-        self.register_tenant_event_listeners()
-
-        #wait for intance spawned event
-        while not self.cartridge_agent_config.initialized:
-            self.log.debug("Waiting for Cartridge Agent to be initialized...")
-            time.sleep(1)
-
-        #Execute instance started shell script
-        CartridgeAgent.extension_handler.on_instance_started_event()
-
-        #Publish instance started event
-        cartridgeagentpublisher.publish_instance_started_event()
-
-        #Execute start servers extension
-        try:
-            CartridgeAgent.extension_handler.start_server_extension()
-        except:
-            self.log.exception("Error processing start servers event")
-
-        #Wait for all ports to be active
-        cartridgeagentutils.wait_until_ports_active(
-            self.cartridge_agent_config.listen_address,
-            self.cartridge_agent_config.ports,
-            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False))
-        )
-
-        # check if artifact management is required before publishing instance activated event
-        repo_url = self.cartridge_agent_config.repo_url
-        if repo_url is None or str(repo_url).strip() == "":
-            self.log.info("No artifact repository found")
-            CartridgeAgent.extension_handler.on_instance_activated_event()
-
-            cartridgeagentpublisher.publish_instance_activated_event()
-
-        persistence_mappping_payload = self.cartridge_agent_config.persistence_mappings
-        if persistence_mappping_payload is not None:
-            CartridgeAgent.extension_handler.volume_mount_extension(persistence_mappping_payload)
-
-        # start log publishing thread
-        if DataPublisherConfiguration.get_instance().enabled:
-            log_file_paths = self.cartridge_agent_config.log_file_paths
-            if log_file_paths is None:
-                self.log.exception("No valid log file paths found, no logs will be published")
-            else:
-                self.log_publish_manager = LogPublisherManager(log_file_paths)
-                self.log_publish_manager.start()
-
-        while not self.terminated:
-            time.sleep(1)
-
-        if DataPublisherConfiguration.get_instance().enabled:
-            self.log_publish_manager.terminate_all_publishers()
-
-    def terminate(self):
-        """
-        Allows the CartridgeAgent thread to be terminated
-
-        :return: void
-        """
-        self.terminated = True
-
-    def validate_required_properties(self):
-        """
-        Checks if required properties are set
-        :return: void
-        """
-        #PARAM_FILE_PATH
-        try:
-            self.cartridge_agent_config.read_property(cartridgeagentconstants.PARAM_FILE_PATH)
-        except ParameterNotFoundException:
-            self.log.error("System property not found: %r" % cartridgeagentconstants.PARAM_FILE_PATH)
-            return
-
-        #EXTENSIONS_DIR
-        try:
-            self.cartridge_agent_config.read_property(cartridgeagentconstants.EXTENSIONS_DIR)
-        except ParameterNotFoundException:
-            self.log.error("System property not found: %r" % cartridgeagentconstants.EXTENSIONS_DIR)
-            return
-        
-    def subscribe_to_topics_and_register_listeners(self):
-        self.log.debug("Starting instance notifier event message receiver thread")
-
-        self.__instance_event_subscriber.register_handler("ArtifactUpdatedEvent", self.on_artifact_updated)
-        self.__instance_event_subscriber.register_handler("InstanceCleanupMemberEvent", self.on_instance_cleanup_member)
-        self.__instance_event_subscriber.register_handler("InstanceCleanupClusterEvent", self.on_instance_cleanup_cluster)
-
-        self.__instance_event_subscriber.start()
-        self.log.info("Instance notifier event message receiver thread started")
-
-        # wait till subscribed to continue
-        while not self.__instance_event_subscriber.is_subscribed():
-            time.sleep(2)
-
-    def on_artifact_updated(self, msg):
-        event_obj = ArtifactUpdatedEvent.create_from_json(msg.payload)
-        CartridgeAgent.extension_handler.on_artifact_updated_event(event_obj)
-
-    def on_instance_cleanup_member(self, msg):
-        member_in_payload = self.cartridge_agent_config.member_id
-        event_obj = InstanceCleanupMemberEvent.create_from_json(msg.payload)
-        member_in_event = event_obj.member_id
-        if member_in_payload == member_in_event:
-            CartridgeAgent.extension_handler.on_instance_cleanup_member_event(event_obj)
-
-    def on_instance_cleanup_cluster(self, msg):
-        event_obj = InstanceCleanupClusterEvent.create_from_json(msg.payload)
-        cluster_in_payload = self.cartridge_agent_config.cluster_id
-        cluster_in_event = event_obj.cluster_id
-
-        if cluster_in_event == cluster_in_payload:
-            CartridgeAgent.extension_handler.on_instance_cleanup_cluster_event(event_obj)
-
-    def register_topology_event_listeners(self):
-        self.log.debug("Starting topology event message receiver thread")
-
-        self.__topology_event_subscriber.register_handler("MemberActivatedEvent", self.on_member_activated)
-        self.__topology_event_subscriber.register_handler("MemberTerminatedEvent", self.on_member_terminated)
-        self.__topology_event_subscriber.register_handler("MemberSuspendedEvent", self.on_member_suspended)
-        self.__topology_event_subscriber.register_handler("CompleteTopologyEvent", self.on_complete_topology)
-        self.__topology_event_subscriber.register_handler("MemberStartedEvent", self.on_member_started)
-        self.__topology_event_subscriber.register_handler("InstanceSpawnedEvent", self.on_instance_spawned)
-
-        self.__topology_event_subscriber.start()
-        self.log.info("Cartridge Agent topology receiver thread started")
-
-    def on_instance_spawned(self, msg):
-        self.log.debug("Instance spawned event received: %r" % msg.payload)
-        if self.cartridge_agent_config.initialized:
-            return
-
-        event_obj = InstanceSpawnedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_instance_spawned_event(event_obj)
-        except:
-            self.log.exception("Error processing instance spawned event")
-
-    def on_member_activated(self, msg):
-        self.log.debug("Member activated event received: %r" % msg.payload)
-        if not self.cartridge_agent_config.initialized:
-            return
-
-        event_obj = MemberActivatedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_member_activated_event(event_obj)
-        except:
-            self.log.exception("Error processing member activated event")
-
-    def on_member_terminated(self, msg):
-        self.log.debug("Member terminated event received: %r" % msg.payload)
-        if not self.cartridge_agent_config.initialized:
-            return
-
-        event_obj = MemberTerminatedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_member_terminated_event(event_obj)
-        except:
-            self.log.exception("Error processing member terminated event")
-
-    def on_member_suspended(self, msg):
-        self.log.debug("Member suspended event received: %r" % msg.payload)
-        if not self.cartridge_agent_config.initialized:
-            return
-
-        event_obj = MemberSuspendedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_member_suspended_event(event_obj)
-        except:
-            self.log.exception("Error processing member suspended event")
-
-    def on_complete_topology(self, msg):
-        if not self.cartridge_agent_config.initialized:
-            self.log.debug("Complete topology event received")
-            event_obj = CompleteTopologyEvent.create_from_json(msg.payload)
-            TopologyContext.update(event_obj.topology)
-            try:
-                CartridgeAgent.extension_handler.on_complete_topology_event(event_obj)
-            except:
-                self.log.exception("Error processing complete topology event")
-        else:
-            self.log.info("Complete topology event updating task disabled")
-
-    def on_member_started(self, msg):
-        self.log.debug("Member started event received: %r" % msg.payload)
-        if not self.cartridge_agent_config.initialized:
-            return
-
-        event_obj = MemberStartedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_member_started_event(event_obj)
-        except:
-            self.log.exception("Error processing member started event")
-
-    def register_tenant_event_listeners(self):
-        self.log.debug("Starting tenant event message receiver thread")
-        self.__tenant_event_subscriber.register_handler("SubscriptionDomainAddedEvent", self.on_subscription_domain_added)
-        self.__tenant_event_subscriber.register_handler("SubscriptionDomainsRemovedEvent", self.on_subscription_domain_removed)
-        self.__tenant_event_subscriber.register_handler("CompleteTenantEvent", self.on_complete_tenant)
-        self.__tenant_event_subscriber.register_handler("TenantSubscribedEvent", self.on_tenant_subscribed)
-        self.__tenant_event_subscriber.register_handler("TenantUnSubscribedEvent", self.on_tenant_unsubscribed)
-
-        self.__tenant_event_subscriber.start()
-        self.log.info("Tenant event message receiver thread started")
-
-    def on_subscription_domain_added(self, msg):
-        self.log.debug("Subscription domain added event received : %r" % msg.payload)
-        event_obj = SubscriptionDomainAddedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_subscription_domain_added_event(event_obj)
-        except:
-            self.log.exception("Error processing subscription domains added event")
-
-    def on_subscription_domain_removed(self, msg):
-        self.log.debug("Subscription domain removed event received : %r" % msg.payload)
-        event_obj = SubscriptionDomainRemovedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_subscription_domain_removed_event(event_obj)
-        except:
-            self.log.exception("Error processing subscription domains removed event")
-
-    def on_complete_tenant(self, msg):
-        if not self.__tenant_context_initialized:
-            self.log.debug("Complete tenant event received")
-            event_obj = CompleteTenantEvent.create_from_json(msg.payload)
-            TenantContext.update(event_obj.tenants)
-
-            try:
-                CartridgeAgent.extension_handler.on_complete_tenant_event(event_obj)
-                self.__tenant_context_initialized = True
-            except:
-                self.log.exception("Error processing complete tenant event")
-        else:
-            self.log.info("Complete tenant event updating task disabled")
-
-    def on_tenant_subscribed(self, msg):
-        self.log.debug("Tenant subscribed event received: %r" % msg.payload)
-        event_obj = TenantSubscribedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_tenant_subscribed_event(event_obj)
-        except:
-            self.log.exception("Error processing tenant subscribed event")
-
-    def on_tenant_unsubscribed(self, msg):
-        self.log.debug("Tenant unSubscribed event received: %r" % msg.payload)
-        event_obj = TenantUnsubscribedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_tenant_unsubscribed_event(event_obj)
-        except:
-            self.log.exception("Error processing tenant unSubscribed event")
-
-
-def main():
-    cartridge_agent = CartridgeAgent()
-    log = LogFactory().get_log(__name__)
-
-    try:
-        log.debug("Starting cartridge agent")
-        cartridge_agent.start()
-    except:
-        log.exception("Cartridge Agent Exception")
-        cartridge_agent.terminate()
-
-
-if __name__ == "__main__":
-    main()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/logging.ini
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/logging.ini b/tools/python-cartridge-agent/cartridgeagent/logging.ini
deleted file mode 100644
index 3e49a96..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/logging.ini
+++ /dev/null
@@ -1,52 +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.
-
-
-[formatters]
-keys=default
-
-[formatter_default]
-format=%(asctime)s:%(levelname)s:%(message)s
-class=logging.Formatter
-
-[handlers]
-keys=console, error_file, log_file
-
-[handler_console]
-class=logging.StreamHandler
-formatter=default
-args=tuple()
-
-[handler_log_file]
-class=logging.FileHandler
-level=LOG_LEVEL
-formatter=default
-args=("agent.log", "w")
-
-[handler_error_file]
-class=logging.FileHandler
-level=ERROR
-formatter=default
-args=("error.log", "w")
-
-[loggers]
-keys=root
-
-[logger_root]
-level=LOG_LEVEL
-formatter=default
-handlers=console,error_file,log_file
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/__init__.py
deleted file mode 100644
index d216be4..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/__init__.py
+++ /dev/null
@@ -1,16 +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.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
deleted file mode 100644
index 6da9c58..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
+++ /dev/null
@@ -1,503 +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.
-
-from threading import current_thread, Thread
-from git import *
-from gittle import Gittle, GittleAuth  # GitPython and Gittle are both used at the time being for pros and cons of both
-import urllib2
-
-from ... util.log import LogFactory
-from ... util import cartridgeagentutils, extensionutils, cartridgeagentconstants
-from gitrepository import GitRepository
-from ... config import cartridgeagentconfiguration
-from ... util.asyncscheduledtask import AbstractAsyncScheduledTask, ScheduledExecutor
-from ... artifactmgt.repositoryinformation import RepositoryInformation
-
-class AgentGitHandler:
-    """
-    Handles all the git artifact management tasks related to a cartridge
-    """
-
-    log = LogFactory().get_log(__name__)
-
-    SUPER_TENANT_ID = -1234
-    SUPER_TENANT_REPO_PATH = "/repository/deployment/server/"
-    TENANT_REPO_PATH = "/repository/tenants/"
-
-    extension_handler = None
-
-    __git_repositories = {}
-    # (tenant_id => gitrepository.GitRepository)
-
-    cartridge_agent_config = cartridgeagentconfiguration.CartridgeAgentConfiguration()
-
-    @staticmethod
-    def checkout(repo_info):
-        """
-        Checks out the code from the remote repository.
-        If local repository path is empty, a clone operation is done.
-        If there is a cloned repository already on the local repository path, a pull operation
-        will be performed.
-        If there are artifacts not in the repository already on the local repository path,
-        they will be added to a git repository, the remote url added as origin, and then
-        a pull operation will be performed.
-
-        :param RepositoryInformation repo_info: The repository information object
-        :return: A tuple containing whether it was an initial clone or not, and the repository
-        context object
-        :rtype: tuple(bool, GitRepository)
-        """
-        repo_context = AgentGitHandler.get_repo_context(repo_info.tenant_id)
-        if repo_context is not None:
-            #has been previously cloned, this is not the subscription run
-            subscribe_run = False
-            if AgentGitHandler.is_valid_git_repository(repo_context):
-                AgentGitHandler.log.debug("Existing git repository detected for tenant %r, no clone required" % repo_info.tenant_id)
-                AgentGitHandler.pull(repo_context)
-            else:
-                if not os.listdir(repo_context.local_repo_path):
-                    #empty dir, clone
-                    repo_context.repo = AgentGitHandler.clone(repo_info)
-                else:
-                    #not empty
-                    if AgentGitHandler.sync_initial_local_artifacts(repo_context):
-                        AgentGitHandler.pull(repo_context)
-                    else:
-                        repo_context = None
-        else:
-            #subscribing run.. need to clone
-            subscribe_run = True
-            repo_context = AgentGitHandler.clone(repo_context)
-
-        return subscribe_run, repo_context
-
-    @staticmethod
-    def sync_initial_local_artifacts(repo_context):
-        #init git repo
-        AgentGitHandler.init(repo_context.local_repo_path)
-
-        # add remote repos
-        return AgentGitHandler.add_remote(repo_context)
-
-    @staticmethod
-    def add_remote(repo_context):
-        try:
-            #add origin remote
-            repo_context.repo.create_remote("origin", repo_context.repo_url)
-            #fetch branch details from origin
-            repo_context.repo.git.fetch()
-            #checkout master branch from origin/master as tracking
-            repo_context.repo.git.branch("-f", "--track", "master", "origin/master")
-            return True
-        except:
-            AgentGitHandler.log.exception("Error in adding remote origin %r for local repository %r"
-                                          % (repo_context.repo_url, repo_context.local_repo_path))
-            return False
-
-    @staticmethod
-    def init(path):
-        try:
-            repo = Gittle.init(path)
-            return repo
-        except:
-            AgentGitHandler.log.exception("Initializing local repo at %r failed" % path)
-            raise Exception("Initializing local repo at %r failed" % path)
-
-    @staticmethod
-    def is_valid_git_repository(repo_context):
-        if repo_context.cloned:
-            return True
-
-        for ref in repo_context.repo.refs:
-            try:
-                ref._get_object()
-            except ValueError:
-                return False
-
-        return True
-
-    @staticmethod
-    def pull(repo_context):
-        repo = Repo(repo_context.local_repo_path)
-        from ....agent import CartridgeAgent
-        AgentGitHandler.extension_handler = CartridgeAgent.extension_handler
-        try:
-            repo.git.checkout("master")
-            pull_output = repo.git.pull()
-            if "Already up-to-date." not in pull_output:
-                AgentGitHandler.log.debug("Artifacts were updated as a result of the pull operation, thread: %r - %r" % (current_thread().getName(), current_thread().ident))
-
-            AgentGitHandler.extension_handler.on_artifact_update_scheduler_event(repo_context.tenant_id)
-        except GitCommandError as ex:
-            if "fatal: Could not read from remote repository." in ex:
-                #invalid configuration, need to delete and reclone
-                AgentGitHandler.log.warn("Git pull unsuccessful for tenant %r, invalid configuration. %r" % (repo_context.tenant_id, ex))
-                cartridgeagentutils.delete_folder_tree(repo_context.local_repo_path)
-                AgentGitHandler.clone(RepositoryInformation(
-                    repo_context.repo_url,
-                    repo_context.repo_username,
-                    repo_context.repo_password,
-                    repo_context.local_repo_path,
-                    repo_context.tenant_id,
-                    repo_context.is_multitenant,
-                    repo_context.commit_enabled
-                ))
-                AgentGitHandler.extension_handler.on_artifact_update_scheduler_event(repo_context.tenant_id)
-            elif "error: Your local changes to the following files would be overwritten by merge:" in ex:
-                #conflict error
-                AgentGitHandler.log.warn("Git pull unsuccessful for tenant %r, conflicts detected." % repo_context.tenant_id)
-                #raise ex
-
-                """
-                0:'git pull' returned exit status 1: error: Your local changes to the following files would be overwritten by merge:
-                1:    README.md
-                2:    index.php
-                3:Please, commit your changes or stash them before you can merge.
-                4:Aborting
-                """
-                conflict_list = []
-                files_arr = str(ex).split("\n")
-                for file_index in range(1, len(files_arr) - 2):
-                    file_name = files_arr[file_index].strip()
-                    conflict_list.append(file_name)
-                    AgentGitHandler.log.debug("Added the file path %r to checkout from the remote repository" % file_name)
-
-                AgentGitHandler.checkout_individually(conflict_list, repo)
-            elif "fatal: unable to access " in ex:
-                #transport error
-                AgentGitHandler.log.exception("Accessing remote git repository %r failed for tenant %r" % (repo_context.repo_url, repo_context.tenant_id))
-            else:
-                AgentGitHandler.log.exception("Git pull operation for tenant %r failed" % repo_context.tenant_id)
-
-    @staticmethod
-    def checkout_individually(conflict_list, repo):
-        try:
-            for conflicted_file in conflict_list:
-                repo.git.checkout(conflicted_file)
-                AgentGitHandler.log.info("Checked out the conflicting files from the remote repository successfully")
-        except:
-            AgentGitHandler.log.exception("Checking out artifacts from index failed")
-
-    @staticmethod
-    def clone(repo_info):
-        repo_context = None
-        try:
-            repo_context = AgentGitHandler.create_git_repo_context(repo_info)
-            #create the directory if it doesn't exist
-            if not os.path.isdir(repo_context.local_repo_path):
-                cartridgeagentutils.create_dir(repo_context.local_repo_path)
-
-            auth = AgentGitHandler.create_auth_configuration(repo_context)
-
-            if auth is not None:
-                # authentication is required, use Gittle
-                gittle_repo = Gittle.clone(repo_context.repo_url, repo_context.local_repo_path, auth=auth)
-                repo = Repo(repo_context.local_repo_path)
-            else:
-                # authentication is not required, use GitPython
-                repo = Repo.clone_from(repo_context.repo_url, repo_context.local_repo_path)
-                gittle_repo = Gittle(repo_context.local_repo_path)
-
-            repo_context.cloned = True
-            repo_context.gittle_repo = gittle_repo
-            repo_context.repo  = repo
-            AgentGitHandler.add_repo_context(repo_context)
-            AgentGitHandler.log.info("Git clone operation for tenant %r successful" % repo_context.tenant_id)
-        except urllib2.URLError:
-            AgentGitHandler.log.exception("Accessing remote git repository failed for tenant %r" % repo_context.tenant_id)
-        except OSError:
-            AgentGitHandler.log.exception("Permission denied for repository path for tenant %r" % repo_context.tenant_id)
-        except:
-            AgentGitHandler.log.exception("Git clone operation for tenant %r failed" % repo_context.tenant_id)
-        finally:
-            return repo_context
-
-    @staticmethod
-    def create_auth_configuration(repo_context):
-        """
-        Creates a GittleAuth object based on the type of authorization
-        :param GitRepository repo_context: The repository context object
-        :return: GittleAuth object or None if no authorization needed
-        :rtype: GittleAuth
-        """
-        if repo_context.key_based_auth:
-            pkey = AgentGitHandler.get_private_key()
-            auth = GittleAuth(pkey=pkey)
-        elif repo_context.repo_username.strip() != "" and repo_context.repo_password.strip() != "":
-            auth = GittleAuth(username=repo_context.repo_username, password=repo_context.repo_password)
-        else:
-            auth = None
-
-        return auth
-
-    @staticmethod
-    def get_private_key():
-        """
-        Returns a file handler to the private key path specified by Carbon or default if not specified
-        by Carbon
-        :return: The file object of the private key file
-        :rtype: file
-        """
-        pkey_name = cartridgeagentutils.get_carbon_server_property("SshPrivateKeyName")
-        if pkey_name is  None:
-            pkey_name = "wso2"
-
-        pkey_path = cartridgeagentutils.get_carbon_server_property("SshPrivateKeyPath")
-        if pkey_path is None:
-            pkey_path = os.environ["HOME"] + "/.ssh"
-
-        if pkey_path.endswith("/"):
-            pkey_ptr = pkey_path + pkey_name
-        else:
-            pkey_ptr = pkey_path + "/" + pkey_name
-
-        pkey_file = open(pkey_ptr)
-
-        return pkey_file
-
-
-    @staticmethod
-    def add_repo_context(repo_context):
-        AgentGitHandler.__git_repositories[repo_context.tenant_id] = repo_context
-
-    @staticmethod
-    def get_repo_context(tenant_id):
-        """
-
-        :param int tenant_id:
-        :return: GitRepository object
-        :rtype: GitRepository
-        """
-        if tenant_id in AgentGitHandler.__git_repositories:
-            return AgentGitHandler.__git_repositories[tenant_id]
-
-        return None
-
-    @staticmethod
-    def remove_repo_context(tenant_id):
-        if tenant_id in AgentGitHandler.__git_repositories:
-            del AgentGitHandler.__git_repositories[tenant_id]
-
-    @staticmethod
-    def create_git_repo_context(repo_info):
-        repo_context = GitRepository()
-        repo_context.tenant_id = repo_info.tenant_id
-        repo_context.local_repo_path = AgentGitHandler.get_repo_path_for_tenant(
-            repo_info.tenant_id, repo_info.repo_path, repo_info.is_multitenant)
-        repo_context.repo_url = repo_info.repo_url
-        repo_context.repo_username = repo_info.repo_username
-        repo_context.repo_password = repo_info.repo_password
-        repo_context.is_multitenant = repo_info.is_multitenant
-        repo_context.commit_enabled = repo_info.commit_enabled
-
-        if AgentGitHandler.is_key_based_auth(repo_info.repo_url, repo_info.tenant_id):
-            repo_context.key_based_auth = True
-        else:
-            repo_context.key_based_auth = False
-
-        repo_context.cloned = False
-
-        repo_context.repo = None
-        repo_context.gittle_repo = None
-
-        return repo_context
-
-    @staticmethod
-    def is_key_based_auth(repo_url, tenant_id):
-        """
-        Checks if the given git repo has key based authentication
-        :param str repo_url: Git repository remote url
-        :param str tenant_id: Tenant ID
-        :return: True if key based, False otherwise
-        :rtype: bool
-        """
-        if repo_url.startswith("http://") or repo_url.startswith("https://"):
-            # username and password, not key based
-            return False
-        elif repo_url.startswith("git://github.com"):
-            # no auth required
-            return False
-        elif repo_url.startswith("ssh://") or "@" in repo_url:
-            # key based
-            return True
-        else:
-            AgentGitHandler.log.error("Invalid git URL provided for tenant " + tenant_id)
-            raise RuntimeError("Invalid git URL provided for tenant " + tenant_id)
-
-    @staticmethod
-    def get_repo_path_for_tenant(tenant_id, git_local_repo_path, is_multitenant):
-        repo_path = ""
-
-        if is_multitenant:
-            if tenant_id == AgentGitHandler.SUPER_TENANT_ID:
-                #super tenant, /repository/deploy/server/
-                super_tenant_repo_path = AgentGitHandler.cartridge_agent_config.super_tenant_repository_path
-                #"app_path"
-                repo_path += git_local_repo_path
-
-                if super_tenant_repo_path is not None  and super_tenant_repo_path != "":
-                    super_tenant_repo_path = super_tenant_repo_path if super_tenant_repo_path.startswith("/") else "/" + super_tenant_repo_path
-                    super_tenant_repo_path = super_tenant_repo_path if super_tenant_repo_path.endswith("/") else  super_tenant_repo_path + "/"
-                    #"app_path/repository/deploy/server/"
-                    repo_path += super_tenant_repo_path
-                else:
-                    #"app_path/repository/deploy/server/"
-                    repo_path += AgentGitHandler.SUPER_TENANT_REPO_PATH
-
-            else:
-                #normal tenant, /repository/tenants/tenant_id
-                tenant_repo_path = AgentGitHandler.cartridge_agent_config.tenant_repository_path
-                #"app_path"
-                repo_path += git_local_repo_path
-
-                if tenant_repo_path is not None and tenant_repo_path != "":
-                    tenant_repo_path = tenant_repo_path if tenant_repo_path.startswith("/") else "/" + tenant_repo_path
-                    tenant_repo_path = tenant_repo_path if tenant_repo_path.endswith("/") else tenant_repo_path + "/"
-                    #"app_path/repository/tenants/244653444"
-                    repo_path += tenant_repo_path + tenant_id
-                else:
-                    #"app_path/repository/tenants/244653444"
-                    repo_path += AgentGitHandler.TENANT_REPO_PATH + tenant_id
-
-                #tenant_dir_path = git_local_repo_path + AgentGitHandler.TENANT_REPO_PATH + tenant_id
-                cartridgeagentutils.create_dir(repo_path)
-        else:
-            #not multi tenant, app_path
-            repo_path = git_local_repo_path
-
-        AgentGitHandler.log.debug("Repo path returned : %r" % repo_path)
-        return repo_path
-
-    @staticmethod
-    def commit(repo_info):
-        """
-        Commits and pushes new artifacts to the remote repository
-        :param repo_info:
-        :return:
-        """
-        tenant_id = repo_info.tenant_id
-        repo_context = AgentGitHandler.get_repo_context(tenant_id)
-        gittle_repo = repo_context.gittle_repo
-        try:
-            modified = True if gittle_repo.modified_unstaged_files.count > 0 else False
-        except OSError:
-            # removed files
-            modified = True
-
-        if not modified:
-            AgentGitHandler.log.debug("No changes detected in the local repository for tenant " + tenant_id)
-            return
-
-        gittle_repo.stage(gittle_repo.untracked_files)
-        gittle_repo.stage(gittle_repo.removed_files)
-        gittle_repo.stage(gittle_repo.modified_unstaged_files)
-
-        #commit to local repositpory
-        commit_message = "tenant " + tenant_id + "'s artifacts committed to local repo at " + repo_context.local_repo_path
-
-        try:
-            commit_hash = gittle_repo.commit(name="First Author", email="author@example.org", message=commit_message)
-            AgentGitHandler.log.debug("Committed artifacts for tenant : " + tenant_id + " : " + commit_hash)
-        except:
-            AgentGitHandler.log.exception("Committing artifacts to local repository failed for tenant " + tenant_id)
-
-        #push to remote
-        try:
-            repo = repo_context.repo
-            #TODO: check key based authentication
-            credentialed_remote_url = AgentGitHandler.get_credentialed_remote_url(repo_context)
-            push_remote = repo.create_remote('push_remote', credentialed_remote_url)
-            push_remote.push()
-            AgentGitHandler.log.debug("Pushed artifacts for tenant : " + tenant_id)
-        except:
-            AgentGitHandler.log.exception("Pushing artifacts to remote repository failed for tenant " + tenant_id)
-
-    @staticmethod
-    def get_credentialed_remote_url(repo_context):
-        """
-        Creates a remote url including the credentials
-        :param repo_context:
-        :return:
-        """
-        username = repo_context.repo_username
-        password = repo_context.repo_password
-
-        raise NotImplementedError
-
-    @staticmethod
-    def schedule_artifact_update_scheduled_task(repo_info, auto_checkout, auto_commit, update_interval):
-        repo_context = AgentGitHandler.get_repo_context(repo_info.tenant_id)
-
-        if repo_context is None:
-            AgentGitHandler.log.error("Unable to schedule artifact sync task, repositoryContext null for tenant %r" % repo_info.tenant_id)
-            return
-
-        if repo_context.scheduled_update_task is None:
-            #TODO: make thread safe
-            artifact_update_task = ArtifactUpdateTask(repo_info, auto_checkout, auto_commit)
-            async_task = ScheduledExecutor(update_interval, artifact_update_task)
-
-            repo_context.scheduled_update_task = async_task
-            async_task.start()
-            AgentGitHandler.log.info("Scheduled Artifact Synchronization Task for path %r" % repo_context.local_repo_path)
-        else:
-            AgentGitHandler.log.info("Artifact Synchronization Task for path %r already scheduled" % repo_context.local_repo_path)
-
-    @staticmethod
-    def remove_repo(tenant_id):
-        repo_context = AgentGitHandler.get_repo_context(tenant_id)
-
-        #stop artifact update task
-        repo_context.scheduled_update_task.terminate()
-
-        #remove git contents
-        cartridgeagentutils.delete_folder_tree(repo_context.local_repo_path)
-
-        AgentGitHandler.remove_repo_context(tenant_id)
-
-        if tenant_id == -1234:
-            if AgentGitHandler.cartridge_agent_config.is_multitenant:
-                extensionutils.execute_copy_artifact_extension(
-                    cartridgeagentconstants.SUPERTENANT_TEMP_PATH,
-                    AgentGitHandler.cartridge_agent_config.app_path + "/repository/deployment/server/"
-                )
-
-        AgentGitHandler.log.info("git repository deleted for tenant %r" % repo_context.tenant_id)
-
-        return True
-
-
-class ArtifactUpdateTask(AbstractAsyncScheduledTask):
-    """
-    Checks if the autocheckout and autocommit are enabled and executes respective tasks
-    """
-
-    def __init__(self, repo_info, auto_checkout, auto_commit):
-        self.log = LogFactory().get_log(__name__)
-        self.repo_info = repo_info
-        self.auto_checkout = auto_checkout
-        self.auto_commit = auto_commit
-
-    def execute_task(self):
-        try:
-            if self.auto_checkout:
-                AgentGitHandler.checkout(self.repo_info)
-        except:
-            self.log.exception("Auto checkout task failed")
-
-        if self.auto_commit:
-            AgentGitHandler.commit(self.repo_info)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/gitrepository.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
deleted file mode 100644
index 98a8a44..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
+++ /dev/null
@@ -1,51 +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.
-
-from ...util.asyncscheduledtask import AsyncScheduledTask
-from gittle import Gittle
-from git import *
-
-class GitRepository:
-    """
-    Represents a git repository inside a particular instance
-    """
-
-    def __init__(self):
-        self.repo_url = None
-        """ :type : str  """
-        self.local_repo_path = None
-        """ :type : str  """
-        self.cloned = False
-        """ :type : bool  """
-        self.repo = None
-        """ :type : git.repo.base.Repo  """
-        self.gittle_repo = None
-        """ :type : gittle.gittle.Gittle  """
-        self.tenant_id = None
-        """ :type : int  """
-        self.key_based_auth = False
-        """ :type : bool  """
-        self.repo_username = None
-        """ :type : str  """
-        self.repo_password = None
-        """ :type : str  """
-        self.is_multitenant = False
-        """ :type : bool  """
-        self.commit_enabled = False
-        """ :type : bool  """
-        self.scheduled_update_task = None
-        """:type : AsyncScheduledTask """
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/repositoryinformation.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/repositoryinformation.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/repositoryinformation.py
deleted file mode 100644
index b67eada..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/repositoryinformation.py
+++ /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.
-
-class RepositoryInformation:
-    """
-    Holds repository information to be used in artifact management
-    """
-
-    def __init__(self, repo_url, repo_username, repo_password, repo_path, tenant_id, is_multitenant, commit_enabled):
-        self.repo_url = repo_url
-        """ :type : str  """
-        self.repo_username = repo_username
-        """ :type : str  """
-        self.repo_password = repo_password
-        """ :type : str  """
-        self.repo_path = repo_path
-        """ :type : str  """
-        self.tenant_id = tenant_id
-        """ :type : int  """
-        self.is_multitenant = is_multitenant
-        """ :type : bool  """
-        self.commit_enabled = commit_enabled
-        """ :type : bool  """
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/config/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/config/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/config/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/config/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/config/cartridgeagentconfiguration.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/config/cartridgeagentconfiguration.py b/tools/python-cartridge-agent/cartridgeagent/modules/config/cartridgeagentconfiguration.py
deleted file mode 100644
index 15871ba..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/config/cartridgeagentconfiguration.py
+++ /dev/null
@@ -1,346 +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.
-
-import ConfigParser
-import os
-import socket
-
-from ..util.log import LogFactory
-
-
-class CartridgeAgentConfiguration:
-    """
-    Handles the configuration information of the particular Cartridge Agent
-    """
-    class __CartridgeAgentConfiguration:
-        def __init__(self):
-            # set log level
-            self.log = LogFactory().get_log(__name__)
-
-            self.payload_params = {}
-            self.properties = None
-
-            self.service_group = None
-            """ :type : str  """
-            self.is_clustered = False
-            """ :type : bool  """
-            self.service_name = None
-            """ :type : str  """
-            self.cluster_id = None
-            """ :type : str  """
-            self.network_partition_id = None
-            """ :type : str  """
-            self.partition_id = None
-            """ :type : str  """
-            self.member_id = None
-            """ :type : str  """
-            self.cartridge_key = None
-            """ :type : str  """
-            self.app_path = None
-            """ :type : str  """
-            self.repo_url = None
-            """ :type : str  """
-            self.ports = []
-            """ :type : list[str]  """
-            self.log_file_paths = []
-            """ :type : list[str]  """
-            self.is_multitenant = False
-            """ :type : bool  """
-            self.persistence_mappings = None
-            """ :type : str  """
-            self.is_commits_enabled = False
-            """ :type : bool  """
-            self.is_checkout_enabled = False
-            """ :type : bool  """
-            self.listen_address = None
-            """ :type : str  """
-            self.is_internal_repo = False
-            """ :type : bool  """
-            self.tenant_id = None
-            """ :type : str  """
-            self.lb_cluster_id = None
-            """ :type : str  """
-            self.min_count = None
-            """ :type : str  """
-            self.lb_private_ip = None
-            """ :type : str  """
-            self.lb_public_ip = None
-            """ :type : str  """
-            self.tenant_repository_path = None
-            """ :type : str  """
-            self.super_tenant_repository_path = None
-            """ :type : str  """
-            self.deployment = None
-            """ :type : str  """
-            self.manager_service_name = None
-            """ :type : str  """
-            self.worker_service_name = None
-            """ :type : str  """
-            self.is_primary = False
-            """ :type : bool  """
-
-            self.payload_params = {}
-            self.__read_conf_file()
-            self.__read_parameter_file()
-
-            self.initialized = False
-            """ :type : bool """
-
-            try:
-                self.service_group = self.payload_params[cartridgeagentconstants.SERVICE_GROUP] \
-                    if cartridgeagentconstants.SERVICE_GROUP in self.payload_params \
-                    else None
-
-                if cartridgeagentconstants.CLUSTERING in self.payload_params and \
-                        str(self.payload_params[cartridgeagentconstants.CLUSTERING]).strip().lower() == "true":
-                    self.is_clustered = True
-                else:
-                    self.is_clustered = False
-                # self.__isClustered = self.payload_params[
-                # cartridgeagentconstants.CLUSTERING] if cartridgeagentconstants.CLUSTERING in self.payload_params else None
-
-                self.service_name = self.read_property(cartridgeagentconstants.SERVICE_NAME)
-                self.cluster_id = self.read_property(cartridgeagentconstants.CLUSTER_ID)
-                self.network_partition_id = self.read_property(cartridgeagentconstants.NETWORK_PARTITION_ID, False)
-                self.partition_id = self.read_property(cartridgeagentconstants.PARTITION_ID, False)
-                self.member_id = self.get_member_id(cartridgeagentconstants.MEMBER_ID)
-                self.cartridge_key = self.read_property(cartridgeagentconstants.CARTRIDGE_KEY)
-                self.app_path = self.read_property(cartridgeagentconstants.APP_PATH, False)
-                self.repo_url = self.read_property(cartridgeagentconstants.REPO_URL, False)
-                self.ports = str(self.read_property(cartridgeagentconstants.PORTS)).split("|")
-
-                try:
-                    self.log_file_paths = str(
-                        self.read_property(cartridgeagentconstants.LOG_FILE_PATHS)).strip().split("|")
-                except ParameterNotFoundException as ex:
-                    self.log.debug("Cannot read log file path : %r" % ex.get_message())
-                    self.log_file_paths = None
-
-                is_multi_str = self.read_property(cartridgeagentconstants.MULTITENANT)
-                self.is_multitenant = True if str(is_multi_str).lower().strip() == "true" else False
-
-                try:
-                    self.persistence_mappings = self.read_property(
-                        cartridgeagentconstants.PERSISTENCE_MAPPING)
-                except ParameterNotFoundException as ex:
-                    self.log.debug("Cannot read persistence mapping : %r" % ex.get_message())
-                    self.persistence_mappings = None
-
-                try:
-                    is_commit_str = self.read_property(cartridgeagentconstants.COMMIT_ENABLED)
-                    self.is_commits_enabled = True if str(is_commit_str).lower().strip() == "true" else False
-                except ParameterNotFoundException:
-                    try:
-                        is_commit_str = self.read_property(cartridgeagentconstants.AUTO_COMMIT)
-                        self.is_commits_enabled = True if str(is_commit_str).lower().strip() == "true" else False
-                    except ParameterNotFoundException:
-                        self.log.info(
-                            "%r is not found and setting it to false" % cartridgeagentconstants.COMMIT_ENABLED)
-                        self.is_commits_enabled = False
-
-                auto_checkout_str = self.read_property(cartridgeagentconstants.AUTO_CHECKOUT, False)
-                self.is_checkout_enabled = True if str(auto_checkout_str).lower().strip() == "true" else False
-
-                self.listen_address = self.read_property(
-                    cartridgeagentconstants.LISTEN_ADDRESS, False)
-
-                try:
-                    int_repo_str = self.read_property(cartridgeagentconstants.PROVIDER)
-                    self.is_internal_repo = True if str(int_repo_str).strip().lower() == cartridgeagentconstants.INTERNAL else False
-                except ParameterNotFoundException:
-                    self.log.info(" INTERNAL payload parameter is not found")
-                    self.is_internal_repo = False
-
-                self.tenant_id = self.read_property(cartridgeagentconstants.TENANT_ID)
-                self.lb_cluster_id = self.read_property(cartridgeagentconstants.LB_CLUSTER_ID, False)
-                self.min_count = self.read_property(cartridgeagentconstants.MIN_INSTANCE_COUNT, False)
-                self.lb_private_ip = self.read_property(cartridgeagentconstants.LB_PRIVATE_IP, False)
-                self.lb_public_ip = self.read_property(cartridgeagentconstants.LB_PUBLIC_IP, False)
-                self.tenant_repository_path = self.read_property(cartridgeagentconstants.TENANT_REPO_PATH, False)
-                self.super_tenant_repository_path = self.read_property(cartridgeagentconstants.SUPER_TENANT_REPO_PATH, False)
-
-                try:
-                    self.deployment = self.read_property(
-                        cartridgeagentconstants.DEPLOYMENT)
-                except ParameterNotFoundException:
-                    self.deployment = None
-
-                # Setting worker-manager setup - manager service name
-                if self.deployment is None:
-                    self.manager_service_name = None
-
-                if str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower():
-                    self.manager_service_name = self.service_name
-
-                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
-                    self.deployment = self.read_property(
-                        cartridgeagentconstants.MANAGER_SERVICE_TYPE)
-
-                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_DEFAULT.lower():
-                    self.deployment = None
-                else:
-                    self.deployment = None
-
-                # Setting worker-manager setup - worker service name
-                if self.deployment is None:
-                    self.worker_service_name = None
-
-                if str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
-                    self.manager_service_name = self.service_name
-
-                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower():
-                    self.deployment = self.read_property(
-                        cartridgeagentconstants.WORKER_SERVICE_TYPE)
-
-                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_DEFAULT.lower():
-                    self.deployment = None
-                else:
-                    self.deployment = None
-
-                try:
-                    self.is_primary = self.read_property(
-                        cartridgeagentconstants.CLUSTERING_PRIMARY_KEY)
-                except ParameterNotFoundException:
-                    self.is_primary = None
-            except ParameterNotFoundException as ex:
-                raise RuntimeError(ex)
-
-            self.log.info("Cartridge agent configuration initialized")
-
-            self.log.debug("service-name: %r" % self.service_name)
-            self.log.debug("cluster-id: %r" % self.cluster_id)
-            self.log.debug(
-                "network-partition-id: %r" % self.network_partition_id)
-            self.log.debug("partition-id: %r" % self.partition_id)
-            self.log.debug("member-id: %r" % self.member_id)
-            self.log.debug("cartridge-key: %r" % self.cartridge_key)
-            self.log.debug("app-path: %r" % self.app_path)
-            self.log.debug("repo-url: %r" % self.repo_url)
-            self.log.debug("ports: %r" % str(self.ports))
-            self.log.debug("lb-private-ip: %r" % self.lb_private_ip)
-            self.log.debug("lb-public-ip: %r" % self.lb_public_ip)
-
-        def get_member_id(self, member_id_field):
-            """
-            Reads the member id from the payload file or configuration file. If neither of
-            these sources contain the member id, the hostname is assigned to it and returned.
-            :param str member_id_field: the key of the member id to lookup
-            :return: The member id
-            :rtype : str
-            """
-            try:
-                member_id = self.read_property(member_id_field)
-            except ParameterNotFoundException:
-                try:
-                    self.log.info("Reading hostname from container")
-                    member_id = socket.gethostname()
-                except:
-                    self.log.exception("Hostname can not be resolved")
-                    member_id = "unknown"
-
-            self.log.debug("MemberId  is taking the value of hostname : [" + member_id + "] ")
-            return member_id
-
-        def __read_conf_file(self):
-            """
-            Reads and stores the agent's configuration file
-            :return: void
-            """
-
-            conf_file_path = os.path.abspath(os.path.dirname(__file__)).split("modules")[0] + "agent.conf"
-            self.log.debug("Config file path : %r" % conf_file_path)
-            self.properties = ConfigParser.SafeConfigParser()
-            self.properties.read(conf_file_path)
-
-        def __read_parameter_file(self):
-            """
-            Reads the payload file of the cartridge and stores the values in a dictionary
-            :return: void
-            """
-
-            param_file = self.read_property(cartridgeagentconstants.PARAM_FILE_PATH, False)
-            self.log.debug("Param file path : %r" % param_file)
-
-            try:
-                if param_file is not None:
-                    metadata_file = open(param_file)
-                    metadata_payload_content = metadata_file.read()
-                    for param in metadata_payload_content.split(","):
-                        if param.strip() != "":
-                            param_value = param.strip().split("=")
-                            self.payload_params[param_value[0]] = param_value[1]
-
-                    # self.payload_params = dict(
-                    #     param.split("=") for param in metadata_payload_content.split(","))
-                    metadata_file.close()
-                else:
-                    self.log.error("File not found: %r" % param_file)
-            except:
-                self.log.exception(
-                    "Could not read launch parameter file, hence trying to read from System properties.")
-
-        def read_property(self, property_key, critical=True):
-            """
-            Returns the value of the provided property
-            :param str property_key: the name of the property to be read
-            :return: Value of the property,
-            :rtype: str
-            :exception: ParameterNotFoundException if the provided property cannot be found
-            """
-
-            if self.properties.has_option("agent", property_key):
-                self.log.debug("Has key: %r" % property_key)
-                temp_str = self.properties.get("agent", property_key)
-                if temp_str != "" and temp_str is not None:
-                    if str(temp_str).strip().lower() == "null":
-                        return ""
-                    else:
-                        return str(temp_str).strip()
-
-            if property_key in self.payload_params:
-                temp_str = self.payload_params[property_key]
-                if temp_str != "" and temp_str is not None:
-                    if str(temp_str).strip().lower() == "null":
-                        return ""
-                    else:
-                        return str(temp_str).strip()
-
-            if critical:
-                raise ParameterNotFoundException("Cannot find the value of required parameter: %r" % property_key)
-
-    instance = None
-    """ :type : __CartridgeAgentConfiguration"""
-
-    # def __new__(cls, *args, **kwargs):
-    #     if not CartridgeAgentConfiguration.instance:
-    #         CartridgeAgentConfiguration.instance = CartridgeAgentConfiguration.__CartridgeAgentConfiguration()
-    #
-    #     return CartridgeAgentConfiguration.instance
-
-    def __init__(self):
-        if not CartridgeAgentConfiguration.instance:
-            CartridgeAgentConfiguration.instance = CartridgeAgentConfiguration.__CartridgeAgentConfiguration()
-
-    def __getattr__(self, name):
-        return getattr(self.instance, name)
-
-    def __setattr__(self, name, value):
-        return setattr(self.instance, name, value)
-
-
-from ..exception.parameternotfoundexception import ParameterNotFoundException
-from ..util import cartridgeagentconstants

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/__init__.py
+++ /dev/null
@@ -1,17 +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.
-


[49/50] [abbrv] git commit: Fixed wrongly formatted event fired to CEP after 60 minutes Renamed test folder to tests for consistency

Posted by im...@apache.org.
Fixed wrongly formatted event fired to CEP after 60 minutes
Renamed test folder to tests for consistency


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

Branch: refs/heads/master
Commit: 75cb99421a2efc5067140c626893ca6ecf804a31
Parents: c76076e
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Mon Oct 27 17:55:37 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Mon Oct 27 17:55:37 2014 +0530

----------------------------------------------------------------------
 .../cartridgeagent/agent.py                     |   6 +
 .../cartridgeagent/modules/databridge/agent.py  |  32 +++--
 tools/python_cartridgeagent/test/__init__.py    |  16 ---
 tools/python_cartridgeagent/test/asynctest.txt  |   1 -
 tools/python_cartridgeagent/test/test_util.py   | 133 -------------------
 tools/python_cartridgeagent/tests/__init__.py   |  16 +++
 tools/python_cartridgeagent/tests/asynctest.txt |   1 +
 tools/python_cartridgeagent/tests/test_util.py  | 133 +++++++++++++++++++
 8 files changed, 178 insertions(+), 160 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/75cb9942/tools/python_cartridgeagent/cartridgeagent/agent.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/agent.py b/tools/python_cartridgeagent/cartridgeagent/agent.py
index 9f1a972..4336990 100644
--- a/tools/python_cartridgeagent/cartridgeagent/agent.py
+++ b/tools/python_cartridgeagent/cartridgeagent/agent.py
@@ -17,6 +17,7 @@
 # under the License.
 
 import threading
+import sys
 
 from modules.exception.parameternotfoundexception import ParameterNotFoundException
 from modules.subscriber import eventsubscriber
@@ -327,7 +328,12 @@ class CartridgeAgent(threading.Thread):
             self.log.exception("Error processing tenant unSubscribed event")
 
 
+def uncaught_exception_mg(exctype, value, tb):
+    log = LogFactory().get_log(__name__)
+    log.exception("UNCAUGHT EXCEPTION:", value)
+
 def main():
+    sys.excepthook = uncaught_exception_mg
     cartridge_agent = CartridgeAgent()
     log = LogFactory().get_log(__name__)
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/75cb9942/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
index 5d341dd..96762f2 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
@@ -156,25 +156,37 @@ class ThriftPublisher:
         :param ThriftEvent event: The log event to be published
         :return: void
         """
-        event_bundler = EventBundle()
-        event_bundler.addStringAttribute(self.stream_id)
-        event_bundler.addLongAttribute(time.time() * 1000)
-        ThriftPublisher.assign_attributes(event.metaData, event_bundler)
-        ThriftPublisher.assign_attributes(event.correlationData, event_bundler)
-        ThriftPublisher.assign_attributes(event.payloadData, event_bundler)
+
+        event_bundle = self.create_event_bundle(event)
 
         try:
-            self.__publisher.publish(event_bundler)
+            self.__publisher.publish(event_bundle)
         except ThriftSessionExpiredException as ex:
             self.log.debug("ThriftSession expired. Reconnecting")
             self.__publisher.connect(self.username, self.password)
-            self.__publisher.defineStream(str(self.stream_definition))
-            self.stream_id = self.__publisher.streamId
             self.log.debug("connected! stream ID: %r" % self.stream_id)
-            self.__publisher.publish(event_bundler)
+
+            self.publish(event)
 
         self.log.debug("Published event to thrift stream [%r]" % self.stream_id)
 
+    def create_event_bundle(self, event):
+        """
+        Creates an EventBundle object to be published to the Thrift stream
+
+        :param ThriftEvent event:
+        :return: EventBundle event bundle object
+        """
+
+        event_bundle = EventBundle()
+        event_bundle.addStringAttribute(self.stream_id)
+        event_bundle.addLongAttribute(time.time() * 1000)
+        ThriftPublisher.assign_attributes(event.metaData, event_bundle)
+        ThriftPublisher.assign_attributes(event.correlationData, event_bundle)
+        ThriftPublisher.assign_attributes(event.payloadData, event_bundle)
+
+        return event_bundle
+
     def disconnect(self):
         """
         Disconnect the thrift publisher

http://git-wip-us.apache.org/repos/asf/stratos/blob/75cb9942/tools/python_cartridgeagent/test/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/__init__.py b/tools/python_cartridgeagent/test/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python_cartridgeagent/test/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/75cb9942/tools/python_cartridgeagent/test/asynctest.txt
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/asynctest.txt b/tools/python_cartridgeagent/test/asynctest.txt
deleted file mode 100644
index b676e7d..0000000
--- a/tools/python_cartridgeagent/test/asynctest.txt
+++ /dev/null
@@ -1 +0,0 @@
-1414239655582.5959
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/75cb9942/tools/python_cartridgeagent/test/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/test_util.py b/tools/python_cartridgeagent/test/test_util.py
deleted file mode 100644
index 63c0cc7..0000000
--- a/tools/python_cartridgeagent/test/test_util.py
+++ /dev/null
@@ -1,133 +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.
-
-from ..cartridgeagent.modules.util.asyncscheduledtask import *
-from ..cartridgeagent.modules.util import cartridgeagentutils
-import time
-import socket
-from threading import Thread
-
-ASYNC_WRITE_FILE = "asynctest.txt"
-
-
-def test_async_task():
-    with open(ASYNC_WRITE_FILE, "r") as f:
-        init_context = f.read()
-
-    test_task = TestTask()
-    astask = ScheduledExecutor(1, test_task)
-    start_time = time.time() * 1000
-    astask.start()
-    contents_changed = False
-    timeout = 10  #seconds
-
-    # wait till file content is written
-    while not contents_changed and (time.time() * 1000 - start_time) < (10 * 1000):
-        time.sleep(2)
-        with open(ASYNC_WRITE_FILE, "r") as f:
-            now_content = f.read()
-
-        if init_context != now_content:
-            contents_changed = True
-
-    astask.terminate()
-    f = open(ASYNC_WRITE_FILE, "r")
-    end_time = float(f.read())
-    assert (end_time - start_time) >= 1 * 1000, "Task was executed before specified delay"
-
-
-class TestTask(AbstractAsyncScheduledTask):
-
-    def execute_task(self):
-        with open(ASYNC_WRITE_FILE, "w") as f:
-            f.seek(0)
-            f.truncate()
-            f.write("%1.4f" % (time.time()*1000))
-
-
-def test_decrypt_password_success():
-    # def mockgetlog(path):
-    #     return mocklog
-    #
-    # monkeypatch.delattr("LogFactory().get_log")
-    # TODO: enable logging in cartridgeagentutils
-
-    plain_password = "plaintext"
-    secret_key = "tvnw63ufg9gh5111"
-    encrypted_password= "jP1lZ5xMlpLzu8MbY2Porg=="
-
-    decrypted_password = cartridgeagentutils.decrypt_password(encrypted_password, secret_key)
-    #print decrypted_password
-
-    assert decrypted_password == plain_password, "Password decryption failed"
-
-
-def test_decrypt_password_failure():
-    plain_password = "plaintext"
-    secret_key = "notsecretkeyhere"
-    encrypted_password= "jP1lZ5xMlpLzu8MbY2Porg=="
-    assert cartridgeagentutils.decrypt_password(encrypted_password, secret_key) != plain_password, "Password decrypted for wrong key"
-
-
-def test_create_dir_normal():
-    assert True
-
-
-def test_create_dir_system_path():
-    assert True
-
-
-def test_create_dir_existing_dir():
-    assert True
-
-
-def test_wait_for_ports_activity_normal():
-    portnumber = 12345
-    listener = PortListener(portnumber)
-    listener.start()
-
-    assert cartridgeagentutils.check_ports_active(socket.gethostbyname(socket.gethostname()), [str(portnumber)])
-
-
-class PortListener(Thread):
-
-    def __init__(self, portnumber):
-        Thread.__init__(self)
-        self.portnumber = portnumber
-        self.terminated = False
-
-    def run(self):
-        s = socket.socket()
-        host = socket.gethostname()
-
-        s.bind((host, self.portnumber))
-        s.listen(5)
-
-        #while not self.terminated:
-        c, addr = s.accept()     # Establish connection with client.
-        #print 'Got connection from', addr
-        c.send('Thank you for connecting')
-        c.close()
-
-        s.close()
-
-    def terminate(self):
-        self.terminated = True
-
-
-def test_wait_for_ports_activity_non_existent():
-    assert cartridgeagentutils.check_ports_active(socket.gethostbyname(socket.gethostname()), [str(34565)]) == False

http://git-wip-us.apache.org/repos/asf/stratos/blob/75cb9942/tools/python_cartridgeagent/tests/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/tests/__init__.py b/tools/python_cartridgeagent/tests/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/tests/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/75cb9942/tools/python_cartridgeagent/tests/asynctest.txt
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/tests/asynctest.txt b/tools/python_cartridgeagent/tests/asynctest.txt
new file mode 100644
index 0000000..b676e7d
--- /dev/null
+++ b/tools/python_cartridgeagent/tests/asynctest.txt
@@ -0,0 +1 @@
+1414239655582.5959
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/75cb9942/tools/python_cartridgeagent/tests/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/tests/test_util.py b/tools/python_cartridgeagent/tests/test_util.py
new file mode 100644
index 0000000..63c0cc7
--- /dev/null
+++ b/tools/python_cartridgeagent/tests/test_util.py
@@ -0,0 +1,133 @@
+# 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.
+
+from ..cartridgeagent.modules.util.asyncscheduledtask import *
+from ..cartridgeagent.modules.util import cartridgeagentutils
+import time
+import socket
+from threading import Thread
+
+ASYNC_WRITE_FILE = "asynctest.txt"
+
+
+def test_async_task():
+    with open(ASYNC_WRITE_FILE, "r") as f:
+        init_context = f.read()
+
+    test_task = TestTask()
+    astask = ScheduledExecutor(1, test_task)
+    start_time = time.time() * 1000
+    astask.start()
+    contents_changed = False
+    timeout = 10  #seconds
+
+    # wait till file content is written
+    while not contents_changed and (time.time() * 1000 - start_time) < (10 * 1000):
+        time.sleep(2)
+        with open(ASYNC_WRITE_FILE, "r") as f:
+            now_content = f.read()
+
+        if init_context != now_content:
+            contents_changed = True
+
+    astask.terminate()
+    f = open(ASYNC_WRITE_FILE, "r")
+    end_time = float(f.read())
+    assert (end_time - start_time) >= 1 * 1000, "Task was executed before specified delay"
+
+
+class TestTask(AbstractAsyncScheduledTask):
+
+    def execute_task(self):
+        with open(ASYNC_WRITE_FILE, "w") as f:
+            f.seek(0)
+            f.truncate()
+            f.write("%1.4f" % (time.time()*1000))
+
+
+def test_decrypt_password_success():
+    # def mockgetlog(path):
+    #     return mocklog
+    #
+    # monkeypatch.delattr("LogFactory().get_log")
+    # TODO: enable logging in cartridgeagentutils
+
+    plain_password = "plaintext"
+    secret_key = "tvnw63ufg9gh5111"
+    encrypted_password= "jP1lZ5xMlpLzu8MbY2Porg=="
+
+    decrypted_password = cartridgeagentutils.decrypt_password(encrypted_password, secret_key)
+    #print decrypted_password
+
+    assert decrypted_password == plain_password, "Password decryption failed"
+
+
+def test_decrypt_password_failure():
+    plain_password = "plaintext"
+    secret_key = "notsecretkeyhere"
+    encrypted_password= "jP1lZ5xMlpLzu8MbY2Porg=="
+    assert cartridgeagentutils.decrypt_password(encrypted_password, secret_key) != plain_password, "Password decrypted for wrong key"
+
+
+def test_create_dir_normal():
+    assert True
+
+
+def test_create_dir_system_path():
+    assert True
+
+
+def test_create_dir_existing_dir():
+    assert True
+
+
+def test_wait_for_ports_activity_normal():
+    portnumber = 12345
+    listener = PortListener(portnumber)
+    listener.start()
+
+    assert cartridgeagentutils.check_ports_active(socket.gethostbyname(socket.gethostname()), [str(portnumber)])
+
+
+class PortListener(Thread):
+
+    def __init__(self, portnumber):
+        Thread.__init__(self)
+        self.portnumber = portnumber
+        self.terminated = False
+
+    def run(self):
+        s = socket.socket()
+        host = socket.gethostname()
+
+        s.bind((host, self.portnumber))
+        s.listen(5)
+
+        #while not self.terminated:
+        c, addr = s.accept()     # Establish connection with client.
+        #print 'Got connection from', addr
+        c.send('Thank you for connecting')
+        c.close()
+
+        s.close()
+
+    def terminate(self):
+        self.terminated = True
+
+
+def test_wait_for_ports_activity_non_existent():
+    assert cartridgeagentutils.check_ports_active(socket.gethostbyname(socket.gethostname()), [str(34565)]) == False


[46/50] [abbrv] git commit: Fixed issues in git commit with username password auth Added initial methods for git handling with popen and pexpect

Posted by im...@apache.org.
Fixed issues in git commit with username password auth
Added initial methods for git handling with popen and pexpect


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

Branch: refs/heads/master
Commit: 9a4e3a845b582ef0f0982d0de4b282f685d83750
Parents: 514a7e3
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Sat Oct 25 04:04:11 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Sat Oct 25 04:04:11 2014 +0530

----------------------------------------------------------------------
 .../modules/artifactmgt/git/agentgithandler.py  | 115 ++++++++++++++-----
 .../extensions/defaultextensionhandler.py       |   2 +-
 .../modules/util/extensionutils.py              |   2 +-
 .../cartridgeagent/testgit.py                   |   2 +-
 4 files changed, 91 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/9a4e3a84/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
index d6381a0..d5d085c 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
@@ -20,6 +20,8 @@ from git import *
 from gittle import Gittle, GittleAuth  # GitPython and Gittle are both used at the time being for pros and cons of both
 import urllib2
 import os
+import pexpect
+import subprocess
 
 from ... util.log import LogFactory
 from ... util import cartridgeagentutils, extensionutils, cartridgeagentconstants
@@ -205,6 +207,7 @@ class AgentGitHandler:
             if not os.path.isdir(repo_context.local_repo_path):
                 cartridgeagentutils.create_dir(repo_context.local_repo_path)
 
+            #TODO: remove gittle stuff
             auth = AgentGitHandler.create_auth_configuration(repo_context)
 
             if auth is not None:
@@ -396,52 +399,90 @@ class AgentGitHandler:
         """
         tenant_id = repo_info.tenant_id
         repo_context = AgentGitHandler.get_repo_context(tenant_id)
-        gittle_repo = repo_context.gittle_repo
-        try:
-            modified = True if gittle_repo.modified_unstaged_files.count > 0 else False
-        except OSError:
-            # removed files
-            modified = True
+        #check if modified
+        modified, unstaged_files = AgentGitHandler.get_unstaged_files(repo_context.local_repo_path)
+
+        AgentGitHandler.log.debug("Modified: %r" % str(modified))
 
         if not modified:
             AgentGitHandler.log.debug("No changes detected in the local repository for tenant " + tenant_id)
             return
 
-        gittle_repo.stage(gittle_repo.untracked_files)
-        gittle_repo.stage(gittle_repo.removed_files)
-        gittle_repo.stage(gittle_repo.modified_unstaged_files)
+        AgentGitHandler.stage_all(repo_context.local_repo_path)
 
         #commit to local repositpory
         commit_message = "tenant " + tenant_id + "'s artifacts committed to local repo at " + repo_context.local_repo_path
-
-        try:
-            commit_hash = gittle_repo.commit(name="First Author", email="author@example.org", message=commit_message)
+        commit_name="First Author"
+        commit_email="author@example.org"
+        #git config
+        (output, errors) = AgentGitHandler.execute_git_command(["config", "user.email", commit_email], repo_context.local_repo_path)
+        (output, errors) = AgentGitHandler.execute_git_command(["config", "user.name", commit_name], repo_context.local_repo_path)
+
+        #commit
+        (output, errors) = AgentGitHandler.execute_git_command(["commit", "-m", commit_message], repo_context.local_repo_path)
+        if errors.strip() == "":
+            commit_hash = AgentGitHandler.find_between(output, "[master", "]").strip()
             AgentGitHandler.log.debug("Committed artifacts for tenant : " + tenant_id + " : " + commit_hash)
-        except:
+        else:
             AgentGitHandler.log.exception("Committing artifacts to local repository failed for tenant " + tenant_id)
 
         #push to remote
         try:
-            repo = repo_context.repo
             #TODO: check key based authentication
-            credentialed_remote_url = AgentGitHandler.get_credentialed_remote_url(repo_context)
-            push_remote = repo.create_remote('push_remote', credentialed_remote_url)
-            push_remote.push()
+
+            push_op = pexpect.spawn('git push origin master', cwd=repo_context.local_repo_path)
+            #push_op.logfile = sys.stdout
+            push_op.expect("Username for .*")
+            push_op.sendline(repo_context.repo_username)
+            push_op.expect("Password for .*")
+            push_op.sendline(repo_context.repo_password)
+            # result = push_op.expect([commit_hash + "  master -> master", "Authentication failed for"])
+            # if result != 0:
+            #     raise Exception
+            #TODO: handle push failure scenarios
+            push_op.interact()
+
             AgentGitHandler.log.debug("Pushed artifacts for tenant : " + tenant_id)
         except:
             AgentGitHandler.log.exception("Pushing artifacts to remote repository failed for tenant " + tenant_id)
 
     @staticmethod
-    def get_credentialed_remote_url(repo_context):
-        """
-        Creates a remote url including the credentials
-        :param repo_context:
-        :return:
-        """
-        username = repo_context.repo_username
-        password = repo_context.repo_password
+    def get_unstaged_files(repo_path):
+
+        (output, errors) = AgentGitHandler.execute_git_command(["status"], repo_path=repo_path)
+        unstaged_files = {"modified":[], "untracked":[]}
+
+        if "nothing to commit" in output:
+            return False, unstaged_files
 
-        raise NotImplementedError
+        if "Changes not staged for commit" in output:
+            #there are modified files
+            modified_lines = output.split("\n\n")[2].split("\n")
+            for mod_line in modified_lines:
+                file_name = mod_line.split(":")[1].strip()
+                unstaged_files["modified"].append(file_name)
+
+        if "Untracked files" in output:
+            #there are untracked files
+            untracked_files = output.split("Untracked files:")[1].split("\n\n")[1].split("\n")
+            for unt_line in untracked_files:
+                unstaged_files["untracked"].append(unt_line.strip())
+
+        return True, unstaged_files
+
+    @staticmethod
+    def stage_all(repo_path):
+        (output, errors) = AgentGitHandler.execute_git_command(["add", "--all"], repo_path=repo_path)
+        return True if errors.strip() == "" else False
+
+    @staticmethod
+    def find_between( s, first, last ):
+        try:
+            start = s.index( first ) + len( first )
+            end = s.index( last, start )
+            return s[start:end]
+        except ValueError:
+            return ""
 
     @staticmethod
     def schedule_artifact_update_scheduled_task(repo_info, auto_checkout, auto_commit, update_interval):
@@ -452,7 +493,6 @@ class AgentGitHandler:
             return
 
         if repo_context.scheduled_update_task is None:
-            #TODO: make thread safe
             artifact_update_task = ArtifactUpdateTask(repo_info, auto_checkout, auto_commit)
             async_task = ScheduledExecutor(update_interval, artifact_update_task)
 
@@ -485,6 +525,27 @@ class AgentGitHandler:
 
         return True
 
+    @staticmethod
+    def execute_git_command(command, repo_path):
+        """
+        Executes the given command string with given environment parameters
+        :param list command: Command with arguments to be executed
+        :param dict[str, str] env_params: Environment variables to be used
+        :return: output and error string tuple, RuntimeError if errors occur
+        :rtype: tuple(str, str)
+        :exception: RuntimeError
+        """
+        os_env = os.environ.copy()
+
+        command.insert(0, "/usr/bin/git")
+        p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os_env, cwd=repo_path)
+        output, errors = p.communicate()
+        if len(errors) > 0:
+            raise RuntimeError("Git Command execution failed: \n %r" % errors)
+
+        return output, errors
+
+
 
 class ArtifactUpdateTask(AbstractAsyncScheduledTask):
     """

http://git-wip-us.apache.org/repos/asf/stratos/blob/9a4e3a84/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py b/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
index 07107da..bbbc100 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
@@ -100,7 +100,7 @@ class DefaultExtensionHandler(AbstractExtensionHandler):
 
                 try:
                     update_interval = int(
-                        self.cartridge_agent_config.read_property(cartridgeagentconstants.ARTIFACT_UPDATE_INTERVAL, False))
+                        self.cartridge_agent_config.read_property(cartridgeagentconstants.ARTIFACT_UPDATE_INTERVAL))
                 except ParameterNotFoundException:
                     self.log.exception("Invalid artifact sync interval specified ")
                     update_interval = 10

http://git-wip-us.apache.org/repos/asf/stratos/blob/9a4e3a84/tools/python_cartridgeagent/cartridgeagent/modules/util/extensionutils.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/util/extensionutils.py b/tools/python_cartridgeagent/cartridgeagent/modules/util/extensionutils.py
index 6c58852..22639d3 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/util/extensionutils.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/util/extensionutils.py
@@ -468,7 +468,7 @@ def get_lb_member_ip(lb_cluster_id):
     return None
 
 
-def execute_command(command, env_params=None):
+def execute_command(command, env_params=None, cwd=None):
     """
     Executes the given command string with given environment parameters
     :param str command: Command with arguments to be executed

http://git-wip-us.apache.org/repos/asf/stratos/blob/9a4e3a84/tools/python_cartridgeagent/cartridgeagent/testgit.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/testgit.py b/tools/python_cartridgeagent/cartridgeagent/testgit.py
index c683b56..0b38f83 100644
--- a/tools/python_cartridgeagent/cartridgeagent/testgit.py
+++ b/tools/python_cartridgeagent/cartridgeagent/testgit.py
@@ -19,7 +19,7 @@
 from modules.extensions.defaultextensionhandler import *
 from modules.event.instance.notifier.events import ArtifactUpdatedEvent
 
-event_msg = '{"clusterId":"php.php.domain","repoPassword":"","repoURL":"https://github.com/chamilad/NeWoice","tenantId":"-1234","commitEnabled":false}'
+event_msg = '{"clusterId":"newoice.php.domain","repoUserName":"chamilad","repoPassword":"eng3lhimm3lsonn3","repoURL":"https://github.com/chamilad/NeWoice","tenantId":"-1234","commitEnabled":false}'
 event = ArtifactUpdatedEvent.create_from_json(event_msg)
 
 extension_handler = DefaultExtensionHandler()


[42/50] [abbrv] git commit: Completed ports check tests Improved AsyncTask test

Posted by im...@apache.org.
Completed ports check tests
Improved AsyncTask test


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

Branch: refs/heads/master
Commit: cd97e69466c8cf7ae5dc58e7034eb385839ac1bb
Parents: ebf9e0b
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Tue Oct 21 15:35:02 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Tue Oct 21 15:35:02 2014 +0530

----------------------------------------------------------------------
 tools/python_cartridgeagent/test/asynctest.txt |  2 +-
 tools/python_cartridgeagent/test/test_util.py  | 65 ++++++++++++++++++---
 2 files changed, 58 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/cd97e694/tools/python_cartridgeagent/test/asynctest.txt
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/asynctest.txt b/tools/python_cartridgeagent/test/asynctest.txt
index 4032a53..75eddf2 100644
--- a/tools/python_cartridgeagent/test/asynctest.txt
+++ b/tools/python_cartridgeagent/test/asynctest.txt
@@ -1 +1 @@
-1413834107419.9700
\ No newline at end of file
+1413885854235.2659
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/cd97e694/tools/python_cartridgeagent/test/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/test_util.py b/tools/python_cartridgeagent/test/test_util.py
index 2b4186e..e7c42ac 100644
--- a/tools/python_cartridgeagent/test/test_util.py
+++ b/tools/python_cartridgeagent/test/test_util.py
@@ -18,16 +18,34 @@
 from ..cartridgeagent.modules.util.asyncscheduledtask import *
 from ..cartridgeagent.modules.util import cartridgeagentutils
 import time
+import socket
+from threading import Thread
+
+ASYNC_WRITE_FILE = "asynctest.txt"
 
 
 def test_async_task():
+    with open(ASYNC_WRITE_FILE, "r") as f:
+        init_context = f.read()
+
     test_task = TestTask()
     astask = ScheduledExecutor(1, test_task)
     start_time = time.time() * 1000
     astask.start()
-    time.sleep(2)
+    contents_changed = False
+    timeout = 10  #seconds
+
+    # wait till file content is written
+    while not contents_changed and (time.time() * 1000 - start_time) < (10 * 1000):
+        time.sleep(2)
+        with open(ASYNC_WRITE_FILE, "r") as f:
+            now_content = f.read()
+
+        if init_context != now_content:
+            contents_changed = True
+
     astask.terminate()
-    f = open("asynctest.txt", "r")
+    f = open(ASYNC_WRITE_FILE, "r")
     end_time = float(f.read())
     assert (end_time - start_time) >= 1 * 1000, "Task was executed before specified delay"
 
@@ -35,7 +53,7 @@ def test_async_task():
 class TestTask(AbstractAsyncScheduledTask):
 
     def execute_task(self):
-        with open("asynctest.txt", "w") as f:
+        with open(ASYNC_WRITE_FILE, "w") as f:
             f.seek(0)
             f.truncate()
             f.write("%1.4f" % (time.time()*1000))
@@ -65,17 +83,48 @@ def test_decrypt_password_failure():
 def test_create_dir_normal():
     assert True
 
+
 def test_create_dir_system_path():
     assert True
 
+
 def test_create_dir_existing_dir():
     assert True
 
+
 def test_wait_for_ports_activity_normal():
-    assert True
+    portnumber = 12345
+    listener = PortListener(portnumber)
+    listener.start()
 
-def test_wait_for_ports_activity_non_existent():
-    assert True
+    assert cartridgeagentutils.check_ports_active(socket.gethostbyname(socket.gethostname()), [str(portnumber)])
 
-def test_wait_for_ports_activity_timeout():
-    assert True
\ No newline at end of file
+
+class PortListener(Thread):
+
+    def __init__(self, portnumber):
+        Thread.__init__(self)
+        self.portnumber = portnumber
+        self.terminated = False
+
+    def run(self):
+        s = socket.socket()
+        host = socket.gethostname()
+
+        s.bind((host, self.portnumber))
+        s.listen(5)
+
+        #while not self.terminated:
+        c, addr = s.accept()     # Establish connection with client.
+        #print 'Got connection from', addr
+        c.send('Thank you for connecting')
+        c.close()
+
+        s.close()
+
+    def terminate(self):
+        self.terminated = True
+
+
+def test_wait_for_ports_activity_non_existent():
+    assert cartridgeagentutils.check_ports_active(socket.gethostbyname(socket.gethostname()), [str(34565)]) == False


[50/50] [abbrv] git commit: Merge remote-tracking branch 'upstream/master'

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


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

Branch: refs/heads/master
Commit: d82fcc5394c5677006f3de7a8ebc6a7d4265d67f
Parents: 75cb994 bfe230a
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Mon Oct 27 17:59:58 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Mon Oct 27 17:59:58 2014 +0530

----------------------------------------------------------------------
 .../autoscaler/KubernetesClusterContext.java    | 19 +++---
 .../stratos/autoscaler/PartitionContext.java    |  4 +-
 .../impl/CloudControllerServiceImpl.java        |  2 +-
 .../common/constants/StratosConstants.java      |  6 +-
 .../distribution/src/main/conf/autoscaler.xml   | 16 +++--
 .../config/all/repository/conf/autoscaler.xml   | 64 ++++++++++++++------
 6 files changed, 75 insertions(+), 36 deletions(-)
----------------------------------------------------------------------



[27/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/status/events.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/status/events.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/status/events.py
new file mode 100644
index 0000000..c000c55
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/status/events.py
@@ -0,0 +1,98 @@
+# 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.
+
+import json
+
+
+class InstanceActivatedEvent:
+    def __init__(self, service_name, cluster_id, network_partition_id, parition_id, member_id):
+        self.serviceName = service_name
+        """ :type : str  """
+        self.clusterId = cluster_id
+        """ :type : str  """
+        self.networkPartitionId = network_partition_id
+        """ :type : str  """
+        self.partitionId = parition_id
+        """ :type : str  """
+        self.memberId = member_id
+        """ :type : str  """
+
+    def to_json(self):
+        return to_json(self)
+
+
+class InstanceStartedEvent:
+    def __init__(self, service_name, cluster_id, network_partition_id, parition_id, member_id):
+        self.serviceName = service_name
+        """ :type : str  """
+        self.clusterId = cluster_id
+        """ :type : str  """
+        self.networkPartitionId = network_partition_id
+        """ :type : str  """
+        self.partitionId = parition_id
+        """ :type : str  """
+        self.memberId = member_id
+        """ :type : str  """
+
+    def to_json(self):
+        return to_json(self)
+
+
+class InstanceMaintenanceModeEvent:
+
+    def __init__(self, service_name, cluster_id, network_partition_id, partition_id, member_id):
+        self.serviceName = service_name
+        """ :type : str  """
+        self.clusterId = cluster_id
+        """ :type : str  """
+        self.networkPartitionId = network_partition_id
+        """ :type : str  """
+        self.partitionId = partition_id
+        """ :type : str  """
+        self.memberId = member_id
+        """ :type : str  """
+
+    def to_json(self):
+        return to_json(self)
+
+
+class InstanceReadyToShutdownEvent:
+
+    def __init__(self, service_name, cluster_id, network_partition_id, partition_id, member_id):
+        self.serviceName = service_name
+        """ :type : str  """
+        self.clusterId = cluster_id
+        """ :type : str  """
+        self.networkPartitionId = network_partition_id
+        """ :type : str  """
+        self.partitionId = partition_id
+        """ :type : str  """
+        self.memberId = member_id
+        """ :type : str  """
+
+    def to_json(self):
+        return to_json(self)
+
+
+def to_json(instance):
+    """
+    common function to serialize status event object
+    :param obj instance:
+    :return: serialized json string
+    :rtype str
+    """
+    return json.dumps(instance, default=lambda o: o.__dict__, sort_keys=True, indent=4)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/event/tenant/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/tenant/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/tenant/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/event/tenant/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/event/tenant/events.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/tenant/events.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/tenant/events.py
new file mode 100644
index 0000000..def2b64
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/event/tenant/events.py
@@ -0,0 +1,147 @@
+# 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.
+
+import json
+from ... tenant.tenantcontext import *
+
+
+class SubscriptionDomainAddedEvent():
+
+    def __init__(self):
+        self.tenant_id = None
+        """ :type : int  """
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_ids = None
+        """ :type : list[str]  """
+        self.domain_name = None
+        """ :type : str  """
+        self.application_context = None
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = SubscriptionDomainAddedEvent()
+
+        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
+        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.domain_name = json_obj["domainName"] if "domainName" in json_obj else None
+        instance.application_context = json_obj["applicationContext"] if "applicationContext" in json_obj else None
+
+        return instance
+
+
+class SubscriptionDomainRemovedEvent:
+
+    def __init__(self, tenant_id, service_name, cluster_ids, domain_name):
+        self.tenant_id = tenant_id
+        """ :type : int  """
+        self.service_name = service_name
+        """ :type : str  """
+        self.cluster_ids = cluster_ids
+        """ :type : list[str]  """
+        self.domain_name = domain_name
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = SubscriptionDomainRemovedEvent()
+
+        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
+        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.domain_name = json_obj["domainName"] if "domainName" in json_obj else None
+
+        return instance
+
+
+class CompleteTenantEvent:
+
+    def __init__(self):
+        self.tenants = []
+        """ :type : list[Tenant]  """
+        self.tenant_list_json = None
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = CompleteTenantEvent()
+        instance.tenants = []
+
+        tenants_str = json_obj["tenants"] if "tenants" in json_obj else None
+        instance.tenant_list_json = tenants_str
+        if tenants_str is not None:
+            for tenant_str in tenants_str:
+                tenant_obj = Tenant(int(tenant_str["tenantId"]), tenant_str["tenantDomain"])
+                for service_name in tenant_str["serviceNameSubscriptionMap"]:
+                    sub_str = tenant_str["serviceNameSubscriptionMap"][service_name]
+                    sub = Subscription(sub_str["serviceName"], sub_str["clusterIds"])
+                    for domain_name in sub_str["subscriptionDomainMap"]:
+                        subdomain_str = sub_str["subscriptionDomainMap"][domain_name]
+                        sub.add_subscription_domain(domain_name, subdomain_str["applicationContext"])
+                    tenant_obj.add_subscription(sub)
+                instance.tenants.append(tenant_obj)
+
+        return instance
+
+
+class TenantSubscribedEvent:
+
+    def __init__(self):
+        self.tenant_id = None
+        """ :type : int  """
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_ids = None
+        """ :type : list[str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = TenantSubscribedEvent()
+
+        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
+
+        return instance
+
+
+class TenantUnsubscribedEvent:
+
+    def __init__(self):
+        self.tenant_id = None
+        """ :type : int  """
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_ids = None
+        """ :type : list[str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = TenantUnsubscribedEvent()
+
+        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
+
+        return instance
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/event/topology/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/topology/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/topology/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/event/topology/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/event/topology/events.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/topology/events.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/topology/events.py
new file mode 100644
index 0000000..52c7c19
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/event/topology/events.py
@@ -0,0 +1,280 @@
+# 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.
+
+import json
+
+from ... topology.topologycontext import *
+
+
+class MemberActivatedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+        self.port_map = {}
+        """ :type : dict[str, Port]  """
+        self.member_ip = None
+        """ :type : str  """
+
+    def get_port(self, proxy_port):
+        """
+        Returns the port object of the provided port id
+        :param str proxy_port:
+        :return: Port object, None if the port id is invalid
+        :rtype: topology.topologycontext.Port
+        """
+        if proxy_port in self.port_map:
+            return self.port_map[proxy_port]
+
+        return None
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = MemberActivatedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        #instance.port_map = json_obj["portMap"] if "portMap" in json_obj else {}
+        instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None
+
+        for port_proxy in json_obj["portMap"]:
+            port_str = json_obj["portMap"][port_proxy]
+            port_obj = Port(port_str["protocol"], port_str["value"], port_proxy)
+            instance.port_map[port_proxy] = port_obj
+
+        return instance
+
+
+class MemberTerminatedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = MemberTerminatedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        instance.properties = json_obj["properties"] if "properties" in json_obj else None
+
+        return instance
+
+
+class MemberSuspendedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = MemberSuspendedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+
+        return instance
+
+
+class CompleteTopologyEvent:
+
+    def __init__(self):
+        self.topology = None
+        """ :type :  Topology """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = CompleteTopologyEvent()
+
+        topology_str = json_obj["topology"] if "topology" in json_obj else None
+        if topology_str is not None:
+            topology_obj = Topology()
+            topology_obj.json_str = topology_str
+
+            #add service map
+            for service_name in topology_str["serviceMap"]:
+                service_str = topology_str["serviceMap"][service_name]
+
+                service_obj = Service(service_name, service_str["serviceType"])
+                service_obj.properties = service_str["properties"]
+                # add ports to port map
+                for port_proxy in service_str["portMap"]:
+                    port_str = service_str["portMap"][port_proxy]
+                    port_obj = Port(port_str["protocol"], port_str["value"], port_proxy)
+                    service_obj.add_port(port_obj)
+
+                #add cluster map
+                for cluster_id in service_str["clusterIdClusterMap"]:
+                    cluster_str = service_str["clusterIdClusterMap"][cluster_id]
+                    cl_service_name = cluster_str["serviceName"]
+                    cl_autoscale_policy_name = cluster_str["autoscalePolicyName"]
+                    cl_deployment_policy_name = cluster_str["deploymentPolicyName"] if "deploymentPolicyName" in cluster_str else None
+
+                    cluster_obj = Cluster(cl_service_name, cluster_id, cl_deployment_policy_name, cl_autoscale_policy_name)
+                    cluster_obj.hostnames = cluster_str["hostNames"]
+                    cluster_obj.tenant_range = cluster_str["tenantRange"] if "tenantRange" in cluster_str else None
+                    cluster_obj.is_lb_cluster = cluster_str["isLbCluster"]
+                    cluster_obj.is_kubernetes_cluster = cluster_str["isKubernetesCluster"]
+                    cluster_obj.status = cluster_str["status"]
+                    cluster_obj.load_balancer_algorithm_name = cluster_str["loadBalanceAlgorithmName"] if "loadBalanceAlgorithmName" in cluster_str else None
+                    cluster_obj.properties = cluster_str["properties"]
+                    cluster_obj.member_list_json = cluster_str["memberMap"]
+
+                    #add member map
+                    for member_id in cluster_str["memberMap"]:
+                        member_str = cluster_str["memberMap"][member_id]
+                        mm_service_name = member_str["serviceName"]
+                        mm_cluster_id = member_str["clusterId"]
+                        mm_network_partition_id = member_str["networkPartitionId"] if "networkPartitionId" in member_str else None
+                        mm_partition_id = member_str["partitionId"] if "partitionId" in member_str else None
+
+                        member_obj = Member(mm_service_name, mm_cluster_id, mm_network_partition_id, mm_partition_id, member_id)
+                        member_obj.member_public_ip = member_str["memberPublicIp"]
+                        member_obj.status = member_str["status"]
+                        member_obj.member_ip = member_str["memberIp"]
+                        member_obj.properties = member_str["properties"]
+                        member_obj.lb_cluster_id = member_str["lbClusterId"] if "lbClusterId" in member_str else None
+                        member_obj.json_str = member_str
+
+                        #add port map
+                        for mm_port_proxy in member_str["portMap"]:
+                            mm_port_str = member_str["portMap"][mm_port_proxy]
+                            mm_port_obj = Port(mm_port_str["protocol"], mm_port_str["value"], mm_port_proxy)
+                            member_obj.add_port(mm_port_obj)
+                        cluster_obj.add_member(member_obj)
+                    service_obj.add_cluster(cluster_obj)
+                topology_obj.add_service(service_obj)
+            instance.topology = topology_obj
+
+        return instance
+
+    def get_topology(self):
+        return self.topology
+
+
+class MemberStartedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+        self.status = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = MemberStartedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        instance.properties = json_obj["properties"] if "properties" in json_obj else None
+
+        return instance
+
+
+class InstanceSpawnedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+        self.lb_cluster_id = None
+        """ :type : str  """
+        self.member_public_ip = None
+        """ :type : str  """
+        self.member_ip = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = InstanceSpawnedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        instance.lb_cluster_id = json_obj["lbClusterId"] if "lbClusterId" in json_obj else None
+        instance.member_public_ip = json_obj["memberPublicIp"] if "memberPublicIp" in json_obj else None
+        instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None
+        instance.properties = json_obj["properties"]
+
+        return instance
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/exception/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/exception/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/exception/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py b/tools/python_cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py
new file mode 100644
index 0000000..88deafd
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py
@@ -0,0 +1,35 @@
+# 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.
+
+class ParameterNotFoundException(Exception):
+    """
+    Exception raised when a property is not present in the configuration or the payload
+    of the cartridge agent
+    """
+    __message = None
+
+    def __init__(self, message):
+        Exception.__init__(self, message)
+        self.__message = message
+
+    def get_message(self):
+        """
+        The message provided when the exception is raised
+        :return: message
+        :rtype: str
+        """
+        return self.__message

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/extensions/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/extensions/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/extensions/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/extensions/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py b/tools/python_cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py
new file mode 100644
index 0000000..1f2df10
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py
@@ -0,0 +1,78 @@
+# 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.
+
+class AbstractExtensionHandler:
+
+    def on_instance_started_event(self):
+        raise NotImplementedError
+
+    def on_instance_activated_event(self):
+        raise NotImplementedError
+
+    def on_artifact_updated_event(self, artifacts_updated_event):
+        raise NotImplementedError
+
+    def on_artifact_update_scheduler_event(self, tenant_id):
+        raise NotImplementedError
+
+    def on_instance_cleanup_cluster_event(self, instance_cleanup_cluster_event):
+        raise NotImplementedError
+
+    def on_instance_cleanup_member_event(self, instance_cleanup_member_event):
+        raise NotImplementedError
+
+    def on_member_activated_event(self, member_activated_event):
+        raise NotImplementedError
+
+    def on_complete_topology_event(self, complete_topology_event):
+        raise NotImplementedError
+
+    def on_instance_spawned_event(self, instance_spawned_event):
+        raise NotImplementedError
+
+    def on_complete_tenant_event(self, complete_tenant_event):
+        raise NotImplementedError
+
+    def on_member_terminated_event(self, member_terminated_event):
+        raise NotImplementedError
+
+    def on_member_suspended_event(self, member_suspended_event):
+        raise NotImplementedError
+
+    def on_member_started_event(self, member_started_event):
+        raise NotImplementedError
+
+    def start_server_extension(self):
+        raise NotImplementedError
+
+    def volume_mount_extension(self, persistence_mappings_payload):
+        raise NotImplementedError
+
+    def on_subscription_domain_added_event(self, subscription_domain_added_event):
+        raise NotImplementedError
+
+    def on_subscription_domain_removed_event(self, subscription_domain_removed_event):
+        raise NotImplementedError
+
+    def on_copy_artifacts_extension(self, src, des):
+        raise NotImplementedError
+
+    def on_tenant_subscribed_event(self, tenant_subscribed_event):
+            raise NotImplementedError
+
+    def on_tenant_unsubscribed_event(self, tenant_unsubscribed_event):
+            raise NotImplementedError

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py b/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
new file mode 100644
index 0000000..8a7ccc0
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
@@ -0,0 +1,789 @@
+# 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.
+
+import time
+import json
+
+from abstractextensionhandler import AbstractExtensionHandler
+from ..util import extensionutils, cartridgeagentutils
+
+
+class DefaultExtensionHandler(AbstractExtensionHandler):
+    """
+    Default implementation of the AbstractExtensionHandler
+    """
+    log = None
+
+    def __init__(self):
+        self.log = LogFactory().get_log(__name__)
+        self.wk_members = []
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+    def on_instance_started_event(self):
+        try:
+            self.log.debug("Processing instance started event...")
+            if self.cartridge_agent_config.is_multitenant:
+                artifact_source = "%r/repository/deployment/server/" % self.cartridge_agent_config.app_path
+                artifact_dest = cartridgeagentconstants.SUPERTENANT_TEMP_PATH
+                extensionutils.execute_copy_artifact_extension(artifact_source, artifact_dest)
+
+            env_params = {}
+            extensionutils.execute_instance_started_extension(env_params)
+        except:
+            self.log.exception("Error processing instance started event")
+
+    def on_instance_activated_event(self):
+        extensionutils.execute_instance_activated_extension()
+
+    def on_artifact_updated_event(self, artifacts_updated_event):
+        self.log.info("Artifact update event received: [tenant] %r [cluster] %r [status] %r" %
+                      (artifacts_updated_event.tenant_id, artifacts_updated_event.cluster_id,
+                       artifacts_updated_event.status))
+
+        cluster_id_event = str(artifacts_updated_event.cluster_id).strip()
+        cluster_id_payload = self.cartridge_agent_config.cluster_id
+        repo_url = str(artifacts_updated_event.repo_url).strip()
+
+        if (repo_url != "") and (cluster_id_payload is not None) and (cluster_id_payload == cluster_id_event):
+            local_repo_path = self.cartridge_agent_config.app_path
+
+            secret = self.cartridge_agent_config.cartridge_key
+            repo_password = cartridgeagentutils.decrypt_password(artifacts_updated_event.repo_password, secret)
+
+            repo_username = artifacts_updated_event.repo_username
+            tenant_id = artifacts_updated_event.tenant_id
+            is_multitenant = self.cartridge_agent_config.is_multitenant
+            commit_enabled = artifacts_updated_event.commit_enabled
+
+            self.log.info("Executing git checkout")
+
+            # create repo object
+            repo_info = RepositoryInformation(repo_url, repo_username, repo_password, local_repo_path, tenant_id,
+                                              is_multitenant, commit_enabled)
+
+            # checkout code
+            subscribe_run, repo_context = agentgithandler.AgentGitHandler.checkout(repo_info)
+            # repo_context = checkout_result["repo_context"]
+            # execute artifact updated extension
+            env_params = {"STRATOS_ARTIFACT_UPDATED_CLUSTER_ID": artifacts_updated_event.cluster_id,
+                          "STRATOS_ARTIFACT_UPDATED_TENANT_ID": artifacts_updated_event.tenant_id,
+                          "STRATOS_ARTIFACT_UPDATED_REPO_URL": artifacts_updated_event.repo_url,
+                          "STRATOS_ARTIFACT_UPDATED_REPO_PASSWORD": artifacts_updated_event.repo_password,
+                          "STRATOS_ARTIFACT_UPDATED_REPO_USERNAME": artifacts_updated_event.repo_username,
+                          "STRATOS_ARTIFACT_UPDATED_STATUS": artifacts_updated_event.status}
+
+            extensionutils.execute_artifacts_updated_extension(env_params)
+
+            if subscribe_run:
+                # publish instanceActivated
+                cartridgeagentpublisher.publish_instance_activated_event()
+
+            update_artifacts = self.cartridge_agent_config.read_property(cartridgeagentconstants.ENABLE_ARTIFACT_UPDATE, False)
+            update_artifacts = True if str(update_artifacts).strip().lower() == "true" else False
+            if update_artifacts:
+                auto_commit = self.cartridge_agent_config.is_commits_enabled
+                auto_checkout = self.cartridge_agent_config.is_checkout_enabled
+
+                try:
+                    update_interval = len(
+                        self.cartridge_agent_config.read_property(cartridgeagentconstants.ARTIFACT_UPDATE_INTERVAL, False))
+                except ParameterNotFoundException:
+                    self.log.exception("Invalid artifact sync interval specified ")
+                    update_interval = 10
+                except ValueError:
+                    self.log.exception("Invalid artifact sync interval specified ")
+                    update_interval = 10
+
+                self.log.info("Artifact updating task enabled, update interval: %r seconds" % update_interval)
+
+                self.log.info("Auto Commit is turned %r " % "on" if auto_commit else "off")
+                self.log.info("Auto Checkout is turned %r " % "on" if auto_checkout else "off")
+
+                agentgithandler.AgentGitHandler.schedule_artifact_update_scheduled_task(repo_info, auto_checkout, auto_commit,
+                                                                        update_interval)
+
+    def on_artifact_update_scheduler_event(self, tenant_id):
+        env_params = {"STRATOS_ARTIFACT_UPDATED_TENANT_ID": tenant_id, "STRATOS_ARTIFACT_UPDATED_SCHEDULER": True}
+
+        extensionutils.execute_artifacts_updated_extension(env_params)
+
+    def on_instance_cleanup_cluster_event(self, instance_cleanup_cluster_event):
+        self.cleanup()
+
+    def on_instance_cleanup_member_event(self, instance_cleanup_member_event):
+        self.cleanup()
+
+    def on_member_activated_event(self, member_activated_event):
+        self.log.info("Member activated event received: [service] %r [cluster] %r [member] %r"
+            % (member_activated_event.service_name, member_activated_event.cluster_id, member_activated_event.member_id))
+
+        topology_consistent = extensionutils.check_topology_consistency(
+            member_activated_event.service_name,
+            member_activated_event.cluster_id,
+            member_activated_event.member_id)
+
+        if not topology_consistent:
+            self.log.error("Topology is inconsistent...failed to execute member activated event")
+            return
+
+        topology = TopologyContext.get_topology()
+        service = topology.get_service(member_activated_event.service_name)
+        cluster = service.get_cluster(member_activated_event.cluster_id)
+        member = cluster.get_member(member_activated_event.member_id)
+        lb_cluster_id = member.lb_cluster_id
+
+        if extensionutils.is_relevant_member_event(member_activated_event.service_name,
+                                                   member_activated_event.cluster_id, lb_cluster_id):
+
+            env_params = {"STRATOS_MEMBER_ACTIVATED_MEMBER_IP": str(member_activated_event.member_ip),
+                          "STRATOS_MEMBER_ACTIVATED_MEMBER_ID": str(member_activated_event.member_id),
+                          "STRATOS_MEMBER_ACTIVATED_CLUSTER_ID": str(member_activated_event.cluster_id),
+                          "STRATOS_MEMBER_ACTIVATED_LB_CLUSTER_ID": str(lb_cluster_id),
+                          "STRATOS_MEMBER_ACTIVATED_NETWORK_PARTITION_ID": str(member_activated_event.network_partition_id),
+                          "STRATOS_MEMBER_ACTIVATED_SERVICE_NAME": str(member_activated_event.service_name)}
+
+            ports = member_activated_event.port_map.values()
+            ports_str = ""
+            for port in ports:
+                ports_str += port.protocol + "," + str(port.value) + "," + str(port.proxy) + "|"
+
+            env_params["STRATOS_MEMBER_ACTIVATED_PORTS"] = ports_str
+
+            env_params["STRATOS_MEMBER_ACTIVATED_MEMBER_LIST_JSON"] = json.dumps(cluster.member_list_json)
+
+            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
+            if member_ips is not None and len(member_ips) > 1:
+                env_params["STRATOS_MEMBER_ACTIVATED_LB_IP"] = str(member_ips[0])
+                env_params["STRATOS_MEMBER_ACTIVATED_LB_PUBLIC_IP"] = str(member_ips[1])
+
+            env_params["STRATOS_TOPOLOGY_JSON"] = json.dumps(topology.json_str)
+
+            extensionutils.add_properties(service.properties, env_params, "MEMBER_ACTIVATED_SERVICE_PROPERTY")
+            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_ACTIVATED_CLUSTER_PROPERTY")
+            extensionutils.add_properties(member.properties, env_params, "MEMBER_ACTIVATED_MEMBER_PROPERTY")
+
+            clustered = self.cartridge_agent_config.is_clustered
+
+            if member.properties is not None and cartridgeagentconstants.CLUSTERING_PRIMARY_KEY in member.properties \
+                    and member.properties[cartridgeagentconstants.CLUSTERING_PRIMARY_KEY] == "true" \
+                    and clustered is not None and clustered:
+
+                self.log.debug(" If WK member is re-spawned, update axis2.xml ")
+
+                has_wk_ip_changed = True
+                for wk_member in self.wk_members:
+                    if wk_member.member_ip == member_activated_event.member_ip:
+                        has_wk_ip_changed = False
+
+                self.log.debug(" hasWKIpChanged %r" + has_wk_ip_changed)
+
+                min_count = int(self.cartridge_agent_config.min_count)
+                is_wk_member_grp_ready = self.is_wk_member_group_ready(env_params, min_count)
+                self.log.debug("MinCount: %r" % min_count)
+                self.log.debug("is_wk_member_grp_ready : %r" % is_wk_member_grp_ready)
+
+                if has_wk_ip_changed and is_wk_member_grp_ready:
+                    self.log.debug("Setting env var STRATOS_UPDATE_WK_IP to true")
+                    env_params["STRATOS_UPDATE_WK_IP"] = "true"
+
+            self.log.debug("Setting env var STRATOS_CLUSTERING to %r" % clustered)
+            env_params["STRATOS_CLUSTERING"] = str(clustered)
+            env_params["STRATOS_WK_MEMBER_COUNT"] = str(self.cartridge_agent_config.min_count)
+
+            extensionutils.execute_member_activated_extension(env_params)
+        else:
+            self.log.debug("Member activated event is not relevant...skipping agent extension")
+
+    def on_complete_topology_event(self, complete_topology_event):
+        self.log.debug("Complete topology event received")
+
+        service_name_in_payload = self.cartridge_agent_config.service_name
+        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
+        member_id_in_payload = self.cartridge_agent_config.member_id
+
+        consistant = extensionutils.check_topology_consistency(
+            service_name_in_payload,
+            cluster_id_in_payload,
+            member_id_in_payload)
+
+        if not consistant:
+            return
+        else:
+            self.cartridge_agent_config.initialized = True
+
+        topology = complete_topology_event.get_topology()
+        service = topology.get_service(service_name_in_payload)
+        cluster = service.get_cluster(cluster_id_in_payload)
+
+        env_params = {"STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str), "STRATOS_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json)}
+
+        extensionutils.execute_complete_topology_extension(env_params)
+
+    def on_instance_spawned_event(self, instance_spawned_event):
+        self.log.debug("Instance Spawned event received")
+
+        service_name_in_payload = self.cartridge_agent_config.service_name
+        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
+        member_id_in_payload = self.cartridge_agent_config.member_id
+
+        consistant = extensionutils.check_topology_consistency(
+            service_name_in_payload,
+            cluster_id_in_payload,
+            member_id_in_payload)
+
+        if not consistant:
+            return
+        else:
+            self.cartridge_agent_config.initialized = True
+
+    def on_complete_tenant_event(self, complete_tenant_event):
+        self.log.debug("Complete tenant event received")
+
+        tenant_list_json = complete_tenant_event.tenant_list_json
+        self.log.debug("Complete tenants:" + json.dumps(tenant_list_json))
+
+        env_params = {"STRATOS_TENANT_LIST_JSON": json.dumps(tenant_list_json)}
+
+        extensionutils.execute_complete_tenant_extension(env_params)
+
+    def on_member_terminated_event(self, member_terminated_event):
+        self.log.info("Member terminated event received: [service] " + member_terminated_event.service_name +
+                      " [cluster] " + member_terminated_event.cluster_id
+                      + " [member] " + member_terminated_event.member_id)
+
+        topology_consistent = extensionutils.check_topology_consistency(
+            member_terminated_event.service_name,
+            member_terminated_event.cluster_id,
+            member_terminated_event.member_id
+        )
+
+        if not topology_consistent:
+            self.log.error("Topology is inconsistent...failed to execute member terminated event")
+            return
+
+        topology = TopologyContext.get_topology()
+        service = topology.get_service(member_terminated_event.service_name)
+        cluster = service.get_cluster(member_terminated_event.cluster_id)
+        terminated_member = cluster.get_member(member_terminated_event.member_id)
+        lb_cluster_id = cluster.get_member(member_terminated_event.member_id).lb_cluster_id
+
+        #check whether terminated member is within the same cluster, LB cluster or service group
+        if extensionutils.is_relevant_member_event(
+                member_terminated_event.service_name,
+                member_terminated_event.cluster_id,
+                lb_cluster_id):
+
+            env_params = {"STRATOS_MEMBER_TERMINATED_MEMBER_IP": terminated_member.member_ip,
+                          "STRATOS_MEMBER_TERMINATED_MEMBER_ID": member_terminated_event.member_id,
+                          "STRATOS_MEMBER_TERMINATED_CLUSTER_ID": member_terminated_event.cluster_id,
+                          "STRATOS_MEMBER_TERMINATED_LB_CLUSTER_ID": lb_cluster_id,
+                          "STRATOS_MEMBER_TERMINATED_NETWORK_PARTITION_ID": member_terminated_event.network_partition_id,
+                          "STRATOS_MEMBER_TERMINATED_SERVICE_NAME": member_terminated_event.service_name,
+                          "STRATOS_MEMBER_TERMINATED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
+                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
+
+            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
+            if member_ips is not None and len(member_ips) > 1:
+                env_params["STRATOS_MEMBER_TERMINATED_LB_IP"] = member_ips[0]
+                env_params["STRATOS_MEMBER_TERMINATED_LB_PUBLIC_IP"] = member_ips[1]
+
+            extensionutils.add_properties(service.properties, env_params, "MEMBER_TERMINATED_SERVICE_PROPERTY")
+            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_TERMINATED_CLUSTER_PROPERTY")
+            extensionutils.add_properties(terminated_member.properties, env_params, "MEMBER_TERMINATED_MEMBER_PROPERTY")
+
+            extensionutils.execute_member_terminated_extension(env_params)
+
+        else:
+            self.log.debug("Member terminated event is not relevant...skipping agent extension")
+
+    def on_member_suspended_event(self, member_suspended_event):
+        self.log.info("Member suspended event received: [service] " + member_suspended_event.service_name +
+                      " [cluster] " + member_suspended_event.cluster_id + " [member] " + member_suspended_event.member_id)
+
+        topology_consistent = extensionutils.check_topology_consistency(
+            member_suspended_event.service_name,
+            member_suspended_event.cluster_id,
+            member_suspended_event.member_id
+        )
+
+        if not topology_consistent:
+            self.log.error("Topology is inconsistent...failed to execute member suspended event")
+            return
+
+        topology = TopologyContext.get_topology()
+        service = topology.get_service(member_suspended_event.service_name)
+        cluster = service.get_cluster(member_suspended_event.cluster_id)
+        suspended_member = cluster.get_member(member_suspended_event.member_id)
+        lb_cluster_id = cluster.get_member(member_suspended_event.member_id).lb_cluster_id
+
+        #check whether suspended member is within the same cluster, LB cluster or service group
+        if extensionutils.is_relevant_member_event(
+                member_suspended_event.service_name,
+                member_suspended_event.cluster_id,
+                lb_cluster_id):
+
+            env_params = {"STRATOS_MEMBER_SUSPENDED_MEMBER_IP": member_suspended_event.member_ip,
+                          "STRATOS_MEMBER_SUSPENDED_MEMBER_ID": member_suspended_event.member_id,
+                          "STRATOS_MEMBER_SUSPENDED_CLUSTER_ID": member_suspended_event.cluster_id,
+                          "STRATOS_MEMBER_SUSPENDED_LB_CLUSTER_ID": lb_cluster_id,
+                          "STRATOS_MEMBER_SUSPENDED_NETWORK_PARTITION_ID": member_suspended_event.network_partition_id,
+                          "STRATOS_MEMBER_SUSPENDED_SERVICE_NAME": member_suspended_event.service_name,
+                          "STRATOS_MEMBER_SUSPENDED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
+                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
+
+            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
+            if member_ips is not None and len(member_ips) > 1:
+                env_params["STRATOS_MEMBER_SUSPENDED_LB_IP"] = member_ips[0]
+                env_params["STRATOS_MEMBER_SUSPENDED_LB_PUBLIC_IP"] = member_ips[1]
+
+            extensionutils.add_properties(service.properties, env_params, "MEMBER_SUSPENDED_SERVICE_PROPERTY")
+            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_SUSPENDED_CLUSTER_PROPERTY")
+            extensionutils.add_properties(suspended_member.properties, env_params, "MEMBER_SUSPENDED_MEMBER_PROPERTY")
+
+            extensionutils.execute_member_suspended_extension(env_params)
+
+        else:
+            self.log.debug("Member suspended event is not relevant...skipping agent extension")
+
+    def on_member_started_event(self, member_started_event):
+        self.log.info("Member started event received: [service] " + member_started_event.service_name +
+                      " [cluster] " + member_started_event.cluster_id + " [member] " + member_started_event.member_id)
+
+        topology_consistent = extensionutils.check_topology_consistency(
+            member_started_event.service_name,
+            member_started_event.cluster_id,
+            member_started_event.member_id
+        )
+
+        if not topology_consistent:
+            self.log.error("Topology is inconsistent...failed to execute member started event")
+            return
+
+        topology = TopologyContext.get_topology()
+        service = topology.get_service(member_started_event.service_name)
+        cluster = service.get_cluster(member_started_event.cluster_id)
+        started_member = cluster.get_member(member_started_event.member_id)
+        lb_cluster_id = cluster.get_member(member_started_event.member_id).lb_cluster_id
+
+        #check whether started member is within the same cluster, LB cluster or service group
+        if extensionutils.is_relevant_member_event(
+                member_started_event.service_name,
+                member_started_event.cluster_id,
+                lb_cluster_id):
+
+            env_params = {"STRATOS_MEMBER_STARTED_MEMBER_IP": started_member.member_ip,
+                          "STRATOS_MEMBER_STARTED_MEMBER_ID": member_started_event.member_id,
+                          "STRATOS_MEMBER_STARTED_CLUSTER_ID": member_started_event.cluster_id,
+                          "STRATOS_MEMBER_STARTED_LB_CLUSTER_ID": lb_cluster_id,
+                          "STRATOS_MEMBER_STARTED_NETWORK_PARTITION_ID": member_started_event.network_partition_id,
+                          "STRATOS_MEMBER_STARTED_SERVICE_NAME": member_started_event.service_name,
+                          "STRATOS_MEMBER_STARTED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
+                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
+
+            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
+            if member_ips is not None and len(member_ips) > 1:
+                env_params["STRATOS_MEMBER_STARTED_LB_IP"] = member_ips[0]
+                env_params["STRATOS_MEMBER_STARTED_LB_PUBLIC_IP"] = member_ips[1]
+
+            extensionutils.add_properties(service.properties, env_params, "MEMBER_STARTED_SERVICE_PROPERTY")
+            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_STARTED_CLUSTER_PROPERTY")
+            extensionutils.add_properties(started_member.properties, env_params, "MEMBER_STARTED_MEMBER_PROPERTY")
+
+            extensionutils.execute_member_started_extension(env_params)
+
+        else:
+            self.log.debug("Member started event is not relevant...skipping agent extension")
+
+    def start_server_extension(self):
+        #wait until complete topology message is received to get LB IP
+        extensionutils.wait_for_complete_topology()
+        self.log.info("[start server extension] complete topology event received")
+
+        service_name_in_payload = self.cartridge_agent_config.service_name
+        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
+        member_id_in_payload = self.cartridge_agent_config.member_id
+
+        topology_consistant = extensionutils.check_topology_consistency(service_name_in_payload, cluster_id_in_payload, member_id_in_payload)
+
+        try:
+            if not topology_consistant:
+                self.log.error("Topology is inconsistent...failed to execute start server event")
+                return
+
+            topology = TopologyContext.get_topology()
+            service = topology.get_service(service_name_in_payload)
+            cluster = service.get_cluster(cluster_id_in_payload)
+
+            # store environment variable parameters to be passed to extension shell script
+            env_params = {}
+
+            # if clustering is enabled wait until all well known members have started
+            clustering_enabled = self.cartridge_agent_config.is_clustered
+            if clustering_enabled:
+                env_params["STRATOS_CLUSTERING"] = "true"
+                env_params["STRATOS_WK_MEMBER_COUNT"] = self.cartridge_agent_config.min_count
+
+                env_params["STRATOS_PRIMARY"] = "true" if self.cartridge_agent_config.is_primary else "false"
+
+                self.wait_for_wk_members(env_params)
+                self.log.info("All well known members have started! Resuming start server extension...")
+
+            env_params["STRATOS_TOPOLOGY_JSON"] = json.dumps(topology.json_str)
+            env_params["STRATOS_MEMBER_LIST_JSON"] = json.dumps(cluster.member_list_json)
+
+            extensionutils.execute_start_servers_extension(env_params)
+
+        except:
+            self.log.exception("Error processing start servers event")
+
+    def volume_mount_extension(self, persistence_mappings_payload):
+        extensionutils.execute_volume_mount_extension(persistence_mappings_payload)
+
+    def on_subscription_domain_added_event(self, subscription_domain_added_event):
+        tenant_domain = self.find_tenant_domain(subscription_domain_added_event.tenant_id)
+        self.log.info(
+            "Subscription domain added event received: [tenant-id] " + subscription_domain_added_event.tenant_id +
+            " [tenant-domain] " + tenant_domain + " [domain-name] " + subscription_domain_added_event.domain_name +
+            " [application-context] " + subscription_domain_added_event.application_context
+        )
+
+        env_params = {"STRATOS_SUBSCRIPTION_SERVICE_NAME": subscription_domain_added_event.service_name,
+                      "STRATOS_SUBSCRIPTION_DOMAIN_NAME": subscription_domain_added_event.domain_name,
+                      "STRATOS_SUBSCRIPTION_TENANT_ID": int(subscription_domain_added_event.tenant_id),
+                      "STRATOS_SUBSCRIPTION_TENANT_DOMAIN": tenant_domain,
+                      "STRATOS_SUBSCRIPTION_APPLICATION_CONTEXT": subscription_domain_added_event.application_context}
+
+        extensionutils.execute_subscription_domain_added_extension(env_params)
+
+    def on_subscription_domain_removed_event(self, subscription_domain_removed_event):
+        tenant_domain = self.find_tenant_domain(subscription_domain_removed_event.tenant_id)
+        self.log.info(
+            "Subscription domain removed event received: [tenant-id] " + subscription_domain_removed_event.tenant_id +
+            " [tenant-domain] " + tenant_domain + " [domain-name] " + subscription_domain_removed_event.domain_name
+        )
+
+        env_params = {"STRATOS_SUBSCRIPTION_SERVICE_NAME": subscription_domain_removed_event.service_name,
+                      "STRATOS_SUBSCRIPTION_DOMAIN_NAME": subscription_domain_removed_event.domain_name,
+                      "STRATOS_SUBSCRIPTION_TENANT_ID": int(subscription_domain_removed_event.tenant_id),
+                      "STRATOS_SUBSCRIPTION_TENANT_DOMAIN": tenant_domain}
+
+        extensionutils.execute_subscription_domain_removed_extension(env_params)
+
+    def on_copy_artifacts_extension(self, src, des):
+        extensionutils.execute_copy_artifact_extension(src, des)
+
+    def on_tenant_subscribed_event(self, tenant_subscribed_event):
+        self.log.info(
+            "Tenant subscribed event received: [tenant] " + tenant_subscribed_event.tenant_id +
+            " [service] " + tenant_subscribed_event.service_name + " [cluster] " + tenant_subscribed_event.cluster_ids
+        )
+
+        extensionutils.execute_tenant_subscribed_extension({})
+
+    def on_tenant_unsubscribed_event(self, tenant_unsubscribed_event):
+        self.log.info(
+            "Tenant unsubscribed event received: [tenant] " + tenant_unsubscribed_event.tenant_id +
+            " [service] " + tenant_unsubscribed_event.service_name +
+            " [cluster] " + tenant_unsubscribed_event.cluster_ids
+        )
+
+        try:
+            if self.cartridge_agent_config.service_name == tenant_unsubscribed_event.service_name:
+                agentgithandler.AgentGitHandler.remove_repo(tenant_unsubscribed_event.tenant_id)
+        except:
+            self.log.exception("Removing git repository failed: ")
+        extensionutils.execute_tenant_unsubscribed_extension({})
+
+    def cleanup(self):
+        self.log.info("Executing cleaning up the data in the cartridge instance...")
+
+        cartridgeagentpublisher.publish_maintenance_mode_event()
+
+        extensionutils.execute_cleanup_extension()
+        self.log.info("cleaning up finished in the cartridge instance...")
+
+        self.log.info("publishing ready to shutdown event...")
+        cartridgeagentpublisher.publish_instance_ready_to_shutdown_event()
+
+    def is_wk_member_group_ready(self, env_params, min_count):
+        topology = TopologyContext.get_topology()
+        if topology is None or not topology.initialized:
+            return False
+
+        service_group_in_payload = self.cartridge_agent_config.service_group
+        if service_group_in_payload is not None:
+            env_params["STRATOS_SERVICE_GROUP"] = service_group_in_payload
+
+        # clustering logic for apimanager
+        if service_group_in_payload is not None and service_group_in_payload == "apim":
+            # handle apistore and publisher case
+            if self.cartridge_agent_config.service_name == cartridgeagentconstants.APIMANAGER_SERVICE_NAME or \
+                    self.cartridge_agent_config.service_name == cartridgeagentconstants.PUBLISHER_SERVICE_NAME:
+
+                apistore_cluster_collection = topology.get_service(cartridgeagentconstants.APIMANAGER_SERVICE_NAME)\
+                    .get_clusters()
+                publisher_cluster_collection = topology.get_service(cartridgeagentconstants.PUBLISHER_SERVICE_NAME)\
+                    .get_clusters()
+
+                apistore_member_list = []
+                for member in apistore_cluster_collection[0].get_members():
+                    if member.status == MemberStatus.Starting or member.status == MemberStatus.Activated:
+                        apistore_member_list.append(member)
+                        self.wk_members.append(member)
+
+                if len(apistore_member_list) == 0:
+                    self.log.debug("API Store members not yet created")
+                    return False
+
+                apistore_member = apistore_member_list[0]
+                env_params["STRATOS_WK_APISTORE_MEMBER_IP"] = apistore_member.member_ip
+                self.log.debug("STRATOS_WK_APISTORE_MEMBER_IP: %r" % apistore_member.member_ip)
+
+                publisher_member_list = []
+                for member in publisher_cluster_collection[0].get_members():
+                    if member.status == MemberStatus.Starting or member.status == MemberStatus.Activated:
+                        publisher_member_list.append(member)
+                        self.wk_members.append(member)
+
+                if len(publisher_member_list) == 0:
+                    self.log.debug("API Publisher members not yet created")
+
+                publisher_member = publisher_member_list[0]
+                env_params["STRATOS_WK_PUBLISHER_MEMBER_IP"] = publisher_member.member_ip
+                self.log.debug("STRATOS_WK_PUBLISHER_MEMBER_IP: %r" % publisher_member.member_ip)
+
+                return True
+
+            elif self.cartridge_agent_config.service_name == cartridgeagentconstants.GATEWAY_MGT_SERVICE_NAME or \
+                    self.cartridge_agent_config.service_name == cartridgeagentconstants.GATEWAY_SERVICE_NAME:
+
+                if self.cartridge_agent_config.deployment is not None:
+                    # check if deployment is Manager Worker separated
+                    if self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower() or \
+                            self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
+
+                        self.log.info("Deployment pattern for the node: %r" % self.cartridge_agent_config.deployment)
+                        env_params["DEPLOYMENT"] = self.cartridge_agent_config.deployment
+                        # check if WKA members of Manager Worker separated deployment is ready
+                        return self.is_manager_worker_WKA_group_ready(env_params)
+
+            elif self.cartridge_agent_config.service_name == cartridgeagentconstants.KEY_MANAGER_SERVICE_NAME:
+                return True
+
+        else:
+            if self.cartridge_agent_config.deployment is not None:
+                # check if deployment is Manager Worker separated
+                if self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower() or \
+                        self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
+
+                    self.log.info("Deployment pattern for the node: %r" % self.cartridge_agent_config.deployment)
+                    env_params["DEPLOYMENT"] = self.cartridge_agent_config.deployment
+                    # check if WKA members of Manager Worker separated deployment is ready
+                    return self.is_manager_worker_WKA_group_ready(env_params)
+
+            service_name_in_payload = self.cartridge_agent_config.service_name
+            cluster_id_in_payload = self.cartridge_agent_config.cluster_id
+            service = topology.get_service(service_name_in_payload)
+            cluster = service.get_cluster(cluster_id_in_payload)
+
+            wk_members = []
+            for member in cluster.get_members():
+                if member.properties is not None and \
+                        cartridgeagentconstants.PRIMARY in member.properties \
+                        and member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
+                        (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
+
+                    wk_members.append(member)
+                    self.wk_members.append(member)
+                    self.log.debug("Found WKA: STRATOS_WK_MEMBER_IP: " + member.member_ip)
+
+            if len(wk_members) >= min_count:
+                idx = 0
+                for member in wk_members:
+                    env_params["STRATOS_WK_MEMBER_" + idx + "_IP"] = member.member_ip
+                    self.log.debug("STRATOS_WK_MEMBER_" + idx + "_IP:" + member.member_ip)
+
+                    idx += 1
+
+                return True
+
+        return False
+
+    # generic worker manager separated clustering logic
+    def is_manager_worker_WKA_group_ready(self, env_params):
+
+        # for this, we need both manager cluster service name and worker cluster service name
+        manager_service_name = self.cartridge_agent_config.manager_service_name
+        worker_service_name = self.cartridge_agent_config.worker_service_name
+
+        # managerServiceName and workerServiceName both should not be null /empty
+        if manager_service_name is None or manager_service_name.strip() == "":
+            self.log.error("Manager service name [ " + manager_service_name + " ] is invalid")
+            return False
+
+        if worker_service_name is None or worker_service_name.strip() == "":
+            self.log.error("Worker service name [ " + worker_service_name + " ] is invalid")
+            return False
+
+        min_manager_instances_available = False
+        min_worker_instances_available = False
+
+        topology = TopologyContext.get_topology()
+        manager_service = topology.get_service(manager_service_name)
+        worker_service = topology.get_service(worker_service_name)
+
+        if manager_service is None:
+            self.log.warn("Service [ " + manager_service_name + " ] is not found")
+            return False
+
+        if worker_service is None:
+            self.log.warn("Service [ " + worker_service_name + " ] is not found")
+            return False
+
+        # manager clusters
+        manager_clusters = manager_service.get_clusters()
+        if manager_clusters is None or len(manager_clusters) == 0:
+            self.log.warn("No clusters found for service [ " + manager_service_name + " ]")
+            return False
+
+        manager_min_instance_count = 1
+        manager_min_instance_count_found = False
+
+        manager_wka_members = []
+        for member in manager_clusters[0].get_members():
+            if member.properties is not None and \
+                    cartridgeagentconstants.PRIMARY in member.properties \
+                    and member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
+                    (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
+
+                manager_wka_members.append(member)
+                self.wk_members.append(member)
+
+                # get the min instance count
+                if not manager_min_instance_count_found:
+                    manager_min_instance_count = self.get_min_instance_count_from_member(member)
+                    manager_min_instance_count_found = True
+                    self.log.info("Manager min instance count: " + manager_min_instance_count)
+
+        if len(manager_wka_members) >= manager_min_instance_count:
+            min_manager_instances_available = True
+            idx = 0
+            for member in manager_wka_members:
+                env_params["STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP"] = member.member_ip
+                self.log.debug("STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP: " + member.member_ip)
+                idx += 1
+
+            env_params["STRATOS_WK_MANAGER_MEMBER_COUNT"] = int(manager_min_instance_count)
+
+        # If all the manager members are non primary and is greate than or equal to mincount,
+        # minManagerInstancesAvailable should be true
+        all_managers_non_primary = True
+        for member in manager_clusters[0].get_members():
+            # get the min instance count
+            if not manager_min_instance_count_found:
+                manager_min_instance_count = self.get_min_instance_count_from_member(member)
+                manager_min_instance_count_found = True
+                self.log.info(
+                    "Manager min instance count when allManagersNonPrimary true : " + manager_min_instance_count)
+
+            if member.properties is not None and cartridgeagentconstants.PRIMARY in member.properties and \
+                    member.properties[cartridgeagentconstants.PRIMARY].lower() == "true":
+                all_managers_non_primary = False
+                break
+
+        self.log.debug(
+            " allManagerNonPrimary & managerMinInstanceCount [" + all_managers_non_primary +
+            "], [" + manager_min_instance_count + "] ")
+
+        if all_managers_non_primary and len(manager_clusters) >= manager_min_instance_count:
+            min_manager_instances_available = True
+
+        # worker cluster
+        worker_clusters = worker_service.get_clusters()
+        if worker_clusters is None or len(worker_clusters) == 0:
+            self.log.warn("No clusters found for service [ " + worker_service_name + " ]")
+            return False
+
+        worker_min_instance_count = 1
+        worker_min_instance_count_found = False
+
+        worker_wka_members = []
+        for member in worker_clusters[0].get_members():
+            self.log.debug("Checking member : " + member.member_id)
+
+            if member.properties is not None and cartridgeagentconstants.PRIMARY in member.properties and \
+                    member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
+                    (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
+
+                self.log.debug("Added worker member " + member.member_id)
+
+                worker_wka_members.append(member)
+                self.wk_members.append(member)
+
+                # get the min instance count
+                if not worker_min_instance_count_found:
+                    worker_min_instance_count = self.get_min_instance_count_from_member(member)
+                    worker_min_instance_count_found = True
+                    self.log.debug("Worker min instance count: " + worker_min_instance_count)
+
+        if len(worker_wka_members) >= worker_min_instance_count:
+            min_worker_instances_available = True
+            idx = 0
+            for member in worker_wka_members:
+                env_params["STRATOS_WK_WORKER_MEMBER_" + idx + "_IP"] = member.member_ip
+                self.log.debug("STRATOS_WK_WORKER_MEMBER_" + idx + "_IP: " + member.member_ip)
+                idx += 1
+
+            env_params["STRATOS_WK_WORKER_MEMBER_COUNT"] = int(worker_min_instance_count)
+
+        self.log.debug(
+            " Returnning values minManagerInstancesAvailable && minWorkerInstancesAvailable [" +
+            min_manager_instances_available + "],  [" + min_worker_instances_available + "] ")
+
+        return min_manager_instances_available and min_worker_instances_available
+
+    def get_min_instance_count_from_member(self, member):
+        if cartridgeagentconstants.MIN_COUNT in member.properties:
+            return int(member.properties[cartridgeagentconstants.MIN_COUNT])
+
+        return 1
+
+    def find_tenant_domain(self, tenant_id):
+        tenant = TenantContext.get_tenant(tenant_id)
+        if tenant is None:
+            raise RuntimeError("Tenant could not be found: [tenant-id] %r" % tenant_id)
+
+        return tenant.tenant_domain
+
+    def wait_for_wk_members(self, env_params):
+        min_count = int(self.cartridge_agent_config.min_count)
+        is_wk_member_group_ready = False
+        while not is_wk_member_group_ready:
+            self.log.info("Waiting for %r well known members..." % min_count)
+
+            time.sleep(5)
+
+            is_wk_member_group_ready = self.is_wk_member_group_ready(env_params, min_count)
+
+from ..artifactmgt.git import agentgithandler
+from ..artifactmgt.repositoryinformation import RepositoryInformation
+from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
+from ..publisher import cartridgeagentpublisher
+from ..exception.parameternotfoundexception import ParameterNotFoundException
+from ..topology.topologycontext import *
+from ..tenant.tenantcontext import *
+from ..util.log import LogFactory
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py b/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
new file mode 100644
index 0000000..685344d
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
@@ -0,0 +1,62 @@
+# 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.
+
+class AbstractHealthStatisticsReader:
+    """
+    Abstract class to implement to create a custom health stat reader
+    """
+
+    def stat_cartridge_health(self):
+        """
+        Abstract method that when implemented reads the memory usage and the load average
+        of the instance running the agent and returns a CartridgeHealthStatistics object
+        with the information
+
+        :return: CartridgeHealthStatistics object with memory usage and load average values
+        :rtype : CartridgeHealthStatistics
+        """
+        raise NotImplementedError
+
+
+class CartridgeHealthStatistics:
+    """
+    Holds the memory usage and load average reading
+    """
+
+    def __init__(self):
+        self.memory_usage = None
+        """:type : float"""
+        self.load_avg = None
+        """:type : float"""
+
+
+class CEPPublisherException(Exception):
+    """
+    Exception to be used during CEP publishing operations
+    """
+
+    def __init__(self, msg):
+        super(self,  msg)
+        self.message = msg
+
+    def get_message(self):
+        """
+        The message provided when the exception is raised
+        :return: message
+        :rtype: str
+        """
+        return self.message


[12/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py
new file mode 100644
index 0000000..d76afca
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py
@@ -0,0 +1,320 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
+
+from ...thrift.transport import TTransport
+from ...thrift.protocol import TBinaryProtocol, TProtocol
+try:
+  from ...thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+
+class ThriftAttributeType:
+  INT = 0
+  LONG = 1
+  FLOAT = 2
+  DOUBLE = 3
+  BOOL = 4
+  STRING = 5
+
+  _VALUES_TO_NAMES = {
+    0: "INT",
+    1: "LONG",
+    2: "FLOAT",
+    3: "DOUBLE",
+    4: "BOOL",
+    5: "STRING",
+  }
+
+  _NAMES_TO_VALUES = {
+    "INT": 0,
+    "LONG": 1,
+    "FLOAT": 2,
+    "DOUBLE": 3,
+    "BOOL": 4,
+    "STRING": 5,
+  }
+
+
+class ThriftAttribute:
+  """
+  Attributes:
+   - name
+   - attributeType
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'name', None, None, ), # 1
+    (2, TType.I32, 'attributeType', None, None, ), # 2
+  )
+
+  def __init__(self, name=None, attributeType=None,):
+    self.name = name
+    self.attributeType = attributeType
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.name = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.I32:
+          self.attributeType = iprot.readI32();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftAttribute')
+    if self.name is not None:
+      oprot.writeFieldBegin('name', TType.STRING, 1)
+      oprot.writeString(self.name)
+      oprot.writeFieldEnd()
+    if self.attributeType is not None:
+      oprot.writeFieldBegin('attributeType', TType.I32, 2)
+      oprot.writeI32(self.attributeType)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftEventBundle:
+  """
+  Attributes:
+   - sessionId
+   - eventNum
+   - intAttributeList
+   - longAttributeList
+   - doubleAttributeList
+   - boolAttributeList
+   - stringAttributeList
+   - arbitraryDataMapMap
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.I32, 'eventNum', None, None, ), # 2
+    (3, TType.LIST, 'intAttributeList', (TType.I32,None), None, ), # 3
+    (4, TType.LIST, 'longAttributeList', (TType.I64,None), None, ), # 4
+    (5, TType.LIST, 'doubleAttributeList', (TType.DOUBLE,None), None, ), # 5
+    (6, TType.LIST, 'boolAttributeList', (TType.BOOL,None), None, ), # 6
+    (7, TType.LIST, 'stringAttributeList', (TType.STRING,None), None, ), # 7
+    (8, TType.MAP, 'arbitraryDataMapMap', (TType.I32,None,TType.MAP,(TType.STRING,None,TType.STRING,None)), None, ), # 8
+  )
+
+  def __init__(self, sessionId=None, eventNum=None, intAttributeList=None, longAttributeList=None, doubleAttributeList=None, boolAttributeList=None, stringAttributeList=None, arbitraryDataMapMap=None,):
+    self.sessionId = sessionId
+    self.eventNum = eventNum
+    self.intAttributeList = intAttributeList
+    self.longAttributeList = longAttributeList
+    self.doubleAttributeList = doubleAttributeList
+    self.boolAttributeList = boolAttributeList
+    self.stringAttributeList = stringAttributeList
+    self.arbitraryDataMapMap = arbitraryDataMapMap
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.I32:
+          self.eventNum = iprot.readI32();
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.LIST:
+          self.intAttributeList = []
+          (_etype3, _size0) = iprot.readListBegin()
+          for _i4 in xrange(_size0):
+            _elem5 = iprot.readI32();
+            self.intAttributeList.append(_elem5)
+          iprot.readListEnd()
+        else:
+          iprot.skip(ftype)
+      elif fid == 4:
+        if ftype == TType.LIST:
+          self.longAttributeList = []
+          (_etype9, _size6) = iprot.readListBegin()
+          for _i10 in xrange(_size6):
+            _elem11 = iprot.readI64();
+            self.longAttributeList.append(_elem11)
+          iprot.readListEnd()
+        else:
+          iprot.skip(ftype)
+      elif fid == 5:
+        if ftype == TType.LIST:
+          self.doubleAttributeList = []
+          (_etype15, _size12) = iprot.readListBegin()
+          for _i16 in xrange(_size12):
+            _elem17 = iprot.readDouble();
+            self.doubleAttributeList.append(_elem17)
+          iprot.readListEnd()
+        else:
+          iprot.skip(ftype)
+      elif fid == 6:
+        if ftype == TType.LIST:
+          self.boolAttributeList = []
+          (_etype21, _size18) = iprot.readListBegin()
+          for _i22 in xrange(_size18):
+            _elem23 = iprot.readBool();
+            self.boolAttributeList.append(_elem23)
+          iprot.readListEnd()
+        else:
+          iprot.skip(ftype)
+      elif fid == 7:
+        if ftype == TType.LIST:
+          self.stringAttributeList = []
+          (_etype27, _size24) = iprot.readListBegin()
+          for _i28 in xrange(_size24):
+            _elem29 = iprot.readString();
+            self.stringAttributeList.append(_elem29)
+          iprot.readListEnd()
+        else:
+          iprot.skip(ftype)
+      elif fid == 8:
+        if ftype == TType.MAP:
+          self.arbitraryDataMapMap = {}
+          (_ktype31, _vtype32, _size30 ) = iprot.readMapBegin()
+          for _i34 in xrange(_size30):
+            _key35 = iprot.readI32();
+            _val36 = {}
+            (_ktype38, _vtype39, _size37 ) = iprot.readMapBegin()
+            for _i41 in xrange(_size37):
+              _key42 = iprot.readString();
+              _val43 = iprot.readString();
+              _val36[_key42] = _val43
+            iprot.readMapEnd()
+            self.arbitraryDataMapMap[_key35] = _val36
+          iprot.readMapEnd()
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftEventBundle')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.eventNum is not None:
+      oprot.writeFieldBegin('eventNum', TType.I32, 2)
+      oprot.writeI32(self.eventNum)
+      oprot.writeFieldEnd()
+    if self.intAttributeList is not None:
+      oprot.writeFieldBegin('intAttributeList', TType.LIST, 3)
+      oprot.writeListBegin(TType.I32, len(self.intAttributeList))
+      for iter44 in self.intAttributeList:
+        oprot.writeI32(iter44)
+      oprot.writeListEnd()
+      oprot.writeFieldEnd()
+    if self.longAttributeList is not None:
+      oprot.writeFieldBegin('longAttributeList', TType.LIST, 4)
+      oprot.writeListBegin(TType.I64, len(self.longAttributeList))
+      for iter45 in self.longAttributeList:
+        oprot.writeI64(iter45)
+      oprot.writeListEnd()
+      oprot.writeFieldEnd()
+    if self.doubleAttributeList is not None:
+      oprot.writeFieldBegin('doubleAttributeList', TType.LIST, 5)
+      oprot.writeListBegin(TType.DOUBLE, len(self.doubleAttributeList))
+      for iter46 in self.doubleAttributeList:
+        oprot.writeDouble(iter46)
+      oprot.writeListEnd()
+      oprot.writeFieldEnd()
+    if self.boolAttributeList is not None:
+      oprot.writeFieldBegin('boolAttributeList', TType.LIST, 6)
+      oprot.writeListBegin(TType.BOOL, len(self.boolAttributeList))
+      for iter47 in self.boolAttributeList:
+        oprot.writeBool(iter47)
+      oprot.writeListEnd()
+      oprot.writeFieldEnd()
+    if self.stringAttributeList is not None:
+      oprot.writeFieldBegin('stringAttributeList', TType.LIST, 7)
+      oprot.writeListBegin(TType.STRING, len(self.stringAttributeList))
+      for iter48 in self.stringAttributeList:
+        oprot.writeString(iter48)
+      oprot.writeListEnd()
+      oprot.writeFieldEnd()
+    if self.arbitraryDataMapMap is not None:
+      oprot.writeFieldBegin('arbitraryDataMapMap', TType.MAP, 8)
+      oprot.writeMapBegin(TType.I32, TType.MAP, len(self.arbitraryDataMapMap))
+      for kiter49,viter50 in self.arbitraryDataMapMap.items():
+        oprot.writeI32(kiter49)
+        oprot.writeMapBegin(TType.STRING, TType.STRING, len(viter50))
+        for kiter51,viter52 in viter50.items():
+          oprot.writeString(kiter51)
+          oprot.writeString(viter52)
+        oprot.writeMapEnd()
+      oprot.writeMapEnd()
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py
new file mode 100644
index 0000000..adefd8e
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py
@@ -0,0 +1 @@
+__all__ = ['ttypes', 'constants']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py
new file mode 100644
index 0000000..36943ba
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py
@@ -0,0 +1,8 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py
new file mode 100644
index 0000000..9fbb1ce
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py
@@ -0,0 +1,473 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
+
+from ...thrift.transport import TTransport
+from ...thrift.protocol import TBinaryProtocol, TProtocol
+try:
+  from ...thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+
+
+class ThriftStreamDefinitionException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftStreamDefinitionException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftNoStreamDefinitionExistException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftNoStreamDefinitionExistException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftDifferentStreamDefinitionAlreadyDefinedException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftDifferentStreamDefinitionAlreadyDefinedException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftMalformedStreamDefinitionException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftMalformedStreamDefinitionException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftUndefinedEventTypeException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftUndefinedEventTypeException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftSessionExpiredException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftSessionExpiredException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftAuthenticationException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftAuthenticationException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
new file mode 100755
index 0000000..0d18f58
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+import sys
+import pprint
+from urlparse import urlparse
+
+from thrift.transport import TTransport
+from thrift.transport import TSocket
+from thrift.transport import THttpClient
+from thrift.protocol import TBinaryProtocol
+from ThriftEventTransmissionService import ThriftEventTransmissionService
+from ThriftEventTransmissionService.ttypes import *
+
+
+if len(sys.argv) <= 1 or sys.argv[1] == '--help':
+  print ''
+  print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
+  print ''
+  print 'Functions:'
+  print '  string defineStream(string sessionId, string streamDefinition)'
+  print '  string findStreamId(string sessionId, string streamName, string streamVersion)'
+  print '  void publish(ThriftEventBundle eventBundle)'
+  print '  bool deleteStreamById(string sessionId, string streamId)'
+  print '  bool deleteStreamByNameVersion(string sessionId, string streamName, string streamVersion)'
+  print ''
+  sys.exit(0)
+
+pp = pprint.PrettyPrinter(indent = 2)
+host = 'localhost'
+port = 9090
+uri = ''
+framed = False
+http = False
+argi = 1
+
+if sys.argv[argi] == '-h':
+  parts = sys.argv[argi+1].split(':')
+  host = parts[0]
+  if len(parts) > 1:
+    port = int(parts[1])
+  argi += 2
+
+if sys.argv[argi] == '-u':
+  url = urlparse(sys.argv[argi+1])
+  parts = url[1].split(':')
+  host = parts[0]
+  if len(parts) > 1:
+    port = int(parts[1])
+  else:
+    port = 80
+  uri = url[2]
+  if url[4]:
+    uri += '?%s' % url[4]
+  http = True
+  argi += 2
+
+if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
+  framed = True
+  argi += 1
+
+cmd = sys.argv[argi]
+args = sys.argv[argi+1:]
+
+if http:
+  transport = THttpClient.THttpClient(host, port, uri)
+else:
+  socket = TSocket.TSocket(host, port)
+  if framed:
+    transport = TTransport.TFramedTransport(socket)
+  else:
+    transport = TTransport.TBufferedTransport(socket)
+protocol = TBinaryProtocol.TBinaryProtocol(transport)
+client = ThriftEventTransmissionService.Client(protocol)
+transport.open()
+
+if cmd == 'defineStream':
+  if len(args) != 2:
+    print 'defineStream requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.defineStream(args[0],args[1],))
+
+elif cmd == 'findStreamId':
+  if len(args) != 3:
+    print 'findStreamId requires 3 args'
+    sys.exit(1)
+  pp.pprint(client.findStreamId(args[0],args[1],args[2],))
+
+elif cmd == 'publish':
+  if len(args) != 1:
+    print 'publish requires 1 args'
+    sys.exit(1)
+  pp.pprint(client.publish(eval(args[0]),))
+
+elif cmd == 'deleteStreamById':
+  if len(args) != 2:
+    print 'deleteStreamById requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.deleteStreamById(args[0],args[1],))
+
+elif cmd == 'deleteStreamByNameVersion':
+  if len(args) != 3:
+    print 'deleteStreamByNameVersion requires 3 args'
+    sys.exit(1)
+  pp.pprint(client.deleteStreamByNameVersion(args[0],args[1],args[2],))
+
+else:
+  print 'Unrecognized method %s' % cmd
+  sys.exit(1)
+
+transport.close()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
new file mode 100644
index 0000000..4a5a252
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
@@ -0,0 +1,1143 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ttypes import *
+from ...thrift.Thrift import TProcessor
+from ...thrift.transport import TTransport
+
+try:
+  from ...thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+
+class Iface:
+  def defineStream(self, sessionId, streamDefinition):
+    """
+    Parameters:
+     - sessionId
+     - streamDefinition
+    """
+    pass
+
+  def findStreamId(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    pass
+
+  def publish(self, eventBundle):
+    """
+    Parameters:
+     - eventBundle
+    """
+    pass
+
+  def deleteStreamById(self, sessionId, streamId):
+    """
+    Parameters:
+     - sessionId
+     - streamId
+    """
+    pass
+
+  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    pass
+
+
+class Client(Iface):
+  def __init__(self, iprot, oprot=None):
+    self._iprot = self._oprot = iprot
+    if oprot is not None:
+      self._oprot = oprot
+    self._seqid = 0
+
+  def defineStream(self, sessionId, streamDefinition):
+    """
+    Parameters:
+     - sessionId
+     - streamDefinition
+    """
+    self.send_defineStream(sessionId, streamDefinition)
+    return self.recv_defineStream()
+
+  def send_defineStream(self, sessionId, streamDefinition):
+    self._oprot.writeMessageBegin('defineStream', TMessageType.CALL, self._seqid)
+    args = defineStream_args()
+    args.sessionId = sessionId
+    args.streamDefinition = streamDefinition
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_defineStream(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = defineStream_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.ade is not None:
+      raise result.ade
+    if result.mtd is not None:
+      raise result.mtd
+    if result.tde is not None:
+      raise result.tde
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "defineStream failed: unknown result");
+
+  def findStreamId(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    self.send_findStreamId(sessionId, streamName, streamVersion)
+    return self.recv_findStreamId()
+
+  def send_findStreamId(self, sessionId, streamName, streamVersion):
+    self._oprot.writeMessageBegin('findStreamId', TMessageType.CALL, self._seqid)
+    args = findStreamId_args()
+    args.sessionId = sessionId
+    args.streamName = streamName
+    args.streamVersion = streamVersion
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_findStreamId(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = findStreamId_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.tnde is not None:
+      raise result.tnde
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "findStreamId failed: unknown result");
+
+  def publish(self, eventBundle):
+    """
+    Parameters:
+     - eventBundle
+    """
+    self.send_publish(eventBundle)
+    self.recv_publish()
+
+  def send_publish(self, eventBundle):
+    self._oprot.writeMessageBegin('publish', TMessageType.CALL, self._seqid)
+    args = publish_args()
+    args.eventBundle = eventBundle
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_publish(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = publish_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.ue is not None:
+      raise result.ue
+    if result.se is not None:
+      raise result.se
+    return
+
+  def deleteStreamById(self, sessionId, streamId):
+    """
+    Parameters:
+     - sessionId
+     - streamId
+    """
+    self.send_deleteStreamById(sessionId, streamId)
+    return self.recv_deleteStreamById()
+
+  def send_deleteStreamById(self, sessionId, streamId):
+    self._oprot.writeMessageBegin('deleteStreamById', TMessageType.CALL, self._seqid)
+    args = deleteStreamById_args()
+    args.sessionId = sessionId
+    args.streamId = streamId
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_deleteStreamById(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = deleteStreamById_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamById failed: unknown result");
+
+  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    self.send_deleteStreamByNameVersion(sessionId, streamName, streamVersion)
+    return self.recv_deleteStreamByNameVersion()
+
+  def send_deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    self._oprot.writeMessageBegin('deleteStreamByNameVersion', TMessageType.CALL, self._seqid)
+    args = deleteStreamByNameVersion_args()
+    args.sessionId = sessionId
+    args.streamName = streamName
+    args.streamVersion = streamVersion
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_deleteStreamByNameVersion(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = deleteStreamByNameVersion_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamByNameVersion failed: unknown result");
+
+
+class Processor(Iface, TProcessor):
+  def __init__(self, handler):
+    self._handler = handler
+    self._processMap = {}
+    self._processMap["defineStream"] = Processor.process_defineStream
+    self._processMap["findStreamId"] = Processor.process_findStreamId
+    self._processMap["publish"] = Processor.process_publish
+    self._processMap["deleteStreamById"] = Processor.process_deleteStreamById
+    self._processMap["deleteStreamByNameVersion"] = Processor.process_deleteStreamByNameVersion
+
+  def process(self, iprot, oprot):
+    (name, type, seqid) = iprot.readMessageBegin()
+    if name not in self._processMap:
+      iprot.skip(TType.STRUCT)
+      iprot.readMessageEnd()
+      x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
+      oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
+      x.write(oprot)
+      oprot.writeMessageEnd()
+      oprot.trans.flush()
+      return
+    else:
+      self._processMap[name](self, seqid, iprot, oprot)
+    return True
+
+  def process_defineStream(self, seqid, iprot, oprot):
+    args = defineStream_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = defineStream_result()
+    try:
+      result.success = self._handler.defineStream(args.sessionId, args.streamDefinition)
+    except Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ade:
+      result.ade = ade
+    except Exception.ttypes.ThriftMalformedStreamDefinitionException, mtd:
+      result.mtd = mtd
+    except Exception.ttypes.ThriftStreamDefinitionException, tde:
+      result.tde = tde
+    except Exception.ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("defineStream", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_findStreamId(self, seqid, iprot, oprot):
+    args = findStreamId_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = findStreamId_result()
+    try:
+      result.success = self._handler.findStreamId(args.sessionId, args.streamName, args.streamVersion)
+    except Exception.ttypes.ThriftNoStreamDefinitionExistException, tnde:
+      result.tnde = tnde
+    except Exception.ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("findStreamId", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_publish(self, seqid, iprot, oprot):
+    args = publish_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = publish_result()
+    try:
+      self._handler.publish(args.eventBundle)
+    except Exception.ttypes.ThriftUndefinedEventTypeException, ue:
+      result.ue = ue
+    except Exception.ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("publish", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_deleteStreamById(self, seqid, iprot, oprot):
+    args = deleteStreamById_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = deleteStreamById_result()
+    try:
+      result.success = self._handler.deleteStreamById(args.sessionId, args.streamId)
+    except Exception.ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("deleteStreamById", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_deleteStreamByNameVersion(self, seqid, iprot, oprot):
+    args = deleteStreamByNameVersion_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = deleteStreamByNameVersion_result()
+    try:
+      result.success = self._handler.deleteStreamByNameVersion(args.sessionId, args.streamName, args.streamVersion)
+    except Exception.ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("deleteStreamByNameVersion", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+
+# HELPER FUNCTIONS AND STRUCTURES
+
+class defineStream_args:
+  """
+  Attributes:
+   - sessionId
+   - streamDefinition
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamDefinition', None, None, ), # 2
+  )
+
+  def __init__(self, sessionId=None, streamDefinition=None,):
+    self.sessionId = sessionId
+    self.streamDefinition = streamDefinition
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamDefinition = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('defineStream_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamDefinition is not None:
+      oprot.writeFieldBegin('streamDefinition', TType.STRING, 2)
+      oprot.writeString(self.streamDefinition)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class defineStream_result:
+  """
+  Attributes:
+   - success
+   - ade
+   - mtd
+   - tde
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.STRING, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'ade', (Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'mtd', (Exception.ttypes.ThriftMalformedStreamDefinitionException, Exception.ttypes.ThriftMalformedStreamDefinitionException.thrift_spec), None, ), # 2
+    (3, TType.STRUCT, 'tde', (Exception.ttypes.ThriftStreamDefinitionException, Exception.ttypes.ThriftStreamDefinitionException.thrift_spec), None, ), # 3
+    (4, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 4
+  )
+
+  def __init__(self, success=None, ade=None, mtd=None, tde=None, se=None,):
+    self.success = success
+    self.ade = ade
+    self.mtd = mtd
+    self.tde = tde
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRING:
+          self.success = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.ade = Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException()
+          self.ade.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.mtd = Exception.ttypes.ThriftMalformedStreamDefinitionException()
+          self.mtd.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRUCT:
+          self.tde = Exception.ttypes.ThriftStreamDefinitionException()
+          self.tde.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 4:
+        if ftype == TType.STRUCT:
+          self.se = Exception.ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('defineStream_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.STRING, 0)
+      oprot.writeString(self.success)
+      oprot.writeFieldEnd()
+    if self.ade is not None:
+      oprot.writeFieldBegin('ade', TType.STRUCT, 1)
+      self.ade.write(oprot)
+      oprot.writeFieldEnd()
+    if self.mtd is not None:
+      oprot.writeFieldBegin('mtd', TType.STRUCT, 2)
+      self.mtd.write(oprot)
+      oprot.writeFieldEnd()
+    if self.tde is not None:
+      oprot.writeFieldBegin('tde', TType.STRUCT, 3)
+      self.tde.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 4)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class findStreamId_args:
+  """
+  Attributes:
+   - sessionId
+   - streamName
+   - streamVersion
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamName', None, None, ), # 2
+    (3, TType.STRING, 'streamVersion', None, None, ), # 3
+  )
+
+  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
+    self.sessionId = sessionId
+    self.streamName = streamName
+    self.streamVersion = streamVersion
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamName = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRING:
+          self.streamVersion = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('findStreamId_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamName is not None:
+      oprot.writeFieldBegin('streamName', TType.STRING, 2)
+      oprot.writeString(self.streamName)
+      oprot.writeFieldEnd()
+    if self.streamVersion is not None:
+      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
+      oprot.writeString(self.streamVersion)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class findStreamId_result:
+  """
+  Attributes:
+   - success
+   - tnde
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.STRING, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'tnde', (Exception.ttypes.ThriftNoStreamDefinitionExistException, Exception.ttypes.ThriftNoStreamDefinitionExistException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
+  )
+
+  def __init__(self, success=None, tnde=None, se=None,):
+    self.success = success
+    self.tnde = tnde
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRING:
+          self.success = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.tnde = Exception.ttypes.ThriftNoStreamDefinitionExistException()
+          self.tnde.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.se = Exception.ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('findStreamId_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.STRING, 0)
+      oprot.writeString(self.success)
+      oprot.writeFieldEnd()
+    if self.tnde is not None:
+      oprot.writeFieldBegin('tnde', TType.STRUCT, 1)
+      self.tnde.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 2)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class publish_args:
+  """
+  Attributes:
+   - eventBundle
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRUCT, 'eventBundle', (Data.ttypes.ThriftEventBundle, Data.ttypes.ThriftEventBundle.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, eventBundle=None,):
+    self.eventBundle = eventBundle
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRUCT:
+          self.eventBundle = Data.ttypes.ThriftEventBundle()
+          self.eventBundle.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('publish_args')
+    if self.eventBundle is not None:
+      oprot.writeFieldBegin('eventBundle', TType.STRUCT, 1)
+      self.eventBundle.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class publish_result:
+  """
+  Attributes:
+   - ue
+   - se
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRUCT, 'ue', (Exception.ttypes.ThriftUndefinedEventTypeException, Exception.ttypes.ThriftUndefinedEventTypeException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
+  )
+
+  def __init__(self, ue=None, se=None,):
+    self.ue = ue
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRUCT:
+          self.ue = Exception.ttypes.ThriftUndefinedEventTypeException()
+          self.ue.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.se = Exception.ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('publish_result')
+    if self.ue is not None:
+      oprot.writeFieldBegin('ue', TType.STRUCT, 1)
+      self.ue.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 2)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamById_args:
+  """
+  Attributes:
+   - sessionId
+   - streamId
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamId', None, None, ), # 2
+  )
+
+  def __init__(self, sessionId=None, streamId=None,):
+    self.sessionId = sessionId
+    self.streamId = streamId
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamById_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamId is not None:
+      oprot.writeFieldBegin('streamId', TType.STRING, 2)
+      oprot.writeString(self.streamId)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamById_result:
+  """
+  Attributes:
+   - success
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.BOOL, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, se=None,):
+    self.success = success
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.BOOL:
+          self.success = iprot.readBool();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.se = Exception.ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamById_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.BOOL, 0)
+      oprot.writeBool(self.success)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 1)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamByNameVersion_args:
+  """
+  Attributes:
+   - sessionId
+   - streamName
+   - streamVersion
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamName', None, None, ), # 2
+    (3, TType.STRING, 'streamVersion', None, None, ), # 3
+  )
+
+  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
+    self.sessionId = sessionId
+    self.streamName = streamName
+    self.streamVersion = streamVersion
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamName = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRING:
+          self.streamVersion = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamByNameVersion_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamName is not None:
+      oprot.writeFieldBegin('streamName', TType.STRING, 2)
+      oprot.writeString(self.streamName)
+      oprot.writeFieldEnd()
+    if self.streamVersion is not None:
+      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
+      oprot.writeString(self.streamVersion)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamByNameVersion_result:
+  """
+  Attributes:
+   - success
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.BOOL, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, se=None,):
+    self.success = success
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.BOOL:
+          self.success = iprot.readBool();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.se = Exception.ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamByNameVersion_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.BOOL, 0)
+      oprot.writeBool(self.success)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 1)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
new file mode 100644
index 0000000..38575a6
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
@@ -0,0 +1 @@
+__all__ = ['ttypes', 'constants', 'ThriftEventTransmissionService']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
new file mode 100644
index 0000000..36943ba
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
@@ -0,0 +1,8 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
new file mode 100644
index 0000000..37ac241
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
@@ -0,0 +1,21 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
+from ..Data import ttypes
+from ..Exception import ttypes
+
+
+from ...thrift.transport import TTransport
+from ...thrift.protocol import TBinaryProtocol, TProtocol
+try:
+  from thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
new file mode 100755
index 0000000..46757bf
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
@@ -0,0 +1,131 @@
+#!/usr/bin/env python
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+import sys
+import pprint
+from urlparse import urlparse
+
+from thrift.transport import TTransport
+from thrift.transport import TSocket
+from thrift.transport import THttpClient
+from thrift.protocol import TBinaryProtocol
+from ThriftSecureEventTransmissionService import ThriftSecureEventTransmissionService
+from ThriftSecureEventTransmissionService.ttypes import *
+
+
+if len(sys.argv) <= 1 or sys.argv[1] == '--help':
+  print ''
+  print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
+  print ''
+  print 'Functions:'
+  print '  string connect(string userName, string password)'
+  print '  void disconnect(string sessionId)'
+  print '  string defineStream(string sessionId, string streamDefinition)'
+  print '  string findStreamId(string sessionId, string streamName, string streamVersion)'
+  print '  void publish(ThriftEventBundle eventBundle)'
+  print '  bool deleteStreamById(string sessionId, string streamId)'
+  print '  bool deleteStreamByNameVersion(string sessionId, string streamName, string streamVersion)'
+  print ''
+  sys.exit(0)
+
+pp = pprint.PrettyPrinter(indent = 2)
+host = 'localhost'
+port = 9090
+uri = ''
+framed = False
+http = False
+argi = 1
+
+if sys.argv[argi] == '-h':
+  parts = sys.argv[argi+1].split(':')
+  host = parts[0]
+  if len(parts) > 1:
+    port = int(parts[1])
+  argi += 2
+
+if sys.argv[argi] == '-u':
+  url = urlparse(sys.argv[argi+1])
+  parts = url[1].split(':')
+  host = parts[0]
+  if len(parts) > 1:
+    port = int(parts[1])
+  else:
+    port = 80
+  uri = url[2]
+  if url[4]:
+    uri += '?%s' % url[4]
+  http = True
+  argi += 2
+
+if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
+  framed = True
+  argi += 1
+
+cmd = sys.argv[argi]
+args = sys.argv[argi+1:]
+
+if http:
+  transport = THttpClient.THttpClient(host, port, uri)
+else:
+  socket = TSocket.TSocket(host, port)
+  if framed:
+    transport = TTransport.TFramedTransport(socket)
+  else:
+    transport = TTransport.TBufferedTransport(socket)
+protocol = TBinaryProtocol.TBinaryProtocol(transport)
+client = ThriftSecureEventTransmissionService.Client(protocol)
+transport.open()
+
+if cmd == 'connect':
+  if len(args) != 2:
+    print 'connect requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.connect(args[0],args[1],))
+
+elif cmd == 'disconnect':
+  if len(args) != 1:
+    print 'disconnect requires 1 args'
+    sys.exit(1)
+  pp.pprint(client.disconnect(args[0],))
+
+elif cmd == 'defineStream':
+  if len(args) != 2:
+    print 'defineStream requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.defineStream(args[0],args[1],))
+
+elif cmd == 'findStreamId':
+  if len(args) != 3:
+    print 'findStreamId requires 3 args'
+    sys.exit(1)
+  pp.pprint(client.findStreamId(args[0],args[1],args[2],))
+
+elif cmd == 'publish':
+  if len(args) != 1:
+    print 'publish requires 1 args'
+    sys.exit(1)
+  pp.pprint(client.publish(eval(args[0]),))
+
+elif cmd == 'deleteStreamById':
+  if len(args) != 2:
+    print 'deleteStreamById requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.deleteStreamById(args[0],args[1],))
+
+elif cmd == 'deleteStreamByNameVersion':
+  if len(args) != 3:
+    print 'deleteStreamByNameVersion requires 3 args'
+    sys.exit(1)
+  pp.pprint(client.deleteStreamByNameVersion(args[0],args[1],args[2],))
+
+else:
+  print 'Unrecognized method %s' % cmd
+  sys.exit(1)
+
+transport.close()


[13/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/agent.conf
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/agent.conf b/tools/python-cartridge-agent/cartridgeagent/agent.conf
new file mode 100644
index 0000000..5c087e9
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/agent.conf
@@ -0,0 +1,62 @@
+# 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.
+
+[agent]
+mb.ip                                 =MB-IP
+mb.port                               =MB-PORT
+listen.address                        =LISTEN_ADDR
+thrift.receiver.ip                    =CEP-IP
+thrift.receiver.port                  =CEP-PORT
+thrift.server.admin.username          =CEP-ADMIN-USERNAME
+thrift.server.admin.password          =CEP-ADMIN-PASSWORD
+param.file.path                       =/mnt/cartridge-agent/payload/launch-params
+extensions.dir                        =/mnt/cartridge-agent/extensions
+cep.stats.publisher.enabled           =ENABLE_HEALTH_PUBLISHER
+lb.private.ip                         =LB_PRIVATE_IP
+lb.public.ip                          =LB_PUBLIC_IP
+enable.artifact.update                =ENABLE_ARTFCT_UPDATE
+auto.commit                           =COMMIT_ENABLED
+auto.checkout                         =CHECKOUT_ENABLED
+artifact.update.interval              =ARTFCT_UPDATE_INT
+port.check.timeout                    =PORT_CHECK_TIMEOUT
+enable.data.publisher                 =ENABLE-DATA-PUBLISHER
+monitoring.server.ip                  =MONITORING-SERVER-IP
+monitoring.server.port                =MONITORING-SERVER-PORT
+monitoring.server.secure.port         =MONITORING-SERVER-SECURE-PORT
+monitoring.server.admin.username      =MONITORING-SERVER-ADMIN-USERNAME
+monitoring.server.admin.password      =MONITORING-SERVER-ADMIN-PASSWORD
+log.file.paths                        =LOG_FILE_PATHS
+APP_PATH                              =APP-PATH
+super.tenant.repository.path          =/repository/deployment/server/
+tenant.repository.path                =/repository/tenants/
+extension.instance.started            =instance-started.sh
+extension.start.servers               =start-servers.sh
+extension.instance.activated          =instance-activated.sh
+extension.artifacts.updated           =artifacts-updated.sh
+extension.clean                       =clean.sh
+extension.mount.volumes               =mount_volumes.sh
+extension.member.started              =member-started.sh
+extension.member.activated            =member-activated.sh
+extension.member.suspended            =member-suspended.sh
+extension.member.terminated           =member-terminated.sh
+extension.complete.topology           =complete-topology.sh
+extension.complete.tenant             =complete-tenant.sh
+extension.subscription.domain.added   =subscription-domain-added.sh
+extension.subscription.domain.removed =subscription-domain-removed.sh
+extension.artifacts.copy              =artifacts-copy.sh
+extension.tenant.subscribed           =tenant-subscribed.sh
+extension.tenant.unsubscribed         =tenant-unsubscribed.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/agent.py b/tools/python-cartridge-agent/cartridgeagent/agent.py
new file mode 100644
index 0000000..9f1a972
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/agent.py
@@ -0,0 +1,343 @@
+#!/usr/bin/env python
+# 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.
+
+import threading
+
+from modules.exception.parameternotfoundexception import ParameterNotFoundException
+from modules.subscriber import eventsubscriber
+from modules.publisher import cartridgeagentpublisher
+from modules.event.instance.notifier.events import *
+from modules.event.tenant.events import *
+from modules.event.topology.events import *
+from modules.tenant.tenantcontext import *
+from modules.topology.topologycontext import *
+from modules.datapublisher.logpublisher import *
+from modules.config import cartridgeagentconfiguration
+from modules.extensions import defaultextensionhandler
+
+
+class CartridgeAgent(threading.Thread):
+    extension_handler = defaultextensionhandler.DefaultExtensionHandler()
+
+    def __init__(self):
+        threading.Thread.__init__(self)
+
+        mb_ip = cartridgeagentconfiguration.CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_IP)
+        mb_port = cartridgeagentconfiguration.CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_PORT)
+
+        self.__instance_event_subscriber = eventsubscriber.EventSubscriber(
+            cartridgeagentconstants.INSTANCE_NOTIFIER_TOPIC,
+            mb_ip,
+            mb_port)
+        self.__tenant_event_subscriber = eventsubscriber.EventSubscriber(
+            cartridgeagentconstants.TENANT_TOPIC,
+            mb_ip,
+            mb_port)
+        self.__topology_event_subscriber = eventsubscriber.EventSubscriber(
+            cartridgeagentconstants.TOPOLOGY_TOPIC,
+            mb_ip,
+            mb_port)
+
+        self.__tenant_context_initialized = False
+
+        self.log_publish_manager = None
+
+        self.terminated = False
+
+        self.log = LogFactory().get_log(__name__)
+
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+    def run(self):
+        self.log.info("Starting Cartridge Agent...")
+
+        #Check if required prpoerties are set
+        self.validate_required_properties()
+
+        #Start instance notifier listener thread
+        self.subscribe_to_topics_and_register_listeners()
+
+        #Start topology event receiver thread
+        self.register_topology_event_listeners()
+
+        #Start tenant event receiver thread
+        self.register_tenant_event_listeners()
+
+        #wait for intance spawned event
+        while not self.cartridge_agent_config.initialized:
+            self.log.debug("Waiting for Cartridge Agent to be initialized...")
+            time.sleep(1)
+
+        #Execute instance started shell script
+        CartridgeAgent.extension_handler.on_instance_started_event()
+
+        #Publish instance started event
+        cartridgeagentpublisher.publish_instance_started_event()
+
+        #Execute start servers extension
+        try:
+            CartridgeAgent.extension_handler.start_server_extension()
+        except:
+            self.log.exception("Error processing start servers event")
+
+        #Wait for all ports to be active
+        cartridgeagentutils.wait_until_ports_active(
+            self.cartridge_agent_config.listen_address,
+            self.cartridge_agent_config.ports,
+            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False))
+        )
+
+        # check if artifact management is required before publishing instance activated event
+        repo_url = self.cartridge_agent_config.repo_url
+        if repo_url is None or str(repo_url).strip() == "":
+            self.log.info("No artifact repository found")
+            CartridgeAgent.extension_handler.on_instance_activated_event()
+
+            cartridgeagentpublisher.publish_instance_activated_event()
+
+        persistence_mappping_payload = self.cartridge_agent_config.persistence_mappings
+        if persistence_mappping_payload is not None:
+            CartridgeAgent.extension_handler.volume_mount_extension(persistence_mappping_payload)
+
+        # start log publishing thread
+        if DataPublisherConfiguration.get_instance().enabled:
+            log_file_paths = self.cartridge_agent_config.log_file_paths
+            if log_file_paths is None:
+                self.log.exception("No valid log file paths found, no logs will be published")
+            else:
+                self.log_publish_manager = LogPublisherManager(log_file_paths)
+                self.log_publish_manager.start()
+
+        while not self.terminated:
+            time.sleep(1)
+
+        if DataPublisherConfiguration.get_instance().enabled:
+            self.log_publish_manager.terminate_all_publishers()
+
+    def terminate(self):
+        """
+        Allows the CartridgeAgent thread to be terminated
+
+        :return: void
+        """
+        self.terminated = True
+
+    def validate_required_properties(self):
+        """
+        Checks if required properties are set
+        :return: void
+        """
+        #PARAM_FILE_PATH
+        try:
+            self.cartridge_agent_config.read_property(cartridgeagentconstants.PARAM_FILE_PATH)
+        except ParameterNotFoundException:
+            self.log.error("System property not found: %r" % cartridgeagentconstants.PARAM_FILE_PATH)
+            return
+
+        #EXTENSIONS_DIR
+        try:
+            self.cartridge_agent_config.read_property(cartridgeagentconstants.EXTENSIONS_DIR)
+        except ParameterNotFoundException:
+            self.log.error("System property not found: %r" % cartridgeagentconstants.EXTENSIONS_DIR)
+            return
+        
+    def subscribe_to_topics_and_register_listeners(self):
+        self.log.debug("Starting instance notifier event message receiver thread")
+
+        self.__instance_event_subscriber.register_handler("ArtifactUpdatedEvent", self.on_artifact_updated)
+        self.__instance_event_subscriber.register_handler("InstanceCleanupMemberEvent", self.on_instance_cleanup_member)
+        self.__instance_event_subscriber.register_handler("InstanceCleanupClusterEvent", self.on_instance_cleanup_cluster)
+
+        self.__instance_event_subscriber.start()
+        self.log.info("Instance notifier event message receiver thread started")
+
+        # wait till subscribed to continue
+        while not self.__instance_event_subscriber.is_subscribed():
+            time.sleep(2)
+
+    def on_artifact_updated(self, msg):
+        event_obj = ArtifactUpdatedEvent.create_from_json(msg.payload)
+        CartridgeAgent.extension_handler.on_artifact_updated_event(event_obj)
+
+    def on_instance_cleanup_member(self, msg):
+        member_in_payload = self.cartridge_agent_config.member_id
+        event_obj = InstanceCleanupMemberEvent.create_from_json(msg.payload)
+        member_in_event = event_obj.member_id
+        if member_in_payload == member_in_event:
+            CartridgeAgent.extension_handler.on_instance_cleanup_member_event(event_obj)
+
+    def on_instance_cleanup_cluster(self, msg):
+        event_obj = InstanceCleanupClusterEvent.create_from_json(msg.payload)
+        cluster_in_payload = self.cartridge_agent_config.cluster_id
+        cluster_in_event = event_obj.cluster_id
+
+        if cluster_in_event == cluster_in_payload:
+            CartridgeAgent.extension_handler.on_instance_cleanup_cluster_event(event_obj)
+
+    def register_topology_event_listeners(self):
+        self.log.debug("Starting topology event message receiver thread")
+
+        self.__topology_event_subscriber.register_handler("MemberActivatedEvent", self.on_member_activated)
+        self.__topology_event_subscriber.register_handler("MemberTerminatedEvent", self.on_member_terminated)
+        self.__topology_event_subscriber.register_handler("MemberSuspendedEvent", self.on_member_suspended)
+        self.__topology_event_subscriber.register_handler("CompleteTopologyEvent", self.on_complete_topology)
+        self.__topology_event_subscriber.register_handler("MemberStartedEvent", self.on_member_started)
+        self.__topology_event_subscriber.register_handler("InstanceSpawnedEvent", self.on_instance_spawned)
+
+        self.__topology_event_subscriber.start()
+        self.log.info("Cartridge Agent topology receiver thread started")
+
+    def on_instance_spawned(self, msg):
+        self.log.debug("Instance spawned event received: %r" % msg.payload)
+        if self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = InstanceSpawnedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_instance_spawned_event(event_obj)
+        except:
+            self.log.exception("Error processing instance spawned event")
+
+    def on_member_activated(self, msg):
+        self.log.debug("Member activated event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = MemberActivatedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_member_activated_event(event_obj)
+        except:
+            self.log.exception("Error processing member activated event")
+
+    def on_member_terminated(self, msg):
+        self.log.debug("Member terminated event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = MemberTerminatedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_member_terminated_event(event_obj)
+        except:
+            self.log.exception("Error processing member terminated event")
+
+    def on_member_suspended(self, msg):
+        self.log.debug("Member suspended event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = MemberSuspendedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_member_suspended_event(event_obj)
+        except:
+            self.log.exception("Error processing member suspended event")
+
+    def on_complete_topology(self, msg):
+        if not self.cartridge_agent_config.initialized:
+            self.log.debug("Complete topology event received")
+            event_obj = CompleteTopologyEvent.create_from_json(msg.payload)
+            TopologyContext.update(event_obj.topology)
+            try:
+                CartridgeAgent.extension_handler.on_complete_topology_event(event_obj)
+            except:
+                self.log.exception("Error processing complete topology event")
+        else:
+            self.log.info("Complete topology event updating task disabled")
+
+    def on_member_started(self, msg):
+        self.log.debug("Member started event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = MemberStartedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_member_started_event(event_obj)
+        except:
+            self.log.exception("Error processing member started event")
+
+    def register_tenant_event_listeners(self):
+        self.log.debug("Starting tenant event message receiver thread")
+        self.__tenant_event_subscriber.register_handler("SubscriptionDomainAddedEvent", self.on_subscription_domain_added)
+        self.__tenant_event_subscriber.register_handler("SubscriptionDomainsRemovedEvent", self.on_subscription_domain_removed)
+        self.__tenant_event_subscriber.register_handler("CompleteTenantEvent", self.on_complete_tenant)
+        self.__tenant_event_subscriber.register_handler("TenantSubscribedEvent", self.on_tenant_subscribed)
+        self.__tenant_event_subscriber.register_handler("TenantUnSubscribedEvent", self.on_tenant_unsubscribed)
+
+        self.__tenant_event_subscriber.start()
+        self.log.info("Tenant event message receiver thread started")
+
+    def on_subscription_domain_added(self, msg):
+        self.log.debug("Subscription domain added event received : %r" % msg.payload)
+        event_obj = SubscriptionDomainAddedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_subscription_domain_added_event(event_obj)
+        except:
+            self.log.exception("Error processing subscription domains added event")
+
+    def on_subscription_domain_removed(self, msg):
+        self.log.debug("Subscription domain removed event received : %r" % msg.payload)
+        event_obj = SubscriptionDomainRemovedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_subscription_domain_removed_event(event_obj)
+        except:
+            self.log.exception("Error processing subscription domains removed event")
+
+    def on_complete_tenant(self, msg):
+        if not self.__tenant_context_initialized:
+            self.log.debug("Complete tenant event received")
+            event_obj = CompleteTenantEvent.create_from_json(msg.payload)
+            TenantContext.update(event_obj.tenants)
+
+            try:
+                CartridgeAgent.extension_handler.on_complete_tenant_event(event_obj)
+                self.__tenant_context_initialized = True
+            except:
+                self.log.exception("Error processing complete tenant event")
+        else:
+            self.log.info("Complete tenant event updating task disabled")
+
+    def on_tenant_subscribed(self, msg):
+        self.log.debug("Tenant subscribed event received: %r" % msg.payload)
+        event_obj = TenantSubscribedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_tenant_subscribed_event(event_obj)
+        except:
+            self.log.exception("Error processing tenant subscribed event")
+
+    def on_tenant_unsubscribed(self, msg):
+        self.log.debug("Tenant unSubscribed event received: %r" % msg.payload)
+        event_obj = TenantUnsubscribedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_tenant_unsubscribed_event(event_obj)
+        except:
+            self.log.exception("Error processing tenant unSubscribed event")
+
+
+def main():
+    cartridge_agent = CartridgeAgent()
+    log = LogFactory().get_log(__name__)
+
+    try:
+        log.debug("Starting cartridge agent")
+        cartridge_agent.start()
+    except:
+        log.exception("Cartridge Agent Exception")
+        cartridge_agent.terminate()
+
+
+if __name__ == "__main__":
+    main()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/logging.ini
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/logging.ini b/tools/python-cartridge-agent/cartridgeagent/logging.ini
new file mode 100644
index 0000000..3e49a96
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/logging.ini
@@ -0,0 +1,52 @@
+# 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.
+
+
+[formatters]
+keys=default
+
+[formatter_default]
+format=%(asctime)s:%(levelname)s:%(message)s
+class=logging.Formatter
+
+[handlers]
+keys=console, error_file, log_file
+
+[handler_console]
+class=logging.StreamHandler
+formatter=default
+args=tuple()
+
+[handler_log_file]
+class=logging.FileHandler
+level=LOG_LEVEL
+formatter=default
+args=("agent.log", "w")
+
+[handler_error_file]
+class=logging.FileHandler
+level=ERROR
+formatter=default
+args=("error.log", "w")
+
+[loggers]
+keys=root
+
+[logger_root]
+level=LOG_LEVEL
+formatter=default
+handlers=console,error_file,log_file
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/__init__.py
new file mode 100644
index 0000000..d216be4
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/__init__.py
@@ -0,0 +1,16 @@
+# 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.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
new file mode 100644
index 0000000..9e95be0
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
@@ -0,0 +1,501 @@
+# 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.
+
+from threading import current_thread, Thread
+from git import *
+from gittle import Gittle, GittleAuth  # GitPython and Gittle are both used at the time being for pros and cons of both
+import urllib2
+
+from ... util.log import LogFactory
+from ... util import cartridgeagentutils, extensionutils, cartridgeagentconstants
+from gitrepository import GitRepository
+from ... config import cartridgeagentconfiguration
+from ... util.asyncscheduledtask import AsyncScheduledTask
+from ... artifactmgt.repositoryinformation import RepositoryInformation
+
+class AgentGitHandler:
+    """
+    Handles all the git artifact management tasks related to a cartridge
+    """
+
+    log = LogFactory().get_log(__name__)
+
+    SUPER_TENANT_ID = -1234
+    SUPER_TENANT_REPO_PATH = "/repository/deployment/server/"
+    TENANT_REPO_PATH = "/repository/tenants/"
+
+    extension_handler = None
+
+    __git_repositories = {}
+    # (tenant_id => gitrepository.GitRepository)
+
+    cartridge_agent_config = cartridgeagentconfiguration.CartridgeAgentConfiguration()
+
+    @staticmethod
+    def checkout(repo_info):
+        """
+        Checks out the code from the remote repository.
+        If local repository path is empty, a clone operation is done.
+        If there is a cloned repository already on the local repository path, a pull operation
+        will be performed.
+        If there are artifacts not in the repository already on the local repository path,
+        they will be added to a git repository, the remote url added as origin, and then
+        a pull operation will be performed.
+
+        :param RepositoryInformation repo_info: The repository information object
+        :return: A tuple containing whether it was an initial clone or not, and the repository
+        context object
+        :rtype: tuple(bool, GitRepository)
+        """
+        repo_context = AgentGitHandler.get_repo_context(repo_info.tenant_id)
+        if repo_context is not None:
+            #has been previously cloned, this is not the subscription run
+            subscribe_run = False
+            if AgentGitHandler.is_valid_git_repository(repo_context):
+                AgentGitHandler.log.debug("Existing git repository detected for tenant %r, no clone required" % repo_info.tenant_id)
+                AgentGitHandler.pull(repo_context)
+            else:
+                if not os.listdir(repo_context.local_repo_path):
+                    #empty dir, clone
+                    repo_context.repo = AgentGitHandler.clone(repo_info)
+                else:
+                    #not empty
+                    if AgentGitHandler.sync_initial_local_artifacts(repo_context):
+                        AgentGitHandler.pull(repo_context)
+                    else:
+                        repo_context = None
+        else:
+            #subscribing run.. need to clone
+            subscribe_run = True
+            repo_context = AgentGitHandler.clone(repo_context)
+
+        return subscribe_run, repo_context
+
+    @staticmethod
+    def sync_initial_local_artifacts(repo_context):
+        #init git repo
+        AgentGitHandler.init(repo_context.local_repo_path)
+
+        # add remote repos
+        return AgentGitHandler.add_remote(repo_context)
+
+    @staticmethod
+    def add_remote(repo_context):
+        try:
+            #add origin remote
+            repo_context.repo.create_remote("origin", repo_context.repo_url)
+            #fetch branch details from origin
+            repo_context.repo.git.fetch()
+            #checkout master branch from origin/master as tracking
+            repo_context.repo.git.branch("-f", "--track", "master", "origin/master")
+            return True
+        except:
+            AgentGitHandler.log.exception("Error in adding remote origin %r for local repository %r"
+                                          % (repo_context.repo_url, repo_context.local_repo_path))
+            return False
+
+    @staticmethod
+    def init(path):
+        try:
+            repo = Gittle.init(path)
+            return repo
+        except:
+            AgentGitHandler.log.exception("Initializing local repo at %r failed" % path)
+            raise Exception("Initializing local repo at %r failed" % path)
+
+    @staticmethod
+    def is_valid_git_repository(repo_context):
+        if repo_context.cloned:
+            return True
+
+        for ref in repo_context.repo.refs:
+            try:
+                ref._get_object()
+            except ValueError:
+                return False
+
+        return True
+
+    @staticmethod
+    def pull(repo_context):
+        repo = Repo(repo_context.local_repo_path)
+        from ....agent import CartridgeAgent
+        AgentGitHandler.extension_handler = CartridgeAgent.extension_handler
+        try:
+            repo.git.checkout("master")
+            pull_output = repo.git.pull()
+            if "Already up-to-date." not in pull_output:
+                AgentGitHandler.log.debug("Artifacts were updated as a result of the pull operation, thread: %r - %r" % (current_thread().getName(), current_thread().ident))
+
+            AgentGitHandler.extension_handler.on_artifact_update_scheduler_event(repo_context.tenant_id)
+        except GitCommandError as ex:
+            if "fatal: Could not read from remote repository." in ex:
+                #invalid configuration, need to delete and reclone
+                AgentGitHandler.log.warn("Git pull unsuccessful for tenant %r, invalid configuration. %r" % (repo_context.tenant_id, ex))
+                cartridgeagentutils.delete_folder_tree(repo_context.local_repo_path)
+                AgentGitHandler.clone(RepositoryInformation(
+                    repo_context.repo_url,
+                    repo_context.repo_username,
+                    repo_context.repo_password,
+                    repo_context.local_repo_path,
+                    repo_context.tenant_id,
+                    repo_context.is_multitenant,
+                    repo_context.commit_enabled
+                ))
+                AgentGitHandler.extension_handler.on_artifact_update_scheduler_event(repo_context.tenant_id)
+            elif "error: Your local changes to the following files would be overwritten by merge:" in ex:
+                #conflict error
+                AgentGitHandler.log.warn("Git pull unsuccessful for tenant %r, conflicts detected." % repo_context.tenant_id)
+                #raise ex
+
+                """
+                0:'git pull' returned exit status 1: error: Your local changes to the following files would be overwritten by merge:
+                1:    README.md
+                2:    index.php
+                3:Please, commit your changes or stash them before you can merge.
+                4:Aborting
+                """
+                conflict_list = []
+                files_arr = str(ex).split("\n")
+                for file_index in range(1, len(files_arr) - 2):
+                    file_name = files_arr[file_index].strip()
+                    conflict_list.append(file_name)
+                    AgentGitHandler.log.debug("Added the file path %r to checkout from the remote repository" % file_name)
+
+                AgentGitHandler.checkout_individually(conflict_list, repo)
+            elif "fatal: unable to access " in ex:
+                #transport error
+                AgentGitHandler.log.exception("Accessing remote git repository %r failed for tenant %r" % (repo_context.repo_url, repo_context.tenant_id))
+            else:
+                AgentGitHandler.log.exception("Git pull operation for tenant %r failed" % repo_context.tenant_id)
+
+    @staticmethod
+    def checkout_individually(conflict_list, repo):
+        try:
+            for conflicted_file in conflict_list:
+                repo.git.checkout(conflicted_file)
+                AgentGitHandler.log.info("Checked out the conflicting files from the remote repository successfully")
+        except:
+            AgentGitHandler.log.exception("Checking out artifacts from index failed")
+
+    @staticmethod
+    def clone(repo_info):
+        repo_context = None
+        try:
+            repo_context = AgentGitHandler.create_git_repo_context(repo_info)
+            #create the directory if it doesn't exist
+            if not os.path.isdir(repo_context.local_repo_path):
+                cartridgeagentutils.create_dir(repo_context.local_repo_path)
+
+            auth = AgentGitHandler.create_auth_configuration(repo_context)
+
+            if auth is not None:
+                # authentication is required, use Gittle
+                gittle_repo = Gittle.clone(repo_context.repo_url, repo_context.local_repo_path, auth=auth)
+                repo = Repo(repo_context.local_repo_path)
+            else:
+                # authentication is not required, use GitPython
+                repo = Repo.clone_from(repo_context.repo_url, repo_context.local_repo_path)
+                gittle_repo = Gittle(repo_context.local_repo_path)
+
+            repo_context.cloned = True
+            repo_context.gittle_repo = gittle_repo
+            repo_context.repo  = repo
+            AgentGitHandler.add_repo_context(repo_context)
+            AgentGitHandler.log.info("Git clone operation for tenant %r successful" % repo_context.tenant_id)
+        except urllib2.URLError:
+            AgentGitHandler.log.exception("Accessing remote git repository failed for tenant %r" % repo_context.tenant_id)
+        except OSError:
+            AgentGitHandler.log.exception("Permission denied for repository path for tenant %r" % repo_context.tenant_id)
+        except:
+            AgentGitHandler.log.exception("Git clone operation for tenant %r failed" % repo_context.tenant_id)
+        finally:
+            return repo_context
+
+    @staticmethod
+    def create_auth_configuration(repo_context):
+        """
+        Creates a GittleAuth object based on the type of authorization
+        :param GitRepository repo_context: The repository context object
+        :return: GittleAuth object or None if no authorization needed
+        :rtype: GittleAuth
+        """
+        if repo_context.key_based_auth:
+            pkey = AgentGitHandler.get_private_key()
+            auth = GittleAuth(pkey=pkey)
+        elif repo_context.repo_username.strip() != "" and repo_context.repo_password.strip() != "":
+            auth = GittleAuth(username=repo_context.repo_username, password=repo_context.repo_password)
+        else:
+            auth = None
+
+        return auth
+
+    @staticmethod
+    def get_private_key():
+        """
+        Returns a file handler to the private key path specified by Carbon or default if not specified
+        by Carbon
+        :return: The file object of the private key file
+        :rtype: file
+        """
+        pkey_name = cartridgeagentutils.get_carbon_server_property("SshPrivateKeyName")
+        if pkey_name is  None:
+            pkey_name = "wso2"
+
+        pkey_path = cartridgeagentutils.get_carbon_server_property("SshPrivateKeyPath")
+        if pkey_path is None:
+            pkey_path = os.environ["HOME"] + "/.ssh"
+
+        if pkey_path.endswith("/"):
+            pkey_ptr = pkey_path + pkey_name
+        else:
+            pkey_ptr = pkey_path + "/" + pkey_name
+
+        pkey_file = open(pkey_ptr)
+
+        return pkey_file
+
+
+    @staticmethod
+    def add_repo_context(repo_context):
+        AgentGitHandler.__git_repositories[repo_context.tenant_id] = repo_context
+
+    @staticmethod
+    def get_repo_context(tenant_id):
+        """
+
+        :param int tenant_id:
+        :return: GitRepository object
+        :rtype: GitRepository
+        """
+        if tenant_id in AgentGitHandler.__git_repositories:
+            return AgentGitHandler.__git_repositories[tenant_id]
+
+        return None
+
+    @staticmethod
+    def remove_repo_context(tenant_id):
+        if tenant_id in AgentGitHandler.__git_repositories:
+            del AgentGitHandler.__git_repositories[tenant_id]
+
+    @staticmethod
+    def create_git_repo_context(repo_info):
+        repo_context = GitRepository()
+        repo_context.tenant_id = repo_info.tenant_id
+        repo_context.local_repo_path = AgentGitHandler.get_repo_path_for_tenant(
+            repo_info.tenant_id, repo_info.repo_path, repo_info.is_multitenant)
+        repo_context.repo_url = repo_info.repo_url
+        repo_context.repo_username = repo_info.repo_username
+        repo_context.repo_password = repo_info.repo_password
+        repo_context.is_multitenant = repo_info.is_multitenant
+        repo_context.commit_enabled = repo_info.commit_enabled
+
+        if AgentGitHandler.is_key_based_auth(repo_info.repo_url, repo_info.tenant_id):
+            repo_context.key_based_auth = True
+        else:
+            repo_context.key_based_auth = False
+
+        repo_context.cloned = False
+
+        repo_context.repo = None
+        repo_context.gittle_repo = None
+
+        return repo_context
+
+    @staticmethod
+    def is_key_based_auth(repo_url, tenant_id):
+        """
+        Checks if the given git repo has key based authentication
+        :param str repo_url: Git repository remote url
+        :param str tenant_id: Tenant ID
+        :return: True if key based, False otherwise
+        :rtype: bool
+        """
+        if repo_url.startswith("http://") or repo_url.startswith("https://"):
+            # username and password, not key based
+            return False
+        elif repo_url.startswith("git://github.com"):
+            # no auth required
+            return False
+        elif repo_url.startswith("ssh://") or "@" in repo_url:
+            # key based
+            return True
+        else:
+            AgentGitHandler.log.error("Invalid git URL provided for tenant " + tenant_id)
+            raise RuntimeError("Invalid git URL provided for tenant " + tenant_id)
+
+    @staticmethod
+    def get_repo_path_for_tenant(tenant_id, git_local_repo_path, is_multitenant):
+        repo_path = ""
+
+        if is_multitenant:
+            if tenant_id == AgentGitHandler.SUPER_TENANT_ID:
+                #super tenant, /repository/deploy/server/
+                super_tenant_repo_path = AgentGitHandler.cartridge_agent_config.super_tenant_repository_path
+                #"app_path"
+                repo_path += git_local_repo_path
+
+                if super_tenant_repo_path is not None  and super_tenant_repo_path != "":
+                    super_tenant_repo_path = super_tenant_repo_path if super_tenant_repo_path.startswith("/") else "/" + super_tenant_repo_path
+                    super_tenant_repo_path = super_tenant_repo_path if super_tenant_repo_path.endswith("/") else  super_tenant_repo_path + "/"
+                    #"app_path/repository/deploy/server/"
+                    repo_path += super_tenant_repo_path
+                else:
+                    #"app_path/repository/deploy/server/"
+                    repo_path += AgentGitHandler.SUPER_TENANT_REPO_PATH
+
+            else:
+                #normal tenant, /repository/tenants/tenant_id
+                tenant_repo_path = AgentGitHandler.cartridge_agent_config.tenant_repository_path
+                #"app_path"
+                repo_path += git_local_repo_path
+
+                if tenant_repo_path is not None and tenant_repo_path != "":
+                    tenant_repo_path = tenant_repo_path if tenant_repo_path.startswith("/") else "/" + tenant_repo_path
+                    tenant_repo_path = tenant_repo_path if tenant_repo_path.endswith("/") else tenant_repo_path + "/"
+                    #"app_path/repository/tenants/244653444"
+                    repo_path += tenant_repo_path + tenant_id
+                else:
+                    #"app_path/repository/tenants/244653444"
+                    repo_path += AgentGitHandler.TENANT_REPO_PATH + tenant_id
+
+                #tenant_dir_path = git_local_repo_path + AgentGitHandler.TENANT_REPO_PATH + tenant_id
+                cartridgeagentutils.create_dir(repo_path)
+        else:
+            #not multi tenant, app_path
+            repo_path = git_local_repo_path
+
+        AgentGitHandler.log.debug("Repo path returned : %r" % repo_path)
+        return repo_path
+
+    @staticmethod
+    def commit(repo_info):
+        """
+        Commits and pushes new artifacts to the remote repository
+        :param repo_info:
+        :return:
+        """
+        tenant_id = repo_info.tenant_id
+        repo_context = AgentGitHandler.get_repo_context(tenant_id)
+        gittle_repo = repo_context.gittle_repo
+        try:
+            modified = True if gittle_repo.modified_unstaged_files.count > 0 else False
+        except OSError:
+            # removed files
+            modified = True
+
+        if not modified:
+            AgentGitHandler.log.debug("No changes detected in the local repository for tenant " + tenant_id)
+            return
+
+        gittle_repo.stage(gittle_repo.untracked_files)
+        gittle_repo.stage(gittle_repo.removed_files)
+        gittle_repo.stage(gittle_repo.modified_unstaged_files)
+
+        #commit to local repositpory
+        commit_message = "tenant " + tenant_id + "'s artifacts committed to local repo at " + repo_context.local_repo_path
+
+        try:
+            commit_hash = gittle_repo.commit(name="First Author", email="author@example.org", message=commit_message)
+            AgentGitHandler.log.debug("Committed artifacts for tenant : " + tenant_id + " : " + commit_hash)
+        except:
+            AgentGitHandler.log.exception("Committing artifacts to local repository failed for tenant " + tenant_id)
+
+        #push to remote
+        try:
+            repo = repo_context.repo
+            #TODO: check key based authentication
+            credentialed_remote_url = AgentGitHandler.get_credentialed_remote_url(repo_context)
+            push_remote = repo.create_remote('push_remote', credentialed_remote_url)
+            push_remote.push()
+            AgentGitHandler.log.debug("Pushed artifacts for tenant : " + tenant_id)
+        except:
+            AgentGitHandler.log.exception("Pushing artifacts to remote repository failed for tenant " + tenant_id)
+
+    @staticmethod
+    def get_credentialed_remote_url(repo_context):
+        """
+        Creates a remote url including the credentials
+        :param repo_context:
+        :return:
+        """
+        username = repo_context.repo_username
+        password = repo_context.repo_password
+
+        raise NotImplementedError
+
+    @staticmethod
+    def schedule_artifact_update_scheduled_task(repo_info, auto_checkout, auto_commit, update_interval):
+        repo_context = AgentGitHandler.get_repo_context(repo_info.tenant_id)
+
+        if repo_context is None:
+            AgentGitHandler.log.error("Unable to schedule artifact sync task, repositoryContext null for tenant %r" % repo_info.tenant_id)
+            return
+
+        if repo_context.scheduled_update_task is None:
+            #TODO: make thread safe
+            artifact_update_task = ArtifactUpdateTask(repo_info, auto_checkout, auto_commit)
+            async_task = AsyncScheduledTask(update_interval, artifact_update_task)
+
+            repo_context.scheduled_update_task = async_task
+            async_task.start()
+            AgentGitHandler.log.info("Scheduled Artifact Synchronization Task for path %r" % repo_context.local_repo_path)
+        else:
+            AgentGitHandler.log.info("Artifact Synchronization Task for path %r already scheduled" % repo_context.local_repo_path)
+
+    @staticmethod
+    def remove_repo(tenant_id):
+        repo_context = AgentGitHandler.get_repo_context(tenant_id)
+
+        #stop artifact update task
+        repo_context.scheduled_update_task.terminate()
+
+        #remove git contents
+        cartridgeagentutils.delete_folder_tree(repo_context.local_repo_path)
+
+        AgentGitHandler.remove_repo_context(tenant_id)
+
+        if tenant_id == -1234:
+            if AgentGitHandler.cartridge_agent_config.is_multitenant:
+                extensionutils.execute_copy_artifact_extension(
+                    cartridgeagentconstants.SUPERTENANT_TEMP_PATH,
+                    AgentGitHandler.cartridge_agent_config.app_path + "/repository/deployment/server/"
+                )
+
+        AgentGitHandler.log.info("git repository deleted for tenant %r" % repo_context.tenant_id)
+
+        return True
+
+
+class ArtifactUpdateTask(Thread):
+
+    def __init__(self, repo_info, auto_checkout, auto_commit):
+        self.log = LogFactory().get_log(__name__)
+        Thread.__init__(self)
+        self.repo_info = repo_info
+        self.auto_checkout = auto_checkout
+        self.auto_commit = auto_commit
+
+    def run(self):
+        try:
+            if self.auto_checkout:
+                AgentGitHandler.checkout(self.repo_info)
+        except:
+            self.log.exception("Auto checkout task failed")
+
+        if self.auto_commit:
+            AgentGitHandler.commit(self.repo_info)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/gitrepository.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
new file mode 100644
index 0000000..98a8a44
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
@@ -0,0 +1,51 @@
+# 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.
+
+from ...util.asyncscheduledtask import AsyncScheduledTask
+from gittle import Gittle
+from git import *
+
+class GitRepository:
+    """
+    Represents a git repository inside a particular instance
+    """
+
+    def __init__(self):
+        self.repo_url = None
+        """ :type : str  """
+        self.local_repo_path = None
+        """ :type : str  """
+        self.cloned = False
+        """ :type : bool  """
+        self.repo = None
+        """ :type : git.repo.base.Repo  """
+        self.gittle_repo = None
+        """ :type : gittle.gittle.Gittle  """
+        self.tenant_id = None
+        """ :type : int  """
+        self.key_based_auth = False
+        """ :type : bool  """
+        self.repo_username = None
+        """ :type : str  """
+        self.repo_password = None
+        """ :type : str  """
+        self.is_multitenant = False
+        """ :type : bool  """
+        self.commit_enabled = False
+        """ :type : bool  """
+        self.scheduled_update_task = None
+        """:type : AsyncScheduledTask """
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/repositoryinformation.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/repositoryinformation.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/repositoryinformation.py
new file mode 100644
index 0000000..b67eada
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/repositoryinformation.py
@@ -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.
+
+class RepositoryInformation:
+    """
+    Holds repository information to be used in artifact management
+    """
+
+    def __init__(self, repo_url, repo_username, repo_password, repo_path, tenant_id, is_multitenant, commit_enabled):
+        self.repo_url = repo_url
+        """ :type : str  """
+        self.repo_username = repo_username
+        """ :type : str  """
+        self.repo_password = repo_password
+        """ :type : str  """
+        self.repo_path = repo_path
+        """ :type : str  """
+        self.tenant_id = tenant_id
+        """ :type : int  """
+        self.is_multitenant = is_multitenant
+        """ :type : bool  """
+        self.commit_enabled = commit_enabled
+        """ :type : bool  """
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/config/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/config/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/config/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/config/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/config/cartridgeagentconfiguration.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/config/cartridgeagentconfiguration.py b/tools/python-cartridge-agent/cartridgeagent/modules/config/cartridgeagentconfiguration.py
new file mode 100644
index 0000000..15871ba
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/config/cartridgeagentconfiguration.py
@@ -0,0 +1,346 @@
+# 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.
+
+import ConfigParser
+import os
+import socket
+
+from ..util.log import LogFactory
+
+
+class CartridgeAgentConfiguration:
+    """
+    Handles the configuration information of the particular Cartridge Agent
+    """
+    class __CartridgeAgentConfiguration:
+        def __init__(self):
+            # set log level
+            self.log = LogFactory().get_log(__name__)
+
+            self.payload_params = {}
+            self.properties = None
+
+            self.service_group = None
+            """ :type : str  """
+            self.is_clustered = False
+            """ :type : bool  """
+            self.service_name = None
+            """ :type : str  """
+            self.cluster_id = None
+            """ :type : str  """
+            self.network_partition_id = None
+            """ :type : str  """
+            self.partition_id = None
+            """ :type : str  """
+            self.member_id = None
+            """ :type : str  """
+            self.cartridge_key = None
+            """ :type : str  """
+            self.app_path = None
+            """ :type : str  """
+            self.repo_url = None
+            """ :type : str  """
+            self.ports = []
+            """ :type : list[str]  """
+            self.log_file_paths = []
+            """ :type : list[str]  """
+            self.is_multitenant = False
+            """ :type : bool  """
+            self.persistence_mappings = None
+            """ :type : str  """
+            self.is_commits_enabled = False
+            """ :type : bool  """
+            self.is_checkout_enabled = False
+            """ :type : bool  """
+            self.listen_address = None
+            """ :type : str  """
+            self.is_internal_repo = False
+            """ :type : bool  """
+            self.tenant_id = None
+            """ :type : str  """
+            self.lb_cluster_id = None
+            """ :type : str  """
+            self.min_count = None
+            """ :type : str  """
+            self.lb_private_ip = None
+            """ :type : str  """
+            self.lb_public_ip = None
+            """ :type : str  """
+            self.tenant_repository_path = None
+            """ :type : str  """
+            self.super_tenant_repository_path = None
+            """ :type : str  """
+            self.deployment = None
+            """ :type : str  """
+            self.manager_service_name = None
+            """ :type : str  """
+            self.worker_service_name = None
+            """ :type : str  """
+            self.is_primary = False
+            """ :type : bool  """
+
+            self.payload_params = {}
+            self.__read_conf_file()
+            self.__read_parameter_file()
+
+            self.initialized = False
+            """ :type : bool """
+
+            try:
+                self.service_group = self.payload_params[cartridgeagentconstants.SERVICE_GROUP] \
+                    if cartridgeagentconstants.SERVICE_GROUP in self.payload_params \
+                    else None
+
+                if cartridgeagentconstants.CLUSTERING in self.payload_params and \
+                        str(self.payload_params[cartridgeagentconstants.CLUSTERING]).strip().lower() == "true":
+                    self.is_clustered = True
+                else:
+                    self.is_clustered = False
+                # self.__isClustered = self.payload_params[
+                # cartridgeagentconstants.CLUSTERING] if cartridgeagentconstants.CLUSTERING in self.payload_params else None
+
+                self.service_name = self.read_property(cartridgeagentconstants.SERVICE_NAME)
+                self.cluster_id = self.read_property(cartridgeagentconstants.CLUSTER_ID)
+                self.network_partition_id = self.read_property(cartridgeagentconstants.NETWORK_PARTITION_ID, False)
+                self.partition_id = self.read_property(cartridgeagentconstants.PARTITION_ID, False)
+                self.member_id = self.get_member_id(cartridgeagentconstants.MEMBER_ID)
+                self.cartridge_key = self.read_property(cartridgeagentconstants.CARTRIDGE_KEY)
+                self.app_path = self.read_property(cartridgeagentconstants.APP_PATH, False)
+                self.repo_url = self.read_property(cartridgeagentconstants.REPO_URL, False)
+                self.ports = str(self.read_property(cartridgeagentconstants.PORTS)).split("|")
+
+                try:
+                    self.log_file_paths = str(
+                        self.read_property(cartridgeagentconstants.LOG_FILE_PATHS)).strip().split("|")
+                except ParameterNotFoundException as ex:
+                    self.log.debug("Cannot read log file path : %r" % ex.get_message())
+                    self.log_file_paths = None
+
+                is_multi_str = self.read_property(cartridgeagentconstants.MULTITENANT)
+                self.is_multitenant = True if str(is_multi_str).lower().strip() == "true" else False
+
+                try:
+                    self.persistence_mappings = self.read_property(
+                        cartridgeagentconstants.PERSISTENCE_MAPPING)
+                except ParameterNotFoundException as ex:
+                    self.log.debug("Cannot read persistence mapping : %r" % ex.get_message())
+                    self.persistence_mappings = None
+
+                try:
+                    is_commit_str = self.read_property(cartridgeagentconstants.COMMIT_ENABLED)
+                    self.is_commits_enabled = True if str(is_commit_str).lower().strip() == "true" else False
+                except ParameterNotFoundException:
+                    try:
+                        is_commit_str = self.read_property(cartridgeagentconstants.AUTO_COMMIT)
+                        self.is_commits_enabled = True if str(is_commit_str).lower().strip() == "true" else False
+                    except ParameterNotFoundException:
+                        self.log.info(
+                            "%r is not found and setting it to false" % cartridgeagentconstants.COMMIT_ENABLED)
+                        self.is_commits_enabled = False
+
+                auto_checkout_str = self.read_property(cartridgeagentconstants.AUTO_CHECKOUT, False)
+                self.is_checkout_enabled = True if str(auto_checkout_str).lower().strip() == "true" else False
+
+                self.listen_address = self.read_property(
+                    cartridgeagentconstants.LISTEN_ADDRESS, False)
+
+                try:
+                    int_repo_str = self.read_property(cartridgeagentconstants.PROVIDER)
+                    self.is_internal_repo = True if str(int_repo_str).strip().lower() == cartridgeagentconstants.INTERNAL else False
+                except ParameterNotFoundException:
+                    self.log.info(" INTERNAL payload parameter is not found")
+                    self.is_internal_repo = False
+
+                self.tenant_id = self.read_property(cartridgeagentconstants.TENANT_ID)
+                self.lb_cluster_id = self.read_property(cartridgeagentconstants.LB_CLUSTER_ID, False)
+                self.min_count = self.read_property(cartridgeagentconstants.MIN_INSTANCE_COUNT, False)
+                self.lb_private_ip = self.read_property(cartridgeagentconstants.LB_PRIVATE_IP, False)
+                self.lb_public_ip = self.read_property(cartridgeagentconstants.LB_PUBLIC_IP, False)
+                self.tenant_repository_path = self.read_property(cartridgeagentconstants.TENANT_REPO_PATH, False)
+                self.super_tenant_repository_path = self.read_property(cartridgeagentconstants.SUPER_TENANT_REPO_PATH, False)
+
+                try:
+                    self.deployment = self.read_property(
+                        cartridgeagentconstants.DEPLOYMENT)
+                except ParameterNotFoundException:
+                    self.deployment = None
+
+                # Setting worker-manager setup - manager service name
+                if self.deployment is None:
+                    self.manager_service_name = None
+
+                if str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower():
+                    self.manager_service_name = self.service_name
+
+                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
+                    self.deployment = self.read_property(
+                        cartridgeagentconstants.MANAGER_SERVICE_TYPE)
+
+                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_DEFAULT.lower():
+                    self.deployment = None
+                else:
+                    self.deployment = None
+
+                # Setting worker-manager setup - worker service name
+                if self.deployment is None:
+                    self.worker_service_name = None
+
+                if str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
+                    self.manager_service_name = self.service_name
+
+                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower():
+                    self.deployment = self.read_property(
+                        cartridgeagentconstants.WORKER_SERVICE_TYPE)
+
+                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_DEFAULT.lower():
+                    self.deployment = None
+                else:
+                    self.deployment = None
+
+                try:
+                    self.is_primary = self.read_property(
+                        cartridgeagentconstants.CLUSTERING_PRIMARY_KEY)
+                except ParameterNotFoundException:
+                    self.is_primary = None
+            except ParameterNotFoundException as ex:
+                raise RuntimeError(ex)
+
+            self.log.info("Cartridge agent configuration initialized")
+
+            self.log.debug("service-name: %r" % self.service_name)
+            self.log.debug("cluster-id: %r" % self.cluster_id)
+            self.log.debug(
+                "network-partition-id: %r" % self.network_partition_id)
+            self.log.debug("partition-id: %r" % self.partition_id)
+            self.log.debug("member-id: %r" % self.member_id)
+            self.log.debug("cartridge-key: %r" % self.cartridge_key)
+            self.log.debug("app-path: %r" % self.app_path)
+            self.log.debug("repo-url: %r" % self.repo_url)
+            self.log.debug("ports: %r" % str(self.ports))
+            self.log.debug("lb-private-ip: %r" % self.lb_private_ip)
+            self.log.debug("lb-public-ip: %r" % self.lb_public_ip)
+
+        def get_member_id(self, member_id_field):
+            """
+            Reads the member id from the payload file or configuration file. If neither of
+            these sources contain the member id, the hostname is assigned to it and returned.
+            :param str member_id_field: the key of the member id to lookup
+            :return: The member id
+            :rtype : str
+            """
+            try:
+                member_id = self.read_property(member_id_field)
+            except ParameterNotFoundException:
+                try:
+                    self.log.info("Reading hostname from container")
+                    member_id = socket.gethostname()
+                except:
+                    self.log.exception("Hostname can not be resolved")
+                    member_id = "unknown"
+
+            self.log.debug("MemberId  is taking the value of hostname : [" + member_id + "] ")
+            return member_id
+
+        def __read_conf_file(self):
+            """
+            Reads and stores the agent's configuration file
+            :return: void
+            """
+
+            conf_file_path = os.path.abspath(os.path.dirname(__file__)).split("modules")[0] + "agent.conf"
+            self.log.debug("Config file path : %r" % conf_file_path)
+            self.properties = ConfigParser.SafeConfigParser()
+            self.properties.read(conf_file_path)
+
+        def __read_parameter_file(self):
+            """
+            Reads the payload file of the cartridge and stores the values in a dictionary
+            :return: void
+            """
+
+            param_file = self.read_property(cartridgeagentconstants.PARAM_FILE_PATH, False)
+            self.log.debug("Param file path : %r" % param_file)
+
+            try:
+                if param_file is not None:
+                    metadata_file = open(param_file)
+                    metadata_payload_content = metadata_file.read()
+                    for param in metadata_payload_content.split(","):
+                        if param.strip() != "":
+                            param_value = param.strip().split("=")
+                            self.payload_params[param_value[0]] = param_value[1]
+
+                    # self.payload_params = dict(
+                    #     param.split("=") for param in metadata_payload_content.split(","))
+                    metadata_file.close()
+                else:
+                    self.log.error("File not found: %r" % param_file)
+            except:
+                self.log.exception(
+                    "Could not read launch parameter file, hence trying to read from System properties.")
+
+        def read_property(self, property_key, critical=True):
+            """
+            Returns the value of the provided property
+            :param str property_key: the name of the property to be read
+            :return: Value of the property,
+            :rtype: str
+            :exception: ParameterNotFoundException if the provided property cannot be found
+            """
+
+            if self.properties.has_option("agent", property_key):
+                self.log.debug("Has key: %r" % property_key)
+                temp_str = self.properties.get("agent", property_key)
+                if temp_str != "" and temp_str is not None:
+                    if str(temp_str).strip().lower() == "null":
+                        return ""
+                    else:
+                        return str(temp_str).strip()
+
+            if property_key in self.payload_params:
+                temp_str = self.payload_params[property_key]
+                if temp_str != "" and temp_str is not None:
+                    if str(temp_str).strip().lower() == "null":
+                        return ""
+                    else:
+                        return str(temp_str).strip()
+
+            if critical:
+                raise ParameterNotFoundException("Cannot find the value of required parameter: %r" % property_key)
+
+    instance = None
+    """ :type : __CartridgeAgentConfiguration"""
+
+    # def __new__(cls, *args, **kwargs):
+    #     if not CartridgeAgentConfiguration.instance:
+    #         CartridgeAgentConfiguration.instance = CartridgeAgentConfiguration.__CartridgeAgentConfiguration()
+    #
+    #     return CartridgeAgentConfiguration.instance
+
+    def __init__(self):
+        if not CartridgeAgentConfiguration.instance:
+            CartridgeAgentConfiguration.instance = CartridgeAgentConfiguration.__CartridgeAgentConfiguration()
+
+    def __getattr__(self, name):
+        return getattr(self.instance, name)
+
+    def __setattr__(self, name, value):
+        return setattr(self.instance, name, value)
+
+
+from ..exception.parameternotfoundexception import ParameterNotFoundException
+from ..util import cartridgeagentconstants

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/agent.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/agent.py
new file mode 100644
index 0000000..1859d8a
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/agent.py
@@ -0,0 +1,202 @@
+# 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.
+
+from thrift.publisher import *
+from ..util.log import *
+
+
+class StreamDefinition:
+    """
+    Represents a BAM/CEP stream definition
+    """
+
+    STRING = 'STRING'
+    DOUBLE = 'DOUBLE'
+    INT = 'INT'
+    LONG = 'LONG'
+    BOOL = 'BOOL'
+
+    def __init__(self):
+        self.name = None
+        """:type : str"""
+        self.version = None
+        """:type : str"""
+        self.nickname = None
+        """:type : str"""
+        self.description = None
+        """:type : str"""
+        self.meta_data = []
+        """:type : list[str]"""
+        self.correlation_data = []
+        """:type : list[str]"""
+        self.payload_data = []
+        """:type : list[str]"""
+        self.stream_id =  None
+        """ :type : str """
+
+    def add_metadata_attribute(self, attr_name, attr_type):
+        self.meta_data.append({"name": attr_name, "type": attr_type})
+
+    def add_payloaddata_attribute(self, attr_name, attr_type):
+        self.payload_data.append({"name": attr_name, "type": attr_type})
+
+    def add_correlationdata_attribute(self, attr_name, attr_type):
+        self.correlation_data.append({"name": attr_name, "type": attr_type})
+
+    def __str__(self):
+        """
+        To string override
+        """
+
+        json_str = "{"
+        json_str += "\"name\":\"" + self.name + "\","
+        json_str += "\"version\":\"" + self.version + "\","
+        json_str += "\"nickName\":\"" + self.nickname + "\","
+        json_str += "\"description\":\"" + self.description + "\","
+
+        # add metadata attributes if exists
+        if len(self.meta_data) > 0:
+            json_str += "\"metaData\":["
+            for metadatum in self.meta_data:
+                json_str += "{\"name\":\"" + metadatum["name"] + "\", \"type\": \"" + metadatum["type"] + "\"},"
+
+            json_str = json_str[:-1] + "],"
+
+        # add correlationdata attributes if exists
+        if len(self.correlation_data) > 0:
+            json_str += "\"correlationData\":["
+            for coredatum in self.correlation_data:
+                json_str += "{\"name\":\"" + coredatum["name"] + "\", \"type\": \"" + coredatum["type"] + "\"},"
+
+            json_str = json_str[:-1] + "],"
+
+        # add payloaddata attributes if exists
+        if len(self.payload_data) > 0:
+            json_str += "\"payloadData\":["
+            for payloaddatum in self.payload_data:
+                json_str += "{\"name\":\"" + payloaddatum["name"] + "\", \"type\": \"" + payloaddatum["type"] + "\"},"
+
+            json_str = json_str[:-1] + "],"
+
+        json_str = json_str[:-1] + "}"
+
+        return json_str
+
+
+class ThriftEvent:
+    """
+    Represents an event to be published to a BAM/CEP monitoring server
+    """
+    def __init__(self):
+        self.metaData = []
+        """:type : list[str]"""
+        self.correlationData = []
+        """:type : list[str]"""
+        self.payloadData = []
+        """:type : list[str]"""
+
+
+class ThriftPublisher:
+    """
+    Handles publishing events to BAM/CEP through thrift using the provided address and credentials
+    """
+    log = LogFactory().get_log(__name__)
+
+    def __init__(self, ip, port, username, password, stream_definition):
+        """
+        Initializes a ThriftPublisher object.
+
+        At initialization a ThriftPublisher connects and defines a stream definition. A connection
+        should be disconnected after all the publishing has been done.
+
+        :param str ip: IP address of the monitoring server
+        :param str port: Port of the monitoring server
+        :param str username: Username
+        :param str password: Password
+        :param StreamDefinition stream_definition: StreamDefinition object for this particular connection
+        :return: ThriftPublisher object
+        :rtype: ThriftPublisher
+        """
+        try:
+            port_number = int(port)
+        except ValueError:
+            raise RuntimeError("Port number for Thrift Publisher is invalid: %r" % port)
+
+        self.__publisher = Publisher(ip, port_number)
+        self.__publisher.connect(username, password)
+        self.__publisher.defineStream(str(stream_definition))
+
+        self.stream_definition = stream_definition
+        self.stream_id = self.__publisher.streamId
+        self.ip = ip
+        self.port = port
+        self.username = username
+        self.password = password
+
+    def publish(self, event):
+        """
+        Publishes the given event by creating the event bundle from the log event
+
+        :param ThriftEvent event: The log event to be published
+        :return: void
+        """
+        event_bundler = EventBundle()
+        ThriftPublisher.assign_attributes(event.metaData, event_bundler)
+        ThriftPublisher.assign_attributes(event.correlationData, event_bundler)
+        ThriftPublisher.assign_attributes(event.payloadData, event_bundler)
+
+        self.__publisher.publish(event_bundler)
+        self.log.debug("Published event to thrift stream [%r]" % self.stream_id)
+
+    def disconnect(self):
+        """
+        Disconnect the thrift publisher
+        :return: void
+        """
+        self.__publisher.disconnect()
+
+    @staticmethod
+    def assign_attributes(attributes, event_bundler):
+        """
+        Adds the given attributes to the given event bundler according to type of each attribute
+        :param list attributes: attributes to be assigned
+        :param EventBundle event_bundler: Event bundle to assign attributes to
+        :return: void
+        """
+
+        # __intAttributeList = []
+        # __longAttributeList = []
+        # __doubleAttributeList = []
+        # __boolAttributeList = []
+        # __stringAttributeList = []
+
+        if attributes is not None and len(attributes) > 0:
+            for attrib in attributes:
+                if isinstance(attrib, int):
+                    event_bundler.addIntAttribute(attrib)
+                elif isinstance(attrib, long):
+                    event_bundler.addLongAttribute(attrib)
+                elif isinstance(attrib, float):
+                    event_bundler.addDoubleAttribute(attrib)
+                elif isinstance(attrib, bool):
+                    event_bundler.addBoolAttribute(attrib)
+                elif isinstance(attrib, str):
+                    event_bundler.addStringAttribute(attrib)
+                else:
+                    ThriftPublisher.log.error("Undefined attribute type: %r" % attrib)
+        else:
+            ThriftPublisher.log.debug("Empty attribute list")

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py
new file mode 100644
index 0000000..adefd8e
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py
@@ -0,0 +1 @@
+__all__ = ['ttypes', 'constants']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py
new file mode 100644
index 0000000..36943ba
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py
@@ -0,0 +1,8 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+


[15/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/status/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/status/events.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/status/events.py
deleted file mode 100644
index c000c55..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/event/instance/status/events.py
+++ /dev/null
@@ -1,98 +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.
-
-import json
-
-
-class InstanceActivatedEvent:
-    def __init__(self, service_name, cluster_id, network_partition_id, parition_id, member_id):
-        self.serviceName = service_name
-        """ :type : str  """
-        self.clusterId = cluster_id
-        """ :type : str  """
-        self.networkPartitionId = network_partition_id
-        """ :type : str  """
-        self.partitionId = parition_id
-        """ :type : str  """
-        self.memberId = member_id
-        """ :type : str  """
-
-    def to_json(self):
-        return to_json(self)
-
-
-class InstanceStartedEvent:
-    def __init__(self, service_name, cluster_id, network_partition_id, parition_id, member_id):
-        self.serviceName = service_name
-        """ :type : str  """
-        self.clusterId = cluster_id
-        """ :type : str  """
-        self.networkPartitionId = network_partition_id
-        """ :type : str  """
-        self.partitionId = parition_id
-        """ :type : str  """
-        self.memberId = member_id
-        """ :type : str  """
-
-    def to_json(self):
-        return to_json(self)
-
-
-class InstanceMaintenanceModeEvent:
-
-    def __init__(self, service_name, cluster_id, network_partition_id, partition_id, member_id):
-        self.serviceName = service_name
-        """ :type : str  """
-        self.clusterId = cluster_id
-        """ :type : str  """
-        self.networkPartitionId = network_partition_id
-        """ :type : str  """
-        self.partitionId = partition_id
-        """ :type : str  """
-        self.memberId = member_id
-        """ :type : str  """
-
-    def to_json(self):
-        return to_json(self)
-
-
-class InstanceReadyToShutdownEvent:
-
-    def __init__(self, service_name, cluster_id, network_partition_id, partition_id, member_id):
-        self.serviceName = service_name
-        """ :type : str  """
-        self.clusterId = cluster_id
-        """ :type : str  """
-        self.networkPartitionId = network_partition_id
-        """ :type : str  """
-        self.partitionId = partition_id
-        """ :type : str  """
-        self.memberId = member_id
-        """ :type : str  """
-
-    def to_json(self):
-        return to_json(self)
-
-
-def to_json(instance):
-    """
-    common function to serialize status event object
-    :param obj instance:
-    :return: serialized json string
-    :rtype str
-    """
-    return json.dumps(instance, default=lambda o: o.__dict__, sort_keys=True, indent=4)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/event/tenant/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/tenant/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/tenant/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/event/tenant/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/event/tenant/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/tenant/events.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/tenant/events.py
deleted file mode 100644
index def2b64..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/event/tenant/events.py
+++ /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.
-
-import json
-from ... tenant.tenantcontext import *
-
-
-class SubscriptionDomainAddedEvent():
-
-    def __init__(self):
-        self.tenant_id = None
-        """ :type : int  """
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_ids = None
-        """ :type : list[str]  """
-        self.domain_name = None
-        """ :type : str  """
-        self.application_context = None
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = SubscriptionDomainAddedEvent()
-
-        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
-        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.domain_name = json_obj["domainName"] if "domainName" in json_obj else None
-        instance.application_context = json_obj["applicationContext"] if "applicationContext" in json_obj else None
-
-        return instance
-
-
-class SubscriptionDomainRemovedEvent:
-
-    def __init__(self, tenant_id, service_name, cluster_ids, domain_name):
-        self.tenant_id = tenant_id
-        """ :type : int  """
-        self.service_name = service_name
-        """ :type : str  """
-        self.cluster_ids = cluster_ids
-        """ :type : list[str]  """
-        self.domain_name = domain_name
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = SubscriptionDomainRemovedEvent()
-
-        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
-        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.domain_name = json_obj["domainName"] if "domainName" in json_obj else None
-
-        return instance
-
-
-class CompleteTenantEvent:
-
-    def __init__(self):
-        self.tenants = []
-        """ :type : list[Tenant]  """
-        self.tenant_list_json = None
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = CompleteTenantEvent()
-        instance.tenants = []
-
-        tenants_str = json_obj["tenants"] if "tenants" in json_obj else None
-        instance.tenant_list_json = tenants_str
-        if tenants_str is not None:
-            for tenant_str in tenants_str:
-                tenant_obj = Tenant(int(tenant_str["tenantId"]), tenant_str["tenantDomain"])
-                for service_name in tenant_str["serviceNameSubscriptionMap"]:
-                    sub_str = tenant_str["serviceNameSubscriptionMap"][service_name]
-                    sub = Subscription(sub_str["serviceName"], sub_str["clusterIds"])
-                    for domain_name in sub_str["subscriptionDomainMap"]:
-                        subdomain_str = sub_str["subscriptionDomainMap"][domain_name]
-                        sub.add_subscription_domain(domain_name, subdomain_str["applicationContext"])
-                    tenant_obj.add_subscription(sub)
-                instance.tenants.append(tenant_obj)
-
-        return instance
-
-
-class TenantSubscribedEvent:
-
-    def __init__(self):
-        self.tenant_id = None
-        """ :type : int  """
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_ids = None
-        """ :type : list[str]  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = TenantSubscribedEvent()
-
-        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
-
-        return instance
-
-
-class TenantUnsubscribedEvent:
-
-    def __init__(self):
-        self.tenant_id = None
-        """ :type : int  """
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_ids = None
-        """ :type : list[str]  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = TenantUnsubscribedEvent()
-
-        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
-
-        return instance
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/events.py b/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/events.py
deleted file mode 100644
index 52c7c19..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/event/topology/events.py
+++ /dev/null
@@ -1,280 +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.
-
-import json
-
-from ... topology.topologycontext import *
-
-
-class MemberActivatedEvent:
-
-    def __init__(self):
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_id = None
-        """ :type : str  """
-        self.network_partition_id = None
-        """ :type : str  """
-        self.partition_id = None
-        """ :type : str  """
-        self.member_id = None
-        """ :type : str  """
-        self.port_map = {}
-        """ :type : dict[str, Port]  """
-        self.member_ip = None
-        """ :type : str  """
-
-    def get_port(self, proxy_port):
-        """
-        Returns the port object of the provided port id
-        :param str proxy_port:
-        :return: Port object, None if the port id is invalid
-        :rtype: topology.topologycontext.Port
-        """
-        if proxy_port in self.port_map:
-            return self.port_map[proxy_port]
-
-        return None
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = MemberActivatedEvent()
-
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
-        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
-        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
-        #instance.port_map = json_obj["portMap"] if "portMap" in json_obj else {}
-        instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None
-
-        for port_proxy in json_obj["portMap"]:
-            port_str = json_obj["portMap"][port_proxy]
-            port_obj = Port(port_str["protocol"], port_str["value"], port_proxy)
-            instance.port_map[port_proxy] = port_obj
-
-        return instance
-
-
-class MemberTerminatedEvent:
-
-    def __init__(self):
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_id = None
-        """ :type : str  """
-        self.network_partition_id = None
-        """ :type : str  """
-        self.partition_id = None
-        """ :type : str  """
-        self.member_id = None
-        """ :type : str  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = MemberTerminatedEvent()
-
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
-        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
-        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
-        instance.properties = json_obj["properties"] if "properties" in json_obj else None
-
-        return instance
-
-
-class MemberSuspendedEvent:
-
-    def __init__(self):
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_id = None
-        """ :type : str  """
-        self.network_partition_id = None
-        """ :type : str  """
-        self.partition_id = None
-        """ :type : str  """
-        self.member_id = None
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = MemberSuspendedEvent()
-
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
-        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
-        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
-
-        return instance
-
-
-class CompleteTopologyEvent:
-
-    def __init__(self):
-        self.topology = None
-        """ :type :  Topology """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = CompleteTopologyEvent()
-
-        topology_str = json_obj["topology"] if "topology" in json_obj else None
-        if topology_str is not None:
-            topology_obj = Topology()
-            topology_obj.json_str = topology_str
-
-            #add service map
-            for service_name in topology_str["serviceMap"]:
-                service_str = topology_str["serviceMap"][service_name]
-
-                service_obj = Service(service_name, service_str["serviceType"])
-                service_obj.properties = service_str["properties"]
-                # add ports to port map
-                for port_proxy in service_str["portMap"]:
-                    port_str = service_str["portMap"][port_proxy]
-                    port_obj = Port(port_str["protocol"], port_str["value"], port_proxy)
-                    service_obj.add_port(port_obj)
-
-                #add cluster map
-                for cluster_id in service_str["clusterIdClusterMap"]:
-                    cluster_str = service_str["clusterIdClusterMap"][cluster_id]
-                    cl_service_name = cluster_str["serviceName"]
-                    cl_autoscale_policy_name = cluster_str["autoscalePolicyName"]
-                    cl_deployment_policy_name = cluster_str["deploymentPolicyName"] if "deploymentPolicyName" in cluster_str else None
-
-                    cluster_obj = Cluster(cl_service_name, cluster_id, cl_deployment_policy_name, cl_autoscale_policy_name)
-                    cluster_obj.hostnames = cluster_str["hostNames"]
-                    cluster_obj.tenant_range = cluster_str["tenantRange"] if "tenantRange" in cluster_str else None
-                    cluster_obj.is_lb_cluster = cluster_str["isLbCluster"]
-                    cluster_obj.is_kubernetes_cluster = cluster_str["isKubernetesCluster"]
-                    cluster_obj.status = cluster_str["status"]
-                    cluster_obj.load_balancer_algorithm_name = cluster_str["loadBalanceAlgorithmName"] if "loadBalanceAlgorithmName" in cluster_str else None
-                    cluster_obj.properties = cluster_str["properties"]
-                    cluster_obj.member_list_json = cluster_str["memberMap"]
-
-                    #add member map
-                    for member_id in cluster_str["memberMap"]:
-                        member_str = cluster_str["memberMap"][member_id]
-                        mm_service_name = member_str["serviceName"]
-                        mm_cluster_id = member_str["clusterId"]
-                        mm_network_partition_id = member_str["networkPartitionId"] if "networkPartitionId" in member_str else None
-                        mm_partition_id = member_str["partitionId"] if "partitionId" in member_str else None
-
-                        member_obj = Member(mm_service_name, mm_cluster_id, mm_network_partition_id, mm_partition_id, member_id)
-                        member_obj.member_public_ip = member_str["memberPublicIp"]
-                        member_obj.status = member_str["status"]
-                        member_obj.member_ip = member_str["memberIp"]
-                        member_obj.properties = member_str["properties"]
-                        member_obj.lb_cluster_id = member_str["lbClusterId"] if "lbClusterId" in member_str else None
-                        member_obj.json_str = member_str
-
-                        #add port map
-                        for mm_port_proxy in member_str["portMap"]:
-                            mm_port_str = member_str["portMap"][mm_port_proxy]
-                            mm_port_obj = Port(mm_port_str["protocol"], mm_port_str["value"], mm_port_proxy)
-                            member_obj.add_port(mm_port_obj)
-                        cluster_obj.add_member(member_obj)
-                    service_obj.add_cluster(cluster_obj)
-                topology_obj.add_service(service_obj)
-            instance.topology = topology_obj
-
-        return instance
-
-    def get_topology(self):
-        return self.topology
-
-
-class MemberStartedEvent:
-
-    def __init__(self):
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_id = None
-        """ :type : str  """
-        self.network_partition_id = None
-        """ :type : str  """
-        self.partition_id = None
-        """ :type : str  """
-        self.member_id = None
-        """ :type : str  """
-        self.status = None
-        """ :type : str  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = MemberStartedEvent()
-
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
-        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
-        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
-        instance.properties = json_obj["properties"] if "properties" in json_obj else None
-
-        return instance
-
-
-class InstanceSpawnedEvent:
-
-    def __init__(self):
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_id = None
-        """ :type : str  """
-        self.network_partition_id = None
-        """ :type : str  """
-        self.partition_id = None
-        """ :type : str  """
-        self.member_id = None
-        """ :type : str  """
-        self.lb_cluster_id = None
-        """ :type : str  """
-        self.member_public_ip = None
-        """ :type : str  """
-        self.member_ip = None
-        """ :type : str  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = InstanceSpawnedEvent()
-
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
-        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
-        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
-        instance.lb_cluster_id = json_obj["lbClusterId"] if "lbClusterId" in json_obj else None
-        instance.member_public_ip = json_obj["memberPublicIp"] if "memberPublicIp" in json_obj else None
-        instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None
-        instance.properties = json_obj["properties"]
-
-        return instance
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/exception/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/exception/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/exception/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/exception/parameternotfoundexception.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/exception/parameternotfoundexception.py b/tools/python-cartridge-agent/cartridge-agent/modules/exception/parameternotfoundexception.py
deleted file mode 100644
index 88deafd..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/exception/parameternotfoundexception.py
+++ /dev/null
@@ -1,35 +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.
-
-class ParameterNotFoundException(Exception):
-    """
-    Exception raised when a property is not present in the configuration or the payload
-    of the cartridge agent
-    """
-    __message = None
-
-    def __init__(self, message):
-        Exception.__init__(self, message)
-        self.__message = message
-
-    def get_message(self):
-        """
-        The message provided when the exception is raised
-        :return: message
-        :rtype: str
-        """
-        return self.__message

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/extensions/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/extensions/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/extensions/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/extensions/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/extensions/abstractextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/extensions/abstractextensionhandler.py b/tools/python-cartridge-agent/cartridge-agent/modules/extensions/abstractextensionhandler.py
deleted file mode 100644
index 1f2df10..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/extensions/abstractextensionhandler.py
+++ /dev/null
@@ -1,78 +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.
-
-class AbstractExtensionHandler:
-
-    def on_instance_started_event(self):
-        raise NotImplementedError
-
-    def on_instance_activated_event(self):
-        raise NotImplementedError
-
-    def on_artifact_updated_event(self, artifacts_updated_event):
-        raise NotImplementedError
-
-    def on_artifact_update_scheduler_event(self, tenant_id):
-        raise NotImplementedError
-
-    def on_instance_cleanup_cluster_event(self, instance_cleanup_cluster_event):
-        raise NotImplementedError
-
-    def on_instance_cleanup_member_event(self, instance_cleanup_member_event):
-        raise NotImplementedError
-
-    def on_member_activated_event(self, member_activated_event):
-        raise NotImplementedError
-
-    def on_complete_topology_event(self, complete_topology_event):
-        raise NotImplementedError
-
-    def on_instance_spawned_event(self, instance_spawned_event):
-        raise NotImplementedError
-
-    def on_complete_tenant_event(self, complete_tenant_event):
-        raise NotImplementedError
-
-    def on_member_terminated_event(self, member_terminated_event):
-        raise NotImplementedError
-
-    def on_member_suspended_event(self, member_suspended_event):
-        raise NotImplementedError
-
-    def on_member_started_event(self, member_started_event):
-        raise NotImplementedError
-
-    def start_server_extension(self):
-        raise NotImplementedError
-
-    def volume_mount_extension(self, persistence_mappings_payload):
-        raise NotImplementedError
-
-    def on_subscription_domain_added_event(self, subscription_domain_added_event):
-        raise NotImplementedError
-
-    def on_subscription_domain_removed_event(self, subscription_domain_removed_event):
-        raise NotImplementedError
-
-    def on_copy_artifacts_extension(self, src, des):
-        raise NotImplementedError
-
-    def on_tenant_subscribed_event(self, tenant_subscribed_event):
-            raise NotImplementedError
-
-    def on_tenant_unsubscribed_event(self, tenant_unsubscribed_event):
-            raise NotImplementedError

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/extensions/defaultextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/extensions/defaultextensionhandler.py b/tools/python-cartridge-agent/cartridge-agent/modules/extensions/defaultextensionhandler.py
deleted file mode 100644
index 8a7ccc0..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/extensions/defaultextensionhandler.py
+++ /dev/null
@@ -1,789 +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.
-
-import time
-import json
-
-from abstractextensionhandler import AbstractExtensionHandler
-from ..util import extensionutils, cartridgeagentutils
-
-
-class DefaultExtensionHandler(AbstractExtensionHandler):
-    """
-    Default implementation of the AbstractExtensionHandler
-    """
-    log = None
-
-    def __init__(self):
-        self.log = LogFactory().get_log(__name__)
-        self.wk_members = []
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-    def on_instance_started_event(self):
-        try:
-            self.log.debug("Processing instance started event...")
-            if self.cartridge_agent_config.is_multitenant:
-                artifact_source = "%r/repository/deployment/server/" % self.cartridge_agent_config.app_path
-                artifact_dest = cartridgeagentconstants.SUPERTENANT_TEMP_PATH
-                extensionutils.execute_copy_artifact_extension(artifact_source, artifact_dest)
-
-            env_params = {}
-            extensionutils.execute_instance_started_extension(env_params)
-        except:
-            self.log.exception("Error processing instance started event")
-
-    def on_instance_activated_event(self):
-        extensionutils.execute_instance_activated_extension()
-
-    def on_artifact_updated_event(self, artifacts_updated_event):
-        self.log.info("Artifact update event received: [tenant] %r [cluster] %r [status] %r" %
-                      (artifacts_updated_event.tenant_id, artifacts_updated_event.cluster_id,
-                       artifacts_updated_event.status))
-
-        cluster_id_event = str(artifacts_updated_event.cluster_id).strip()
-        cluster_id_payload = self.cartridge_agent_config.cluster_id
-        repo_url = str(artifacts_updated_event.repo_url).strip()
-
-        if (repo_url != "") and (cluster_id_payload is not None) and (cluster_id_payload == cluster_id_event):
-            local_repo_path = self.cartridge_agent_config.app_path
-
-            secret = self.cartridge_agent_config.cartridge_key
-            repo_password = cartridgeagentutils.decrypt_password(artifacts_updated_event.repo_password, secret)
-
-            repo_username = artifacts_updated_event.repo_username
-            tenant_id = artifacts_updated_event.tenant_id
-            is_multitenant = self.cartridge_agent_config.is_multitenant
-            commit_enabled = artifacts_updated_event.commit_enabled
-
-            self.log.info("Executing git checkout")
-
-            # create repo object
-            repo_info = RepositoryInformation(repo_url, repo_username, repo_password, local_repo_path, tenant_id,
-                                              is_multitenant, commit_enabled)
-
-            # checkout code
-            subscribe_run, repo_context = agentgithandler.AgentGitHandler.checkout(repo_info)
-            # repo_context = checkout_result["repo_context"]
-            # execute artifact updated extension
-            env_params = {"STRATOS_ARTIFACT_UPDATED_CLUSTER_ID": artifacts_updated_event.cluster_id,
-                          "STRATOS_ARTIFACT_UPDATED_TENANT_ID": artifacts_updated_event.tenant_id,
-                          "STRATOS_ARTIFACT_UPDATED_REPO_URL": artifacts_updated_event.repo_url,
-                          "STRATOS_ARTIFACT_UPDATED_REPO_PASSWORD": artifacts_updated_event.repo_password,
-                          "STRATOS_ARTIFACT_UPDATED_REPO_USERNAME": artifacts_updated_event.repo_username,
-                          "STRATOS_ARTIFACT_UPDATED_STATUS": artifacts_updated_event.status}
-
-            extensionutils.execute_artifacts_updated_extension(env_params)
-
-            if subscribe_run:
-                # publish instanceActivated
-                cartridgeagentpublisher.publish_instance_activated_event()
-
-            update_artifacts = self.cartridge_agent_config.read_property(cartridgeagentconstants.ENABLE_ARTIFACT_UPDATE, False)
-            update_artifacts = True if str(update_artifacts).strip().lower() == "true" else False
-            if update_artifacts:
-                auto_commit = self.cartridge_agent_config.is_commits_enabled
-                auto_checkout = self.cartridge_agent_config.is_checkout_enabled
-
-                try:
-                    update_interval = len(
-                        self.cartridge_agent_config.read_property(cartridgeagentconstants.ARTIFACT_UPDATE_INTERVAL, False))
-                except ParameterNotFoundException:
-                    self.log.exception("Invalid artifact sync interval specified ")
-                    update_interval = 10
-                except ValueError:
-                    self.log.exception("Invalid artifact sync interval specified ")
-                    update_interval = 10
-
-                self.log.info("Artifact updating task enabled, update interval: %r seconds" % update_interval)
-
-                self.log.info("Auto Commit is turned %r " % "on" if auto_commit else "off")
-                self.log.info("Auto Checkout is turned %r " % "on" if auto_checkout else "off")
-
-                agentgithandler.AgentGitHandler.schedule_artifact_update_scheduled_task(repo_info, auto_checkout, auto_commit,
-                                                                        update_interval)
-
-    def on_artifact_update_scheduler_event(self, tenant_id):
-        env_params = {"STRATOS_ARTIFACT_UPDATED_TENANT_ID": tenant_id, "STRATOS_ARTIFACT_UPDATED_SCHEDULER": True}
-
-        extensionutils.execute_artifacts_updated_extension(env_params)
-
-    def on_instance_cleanup_cluster_event(self, instance_cleanup_cluster_event):
-        self.cleanup()
-
-    def on_instance_cleanup_member_event(self, instance_cleanup_member_event):
-        self.cleanup()
-
-    def on_member_activated_event(self, member_activated_event):
-        self.log.info("Member activated event received: [service] %r [cluster] %r [member] %r"
-            % (member_activated_event.service_name, member_activated_event.cluster_id, member_activated_event.member_id))
-
-        topology_consistent = extensionutils.check_topology_consistency(
-            member_activated_event.service_name,
-            member_activated_event.cluster_id,
-            member_activated_event.member_id)
-
-        if not topology_consistent:
-            self.log.error("Topology is inconsistent...failed to execute member activated event")
-            return
-
-        topology = TopologyContext.get_topology()
-        service = topology.get_service(member_activated_event.service_name)
-        cluster = service.get_cluster(member_activated_event.cluster_id)
-        member = cluster.get_member(member_activated_event.member_id)
-        lb_cluster_id = member.lb_cluster_id
-
-        if extensionutils.is_relevant_member_event(member_activated_event.service_name,
-                                                   member_activated_event.cluster_id, lb_cluster_id):
-
-            env_params = {"STRATOS_MEMBER_ACTIVATED_MEMBER_IP": str(member_activated_event.member_ip),
-                          "STRATOS_MEMBER_ACTIVATED_MEMBER_ID": str(member_activated_event.member_id),
-                          "STRATOS_MEMBER_ACTIVATED_CLUSTER_ID": str(member_activated_event.cluster_id),
-                          "STRATOS_MEMBER_ACTIVATED_LB_CLUSTER_ID": str(lb_cluster_id),
-                          "STRATOS_MEMBER_ACTIVATED_NETWORK_PARTITION_ID": str(member_activated_event.network_partition_id),
-                          "STRATOS_MEMBER_ACTIVATED_SERVICE_NAME": str(member_activated_event.service_name)}
-
-            ports = member_activated_event.port_map.values()
-            ports_str = ""
-            for port in ports:
-                ports_str += port.protocol + "," + str(port.value) + "," + str(port.proxy) + "|"
-
-            env_params["STRATOS_MEMBER_ACTIVATED_PORTS"] = ports_str
-
-            env_params["STRATOS_MEMBER_ACTIVATED_MEMBER_LIST_JSON"] = json.dumps(cluster.member_list_json)
-
-            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
-            if member_ips is not None and len(member_ips) > 1:
-                env_params["STRATOS_MEMBER_ACTIVATED_LB_IP"] = str(member_ips[0])
-                env_params["STRATOS_MEMBER_ACTIVATED_LB_PUBLIC_IP"] = str(member_ips[1])
-
-            env_params["STRATOS_TOPOLOGY_JSON"] = json.dumps(topology.json_str)
-
-            extensionutils.add_properties(service.properties, env_params, "MEMBER_ACTIVATED_SERVICE_PROPERTY")
-            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_ACTIVATED_CLUSTER_PROPERTY")
-            extensionutils.add_properties(member.properties, env_params, "MEMBER_ACTIVATED_MEMBER_PROPERTY")
-
-            clustered = self.cartridge_agent_config.is_clustered
-
-            if member.properties is not None and cartridgeagentconstants.CLUSTERING_PRIMARY_KEY in member.properties \
-                    and member.properties[cartridgeagentconstants.CLUSTERING_PRIMARY_KEY] == "true" \
-                    and clustered is not None and clustered:
-
-                self.log.debug(" If WK member is re-spawned, update axis2.xml ")
-
-                has_wk_ip_changed = True
-                for wk_member in self.wk_members:
-                    if wk_member.member_ip == member_activated_event.member_ip:
-                        has_wk_ip_changed = False
-
-                self.log.debug(" hasWKIpChanged %r" + has_wk_ip_changed)
-
-                min_count = int(self.cartridge_agent_config.min_count)
-                is_wk_member_grp_ready = self.is_wk_member_group_ready(env_params, min_count)
-                self.log.debug("MinCount: %r" % min_count)
-                self.log.debug("is_wk_member_grp_ready : %r" % is_wk_member_grp_ready)
-
-                if has_wk_ip_changed and is_wk_member_grp_ready:
-                    self.log.debug("Setting env var STRATOS_UPDATE_WK_IP to true")
-                    env_params["STRATOS_UPDATE_WK_IP"] = "true"
-
-            self.log.debug("Setting env var STRATOS_CLUSTERING to %r" % clustered)
-            env_params["STRATOS_CLUSTERING"] = str(clustered)
-            env_params["STRATOS_WK_MEMBER_COUNT"] = str(self.cartridge_agent_config.min_count)
-
-            extensionutils.execute_member_activated_extension(env_params)
-        else:
-            self.log.debug("Member activated event is not relevant...skipping agent extension")
-
-    def on_complete_topology_event(self, complete_topology_event):
-        self.log.debug("Complete topology event received")
-
-        service_name_in_payload = self.cartridge_agent_config.service_name
-        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
-        member_id_in_payload = self.cartridge_agent_config.member_id
-
-        consistant = extensionutils.check_topology_consistency(
-            service_name_in_payload,
-            cluster_id_in_payload,
-            member_id_in_payload)
-
-        if not consistant:
-            return
-        else:
-            self.cartridge_agent_config.initialized = True
-
-        topology = complete_topology_event.get_topology()
-        service = topology.get_service(service_name_in_payload)
-        cluster = service.get_cluster(cluster_id_in_payload)
-
-        env_params = {"STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str), "STRATOS_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json)}
-
-        extensionutils.execute_complete_topology_extension(env_params)
-
-    def on_instance_spawned_event(self, instance_spawned_event):
-        self.log.debug("Instance Spawned event received")
-
-        service_name_in_payload = self.cartridge_agent_config.service_name
-        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
-        member_id_in_payload = self.cartridge_agent_config.member_id
-
-        consistant = extensionutils.check_topology_consistency(
-            service_name_in_payload,
-            cluster_id_in_payload,
-            member_id_in_payload)
-
-        if not consistant:
-            return
-        else:
-            self.cartridge_agent_config.initialized = True
-
-    def on_complete_tenant_event(self, complete_tenant_event):
-        self.log.debug("Complete tenant event received")
-
-        tenant_list_json = complete_tenant_event.tenant_list_json
-        self.log.debug("Complete tenants:" + json.dumps(tenant_list_json))
-
-        env_params = {"STRATOS_TENANT_LIST_JSON": json.dumps(tenant_list_json)}
-
-        extensionutils.execute_complete_tenant_extension(env_params)
-
-    def on_member_terminated_event(self, member_terminated_event):
-        self.log.info("Member terminated event received: [service] " + member_terminated_event.service_name +
-                      " [cluster] " + member_terminated_event.cluster_id
-                      + " [member] " + member_terminated_event.member_id)
-
-        topology_consistent = extensionutils.check_topology_consistency(
-            member_terminated_event.service_name,
-            member_terminated_event.cluster_id,
-            member_terminated_event.member_id
-        )
-
-        if not topology_consistent:
-            self.log.error("Topology is inconsistent...failed to execute member terminated event")
-            return
-
-        topology = TopologyContext.get_topology()
-        service = topology.get_service(member_terminated_event.service_name)
-        cluster = service.get_cluster(member_terminated_event.cluster_id)
-        terminated_member = cluster.get_member(member_terminated_event.member_id)
-        lb_cluster_id = cluster.get_member(member_terminated_event.member_id).lb_cluster_id
-
-        #check whether terminated member is within the same cluster, LB cluster or service group
-        if extensionutils.is_relevant_member_event(
-                member_terminated_event.service_name,
-                member_terminated_event.cluster_id,
-                lb_cluster_id):
-
-            env_params = {"STRATOS_MEMBER_TERMINATED_MEMBER_IP": terminated_member.member_ip,
-                          "STRATOS_MEMBER_TERMINATED_MEMBER_ID": member_terminated_event.member_id,
-                          "STRATOS_MEMBER_TERMINATED_CLUSTER_ID": member_terminated_event.cluster_id,
-                          "STRATOS_MEMBER_TERMINATED_LB_CLUSTER_ID": lb_cluster_id,
-                          "STRATOS_MEMBER_TERMINATED_NETWORK_PARTITION_ID": member_terminated_event.network_partition_id,
-                          "STRATOS_MEMBER_TERMINATED_SERVICE_NAME": member_terminated_event.service_name,
-                          "STRATOS_MEMBER_TERMINATED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
-                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
-
-            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
-            if member_ips is not None and len(member_ips) > 1:
-                env_params["STRATOS_MEMBER_TERMINATED_LB_IP"] = member_ips[0]
-                env_params["STRATOS_MEMBER_TERMINATED_LB_PUBLIC_IP"] = member_ips[1]
-
-            extensionutils.add_properties(service.properties, env_params, "MEMBER_TERMINATED_SERVICE_PROPERTY")
-            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_TERMINATED_CLUSTER_PROPERTY")
-            extensionutils.add_properties(terminated_member.properties, env_params, "MEMBER_TERMINATED_MEMBER_PROPERTY")
-
-            extensionutils.execute_member_terminated_extension(env_params)
-
-        else:
-            self.log.debug("Member terminated event is not relevant...skipping agent extension")
-
-    def on_member_suspended_event(self, member_suspended_event):
-        self.log.info("Member suspended event received: [service] " + member_suspended_event.service_name +
-                      " [cluster] " + member_suspended_event.cluster_id + " [member] " + member_suspended_event.member_id)
-
-        topology_consistent = extensionutils.check_topology_consistency(
-            member_suspended_event.service_name,
-            member_suspended_event.cluster_id,
-            member_suspended_event.member_id
-        )
-
-        if not topology_consistent:
-            self.log.error("Topology is inconsistent...failed to execute member suspended event")
-            return
-
-        topology = TopologyContext.get_topology()
-        service = topology.get_service(member_suspended_event.service_name)
-        cluster = service.get_cluster(member_suspended_event.cluster_id)
-        suspended_member = cluster.get_member(member_suspended_event.member_id)
-        lb_cluster_id = cluster.get_member(member_suspended_event.member_id).lb_cluster_id
-
-        #check whether suspended member is within the same cluster, LB cluster or service group
-        if extensionutils.is_relevant_member_event(
-                member_suspended_event.service_name,
-                member_suspended_event.cluster_id,
-                lb_cluster_id):
-
-            env_params = {"STRATOS_MEMBER_SUSPENDED_MEMBER_IP": member_suspended_event.member_ip,
-                          "STRATOS_MEMBER_SUSPENDED_MEMBER_ID": member_suspended_event.member_id,
-                          "STRATOS_MEMBER_SUSPENDED_CLUSTER_ID": member_suspended_event.cluster_id,
-                          "STRATOS_MEMBER_SUSPENDED_LB_CLUSTER_ID": lb_cluster_id,
-                          "STRATOS_MEMBER_SUSPENDED_NETWORK_PARTITION_ID": member_suspended_event.network_partition_id,
-                          "STRATOS_MEMBER_SUSPENDED_SERVICE_NAME": member_suspended_event.service_name,
-                          "STRATOS_MEMBER_SUSPENDED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
-                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
-
-            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
-            if member_ips is not None and len(member_ips) > 1:
-                env_params["STRATOS_MEMBER_SUSPENDED_LB_IP"] = member_ips[0]
-                env_params["STRATOS_MEMBER_SUSPENDED_LB_PUBLIC_IP"] = member_ips[1]
-
-            extensionutils.add_properties(service.properties, env_params, "MEMBER_SUSPENDED_SERVICE_PROPERTY")
-            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_SUSPENDED_CLUSTER_PROPERTY")
-            extensionutils.add_properties(suspended_member.properties, env_params, "MEMBER_SUSPENDED_MEMBER_PROPERTY")
-
-            extensionutils.execute_member_suspended_extension(env_params)
-
-        else:
-            self.log.debug("Member suspended event is not relevant...skipping agent extension")
-
-    def on_member_started_event(self, member_started_event):
-        self.log.info("Member started event received: [service] " + member_started_event.service_name +
-                      " [cluster] " + member_started_event.cluster_id + " [member] " + member_started_event.member_id)
-
-        topology_consistent = extensionutils.check_topology_consistency(
-            member_started_event.service_name,
-            member_started_event.cluster_id,
-            member_started_event.member_id
-        )
-
-        if not topology_consistent:
-            self.log.error("Topology is inconsistent...failed to execute member started event")
-            return
-
-        topology = TopologyContext.get_topology()
-        service = topology.get_service(member_started_event.service_name)
-        cluster = service.get_cluster(member_started_event.cluster_id)
-        started_member = cluster.get_member(member_started_event.member_id)
-        lb_cluster_id = cluster.get_member(member_started_event.member_id).lb_cluster_id
-
-        #check whether started member is within the same cluster, LB cluster or service group
-        if extensionutils.is_relevant_member_event(
-                member_started_event.service_name,
-                member_started_event.cluster_id,
-                lb_cluster_id):
-
-            env_params = {"STRATOS_MEMBER_STARTED_MEMBER_IP": started_member.member_ip,
-                          "STRATOS_MEMBER_STARTED_MEMBER_ID": member_started_event.member_id,
-                          "STRATOS_MEMBER_STARTED_CLUSTER_ID": member_started_event.cluster_id,
-                          "STRATOS_MEMBER_STARTED_LB_CLUSTER_ID": lb_cluster_id,
-                          "STRATOS_MEMBER_STARTED_NETWORK_PARTITION_ID": member_started_event.network_partition_id,
-                          "STRATOS_MEMBER_STARTED_SERVICE_NAME": member_started_event.service_name,
-                          "STRATOS_MEMBER_STARTED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
-                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
-
-            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
-            if member_ips is not None and len(member_ips) > 1:
-                env_params["STRATOS_MEMBER_STARTED_LB_IP"] = member_ips[0]
-                env_params["STRATOS_MEMBER_STARTED_LB_PUBLIC_IP"] = member_ips[1]
-
-            extensionutils.add_properties(service.properties, env_params, "MEMBER_STARTED_SERVICE_PROPERTY")
-            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_STARTED_CLUSTER_PROPERTY")
-            extensionutils.add_properties(started_member.properties, env_params, "MEMBER_STARTED_MEMBER_PROPERTY")
-
-            extensionutils.execute_member_started_extension(env_params)
-
-        else:
-            self.log.debug("Member started event is not relevant...skipping agent extension")
-
-    def start_server_extension(self):
-        #wait until complete topology message is received to get LB IP
-        extensionutils.wait_for_complete_topology()
-        self.log.info("[start server extension] complete topology event received")
-
-        service_name_in_payload = self.cartridge_agent_config.service_name
-        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
-        member_id_in_payload = self.cartridge_agent_config.member_id
-
-        topology_consistant = extensionutils.check_topology_consistency(service_name_in_payload, cluster_id_in_payload, member_id_in_payload)
-
-        try:
-            if not topology_consistant:
-                self.log.error("Topology is inconsistent...failed to execute start server event")
-                return
-
-            topology = TopologyContext.get_topology()
-            service = topology.get_service(service_name_in_payload)
-            cluster = service.get_cluster(cluster_id_in_payload)
-
-            # store environment variable parameters to be passed to extension shell script
-            env_params = {}
-
-            # if clustering is enabled wait until all well known members have started
-            clustering_enabled = self.cartridge_agent_config.is_clustered
-            if clustering_enabled:
-                env_params["STRATOS_CLUSTERING"] = "true"
-                env_params["STRATOS_WK_MEMBER_COUNT"] = self.cartridge_agent_config.min_count
-
-                env_params["STRATOS_PRIMARY"] = "true" if self.cartridge_agent_config.is_primary else "false"
-
-                self.wait_for_wk_members(env_params)
-                self.log.info("All well known members have started! Resuming start server extension...")
-
-            env_params["STRATOS_TOPOLOGY_JSON"] = json.dumps(topology.json_str)
-            env_params["STRATOS_MEMBER_LIST_JSON"] = json.dumps(cluster.member_list_json)
-
-            extensionutils.execute_start_servers_extension(env_params)
-
-        except:
-            self.log.exception("Error processing start servers event")
-
-    def volume_mount_extension(self, persistence_mappings_payload):
-        extensionutils.execute_volume_mount_extension(persistence_mappings_payload)
-
-    def on_subscription_domain_added_event(self, subscription_domain_added_event):
-        tenant_domain = self.find_tenant_domain(subscription_domain_added_event.tenant_id)
-        self.log.info(
-            "Subscription domain added event received: [tenant-id] " + subscription_domain_added_event.tenant_id +
-            " [tenant-domain] " + tenant_domain + " [domain-name] " + subscription_domain_added_event.domain_name +
-            " [application-context] " + subscription_domain_added_event.application_context
-        )
-
-        env_params = {"STRATOS_SUBSCRIPTION_SERVICE_NAME": subscription_domain_added_event.service_name,
-                      "STRATOS_SUBSCRIPTION_DOMAIN_NAME": subscription_domain_added_event.domain_name,
-                      "STRATOS_SUBSCRIPTION_TENANT_ID": int(subscription_domain_added_event.tenant_id),
-                      "STRATOS_SUBSCRIPTION_TENANT_DOMAIN": tenant_domain,
-                      "STRATOS_SUBSCRIPTION_APPLICATION_CONTEXT": subscription_domain_added_event.application_context}
-
-        extensionutils.execute_subscription_domain_added_extension(env_params)
-
-    def on_subscription_domain_removed_event(self, subscription_domain_removed_event):
-        tenant_domain = self.find_tenant_domain(subscription_domain_removed_event.tenant_id)
-        self.log.info(
-            "Subscription domain removed event received: [tenant-id] " + subscription_domain_removed_event.tenant_id +
-            " [tenant-domain] " + tenant_domain + " [domain-name] " + subscription_domain_removed_event.domain_name
-        )
-
-        env_params = {"STRATOS_SUBSCRIPTION_SERVICE_NAME": subscription_domain_removed_event.service_name,
-                      "STRATOS_SUBSCRIPTION_DOMAIN_NAME": subscription_domain_removed_event.domain_name,
-                      "STRATOS_SUBSCRIPTION_TENANT_ID": int(subscription_domain_removed_event.tenant_id),
-                      "STRATOS_SUBSCRIPTION_TENANT_DOMAIN": tenant_domain}
-
-        extensionutils.execute_subscription_domain_removed_extension(env_params)
-
-    def on_copy_artifacts_extension(self, src, des):
-        extensionutils.execute_copy_artifact_extension(src, des)
-
-    def on_tenant_subscribed_event(self, tenant_subscribed_event):
-        self.log.info(
-            "Tenant subscribed event received: [tenant] " + tenant_subscribed_event.tenant_id +
-            " [service] " + tenant_subscribed_event.service_name + " [cluster] " + tenant_subscribed_event.cluster_ids
-        )
-
-        extensionutils.execute_tenant_subscribed_extension({})
-
-    def on_tenant_unsubscribed_event(self, tenant_unsubscribed_event):
-        self.log.info(
-            "Tenant unsubscribed event received: [tenant] " + tenant_unsubscribed_event.tenant_id +
-            " [service] " + tenant_unsubscribed_event.service_name +
-            " [cluster] " + tenant_unsubscribed_event.cluster_ids
-        )
-
-        try:
-            if self.cartridge_agent_config.service_name == tenant_unsubscribed_event.service_name:
-                agentgithandler.AgentGitHandler.remove_repo(tenant_unsubscribed_event.tenant_id)
-        except:
-            self.log.exception("Removing git repository failed: ")
-        extensionutils.execute_tenant_unsubscribed_extension({})
-
-    def cleanup(self):
-        self.log.info("Executing cleaning up the data in the cartridge instance...")
-
-        cartridgeagentpublisher.publish_maintenance_mode_event()
-
-        extensionutils.execute_cleanup_extension()
-        self.log.info("cleaning up finished in the cartridge instance...")
-
-        self.log.info("publishing ready to shutdown event...")
-        cartridgeagentpublisher.publish_instance_ready_to_shutdown_event()
-
-    def is_wk_member_group_ready(self, env_params, min_count):
-        topology = TopologyContext.get_topology()
-        if topology is None or not topology.initialized:
-            return False
-
-        service_group_in_payload = self.cartridge_agent_config.service_group
-        if service_group_in_payload is not None:
-            env_params["STRATOS_SERVICE_GROUP"] = service_group_in_payload
-
-        # clustering logic for apimanager
-        if service_group_in_payload is not None and service_group_in_payload == "apim":
-            # handle apistore and publisher case
-            if self.cartridge_agent_config.service_name == cartridgeagentconstants.APIMANAGER_SERVICE_NAME or \
-                    self.cartridge_agent_config.service_name == cartridgeagentconstants.PUBLISHER_SERVICE_NAME:
-
-                apistore_cluster_collection = topology.get_service(cartridgeagentconstants.APIMANAGER_SERVICE_NAME)\
-                    .get_clusters()
-                publisher_cluster_collection = topology.get_service(cartridgeagentconstants.PUBLISHER_SERVICE_NAME)\
-                    .get_clusters()
-
-                apistore_member_list = []
-                for member in apistore_cluster_collection[0].get_members():
-                    if member.status == MemberStatus.Starting or member.status == MemberStatus.Activated:
-                        apistore_member_list.append(member)
-                        self.wk_members.append(member)
-
-                if len(apistore_member_list) == 0:
-                    self.log.debug("API Store members not yet created")
-                    return False
-
-                apistore_member = apistore_member_list[0]
-                env_params["STRATOS_WK_APISTORE_MEMBER_IP"] = apistore_member.member_ip
-                self.log.debug("STRATOS_WK_APISTORE_MEMBER_IP: %r" % apistore_member.member_ip)
-
-                publisher_member_list = []
-                for member in publisher_cluster_collection[0].get_members():
-                    if member.status == MemberStatus.Starting or member.status == MemberStatus.Activated:
-                        publisher_member_list.append(member)
-                        self.wk_members.append(member)
-
-                if len(publisher_member_list) == 0:
-                    self.log.debug("API Publisher members not yet created")
-
-                publisher_member = publisher_member_list[0]
-                env_params["STRATOS_WK_PUBLISHER_MEMBER_IP"] = publisher_member.member_ip
-                self.log.debug("STRATOS_WK_PUBLISHER_MEMBER_IP: %r" % publisher_member.member_ip)
-
-                return True
-
-            elif self.cartridge_agent_config.service_name == cartridgeagentconstants.GATEWAY_MGT_SERVICE_NAME or \
-                    self.cartridge_agent_config.service_name == cartridgeagentconstants.GATEWAY_SERVICE_NAME:
-
-                if self.cartridge_agent_config.deployment is not None:
-                    # check if deployment is Manager Worker separated
-                    if self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower() or \
-                            self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
-
-                        self.log.info("Deployment pattern for the node: %r" % self.cartridge_agent_config.deployment)
-                        env_params["DEPLOYMENT"] = self.cartridge_agent_config.deployment
-                        # check if WKA members of Manager Worker separated deployment is ready
-                        return self.is_manager_worker_WKA_group_ready(env_params)
-
-            elif self.cartridge_agent_config.service_name == cartridgeagentconstants.KEY_MANAGER_SERVICE_NAME:
-                return True
-
-        else:
-            if self.cartridge_agent_config.deployment is not None:
-                # check if deployment is Manager Worker separated
-                if self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower() or \
-                        self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
-
-                    self.log.info("Deployment pattern for the node: %r" % self.cartridge_agent_config.deployment)
-                    env_params["DEPLOYMENT"] = self.cartridge_agent_config.deployment
-                    # check if WKA members of Manager Worker separated deployment is ready
-                    return self.is_manager_worker_WKA_group_ready(env_params)
-
-            service_name_in_payload = self.cartridge_agent_config.service_name
-            cluster_id_in_payload = self.cartridge_agent_config.cluster_id
-            service = topology.get_service(service_name_in_payload)
-            cluster = service.get_cluster(cluster_id_in_payload)
-
-            wk_members = []
-            for member in cluster.get_members():
-                if member.properties is not None and \
-                        cartridgeagentconstants.PRIMARY in member.properties \
-                        and member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
-                        (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
-
-                    wk_members.append(member)
-                    self.wk_members.append(member)
-                    self.log.debug("Found WKA: STRATOS_WK_MEMBER_IP: " + member.member_ip)
-
-            if len(wk_members) >= min_count:
-                idx = 0
-                for member in wk_members:
-                    env_params["STRATOS_WK_MEMBER_" + idx + "_IP"] = member.member_ip
-                    self.log.debug("STRATOS_WK_MEMBER_" + idx + "_IP:" + member.member_ip)
-
-                    idx += 1
-
-                return True
-
-        return False
-
-    # generic worker manager separated clustering logic
-    def is_manager_worker_WKA_group_ready(self, env_params):
-
-        # for this, we need both manager cluster service name and worker cluster service name
-        manager_service_name = self.cartridge_agent_config.manager_service_name
-        worker_service_name = self.cartridge_agent_config.worker_service_name
-
-        # managerServiceName and workerServiceName both should not be null /empty
-        if manager_service_name is None or manager_service_name.strip() == "":
-            self.log.error("Manager service name [ " + manager_service_name + " ] is invalid")
-            return False
-
-        if worker_service_name is None or worker_service_name.strip() == "":
-            self.log.error("Worker service name [ " + worker_service_name + " ] is invalid")
-            return False
-
-        min_manager_instances_available = False
-        min_worker_instances_available = False
-
-        topology = TopologyContext.get_topology()
-        manager_service = topology.get_service(manager_service_name)
-        worker_service = topology.get_service(worker_service_name)
-
-        if manager_service is None:
-            self.log.warn("Service [ " + manager_service_name + " ] is not found")
-            return False
-
-        if worker_service is None:
-            self.log.warn("Service [ " + worker_service_name + " ] is not found")
-            return False
-
-        # manager clusters
-        manager_clusters = manager_service.get_clusters()
-        if manager_clusters is None or len(manager_clusters) == 0:
-            self.log.warn("No clusters found for service [ " + manager_service_name + " ]")
-            return False
-
-        manager_min_instance_count = 1
-        manager_min_instance_count_found = False
-
-        manager_wka_members = []
-        for member in manager_clusters[0].get_members():
-            if member.properties is not None and \
-                    cartridgeagentconstants.PRIMARY in member.properties \
-                    and member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
-                    (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
-
-                manager_wka_members.append(member)
-                self.wk_members.append(member)
-
-                # get the min instance count
-                if not manager_min_instance_count_found:
-                    manager_min_instance_count = self.get_min_instance_count_from_member(member)
-                    manager_min_instance_count_found = True
-                    self.log.info("Manager min instance count: " + manager_min_instance_count)
-
-        if len(manager_wka_members) >= manager_min_instance_count:
-            min_manager_instances_available = True
-            idx = 0
-            for member in manager_wka_members:
-                env_params["STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP"] = member.member_ip
-                self.log.debug("STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP: " + member.member_ip)
-                idx += 1
-
-            env_params["STRATOS_WK_MANAGER_MEMBER_COUNT"] = int(manager_min_instance_count)
-
-        # If all the manager members are non primary and is greate than or equal to mincount,
-        # minManagerInstancesAvailable should be true
-        all_managers_non_primary = True
-        for member in manager_clusters[0].get_members():
-            # get the min instance count
-            if not manager_min_instance_count_found:
-                manager_min_instance_count = self.get_min_instance_count_from_member(member)
-                manager_min_instance_count_found = True
-                self.log.info(
-                    "Manager min instance count when allManagersNonPrimary true : " + manager_min_instance_count)
-
-            if member.properties is not None and cartridgeagentconstants.PRIMARY in member.properties and \
-                    member.properties[cartridgeagentconstants.PRIMARY].lower() == "true":
-                all_managers_non_primary = False
-                break
-
-        self.log.debug(
-            " allManagerNonPrimary & managerMinInstanceCount [" + all_managers_non_primary +
-            "], [" + manager_min_instance_count + "] ")
-
-        if all_managers_non_primary and len(manager_clusters) >= manager_min_instance_count:
-            min_manager_instances_available = True
-
-        # worker cluster
-        worker_clusters = worker_service.get_clusters()
-        if worker_clusters is None or len(worker_clusters) == 0:
-            self.log.warn("No clusters found for service [ " + worker_service_name + " ]")
-            return False
-
-        worker_min_instance_count = 1
-        worker_min_instance_count_found = False
-
-        worker_wka_members = []
-        for member in worker_clusters[0].get_members():
-            self.log.debug("Checking member : " + member.member_id)
-
-            if member.properties is not None and cartridgeagentconstants.PRIMARY in member.properties and \
-                    member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
-                    (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
-
-                self.log.debug("Added worker member " + member.member_id)
-
-                worker_wka_members.append(member)
-                self.wk_members.append(member)
-
-                # get the min instance count
-                if not worker_min_instance_count_found:
-                    worker_min_instance_count = self.get_min_instance_count_from_member(member)
-                    worker_min_instance_count_found = True
-                    self.log.debug("Worker min instance count: " + worker_min_instance_count)
-
-        if len(worker_wka_members) >= worker_min_instance_count:
-            min_worker_instances_available = True
-            idx = 0
-            for member in worker_wka_members:
-                env_params["STRATOS_WK_WORKER_MEMBER_" + idx + "_IP"] = member.member_ip
-                self.log.debug("STRATOS_WK_WORKER_MEMBER_" + idx + "_IP: " + member.member_ip)
-                idx += 1
-
-            env_params["STRATOS_WK_WORKER_MEMBER_COUNT"] = int(worker_min_instance_count)
-
-        self.log.debug(
-            " Returnning values minManagerInstancesAvailable && minWorkerInstancesAvailable [" +
-            min_manager_instances_available + "],  [" + min_worker_instances_available + "] ")
-
-        return min_manager_instances_available and min_worker_instances_available
-
-    def get_min_instance_count_from_member(self, member):
-        if cartridgeagentconstants.MIN_COUNT in member.properties:
-            return int(member.properties[cartridgeagentconstants.MIN_COUNT])
-
-        return 1
-
-    def find_tenant_domain(self, tenant_id):
-        tenant = TenantContext.get_tenant(tenant_id)
-        if tenant is None:
-            raise RuntimeError("Tenant could not be found: [tenant-id] %r" % tenant_id)
-
-        return tenant.tenant_domain
-
-    def wait_for_wk_members(self, env_params):
-        min_count = int(self.cartridge_agent_config.min_count)
-        is_wk_member_group_ready = False
-        while not is_wk_member_group_ready:
-            self.log.info("Waiting for %r well known members..." % min_count)
-
-            time.sleep(5)
-
-            is_wk_member_group_ready = self.is_wk_member_group_ready(env_params, min_count)
-
-from ..artifactmgt.git import agentgithandler
-from ..artifactmgt.repositoryinformation import RepositoryInformation
-from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
-from ..publisher import cartridgeagentpublisher
-from ..exception.parameternotfoundexception import ParameterNotFoundException
-from ..topology.topologycontext import *
-from ..tenant.tenantcontext import *
-from ..util.log import LogFactory
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py b/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
deleted file mode 100644
index 685344d..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
+++ /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.
-
-class AbstractHealthStatisticsReader:
-    """
-    Abstract class to implement to create a custom health stat reader
-    """
-
-    def stat_cartridge_health(self):
-        """
-        Abstract method that when implemented reads the memory usage and the load average
-        of the instance running the agent and returns a CartridgeHealthStatistics object
-        with the information
-
-        :return: CartridgeHealthStatistics object with memory usage and load average values
-        :rtype : CartridgeHealthStatistics
-        """
-        raise NotImplementedError
-
-
-class CartridgeHealthStatistics:
-    """
-    Holds the memory usage and load average reading
-    """
-
-    def __init__(self):
-        self.memory_usage = None
-        """:type : float"""
-        self.load_avg = None
-        """:type : float"""
-
-
-class CEPPublisherException(Exception):
-    """
-    Exception to be used during CEP publishing operations
-    """
-
-    def __init__(self, msg):
-        super(self,  msg)
-        self.message = msg
-
-    def get_message(self):
-        """
-        The message provided when the exception is raised
-        :return: message
-        :rtype: str
-        """
-        return self.message


[10/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
new file mode 100644
index 0000000..953838e
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
@@ -0,0 +1,405 @@
+#
+# 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.
+#
+
+from struct import pack, unpack
+
+from TProtocol import *
+
+
+__all__ = ['TCompactProtocol', 'TCompactProtocolFactory']
+
+CLEAR = 0
+FIELD_WRITE = 1
+VALUE_WRITE = 2
+CONTAINER_WRITE = 3
+BOOL_WRITE = 4
+FIELD_READ = 5
+CONTAINER_READ = 6
+VALUE_READ = 7
+BOOL_READ = 8
+
+
+def make_helper(v_from, container):
+  def helper(func):
+    def nested(self, *args, **kwargs):
+      assert self.state in (v_from, container), (self.state, v_from, container)
+      return func(self, *args, **kwargs)
+    return nested
+  return helper
+writer = make_helper(VALUE_WRITE, CONTAINER_WRITE)
+reader = make_helper(VALUE_READ, CONTAINER_READ)
+
+
+def makeZigZag(n, bits):
+  return (n << 1) ^ (n >> (bits - 1))
+
+
+def fromZigZag(n):
+  return (n >> 1) ^ -(n & 1)
+
+
+def writeVarint(trans, n):
+  out = []
+  while True:
+    if n & ~0x7f == 0:
+      out.append(n)
+      break
+    else:
+      out.append((n & 0xff) | 0x80)
+      n = n >> 7
+  trans.write(''.join(map(chr, out)))
+
+
+def readVarint(trans):
+  result = 0
+  shift = 0
+  while True:
+    x = trans.readAll(1)
+    byte = ord(x)
+    result |= (byte & 0x7f) << shift
+    if byte >> 7 == 0:
+      return result
+    shift += 7
+
+
+class CompactType:
+  STOP = 0x00
+  TRUE = 0x01
+  FALSE = 0x02
+  BYTE = 0x03
+  I16 = 0x04
+  I32 = 0x05
+  I64 = 0x06
+  DOUBLE = 0x07
+  BINARY = 0x08
+  LIST = 0x09
+  SET = 0x0A
+  MAP = 0x0B
+  STRUCT = 0x0C
+
+CTYPES = {TType.STOP: CompactType.STOP,
+          TType.BOOL: CompactType.TRUE,  # used for collection
+          TType.BYTE: CompactType.BYTE,
+          TType.I16: CompactType.I16,
+          TType.I32: CompactType.I32,
+          TType.I64: CompactType.I64,
+          TType.DOUBLE: CompactType.DOUBLE,
+          TType.STRING: CompactType.BINARY,
+          TType.STRUCT: CompactType.STRUCT,
+          TType.LIST: CompactType.LIST,
+          TType.SET: CompactType.SET,
+          TType.MAP: CompactType.MAP
+          }
+
+TTYPES = {}
+for k, v in CTYPES.items():
+  TTYPES[v] = k
+TTYPES[CompactType.FALSE] = TType.BOOL
+del k
+del v
+
+
+class TCompactProtocol(TProtocolBase):
+  """Compact implementation of the Thrift protocol driver."""
+
+  PROTOCOL_ID = 0x82
+  VERSION = 1
+  VERSION_MASK = 0x1f
+  TYPE_MASK = 0xe0
+  TYPE_SHIFT_AMOUNT = 5
+
+  def __init__(self, trans):
+    TProtocolBase.__init__(self, trans)
+    self.state = CLEAR
+    self.__last_fid = 0
+    self.__bool_fid = None
+    self.__bool_value = None
+    self.__structs = []
+    self.__containers = []
+
+  def __writeVarint(self, n):
+    writeVarint(self.trans, n)
+
+  def writeMessageBegin(self, name, type, seqid):
+    assert self.state == CLEAR
+    self.__writeUByte(self.PROTOCOL_ID)
+    self.__writeUByte(self.VERSION | (type << self.TYPE_SHIFT_AMOUNT))
+    self.__writeVarint(seqid)
+    self.__writeString(name)
+    self.state = VALUE_WRITE
+
+  def writeMessageEnd(self):
+    assert self.state == VALUE_WRITE
+    self.state = CLEAR
+
+  def writeStructBegin(self, name):
+    assert self.state in (CLEAR, CONTAINER_WRITE, VALUE_WRITE), self.state
+    self.__structs.append((self.state, self.__last_fid))
+    self.state = FIELD_WRITE
+    self.__last_fid = 0
+
+  def writeStructEnd(self):
+    assert self.state == FIELD_WRITE
+    self.state, self.__last_fid = self.__structs.pop()
+
+  def writeFieldStop(self):
+    self.__writeByte(0)
+
+  def __writeFieldHeader(self, type, fid):
+    delta = fid - self.__last_fid
+    if 0 < delta <= 15:
+      self.__writeUByte(delta << 4 | type)
+    else:
+      self.__writeByte(type)
+      self.__writeI16(fid)
+    self.__last_fid = fid
+
+  def writeFieldBegin(self, name, type, fid):
+    assert self.state == FIELD_WRITE, self.state
+    if type == TType.BOOL:
+      self.state = BOOL_WRITE
+      self.__bool_fid = fid
+    else:
+      self.state = VALUE_WRITE
+      self.__writeFieldHeader(CTYPES[type], fid)
+
+  def writeFieldEnd(self):
+    assert self.state in (VALUE_WRITE, BOOL_WRITE), self.state
+    self.state = FIELD_WRITE
+
+  def __writeUByte(self, byte):
+    self.trans.write(pack('!B', byte))
+
+  def __writeByte(self, byte):
+    self.trans.write(pack('!b', byte))
+
+  def __writeI16(self, i16):
+    self.__writeVarint(makeZigZag(i16, 16))
+
+  def __writeSize(self, i32):
+    self.__writeVarint(i32)
+
+  def writeCollectionBegin(self, etype, size):
+    assert self.state in (VALUE_WRITE, CONTAINER_WRITE), self.state
+    if size <= 14:
+      self.__writeUByte(size << 4 | CTYPES[etype])
+    else:
+      self.__writeUByte(0xf0 | CTYPES[etype])
+      self.__writeSize(size)
+    self.__containers.append(self.state)
+    self.state = CONTAINER_WRITE
+  writeSetBegin = writeCollectionBegin
+  writeListBegin = writeCollectionBegin
+
+  def writeMapBegin(self, ktype, vtype, size):
+    assert self.state in (VALUE_WRITE, CONTAINER_WRITE), self.state
+    if size == 0:
+      self.__writeByte(0)
+    else:
+      self.__writeSize(size)
+      self.__writeUByte(CTYPES[ktype] << 4 | CTYPES[vtype])
+    self.__containers.append(self.state)
+    self.state = CONTAINER_WRITE
+
+  def writeCollectionEnd(self):
+    assert self.state == CONTAINER_WRITE, self.state
+    self.state = self.__containers.pop()
+  writeMapEnd = writeCollectionEnd
+  writeSetEnd = writeCollectionEnd
+  writeListEnd = writeCollectionEnd
+
+  def writeBool(self, bool):
+    if self.state == BOOL_WRITE:
+      if bool:
+        ctype = CompactType.TRUE
+      else:
+        ctype = CompactType.FALSE
+      self.__writeFieldHeader(ctype, self.__bool_fid)
+    elif self.state == CONTAINER_WRITE:
+      if bool:
+        self.__writeByte(CompactType.TRUE)
+      else:
+        self.__writeByte(CompactType.FALSE)
+    else:
+      raise AssertionError("Invalid state in compact protocol")
+
+  writeByte = writer(__writeByte)
+  writeI16 = writer(__writeI16)
+
+  @writer
+  def writeI32(self, i32):
+    self.__writeVarint(makeZigZag(i32, 32))
+
+  @writer
+  def writeI64(self, i64):
+    self.__writeVarint(makeZigZag(i64, 64))
+
+  @writer
+  def writeDouble(self, dub):
+    self.trans.write(pack('!d', dub))
+
+  def __writeString(self, s):
+    self.__writeSize(len(s))
+    self.trans.write(s)
+  writeString = writer(__writeString)
+
+  def readFieldBegin(self):
+    assert self.state == FIELD_READ, self.state
+    type = self.__readUByte()
+    if type & 0x0f == TType.STOP:
+      return (None, 0, 0)
+    delta = type >> 4
+    if delta == 0:
+      fid = self.__readI16()
+    else:
+      fid = self.__last_fid + delta
+    self.__last_fid = fid
+    type = type & 0x0f
+    if type == CompactType.TRUE:
+      self.state = BOOL_READ
+      self.__bool_value = True
+    elif type == CompactType.FALSE:
+      self.state = BOOL_READ
+      self.__bool_value = False
+    else:
+      self.state = VALUE_READ
+    return (None, self.__getTType(type), fid)
+
+  def readFieldEnd(self):
+    assert self.state in (VALUE_READ, BOOL_READ), self.state
+    self.state = FIELD_READ
+
+  def __readUByte(self):
+    result, = unpack('!B', self.trans.readAll(1))
+    return result
+
+  def __readByte(self):
+    result, = unpack('!b', self.trans.readAll(1))
+    return result
+
+  def __readVarint(self):
+    return readVarint(self.trans)
+
+  def __readZigZag(self):
+    return fromZigZag(self.__readVarint())
+
+  def __readSize(self):
+    result = self.__readVarint()
+    if result < 0:
+      raise TException("Length < 0")
+    return result
+
+  def readMessageBegin(self):
+    assert self.state == CLEAR
+    proto_id = self.__readUByte()
+    if proto_id != self.PROTOCOL_ID:
+      raise TProtocolException(TProtocolException.BAD_VERSION,
+          'Bad protocol id in the message: %d' % proto_id)
+    ver_type = self.__readUByte()
+    type = (ver_type & self.TYPE_MASK) >> self.TYPE_SHIFT_AMOUNT
+    version = ver_type & self.VERSION_MASK
+    if version != self.VERSION:
+      raise TProtocolException(TProtocolException.BAD_VERSION,
+          'Bad version: %d (expect %d)' % (version, self.VERSION))
+    seqid = self.__readVarint()
+    name = self.__readString()
+    return (name, type, seqid)
+
+  def readMessageEnd(self):
+    assert self.state == CLEAR
+    assert len(self.__structs) == 0
+
+  def readStructBegin(self):
+    assert self.state in (CLEAR, CONTAINER_READ, VALUE_READ), self.state
+    self.__structs.append((self.state, self.__last_fid))
+    self.state = FIELD_READ
+    self.__last_fid = 0
+
+  def readStructEnd(self):
+    assert self.state == FIELD_READ
+    self.state, self.__last_fid = self.__structs.pop()
+
+  def readCollectionBegin(self):
+    assert self.state in (VALUE_READ, CONTAINER_READ), self.state
+    size_type = self.__readUByte()
+    size = size_type >> 4
+    type = self.__getTType(size_type)
+    if size == 15:
+      size = self.__readSize()
+    self.__containers.append(self.state)
+    self.state = CONTAINER_READ
+    return type, size
+  readSetBegin = readCollectionBegin
+  readListBegin = readCollectionBegin
+
+  def readMapBegin(self):
+    assert self.state in (VALUE_READ, CONTAINER_READ), self.state
+    size = self.__readSize()
+    types = 0
+    if size > 0:
+      types = self.__readUByte()
+    vtype = self.__getTType(types)
+    ktype = self.__getTType(types >> 4)
+    self.__containers.append(self.state)
+    self.state = CONTAINER_READ
+    return (ktype, vtype, size)
+
+  def readCollectionEnd(self):
+    assert self.state == CONTAINER_READ, self.state
+    self.state = self.__containers.pop()
+  readSetEnd = readCollectionEnd
+  readListEnd = readCollectionEnd
+  readMapEnd = readCollectionEnd
+
+  def readBool(self):
+    if self.state == BOOL_READ:
+      return self.__bool_value == CompactType.TRUE
+    elif self.state == CONTAINER_READ:
+      return self.__readByte() == CompactType.TRUE
+    else:
+      raise AssertionError("Invalid state in compact protocol: %d" %
+                           self.state)
+
+  readByte = reader(__readByte)
+  __readI16 = __readZigZag
+  readI16 = reader(__readZigZag)
+  readI32 = reader(__readZigZag)
+  readI64 = reader(__readZigZag)
+
+  @reader
+  def readDouble(self):
+    buff = self.trans.readAll(8)
+    val, = unpack('!d', buff)
+    return val
+
+  def __readString(self):
+    len = self.__readSize()
+    return self.trans.readAll(len)
+  readString = reader(__readString)
+
+  def __getTType(self, byte):
+    return TTYPES[byte & 0x0f]
+
+
+class TCompactProtocolFactory:
+  def __init__(self):
+    pass
+
+  def getProtocol(self, trans):
+    return TCompactProtocol(trans)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
new file mode 100644
index 0000000..7d9d7aa
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
@@ -0,0 +1,552 @@
+#
+# 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.
+#
+
+import base64
+import json
+import math
+
+from TProtocol import TType, TProtocolBase, TProtocolException
+
+
+__all__ = ['TJSONProtocol',
+           'TJSONProtocolFactory',
+           'TSimpleJSONProtocol',
+           'TSimpleJSONProtocolFactory']
+
+VERSION = 1
+
+COMMA = ','
+COLON = ':'
+LBRACE = '{'
+RBRACE = '}'
+LBRACKET = '['
+RBRACKET = ']'
+QUOTE = '"'
+BACKSLASH = '\\'
+ZERO = '0'
+
+ESCSEQ = '\\u00'
+ESCAPE_CHAR = '"\\bfnrt'
+ESCAPE_CHAR_VALS = ['"', '\\', '\b', '\f', '\n', '\r', '\t']
+NUMERIC_CHAR = '+-.0123456789Ee'
+
+CTYPES = {TType.BOOL:       'tf',
+          TType.BYTE:       'i8',
+          TType.I16:        'i16',
+          TType.I32:        'i32',
+          TType.I64:        'i64',
+          TType.DOUBLE:     'dbl',
+          TType.STRING:     'str',
+          TType.STRUCT:     'rec',
+          TType.LIST:       'lst',
+          TType.SET:        'set',
+          TType.MAP:        'map'}
+
+JTYPES = {}
+for key in CTYPES.keys():
+  JTYPES[CTYPES[key]] = key
+
+
+class JSONBaseContext(object):
+
+  def __init__(self, protocol):
+    self.protocol = protocol
+    self.first = True
+
+  def doIO(self, function):
+    pass
+  
+  def write(self):
+    pass
+
+  def read(self):
+    pass
+
+  def escapeNum(self):
+    return False
+
+  def __str__(self):
+    return self.__class__.__name__
+
+
+class JSONListContext(JSONBaseContext):
+    
+  def doIO(self, function):
+    if self.first is True:
+      self.first = False
+    else:
+      function(COMMA)
+
+  def write(self):
+    self.doIO(self.protocol.trans.write)
+
+  def read(self):
+    self.doIO(self.protocol.readJSONSyntaxChar)
+
+
+class JSONPairContext(JSONBaseContext):
+  
+  def __init__(self, protocol):
+    super(JSONPairContext, self).__init__(protocol)
+    self.colon = True
+
+  def doIO(self, function):
+    if self.first:
+      self.first = False
+      self.colon = True
+    else:
+      function(COLON if self.colon else COMMA)
+      self.colon = not self.colon
+
+  def write(self):
+    self.doIO(self.protocol.trans.write)
+
+  def read(self):
+    self.doIO(self.protocol.readJSONSyntaxChar)
+
+  def escapeNum(self):
+    return self.colon
+
+  def __str__(self):
+    return '%s, colon=%s' % (self.__class__.__name__, self.colon)
+
+
+class LookaheadReader():
+  hasData = False
+  data = ''
+
+  def __init__(self, protocol):
+    self.protocol = protocol
+
+  def read(self):
+    if self.hasData is True:
+      self.hasData = False
+    else:
+      self.data = self.protocol.trans.read(1)
+    return self.data
+
+  def peek(self):
+    if self.hasData is False:
+      self.data = self.protocol.trans.read(1)
+    self.hasData = True
+    return self.data
+
+class TJSONProtocolBase(TProtocolBase):
+
+  def __init__(self, trans):
+    TProtocolBase.__init__(self, trans)
+    self.resetWriteContext()
+    self.resetReadContext()
+
+  def resetWriteContext(self):
+    self.context = JSONBaseContext(self)
+    self.contextStack = [self.context]
+
+  def resetReadContext(self):
+    self.resetWriteContext()
+    self.reader = LookaheadReader(self)
+
+  def pushContext(self, ctx):
+    self.contextStack.append(ctx)
+    self.context = ctx
+
+  def popContext(self):
+    self.contextStack.pop()
+    if self.contextStack:
+      self.context = self.contextStack[-1]
+    else:
+      self.context = JSONBaseContext(self)
+
+  def writeJSONString(self, string):
+    self.context.write()
+    self.trans.write(json.dumps(string))
+
+  def writeJSONNumber(self, number):
+    self.context.write()
+    jsNumber = str(number)
+    if self.context.escapeNum():
+      jsNumber = "%s%s%s" % (QUOTE, jsNumber,  QUOTE)
+    self.trans.write(jsNumber)
+
+  def writeJSONBase64(self, binary):
+    self.context.write()
+    self.trans.write(QUOTE)
+    self.trans.write(base64.b64encode(binary))
+    self.trans.write(QUOTE)
+
+  def writeJSONObjectStart(self):
+    self.context.write()
+    self.trans.write(LBRACE)
+    self.pushContext(JSONPairContext(self))
+
+  def writeJSONObjectEnd(self):
+    self.popContext()
+    self.trans.write(RBRACE)
+
+  def writeJSONArrayStart(self):
+    self.context.write()
+    self.trans.write(LBRACKET)
+    self.pushContext(JSONListContext(self))
+
+  def writeJSONArrayEnd(self):
+    self.popContext()
+    self.trans.write(RBRACKET)
+
+  def readJSONSyntaxChar(self, character):
+    current = self.reader.read()
+    if character != current:
+      raise TProtocolException(TProtocolException.INVALID_DATA,
+                               "Unexpected character: %s" % current)
+
+  def readJSONString(self, skipContext):
+    string = []
+    if skipContext is False:
+      self.context.read()
+    self.readJSONSyntaxChar(QUOTE)
+    while True:
+      character = self.reader.read()
+      if character == QUOTE:
+        break
+      if character == ESCSEQ[0]:
+        character = self.reader.read()
+        if character == ESCSEQ[1]:
+          self.readJSONSyntaxChar(ZERO)
+          self.readJSONSyntaxChar(ZERO)
+          character = json.JSONDecoder().decode('"\u00%s"' % self.trans.read(2))
+        else:
+          off = ESCAPE_CHAR.find(character)
+          if off == -1:
+            raise TProtocolException(TProtocolException.INVALID_DATA,
+                                     "Expected control char")
+          character = ESCAPE_CHAR_VALS[off]
+      string.append(character)
+    return ''.join(string)
+
+  def isJSONNumeric(self, character):
+    return (True if NUMERIC_CHAR.find(character) != - 1 else False)
+
+  def readJSONQuotes(self):
+    if (self.context.escapeNum()):
+      self.readJSONSyntaxChar(QUOTE)
+
+  def readJSONNumericChars(self):
+    numeric = []
+    while True:
+      character = self.reader.peek()
+      if self.isJSONNumeric(character) is False:
+        break
+      numeric.append(self.reader.read())
+    return ''.join(numeric)
+
+  def readJSONInteger(self):
+    self.context.read()
+    self.readJSONQuotes()
+    numeric = self.readJSONNumericChars()
+    self.readJSONQuotes()
+    try:
+      return int(numeric)
+    except ValueError:
+      raise TProtocolException(TProtocolException.INVALID_DATA,
+                               "Bad data encounted in numeric data")
+
+  def readJSONDouble(self):
+    self.context.read()
+    if self.reader.peek() == QUOTE:
+      string  = self.readJSONString(True)
+      try:
+        double = float(string)
+        if (self.context.escapeNum is False and
+            not math.isinf(double) and
+            not math.isnan(double)):
+          raise TProtocolException(TProtocolException.INVALID_DATA,
+                                   "Numeric data unexpectedly quoted")
+        return double
+      except ValueError:
+        raise TProtocolException(TProtocolException.INVALID_DATA,
+                                 "Bad data encounted in numeric data")
+    else:
+      if self.context.escapeNum() is True:
+        self.readJSONSyntaxChar(QUOTE)
+      try:
+        return float(self.readJSONNumericChars())
+      except ValueError:
+        raise TProtocolException(TProtocolException.INVALID_DATA,
+                                 "Bad data encounted in numeric data")
+
+  def readJSONBase64(self):
+    string = self.readJSONString(False)
+    return base64.b64decode(string)
+
+  def readJSONObjectStart(self):
+    self.context.read()
+    self.readJSONSyntaxChar(LBRACE)
+    self.pushContext(JSONPairContext(self))
+
+  def readJSONObjectEnd(self):
+    self.readJSONSyntaxChar(RBRACE)
+    self.popContext()
+
+  def readJSONArrayStart(self):
+    self.context.read()
+    self.readJSONSyntaxChar(LBRACKET)
+    self.pushContext(JSONListContext(self))
+
+  def readJSONArrayEnd(self):
+    self.readJSONSyntaxChar(RBRACKET)
+    self.popContext()
+
+
+class TJSONProtocol(TJSONProtocolBase):
+
+  def readMessageBegin(self):
+    self.resetReadContext()
+    self.readJSONArrayStart()
+    if self.readJSONInteger() != VERSION:
+      raise TProtocolException(TProtocolException.BAD_VERSION,
+                               "Message contained bad version.")
+    name = self.readJSONString(False)
+    typen = self.readJSONInteger()
+    seqid = self.readJSONInteger()
+    return (name, typen, seqid)
+
+  def readMessageEnd(self):
+    self.readJSONArrayEnd()
+
+  def readStructBegin(self):
+    self.readJSONObjectStart()
+
+  def readStructEnd(self):
+    self.readJSONObjectEnd()
+
+  def readFieldBegin(self):
+    character = self.reader.peek()
+    ttype = 0
+    id = 0
+    if character == RBRACE:
+      ttype = TType.STOP
+    else:
+      id = self.readJSONInteger()
+      self.readJSONObjectStart()
+      ttype = JTYPES[self.readJSONString(False)]
+    return (None, ttype, id)
+
+  def readFieldEnd(self):
+    self.readJSONObjectEnd()
+
+  def readMapBegin(self):
+    self.readJSONArrayStart()
+    keyType = JTYPES[self.readJSONString(False)]
+    valueType = JTYPES[self.readJSONString(False)]
+    size = self.readJSONInteger()
+    self.readJSONObjectStart()
+    return (keyType, valueType, size)
+
+  def readMapEnd(self):
+    self.readJSONObjectEnd()
+    self.readJSONArrayEnd()
+
+  def readCollectionBegin(self):
+    self.readJSONArrayStart()
+    elemType = JTYPES[self.readJSONString(False)]
+    size = self.readJSONInteger()
+    return (elemType, size)
+  readListBegin = readCollectionBegin
+  readSetBegin = readCollectionBegin
+
+  def readCollectionEnd(self):
+    self.readJSONArrayEnd()
+  readSetEnd = readCollectionEnd
+  readListEnd = readCollectionEnd
+
+  def readBool(self):
+    return (False if self.readJSONInteger() == 0 else True)
+
+  def readNumber(self):
+    return self.readJSONInteger()
+  readByte = readNumber
+  readI16 = readNumber
+  readI32 = readNumber
+  readI64 = readNumber
+
+  def readDouble(self):
+    return self.readJSONDouble()
+
+  def readString(self):
+    return self.readJSONString(False)
+
+  def readBinary(self):
+    return self.readJSONBase64()
+
+  def writeMessageBegin(self, name, request_type, seqid):
+    self.resetWriteContext()
+    self.writeJSONArrayStart()
+    self.writeJSONNumber(VERSION)
+    self.writeJSONString(name)
+    self.writeJSONNumber(request_type)
+    self.writeJSONNumber(seqid)
+
+  def writeMessageEnd(self):
+    self.writeJSONArrayEnd()
+
+  def writeStructBegin(self, name):
+    self.writeJSONObjectStart()
+
+  def writeStructEnd(self):
+    self.writeJSONObjectEnd()
+
+  def writeFieldBegin(self, name, ttype, id):
+    self.writeJSONNumber(id)
+    self.writeJSONObjectStart()
+    self.writeJSONString(CTYPES[ttype])
+
+  def writeFieldEnd(self):
+    self.writeJSONObjectEnd()
+
+  def writeFieldStop(self):
+    pass
+
+  def writeMapBegin(self, ktype, vtype, size):
+    self.writeJSONArrayStart()
+    self.writeJSONString(CTYPES[ktype])
+    self.writeJSONString(CTYPES[vtype])
+    self.writeJSONNumber(size)
+    self.writeJSONObjectStart()
+
+  def writeMapEnd(self):
+    self.writeJSONObjectEnd()
+    self.writeJSONArrayEnd()
+    
+  def writeListBegin(self, etype, size):
+    self.writeJSONArrayStart()
+    self.writeJSONString(CTYPES[etype])
+    self.writeJSONNumber(size)
+    
+  def writeListEnd(self):
+    self.writeJSONArrayEnd()
+
+  def writeSetBegin(self, etype, size):
+    self.writeJSONArrayStart()
+    self.writeJSONString(CTYPES[etype])
+    self.writeJSONNumber(size)
+    
+  def writeSetEnd(self):
+    self.writeJSONArrayEnd()
+
+  def writeBool(self, boolean):
+    self.writeJSONNumber(1 if boolean is True else 0)
+
+  def writeInteger(self, integer):
+    self.writeJSONNumber(integer)
+  writeByte = writeInteger
+  writeI16 = writeInteger
+  writeI32 = writeInteger
+  writeI64 = writeInteger
+
+  def writeDouble(self, dbl):
+    self.writeJSONNumber(dbl)
+
+  def writeString(self, string):
+    self.writeJSONString(string)
+    
+  def writeBinary(self, binary):
+    self.writeJSONBase64(binary)
+
+
+class TJSONProtocolFactory:
+
+  def getProtocol(self, trans):
+    return TJSONProtocol(trans)
+
+
+class TSimpleJSONProtocol(TJSONProtocolBase):
+    """Simple, readable, write-only JSON protocol.
+    
+    Useful for interacting with scripting languages.
+    """
+
+    def readMessageBegin(self):
+        raise NotImplementedError()
+    
+    def readMessageEnd(self):
+        raise NotImplementedError()
+    
+    def readStructBegin(self):
+        raise NotImplementedError()
+    
+    def readStructEnd(self):
+        raise NotImplementedError()
+    
+    def writeMessageBegin(self, name, request_type, seqid):
+        self.resetWriteContext()
+    
+    def writeMessageEnd(self):
+        pass
+    
+    def writeStructBegin(self, name):
+        self.writeJSONObjectStart()
+    
+    def writeStructEnd(self):
+        self.writeJSONObjectEnd()
+      
+    def writeFieldBegin(self, name, ttype, fid):
+        self.writeJSONString(name)
+    
+    def writeFieldEnd(self):
+        pass
+    
+    def writeMapBegin(self, ktype, vtype, size):
+        self.writeJSONObjectStart()
+    
+    def writeMapEnd(self):
+        self.writeJSONObjectEnd()
+    
+    def _writeCollectionBegin(self, etype, size):
+        self.writeJSONArrayStart()
+    
+    def _writeCollectionEnd(self):
+        self.writeJSONArrayEnd()
+    writeListBegin = _writeCollectionBegin
+    writeListEnd = _writeCollectionEnd
+    writeSetBegin = _writeCollectionBegin
+    writeSetEnd = _writeCollectionEnd
+
+    def writeInteger(self, integer):
+        self.writeJSONNumber(integer)
+    writeByte = writeInteger
+    writeI16 = writeInteger
+    writeI32 = writeInteger
+    writeI64 = writeInteger
+    
+    def writeBool(self, boolean):
+        self.writeJSONNumber(1 if boolean is True else 0)
+
+    def writeDouble(self, dbl):
+        self.writeJSONNumber(dbl)
+    
+    def writeString(self, string):
+        self.writeJSONString(string)
+      
+    def writeBinary(self, binary):
+        self.writeJSONBase64(binary)
+
+
+class TSimpleJSONProtocolFactory(object):
+
+    def getProtocol(self, trans):
+        return TSimpleJSONProtocol(trans)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py
new file mode 100644
index 0000000..0154641
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py
@@ -0,0 +1,406 @@
+#
+# 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.
+#
+
+from ..Thrift import *
+
+
+class TProtocolException(TException):
+  """Custom Protocol Exception class"""
+
+  UNKNOWN = 0
+  INVALID_DATA = 1
+  NEGATIVE_SIZE = 2
+  SIZE_LIMIT = 3
+  BAD_VERSION = 4
+
+  def __init__(self, type=UNKNOWN, message=None):
+    TException.__init__(self, message)
+    self.type = type
+
+
+class TProtocolBase:
+  """Base class for Thrift protocol driver."""
+
+  def __init__(self, trans):
+    self.trans = trans
+
+  def writeMessageBegin(self, name, ttype, seqid):
+    pass
+
+  def writeMessageEnd(self):
+    pass
+
+  def writeStructBegin(self, name):
+    pass
+
+  def writeStructEnd(self):
+    pass
+
+  def writeFieldBegin(self, name, ttype, fid):
+    pass
+
+  def writeFieldEnd(self):
+    pass
+
+  def writeFieldStop(self):
+    pass
+
+  def writeMapBegin(self, ktype, vtype, size):
+    pass
+
+  def writeMapEnd(self):
+    pass
+
+  def writeListBegin(self, etype, size):
+    pass
+
+  def writeListEnd(self):
+    pass
+
+  def writeSetBegin(self, etype, size):
+    pass
+
+  def writeSetEnd(self):
+    pass
+
+  def writeBool(self, bool_val):
+    pass
+
+  def writeByte(self, byte):
+    pass
+
+  def writeI16(self, i16):
+    pass
+
+  def writeI32(self, i32):
+    pass
+
+  def writeI64(self, i64):
+    pass
+
+  def writeDouble(self, dub):
+    pass
+
+  def writeString(self, str_val):
+    pass
+
+  def readMessageBegin(self):
+    pass
+
+  def readMessageEnd(self):
+    pass
+
+  def readStructBegin(self):
+    pass
+
+  def readStructEnd(self):
+    pass
+
+  def readFieldBegin(self):
+    pass
+
+  def readFieldEnd(self):
+    pass
+
+  def readMapBegin(self):
+    pass
+
+  def readMapEnd(self):
+    pass
+
+  def readListBegin(self):
+    pass
+
+  def readListEnd(self):
+    pass
+
+  def readSetBegin(self):
+    pass
+
+  def readSetEnd(self):
+    pass
+
+  def readBool(self):
+    pass
+
+  def readByte(self):
+    pass
+
+  def readI16(self):
+    pass
+
+  def readI32(self):
+    pass
+
+  def readI64(self):
+    pass
+
+  def readDouble(self):
+    pass
+
+  def readString(self):
+    pass
+
+  def skip(self, ttype):
+    if ttype == TType.STOP:
+      return
+    elif ttype == TType.BOOL:
+      self.readBool()
+    elif ttype == TType.BYTE:
+      self.readByte()
+    elif ttype == TType.I16:
+      self.readI16()
+    elif ttype == TType.I32:
+      self.readI32()
+    elif ttype == TType.I64:
+      self.readI64()
+    elif ttype == TType.DOUBLE:
+      self.readDouble()
+    elif ttype == TType.STRING:
+      self.readString()
+    elif ttype == TType.STRUCT:
+      name = self.readStructBegin()
+      while True:
+        (name, ttype, id) = self.readFieldBegin()
+        if ttype == TType.STOP:
+          break
+        self.skip(ttype)
+        self.readFieldEnd()
+      self.readStructEnd()
+    elif ttype == TType.MAP:
+      (ktype, vtype, size) = self.readMapBegin()
+      for i in xrange(size):
+        self.skip(ktype)
+        self.skip(vtype)
+      self.readMapEnd()
+    elif ttype == TType.SET:
+      (etype, size) = self.readSetBegin()
+      for i in xrange(size):
+        self.skip(etype)
+      self.readSetEnd()
+    elif ttype == TType.LIST:
+      (etype, size) = self.readListBegin()
+      for i in xrange(size):
+        self.skip(etype)
+      self.readListEnd()
+
+  # tuple of: ( 'reader method' name, is_container bool, 'writer_method' name )
+  _TTYPE_HANDLERS = (
+       (None, None, False),  # 0 TType.STOP
+       (None, None, False),  # 1 TType.VOID # TODO: handle void?
+       ('readBool', 'writeBool', False),  # 2 TType.BOOL
+       ('readByte',  'writeByte', False),  # 3 TType.BYTE and I08
+       ('readDouble', 'writeDouble', False),  # 4 TType.DOUBLE
+       (None, None, False),  # 5 undefined
+       ('readI16', 'writeI16', False),  # 6 TType.I16
+       (None, None, False),  # 7 undefined
+       ('readI32', 'writeI32', False),  # 8 TType.I32
+       (None, None, False),  # 9 undefined
+       ('readI64', 'writeI64', False),  # 10 TType.I64
+       ('readString', 'writeString', False),  # 11 TType.STRING and UTF7
+       ('readContainerStruct', 'writeContainerStruct', True),  # 12 *.STRUCT
+       ('readContainerMap', 'writeContainerMap', True),  # 13 TType.MAP
+       ('readContainerSet', 'writeContainerSet', True),  # 14 TType.SET
+       ('readContainerList', 'writeContainerList', True),  # 15 TType.LIST
+       (None, None, False),  # 16 TType.UTF8 # TODO: handle utf8 types?
+       (None, None, False)  # 17 TType.UTF16 # TODO: handle utf16 types?
+      )
+
+  def readFieldByTType(self, ttype, spec):
+    try:
+      (r_handler, w_handler, is_container) = self._TTYPE_HANDLERS[ttype]
+    except IndexError:
+      raise TProtocolException(type=TProtocolException.INVALID_DATA,
+                               message='Invalid field type %d' % (ttype))
+    if r_handler is None:
+      raise TProtocolException(type=TProtocolException.INVALID_DATA,
+                               message='Invalid field type %d' % (ttype))
+    reader = getattr(self, r_handler)
+    if not is_container:
+      return reader()
+    return reader(spec)
+
+  def readContainerList(self, spec):
+    results = []
+    ttype, tspec = spec[0], spec[1]
+    r_handler = self._TTYPE_HANDLERS[ttype][0]
+    reader = getattr(self, r_handler)
+    (list_type, list_len) = self.readListBegin()
+    if tspec is None:
+      # list values are simple types
+      for idx in xrange(list_len):
+        results.append(reader())
+    else:
+      # this is like an inlined readFieldByTType
+      container_reader = self._TTYPE_HANDLERS[list_type][0]
+      val_reader = getattr(self, container_reader)
+      for idx in xrange(list_len):
+        val = val_reader(tspec)
+        results.append(val)
+    self.readListEnd()
+    return results
+
+  def readContainerSet(self, spec):
+    results = set()
+    ttype, tspec = spec[0], spec[1]
+    r_handler = self._TTYPE_HANDLERS[ttype][0]
+    reader = getattr(self, r_handler)
+    (set_type, set_len) = self.readSetBegin()
+    if tspec is None:
+      # set members are simple types
+      for idx in xrange(set_len):
+        results.add(reader())
+    else:
+      container_reader = self._TTYPE_HANDLERS[set_type][0]
+      val_reader = getattr(self, container_reader)
+      for idx in xrange(set_len):
+        results.add(val_reader(tspec))
+    self.readSetEnd()
+    return results
+
+  def readContainerStruct(self, spec):
+    (obj_class, obj_spec) = spec
+    obj = obj_class()
+    obj.read(self)
+    return obj
+
+  def readContainerMap(self, spec):
+    results = dict()
+    key_ttype, key_spec = spec[0], spec[1]
+    val_ttype, val_spec = spec[2], spec[3]
+    (map_ktype, map_vtype, map_len) = self.readMapBegin()
+    # TODO: compare types we just decoded with thrift_spec and
+    # abort/skip if types disagree
+    key_reader = getattr(self, self._TTYPE_HANDLERS[key_ttype][0])
+    val_reader = getattr(self, self._TTYPE_HANDLERS[val_ttype][0])
+    # list values are simple types
+    for idx in xrange(map_len):
+      if key_spec is None:
+        k_val = key_reader()
+      else:
+        k_val = self.readFieldByTType(key_ttype, key_spec)
+      if val_spec is None:
+        v_val = val_reader()
+      else:
+        v_val = self.readFieldByTType(val_ttype, val_spec)
+      # this raises a TypeError with unhashable keys types
+      # i.e. this fails: d=dict(); d[[0,1]] = 2
+      results[k_val] = v_val
+    self.readMapEnd()
+    return results
+
+  def readStruct(self, obj, thrift_spec):
+    self.readStructBegin()
+    while True:
+      (fname, ftype, fid) = self.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      try:
+        field = thrift_spec[fid]
+      except IndexError:
+        self.skip(ftype)
+      else:
+        if field is not None and ftype == field[1]:
+          fname = field[2]
+          fspec = field[3]
+          val = self.readFieldByTType(ftype, fspec)
+          setattr(obj, fname, val)
+        else:
+          self.skip(ftype)
+      self.readFieldEnd()
+    self.readStructEnd()
+
+  def writeContainerStruct(self, val, spec):
+    val.write(self)
+
+  def writeContainerList(self, val, spec):
+    self.writeListBegin(spec[0], len(val))
+    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[spec[0]]
+    e_writer = getattr(self, w_handler)
+    if not is_container:
+      for elem in val:
+        e_writer(elem)
+    else:
+      for elem in val:
+        e_writer(elem, spec[1])
+    self.writeListEnd()
+
+  def writeContainerSet(self, val, spec):
+    self.writeSetBegin(spec[0], len(val))
+    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[spec[0]]
+    e_writer = getattr(self, w_handler)
+    if not is_container:
+      for elem in val:
+        e_writer(elem)
+    else:
+      for elem in val:
+        e_writer(elem, spec[1])
+    self.writeSetEnd()
+
+  def writeContainerMap(self, val, spec):
+    k_type = spec[0]
+    v_type = spec[2]
+    ignore, ktype_name, k_is_container = self._TTYPE_HANDLERS[k_type]
+    ignore, vtype_name, v_is_container = self._TTYPE_HANDLERS[v_type]
+    k_writer = getattr(self, ktype_name)
+    v_writer = getattr(self, vtype_name)
+    self.writeMapBegin(k_type, v_type, len(val))
+    for m_key, m_val in val.iteritems():
+      if not k_is_container:
+        k_writer(m_key)
+      else:
+        k_writer(m_key, spec[1])
+      if not v_is_container:
+        v_writer(m_val)
+      else:
+        v_writer(m_val, spec[3])
+    self.writeMapEnd()
+
+  def writeStruct(self, obj, thrift_spec):
+    self.writeStructBegin(obj.__class__.__name__)
+    for field in thrift_spec:
+      if field is None:
+        continue
+      fname = field[2]
+      val = getattr(obj, fname)
+      if val is None:
+        # skip writing out unset fields
+        continue
+      fid = field[0]
+      ftype = field[1]
+      fspec = field[3]
+      # get the writer method for this value
+      self.writeFieldBegin(fname, ftype, fid)
+      self.writeFieldByTType(ftype, val, fspec)
+      self.writeFieldEnd()
+    self.writeFieldStop()
+    self.writeStructEnd()
+
+  def writeFieldByTType(self, ttype, val, spec):
+    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[ttype]
+    writer = getattr(self, w_handler)
+    if is_container:
+      writer(val, spec)
+    else:
+      writer(val)
+
+
+class TProtocolFactory:
+  def getProtocol(self, trans):
+    pass

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py
new file mode 100644
index 0000000..7eefb45
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+__all__ = ['fastbinary', 'TBase', 'TBinaryProtocol', 'TCompactProtocol', 'TJSONProtocol', 'TProtocol']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c
new file mode 100644
index 0000000..2ce5660
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c
@@ -0,0 +1,1219 @@
+/*
+ * 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.
+ */
+
+#include <Python.h>
+#include "cStringIO.h"
+#include <stdint.h>
+#ifndef _WIN32
+# include <stdbool.h>
+# include <netinet/in.h>
+#else
+# include <WinSock2.h>
+# pragma comment (lib, "ws2_32.lib")
+# define BIG_ENDIAN (4321)
+# define LITTLE_ENDIAN (1234)
+# define BYTE_ORDER LITTLE_ENDIAN
+# if defined(_MSC_VER) && _MSC_VER < 1600
+   typedef int _Bool;
+#  define bool _Bool
+#  define false 0 
+#  define true 1
+# endif
+# define inline __inline
+#endif
+
+/* Fix endianness issues on Solaris */
+#if defined (__SVR4) && defined (__sun)
+ #if defined(__i386) && !defined(__i386__)
+  #define __i386__
+ #endif
+
+ #ifndef BIG_ENDIAN
+  #define BIG_ENDIAN (4321)
+ #endif
+ #ifndef LITTLE_ENDIAN
+  #define LITTLE_ENDIAN (1234)
+ #endif
+
+ /* I386 is LE, even on Solaris */
+ #if !defined(BYTE_ORDER) && defined(__i386__)
+  #define BYTE_ORDER LITTLE_ENDIAN
+ #endif
+#endif
+
+// TODO(dreiss): defval appears to be unused.  Look into removing it.
+// TODO(dreiss): Make parse_spec_args recursive, and cache the output
+//               permanently in the object.  (Malloc and orphan.)
+// TODO(dreiss): Why do we need cStringIO for reading, why not just char*?
+//               Can cStringIO let us work with a BufferedTransport?
+// TODO(dreiss): Don't ignore the rv from cwrite (maybe).
+
+/* ====== BEGIN UTILITIES ====== */
+
+#define INIT_OUTBUF_SIZE 128
+
+// Stolen out of TProtocol.h.
+// It would be a huge pain to have both get this from one place.
+typedef enum TType {
+  T_STOP       = 0,
+  T_VOID       = 1,
+  T_BOOL       = 2,
+  T_BYTE       = 3,
+  T_I08        = 3,
+  T_I16        = 6,
+  T_I32        = 8,
+  T_U64        = 9,
+  T_I64        = 10,
+  T_DOUBLE     = 4,
+  T_STRING     = 11,
+  T_UTF7       = 11,
+  T_STRUCT     = 12,
+  T_MAP        = 13,
+  T_SET        = 14,
+  T_LIST       = 15,
+  T_UTF8       = 16,
+  T_UTF16      = 17
+} TType;
+
+#ifndef __BYTE_ORDER
+# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
+#  define __BYTE_ORDER BYTE_ORDER
+#  define __LITTLE_ENDIAN LITTLE_ENDIAN
+#  define __BIG_ENDIAN BIG_ENDIAN
+# else
+#  error "Cannot determine endianness"
+# endif
+#endif
+
+// Same comment as the enum.  Sorry.
+#if __BYTE_ORDER == __BIG_ENDIAN
+# define ntohll(n) (n)
+# define htonll(n) (n)
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+# if defined(__GNUC__) && defined(__GLIBC__)
+#  include <byteswap.h>
+#  define ntohll(n) bswap_64(n)
+#  define htonll(n) bswap_64(n)
+# else /* GNUC & GLIBC */
+#  define ntohll(n) ( (((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32) )
+#  define htonll(n) ( (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32) )
+# endif /* GNUC & GLIBC */
+#else /* __BYTE_ORDER */
+# error "Can't define htonll or ntohll!"
+#endif
+
+// Doing a benchmark shows that interning actually makes a difference, amazingly.
+#define INTERN_STRING(value) _intern_ ## value
+
+#define INT_CONV_ERROR_OCCURRED(v) ( ((v) == -1) && PyErr_Occurred() )
+#define CHECK_RANGE(v, min, max) ( ((v) <= (max)) && ((v) >= (min)) )
+
+// Py_ssize_t was not defined before Python 2.5
+#if (PY_VERSION_HEX < 0x02050000)
+typedef int Py_ssize_t;
+#endif
+
+/**
+ * A cache of the spec_args for a set or list,
+ * so we don't have to keep calling PyTuple_GET_ITEM.
+ */
+typedef struct {
+  TType element_type;
+  PyObject* typeargs;
+} SetListTypeArgs;
+
+/**
+ * A cache of the spec_args for a map,
+ * so we don't have to keep calling PyTuple_GET_ITEM.
+ */
+typedef struct {
+  TType ktag;
+  TType vtag;
+  PyObject* ktypeargs;
+  PyObject* vtypeargs;
+} MapTypeArgs;
+
+/**
+ * A cache of the spec_args for a struct,
+ * so we don't have to keep calling PyTuple_GET_ITEM.
+ */
+typedef struct {
+  PyObject* klass;
+  PyObject* spec;
+} StructTypeArgs;
+
+/**
+ * A cache of the item spec from a struct specification,
+ * so we don't have to keep calling PyTuple_GET_ITEM.
+ */
+typedef struct {
+  int tag;
+  TType type;
+  PyObject* attrname;
+  PyObject* typeargs;
+  PyObject* defval;
+} StructItemSpec;
+
+/**
+ * A cache of the two key attributes of a CReadableTransport,
+ * so we don't have to keep calling PyObject_GetAttr.
+ */
+typedef struct {
+  PyObject* stringiobuf;
+  PyObject* refill_callable;
+} DecodeBuffer;
+
+/** Pointer to interned string to speed up attribute lookup. */
+static PyObject* INTERN_STRING(cstringio_buf);
+/** Pointer to interned string to speed up attribute lookup. */
+static PyObject* INTERN_STRING(cstringio_refill);
+
+static inline bool
+check_ssize_t_32(Py_ssize_t len) {
+  // error from getting the int
+  if (INT_CONV_ERROR_OCCURRED(len)) {
+    return false;
+  }
+  if (!CHECK_RANGE(len, 0, INT32_MAX)) {
+    PyErr_SetString(PyExc_OverflowError, "string size out of range");
+    return false;
+  }
+  return true;
+}
+
+static inline bool
+parse_pyint(PyObject* o, int32_t* ret, int32_t min, int32_t max) {
+  long val = PyInt_AsLong(o);
+
+  if (INT_CONV_ERROR_OCCURRED(val)) {
+    return false;
+  }
+  if (!CHECK_RANGE(val, min, max)) {
+    PyErr_SetString(PyExc_OverflowError, "int out of range");
+    return false;
+  }
+
+  *ret = (int32_t) val;
+  return true;
+}
+
+
+/* --- FUNCTIONS TO PARSE STRUCT SPECIFICATOINS --- */
+
+static bool
+parse_set_list_args(SetListTypeArgs* dest, PyObject* typeargs) {
+  if (PyTuple_Size(typeargs) != 2) {
+    PyErr_SetString(PyExc_TypeError, "expecting tuple of size 2 for list/set type args");
+    return false;
+  }
+
+  dest->element_type = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 0));
+  if (INT_CONV_ERROR_OCCURRED(dest->element_type)) {
+    return false;
+  }
+
+  dest->typeargs = PyTuple_GET_ITEM(typeargs, 1);
+
+  return true;
+}
+
+static bool
+parse_map_args(MapTypeArgs* dest, PyObject* typeargs) {
+  if (PyTuple_Size(typeargs) != 4) {
+    PyErr_SetString(PyExc_TypeError, "expecting 4 arguments for typeargs to map");
+    return false;
+  }
+
+  dest->ktag = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 0));
+  if (INT_CONV_ERROR_OCCURRED(dest->ktag)) {
+    return false;
+  }
+
+  dest->vtag = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 2));
+  if (INT_CONV_ERROR_OCCURRED(dest->vtag)) {
+    return false;
+  }
+
+  dest->ktypeargs = PyTuple_GET_ITEM(typeargs, 1);
+  dest->vtypeargs = PyTuple_GET_ITEM(typeargs, 3);
+
+  return true;
+}
+
+static bool
+parse_struct_args(StructTypeArgs* dest, PyObject* typeargs) {
+  if (PyTuple_Size(typeargs) != 2) {
+    PyErr_SetString(PyExc_TypeError, "expecting tuple of size 2 for struct args");
+    return false;
+  }
+
+  dest->klass = PyTuple_GET_ITEM(typeargs, 0);
+  dest->spec = PyTuple_GET_ITEM(typeargs, 1);
+
+  return true;
+}
+
+static int
+parse_struct_item_spec(StructItemSpec* dest, PyObject* spec_tuple) {
+
+  // i'd like to use ParseArgs here, but it seems to be a bottleneck.
+  if (PyTuple_Size(spec_tuple) != 5) {
+    PyErr_SetString(PyExc_TypeError, "expecting 5 arguments for spec tuple");
+    return false;
+  }
+
+  dest->tag = PyInt_AsLong(PyTuple_GET_ITEM(spec_tuple, 0));
+  if (INT_CONV_ERROR_OCCURRED(dest->tag)) {
+    return false;
+  }
+
+  dest->type = PyInt_AsLong(PyTuple_GET_ITEM(spec_tuple, 1));
+  if (INT_CONV_ERROR_OCCURRED(dest->type)) {
+    return false;
+  }
+
+  dest->attrname = PyTuple_GET_ITEM(spec_tuple, 2);
+  dest->typeargs = PyTuple_GET_ITEM(spec_tuple, 3);
+  dest->defval = PyTuple_GET_ITEM(spec_tuple, 4);
+  return true;
+}
+
+/* ====== END UTILITIES ====== */
+
+
+/* ====== BEGIN WRITING FUNCTIONS ====== */
+
+/* --- LOW-LEVEL WRITING FUNCTIONS --- */
+
+static void writeByte(PyObject* outbuf, int8_t val) {
+  int8_t net = val;
+  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int8_t));
+}
+
+static void writeI16(PyObject* outbuf, int16_t val) {
+  int16_t net = (int16_t)htons(val);
+  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int16_t));
+}
+
+static void writeI32(PyObject* outbuf, int32_t val) {
+  int32_t net = (int32_t)htonl(val);
+  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int32_t));
+}
+
+static void writeI64(PyObject* outbuf, int64_t val) {
+  int64_t net = (int64_t)htonll(val);
+  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int64_t));
+}
+
+static void writeDouble(PyObject* outbuf, double dub) {
+  // Unfortunately, bitwise_cast doesn't work in C.  Bad C!
+  union {
+    double f;
+    int64_t t;
+  } transfer;
+  transfer.f = dub;
+  writeI64(outbuf, transfer.t);
+}
+
+
+/* --- MAIN RECURSIVE OUTPUT FUCNTION -- */
+
+static int
+output_val(PyObject* output, PyObject* value, TType type, PyObject* typeargs) {
+  /*
+   * Refcounting Strategy:
+   *
+   * We assume that elements of the thrift_spec tuple are not going to be
+   * mutated, so we don't ref count those at all. Other than that, we try to
+   * keep a reference to all the user-created objects while we work with them.
+   * output_val assumes that a reference is already held. The *caller* is
+   * responsible for handling references
+   */
+
+  switch (type) {
+
+  case T_BOOL: {
+    int v = PyObject_IsTrue(value);
+    if (v == -1) {
+      return false;
+    }
+
+    writeByte(output, (int8_t) v);
+    break;
+  }
+  case T_I08: {
+    int32_t val;
+
+    if (!parse_pyint(value, &val, INT8_MIN, INT8_MAX)) {
+      return false;
+    }
+
+    writeByte(output, (int8_t) val);
+    break;
+  }
+  case T_I16: {
+    int32_t val;
+
+    if (!parse_pyint(value, &val, INT16_MIN, INT16_MAX)) {
+      return false;
+    }
+
+    writeI16(output, (int16_t) val);
+    break;
+  }
+  case T_I32: {
+    int32_t val;
+
+    if (!parse_pyint(value, &val, INT32_MIN, INT32_MAX)) {
+      return false;
+    }
+
+    writeI32(output, val);
+    break;
+  }
+  case T_I64: {
+    int64_t nval = PyLong_AsLongLong(value);
+
+    if (INT_CONV_ERROR_OCCURRED(nval)) {
+      return false;
+    }
+
+    if (!CHECK_RANGE(nval, INT64_MIN, INT64_MAX)) {
+      PyErr_SetString(PyExc_OverflowError, "int out of range");
+      return false;
+    }
+
+    writeI64(output, nval);
+    break;
+  }
+
+  case T_DOUBLE: {
+    double nval = PyFloat_AsDouble(value);
+    if (nval == -1.0 && PyErr_Occurred()) {
+      return false;
+    }
+
+    writeDouble(output, nval);
+    break;
+  }
+
+  case T_STRING: {
+    Py_ssize_t len = PyString_Size(value);
+
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    writeI32(output, (int32_t) len);
+    PycStringIO->cwrite(output, PyString_AsString(value), (int32_t) len);
+    break;
+  }
+
+  case T_LIST:
+  case T_SET: {
+    Py_ssize_t len;
+    SetListTypeArgs parsedargs;
+    PyObject *item;
+    PyObject *iterator;
+
+    if (!parse_set_list_args(&parsedargs, typeargs)) {
+      return false;
+    }
+
+    len = PyObject_Length(value);
+
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    writeByte(output, parsedargs.element_type);
+    writeI32(output, (int32_t) len);
+
+    iterator =  PyObject_GetIter(value);
+    if (iterator == NULL) {
+      return false;
+    }
+
+    while ((item = PyIter_Next(iterator))) {
+      if (!output_val(output, item, parsedargs.element_type, parsedargs.typeargs)) {
+        Py_DECREF(item);
+        Py_DECREF(iterator);
+        return false;
+      }
+      Py_DECREF(item);
+    }
+
+    Py_DECREF(iterator);
+
+    if (PyErr_Occurred()) {
+      return false;
+    }
+
+    break;
+  }
+
+  case T_MAP: {
+    PyObject *k, *v;
+    Py_ssize_t pos = 0;
+    Py_ssize_t len;
+
+    MapTypeArgs parsedargs;
+
+    len = PyDict_Size(value);
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    if (!parse_map_args(&parsedargs, typeargs)) {
+      return false;
+    }
+
+    writeByte(output, parsedargs.ktag);
+    writeByte(output, parsedargs.vtag);
+    writeI32(output, len);
+
+    // TODO(bmaurer): should support any mapping, not just dicts
+    while (PyDict_Next(value, &pos, &k, &v)) {
+      // TODO(dreiss): Think hard about whether these INCREFs actually
+      //               turn any unsafe scenarios into safe scenarios.
+      Py_INCREF(k);
+      Py_INCREF(v);
+
+      if (!output_val(output, k, parsedargs.ktag, parsedargs.ktypeargs)
+          || !output_val(output, v, parsedargs.vtag, parsedargs.vtypeargs)) {
+        Py_DECREF(k);
+        Py_DECREF(v);
+        return false;
+      }
+      Py_DECREF(k);
+      Py_DECREF(v);
+    }
+    break;
+  }
+
+  // TODO(dreiss): Consider breaking this out as a function
+  //               the way we did for decode_struct.
+  case T_STRUCT: {
+    StructTypeArgs parsedargs;
+    Py_ssize_t nspec;
+    Py_ssize_t i;
+
+    if (!parse_struct_args(&parsedargs, typeargs)) {
+      return false;
+    }
+
+    nspec = PyTuple_Size(parsedargs.spec);
+
+    if (nspec == -1) {
+      return false;
+    }
+
+    for (i = 0; i < nspec; i++) {
+      StructItemSpec parsedspec;
+      PyObject* spec_tuple;
+      PyObject* instval = NULL;
+
+      spec_tuple = PyTuple_GET_ITEM(parsedargs.spec, i);
+      if (spec_tuple == Py_None) {
+        continue;
+      }
+
+      if (!parse_struct_item_spec (&parsedspec, spec_tuple)) {
+        return false;
+      }
+
+      instval = PyObject_GetAttr(value, parsedspec.attrname);
+
+      if (!instval) {
+        return false;
+      }
+
+      if (instval == Py_None) {
+        Py_DECREF(instval);
+        continue;
+      }
+
+      writeByte(output, (int8_t) parsedspec.type);
+      writeI16(output, parsedspec.tag);
+
+      if (!output_val(output, instval, parsedspec.type, parsedspec.typeargs)) {
+        Py_DECREF(instval);
+        return false;
+      }
+
+      Py_DECREF(instval);
+    }
+
+    writeByte(output, (int8_t)T_STOP);
+    break;
+  }
+
+  case T_STOP:
+  case T_VOID:
+  case T_UTF16:
+  case T_UTF8:
+  case T_U64:
+  default:
+    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
+    return false;
+
+  }
+
+  return true;
+}
+
+
+/* --- TOP-LEVEL WRAPPER FOR OUTPUT -- */
+
+static PyObject *
+encode_binary(PyObject *self, PyObject *args) {
+  PyObject* enc_obj;
+  PyObject* type_args;
+  PyObject* buf;
+  PyObject* ret = NULL;
+
+  if (!PyArg_ParseTuple(args, "OO", &enc_obj, &type_args)) {
+    return NULL;
+  }
+
+  buf = PycStringIO->NewOutput(INIT_OUTBUF_SIZE);
+  if (output_val(buf, enc_obj, T_STRUCT, type_args)) {
+    ret = PycStringIO->cgetvalue(buf);
+  }
+
+  Py_DECREF(buf);
+  return ret;
+}
+
+/* ====== END WRITING FUNCTIONS ====== */
+
+
+/* ====== BEGIN READING FUNCTIONS ====== */
+
+/* --- LOW-LEVEL READING FUNCTIONS --- */
+
+static void
+free_decodebuf(DecodeBuffer* d) {
+  Py_XDECREF(d->stringiobuf);
+  Py_XDECREF(d->refill_callable);
+}
+
+static bool
+decode_buffer_from_obj(DecodeBuffer* dest, PyObject* obj) {
+  dest->stringiobuf = PyObject_GetAttr(obj, INTERN_STRING(cstringio_buf));
+  if (!dest->stringiobuf) {
+    return false;
+  }
+
+  if (!PycStringIO_InputCheck(dest->stringiobuf)) {
+    free_decodebuf(dest);
+    PyErr_SetString(PyExc_TypeError, "expecting stringio input");
+    return false;
+  }
+
+  dest->refill_callable = PyObject_GetAttr(obj, INTERN_STRING(cstringio_refill));
+
+  if(!dest->refill_callable) {
+    free_decodebuf(dest);
+    return false;
+  }
+
+  if (!PyCallable_Check(dest->refill_callable)) {
+    free_decodebuf(dest);
+    PyErr_SetString(PyExc_TypeError, "expecting callable");
+    return false;
+  }
+
+  return true;
+}
+
+static bool readBytes(DecodeBuffer* input, char** output, int len) {
+  int read;
+
+  // TODO(dreiss): Don't fear the malloc.  Think about taking a copy of
+  //               the partial read instead of forcing the transport
+  //               to prepend it to its buffer.
+
+  read = PycStringIO->cread(input->stringiobuf, output, len);
+
+  if (read == len) {
+    return true;
+  } else if (read == -1) {
+    return false;
+  } else {
+    PyObject* newiobuf;
+
+    // using building functions as this is a rare codepath
+    newiobuf = PyObject_CallFunction(
+        input->refill_callable, "s#i", *output, read, len, NULL);
+    if (newiobuf == NULL) {
+      return false;
+    }
+
+    // must do this *AFTER* the call so that we don't deref the io buffer
+    Py_CLEAR(input->stringiobuf);
+    input->stringiobuf = newiobuf;
+
+    read = PycStringIO->cread(input->stringiobuf, output, len);
+
+    if (read == len) {
+      return true;
+    } else if (read == -1) {
+      return false;
+    } else {
+      // TODO(dreiss): This could be a valid code path for big binary blobs.
+      PyErr_SetString(PyExc_TypeError,
+          "refill claimed to have refilled the buffer, but didn't!!");
+      return false;
+    }
+  }
+}
+
+static int8_t readByte(DecodeBuffer* input) {
+  char* buf;
+  if (!readBytes(input, &buf, sizeof(int8_t))) {
+    return -1;
+  }
+
+  return *(int8_t*) buf;
+}
+
+static int16_t readI16(DecodeBuffer* input) {
+  char* buf;
+  if (!readBytes(input, &buf, sizeof(int16_t))) {
+    return -1;
+  }
+
+  return (int16_t) ntohs(*(int16_t*) buf);
+}
+
+static int32_t readI32(DecodeBuffer* input) {
+  char* buf;
+  if (!readBytes(input, &buf, sizeof(int32_t))) {
+    return -1;
+  }
+  return (int32_t) ntohl(*(int32_t*) buf);
+}
+
+
+static int64_t readI64(DecodeBuffer* input) {
+  char* buf;
+  if (!readBytes(input, &buf, sizeof(int64_t))) {
+    return -1;
+  }
+
+  return (int64_t) ntohll(*(int64_t*) buf);
+}
+
+static double readDouble(DecodeBuffer* input) {
+  union {
+    int64_t f;
+    double t;
+  } transfer;
+
+  transfer.f = readI64(input);
+  if (transfer.f == -1) {
+    return -1;
+  }
+  return transfer.t;
+}
+
+static bool
+checkTypeByte(DecodeBuffer* input, TType expected) {
+  TType got = readByte(input);
+  if (INT_CONV_ERROR_OCCURRED(got)) {
+    return false;
+  }
+
+  if (expected != got) {
+    PyErr_SetString(PyExc_TypeError, "got wrong ttype while reading field");
+    return false;
+  }
+  return true;
+}
+
+static bool
+skip(DecodeBuffer* input, TType type) {
+#define SKIPBYTES(n) \
+  do { \
+    if (!readBytes(input, &dummy_buf, (n))) { \
+      return false; \
+    } \
+  } while(0)
+
+  char* dummy_buf;
+
+  switch (type) {
+
+  case T_BOOL:
+  case T_I08: SKIPBYTES(1); break;
+  case T_I16: SKIPBYTES(2); break;
+  case T_I32: SKIPBYTES(4); break;
+  case T_I64:
+  case T_DOUBLE: SKIPBYTES(8); break;
+
+  case T_STRING: {
+    // TODO(dreiss): Find out if these check_ssize_t32s are really necessary.
+    int len = readI32(input);
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+    SKIPBYTES(len);
+    break;
+  }
+
+  case T_LIST:
+  case T_SET: {
+    TType etype;
+    int len, i;
+
+    etype = readByte(input);
+    if (etype == -1) {
+      return false;
+    }
+
+    len = readI32(input);
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    for (i = 0; i < len; i++) {
+      if (!skip(input, etype)) {
+        return false;
+      }
+    }
+    break;
+  }
+
+  case T_MAP: {
+    TType ktype, vtype;
+    int len, i;
+
+    ktype = readByte(input);
+    if (ktype == -1) {
+      return false;
+    }
+
+    vtype = readByte(input);
+    if (vtype == -1) {
+      return false;
+    }
+
+    len = readI32(input);
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    for (i = 0; i < len; i++) {
+      if (!(skip(input, ktype) && skip(input, vtype))) {
+        return false;
+      }
+    }
+    break;
+  }
+
+  case T_STRUCT: {
+    while (true) {
+      TType type;
+
+      type = readByte(input);
+      if (type == -1) {
+        return false;
+      }
+
+      if (type == T_STOP)
+        break;
+
+      SKIPBYTES(2); // tag
+      if (!skip(input, type)) {
+        return false;
+      }
+    }
+    break;
+  }
+
+  case T_STOP:
+  case T_VOID:
+  case T_UTF16:
+  case T_UTF8:
+  case T_U64:
+  default:
+    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
+    return false;
+
+  }
+
+  return true;
+
+#undef SKIPBYTES
+}
+
+
+/* --- HELPER FUNCTION FOR DECODE_VAL --- */
+
+static PyObject*
+decode_val(DecodeBuffer* input, TType type, PyObject* typeargs);
+
+static bool
+decode_struct(DecodeBuffer* input, PyObject* output, PyObject* spec_seq) {
+  int spec_seq_len = PyTuple_Size(spec_seq);
+  if (spec_seq_len == -1) {
+    return false;
+  }
+
+  while (true) {
+    TType type;
+    int16_t tag;
+    PyObject* item_spec;
+    PyObject* fieldval = NULL;
+    StructItemSpec parsedspec;
+
+    type = readByte(input);
+    if (type == -1) {
+      return false;
+    }
+    if (type == T_STOP) {
+      break;
+    }
+    tag = readI16(input);
+    if (INT_CONV_ERROR_OCCURRED(tag)) {
+      return false;
+    }
+    if (tag >= 0 && tag < spec_seq_len) {
+      item_spec = PyTuple_GET_ITEM(spec_seq, tag);
+    } else {
+      item_spec = Py_None;
+    }
+
+    if (item_spec == Py_None) {
+      if (!skip(input, type)) {
+        return false;
+      } else {
+        continue;
+      }
+    }
+
+    if (!parse_struct_item_spec(&parsedspec, item_spec)) {
+      return false;
+    }
+    if (parsedspec.type != type) {
+      if (!skip(input, type)) {
+        PyErr_SetString(PyExc_TypeError, "struct field had wrong type while reading and can't be skipped");
+        return false;
+      } else {
+        continue;
+      }
+    }
+
+    fieldval = decode_val(input, parsedspec.type, parsedspec.typeargs);
+    if (fieldval == NULL) {
+      return false;
+    }
+
+    if (PyObject_SetAttr(output, parsedspec.attrname, fieldval) == -1) {
+      Py_DECREF(fieldval);
+      return false;
+    }
+    Py_DECREF(fieldval);
+  }
+  return true;
+}
+
+
+/* --- MAIN RECURSIVE INPUT FUCNTION --- */
+
+// Returns a new reference.
+static PyObject*
+decode_val(DecodeBuffer* input, TType type, PyObject* typeargs) {
+  switch (type) {
+
+  case T_BOOL: {
+    int8_t v = readByte(input);
+    if (INT_CONV_ERROR_OCCURRED(v)) {
+      return NULL;
+    }
+
+    switch (v) {
+    case 0: Py_RETURN_FALSE;
+    case 1: Py_RETURN_TRUE;
+    // Don't laugh.  This is a potentially serious issue.
+    default: PyErr_SetString(PyExc_TypeError, "boolean out of range"); return NULL;
+    }
+    break;
+  }
+  case T_I08: {
+    int8_t v = readByte(input);
+    if (INT_CONV_ERROR_OCCURRED(v)) {
+      return NULL;
+    }
+
+    return PyInt_FromLong(v);
+  }
+  case T_I16: {
+    int16_t v = readI16(input);
+    if (INT_CONV_ERROR_OCCURRED(v)) {
+      return NULL;
+    }
+    return PyInt_FromLong(v);
+  }
+  case T_I32: {
+    int32_t v = readI32(input);
+    if (INT_CONV_ERROR_OCCURRED(v)) {
+      return NULL;
+    }
+    return PyInt_FromLong(v);
+  }
+
+  case T_I64: {
+    int64_t v = readI64(input);
+    if (INT_CONV_ERROR_OCCURRED(v)) {
+      return NULL;
+    }
+    // TODO(dreiss): Find out if we can take this fastpath always when
+    //               sizeof(long) == sizeof(long long).
+    if (CHECK_RANGE(v, LONG_MIN, LONG_MAX)) {
+      return PyInt_FromLong((long) v);
+    }
+
+    return PyLong_FromLongLong(v);
+  }
+
+  case T_DOUBLE: {
+    double v = readDouble(input);
+    if (v == -1.0 && PyErr_Occurred()) {
+      return false;
+    }
+    return PyFloat_FromDouble(v);
+  }
+
+  case T_STRING: {
+    Py_ssize_t len = readI32(input);
+    char* buf;
+    if (!readBytes(input, &buf, len)) {
+      return NULL;
+    }
+
+    return PyString_FromStringAndSize(buf, len);
+  }
+
+  case T_LIST:
+  case T_SET: {
+    SetListTypeArgs parsedargs;
+    int32_t len;
+    PyObject* ret = NULL;
+    int i;
+
+    if (!parse_set_list_args(&parsedargs, typeargs)) {
+      return NULL;
+    }
+
+    if (!checkTypeByte(input, parsedargs.element_type)) {
+      return NULL;
+    }
+
+    len = readI32(input);
+    if (!check_ssize_t_32(len)) {
+      return NULL;
+    }
+
+    ret = PyList_New(len);
+    if (!ret) {
+      return NULL;
+    }
+
+    for (i = 0; i < len; i++) {
+      PyObject* item = decode_val(input, parsedargs.element_type, parsedargs.typeargs);
+      if (!item) {
+        Py_DECREF(ret);
+        return NULL;
+      }
+      PyList_SET_ITEM(ret, i, item);
+    }
+
+    // TODO(dreiss): Consider biting the bullet and making two separate cases
+    //               for list and set, avoiding this post facto conversion.
+    if (type == T_SET) {
+      PyObject* setret;
+#if (PY_VERSION_HEX < 0x02050000)
+      // hack needed for older versions
+      setret = PyObject_CallFunctionObjArgs((PyObject*)&PySet_Type, ret, NULL);
+#else
+      // official version
+      setret = PySet_New(ret);
+#endif
+      Py_DECREF(ret);
+      return setret;
+    }
+    return ret;
+  }
+
+  case T_MAP: {
+    int32_t len;
+    int i;
+    MapTypeArgs parsedargs;
+    PyObject* ret = NULL;
+
+    if (!parse_map_args(&parsedargs, typeargs)) {
+      return NULL;
+    }
+
+    if (!checkTypeByte(input, parsedargs.ktag)) {
+      return NULL;
+    }
+    if (!checkTypeByte(input, parsedargs.vtag)) {
+      return NULL;
+    }
+
+    len = readI32(input);
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    ret = PyDict_New();
+    if (!ret) {
+      goto error;
+    }
+
+    for (i = 0; i < len; i++) {
+      PyObject* k = NULL;
+      PyObject* v = NULL;
+      k = decode_val(input, parsedargs.ktag, parsedargs.ktypeargs);
+      if (k == NULL) {
+        goto loop_error;
+      }
+      v = decode_val(input, parsedargs.vtag, parsedargs.vtypeargs);
+      if (v == NULL) {
+        goto loop_error;
+      }
+      if (PyDict_SetItem(ret, k, v) == -1) {
+        goto loop_error;
+      }
+
+      Py_DECREF(k);
+      Py_DECREF(v);
+      continue;
+
+      // Yuck!  Destructors, anyone?
+      loop_error:
+      Py_XDECREF(k);
+      Py_XDECREF(v);
+      goto error;
+    }
+
+    return ret;
+
+    error:
+    Py_XDECREF(ret);
+    return NULL;
+  }
+
+  case T_STRUCT: {
+    StructTypeArgs parsedargs;
+	PyObject* ret;
+    if (!parse_struct_args(&parsedargs, typeargs)) {
+      return NULL;
+    }
+
+    ret = PyObject_CallObject(parsedargs.klass, NULL);
+    if (!ret) {
+      return NULL;
+    }
+
+    if (!decode_struct(input, ret, parsedargs.spec)) {
+      Py_DECREF(ret);
+      return NULL;
+    }
+
+    return ret;
+  }
+
+  case T_STOP:
+  case T_VOID:
+  case T_UTF16:
+  case T_UTF8:
+  case T_U64:
+  default:
+    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
+    return NULL;
+  }
+}
+
+
+/* --- TOP-LEVEL WRAPPER FOR INPUT -- */
+
+static PyObject*
+decode_binary(PyObject *self, PyObject *args) {
+  PyObject* output_obj = NULL;
+  PyObject* transport = NULL;
+  PyObject* typeargs = NULL;
+  StructTypeArgs parsedargs;
+  DecodeBuffer input = {0, 0};
+  
+  if (!PyArg_ParseTuple(args, "OOO", &output_obj, &transport, &typeargs)) {
+    return NULL;
+  }
+
+  if (!parse_struct_args(&parsedargs, typeargs)) {
+    return NULL;
+  }
+
+  if (!decode_buffer_from_obj(&input, transport)) {
+    return NULL;
+  }
+
+  if (!decode_struct(&input, output_obj, parsedargs.spec)) {
+    free_decodebuf(&input);
+    return NULL;
+  }
+
+  free_decodebuf(&input);
+
+  Py_RETURN_NONE;
+}
+
+/* ====== END READING FUNCTIONS ====== */
+
+
+/* -- PYTHON MODULE SETUP STUFF --- */
+
+static PyMethodDef ThriftFastBinaryMethods[] = {
+
+  {"encode_binary",  encode_binary, METH_VARARGS, ""},
+  {"decode_binary",  decode_binary, METH_VARARGS, ""},
+
+  {NULL, NULL, 0, NULL}        /* Sentinel */
+};
+
+PyMODINIT_FUNC
+initfastbinary(void) {
+#define INIT_INTERN_STRING(value) \
+  do { \
+    INTERN_STRING(value) = PyString_InternFromString(#value); \
+    if(!INTERN_STRING(value)) return; \
+  } while(0)
+
+  INIT_INTERN_STRING(cstringio_buf);
+  INIT_INTERN_STRING(cstringio_refill);
+#undef INIT_INTERN_STRING
+
+  PycString_IMPORT;
+  if (PycStringIO == NULL) return;
+
+  (void) Py_InitModule("thrift.protocol.fastbinary", ThriftFastBinaryMethods);
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py
new file mode 100644
index 0000000..6ee18dd
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py
@@ -0,0 +1,87 @@
+#
+# 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.
+#
+
+import BaseHTTPServer
+
+from ..server import TServer
+from ..transport import TTransport
+
+
+class ResponseException(Exception):
+  """Allows handlers to override the HTTP response
+
+  Normally, THttpServer always sends a 200 response.  If a handler wants
+  to override this behavior (e.g., to simulate a misconfigured or
+  overloaded web server during testing), it can raise a ResponseException.
+  The function passed to the constructor will be called with the
+  RequestHandler as its only argument.
+  """
+  def __init__(self, handler):
+    self.handler = handler
+
+
+class THttpServer(TServer.TServer):
+  """A simple HTTP-based Thrift server
+
+  This class is not very performant, but it is useful (for example) for
+  acting as a mock version of an Apache-based PHP Thrift endpoint.
+  """
+  def __init__(self,
+               processor,
+               server_address,
+               inputProtocolFactory,
+               outputProtocolFactory=None,
+               server_class=BaseHTTPServer.HTTPServer):
+    """Set up protocol factories and HTTP server.
+
+    See BaseHTTPServer for server_address.
+    See TServer for protocol factories.
+    """
+    if outputProtocolFactory is None:
+      outputProtocolFactory = inputProtocolFactory
+
+    TServer.TServer.__init__(self, processor, None, None, None,
+        inputProtocolFactory, outputProtocolFactory)
+
+    thttpserver = self
+
+    class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
+      def do_POST(self):
+        # Don't care about the request path.
+        itrans = TTransport.TFileObjectTransport(self.rfile)
+        otrans = TTransport.TFileObjectTransport(self.wfile)
+        itrans = TTransport.TBufferedTransport(
+          itrans, int(self.headers['Content-Length']))
+        otrans = TTransport.TMemoryBuffer()
+        iprot = thttpserver.inputProtocolFactory.getProtocol(itrans)
+        oprot = thttpserver.outputProtocolFactory.getProtocol(otrans)
+        try:
+          thttpserver.processor.process(iprot, oprot)
+        except ResponseException, exn:
+          exn.handler(self)
+        else:
+          self.send_response(200)
+          self.send_header("content-type", "application/x-thrift")
+          self.end_headers()
+          self.wfile.write(otrans.getvalue())
+
+    self.httpd = server_class(server_address, RequestHander)
+
+  def serve(self):
+    self.httpd.serve_forever()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
new file mode 100644
index 0000000..aa27991
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
@@ -0,0 +1,346 @@
+#
+# 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.
+#
+"""Implementation of non-blocking server.
+
+The main idea of the server is to receive and send requests
+only from the main thread.
+
+The thread poool should be sized for concurrent tasks, not
+maximum connections
+"""
+import threading
+import socket
+import Queue
+import select
+import struct
+import logging
+
+from ..transport import TTransport
+from ..protocol.TBinaryProtocol import TBinaryProtocolFactory
+
+__all__ = ['TNonblockingServer']
+
+
+class Worker(threading.Thread):
+    """Worker is a small helper to process incoming connection."""
+
+    def __init__(self, queue):
+        threading.Thread.__init__(self)
+        self.queue = queue
+
+    def run(self):
+        """Process queries from task queue, stop if processor is None."""
+        while True:
+            try:
+                processor, iprot, oprot, otrans, callback = self.queue.get()
+                if processor is None:
+                    break
+                processor.process(iprot, oprot)
+                callback(True, otrans.getvalue())
+            except Exception:
+                logging.exception("Exception while processing request")
+                callback(False, '')
+
+WAIT_LEN = 0
+WAIT_MESSAGE = 1
+WAIT_PROCESS = 2
+SEND_ANSWER = 3
+CLOSED = 4
+
+
+def locked(func):
+    """Decorator which locks self.lock."""
+    def nested(self, *args, **kwargs):
+        self.lock.acquire()
+        try:
+            return func(self, *args, **kwargs)
+        finally:
+            self.lock.release()
+    return nested
+
+
+def socket_exception(func):
+    """Decorator close object on socket.error."""
+    def read(self, *args, **kwargs):
+        try:
+            return func(self, *args, **kwargs)
+        except socket.error:
+            self.close()
+    return read
+
+
+class Connection:
+    """Basic class is represented connection.
+
+    It can be in state:
+        WAIT_LEN --- connection is reading request len.
+        WAIT_MESSAGE --- connection is reading request.
+        WAIT_PROCESS --- connection has just read whole request and
+                         waits for call ready routine.
+        SEND_ANSWER --- connection is sending answer string (including length
+                        of answer).
+        CLOSED --- socket was closed and connection should be deleted.
+    """
+    def __init__(self, new_socket, wake_up):
+        self.socket = new_socket
+        self.socket.setblocking(False)
+        self.status = WAIT_LEN
+        self.len = 0
+        self.message = ''
+        self.lock = threading.Lock()
+        self.wake_up = wake_up
+
+    def _read_len(self):
+        """Reads length of request.
+
+        It's a safer alternative to self.socket.recv(4)
+        """
+        read = self.socket.recv(4 - len(self.message))
+        if len(read) == 0:
+            # if we read 0 bytes and self.message is empty, then
+            # the client closed the connection
+            if len(self.message) != 0:
+                logging.error("can't read frame size from socket")
+            self.close()
+            return
+        self.message += read
+        if len(self.message) == 4:
+            self.len, = struct.unpack('!i', self.message)
+            if self.len < 0:
+                logging.error("negative frame size, it seems client "
+                              "doesn't use FramedTransport")
+                self.close()
+            elif self.len == 0:
+                logging.error("empty frame, it's really strange")
+                self.close()
+            else:
+                self.message = ''
+                self.status = WAIT_MESSAGE
+
+    @socket_exception
+    def read(self):
+        """Reads data from stream and switch state."""
+        assert self.status in (WAIT_LEN, WAIT_MESSAGE)
+        if self.status == WAIT_LEN:
+            self._read_len()
+            # go back to the main loop here for simplicity instead of
+            # falling through, even though there is a good chance that
+            # the message is already available
+        elif self.status == WAIT_MESSAGE:
+            read = self.socket.recv(self.len - len(self.message))
+            if len(read) == 0:
+                logging.error("can't read frame from socket (get %d of "
+                              "%d bytes)" % (len(self.message), self.len))
+                self.close()
+                return
+            self.message += read
+            if len(self.message) == self.len:
+                self.status = WAIT_PROCESS
+
+    @socket_exception
+    def write(self):
+        """Writes data from socket and switch state."""
+        assert self.status == SEND_ANSWER
+        sent = self.socket.send(self.message)
+        if sent == len(self.message):
+            self.status = WAIT_LEN
+            self.message = ''
+            self.len = 0
+        else:
+            self.message = self.message[sent:]
+
+    @locked
+    def ready(self, all_ok, message):
+        """Callback function for switching state and waking up main thread.
+
+        This function is the only function witch can be called asynchronous.
+
+        The ready can switch Connection to three states:
+            WAIT_LEN if request was oneway.
+            SEND_ANSWER if request was processed in normal way.
+            CLOSED if request throws unexpected exception.
+
+        The one wakes up main thread.
+        """
+        assert self.status == WAIT_PROCESS
+        if not all_ok:
+            self.close()
+            self.wake_up()
+            return
+        self.len = ''
+        if len(message) == 0:
+            # it was a oneway request, do not write answer
+            self.message = ''
+            self.status = WAIT_LEN
+        else:
+            self.message = struct.pack('!i', len(message)) + message
+            self.status = SEND_ANSWER
+        self.wake_up()
+
+    @locked
+    def is_writeable(self):
+        """Return True if connection should be added to write list of select"""
+        return self.status == SEND_ANSWER
+
+    # it's not necessary, but...
+    @locked
+    def is_readable(self):
+        """Return True if connection should be added to read list of select"""
+        return self.status in (WAIT_LEN, WAIT_MESSAGE)
+
+    @locked
+    def is_closed(self):
+        """Returns True if connection is closed."""
+        return self.status == CLOSED
+
+    def fileno(self):
+        """Returns the file descriptor of the associated socket."""
+        return self.socket.fileno()
+
+    def close(self):
+        """Closes connection"""
+        self.status = CLOSED
+        self.socket.close()
+
+
+class TNonblockingServer:
+    """Non-blocking server."""
+
+    def __init__(self,
+                 processor,
+                 lsocket,
+                 inputProtocolFactory=None,
+                 outputProtocolFactory=None,
+                 threads=10):
+        self.processor = processor
+        self.socket = lsocket
+        self.in_protocol = inputProtocolFactory or TBinaryProtocolFactory()
+        self.out_protocol = outputProtocolFactory or self.in_protocol
+        self.threads = int(threads)
+        self.clients = {}
+        self.tasks = Queue.Queue()
+        self._read, self._write = socket.socketpair()
+        self.prepared = False
+        self._stop = False
+
+    def setNumThreads(self, num):
+        """Set the number of worker threads that should be created."""
+        # implement ThreadPool interface
+        assert not self.prepared, "Can't change number of threads after start"
+        self.threads = num
+
+    def prepare(self):
+        """Prepares server for serve requests."""
+        if self.prepared:
+            return
+        self.socket.listen()
+        for _ in xrange(self.threads):
+            thread = Worker(self.tasks)
+            thread.setDaemon(True)
+            thread.start()
+        self.prepared = True
+
+    def wake_up(self):
+        """Wake up main thread.
+
+        The server usualy waits in select call in we should terminate one.
+        The simplest way is using socketpair.
+
+        Select always wait to read from the first socket of socketpair.
+
+        In this case, we can just write anything to the second socket from
+        socketpair.
+        """
+        self._write.send('1')
+
+    def stop(self):
+        """Stop the server.
+
+        This method causes the serve() method to return.  stop() may be invoked
+        from within your handler, or from another thread.
+
+        After stop() is called, serve() will return but the server will still
+        be listening on the socket.  serve() may then be called again to resume
+        processing requests.  Alternatively, close() may be called after
+        serve() returns to close the server socket and shutdown all worker
+        threads.
+        """
+        self._stop = True
+        self.wake_up()
+
+    def _select(self):
+        """Does select on open connections."""
+        readable = [self.socket.handle.fileno(), self._read.fileno()]
+        writable = []
+        for i, connection in self.clients.items():
+            if connection.is_readable():
+                readable.append(connection.fileno())
+            if connection.is_writeable():
+                writable.append(connection.fileno())
+            if connection.is_closed():
+                del self.clients[i]
+        return select.select(readable, writable, readable)
+
+    def handle(self):
+        """Handle requests.
+
+        WARNING! You must call prepare() BEFORE calling handle()
+        """
+        assert self.prepared, "You have to call prepare before handle"
+        rset, wset, xset = self._select()
+        for readable in rset:
+            if readable == self._read.fileno():
+                # don't care i just need to clean readable flag
+                self._read.recv(1024)
+            elif readable == self.socket.handle.fileno():
+                client = self.socket.accept().handle
+                self.clients[client.fileno()] = Connection(client,
+                                                           self.wake_up)
+            else:
+                connection = self.clients[readable]
+                connection.read()
+                if connection.status == WAIT_PROCESS:
+                    itransport = TTransport.TMemoryBuffer(connection.message)
+                    otransport = TTransport.TMemoryBuffer()
+                    iprot = self.in_protocol.getProtocol(itransport)
+                    oprot = self.out_protocol.getProtocol(otransport)
+                    self.tasks.put([self.processor, iprot, oprot,
+                                    otransport, connection.ready])
+        for writeable in wset:
+            self.clients[writeable].write()
+        for oob in xset:
+            self.clients[oob].close()
+            del self.clients[oob]
+
+    def close(self):
+        """Closes the server."""
+        for _ in xrange(self.threads):
+            self.tasks.put([None, None, None, None, None])
+        self.socket.close()
+        self.prepared = False
+
+    def serve(self):
+        """Serve requests.
+
+        Serve requests forever, or until stop() is called.
+        """
+        self._stop = False
+        self.prepare()
+        while not self._stop:
+            self.handle()


[33/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/healthstats.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/healthstats.py b/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/healthstats.py
deleted file mode 100644
index 4ceb948..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/healthstats.py
+++ /dev/null
@@ -1,246 +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.
-
-from threading import Thread
-import time
-import psutil
-import os
-
-from abstracthealthstatisticspublisher import *
-from ..databridge.agent import *
-from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
-from ..util import cartridgeagentutils, cartridgeagentconstants
-
-
-class HealthStatisticsPublisherManager(Thread):
-    """
-    Read from an implementation of AbstractHealthStatisticsPublisher the value for memory usage and
-    load average and publishes them as ThriftEvents to a CEP server
-    """
-    STREAM_NAME = "cartridge_agent_health_stats"
-    STREAM_VERSION = "1.0.0"
-    STREAM_NICKNAME = "agent health stats"
-    STREAM_DESCRIPTION = "agent health stats"
-
-    def __init__(self, publish_interval):
-        """
-        Initializes a new HealthStatistsPublisherManager with a given number of seconds as the interval
-        :param int publish_interval: Number of seconds as the interval
-        :return: void
-        """
-        Thread.__init__(self)
-
-        self.log = LogFactory().get_log(__name__)
-
-        self.publish_interval = publish_interval
-        """:type : int"""
-
-        self.terminated = False
-
-        self.publisher = HealthStatisticsPublisher()
-        """:type : HealthStatisticsPublisher"""
-        # TODO: load plugins for the reader
-        self.stats_reader = DefaultHealthStatisticsReader()
-        """:type : AbstractHealthStatisticsReader"""
-
-    def run(self):
-        while not self.terminated:
-            time.sleep(self.publish_interval)
-
-            cartridge_stats = self.stats_reader.stat_cartridge_health()
-            self.log.debug("Publishing memory consumption: %r" % cartridge_stats.memory_usage)
-            self.publisher.publish_memory_usage(cartridge_stats.memory_usage)
-
-            self.log.debug("Publishing load average: %r" % cartridge_stats.load_avg)
-            self.publisher.publish_load_average(cartridge_stats.load_avg)
-
-        self.publisher.publisher.disconnect()
-
-
-class HealthStatisticsPublisher:
-    """
-    Publishes memory usage and load average to thrift server
-    """
-    log = LogFactory().get_log(__name__)
-
-    def __init__(self):
-
-        self.ports = []
-        self.ports.append(CEPPublisherConfiguration.get_instance().server_port)
-
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-        cartridgeagentutils.wait_until_ports_active(
-            CEPPublisherConfiguration.get_instance().server_ip,
-            self.ports,
-            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False)))
-        cep_active = cartridgeagentutils.check_ports_active(CEPPublisherConfiguration.get_instance().server_ip, self.ports)
-        if not cep_active:
-            raise CEPPublisherException("CEP server not active. Health statistics publishing aborted.")
-
-        self.stream_definition = HealthStatisticsPublisher.create_stream_definition()
-        HealthStatisticsPublisher.log.debug("Stream definition created: %r" % str(self.stream_definition))
-        self.publisher = ThriftPublisher(
-            CEPPublisherConfiguration.get_instance().server_ip,
-            CEPPublisherConfiguration.get_instance().server_port,
-            CEPPublisherConfiguration.get_instance().admin_username,
-            CEPPublisherConfiguration.get_instance().admin_password,
-            self.stream_definition)
-
-        HealthStatisticsPublisher.log.debug("HealthStatisticsPublisher initialized")
-
-    @staticmethod
-    def create_stream_definition():
-        """
-        Create a StreamDefinition for publishing to CEP
-        """
-        stream_def = StreamDefinition()
-        stream_def.name = HealthStatisticsPublisherManager.STREAM_NAME
-        stream_def.version = HealthStatisticsPublisherManager.STREAM_VERSION
-        stream_def.nickname = HealthStatisticsPublisherManager.STREAM_NICKNAME
-        stream_def.description = HealthStatisticsPublisherManager.STREAM_DESCRIPTION
-
-        stream_def.add_payloaddata_attribute("cluster_id", StreamDefinition.STRING)
-        stream_def.add_payloaddata_attribute("network_partition_id", StreamDefinition.STRING)
-        stream_def.add_payloaddata_attribute("member_id", StreamDefinition.STRING)
-        stream_def.add_payloaddata_attribute("partition_id", StreamDefinition.STRING)
-        stream_def.add_payloaddata_attribute("health_description", StreamDefinition.STRING)
-        stream_def.add_payloaddata_attribute("value", StreamDefinition.DOUBLE)
-
-        return stream_def
-
-    def publish_memory_usage(self, memory_usage):
-        """
-        Publishes the given memory usage value to the thrift server as a ThriftEvent
-        :param float memory_usage: memory usage
-        """
-
-        event = ThriftEvent()
-        event.payloadData.append(self.cartridge_agent_config.cluster_id)
-        event.payloadData.append(self.cartridge_agent_config.network_partition_id)
-        event.payloadData.append(self.cartridge_agent_config.member_id)
-        event.payloadData.append(self.cartridge_agent_config.partition_id)
-        event.payloadData.append(cartridgeagentconstants.MEMORY_CONSUMPTION)
-        event.payloadData.append(memory_usage)
-
-        HealthStatisticsPublisher.log.debug("Publishing cep event: [stream] %r [version] %r" % (self.stream_definition.name, self.stream_definition.version))
-        self.publisher.publish(event)
-
-    def publish_load_average(self, load_avg):
-        """
-        Publishes the given load average value to the thrift server as a ThriftEvent
-        :param float load_avg: load average value
-        """
-
-        event = ThriftEvent()
-        event.payloadData.append(self.cartridge_agent_config.cluster_id)
-        event.payloadData.append(self.cartridge_agent_config.network_partition_id)
-        event.payloadData.append(self.cartridge_agent_config.member_id)
-        event.payloadData.append(self.cartridge_agent_config.partition_id)
-        event.payloadData.append(cartridgeagentconstants.LOAD_AVERAGE)
-        event.payloadData.append(load_avg)
-
-        HealthStatisticsPublisher.log.debug("Publishing cep event: [stream] %r [version] %r" % (self.stream_definition.name, self.stream_definition.version))
-        self.publisher.publish(event)
-
-
-class DefaultHealthStatisticsReader(AbstractHealthStatisticsReader):
-    """
-    Default implementation of the AbstractHealthStatisticsReader
-    """
-
-    def __init__(self):
-        self.log = LogFactory().get_log(__name__)
-
-    def stat_cartridge_health(self):
-        cartridge_stats = CartridgeHealthStatistics()
-        cartridge_stats.memory_usage = DefaultHealthStatisticsReader.__read_mem_usage()
-        cartridge_stats.load_avg = DefaultHealthStatisticsReader.__read_load_avg()
-
-        self.log.debug("Memory read: %r, CPU read: %r" % (cartridge_stats.memory_usage, cartridge_stats.load_avg))
-        return cartridge_stats
-
-    @staticmethod
-    def __read_mem_usage():
-        return psutil.virtual_memory().percent
-
-    @staticmethod
-    def __read_load_avg():
-        (one, five, fifteen) = os.getloadavg()
-        return one
-
-
-class CEPPublisherConfiguration:
-    """
-    TODO: Extract common functionality
-    """
-
-    __instance = None
-    log = LogFactory().get_log(__name__)
-
-    @staticmethod
-    def get_instance():
-        """
-        Singleton instance retriever
-        :return: Instance
-        :rtype : CEPPublisherConfiguration
-        """
-        if CEPPublisherConfiguration.__instance is None:
-            CEPPublisherConfiguration.__instance = CEPPublisherConfiguration()
-
-        return CEPPublisherConfiguration.__instance
-
-    def __init__(self):
-        self.enabled = False
-        self.server_ip = None
-        self.server_port = None
-        self.admin_username = None
-        self.admin_password = None
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-        self.read_config()
-
-    def read_config(self):
-        self.enabled = True if self.cartridge_agent_config.read_property(
-           cartridgeagentconstants.CEP_PUBLISHER_ENABLED, False).strip().lower() == "true" else False
-        if not self.enabled:
-            CEPPublisherConfiguration.log.info("CEP Publisher disabled")
-            return
-
-        CEPPublisherConfiguration.log.info("CEP Publisher enabled")
-
-        self.server_ip = self.cartridge_agent_config.read_property(
-            cartridgeagentconstants.CEP_RECEIVER_IP, False)
-        if self.server_ip is None or self.server_ip.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_RECEIVER_IP)
-
-        self.server_port = self.cartridge_agent_config.read_property(
-            cartridgeagentconstants.CEP_RECEIVER_PORT, False)
-        if self.server_port is None or self.server_port.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_RECEIVER_PORT)
-
-        self.admin_username = self.cartridge_agent_config.read_property(
-            cartridgeagentconstants.CEP_SERVER_ADMIN_USERNAME, False)
-        if self.admin_username is None or self.admin_username.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_SERVER_ADMIN_USERNAME)
-
-        self.admin_password = self.cartridge_agent_config.read_property(
-            cartridgeagentconstants.CEP_SERVER_ADMIN_PASSWORD, False)
-        if self.admin_password is None or self.admin_password.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_SERVER_ADMIN_PASSWORD)
-
-        CEPPublisherConfiguration.log.info("CEP Publisher configuration initialized")

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/publisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/publisher/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/publisher/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/publisher/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py b/tools/python-cartridge-agent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py
deleted file mode 100644
index 1ce8ffb..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py
+++ /dev/null
@@ -1,165 +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.
-
-import logging
-
-import paho.mqtt.publish as publish
-
-from .. event.instance.status.events import *
-from .. config.cartridgeagentconfiguration import CartridgeAgentConfiguration
-from .. util import cartridgeagentconstants
-from .. healthstatspublisher.healthstats import *
-from .. healthstatspublisher.abstracthealthstatisticspublisher import *
-
-
-log = LogFactory().get_log(__name__)
-
-started = False
-activated = False
-ready_to_shutdown = False
-maintenance = False
-
-publishers = {}
-""" :type : dict[str, EventPublisher] """
-
-
-def publish_instance_started_event():
-    global started, log
-    if not started:
-        log.info("Publishing instance started event")
-        service_name = CartridgeAgentConfiguration().service_name
-        cluster_id = CartridgeAgentConfiguration().cluster_id
-        network_partition_id = CartridgeAgentConfiguration().network_partition_id
-        parition_id = CartridgeAgentConfiguration().partition_id
-        member_id = CartridgeAgentConfiguration().member_id
-
-        instance_started_event = InstanceStartedEvent(service_name, cluster_id, network_partition_id, parition_id,
-                                                      member_id)
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_STARTED_EVENT)
-        publisher.publish(instance_started_event)
-        started = True
-        log.info("Instance started event published")
-    else:
-        log.warn("Instance already started")
-
-
-def publish_instance_activated_event():
-    global activated, log
-    if not activated:
-        log.info("Publishing instance activated event")
-        service_name = CartridgeAgentConfiguration().service_name
-        cluster_id = CartridgeAgentConfiguration().cluster_id
-        network_partition_id = CartridgeAgentConfiguration().network_partition_id
-        parition_id = CartridgeAgentConfiguration().partition_id
-        member_id = CartridgeAgentConfiguration().member_id
-
-        instance_activated_event = InstanceActivatedEvent(service_name, cluster_id, network_partition_id, parition_id,
-                                                          member_id)
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_ACTIVATED_EVENT)
-        publisher.publish(instance_activated_event)
-
-        log.info("Instance activated event published")
-        log.info("Starting health statistics notifier")
-
-        if CEPPublisherConfiguration.get_instance().enabled:
-            interval_default = 15  # seconds
-            interval = CartridgeAgentConfiguration().read_property("stats.notifier.interval", False)
-            if interval is not None and len(interval) > 0:
-                try:
-                    interval = int(interval)
-                except ValueError:
-                    interval = interval_default
-            else:
-                interval = interval_default
-
-            health_stats_publisher = HealthStatisticsPublisherManager(interval)
-            log.info("Starting Health statistics publisher with interval %r" % interval_default)
-            health_stats_publisher.start()
-        else:
-            log.warn("Statistics publisher is disabled")
-
-        activated = True
-        log.info("Health statistics notifier started")
-    else:
-        log.warn("Instance already activated")
-
-
-def publish_maintenance_mode_event():
-    global maintenance, log
-    if not maintenance:
-        log.info("Publishing instance maintenance mode event")
-
-        service_name = CartridgeAgentConfiguration().service_name
-        cluster_id = CartridgeAgentConfiguration().cluster_id
-        network_partition_id = CartridgeAgentConfiguration().network_partition_id
-        parition_id = CartridgeAgentConfiguration().partition_id
-        member_id = CartridgeAgentConfiguration().member_id
-
-        instance_maintenance_mode_event = InstanceMaintenanceModeEvent(service_name, cluster_id, network_partition_id, parition_id,
-                                                          member_id)
-
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_MAINTENANCE_MODE_EVENT)
-        publisher.publish(instance_maintenance_mode_event)
-
-        maintenance = True
-        log.info("Instance Maintenance mode event published")
-    else:
-        log.warn("Instance already in a Maintenance mode....")
-
-
-def publish_instance_ready_to_shutdown_event():
-    global ready_to_shutdown, log
-    if not ready_to_shutdown:
-        log.info("Publishing instance activated event")
-
-        service_name = CartridgeAgentConfiguration().service_name
-        cluster_id = CartridgeAgentConfiguration().cluster_id
-        network_partition_id = CartridgeAgentConfiguration().network_partition_id
-        parition_id = CartridgeAgentConfiguration().partition_id
-        member_id = CartridgeAgentConfiguration().member_id
-
-        instance_shutdown_event = InstanceReadyToShutdownEvent(service_name, cluster_id, network_partition_id, parition_id,
-                                                          member_id)
-
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_READY_TO_SHUTDOWN_EVENT)
-        publisher.publish(instance_shutdown_event)
-
-        ready_to_shutdown = True
-        log.info("Instance ReadyToShutDown event published")
-    else:
-        log.warn("Instance already in a ReadyToShutDown event....")
-
-
-def get_publisher(topic):
-    if topic not in publishers:
-        publishers[topic] = EventPublisher(topic)
-
-    return publishers[topic]
-
-
-class EventPublisher:
-    """
-    Handles publishing events to topics to the provided message broker
-    """
-    def __init__(self, topic):
-        self.__topic = topic
-
-    def publish(self, event):
-        mb_ip = CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_IP)
-        mb_port = CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_PORT)
-        payload = event.to_json()
-        publish.single(self.__topic, payload, hostname=mb_ip, port=mb_port)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/eventsubscriber.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/eventsubscriber.py b/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/eventsubscriber.py
deleted file mode 100644
index bc026dd..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/eventsubscriber.py
+++ /dev/null
@@ -1,96 +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.
-
-import threading
-import paho.mqtt.client as mqtt
-
-
-class EventSubscriber(threading.Thread):
-    """
-    Provides functionality to subscribe to a given topic on the stratos MB and
-    register event handlers for various events.
-    """
-
-    def __init__(self, topic, ip, port):
-        threading.Thread.__init__(self)
-
-        #{"ArtifactUpdateEvent" : onArtifactUpdateEvent()}
-        self.__event_handlers = {}
-
-        self.log = LogFactory().get_log(__name__)
-
-        self.__mb_client = None
-
-        self.__topic = topic
-
-        self.__subscribed = False
-
-        self.__ip = ip
-        self.__port = port
-
-    def run(self):
-        self.__mb_client = mqtt.Client()
-        self.__mb_client.on_connect = self.on_connect
-        self.__mb_client.on_message = self.on_message
-
-        self.log.debug("Connecting to the message broker with address %r:%r" % (self.__ip, self.__port))
-        self.__mb_client.connect(self.__ip, self.__port, 60)
-        self.__subscribed = True
-        self.__mb_client.loop_forever()
-
-    def register_handler(self, event, handler):
-        """
-        Adds an event handler function mapped to the provided event.
-        :param str event: Name of the event to attach the provided handler
-        :param handler: The handler function
-        :return: void
-        :rtype: void
-        """
-        self.__event_handlers[event] = handler
-        self.log.debug("Registered handler for event %r" % event)
-
-    def on_connect(self, client, userdata, flags, rc):
-        self.log.debug("Connected to message broker.")
-        self.__mb_client.subscribe(self.__topic)
-        self.log.debug("Subscribed to %r" % self.__topic)
-
-    def on_message(self, client, userdata, msg):
-        self.log.debug("Message received: %r:\n%r" % (msg.topic, msg.payload))
-
-        event = msg.topic.rpartition('/')[2]
-
-        if event in self.__event_handlers:
-            handler = self.__event_handlers[event]
-
-            try:
-                self.log.debug("Executing handler for event %r" % event)
-                handler(msg)
-            except:
-                self.log.exception("Error processing %r event" % event)
-        else:
-            self.log.debug("Event handler not found for event : %r" % event)
-
-    def is_subscribed(self):
-        """
-        Checks if this event subscriber is successfully subscribed to the provided topic
-        :return: True if subscribed, False if otherwise
-        :rtype: bool
-        """
-        return self.__subscribed
-
-
-from .. util.log import LogFactory
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/tenant/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/tenant/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/tenant/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/tenant/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/tenant/tenantcontext.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/tenant/tenantcontext.py b/tools/python-cartridge-agent/cartridgeagent/modules/tenant/tenantcontext.py
deleted file mode 100644
index 202bd35..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/tenant/tenantcontext.py
+++ /dev/null
@@ -1,184 +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.
-
-class Tenant:
-    """
-    Object type representing the tenant details of a single tenant
-    """
-
-    def __init__(self, tenant_id,  tenant_domain):
-        self.tenant_id = tenant_id
-        """ :type : int """
-        self.tenant_domain = tenant_domain
-        """ :type : str """
-        self.service_name_subscription_map = {}
-        """ :type : dict[str, Subscription] """
-
-    def get_subscription(self, service_name):
-        """
-        Returns the Subscription object related to the provided service name
-        :param str service_name: service name to be retrieved
-        :return: Subscription of the service or None if the service name doesn't exist
-        :rtype: Subscription
-        """
-        if service_name in self.service_name_subscription_map:
-            return self.service_name_subscription_map[service_name]
-
-        return None
-
-    def is_subscribed(self, service_name):
-        """
-        Checks if the given service name has a subscription from this tenant
-        :param str service_name: name of the service to check
-        :return: True if the tenant is subscribed to the given service name, False if not
-        :rtype: bool
-        """
-        return service_name in self.service_name_subscription_map
-
-    def add_subscription(self, subscription):
-        """
-        Adds a subscription information entry on the subscription list for this tenant
-        :param Subscription subscription: Subscription information to be added
-        :return: void
-        :rtype: void
-        """
-        self.service_name_subscription_map[subscription.service_name] = subscription
-
-    def remove_subscription(self, service_name):
-        """
-        Removes the specified subscription details from the subscription list
-        :param str service_name: The service name of the subscription to be removed
-        :return: void
-        :rtype: void
-        """
-        if service_name in self.service_name_subscription_map:
-            self.service_name_subscription_map.pop(service_name)
-
-
-class Subscription:
-    """
-    Subscription information of a particular subscription to a service
-    """
-
-    def __init__(self, service_name, cluster_ids):
-        self.service_name = service_name
-        """ :type : str """
-        self.cluster_ids = cluster_ids
-        """ :type : list[str]  """
-        self.subscription_domain_map = {}
-        """ :type : dict[str, SubscriptionDomain]  """
-
-    def add_subscription_domain(self, domain_name, application_context):
-        """
-        Adds a subscription domain
-        :param str domain_name:
-        :param str application_context:
-        :return: void
-        :rtype: void
-        """
-        self.subscription_domain_map[domain_name] = SubscriptionDomain(domain_name, application_context)
-
-    def remove_subscription_domain(self, domain_name):
-        """
-        Removes the subscription domain of the specified domain name
-        :param str domain_name:
-        :return: void
-        :rtype: void
-        """
-        if domain_name in self.subscription_domain_map:
-            self.subscription_domain_map.pop(domain_name)
-
-    def subscription_domain_exists(self, domain_name):
-        """
-        Returns the SubscriptionDomain information of the specified domain name
-        :param str domain_name:
-        :return: SubscriptionDomain
-        :rtype: SubscriptionDomain
-        """
-        return domain_name in self.subscription_domain_map
-
-    def get_subscription_domains(self):
-        """
-        Returns the list of subscription domains of this subscription
-        :return: List of SubscriptionDomain objects
-        :rtype: list[SubscriptionDomain]
-        """
-        return self.subscription_domain_map.values()
-
-
-class SubscriptionDomain:
-    """
-    Represents a Subscription Domain
-    """
-
-    def __init__(self, domain_name, application_context):
-        self.domain_name = domain_name
-        """ :type : str  """
-        self.application_context = application_context
-        """ :type : str  """
-
-
-class TenantContext:
-    """
-    Handles and maintains a model of all the information related to tenants within this instance
-    """
-    tenants = {}
-    initialized = False
-    tenant_domains = {"carbon.super": Tenant(-1234, "carbon.super")}
-
-    @staticmethod
-    def add_tenant(tenant):
-        TenantContext.tenants[tenant.tenant_id] = tenant
-        TenantContext.tenant_domains[tenant.tenant_domain] = tenant
-
-    @staticmethod
-    def remove_tenant(tenant_id):
-        if tenant_id in TenantContext.tenants:
-            tenant = TenantContext.get_tenant(tenant_id)
-            TenantContext.tenants.pop(tenant.tenant_id)
-            TenantContext.tenant_domains.pop(tenant.tenant_domain)
-
-    @staticmethod
-    def update(tenants):
-        for tenant in tenants:
-            TenantContext.add_tenant(tenant)
-
-    @staticmethod
-    def get_tenant(tenant_id):
-        """
-        Gets the Tenant object of the provided tenant ID
-        :param int tenant_id:
-        :return: Tenant object of the provided tenant ID
-        :rtype: Tenant
-        """
-        if tenant_id in TenantContext.tenants:
-            return TenantContext.tenants[tenant_id]
-
-        return None
-
-    @staticmethod
-    def get_tenant_by_domain(tenant_domain):
-        """
-        Gets the Tenant object of the provided tenant domain
-        :param str tenant_domain:
-        :return: Tenant object of the provided tenant domain
-        :rtype: str
-        """
-        if tenant_domain in TenantContext.tenant_domains:
-            return TenantContext.tenant_domains[tenant_domain]
-
-        return None
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/topology/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/topology/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/topology/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/topology/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/topology/topologycontext.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/topology/topologycontext.py b/tools/python-cartridge-agent/cartridgeagent/modules/topology/topologycontext.py
deleted file mode 100644
index 5fe2ea4..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/topology/topologycontext.py
+++ /dev/null
@@ -1,454 +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.
-
-from ..util import cartridgeagentconstants
-
-
-class Topology:
-    """
-    Represents the topology provided by the Cloud Controller
-    """
-
-    def __init__(self):
-        self.service_map = {}
-        """ :type : dict[str, Service]  """
-        self.initialized = False
-        """ :type : bool  """
-        self.json_str = None
-        """ :type : str  """
-
-    def get_services(self):
-        """
-        Provides the list of services on the topology
-        :return: The list of Service objects
-        :rtype: list[Service]
-        """
-        return self.service_map.values()
-
-    def get_service(self, service_name):
-        """
-        Provides the service information for the given service name
-        :param str service_name: service name to be retrieved
-        :return: Service object of the service, None if the provided service name is invalid
-        :rtype: Service
-        """
-        if service_name in self.service_map:
-            return self.service_map[service_name]
-
-        return None
-
-    def add_service(self, service):
-        """
-        Adds a service to the list of services on the topology
-
-        :param Service service:
-        :return: void
-        """
-        self.service_map[service.service_name] = service
-
-    def add_services(self, services):
-        """
-
-        :param list[Service] services:
-        :return: void
-        """
-        for service in services:
-            self.add_service(service)
-
-    def remove_service(self, service_name):
-        """
-        Removes the service of the provided service name
-        :param str service_name:
-        :return: void
-        """
-        if service_name in self.service_map:
-            self.service_map.pop(service_name)
-
-    def service_exists(self, service_name):
-        """
-        Checks if the service of the provided service name exists
-        :param str service_name:
-        :return: True if the service exists, False if otherwise
-        :rtype: bool
-        """
-        return service_name in self.service_map
-
-    def clear(self):
-        """
-        Clears the service information list
-        :return: void
-        """
-        self.service_map = {}
-
-    def __str__(self):
-        """
-        to string override
-        :return:
-        """
-        return "Topology [serviceMap= %r , initialized= %r ]" % (self.service_map, self.initialized)
-
-
-class Service:
-    """
-    Represents a service on the topology
-    """
-
-    def __init__(self, service_name, service_type):
-        self.service_name = service_name
-        """ :type : str  """
-        self.service_type = service_type
-        """ :type : str  """
-        self.cluster_id_cluster_map = {}
-        """ :type : dict[str, Cluster]  """
-        self.port_map = {}
-        """ :type : dict[str, Port]  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-
-    def get_clusters(self):
-        """
-        Provides the list of clusters in the particular service
-        :return: The list of Cluster objects
-        :rtype: list[Cluster]
-        """
-        return self.cluster_id_cluster_map.values()
-
-    def add_cluster(self, cluster):
-        """
-        Adds a cluster to the service
-        :param Cluster cluster: the cluster to be added
-        :return: void
-        """
-        self.cluster_id_cluster_map[cluster.cluster_id] = cluster
-
-    def remove_cluster(self, cluster_id):
-        if cluster_id in self.cluster_id_cluster_map:
-            self.cluster_id_cluster_map.pop(cluster_id)
-
-    def cluster_exists(self, cluster_id):
-        """
-        Checks if the cluster with the given cluster id exists for ther service
-        :param str cluster_id:
-        :return: True if the cluster for the given cluster id exists, False if otherwise
-        :rtype: bool
-        """
-        return cluster_id in self.cluster_id_cluster_map
-
-    def get_cluster(self, cluster_id):
-        """
-        Provides the Cluster information for the provided cluster id
-        :param str cluster_id: the cluster id to search for
-        :return: Cluster object for the given cluster id, None if the cluster id is invalid
-        :rtype: Cluster
-        """
-        if cluster_id in self.cluster_id_cluster_map:
-            return self.cluster_id_cluster_map[cluster_id]
-
-        return None
-
-    def get_ports(self):
-        """
-        Returns the list of ports in the particular service
-        :return: The list of Port object
-        :rtype: list[Port]
-        """
-        return self.port_map.values()
-
-    def get_port(self, proxy_port):
-        """
-        Provides the port information for the provided proxy port
-        :param str proxy_port:
-        :return: Port object for the provided port, None if port is invalid
-        :rtype: Port
-        """
-        if proxy_port in self.port_map:
-            return self.port_map[proxy_port]
-
-        return None
-
-    def add_port(self, port):
-        self.port_map[port.proxy] = port
-
-    def add_ports(self, ports):
-        for port in ports:
-            self.add_port(port)
-
-
-class Cluster:
-    """
-    Represents a cluster for a service
-    """
-
-    def __init__(self, service_name="", cluster_id="", deployment_policy_name="", autoscale_policy_name=""):
-        self.service_name = service_name
-        """ :type : str  """
-        self.cluster_id = cluster_id
-        """ :type : str  """
-        self.deployment_policy_name = deployment_policy_name
-        """ :type : str  """
-        self.autoscale_policy_name = autoscale_policy_name
-        """ :type : str  """
-        self.hostnames = []
-        """ :type : list[str]  """
-        self.member_map = {}
-        """ :type : dict[str, Member]  """
-
-        self.tenant_range = None
-        """ :type : str  """
-        self.is_lb_cluster = False
-        """ :type : bool  """
-        self.is_kubernetes_cluster = False
-        """ :type : bool  """
-        self.status = None
-        """ :type : str  """
-        self.load_balancer_algorithm_name = None
-        """ :type : str  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-        self.member_list_json = None
-        """ :type : str  """
-
-    def add_hostname(self, hostname):
-        self.hostnames.append(hostname)
-
-    def set_tenant_range(self, tenant_range):
-        self.validate_tenant_range(tenant_range)
-        self.tenant_range = tenant_range
-
-    def get_members(self):
-        """
-        Provides the list of member information in the cluster
-        :return: The list of Member object
-        :rtype: list[Member]
-        """
-        return self.member_map.values()
-
-    def add_member(self, member):
-        self.member_map[member.member_id] = member
-
-    def remove_member(self, member_id):
-        if self.member_exists(member_id):
-            self.member_map.pop(member_id)
-
-    def get_member(self, member_id):
-        """
-        Provides the member information for the provided member id
-        :param str member_id:
-        :return: Member object for the provided member id, None if member id is invalid
-        :rtype: Member
-        """
-        if self.member_exists(member_id):
-            return self.member_map[member_id]
-
-        return None
-
-    def member_exists(self, member_id):
-        """
-        Checks if the member for the provided member id exists in this cluster
-        :param str member_id: member id to be searched
-        :return: True if the member exists, False if otherwise
-        :rtype: bool
-        """
-        return member_id in self.member_map
-
-    def __str__(self):
-        return "Cluster [serviceName=" + self.service_name + ", clusterId=" + self.cluster_id \
-               + ", autoscalePolicyName=" + self.autoscale_policy_name + ", deploymentPolicyName=" \
-               + self.deployment_policy_name + ", hostNames=" + self.hostnames + ", tenantRange=" + self.tenant_range \
-               + ", isLbCluster=" + self.is_lb_cluster + ", properties=" + self.properties + "]"
-
-    def tenant_id_in_range(self, tenant_id):
-        """
-        Check whether a given tenant id is in tenant range of the cluster.
-        :param str tenant_id: tenant id to be checked
-        :return: True if the tenant id is in tenant id range, False if otherwise
-        :rtype: bool
-        """
-        if self.tenant_range is None:
-            return False
-
-        if self.tenant_range == "*":
-            return True
-        else:
-            arr = self.tenant_range.split(cartridgeagentconstants.TENANT_RANGE_DELIMITER)
-            tenant_start = int(arr[0])
-            if tenant_start <= tenant_id:
-                tenant_end = arr[1]
-                if tenant_end == "*":
-                    return True
-                else:
-                    if tenant_id <= int(tenant_end):
-                        return True
-
-        return False
-
-    def validate_tenant_range(self, tenant_range):
-        """
-        Validates the tenant range to be either '*' or a delimeted range of numbers
-        :param str tenant_range: The tenant range string to be validated
-        :return: void if the provided tenant range is valid, RuntimeError if otherwise
-        :exception: RuntimeError if the tenant range is invalid
-        """
-        valid = False
-        if tenant_range == "*":
-            valid = True
-        else:
-            arr = tenant_range.split(cartridgeagentconstants.TENANT_RANGE_DELIMITER)
-            if len(arr) == 2:
-                if arr[0].isdigit() and arr[1].isdigit():
-                    valid = True
-                elif arr[0].isdigit() and arr[1] == "*":
-                    valid = True
-
-        if not valid:
-            raise RuntimeError("Tenant range %r is not valid" % tenant_range)
-
-
-class Member:
-    """
-    Represents a member on a particular cluster
-    """
-
-    def __init__(self, service_name="", cluster_id="", network_partition_id="", parition_id="", member_id=""):
-        self.service_name = service_name
-        """ :type : str  """
-        self.cluster_id = cluster_id
-        """ :type : str  """
-        self.network_partition_id = network_partition_id
-        """ :type : str  """
-        self.partition_id = parition_id
-        """ :type : str  """
-        self.member_id = member_id
-        """ :type : str  """
-        self.port_map = {}
-        """ :type : dict[str, Port]  """
-
-        self.member_public_ip = None
-        """ :type : str  """
-        self.status = None
-        """ :type : str  """
-        self.member_ip = None
-        """ :type : str  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-        self.lb_cluster_id = None
-        """ :type : str  """
-        self.json_str = None
-        """ :type : str  """
-
-    def is_active(self):
-        """
-        Checks if the member is in active state
-        :return: True if active, False if otherwise
-        :rtype: bool
-        """
-        return self.status == MemberStatus.Activated
-
-    def get_ports(self):
-        """
-        Provides the list of the ports in the member
-        :return: List of Port objects
-        :rtype: list[Port]
-        """
-        return self.port_map.values()
-
-    def get_port(self, proxy):
-        """
-        Provides the port information for the given port id
-        :param str proxy: The port id
-        :return: Port object of the provided port id, None if otherwise
-        :rtype: Port
-        """
-        if proxy in self.port_map:
-            return self.port_map[proxy]
-
-        return None
-
-    def add_port(self, port):
-        self.port_map[port.proxy] = port
-
-    def add_ports(self, ports):
-        for port in ports:
-            self.add_port(port)
-
-
-class Port:
-    """
-    Represents a port on a particular member
-    """
-
-    def __init__(self, protocol, value, proxy):
-        self.protocol = protocol
-        """ :type : str  """
-        self.value = value
-        """ :type : str  """
-        self.proxy = proxy
-        """ :type : str  """
-
-    def __str__(self):
-        return "Port [protocol=%r, value=%r proxy=%r]" % (self.protocol, self.value, self.proxy)
-
-
-class ServiceType:
-    """
-    ServiceType enum
-    """
-    SingleTenant = 1
-    MultiTenant = 2
-
-
-class ClusterStatus:
-    """
-    ClusterStatus enum
-    """
-    Created = 1
-    In_Maintenance = 2
-    Removed = 3
-
-
-class MemberStatus:
-    """
-    MemberStatus enum
-    """
-    Created = 1
-    Starting = 2
-    Activated = 3
-    In_Maintenance = 4
-    ReadyToShutDown = 5
-    Terminated = 6
-    Suspended = 0
-    ShuttingDown = 0
-
-
-class TopologyContext:
-    """
-    Handles and maintains a model of the topology provided by the Cloud Controller
-    """
-    topology = None
-    # TODO: read write locks, Lock() and RLock()
-
-    @staticmethod
-    def get_topology():
-        #TODO: thread-safety missing
-        if TopologyContext.topology is None:
-            TopologyContext.topology = Topology()
-        return TopologyContext.topology
-
-    @staticmethod
-    def update(topology):
-        TopologyContext.topology = topology
-        TopologyContext.topology.initialized = True
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/util/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/util/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py
deleted file mode 100644
index 4ff0416..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py
+++ /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.
-
-import time
-from threading import Thread
-
-class AbstractAsyncScheduledTask:
-    """
-    Exposes the contract to follow to implement a scheduled task to be executed by the ScheduledExecutor
-    """
-
-    def execute_task(self):
-        """
-        Override this method and implement the task to be executed by the ScheduledExecutor with a specified
-        interval.
-        """
-        raise NotImplementedError
-
-
-class ScheduledExecutor(Thread):
-    """
-    Executes a given task with a given interval until being terminated
-    """
-
-    def __init__(self, delay, task):
-        """
-        Creates a ScheduledExecutor thread to handle interval based repeated execution of a given task of type
-        AbstractAsyncScheduledTask
-        :param int delay: The interval to keep between executions
-        :param AbstractAsyncScheduledTask task: The task to be implemented
-        :return:
-        """
-
-        Thread.__init__(self)
-        self.delay = delay
-        """ :type : int  """
-        self.task = task
-        """ :type : AbstractAsyncScheduledTask  """
-        self.terminated = False
-        """ :type : bool  """
-
-    def run(self):
-        """
-        Start the scheduled task with a sleep time of delay in between
-        :return:
-        """
-        while not self.terminated:
-            time.sleep(self.delay)
-            task_thread = Thread(target=self.task.execute_task)
-            task_thread.start()
-
-    def terminate(self):
-        """
-        Terminate the scheduled task. Allow a maximum of 'delay' seconds to be terminated.
-        :return: void
-        """
-        self.terminated = True
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentconstants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentconstants.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentconstants.py
deleted file mode 100644
index 70afb30..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentconstants.py
+++ /dev/null
@@ -1,135 +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.
-
-PARAM_FILE_PATH = "param.file.path"
-EXTENSIONS_DIR = "extensions.dir"
-
-MB_IP = "mb.ip"
-MB_PORT = "mb.port"
-
-CARTRIDGE_KEY = "CARTRIDGE_KEY"
-APP_PATH = "APP_PATH"
-SERVICE_GROUP = "SERIVCE_GROUP"
-SERVICE_NAME = "SERVICE_NAME"
-CLUSTER_ID = "CLUSTER_ID"
-LB_CLUSTER_ID = "LB_CLUSTER_ID"
-NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID"
-PARTITION_ID = "PARTITION_ID"
-MEMBER_ID = "MEMBER_ID"
-TENANT_ID = "TENANT_ID"
-REPO_URL = "REPO_URL"
-PORTS = "PORTS"
-DEPLOYMENT = "DEPLOYMENT"
-MANAGER_SERVICE_TYPE = "MANAGER_SERVICE_TYPE"
-WORKER_SERVICE_TYPE = "WORKER_SERVICE_TYPE"
-PERSISTENCE_MAPPING = "PERSISTENCE_MAPPING"
-
-# stratos.sh environment variables keys
-LOG_FILE_PATHS = "LOG_FILE_PATHS"
-MEMORY_CONSUMPTION = "memory_consumption"
-LOAD_AVERAGE = "load_average"
-PORTS_NOT_OPEN = "ports_not_open"
-MULTITENANT = "MULTITENANT"
-CLUSTERING = "CLUSTERING"
-MIN_INSTANCE_COUNT = "MIN_COUNT"
-ENABLE_ARTIFACT_UPDATE = "enable.artifact.update"
-ARTIFACT_UPDATE_INTERVAL = "artifact.update.interval"
-COMMIT_ENABLED = "COMMIT_ENABLED"
-AUTO_COMMIT = "auto.commit"
-AUTO_CHECKOUT = "auto.checkout"
-LISTEN_ADDRESS = "listen.address"
-PROVIDER = "PROVIDER"
-INTERNAL = "internal"
-LB_PRIVATE_IP = "lb.private.ip"
-LB_PUBLIC_IP = "lb.public.ip"
-
-# stratos.sh extension points shell scripts names keys
-INSTANCE_STARTED_SCRIPT = "extension.instance.started"
-START_SERVERS_SCRIPT = "extension.start.servers"
-INSTANCE_ACTIVATED_SCRIPT = "extension.instance.activated"
-ARTIFACTS_UPDATED_SCRIPT = "extension.artifacts.updated"
-CLEAN_UP_SCRIPT = "extension.clean"
-MOUNT_VOLUMES_SCRIPT = "extension.mount.volumes"
-MEMBER_ACTIVATED_SCRIPT = "extension.member.activated"
-MEMBER_TERMINATED_SCRIPT = "extension.member.terminated"
-MEMBER_SUSPENDED_SCRIPT = "extension.member.suspended"
-MEMBER_STARTED_SCRIPT = "extension.member.started"
-COMPLETE_TOPOLOGY_SCRIPT = "extension.complete.topology"
-COMPLETE_TENANT_SCRIPT = "extension.complete.tenant"
-SUBSCRIPTION_DOMAIN_ADDED_SCRIPT = "extension.subscription.domain.added"
-SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT = "extension.subscription.domain.removed"
-ARTIFACTS_COPY_SCRIPT = "extension.artifacts.copy"
-TENANT_SUBSCRIBED_SCRIPT = "extension.tenant.subscribed"
-TENANT_UNSUBSCRIBED_SCRIPT = "extension.tenant.unsubscribed"
-
-SERVICE_GROUP_TOPOLOGY_KEY = "payload_parameter.SERIVCE_GROUP"
-CLUSTERING_TOPOLOGY_KEY = "payload_parameter.CLUSTERING"
-CLUSTERING_PRIMARY_KEY = "PRIMARY"
-
-SUPERTENANT_TEMP_PATH = "/tmp/-1234/"
-
-DEPLOYMENT_MANAGER = "manager"
-DEPLOYMENT_WORKER = "worker"
-DEPLOYMENT_DEFAULT = "default"
-SUPER_TENANT_REPO_PATH = "super.tenant.repository.path"
-TENANT_REPO_PATH = "tenant.repository.path"
-
-# topic names to subscribe
-INSTANCE_NOTIFIER_TOPIC = "instance/#"
-HEALTH_STAT_TOPIC = "health/#"
-TOPOLOGY_TOPIC = "topology/#"
-TENANT_TOPIC = "tenant/#"
-INSTANCE_STATUS_TOPIC = "instance/status/"
-
-#Messaging Model
-TENANT_RANGE_DELIMITER = "-"
-
-INSTANCE_STARTED_EVENT = "InstanceStartedEvent"
-INSTANCE_ACTIVATED_EVENT = "InstanceActivatedEvent"
-INSTANCE_MAINTENANCE_MODE_EVENT = "InstanceMaintenanceModeEvent"
-INSTANCE_READY_TO_SHUTDOWN_EVENT = "InstanceReadyToShutdownEvent"
-
-PUBLISHER_SERVICE_NAME = "publisher"
-APISTORE_SERVICE_NAME = "apistore"
-APIMANAGER_SERVICE_NAME = "apim"
-GATEWAY_SERVICE_NAME = "gatewaymgt"
-GATEWAY_MGT_SERVICE_NAME = "gateway"
-KEY_MANAGER_SERVICE_NAME = "keymanager"
-
-PRIMARY = "PRIMARY"
-MIN_COUNT = "MIN_COUNT"
-
-#multi tenant constants
-INVALID_TENANT_ID = "-1"
-SUPER_TENANT_ID = "-1234"
-
-DATE_FORMAT = "%Y.%m.%d"
-
-PORT_CHECK_TIMEOUT = "port.check.timeout"
-
-CEP_PUBLISHER_ENABLED = "cep.stats.publisher.enabled"
-CEP_RECEIVER_IP = "thrift.receiver.ip"
-CEP_RECEIVER_PORT = "thrift.receiver.port"
-CEP_SERVER_ADMIN_USERNAME = "thrift.server.admin.username"
-CEP_SERVER_ADMIN_PASSWORD = "thrift.server.admin.password"
-
-MONITORING_PUBLISHER_ENABLED = "enable.data.publisher"
-MONITORING_RECEIVER_IP = "monitoring.server.ip"
-MONITORING_RECEIVER_PORT = "monitoring.server.port"
-MONITORING_RECEIVER_SECURE_PORT = "monitoring.server.secure.port"
-MONITORING_SERVER_ADMIN_USERNAME = "monitoring.server.admin.username"
-MONITORING_SERVER_ADMIN_PASSWORD = "monitoring.server.admin.password"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentutils.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentutils.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentutils.py
deleted file mode 100644
index 42a7dd5..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentutils.py
+++ /dev/null
@@ -1,165 +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.
-
-from Crypto.Cipher import AES
-import base64
-import os
-import time
-import socket
-import shutil
-
-from log import LogFactory
-
-unpad = lambda s: s[0:-ord(s[-1])]
-
-log = LogFactory().get_log(__name__)
-
-current_milli_time = lambda: int(round(time.time() * 1000))
-
-
-def decrypt_password(pass_str, secret):
-    """
-    Decrypts the given password using the given secret. The encryption is assumed to be done
-    without IV, in AES.
-    :param str pass_str: Encrypted password string in Base64 encoding
-    :param str secret: The secret string
-    :return: The decrypted password
-    :rtype: str
-    """
-
-    if pass_str is None or pass_str.strip() == "":
-        return pass_str.strip()
-
-    dec_pass = ""
-
-    try:
-        log.debug("Decrypting password")
-        bdecoded_pass = base64.b64decode(pass_str)
-        #secret length should be 16
-        cipher = AES.new(secret, AES.MODE_ECB)
-        dec_pass = unpad(cipher.decrypt(bdecoded_pass))
-    except:
-        log.exception("Exception occurred while decrypting password")
-
-    log.debug("Decrypted PWD: [%r]" % dec_pass)
-    return dec_pass
-
-
-def create_dir(path):
-    """
-    mkdir the provided path
-    :param path: The path to the directory to be made
-    :return: True if mkdir was successful, False if dir already exists
-    :rtype: bool
-    """
-    try:
-        os.mkdir(path)
-        log.info("Successfully created directory [%r]" % path)
-        return True
-    except OSError:
-        log.exception("Directory creating failed in [%r]. Directory already exists. " % path)
-
-    return False
-
-
-def delete_folder_tree(path):
-    """
-    Completely deletes the provided folder
-    :param str path: Full path of the folder
-    :return: void
-    """
-    try:
-        shutil.rmtree(path)
-        log.debug("Directory [%r] deleted." % path)
-    except OSError:
-        log.exception("Deletion of folder path %r failed." % path)
-
-
-def wait_until_ports_active(ip_address, ports, ports_check_timeout=600000):
-    """
-    Blocks until the given list of ports become active
-    :param str ip_address: Ip address of the member to be checked
-    :param list[str] ports: List of ports to be checked
-    :param int ports_check_timeout: The timeout in milliseconds, defaults to 1000*60*10
-    :return: void
-    """
-    if ports_check_timeout is None:
-        ports_check_timeout = 1000 * 60 * 10
-
-    log.debug("Port check timeout: %r" % ports_check_timeout)
-
-    active = False
-    start_time = current_milli_time()
-    while not active:
-        log.info("Waiting for ports to be active: [ip] %r [ports] %r" % (ip_address, ports))
-        active = check_ports_active(ip_address, ports)
-        end_time = current_milli_time()
-        duration = end_time - start_time
-
-        if duration > ports_check_timeout:
-            return
-
-        time.sleep(5)
-
-    log.info("Ports activated: [ip] %r [ports] %r" % (ip_address, ports))
-
-
-def check_ports_active(ip_address, ports):
-    """
-    Checks the given list of port addresses for active state
-    :param str ip_address: Ip address of the member to be checked
-    :param list[str] ports: The list of ports to be checked
-    :return: True if the ports are active, False if at least one is not active
-    :rtype: bool
-    """
-    if len(ports) < 1:
-        raise RuntimeError("No ports found")
-
-    for port in ports:
-        s = socket.socket()
-        s.settimeout(5)
-        try:
-            s.connect((ip_address, int(port)))
-            log.debug("Port %r is active" % port)
-            s.close()
-        except socket.error:
-            log.debug("Print %r is not active" % port)
-            return False
-
-    return True
-
-
-def get_carbon_server_property(property_key):
-    """
-    Reads the carbon.xml file and returns the value for the property key.
-    TODO: Get carbon server xml location
-    :param str property_key: Property key to look for
-    :return: The value of the property, None if the property key is invalid or not present
-    :rtype : str
-    """
-
-    raise NotImplementedError
-
-
-def get_working_dir():
-    """
-    Returns the base directory of the cartridge agent.
-    :return: Base working dir path
-    :rtype : str
-    """
-    #"/path/to/cartridge-agent/modules/util/".split("modules") returns ["/path/to/cartridge-agent/", "/util"]
-    return os.path.abspath(os.path.dirname(__file__)).split("modules")[0]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/util/extensionutils.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/extensionutils.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/extensionutils.py
deleted file mode 100644
index 6c58852..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/util/extensionutils.py
+++ /dev/null
@@ -1,494 +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.
-
-import logging
-import os
-import subprocess
-import time
-
-from log import LogFactory
-from .. config import cartridgeagentconfiguration
-
-
-log = LogFactory().get_log(__name__)
-
-cartridge_agent_config = cartridgeagentconfiguration.CartridgeAgentConfiguration()
-
-
-def execute_copy_artifact_extension(source, destination):
-    try:
-        log.debug("Executing artifacts copy extension")
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.ARTIFACTS_COPY_SCRIPT, False)
-        command = prepare_command(script_name)
-
-        output, errors = execute_command(command + " " + source + " " + destination)
-        log.debug("Artifacts copy script returned: %r" % output)
-    except:
-        log.exception("Could not execute artifacts copy extension")
-
-
-def execute_instance_started_extension(env_params):
-    try:
-        log.debug("Executing instance started extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.INSTANCE_STARTED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Instance started script returned: %r" % output)
-    except:
-        log.exception("Could not execute instance started extension")
-
-
-def execute_instance_activated_extension():
-    try:
-        log.debug("Executing instance activated extension")
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.INSTANCE_ACTIVATED_SCRIPT, False)
-        command = prepare_command(script_name)
-
-        output, errors = execute_command(command)
-        log.debug("Instance activated script returned: %r" % output)
-    except:
-        log.exception("Could not execute instance activated extension")
-
-
-def execute_artifacts_updated_extension(env_params):
-    try:
-        log.debug("Executing artifacts updated extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.ARTIFACTS_UPDATED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Artifacts updated script returned: %r" % output)
-    except:
-        log.exception("Could not execute artifacts updated extension")
-
-
-def execute_subscription_domain_added_extension(env_params):
-    try:
-        log.debug("Executing subscription domain added extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.SUBSCRIPTION_DOMAIN_ADDED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Subscription domain added script returned: %r" % output)
-    except:
-        log.exception("Could not execute subscription domain added extension")
-
-
-def execute_subscription_domain_removed_extension(env_params):
-    try:
-        log.debug("Executing subscription domain removed extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Subscription domain removed script returned: %r" % output)
-    except:
-        log.exception("Could not execute subscription domain removed extension")
-
-
-def execute_start_servers_extension(env_params):
-    try:
-        log.debug("Executing start servers extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.START_SERVERS_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Start servers script returned: %r" % output)
-    except:
-        log.exception("Could not execute start servers extension")
-
-
-def execute_complete_topology_extension(env_params):
-    try:
-        log.debug("Executing complete topology extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.COMPLETE_TOPOLOGY_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Complete topology script returned: %r" % output)
-    except:
-        log.exception("Could not execute complete topology extension")
-
-
-def execute_complete_tenant_extension(env_params):
-    try:
-        log.debug("Executing complete tenant extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.COMPLETE_TENANT_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Complete tenant script returned: %r" % output)
-    except:
-        log.exception("Could not execute complete tenant extension")
-
-
-def execute_tenant_subscribed_extension(env_params):
-    try:
-        log.debug("Executing tenant subscribed extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.TENANT_SUBSCRIBED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Tenant subscribed script returned: %r" % output)
-    except:
-        log.exception("Could not execute tenant subscribed extension")
-
-
-def execute_tenant_unsubscribed_extension(env_params):
-    try:
-        log.debug("Executing tenant unsubscribed extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.TENANT_UNSUBSCRIBED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Tenant unsubscribed script returned: %r" % output)
-    except:
-        log.exception("Could not execute tenant unsubscribed extension")
-
-
-def execute_member_terminated_extension(env_params):
-    try:
-        log.debug("Executing member terminated extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.MEMBER_TERMINATED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Member terminated script returned: %r" % output)
-    except:
-        log.exception("Could not execute member terminated extension")
-
-
-def execute_member_suspended_extension(env_params):
-    try:
-        log.debug("Executing member suspended extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.MEMBER_SUSPENDED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Member suspended script returned: %r" % output)
-    except:
-        log.exception("Could not execute member suspended extension")
-
-
-def execute_member_started_extension(env_params):
-    try:
-        log.debug("Executing member started extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.MEMBER_STARTED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Member started script returned: %r" % output)
-    except:
-        log.exception("Could not execute member started extension")
-
-
-def wait_for_complete_topology():
-    while not TopologyContext.topology.initialized:
-        log.info("Waiting for complete topology event...")
-        time.sleep(5)
-
-
-def check_topology_consistency(service_name, cluster_id, member_id):
-    topology = TopologyContext.get_topology()
-    service = topology.get_service(service_name)
-    if service is None:
-        log.error("Service not found in topology [service] %r" % service_name)
-        return False
-
-    cluster = service.get_cluster(cluster_id)
-    if cluster is None:
-        log.error("Cluster id not found in topology [cluster] %r" % cluster_id)
-        return False
-
-    activated_member = cluster.get_member(member_id)
-    if activated_member is None:
-        log.error("Member id not found in topology [member] %r" % member_id)
-        return False
-
-    return True
-
-
-def is_relevant_member_event(service_name, cluster_id, lb_cluster_id):
-    cluster_id_in_payload = cartridge_agent_config.cluster_id
-    if cluster_id_in_payload is None:
-        return False
-
-    topology = TopologyContext.get_topology()
-    if topology is None or not topology.initialized:
-        return False
-
-    if cluster_id_in_payload == cluster_id:
-        return True
-
-    if cluster_id_in_payload == lb_cluster_id:
-        return True
-
-    service_group_in_payload = cartridge_agent_config.service_group
-    if service_group_in_payload is not None:
-        service_properties = topology.get_service(service_name).properties
-        if service_properties is None:
-            return False
-
-        member_service_group = service_properties[cartridgeagentconstants.SERVICE_GROUP_TOPOLOGY_KEY]
-        if member_service_group is not None and member_service_group == service_group_in_payload:
-            if service_name == cartridge_agent_config.service_name:
-                log.debug("Service names are same")
-                return True
-            elif cartridgeagentconstants.APISTORE_SERVICE_NAME == \
-                    cartridge_agent_config.service_name \
-                    and service_name == cartridgeagentconstants.PUBLISHER_SERVICE_NAME:
-                log.debug("Service name in payload is [store]. Serivce name in event is [%r] " % service_name)
-                return True
-            elif cartridgeagentconstants.PUBLISHER_SERVICE_NAME == \
-                    cartridge_agent_config.service_name \
-                    and service_name == cartridgeagentconstants.APISTORE_SERVICE_NAME:
-                log.debug("Service name in payload is [publisher]. Serivce name in event is [%r] " % service_name)
-                return True
-            elif cartridgeagentconstants.DEPLOYMENT_WORKER == \
-                    cartridge_agent_config.deployment \
-                    and service_name == cartridge_agent_config.manager_service_name:
-                log.debug("Deployment is worker. Worker's manager service name & service name in event are same")
-                return True
-            elif cartridgeagentconstants.DEPLOYMENT_MANAGER == \
-                    cartridge_agent_config.deployment  \
-                    and service_name == cartridge_agent_config.worker_service_name:
-                log.debug("Deployment is manager. Manager's worker service name & service name in event are same")
-                return True
-
-    return False
-
-
-def execute_volume_mount_extension(persistance_mappings_payload):
-    try:
-        log.debug("Executing volume mounting extension: [payload] %r" % persistance_mappings_payload)
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.MOUNT_VOLUMES_SCRIPT, False)
-        command = prepare_command(script_name)
-
-        output, errors = execute_command(command + " " + persistance_mappings_payload)
-        log.debug("Volume mount script returned: %r" % output)
-    except:
-        log.exception("Could not execute Volume mount extension")
-
-
-def execute_cleanup_extension():
-    try:
-        log.debug("Executing cleanup extension")
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.CLEAN_UP_SCRIPT, False)
-        command = prepare_command(script_name)
-
-        output, errors = execute_command(command)
-        log.debug("Cleanup script returned: %r" % output)
-    except:
-        log.exception("Could not execute Cleanup extension")
-
-
-def execute_member_activated_extension(env_params):
-    try:
-        log.debug("Executing member activated extension")
-
-        script_name = cartridge_agent_config.read_property(
-            cartridgeagentconstants.MEMBER_ACTIVATED_SCRIPT, False)
-        command = prepare_command(script_name)
-        env_params = add_payload_parameters(env_params)
-        env_params = clean_process_parameters(env_params)
-
-        output, errors = execute_command(command, env_params)
-        log.debug("Member activated script returned: %r" % output)
-    except:
-        log.exception("Could not execute member activated extension")
-
-
-def prepare_command(script_name):
-    extensions_dir = cartridge_agent_config.read_property(
-        cartridgeagentconstants.EXTENSIONS_DIR, False)
-    if extensions_dir.strip() == "":
-        raise RuntimeError("System property not found: %r" % cartridgeagentconstants.EXTENSIONS_DIR)
-
-    file_path = extensions_dir + script_name if str(extensions_dir).endswith("/") \
-        else extensions_dir + "/" + script_name
-
-    if os.path.isfile(file_path):
-        return file_path
-
-    raise IOError("Script file not found : %r" % file_path)
-
-
-def clean_process_parameters(params):
-    """
-    Removes any null valued parameters before passing them to the extension scripts
-    :param dict params:
-    :return: cleaned parameters
-    :rtype: dict
-    """
-    for key, value in params.items():
-        if value is None:
-            del params[key]
-
-    return params
-
-
-def add_payload_parameters(env_params):
-    """
-    Adds the common parameters to be used by the extension scripts
-    :param dict[str, str] env_params: Dictionary to be added
-    :return: Dictionary with updated parameters
-    :rtype: dict[str, str]
-    """
-    env_params["STRATOS_APP_PATH"] = cartridge_agent_config.app_path
-    env_params["STRATOS_PARAM_FILE_PATH"] = cartridge_agent_config.read_property(
-        cartridgeagentconstants.PARAM_FILE_PATH, False)
-    env_params["STRATOS_SERVICE_NAME"] = cartridge_agent_config.service_name
-    env_params["STRATOS_TENANT_ID"] = cartridge_agent_config.tenant_id
-    env_params["STRATOS_CARTRIDGE_KEY"] = cartridge_agent_config.cartridge_key
-    env_params["STRATOS_LB_CLUSTER_ID"] = cartridge_agent_config.lb_cluster_id
-    env_params["STRATOS_CLUSTER_ID"] = cartridge_agent_config.cluster_id
-    env_params["STRATOS_NETWORK_PARTITION_ID"] = \
-        cartridge_agent_config.network_partition_id
-    env_params["STRATOS_PARTITION_ID"] = cartridge_agent_config.partition_id
-    env_params["STRATOS_PERSISTENCE_MAPPINGS"] = \
-        cartridge_agent_config.persistence_mappings
-    env_params["STRATOS_REPO_URL"] = cartridge_agent_config.repo_url
-
-    lb_cluster_id_in_payload = cartridge_agent_config.lb_cluster_id
-    member_ips = get_lb_member_ip(lb_cluster_id_in_payload)
-    if member_ips is not None:
-        env_params["STRATOS_LB_IP"] = member_ips[0]
-        env_params["STRATOS_LB_PUBLIC_IP"] = member_ips[1]
-    else:
-        env_params["STRATOS_LB_IP"] = cartridge_agent_config.lb_private_ip
-        env_params["STRATOS_LB_PUBLIC_IP"] = cartridge_agent_config.lb_public_ip
-
-    topology = TopologyContext.get_topology()
-    if topology.initialized:
-        service = topology.get_service(cartridge_agent_config.service_name)
-        cluster = service.get_cluster(cartridge_agent_config.cluster_id)
-        member_id_in_payload = cartridge_agent_config.member_id
-        add_properties(service.properties, env_params, "SERVICE_PROPERTY")
-        add_properties(cluster.properties, env_params, "CLUSTER_PROPERTY")
-        add_properties(cluster.get_member(member_id_in_payload).properties, env_params, "MEMBER_PROPERTY")
-
-    return env_params
-
-
-def add_properties(properties, params, prefix):
-    """
-    Adds the given property list to the parameters list with given prefix in the parameter name
-    :param dict[str, str] properties: service properties
-    :param dict[str, str] params:
-    :param str prefix:
-    :return: dict[str, str]
-    """
-    if properties is None or properties.items() is None:
-        return
-
-    for key in properties:
-        params["STRATOS_" + prefix + "_" + key] = str(properties[key])
-        log.debug("Property added: [key] STRATOS_ " + prefix + "_" + key + "[value] " + properties[key])
-
-
-def get_lb_member_ip(lb_cluster_id):
-    topology = TopologyContext.get_topology()
-    services = topology.get_services()
-
-    for service in services:
-        clusters = service.get_clusters()
-        for cluster in clusters:
-            members = cluster.get_members()
-            for member in members:
-                if member.cluster_id == lb_cluster_id:
-                    return [member.member_ip, member.member_public_ip]
-
-    return None
-
-
-def execute_command(command, env_params=None):
-    """
-    Executes the given command string with given environment parameters
-    :param str command: Command with arguments to be executed
-    :param dict[str, str] env_params: Environment variables to be used
-    :return: output and error string tuple, RuntimeError if errors occur
-    :rtype: tuple
-    :exception: RuntimeError
-    """
-    os_env = os.environ.copy()
-    if env_params is not None:
-        os_env.update(env_params)
-
-    p = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os_env)
-    output, errors = p.communicate()
-    log.debug("output = %r" % output)
-    log.debug("error = %r" % errors)
-    if len(errors) > 0:
-        raise RuntimeError("Command execution failed: \n %r" % errors)
-
-    return output, errors
-
-
-from .. topology.topologycontext import *
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/util/log.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/log.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/log.py
deleted file mode 100644
index 9bad214..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/util/log.py
+++ /dev/null
@@ -1,55 +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.
-
-import logging
-import logging.config
-import os
-
-
-class LogFactory(object):
-    """
-    Singleton implementation for handling logging in CartridgeAgent
-    """
-    class __LogFactory:
-        def __init__(self):
-            self.logs = {}
-            logging_conf = os.path.abspath(os.path.dirname(__file__)).split("modules")[0] + "logging.ini"
-            logging.config.fileConfig(logging_conf)
-
-        def get_log(self, name):
-            if name not in self.logs:
-                self.logs[name] = logging.getLogger(name)
-
-            return self.logs[name]
-
-    instance = None
-
-    def __new__(cls, *args, **kwargs):
-        if not LogFactory.instance:
-            LogFactory.instance = LogFactory.__LogFactory()
-
-        return LogFactory.instance
-
-    def get_log(self, name):
-        """
-        Returns a logger class with the specified channel name. Creates a new logger if one doesn't exists for the
-        specified channel
-        :param str name: Channel name
-        :return: The logger class
-        :rtype: RootLogger
-        """
-        return self.instance.get_log(name)
\ No newline at end of file


[34/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/events.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/events.py
deleted file mode 100644
index c000c55..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/events.py
+++ /dev/null
@@ -1,98 +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.
-
-import json
-
-
-class InstanceActivatedEvent:
-    def __init__(self, service_name, cluster_id, network_partition_id, parition_id, member_id):
-        self.serviceName = service_name
-        """ :type : str  """
-        self.clusterId = cluster_id
-        """ :type : str  """
-        self.networkPartitionId = network_partition_id
-        """ :type : str  """
-        self.partitionId = parition_id
-        """ :type : str  """
-        self.memberId = member_id
-        """ :type : str  """
-
-    def to_json(self):
-        return to_json(self)
-
-
-class InstanceStartedEvent:
-    def __init__(self, service_name, cluster_id, network_partition_id, parition_id, member_id):
-        self.serviceName = service_name
-        """ :type : str  """
-        self.clusterId = cluster_id
-        """ :type : str  """
-        self.networkPartitionId = network_partition_id
-        """ :type : str  """
-        self.partitionId = parition_id
-        """ :type : str  """
-        self.memberId = member_id
-        """ :type : str  """
-
-    def to_json(self):
-        return to_json(self)
-
-
-class InstanceMaintenanceModeEvent:
-
-    def __init__(self, service_name, cluster_id, network_partition_id, partition_id, member_id):
-        self.serviceName = service_name
-        """ :type : str  """
-        self.clusterId = cluster_id
-        """ :type : str  """
-        self.networkPartitionId = network_partition_id
-        """ :type : str  """
-        self.partitionId = partition_id
-        """ :type : str  """
-        self.memberId = member_id
-        """ :type : str  """
-
-    def to_json(self):
-        return to_json(self)
-
-
-class InstanceReadyToShutdownEvent:
-
-    def __init__(self, service_name, cluster_id, network_partition_id, partition_id, member_id):
-        self.serviceName = service_name
-        """ :type : str  """
-        self.clusterId = cluster_id
-        """ :type : str  """
-        self.networkPartitionId = network_partition_id
-        """ :type : str  """
-        self.partitionId = partition_id
-        """ :type : str  """
-        self.memberId = member_id
-        """ :type : str  """
-
-    def to_json(self):
-        return to_json(self)
-
-
-def to_json(instance):
-    """
-    common function to serialize status event object
-    :param obj instance:
-    :return: serialized json string
-    :rtype str
-    """
-    return json.dumps(instance, default=lambda o: o.__dict__, sort_keys=True, indent=4)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/events.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/events.py
deleted file mode 100644
index def2b64..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/events.py
+++ /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.
-
-import json
-from ... tenant.tenantcontext import *
-
-
-class SubscriptionDomainAddedEvent():
-
-    def __init__(self):
-        self.tenant_id = None
-        """ :type : int  """
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_ids = None
-        """ :type : list[str]  """
-        self.domain_name = None
-        """ :type : str  """
-        self.application_context = None
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = SubscriptionDomainAddedEvent()
-
-        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
-        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.domain_name = json_obj["domainName"] if "domainName" in json_obj else None
-        instance.application_context = json_obj["applicationContext"] if "applicationContext" in json_obj else None
-
-        return instance
-
-
-class SubscriptionDomainRemovedEvent:
-
-    def __init__(self, tenant_id, service_name, cluster_ids, domain_name):
-        self.tenant_id = tenant_id
-        """ :type : int  """
-        self.service_name = service_name
-        """ :type : str  """
-        self.cluster_ids = cluster_ids
-        """ :type : list[str]  """
-        self.domain_name = domain_name
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = SubscriptionDomainRemovedEvent()
-
-        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
-        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.domain_name = json_obj["domainName"] if "domainName" in json_obj else None
-
-        return instance
-
-
-class CompleteTenantEvent:
-
-    def __init__(self):
-        self.tenants = []
-        """ :type : list[Tenant]  """
-        self.tenant_list_json = None
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = CompleteTenantEvent()
-        instance.tenants = []
-
-        tenants_str = json_obj["tenants"] if "tenants" in json_obj else None
-        instance.tenant_list_json = tenants_str
-        if tenants_str is not None:
-            for tenant_str in tenants_str:
-                tenant_obj = Tenant(int(tenant_str["tenantId"]), tenant_str["tenantDomain"])
-                for service_name in tenant_str["serviceNameSubscriptionMap"]:
-                    sub_str = tenant_str["serviceNameSubscriptionMap"][service_name]
-                    sub = Subscription(sub_str["serviceName"], sub_str["clusterIds"])
-                    for domain_name in sub_str["subscriptionDomainMap"]:
-                        subdomain_str = sub_str["subscriptionDomainMap"][domain_name]
-                        sub.add_subscription_domain(domain_name, subdomain_str["applicationContext"])
-                    tenant_obj.add_subscription(sub)
-                instance.tenants.append(tenant_obj)
-
-        return instance
-
-
-class TenantSubscribedEvent:
-
-    def __init__(self):
-        self.tenant_id = None
-        """ :type : int  """
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_ids = None
-        """ :type : list[str]  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = TenantSubscribedEvent()
-
-        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
-
-        return instance
-
-
-class TenantUnsubscribedEvent:
-
-    def __init__(self):
-        self.tenant_id = None
-        """ :type : int  """
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_ids = None
-        """ :type : list[str]  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = TenantUnsubscribedEvent()
-
-        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
-
-        return instance
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/events.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/events.py
deleted file mode 100644
index 52c7c19..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/events.py
+++ /dev/null
@@ -1,280 +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.
-
-import json
-
-from ... topology.topologycontext import *
-
-
-class MemberActivatedEvent:
-
-    def __init__(self):
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_id = None
-        """ :type : str  """
-        self.network_partition_id = None
-        """ :type : str  """
-        self.partition_id = None
-        """ :type : str  """
-        self.member_id = None
-        """ :type : str  """
-        self.port_map = {}
-        """ :type : dict[str, Port]  """
-        self.member_ip = None
-        """ :type : str  """
-
-    def get_port(self, proxy_port):
-        """
-        Returns the port object of the provided port id
-        :param str proxy_port:
-        :return: Port object, None if the port id is invalid
-        :rtype: topology.topologycontext.Port
-        """
-        if proxy_port in self.port_map:
-            return self.port_map[proxy_port]
-
-        return None
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = MemberActivatedEvent()
-
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
-        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
-        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
-        #instance.port_map = json_obj["portMap"] if "portMap" in json_obj else {}
-        instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None
-
-        for port_proxy in json_obj["portMap"]:
-            port_str = json_obj["portMap"][port_proxy]
-            port_obj = Port(port_str["protocol"], port_str["value"], port_proxy)
-            instance.port_map[port_proxy] = port_obj
-
-        return instance
-
-
-class MemberTerminatedEvent:
-
-    def __init__(self):
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_id = None
-        """ :type : str  """
-        self.network_partition_id = None
-        """ :type : str  """
-        self.partition_id = None
-        """ :type : str  """
-        self.member_id = None
-        """ :type : str  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = MemberTerminatedEvent()
-
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
-        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
-        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
-        instance.properties = json_obj["properties"] if "properties" in json_obj else None
-
-        return instance
-
-
-class MemberSuspendedEvent:
-
-    def __init__(self):
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_id = None
-        """ :type : str  """
-        self.network_partition_id = None
-        """ :type : str  """
-        self.partition_id = None
-        """ :type : str  """
-        self.member_id = None
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = MemberSuspendedEvent()
-
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
-        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
-        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
-
-        return instance
-
-
-class CompleteTopologyEvent:
-
-    def __init__(self):
-        self.topology = None
-        """ :type :  Topology """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = CompleteTopologyEvent()
-
-        topology_str = json_obj["topology"] if "topology" in json_obj else None
-        if topology_str is not None:
-            topology_obj = Topology()
-            topology_obj.json_str = topology_str
-
-            #add service map
-            for service_name in topology_str["serviceMap"]:
-                service_str = topology_str["serviceMap"][service_name]
-
-                service_obj = Service(service_name, service_str["serviceType"])
-                service_obj.properties = service_str["properties"]
-                # add ports to port map
-                for port_proxy in service_str["portMap"]:
-                    port_str = service_str["portMap"][port_proxy]
-                    port_obj = Port(port_str["protocol"], port_str["value"], port_proxy)
-                    service_obj.add_port(port_obj)
-
-                #add cluster map
-                for cluster_id in service_str["clusterIdClusterMap"]:
-                    cluster_str = service_str["clusterIdClusterMap"][cluster_id]
-                    cl_service_name = cluster_str["serviceName"]
-                    cl_autoscale_policy_name = cluster_str["autoscalePolicyName"]
-                    cl_deployment_policy_name = cluster_str["deploymentPolicyName"] if "deploymentPolicyName" in cluster_str else None
-
-                    cluster_obj = Cluster(cl_service_name, cluster_id, cl_deployment_policy_name, cl_autoscale_policy_name)
-                    cluster_obj.hostnames = cluster_str["hostNames"]
-                    cluster_obj.tenant_range = cluster_str["tenantRange"] if "tenantRange" in cluster_str else None
-                    cluster_obj.is_lb_cluster = cluster_str["isLbCluster"]
-                    cluster_obj.is_kubernetes_cluster = cluster_str["isKubernetesCluster"]
-                    cluster_obj.status = cluster_str["status"]
-                    cluster_obj.load_balancer_algorithm_name = cluster_str["loadBalanceAlgorithmName"] if "loadBalanceAlgorithmName" in cluster_str else None
-                    cluster_obj.properties = cluster_str["properties"]
-                    cluster_obj.member_list_json = cluster_str["memberMap"]
-
-                    #add member map
-                    for member_id in cluster_str["memberMap"]:
-                        member_str = cluster_str["memberMap"][member_id]
-                        mm_service_name = member_str["serviceName"]
-                        mm_cluster_id = member_str["clusterId"]
-                        mm_network_partition_id = member_str["networkPartitionId"] if "networkPartitionId" in member_str else None
-                        mm_partition_id = member_str["partitionId"] if "partitionId" in member_str else None
-
-                        member_obj = Member(mm_service_name, mm_cluster_id, mm_network_partition_id, mm_partition_id, member_id)
-                        member_obj.member_public_ip = member_str["memberPublicIp"]
-                        member_obj.status = member_str["status"]
-                        member_obj.member_ip = member_str["memberIp"]
-                        member_obj.properties = member_str["properties"]
-                        member_obj.lb_cluster_id = member_str["lbClusterId"] if "lbClusterId" in member_str else None
-                        member_obj.json_str = member_str
-
-                        #add port map
-                        for mm_port_proxy in member_str["portMap"]:
-                            mm_port_str = member_str["portMap"][mm_port_proxy]
-                            mm_port_obj = Port(mm_port_str["protocol"], mm_port_str["value"], mm_port_proxy)
-                            member_obj.add_port(mm_port_obj)
-                        cluster_obj.add_member(member_obj)
-                    service_obj.add_cluster(cluster_obj)
-                topology_obj.add_service(service_obj)
-            instance.topology = topology_obj
-
-        return instance
-
-    def get_topology(self):
-        return self.topology
-
-
-class MemberStartedEvent:
-
-    def __init__(self):
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_id = None
-        """ :type : str  """
-        self.network_partition_id = None
-        """ :type : str  """
-        self.partition_id = None
-        """ :type : str  """
-        self.member_id = None
-        """ :type : str  """
-        self.status = None
-        """ :type : str  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = MemberStartedEvent()
-
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
-        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
-        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
-        instance.properties = json_obj["properties"] if "properties" in json_obj else None
-
-        return instance
-
-
-class InstanceSpawnedEvent:
-
-    def __init__(self):
-        self.service_name = None
-        """ :type : str  """
-        self.cluster_id = None
-        """ :type : str  """
-        self.network_partition_id = None
-        """ :type : str  """
-        self.partition_id = None
-        """ :type : str  """
-        self.member_id = None
-        """ :type : str  """
-        self.lb_cluster_id = None
-        """ :type : str  """
-        self.member_public_ip = None
-        """ :type : str  """
-        self.member_ip = None
-        """ :type : str  """
-        self.properties = {}
-        """ :type : dict[str, str]  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = InstanceSpawnedEvent()
-
-        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
-        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
-        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
-        instance.lb_cluster_id = json_obj["lbClusterId"] if "lbClusterId" in json_obj else None
-        instance.member_public_ip = json_obj["memberPublicIp"] if "memberPublicIp" in json_obj else None
-        instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None
-        instance.properties = json_obj["properties"]
-
-        return instance
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/exception/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/exception/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/exception/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/exception/parameternotfoundexception.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/exception/parameternotfoundexception.py b/tools/python-cartridge-agent/cartridgeagent/modules/exception/parameternotfoundexception.py
deleted file mode 100644
index 88deafd..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/exception/parameternotfoundexception.py
+++ /dev/null
@@ -1,35 +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.
-
-class ParameterNotFoundException(Exception):
-    """
-    Exception raised when a property is not present in the configuration or the payload
-    of the cartridge agent
-    """
-    __message = None
-
-    def __init__(self, message):
-        Exception.__init__(self, message)
-        self.__message = message
-
-    def get_message(self):
-        """
-        The message provided when the exception is raised
-        :return: message
-        :rtype: str
-        """
-        return self.__message

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/extensions/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/extensions/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/extensions/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/extensions/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/extensions/abstractextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/extensions/abstractextensionhandler.py b/tools/python-cartridge-agent/cartridgeagent/modules/extensions/abstractextensionhandler.py
deleted file mode 100644
index 1f2df10..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/extensions/abstractextensionhandler.py
+++ /dev/null
@@ -1,78 +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.
-
-class AbstractExtensionHandler:
-
-    def on_instance_started_event(self):
-        raise NotImplementedError
-
-    def on_instance_activated_event(self):
-        raise NotImplementedError
-
-    def on_artifact_updated_event(self, artifacts_updated_event):
-        raise NotImplementedError
-
-    def on_artifact_update_scheduler_event(self, tenant_id):
-        raise NotImplementedError
-
-    def on_instance_cleanup_cluster_event(self, instance_cleanup_cluster_event):
-        raise NotImplementedError
-
-    def on_instance_cleanup_member_event(self, instance_cleanup_member_event):
-        raise NotImplementedError
-
-    def on_member_activated_event(self, member_activated_event):
-        raise NotImplementedError
-
-    def on_complete_topology_event(self, complete_topology_event):
-        raise NotImplementedError
-
-    def on_instance_spawned_event(self, instance_spawned_event):
-        raise NotImplementedError
-
-    def on_complete_tenant_event(self, complete_tenant_event):
-        raise NotImplementedError
-
-    def on_member_terminated_event(self, member_terminated_event):
-        raise NotImplementedError
-
-    def on_member_suspended_event(self, member_suspended_event):
-        raise NotImplementedError
-
-    def on_member_started_event(self, member_started_event):
-        raise NotImplementedError
-
-    def start_server_extension(self):
-        raise NotImplementedError
-
-    def volume_mount_extension(self, persistence_mappings_payload):
-        raise NotImplementedError
-
-    def on_subscription_domain_added_event(self, subscription_domain_added_event):
-        raise NotImplementedError
-
-    def on_subscription_domain_removed_event(self, subscription_domain_removed_event):
-        raise NotImplementedError
-
-    def on_copy_artifacts_extension(self, src, des):
-        raise NotImplementedError
-
-    def on_tenant_subscribed_event(self, tenant_subscribed_event):
-            raise NotImplementedError
-
-    def on_tenant_unsubscribed_event(self, tenant_unsubscribed_event):
-            raise NotImplementedError

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/extensions/defaultextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/extensions/defaultextensionhandler.py b/tools/python-cartridge-agent/cartridgeagent/modules/extensions/defaultextensionhandler.py
deleted file mode 100644
index 8a7ccc0..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/extensions/defaultextensionhandler.py
+++ /dev/null
@@ -1,789 +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.
-
-import time
-import json
-
-from abstractextensionhandler import AbstractExtensionHandler
-from ..util import extensionutils, cartridgeagentutils
-
-
-class DefaultExtensionHandler(AbstractExtensionHandler):
-    """
-    Default implementation of the AbstractExtensionHandler
-    """
-    log = None
-
-    def __init__(self):
-        self.log = LogFactory().get_log(__name__)
-        self.wk_members = []
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-    def on_instance_started_event(self):
-        try:
-            self.log.debug("Processing instance started event...")
-            if self.cartridge_agent_config.is_multitenant:
-                artifact_source = "%r/repository/deployment/server/" % self.cartridge_agent_config.app_path
-                artifact_dest = cartridgeagentconstants.SUPERTENANT_TEMP_PATH
-                extensionutils.execute_copy_artifact_extension(artifact_source, artifact_dest)
-
-            env_params = {}
-            extensionutils.execute_instance_started_extension(env_params)
-        except:
-            self.log.exception("Error processing instance started event")
-
-    def on_instance_activated_event(self):
-        extensionutils.execute_instance_activated_extension()
-
-    def on_artifact_updated_event(self, artifacts_updated_event):
-        self.log.info("Artifact update event received: [tenant] %r [cluster] %r [status] %r" %
-                      (artifacts_updated_event.tenant_id, artifacts_updated_event.cluster_id,
-                       artifacts_updated_event.status))
-
-        cluster_id_event = str(artifacts_updated_event.cluster_id).strip()
-        cluster_id_payload = self.cartridge_agent_config.cluster_id
-        repo_url = str(artifacts_updated_event.repo_url).strip()
-
-        if (repo_url != "") and (cluster_id_payload is not None) and (cluster_id_payload == cluster_id_event):
-            local_repo_path = self.cartridge_agent_config.app_path
-
-            secret = self.cartridge_agent_config.cartridge_key
-            repo_password = cartridgeagentutils.decrypt_password(artifacts_updated_event.repo_password, secret)
-
-            repo_username = artifacts_updated_event.repo_username
-            tenant_id = artifacts_updated_event.tenant_id
-            is_multitenant = self.cartridge_agent_config.is_multitenant
-            commit_enabled = artifacts_updated_event.commit_enabled
-
-            self.log.info("Executing git checkout")
-
-            # create repo object
-            repo_info = RepositoryInformation(repo_url, repo_username, repo_password, local_repo_path, tenant_id,
-                                              is_multitenant, commit_enabled)
-
-            # checkout code
-            subscribe_run, repo_context = agentgithandler.AgentGitHandler.checkout(repo_info)
-            # repo_context = checkout_result["repo_context"]
-            # execute artifact updated extension
-            env_params = {"STRATOS_ARTIFACT_UPDATED_CLUSTER_ID": artifacts_updated_event.cluster_id,
-                          "STRATOS_ARTIFACT_UPDATED_TENANT_ID": artifacts_updated_event.tenant_id,
-                          "STRATOS_ARTIFACT_UPDATED_REPO_URL": artifacts_updated_event.repo_url,
-                          "STRATOS_ARTIFACT_UPDATED_REPO_PASSWORD": artifacts_updated_event.repo_password,
-                          "STRATOS_ARTIFACT_UPDATED_REPO_USERNAME": artifacts_updated_event.repo_username,
-                          "STRATOS_ARTIFACT_UPDATED_STATUS": artifacts_updated_event.status}
-
-            extensionutils.execute_artifacts_updated_extension(env_params)
-
-            if subscribe_run:
-                # publish instanceActivated
-                cartridgeagentpublisher.publish_instance_activated_event()
-
-            update_artifacts = self.cartridge_agent_config.read_property(cartridgeagentconstants.ENABLE_ARTIFACT_UPDATE, False)
-            update_artifacts = True if str(update_artifacts).strip().lower() == "true" else False
-            if update_artifacts:
-                auto_commit = self.cartridge_agent_config.is_commits_enabled
-                auto_checkout = self.cartridge_agent_config.is_checkout_enabled
-
-                try:
-                    update_interval = len(
-                        self.cartridge_agent_config.read_property(cartridgeagentconstants.ARTIFACT_UPDATE_INTERVAL, False))
-                except ParameterNotFoundException:
-                    self.log.exception("Invalid artifact sync interval specified ")
-                    update_interval = 10
-                except ValueError:
-                    self.log.exception("Invalid artifact sync interval specified ")
-                    update_interval = 10
-
-                self.log.info("Artifact updating task enabled, update interval: %r seconds" % update_interval)
-
-                self.log.info("Auto Commit is turned %r " % "on" if auto_commit else "off")
-                self.log.info("Auto Checkout is turned %r " % "on" if auto_checkout else "off")
-
-                agentgithandler.AgentGitHandler.schedule_artifact_update_scheduled_task(repo_info, auto_checkout, auto_commit,
-                                                                        update_interval)
-
-    def on_artifact_update_scheduler_event(self, tenant_id):
-        env_params = {"STRATOS_ARTIFACT_UPDATED_TENANT_ID": tenant_id, "STRATOS_ARTIFACT_UPDATED_SCHEDULER": True}
-
-        extensionutils.execute_artifacts_updated_extension(env_params)
-
-    def on_instance_cleanup_cluster_event(self, instance_cleanup_cluster_event):
-        self.cleanup()
-
-    def on_instance_cleanup_member_event(self, instance_cleanup_member_event):
-        self.cleanup()
-
-    def on_member_activated_event(self, member_activated_event):
-        self.log.info("Member activated event received: [service] %r [cluster] %r [member] %r"
-            % (member_activated_event.service_name, member_activated_event.cluster_id, member_activated_event.member_id))
-
-        topology_consistent = extensionutils.check_topology_consistency(
-            member_activated_event.service_name,
-            member_activated_event.cluster_id,
-            member_activated_event.member_id)
-
-        if not topology_consistent:
-            self.log.error("Topology is inconsistent...failed to execute member activated event")
-            return
-
-        topology = TopologyContext.get_topology()
-        service = topology.get_service(member_activated_event.service_name)
-        cluster = service.get_cluster(member_activated_event.cluster_id)
-        member = cluster.get_member(member_activated_event.member_id)
-        lb_cluster_id = member.lb_cluster_id
-
-        if extensionutils.is_relevant_member_event(member_activated_event.service_name,
-                                                   member_activated_event.cluster_id, lb_cluster_id):
-
-            env_params = {"STRATOS_MEMBER_ACTIVATED_MEMBER_IP": str(member_activated_event.member_ip),
-                          "STRATOS_MEMBER_ACTIVATED_MEMBER_ID": str(member_activated_event.member_id),
-                          "STRATOS_MEMBER_ACTIVATED_CLUSTER_ID": str(member_activated_event.cluster_id),
-                          "STRATOS_MEMBER_ACTIVATED_LB_CLUSTER_ID": str(lb_cluster_id),
-                          "STRATOS_MEMBER_ACTIVATED_NETWORK_PARTITION_ID": str(member_activated_event.network_partition_id),
-                          "STRATOS_MEMBER_ACTIVATED_SERVICE_NAME": str(member_activated_event.service_name)}
-
-            ports = member_activated_event.port_map.values()
-            ports_str = ""
-            for port in ports:
-                ports_str += port.protocol + "," + str(port.value) + "," + str(port.proxy) + "|"
-
-            env_params["STRATOS_MEMBER_ACTIVATED_PORTS"] = ports_str
-
-            env_params["STRATOS_MEMBER_ACTIVATED_MEMBER_LIST_JSON"] = json.dumps(cluster.member_list_json)
-
-            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
-            if member_ips is not None and len(member_ips) > 1:
-                env_params["STRATOS_MEMBER_ACTIVATED_LB_IP"] = str(member_ips[0])
-                env_params["STRATOS_MEMBER_ACTIVATED_LB_PUBLIC_IP"] = str(member_ips[1])
-
-            env_params["STRATOS_TOPOLOGY_JSON"] = json.dumps(topology.json_str)
-
-            extensionutils.add_properties(service.properties, env_params, "MEMBER_ACTIVATED_SERVICE_PROPERTY")
-            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_ACTIVATED_CLUSTER_PROPERTY")
-            extensionutils.add_properties(member.properties, env_params, "MEMBER_ACTIVATED_MEMBER_PROPERTY")
-
-            clustered = self.cartridge_agent_config.is_clustered
-
-            if member.properties is not None and cartridgeagentconstants.CLUSTERING_PRIMARY_KEY in member.properties \
-                    and member.properties[cartridgeagentconstants.CLUSTERING_PRIMARY_KEY] == "true" \
-                    and clustered is not None and clustered:
-
-                self.log.debug(" If WK member is re-spawned, update axis2.xml ")
-
-                has_wk_ip_changed = True
-                for wk_member in self.wk_members:
-                    if wk_member.member_ip == member_activated_event.member_ip:
-                        has_wk_ip_changed = False
-
-                self.log.debug(" hasWKIpChanged %r" + has_wk_ip_changed)
-
-                min_count = int(self.cartridge_agent_config.min_count)
-                is_wk_member_grp_ready = self.is_wk_member_group_ready(env_params, min_count)
-                self.log.debug("MinCount: %r" % min_count)
-                self.log.debug("is_wk_member_grp_ready : %r" % is_wk_member_grp_ready)
-
-                if has_wk_ip_changed and is_wk_member_grp_ready:
-                    self.log.debug("Setting env var STRATOS_UPDATE_WK_IP to true")
-                    env_params["STRATOS_UPDATE_WK_IP"] = "true"
-
-            self.log.debug("Setting env var STRATOS_CLUSTERING to %r" % clustered)
-            env_params["STRATOS_CLUSTERING"] = str(clustered)
-            env_params["STRATOS_WK_MEMBER_COUNT"] = str(self.cartridge_agent_config.min_count)
-
-            extensionutils.execute_member_activated_extension(env_params)
-        else:
-            self.log.debug("Member activated event is not relevant...skipping agent extension")
-
-    def on_complete_topology_event(self, complete_topology_event):
-        self.log.debug("Complete topology event received")
-
-        service_name_in_payload = self.cartridge_agent_config.service_name
-        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
-        member_id_in_payload = self.cartridge_agent_config.member_id
-
-        consistant = extensionutils.check_topology_consistency(
-            service_name_in_payload,
-            cluster_id_in_payload,
-            member_id_in_payload)
-
-        if not consistant:
-            return
-        else:
-            self.cartridge_agent_config.initialized = True
-
-        topology = complete_topology_event.get_topology()
-        service = topology.get_service(service_name_in_payload)
-        cluster = service.get_cluster(cluster_id_in_payload)
-
-        env_params = {"STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str), "STRATOS_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json)}
-
-        extensionutils.execute_complete_topology_extension(env_params)
-
-    def on_instance_spawned_event(self, instance_spawned_event):
-        self.log.debug("Instance Spawned event received")
-
-        service_name_in_payload = self.cartridge_agent_config.service_name
-        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
-        member_id_in_payload = self.cartridge_agent_config.member_id
-
-        consistant = extensionutils.check_topology_consistency(
-            service_name_in_payload,
-            cluster_id_in_payload,
-            member_id_in_payload)
-
-        if not consistant:
-            return
-        else:
-            self.cartridge_agent_config.initialized = True
-
-    def on_complete_tenant_event(self, complete_tenant_event):
-        self.log.debug("Complete tenant event received")
-
-        tenant_list_json = complete_tenant_event.tenant_list_json
-        self.log.debug("Complete tenants:" + json.dumps(tenant_list_json))
-
-        env_params = {"STRATOS_TENANT_LIST_JSON": json.dumps(tenant_list_json)}
-
-        extensionutils.execute_complete_tenant_extension(env_params)
-
-    def on_member_terminated_event(self, member_terminated_event):
-        self.log.info("Member terminated event received: [service] " + member_terminated_event.service_name +
-                      " [cluster] " + member_terminated_event.cluster_id
-                      + " [member] " + member_terminated_event.member_id)
-
-        topology_consistent = extensionutils.check_topology_consistency(
-            member_terminated_event.service_name,
-            member_terminated_event.cluster_id,
-            member_terminated_event.member_id
-        )
-
-        if not topology_consistent:
-            self.log.error("Topology is inconsistent...failed to execute member terminated event")
-            return
-
-        topology = TopologyContext.get_topology()
-        service = topology.get_service(member_terminated_event.service_name)
-        cluster = service.get_cluster(member_terminated_event.cluster_id)
-        terminated_member = cluster.get_member(member_terminated_event.member_id)
-        lb_cluster_id = cluster.get_member(member_terminated_event.member_id).lb_cluster_id
-
-        #check whether terminated member is within the same cluster, LB cluster or service group
-        if extensionutils.is_relevant_member_event(
-                member_terminated_event.service_name,
-                member_terminated_event.cluster_id,
-                lb_cluster_id):
-
-            env_params = {"STRATOS_MEMBER_TERMINATED_MEMBER_IP": terminated_member.member_ip,
-                          "STRATOS_MEMBER_TERMINATED_MEMBER_ID": member_terminated_event.member_id,
-                          "STRATOS_MEMBER_TERMINATED_CLUSTER_ID": member_terminated_event.cluster_id,
-                          "STRATOS_MEMBER_TERMINATED_LB_CLUSTER_ID": lb_cluster_id,
-                          "STRATOS_MEMBER_TERMINATED_NETWORK_PARTITION_ID": member_terminated_event.network_partition_id,
-                          "STRATOS_MEMBER_TERMINATED_SERVICE_NAME": member_terminated_event.service_name,
-                          "STRATOS_MEMBER_TERMINATED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
-                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
-
-            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
-            if member_ips is not None and len(member_ips) > 1:
-                env_params["STRATOS_MEMBER_TERMINATED_LB_IP"] = member_ips[0]
-                env_params["STRATOS_MEMBER_TERMINATED_LB_PUBLIC_IP"] = member_ips[1]
-
-            extensionutils.add_properties(service.properties, env_params, "MEMBER_TERMINATED_SERVICE_PROPERTY")
-            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_TERMINATED_CLUSTER_PROPERTY")
-            extensionutils.add_properties(terminated_member.properties, env_params, "MEMBER_TERMINATED_MEMBER_PROPERTY")
-
-            extensionutils.execute_member_terminated_extension(env_params)
-
-        else:
-            self.log.debug("Member terminated event is not relevant...skipping agent extension")
-
-    def on_member_suspended_event(self, member_suspended_event):
-        self.log.info("Member suspended event received: [service] " + member_suspended_event.service_name +
-                      " [cluster] " + member_suspended_event.cluster_id + " [member] " + member_suspended_event.member_id)
-
-        topology_consistent = extensionutils.check_topology_consistency(
-            member_suspended_event.service_name,
-            member_suspended_event.cluster_id,
-            member_suspended_event.member_id
-        )
-
-        if not topology_consistent:
-            self.log.error("Topology is inconsistent...failed to execute member suspended event")
-            return
-
-        topology = TopologyContext.get_topology()
-        service = topology.get_service(member_suspended_event.service_name)
-        cluster = service.get_cluster(member_suspended_event.cluster_id)
-        suspended_member = cluster.get_member(member_suspended_event.member_id)
-        lb_cluster_id = cluster.get_member(member_suspended_event.member_id).lb_cluster_id
-
-        #check whether suspended member is within the same cluster, LB cluster or service group
-        if extensionutils.is_relevant_member_event(
-                member_suspended_event.service_name,
-                member_suspended_event.cluster_id,
-                lb_cluster_id):
-
-            env_params = {"STRATOS_MEMBER_SUSPENDED_MEMBER_IP": member_suspended_event.member_ip,
-                          "STRATOS_MEMBER_SUSPENDED_MEMBER_ID": member_suspended_event.member_id,
-                          "STRATOS_MEMBER_SUSPENDED_CLUSTER_ID": member_suspended_event.cluster_id,
-                          "STRATOS_MEMBER_SUSPENDED_LB_CLUSTER_ID": lb_cluster_id,
-                          "STRATOS_MEMBER_SUSPENDED_NETWORK_PARTITION_ID": member_suspended_event.network_partition_id,
-                          "STRATOS_MEMBER_SUSPENDED_SERVICE_NAME": member_suspended_event.service_name,
-                          "STRATOS_MEMBER_SUSPENDED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
-                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
-
-            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
-            if member_ips is not None and len(member_ips) > 1:
-                env_params["STRATOS_MEMBER_SUSPENDED_LB_IP"] = member_ips[0]
-                env_params["STRATOS_MEMBER_SUSPENDED_LB_PUBLIC_IP"] = member_ips[1]
-
-            extensionutils.add_properties(service.properties, env_params, "MEMBER_SUSPENDED_SERVICE_PROPERTY")
-            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_SUSPENDED_CLUSTER_PROPERTY")
-            extensionutils.add_properties(suspended_member.properties, env_params, "MEMBER_SUSPENDED_MEMBER_PROPERTY")
-
-            extensionutils.execute_member_suspended_extension(env_params)
-
-        else:
-            self.log.debug("Member suspended event is not relevant...skipping agent extension")
-
-    def on_member_started_event(self, member_started_event):
-        self.log.info("Member started event received: [service] " + member_started_event.service_name +
-                      " [cluster] " + member_started_event.cluster_id + " [member] " + member_started_event.member_id)
-
-        topology_consistent = extensionutils.check_topology_consistency(
-            member_started_event.service_name,
-            member_started_event.cluster_id,
-            member_started_event.member_id
-        )
-
-        if not topology_consistent:
-            self.log.error("Topology is inconsistent...failed to execute member started event")
-            return
-
-        topology = TopologyContext.get_topology()
-        service = topology.get_service(member_started_event.service_name)
-        cluster = service.get_cluster(member_started_event.cluster_id)
-        started_member = cluster.get_member(member_started_event.member_id)
-        lb_cluster_id = cluster.get_member(member_started_event.member_id).lb_cluster_id
-
-        #check whether started member is within the same cluster, LB cluster or service group
-        if extensionutils.is_relevant_member_event(
-                member_started_event.service_name,
-                member_started_event.cluster_id,
-                lb_cluster_id):
-
-            env_params = {"STRATOS_MEMBER_STARTED_MEMBER_IP": started_member.member_ip,
-                          "STRATOS_MEMBER_STARTED_MEMBER_ID": member_started_event.member_id,
-                          "STRATOS_MEMBER_STARTED_CLUSTER_ID": member_started_event.cluster_id,
-                          "STRATOS_MEMBER_STARTED_LB_CLUSTER_ID": lb_cluster_id,
-                          "STRATOS_MEMBER_STARTED_NETWORK_PARTITION_ID": member_started_event.network_partition_id,
-                          "STRATOS_MEMBER_STARTED_SERVICE_NAME": member_started_event.service_name,
-                          "STRATOS_MEMBER_STARTED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
-                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
-
-            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
-            if member_ips is not None and len(member_ips) > 1:
-                env_params["STRATOS_MEMBER_STARTED_LB_IP"] = member_ips[0]
-                env_params["STRATOS_MEMBER_STARTED_LB_PUBLIC_IP"] = member_ips[1]
-
-            extensionutils.add_properties(service.properties, env_params, "MEMBER_STARTED_SERVICE_PROPERTY")
-            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_STARTED_CLUSTER_PROPERTY")
-            extensionutils.add_properties(started_member.properties, env_params, "MEMBER_STARTED_MEMBER_PROPERTY")
-
-            extensionutils.execute_member_started_extension(env_params)
-
-        else:
-            self.log.debug("Member started event is not relevant...skipping agent extension")
-
-    def start_server_extension(self):
-        #wait until complete topology message is received to get LB IP
-        extensionutils.wait_for_complete_topology()
-        self.log.info("[start server extension] complete topology event received")
-
-        service_name_in_payload = self.cartridge_agent_config.service_name
-        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
-        member_id_in_payload = self.cartridge_agent_config.member_id
-
-        topology_consistant = extensionutils.check_topology_consistency(service_name_in_payload, cluster_id_in_payload, member_id_in_payload)
-
-        try:
-            if not topology_consistant:
-                self.log.error("Topology is inconsistent...failed to execute start server event")
-                return
-
-            topology = TopologyContext.get_topology()
-            service = topology.get_service(service_name_in_payload)
-            cluster = service.get_cluster(cluster_id_in_payload)
-
-            # store environment variable parameters to be passed to extension shell script
-            env_params = {}
-
-            # if clustering is enabled wait until all well known members have started
-            clustering_enabled = self.cartridge_agent_config.is_clustered
-            if clustering_enabled:
-                env_params["STRATOS_CLUSTERING"] = "true"
-                env_params["STRATOS_WK_MEMBER_COUNT"] = self.cartridge_agent_config.min_count
-
-                env_params["STRATOS_PRIMARY"] = "true" if self.cartridge_agent_config.is_primary else "false"
-
-                self.wait_for_wk_members(env_params)
-                self.log.info("All well known members have started! Resuming start server extension...")
-
-            env_params["STRATOS_TOPOLOGY_JSON"] = json.dumps(topology.json_str)
-            env_params["STRATOS_MEMBER_LIST_JSON"] = json.dumps(cluster.member_list_json)
-
-            extensionutils.execute_start_servers_extension(env_params)
-
-        except:
-            self.log.exception("Error processing start servers event")
-
-    def volume_mount_extension(self, persistence_mappings_payload):
-        extensionutils.execute_volume_mount_extension(persistence_mappings_payload)
-
-    def on_subscription_domain_added_event(self, subscription_domain_added_event):
-        tenant_domain = self.find_tenant_domain(subscription_domain_added_event.tenant_id)
-        self.log.info(
-            "Subscription domain added event received: [tenant-id] " + subscription_domain_added_event.tenant_id +
-            " [tenant-domain] " + tenant_domain + " [domain-name] " + subscription_domain_added_event.domain_name +
-            " [application-context] " + subscription_domain_added_event.application_context
-        )
-
-        env_params = {"STRATOS_SUBSCRIPTION_SERVICE_NAME": subscription_domain_added_event.service_name,
-                      "STRATOS_SUBSCRIPTION_DOMAIN_NAME": subscription_domain_added_event.domain_name,
-                      "STRATOS_SUBSCRIPTION_TENANT_ID": int(subscription_domain_added_event.tenant_id),
-                      "STRATOS_SUBSCRIPTION_TENANT_DOMAIN": tenant_domain,
-                      "STRATOS_SUBSCRIPTION_APPLICATION_CONTEXT": subscription_domain_added_event.application_context}
-
-        extensionutils.execute_subscription_domain_added_extension(env_params)
-
-    def on_subscription_domain_removed_event(self, subscription_domain_removed_event):
-        tenant_domain = self.find_tenant_domain(subscription_domain_removed_event.tenant_id)
-        self.log.info(
-            "Subscription domain removed event received: [tenant-id] " + subscription_domain_removed_event.tenant_id +
-            " [tenant-domain] " + tenant_domain + " [domain-name] " + subscription_domain_removed_event.domain_name
-        )
-
-        env_params = {"STRATOS_SUBSCRIPTION_SERVICE_NAME": subscription_domain_removed_event.service_name,
-                      "STRATOS_SUBSCRIPTION_DOMAIN_NAME": subscription_domain_removed_event.domain_name,
-                      "STRATOS_SUBSCRIPTION_TENANT_ID": int(subscription_domain_removed_event.tenant_id),
-                      "STRATOS_SUBSCRIPTION_TENANT_DOMAIN": tenant_domain}
-
-        extensionutils.execute_subscription_domain_removed_extension(env_params)
-
-    def on_copy_artifacts_extension(self, src, des):
-        extensionutils.execute_copy_artifact_extension(src, des)
-
-    def on_tenant_subscribed_event(self, tenant_subscribed_event):
-        self.log.info(
-            "Tenant subscribed event received: [tenant] " + tenant_subscribed_event.tenant_id +
-            " [service] " + tenant_subscribed_event.service_name + " [cluster] " + tenant_subscribed_event.cluster_ids
-        )
-
-        extensionutils.execute_tenant_subscribed_extension({})
-
-    def on_tenant_unsubscribed_event(self, tenant_unsubscribed_event):
-        self.log.info(
-            "Tenant unsubscribed event received: [tenant] " + tenant_unsubscribed_event.tenant_id +
-            " [service] " + tenant_unsubscribed_event.service_name +
-            " [cluster] " + tenant_unsubscribed_event.cluster_ids
-        )
-
-        try:
-            if self.cartridge_agent_config.service_name == tenant_unsubscribed_event.service_name:
-                agentgithandler.AgentGitHandler.remove_repo(tenant_unsubscribed_event.tenant_id)
-        except:
-            self.log.exception("Removing git repository failed: ")
-        extensionutils.execute_tenant_unsubscribed_extension({})
-
-    def cleanup(self):
-        self.log.info("Executing cleaning up the data in the cartridge instance...")
-
-        cartridgeagentpublisher.publish_maintenance_mode_event()
-
-        extensionutils.execute_cleanup_extension()
-        self.log.info("cleaning up finished in the cartridge instance...")
-
-        self.log.info("publishing ready to shutdown event...")
-        cartridgeagentpublisher.publish_instance_ready_to_shutdown_event()
-
-    def is_wk_member_group_ready(self, env_params, min_count):
-        topology = TopologyContext.get_topology()
-        if topology is None or not topology.initialized:
-            return False
-
-        service_group_in_payload = self.cartridge_agent_config.service_group
-        if service_group_in_payload is not None:
-            env_params["STRATOS_SERVICE_GROUP"] = service_group_in_payload
-
-        # clustering logic for apimanager
-        if service_group_in_payload is not None and service_group_in_payload == "apim":
-            # handle apistore and publisher case
-            if self.cartridge_agent_config.service_name == cartridgeagentconstants.APIMANAGER_SERVICE_NAME or \
-                    self.cartridge_agent_config.service_name == cartridgeagentconstants.PUBLISHER_SERVICE_NAME:
-
-                apistore_cluster_collection = topology.get_service(cartridgeagentconstants.APIMANAGER_SERVICE_NAME)\
-                    .get_clusters()
-                publisher_cluster_collection = topology.get_service(cartridgeagentconstants.PUBLISHER_SERVICE_NAME)\
-                    .get_clusters()
-
-                apistore_member_list = []
-                for member in apistore_cluster_collection[0].get_members():
-                    if member.status == MemberStatus.Starting or member.status == MemberStatus.Activated:
-                        apistore_member_list.append(member)
-                        self.wk_members.append(member)
-
-                if len(apistore_member_list) == 0:
-                    self.log.debug("API Store members not yet created")
-                    return False
-
-                apistore_member = apistore_member_list[0]
-                env_params["STRATOS_WK_APISTORE_MEMBER_IP"] = apistore_member.member_ip
-                self.log.debug("STRATOS_WK_APISTORE_MEMBER_IP: %r" % apistore_member.member_ip)
-
-                publisher_member_list = []
-                for member in publisher_cluster_collection[0].get_members():
-                    if member.status == MemberStatus.Starting or member.status == MemberStatus.Activated:
-                        publisher_member_list.append(member)
-                        self.wk_members.append(member)
-
-                if len(publisher_member_list) == 0:
-                    self.log.debug("API Publisher members not yet created")
-
-                publisher_member = publisher_member_list[0]
-                env_params["STRATOS_WK_PUBLISHER_MEMBER_IP"] = publisher_member.member_ip
-                self.log.debug("STRATOS_WK_PUBLISHER_MEMBER_IP: %r" % publisher_member.member_ip)
-
-                return True
-
-            elif self.cartridge_agent_config.service_name == cartridgeagentconstants.GATEWAY_MGT_SERVICE_NAME or \
-                    self.cartridge_agent_config.service_name == cartridgeagentconstants.GATEWAY_SERVICE_NAME:
-
-                if self.cartridge_agent_config.deployment is not None:
-                    # check if deployment is Manager Worker separated
-                    if self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower() or \
-                            self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
-
-                        self.log.info("Deployment pattern for the node: %r" % self.cartridge_agent_config.deployment)
-                        env_params["DEPLOYMENT"] = self.cartridge_agent_config.deployment
-                        # check if WKA members of Manager Worker separated deployment is ready
-                        return self.is_manager_worker_WKA_group_ready(env_params)
-
-            elif self.cartridge_agent_config.service_name == cartridgeagentconstants.KEY_MANAGER_SERVICE_NAME:
-                return True
-
-        else:
-            if self.cartridge_agent_config.deployment is not None:
-                # check if deployment is Manager Worker separated
-                if self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower() or \
-                        self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
-
-                    self.log.info("Deployment pattern for the node: %r" % self.cartridge_agent_config.deployment)
-                    env_params["DEPLOYMENT"] = self.cartridge_agent_config.deployment
-                    # check if WKA members of Manager Worker separated deployment is ready
-                    return self.is_manager_worker_WKA_group_ready(env_params)
-
-            service_name_in_payload = self.cartridge_agent_config.service_name
-            cluster_id_in_payload = self.cartridge_agent_config.cluster_id
-            service = topology.get_service(service_name_in_payload)
-            cluster = service.get_cluster(cluster_id_in_payload)
-
-            wk_members = []
-            for member in cluster.get_members():
-                if member.properties is not None and \
-                        cartridgeagentconstants.PRIMARY in member.properties \
-                        and member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
-                        (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
-
-                    wk_members.append(member)
-                    self.wk_members.append(member)
-                    self.log.debug("Found WKA: STRATOS_WK_MEMBER_IP: " + member.member_ip)
-
-            if len(wk_members) >= min_count:
-                idx = 0
-                for member in wk_members:
-                    env_params["STRATOS_WK_MEMBER_" + idx + "_IP"] = member.member_ip
-                    self.log.debug("STRATOS_WK_MEMBER_" + idx + "_IP:" + member.member_ip)
-
-                    idx += 1
-
-                return True
-
-        return False
-
-    # generic worker manager separated clustering logic
-    def is_manager_worker_WKA_group_ready(self, env_params):
-
-        # for this, we need both manager cluster service name and worker cluster service name
-        manager_service_name = self.cartridge_agent_config.manager_service_name
-        worker_service_name = self.cartridge_agent_config.worker_service_name
-
-        # managerServiceName and workerServiceName both should not be null /empty
-        if manager_service_name is None or manager_service_name.strip() == "":
-            self.log.error("Manager service name [ " + manager_service_name + " ] is invalid")
-            return False
-
-        if worker_service_name is None or worker_service_name.strip() == "":
-            self.log.error("Worker service name [ " + worker_service_name + " ] is invalid")
-            return False
-
-        min_manager_instances_available = False
-        min_worker_instances_available = False
-
-        topology = TopologyContext.get_topology()
-        manager_service = topology.get_service(manager_service_name)
-        worker_service = topology.get_service(worker_service_name)
-
-        if manager_service is None:
-            self.log.warn("Service [ " + manager_service_name + " ] is not found")
-            return False
-
-        if worker_service is None:
-            self.log.warn("Service [ " + worker_service_name + " ] is not found")
-            return False
-
-        # manager clusters
-        manager_clusters = manager_service.get_clusters()
-        if manager_clusters is None or len(manager_clusters) == 0:
-            self.log.warn("No clusters found for service [ " + manager_service_name + " ]")
-            return False
-
-        manager_min_instance_count = 1
-        manager_min_instance_count_found = False
-
-        manager_wka_members = []
-        for member in manager_clusters[0].get_members():
-            if member.properties is not None and \
-                    cartridgeagentconstants.PRIMARY in member.properties \
-                    and member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
-                    (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
-
-                manager_wka_members.append(member)
-                self.wk_members.append(member)
-
-                # get the min instance count
-                if not manager_min_instance_count_found:
-                    manager_min_instance_count = self.get_min_instance_count_from_member(member)
-                    manager_min_instance_count_found = True
-                    self.log.info("Manager min instance count: " + manager_min_instance_count)
-
-        if len(manager_wka_members) >= manager_min_instance_count:
-            min_manager_instances_available = True
-            idx = 0
-            for member in manager_wka_members:
-                env_params["STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP"] = member.member_ip
-                self.log.debug("STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP: " + member.member_ip)
-                idx += 1
-
-            env_params["STRATOS_WK_MANAGER_MEMBER_COUNT"] = int(manager_min_instance_count)
-
-        # If all the manager members are non primary and is greate than or equal to mincount,
-        # minManagerInstancesAvailable should be true
-        all_managers_non_primary = True
-        for member in manager_clusters[0].get_members():
-            # get the min instance count
-            if not manager_min_instance_count_found:
-                manager_min_instance_count = self.get_min_instance_count_from_member(member)
-                manager_min_instance_count_found = True
-                self.log.info(
-                    "Manager min instance count when allManagersNonPrimary true : " + manager_min_instance_count)
-
-            if member.properties is not None and cartridgeagentconstants.PRIMARY in member.properties and \
-                    member.properties[cartridgeagentconstants.PRIMARY].lower() == "true":
-                all_managers_non_primary = False
-                break
-
-        self.log.debug(
-            " allManagerNonPrimary & managerMinInstanceCount [" + all_managers_non_primary +
-            "], [" + manager_min_instance_count + "] ")
-
-        if all_managers_non_primary and len(manager_clusters) >= manager_min_instance_count:
-            min_manager_instances_available = True
-
-        # worker cluster
-        worker_clusters = worker_service.get_clusters()
-        if worker_clusters is None or len(worker_clusters) == 0:
-            self.log.warn("No clusters found for service [ " + worker_service_name + " ]")
-            return False
-
-        worker_min_instance_count = 1
-        worker_min_instance_count_found = False
-
-        worker_wka_members = []
-        for member in worker_clusters[0].get_members():
-            self.log.debug("Checking member : " + member.member_id)
-
-            if member.properties is not None and cartridgeagentconstants.PRIMARY in member.properties and \
-                    member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
-                    (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
-
-                self.log.debug("Added worker member " + member.member_id)
-
-                worker_wka_members.append(member)
-                self.wk_members.append(member)
-
-                # get the min instance count
-                if not worker_min_instance_count_found:
-                    worker_min_instance_count = self.get_min_instance_count_from_member(member)
-                    worker_min_instance_count_found = True
-                    self.log.debug("Worker min instance count: " + worker_min_instance_count)
-
-        if len(worker_wka_members) >= worker_min_instance_count:
-            min_worker_instances_available = True
-            idx = 0
-            for member in worker_wka_members:
-                env_params["STRATOS_WK_WORKER_MEMBER_" + idx + "_IP"] = member.member_ip
-                self.log.debug("STRATOS_WK_WORKER_MEMBER_" + idx + "_IP: " + member.member_ip)
-                idx += 1
-
-            env_params["STRATOS_WK_WORKER_MEMBER_COUNT"] = int(worker_min_instance_count)
-
-        self.log.debug(
-            " Returnning values minManagerInstancesAvailable && minWorkerInstancesAvailable [" +
-            min_manager_instances_available + "],  [" + min_worker_instances_available + "] ")
-
-        return min_manager_instances_available and min_worker_instances_available
-
-    def get_min_instance_count_from_member(self, member):
-        if cartridgeagentconstants.MIN_COUNT in member.properties:
-            return int(member.properties[cartridgeagentconstants.MIN_COUNT])
-
-        return 1
-
-    def find_tenant_domain(self, tenant_id):
-        tenant = TenantContext.get_tenant(tenant_id)
-        if tenant is None:
-            raise RuntimeError("Tenant could not be found: [tenant-id] %r" % tenant_id)
-
-        return tenant.tenant_domain
-
-    def wait_for_wk_members(self, env_params):
-        min_count = int(self.cartridge_agent_config.min_count)
-        is_wk_member_group_ready = False
-        while not is_wk_member_group_ready:
-            self.log.info("Waiting for %r well known members..." % min_count)
-
-            time.sleep(5)
-
-            is_wk_member_group_ready = self.is_wk_member_group_ready(env_params, min_count)
-
-from ..artifactmgt.git import agentgithandler
-from ..artifactmgt.repositoryinformation import RepositoryInformation
-from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
-from ..publisher import cartridgeagentpublisher
-from ..exception.parameternotfoundexception import ParameterNotFoundException
-from ..topology.topologycontext import *
-from ..tenant.tenantcontext import *
-from ..util.log import LogFactory
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py b/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
deleted file mode 100644
index 685344d..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
+++ /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.
-
-class AbstractHealthStatisticsReader:
-    """
-    Abstract class to implement to create a custom health stat reader
-    """
-
-    def stat_cartridge_health(self):
-        """
-        Abstract method that when implemented reads the memory usage and the load average
-        of the instance running the agent and returns a CartridgeHealthStatistics object
-        with the information
-
-        :return: CartridgeHealthStatistics object with memory usage and load average values
-        :rtype : CartridgeHealthStatistics
-        """
-        raise NotImplementedError
-
-
-class CartridgeHealthStatistics:
-    """
-    Holds the memory usage and load average reading
-    """
-
-    def __init__(self):
-        self.memory_usage = None
-        """:type : float"""
-        self.load_avg = None
-        """:type : float"""
-
-
-class CEPPublisherException(Exception):
-    """
-    Exception to be used during CEP publishing operations
-    """
-
-    def __init__(self, msg):
-        super(self,  msg)
-        self.message = msg
-
-    def get_message(self):
-        """
-        The message provided when the exception is raised
-        :return: message
-        :rtype: str
-        """
-        return self.message


[05/50] [abbrv] git commit: Merge remote-tracking branch 'upstream/master'

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


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

Branch: refs/heads/master
Commit: 33a1f2b8031cb1b29c7d591b4ace9e95a68c2298
Parents: 56b5265 5c63660
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Thu Oct 16 15:24:36 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Thu Oct 16 15:24:36 2014 +0530

----------------------------------------------------------------------
 tools/stratos-installer/clean.sh | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[48/50] [abbrv] git commit: Merge remote-tracking branch 'upstream/master'

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


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

Branch: refs/heads/master
Commit: c76076eb8e896a17fe4857aedbc8d9c626aa9a30
Parents: e7a3c27 f3653d3
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Sun Oct 26 17:13:21 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Sun Oct 26 17:13:21 2014 +0530

----------------------------------------------------------------------
 .../stratos/autoscaler/PartitionContext.java    |   23 +-
 .../autoscaler/api/AutoScalerServiceImpl.java   |   18 +-
 .../interfaces/AutoScalerServiceInterface.java  |    4 +
 .../monitor/ClusterMonitorFactory.java          |    2 +-
 .../monitor/KubernetesClusterMonitor.java       |   13 +-
 .../KubernetesServiceClusterMonitor.java        |   11 +-
 .../autoscaler/monitor/VMLbClusterMonitor.java  |    4 +-
 .../monitor/VMServiceClusterMonitor.java        |    4 +-
 .../autoscaler/policy/PolicyManager.java        |   67 +-
 .../autoscaler/util/AutoScalerConstants.java    |    6 +-
 .../stratos/cli/RestCommandLineService.java     |   23 +-
 .../apache/stratos/cli/StratosApplication.java  |    8 +-
 .../UpdateAutoscalingPolicyCommand.java         |  122 ++
 .../commands/UpdateDeploymentPolicyCommand.java |  122 ++
 .../impl/CloudControllerServiceImpl.java        |  174 +-
 .../InstanceStatusEventMessageListener.java     |    4 +-
 .../controller/topology/TopologyBuilder.java    |   46 +-
 .../common/constants/StratosConstants.java      |    6 +-
 .../kubernetes/client/KubernetesApiClient.java  |   39 +-
 .../KubernetesAPIClientInterface.java           |    4 +-
 .../stratos/kubernetes/client/model/State.java  |   14 +-
 .../client/rest/KubernetesResponseHandler.java  |   10 +-
 .../kubernetes/client/rest/RestClient.java      |   42 +-
 .../org.apache.stratos.load.balancer/pom.xml    |    6 +-
 .../manager/client/AutoscalerServiceClient.java |   12 +
 .../topology/TopologyEventMessageListener.java  |   71 +-
 .../policy/deployment/DeploymentPolicy.java     |   50 +-
 .../bean/util/converter/PojoConverter.java      |   18 +-
 .../stratos/rest/endpoint/mock/MockContext.java |   14 +-
 .../rest/endpoint/services/ServiceUtils.java    |   57 +-
 .../rest/endpoint/services/StratosAdmin.java    |   28 +-
 .../load-balancer/modules/distribution/pom.xml  |   21 +
 .../distribution/src/main/assembly/bin.xml      |   14 +
 .../src/main/conf/mqtttopic.properties          |   21 +
 .../distribution/src/main/conf/autoscaler.xml   |   21 +-
 .../src/main/conf/drools/container-scaling.drl  |    8 +-
 .../src/main/resources/AutoScalerService.wsdl   | 1554 ++++++++++--------
 .../lib/puppet/parser/functions/difference.rb   |   17 +
 .../all/repository/conf/cloud-controller.xml    |    4 +-
 .../cc/repository/conf/cloud-controller.xml     |    4 +-
 40 files changed, 1619 insertions(+), 1067 deletions(-)
----------------------------------------------------------------------



[29/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
new file mode 100644
index 0000000..953838e
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
@@ -0,0 +1,405 @@
+#
+# 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.
+#
+
+from struct import pack, unpack
+
+from TProtocol import *
+
+
+__all__ = ['TCompactProtocol', 'TCompactProtocolFactory']
+
+CLEAR = 0
+FIELD_WRITE = 1
+VALUE_WRITE = 2
+CONTAINER_WRITE = 3
+BOOL_WRITE = 4
+FIELD_READ = 5
+CONTAINER_READ = 6
+VALUE_READ = 7
+BOOL_READ = 8
+
+
+def make_helper(v_from, container):
+  def helper(func):
+    def nested(self, *args, **kwargs):
+      assert self.state in (v_from, container), (self.state, v_from, container)
+      return func(self, *args, **kwargs)
+    return nested
+  return helper
+writer = make_helper(VALUE_WRITE, CONTAINER_WRITE)
+reader = make_helper(VALUE_READ, CONTAINER_READ)
+
+
+def makeZigZag(n, bits):
+  return (n << 1) ^ (n >> (bits - 1))
+
+
+def fromZigZag(n):
+  return (n >> 1) ^ -(n & 1)
+
+
+def writeVarint(trans, n):
+  out = []
+  while True:
+    if n & ~0x7f == 0:
+      out.append(n)
+      break
+    else:
+      out.append((n & 0xff) | 0x80)
+      n = n >> 7
+  trans.write(''.join(map(chr, out)))
+
+
+def readVarint(trans):
+  result = 0
+  shift = 0
+  while True:
+    x = trans.readAll(1)
+    byte = ord(x)
+    result |= (byte & 0x7f) << shift
+    if byte >> 7 == 0:
+      return result
+    shift += 7
+
+
+class CompactType:
+  STOP = 0x00
+  TRUE = 0x01
+  FALSE = 0x02
+  BYTE = 0x03
+  I16 = 0x04
+  I32 = 0x05
+  I64 = 0x06
+  DOUBLE = 0x07
+  BINARY = 0x08
+  LIST = 0x09
+  SET = 0x0A
+  MAP = 0x0B
+  STRUCT = 0x0C
+
+CTYPES = {TType.STOP: CompactType.STOP,
+          TType.BOOL: CompactType.TRUE,  # used for collection
+          TType.BYTE: CompactType.BYTE,
+          TType.I16: CompactType.I16,
+          TType.I32: CompactType.I32,
+          TType.I64: CompactType.I64,
+          TType.DOUBLE: CompactType.DOUBLE,
+          TType.STRING: CompactType.BINARY,
+          TType.STRUCT: CompactType.STRUCT,
+          TType.LIST: CompactType.LIST,
+          TType.SET: CompactType.SET,
+          TType.MAP: CompactType.MAP
+          }
+
+TTYPES = {}
+for k, v in CTYPES.items():
+  TTYPES[v] = k
+TTYPES[CompactType.FALSE] = TType.BOOL
+del k
+del v
+
+
+class TCompactProtocol(TProtocolBase):
+  """Compact implementation of the Thrift protocol driver."""
+
+  PROTOCOL_ID = 0x82
+  VERSION = 1
+  VERSION_MASK = 0x1f
+  TYPE_MASK = 0xe0
+  TYPE_SHIFT_AMOUNT = 5
+
+  def __init__(self, trans):
+    TProtocolBase.__init__(self, trans)
+    self.state = CLEAR
+    self.__last_fid = 0
+    self.__bool_fid = None
+    self.__bool_value = None
+    self.__structs = []
+    self.__containers = []
+
+  def __writeVarint(self, n):
+    writeVarint(self.trans, n)
+
+  def writeMessageBegin(self, name, type, seqid):
+    assert self.state == CLEAR
+    self.__writeUByte(self.PROTOCOL_ID)
+    self.__writeUByte(self.VERSION | (type << self.TYPE_SHIFT_AMOUNT))
+    self.__writeVarint(seqid)
+    self.__writeString(name)
+    self.state = VALUE_WRITE
+
+  def writeMessageEnd(self):
+    assert self.state == VALUE_WRITE
+    self.state = CLEAR
+
+  def writeStructBegin(self, name):
+    assert self.state in (CLEAR, CONTAINER_WRITE, VALUE_WRITE), self.state
+    self.__structs.append((self.state, self.__last_fid))
+    self.state = FIELD_WRITE
+    self.__last_fid = 0
+
+  def writeStructEnd(self):
+    assert self.state == FIELD_WRITE
+    self.state, self.__last_fid = self.__structs.pop()
+
+  def writeFieldStop(self):
+    self.__writeByte(0)
+
+  def __writeFieldHeader(self, type, fid):
+    delta = fid - self.__last_fid
+    if 0 < delta <= 15:
+      self.__writeUByte(delta << 4 | type)
+    else:
+      self.__writeByte(type)
+      self.__writeI16(fid)
+    self.__last_fid = fid
+
+  def writeFieldBegin(self, name, type, fid):
+    assert self.state == FIELD_WRITE, self.state
+    if type == TType.BOOL:
+      self.state = BOOL_WRITE
+      self.__bool_fid = fid
+    else:
+      self.state = VALUE_WRITE
+      self.__writeFieldHeader(CTYPES[type], fid)
+
+  def writeFieldEnd(self):
+    assert self.state in (VALUE_WRITE, BOOL_WRITE), self.state
+    self.state = FIELD_WRITE
+
+  def __writeUByte(self, byte):
+    self.trans.write(pack('!B', byte))
+
+  def __writeByte(self, byte):
+    self.trans.write(pack('!b', byte))
+
+  def __writeI16(self, i16):
+    self.__writeVarint(makeZigZag(i16, 16))
+
+  def __writeSize(self, i32):
+    self.__writeVarint(i32)
+
+  def writeCollectionBegin(self, etype, size):
+    assert self.state in (VALUE_WRITE, CONTAINER_WRITE), self.state
+    if size <= 14:
+      self.__writeUByte(size << 4 | CTYPES[etype])
+    else:
+      self.__writeUByte(0xf0 | CTYPES[etype])
+      self.__writeSize(size)
+    self.__containers.append(self.state)
+    self.state = CONTAINER_WRITE
+  writeSetBegin = writeCollectionBegin
+  writeListBegin = writeCollectionBegin
+
+  def writeMapBegin(self, ktype, vtype, size):
+    assert self.state in (VALUE_WRITE, CONTAINER_WRITE), self.state
+    if size == 0:
+      self.__writeByte(0)
+    else:
+      self.__writeSize(size)
+      self.__writeUByte(CTYPES[ktype] << 4 | CTYPES[vtype])
+    self.__containers.append(self.state)
+    self.state = CONTAINER_WRITE
+
+  def writeCollectionEnd(self):
+    assert self.state == CONTAINER_WRITE, self.state
+    self.state = self.__containers.pop()
+  writeMapEnd = writeCollectionEnd
+  writeSetEnd = writeCollectionEnd
+  writeListEnd = writeCollectionEnd
+
+  def writeBool(self, bool):
+    if self.state == BOOL_WRITE:
+      if bool:
+        ctype = CompactType.TRUE
+      else:
+        ctype = CompactType.FALSE
+      self.__writeFieldHeader(ctype, self.__bool_fid)
+    elif self.state == CONTAINER_WRITE:
+      if bool:
+        self.__writeByte(CompactType.TRUE)
+      else:
+        self.__writeByte(CompactType.FALSE)
+    else:
+      raise AssertionError("Invalid state in compact protocol")
+
+  writeByte = writer(__writeByte)
+  writeI16 = writer(__writeI16)
+
+  @writer
+  def writeI32(self, i32):
+    self.__writeVarint(makeZigZag(i32, 32))
+
+  @writer
+  def writeI64(self, i64):
+    self.__writeVarint(makeZigZag(i64, 64))
+
+  @writer
+  def writeDouble(self, dub):
+    self.trans.write(pack('!d', dub))
+
+  def __writeString(self, s):
+    self.__writeSize(len(s))
+    self.trans.write(s)
+  writeString = writer(__writeString)
+
+  def readFieldBegin(self):
+    assert self.state == FIELD_READ, self.state
+    type = self.__readUByte()
+    if type & 0x0f == TType.STOP:
+      return (None, 0, 0)
+    delta = type >> 4
+    if delta == 0:
+      fid = self.__readI16()
+    else:
+      fid = self.__last_fid + delta
+    self.__last_fid = fid
+    type = type & 0x0f
+    if type == CompactType.TRUE:
+      self.state = BOOL_READ
+      self.__bool_value = True
+    elif type == CompactType.FALSE:
+      self.state = BOOL_READ
+      self.__bool_value = False
+    else:
+      self.state = VALUE_READ
+    return (None, self.__getTType(type), fid)
+
+  def readFieldEnd(self):
+    assert self.state in (VALUE_READ, BOOL_READ), self.state
+    self.state = FIELD_READ
+
+  def __readUByte(self):
+    result, = unpack('!B', self.trans.readAll(1))
+    return result
+
+  def __readByte(self):
+    result, = unpack('!b', self.trans.readAll(1))
+    return result
+
+  def __readVarint(self):
+    return readVarint(self.trans)
+
+  def __readZigZag(self):
+    return fromZigZag(self.__readVarint())
+
+  def __readSize(self):
+    result = self.__readVarint()
+    if result < 0:
+      raise TException("Length < 0")
+    return result
+
+  def readMessageBegin(self):
+    assert self.state == CLEAR
+    proto_id = self.__readUByte()
+    if proto_id != self.PROTOCOL_ID:
+      raise TProtocolException(TProtocolException.BAD_VERSION,
+          'Bad protocol id in the message: %d' % proto_id)
+    ver_type = self.__readUByte()
+    type = (ver_type & self.TYPE_MASK) >> self.TYPE_SHIFT_AMOUNT
+    version = ver_type & self.VERSION_MASK
+    if version != self.VERSION:
+      raise TProtocolException(TProtocolException.BAD_VERSION,
+          'Bad version: %d (expect %d)' % (version, self.VERSION))
+    seqid = self.__readVarint()
+    name = self.__readString()
+    return (name, type, seqid)
+
+  def readMessageEnd(self):
+    assert self.state == CLEAR
+    assert len(self.__structs) == 0
+
+  def readStructBegin(self):
+    assert self.state in (CLEAR, CONTAINER_READ, VALUE_READ), self.state
+    self.__structs.append((self.state, self.__last_fid))
+    self.state = FIELD_READ
+    self.__last_fid = 0
+
+  def readStructEnd(self):
+    assert self.state == FIELD_READ
+    self.state, self.__last_fid = self.__structs.pop()
+
+  def readCollectionBegin(self):
+    assert self.state in (VALUE_READ, CONTAINER_READ), self.state
+    size_type = self.__readUByte()
+    size = size_type >> 4
+    type = self.__getTType(size_type)
+    if size == 15:
+      size = self.__readSize()
+    self.__containers.append(self.state)
+    self.state = CONTAINER_READ
+    return type, size
+  readSetBegin = readCollectionBegin
+  readListBegin = readCollectionBegin
+
+  def readMapBegin(self):
+    assert self.state in (VALUE_READ, CONTAINER_READ), self.state
+    size = self.__readSize()
+    types = 0
+    if size > 0:
+      types = self.__readUByte()
+    vtype = self.__getTType(types)
+    ktype = self.__getTType(types >> 4)
+    self.__containers.append(self.state)
+    self.state = CONTAINER_READ
+    return (ktype, vtype, size)
+
+  def readCollectionEnd(self):
+    assert self.state == CONTAINER_READ, self.state
+    self.state = self.__containers.pop()
+  readSetEnd = readCollectionEnd
+  readListEnd = readCollectionEnd
+  readMapEnd = readCollectionEnd
+
+  def readBool(self):
+    if self.state == BOOL_READ:
+      return self.__bool_value == CompactType.TRUE
+    elif self.state == CONTAINER_READ:
+      return self.__readByte() == CompactType.TRUE
+    else:
+      raise AssertionError("Invalid state in compact protocol: %d" %
+                           self.state)
+
+  readByte = reader(__readByte)
+  __readI16 = __readZigZag
+  readI16 = reader(__readZigZag)
+  readI32 = reader(__readZigZag)
+  readI64 = reader(__readZigZag)
+
+  @reader
+  def readDouble(self):
+    buff = self.trans.readAll(8)
+    val, = unpack('!d', buff)
+    return val
+
+  def __readString(self):
+    len = self.__readSize()
+    return self.trans.readAll(len)
+  readString = reader(__readString)
+
+  def __getTType(self, byte):
+    return TTYPES[byte & 0x0f]
+
+
+class TCompactProtocolFactory:
+  def __init__(self):
+    pass
+
+  def getProtocol(self, trans):
+    return TCompactProtocol(trans)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
new file mode 100644
index 0000000..7d9d7aa
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
@@ -0,0 +1,552 @@
+#
+# 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.
+#
+
+import base64
+import json
+import math
+
+from TProtocol import TType, TProtocolBase, TProtocolException
+
+
+__all__ = ['TJSONProtocol',
+           'TJSONProtocolFactory',
+           'TSimpleJSONProtocol',
+           'TSimpleJSONProtocolFactory']
+
+VERSION = 1
+
+COMMA = ','
+COLON = ':'
+LBRACE = '{'
+RBRACE = '}'
+LBRACKET = '['
+RBRACKET = ']'
+QUOTE = '"'
+BACKSLASH = '\\'
+ZERO = '0'
+
+ESCSEQ = '\\u00'
+ESCAPE_CHAR = '"\\bfnrt'
+ESCAPE_CHAR_VALS = ['"', '\\', '\b', '\f', '\n', '\r', '\t']
+NUMERIC_CHAR = '+-.0123456789Ee'
+
+CTYPES = {TType.BOOL:       'tf',
+          TType.BYTE:       'i8',
+          TType.I16:        'i16',
+          TType.I32:        'i32',
+          TType.I64:        'i64',
+          TType.DOUBLE:     'dbl',
+          TType.STRING:     'str',
+          TType.STRUCT:     'rec',
+          TType.LIST:       'lst',
+          TType.SET:        'set',
+          TType.MAP:        'map'}
+
+JTYPES = {}
+for key in CTYPES.keys():
+  JTYPES[CTYPES[key]] = key
+
+
+class JSONBaseContext(object):
+
+  def __init__(self, protocol):
+    self.protocol = protocol
+    self.first = True
+
+  def doIO(self, function):
+    pass
+  
+  def write(self):
+    pass
+
+  def read(self):
+    pass
+
+  def escapeNum(self):
+    return False
+
+  def __str__(self):
+    return self.__class__.__name__
+
+
+class JSONListContext(JSONBaseContext):
+    
+  def doIO(self, function):
+    if self.first is True:
+      self.first = False
+    else:
+      function(COMMA)
+
+  def write(self):
+    self.doIO(self.protocol.trans.write)
+
+  def read(self):
+    self.doIO(self.protocol.readJSONSyntaxChar)
+
+
+class JSONPairContext(JSONBaseContext):
+  
+  def __init__(self, protocol):
+    super(JSONPairContext, self).__init__(protocol)
+    self.colon = True
+
+  def doIO(self, function):
+    if self.first:
+      self.first = False
+      self.colon = True
+    else:
+      function(COLON if self.colon else COMMA)
+      self.colon = not self.colon
+
+  def write(self):
+    self.doIO(self.protocol.trans.write)
+
+  def read(self):
+    self.doIO(self.protocol.readJSONSyntaxChar)
+
+  def escapeNum(self):
+    return self.colon
+
+  def __str__(self):
+    return '%s, colon=%s' % (self.__class__.__name__, self.colon)
+
+
+class LookaheadReader():
+  hasData = False
+  data = ''
+
+  def __init__(self, protocol):
+    self.protocol = protocol
+
+  def read(self):
+    if self.hasData is True:
+      self.hasData = False
+    else:
+      self.data = self.protocol.trans.read(1)
+    return self.data
+
+  def peek(self):
+    if self.hasData is False:
+      self.data = self.protocol.trans.read(1)
+    self.hasData = True
+    return self.data
+
+class TJSONProtocolBase(TProtocolBase):
+
+  def __init__(self, trans):
+    TProtocolBase.__init__(self, trans)
+    self.resetWriteContext()
+    self.resetReadContext()
+
+  def resetWriteContext(self):
+    self.context = JSONBaseContext(self)
+    self.contextStack = [self.context]
+
+  def resetReadContext(self):
+    self.resetWriteContext()
+    self.reader = LookaheadReader(self)
+
+  def pushContext(self, ctx):
+    self.contextStack.append(ctx)
+    self.context = ctx
+
+  def popContext(self):
+    self.contextStack.pop()
+    if self.contextStack:
+      self.context = self.contextStack[-1]
+    else:
+      self.context = JSONBaseContext(self)
+
+  def writeJSONString(self, string):
+    self.context.write()
+    self.trans.write(json.dumps(string))
+
+  def writeJSONNumber(self, number):
+    self.context.write()
+    jsNumber = str(number)
+    if self.context.escapeNum():
+      jsNumber = "%s%s%s" % (QUOTE, jsNumber,  QUOTE)
+    self.trans.write(jsNumber)
+
+  def writeJSONBase64(self, binary):
+    self.context.write()
+    self.trans.write(QUOTE)
+    self.trans.write(base64.b64encode(binary))
+    self.trans.write(QUOTE)
+
+  def writeJSONObjectStart(self):
+    self.context.write()
+    self.trans.write(LBRACE)
+    self.pushContext(JSONPairContext(self))
+
+  def writeJSONObjectEnd(self):
+    self.popContext()
+    self.trans.write(RBRACE)
+
+  def writeJSONArrayStart(self):
+    self.context.write()
+    self.trans.write(LBRACKET)
+    self.pushContext(JSONListContext(self))
+
+  def writeJSONArrayEnd(self):
+    self.popContext()
+    self.trans.write(RBRACKET)
+
+  def readJSONSyntaxChar(self, character):
+    current = self.reader.read()
+    if character != current:
+      raise TProtocolException(TProtocolException.INVALID_DATA,
+                               "Unexpected character: %s" % current)
+
+  def readJSONString(self, skipContext):
+    string = []
+    if skipContext is False:
+      self.context.read()
+    self.readJSONSyntaxChar(QUOTE)
+    while True:
+      character = self.reader.read()
+      if character == QUOTE:
+        break
+      if character == ESCSEQ[0]:
+        character = self.reader.read()
+        if character == ESCSEQ[1]:
+          self.readJSONSyntaxChar(ZERO)
+          self.readJSONSyntaxChar(ZERO)
+          character = json.JSONDecoder().decode('"\u00%s"' % self.trans.read(2))
+        else:
+          off = ESCAPE_CHAR.find(character)
+          if off == -1:
+            raise TProtocolException(TProtocolException.INVALID_DATA,
+                                     "Expected control char")
+          character = ESCAPE_CHAR_VALS[off]
+      string.append(character)
+    return ''.join(string)
+
+  def isJSONNumeric(self, character):
+    return (True if NUMERIC_CHAR.find(character) != - 1 else False)
+
+  def readJSONQuotes(self):
+    if (self.context.escapeNum()):
+      self.readJSONSyntaxChar(QUOTE)
+
+  def readJSONNumericChars(self):
+    numeric = []
+    while True:
+      character = self.reader.peek()
+      if self.isJSONNumeric(character) is False:
+        break
+      numeric.append(self.reader.read())
+    return ''.join(numeric)
+
+  def readJSONInteger(self):
+    self.context.read()
+    self.readJSONQuotes()
+    numeric = self.readJSONNumericChars()
+    self.readJSONQuotes()
+    try:
+      return int(numeric)
+    except ValueError:
+      raise TProtocolException(TProtocolException.INVALID_DATA,
+                               "Bad data encounted in numeric data")
+
+  def readJSONDouble(self):
+    self.context.read()
+    if self.reader.peek() == QUOTE:
+      string  = self.readJSONString(True)
+      try:
+        double = float(string)
+        if (self.context.escapeNum is False and
+            not math.isinf(double) and
+            not math.isnan(double)):
+          raise TProtocolException(TProtocolException.INVALID_DATA,
+                                   "Numeric data unexpectedly quoted")
+        return double
+      except ValueError:
+        raise TProtocolException(TProtocolException.INVALID_DATA,
+                                 "Bad data encounted in numeric data")
+    else:
+      if self.context.escapeNum() is True:
+        self.readJSONSyntaxChar(QUOTE)
+      try:
+        return float(self.readJSONNumericChars())
+      except ValueError:
+        raise TProtocolException(TProtocolException.INVALID_DATA,
+                                 "Bad data encounted in numeric data")
+
+  def readJSONBase64(self):
+    string = self.readJSONString(False)
+    return base64.b64decode(string)
+
+  def readJSONObjectStart(self):
+    self.context.read()
+    self.readJSONSyntaxChar(LBRACE)
+    self.pushContext(JSONPairContext(self))
+
+  def readJSONObjectEnd(self):
+    self.readJSONSyntaxChar(RBRACE)
+    self.popContext()
+
+  def readJSONArrayStart(self):
+    self.context.read()
+    self.readJSONSyntaxChar(LBRACKET)
+    self.pushContext(JSONListContext(self))
+
+  def readJSONArrayEnd(self):
+    self.readJSONSyntaxChar(RBRACKET)
+    self.popContext()
+
+
+class TJSONProtocol(TJSONProtocolBase):
+
+  def readMessageBegin(self):
+    self.resetReadContext()
+    self.readJSONArrayStart()
+    if self.readJSONInteger() != VERSION:
+      raise TProtocolException(TProtocolException.BAD_VERSION,
+                               "Message contained bad version.")
+    name = self.readJSONString(False)
+    typen = self.readJSONInteger()
+    seqid = self.readJSONInteger()
+    return (name, typen, seqid)
+
+  def readMessageEnd(self):
+    self.readJSONArrayEnd()
+
+  def readStructBegin(self):
+    self.readJSONObjectStart()
+
+  def readStructEnd(self):
+    self.readJSONObjectEnd()
+
+  def readFieldBegin(self):
+    character = self.reader.peek()
+    ttype = 0
+    id = 0
+    if character == RBRACE:
+      ttype = TType.STOP
+    else:
+      id = self.readJSONInteger()
+      self.readJSONObjectStart()
+      ttype = JTYPES[self.readJSONString(False)]
+    return (None, ttype, id)
+
+  def readFieldEnd(self):
+    self.readJSONObjectEnd()
+
+  def readMapBegin(self):
+    self.readJSONArrayStart()
+    keyType = JTYPES[self.readJSONString(False)]
+    valueType = JTYPES[self.readJSONString(False)]
+    size = self.readJSONInteger()
+    self.readJSONObjectStart()
+    return (keyType, valueType, size)
+
+  def readMapEnd(self):
+    self.readJSONObjectEnd()
+    self.readJSONArrayEnd()
+
+  def readCollectionBegin(self):
+    self.readJSONArrayStart()
+    elemType = JTYPES[self.readJSONString(False)]
+    size = self.readJSONInteger()
+    return (elemType, size)
+  readListBegin = readCollectionBegin
+  readSetBegin = readCollectionBegin
+
+  def readCollectionEnd(self):
+    self.readJSONArrayEnd()
+  readSetEnd = readCollectionEnd
+  readListEnd = readCollectionEnd
+
+  def readBool(self):
+    return (False if self.readJSONInteger() == 0 else True)
+
+  def readNumber(self):
+    return self.readJSONInteger()
+  readByte = readNumber
+  readI16 = readNumber
+  readI32 = readNumber
+  readI64 = readNumber
+
+  def readDouble(self):
+    return self.readJSONDouble()
+
+  def readString(self):
+    return self.readJSONString(False)
+
+  def readBinary(self):
+    return self.readJSONBase64()
+
+  def writeMessageBegin(self, name, request_type, seqid):
+    self.resetWriteContext()
+    self.writeJSONArrayStart()
+    self.writeJSONNumber(VERSION)
+    self.writeJSONString(name)
+    self.writeJSONNumber(request_type)
+    self.writeJSONNumber(seqid)
+
+  def writeMessageEnd(self):
+    self.writeJSONArrayEnd()
+
+  def writeStructBegin(self, name):
+    self.writeJSONObjectStart()
+
+  def writeStructEnd(self):
+    self.writeJSONObjectEnd()
+
+  def writeFieldBegin(self, name, ttype, id):
+    self.writeJSONNumber(id)
+    self.writeJSONObjectStart()
+    self.writeJSONString(CTYPES[ttype])
+
+  def writeFieldEnd(self):
+    self.writeJSONObjectEnd()
+
+  def writeFieldStop(self):
+    pass
+
+  def writeMapBegin(self, ktype, vtype, size):
+    self.writeJSONArrayStart()
+    self.writeJSONString(CTYPES[ktype])
+    self.writeJSONString(CTYPES[vtype])
+    self.writeJSONNumber(size)
+    self.writeJSONObjectStart()
+
+  def writeMapEnd(self):
+    self.writeJSONObjectEnd()
+    self.writeJSONArrayEnd()
+    
+  def writeListBegin(self, etype, size):
+    self.writeJSONArrayStart()
+    self.writeJSONString(CTYPES[etype])
+    self.writeJSONNumber(size)
+    
+  def writeListEnd(self):
+    self.writeJSONArrayEnd()
+
+  def writeSetBegin(self, etype, size):
+    self.writeJSONArrayStart()
+    self.writeJSONString(CTYPES[etype])
+    self.writeJSONNumber(size)
+    
+  def writeSetEnd(self):
+    self.writeJSONArrayEnd()
+
+  def writeBool(self, boolean):
+    self.writeJSONNumber(1 if boolean is True else 0)
+
+  def writeInteger(self, integer):
+    self.writeJSONNumber(integer)
+  writeByte = writeInteger
+  writeI16 = writeInteger
+  writeI32 = writeInteger
+  writeI64 = writeInteger
+
+  def writeDouble(self, dbl):
+    self.writeJSONNumber(dbl)
+
+  def writeString(self, string):
+    self.writeJSONString(string)
+    
+  def writeBinary(self, binary):
+    self.writeJSONBase64(binary)
+
+
+class TJSONProtocolFactory:
+
+  def getProtocol(self, trans):
+    return TJSONProtocol(trans)
+
+
+class TSimpleJSONProtocol(TJSONProtocolBase):
+    """Simple, readable, write-only JSON protocol.
+    
+    Useful for interacting with scripting languages.
+    """
+
+    def readMessageBegin(self):
+        raise NotImplementedError()
+    
+    def readMessageEnd(self):
+        raise NotImplementedError()
+    
+    def readStructBegin(self):
+        raise NotImplementedError()
+    
+    def readStructEnd(self):
+        raise NotImplementedError()
+    
+    def writeMessageBegin(self, name, request_type, seqid):
+        self.resetWriteContext()
+    
+    def writeMessageEnd(self):
+        pass
+    
+    def writeStructBegin(self, name):
+        self.writeJSONObjectStart()
+    
+    def writeStructEnd(self):
+        self.writeJSONObjectEnd()
+      
+    def writeFieldBegin(self, name, ttype, fid):
+        self.writeJSONString(name)
+    
+    def writeFieldEnd(self):
+        pass
+    
+    def writeMapBegin(self, ktype, vtype, size):
+        self.writeJSONObjectStart()
+    
+    def writeMapEnd(self):
+        self.writeJSONObjectEnd()
+    
+    def _writeCollectionBegin(self, etype, size):
+        self.writeJSONArrayStart()
+    
+    def _writeCollectionEnd(self):
+        self.writeJSONArrayEnd()
+    writeListBegin = _writeCollectionBegin
+    writeListEnd = _writeCollectionEnd
+    writeSetBegin = _writeCollectionBegin
+    writeSetEnd = _writeCollectionEnd
+
+    def writeInteger(self, integer):
+        self.writeJSONNumber(integer)
+    writeByte = writeInteger
+    writeI16 = writeInteger
+    writeI32 = writeInteger
+    writeI64 = writeInteger
+    
+    def writeBool(self, boolean):
+        self.writeJSONNumber(1 if boolean is True else 0)
+
+    def writeDouble(self, dbl):
+        self.writeJSONNumber(dbl)
+    
+    def writeString(self, string):
+        self.writeJSONString(string)
+      
+    def writeBinary(self, binary):
+        self.writeJSONBase64(binary)
+
+
+class TSimpleJSONProtocolFactory(object):
+
+    def getProtocol(self, trans):
+        return TSimpleJSONProtocol(trans)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py
new file mode 100644
index 0000000..0154641
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TProtocol.py
@@ -0,0 +1,406 @@
+#
+# 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.
+#
+
+from ..Thrift import *
+
+
+class TProtocolException(TException):
+  """Custom Protocol Exception class"""
+
+  UNKNOWN = 0
+  INVALID_DATA = 1
+  NEGATIVE_SIZE = 2
+  SIZE_LIMIT = 3
+  BAD_VERSION = 4
+
+  def __init__(self, type=UNKNOWN, message=None):
+    TException.__init__(self, message)
+    self.type = type
+
+
+class TProtocolBase:
+  """Base class for Thrift protocol driver."""
+
+  def __init__(self, trans):
+    self.trans = trans
+
+  def writeMessageBegin(self, name, ttype, seqid):
+    pass
+
+  def writeMessageEnd(self):
+    pass
+
+  def writeStructBegin(self, name):
+    pass
+
+  def writeStructEnd(self):
+    pass
+
+  def writeFieldBegin(self, name, ttype, fid):
+    pass
+
+  def writeFieldEnd(self):
+    pass
+
+  def writeFieldStop(self):
+    pass
+
+  def writeMapBegin(self, ktype, vtype, size):
+    pass
+
+  def writeMapEnd(self):
+    pass
+
+  def writeListBegin(self, etype, size):
+    pass
+
+  def writeListEnd(self):
+    pass
+
+  def writeSetBegin(self, etype, size):
+    pass
+
+  def writeSetEnd(self):
+    pass
+
+  def writeBool(self, bool_val):
+    pass
+
+  def writeByte(self, byte):
+    pass
+
+  def writeI16(self, i16):
+    pass
+
+  def writeI32(self, i32):
+    pass
+
+  def writeI64(self, i64):
+    pass
+
+  def writeDouble(self, dub):
+    pass
+
+  def writeString(self, str_val):
+    pass
+
+  def readMessageBegin(self):
+    pass
+
+  def readMessageEnd(self):
+    pass
+
+  def readStructBegin(self):
+    pass
+
+  def readStructEnd(self):
+    pass
+
+  def readFieldBegin(self):
+    pass
+
+  def readFieldEnd(self):
+    pass
+
+  def readMapBegin(self):
+    pass
+
+  def readMapEnd(self):
+    pass
+
+  def readListBegin(self):
+    pass
+
+  def readListEnd(self):
+    pass
+
+  def readSetBegin(self):
+    pass
+
+  def readSetEnd(self):
+    pass
+
+  def readBool(self):
+    pass
+
+  def readByte(self):
+    pass
+
+  def readI16(self):
+    pass
+
+  def readI32(self):
+    pass
+
+  def readI64(self):
+    pass
+
+  def readDouble(self):
+    pass
+
+  def readString(self):
+    pass
+
+  def skip(self, ttype):
+    if ttype == TType.STOP:
+      return
+    elif ttype == TType.BOOL:
+      self.readBool()
+    elif ttype == TType.BYTE:
+      self.readByte()
+    elif ttype == TType.I16:
+      self.readI16()
+    elif ttype == TType.I32:
+      self.readI32()
+    elif ttype == TType.I64:
+      self.readI64()
+    elif ttype == TType.DOUBLE:
+      self.readDouble()
+    elif ttype == TType.STRING:
+      self.readString()
+    elif ttype == TType.STRUCT:
+      name = self.readStructBegin()
+      while True:
+        (name, ttype, id) = self.readFieldBegin()
+        if ttype == TType.STOP:
+          break
+        self.skip(ttype)
+        self.readFieldEnd()
+      self.readStructEnd()
+    elif ttype == TType.MAP:
+      (ktype, vtype, size) = self.readMapBegin()
+      for i in xrange(size):
+        self.skip(ktype)
+        self.skip(vtype)
+      self.readMapEnd()
+    elif ttype == TType.SET:
+      (etype, size) = self.readSetBegin()
+      for i in xrange(size):
+        self.skip(etype)
+      self.readSetEnd()
+    elif ttype == TType.LIST:
+      (etype, size) = self.readListBegin()
+      for i in xrange(size):
+        self.skip(etype)
+      self.readListEnd()
+
+  # tuple of: ( 'reader method' name, is_container bool, 'writer_method' name )
+  _TTYPE_HANDLERS = (
+       (None, None, False),  # 0 TType.STOP
+       (None, None, False),  # 1 TType.VOID # TODO: handle void?
+       ('readBool', 'writeBool', False),  # 2 TType.BOOL
+       ('readByte',  'writeByte', False),  # 3 TType.BYTE and I08
+       ('readDouble', 'writeDouble', False),  # 4 TType.DOUBLE
+       (None, None, False),  # 5 undefined
+       ('readI16', 'writeI16', False),  # 6 TType.I16
+       (None, None, False),  # 7 undefined
+       ('readI32', 'writeI32', False),  # 8 TType.I32
+       (None, None, False),  # 9 undefined
+       ('readI64', 'writeI64', False),  # 10 TType.I64
+       ('readString', 'writeString', False),  # 11 TType.STRING and UTF7
+       ('readContainerStruct', 'writeContainerStruct', True),  # 12 *.STRUCT
+       ('readContainerMap', 'writeContainerMap', True),  # 13 TType.MAP
+       ('readContainerSet', 'writeContainerSet', True),  # 14 TType.SET
+       ('readContainerList', 'writeContainerList', True),  # 15 TType.LIST
+       (None, None, False),  # 16 TType.UTF8 # TODO: handle utf8 types?
+       (None, None, False)  # 17 TType.UTF16 # TODO: handle utf16 types?
+      )
+
+  def readFieldByTType(self, ttype, spec):
+    try:
+      (r_handler, w_handler, is_container) = self._TTYPE_HANDLERS[ttype]
+    except IndexError:
+      raise TProtocolException(type=TProtocolException.INVALID_DATA,
+                               message='Invalid field type %d' % (ttype))
+    if r_handler is None:
+      raise TProtocolException(type=TProtocolException.INVALID_DATA,
+                               message='Invalid field type %d' % (ttype))
+    reader = getattr(self, r_handler)
+    if not is_container:
+      return reader()
+    return reader(spec)
+
+  def readContainerList(self, spec):
+    results = []
+    ttype, tspec = spec[0], spec[1]
+    r_handler = self._TTYPE_HANDLERS[ttype][0]
+    reader = getattr(self, r_handler)
+    (list_type, list_len) = self.readListBegin()
+    if tspec is None:
+      # list values are simple types
+      for idx in xrange(list_len):
+        results.append(reader())
+    else:
+      # this is like an inlined readFieldByTType
+      container_reader = self._TTYPE_HANDLERS[list_type][0]
+      val_reader = getattr(self, container_reader)
+      for idx in xrange(list_len):
+        val = val_reader(tspec)
+        results.append(val)
+    self.readListEnd()
+    return results
+
+  def readContainerSet(self, spec):
+    results = set()
+    ttype, tspec = spec[0], spec[1]
+    r_handler = self._TTYPE_HANDLERS[ttype][0]
+    reader = getattr(self, r_handler)
+    (set_type, set_len) = self.readSetBegin()
+    if tspec is None:
+      # set members are simple types
+      for idx in xrange(set_len):
+        results.add(reader())
+    else:
+      container_reader = self._TTYPE_HANDLERS[set_type][0]
+      val_reader = getattr(self, container_reader)
+      for idx in xrange(set_len):
+        results.add(val_reader(tspec))
+    self.readSetEnd()
+    return results
+
+  def readContainerStruct(self, spec):
+    (obj_class, obj_spec) = spec
+    obj = obj_class()
+    obj.read(self)
+    return obj
+
+  def readContainerMap(self, spec):
+    results = dict()
+    key_ttype, key_spec = spec[0], spec[1]
+    val_ttype, val_spec = spec[2], spec[3]
+    (map_ktype, map_vtype, map_len) = self.readMapBegin()
+    # TODO: compare types we just decoded with thrift_spec and
+    # abort/skip if types disagree
+    key_reader = getattr(self, self._TTYPE_HANDLERS[key_ttype][0])
+    val_reader = getattr(self, self._TTYPE_HANDLERS[val_ttype][0])
+    # list values are simple types
+    for idx in xrange(map_len):
+      if key_spec is None:
+        k_val = key_reader()
+      else:
+        k_val = self.readFieldByTType(key_ttype, key_spec)
+      if val_spec is None:
+        v_val = val_reader()
+      else:
+        v_val = self.readFieldByTType(val_ttype, val_spec)
+      # this raises a TypeError with unhashable keys types
+      # i.e. this fails: d=dict(); d[[0,1]] = 2
+      results[k_val] = v_val
+    self.readMapEnd()
+    return results
+
+  def readStruct(self, obj, thrift_spec):
+    self.readStructBegin()
+    while True:
+      (fname, ftype, fid) = self.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      try:
+        field = thrift_spec[fid]
+      except IndexError:
+        self.skip(ftype)
+      else:
+        if field is not None and ftype == field[1]:
+          fname = field[2]
+          fspec = field[3]
+          val = self.readFieldByTType(ftype, fspec)
+          setattr(obj, fname, val)
+        else:
+          self.skip(ftype)
+      self.readFieldEnd()
+    self.readStructEnd()
+
+  def writeContainerStruct(self, val, spec):
+    val.write(self)
+
+  def writeContainerList(self, val, spec):
+    self.writeListBegin(spec[0], len(val))
+    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[spec[0]]
+    e_writer = getattr(self, w_handler)
+    if not is_container:
+      for elem in val:
+        e_writer(elem)
+    else:
+      for elem in val:
+        e_writer(elem, spec[1])
+    self.writeListEnd()
+
+  def writeContainerSet(self, val, spec):
+    self.writeSetBegin(spec[0], len(val))
+    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[spec[0]]
+    e_writer = getattr(self, w_handler)
+    if not is_container:
+      for elem in val:
+        e_writer(elem)
+    else:
+      for elem in val:
+        e_writer(elem, spec[1])
+    self.writeSetEnd()
+
+  def writeContainerMap(self, val, spec):
+    k_type = spec[0]
+    v_type = spec[2]
+    ignore, ktype_name, k_is_container = self._TTYPE_HANDLERS[k_type]
+    ignore, vtype_name, v_is_container = self._TTYPE_HANDLERS[v_type]
+    k_writer = getattr(self, ktype_name)
+    v_writer = getattr(self, vtype_name)
+    self.writeMapBegin(k_type, v_type, len(val))
+    for m_key, m_val in val.iteritems():
+      if not k_is_container:
+        k_writer(m_key)
+      else:
+        k_writer(m_key, spec[1])
+      if not v_is_container:
+        v_writer(m_val)
+      else:
+        v_writer(m_val, spec[3])
+    self.writeMapEnd()
+
+  def writeStruct(self, obj, thrift_spec):
+    self.writeStructBegin(obj.__class__.__name__)
+    for field in thrift_spec:
+      if field is None:
+        continue
+      fname = field[2]
+      val = getattr(obj, fname)
+      if val is None:
+        # skip writing out unset fields
+        continue
+      fid = field[0]
+      ftype = field[1]
+      fspec = field[3]
+      # get the writer method for this value
+      self.writeFieldBegin(fname, ftype, fid)
+      self.writeFieldByTType(ftype, val, fspec)
+      self.writeFieldEnd()
+    self.writeFieldStop()
+    self.writeStructEnd()
+
+  def writeFieldByTType(self, ttype, val, spec):
+    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[ttype]
+    writer = getattr(self, w_handler)
+    if is_container:
+      writer(val, spec)
+    else:
+      writer(val)
+
+
+class TProtocolFactory:
+  def getProtocol(self, trans):
+    pass

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py
new file mode 100644
index 0000000..7eefb45
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/__init__.py
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+__all__ = ['fastbinary', 'TBase', 'TBinaryProtocol', 'TCompactProtocol', 'TJSONProtocol', 'TProtocol']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c
new file mode 100644
index 0000000..2ce5660
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/fastbinary.c
@@ -0,0 +1,1219 @@
+/*
+ * 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.
+ */
+
+#include <Python.h>
+#include "cStringIO.h"
+#include <stdint.h>
+#ifndef _WIN32
+# include <stdbool.h>
+# include <netinet/in.h>
+#else
+# include <WinSock2.h>
+# pragma comment (lib, "ws2_32.lib")
+# define BIG_ENDIAN (4321)
+# define LITTLE_ENDIAN (1234)
+# define BYTE_ORDER LITTLE_ENDIAN
+# if defined(_MSC_VER) && _MSC_VER < 1600
+   typedef int _Bool;
+#  define bool _Bool
+#  define false 0 
+#  define true 1
+# endif
+# define inline __inline
+#endif
+
+/* Fix endianness issues on Solaris */
+#if defined (__SVR4) && defined (__sun)
+ #if defined(__i386) && !defined(__i386__)
+  #define __i386__
+ #endif
+
+ #ifndef BIG_ENDIAN
+  #define BIG_ENDIAN (4321)
+ #endif
+ #ifndef LITTLE_ENDIAN
+  #define LITTLE_ENDIAN (1234)
+ #endif
+
+ /* I386 is LE, even on Solaris */
+ #if !defined(BYTE_ORDER) && defined(__i386__)
+  #define BYTE_ORDER LITTLE_ENDIAN
+ #endif
+#endif
+
+// TODO(dreiss): defval appears to be unused.  Look into removing it.
+// TODO(dreiss): Make parse_spec_args recursive, and cache the output
+//               permanently in the object.  (Malloc and orphan.)
+// TODO(dreiss): Why do we need cStringIO for reading, why not just char*?
+//               Can cStringIO let us work with a BufferedTransport?
+// TODO(dreiss): Don't ignore the rv from cwrite (maybe).
+
+/* ====== BEGIN UTILITIES ====== */
+
+#define INIT_OUTBUF_SIZE 128
+
+// Stolen out of TProtocol.h.
+// It would be a huge pain to have both get this from one place.
+typedef enum TType {
+  T_STOP       = 0,
+  T_VOID       = 1,
+  T_BOOL       = 2,
+  T_BYTE       = 3,
+  T_I08        = 3,
+  T_I16        = 6,
+  T_I32        = 8,
+  T_U64        = 9,
+  T_I64        = 10,
+  T_DOUBLE     = 4,
+  T_STRING     = 11,
+  T_UTF7       = 11,
+  T_STRUCT     = 12,
+  T_MAP        = 13,
+  T_SET        = 14,
+  T_LIST       = 15,
+  T_UTF8       = 16,
+  T_UTF16      = 17
+} TType;
+
+#ifndef __BYTE_ORDER
+# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
+#  define __BYTE_ORDER BYTE_ORDER
+#  define __LITTLE_ENDIAN LITTLE_ENDIAN
+#  define __BIG_ENDIAN BIG_ENDIAN
+# else
+#  error "Cannot determine endianness"
+# endif
+#endif
+
+// Same comment as the enum.  Sorry.
+#if __BYTE_ORDER == __BIG_ENDIAN
+# define ntohll(n) (n)
+# define htonll(n) (n)
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+# if defined(__GNUC__) && defined(__GLIBC__)
+#  include <byteswap.h>
+#  define ntohll(n) bswap_64(n)
+#  define htonll(n) bswap_64(n)
+# else /* GNUC & GLIBC */
+#  define ntohll(n) ( (((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32) )
+#  define htonll(n) ( (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32) )
+# endif /* GNUC & GLIBC */
+#else /* __BYTE_ORDER */
+# error "Can't define htonll or ntohll!"
+#endif
+
+// Doing a benchmark shows that interning actually makes a difference, amazingly.
+#define INTERN_STRING(value) _intern_ ## value
+
+#define INT_CONV_ERROR_OCCURRED(v) ( ((v) == -1) && PyErr_Occurred() )
+#define CHECK_RANGE(v, min, max) ( ((v) <= (max)) && ((v) >= (min)) )
+
+// Py_ssize_t was not defined before Python 2.5
+#if (PY_VERSION_HEX < 0x02050000)
+typedef int Py_ssize_t;
+#endif
+
+/**
+ * A cache of the spec_args for a set or list,
+ * so we don't have to keep calling PyTuple_GET_ITEM.
+ */
+typedef struct {
+  TType element_type;
+  PyObject* typeargs;
+} SetListTypeArgs;
+
+/**
+ * A cache of the spec_args for a map,
+ * so we don't have to keep calling PyTuple_GET_ITEM.
+ */
+typedef struct {
+  TType ktag;
+  TType vtag;
+  PyObject* ktypeargs;
+  PyObject* vtypeargs;
+} MapTypeArgs;
+
+/**
+ * A cache of the spec_args for a struct,
+ * so we don't have to keep calling PyTuple_GET_ITEM.
+ */
+typedef struct {
+  PyObject* klass;
+  PyObject* spec;
+} StructTypeArgs;
+
+/**
+ * A cache of the item spec from a struct specification,
+ * so we don't have to keep calling PyTuple_GET_ITEM.
+ */
+typedef struct {
+  int tag;
+  TType type;
+  PyObject* attrname;
+  PyObject* typeargs;
+  PyObject* defval;
+} StructItemSpec;
+
+/**
+ * A cache of the two key attributes of a CReadableTransport,
+ * so we don't have to keep calling PyObject_GetAttr.
+ */
+typedef struct {
+  PyObject* stringiobuf;
+  PyObject* refill_callable;
+} DecodeBuffer;
+
+/** Pointer to interned string to speed up attribute lookup. */
+static PyObject* INTERN_STRING(cstringio_buf);
+/** Pointer to interned string to speed up attribute lookup. */
+static PyObject* INTERN_STRING(cstringio_refill);
+
+static inline bool
+check_ssize_t_32(Py_ssize_t len) {
+  // error from getting the int
+  if (INT_CONV_ERROR_OCCURRED(len)) {
+    return false;
+  }
+  if (!CHECK_RANGE(len, 0, INT32_MAX)) {
+    PyErr_SetString(PyExc_OverflowError, "string size out of range");
+    return false;
+  }
+  return true;
+}
+
+static inline bool
+parse_pyint(PyObject* o, int32_t* ret, int32_t min, int32_t max) {
+  long val = PyInt_AsLong(o);
+
+  if (INT_CONV_ERROR_OCCURRED(val)) {
+    return false;
+  }
+  if (!CHECK_RANGE(val, min, max)) {
+    PyErr_SetString(PyExc_OverflowError, "int out of range");
+    return false;
+  }
+
+  *ret = (int32_t) val;
+  return true;
+}
+
+
+/* --- FUNCTIONS TO PARSE STRUCT SPECIFICATOINS --- */
+
+static bool
+parse_set_list_args(SetListTypeArgs* dest, PyObject* typeargs) {
+  if (PyTuple_Size(typeargs) != 2) {
+    PyErr_SetString(PyExc_TypeError, "expecting tuple of size 2 for list/set type args");
+    return false;
+  }
+
+  dest->element_type = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 0));
+  if (INT_CONV_ERROR_OCCURRED(dest->element_type)) {
+    return false;
+  }
+
+  dest->typeargs = PyTuple_GET_ITEM(typeargs, 1);
+
+  return true;
+}
+
+static bool
+parse_map_args(MapTypeArgs* dest, PyObject* typeargs) {
+  if (PyTuple_Size(typeargs) != 4) {
+    PyErr_SetString(PyExc_TypeError, "expecting 4 arguments for typeargs to map");
+    return false;
+  }
+
+  dest->ktag = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 0));
+  if (INT_CONV_ERROR_OCCURRED(dest->ktag)) {
+    return false;
+  }
+
+  dest->vtag = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 2));
+  if (INT_CONV_ERROR_OCCURRED(dest->vtag)) {
+    return false;
+  }
+
+  dest->ktypeargs = PyTuple_GET_ITEM(typeargs, 1);
+  dest->vtypeargs = PyTuple_GET_ITEM(typeargs, 3);
+
+  return true;
+}
+
+static bool
+parse_struct_args(StructTypeArgs* dest, PyObject* typeargs) {
+  if (PyTuple_Size(typeargs) != 2) {
+    PyErr_SetString(PyExc_TypeError, "expecting tuple of size 2 for struct args");
+    return false;
+  }
+
+  dest->klass = PyTuple_GET_ITEM(typeargs, 0);
+  dest->spec = PyTuple_GET_ITEM(typeargs, 1);
+
+  return true;
+}
+
+static int
+parse_struct_item_spec(StructItemSpec* dest, PyObject* spec_tuple) {
+
+  // i'd like to use ParseArgs here, but it seems to be a bottleneck.
+  if (PyTuple_Size(spec_tuple) != 5) {
+    PyErr_SetString(PyExc_TypeError, "expecting 5 arguments for spec tuple");
+    return false;
+  }
+
+  dest->tag = PyInt_AsLong(PyTuple_GET_ITEM(spec_tuple, 0));
+  if (INT_CONV_ERROR_OCCURRED(dest->tag)) {
+    return false;
+  }
+
+  dest->type = PyInt_AsLong(PyTuple_GET_ITEM(spec_tuple, 1));
+  if (INT_CONV_ERROR_OCCURRED(dest->type)) {
+    return false;
+  }
+
+  dest->attrname = PyTuple_GET_ITEM(spec_tuple, 2);
+  dest->typeargs = PyTuple_GET_ITEM(spec_tuple, 3);
+  dest->defval = PyTuple_GET_ITEM(spec_tuple, 4);
+  return true;
+}
+
+/* ====== END UTILITIES ====== */
+
+
+/* ====== BEGIN WRITING FUNCTIONS ====== */
+
+/* --- LOW-LEVEL WRITING FUNCTIONS --- */
+
+static void writeByte(PyObject* outbuf, int8_t val) {
+  int8_t net = val;
+  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int8_t));
+}
+
+static void writeI16(PyObject* outbuf, int16_t val) {
+  int16_t net = (int16_t)htons(val);
+  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int16_t));
+}
+
+static void writeI32(PyObject* outbuf, int32_t val) {
+  int32_t net = (int32_t)htonl(val);
+  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int32_t));
+}
+
+static void writeI64(PyObject* outbuf, int64_t val) {
+  int64_t net = (int64_t)htonll(val);
+  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int64_t));
+}
+
+static void writeDouble(PyObject* outbuf, double dub) {
+  // Unfortunately, bitwise_cast doesn't work in C.  Bad C!
+  union {
+    double f;
+    int64_t t;
+  } transfer;
+  transfer.f = dub;
+  writeI64(outbuf, transfer.t);
+}
+
+
+/* --- MAIN RECURSIVE OUTPUT FUCNTION -- */
+
+static int
+output_val(PyObject* output, PyObject* value, TType type, PyObject* typeargs) {
+  /*
+   * Refcounting Strategy:
+   *
+   * We assume that elements of the thrift_spec tuple are not going to be
+   * mutated, so we don't ref count those at all. Other than that, we try to
+   * keep a reference to all the user-created objects while we work with them.
+   * output_val assumes that a reference is already held. The *caller* is
+   * responsible for handling references
+   */
+
+  switch (type) {
+
+  case T_BOOL: {
+    int v = PyObject_IsTrue(value);
+    if (v == -1) {
+      return false;
+    }
+
+    writeByte(output, (int8_t) v);
+    break;
+  }
+  case T_I08: {
+    int32_t val;
+
+    if (!parse_pyint(value, &val, INT8_MIN, INT8_MAX)) {
+      return false;
+    }
+
+    writeByte(output, (int8_t) val);
+    break;
+  }
+  case T_I16: {
+    int32_t val;
+
+    if (!parse_pyint(value, &val, INT16_MIN, INT16_MAX)) {
+      return false;
+    }
+
+    writeI16(output, (int16_t) val);
+    break;
+  }
+  case T_I32: {
+    int32_t val;
+
+    if (!parse_pyint(value, &val, INT32_MIN, INT32_MAX)) {
+      return false;
+    }
+
+    writeI32(output, val);
+    break;
+  }
+  case T_I64: {
+    int64_t nval = PyLong_AsLongLong(value);
+
+    if (INT_CONV_ERROR_OCCURRED(nval)) {
+      return false;
+    }
+
+    if (!CHECK_RANGE(nval, INT64_MIN, INT64_MAX)) {
+      PyErr_SetString(PyExc_OverflowError, "int out of range");
+      return false;
+    }
+
+    writeI64(output, nval);
+    break;
+  }
+
+  case T_DOUBLE: {
+    double nval = PyFloat_AsDouble(value);
+    if (nval == -1.0 && PyErr_Occurred()) {
+      return false;
+    }
+
+    writeDouble(output, nval);
+    break;
+  }
+
+  case T_STRING: {
+    Py_ssize_t len = PyString_Size(value);
+
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    writeI32(output, (int32_t) len);
+    PycStringIO->cwrite(output, PyString_AsString(value), (int32_t) len);
+    break;
+  }
+
+  case T_LIST:
+  case T_SET: {
+    Py_ssize_t len;
+    SetListTypeArgs parsedargs;
+    PyObject *item;
+    PyObject *iterator;
+
+    if (!parse_set_list_args(&parsedargs, typeargs)) {
+      return false;
+    }
+
+    len = PyObject_Length(value);
+
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    writeByte(output, parsedargs.element_type);
+    writeI32(output, (int32_t) len);
+
+    iterator =  PyObject_GetIter(value);
+    if (iterator == NULL) {
+      return false;
+    }
+
+    while ((item = PyIter_Next(iterator))) {
+      if (!output_val(output, item, parsedargs.element_type, parsedargs.typeargs)) {
+        Py_DECREF(item);
+        Py_DECREF(iterator);
+        return false;
+      }
+      Py_DECREF(item);
+    }
+
+    Py_DECREF(iterator);
+
+    if (PyErr_Occurred()) {
+      return false;
+    }
+
+    break;
+  }
+
+  case T_MAP: {
+    PyObject *k, *v;
+    Py_ssize_t pos = 0;
+    Py_ssize_t len;
+
+    MapTypeArgs parsedargs;
+
+    len = PyDict_Size(value);
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    if (!parse_map_args(&parsedargs, typeargs)) {
+      return false;
+    }
+
+    writeByte(output, parsedargs.ktag);
+    writeByte(output, parsedargs.vtag);
+    writeI32(output, len);
+
+    // TODO(bmaurer): should support any mapping, not just dicts
+    while (PyDict_Next(value, &pos, &k, &v)) {
+      // TODO(dreiss): Think hard about whether these INCREFs actually
+      //               turn any unsafe scenarios into safe scenarios.
+      Py_INCREF(k);
+      Py_INCREF(v);
+
+      if (!output_val(output, k, parsedargs.ktag, parsedargs.ktypeargs)
+          || !output_val(output, v, parsedargs.vtag, parsedargs.vtypeargs)) {
+        Py_DECREF(k);
+        Py_DECREF(v);
+        return false;
+      }
+      Py_DECREF(k);
+      Py_DECREF(v);
+    }
+    break;
+  }
+
+  // TODO(dreiss): Consider breaking this out as a function
+  //               the way we did for decode_struct.
+  case T_STRUCT: {
+    StructTypeArgs parsedargs;
+    Py_ssize_t nspec;
+    Py_ssize_t i;
+
+    if (!parse_struct_args(&parsedargs, typeargs)) {
+      return false;
+    }
+
+    nspec = PyTuple_Size(parsedargs.spec);
+
+    if (nspec == -1) {
+      return false;
+    }
+
+    for (i = 0; i < nspec; i++) {
+      StructItemSpec parsedspec;
+      PyObject* spec_tuple;
+      PyObject* instval = NULL;
+
+      spec_tuple = PyTuple_GET_ITEM(parsedargs.spec, i);
+      if (spec_tuple == Py_None) {
+        continue;
+      }
+
+      if (!parse_struct_item_spec (&parsedspec, spec_tuple)) {
+        return false;
+      }
+
+      instval = PyObject_GetAttr(value, parsedspec.attrname);
+
+      if (!instval) {
+        return false;
+      }
+
+      if (instval == Py_None) {
+        Py_DECREF(instval);
+        continue;
+      }
+
+      writeByte(output, (int8_t) parsedspec.type);
+      writeI16(output, parsedspec.tag);
+
+      if (!output_val(output, instval, parsedspec.type, parsedspec.typeargs)) {
+        Py_DECREF(instval);
+        return false;
+      }
+
+      Py_DECREF(instval);
+    }
+
+    writeByte(output, (int8_t)T_STOP);
+    break;
+  }
+
+  case T_STOP:
+  case T_VOID:
+  case T_UTF16:
+  case T_UTF8:
+  case T_U64:
+  default:
+    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
+    return false;
+
+  }
+
+  return true;
+}
+
+
+/* --- TOP-LEVEL WRAPPER FOR OUTPUT -- */
+
+static PyObject *
+encode_binary(PyObject *self, PyObject *args) {
+  PyObject* enc_obj;
+  PyObject* type_args;
+  PyObject* buf;
+  PyObject* ret = NULL;
+
+  if (!PyArg_ParseTuple(args, "OO", &enc_obj, &type_args)) {
+    return NULL;
+  }
+
+  buf = PycStringIO->NewOutput(INIT_OUTBUF_SIZE);
+  if (output_val(buf, enc_obj, T_STRUCT, type_args)) {
+    ret = PycStringIO->cgetvalue(buf);
+  }
+
+  Py_DECREF(buf);
+  return ret;
+}
+
+/* ====== END WRITING FUNCTIONS ====== */
+
+
+/* ====== BEGIN READING FUNCTIONS ====== */
+
+/* --- LOW-LEVEL READING FUNCTIONS --- */
+
+static void
+free_decodebuf(DecodeBuffer* d) {
+  Py_XDECREF(d->stringiobuf);
+  Py_XDECREF(d->refill_callable);
+}
+
+static bool
+decode_buffer_from_obj(DecodeBuffer* dest, PyObject* obj) {
+  dest->stringiobuf = PyObject_GetAttr(obj, INTERN_STRING(cstringio_buf));
+  if (!dest->stringiobuf) {
+    return false;
+  }
+
+  if (!PycStringIO_InputCheck(dest->stringiobuf)) {
+    free_decodebuf(dest);
+    PyErr_SetString(PyExc_TypeError, "expecting stringio input");
+    return false;
+  }
+
+  dest->refill_callable = PyObject_GetAttr(obj, INTERN_STRING(cstringio_refill));
+
+  if(!dest->refill_callable) {
+    free_decodebuf(dest);
+    return false;
+  }
+
+  if (!PyCallable_Check(dest->refill_callable)) {
+    free_decodebuf(dest);
+    PyErr_SetString(PyExc_TypeError, "expecting callable");
+    return false;
+  }
+
+  return true;
+}
+
+static bool readBytes(DecodeBuffer* input, char** output, int len) {
+  int read;
+
+  // TODO(dreiss): Don't fear the malloc.  Think about taking a copy of
+  //               the partial read instead of forcing the transport
+  //               to prepend it to its buffer.
+
+  read = PycStringIO->cread(input->stringiobuf, output, len);
+
+  if (read == len) {
+    return true;
+  } else if (read == -1) {
+    return false;
+  } else {
+    PyObject* newiobuf;
+
+    // using building functions as this is a rare codepath
+    newiobuf = PyObject_CallFunction(
+        input->refill_callable, "s#i", *output, read, len, NULL);
+    if (newiobuf == NULL) {
+      return false;
+    }
+
+    // must do this *AFTER* the call so that we don't deref the io buffer
+    Py_CLEAR(input->stringiobuf);
+    input->stringiobuf = newiobuf;
+
+    read = PycStringIO->cread(input->stringiobuf, output, len);
+
+    if (read == len) {
+      return true;
+    } else if (read == -1) {
+      return false;
+    } else {
+      // TODO(dreiss): This could be a valid code path for big binary blobs.
+      PyErr_SetString(PyExc_TypeError,
+          "refill claimed to have refilled the buffer, but didn't!!");
+      return false;
+    }
+  }
+}
+
+static int8_t readByte(DecodeBuffer* input) {
+  char* buf;
+  if (!readBytes(input, &buf, sizeof(int8_t))) {
+    return -1;
+  }
+
+  return *(int8_t*) buf;
+}
+
+static int16_t readI16(DecodeBuffer* input) {
+  char* buf;
+  if (!readBytes(input, &buf, sizeof(int16_t))) {
+    return -1;
+  }
+
+  return (int16_t) ntohs(*(int16_t*) buf);
+}
+
+static int32_t readI32(DecodeBuffer* input) {
+  char* buf;
+  if (!readBytes(input, &buf, sizeof(int32_t))) {
+    return -1;
+  }
+  return (int32_t) ntohl(*(int32_t*) buf);
+}
+
+
+static int64_t readI64(DecodeBuffer* input) {
+  char* buf;
+  if (!readBytes(input, &buf, sizeof(int64_t))) {
+    return -1;
+  }
+
+  return (int64_t) ntohll(*(int64_t*) buf);
+}
+
+static double readDouble(DecodeBuffer* input) {
+  union {
+    int64_t f;
+    double t;
+  } transfer;
+
+  transfer.f = readI64(input);
+  if (transfer.f == -1) {
+    return -1;
+  }
+  return transfer.t;
+}
+
+static bool
+checkTypeByte(DecodeBuffer* input, TType expected) {
+  TType got = readByte(input);
+  if (INT_CONV_ERROR_OCCURRED(got)) {
+    return false;
+  }
+
+  if (expected != got) {
+    PyErr_SetString(PyExc_TypeError, "got wrong ttype while reading field");
+    return false;
+  }
+  return true;
+}
+
+static bool
+skip(DecodeBuffer* input, TType type) {
+#define SKIPBYTES(n) \
+  do { \
+    if (!readBytes(input, &dummy_buf, (n))) { \
+      return false; \
+    } \
+  } while(0)
+
+  char* dummy_buf;
+
+  switch (type) {
+
+  case T_BOOL:
+  case T_I08: SKIPBYTES(1); break;
+  case T_I16: SKIPBYTES(2); break;
+  case T_I32: SKIPBYTES(4); break;
+  case T_I64:
+  case T_DOUBLE: SKIPBYTES(8); break;
+
+  case T_STRING: {
+    // TODO(dreiss): Find out if these check_ssize_t32s are really necessary.
+    int len = readI32(input);
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+    SKIPBYTES(len);
+    break;
+  }
+
+  case T_LIST:
+  case T_SET: {
+    TType etype;
+    int len, i;
+
+    etype = readByte(input);
+    if (etype == -1) {
+      return false;
+    }
+
+    len = readI32(input);
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    for (i = 0; i < len; i++) {
+      if (!skip(input, etype)) {
+        return false;
+      }
+    }
+    break;
+  }
+
+  case T_MAP: {
+    TType ktype, vtype;
+    int len, i;
+
+    ktype = readByte(input);
+    if (ktype == -1) {
+      return false;
+    }
+
+    vtype = readByte(input);
+    if (vtype == -1) {
+      return false;
+    }
+
+    len = readI32(input);
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    for (i = 0; i < len; i++) {
+      if (!(skip(input, ktype) && skip(input, vtype))) {
+        return false;
+      }
+    }
+    break;
+  }
+
+  case T_STRUCT: {
+    while (true) {
+      TType type;
+
+      type = readByte(input);
+      if (type == -1) {
+        return false;
+      }
+
+      if (type == T_STOP)
+        break;
+
+      SKIPBYTES(2); // tag
+      if (!skip(input, type)) {
+        return false;
+      }
+    }
+    break;
+  }
+
+  case T_STOP:
+  case T_VOID:
+  case T_UTF16:
+  case T_UTF8:
+  case T_U64:
+  default:
+    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
+    return false;
+
+  }
+
+  return true;
+
+#undef SKIPBYTES
+}
+
+
+/* --- HELPER FUNCTION FOR DECODE_VAL --- */
+
+static PyObject*
+decode_val(DecodeBuffer* input, TType type, PyObject* typeargs);
+
+static bool
+decode_struct(DecodeBuffer* input, PyObject* output, PyObject* spec_seq) {
+  int spec_seq_len = PyTuple_Size(spec_seq);
+  if (spec_seq_len == -1) {
+    return false;
+  }
+
+  while (true) {
+    TType type;
+    int16_t tag;
+    PyObject* item_spec;
+    PyObject* fieldval = NULL;
+    StructItemSpec parsedspec;
+
+    type = readByte(input);
+    if (type == -1) {
+      return false;
+    }
+    if (type == T_STOP) {
+      break;
+    }
+    tag = readI16(input);
+    if (INT_CONV_ERROR_OCCURRED(tag)) {
+      return false;
+    }
+    if (tag >= 0 && tag < spec_seq_len) {
+      item_spec = PyTuple_GET_ITEM(spec_seq, tag);
+    } else {
+      item_spec = Py_None;
+    }
+
+    if (item_spec == Py_None) {
+      if (!skip(input, type)) {
+        return false;
+      } else {
+        continue;
+      }
+    }
+
+    if (!parse_struct_item_spec(&parsedspec, item_spec)) {
+      return false;
+    }
+    if (parsedspec.type != type) {
+      if (!skip(input, type)) {
+        PyErr_SetString(PyExc_TypeError, "struct field had wrong type while reading and can't be skipped");
+        return false;
+      } else {
+        continue;
+      }
+    }
+
+    fieldval = decode_val(input, parsedspec.type, parsedspec.typeargs);
+    if (fieldval == NULL) {
+      return false;
+    }
+
+    if (PyObject_SetAttr(output, parsedspec.attrname, fieldval) == -1) {
+      Py_DECREF(fieldval);
+      return false;
+    }
+    Py_DECREF(fieldval);
+  }
+  return true;
+}
+
+
+/* --- MAIN RECURSIVE INPUT FUCNTION --- */
+
+// Returns a new reference.
+static PyObject*
+decode_val(DecodeBuffer* input, TType type, PyObject* typeargs) {
+  switch (type) {
+
+  case T_BOOL: {
+    int8_t v = readByte(input);
+    if (INT_CONV_ERROR_OCCURRED(v)) {
+      return NULL;
+    }
+
+    switch (v) {
+    case 0: Py_RETURN_FALSE;
+    case 1: Py_RETURN_TRUE;
+    // Don't laugh.  This is a potentially serious issue.
+    default: PyErr_SetString(PyExc_TypeError, "boolean out of range"); return NULL;
+    }
+    break;
+  }
+  case T_I08: {
+    int8_t v = readByte(input);
+    if (INT_CONV_ERROR_OCCURRED(v)) {
+      return NULL;
+    }
+
+    return PyInt_FromLong(v);
+  }
+  case T_I16: {
+    int16_t v = readI16(input);
+    if (INT_CONV_ERROR_OCCURRED(v)) {
+      return NULL;
+    }
+    return PyInt_FromLong(v);
+  }
+  case T_I32: {
+    int32_t v = readI32(input);
+    if (INT_CONV_ERROR_OCCURRED(v)) {
+      return NULL;
+    }
+    return PyInt_FromLong(v);
+  }
+
+  case T_I64: {
+    int64_t v = readI64(input);
+    if (INT_CONV_ERROR_OCCURRED(v)) {
+      return NULL;
+    }
+    // TODO(dreiss): Find out if we can take this fastpath always when
+    //               sizeof(long) == sizeof(long long).
+    if (CHECK_RANGE(v, LONG_MIN, LONG_MAX)) {
+      return PyInt_FromLong((long) v);
+    }
+
+    return PyLong_FromLongLong(v);
+  }
+
+  case T_DOUBLE: {
+    double v = readDouble(input);
+    if (v == -1.0 && PyErr_Occurred()) {
+      return false;
+    }
+    return PyFloat_FromDouble(v);
+  }
+
+  case T_STRING: {
+    Py_ssize_t len = readI32(input);
+    char* buf;
+    if (!readBytes(input, &buf, len)) {
+      return NULL;
+    }
+
+    return PyString_FromStringAndSize(buf, len);
+  }
+
+  case T_LIST:
+  case T_SET: {
+    SetListTypeArgs parsedargs;
+    int32_t len;
+    PyObject* ret = NULL;
+    int i;
+
+    if (!parse_set_list_args(&parsedargs, typeargs)) {
+      return NULL;
+    }
+
+    if (!checkTypeByte(input, parsedargs.element_type)) {
+      return NULL;
+    }
+
+    len = readI32(input);
+    if (!check_ssize_t_32(len)) {
+      return NULL;
+    }
+
+    ret = PyList_New(len);
+    if (!ret) {
+      return NULL;
+    }
+
+    for (i = 0; i < len; i++) {
+      PyObject* item = decode_val(input, parsedargs.element_type, parsedargs.typeargs);
+      if (!item) {
+        Py_DECREF(ret);
+        return NULL;
+      }
+      PyList_SET_ITEM(ret, i, item);
+    }
+
+    // TODO(dreiss): Consider biting the bullet and making two separate cases
+    //               for list and set, avoiding this post facto conversion.
+    if (type == T_SET) {
+      PyObject* setret;
+#if (PY_VERSION_HEX < 0x02050000)
+      // hack needed for older versions
+      setret = PyObject_CallFunctionObjArgs((PyObject*)&PySet_Type, ret, NULL);
+#else
+      // official version
+      setret = PySet_New(ret);
+#endif
+      Py_DECREF(ret);
+      return setret;
+    }
+    return ret;
+  }
+
+  case T_MAP: {
+    int32_t len;
+    int i;
+    MapTypeArgs parsedargs;
+    PyObject* ret = NULL;
+
+    if (!parse_map_args(&parsedargs, typeargs)) {
+      return NULL;
+    }
+
+    if (!checkTypeByte(input, parsedargs.ktag)) {
+      return NULL;
+    }
+    if (!checkTypeByte(input, parsedargs.vtag)) {
+      return NULL;
+    }
+
+    len = readI32(input);
+    if (!check_ssize_t_32(len)) {
+      return false;
+    }
+
+    ret = PyDict_New();
+    if (!ret) {
+      goto error;
+    }
+
+    for (i = 0; i < len; i++) {
+      PyObject* k = NULL;
+      PyObject* v = NULL;
+      k = decode_val(input, parsedargs.ktag, parsedargs.ktypeargs);
+      if (k == NULL) {
+        goto loop_error;
+      }
+      v = decode_val(input, parsedargs.vtag, parsedargs.vtypeargs);
+      if (v == NULL) {
+        goto loop_error;
+      }
+      if (PyDict_SetItem(ret, k, v) == -1) {
+        goto loop_error;
+      }
+
+      Py_DECREF(k);
+      Py_DECREF(v);
+      continue;
+
+      // Yuck!  Destructors, anyone?
+      loop_error:
+      Py_XDECREF(k);
+      Py_XDECREF(v);
+      goto error;
+    }
+
+    return ret;
+
+    error:
+    Py_XDECREF(ret);
+    return NULL;
+  }
+
+  case T_STRUCT: {
+    StructTypeArgs parsedargs;
+	PyObject* ret;
+    if (!parse_struct_args(&parsedargs, typeargs)) {
+      return NULL;
+    }
+
+    ret = PyObject_CallObject(parsedargs.klass, NULL);
+    if (!ret) {
+      return NULL;
+    }
+
+    if (!decode_struct(input, ret, parsedargs.spec)) {
+      Py_DECREF(ret);
+      return NULL;
+    }
+
+    return ret;
+  }
+
+  case T_STOP:
+  case T_VOID:
+  case T_UTF16:
+  case T_UTF8:
+  case T_U64:
+  default:
+    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
+    return NULL;
+  }
+}
+
+
+/* --- TOP-LEVEL WRAPPER FOR INPUT -- */
+
+static PyObject*
+decode_binary(PyObject *self, PyObject *args) {
+  PyObject* output_obj = NULL;
+  PyObject* transport = NULL;
+  PyObject* typeargs = NULL;
+  StructTypeArgs parsedargs;
+  DecodeBuffer input = {0, 0};
+  
+  if (!PyArg_ParseTuple(args, "OOO", &output_obj, &transport, &typeargs)) {
+    return NULL;
+  }
+
+  if (!parse_struct_args(&parsedargs, typeargs)) {
+    return NULL;
+  }
+
+  if (!decode_buffer_from_obj(&input, transport)) {
+    return NULL;
+  }
+
+  if (!decode_struct(&input, output_obj, parsedargs.spec)) {
+    free_decodebuf(&input);
+    return NULL;
+  }
+
+  free_decodebuf(&input);
+
+  Py_RETURN_NONE;
+}
+
+/* ====== END READING FUNCTIONS ====== */
+
+
+/* -- PYTHON MODULE SETUP STUFF --- */
+
+static PyMethodDef ThriftFastBinaryMethods[] = {
+
+  {"encode_binary",  encode_binary, METH_VARARGS, ""},
+  {"decode_binary",  decode_binary, METH_VARARGS, ""},
+
+  {NULL, NULL, 0, NULL}        /* Sentinel */
+};
+
+PyMODINIT_FUNC
+initfastbinary(void) {
+#define INIT_INTERN_STRING(value) \
+  do { \
+    INTERN_STRING(value) = PyString_InternFromString(#value); \
+    if(!INTERN_STRING(value)) return; \
+  } while(0)
+
+  INIT_INTERN_STRING(cstringio_buf);
+  INIT_INTERN_STRING(cstringio_refill);
+#undef INIT_INTERN_STRING
+
+  PycString_IMPORT;
+  if (PycStringIO == NULL) return;
+
+  (void) Py_InitModule("thrift.protocol.fastbinary", ThriftFastBinaryMethods);
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py
new file mode 100644
index 0000000..6ee18dd
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/THttpServer.py
@@ -0,0 +1,87 @@
+#
+# 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.
+#
+
+import BaseHTTPServer
+
+from ..server import TServer
+from ..transport import TTransport
+
+
+class ResponseException(Exception):
+  """Allows handlers to override the HTTP response
+
+  Normally, THttpServer always sends a 200 response.  If a handler wants
+  to override this behavior (e.g., to simulate a misconfigured or
+  overloaded web server during testing), it can raise a ResponseException.
+  The function passed to the constructor will be called with the
+  RequestHandler as its only argument.
+  """
+  def __init__(self, handler):
+    self.handler = handler
+
+
+class THttpServer(TServer.TServer):
+  """A simple HTTP-based Thrift server
+
+  This class is not very performant, but it is useful (for example) for
+  acting as a mock version of an Apache-based PHP Thrift endpoint.
+  """
+  def __init__(self,
+               processor,
+               server_address,
+               inputProtocolFactory,
+               outputProtocolFactory=None,
+               server_class=BaseHTTPServer.HTTPServer):
+    """Set up protocol factories and HTTP server.
+
+    See BaseHTTPServer for server_address.
+    See TServer for protocol factories.
+    """
+    if outputProtocolFactory is None:
+      outputProtocolFactory = inputProtocolFactory
+
+    TServer.TServer.__init__(self, processor, None, None, None,
+        inputProtocolFactory, outputProtocolFactory)
+
+    thttpserver = self
+
+    class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
+      def do_POST(self):
+        # Don't care about the request path.
+        itrans = TTransport.TFileObjectTransport(self.rfile)
+        otrans = TTransport.TFileObjectTransport(self.wfile)
+        itrans = TTransport.TBufferedTransport(
+          itrans, int(self.headers['Content-Length']))
+        otrans = TTransport.TMemoryBuffer()
+        iprot = thttpserver.inputProtocolFactory.getProtocol(itrans)
+        oprot = thttpserver.outputProtocolFactory.getProtocol(otrans)
+        try:
+          thttpserver.processor.process(iprot, oprot)
+        except ResponseException, exn:
+          exn.handler(self)
+        else:
+          self.send_response(200)
+          self.send_header("content-type", "application/x-thrift")
+          self.end_headers()
+          self.wfile.write(otrans.getvalue())
+
+    self.httpd = server_class(server_address, RequestHander)
+
+  def serve(self):
+    self.httpd.serve_forever()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
new file mode 100644
index 0000000..aa27991
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
@@ -0,0 +1,346 @@
+#
+# 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.
+#
+"""Implementation of non-blocking server.
+
+The main idea of the server is to receive and send requests
+only from the main thread.
+
+The thread poool should be sized for concurrent tasks, not
+maximum connections
+"""
+import threading
+import socket
+import Queue
+import select
+import struct
+import logging
+
+from ..transport import TTransport
+from ..protocol.TBinaryProtocol import TBinaryProtocolFactory
+
+__all__ = ['TNonblockingServer']
+
+
+class Worker(threading.Thread):
+    """Worker is a small helper to process incoming connection."""
+
+    def __init__(self, queue):
+        threading.Thread.__init__(self)
+        self.queue = queue
+
+    def run(self):
+        """Process queries from task queue, stop if processor is None."""
+        while True:
+            try:
+                processor, iprot, oprot, otrans, callback = self.queue.get()
+                if processor is None:
+                    break
+                processor.process(iprot, oprot)
+                callback(True, otrans.getvalue())
+            except Exception:
+                logging.exception("Exception while processing request")
+                callback(False, '')
+
+WAIT_LEN = 0
+WAIT_MESSAGE = 1
+WAIT_PROCESS = 2
+SEND_ANSWER = 3
+CLOSED = 4
+
+
+def locked(func):
+    """Decorator which locks self.lock."""
+    def nested(self, *args, **kwargs):
+        self.lock.acquire()
+        try:
+            return func(self, *args, **kwargs)
+        finally:
+            self.lock.release()
+    return nested
+
+
+def socket_exception(func):
+    """Decorator close object on socket.error."""
+    def read(self, *args, **kwargs):
+        try:
+            return func(self, *args, **kwargs)
+        except socket.error:
+            self.close()
+    return read
+
+
+class Connection:
+    """Basic class is represented connection.
+
+    It can be in state:
+        WAIT_LEN --- connection is reading request len.
+        WAIT_MESSAGE --- connection is reading request.
+        WAIT_PROCESS --- connection has just read whole request and
+                         waits for call ready routine.
+        SEND_ANSWER --- connection is sending answer string (including length
+                        of answer).
+        CLOSED --- socket was closed and connection should be deleted.
+    """
+    def __init__(self, new_socket, wake_up):
+        self.socket = new_socket
+        self.socket.setblocking(False)
+        self.status = WAIT_LEN
+        self.len = 0
+        self.message = ''
+        self.lock = threading.Lock()
+        self.wake_up = wake_up
+
+    def _read_len(self):
+        """Reads length of request.
+
+        It's a safer alternative to self.socket.recv(4)
+        """
+        read = self.socket.recv(4 - len(self.message))
+        if len(read) == 0:
+            # if we read 0 bytes and self.message is empty, then
+            # the client closed the connection
+            if len(self.message) != 0:
+                logging.error("can't read frame size from socket")
+            self.close()
+            return
+        self.message += read
+        if len(self.message) == 4:
+            self.len, = struct.unpack('!i', self.message)
+            if self.len < 0:
+                logging.error("negative frame size, it seems client "
+                              "doesn't use FramedTransport")
+                self.close()
+            elif self.len == 0:
+                logging.error("empty frame, it's really strange")
+                self.close()
+            else:
+                self.message = ''
+                self.status = WAIT_MESSAGE
+
+    @socket_exception
+    def read(self):
+        """Reads data from stream and switch state."""
+        assert self.status in (WAIT_LEN, WAIT_MESSAGE)
+        if self.status == WAIT_LEN:
+            self._read_len()
+            # go back to the main loop here for simplicity instead of
+            # falling through, even though there is a good chance that
+            # the message is already available
+        elif self.status == WAIT_MESSAGE:
+            read = self.socket.recv(self.len - len(self.message))
+            if len(read) == 0:
+                logging.error("can't read frame from socket (get %d of "
+                              "%d bytes)" % (len(self.message), self.len))
+                self.close()
+                return
+            self.message += read
+            if len(self.message) == self.len:
+                self.status = WAIT_PROCESS
+
+    @socket_exception
+    def write(self):
+        """Writes data from socket and switch state."""
+        assert self.status == SEND_ANSWER
+        sent = self.socket.send(self.message)
+        if sent == len(self.message):
+            self.status = WAIT_LEN
+            self.message = ''
+            self.len = 0
+        else:
+            self.message = self.message[sent:]
+
+    @locked
+    def ready(self, all_ok, message):
+        """Callback function for switching state and waking up main thread.
+
+        This function is the only function witch can be called asynchronous.
+
+        The ready can switch Connection to three states:
+            WAIT_LEN if request was oneway.
+            SEND_ANSWER if request was processed in normal way.
+            CLOSED if request throws unexpected exception.
+
+        The one wakes up main thread.
+        """
+        assert self.status == WAIT_PROCESS
+        if not all_ok:
+            self.close()
+            self.wake_up()
+            return
+        self.len = ''
+        if len(message) == 0:
+            # it was a oneway request, do not write answer
+            self.message = ''
+            self.status = WAIT_LEN
+        else:
+            self.message = struct.pack('!i', len(message)) + message
+            self.status = SEND_ANSWER
+        self.wake_up()
+
+    @locked
+    def is_writeable(self):
+        """Return True if connection should be added to write list of select"""
+        return self.status == SEND_ANSWER
+
+    # it's not necessary, but...
+    @locked
+    def is_readable(self):
+        """Return True if connection should be added to read list of select"""
+        return self.status in (WAIT_LEN, WAIT_MESSAGE)
+
+    @locked
+    def is_closed(self):
+        """Returns True if connection is closed."""
+        return self.status == CLOSED
+
+    def fileno(self):
+        """Returns the file descriptor of the associated socket."""
+        return self.socket.fileno()
+
+    def close(self):
+        """Closes connection"""
+        self.status = CLOSED
+        self.socket.close()
+
+
+class TNonblockingServer:
+    """Non-blocking server."""
+
+    def __init__(self,
+                 processor,
+                 lsocket,
+                 inputProtocolFactory=None,
+                 outputProtocolFactory=None,
+                 threads=10):
+        self.processor = processor
+        self.socket = lsocket
+        self.in_protocol = inputProtocolFactory or TBinaryProtocolFactory()
+        self.out_protocol = outputProtocolFactory or self.in_protocol
+        self.threads = int(threads)
+        self.clients = {}
+        self.tasks = Queue.Queue()
+        self._read, self._write = socket.socketpair()
+        self.prepared = False
+        self._stop = False
+
+    def setNumThreads(self, num):
+        """Set the number of worker threads that should be created."""
+        # implement ThreadPool interface
+        assert not self.prepared, "Can't change number of threads after start"
+        self.threads = num
+
+    def prepare(self):
+        """Prepares server for serve requests."""
+        if self.prepared:
+            return
+        self.socket.listen()
+        for _ in xrange(self.threads):
+            thread = Worker(self.tasks)
+            thread.setDaemon(True)
+            thread.start()
+        self.prepared = True
+
+    def wake_up(self):
+        """Wake up main thread.
+
+        The server usualy waits in select call in we should terminate one.
+        The simplest way is using socketpair.
+
+        Select always wait to read from the first socket of socketpair.
+
+        In this case, we can just write anything to the second socket from
+        socketpair.
+        """
+        self._write.send('1')
+
+    def stop(self):
+        """Stop the server.
+
+        This method causes the serve() method to return.  stop() may be invoked
+        from within your handler, or from another thread.
+
+        After stop() is called, serve() will return but the server will still
+        be listening on the socket.  serve() may then be called again to resume
+        processing requests.  Alternatively, close() may be called after
+        serve() returns to close the server socket and shutdown all worker
+        threads.
+        """
+        self._stop = True
+        self.wake_up()
+
+    def _select(self):
+        """Does select on open connections."""
+        readable = [self.socket.handle.fileno(), self._read.fileno()]
+        writable = []
+        for i, connection in self.clients.items():
+            if connection.is_readable():
+                readable.append(connection.fileno())
+            if connection.is_writeable():
+                writable.append(connection.fileno())
+            if connection.is_closed():
+                del self.clients[i]
+        return select.select(readable, writable, readable)
+
+    def handle(self):
+        """Handle requests.
+
+        WARNING! You must call prepare() BEFORE calling handle()
+        """
+        assert self.prepared, "You have to call prepare before handle"
+        rset, wset, xset = self._select()
+        for readable in rset:
+            if readable == self._read.fileno():
+                # don't care i just need to clean readable flag
+                self._read.recv(1024)
+            elif readable == self.socket.handle.fileno():
+                client = self.socket.accept().handle
+                self.clients[client.fileno()] = Connection(client,
+                                                           self.wake_up)
+            else:
+                connection = self.clients[readable]
+                connection.read()
+                if connection.status == WAIT_PROCESS:
+                    itransport = TTransport.TMemoryBuffer(connection.message)
+                    otransport = TTransport.TMemoryBuffer()
+                    iprot = self.in_protocol.getProtocol(itransport)
+                    oprot = self.out_protocol.getProtocol(otransport)
+                    self.tasks.put([self.processor, iprot, oprot,
+                                    otransport, connection.ready])
+        for writeable in wset:
+            self.clients[writeable].write()
+        for oob in xset:
+            self.clients[oob].close()
+            del self.clients[oob]
+
+    def close(self):
+        """Closes the server."""
+        for _ in xrange(self.threads):
+            self.tasks.put([None, None, None, None, None])
+        self.socket.close()
+        self.prepared = False
+
+    def serve(self):
+        """Serve requests.
+
+        Serve requests forever, or until stop() is called.
+        """
+        self._stop = False
+        self.prepare()
+        while not self._stop:
+            self.handle()


[44/50] [abbrv] git commit: Fixed loadavg reading issue

Posted by im...@apache.org.
Fixed loadavg reading issue


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

Branch: refs/heads/master
Commit: 55e7ea003b7e517d44d2013c5c187d0d5c234623
Parents: 7f8ef63
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Thu Oct 23 15:28:05 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Thu Oct 23 15:28:05 2014 +0530

----------------------------------------------------------------------
 .../cartridgeagent/modules/healthstatspublisher/healthstats.py  | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/55e7ea00/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py b/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py
index 4ceb948..6bb574b 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py
@@ -19,6 +19,7 @@ from threading import Thread
 import time
 import psutil
 import os
+import multiprocessing
 
 from abstracthealthstatisticspublisher import *
 from ..databridge.agent import *
@@ -181,7 +182,9 @@ class DefaultHealthStatisticsReader(AbstractHealthStatisticsReader):
     @staticmethod
     def __read_load_avg():
         (one, five, fifteen) = os.getloadavg()
-        return one
+        cores = multiprocessing.cpu_count()
+
+        return (one/cores) * 100
 
 
 class CEPPublisherConfiguration:


[04/50] [abbrv] git commit: Fixing stream ID issue in publishing to CEP

Posted by im...@apache.org.
Fixing stream ID issue in publishing to CEP


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

Branch: refs/heads/master
Commit: 56b52659da488bce06b0a14716e6dcd1b4ebf520
Parents: 32d2ecc
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Thu Oct 16 14:29:29 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Thu Oct 16 14:29:29 2014 +0530

----------------------------------------------------------------------
 .../cartridge-agent/modules/databridge/agent.py             | 9 +++++++++
 .../cartridge-agent/modules/databridge/thrift/publisher.py  | 6 ++----
 2 files changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/56b52659/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
index c4357df..8146666 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
@@ -45,6 +45,8 @@ class StreamDefinition:
         """:type : list[str]"""
         self.payload_data = []
         """:type : list[str]"""
+        self.stream_id =  None
+        """ :type : str """
 
     def add_metadata_attribute(self, attr_name, attr_type):
         self.meta_data.append({"name": attr_name, "type": attr_type})
@@ -141,6 +143,13 @@ class ThriftPublisher:
         self.__publisher.defineStream(str(stream_definition))
         ThriftPublisher.log.debug("DEFINED STREAM to %r:%r with stream definition %r" % (ip, port, str(stream_definition)))
 
+        self.stream_definition = stream_definition
+        self.stream_id = self.__publisher.streamId
+        self.ip = ip
+        self.port = port
+        self.username = username
+        self.password = password
+
     def publish(self, event):
         """
         Publishes the given event by creating the event bundle from the log event

http://git-wip-us.apache.org/repos/asf/stratos/blob/56b52659/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
index b33c8ac..325b05d 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
@@ -21,7 +21,6 @@ import sys
 sys.path.append("gen")
 
 from gen.ThriftSecureEventTransmissionService import ThriftSecureEventTransmissionService
-from gen.ThriftSecureEventTransmissionService.ttypes import *
 from gen.Data.ttypes import ThriftEventBundle
 
 from thrift.transport import TSSLSocket
@@ -60,12 +59,11 @@ class Publisher:
         # Build thrift event bundle
         #event = EventBundle()
         event.setSessionId(self.sessionId)
-        event.setEventNum(1)
-        event.addLongAttribute(time.time() * 1000)
+        event.setEventNum(0)
         event.addStringAttribute(self.streamId)
+        event.addLongAttribute(time.time() * 1000)
         #event.addStringAttribute(msg)
         # Publish
-        print "TO THE WIRE!!! "
         Publisher.client.publish(event.getEventBundle())
 
     def disconnect(self):


[25/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/test/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/__init__.py b/tools/python_cartridgeagent/test/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/test/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/test/asynctest.txt
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/asynctest.txt b/tools/python_cartridgeagent/test/asynctest.txt
new file mode 100644
index 0000000..08b3931
--- /dev/null
+++ b/tools/python_cartridgeagent/test/asynctest.txt
@@ -0,0 +1 @@
+1413809843291.4761
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/test/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/test_util.py b/tools/python_cartridgeagent/test/test_util.py
new file mode 100644
index 0000000..fd38c3e
--- /dev/null
+++ b/tools/python_cartridgeagent/test/test_util.py
@@ -0,0 +1,55 @@
+# 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.
+
+from ..cartridgeagent.modules.util.asyncscheduledtask import *
+from ..cartridgeagent.modules.util import cartridgeagentutils
+import time
+
+
+def test_async_task():
+    test_task = TestTask()
+    astask = ScheduledExecutor(1, test_task)
+    start_time = time.time() * 1000
+    astask.start()
+    time.sleep(2)
+    astask.terminate()
+    f = open("asynctest.txt", "r")
+    end_time = float(f.read())
+    assert (end_time - start_time) >= 1 * 1000, "Task was executed before specified delay"
+
+
+class TestTask(AbstractAsyncScheduledTask):
+
+    def execute_task(self):
+        with open("asynctest.txt", "w") as f:
+            f.seek(0)
+            f.truncate()
+            f.write("%1.4f" % (time.time()*1000))
+
+
+def test_decrypt_password():
+    # def mockgetlog(path):
+    #     return mocklog
+    #
+    # monkeypatch.delattr("LogFactory().get_log")
+
+    plain_password = "plaintext"
+    secret_key = "secret"
+    encrypted_password= "v5UltRskmSGbwTIbXym7jQ=="
+    b64encoded_encrypted_password = "djVVbHRSc2ttU0did1RJYlh5bTdqUT09"
+
+    assert cartridgeagentutils.decrypt_password(b64encoded_encrypted_password, secret_key) == plain_password, "Password decryption failed"
\ No newline at end of file


[35/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
deleted file mode 100644
index 74e142c..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
+++ /dev/null
@@ -1,118 +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.
-#
-
-
-import logging
-from multiprocessing import  Process, Value, Condition
-
-from TServer import TServer
-from ..transport.TTransport import TTransportException
-
-
-class TProcessPoolServer(TServer):
-    """Server with a fixed size pool of worker subprocesses to service requests
-
-    Note that if you need shared state between the handlers - it's up to you!
-    Written by Dvir Volk, doat.com
-    """
-    def __init__(self, *args):
-        TServer.__init__(self, *args)
-        self.numWorkers = 10
-        self.workers = []
-        self.isRunning = Value('b', False)
-        self.stopCondition = Condition()
-        self.postForkCallback = None
-
-    def setPostForkCallback(self, callback):
-        if not callable(callback):
-            raise TypeError("This is not a callback!")
-        self.postForkCallback = callback
-
-    def setNumWorkers(self, num):
-        """Set the number of worker threads that should be created"""
-        self.numWorkers = num
-
-    def workerProcess(self):
-        """Loop getting clients from the shared queue and process them"""
-        if self.postForkCallback:
-            self.postForkCallback()
-
-        while self.isRunning.value:
-            try:
-                client = self.serverTransport.accept()
-                self.serveClient(client)
-            except (KeyboardInterrupt, SystemExit):
-                return 0
-            except Exception, x:
-                logging.exception(x)
-
-    def serveClient(self, client):
-        """Process input/output from a client for as long as possible"""
-        itrans = self.inputTransportFactory.getTransport(client)
-        otrans = self.outputTransportFactory.getTransport(client)
-        iprot = self.inputProtocolFactory.getProtocol(itrans)
-        oprot = self.outputProtocolFactory.getProtocol(otrans)
-
-        try:
-            while True:
-                self.processor.process(iprot, oprot)
-        except TTransportException, tx:
-            pass
-        except Exception, x:
-            logging.exception(x)
-
-        itrans.close()
-        otrans.close()
-
-    def serve(self):
-        """Start workers and put into queue"""
-        # this is a shared state that can tell the workers to exit when False
-        self.isRunning.value = True
-
-        # first bind and listen to the port
-        self.serverTransport.listen()
-
-        # fork the children
-        for i in range(self.numWorkers):
-            try:
-                w = Process(target=self.workerProcess)
-                w.daemon = True
-                w.start()
-                self.workers.append(w)
-            except Exception, x:
-                logging.exception(x)
-
-        # wait until the condition is set by stop()
-        while True:
-            self.stopCondition.acquire()
-            try:
-                self.stopCondition.wait()
-                break
-            except (SystemExit, KeyboardInterrupt):
-                break
-            except Exception, x:
-                logging.exception(x)
-
-        self.isRunning.value = False
-
-    def stop(self):
-        self.isRunning.value = False
-        self.stopCondition.acquire()
-        self.stopCondition.notify()
-        self.stopCondition.release()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py
deleted file mode 100644
index 3e44107..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py
+++ /dev/null
@@ -1,269 +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.
-#
-
-import Queue
-import logging
-import os
-import sys
-import threading
-import traceback
-
-from ..Thrift import TProcessor
-from ..protocol import TBinaryProtocol
-from ..transport import TTransport
-
-
-class TServer:
-  """Base interface for a server, which must have a serve() method.
-
-  Three constructors for all servers:
-  1) (processor, serverTransport)
-  2) (processor, serverTransport, transportFactory, protocolFactory)
-  3) (processor, serverTransport,
-      inputTransportFactory, outputTransportFactory,
-      inputProtocolFactory, outputProtocolFactory)
-  """
-  def __init__(self, *args):
-    if (len(args) == 2):
-      self.__initArgs__(args[0], args[1],
-                        TTransport.TTransportFactoryBase(),
-                        TTransport.TTransportFactoryBase(),
-                        TBinaryProtocol.TBinaryProtocolFactory(),
-                        TBinaryProtocol.TBinaryProtocolFactory())
-    elif (len(args) == 4):
-      self.__initArgs__(args[0], args[1], args[2], args[2], args[3], args[3])
-    elif (len(args) == 6):
-      self.__initArgs__(args[0], args[1], args[2], args[3], args[4], args[5])
-
-  def __initArgs__(self, processor, serverTransport,
-                   inputTransportFactory, outputTransportFactory,
-                   inputProtocolFactory, outputProtocolFactory):
-    self.processor = processor
-    self.serverTransport = serverTransport
-    self.inputTransportFactory = inputTransportFactory
-    self.outputTransportFactory = outputTransportFactory
-    self.inputProtocolFactory = inputProtocolFactory
-    self.outputProtocolFactory = outputProtocolFactory
-
-  def serve(self):
-    pass
-
-
-class TSimpleServer(TServer):
-  """Simple single-threaded server that just pumps around one transport."""
-
-  def __init__(self, *args):
-    TServer.__init__(self, *args)
-
-  def serve(self):
-    self.serverTransport.listen()
-    while True:
-      client = self.serverTransport.accept()
-      itrans = self.inputTransportFactory.getTransport(client)
-      otrans = self.outputTransportFactory.getTransport(client)
-      iprot = self.inputProtocolFactory.getProtocol(itrans)
-      oprot = self.outputProtocolFactory.getProtocol(otrans)
-      try:
-        while True:
-          self.processor.process(iprot, oprot)
-      except TTransport.TTransportException, tx:
-        pass
-      except Exception, x:
-        logging.exception(x)
-
-      itrans.close()
-      otrans.close()
-
-
-class TThreadedServer(TServer):
-  """Threaded server that spawns a new thread per each connection."""
-
-  def __init__(self, *args, **kwargs):
-    TServer.__init__(self, *args)
-    self.daemon = kwargs.get("daemon", False)
-
-  def serve(self):
-    self.serverTransport.listen()
-    while True:
-      try:
-        client = self.serverTransport.accept()
-        t = threading.Thread(target=self.handle, args=(client,))
-        t.setDaemon(self.daemon)
-        t.start()
-      except KeyboardInterrupt:
-        raise
-      except Exception, x:
-        logging.exception(x)
-
-  def handle(self, client):
-    itrans = self.inputTransportFactory.getTransport(client)
-    otrans = self.outputTransportFactory.getTransport(client)
-    iprot = self.inputProtocolFactory.getProtocol(itrans)
-    oprot = self.outputProtocolFactory.getProtocol(otrans)
-    try:
-      while True:
-        self.processor.process(iprot, oprot)
-    except TTransport.TTransportException, tx:
-      pass
-    except Exception, x:
-      logging.exception(x)
-
-    itrans.close()
-    otrans.close()
-
-
-class TThreadPoolServer(TServer):
-  """Server with a fixed size pool of threads which service requests."""
-
-  def __init__(self, *args, **kwargs):
-    TServer.__init__(self, *args)
-    self.clients = Queue.Queue()
-    self.threads = 10
-    self.daemon = kwargs.get("daemon", False)
-
-  def setNumThreads(self, num):
-    """Set the number of worker threads that should be created"""
-    self.threads = num
-
-  def serveThread(self):
-    """Loop around getting clients from the shared queue and process them."""
-    while True:
-      try:
-        client = self.clients.get()
-        self.serveClient(client)
-      except Exception, x:
-        logging.exception(x)
-
-  def serveClient(self, client):
-    """Process input/output from a client for as long as possible"""
-    itrans = self.inputTransportFactory.getTransport(client)
-    otrans = self.outputTransportFactory.getTransport(client)
-    iprot = self.inputProtocolFactory.getProtocol(itrans)
-    oprot = self.outputProtocolFactory.getProtocol(otrans)
-    try:
-      while True:
-        self.processor.process(iprot, oprot)
-    except TTransport.TTransportException, tx:
-      pass
-    except Exception, x:
-      logging.exception(x)
-
-    itrans.close()
-    otrans.close()
-
-  def serve(self):
-    """Start a fixed number of worker threads and put client into a queue"""
-    for i in range(self.threads):
-      try:
-        t = threading.Thread(target=self.serveThread)
-        t.setDaemon(self.daemon)
-        t.start()
-      except Exception, x:
-        logging.exception(x)
-
-    # Pump the socket for clients
-    self.serverTransport.listen()
-    while True:
-      try:
-        client = self.serverTransport.accept()
-        self.clients.put(client)
-      except Exception, x:
-        logging.exception(x)
-
-
-class TForkingServer(TServer):
-  """A Thrift server that forks a new process for each request
-
-  This is more scalable than the threaded server as it does not cause
-  GIL contention.
-
-  Note that this has different semantics from the threading server.
-  Specifically, updates to shared variables will no longer be shared.
-  It will also not work on windows.
-
-  This code is heavily inspired by SocketServer.ForkingMixIn in the
-  Python stdlib.
-  """
-  def __init__(self, *args):
-    TServer.__init__(self, *args)
-    self.children = []
-
-  def serve(self):
-    def try_close(file):
-      try:
-        file.close()
-      except IOError, e:
-        logging.warning(e, exc_info=True)
-
-    self.serverTransport.listen()
-    while True:
-      client = self.serverTransport.accept()
-      try:
-        pid = os.fork()
-
-        if pid:  # parent
-          # add before collect, otherwise you race w/ waitpid
-          self.children.append(pid)
-          self.collect_children()
-
-          # Parent must close socket or the connection may not get
-          # closed promptly
-          itrans = self.inputTransportFactory.getTransport(client)
-          otrans = self.outputTransportFactory.getTransport(client)
-          try_close(itrans)
-          try_close(otrans)
-        else:
-          itrans = self.inputTransportFactory.getTransport(client)
-          otrans = self.outputTransportFactory.getTransport(client)
-
-          iprot = self.inputProtocolFactory.getProtocol(itrans)
-          oprot = self.outputProtocolFactory.getProtocol(otrans)
-
-          ecode = 0
-          try:
-            try:
-              while True:
-                self.processor.process(iprot, oprot)
-            except TTransport.TTransportException, tx:
-              pass
-            except Exception, e:
-              logging.exception(e)
-              ecode = 1
-          finally:
-            try_close(itrans)
-            try_close(otrans)
-
-          os._exit(ecode)
-
-      except TTransport.TTransportException, tx:
-        pass
-      except Exception, x:
-        logging.exception(x)
-
-  def collect_children(self):
-    while self.children:
-      try:
-        pid, status = os.waitpid(0, os.WNOHANG)
-      except os.error:
-        pid = None
-
-      if pid:
-        self.children.remove(pid)
-      else:
-        break

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py
deleted file mode 100644
index 1bf6e25..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py
+++ /dev/null
@@ -1,20 +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.
-#
-
-__all__ = ['TServer', 'TNonblockingServer']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py
deleted file mode 100644
index 9ef9535..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py
+++ /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.
-#
-
-import httplib
-import os
-import socket
-import sys
-import urllib
-import urlparse
-import warnings
-
-from TTransport import *
-
-
-class THttpClient(TTransportBase):
-  """Http implementation of TTransport base."""
-
-  def __init__(self, uri_or_host, port=None, path=None):
-    """THttpClient supports two different types constructor parameters.
-
-    THttpClient(host, port, path) - deprecated
-    THttpClient(uri)
-
-    Only the second supports https.
-    """
-    if port is not None:
-      warnings.warn(
-        "Please use the THttpClient('http://host:port/path') syntax",
-        DeprecationWarning,
-        stacklevel=2)
-      self.host = uri_or_host
-      self.port = port
-      assert path
-      self.path = path
-      self.scheme = 'http'
-    else:
-      parsed = urlparse.urlparse(uri_or_host)
-      self.scheme = parsed.scheme
-      assert self.scheme in ('http', 'https')
-      if self.scheme == 'http':
-        self.port = parsed.port or httplib.HTTP_PORT
-      elif self.scheme == 'https':
-        self.port = parsed.port or httplib.HTTPS_PORT
-      self.host = parsed.hostname
-      self.path = parsed.path
-      if parsed.query:
-        self.path += '?%s' % parsed.query
-    self.__wbuf = StringIO()
-    self.__http = None
-    self.__timeout = None
-    self.__custom_headers = None
-
-  def open(self):
-    if self.scheme == 'http':
-      self.__http = httplib.HTTP(self.host, self.port)
-    else:
-      self.__http = httplib.HTTPS(self.host, self.port)
-
-  def close(self):
-    self.__http.close()
-    self.__http = None
-
-  def isOpen(self):
-    return self.__http is not None
-
-  def setTimeout(self, ms):
-    if not hasattr(socket, 'getdefaulttimeout'):
-      raise NotImplementedError
-
-    if ms is None:
-      self.__timeout = None
-    else:
-      self.__timeout = ms / 1000.0
-
-  def setCustomHeaders(self, headers):
-    self.__custom_headers = headers
-
-  def read(self, sz):
-    return self.__http.file.read(sz)
-
-  def write(self, buf):
-    self.__wbuf.write(buf)
-
-  def __withTimeout(f):
-    def _f(*args, **kwargs):
-      orig_timeout = socket.getdefaulttimeout()
-      socket.setdefaulttimeout(args[0].__timeout)
-      result = f(*args, **kwargs)
-      socket.setdefaulttimeout(orig_timeout)
-      return result
-    return _f
-
-  def flush(self):
-    if self.isOpen():
-      self.close()
-    self.open()
-
-    # Pull data out of buffer
-    data = self.__wbuf.getvalue()
-    self.__wbuf = StringIO()
-
-    # HTTP request
-    self.__http.putrequest('POST', self.path)
-
-    # Write headers
-    self.__http.putheader('Host', self.host)
-    self.__http.putheader('Content-Type', 'application/x-thrift')
-    self.__http.putheader('Content-Length', str(len(data)))
-
-    if not self.__custom_headers or 'User-Agent' not in self.__custom_headers:
-      user_agent = 'Python/THttpClient'
-      script = os.path.basename(sys.argv[0])
-      if script:
-        user_agent = '%s (%s)' % (user_agent, urllib.quote(script))
-      self.__http.putheader('User-Agent', user_agent)
-
-    if self.__custom_headers:
-        for key, val in self.__custom_headers.iteritems():
-            self.__http.putheader(key, val)
-
-    self.__http.endheaders()
-
-    # Write payload
-    self.__http.send(data)
-
-    # Get reply to flush the request
-    self.code, self.message, self.headers = self.__http.getreply()
-
-  # Decorate if we know how to timeout
-  if hasattr(socket, 'getdefaulttimeout'):
-    flush = __withTimeout(flush)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
deleted file mode 100644
index df35be4..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
+++ /dev/null
@@ -1,214 +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.
-#
-
-import os
-import socket
-import ssl
-
-import TSocket
-from TTransport import TTransportException
-
-
-class TSSLSocket(TSocket.TSocket):
-  """
-  SSL implementation of client-side TSocket
-
-  This class creates outbound sockets wrapped using the
-  python standard ssl module for encrypted connections.
-
-  The protocol used is set using the class variable
-  SSL_VERSION, which must be one of ssl.PROTOCOL_* and
-  defaults to  ssl.PROTOCOL_TLSv1 for greatest security.
-  """
-  SSL_VERSION = ssl.PROTOCOL_TLSv1
-
-  def __init__(self,
-               host='localhost',
-               port=9090,
-               validate=True,
-               ca_certs=None,
-               keyfile=None,
-               certfile=None,
-               unix_socket=None):
-    """Create SSL TSocket
-
-    @param validate: Set to False to disable SSL certificate validation
-    @type validate: bool
-    @param ca_certs: Filename to the Certificate Authority pem file, possibly a
-    file downloaded from: http://curl.haxx.se/ca/cacert.pem  This is passed to
-    the ssl_wrap function as the 'ca_certs' parameter.
-    @type ca_certs: str
-    @param keyfile: The private key
-    @type keyfile: str
-    @param certfile: The cert file
-    @type certfile: str
-    
-    Raises an IOError exception if validate is True and the ca_certs file is
-    None, not present or unreadable.
-    """
-    self.validate = validate
-    self.is_valid = False
-    self.peercert = None
-    if not validate:
-      self.cert_reqs = ssl.CERT_NONE
-    else:
-      self.cert_reqs = ssl.CERT_REQUIRED
-    self.ca_certs = ca_certs
-    self.keyfile = keyfile
-    self.certfile = certfile
-    if validate:
-      if ca_certs is None or not os.access(ca_certs, os.R_OK):
-        raise IOError('Certificate Authority ca_certs file "%s" '
-                      'is not readable, cannot validate SSL '
-                      'certificates.' % (ca_certs))
-    TSocket.TSocket.__init__(self, host, port, unix_socket)
-
-  def open(self):
-    try:
-      res0 = self._resolveAddr()
-      for res in res0:
-        sock_family, sock_type = res[0:2]
-        ip_port = res[4]
-        plain_sock = socket.socket(sock_family, sock_type)
-        self.handle = ssl.wrap_socket(plain_sock,
-                                      ssl_version=self.SSL_VERSION,
-                                      do_handshake_on_connect=True,
-                                      ca_certs=self.ca_certs,
-                                      keyfile=self.keyfile,
-                                      certfile=self.certfile,
-                                      cert_reqs=self.cert_reqs)
-        self.handle.settimeout(self._timeout)
-        try:
-          self.handle.connect(ip_port)
-        except socket.error, e:
-          if res is not res0[-1]:
-            continue
-          else:
-            raise e
-        break
-    except socket.error, e:
-      if self._unix_socket:
-        message = 'Could not connect to secure socket %s: %s' \
-                % (self._unix_socket, e)
-      else:
-        message = 'Could not connect to %s:%d: %s' % (self.host, self.port, e)
-      raise TTransportException(type=TTransportException.NOT_OPEN,
-                                message=message)
-    if self.validate:
-      self._validate_cert()
-
-  def _validate_cert(self):
-    """internal method to validate the peer's SSL certificate, and to check the
-    commonName of the certificate to ensure it matches the hostname we
-    used to make this connection.  Does not support subjectAltName records
-    in certificates.
-
-    raises TTransportException if the certificate fails validation.
-    """
-    cert = self.handle.getpeercert()
-    self.peercert = cert
-    if 'subject' not in cert:
-      raise TTransportException(
-        type=TTransportException.NOT_OPEN,
-        message='No SSL certificate found from %s:%s' % (self.host, self.port))
-    fields = cert['subject']
-    for field in fields:
-      # ensure structure we get back is what we expect
-      if not isinstance(field, tuple):
-        continue
-      cert_pair = field[0]
-      if len(cert_pair) < 2:
-        continue
-      cert_key, cert_value = cert_pair[0:2]
-      if cert_key != 'commonName':
-        continue
-      certhost = cert_value
-      # this check should be performed by some sort of Access Manager
-      if certhost == self.host:
-        # success, cert commonName matches desired hostname
-        self.is_valid = True
-        return
-      else:
-        raise TTransportException(
-          type=TTransportException.UNKNOWN,
-          message='Hostname we connected to "%s" doesn\'t match certificate '
-                  'provided commonName "%s"' % (self.host, certhost))
-    raise TTransportException(
-      type=TTransportException.UNKNOWN,
-      message='Could not validate SSL certificate from '
-              'host "%s".  Cert=%s' % (self.host, cert))
-
-
-class TSSLServerSocket(TSocket.TServerSocket):
-  """SSL implementation of TServerSocket
-
-  This uses the ssl module's wrap_socket() method to provide SSL
-  negotiated encryption.
-  """
-  SSL_VERSION = ssl.PROTOCOL_TLSv1
-
-  def __init__(self,
-               host=None,
-               port=9090,
-               certfile='cert.pem',
-               unix_socket=None):
-    """Initialize a TSSLServerSocket
-
-    @param certfile: filename of the server certificate, defaults to cert.pem
-    @type certfile: str
-    @param host: The hostname or IP to bind the listen socket to,
-                 i.e. 'localhost' for only allowing local network connections.
-                 Pass None to bind to all interfaces.
-    @type host: str
-    @param port: The port to listen on for inbound connections.
-    @type port: int
-    """
-    self.setCertfile(certfile)
-    TSocket.TServerSocket.__init__(self, host, port)
-
-  def setCertfile(self, certfile):
-    """Set or change the server certificate file used to wrap new connections.
-
-    @param certfile: The filename of the server certificate,
-                     i.e. '/etc/certs/server.pem'
-    @type certfile: str
-
-    Raises an IOError exception if the certfile is not present or unreadable.
-    """
-    if not os.access(certfile, os.R_OK):
-      raise IOError('No such certfile found: %s' % (certfile))
-    self.certfile = certfile
-
-  def accept(self):
-    plain_client, addr = self.handle.accept()
-    try:
-      client = ssl.wrap_socket(plain_client, certfile=self.certfile,
-                      server_side=True, ssl_version=self.SSL_VERSION)
-    except ssl.SSLError, ssl_exc:
-      # failed handshake/ssl wrap, close socket to client
-      plain_client.close()
-      # raise ssl_exc
-      # We can't raise the exception, because it kills most TServer derived
-      # serve() methods.
-      # Instead, return None, and let the TServer instance deal with it in
-      # other exception handling.  (but TSimpleServer dies anyway)
-      return None
-    result = TSocket.TSocket()
-    result.setHandle(client)
-    return result

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py
deleted file mode 100644
index 9e2b384..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py
+++ /dev/null
@@ -1,176 +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.
-#
-
-import errno
-import os
-import socket
-import sys
-
-from TTransport import *
-
-
-class TSocketBase(TTransportBase):
-  def _resolveAddr(self):
-    if self._unix_socket is not None:
-      return [(socket.AF_UNIX, socket.SOCK_STREAM, None, None,
-               self._unix_socket)]
-    else:
-      return socket.getaddrinfo(self.host,
-                                self.port,
-                                socket.AF_UNSPEC,
-                                socket.SOCK_STREAM,
-                                0,
-                                socket.AI_PASSIVE | socket.AI_ADDRCONFIG)
-
-  def close(self):
-    if self.handle:
-      self.handle.close()
-      self.handle = None
-
-
-class TSocket(TSocketBase):
-  """Socket implementation of TTransport base."""
-
-  def __init__(self, host='localhost', port=9090, unix_socket=None):
-    """Initialize a TSocket
-
-    @param host(str)  The host to connect to.
-    @param port(int)  The (TCP) port to connect to.
-    @param unix_socket(str)  The filename of a unix socket to connect to.
-                             (host and port will be ignored.)
-    """
-    self.host = host
-    self.port = port
-    self.handle = None
-    self._unix_socket = unix_socket
-    self._timeout = None
-
-  def setHandle(self, h):
-    self.handle = h
-
-  def isOpen(self):
-    return self.handle is not None
-
-  def setTimeout(self, ms):
-    if ms is None:
-      self._timeout = None
-    else:
-      self._timeout = ms / 1000.0
-
-    if self.handle is not None:
-      self.handle.settimeout(self._timeout)
-
-  def open(self):
-    try:
-      res0 = self._resolveAddr()
-      for res in res0:
-        self.handle = socket.socket(res[0], res[1])
-        self.handle.settimeout(self._timeout)
-        try:
-          self.handle.connect(res[4])
-        except socket.error, e:
-          if res is not res0[-1]:
-            continue
-          else:
-            raise e
-        break
-    except socket.error, e:
-      if self._unix_socket:
-        message = 'Could not connect to socket %s' % self._unix_socket
-      else:
-        message = 'Could not connect to %s:%d' % (self.host, self.port)
-      raise TTransportException(type=TTransportException.NOT_OPEN,
-                                message=message)
-
-  def read(self, sz):
-    try:
-      buff = self.handle.recv(sz)
-    except socket.error, e:
-      if (e.args[0] == errno.ECONNRESET and
-          (sys.platform == 'darwin' or sys.platform.startswith('freebsd'))):
-        # freebsd and Mach don't follow POSIX semantic of recv
-        # and fail with ECONNRESET if peer performed shutdown.
-        # See corresponding comment and code in TSocket::read()
-        # in lib/cpp/src/transport/TSocket.cpp.
-        self.close()
-        # Trigger the check to raise the END_OF_FILE exception below.
-        buff = ''
-      else:
-        raise
-    if len(buff) == 0:
-      raise TTransportException(type=TTransportException.END_OF_FILE,
-                                message='TSocket read 0 bytes')
-    return buff
-
-  def write(self, buff):
-    if not self.handle:
-      raise TTransportException(type=TTransportException.NOT_OPEN,
-                                message='Transport not open')
-    sent = 0
-    have = len(buff)
-    while sent < have:
-      plus = self.handle.send(buff)
-      if plus == 0:
-        raise TTransportException(type=TTransportException.END_OF_FILE,
-                                  message='TSocket sent 0 bytes')
-      sent += plus
-      buff = buff[plus:]
-
-  def flush(self):
-    pass
-
-
-class TServerSocket(TSocketBase, TServerTransportBase):
-  """Socket implementation of TServerTransport base."""
-
-  def __init__(self, host=None, port=9090, unix_socket=None):
-    self.host = host
-    self.port = port
-    self._unix_socket = unix_socket
-    self.handle = None
-
-  def listen(self):
-    res0 = self._resolveAddr()
-    for res in res0:
-      if res[0] is socket.AF_INET6 or res is res0[-1]:
-        break
-
-    # We need remove the old unix socket if the file exists and
-    # nobody is listening on it.
-    if self._unix_socket:
-      tmp = socket.socket(res[0], res[1])
-      try:
-        tmp.connect(res[4])
-      except socket.error, err:
-        eno, message = err.args
-        if eno == errno.ECONNREFUSED:
-          os.unlink(res[4])
-
-    self.handle = socket.socket(res[0], res[1])
-    self.handle.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-    if hasattr(self.handle, 'settimeout'):
-      self.handle.settimeout(None)
-    self.handle.bind(res[4])
-    self.handle.listen(128)
-
-  def accept(self):
-    client, addr = self.handle.accept()
-    result = TSocket()
-    result.setHandle(client)
-    return result

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py
deleted file mode 100644
index ed023d5..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py
+++ /dev/null
@@ -1,330 +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.
-#
-
-from cStringIO import StringIO
-from struct import pack, unpack
-from ..Thrift import TException
-
-
-class TTransportException(TException):
-  """Custom Transport Exception class"""
-
-  UNKNOWN = 0
-  NOT_OPEN = 1
-  ALREADY_OPEN = 2
-  TIMED_OUT = 3
-  END_OF_FILE = 4
-
-  def __init__(self, type=UNKNOWN, message=None):
-    TException.__init__(self, message)
-    self.type = type
-
-
-class TTransportBase:
-  """Base class for Thrift transport layer."""
-
-  def isOpen(self):
-    pass
-
-  def open(self):
-    pass
-
-  def close(self):
-    pass
-
-  def read(self, sz):
-    pass
-
-  def readAll(self, sz):
-    buff = ''
-    have = 0
-    while (have < sz):
-      chunk = self.read(sz - have)
-      have += len(chunk)
-      buff += chunk
-
-      if len(chunk) == 0:
-        raise EOFError()
-
-    return buff
-
-  def write(self, buf):
-    pass
-
-  def flush(self):
-    pass
-
-
-# This class should be thought of as an interface.
-class CReadableTransport:
-  """base class for transports that are readable from C"""
-
-  # TODO(dreiss): Think about changing this interface to allow us to use
-  #               a (Python, not c) StringIO instead, because it allows
-  #               you to write after reading.
-
-  # NOTE: This is a classic class, so properties will NOT work
-  #       correctly for setting.
-  @property
-  def cstringio_buf(self):
-    """A cStringIO buffer that contains the current chunk we are reading."""
-    pass
-
-  def cstringio_refill(self, partialread, reqlen):
-    """Refills cstringio_buf.
-
-    Returns the currently used buffer (which can but need not be the same as
-    the old cstringio_buf). partialread is what the C code has read from the
-    buffer, and should be inserted into the buffer before any more reads.  The
-    return value must be a new, not borrowed reference.  Something along the
-    lines of self._buf should be fine.
-
-    If reqlen bytes can't be read, throw EOFError.
-    """
-    pass
-
-
-class TServerTransportBase:
-  """Base class for Thrift server transports."""
-
-  def listen(self):
-    pass
-
-  def accept(self):
-    pass
-
-  def close(self):
-    pass
-
-
-class TTransportFactoryBase:
-  """Base class for a Transport Factory"""
-
-  def getTransport(self, trans):
-    return trans
-
-
-class TBufferedTransportFactory:
-  """Factory transport that builds buffered transports"""
-
-  def getTransport(self, trans):
-    buffered = TBufferedTransport(trans)
-    return buffered
-
-
-class TBufferedTransport(TTransportBase, CReadableTransport):
-  """Class that wraps another transport and buffers its I/O.
-
-  The implementation uses a (configurable) fixed-size read buffer
-  but buffers all writes until a flush is performed.
-  """
-  DEFAULT_BUFFER = 4096
-
-  def __init__(self, trans, rbuf_size=DEFAULT_BUFFER):
-    self.__trans = trans
-    self.__wbuf = StringIO()
-    self.__rbuf = StringIO("")
-    self.__rbuf_size = rbuf_size
-
-  def isOpen(self):
-    return self.__trans.isOpen()
-
-  def open(self):
-    return self.__trans.open()
-
-  def close(self):
-    return self.__trans.close()
-
-  def read(self, sz):
-    ret = self.__rbuf.read(sz)
-    if len(ret) != 0:
-      return ret
-
-    self.__rbuf = StringIO(self.__trans.read(max(sz, self.__rbuf_size)))
-    return self.__rbuf.read(sz)
-
-  def write(self, buf):
-    self.__wbuf.write(buf)
-
-  def flush(self):
-    out = self.__wbuf.getvalue()
-    # reset wbuf before write/flush to preserve state on underlying failure
-    self.__wbuf = StringIO()
-    self.__trans.write(out)
-    self.__trans.flush()
-
-  # Implement the CReadableTransport interface.
-  @property
-  def cstringio_buf(self):
-    return self.__rbuf
-
-  def cstringio_refill(self, partialread, reqlen):
-    retstring = partialread
-    if reqlen < self.__rbuf_size:
-      # try to make a read of as much as we can.
-      retstring += self.__trans.read(self.__rbuf_size)
-
-    # but make sure we do read reqlen bytes.
-    if len(retstring) < reqlen:
-      retstring += self.__trans.readAll(reqlen - len(retstring))
-
-    self.__rbuf = StringIO(retstring)
-    return self.__rbuf
-
-
-class TMemoryBuffer(TTransportBase, CReadableTransport):
-  """Wraps a cStringIO object as a TTransport.
-
-  NOTE: Unlike the C++ version of this class, you cannot write to it
-        then immediately read from it.  If you want to read from a
-        TMemoryBuffer, you must either pass a string to the constructor.
-  TODO(dreiss): Make this work like the C++ version.
-  """
-
-  def __init__(self, value=None):
-    """value -- a value to read from for stringio
-
-    If value is set, this will be a transport for reading,
-    otherwise, it is for writing"""
-    if value is not None:
-      self._buffer = StringIO(value)
-    else:
-      self._buffer = StringIO()
-
-  def isOpen(self):
-    return not self._buffer.closed
-
-  def open(self):
-    pass
-
-  def close(self):
-    self._buffer.close()
-
-  def read(self, sz):
-    return self._buffer.read(sz)
-
-  def write(self, buf):
-    self._buffer.write(buf)
-
-  def flush(self):
-    pass
-
-  def getvalue(self):
-    return self._buffer.getvalue()
-
-  # Implement the CReadableTransport interface.
-  @property
-  def cstringio_buf(self):
-    return self._buffer
-
-  def cstringio_refill(self, partialread, reqlen):
-    # only one shot at reading...
-    raise EOFError()
-
-
-class TFramedTransportFactory:
-  """Factory transport that builds framed transports"""
-
-  def getTransport(self, trans):
-    framed = TFramedTransport(trans)
-    return framed
-
-
-class TFramedTransport(TTransportBase, CReadableTransport):
-  """Class that wraps another transport and frames its I/O when writing."""
-
-  def __init__(self, trans,):
-    self.__trans = trans
-    self.__rbuf = StringIO()
-    self.__wbuf = StringIO()
-
-  def isOpen(self):
-    return self.__trans.isOpen()
-
-  def open(self):
-    return self.__trans.open()
-
-  def close(self):
-    return self.__trans.close()
-
-  def read(self, sz):
-    ret = self.__rbuf.read(sz)
-    if len(ret) != 0:
-      return ret
-
-    self.readFrame()
-    return self.__rbuf.read(sz)
-
-  def readFrame(self):
-    buff = self.__trans.readAll(4)
-    sz, = unpack('!i', buff)
-    self.__rbuf = StringIO(self.__trans.readAll(sz))
-
-  def write(self, buf):
-    self.__wbuf.write(buf)
-
-  def flush(self):
-    wout = self.__wbuf.getvalue()
-    wsz = len(wout)
-    # reset wbuf before write/flush to preserve state on underlying failure
-    self.__wbuf = StringIO()
-    # N.B.: Doing this string concatenation is WAY cheaper than making
-    # two separate calls to the underlying socket object. Socket writes in
-    # Python turn out to be REALLY expensive, but it seems to do a pretty
-    # good job of managing string buffer operations without excessive copies
-    buf = pack("!i", wsz) + wout
-    self.__trans.write(buf)
-    self.__trans.flush()
-
-  # Implement the CReadableTransport interface.
-  @property
-  def cstringio_buf(self):
-    return self.__rbuf
-
-  def cstringio_refill(self, prefix, reqlen):
-    # self.__rbuf will already be empty here because fastbinary doesn't
-    # ask for a refill until the previous buffer is empty.  Therefore,
-    # we can start reading new frames immediately.
-    while len(prefix) < reqlen:
-      self.readFrame()
-      prefix += self.__rbuf.getvalue()
-    self.__rbuf = StringIO(prefix)
-    return self.__rbuf
-
-
-class TFileObjectTransport(TTransportBase):
-  """Wraps a file-like object to make it work as a Thrift transport."""
-
-  def __init__(self, fileobj):
-    self.fileobj = fileobj
-
-  def isOpen(self):
-    return True
-
-  def close(self):
-    self.fileobj.close()
-
-  def read(self, sz):
-    return self.fileobj.read(sz)
-
-  def write(self, buf):
-    self.fileobj.write(buf)
-
-  def flush(self):
-    self.fileobj.flush()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py
deleted file mode 100644
index 6cdb172..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py
+++ /dev/null
@@ -1,221 +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.
-#
-
-from cStringIO import StringIO
-
-from zope.interface import implements, Interface, Attribute
-from twisted.internet.protocol import Protocol, ServerFactory, ClientFactory, \
-    connectionDone
-from twisted.internet import defer
-from twisted.protocols import basic
-from twisted.python import log
-from twisted.web import server, resource, http
-
-import TTransport
-
-
-class TMessageSenderTransport(TTransport.TTransportBase):
-
-    def __init__(self):
-        self.__wbuf = StringIO()
-
-    def write(self, buf):
-        self.__wbuf.write(buf)
-
-    def flush(self):
-        msg = self.__wbuf.getvalue()
-        self.__wbuf = StringIO()
-        self.sendMessage(msg)
-
-    def sendMessage(self, message):
-        raise NotImplementedError
-
-
-class TCallbackTransport(TMessageSenderTransport):
-
-    def __init__(self, func):
-        TMessageSenderTransport.__init__(self)
-        self.func = func
-
-    def sendMessage(self, message):
-        self.func(message)
-
-
-class ThriftClientProtocol(basic.Int32StringReceiver):
-
-    MAX_LENGTH = 2 ** 31 - 1
-
-    def __init__(self, client_class, iprot_factory, oprot_factory=None):
-        self._client_class = client_class
-        self._iprot_factory = iprot_factory
-        if oprot_factory is None:
-            self._oprot_factory = iprot_factory
-        else:
-            self._oprot_factory = oprot_factory
-
-        self.recv_map = {}
-        self.started = defer.Deferred()
-
-    def dispatch(self, msg):
-        self.sendString(msg)
-
-    def connectionMade(self):
-        tmo = TCallbackTransport(self.dispatch)
-        self.client = self._client_class(tmo, self._oprot_factory)
-        self.started.callback(self.client)
-
-    def connectionLost(self, reason=connectionDone):
-        for k, v in self.client._reqs.iteritems():
-            tex = TTransport.TTransportException(
-                type=TTransport.TTransportException.END_OF_FILE,
-                message='Connection closed')
-            v.errback(tex)
-
-    def stringReceived(self, frame):
-        tr = TTransport.TMemoryBuffer(frame)
-        iprot = self._iprot_factory.getProtocol(tr)
-        (fname, mtype, rseqid) = iprot.readMessageBegin()
-
-        try:
-            method = self.recv_map[fname]
-        except KeyError:
-            method = getattr(self.client, 'recv_' + fname)
-            self.recv_map[fname] = method
-
-        method(iprot, mtype, rseqid)
-
-
-class ThriftServerProtocol(basic.Int32StringReceiver):
-
-    MAX_LENGTH = 2 ** 31 - 1
-
-    def dispatch(self, msg):
-        self.sendString(msg)
-
-    def processError(self, error):
-        self.transport.loseConnection()
-
-    def processOk(self, _, tmo):
-        msg = tmo.getvalue()
-
-        if len(msg) > 0:
-            self.dispatch(msg)
-
-    def stringReceived(self, frame):
-        tmi = TTransport.TMemoryBuffer(frame)
-        tmo = TTransport.TMemoryBuffer()
-
-        iprot = self.factory.iprot_factory.getProtocol(tmi)
-        oprot = self.factory.oprot_factory.getProtocol(tmo)
-
-        d = self.factory.processor.process(iprot, oprot)
-        d.addCallbacks(self.processOk, self.processError,
-            callbackArgs=(tmo,))
-
-
-class IThriftServerFactory(Interface):
-
-    processor = Attribute("Thrift processor")
-
-    iprot_factory = Attribute("Input protocol factory")
-
-    oprot_factory = Attribute("Output protocol factory")
-
-
-class IThriftClientFactory(Interface):
-
-    client_class = Attribute("Thrift client class")
-
-    iprot_factory = Attribute("Input protocol factory")
-
-    oprot_factory = Attribute("Output protocol factory")
-
-
-class ThriftServerFactory(ServerFactory):
-
-    implements(IThriftServerFactory)
-
-    protocol = ThriftServerProtocol
-
-    def __init__(self, processor, iprot_factory, oprot_factory=None):
-        self.processor = processor
-        self.iprot_factory = iprot_factory
-        if oprot_factory is None:
-            self.oprot_factory = iprot_factory
-        else:
-            self.oprot_factory = oprot_factory
-
-
-class ThriftClientFactory(ClientFactory):
-
-    implements(IThriftClientFactory)
-
-    protocol = ThriftClientProtocol
-
-    def __init__(self, client_class, iprot_factory, oprot_factory=None):
-        self.client_class = client_class
-        self.iprot_factory = iprot_factory
-        if oprot_factory is None:
-            self.oprot_factory = iprot_factory
-        else:
-            self.oprot_factory = oprot_factory
-
-    def buildProtocol(self, addr):
-        p = self.protocol(self.client_class, self.iprot_factory,
-            self.oprot_factory)
-        p.factory = self
-        return p
-
-
-class ThriftResource(resource.Resource):
-
-    allowedMethods = ('POST',)
-
-    def __init__(self, processor, inputProtocolFactory,
-        outputProtocolFactory=None):
-        resource.Resource.__init__(self)
-        self.inputProtocolFactory = inputProtocolFactory
-        if outputProtocolFactory is None:
-            self.outputProtocolFactory = inputProtocolFactory
-        else:
-            self.outputProtocolFactory = outputProtocolFactory
-        self.processor = processor
-
-    def getChild(self, path, request):
-        return self
-
-    def _cbProcess(self, _, request, tmo):
-        msg = tmo.getvalue()
-        request.setResponseCode(http.OK)
-        request.setHeader("content-type", "application/x-thrift")
-        request.write(msg)
-        request.finish()
-
-    def render_POST(self, request):
-        request.content.seek(0, 0)
-        data = request.content.read()
-        tmi = TTransport.TMemoryBuffer(data)
-        tmo = TTransport.TMemoryBuffer()
-
-        iprot = self.inputProtocolFactory.getProtocol(tmi)
-        oprot = self.outputProtocolFactory.getProtocol(tmo)
-
-        d = self.processor.process(iprot, oprot)
-        d.addCallback(self._cbProcess, request, tmo)
-        return server.NOT_DONE_YET

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
deleted file mode 100644
index 2bdfd14..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
+++ /dev/null
@@ -1,249 +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.
-#
-
-"""TZlibTransport provides a compressed transport and transport factory
-class, using the python standard library zlib module to implement
-data compression.
-"""
-
-from __future__ import division
-import zlib
-from cStringIO import StringIO
-
-from TTransport import TTransportBase, CReadableTransport
-
-
-class TZlibTransportFactory(object):
-  """Factory transport that builds zlib compressed transports.
-
-  This factory caches the last single client/transport that it was passed
-  and returns the same TZlibTransport object that was created.
-
-  This caching means the TServer class will get the _same_ transport
-  object for both input and output transports from this factory.
-  (For non-threaded scenarios only, since the cache only holds one object)
-
-  The purpose of this caching is to allocate only one TZlibTransport where
-  only one is really needed (since it must have separate read/write buffers),
-  and makes the statistics from getCompSavings() and getCompRatio()
-  easier to understand.
-  """
-  # class scoped cache of last transport given and zlibtransport returned
-  _last_trans = None
-  _last_z = None
-
-  def getTransport(self, trans, compresslevel=9):
-    """Wrap a transport, trans, with the TZlibTransport
-    compressed transport class, returning a new
-    transport to the caller.
-
-    @param compresslevel: The zlib compression level, ranging
-    from 0 (no compression) to 9 (best compression).  Defaults to 9.
-    @type compresslevel: int
-
-    This method returns a TZlibTransport which wraps the
-    passed C{trans} TTransport derived instance.
-    """
-    if trans == self._last_trans:
-      return self._last_z
-    ztrans = TZlibTransport(trans, compresslevel)
-    self._last_trans = trans
-    self._last_z = ztrans
-    return ztrans
-
-
-class TZlibTransport(TTransportBase, CReadableTransport):
-  """Class that wraps a transport with zlib, compressing writes
-  and decompresses reads, using the python standard
-  library zlib module.
-  """
-  # Read buffer size for the python fastbinary C extension,
-  # the TBinaryProtocolAccelerated class.
-  DEFAULT_BUFFSIZE = 4096
-
-  def __init__(self, trans, compresslevel=9):
-    """Create a new TZlibTransport, wrapping C{trans}, another
-    TTransport derived object.
-
-    @param trans: A thrift transport object, i.e. a TSocket() object.
-    @type trans: TTransport
-    @param compresslevel: The zlib compression level, ranging
-    from 0 (no compression) to 9 (best compression).  Default is 9.
-    @type compresslevel: int
-    """
-    self.__trans = trans
-    self.compresslevel = compresslevel
-    self.__rbuf = StringIO()
-    self.__wbuf = StringIO()
-    self._init_zlib()
-    self._init_stats()
-
-  def _reinit_buffers(self):
-    """Internal method to initialize/reset the internal StringIO objects
-    for read and write buffers.
-    """
-    self.__rbuf = StringIO()
-    self.__wbuf = StringIO()
-
-  def _init_stats(self):
-    """Internal method to reset the internal statistics counters
-    for compression ratios and bandwidth savings.
-    """
-    self.bytes_in = 0
-    self.bytes_out = 0
-    self.bytes_in_comp = 0
-    self.bytes_out_comp = 0
-
-  def _init_zlib(self):
-    """Internal method for setting up the zlib compression and
-    decompression objects.
-    """
-    self._zcomp_read = zlib.decompressobj()
-    self._zcomp_write = zlib.compressobj(self.compresslevel)
-
-  def getCompRatio(self):
-    """Get the current measured compression ratios (in,out) from
-    this transport.
-
-    Returns a tuple of:
-    (inbound_compression_ratio, outbound_compression_ratio)
-
-    The compression ratios are computed as:
-        compressed / uncompressed
-
-    E.g., data that compresses by 10x will have a ratio of: 0.10
-    and data that compresses to half of ts original size will
-    have a ratio of 0.5
-
-    None is returned if no bytes have yet been processed in
-    a particular direction.
-    """
-    r_percent, w_percent = (None, None)
-    if self.bytes_in > 0:
-      r_percent = self.bytes_in_comp / self.bytes_in
-    if self.bytes_out > 0:
-      w_percent = self.bytes_out_comp / self.bytes_out
-    return (r_percent, w_percent)
-
-  def getCompSavings(self):
-    """Get the current count of saved bytes due to data
-    compression.
-
-    Returns a tuple of:
-    (inbound_saved_bytes, outbound_saved_bytes)
-
-    Note: if compression is actually expanding your
-    data (only likely with very tiny thrift objects), then
-    the values returned will be negative.
-    """
-    r_saved = self.bytes_in - self.bytes_in_comp
-    w_saved = self.bytes_out - self.bytes_out_comp
-    return (r_saved, w_saved)
-
-  def isOpen(self):
-    """Return the underlying transport's open status"""
-    return self.__trans.isOpen()
-
-  def open(self):
-    """Open the underlying transport"""
-    self._init_stats()
-    return self.__trans.open()
-
-  def listen(self):
-    """Invoke the underlying transport's listen() method"""
-    self.__trans.listen()
-
-  def accept(self):
-    """Accept connections on the underlying transport"""
-    return self.__trans.accept()
-
-  def close(self):
-    """Close the underlying transport,"""
-    self._reinit_buffers()
-    self._init_zlib()
-    return self.__trans.close()
-
-  def read(self, sz):
-    """Read up to sz bytes from the decompressed bytes buffer, and
-    read from the underlying transport if the decompression
-    buffer is empty.
-    """
-    ret = self.__rbuf.read(sz)
-    if len(ret) > 0:
-      return ret
-    # keep reading from transport until something comes back
-    while True:
-      if self.readComp(sz):
-        break
-    ret = self.__rbuf.read(sz)
-    return ret
-
-  def readComp(self, sz):
-    """Read compressed data from the underlying transport, then
-    decompress it and append it to the internal StringIO read buffer
-    """
-    zbuf = self.__trans.read(sz)
-    zbuf = self._zcomp_read.unconsumed_tail + zbuf
-    buf = self._zcomp_read.decompress(zbuf)
-    self.bytes_in += len(zbuf)
-    self.bytes_in_comp += len(buf)
-    old = self.__rbuf.read()
-    self.__rbuf = StringIO(old + buf)
-    if len(old) + len(buf) == 0:
-      return False
-    return True
-
-  def write(self, buf):
-    """Write some bytes, putting them into the internal write
-    buffer for eventual compression.
-    """
-    self.__wbuf.write(buf)
-
-  def flush(self):
-    """Flush any queued up data in the write buffer and ensure the
-    compression buffer is flushed out to the underlying transport
-    """
-    wout = self.__wbuf.getvalue()
-    if len(wout) > 0:
-      zbuf = self._zcomp_write.compress(wout)
-      self.bytes_out += len(wout)
-      self.bytes_out_comp += len(zbuf)
-    else:
-      zbuf = ''
-    ztail = self._zcomp_write.flush(zlib.Z_SYNC_FLUSH)
-    self.bytes_out_comp += len(ztail)
-    if (len(zbuf) + len(ztail)) > 0:
-      self.__wbuf = StringIO()
-      self.__trans.write(zbuf + ztail)
-    self.__trans.flush()
-
-  @property
-  def cstringio_buf(self):
-    """Implement the CReadableTransport interface"""
-    return self.__rbuf
-
-  def cstringio_refill(self, partialread, reqlen):
-    """Implement the CReadableTransport interface for refill"""
-    retstring = partialread
-    if reqlen < self.DEFAULT_BUFFSIZE:
-      retstring += self.read(self.DEFAULT_BUFFSIZE)
-    while len(retstring) < reqlen:
-      retstring += self.read(reqlen - len(retstring))
-    self.__rbuf = StringIO(retstring)
-    return self.__rbuf

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py
deleted file mode 100644
index c9596d9..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py
+++ /dev/null
@@ -1,20 +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.
-#
-
-__all__ = ['TTransport', 'TSocket', 'THttpClient', 'TZlibTransport']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/__init__.py
deleted file mode 100644
index a595c84..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/__init__.py
+++ /dev/null
@@ -1,18 +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.
-
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py
deleted file mode 100644
index fc4bfc9..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py
+++ /dev/null
@@ -1,33 +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.
-
-class DataPublisherException(Exception):
-    """
-    Exception to be used during log publishing operations
-    """
-
-    def __init__(self, msg):
-        super(self,  msg)
-        self.message = msg
-
-    def get_message(self):
-        """
-        The message provided when the exception is raised
-        :return: message
-        :rtype: str
-        """
-        return self.message

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/logpublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/logpublisher.py b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/logpublisher.py
deleted file mode 100644
index 050dd9e..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/logpublisher.py
+++ /dev/null
@@ -1,273 +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.
-
-import os
-import datetime
-from threading import Thread, current_thread
-
-from ..databridge.agent import *
-from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
-from ..util import cartridgeagentutils, cartridgeagentconstants
-from exception.datapublisherexception import DataPublisherException
-
-
-class LogPublisher(Thread):
-
-    def __init__(self, file_path, stream_definition, tenant_id, alias, date_time, member_id):
-        Thread.__init__(self)
-
-        self.log = LogFactory().get_log(__name__)
-
-        self.file_path = file_path
-        self.thrift_publisher = ThriftPublisher(
-            DataPublisherConfiguration.get_instance().monitoring_server_ip,
-            DataPublisherConfiguration.get_instance().monitoring_server_port,
-            DataPublisherConfiguration.get_instance().admin_username,
-            DataPublisherConfiguration.get_instance().admin_password,
-            stream_definition)
-        self.tenant_id = tenant_id
-        self.alias = alias
-        self.datetime = date_time
-        self.member_id = member_id
-
-        self.terminated = False
-
-    def run(self):
-        if os.path.isfile(self.file_path) and os.access(self.file_path, os.R_OK):
-            self.log.info("Starting log publisher for file: " + self.file_path + ", thread: " + current_thread())
-            # open file and keep reading for new entries
-            read_file = open(self.file_path, "r")
-            read_file.seek(os.stat(self.file_path)[6])  # go to the end of the file
-
-            while not self.terminated:
-                where = read_file.tell()  # where the seeker is in the file
-                line = read_file.readline()   # read the current line
-                if not line:
-                    # no new line entered
-                    time.sleep(1)
-                    read_file.seek(where)  # set seeker
-                else:
-                    # new line detected, create event object
-                    event = ThriftEvent()
-                    event.metaData.append(self.member_id)
-                    event.payloadData.append(self.tenant_id)
-                    event.payloadData.append(self.alias)
-                    event.payloadData.append("")
-                    event.payloadData.append(self.datetime)
-                    event.payloadData.append("")
-                    event.payloadData.append(line)
-                    event.payloadData.append("")
-                    event.payloadData.append("")
-                    event.payloadData.append(self.member_id)
-                    event.payloadData.append("")
-
-                    self.thrift_publisher.publish(event)
-
-            self.thrift_publisher.disconnect()  # dicsonnect the publisher upon being terminated
-        else:
-            raise DataPublisherException("Unable to read the file at path %r" % self.file_path)
-
-    def terminate(self):
-        """
-        Allows the LogPublisher thread to be terminated to stop publishing to BAM/CEP. Allow a minimum of 1 second delay
-        to take effect.
-        """
-        self.terminated = True
-
-
-class LogPublisherManager(Thread):
-    """
-    A log publishing thread management thread which maintains a log publisher for each log file. Also defines a stream
-    definition and the BAM/CEP server information for a single publishing context.
-    """
-
-    @staticmethod
-    def define_stream():
-        """
-        Creates a stream definition for Log Publishing
-        :return: A StreamDefinition object with the required attributes added
-        :rtype : StreamDefinition
-        """
-        # stream definition
-        stream_definition = StreamDefinition()
-        valid_tenant_id = LogPublisherManager.get_valid_tenant_id(CartridgeAgentConfiguration().tenant_id)
-        alias = LogPublisherManager.get_alias(CartridgeAgentConfiguration().cluster_id)
-        stream_name = "logs." + valid_tenant_id + "." \
-                      + alias + "." + LogPublisherManager.get_current_date()
-        stream_version = "1.0.0"
-
-        stream_definition.name = stream_name
-        stream_definition.version = stream_version
-        stream_definition.description = "Apache Stratos Instance Log Publisher"
-        stream_definition.add_metadata_attribute("memberId", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("tenantID", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("serverName", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("appName", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("logTime", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("priority", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("message", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("logger", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("ip", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("instance", StreamDefinition.STRING)
-        stream_definition.add_payloaddata_attribute("stacktrace", StreamDefinition.STRING)
-
-        return stream_definition
-
-    def __init__(self, logfile_paths):
-        Thread.__init__(self)
-        self.logfile_paths = logfile_paths
-        self.publishers = {}
-        self.ports = []
-        self.ports.append(DataPublisherConfiguration.get_instance().monitoring_server_port)
-        self.ports.append(DataPublisherConfiguration.get_instance().monitoring_server_secure_port)
-
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-        cartridgeagentutils.wait_until_ports_active(
-            DataPublisherConfiguration.get_instance().monitoring_server_ip,
-            self.ports,
-            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False)))
-
-        ports_active = cartridgeagentutils.check_ports_active(
-            DataPublisherConfiguration.get_instance().monitoring_server_ip,
-            self.ports)
-
-        if not ports_active:
-            raise DataPublisherException("Monitoring server not active, data publishing is aborted")
-
-        self.stream_definition = self.define_stream()
-
-    def run(self):
-        if self.logfile_paths is not None and len(self.logfile_paths):
-            for log_path in self.logfile_paths:
-                # thread for each log file
-                publisher = self.get_publisher(log_path)
-                publisher.start()
-
-    def get_publisher(self, log_path):
-        """
-        Retrieve the publisher for the specified log file path. Creates a new LogPublisher if one is not available
-        :return: The LogPublisher object
-        :rtype : LogPublisher
-        """
-        if log_path not in self.publishers:
-            self.publishers[log_path] = LogPublisher(log_path, self.stream_definition)
-
-        return self.publishers[log_path]
-
-    def terminate_publisher(self, log_path):
-        """
-        Terminates the LogPublisher thread associated with the specified log file
-        """
-        if log_path in self.publishers:
-            self.publishers[log_path].terminate()
-
-    def terminate_all_publishers(self):
-        """
-        Terminates all LogPublisher threads
-        """
-        for publisher in self.publishers:
-            publisher.terminate()
-
-    @staticmethod
-    def get_valid_tenant_id(tenant_id):
-        if tenant_id == cartridgeagentconstants.INVALID_TENANT_ID \
-                or tenant_id == cartridgeagentconstants.SUPER_TENANT_ID:
-            return "0"
-
-        return tenant_id
-
-    @staticmethod
-    def get_alias(cluster_id):
-        try:
-            alias = cluster_id.split("\\.")[0]
-        except:
-            alias = cluster_id
-
-        return alias
-
-    @staticmethod
-    def get_current_date():
-        """
-        Returns the current date formatted as yyyy-MM-dd
-        :return: Formatted date string
-        :rtype : str
-        """
-        return datetime.date.today().strftime(cartridgeagentconstants.DATE_FORMAT)
-
-
-class DataPublisherConfiguration:
-    """
-    A singleton implementation to access configuration information for data publishing to BAM/CEP
-    TODO: perfect singleton impl ex: Borg
-    """
-
-    __instance = None
-    log = LogFactory().get_log(__name__)
-
-    @staticmethod
-    def get_instance():
-        """
-        Singleton instance retriever
-        :return: Instance
-        :rtype : DataPublisherConfiguration
-        """
-        if DataPublisherConfiguration.__instance is None:
-            DataPublisherConfiguration.__instance = DataPublisherConfiguration()
-
-        return DataPublisherConfiguration.__instance
-
-    def __init__(self):
-        self.enabled = False
-        self.monitoring_server_ip = None
-        self.monitoring_server_port = None
-        self.monitoring_server_secure_port = None
-        self.admin_username = None
-        self.admin_password = None
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-        self.read_config()
-
-    def read_config(self):
-        self.enabled = True if self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_PUBLISHER_ENABLED, False).strip().lower() == "true" else False
-        if not self.enabled:
-            DataPublisherConfiguration.log.info("Data Publisher disabled")
-            return
-
-        DataPublisherConfiguration.log.info("Data Publisher enabled")
-
-        self.monitoring_server_ip = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_RECEIVER_IP, False)
-        if self.monitoring_server_ip is None or self.monitoring_server_ip.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_RECEIVER_IP)
-
-        self.monitoring_server_port = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_RECEIVER_PORT, False)
-        if self.monitoring_server_port is None or self.monitoring_server_port.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_RECEIVER_PORT)
-
-        self.monitoring_server_secure_port = self.cartridge_agent_config.read_property("monitoring.server.secure.port", False)
-        if self.monitoring_server_secure_port is None or self.monitoring_server_secure_port.strip() == "":
-            raise RuntimeError("System property not found: monitoring.server.secure.port")
-
-        self.admin_username = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_SERVER_ADMIN_USERNAME, False)
-        if self.admin_username is None or self.admin_username.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_SERVER_ADMIN_USERNAME)
-
-        self.admin_password = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_SERVER_ADMIN_PASSWORD, False)
-        if self.admin_password is None or self.admin_password.strip() == "":
-            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_SERVER_ADMIN_PASSWORD)
-
-        DataPublisherConfiguration.log.info("Data Publisher configuration initialized")

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/event/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/__init__.py
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/events.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/events.py
deleted file mode 100644
index 024e1e4..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/events.py
+++ /dev/null
@@ -1,77 +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.
-
-import json
-
-
-class ArtifactUpdatedEvent:
-    def __init__(self):
-        self.cluster_id = None
-        """ :type : str  """
-        self.status = None
-        """ :type : str  """
-        self.repo_username = None
-        """ :type : str  """
-        self.repo_password = None
-        """ :type : str  """
-        self.repo_url = None
-        """ :type : str  """
-        self.tenant_id = None
-        """ :type : int  """
-        self.commit_enabled = None
-        """ :type : bool  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        instance = ArtifactUpdatedEvent()
-
-        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-        instance.status = json_obj["status"] if "status" in json_obj else None
-        instance.repo_username = json_obj["repoUserName"] if "repoUserName" in json_obj else None
-        instance.repo_password = json_obj["repoPassword"] if "repoPassword" in json_obj else None
-        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
-        instance.repo_url = json_obj["repoUrl"] if "repoUrl" in json_obj else ""
-        instance.commit_enabled = json_obj["commitEnabled"] if "commitEnabled" in json_obj else None
-
-        return instance
-
-
-class InstanceCleanupClusterEvent:
-    def __init__(self, cluster_id):
-        self.cluster_id = cluster_id
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        c_id = json_obj["clusterId"] if "clusterId" in json_obj else None
-
-        return InstanceCleanupClusterEvent(c_id)
-
-
-class InstanceCleanupMemberEvent:
-    def __init__(self, member_id):
-        self.member_id = member_id
-        """ :type : str  """
-
-    @staticmethod
-    def create_from_json(json_str):
-        json_obj = json.loads(json_str)
-        m_id = json_obj["memberId"] if "memberId" in json_obj else None
-
-        return InstanceCleanupMemberEvent(m_id)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/__init__.py
+++ /dev/null
@@ -1,17 +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.
-


[02/50] [abbrv] git commit: Merge remote-tracking branch 'upstream/master'

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


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

Branch: refs/heads/master
Commit: 7cc189eb803aa841b6064bb28285dd041da847c2
Parents: 5e60755 7d4abd0
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Wed Oct 15 13:54:38 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Wed Oct 15 13:54:38 2014 +0530

----------------------------------------------------------------------
 .../autoscaler/api/AutoScalerServiceImpl.java   |  17 +
 .../exception/InvalidArgumentException.java     |  46 +
 .../interfaces/AutoScalerServiceInterface.java  |   8 +
 .../monitor/AbstractClusterMonitor.java         |   4 +
 .../monitor/ClusterMonitorFactory.java          |  38 +-
 .../monitor/KubernetesClusterMonitor.java       |  67 +-
 .../KubernetesServiceClusterMonitor.java        |  41 +
 .../autoscaler/monitor/VMLbClusterMonitor.java  |   8 +
 .../monitor/VMServiceClusterMonitor.java        |   7 +
 .../rule/AutoscalerRuleEvaluator.java           |   4 +-
 .../autoscaler/rule/RuleTasksDelegator.java     |  31 +-
 .../stratos/autoscaler/TestRulesPackaged.java   |   6 +-
 .../java/org/apache/stratos/cli/RestClient.java |  52 +-
 .../stratos/cli/RestCommandLineService.java     | 916 ++++++++-----------
 .../apache/stratos/cli/StratosApplication.java  |  13 +-
 .../autoscaler/partition/PropertyBean.java      |   6 +
 .../stratos/cli/beans/topology/Cluster.java     |  14 +
 .../stratos/cli/beans/topology/Member.java      |  19 +-
 .../commands/DeployKubernetesGroupCommand.java  |   9 +-
 .../commands/DeployKubernetesHostCommand.java   |   9 +-
 .../cli/commands/DeployPartitionCommand.java    |  21 +-
 .../DescribeCartridgeSubscriptionCommand.java   |  95 ++
 .../commands/ListAutoscalePolicyCommand.java    |   1 -
 .../ListCartridgeSubscriptionsCommand.java      |  84 +-
 .../cli/commands/ListCartridgesCommand.java     |   3 +-
 .../commands/ListDeploymentPolicyCommand.java   |   1 -
 .../ListSubscribedCartridgesCommand.java        | 120 ---
 .../cli/commands/SubscribeCartridgeCommand.java |  42 +-
 .../commands/UpdateKubernetesHostCommand.java   | 109 +++
 .../commands/UpdateKubernetesMasterCommand.java | 109 +++
 .../UpdateSubscriptionPropertiesCommand.java    | 135 +++
 .../apache/stratos/cli/utils/CliConstants.java  |   5 +
 .../org/apache/stratos/cli/utils/CliUtils.java  |  63 +-
 .../impl/CloudControllerServiceImpl.java        |  20 +-
 .../CartridgeInstanceDataPublisher.java         |  26 +-
 .../controller/topology/TopologyBuilder.java    |   5 +-
 .../topology/TopologyEventPublisher.java        |   8 +-
 .../common/constants/StratosConstants.java      |   1 +
 .../conf/LoadBalancerConfiguration.java         |   4 +-
 .../manager/client/AutoscalerServiceClient.java |   5 +
 .../CartridgeSubscriptionDataPublisher.java     |  25 +-
 .../model/TopologyClusterInformationModel.java  |  12 +-
 .../broker/publish/EventPublisherPool.java      |   1 -
 .../broker/publish/TopicPublisher.java          |  92 +-
 .../broker/subscribe/TopicSubscriber.java       |  54 +-
 .../messaging/domain/topology/Cluster.java      |  17 +-
 .../messaging/domain/topology/Member.java       |  19 +-
 .../event/topology/InstanceSpawnedEvent.java    |   8 +-
 .../InstanceSpawnedMessageProcessor.java        |   7 +-
 .../stat/HealthStatEventMessageListener.java    |  45 +-
 .../InstanceNotifierEventMessageListener.java   |  46 +-
 .../stratos/messaging/util/Constants.java       |   2 +-
 .../rest/endpoint/bean/topology/Cluster.java    |  21 +-
 .../rest/endpoint/bean/topology/Member.java     |  17 +-
 .../bean/util/converter/PojoConverter.java      |  23 +-
 .../rest/endpoint/services/ServiceUtils.java    |  28 +
 .../rest/endpoint/services/StratosAdmin.java    |  13 +
 .../extension/FaultHandlingWindowProcessor.java |  43 +-
 .../modules/distribution/src/assembly/bin.xml   |  22 +-
 .../distribution/src/main/conf/autoscaler.xml   |   2 +-
 .../src/main/conf/container-mincheck.drl        |  72 --
 .../src/main/conf/container-scaling.drl         | 163 ----
 .../src/main/conf/drools/container-mincheck.drl |  73 ++
 .../src/main/conf/drools/container-scaling.drl  | 173 ++++
 .../src/main/conf/drools/mincheck.drl           |  83 ++
 .../src/main/conf/drools/scaling.drl            | 205 +++++
 .../src/main/conf/drools/terminateall.drl       |  44 +
 .../distribution/src/main/conf/mincheck.drl     |  83 --
 .../distribution/src/main/conf/scaling.drl      | 205 -----
 .../distribution/src/main/conf/terminateall.drl |  44 -
 .../src/main/resources/AutoScalerService.wsdl   | 366 +++++---
 71 files changed, 2440 insertions(+), 1740 deletions(-)
----------------------------------------------------------------------



[43/50] [abbrv] git commit: Fixed left out name changes Fixed health stats event not being published to CEP Fixed incrementing event number of the events published to the thrift receiver

Posted by im...@apache.org.
Fixed left out name changes
Fixed health stats event not being published to CEP
Fixed incrementing event number of the events published to the thrift receiver


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

Branch: refs/heads/master
Commit: 7f8ef63f985bbaae4e7fc80f4873fbb4f2e0393b
Parents: cd97e69
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Wed Oct 22 19:40:54 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Wed Oct 22 19:40:54 2014 +0530

----------------------------------------------------------------------
 tools/python_cartridgeagent/cartridgeagent/agent.conf     |  4 ++--
 .../modules/artifactmgt/git/gitrepository.py              |  5 +----
 .../cartridgeagent/modules/databridge/agent.py            |  2 ++
 .../cartridgeagent/modules/databridge/thrift/publisher.py | 10 +++++-----
 .../cartridgeagent/modules/util/cartridgeagentutils.py    |  2 +-
 5 files changed, 11 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/7f8ef63f/tools/python_cartridgeagent/cartridgeagent/agent.conf
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/agent.conf b/tools/python_cartridgeagent/cartridgeagent/agent.conf
index 5c087e9..dff3cd7 100644
--- a/tools/python_cartridgeagent/cartridgeagent/agent.conf
+++ b/tools/python_cartridgeagent/cartridgeagent/agent.conf
@@ -23,8 +23,8 @@ thrift.receiver.ip                    =CEP-IP
 thrift.receiver.port                  =CEP-PORT
 thrift.server.admin.username          =CEP-ADMIN-USERNAME
 thrift.server.admin.password          =CEP-ADMIN-PASSWORD
-param.file.path                       =/mnt/cartridge-agent/payload/launch-params
-extensions.dir                        =/mnt/cartridge-agent/extensions
+param.file.path                       =/mnt/cartridgeagent/payload/launch-params
+extensions.dir                        =/mnt/cartridgeagent/extensions
 cep.stats.publisher.enabled           =ENABLE_HEALTH_PUBLISHER
 lb.private.ip                         =LB_PRIVATE_IP
 lb.public.ip                          =LB_PUBLIC_IP

http://git-wip-us.apache.org/repos/asf/stratos/blob/7f8ef63f/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/gitrepository.py b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
index 98a8a44..d710d9b 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
@@ -15,9 +15,6 @@
 # specific language governing permissions and limitations
 # under the License.
 
-from ...util.asyncscheduledtask import AsyncScheduledTask
-from gittle import Gittle
-from git import *
 
 class GitRepository:
     """
@@ -48,4 +45,4 @@ class GitRepository:
         self.commit_enabled = False
         """ :type : bool  """
         self.scheduled_update_task = None
-        """:type : AsyncScheduledTask """
\ No newline at end of file
+        """:type : ScheduledExecutor """
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/7f8ef63f/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
index 1859d8a..d67be89 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
@@ -155,6 +155,8 @@ class ThriftPublisher:
         :return: void
         """
         event_bundler = EventBundle()
+        event_bundler.addStringAttribute(self.stream_id)
+        event_bundler.addLongAttribute(time.time() * 1000)
         ThriftPublisher.assign_attributes(event.metaData, event_bundler)
         ThriftPublisher.assign_attributes(event.correlationData, event_bundler)
         ThriftPublisher.assign_attributes(event.payloadData, event_bundler)

http://git-wip-us.apache.org/repos/asf/stratos/blob/7f8ef63f/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
index 325b05d..dfe4aa2 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
@@ -42,6 +42,8 @@ class Publisher:
         self.sessionId = None
         self.streamId = None
 
+        self.event_num = 0
+
     def connect(self, username, password):
         # Create a client to use the protocol encoder
         Publisher.client = ThriftSecureEventTransmissionService.Client(self.protocol)
@@ -57,12 +59,10 @@ class Publisher:
 
     def publish(self, event):
         # Build thrift event bundle
-        #event = EventBundle()
         event.setSessionId(self.sessionId)
-        event.setEventNum(0)
-        event.addStringAttribute(self.streamId)
-        event.addLongAttribute(time.time() * 1000)
-        #event.addStringAttribute(msg)
+        event.setEventNum(self.event_num)
+        self.event_num += 1
+
         # Publish
         Publisher.client.publish(event.getEventBundle())
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/7f8ef63f/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentutils.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentutils.py b/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentutils.py
index 6ae89b1..583cae2 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentutils.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentutils.py
@@ -164,5 +164,5 @@ def get_working_dir():
     :return: Base working dir path
     :rtype : str
     """
-    #"/path/to/cartridge-agent/modules/util/".split("modules") returns ["/path/to/cartridge-agent/", "/util"]
+    #"/path/to/cartridgeagent/modules/util/".split("modules") returns ["/path/to/cartridgeagent/", "/util"]
     return os.path.abspath(os.path.dirname(__file__)).split("modules")[0]
\ No newline at end of file


[17/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
deleted file mode 100644
index 953838e..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TCompactProtocol.py
+++ /dev/null
@@ -1,405 +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.
-#
-
-from struct import pack, unpack
-
-from TProtocol import *
-
-
-__all__ = ['TCompactProtocol', 'TCompactProtocolFactory']
-
-CLEAR = 0
-FIELD_WRITE = 1
-VALUE_WRITE = 2
-CONTAINER_WRITE = 3
-BOOL_WRITE = 4
-FIELD_READ = 5
-CONTAINER_READ = 6
-VALUE_READ = 7
-BOOL_READ = 8
-
-
-def make_helper(v_from, container):
-  def helper(func):
-    def nested(self, *args, **kwargs):
-      assert self.state in (v_from, container), (self.state, v_from, container)
-      return func(self, *args, **kwargs)
-    return nested
-  return helper
-writer = make_helper(VALUE_WRITE, CONTAINER_WRITE)
-reader = make_helper(VALUE_READ, CONTAINER_READ)
-
-
-def makeZigZag(n, bits):
-  return (n << 1) ^ (n >> (bits - 1))
-
-
-def fromZigZag(n):
-  return (n >> 1) ^ -(n & 1)
-
-
-def writeVarint(trans, n):
-  out = []
-  while True:
-    if n & ~0x7f == 0:
-      out.append(n)
-      break
-    else:
-      out.append((n & 0xff) | 0x80)
-      n = n >> 7
-  trans.write(''.join(map(chr, out)))
-
-
-def readVarint(trans):
-  result = 0
-  shift = 0
-  while True:
-    x = trans.readAll(1)
-    byte = ord(x)
-    result |= (byte & 0x7f) << shift
-    if byte >> 7 == 0:
-      return result
-    shift += 7
-
-
-class CompactType:
-  STOP = 0x00
-  TRUE = 0x01
-  FALSE = 0x02
-  BYTE = 0x03
-  I16 = 0x04
-  I32 = 0x05
-  I64 = 0x06
-  DOUBLE = 0x07
-  BINARY = 0x08
-  LIST = 0x09
-  SET = 0x0A
-  MAP = 0x0B
-  STRUCT = 0x0C
-
-CTYPES = {TType.STOP: CompactType.STOP,
-          TType.BOOL: CompactType.TRUE,  # used for collection
-          TType.BYTE: CompactType.BYTE,
-          TType.I16: CompactType.I16,
-          TType.I32: CompactType.I32,
-          TType.I64: CompactType.I64,
-          TType.DOUBLE: CompactType.DOUBLE,
-          TType.STRING: CompactType.BINARY,
-          TType.STRUCT: CompactType.STRUCT,
-          TType.LIST: CompactType.LIST,
-          TType.SET: CompactType.SET,
-          TType.MAP: CompactType.MAP
-          }
-
-TTYPES = {}
-for k, v in CTYPES.items():
-  TTYPES[v] = k
-TTYPES[CompactType.FALSE] = TType.BOOL
-del k
-del v
-
-
-class TCompactProtocol(TProtocolBase):
-  """Compact implementation of the Thrift protocol driver."""
-
-  PROTOCOL_ID = 0x82
-  VERSION = 1
-  VERSION_MASK = 0x1f
-  TYPE_MASK = 0xe0
-  TYPE_SHIFT_AMOUNT = 5
-
-  def __init__(self, trans):
-    TProtocolBase.__init__(self, trans)
-    self.state = CLEAR
-    self.__last_fid = 0
-    self.__bool_fid = None
-    self.__bool_value = None
-    self.__structs = []
-    self.__containers = []
-
-  def __writeVarint(self, n):
-    writeVarint(self.trans, n)
-
-  def writeMessageBegin(self, name, type, seqid):
-    assert self.state == CLEAR
-    self.__writeUByte(self.PROTOCOL_ID)
-    self.__writeUByte(self.VERSION | (type << self.TYPE_SHIFT_AMOUNT))
-    self.__writeVarint(seqid)
-    self.__writeString(name)
-    self.state = VALUE_WRITE
-
-  def writeMessageEnd(self):
-    assert self.state == VALUE_WRITE
-    self.state = CLEAR
-
-  def writeStructBegin(self, name):
-    assert self.state in (CLEAR, CONTAINER_WRITE, VALUE_WRITE), self.state
-    self.__structs.append((self.state, self.__last_fid))
-    self.state = FIELD_WRITE
-    self.__last_fid = 0
-
-  def writeStructEnd(self):
-    assert self.state == FIELD_WRITE
-    self.state, self.__last_fid = self.__structs.pop()
-
-  def writeFieldStop(self):
-    self.__writeByte(0)
-
-  def __writeFieldHeader(self, type, fid):
-    delta = fid - self.__last_fid
-    if 0 < delta <= 15:
-      self.__writeUByte(delta << 4 | type)
-    else:
-      self.__writeByte(type)
-      self.__writeI16(fid)
-    self.__last_fid = fid
-
-  def writeFieldBegin(self, name, type, fid):
-    assert self.state == FIELD_WRITE, self.state
-    if type == TType.BOOL:
-      self.state = BOOL_WRITE
-      self.__bool_fid = fid
-    else:
-      self.state = VALUE_WRITE
-      self.__writeFieldHeader(CTYPES[type], fid)
-
-  def writeFieldEnd(self):
-    assert self.state in (VALUE_WRITE, BOOL_WRITE), self.state
-    self.state = FIELD_WRITE
-
-  def __writeUByte(self, byte):
-    self.trans.write(pack('!B', byte))
-
-  def __writeByte(self, byte):
-    self.trans.write(pack('!b', byte))
-
-  def __writeI16(self, i16):
-    self.__writeVarint(makeZigZag(i16, 16))
-
-  def __writeSize(self, i32):
-    self.__writeVarint(i32)
-
-  def writeCollectionBegin(self, etype, size):
-    assert self.state in (VALUE_WRITE, CONTAINER_WRITE), self.state
-    if size <= 14:
-      self.__writeUByte(size << 4 | CTYPES[etype])
-    else:
-      self.__writeUByte(0xf0 | CTYPES[etype])
-      self.__writeSize(size)
-    self.__containers.append(self.state)
-    self.state = CONTAINER_WRITE
-  writeSetBegin = writeCollectionBegin
-  writeListBegin = writeCollectionBegin
-
-  def writeMapBegin(self, ktype, vtype, size):
-    assert self.state in (VALUE_WRITE, CONTAINER_WRITE), self.state
-    if size == 0:
-      self.__writeByte(0)
-    else:
-      self.__writeSize(size)
-      self.__writeUByte(CTYPES[ktype] << 4 | CTYPES[vtype])
-    self.__containers.append(self.state)
-    self.state = CONTAINER_WRITE
-
-  def writeCollectionEnd(self):
-    assert self.state == CONTAINER_WRITE, self.state
-    self.state = self.__containers.pop()
-  writeMapEnd = writeCollectionEnd
-  writeSetEnd = writeCollectionEnd
-  writeListEnd = writeCollectionEnd
-
-  def writeBool(self, bool):
-    if self.state == BOOL_WRITE:
-      if bool:
-        ctype = CompactType.TRUE
-      else:
-        ctype = CompactType.FALSE
-      self.__writeFieldHeader(ctype, self.__bool_fid)
-    elif self.state == CONTAINER_WRITE:
-      if bool:
-        self.__writeByte(CompactType.TRUE)
-      else:
-        self.__writeByte(CompactType.FALSE)
-    else:
-      raise AssertionError("Invalid state in compact protocol")
-
-  writeByte = writer(__writeByte)
-  writeI16 = writer(__writeI16)
-
-  @writer
-  def writeI32(self, i32):
-    self.__writeVarint(makeZigZag(i32, 32))
-
-  @writer
-  def writeI64(self, i64):
-    self.__writeVarint(makeZigZag(i64, 64))
-
-  @writer
-  def writeDouble(self, dub):
-    self.trans.write(pack('!d', dub))
-
-  def __writeString(self, s):
-    self.__writeSize(len(s))
-    self.trans.write(s)
-  writeString = writer(__writeString)
-
-  def readFieldBegin(self):
-    assert self.state == FIELD_READ, self.state
-    type = self.__readUByte()
-    if type & 0x0f == TType.STOP:
-      return (None, 0, 0)
-    delta = type >> 4
-    if delta == 0:
-      fid = self.__readI16()
-    else:
-      fid = self.__last_fid + delta
-    self.__last_fid = fid
-    type = type & 0x0f
-    if type == CompactType.TRUE:
-      self.state = BOOL_READ
-      self.__bool_value = True
-    elif type == CompactType.FALSE:
-      self.state = BOOL_READ
-      self.__bool_value = False
-    else:
-      self.state = VALUE_READ
-    return (None, self.__getTType(type), fid)
-
-  def readFieldEnd(self):
-    assert self.state in (VALUE_READ, BOOL_READ), self.state
-    self.state = FIELD_READ
-
-  def __readUByte(self):
-    result, = unpack('!B', self.trans.readAll(1))
-    return result
-
-  def __readByte(self):
-    result, = unpack('!b', self.trans.readAll(1))
-    return result
-
-  def __readVarint(self):
-    return readVarint(self.trans)
-
-  def __readZigZag(self):
-    return fromZigZag(self.__readVarint())
-
-  def __readSize(self):
-    result = self.__readVarint()
-    if result < 0:
-      raise TException("Length < 0")
-    return result
-
-  def readMessageBegin(self):
-    assert self.state == CLEAR
-    proto_id = self.__readUByte()
-    if proto_id != self.PROTOCOL_ID:
-      raise TProtocolException(TProtocolException.BAD_VERSION,
-          'Bad protocol id in the message: %d' % proto_id)
-    ver_type = self.__readUByte()
-    type = (ver_type & self.TYPE_MASK) >> self.TYPE_SHIFT_AMOUNT
-    version = ver_type & self.VERSION_MASK
-    if version != self.VERSION:
-      raise TProtocolException(TProtocolException.BAD_VERSION,
-          'Bad version: %d (expect %d)' % (version, self.VERSION))
-    seqid = self.__readVarint()
-    name = self.__readString()
-    return (name, type, seqid)
-
-  def readMessageEnd(self):
-    assert self.state == CLEAR
-    assert len(self.__structs) == 0
-
-  def readStructBegin(self):
-    assert self.state in (CLEAR, CONTAINER_READ, VALUE_READ), self.state
-    self.__structs.append((self.state, self.__last_fid))
-    self.state = FIELD_READ
-    self.__last_fid = 0
-
-  def readStructEnd(self):
-    assert self.state == FIELD_READ
-    self.state, self.__last_fid = self.__structs.pop()
-
-  def readCollectionBegin(self):
-    assert self.state in (VALUE_READ, CONTAINER_READ), self.state
-    size_type = self.__readUByte()
-    size = size_type >> 4
-    type = self.__getTType(size_type)
-    if size == 15:
-      size = self.__readSize()
-    self.__containers.append(self.state)
-    self.state = CONTAINER_READ
-    return type, size
-  readSetBegin = readCollectionBegin
-  readListBegin = readCollectionBegin
-
-  def readMapBegin(self):
-    assert self.state in (VALUE_READ, CONTAINER_READ), self.state
-    size = self.__readSize()
-    types = 0
-    if size > 0:
-      types = self.__readUByte()
-    vtype = self.__getTType(types)
-    ktype = self.__getTType(types >> 4)
-    self.__containers.append(self.state)
-    self.state = CONTAINER_READ
-    return (ktype, vtype, size)
-
-  def readCollectionEnd(self):
-    assert self.state == CONTAINER_READ, self.state
-    self.state = self.__containers.pop()
-  readSetEnd = readCollectionEnd
-  readListEnd = readCollectionEnd
-  readMapEnd = readCollectionEnd
-
-  def readBool(self):
-    if self.state == BOOL_READ:
-      return self.__bool_value == CompactType.TRUE
-    elif self.state == CONTAINER_READ:
-      return self.__readByte() == CompactType.TRUE
-    else:
-      raise AssertionError("Invalid state in compact protocol: %d" %
-                           self.state)
-
-  readByte = reader(__readByte)
-  __readI16 = __readZigZag
-  readI16 = reader(__readZigZag)
-  readI32 = reader(__readZigZag)
-  readI64 = reader(__readZigZag)
-
-  @reader
-  def readDouble(self):
-    buff = self.trans.readAll(8)
-    val, = unpack('!d', buff)
-    return val
-
-  def __readString(self):
-    len = self.__readSize()
-    return self.trans.readAll(len)
-  readString = reader(__readString)
-
-  def __getTType(self, byte):
-    return TTYPES[byte & 0x0f]
-
-
-class TCompactProtocolFactory:
-  def __init__(self):
-    pass
-
-  def getProtocol(self, trans):
-    return TCompactProtocol(trans)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
deleted file mode 100644
index 7d9d7aa..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TJSONProtocol.py
+++ /dev/null
@@ -1,552 +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.
-#
-
-import base64
-import json
-import math
-
-from TProtocol import TType, TProtocolBase, TProtocolException
-
-
-__all__ = ['TJSONProtocol',
-           'TJSONProtocolFactory',
-           'TSimpleJSONProtocol',
-           'TSimpleJSONProtocolFactory']
-
-VERSION = 1
-
-COMMA = ','
-COLON = ':'
-LBRACE = '{'
-RBRACE = '}'
-LBRACKET = '['
-RBRACKET = ']'
-QUOTE = '"'
-BACKSLASH = '\\'
-ZERO = '0'
-
-ESCSEQ = '\\u00'
-ESCAPE_CHAR = '"\\bfnrt'
-ESCAPE_CHAR_VALS = ['"', '\\', '\b', '\f', '\n', '\r', '\t']
-NUMERIC_CHAR = '+-.0123456789Ee'
-
-CTYPES = {TType.BOOL:       'tf',
-          TType.BYTE:       'i8',
-          TType.I16:        'i16',
-          TType.I32:        'i32',
-          TType.I64:        'i64',
-          TType.DOUBLE:     'dbl',
-          TType.STRING:     'str',
-          TType.STRUCT:     'rec',
-          TType.LIST:       'lst',
-          TType.SET:        'set',
-          TType.MAP:        'map'}
-
-JTYPES = {}
-for key in CTYPES.keys():
-  JTYPES[CTYPES[key]] = key
-
-
-class JSONBaseContext(object):
-
-  def __init__(self, protocol):
-    self.protocol = protocol
-    self.first = True
-
-  def doIO(self, function):
-    pass
-  
-  def write(self):
-    pass
-
-  def read(self):
-    pass
-
-  def escapeNum(self):
-    return False
-
-  def __str__(self):
-    return self.__class__.__name__
-
-
-class JSONListContext(JSONBaseContext):
-    
-  def doIO(self, function):
-    if self.first is True:
-      self.first = False
-    else:
-      function(COMMA)
-
-  def write(self):
-    self.doIO(self.protocol.trans.write)
-
-  def read(self):
-    self.doIO(self.protocol.readJSONSyntaxChar)
-
-
-class JSONPairContext(JSONBaseContext):
-  
-  def __init__(self, protocol):
-    super(JSONPairContext, self).__init__(protocol)
-    self.colon = True
-
-  def doIO(self, function):
-    if self.first:
-      self.first = False
-      self.colon = True
-    else:
-      function(COLON if self.colon else COMMA)
-      self.colon = not self.colon
-
-  def write(self):
-    self.doIO(self.protocol.trans.write)
-
-  def read(self):
-    self.doIO(self.protocol.readJSONSyntaxChar)
-
-  def escapeNum(self):
-    return self.colon
-
-  def __str__(self):
-    return '%s, colon=%s' % (self.__class__.__name__, self.colon)
-
-
-class LookaheadReader():
-  hasData = False
-  data = ''
-
-  def __init__(self, protocol):
-    self.protocol = protocol
-
-  def read(self):
-    if self.hasData is True:
-      self.hasData = False
-    else:
-      self.data = self.protocol.trans.read(1)
-    return self.data
-
-  def peek(self):
-    if self.hasData is False:
-      self.data = self.protocol.trans.read(1)
-    self.hasData = True
-    return self.data
-
-class TJSONProtocolBase(TProtocolBase):
-
-  def __init__(self, trans):
-    TProtocolBase.__init__(self, trans)
-    self.resetWriteContext()
-    self.resetReadContext()
-
-  def resetWriteContext(self):
-    self.context = JSONBaseContext(self)
-    self.contextStack = [self.context]
-
-  def resetReadContext(self):
-    self.resetWriteContext()
-    self.reader = LookaheadReader(self)
-
-  def pushContext(self, ctx):
-    self.contextStack.append(ctx)
-    self.context = ctx
-
-  def popContext(self):
-    self.contextStack.pop()
-    if self.contextStack:
-      self.context = self.contextStack[-1]
-    else:
-      self.context = JSONBaseContext(self)
-
-  def writeJSONString(self, string):
-    self.context.write()
-    self.trans.write(json.dumps(string))
-
-  def writeJSONNumber(self, number):
-    self.context.write()
-    jsNumber = str(number)
-    if self.context.escapeNum():
-      jsNumber = "%s%s%s" % (QUOTE, jsNumber,  QUOTE)
-    self.trans.write(jsNumber)
-
-  def writeJSONBase64(self, binary):
-    self.context.write()
-    self.trans.write(QUOTE)
-    self.trans.write(base64.b64encode(binary))
-    self.trans.write(QUOTE)
-
-  def writeJSONObjectStart(self):
-    self.context.write()
-    self.trans.write(LBRACE)
-    self.pushContext(JSONPairContext(self))
-
-  def writeJSONObjectEnd(self):
-    self.popContext()
-    self.trans.write(RBRACE)
-
-  def writeJSONArrayStart(self):
-    self.context.write()
-    self.trans.write(LBRACKET)
-    self.pushContext(JSONListContext(self))
-
-  def writeJSONArrayEnd(self):
-    self.popContext()
-    self.trans.write(RBRACKET)
-
-  def readJSONSyntaxChar(self, character):
-    current = self.reader.read()
-    if character != current:
-      raise TProtocolException(TProtocolException.INVALID_DATA,
-                               "Unexpected character: %s" % current)
-
-  def readJSONString(self, skipContext):
-    string = []
-    if skipContext is False:
-      self.context.read()
-    self.readJSONSyntaxChar(QUOTE)
-    while True:
-      character = self.reader.read()
-      if character == QUOTE:
-        break
-      if character == ESCSEQ[0]:
-        character = self.reader.read()
-        if character == ESCSEQ[1]:
-          self.readJSONSyntaxChar(ZERO)
-          self.readJSONSyntaxChar(ZERO)
-          character = json.JSONDecoder().decode('"\u00%s"' % self.trans.read(2))
-        else:
-          off = ESCAPE_CHAR.find(character)
-          if off == -1:
-            raise TProtocolException(TProtocolException.INVALID_DATA,
-                                     "Expected control char")
-          character = ESCAPE_CHAR_VALS[off]
-      string.append(character)
-    return ''.join(string)
-
-  def isJSONNumeric(self, character):
-    return (True if NUMERIC_CHAR.find(character) != - 1 else False)
-
-  def readJSONQuotes(self):
-    if (self.context.escapeNum()):
-      self.readJSONSyntaxChar(QUOTE)
-
-  def readJSONNumericChars(self):
-    numeric = []
-    while True:
-      character = self.reader.peek()
-      if self.isJSONNumeric(character) is False:
-        break
-      numeric.append(self.reader.read())
-    return ''.join(numeric)
-
-  def readJSONInteger(self):
-    self.context.read()
-    self.readJSONQuotes()
-    numeric = self.readJSONNumericChars()
-    self.readJSONQuotes()
-    try:
-      return int(numeric)
-    except ValueError:
-      raise TProtocolException(TProtocolException.INVALID_DATA,
-                               "Bad data encounted in numeric data")
-
-  def readJSONDouble(self):
-    self.context.read()
-    if self.reader.peek() == QUOTE:
-      string  = self.readJSONString(True)
-      try:
-        double = float(string)
-        if (self.context.escapeNum is False and
-            not math.isinf(double) and
-            not math.isnan(double)):
-          raise TProtocolException(TProtocolException.INVALID_DATA,
-                                   "Numeric data unexpectedly quoted")
-        return double
-      except ValueError:
-        raise TProtocolException(TProtocolException.INVALID_DATA,
-                                 "Bad data encounted in numeric data")
-    else:
-      if self.context.escapeNum() is True:
-        self.readJSONSyntaxChar(QUOTE)
-      try:
-        return float(self.readJSONNumericChars())
-      except ValueError:
-        raise TProtocolException(TProtocolException.INVALID_DATA,
-                                 "Bad data encounted in numeric data")
-
-  def readJSONBase64(self):
-    string = self.readJSONString(False)
-    return base64.b64decode(string)
-
-  def readJSONObjectStart(self):
-    self.context.read()
-    self.readJSONSyntaxChar(LBRACE)
-    self.pushContext(JSONPairContext(self))
-
-  def readJSONObjectEnd(self):
-    self.readJSONSyntaxChar(RBRACE)
-    self.popContext()
-
-  def readJSONArrayStart(self):
-    self.context.read()
-    self.readJSONSyntaxChar(LBRACKET)
-    self.pushContext(JSONListContext(self))
-
-  def readJSONArrayEnd(self):
-    self.readJSONSyntaxChar(RBRACKET)
-    self.popContext()
-
-
-class TJSONProtocol(TJSONProtocolBase):
-
-  def readMessageBegin(self):
-    self.resetReadContext()
-    self.readJSONArrayStart()
-    if self.readJSONInteger() != VERSION:
-      raise TProtocolException(TProtocolException.BAD_VERSION,
-                               "Message contained bad version.")
-    name = self.readJSONString(False)
-    typen = self.readJSONInteger()
-    seqid = self.readJSONInteger()
-    return (name, typen, seqid)
-
-  def readMessageEnd(self):
-    self.readJSONArrayEnd()
-
-  def readStructBegin(self):
-    self.readJSONObjectStart()
-
-  def readStructEnd(self):
-    self.readJSONObjectEnd()
-
-  def readFieldBegin(self):
-    character = self.reader.peek()
-    ttype = 0
-    id = 0
-    if character == RBRACE:
-      ttype = TType.STOP
-    else:
-      id = self.readJSONInteger()
-      self.readJSONObjectStart()
-      ttype = JTYPES[self.readJSONString(False)]
-    return (None, ttype, id)
-
-  def readFieldEnd(self):
-    self.readJSONObjectEnd()
-
-  def readMapBegin(self):
-    self.readJSONArrayStart()
-    keyType = JTYPES[self.readJSONString(False)]
-    valueType = JTYPES[self.readJSONString(False)]
-    size = self.readJSONInteger()
-    self.readJSONObjectStart()
-    return (keyType, valueType, size)
-
-  def readMapEnd(self):
-    self.readJSONObjectEnd()
-    self.readJSONArrayEnd()
-
-  def readCollectionBegin(self):
-    self.readJSONArrayStart()
-    elemType = JTYPES[self.readJSONString(False)]
-    size = self.readJSONInteger()
-    return (elemType, size)
-  readListBegin = readCollectionBegin
-  readSetBegin = readCollectionBegin
-
-  def readCollectionEnd(self):
-    self.readJSONArrayEnd()
-  readSetEnd = readCollectionEnd
-  readListEnd = readCollectionEnd
-
-  def readBool(self):
-    return (False if self.readJSONInteger() == 0 else True)
-
-  def readNumber(self):
-    return self.readJSONInteger()
-  readByte = readNumber
-  readI16 = readNumber
-  readI32 = readNumber
-  readI64 = readNumber
-
-  def readDouble(self):
-    return self.readJSONDouble()
-
-  def readString(self):
-    return self.readJSONString(False)
-
-  def readBinary(self):
-    return self.readJSONBase64()
-
-  def writeMessageBegin(self, name, request_type, seqid):
-    self.resetWriteContext()
-    self.writeJSONArrayStart()
-    self.writeJSONNumber(VERSION)
-    self.writeJSONString(name)
-    self.writeJSONNumber(request_type)
-    self.writeJSONNumber(seqid)
-
-  def writeMessageEnd(self):
-    self.writeJSONArrayEnd()
-
-  def writeStructBegin(self, name):
-    self.writeJSONObjectStart()
-
-  def writeStructEnd(self):
-    self.writeJSONObjectEnd()
-
-  def writeFieldBegin(self, name, ttype, id):
-    self.writeJSONNumber(id)
-    self.writeJSONObjectStart()
-    self.writeJSONString(CTYPES[ttype])
-
-  def writeFieldEnd(self):
-    self.writeJSONObjectEnd()
-
-  def writeFieldStop(self):
-    pass
-
-  def writeMapBegin(self, ktype, vtype, size):
-    self.writeJSONArrayStart()
-    self.writeJSONString(CTYPES[ktype])
-    self.writeJSONString(CTYPES[vtype])
-    self.writeJSONNumber(size)
-    self.writeJSONObjectStart()
-
-  def writeMapEnd(self):
-    self.writeJSONObjectEnd()
-    self.writeJSONArrayEnd()
-    
-  def writeListBegin(self, etype, size):
-    self.writeJSONArrayStart()
-    self.writeJSONString(CTYPES[etype])
-    self.writeJSONNumber(size)
-    
-  def writeListEnd(self):
-    self.writeJSONArrayEnd()
-
-  def writeSetBegin(self, etype, size):
-    self.writeJSONArrayStart()
-    self.writeJSONString(CTYPES[etype])
-    self.writeJSONNumber(size)
-    
-  def writeSetEnd(self):
-    self.writeJSONArrayEnd()
-
-  def writeBool(self, boolean):
-    self.writeJSONNumber(1 if boolean is True else 0)
-
-  def writeInteger(self, integer):
-    self.writeJSONNumber(integer)
-  writeByte = writeInteger
-  writeI16 = writeInteger
-  writeI32 = writeInteger
-  writeI64 = writeInteger
-
-  def writeDouble(self, dbl):
-    self.writeJSONNumber(dbl)
-
-  def writeString(self, string):
-    self.writeJSONString(string)
-    
-  def writeBinary(self, binary):
-    self.writeJSONBase64(binary)
-
-
-class TJSONProtocolFactory:
-
-  def getProtocol(self, trans):
-    return TJSONProtocol(trans)
-
-
-class TSimpleJSONProtocol(TJSONProtocolBase):
-    """Simple, readable, write-only JSON protocol.
-    
-    Useful for interacting with scripting languages.
-    """
-
-    def readMessageBegin(self):
-        raise NotImplementedError()
-    
-    def readMessageEnd(self):
-        raise NotImplementedError()
-    
-    def readStructBegin(self):
-        raise NotImplementedError()
-    
-    def readStructEnd(self):
-        raise NotImplementedError()
-    
-    def writeMessageBegin(self, name, request_type, seqid):
-        self.resetWriteContext()
-    
-    def writeMessageEnd(self):
-        pass
-    
-    def writeStructBegin(self, name):
-        self.writeJSONObjectStart()
-    
-    def writeStructEnd(self):
-        self.writeJSONObjectEnd()
-      
-    def writeFieldBegin(self, name, ttype, fid):
-        self.writeJSONString(name)
-    
-    def writeFieldEnd(self):
-        pass
-    
-    def writeMapBegin(self, ktype, vtype, size):
-        self.writeJSONObjectStart()
-    
-    def writeMapEnd(self):
-        self.writeJSONObjectEnd()
-    
-    def _writeCollectionBegin(self, etype, size):
-        self.writeJSONArrayStart()
-    
-    def _writeCollectionEnd(self):
-        self.writeJSONArrayEnd()
-    writeListBegin = _writeCollectionBegin
-    writeListEnd = _writeCollectionEnd
-    writeSetBegin = _writeCollectionBegin
-    writeSetEnd = _writeCollectionEnd
-
-    def writeInteger(self, integer):
-        self.writeJSONNumber(integer)
-    writeByte = writeInteger
-    writeI16 = writeInteger
-    writeI32 = writeInteger
-    writeI64 = writeInteger
-    
-    def writeBool(self, boolean):
-        self.writeJSONNumber(1 if boolean is True else 0)
-
-    def writeDouble(self, dbl):
-        self.writeJSONNumber(dbl)
-    
-    def writeString(self, string):
-        self.writeJSONString(string)
-      
-    def writeBinary(self, binary):
-        self.writeJSONBase64(binary)
-
-
-class TSimpleJSONProtocolFactory(object):
-
-    def getProtocol(self, trans):
-        return TSimpleJSONProtocol(trans)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TProtocol.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TProtocol.py
deleted file mode 100644
index 0154641..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/TProtocol.py
+++ /dev/null
@@ -1,406 +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.
-#
-
-from ..Thrift import *
-
-
-class TProtocolException(TException):
-  """Custom Protocol Exception class"""
-
-  UNKNOWN = 0
-  INVALID_DATA = 1
-  NEGATIVE_SIZE = 2
-  SIZE_LIMIT = 3
-  BAD_VERSION = 4
-
-  def __init__(self, type=UNKNOWN, message=None):
-    TException.__init__(self, message)
-    self.type = type
-
-
-class TProtocolBase:
-  """Base class for Thrift protocol driver."""
-
-  def __init__(self, trans):
-    self.trans = trans
-
-  def writeMessageBegin(self, name, ttype, seqid):
-    pass
-
-  def writeMessageEnd(self):
-    pass
-
-  def writeStructBegin(self, name):
-    pass
-
-  def writeStructEnd(self):
-    pass
-
-  def writeFieldBegin(self, name, ttype, fid):
-    pass
-
-  def writeFieldEnd(self):
-    pass
-
-  def writeFieldStop(self):
-    pass
-
-  def writeMapBegin(self, ktype, vtype, size):
-    pass
-
-  def writeMapEnd(self):
-    pass
-
-  def writeListBegin(self, etype, size):
-    pass
-
-  def writeListEnd(self):
-    pass
-
-  def writeSetBegin(self, etype, size):
-    pass
-
-  def writeSetEnd(self):
-    pass
-
-  def writeBool(self, bool_val):
-    pass
-
-  def writeByte(self, byte):
-    pass
-
-  def writeI16(self, i16):
-    pass
-
-  def writeI32(self, i32):
-    pass
-
-  def writeI64(self, i64):
-    pass
-
-  def writeDouble(self, dub):
-    pass
-
-  def writeString(self, str_val):
-    pass
-
-  def readMessageBegin(self):
-    pass
-
-  def readMessageEnd(self):
-    pass
-
-  def readStructBegin(self):
-    pass
-
-  def readStructEnd(self):
-    pass
-
-  def readFieldBegin(self):
-    pass
-
-  def readFieldEnd(self):
-    pass
-
-  def readMapBegin(self):
-    pass
-
-  def readMapEnd(self):
-    pass
-
-  def readListBegin(self):
-    pass
-
-  def readListEnd(self):
-    pass
-
-  def readSetBegin(self):
-    pass
-
-  def readSetEnd(self):
-    pass
-
-  def readBool(self):
-    pass
-
-  def readByte(self):
-    pass
-
-  def readI16(self):
-    pass
-
-  def readI32(self):
-    pass
-
-  def readI64(self):
-    pass
-
-  def readDouble(self):
-    pass
-
-  def readString(self):
-    pass
-
-  def skip(self, ttype):
-    if ttype == TType.STOP:
-      return
-    elif ttype == TType.BOOL:
-      self.readBool()
-    elif ttype == TType.BYTE:
-      self.readByte()
-    elif ttype == TType.I16:
-      self.readI16()
-    elif ttype == TType.I32:
-      self.readI32()
-    elif ttype == TType.I64:
-      self.readI64()
-    elif ttype == TType.DOUBLE:
-      self.readDouble()
-    elif ttype == TType.STRING:
-      self.readString()
-    elif ttype == TType.STRUCT:
-      name = self.readStructBegin()
-      while True:
-        (name, ttype, id) = self.readFieldBegin()
-        if ttype == TType.STOP:
-          break
-        self.skip(ttype)
-        self.readFieldEnd()
-      self.readStructEnd()
-    elif ttype == TType.MAP:
-      (ktype, vtype, size) = self.readMapBegin()
-      for i in xrange(size):
-        self.skip(ktype)
-        self.skip(vtype)
-      self.readMapEnd()
-    elif ttype == TType.SET:
-      (etype, size) = self.readSetBegin()
-      for i in xrange(size):
-        self.skip(etype)
-      self.readSetEnd()
-    elif ttype == TType.LIST:
-      (etype, size) = self.readListBegin()
-      for i in xrange(size):
-        self.skip(etype)
-      self.readListEnd()
-
-  # tuple of: ( 'reader method' name, is_container bool, 'writer_method' name )
-  _TTYPE_HANDLERS = (
-       (None, None, False),  # 0 TType.STOP
-       (None, None, False),  # 1 TType.VOID # TODO: handle void?
-       ('readBool', 'writeBool', False),  # 2 TType.BOOL
-       ('readByte',  'writeByte', False),  # 3 TType.BYTE and I08
-       ('readDouble', 'writeDouble', False),  # 4 TType.DOUBLE
-       (None, None, False),  # 5 undefined
-       ('readI16', 'writeI16', False),  # 6 TType.I16
-       (None, None, False),  # 7 undefined
-       ('readI32', 'writeI32', False),  # 8 TType.I32
-       (None, None, False),  # 9 undefined
-       ('readI64', 'writeI64', False),  # 10 TType.I64
-       ('readString', 'writeString', False),  # 11 TType.STRING and UTF7
-       ('readContainerStruct', 'writeContainerStruct', True),  # 12 *.STRUCT
-       ('readContainerMap', 'writeContainerMap', True),  # 13 TType.MAP
-       ('readContainerSet', 'writeContainerSet', True),  # 14 TType.SET
-       ('readContainerList', 'writeContainerList', True),  # 15 TType.LIST
-       (None, None, False),  # 16 TType.UTF8 # TODO: handle utf8 types?
-       (None, None, False)  # 17 TType.UTF16 # TODO: handle utf16 types?
-      )
-
-  def readFieldByTType(self, ttype, spec):
-    try:
-      (r_handler, w_handler, is_container) = self._TTYPE_HANDLERS[ttype]
-    except IndexError:
-      raise TProtocolException(type=TProtocolException.INVALID_DATA,
-                               message='Invalid field type %d' % (ttype))
-    if r_handler is None:
-      raise TProtocolException(type=TProtocolException.INVALID_DATA,
-                               message='Invalid field type %d' % (ttype))
-    reader = getattr(self, r_handler)
-    if not is_container:
-      return reader()
-    return reader(spec)
-
-  def readContainerList(self, spec):
-    results = []
-    ttype, tspec = spec[0], spec[1]
-    r_handler = self._TTYPE_HANDLERS[ttype][0]
-    reader = getattr(self, r_handler)
-    (list_type, list_len) = self.readListBegin()
-    if tspec is None:
-      # list values are simple types
-      for idx in xrange(list_len):
-        results.append(reader())
-    else:
-      # this is like an inlined readFieldByTType
-      container_reader = self._TTYPE_HANDLERS[list_type][0]
-      val_reader = getattr(self, container_reader)
-      for idx in xrange(list_len):
-        val = val_reader(tspec)
-        results.append(val)
-    self.readListEnd()
-    return results
-
-  def readContainerSet(self, spec):
-    results = set()
-    ttype, tspec = spec[0], spec[1]
-    r_handler = self._TTYPE_HANDLERS[ttype][0]
-    reader = getattr(self, r_handler)
-    (set_type, set_len) = self.readSetBegin()
-    if tspec is None:
-      # set members are simple types
-      for idx in xrange(set_len):
-        results.add(reader())
-    else:
-      container_reader = self._TTYPE_HANDLERS[set_type][0]
-      val_reader = getattr(self, container_reader)
-      for idx in xrange(set_len):
-        results.add(val_reader(tspec))
-    self.readSetEnd()
-    return results
-
-  def readContainerStruct(self, spec):
-    (obj_class, obj_spec) = spec
-    obj = obj_class()
-    obj.read(self)
-    return obj
-
-  def readContainerMap(self, spec):
-    results = dict()
-    key_ttype, key_spec = spec[0], spec[1]
-    val_ttype, val_spec = spec[2], spec[3]
-    (map_ktype, map_vtype, map_len) = self.readMapBegin()
-    # TODO: compare types we just decoded with thrift_spec and
-    # abort/skip if types disagree
-    key_reader = getattr(self, self._TTYPE_HANDLERS[key_ttype][0])
-    val_reader = getattr(self, self._TTYPE_HANDLERS[val_ttype][0])
-    # list values are simple types
-    for idx in xrange(map_len):
-      if key_spec is None:
-        k_val = key_reader()
-      else:
-        k_val = self.readFieldByTType(key_ttype, key_spec)
-      if val_spec is None:
-        v_val = val_reader()
-      else:
-        v_val = self.readFieldByTType(val_ttype, val_spec)
-      # this raises a TypeError with unhashable keys types
-      # i.e. this fails: d=dict(); d[[0,1]] = 2
-      results[k_val] = v_val
-    self.readMapEnd()
-    return results
-
-  def readStruct(self, obj, thrift_spec):
-    self.readStructBegin()
-    while True:
-      (fname, ftype, fid) = self.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      try:
-        field = thrift_spec[fid]
-      except IndexError:
-        self.skip(ftype)
-      else:
-        if field is not None and ftype == field[1]:
-          fname = field[2]
-          fspec = field[3]
-          val = self.readFieldByTType(ftype, fspec)
-          setattr(obj, fname, val)
-        else:
-          self.skip(ftype)
-      self.readFieldEnd()
-    self.readStructEnd()
-
-  def writeContainerStruct(self, val, spec):
-    val.write(self)
-
-  def writeContainerList(self, val, spec):
-    self.writeListBegin(spec[0], len(val))
-    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[spec[0]]
-    e_writer = getattr(self, w_handler)
-    if not is_container:
-      for elem in val:
-        e_writer(elem)
-    else:
-      for elem in val:
-        e_writer(elem, spec[1])
-    self.writeListEnd()
-
-  def writeContainerSet(self, val, spec):
-    self.writeSetBegin(spec[0], len(val))
-    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[spec[0]]
-    e_writer = getattr(self, w_handler)
-    if not is_container:
-      for elem in val:
-        e_writer(elem)
-    else:
-      for elem in val:
-        e_writer(elem, spec[1])
-    self.writeSetEnd()
-
-  def writeContainerMap(self, val, spec):
-    k_type = spec[0]
-    v_type = spec[2]
-    ignore, ktype_name, k_is_container = self._TTYPE_HANDLERS[k_type]
-    ignore, vtype_name, v_is_container = self._TTYPE_HANDLERS[v_type]
-    k_writer = getattr(self, ktype_name)
-    v_writer = getattr(self, vtype_name)
-    self.writeMapBegin(k_type, v_type, len(val))
-    for m_key, m_val in val.iteritems():
-      if not k_is_container:
-        k_writer(m_key)
-      else:
-        k_writer(m_key, spec[1])
-      if not v_is_container:
-        v_writer(m_val)
-      else:
-        v_writer(m_val, spec[3])
-    self.writeMapEnd()
-
-  def writeStruct(self, obj, thrift_spec):
-    self.writeStructBegin(obj.__class__.__name__)
-    for field in thrift_spec:
-      if field is None:
-        continue
-      fname = field[2]
-      val = getattr(obj, fname)
-      if val is None:
-        # skip writing out unset fields
-        continue
-      fid = field[0]
-      ftype = field[1]
-      fspec = field[3]
-      # get the writer method for this value
-      self.writeFieldBegin(fname, ftype, fid)
-      self.writeFieldByTType(ftype, val, fspec)
-      self.writeFieldEnd()
-    self.writeFieldStop()
-    self.writeStructEnd()
-
-  def writeFieldByTType(self, ttype, val, spec):
-    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[ttype]
-    writer = getattr(self, w_handler)
-    if is_container:
-      writer(val, spec)
-    else:
-      writer(val)
-
-
-class TProtocolFactory:
-  def getProtocol(self, trans):
-    pass

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/__init__.py
deleted file mode 100644
index 7eefb45..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/__init__.py
+++ /dev/null
@@ -1,20 +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.
-#
-
-__all__ = ['fastbinary', 'TBase', 'TBinaryProtocol', 'TCompactProtocol', 'TJSONProtocol', 'TProtocol']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/fastbinary.c
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/fastbinary.c b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/fastbinary.c
deleted file mode 100644
index 2ce5660..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/protocol/fastbinary.c
+++ /dev/null
@@ -1,1219 +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.
- */
-
-#include <Python.h>
-#include "cStringIO.h"
-#include <stdint.h>
-#ifndef _WIN32
-# include <stdbool.h>
-# include <netinet/in.h>
-#else
-# include <WinSock2.h>
-# pragma comment (lib, "ws2_32.lib")
-# define BIG_ENDIAN (4321)
-# define LITTLE_ENDIAN (1234)
-# define BYTE_ORDER LITTLE_ENDIAN
-# if defined(_MSC_VER) && _MSC_VER < 1600
-   typedef int _Bool;
-#  define bool _Bool
-#  define false 0 
-#  define true 1
-# endif
-# define inline __inline
-#endif
-
-/* Fix endianness issues on Solaris */
-#if defined (__SVR4) && defined (__sun)
- #if defined(__i386) && !defined(__i386__)
-  #define __i386__
- #endif
-
- #ifndef BIG_ENDIAN
-  #define BIG_ENDIAN (4321)
- #endif
- #ifndef LITTLE_ENDIAN
-  #define LITTLE_ENDIAN (1234)
- #endif
-
- /* I386 is LE, even on Solaris */
- #if !defined(BYTE_ORDER) && defined(__i386__)
-  #define BYTE_ORDER LITTLE_ENDIAN
- #endif
-#endif
-
-// TODO(dreiss): defval appears to be unused.  Look into removing it.
-// TODO(dreiss): Make parse_spec_args recursive, and cache the output
-//               permanently in the object.  (Malloc and orphan.)
-// TODO(dreiss): Why do we need cStringIO for reading, why not just char*?
-//               Can cStringIO let us work with a BufferedTransport?
-// TODO(dreiss): Don't ignore the rv from cwrite (maybe).
-
-/* ====== BEGIN UTILITIES ====== */
-
-#define INIT_OUTBUF_SIZE 128
-
-// Stolen out of TProtocol.h.
-// It would be a huge pain to have both get this from one place.
-typedef enum TType {
-  T_STOP       = 0,
-  T_VOID       = 1,
-  T_BOOL       = 2,
-  T_BYTE       = 3,
-  T_I08        = 3,
-  T_I16        = 6,
-  T_I32        = 8,
-  T_U64        = 9,
-  T_I64        = 10,
-  T_DOUBLE     = 4,
-  T_STRING     = 11,
-  T_UTF7       = 11,
-  T_STRUCT     = 12,
-  T_MAP        = 13,
-  T_SET        = 14,
-  T_LIST       = 15,
-  T_UTF8       = 16,
-  T_UTF16      = 17
-} TType;
-
-#ifndef __BYTE_ORDER
-# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
-#  define __BYTE_ORDER BYTE_ORDER
-#  define __LITTLE_ENDIAN LITTLE_ENDIAN
-#  define __BIG_ENDIAN BIG_ENDIAN
-# else
-#  error "Cannot determine endianness"
-# endif
-#endif
-
-// Same comment as the enum.  Sorry.
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define ntohll(n) (n)
-# define htonll(n) (n)
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-# if defined(__GNUC__) && defined(__GLIBC__)
-#  include <byteswap.h>
-#  define ntohll(n) bswap_64(n)
-#  define htonll(n) bswap_64(n)
-# else /* GNUC & GLIBC */
-#  define ntohll(n) ( (((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32) )
-#  define htonll(n) ( (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32) )
-# endif /* GNUC & GLIBC */
-#else /* __BYTE_ORDER */
-# error "Can't define htonll or ntohll!"
-#endif
-
-// Doing a benchmark shows that interning actually makes a difference, amazingly.
-#define INTERN_STRING(value) _intern_ ## value
-
-#define INT_CONV_ERROR_OCCURRED(v) ( ((v) == -1) && PyErr_Occurred() )
-#define CHECK_RANGE(v, min, max) ( ((v) <= (max)) && ((v) >= (min)) )
-
-// Py_ssize_t was not defined before Python 2.5
-#if (PY_VERSION_HEX < 0x02050000)
-typedef int Py_ssize_t;
-#endif
-
-/**
- * A cache of the spec_args for a set or list,
- * so we don't have to keep calling PyTuple_GET_ITEM.
- */
-typedef struct {
-  TType element_type;
-  PyObject* typeargs;
-} SetListTypeArgs;
-
-/**
- * A cache of the spec_args for a map,
- * so we don't have to keep calling PyTuple_GET_ITEM.
- */
-typedef struct {
-  TType ktag;
-  TType vtag;
-  PyObject* ktypeargs;
-  PyObject* vtypeargs;
-} MapTypeArgs;
-
-/**
- * A cache of the spec_args for a struct,
- * so we don't have to keep calling PyTuple_GET_ITEM.
- */
-typedef struct {
-  PyObject* klass;
-  PyObject* spec;
-} StructTypeArgs;
-
-/**
- * A cache of the item spec from a struct specification,
- * so we don't have to keep calling PyTuple_GET_ITEM.
- */
-typedef struct {
-  int tag;
-  TType type;
-  PyObject* attrname;
-  PyObject* typeargs;
-  PyObject* defval;
-} StructItemSpec;
-
-/**
- * A cache of the two key attributes of a CReadableTransport,
- * so we don't have to keep calling PyObject_GetAttr.
- */
-typedef struct {
-  PyObject* stringiobuf;
-  PyObject* refill_callable;
-} DecodeBuffer;
-
-/** Pointer to interned string to speed up attribute lookup. */
-static PyObject* INTERN_STRING(cstringio_buf);
-/** Pointer to interned string to speed up attribute lookup. */
-static PyObject* INTERN_STRING(cstringio_refill);
-
-static inline bool
-check_ssize_t_32(Py_ssize_t len) {
-  // error from getting the int
-  if (INT_CONV_ERROR_OCCURRED(len)) {
-    return false;
-  }
-  if (!CHECK_RANGE(len, 0, INT32_MAX)) {
-    PyErr_SetString(PyExc_OverflowError, "string size out of range");
-    return false;
-  }
-  return true;
-}
-
-static inline bool
-parse_pyint(PyObject* o, int32_t* ret, int32_t min, int32_t max) {
-  long val = PyInt_AsLong(o);
-
-  if (INT_CONV_ERROR_OCCURRED(val)) {
-    return false;
-  }
-  if (!CHECK_RANGE(val, min, max)) {
-    PyErr_SetString(PyExc_OverflowError, "int out of range");
-    return false;
-  }
-
-  *ret = (int32_t) val;
-  return true;
-}
-
-
-/* --- FUNCTIONS TO PARSE STRUCT SPECIFICATOINS --- */
-
-static bool
-parse_set_list_args(SetListTypeArgs* dest, PyObject* typeargs) {
-  if (PyTuple_Size(typeargs) != 2) {
-    PyErr_SetString(PyExc_TypeError, "expecting tuple of size 2 for list/set type args");
-    return false;
-  }
-
-  dest->element_type = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 0));
-  if (INT_CONV_ERROR_OCCURRED(dest->element_type)) {
-    return false;
-  }
-
-  dest->typeargs = PyTuple_GET_ITEM(typeargs, 1);
-
-  return true;
-}
-
-static bool
-parse_map_args(MapTypeArgs* dest, PyObject* typeargs) {
-  if (PyTuple_Size(typeargs) != 4) {
-    PyErr_SetString(PyExc_TypeError, "expecting 4 arguments for typeargs to map");
-    return false;
-  }
-
-  dest->ktag = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 0));
-  if (INT_CONV_ERROR_OCCURRED(dest->ktag)) {
-    return false;
-  }
-
-  dest->vtag = PyInt_AsLong(PyTuple_GET_ITEM(typeargs, 2));
-  if (INT_CONV_ERROR_OCCURRED(dest->vtag)) {
-    return false;
-  }
-
-  dest->ktypeargs = PyTuple_GET_ITEM(typeargs, 1);
-  dest->vtypeargs = PyTuple_GET_ITEM(typeargs, 3);
-
-  return true;
-}
-
-static bool
-parse_struct_args(StructTypeArgs* dest, PyObject* typeargs) {
-  if (PyTuple_Size(typeargs) != 2) {
-    PyErr_SetString(PyExc_TypeError, "expecting tuple of size 2 for struct args");
-    return false;
-  }
-
-  dest->klass = PyTuple_GET_ITEM(typeargs, 0);
-  dest->spec = PyTuple_GET_ITEM(typeargs, 1);
-
-  return true;
-}
-
-static int
-parse_struct_item_spec(StructItemSpec* dest, PyObject* spec_tuple) {
-
-  // i'd like to use ParseArgs here, but it seems to be a bottleneck.
-  if (PyTuple_Size(spec_tuple) != 5) {
-    PyErr_SetString(PyExc_TypeError, "expecting 5 arguments for spec tuple");
-    return false;
-  }
-
-  dest->tag = PyInt_AsLong(PyTuple_GET_ITEM(spec_tuple, 0));
-  if (INT_CONV_ERROR_OCCURRED(dest->tag)) {
-    return false;
-  }
-
-  dest->type = PyInt_AsLong(PyTuple_GET_ITEM(spec_tuple, 1));
-  if (INT_CONV_ERROR_OCCURRED(dest->type)) {
-    return false;
-  }
-
-  dest->attrname = PyTuple_GET_ITEM(spec_tuple, 2);
-  dest->typeargs = PyTuple_GET_ITEM(spec_tuple, 3);
-  dest->defval = PyTuple_GET_ITEM(spec_tuple, 4);
-  return true;
-}
-
-/* ====== END UTILITIES ====== */
-
-
-/* ====== BEGIN WRITING FUNCTIONS ====== */
-
-/* --- LOW-LEVEL WRITING FUNCTIONS --- */
-
-static void writeByte(PyObject* outbuf, int8_t val) {
-  int8_t net = val;
-  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int8_t));
-}
-
-static void writeI16(PyObject* outbuf, int16_t val) {
-  int16_t net = (int16_t)htons(val);
-  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int16_t));
-}
-
-static void writeI32(PyObject* outbuf, int32_t val) {
-  int32_t net = (int32_t)htonl(val);
-  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int32_t));
-}
-
-static void writeI64(PyObject* outbuf, int64_t val) {
-  int64_t net = (int64_t)htonll(val);
-  PycStringIO->cwrite(outbuf, (char*)&net, sizeof(int64_t));
-}
-
-static void writeDouble(PyObject* outbuf, double dub) {
-  // Unfortunately, bitwise_cast doesn't work in C.  Bad C!
-  union {
-    double f;
-    int64_t t;
-  } transfer;
-  transfer.f = dub;
-  writeI64(outbuf, transfer.t);
-}
-
-
-/* --- MAIN RECURSIVE OUTPUT FUCNTION -- */
-
-static int
-output_val(PyObject* output, PyObject* value, TType type, PyObject* typeargs) {
-  /*
-   * Refcounting Strategy:
-   *
-   * We assume that elements of the thrift_spec tuple are not going to be
-   * mutated, so we don't ref count those at all. Other than that, we try to
-   * keep a reference to all the user-created objects while we work with them.
-   * output_val assumes that a reference is already held. The *caller* is
-   * responsible for handling references
-   */
-
-  switch (type) {
-
-  case T_BOOL: {
-    int v = PyObject_IsTrue(value);
-    if (v == -1) {
-      return false;
-    }
-
-    writeByte(output, (int8_t) v);
-    break;
-  }
-  case T_I08: {
-    int32_t val;
-
-    if (!parse_pyint(value, &val, INT8_MIN, INT8_MAX)) {
-      return false;
-    }
-
-    writeByte(output, (int8_t) val);
-    break;
-  }
-  case T_I16: {
-    int32_t val;
-
-    if (!parse_pyint(value, &val, INT16_MIN, INT16_MAX)) {
-      return false;
-    }
-
-    writeI16(output, (int16_t) val);
-    break;
-  }
-  case T_I32: {
-    int32_t val;
-
-    if (!parse_pyint(value, &val, INT32_MIN, INT32_MAX)) {
-      return false;
-    }
-
-    writeI32(output, val);
-    break;
-  }
-  case T_I64: {
-    int64_t nval = PyLong_AsLongLong(value);
-
-    if (INT_CONV_ERROR_OCCURRED(nval)) {
-      return false;
-    }
-
-    if (!CHECK_RANGE(nval, INT64_MIN, INT64_MAX)) {
-      PyErr_SetString(PyExc_OverflowError, "int out of range");
-      return false;
-    }
-
-    writeI64(output, nval);
-    break;
-  }
-
-  case T_DOUBLE: {
-    double nval = PyFloat_AsDouble(value);
-    if (nval == -1.0 && PyErr_Occurred()) {
-      return false;
-    }
-
-    writeDouble(output, nval);
-    break;
-  }
-
-  case T_STRING: {
-    Py_ssize_t len = PyString_Size(value);
-
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    writeI32(output, (int32_t) len);
-    PycStringIO->cwrite(output, PyString_AsString(value), (int32_t) len);
-    break;
-  }
-
-  case T_LIST:
-  case T_SET: {
-    Py_ssize_t len;
-    SetListTypeArgs parsedargs;
-    PyObject *item;
-    PyObject *iterator;
-
-    if (!parse_set_list_args(&parsedargs, typeargs)) {
-      return false;
-    }
-
-    len = PyObject_Length(value);
-
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    writeByte(output, parsedargs.element_type);
-    writeI32(output, (int32_t) len);
-
-    iterator =  PyObject_GetIter(value);
-    if (iterator == NULL) {
-      return false;
-    }
-
-    while ((item = PyIter_Next(iterator))) {
-      if (!output_val(output, item, parsedargs.element_type, parsedargs.typeargs)) {
-        Py_DECREF(item);
-        Py_DECREF(iterator);
-        return false;
-      }
-      Py_DECREF(item);
-    }
-
-    Py_DECREF(iterator);
-
-    if (PyErr_Occurred()) {
-      return false;
-    }
-
-    break;
-  }
-
-  case T_MAP: {
-    PyObject *k, *v;
-    Py_ssize_t pos = 0;
-    Py_ssize_t len;
-
-    MapTypeArgs parsedargs;
-
-    len = PyDict_Size(value);
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    if (!parse_map_args(&parsedargs, typeargs)) {
-      return false;
-    }
-
-    writeByte(output, parsedargs.ktag);
-    writeByte(output, parsedargs.vtag);
-    writeI32(output, len);
-
-    // TODO(bmaurer): should support any mapping, not just dicts
-    while (PyDict_Next(value, &pos, &k, &v)) {
-      // TODO(dreiss): Think hard about whether these INCREFs actually
-      //               turn any unsafe scenarios into safe scenarios.
-      Py_INCREF(k);
-      Py_INCREF(v);
-
-      if (!output_val(output, k, parsedargs.ktag, parsedargs.ktypeargs)
-          || !output_val(output, v, parsedargs.vtag, parsedargs.vtypeargs)) {
-        Py_DECREF(k);
-        Py_DECREF(v);
-        return false;
-      }
-      Py_DECREF(k);
-      Py_DECREF(v);
-    }
-    break;
-  }
-
-  // TODO(dreiss): Consider breaking this out as a function
-  //               the way we did for decode_struct.
-  case T_STRUCT: {
-    StructTypeArgs parsedargs;
-    Py_ssize_t nspec;
-    Py_ssize_t i;
-
-    if (!parse_struct_args(&parsedargs, typeargs)) {
-      return false;
-    }
-
-    nspec = PyTuple_Size(parsedargs.spec);
-
-    if (nspec == -1) {
-      return false;
-    }
-
-    for (i = 0; i < nspec; i++) {
-      StructItemSpec parsedspec;
-      PyObject* spec_tuple;
-      PyObject* instval = NULL;
-
-      spec_tuple = PyTuple_GET_ITEM(parsedargs.spec, i);
-      if (spec_tuple == Py_None) {
-        continue;
-      }
-
-      if (!parse_struct_item_spec (&parsedspec, spec_tuple)) {
-        return false;
-      }
-
-      instval = PyObject_GetAttr(value, parsedspec.attrname);
-
-      if (!instval) {
-        return false;
-      }
-
-      if (instval == Py_None) {
-        Py_DECREF(instval);
-        continue;
-      }
-
-      writeByte(output, (int8_t) parsedspec.type);
-      writeI16(output, parsedspec.tag);
-
-      if (!output_val(output, instval, parsedspec.type, parsedspec.typeargs)) {
-        Py_DECREF(instval);
-        return false;
-      }
-
-      Py_DECREF(instval);
-    }
-
-    writeByte(output, (int8_t)T_STOP);
-    break;
-  }
-
-  case T_STOP:
-  case T_VOID:
-  case T_UTF16:
-  case T_UTF8:
-  case T_U64:
-  default:
-    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
-    return false;
-
-  }
-
-  return true;
-}
-
-
-/* --- TOP-LEVEL WRAPPER FOR OUTPUT -- */
-
-static PyObject *
-encode_binary(PyObject *self, PyObject *args) {
-  PyObject* enc_obj;
-  PyObject* type_args;
-  PyObject* buf;
-  PyObject* ret = NULL;
-
-  if (!PyArg_ParseTuple(args, "OO", &enc_obj, &type_args)) {
-    return NULL;
-  }
-
-  buf = PycStringIO->NewOutput(INIT_OUTBUF_SIZE);
-  if (output_val(buf, enc_obj, T_STRUCT, type_args)) {
-    ret = PycStringIO->cgetvalue(buf);
-  }
-
-  Py_DECREF(buf);
-  return ret;
-}
-
-/* ====== END WRITING FUNCTIONS ====== */
-
-
-/* ====== BEGIN READING FUNCTIONS ====== */
-
-/* --- LOW-LEVEL READING FUNCTIONS --- */
-
-static void
-free_decodebuf(DecodeBuffer* d) {
-  Py_XDECREF(d->stringiobuf);
-  Py_XDECREF(d->refill_callable);
-}
-
-static bool
-decode_buffer_from_obj(DecodeBuffer* dest, PyObject* obj) {
-  dest->stringiobuf = PyObject_GetAttr(obj, INTERN_STRING(cstringio_buf));
-  if (!dest->stringiobuf) {
-    return false;
-  }
-
-  if (!PycStringIO_InputCheck(dest->stringiobuf)) {
-    free_decodebuf(dest);
-    PyErr_SetString(PyExc_TypeError, "expecting stringio input");
-    return false;
-  }
-
-  dest->refill_callable = PyObject_GetAttr(obj, INTERN_STRING(cstringio_refill));
-
-  if(!dest->refill_callable) {
-    free_decodebuf(dest);
-    return false;
-  }
-
-  if (!PyCallable_Check(dest->refill_callable)) {
-    free_decodebuf(dest);
-    PyErr_SetString(PyExc_TypeError, "expecting callable");
-    return false;
-  }
-
-  return true;
-}
-
-static bool readBytes(DecodeBuffer* input, char** output, int len) {
-  int read;
-
-  // TODO(dreiss): Don't fear the malloc.  Think about taking a copy of
-  //               the partial read instead of forcing the transport
-  //               to prepend it to its buffer.
-
-  read = PycStringIO->cread(input->stringiobuf, output, len);
-
-  if (read == len) {
-    return true;
-  } else if (read == -1) {
-    return false;
-  } else {
-    PyObject* newiobuf;
-
-    // using building functions as this is a rare codepath
-    newiobuf = PyObject_CallFunction(
-        input->refill_callable, "s#i", *output, read, len, NULL);
-    if (newiobuf == NULL) {
-      return false;
-    }
-
-    // must do this *AFTER* the call so that we don't deref the io buffer
-    Py_CLEAR(input->stringiobuf);
-    input->stringiobuf = newiobuf;
-
-    read = PycStringIO->cread(input->stringiobuf, output, len);
-
-    if (read == len) {
-      return true;
-    } else if (read == -1) {
-      return false;
-    } else {
-      // TODO(dreiss): This could be a valid code path for big binary blobs.
-      PyErr_SetString(PyExc_TypeError,
-          "refill claimed to have refilled the buffer, but didn't!!");
-      return false;
-    }
-  }
-}
-
-static int8_t readByte(DecodeBuffer* input) {
-  char* buf;
-  if (!readBytes(input, &buf, sizeof(int8_t))) {
-    return -1;
-  }
-
-  return *(int8_t*) buf;
-}
-
-static int16_t readI16(DecodeBuffer* input) {
-  char* buf;
-  if (!readBytes(input, &buf, sizeof(int16_t))) {
-    return -1;
-  }
-
-  return (int16_t) ntohs(*(int16_t*) buf);
-}
-
-static int32_t readI32(DecodeBuffer* input) {
-  char* buf;
-  if (!readBytes(input, &buf, sizeof(int32_t))) {
-    return -1;
-  }
-  return (int32_t) ntohl(*(int32_t*) buf);
-}
-
-
-static int64_t readI64(DecodeBuffer* input) {
-  char* buf;
-  if (!readBytes(input, &buf, sizeof(int64_t))) {
-    return -1;
-  }
-
-  return (int64_t) ntohll(*(int64_t*) buf);
-}
-
-static double readDouble(DecodeBuffer* input) {
-  union {
-    int64_t f;
-    double t;
-  } transfer;
-
-  transfer.f = readI64(input);
-  if (transfer.f == -1) {
-    return -1;
-  }
-  return transfer.t;
-}
-
-static bool
-checkTypeByte(DecodeBuffer* input, TType expected) {
-  TType got = readByte(input);
-  if (INT_CONV_ERROR_OCCURRED(got)) {
-    return false;
-  }
-
-  if (expected != got) {
-    PyErr_SetString(PyExc_TypeError, "got wrong ttype while reading field");
-    return false;
-  }
-  return true;
-}
-
-static bool
-skip(DecodeBuffer* input, TType type) {
-#define SKIPBYTES(n) \
-  do { \
-    if (!readBytes(input, &dummy_buf, (n))) { \
-      return false; \
-    } \
-  } while(0)
-
-  char* dummy_buf;
-
-  switch (type) {
-
-  case T_BOOL:
-  case T_I08: SKIPBYTES(1); break;
-  case T_I16: SKIPBYTES(2); break;
-  case T_I32: SKIPBYTES(4); break;
-  case T_I64:
-  case T_DOUBLE: SKIPBYTES(8); break;
-
-  case T_STRING: {
-    // TODO(dreiss): Find out if these check_ssize_t32s are really necessary.
-    int len = readI32(input);
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-    SKIPBYTES(len);
-    break;
-  }
-
-  case T_LIST:
-  case T_SET: {
-    TType etype;
-    int len, i;
-
-    etype = readByte(input);
-    if (etype == -1) {
-      return false;
-    }
-
-    len = readI32(input);
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    for (i = 0; i < len; i++) {
-      if (!skip(input, etype)) {
-        return false;
-      }
-    }
-    break;
-  }
-
-  case T_MAP: {
-    TType ktype, vtype;
-    int len, i;
-
-    ktype = readByte(input);
-    if (ktype == -1) {
-      return false;
-    }
-
-    vtype = readByte(input);
-    if (vtype == -1) {
-      return false;
-    }
-
-    len = readI32(input);
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    for (i = 0; i < len; i++) {
-      if (!(skip(input, ktype) && skip(input, vtype))) {
-        return false;
-      }
-    }
-    break;
-  }
-
-  case T_STRUCT: {
-    while (true) {
-      TType type;
-
-      type = readByte(input);
-      if (type == -1) {
-        return false;
-      }
-
-      if (type == T_STOP)
-        break;
-
-      SKIPBYTES(2); // tag
-      if (!skip(input, type)) {
-        return false;
-      }
-    }
-    break;
-  }
-
-  case T_STOP:
-  case T_VOID:
-  case T_UTF16:
-  case T_UTF8:
-  case T_U64:
-  default:
-    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
-    return false;
-
-  }
-
-  return true;
-
-#undef SKIPBYTES
-}
-
-
-/* --- HELPER FUNCTION FOR DECODE_VAL --- */
-
-static PyObject*
-decode_val(DecodeBuffer* input, TType type, PyObject* typeargs);
-
-static bool
-decode_struct(DecodeBuffer* input, PyObject* output, PyObject* spec_seq) {
-  int spec_seq_len = PyTuple_Size(spec_seq);
-  if (spec_seq_len == -1) {
-    return false;
-  }
-
-  while (true) {
-    TType type;
-    int16_t tag;
-    PyObject* item_spec;
-    PyObject* fieldval = NULL;
-    StructItemSpec parsedspec;
-
-    type = readByte(input);
-    if (type == -1) {
-      return false;
-    }
-    if (type == T_STOP) {
-      break;
-    }
-    tag = readI16(input);
-    if (INT_CONV_ERROR_OCCURRED(tag)) {
-      return false;
-    }
-    if (tag >= 0 && tag < spec_seq_len) {
-      item_spec = PyTuple_GET_ITEM(spec_seq, tag);
-    } else {
-      item_spec = Py_None;
-    }
-
-    if (item_spec == Py_None) {
-      if (!skip(input, type)) {
-        return false;
-      } else {
-        continue;
-      }
-    }
-
-    if (!parse_struct_item_spec(&parsedspec, item_spec)) {
-      return false;
-    }
-    if (parsedspec.type != type) {
-      if (!skip(input, type)) {
-        PyErr_SetString(PyExc_TypeError, "struct field had wrong type while reading and can't be skipped");
-        return false;
-      } else {
-        continue;
-      }
-    }
-
-    fieldval = decode_val(input, parsedspec.type, parsedspec.typeargs);
-    if (fieldval == NULL) {
-      return false;
-    }
-
-    if (PyObject_SetAttr(output, parsedspec.attrname, fieldval) == -1) {
-      Py_DECREF(fieldval);
-      return false;
-    }
-    Py_DECREF(fieldval);
-  }
-  return true;
-}
-
-
-/* --- MAIN RECURSIVE INPUT FUCNTION --- */
-
-// Returns a new reference.
-static PyObject*
-decode_val(DecodeBuffer* input, TType type, PyObject* typeargs) {
-  switch (type) {
-
-  case T_BOOL: {
-    int8_t v = readByte(input);
-    if (INT_CONV_ERROR_OCCURRED(v)) {
-      return NULL;
-    }
-
-    switch (v) {
-    case 0: Py_RETURN_FALSE;
-    case 1: Py_RETURN_TRUE;
-    // Don't laugh.  This is a potentially serious issue.
-    default: PyErr_SetString(PyExc_TypeError, "boolean out of range"); return NULL;
-    }
-    break;
-  }
-  case T_I08: {
-    int8_t v = readByte(input);
-    if (INT_CONV_ERROR_OCCURRED(v)) {
-      return NULL;
-    }
-
-    return PyInt_FromLong(v);
-  }
-  case T_I16: {
-    int16_t v = readI16(input);
-    if (INT_CONV_ERROR_OCCURRED(v)) {
-      return NULL;
-    }
-    return PyInt_FromLong(v);
-  }
-  case T_I32: {
-    int32_t v = readI32(input);
-    if (INT_CONV_ERROR_OCCURRED(v)) {
-      return NULL;
-    }
-    return PyInt_FromLong(v);
-  }
-
-  case T_I64: {
-    int64_t v = readI64(input);
-    if (INT_CONV_ERROR_OCCURRED(v)) {
-      return NULL;
-    }
-    // TODO(dreiss): Find out if we can take this fastpath always when
-    //               sizeof(long) == sizeof(long long).
-    if (CHECK_RANGE(v, LONG_MIN, LONG_MAX)) {
-      return PyInt_FromLong((long) v);
-    }
-
-    return PyLong_FromLongLong(v);
-  }
-
-  case T_DOUBLE: {
-    double v = readDouble(input);
-    if (v == -1.0 && PyErr_Occurred()) {
-      return false;
-    }
-    return PyFloat_FromDouble(v);
-  }
-
-  case T_STRING: {
-    Py_ssize_t len = readI32(input);
-    char* buf;
-    if (!readBytes(input, &buf, len)) {
-      return NULL;
-    }
-
-    return PyString_FromStringAndSize(buf, len);
-  }
-
-  case T_LIST:
-  case T_SET: {
-    SetListTypeArgs parsedargs;
-    int32_t len;
-    PyObject* ret = NULL;
-    int i;
-
-    if (!parse_set_list_args(&parsedargs, typeargs)) {
-      return NULL;
-    }
-
-    if (!checkTypeByte(input, parsedargs.element_type)) {
-      return NULL;
-    }
-
-    len = readI32(input);
-    if (!check_ssize_t_32(len)) {
-      return NULL;
-    }
-
-    ret = PyList_New(len);
-    if (!ret) {
-      return NULL;
-    }
-
-    for (i = 0; i < len; i++) {
-      PyObject* item = decode_val(input, parsedargs.element_type, parsedargs.typeargs);
-      if (!item) {
-        Py_DECREF(ret);
-        return NULL;
-      }
-      PyList_SET_ITEM(ret, i, item);
-    }
-
-    // TODO(dreiss): Consider biting the bullet and making two separate cases
-    //               for list and set, avoiding this post facto conversion.
-    if (type == T_SET) {
-      PyObject* setret;
-#if (PY_VERSION_HEX < 0x02050000)
-      // hack needed for older versions
-      setret = PyObject_CallFunctionObjArgs((PyObject*)&PySet_Type, ret, NULL);
-#else
-      // official version
-      setret = PySet_New(ret);
-#endif
-      Py_DECREF(ret);
-      return setret;
-    }
-    return ret;
-  }
-
-  case T_MAP: {
-    int32_t len;
-    int i;
-    MapTypeArgs parsedargs;
-    PyObject* ret = NULL;
-
-    if (!parse_map_args(&parsedargs, typeargs)) {
-      return NULL;
-    }
-
-    if (!checkTypeByte(input, parsedargs.ktag)) {
-      return NULL;
-    }
-    if (!checkTypeByte(input, parsedargs.vtag)) {
-      return NULL;
-    }
-
-    len = readI32(input);
-    if (!check_ssize_t_32(len)) {
-      return false;
-    }
-
-    ret = PyDict_New();
-    if (!ret) {
-      goto error;
-    }
-
-    for (i = 0; i < len; i++) {
-      PyObject* k = NULL;
-      PyObject* v = NULL;
-      k = decode_val(input, parsedargs.ktag, parsedargs.ktypeargs);
-      if (k == NULL) {
-        goto loop_error;
-      }
-      v = decode_val(input, parsedargs.vtag, parsedargs.vtypeargs);
-      if (v == NULL) {
-        goto loop_error;
-      }
-      if (PyDict_SetItem(ret, k, v) == -1) {
-        goto loop_error;
-      }
-
-      Py_DECREF(k);
-      Py_DECREF(v);
-      continue;
-
-      // Yuck!  Destructors, anyone?
-      loop_error:
-      Py_XDECREF(k);
-      Py_XDECREF(v);
-      goto error;
-    }
-
-    return ret;
-
-    error:
-    Py_XDECREF(ret);
-    return NULL;
-  }
-
-  case T_STRUCT: {
-    StructTypeArgs parsedargs;
-	PyObject* ret;
-    if (!parse_struct_args(&parsedargs, typeargs)) {
-      return NULL;
-    }
-
-    ret = PyObject_CallObject(parsedargs.klass, NULL);
-    if (!ret) {
-      return NULL;
-    }
-
-    if (!decode_struct(input, ret, parsedargs.spec)) {
-      Py_DECREF(ret);
-      return NULL;
-    }
-
-    return ret;
-  }
-
-  case T_STOP:
-  case T_VOID:
-  case T_UTF16:
-  case T_UTF8:
-  case T_U64:
-  default:
-    PyErr_SetString(PyExc_TypeError, "Unexpected TType");
-    return NULL;
-  }
-}
-
-
-/* --- TOP-LEVEL WRAPPER FOR INPUT -- */
-
-static PyObject*
-decode_binary(PyObject *self, PyObject *args) {
-  PyObject* output_obj = NULL;
-  PyObject* transport = NULL;
-  PyObject* typeargs = NULL;
-  StructTypeArgs parsedargs;
-  DecodeBuffer input = {0, 0};
-  
-  if (!PyArg_ParseTuple(args, "OOO", &output_obj, &transport, &typeargs)) {
-    return NULL;
-  }
-
-  if (!parse_struct_args(&parsedargs, typeargs)) {
-    return NULL;
-  }
-
-  if (!decode_buffer_from_obj(&input, transport)) {
-    return NULL;
-  }
-
-  if (!decode_struct(&input, output_obj, parsedargs.spec)) {
-    free_decodebuf(&input);
-    return NULL;
-  }
-
-  free_decodebuf(&input);
-
-  Py_RETURN_NONE;
-}
-
-/* ====== END READING FUNCTIONS ====== */
-
-
-/* -- PYTHON MODULE SETUP STUFF --- */
-
-static PyMethodDef ThriftFastBinaryMethods[] = {
-
-  {"encode_binary",  encode_binary, METH_VARARGS, ""},
-  {"decode_binary",  decode_binary, METH_VARARGS, ""},
-
-  {NULL, NULL, 0, NULL}        /* Sentinel */
-};
-
-PyMODINIT_FUNC
-initfastbinary(void) {
-#define INIT_INTERN_STRING(value) \
-  do { \
-    INTERN_STRING(value) = PyString_InternFromString(#value); \
-    if(!INTERN_STRING(value)) return; \
-  } while(0)
-
-  INIT_INTERN_STRING(cstringio_buf);
-  INIT_INTERN_STRING(cstringio_refill);
-#undef INIT_INTERN_STRING
-
-  PycString_IMPORT;
-  if (PycStringIO == NULL) return;
-
-  (void) Py_InitModule("thrift.protocol.fastbinary", ThriftFastBinaryMethods);
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/THttpServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/THttpServer.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/THttpServer.py
deleted file mode 100644
index 6ee18dd..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/THttpServer.py
+++ /dev/null
@@ -1,87 +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.
-#
-
-import BaseHTTPServer
-
-from ..server import TServer
-from ..transport import TTransport
-
-
-class ResponseException(Exception):
-  """Allows handlers to override the HTTP response
-
-  Normally, THttpServer always sends a 200 response.  If a handler wants
-  to override this behavior (e.g., to simulate a misconfigured or
-  overloaded web server during testing), it can raise a ResponseException.
-  The function passed to the constructor will be called with the
-  RequestHandler as its only argument.
-  """
-  def __init__(self, handler):
-    self.handler = handler
-
-
-class THttpServer(TServer.TServer):
-  """A simple HTTP-based Thrift server
-
-  This class is not very performant, but it is useful (for example) for
-  acting as a mock version of an Apache-based PHP Thrift endpoint.
-  """
-  def __init__(self,
-               processor,
-               server_address,
-               inputProtocolFactory,
-               outputProtocolFactory=None,
-               server_class=BaseHTTPServer.HTTPServer):
-    """Set up protocol factories and HTTP server.
-
-    See BaseHTTPServer for server_address.
-    See TServer for protocol factories.
-    """
-    if outputProtocolFactory is None:
-      outputProtocolFactory = inputProtocolFactory
-
-    TServer.TServer.__init__(self, processor, None, None, None,
-        inputProtocolFactory, outputProtocolFactory)
-
-    thttpserver = self
-
-    class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
-      def do_POST(self):
-        # Don't care about the request path.
-        itrans = TTransport.TFileObjectTransport(self.rfile)
-        otrans = TTransport.TFileObjectTransport(self.wfile)
-        itrans = TTransport.TBufferedTransport(
-          itrans, int(self.headers['Content-Length']))
-        otrans = TTransport.TMemoryBuffer()
-        iprot = thttpserver.inputProtocolFactory.getProtocol(itrans)
-        oprot = thttpserver.outputProtocolFactory.getProtocol(otrans)
-        try:
-          thttpserver.processor.process(iprot, oprot)
-        except ResponseException, exn:
-          exn.handler(self)
-        else:
-          self.send_response(200)
-          self.send_header("content-type", "application/x-thrift")
-          self.end_headers()
-          self.wfile.write(otrans.getvalue())
-
-    self.httpd = server_class(server_address, RequestHander)
-
-  def serve(self):
-    self.httpd.serve_forever()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TNonblockingServer.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
deleted file mode 100644
index aa27991..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/thrift/server/TNonblockingServer.py
+++ /dev/null
@@ -1,346 +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.
-#
-"""Implementation of non-blocking server.
-
-The main idea of the server is to receive and send requests
-only from the main thread.
-
-The thread poool should be sized for concurrent tasks, not
-maximum connections
-"""
-import threading
-import socket
-import Queue
-import select
-import struct
-import logging
-
-from ..transport import TTransport
-from ..protocol.TBinaryProtocol import TBinaryProtocolFactory
-
-__all__ = ['TNonblockingServer']
-
-
-class Worker(threading.Thread):
-    """Worker is a small helper to process incoming connection."""
-
-    def __init__(self, queue):
-        threading.Thread.__init__(self)
-        self.queue = queue
-
-    def run(self):
-        """Process queries from task queue, stop if processor is None."""
-        while True:
-            try:
-                processor, iprot, oprot, otrans, callback = self.queue.get()
-                if processor is None:
-                    break
-                processor.process(iprot, oprot)
-                callback(True, otrans.getvalue())
-            except Exception:
-                logging.exception("Exception while processing request")
-                callback(False, '')
-
-WAIT_LEN = 0
-WAIT_MESSAGE = 1
-WAIT_PROCESS = 2
-SEND_ANSWER = 3
-CLOSED = 4
-
-
-def locked(func):
-    """Decorator which locks self.lock."""
-    def nested(self, *args, **kwargs):
-        self.lock.acquire()
-        try:
-            return func(self, *args, **kwargs)
-        finally:
-            self.lock.release()
-    return nested
-
-
-def socket_exception(func):
-    """Decorator close object on socket.error."""
-    def read(self, *args, **kwargs):
-        try:
-            return func(self, *args, **kwargs)
-        except socket.error:
-            self.close()
-    return read
-
-
-class Connection:
-    """Basic class is represented connection.
-
-    It can be in state:
-        WAIT_LEN --- connection is reading request len.
-        WAIT_MESSAGE --- connection is reading request.
-        WAIT_PROCESS --- connection has just read whole request and
-                         waits for call ready routine.
-        SEND_ANSWER --- connection is sending answer string (including length
-                        of answer).
-        CLOSED --- socket was closed and connection should be deleted.
-    """
-    def __init__(self, new_socket, wake_up):
-        self.socket = new_socket
-        self.socket.setblocking(False)
-        self.status = WAIT_LEN
-        self.len = 0
-        self.message = ''
-        self.lock = threading.Lock()
-        self.wake_up = wake_up
-
-    def _read_len(self):
-        """Reads length of request.
-
-        It's a safer alternative to self.socket.recv(4)
-        """
-        read = self.socket.recv(4 - len(self.message))
-        if len(read) == 0:
-            # if we read 0 bytes and self.message is empty, then
-            # the client closed the connection
-            if len(self.message) != 0:
-                logging.error("can't read frame size from socket")
-            self.close()
-            return
-        self.message += read
-        if len(self.message) == 4:
-            self.len, = struct.unpack('!i', self.message)
-            if self.len < 0:
-                logging.error("negative frame size, it seems client "
-                              "doesn't use FramedTransport")
-                self.close()
-            elif self.len == 0:
-                logging.error("empty frame, it's really strange")
-                self.close()
-            else:
-                self.message = ''
-                self.status = WAIT_MESSAGE
-
-    @socket_exception
-    def read(self):
-        """Reads data from stream and switch state."""
-        assert self.status in (WAIT_LEN, WAIT_MESSAGE)
-        if self.status == WAIT_LEN:
-            self._read_len()
-            # go back to the main loop here for simplicity instead of
-            # falling through, even though there is a good chance that
-            # the message is already available
-        elif self.status == WAIT_MESSAGE:
-            read = self.socket.recv(self.len - len(self.message))
-            if len(read) == 0:
-                logging.error("can't read frame from socket (get %d of "
-                              "%d bytes)" % (len(self.message), self.len))
-                self.close()
-                return
-            self.message += read
-            if len(self.message) == self.len:
-                self.status = WAIT_PROCESS
-
-    @socket_exception
-    def write(self):
-        """Writes data from socket and switch state."""
-        assert self.status == SEND_ANSWER
-        sent = self.socket.send(self.message)
-        if sent == len(self.message):
-            self.status = WAIT_LEN
-            self.message = ''
-            self.len = 0
-        else:
-            self.message = self.message[sent:]
-
-    @locked
-    def ready(self, all_ok, message):
-        """Callback function for switching state and waking up main thread.
-
-        This function is the only function witch can be called asynchronous.
-
-        The ready can switch Connection to three states:
-            WAIT_LEN if request was oneway.
-            SEND_ANSWER if request was processed in normal way.
-            CLOSED if request throws unexpected exception.
-
-        The one wakes up main thread.
-        """
-        assert self.status == WAIT_PROCESS
-        if not all_ok:
-            self.close()
-            self.wake_up()
-            return
-        self.len = ''
-        if len(message) == 0:
-            # it was a oneway request, do not write answer
-            self.message = ''
-            self.status = WAIT_LEN
-        else:
-            self.message = struct.pack('!i', len(message)) + message
-            self.status = SEND_ANSWER
-        self.wake_up()
-
-    @locked
-    def is_writeable(self):
-        """Return True if connection should be added to write list of select"""
-        return self.status == SEND_ANSWER
-
-    # it's not necessary, but...
-    @locked
-    def is_readable(self):
-        """Return True if connection should be added to read list of select"""
-        return self.status in (WAIT_LEN, WAIT_MESSAGE)
-
-    @locked
-    def is_closed(self):
-        """Returns True if connection is closed."""
-        return self.status == CLOSED
-
-    def fileno(self):
-        """Returns the file descriptor of the associated socket."""
-        return self.socket.fileno()
-
-    def close(self):
-        """Closes connection"""
-        self.status = CLOSED
-        self.socket.close()
-
-
-class TNonblockingServer:
-    """Non-blocking server."""
-
-    def __init__(self,
-                 processor,
-                 lsocket,
-                 inputProtocolFactory=None,
-                 outputProtocolFactory=None,
-                 threads=10):
-        self.processor = processor
-        self.socket = lsocket
-        self.in_protocol = inputProtocolFactory or TBinaryProtocolFactory()
-        self.out_protocol = outputProtocolFactory or self.in_protocol
-        self.threads = int(threads)
-        self.clients = {}
-        self.tasks = Queue.Queue()
-        self._read, self._write = socket.socketpair()
-        self.prepared = False
-        self._stop = False
-
-    def setNumThreads(self, num):
-        """Set the number of worker threads that should be created."""
-        # implement ThreadPool interface
-        assert not self.prepared, "Can't change number of threads after start"
-        self.threads = num
-
-    def prepare(self):
-        """Prepares server for serve requests."""
-        if self.prepared:
-            return
-        self.socket.listen()
-        for _ in xrange(self.threads):
-            thread = Worker(self.tasks)
-            thread.setDaemon(True)
-            thread.start()
-        self.prepared = True
-
-    def wake_up(self):
-        """Wake up main thread.
-
-        The server usualy waits in select call in we should terminate one.
-        The simplest way is using socketpair.
-
-        Select always wait to read from the first socket of socketpair.
-
-        In this case, we can just write anything to the second socket from
-        socketpair.
-        """
-        self._write.send('1')
-
-    def stop(self):
-        """Stop the server.
-
-        This method causes the serve() method to return.  stop() may be invoked
-        from within your handler, or from another thread.
-
-        After stop() is called, serve() will return but the server will still
-        be listening on the socket.  serve() may then be called again to resume
-        processing requests.  Alternatively, close() may be called after
-        serve() returns to close the server socket and shutdown all worker
-        threads.
-        """
-        self._stop = True
-        self.wake_up()
-
-    def _select(self):
-        """Does select on open connections."""
-        readable = [self.socket.handle.fileno(), self._read.fileno()]
-        writable = []
-        for i, connection in self.clients.items():
-            if connection.is_readable():
-                readable.append(connection.fileno())
-            if connection.is_writeable():
-                writable.append(connection.fileno())
-            if connection.is_closed():
-                del self.clients[i]
-        return select.select(readable, writable, readable)
-
-    def handle(self):
-        """Handle requests.
-
-        WARNING! You must call prepare() BEFORE calling handle()
-        """
-        assert self.prepared, "You have to call prepare before handle"
-        rset, wset, xset = self._select()
-        for readable in rset:
-            if readable == self._read.fileno():
-                # don't care i just need to clean readable flag
-                self._read.recv(1024)
-            elif readable == self.socket.handle.fileno():
-                client = self.socket.accept().handle
-                self.clients[client.fileno()] = Connection(client,
-                                                           self.wake_up)
-            else:
-                connection = self.clients[readable]
-                connection.read()
-                if connection.status == WAIT_PROCESS:
-                    itransport = TTransport.TMemoryBuffer(connection.message)
-                    otransport = TTransport.TMemoryBuffer()
-                    iprot = self.in_protocol.getProtocol(itransport)
-                    oprot = self.out_protocol.getProtocol(otransport)
-                    self.tasks.put([self.processor, iprot, oprot,
-                                    otransport, connection.ready])
-        for writeable in wset:
-            self.clients[writeable].write()
-        for oob in xset:
-            self.clients[oob].close()
-            del self.clients[oob]
-
-    def close(self):
-        """Closes the server."""
-        for _ in xrange(self.threads):
-            self.tasks.put([None, None, None, None, None])
-        self.socket.close()
-        self.prepared = False
-
-    def serve(self):
-        """Serve requests.
-
-        Serve requests forever, or until stop() is called.
-        """
-        self._stop = False
-        self.prepare()
-        while not self._stop:
-            self.handle()


[38/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/agent.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/agent.py
deleted file mode 100644
index 1859d8a..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/agent.py
+++ /dev/null
@@ -1,202 +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.
-
-from thrift.publisher import *
-from ..util.log import *
-
-
-class StreamDefinition:
-    """
-    Represents a BAM/CEP stream definition
-    """
-
-    STRING = 'STRING'
-    DOUBLE = 'DOUBLE'
-    INT = 'INT'
-    LONG = 'LONG'
-    BOOL = 'BOOL'
-
-    def __init__(self):
-        self.name = None
-        """:type : str"""
-        self.version = None
-        """:type : str"""
-        self.nickname = None
-        """:type : str"""
-        self.description = None
-        """:type : str"""
-        self.meta_data = []
-        """:type : list[str]"""
-        self.correlation_data = []
-        """:type : list[str]"""
-        self.payload_data = []
-        """:type : list[str]"""
-        self.stream_id =  None
-        """ :type : str """
-
-    def add_metadata_attribute(self, attr_name, attr_type):
-        self.meta_data.append({"name": attr_name, "type": attr_type})
-
-    def add_payloaddata_attribute(self, attr_name, attr_type):
-        self.payload_data.append({"name": attr_name, "type": attr_type})
-
-    def add_correlationdata_attribute(self, attr_name, attr_type):
-        self.correlation_data.append({"name": attr_name, "type": attr_type})
-
-    def __str__(self):
-        """
-        To string override
-        """
-
-        json_str = "{"
-        json_str += "\"name\":\"" + self.name + "\","
-        json_str += "\"version\":\"" + self.version + "\","
-        json_str += "\"nickName\":\"" + self.nickname + "\","
-        json_str += "\"description\":\"" + self.description + "\","
-
-        # add metadata attributes if exists
-        if len(self.meta_data) > 0:
-            json_str += "\"metaData\":["
-            for metadatum in self.meta_data:
-                json_str += "{\"name\":\"" + metadatum["name"] + "\", \"type\": \"" + metadatum["type"] + "\"},"
-
-            json_str = json_str[:-1] + "],"
-
-        # add correlationdata attributes if exists
-        if len(self.correlation_data) > 0:
-            json_str += "\"correlationData\":["
-            for coredatum in self.correlation_data:
-                json_str += "{\"name\":\"" + coredatum["name"] + "\", \"type\": \"" + coredatum["type"] + "\"},"
-
-            json_str = json_str[:-1] + "],"
-
-        # add payloaddata attributes if exists
-        if len(self.payload_data) > 0:
-            json_str += "\"payloadData\":["
-            for payloaddatum in self.payload_data:
-                json_str += "{\"name\":\"" + payloaddatum["name"] + "\", \"type\": \"" + payloaddatum["type"] + "\"},"
-
-            json_str = json_str[:-1] + "],"
-
-        json_str = json_str[:-1] + "}"
-
-        return json_str
-
-
-class ThriftEvent:
-    """
-    Represents an event to be published to a BAM/CEP monitoring server
-    """
-    def __init__(self):
-        self.metaData = []
-        """:type : list[str]"""
-        self.correlationData = []
-        """:type : list[str]"""
-        self.payloadData = []
-        """:type : list[str]"""
-
-
-class ThriftPublisher:
-    """
-    Handles publishing events to BAM/CEP through thrift using the provided address and credentials
-    """
-    log = LogFactory().get_log(__name__)
-
-    def __init__(self, ip, port, username, password, stream_definition):
-        """
-        Initializes a ThriftPublisher object.
-
-        At initialization a ThriftPublisher connects and defines a stream definition. A connection
-        should be disconnected after all the publishing has been done.
-
-        :param str ip: IP address of the monitoring server
-        :param str port: Port of the monitoring server
-        :param str username: Username
-        :param str password: Password
-        :param StreamDefinition stream_definition: StreamDefinition object for this particular connection
-        :return: ThriftPublisher object
-        :rtype: ThriftPublisher
-        """
-        try:
-            port_number = int(port)
-        except ValueError:
-            raise RuntimeError("Port number for Thrift Publisher is invalid: %r" % port)
-
-        self.__publisher = Publisher(ip, port_number)
-        self.__publisher.connect(username, password)
-        self.__publisher.defineStream(str(stream_definition))
-
-        self.stream_definition = stream_definition
-        self.stream_id = self.__publisher.streamId
-        self.ip = ip
-        self.port = port
-        self.username = username
-        self.password = password
-
-    def publish(self, event):
-        """
-        Publishes the given event by creating the event bundle from the log event
-
-        :param ThriftEvent event: The log event to be published
-        :return: void
-        """
-        event_bundler = EventBundle()
-        ThriftPublisher.assign_attributes(event.metaData, event_bundler)
-        ThriftPublisher.assign_attributes(event.correlationData, event_bundler)
-        ThriftPublisher.assign_attributes(event.payloadData, event_bundler)
-
-        self.__publisher.publish(event_bundler)
-        self.log.debug("Published event to thrift stream [%r]" % self.stream_id)
-
-    def disconnect(self):
-        """
-        Disconnect the thrift publisher
-        :return: void
-        """
-        self.__publisher.disconnect()
-
-    @staticmethod
-    def assign_attributes(attributes, event_bundler):
-        """
-        Adds the given attributes to the given event bundler according to type of each attribute
-        :param list attributes: attributes to be assigned
-        :param EventBundle event_bundler: Event bundle to assign attributes to
-        :return: void
-        """
-
-        # __intAttributeList = []
-        # __longAttributeList = []
-        # __doubleAttributeList = []
-        # __boolAttributeList = []
-        # __stringAttributeList = []
-
-        if attributes is not None and len(attributes) > 0:
-            for attrib in attributes:
-                if isinstance(attrib, int):
-                    event_bundler.addIntAttribute(attrib)
-                elif isinstance(attrib, long):
-                    event_bundler.addLongAttribute(attrib)
-                elif isinstance(attrib, float):
-                    event_bundler.addDoubleAttribute(attrib)
-                elif isinstance(attrib, bool):
-                    event_bundler.addBoolAttribute(attrib)
-                elif isinstance(attrib, str):
-                    event_bundler.addStringAttribute(attrib)
-                else:
-                    ThriftPublisher.log.error("Undefined attribute type: %r" % attrib)
-        else:
-            ThriftPublisher.log.debug("Empty attribute list")

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py
deleted file mode 100644
index adefd8e..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-__all__ = ['ttypes', 'constants']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py
deleted file mode 100644
index 36943ba..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py
deleted file mode 100644
index d76afca..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py
+++ /dev/null
@@ -1,320 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
-
-from ...thrift.transport import TTransport
-from ...thrift.protocol import TBinaryProtocol, TProtocol
-try:
-  from ...thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-
-class ThriftAttributeType:
-  INT = 0
-  LONG = 1
-  FLOAT = 2
-  DOUBLE = 3
-  BOOL = 4
-  STRING = 5
-
-  _VALUES_TO_NAMES = {
-    0: "INT",
-    1: "LONG",
-    2: "FLOAT",
-    3: "DOUBLE",
-    4: "BOOL",
-    5: "STRING",
-  }
-
-  _NAMES_TO_VALUES = {
-    "INT": 0,
-    "LONG": 1,
-    "FLOAT": 2,
-    "DOUBLE": 3,
-    "BOOL": 4,
-    "STRING": 5,
-  }
-
-
-class ThriftAttribute:
-  """
-  Attributes:
-   - name
-   - attributeType
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'name', None, None, ), # 1
-    (2, TType.I32, 'attributeType', None, None, ), # 2
-  )
-
-  def __init__(self, name=None, attributeType=None,):
-    self.name = name
-    self.attributeType = attributeType
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.name = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.I32:
-          self.attributeType = iprot.readI32();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftAttribute')
-    if self.name is not None:
-      oprot.writeFieldBegin('name', TType.STRING, 1)
-      oprot.writeString(self.name)
-      oprot.writeFieldEnd()
-    if self.attributeType is not None:
-      oprot.writeFieldBegin('attributeType', TType.I32, 2)
-      oprot.writeI32(self.attributeType)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftEventBundle:
-  """
-  Attributes:
-   - sessionId
-   - eventNum
-   - intAttributeList
-   - longAttributeList
-   - doubleAttributeList
-   - boolAttributeList
-   - stringAttributeList
-   - arbitraryDataMapMap
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.I32, 'eventNum', None, None, ), # 2
-    (3, TType.LIST, 'intAttributeList', (TType.I32,None), None, ), # 3
-    (4, TType.LIST, 'longAttributeList', (TType.I64,None), None, ), # 4
-    (5, TType.LIST, 'doubleAttributeList', (TType.DOUBLE,None), None, ), # 5
-    (6, TType.LIST, 'boolAttributeList', (TType.BOOL,None), None, ), # 6
-    (7, TType.LIST, 'stringAttributeList', (TType.STRING,None), None, ), # 7
-    (8, TType.MAP, 'arbitraryDataMapMap', (TType.I32,None,TType.MAP,(TType.STRING,None,TType.STRING,None)), None, ), # 8
-  )
-
-  def __init__(self, sessionId=None, eventNum=None, intAttributeList=None, longAttributeList=None, doubleAttributeList=None, boolAttributeList=None, stringAttributeList=None, arbitraryDataMapMap=None,):
-    self.sessionId = sessionId
-    self.eventNum = eventNum
-    self.intAttributeList = intAttributeList
-    self.longAttributeList = longAttributeList
-    self.doubleAttributeList = doubleAttributeList
-    self.boolAttributeList = boolAttributeList
-    self.stringAttributeList = stringAttributeList
-    self.arbitraryDataMapMap = arbitraryDataMapMap
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.I32:
-          self.eventNum = iprot.readI32();
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.LIST:
-          self.intAttributeList = []
-          (_etype3, _size0) = iprot.readListBegin()
-          for _i4 in xrange(_size0):
-            _elem5 = iprot.readI32();
-            self.intAttributeList.append(_elem5)
-          iprot.readListEnd()
-        else:
-          iprot.skip(ftype)
-      elif fid == 4:
-        if ftype == TType.LIST:
-          self.longAttributeList = []
-          (_etype9, _size6) = iprot.readListBegin()
-          for _i10 in xrange(_size6):
-            _elem11 = iprot.readI64();
-            self.longAttributeList.append(_elem11)
-          iprot.readListEnd()
-        else:
-          iprot.skip(ftype)
-      elif fid == 5:
-        if ftype == TType.LIST:
-          self.doubleAttributeList = []
-          (_etype15, _size12) = iprot.readListBegin()
-          for _i16 in xrange(_size12):
-            _elem17 = iprot.readDouble();
-            self.doubleAttributeList.append(_elem17)
-          iprot.readListEnd()
-        else:
-          iprot.skip(ftype)
-      elif fid == 6:
-        if ftype == TType.LIST:
-          self.boolAttributeList = []
-          (_etype21, _size18) = iprot.readListBegin()
-          for _i22 in xrange(_size18):
-            _elem23 = iprot.readBool();
-            self.boolAttributeList.append(_elem23)
-          iprot.readListEnd()
-        else:
-          iprot.skip(ftype)
-      elif fid == 7:
-        if ftype == TType.LIST:
-          self.stringAttributeList = []
-          (_etype27, _size24) = iprot.readListBegin()
-          for _i28 in xrange(_size24):
-            _elem29 = iprot.readString();
-            self.stringAttributeList.append(_elem29)
-          iprot.readListEnd()
-        else:
-          iprot.skip(ftype)
-      elif fid == 8:
-        if ftype == TType.MAP:
-          self.arbitraryDataMapMap = {}
-          (_ktype31, _vtype32, _size30 ) = iprot.readMapBegin()
-          for _i34 in xrange(_size30):
-            _key35 = iprot.readI32();
-            _val36 = {}
-            (_ktype38, _vtype39, _size37 ) = iprot.readMapBegin()
-            for _i41 in xrange(_size37):
-              _key42 = iprot.readString();
-              _val43 = iprot.readString();
-              _val36[_key42] = _val43
-            iprot.readMapEnd()
-            self.arbitraryDataMapMap[_key35] = _val36
-          iprot.readMapEnd()
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftEventBundle')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.eventNum is not None:
-      oprot.writeFieldBegin('eventNum', TType.I32, 2)
-      oprot.writeI32(self.eventNum)
-      oprot.writeFieldEnd()
-    if self.intAttributeList is not None:
-      oprot.writeFieldBegin('intAttributeList', TType.LIST, 3)
-      oprot.writeListBegin(TType.I32, len(self.intAttributeList))
-      for iter44 in self.intAttributeList:
-        oprot.writeI32(iter44)
-      oprot.writeListEnd()
-      oprot.writeFieldEnd()
-    if self.longAttributeList is not None:
-      oprot.writeFieldBegin('longAttributeList', TType.LIST, 4)
-      oprot.writeListBegin(TType.I64, len(self.longAttributeList))
-      for iter45 in self.longAttributeList:
-        oprot.writeI64(iter45)
-      oprot.writeListEnd()
-      oprot.writeFieldEnd()
-    if self.doubleAttributeList is not None:
-      oprot.writeFieldBegin('doubleAttributeList', TType.LIST, 5)
-      oprot.writeListBegin(TType.DOUBLE, len(self.doubleAttributeList))
-      for iter46 in self.doubleAttributeList:
-        oprot.writeDouble(iter46)
-      oprot.writeListEnd()
-      oprot.writeFieldEnd()
-    if self.boolAttributeList is not None:
-      oprot.writeFieldBegin('boolAttributeList', TType.LIST, 6)
-      oprot.writeListBegin(TType.BOOL, len(self.boolAttributeList))
-      for iter47 in self.boolAttributeList:
-        oprot.writeBool(iter47)
-      oprot.writeListEnd()
-      oprot.writeFieldEnd()
-    if self.stringAttributeList is not None:
-      oprot.writeFieldBegin('stringAttributeList', TType.LIST, 7)
-      oprot.writeListBegin(TType.STRING, len(self.stringAttributeList))
-      for iter48 in self.stringAttributeList:
-        oprot.writeString(iter48)
-      oprot.writeListEnd()
-      oprot.writeFieldEnd()
-    if self.arbitraryDataMapMap is not None:
-      oprot.writeFieldBegin('arbitraryDataMapMap', TType.MAP, 8)
-      oprot.writeMapBegin(TType.I32, TType.MAP, len(self.arbitraryDataMapMap))
-      for kiter49,viter50 in self.arbitraryDataMapMap.items():
-        oprot.writeI32(kiter49)
-        oprot.writeMapBegin(TType.STRING, TType.STRING, len(viter50))
-        for kiter51,viter52 in viter50.items():
-          oprot.writeString(kiter51)
-          oprot.writeString(viter52)
-        oprot.writeMapEnd()
-      oprot.writeMapEnd()
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py
deleted file mode 100644
index adefd8e..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-__all__ = ['ttypes', 'constants']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py
deleted file mode 100644
index 36943ba..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py
deleted file mode 100644
index 9fbb1ce..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py
+++ /dev/null
@@ -1,473 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
-
-from ...thrift.transport import TTransport
-from ...thrift.protocol import TBinaryProtocol, TProtocol
-try:
-  from ...thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-
-
-class ThriftStreamDefinitionException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftStreamDefinitionException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftNoStreamDefinitionExistException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftNoStreamDefinitionExistException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftDifferentStreamDefinitionAlreadyDefinedException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftDifferentStreamDefinitionAlreadyDefinedException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftMalformedStreamDefinitionException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftMalformedStreamDefinitionException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftUndefinedEventTypeException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftUndefinedEventTypeException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftSessionExpiredException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftSessionExpiredException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class ThriftAuthenticationException(TException):
-  """
-  Attributes:
-   - message
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'message', None, None, ), # 1
-  )
-
-  def __init__(self, message=None,):
-    self.message = message
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('ThriftAuthenticationException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    if self.message is None:
-      raise TProtocol.TProtocolException(message='Required field message is unset!')
-    return
-
-
-  def __str__(self):
-    return repr(self)
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
deleted file mode 100755
index 0d18f58..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/usr/bin/env python
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-import sys
-import pprint
-from urlparse import urlparse
-
-from thrift.transport import TTransport
-from thrift.transport import TSocket
-from thrift.transport import THttpClient
-from thrift.protocol import TBinaryProtocol
-from ThriftEventTransmissionService import ThriftEventTransmissionService
-from ThriftEventTransmissionService.ttypes import *
-
-
-if len(sys.argv) <= 1 or sys.argv[1] == '--help':
-  print ''
-  print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
-  print ''
-  print 'Functions:'
-  print '  string defineStream(string sessionId, string streamDefinition)'
-  print '  string findStreamId(string sessionId, string streamName, string streamVersion)'
-  print '  void publish(ThriftEventBundle eventBundle)'
-  print '  bool deleteStreamById(string sessionId, string streamId)'
-  print '  bool deleteStreamByNameVersion(string sessionId, string streamName, string streamVersion)'
-  print ''
-  sys.exit(0)
-
-pp = pprint.PrettyPrinter(indent = 2)
-host = 'localhost'
-port = 9090
-uri = ''
-framed = False
-http = False
-argi = 1
-
-if sys.argv[argi] == '-h':
-  parts = sys.argv[argi+1].split(':')
-  host = parts[0]
-  if len(parts) > 1:
-    port = int(parts[1])
-  argi += 2
-
-if sys.argv[argi] == '-u':
-  url = urlparse(sys.argv[argi+1])
-  parts = url[1].split(':')
-  host = parts[0]
-  if len(parts) > 1:
-    port = int(parts[1])
-  else:
-    port = 80
-  uri = url[2]
-  if url[4]:
-    uri += '?%s' % url[4]
-  http = True
-  argi += 2
-
-if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
-  framed = True
-  argi += 1
-
-cmd = sys.argv[argi]
-args = sys.argv[argi+1:]
-
-if http:
-  transport = THttpClient.THttpClient(host, port, uri)
-else:
-  socket = TSocket.TSocket(host, port)
-  if framed:
-    transport = TTransport.TFramedTransport(socket)
-  else:
-    transport = TTransport.TBufferedTransport(socket)
-protocol = TBinaryProtocol.TBinaryProtocol(transport)
-client = ThriftEventTransmissionService.Client(protocol)
-transport.open()
-
-if cmd == 'defineStream':
-  if len(args) != 2:
-    print 'defineStream requires 2 args'
-    sys.exit(1)
-  pp.pprint(client.defineStream(args[0],args[1],))
-
-elif cmd == 'findStreamId':
-  if len(args) != 3:
-    print 'findStreamId requires 3 args'
-    sys.exit(1)
-  pp.pprint(client.findStreamId(args[0],args[1],args[2],))
-
-elif cmd == 'publish':
-  if len(args) != 1:
-    print 'publish requires 1 args'
-    sys.exit(1)
-  pp.pprint(client.publish(eval(args[0]),))
-
-elif cmd == 'deleteStreamById':
-  if len(args) != 2:
-    print 'deleteStreamById requires 2 args'
-    sys.exit(1)
-  pp.pprint(client.deleteStreamById(args[0],args[1],))
-
-elif cmd == 'deleteStreamByNameVersion':
-  if len(args) != 3:
-    print 'deleteStreamByNameVersion requires 3 args'
-    sys.exit(1)
-  pp.pprint(client.deleteStreamByNameVersion(args[0],args[1],args[2],))
-
-else:
-  print 'Unrecognized method %s' % cmd
-  sys.exit(1)
-
-transport.close()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
deleted file mode 100644
index 4a5a252..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
+++ /dev/null
@@ -1,1143 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ttypes import *
-from ...thrift.Thrift import TProcessor
-from ...thrift.transport import TTransport
-
-try:
-  from ...thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-
-class Iface:
-  def defineStream(self, sessionId, streamDefinition):
-    """
-    Parameters:
-     - sessionId
-     - streamDefinition
-    """
-    pass
-
-  def findStreamId(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    pass
-
-  def publish(self, eventBundle):
-    """
-    Parameters:
-     - eventBundle
-    """
-    pass
-
-  def deleteStreamById(self, sessionId, streamId):
-    """
-    Parameters:
-     - sessionId
-     - streamId
-    """
-    pass
-
-  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    pass
-
-
-class Client(Iface):
-  def __init__(self, iprot, oprot=None):
-    self._iprot = self._oprot = iprot
-    if oprot is not None:
-      self._oprot = oprot
-    self._seqid = 0
-
-  def defineStream(self, sessionId, streamDefinition):
-    """
-    Parameters:
-     - sessionId
-     - streamDefinition
-    """
-    self.send_defineStream(sessionId, streamDefinition)
-    return self.recv_defineStream()
-
-  def send_defineStream(self, sessionId, streamDefinition):
-    self._oprot.writeMessageBegin('defineStream', TMessageType.CALL, self._seqid)
-    args = defineStream_args()
-    args.sessionId = sessionId
-    args.streamDefinition = streamDefinition
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_defineStream(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = defineStream_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.ade is not None:
-      raise result.ade
-    if result.mtd is not None:
-      raise result.mtd
-    if result.tde is not None:
-      raise result.tde
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "defineStream failed: unknown result");
-
-  def findStreamId(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    self.send_findStreamId(sessionId, streamName, streamVersion)
-    return self.recv_findStreamId()
-
-  def send_findStreamId(self, sessionId, streamName, streamVersion):
-    self._oprot.writeMessageBegin('findStreamId', TMessageType.CALL, self._seqid)
-    args = findStreamId_args()
-    args.sessionId = sessionId
-    args.streamName = streamName
-    args.streamVersion = streamVersion
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_findStreamId(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = findStreamId_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.tnde is not None:
-      raise result.tnde
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "findStreamId failed: unknown result");
-
-  def publish(self, eventBundle):
-    """
-    Parameters:
-     - eventBundle
-    """
-    self.send_publish(eventBundle)
-    self.recv_publish()
-
-  def send_publish(self, eventBundle):
-    self._oprot.writeMessageBegin('publish', TMessageType.CALL, self._seqid)
-    args = publish_args()
-    args.eventBundle = eventBundle
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_publish(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = publish_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.ue is not None:
-      raise result.ue
-    if result.se is not None:
-      raise result.se
-    return
-
-  def deleteStreamById(self, sessionId, streamId):
-    """
-    Parameters:
-     - sessionId
-     - streamId
-    """
-    self.send_deleteStreamById(sessionId, streamId)
-    return self.recv_deleteStreamById()
-
-  def send_deleteStreamById(self, sessionId, streamId):
-    self._oprot.writeMessageBegin('deleteStreamById', TMessageType.CALL, self._seqid)
-    args = deleteStreamById_args()
-    args.sessionId = sessionId
-    args.streamId = streamId
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_deleteStreamById(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = deleteStreamById_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamById failed: unknown result");
-
-  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    self.send_deleteStreamByNameVersion(sessionId, streamName, streamVersion)
-    return self.recv_deleteStreamByNameVersion()
-
-  def send_deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    self._oprot.writeMessageBegin('deleteStreamByNameVersion', TMessageType.CALL, self._seqid)
-    args = deleteStreamByNameVersion_args()
-    args.sessionId = sessionId
-    args.streamName = streamName
-    args.streamVersion = streamVersion
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_deleteStreamByNameVersion(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = deleteStreamByNameVersion_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamByNameVersion failed: unknown result");
-
-
-class Processor(Iface, TProcessor):
-  def __init__(self, handler):
-    self._handler = handler
-    self._processMap = {}
-    self._processMap["defineStream"] = Processor.process_defineStream
-    self._processMap["findStreamId"] = Processor.process_findStreamId
-    self._processMap["publish"] = Processor.process_publish
-    self._processMap["deleteStreamById"] = Processor.process_deleteStreamById
-    self._processMap["deleteStreamByNameVersion"] = Processor.process_deleteStreamByNameVersion
-
-  def process(self, iprot, oprot):
-    (name, type, seqid) = iprot.readMessageBegin()
-    if name not in self._processMap:
-      iprot.skip(TType.STRUCT)
-      iprot.readMessageEnd()
-      x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
-      oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
-      x.write(oprot)
-      oprot.writeMessageEnd()
-      oprot.trans.flush()
-      return
-    else:
-      self._processMap[name](self, seqid, iprot, oprot)
-    return True
-
-  def process_defineStream(self, seqid, iprot, oprot):
-    args = defineStream_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = defineStream_result()
-    try:
-      result.success = self._handler.defineStream(args.sessionId, args.streamDefinition)
-    except Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ade:
-      result.ade = ade
-    except Exception.ttypes.ThriftMalformedStreamDefinitionException, mtd:
-      result.mtd = mtd
-    except Exception.ttypes.ThriftStreamDefinitionException, tde:
-      result.tde = tde
-    except Exception.ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("defineStream", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_findStreamId(self, seqid, iprot, oprot):
-    args = findStreamId_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = findStreamId_result()
-    try:
-      result.success = self._handler.findStreamId(args.sessionId, args.streamName, args.streamVersion)
-    except Exception.ttypes.ThriftNoStreamDefinitionExistException, tnde:
-      result.tnde = tnde
-    except Exception.ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("findStreamId", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_publish(self, seqid, iprot, oprot):
-    args = publish_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = publish_result()
-    try:
-      self._handler.publish(args.eventBundle)
-    except Exception.ttypes.ThriftUndefinedEventTypeException, ue:
-      result.ue = ue
-    except Exception.ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("publish", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_deleteStreamById(self, seqid, iprot, oprot):
-    args = deleteStreamById_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = deleteStreamById_result()
-    try:
-      result.success = self._handler.deleteStreamById(args.sessionId, args.streamId)
-    except Exception.ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("deleteStreamById", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_deleteStreamByNameVersion(self, seqid, iprot, oprot):
-    args = deleteStreamByNameVersion_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = deleteStreamByNameVersion_result()
-    try:
-      result.success = self._handler.deleteStreamByNameVersion(args.sessionId, args.streamName, args.streamVersion)
-    except Exception.ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("deleteStreamByNameVersion", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-
-# HELPER FUNCTIONS AND STRUCTURES
-
-class defineStream_args:
-  """
-  Attributes:
-   - sessionId
-   - streamDefinition
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamDefinition', None, None, ), # 2
-  )
-
-  def __init__(self, sessionId=None, streamDefinition=None,):
-    self.sessionId = sessionId
-    self.streamDefinition = streamDefinition
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamDefinition = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('defineStream_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamDefinition is not None:
-      oprot.writeFieldBegin('streamDefinition', TType.STRING, 2)
-      oprot.writeString(self.streamDefinition)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class defineStream_result:
-  """
-  Attributes:
-   - success
-   - ade
-   - mtd
-   - tde
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.STRING, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'ade', (Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'mtd', (Exception.ttypes.ThriftMalformedStreamDefinitionException, Exception.ttypes.ThriftMalformedStreamDefinitionException.thrift_spec), None, ), # 2
-    (3, TType.STRUCT, 'tde', (Exception.ttypes.ThriftStreamDefinitionException, Exception.ttypes.ThriftStreamDefinitionException.thrift_spec), None, ), # 3
-    (4, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 4
-  )
-
-  def __init__(self, success=None, ade=None, mtd=None, tde=None, se=None,):
-    self.success = success
-    self.ade = ade
-    self.mtd = mtd
-    self.tde = tde
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.STRING:
-          self.success = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.ade = Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException()
-          self.ade.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.mtd = Exception.ttypes.ThriftMalformedStreamDefinitionException()
-          self.mtd.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRUCT:
-          self.tde = Exception.ttypes.ThriftStreamDefinitionException()
-          self.tde.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 4:
-        if ftype == TType.STRUCT:
-          self.se = Exception.ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('defineStream_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.STRING, 0)
-      oprot.writeString(self.success)
-      oprot.writeFieldEnd()
-    if self.ade is not None:
-      oprot.writeFieldBegin('ade', TType.STRUCT, 1)
-      self.ade.write(oprot)
-      oprot.writeFieldEnd()
-    if self.mtd is not None:
-      oprot.writeFieldBegin('mtd', TType.STRUCT, 2)
-      self.mtd.write(oprot)
-      oprot.writeFieldEnd()
-    if self.tde is not None:
-      oprot.writeFieldBegin('tde', TType.STRUCT, 3)
-      self.tde.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 4)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class findStreamId_args:
-  """
-  Attributes:
-   - sessionId
-   - streamName
-   - streamVersion
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamName', None, None, ), # 2
-    (3, TType.STRING, 'streamVersion', None, None, ), # 3
-  )
-
-  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
-    self.sessionId = sessionId
-    self.streamName = streamName
-    self.streamVersion = streamVersion
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamName = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRING:
-          self.streamVersion = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('findStreamId_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamName is not None:
-      oprot.writeFieldBegin('streamName', TType.STRING, 2)
-      oprot.writeString(self.streamName)
-      oprot.writeFieldEnd()
-    if self.streamVersion is not None:
-      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
-      oprot.writeString(self.streamVersion)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class findStreamId_result:
-  """
-  Attributes:
-   - success
-   - tnde
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.STRING, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'tnde', (Exception.ttypes.ThriftNoStreamDefinitionExistException, Exception.ttypes.ThriftNoStreamDefinitionExistException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
-  )
-
-  def __init__(self, success=None, tnde=None, se=None,):
-    self.success = success
-    self.tnde = tnde
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.STRING:
-          self.success = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.tnde = Exception.ttypes.ThriftNoStreamDefinitionExistException()
-          self.tnde.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.se = Exception.ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('findStreamId_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.STRING, 0)
-      oprot.writeString(self.success)
-      oprot.writeFieldEnd()
-    if self.tnde is not None:
-      oprot.writeFieldBegin('tnde', TType.STRUCT, 1)
-      self.tnde.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 2)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class publish_args:
-  """
-  Attributes:
-   - eventBundle
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRUCT, 'eventBundle', (Data.ttypes.ThriftEventBundle, Data.ttypes.ThriftEventBundle.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, eventBundle=None,):
-    self.eventBundle = eventBundle
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRUCT:
-          self.eventBundle = Data.ttypes.ThriftEventBundle()
-          self.eventBundle.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('publish_args')
-    if self.eventBundle is not None:
-      oprot.writeFieldBegin('eventBundle', TType.STRUCT, 1)
-      self.eventBundle.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class publish_result:
-  """
-  Attributes:
-   - ue
-   - se
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRUCT, 'ue', (Exception.ttypes.ThriftUndefinedEventTypeException, Exception.ttypes.ThriftUndefinedEventTypeException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
-  )
-
-  def __init__(self, ue=None, se=None,):
-    self.ue = ue
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRUCT:
-          self.ue = Exception.ttypes.ThriftUndefinedEventTypeException()
-          self.ue.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.se = Exception.ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('publish_result')
-    if self.ue is not None:
-      oprot.writeFieldBegin('ue', TType.STRUCT, 1)
-      self.ue.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 2)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamById_args:
-  """
-  Attributes:
-   - sessionId
-   - streamId
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamId', None, None, ), # 2
-  )
-
-  def __init__(self, sessionId=None, streamId=None,):
-    self.sessionId = sessionId
-    self.streamId = streamId
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamById_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamId is not None:
-      oprot.writeFieldBegin('streamId', TType.STRING, 2)
-      oprot.writeString(self.streamId)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamById_result:
-  """
-  Attributes:
-   - success
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.BOOL, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, success=None, se=None,):
-    self.success = success
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.BOOL:
-          self.success = iprot.readBool();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.se = Exception.ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamById_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.BOOL, 0)
-      oprot.writeBool(self.success)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 1)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamByNameVersion_args:
-  """
-  Attributes:
-   - sessionId
-   - streamName
-   - streamVersion
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamName', None, None, ), # 2
-    (3, TType.STRING, 'streamVersion', None, None, ), # 3
-  )
-
-  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
-    self.sessionId = sessionId
-    self.streamName = streamName
-    self.streamVersion = streamVersion
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamName = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRING:
-          self.streamVersion = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamByNameVersion_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamName is not None:
-      oprot.writeFieldBegin('streamName', TType.STRING, 2)
-      oprot.writeString(self.streamName)
-      oprot.writeFieldEnd()
-    if self.streamVersion is not None:
-      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
-      oprot.writeString(self.streamVersion)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamByNameVersion_result:
-  """
-  Attributes:
-   - success
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.BOOL, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, success=None, se=None,):
-    self.success = success
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.BOOL:
-          self.success = iprot.readBool();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.se = Exception.ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamByNameVersion_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.BOOL, 0)
-      oprot.writeBool(self.success)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 1)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
deleted file mode 100644
index 38575a6..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-__all__ = ['ttypes', 'constants', 'ThriftEventTransmissionService']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
deleted file mode 100644
index 36943ba..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
deleted file mode 100644
index 37ac241..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
-from ..Data import ttypes
-from ..Exception import ttypes
-
-
-from ...thrift.transport import TTransport
-from ...thrift.protocol import TBinaryProtocol, TProtocol
-try:
-  from thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
deleted file mode 100755
index 46757bf..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/usr/bin/env python
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-import sys
-import pprint
-from urlparse import urlparse
-
-from thrift.transport import TTransport
-from thrift.transport import TSocket
-from thrift.transport import THttpClient
-from thrift.protocol import TBinaryProtocol
-from ThriftSecureEventTransmissionService import ThriftSecureEventTransmissionService
-from ThriftSecureEventTransmissionService.ttypes import *
-
-
-if len(sys.argv) <= 1 or sys.argv[1] == '--help':
-  print ''
-  print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
-  print ''
-  print 'Functions:'
-  print '  string connect(string userName, string password)'
-  print '  void disconnect(string sessionId)'
-  print '  string defineStream(string sessionId, string streamDefinition)'
-  print '  string findStreamId(string sessionId, string streamName, string streamVersion)'
-  print '  void publish(ThriftEventBundle eventBundle)'
-  print '  bool deleteStreamById(string sessionId, string streamId)'
-  print '  bool deleteStreamByNameVersion(string sessionId, string streamName, string streamVersion)'
-  print ''
-  sys.exit(0)
-
-pp = pprint.PrettyPrinter(indent = 2)
-host = 'localhost'
-port = 9090
-uri = ''
-framed = False
-http = False
-argi = 1
-
-if sys.argv[argi] == '-h':
-  parts = sys.argv[argi+1].split(':')
-  host = parts[0]
-  if len(parts) > 1:
-    port = int(parts[1])
-  argi += 2
-
-if sys.argv[argi] == '-u':
-  url = urlparse(sys.argv[argi+1])
-  parts = url[1].split(':')
-  host = parts[0]
-  if len(parts) > 1:
-    port = int(parts[1])
-  else:
-    port = 80
-  uri = url[2]
-  if url[4]:
-    uri += '?%s' % url[4]
-  http = True
-  argi += 2
-
-if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
-  framed = True
-  argi += 1
-
-cmd = sys.argv[argi]
-args = sys.argv[argi+1:]
-
-if http:
-  transport = THttpClient.THttpClient(host, port, uri)
-else:
-  socket = TSocket.TSocket(host, port)
-  if framed:
-    transport = TTransport.TFramedTransport(socket)
-  else:
-    transport = TTransport.TBufferedTransport(socket)
-protocol = TBinaryProtocol.TBinaryProtocol(transport)
-client = ThriftSecureEventTransmissionService.Client(protocol)
-transport.open()
-
-if cmd == 'connect':
-  if len(args) != 2:
-    print 'connect requires 2 args'
-    sys.exit(1)
-  pp.pprint(client.connect(args[0],args[1],))
-
-elif cmd == 'disconnect':
-  if len(args) != 1:
-    print 'disconnect requires 1 args'
-    sys.exit(1)
-  pp.pprint(client.disconnect(args[0],))
-
-elif cmd == 'defineStream':
-  if len(args) != 2:
-    print 'defineStream requires 2 args'
-    sys.exit(1)
-  pp.pprint(client.defineStream(args[0],args[1],))
-
-elif cmd == 'findStreamId':
-  if len(args) != 3:
-    print 'findStreamId requires 3 args'
-    sys.exit(1)
-  pp.pprint(client.findStreamId(args[0],args[1],args[2],))
-
-elif cmd == 'publish':
-  if len(args) != 1:
-    print 'publish requires 1 args'
-    sys.exit(1)
-  pp.pprint(client.publish(eval(args[0]),))
-
-elif cmd == 'deleteStreamById':
-  if len(args) != 2:
-    print 'deleteStreamById requires 2 args'
-    sys.exit(1)
-  pp.pprint(client.deleteStreamById(args[0],args[1],))
-
-elif cmd == 'deleteStreamByNameVersion':
-  if len(args) != 3:
-    print 'deleteStreamByNameVersion requires 3 args'
-    sys.exit(1)
-  pp.pprint(client.deleteStreamByNameVersion(args[0],args[1],args[2],))
-
-else:
-  print 'Unrecognized method %s' % cmd
-  sys.exit(1)
-
-transport.close()


[08/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/events.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/events.py
new file mode 100644
index 0000000..c000c55
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/events.py
@@ -0,0 +1,98 @@
+# 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.
+
+import json
+
+
+class InstanceActivatedEvent:
+    def __init__(self, service_name, cluster_id, network_partition_id, parition_id, member_id):
+        self.serviceName = service_name
+        """ :type : str  """
+        self.clusterId = cluster_id
+        """ :type : str  """
+        self.networkPartitionId = network_partition_id
+        """ :type : str  """
+        self.partitionId = parition_id
+        """ :type : str  """
+        self.memberId = member_id
+        """ :type : str  """
+
+    def to_json(self):
+        return to_json(self)
+
+
+class InstanceStartedEvent:
+    def __init__(self, service_name, cluster_id, network_partition_id, parition_id, member_id):
+        self.serviceName = service_name
+        """ :type : str  """
+        self.clusterId = cluster_id
+        """ :type : str  """
+        self.networkPartitionId = network_partition_id
+        """ :type : str  """
+        self.partitionId = parition_id
+        """ :type : str  """
+        self.memberId = member_id
+        """ :type : str  """
+
+    def to_json(self):
+        return to_json(self)
+
+
+class InstanceMaintenanceModeEvent:
+
+    def __init__(self, service_name, cluster_id, network_partition_id, partition_id, member_id):
+        self.serviceName = service_name
+        """ :type : str  """
+        self.clusterId = cluster_id
+        """ :type : str  """
+        self.networkPartitionId = network_partition_id
+        """ :type : str  """
+        self.partitionId = partition_id
+        """ :type : str  """
+        self.memberId = member_id
+        """ :type : str  """
+
+    def to_json(self):
+        return to_json(self)
+
+
+class InstanceReadyToShutdownEvent:
+
+    def __init__(self, service_name, cluster_id, network_partition_id, partition_id, member_id):
+        self.serviceName = service_name
+        """ :type : str  """
+        self.clusterId = cluster_id
+        """ :type : str  """
+        self.networkPartitionId = network_partition_id
+        """ :type : str  """
+        self.partitionId = partition_id
+        """ :type : str  """
+        self.memberId = member_id
+        """ :type : str  """
+
+    def to_json(self):
+        return to_json(self)
+
+
+def to_json(instance):
+    """
+    common function to serialize status event object
+    :param obj instance:
+    :return: serialized json string
+    :rtype str
+    """
+    return json.dumps(instance, default=lambda o: o.__dict__, sort_keys=True, indent=4)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/events.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/events.py
new file mode 100644
index 0000000..def2b64
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/event/tenant/events.py
@@ -0,0 +1,147 @@
+# 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.
+
+import json
+from ... tenant.tenantcontext import *
+
+
+class SubscriptionDomainAddedEvent():
+
+    def __init__(self):
+        self.tenant_id = None
+        """ :type : int  """
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_ids = None
+        """ :type : list[str]  """
+        self.domain_name = None
+        """ :type : str  """
+        self.application_context = None
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = SubscriptionDomainAddedEvent()
+
+        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
+        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.domain_name = json_obj["domainName"] if "domainName" in json_obj else None
+        instance.application_context = json_obj["applicationContext"] if "applicationContext" in json_obj else None
+
+        return instance
+
+
+class SubscriptionDomainRemovedEvent:
+
+    def __init__(self, tenant_id, service_name, cluster_ids, domain_name):
+        self.tenant_id = tenant_id
+        """ :type : int  """
+        self.service_name = service_name
+        """ :type : str  """
+        self.cluster_ids = cluster_ids
+        """ :type : list[str]  """
+        self.domain_name = domain_name
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = SubscriptionDomainRemovedEvent()
+
+        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
+        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.domain_name = json_obj["domainName"] if "domainName" in json_obj else None
+
+        return instance
+
+
+class CompleteTenantEvent:
+
+    def __init__(self):
+        self.tenants = []
+        """ :type : list[Tenant]  """
+        self.tenant_list_json = None
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = CompleteTenantEvent()
+        instance.tenants = []
+
+        tenants_str = json_obj["tenants"] if "tenants" in json_obj else None
+        instance.tenant_list_json = tenants_str
+        if tenants_str is not None:
+            for tenant_str in tenants_str:
+                tenant_obj = Tenant(int(tenant_str["tenantId"]), tenant_str["tenantDomain"])
+                for service_name in tenant_str["serviceNameSubscriptionMap"]:
+                    sub_str = tenant_str["serviceNameSubscriptionMap"][service_name]
+                    sub = Subscription(sub_str["serviceName"], sub_str["clusterIds"])
+                    for domain_name in sub_str["subscriptionDomainMap"]:
+                        subdomain_str = sub_str["subscriptionDomainMap"][domain_name]
+                        sub.add_subscription_domain(domain_name, subdomain_str["applicationContext"])
+                    tenant_obj.add_subscription(sub)
+                instance.tenants.append(tenant_obj)
+
+        return instance
+
+
+class TenantSubscribedEvent:
+
+    def __init__(self):
+        self.tenant_id = None
+        """ :type : int  """
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_ids = None
+        """ :type : list[str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = TenantSubscribedEvent()
+
+        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
+
+        return instance
+
+
+class TenantUnsubscribedEvent:
+
+    def __init__(self):
+        self.tenant_id = None
+        """ :type : int  """
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_ids = None
+        """ :type : list[str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = TenantUnsubscribedEvent()
+
+        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None
+
+        return instance
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/events.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/events.py
new file mode 100644
index 0000000..52c7c19
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/event/topology/events.py
@@ -0,0 +1,280 @@
+# 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.
+
+import json
+
+from ... topology.topologycontext import *
+
+
+class MemberActivatedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+        self.port_map = {}
+        """ :type : dict[str, Port]  """
+        self.member_ip = None
+        """ :type : str  """
+
+    def get_port(self, proxy_port):
+        """
+        Returns the port object of the provided port id
+        :param str proxy_port:
+        :return: Port object, None if the port id is invalid
+        :rtype: topology.topologycontext.Port
+        """
+        if proxy_port in self.port_map:
+            return self.port_map[proxy_port]
+
+        return None
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = MemberActivatedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        #instance.port_map = json_obj["portMap"] if "portMap" in json_obj else {}
+        instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None
+
+        for port_proxy in json_obj["portMap"]:
+            port_str = json_obj["portMap"][port_proxy]
+            port_obj = Port(port_str["protocol"], port_str["value"], port_proxy)
+            instance.port_map[port_proxy] = port_obj
+
+        return instance
+
+
+class MemberTerminatedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = MemberTerminatedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        instance.properties = json_obj["properties"] if "properties" in json_obj else None
+
+        return instance
+
+
+class MemberSuspendedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = MemberSuspendedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+
+        return instance
+
+
+class CompleteTopologyEvent:
+
+    def __init__(self):
+        self.topology = None
+        """ :type :  Topology """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = CompleteTopologyEvent()
+
+        topology_str = json_obj["topology"] if "topology" in json_obj else None
+        if topology_str is not None:
+            topology_obj = Topology()
+            topology_obj.json_str = topology_str
+
+            #add service map
+            for service_name in topology_str["serviceMap"]:
+                service_str = topology_str["serviceMap"][service_name]
+
+                service_obj = Service(service_name, service_str["serviceType"])
+                service_obj.properties = service_str["properties"]
+                # add ports to port map
+                for port_proxy in service_str["portMap"]:
+                    port_str = service_str["portMap"][port_proxy]
+                    port_obj = Port(port_str["protocol"], port_str["value"], port_proxy)
+                    service_obj.add_port(port_obj)
+
+                #add cluster map
+                for cluster_id in service_str["clusterIdClusterMap"]:
+                    cluster_str = service_str["clusterIdClusterMap"][cluster_id]
+                    cl_service_name = cluster_str["serviceName"]
+                    cl_autoscale_policy_name = cluster_str["autoscalePolicyName"]
+                    cl_deployment_policy_name = cluster_str["deploymentPolicyName"] if "deploymentPolicyName" in cluster_str else None
+
+                    cluster_obj = Cluster(cl_service_name, cluster_id, cl_deployment_policy_name, cl_autoscale_policy_name)
+                    cluster_obj.hostnames = cluster_str["hostNames"]
+                    cluster_obj.tenant_range = cluster_str["tenantRange"] if "tenantRange" in cluster_str else None
+                    cluster_obj.is_lb_cluster = cluster_str["isLbCluster"]
+                    cluster_obj.is_kubernetes_cluster = cluster_str["isKubernetesCluster"]
+                    cluster_obj.status = cluster_str["status"]
+                    cluster_obj.load_balancer_algorithm_name = cluster_str["loadBalanceAlgorithmName"] if "loadBalanceAlgorithmName" in cluster_str else None
+                    cluster_obj.properties = cluster_str["properties"]
+                    cluster_obj.member_list_json = cluster_str["memberMap"]
+
+                    #add member map
+                    for member_id in cluster_str["memberMap"]:
+                        member_str = cluster_str["memberMap"][member_id]
+                        mm_service_name = member_str["serviceName"]
+                        mm_cluster_id = member_str["clusterId"]
+                        mm_network_partition_id = member_str["networkPartitionId"] if "networkPartitionId" in member_str else None
+                        mm_partition_id = member_str["partitionId"] if "partitionId" in member_str else None
+
+                        member_obj = Member(mm_service_name, mm_cluster_id, mm_network_partition_id, mm_partition_id, member_id)
+                        member_obj.member_public_ip = member_str["memberPublicIp"]
+                        member_obj.status = member_str["status"]
+                        member_obj.member_ip = member_str["memberIp"]
+                        member_obj.properties = member_str["properties"]
+                        member_obj.lb_cluster_id = member_str["lbClusterId"] if "lbClusterId" in member_str else None
+                        member_obj.json_str = member_str
+
+                        #add port map
+                        for mm_port_proxy in member_str["portMap"]:
+                            mm_port_str = member_str["portMap"][mm_port_proxy]
+                            mm_port_obj = Port(mm_port_str["protocol"], mm_port_str["value"], mm_port_proxy)
+                            member_obj.add_port(mm_port_obj)
+                        cluster_obj.add_member(member_obj)
+                    service_obj.add_cluster(cluster_obj)
+                topology_obj.add_service(service_obj)
+            instance.topology = topology_obj
+
+        return instance
+
+    def get_topology(self):
+        return self.topology
+
+
+class MemberStartedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+        self.status = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = MemberStartedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        instance.properties = json_obj["properties"] if "properties" in json_obj else None
+
+        return instance
+
+
+class InstanceSpawnedEvent:
+
+    def __init__(self):
+        self.service_name = None
+        """ :type : str  """
+        self.cluster_id = None
+        """ :type : str  """
+        self.network_partition_id = None
+        """ :type : str  """
+        self.partition_id = None
+        """ :type : str  """
+        self.member_id = None
+        """ :type : str  """
+        self.lb_cluster_id = None
+        """ :type : str  """
+        self.member_public_ip = None
+        """ :type : str  """
+        self.member_ip = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = InstanceSpawnedEvent()
+
+        instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None
+        instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None
+        instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None
+        instance.lb_cluster_id = json_obj["lbClusterId"] if "lbClusterId" in json_obj else None
+        instance.member_public_ip = json_obj["memberPublicIp"] if "memberPublicIp" in json_obj else None
+        instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None
+        instance.properties = json_obj["properties"]
+
+        return instance
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/exception/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/exception/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/exception/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/exception/parameternotfoundexception.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/exception/parameternotfoundexception.py b/tools/python-cartridge-agent/cartridgeagent/modules/exception/parameternotfoundexception.py
new file mode 100644
index 0000000..88deafd
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/exception/parameternotfoundexception.py
@@ -0,0 +1,35 @@
+# 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.
+
+class ParameterNotFoundException(Exception):
+    """
+    Exception raised when a property is not present in the configuration or the payload
+    of the cartridge agent
+    """
+    __message = None
+
+    def __init__(self, message):
+        Exception.__init__(self, message)
+        self.__message = message
+
+    def get_message(self):
+        """
+        The message provided when the exception is raised
+        :return: message
+        :rtype: str
+        """
+        return self.__message

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/extensions/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/extensions/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/extensions/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/extensions/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/extensions/abstractextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/extensions/abstractextensionhandler.py b/tools/python-cartridge-agent/cartridgeagent/modules/extensions/abstractextensionhandler.py
new file mode 100644
index 0000000..1f2df10
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/extensions/abstractextensionhandler.py
@@ -0,0 +1,78 @@
+# 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.
+
+class AbstractExtensionHandler:
+
+    def on_instance_started_event(self):
+        raise NotImplementedError
+
+    def on_instance_activated_event(self):
+        raise NotImplementedError
+
+    def on_artifact_updated_event(self, artifacts_updated_event):
+        raise NotImplementedError
+
+    def on_artifact_update_scheduler_event(self, tenant_id):
+        raise NotImplementedError
+
+    def on_instance_cleanup_cluster_event(self, instance_cleanup_cluster_event):
+        raise NotImplementedError
+
+    def on_instance_cleanup_member_event(self, instance_cleanup_member_event):
+        raise NotImplementedError
+
+    def on_member_activated_event(self, member_activated_event):
+        raise NotImplementedError
+
+    def on_complete_topology_event(self, complete_topology_event):
+        raise NotImplementedError
+
+    def on_instance_spawned_event(self, instance_spawned_event):
+        raise NotImplementedError
+
+    def on_complete_tenant_event(self, complete_tenant_event):
+        raise NotImplementedError
+
+    def on_member_terminated_event(self, member_terminated_event):
+        raise NotImplementedError
+
+    def on_member_suspended_event(self, member_suspended_event):
+        raise NotImplementedError
+
+    def on_member_started_event(self, member_started_event):
+        raise NotImplementedError
+
+    def start_server_extension(self):
+        raise NotImplementedError
+
+    def volume_mount_extension(self, persistence_mappings_payload):
+        raise NotImplementedError
+
+    def on_subscription_domain_added_event(self, subscription_domain_added_event):
+        raise NotImplementedError
+
+    def on_subscription_domain_removed_event(self, subscription_domain_removed_event):
+        raise NotImplementedError
+
+    def on_copy_artifacts_extension(self, src, des):
+        raise NotImplementedError
+
+    def on_tenant_subscribed_event(self, tenant_subscribed_event):
+            raise NotImplementedError
+
+    def on_tenant_unsubscribed_event(self, tenant_unsubscribed_event):
+            raise NotImplementedError

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/extensions/defaultextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/extensions/defaultextensionhandler.py b/tools/python-cartridge-agent/cartridgeagent/modules/extensions/defaultextensionhandler.py
new file mode 100644
index 0000000..8a7ccc0
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/extensions/defaultextensionhandler.py
@@ -0,0 +1,789 @@
+# 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.
+
+import time
+import json
+
+from abstractextensionhandler import AbstractExtensionHandler
+from ..util import extensionutils, cartridgeagentutils
+
+
+class DefaultExtensionHandler(AbstractExtensionHandler):
+    """
+    Default implementation of the AbstractExtensionHandler
+    """
+    log = None
+
+    def __init__(self):
+        self.log = LogFactory().get_log(__name__)
+        self.wk_members = []
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+    def on_instance_started_event(self):
+        try:
+            self.log.debug("Processing instance started event...")
+            if self.cartridge_agent_config.is_multitenant:
+                artifact_source = "%r/repository/deployment/server/" % self.cartridge_agent_config.app_path
+                artifact_dest = cartridgeagentconstants.SUPERTENANT_TEMP_PATH
+                extensionutils.execute_copy_artifact_extension(artifact_source, artifact_dest)
+
+            env_params = {}
+            extensionutils.execute_instance_started_extension(env_params)
+        except:
+            self.log.exception("Error processing instance started event")
+
+    def on_instance_activated_event(self):
+        extensionutils.execute_instance_activated_extension()
+
+    def on_artifact_updated_event(self, artifacts_updated_event):
+        self.log.info("Artifact update event received: [tenant] %r [cluster] %r [status] %r" %
+                      (artifacts_updated_event.tenant_id, artifacts_updated_event.cluster_id,
+                       artifacts_updated_event.status))
+
+        cluster_id_event = str(artifacts_updated_event.cluster_id).strip()
+        cluster_id_payload = self.cartridge_agent_config.cluster_id
+        repo_url = str(artifacts_updated_event.repo_url).strip()
+
+        if (repo_url != "") and (cluster_id_payload is not None) and (cluster_id_payload == cluster_id_event):
+            local_repo_path = self.cartridge_agent_config.app_path
+
+            secret = self.cartridge_agent_config.cartridge_key
+            repo_password = cartridgeagentutils.decrypt_password(artifacts_updated_event.repo_password, secret)
+
+            repo_username = artifacts_updated_event.repo_username
+            tenant_id = artifacts_updated_event.tenant_id
+            is_multitenant = self.cartridge_agent_config.is_multitenant
+            commit_enabled = artifacts_updated_event.commit_enabled
+
+            self.log.info("Executing git checkout")
+
+            # create repo object
+            repo_info = RepositoryInformation(repo_url, repo_username, repo_password, local_repo_path, tenant_id,
+                                              is_multitenant, commit_enabled)
+
+            # checkout code
+            subscribe_run, repo_context = agentgithandler.AgentGitHandler.checkout(repo_info)
+            # repo_context = checkout_result["repo_context"]
+            # execute artifact updated extension
+            env_params = {"STRATOS_ARTIFACT_UPDATED_CLUSTER_ID": artifacts_updated_event.cluster_id,
+                          "STRATOS_ARTIFACT_UPDATED_TENANT_ID": artifacts_updated_event.tenant_id,
+                          "STRATOS_ARTIFACT_UPDATED_REPO_URL": artifacts_updated_event.repo_url,
+                          "STRATOS_ARTIFACT_UPDATED_REPO_PASSWORD": artifacts_updated_event.repo_password,
+                          "STRATOS_ARTIFACT_UPDATED_REPO_USERNAME": artifacts_updated_event.repo_username,
+                          "STRATOS_ARTIFACT_UPDATED_STATUS": artifacts_updated_event.status}
+
+            extensionutils.execute_artifacts_updated_extension(env_params)
+
+            if subscribe_run:
+                # publish instanceActivated
+                cartridgeagentpublisher.publish_instance_activated_event()
+
+            update_artifacts = self.cartridge_agent_config.read_property(cartridgeagentconstants.ENABLE_ARTIFACT_UPDATE, False)
+            update_artifacts = True if str(update_artifacts).strip().lower() == "true" else False
+            if update_artifacts:
+                auto_commit = self.cartridge_agent_config.is_commits_enabled
+                auto_checkout = self.cartridge_agent_config.is_checkout_enabled
+
+                try:
+                    update_interval = len(
+                        self.cartridge_agent_config.read_property(cartridgeagentconstants.ARTIFACT_UPDATE_INTERVAL, False))
+                except ParameterNotFoundException:
+                    self.log.exception("Invalid artifact sync interval specified ")
+                    update_interval = 10
+                except ValueError:
+                    self.log.exception("Invalid artifact sync interval specified ")
+                    update_interval = 10
+
+                self.log.info("Artifact updating task enabled, update interval: %r seconds" % update_interval)
+
+                self.log.info("Auto Commit is turned %r " % "on" if auto_commit else "off")
+                self.log.info("Auto Checkout is turned %r " % "on" if auto_checkout else "off")
+
+                agentgithandler.AgentGitHandler.schedule_artifact_update_scheduled_task(repo_info, auto_checkout, auto_commit,
+                                                                        update_interval)
+
+    def on_artifact_update_scheduler_event(self, tenant_id):
+        env_params = {"STRATOS_ARTIFACT_UPDATED_TENANT_ID": tenant_id, "STRATOS_ARTIFACT_UPDATED_SCHEDULER": True}
+
+        extensionutils.execute_artifacts_updated_extension(env_params)
+
+    def on_instance_cleanup_cluster_event(self, instance_cleanup_cluster_event):
+        self.cleanup()
+
+    def on_instance_cleanup_member_event(self, instance_cleanup_member_event):
+        self.cleanup()
+
+    def on_member_activated_event(self, member_activated_event):
+        self.log.info("Member activated event received: [service] %r [cluster] %r [member] %r"
+            % (member_activated_event.service_name, member_activated_event.cluster_id, member_activated_event.member_id))
+
+        topology_consistent = extensionutils.check_topology_consistency(
+            member_activated_event.service_name,
+            member_activated_event.cluster_id,
+            member_activated_event.member_id)
+
+        if not topology_consistent:
+            self.log.error("Topology is inconsistent...failed to execute member activated event")
+            return
+
+        topology = TopologyContext.get_topology()
+        service = topology.get_service(member_activated_event.service_name)
+        cluster = service.get_cluster(member_activated_event.cluster_id)
+        member = cluster.get_member(member_activated_event.member_id)
+        lb_cluster_id = member.lb_cluster_id
+
+        if extensionutils.is_relevant_member_event(member_activated_event.service_name,
+                                                   member_activated_event.cluster_id, lb_cluster_id):
+
+            env_params = {"STRATOS_MEMBER_ACTIVATED_MEMBER_IP": str(member_activated_event.member_ip),
+                          "STRATOS_MEMBER_ACTIVATED_MEMBER_ID": str(member_activated_event.member_id),
+                          "STRATOS_MEMBER_ACTIVATED_CLUSTER_ID": str(member_activated_event.cluster_id),
+                          "STRATOS_MEMBER_ACTIVATED_LB_CLUSTER_ID": str(lb_cluster_id),
+                          "STRATOS_MEMBER_ACTIVATED_NETWORK_PARTITION_ID": str(member_activated_event.network_partition_id),
+                          "STRATOS_MEMBER_ACTIVATED_SERVICE_NAME": str(member_activated_event.service_name)}
+
+            ports = member_activated_event.port_map.values()
+            ports_str = ""
+            for port in ports:
+                ports_str += port.protocol + "," + str(port.value) + "," + str(port.proxy) + "|"
+
+            env_params["STRATOS_MEMBER_ACTIVATED_PORTS"] = ports_str
+
+            env_params["STRATOS_MEMBER_ACTIVATED_MEMBER_LIST_JSON"] = json.dumps(cluster.member_list_json)
+
+            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
+            if member_ips is not None and len(member_ips) > 1:
+                env_params["STRATOS_MEMBER_ACTIVATED_LB_IP"] = str(member_ips[0])
+                env_params["STRATOS_MEMBER_ACTIVATED_LB_PUBLIC_IP"] = str(member_ips[1])
+
+            env_params["STRATOS_TOPOLOGY_JSON"] = json.dumps(topology.json_str)
+
+            extensionutils.add_properties(service.properties, env_params, "MEMBER_ACTIVATED_SERVICE_PROPERTY")
+            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_ACTIVATED_CLUSTER_PROPERTY")
+            extensionutils.add_properties(member.properties, env_params, "MEMBER_ACTIVATED_MEMBER_PROPERTY")
+
+            clustered = self.cartridge_agent_config.is_clustered
+
+            if member.properties is not None and cartridgeagentconstants.CLUSTERING_PRIMARY_KEY in member.properties \
+                    and member.properties[cartridgeagentconstants.CLUSTERING_PRIMARY_KEY] == "true" \
+                    and clustered is not None and clustered:
+
+                self.log.debug(" If WK member is re-spawned, update axis2.xml ")
+
+                has_wk_ip_changed = True
+                for wk_member in self.wk_members:
+                    if wk_member.member_ip == member_activated_event.member_ip:
+                        has_wk_ip_changed = False
+
+                self.log.debug(" hasWKIpChanged %r" + has_wk_ip_changed)
+
+                min_count = int(self.cartridge_agent_config.min_count)
+                is_wk_member_grp_ready = self.is_wk_member_group_ready(env_params, min_count)
+                self.log.debug("MinCount: %r" % min_count)
+                self.log.debug("is_wk_member_grp_ready : %r" % is_wk_member_grp_ready)
+
+                if has_wk_ip_changed and is_wk_member_grp_ready:
+                    self.log.debug("Setting env var STRATOS_UPDATE_WK_IP to true")
+                    env_params["STRATOS_UPDATE_WK_IP"] = "true"
+
+            self.log.debug("Setting env var STRATOS_CLUSTERING to %r" % clustered)
+            env_params["STRATOS_CLUSTERING"] = str(clustered)
+            env_params["STRATOS_WK_MEMBER_COUNT"] = str(self.cartridge_agent_config.min_count)
+
+            extensionutils.execute_member_activated_extension(env_params)
+        else:
+            self.log.debug("Member activated event is not relevant...skipping agent extension")
+
+    def on_complete_topology_event(self, complete_topology_event):
+        self.log.debug("Complete topology event received")
+
+        service_name_in_payload = self.cartridge_agent_config.service_name
+        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
+        member_id_in_payload = self.cartridge_agent_config.member_id
+
+        consistant = extensionutils.check_topology_consistency(
+            service_name_in_payload,
+            cluster_id_in_payload,
+            member_id_in_payload)
+
+        if not consistant:
+            return
+        else:
+            self.cartridge_agent_config.initialized = True
+
+        topology = complete_topology_event.get_topology()
+        service = topology.get_service(service_name_in_payload)
+        cluster = service.get_cluster(cluster_id_in_payload)
+
+        env_params = {"STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str), "STRATOS_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json)}
+
+        extensionutils.execute_complete_topology_extension(env_params)
+
+    def on_instance_spawned_event(self, instance_spawned_event):
+        self.log.debug("Instance Spawned event received")
+
+        service_name_in_payload = self.cartridge_agent_config.service_name
+        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
+        member_id_in_payload = self.cartridge_agent_config.member_id
+
+        consistant = extensionutils.check_topology_consistency(
+            service_name_in_payload,
+            cluster_id_in_payload,
+            member_id_in_payload)
+
+        if not consistant:
+            return
+        else:
+            self.cartridge_agent_config.initialized = True
+
+    def on_complete_tenant_event(self, complete_tenant_event):
+        self.log.debug("Complete tenant event received")
+
+        tenant_list_json = complete_tenant_event.tenant_list_json
+        self.log.debug("Complete tenants:" + json.dumps(tenant_list_json))
+
+        env_params = {"STRATOS_TENANT_LIST_JSON": json.dumps(tenant_list_json)}
+
+        extensionutils.execute_complete_tenant_extension(env_params)
+
+    def on_member_terminated_event(self, member_terminated_event):
+        self.log.info("Member terminated event received: [service] " + member_terminated_event.service_name +
+                      " [cluster] " + member_terminated_event.cluster_id
+                      + " [member] " + member_terminated_event.member_id)
+
+        topology_consistent = extensionutils.check_topology_consistency(
+            member_terminated_event.service_name,
+            member_terminated_event.cluster_id,
+            member_terminated_event.member_id
+        )
+
+        if not topology_consistent:
+            self.log.error("Topology is inconsistent...failed to execute member terminated event")
+            return
+
+        topology = TopologyContext.get_topology()
+        service = topology.get_service(member_terminated_event.service_name)
+        cluster = service.get_cluster(member_terminated_event.cluster_id)
+        terminated_member = cluster.get_member(member_terminated_event.member_id)
+        lb_cluster_id = cluster.get_member(member_terminated_event.member_id).lb_cluster_id
+
+        #check whether terminated member is within the same cluster, LB cluster or service group
+        if extensionutils.is_relevant_member_event(
+                member_terminated_event.service_name,
+                member_terminated_event.cluster_id,
+                lb_cluster_id):
+
+            env_params = {"STRATOS_MEMBER_TERMINATED_MEMBER_IP": terminated_member.member_ip,
+                          "STRATOS_MEMBER_TERMINATED_MEMBER_ID": member_terminated_event.member_id,
+                          "STRATOS_MEMBER_TERMINATED_CLUSTER_ID": member_terminated_event.cluster_id,
+                          "STRATOS_MEMBER_TERMINATED_LB_CLUSTER_ID": lb_cluster_id,
+                          "STRATOS_MEMBER_TERMINATED_NETWORK_PARTITION_ID": member_terminated_event.network_partition_id,
+                          "STRATOS_MEMBER_TERMINATED_SERVICE_NAME": member_terminated_event.service_name,
+                          "STRATOS_MEMBER_TERMINATED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
+                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
+
+            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
+            if member_ips is not None and len(member_ips) > 1:
+                env_params["STRATOS_MEMBER_TERMINATED_LB_IP"] = member_ips[0]
+                env_params["STRATOS_MEMBER_TERMINATED_LB_PUBLIC_IP"] = member_ips[1]
+
+            extensionutils.add_properties(service.properties, env_params, "MEMBER_TERMINATED_SERVICE_PROPERTY")
+            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_TERMINATED_CLUSTER_PROPERTY")
+            extensionutils.add_properties(terminated_member.properties, env_params, "MEMBER_TERMINATED_MEMBER_PROPERTY")
+
+            extensionutils.execute_member_terminated_extension(env_params)
+
+        else:
+            self.log.debug("Member terminated event is not relevant...skipping agent extension")
+
+    def on_member_suspended_event(self, member_suspended_event):
+        self.log.info("Member suspended event received: [service] " + member_suspended_event.service_name +
+                      " [cluster] " + member_suspended_event.cluster_id + " [member] " + member_suspended_event.member_id)
+
+        topology_consistent = extensionutils.check_topology_consistency(
+            member_suspended_event.service_name,
+            member_suspended_event.cluster_id,
+            member_suspended_event.member_id
+        )
+
+        if not topology_consistent:
+            self.log.error("Topology is inconsistent...failed to execute member suspended event")
+            return
+
+        topology = TopologyContext.get_topology()
+        service = topology.get_service(member_suspended_event.service_name)
+        cluster = service.get_cluster(member_suspended_event.cluster_id)
+        suspended_member = cluster.get_member(member_suspended_event.member_id)
+        lb_cluster_id = cluster.get_member(member_suspended_event.member_id).lb_cluster_id
+
+        #check whether suspended member is within the same cluster, LB cluster or service group
+        if extensionutils.is_relevant_member_event(
+                member_suspended_event.service_name,
+                member_suspended_event.cluster_id,
+                lb_cluster_id):
+
+            env_params = {"STRATOS_MEMBER_SUSPENDED_MEMBER_IP": member_suspended_event.member_ip,
+                          "STRATOS_MEMBER_SUSPENDED_MEMBER_ID": member_suspended_event.member_id,
+                          "STRATOS_MEMBER_SUSPENDED_CLUSTER_ID": member_suspended_event.cluster_id,
+                          "STRATOS_MEMBER_SUSPENDED_LB_CLUSTER_ID": lb_cluster_id,
+                          "STRATOS_MEMBER_SUSPENDED_NETWORK_PARTITION_ID": member_suspended_event.network_partition_id,
+                          "STRATOS_MEMBER_SUSPENDED_SERVICE_NAME": member_suspended_event.service_name,
+                          "STRATOS_MEMBER_SUSPENDED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
+                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
+
+            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
+            if member_ips is not None and len(member_ips) > 1:
+                env_params["STRATOS_MEMBER_SUSPENDED_LB_IP"] = member_ips[0]
+                env_params["STRATOS_MEMBER_SUSPENDED_LB_PUBLIC_IP"] = member_ips[1]
+
+            extensionutils.add_properties(service.properties, env_params, "MEMBER_SUSPENDED_SERVICE_PROPERTY")
+            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_SUSPENDED_CLUSTER_PROPERTY")
+            extensionutils.add_properties(suspended_member.properties, env_params, "MEMBER_SUSPENDED_MEMBER_PROPERTY")
+
+            extensionutils.execute_member_suspended_extension(env_params)
+
+        else:
+            self.log.debug("Member suspended event is not relevant...skipping agent extension")
+
+    def on_member_started_event(self, member_started_event):
+        self.log.info("Member started event received: [service] " + member_started_event.service_name +
+                      " [cluster] " + member_started_event.cluster_id + " [member] " + member_started_event.member_id)
+
+        topology_consistent = extensionutils.check_topology_consistency(
+            member_started_event.service_name,
+            member_started_event.cluster_id,
+            member_started_event.member_id
+        )
+
+        if not topology_consistent:
+            self.log.error("Topology is inconsistent...failed to execute member started event")
+            return
+
+        topology = TopologyContext.get_topology()
+        service = topology.get_service(member_started_event.service_name)
+        cluster = service.get_cluster(member_started_event.cluster_id)
+        started_member = cluster.get_member(member_started_event.member_id)
+        lb_cluster_id = cluster.get_member(member_started_event.member_id).lb_cluster_id
+
+        #check whether started member is within the same cluster, LB cluster or service group
+        if extensionutils.is_relevant_member_event(
+                member_started_event.service_name,
+                member_started_event.cluster_id,
+                lb_cluster_id):
+
+            env_params = {"STRATOS_MEMBER_STARTED_MEMBER_IP": started_member.member_ip,
+                          "STRATOS_MEMBER_STARTED_MEMBER_ID": member_started_event.member_id,
+                          "STRATOS_MEMBER_STARTED_CLUSTER_ID": member_started_event.cluster_id,
+                          "STRATOS_MEMBER_STARTED_LB_CLUSTER_ID": lb_cluster_id,
+                          "STRATOS_MEMBER_STARTED_NETWORK_PARTITION_ID": member_started_event.network_partition_id,
+                          "STRATOS_MEMBER_STARTED_SERVICE_NAME": member_started_event.service_name,
+                          "STRATOS_MEMBER_STARTED_MEMBER_LIST_JSON": json.dumps(cluster.member_list_json),
+                          "STRATOS_TOPOLOGY_JSON": json.dumps(topology.json_str)}
+
+            member_ips = extensionutils.get_lb_member_ip(lb_cluster_id)
+            if member_ips is not None and len(member_ips) > 1:
+                env_params["STRATOS_MEMBER_STARTED_LB_IP"] = member_ips[0]
+                env_params["STRATOS_MEMBER_STARTED_LB_PUBLIC_IP"] = member_ips[1]
+
+            extensionutils.add_properties(service.properties, env_params, "MEMBER_STARTED_SERVICE_PROPERTY")
+            extensionutils.add_properties(cluster.properties, env_params, "MEMBER_STARTED_CLUSTER_PROPERTY")
+            extensionutils.add_properties(started_member.properties, env_params, "MEMBER_STARTED_MEMBER_PROPERTY")
+
+            extensionutils.execute_member_started_extension(env_params)
+
+        else:
+            self.log.debug("Member started event is not relevant...skipping agent extension")
+
+    def start_server_extension(self):
+        #wait until complete topology message is received to get LB IP
+        extensionutils.wait_for_complete_topology()
+        self.log.info("[start server extension] complete topology event received")
+
+        service_name_in_payload = self.cartridge_agent_config.service_name
+        cluster_id_in_payload = self.cartridge_agent_config.cluster_id
+        member_id_in_payload = self.cartridge_agent_config.member_id
+
+        topology_consistant = extensionutils.check_topology_consistency(service_name_in_payload, cluster_id_in_payload, member_id_in_payload)
+
+        try:
+            if not topology_consistant:
+                self.log.error("Topology is inconsistent...failed to execute start server event")
+                return
+
+            topology = TopologyContext.get_topology()
+            service = topology.get_service(service_name_in_payload)
+            cluster = service.get_cluster(cluster_id_in_payload)
+
+            # store environment variable parameters to be passed to extension shell script
+            env_params = {}
+
+            # if clustering is enabled wait until all well known members have started
+            clustering_enabled = self.cartridge_agent_config.is_clustered
+            if clustering_enabled:
+                env_params["STRATOS_CLUSTERING"] = "true"
+                env_params["STRATOS_WK_MEMBER_COUNT"] = self.cartridge_agent_config.min_count
+
+                env_params["STRATOS_PRIMARY"] = "true" if self.cartridge_agent_config.is_primary else "false"
+
+                self.wait_for_wk_members(env_params)
+                self.log.info("All well known members have started! Resuming start server extension...")
+
+            env_params["STRATOS_TOPOLOGY_JSON"] = json.dumps(topology.json_str)
+            env_params["STRATOS_MEMBER_LIST_JSON"] = json.dumps(cluster.member_list_json)
+
+            extensionutils.execute_start_servers_extension(env_params)
+
+        except:
+            self.log.exception("Error processing start servers event")
+
+    def volume_mount_extension(self, persistence_mappings_payload):
+        extensionutils.execute_volume_mount_extension(persistence_mappings_payload)
+
+    def on_subscription_domain_added_event(self, subscription_domain_added_event):
+        tenant_domain = self.find_tenant_domain(subscription_domain_added_event.tenant_id)
+        self.log.info(
+            "Subscription domain added event received: [tenant-id] " + subscription_domain_added_event.tenant_id +
+            " [tenant-domain] " + tenant_domain + " [domain-name] " + subscription_domain_added_event.domain_name +
+            " [application-context] " + subscription_domain_added_event.application_context
+        )
+
+        env_params = {"STRATOS_SUBSCRIPTION_SERVICE_NAME": subscription_domain_added_event.service_name,
+                      "STRATOS_SUBSCRIPTION_DOMAIN_NAME": subscription_domain_added_event.domain_name,
+                      "STRATOS_SUBSCRIPTION_TENANT_ID": int(subscription_domain_added_event.tenant_id),
+                      "STRATOS_SUBSCRIPTION_TENANT_DOMAIN": tenant_domain,
+                      "STRATOS_SUBSCRIPTION_APPLICATION_CONTEXT": subscription_domain_added_event.application_context}
+
+        extensionutils.execute_subscription_domain_added_extension(env_params)
+
+    def on_subscription_domain_removed_event(self, subscription_domain_removed_event):
+        tenant_domain = self.find_tenant_domain(subscription_domain_removed_event.tenant_id)
+        self.log.info(
+            "Subscription domain removed event received: [tenant-id] " + subscription_domain_removed_event.tenant_id +
+            " [tenant-domain] " + tenant_domain + " [domain-name] " + subscription_domain_removed_event.domain_name
+        )
+
+        env_params = {"STRATOS_SUBSCRIPTION_SERVICE_NAME": subscription_domain_removed_event.service_name,
+                      "STRATOS_SUBSCRIPTION_DOMAIN_NAME": subscription_domain_removed_event.domain_name,
+                      "STRATOS_SUBSCRIPTION_TENANT_ID": int(subscription_domain_removed_event.tenant_id),
+                      "STRATOS_SUBSCRIPTION_TENANT_DOMAIN": tenant_domain}
+
+        extensionutils.execute_subscription_domain_removed_extension(env_params)
+
+    def on_copy_artifacts_extension(self, src, des):
+        extensionutils.execute_copy_artifact_extension(src, des)
+
+    def on_tenant_subscribed_event(self, tenant_subscribed_event):
+        self.log.info(
+            "Tenant subscribed event received: [tenant] " + tenant_subscribed_event.tenant_id +
+            " [service] " + tenant_subscribed_event.service_name + " [cluster] " + tenant_subscribed_event.cluster_ids
+        )
+
+        extensionutils.execute_tenant_subscribed_extension({})
+
+    def on_tenant_unsubscribed_event(self, tenant_unsubscribed_event):
+        self.log.info(
+            "Tenant unsubscribed event received: [tenant] " + tenant_unsubscribed_event.tenant_id +
+            " [service] " + tenant_unsubscribed_event.service_name +
+            " [cluster] " + tenant_unsubscribed_event.cluster_ids
+        )
+
+        try:
+            if self.cartridge_agent_config.service_name == tenant_unsubscribed_event.service_name:
+                agentgithandler.AgentGitHandler.remove_repo(tenant_unsubscribed_event.tenant_id)
+        except:
+            self.log.exception("Removing git repository failed: ")
+        extensionutils.execute_tenant_unsubscribed_extension({})
+
+    def cleanup(self):
+        self.log.info("Executing cleaning up the data in the cartridge instance...")
+
+        cartridgeagentpublisher.publish_maintenance_mode_event()
+
+        extensionutils.execute_cleanup_extension()
+        self.log.info("cleaning up finished in the cartridge instance...")
+
+        self.log.info("publishing ready to shutdown event...")
+        cartridgeagentpublisher.publish_instance_ready_to_shutdown_event()
+
+    def is_wk_member_group_ready(self, env_params, min_count):
+        topology = TopologyContext.get_topology()
+        if topology is None or not topology.initialized:
+            return False
+
+        service_group_in_payload = self.cartridge_agent_config.service_group
+        if service_group_in_payload is not None:
+            env_params["STRATOS_SERVICE_GROUP"] = service_group_in_payload
+
+        # clustering logic for apimanager
+        if service_group_in_payload is not None and service_group_in_payload == "apim":
+            # handle apistore and publisher case
+            if self.cartridge_agent_config.service_name == cartridgeagentconstants.APIMANAGER_SERVICE_NAME or \
+                    self.cartridge_agent_config.service_name == cartridgeagentconstants.PUBLISHER_SERVICE_NAME:
+
+                apistore_cluster_collection = topology.get_service(cartridgeagentconstants.APIMANAGER_SERVICE_NAME)\
+                    .get_clusters()
+                publisher_cluster_collection = topology.get_service(cartridgeagentconstants.PUBLISHER_SERVICE_NAME)\
+                    .get_clusters()
+
+                apistore_member_list = []
+                for member in apistore_cluster_collection[0].get_members():
+                    if member.status == MemberStatus.Starting or member.status == MemberStatus.Activated:
+                        apistore_member_list.append(member)
+                        self.wk_members.append(member)
+
+                if len(apistore_member_list) == 0:
+                    self.log.debug("API Store members not yet created")
+                    return False
+
+                apistore_member = apistore_member_list[0]
+                env_params["STRATOS_WK_APISTORE_MEMBER_IP"] = apistore_member.member_ip
+                self.log.debug("STRATOS_WK_APISTORE_MEMBER_IP: %r" % apistore_member.member_ip)
+
+                publisher_member_list = []
+                for member in publisher_cluster_collection[0].get_members():
+                    if member.status == MemberStatus.Starting or member.status == MemberStatus.Activated:
+                        publisher_member_list.append(member)
+                        self.wk_members.append(member)
+
+                if len(publisher_member_list) == 0:
+                    self.log.debug("API Publisher members not yet created")
+
+                publisher_member = publisher_member_list[0]
+                env_params["STRATOS_WK_PUBLISHER_MEMBER_IP"] = publisher_member.member_ip
+                self.log.debug("STRATOS_WK_PUBLISHER_MEMBER_IP: %r" % publisher_member.member_ip)
+
+                return True
+
+            elif self.cartridge_agent_config.service_name == cartridgeagentconstants.GATEWAY_MGT_SERVICE_NAME or \
+                    self.cartridge_agent_config.service_name == cartridgeagentconstants.GATEWAY_SERVICE_NAME:
+
+                if self.cartridge_agent_config.deployment is not None:
+                    # check if deployment is Manager Worker separated
+                    if self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower() or \
+                            self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
+
+                        self.log.info("Deployment pattern for the node: %r" % self.cartridge_agent_config.deployment)
+                        env_params["DEPLOYMENT"] = self.cartridge_agent_config.deployment
+                        # check if WKA members of Manager Worker separated deployment is ready
+                        return self.is_manager_worker_WKA_group_ready(env_params)
+
+            elif self.cartridge_agent_config.service_name == cartridgeagentconstants.KEY_MANAGER_SERVICE_NAME:
+                return True
+
+        else:
+            if self.cartridge_agent_config.deployment is not None:
+                # check if deployment is Manager Worker separated
+                if self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower() or \
+                        self.cartridge_agent_config.deployment.lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
+
+                    self.log.info("Deployment pattern for the node: %r" % self.cartridge_agent_config.deployment)
+                    env_params["DEPLOYMENT"] = self.cartridge_agent_config.deployment
+                    # check if WKA members of Manager Worker separated deployment is ready
+                    return self.is_manager_worker_WKA_group_ready(env_params)
+
+            service_name_in_payload = self.cartridge_agent_config.service_name
+            cluster_id_in_payload = self.cartridge_agent_config.cluster_id
+            service = topology.get_service(service_name_in_payload)
+            cluster = service.get_cluster(cluster_id_in_payload)
+
+            wk_members = []
+            for member in cluster.get_members():
+                if member.properties is not None and \
+                        cartridgeagentconstants.PRIMARY in member.properties \
+                        and member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
+                        (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
+
+                    wk_members.append(member)
+                    self.wk_members.append(member)
+                    self.log.debug("Found WKA: STRATOS_WK_MEMBER_IP: " + member.member_ip)
+
+            if len(wk_members) >= min_count:
+                idx = 0
+                for member in wk_members:
+                    env_params["STRATOS_WK_MEMBER_" + idx + "_IP"] = member.member_ip
+                    self.log.debug("STRATOS_WK_MEMBER_" + idx + "_IP:" + member.member_ip)
+
+                    idx += 1
+
+                return True
+
+        return False
+
+    # generic worker manager separated clustering logic
+    def is_manager_worker_WKA_group_ready(self, env_params):
+
+        # for this, we need both manager cluster service name and worker cluster service name
+        manager_service_name = self.cartridge_agent_config.manager_service_name
+        worker_service_name = self.cartridge_agent_config.worker_service_name
+
+        # managerServiceName and workerServiceName both should not be null /empty
+        if manager_service_name is None or manager_service_name.strip() == "":
+            self.log.error("Manager service name [ " + manager_service_name + " ] is invalid")
+            return False
+
+        if worker_service_name is None or worker_service_name.strip() == "":
+            self.log.error("Worker service name [ " + worker_service_name + " ] is invalid")
+            return False
+
+        min_manager_instances_available = False
+        min_worker_instances_available = False
+
+        topology = TopologyContext.get_topology()
+        manager_service = topology.get_service(manager_service_name)
+        worker_service = topology.get_service(worker_service_name)
+
+        if manager_service is None:
+            self.log.warn("Service [ " + manager_service_name + " ] is not found")
+            return False
+
+        if worker_service is None:
+            self.log.warn("Service [ " + worker_service_name + " ] is not found")
+            return False
+
+        # manager clusters
+        manager_clusters = manager_service.get_clusters()
+        if manager_clusters is None or len(manager_clusters) == 0:
+            self.log.warn("No clusters found for service [ " + manager_service_name + " ]")
+            return False
+
+        manager_min_instance_count = 1
+        manager_min_instance_count_found = False
+
+        manager_wka_members = []
+        for member in manager_clusters[0].get_members():
+            if member.properties is not None and \
+                    cartridgeagentconstants.PRIMARY in member.properties \
+                    and member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
+                    (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
+
+                manager_wka_members.append(member)
+                self.wk_members.append(member)
+
+                # get the min instance count
+                if not manager_min_instance_count_found:
+                    manager_min_instance_count = self.get_min_instance_count_from_member(member)
+                    manager_min_instance_count_found = True
+                    self.log.info("Manager min instance count: " + manager_min_instance_count)
+
+        if len(manager_wka_members) >= manager_min_instance_count:
+            min_manager_instances_available = True
+            idx = 0
+            for member in manager_wka_members:
+                env_params["STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP"] = member.member_ip
+                self.log.debug("STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP: " + member.member_ip)
+                idx += 1
+
+            env_params["STRATOS_WK_MANAGER_MEMBER_COUNT"] = int(manager_min_instance_count)
+
+        # If all the manager members are non primary and is greate than or equal to mincount,
+        # minManagerInstancesAvailable should be true
+        all_managers_non_primary = True
+        for member in manager_clusters[0].get_members():
+            # get the min instance count
+            if not manager_min_instance_count_found:
+                manager_min_instance_count = self.get_min_instance_count_from_member(member)
+                manager_min_instance_count_found = True
+                self.log.info(
+                    "Manager min instance count when allManagersNonPrimary true : " + manager_min_instance_count)
+
+            if member.properties is not None and cartridgeagentconstants.PRIMARY in member.properties and \
+                    member.properties[cartridgeagentconstants.PRIMARY].lower() == "true":
+                all_managers_non_primary = False
+                break
+
+        self.log.debug(
+            " allManagerNonPrimary & managerMinInstanceCount [" + all_managers_non_primary +
+            "], [" + manager_min_instance_count + "] ")
+
+        if all_managers_non_primary and len(manager_clusters) >= manager_min_instance_count:
+            min_manager_instances_available = True
+
+        # worker cluster
+        worker_clusters = worker_service.get_clusters()
+        if worker_clusters is None or len(worker_clusters) == 0:
+            self.log.warn("No clusters found for service [ " + worker_service_name + " ]")
+            return False
+
+        worker_min_instance_count = 1
+        worker_min_instance_count_found = False
+
+        worker_wka_members = []
+        for member in worker_clusters[0].get_members():
+            self.log.debug("Checking member : " + member.member_id)
+
+            if member.properties is not None and cartridgeagentconstants.PRIMARY in member.properties and \
+                    member.properties[cartridgeagentconstants.PRIMARY].lower() == "true" and \
+                    (member.status == MemberStatus.Starting or member.status == MemberStatus.Activated):
+
+                self.log.debug("Added worker member " + member.member_id)
+
+                worker_wka_members.append(member)
+                self.wk_members.append(member)
+
+                # get the min instance count
+                if not worker_min_instance_count_found:
+                    worker_min_instance_count = self.get_min_instance_count_from_member(member)
+                    worker_min_instance_count_found = True
+                    self.log.debug("Worker min instance count: " + worker_min_instance_count)
+
+        if len(worker_wka_members) >= worker_min_instance_count:
+            min_worker_instances_available = True
+            idx = 0
+            for member in worker_wka_members:
+                env_params["STRATOS_WK_WORKER_MEMBER_" + idx + "_IP"] = member.member_ip
+                self.log.debug("STRATOS_WK_WORKER_MEMBER_" + idx + "_IP: " + member.member_ip)
+                idx += 1
+
+            env_params["STRATOS_WK_WORKER_MEMBER_COUNT"] = int(worker_min_instance_count)
+
+        self.log.debug(
+            " Returnning values minManagerInstancesAvailable && minWorkerInstancesAvailable [" +
+            min_manager_instances_available + "],  [" + min_worker_instances_available + "] ")
+
+        return min_manager_instances_available and min_worker_instances_available
+
+    def get_min_instance_count_from_member(self, member):
+        if cartridgeagentconstants.MIN_COUNT in member.properties:
+            return int(member.properties[cartridgeagentconstants.MIN_COUNT])
+
+        return 1
+
+    def find_tenant_domain(self, tenant_id):
+        tenant = TenantContext.get_tenant(tenant_id)
+        if tenant is None:
+            raise RuntimeError("Tenant could not be found: [tenant-id] %r" % tenant_id)
+
+        return tenant.tenant_domain
+
+    def wait_for_wk_members(self, env_params):
+        min_count = int(self.cartridge_agent_config.min_count)
+        is_wk_member_group_ready = False
+        while not is_wk_member_group_ready:
+            self.log.info("Waiting for %r well known members..." % min_count)
+
+            time.sleep(5)
+
+            is_wk_member_group_ready = self.is_wk_member_group_ready(env_params, min_count)
+
+from ..artifactmgt.git import agentgithandler
+from ..artifactmgt.repositoryinformation import RepositoryInformation
+from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
+from ..publisher import cartridgeagentpublisher
+from ..exception.parameternotfoundexception import ParameterNotFoundException
+from ..topology.topologycontext import *
+from ..tenant.tenantcontext import *
+from ..util.log import LogFactory
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py b/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
new file mode 100644
index 0000000..685344d
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/abstracthealthstatisticspublisher.py
@@ -0,0 +1,62 @@
+# 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.
+
+class AbstractHealthStatisticsReader:
+    """
+    Abstract class to implement to create a custom health stat reader
+    """
+
+    def stat_cartridge_health(self):
+        """
+        Abstract method that when implemented reads the memory usage and the load average
+        of the instance running the agent and returns a CartridgeHealthStatistics object
+        with the information
+
+        :return: CartridgeHealthStatistics object with memory usage and load average values
+        :rtype : CartridgeHealthStatistics
+        """
+        raise NotImplementedError
+
+
+class CartridgeHealthStatistics:
+    """
+    Holds the memory usage and load average reading
+    """
+
+    def __init__(self):
+        self.memory_usage = None
+        """:type : float"""
+        self.load_avg = None
+        """:type : float"""
+
+
+class CEPPublisherException(Exception):
+    """
+    Exception to be used during CEP publishing operations
+    """
+
+    def __init__(self, msg):
+        super(self,  msg)
+        self.message = msg
+
+    def get_message(self):
+        """
+        The message provided when the exception is raised
+        :return: message
+        :rtype: str
+        """
+        return self.message


[21/50] [abbrv] git commit: Merge remote-tracking branch 'upstream/master'

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


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

Branch: refs/heads/master
Commit: 9982ae92ed482ad4125a7af90afef0f2f9494242
Parents: bcddfba b23a9c7
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Mon Oct 20 13:21:56 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Mon Oct 20 13:21:56 2014 +0530

----------------------------------------------------------------------
 .../org.apache.stratos.cloud.controller/pom.xml |    5 +
 .../cloud/controller/iaases/GCEIaas.java        |  455 +++++++
 .../validate/GCEPartitionValidator.java         |   54 +
 .../jclouds/apis/gce/1.8.0-stratos/README.txt   |   77 ++
 .../jclouds/apis/gce/1.8.0-stratos/pom.xml      |  135 ++
 .../GoogleComputeEngineApi.java                 |  185 +++
 .../GoogleComputeEngineApiMetadata.java         |  104 ++
 .../GoogleComputeEngineConstants.java           |   81 ++
 .../compute/GoogleComputeEngineService.java     |  200 +++
 .../GoogleComputeEngineServiceAdapter.java      |  439 +++++++
 ...GoogleComputeEngineServiceContextModule.java |  283 +++++
 ...ogleComputeEngineSecurityGroupExtension.java |  338 +++++
 .../functions/BuildInstanceMetadata.java        |   46 +
 .../functions/FirewallTagNamingConvention.java  |   62 +
 .../functions/FirewallToIpPermission.java       |   87 ++
 .../GoogleComputeEngineImageToImage.java        |   80 ++
 .../functions/InstanceInZoneToNodeMetadata.java |  150 +++
 .../functions/MachineTypeInZoneToHardware.java  |  100 ++
 .../functions/NetworkToSecurityGroup.java       |   82 ++
 .../functions/OrphanedGroupsFromDeadNodes.java  |   57 +
 .../compute/functions/RegionToLocation.java     |   45 +
 .../compute/functions/ZoneToLocation.java       |   45 +
 .../compute/loaders/FindNetworkOrCreate.java    |   62 +
 .../GoogleComputeEngineTemplateOptions.java     |  382 ++++++
 .../predicates/AllNodesInGroupTerminated.java   |   48 +
 ...desWithGroupEncodedIntoNameThenAddToSet.java |  183 +++
 ...DefaultLoginCredentialsForImageStrategy.java |   69 +
 ...eNodeCredentialsButOverrideFromTemplate.java |   57 +
 .../GoogleComputeEngineHttpApiModule.java       |  177 +++
 .../config/GoogleComputeEngineParserModule.java |  413 ++++++
 .../config/OAuthModuleWithoutTypeAdapters.java  |   51 +
 .../googlecomputeengine/config/UserProject.java |   33 +
 .../domain/AbstractDisk.java                    |  121 ++
 .../googlecomputeengine/domain/Address.java     |  177 +++
 .../googlecomputeengine/domain/Deprecated.java  |  195 +++
 .../googlecomputeengine/domain/Disk.java        |  123 ++
 .../googlecomputeengine/domain/Firewall.java    |  379 ++++++
 .../googlecomputeengine/domain/Image.java       |  286 +++++
 .../googlecomputeengine/domain/Instance.java    | 1187 ++++++++++++++++++
 .../domain/InstanceInZone.java                  |   52 +
 .../domain/InstanceTemplate.java                |  445 +++++++
 .../googlecomputeengine/domain/ListPage.java    |  179 +++
 .../googlecomputeengine/domain/MachineType.java |  360 ++++++
 .../domain/MachineTypeInZone.java               |   52 +
 .../googlecomputeengine/domain/Metadata.java    |  139 ++
 .../googlecomputeengine/domain/Network.java     |  133 ++
 .../googlecomputeengine/domain/Operation.java   |  556 ++++++++
 .../googlecomputeengine/domain/Project.java     |  162 +++
 .../googlecomputeengine/domain/Quota.java       |  152 +++
 .../googlecomputeengine/domain/Region.java      |  175 +++
 .../googlecomputeengine/domain/Resource.java    |  283 +++++
 .../googlecomputeengine/domain/Route.java       |  433 +++++++
 .../domain/SlashEncodedIds.java                 |   83 ++
 .../googlecomputeengine/domain/Snapshot.java    |  135 ++
 .../googlecomputeengine/domain/Zone.java        |  334 +++++
 .../domain/internal/NetworkAndAddressRange.java |   91 ++
 .../features/AddressApi.java                    |  187 +++
 .../googlecomputeengine/features/DiskApi.java   |  255 ++++
 .../features/FirewallApi.java                   |  227 ++++
 .../features/GlobalOperationApi.java            |  158 +++
 .../googlecomputeengine/features/ImageApi.java  |  167 +++
 .../features/InstanceApi.java                   |  381 ++++++
 .../features/MachineTypeApi.java                |  143 +++
 .../features/NetworkApi.java                    |  204 +++
 .../features/ProjectApi.java                    |   96 ++
 .../googlecomputeengine/features/RegionApi.java |  135 ++
 .../features/RegionOperationApi.java            |  163 +++
 .../googlecomputeengine/features/RouteApi.java  |  184 +++
 .../features/SnapshotApi.java                   |  160 +++
 .../googlecomputeengine/features/ZoneApi.java   |  135 ++
 .../features/ZoneOperationApi.java              |  163 +++
 .../functions/CreateNetworkIfNeeded.java        |  100 ++
 .../functions/internal/BaseToPagedIterable.java |   66 +
 .../internal/BaseWithRegionToPagedIterable.java |   72 ++
 .../internal/BaseWithZoneToPagedIterable.java   |   72 ++
 .../functions/internal/PATCH.java               |   35 +
 .../functions/internal/ParseAddresses.java      |   67 +
 .../functions/internal/ParseDisks.java          |   67 +
 .../functions/internal/ParseFirewalls.java      |   63 +
 .../internal/ParseGlobalOperations.java         |   63 +
 .../functions/internal/ParseImages.java         |   63 +
 .../functions/internal/ParseInstances.java      |   65 +
 .../functions/internal/ParseMachineTypes.java   |   64 +
 .../functions/internal/ParseNetworks.java       |   63 +
 .../internal/ParseRegionOperations.java         |   65 +
 .../functions/internal/ParseRegions.java        |   63 +
 .../functions/internal/ParseRoutes.java         |   63 +
 .../functions/internal/ParseSnapshots.java      |   66 +
 .../functions/internal/ParseZoneOperations.java |   65 +
 .../functions/internal/ParseZones.java          |   63 +
 .../handlers/FirewallBinder.java                |   56 +
 .../GoogleComputeEngineErrorHandler.java        |   62 +
 .../handlers/InstanceBinder.java                |   65 +
 .../handlers/MetadataBinder.java                |   60 +
 .../handlers/RouteBinder.java                   |   56 +
 .../options/AttachDiskOptions.java              |  128 ++
 .../options/DeprecateOptions.java               |  126 ++
 .../options/FirewallOptions.java                |  166 +++
 .../options/ListOptions.java                    |   91 ++
 .../options/RouteOptions.java                   |  202 +++
 .../GlobalOperationDonePredicate.java           |   59 +
 .../predicates/InstancePredicates.java          |   33 +
 .../predicates/NetworkFirewallPredicates.java   |  121 ++
 .../RegionOperationDonePredicate.java           |   69 +
 .../predicates/ZoneOperationDonePredicate.java  |   68 +
 .../java/org/jclouds/oauth/v2/OAuthApi.java     |   63 +
 .../org/jclouds/oauth/v2/OAuthApiMetadata.java  |   80 ++
 .../org/jclouds/oauth/v2/OAuthConstants.java    |   78 ++
 .../jclouds/oauth/v2/config/Authentication.java |   35 +
 .../v2/config/OAuthAuthenticationModule.java    |   52 +
 .../oauth/v2/config/OAuthHttpApiModule.java     |   45 +
 .../jclouds/oauth/v2/config/OAuthModule.java    |   86 ++
 .../oauth/v2/config/OAuthProperties.java        |   43 +
 .../jclouds/oauth/v2/config/OAuthScopes.java    |   40 +
 .../org/jclouds/oauth/v2/domain/ClaimSet.java   |  191 +++
 .../org/jclouds/oauth/v2/domain/Header.java     |  128 ++
 .../oauth/v2/domain/OAuthCredentials.java       |  129 ++
 .../java/org/jclouds/oauth/v2/domain/Token.java |  149 +++
 .../jclouds/oauth/v2/domain/TokenRequest.java   |  131 ++
 .../oauth/v2/domain/TokenRequestFormat.java     |   45 +
 .../oauth/v2/filters/OAuthAuthenticator.java    |   63 +
 .../oauth/v2/functions/BuildTokenRequest.java   |  135 ++
 .../jclouds/oauth/v2/functions/FetchToken.java  |   41 +
 .../v2/functions/OAuthCredentialsSupplier.java  |  125 ++
 .../v2/functions/SignOrProduceMacForToken.java  |  119 ++
 .../oauth/v2/handlers/OAuthErrorHandler.java    |   64 +
 .../oauth/v2/handlers/OAuthTokenBinder.java     |   45 +
 .../oauth/v2/json/ClaimSetTypeAdapter.java      |   59 +
 .../oauth/v2/json/HeaderTypeAdapter.java        |   52 +
 .../oauth/v2/json/JWTTokenRequestFormat.java    |   96 ++
 .../services/org.jclouds.apis.ApiMetadata       |   19 +
 .../GoogleComputeEngineApiMetadataTest.java     |   38 +
 ...eEngineAuthenticatedRestContextLiveTest.java |   33 +
 .../PageSystemExpectTest.java                   |  114 ++
 .../GoogleComputeEngineServiceExpectTest.java   |  574 +++++++++
 .../GoogleComputeEngineServiceLiveTest.java     |  128 ++
 ...uteEngineSecurityGroupExtensionLiveTest.java |   28 +
 .../functions/FirewallToIpPermissionTest.java   |   93 ++
 .../GoogleComputeEngineImageToImageTest.java    |   60 +
 .../InstanceInZoneToNodeMetadataTest.java       |  286 +++++
 .../functions/NetworkToSecurityGroupTest.java   |   94 ++
 .../OrphanedGroupsFromDeadNodesTest.java        |  136 ++
 .../loaders/FindNetworkOrCreateTest.java        |  141 +++
 .../features/AddressApiExpectTest.java          |  163 +++
 .../features/AddressApiLiveTest.java            |   71 ++
 .../features/DiskApiExpectTest.java             |  226 ++++
 .../features/DiskApiLiveTest.java               |   85 ++
 .../features/FirewallApiExpectTest.java         |  301 +++++
 .../features/FirewallApiLiveTest.java           |  163 +++
 .../features/GlobalOperationApiExpectTest.java  |  158 +++
 .../features/GlobalOperationApiLiveTest.java    |   91 ++
 .../features/ImageApiExpectTest.java            |  159 +++
 .../features/ImageApiLiveTest.java              |   74 ++
 .../features/InstanceApiExpectTest.java         |  410 ++++++
 .../features/InstanceApiLiveTest.java           |  240 ++++
 .../features/MachineTypeApiExpectTest.java      |  113 ++
 .../features/MachineTypeApiLiveTest.java        |   73 ++
 .../features/NetworkApiExpectTest.java          |  164 +++
 .../features/NetworkApiLiveTest.java            |   83 ++
 .../features/ProjectApiExpectTest.java          |   96 ++
 .../features/ProjectApiLiveTest.java            |  123 ++
 .../features/RegionApiExpectTest.java           |   94 ++
 .../features/RegionApiLiveTest.java             |   74 ++
 .../features/RegionOperationApiExpectTest.java  |  195 +++
 .../features/RegionOperationApiLiveTest.java    |   91 ++
 .../features/RouteApiExpectTest.java            |  175 +++
 .../features/RouteApiLiveTest.java              |   96 ++
 .../features/SnapshotApiExpectTest.java         |   94 ++
 .../features/SnapshotApiLiveTest.java           |   92 ++
 .../features/ZoneApiExpectTest.java             |   97 ++
 .../features/ZoneApiLiveTest.java               |   74 ++
 .../features/ZoneOperationApiExpectTest.java    |  193 +++
 .../features/ZoneOperationApiLiveTest.java      |   90 ++
 .../functions/CreateNetworkIfNeededTest.java    |  132 ++
 .../GoogleComputeEngineErrorHandlerTest.java    |   92 ++
 .../BaseGoogleComputeEngineApiExpectTest.java   |   31 +
 .../BaseGoogleComputeEngineApiLiveTest.java     |  160 +++
 .../BaseGoogleComputeEngineExpectTest.java      |  195 +++
 .../BaseGoogleComputeEngineParseTest.java       |   33 +
 ...leComputeEngineServiceContextExpectTest.java |   49 +
 ...aseGoogleComputeEngineServiceExpectTest.java |   28 +
 .../parse/ParseAddressListTest.java             |   61 +
 .../parse/ParseAddressTest.java                 |   51 +
 .../parse/ParseDiskListTest.java                |   61 +
 .../parse/ParseDiskTest.java                    |   50 +
 .../parse/ParseFirewallListTest.java            |   68 +
 .../parse/ParseFirewallTest.java                |   60 +
 .../parse/ParseImageListTest.java               |   71 ++
 .../parse/ParseImageTest.java                   |   55 +
 .../parse/ParseInstanceListTest.java            |   48 +
 .../parse/ParseInstanceSerialOutputTest.java    |   38 +
 .../parse/ParseInstanceTest.java                |   81 ++
 .../parse/ParseMachineTypeListTest.java         |   94 ++
 .../parse/ParseMachineTypeTest.java             |   57 +
 .../parse/ParseMetadataTest.java                |   45 +
 .../parse/ParseNetworkListTest.java             |   49 +
 .../parse/ParseNetworkTest.java                 |   48 +
 .../parse/ParseOperationListTest.java           |   46 +
 .../parse/ParseOperationTest.java               |   58 +
 .../parse/ParseProjectTest.java                 |   67 +
 .../parse/ParseQuotaTest.java                   |   39 +
 .../parse/ParseRegionListTest.java              |   72 ++
 .../parse/ParseRegionTest.java                  |   62 +
 .../parse/ParseRouteListTest.java               |   62 +
 .../parse/ParseRouteTest.java                   |   56 +
 .../parse/ParseSnapshotListTest.java            |   64 +
 .../parse/ParseSnapshotTest.java                |   52 +
 .../parse/ParseZoneListTest.java                |   70 ++
 .../parse/ParseZoneTest.java                    |   55 +
 .../NetworkFirewallPredicatesTest.java          |  162 +++
 .../jclouds/oauth/v2/OAuthApiMetadataTest.java  |   38 +
 .../org/jclouds/oauth/v2/OAuthTestUtils.java    |   75 ++
 .../oauth/v2/features/OAuthApiExpectTest.java   |   99 ++
 .../oauth/v2/features/OAuthApiLiveTest.java     |   80 ++
 .../functions/OAuthCredentialsFromPKTest.java   |   61 +
 .../functions/OAuthCredentialsSupplierTest.java |   55 +
 .../oauth/v2/functions/SignerFunctionTest.java  |   61 +
 .../v2/handlers/OAuthErrorHandlerTest.java      |   92 ++
 .../oauth/v2/internal/Base64UrlSafeTest.java    |   40 +
 .../v2/internal/BaseOAuthApiExpectTest.java     |   23 +
 .../oauth/v2/internal/BaseOAuthApiLiveTest.java |   56 +
 .../BaseOAuthAuthenticatedApiLiveTest.java      |  110 ++
 .../oauth/v2/internal/BaseOAuthExpectTest.java  |   26 +
 .../v2/json/JWTTokenRequestFormatTest.java      |   69 +
 .../jclouds/oauth/v2/parse/ParseTokenTest.java  |   40 +
 .../firewall_list.json                          |   37 +
 .../network_get.json                            |   10 +
 .../src/test/resources/address_get.json         |   12 +
 .../src/test/resources/address_insert.json      |    1 +
 .../src/test/resources/address_list.json        |   31 +
 .../test/resources/disk_create_snapshot.json    |    1 +
 .../src/test/resources/disk_get.json            |   10 +
 .../src/test/resources/disk_insert.json         |    1 +
 .../src/test/resources/disk_list.json           |   17 +
 .../src/test/resources/firewall_get.json        |   30 +
 .../src/test/resources/firewall_insert.json     |    1 +
 .../src/test/resources/firewall_list.json       |   58 +
 .../src/test/resources/global_operation.json    |   15 +
 .../test/resources/global_operation_list.json   |   22 +
 .../src/test/resources/image_get.json           |   13 +
 .../src/test/resources/image_insert.json        |    4 +
 .../src/test/resources/image_list.json          |   24 +
 .../src/test/resources/image_list_empty.json    |    6 +
 .../resources/image_list_multiple_page_1.json   |   55 +
 .../resources/image_list_multiple_page_2.json   |   47 +
 .../test/resources/image_list_single_page.json  |   50 +
 .../resources/instance_add_access_config.json   |   11 +
 .../test/resources/instance_attach_disk.json    |    6 +
 .../src/test/resources/instance_get.json        |   62 +
 .../src/test/resources/instance_insert.json     |    1 +
 .../test/resources/instance_insert_simple.json  |    1 +
 .../src/test/resources/instance_list.json       |   69 +
 .../instance_list_central1b_empty.json          |    6 +
 .../test/resources/instance_serial_port.json    |    4 +
 .../test/resources/instance_set_metadata.json   |   10 +
 .../src/test/resources/logback.xml              |   83 ++
 .../src/test/resources/machinetype.json         |   22 +
 .../src/test/resources/machinetype_list.json    |   57 +
 .../resources/machinetype_list_central1b.json   |   43 +
 .../machinetype_list_central1b_empty.json       |    6 +
 .../src/test/resources/metadata.json            |    1 +
 .../src/test/resources/network_get.json         |   10 +
 .../src/test/resources/network_insert.json      |    1 +
 .../src/test/resources/network_list.json        |   18 +
 .../src/test/resources/operation.json           |   17 +
 .../src/test/resources/operation_error.json     |   26 +
 .../src/test/resources/operation_list.json      |   24 +
 .../src/test/resources/project.json             |   69 +
 .../1.8.0-stratos/src/test/resources/quota.json |    5 +
 .../src/test/resources/region_get.json          |   60 +
 .../src/test/resources/region_list.json         |  126 ++
 .../src/test/resources/region_operation.json    |   16 +
 .../test/resources/region_operation_list.json   |   23 +
 .../src/test/resources/route_get.json           |   14 +
 .../src/test/resources/route_insert.json        |    1 +
 .../src/test/resources/route_list.json          |   34 +
 .../src/test/resources/snapshot_get.json        |   13 +
 .../src/test/resources/snapshot_list.json       |   33 +
 .../src/test/resources/tag_insert.json          |    1 +
 .../1.8.0-stratos/src/test/resources/testpk.pem |   15 +
 .../src/test/resources/tokenResponse.json       |    5 +
 .../src/test/resources/zone_get.json            |   17 +
 .../src/test/resources/zone_list.json           |   41 +
 .../src/test/resources/zone_list_short.json     |   24 +
 .../src/test/resources/zone_operation.json      |   16 +
 .../test/resources/zone_operation_error.json    |   25 +
 .../src/test/resources/zone_operation_list.json |   23 +
 dependencies/pom.xml                            |    1 +
 .../pom.xml                                     |    6 +
 tools/puppet3-agent/config-gce.sh               |  101 ++
 tools/puppet3-agent/init-gce.sh                 |  146 +++
 tools/stratos-installer/clean.sh                |    2 -
 tools/stratos-installer/conf/setup.conf         |    4 +
 .../all/repository/conf/cloud-controller.xml    |    8 +
 tools/stratos-installer/ec2.sh                  |    2 +
 tools/stratos-installer/gce.sh                  |   67 +
 tools/stratos-installer/openstack.sh            |    2 +
 tools/stratos-installer/setup.sh                |   12 +-
 tools/stratos-installer/vcloud.sh               |    2 +
 299 files changed, 29459 insertions(+), 3 deletions(-)
----------------------------------------------------------------------



[30/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
new file mode 100644
index 0000000..b8c13c1
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
@@ -0,0 +1,1495 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ttypes import *
+from ...thrift.Thrift import TProcessor
+from ...thrift.transport import TTransport
+from ..Exception import ttypes
+from .. import Data
+
+try:
+  from ...thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+
+class Iface:
+  def connect(self, userName, password):
+    """
+    Parameters:
+     - userName
+     - password
+    """
+    pass
+
+  def disconnect(self, sessionId):
+    """
+    Parameters:
+     - sessionId
+    """
+    pass
+
+  def defineStream(self, sessionId, streamDefinition):
+    """
+    Parameters:
+     - sessionId
+     - streamDefinition
+    """
+    pass
+
+  def findStreamId(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    pass
+
+  def publish(self, eventBundle):
+    """
+    Parameters:
+     - eventBundle
+    """
+    pass
+
+  def deleteStreamById(self, sessionId, streamId):
+    """
+    Parameters:
+     - sessionId
+     - streamId
+    """
+    pass
+
+  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    pass
+
+
+class Client(Iface):
+  def __init__(self, iprot, oprot=None):
+    self._iprot = self._oprot = iprot
+    if oprot is not None:
+      self._oprot = oprot
+    self._seqid = 0
+
+  def connect(self, userName, password):
+    """
+    Parameters:
+     - userName
+     - password
+    """
+    self.send_connect(userName, password)
+    return self.recv_connect()
+
+  def send_connect(self, userName, password):
+    self._oprot.writeMessageBegin('connect', TMessageType.CALL, self._seqid)
+    args = connect_args()
+    args.userName = userName
+    args.password = password
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_connect(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = connect_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.ae is not None:
+      raise result.ae
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "connect failed: unknown result");
+
+  def disconnect(self, sessionId):
+    """
+    Parameters:
+     - sessionId
+    """
+    self.send_disconnect(sessionId)
+    self.recv_disconnect()
+
+  def send_disconnect(self, sessionId):
+    self._oprot.writeMessageBegin('disconnect', TMessageType.CALL, self._seqid)
+    args = disconnect_args()
+    args.sessionId = sessionId
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_disconnect(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = disconnect_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    return
+
+  def defineStream(self, sessionId, streamDefinition):
+    """
+    Parameters:
+     - sessionId
+     - streamDefinition
+    """
+    self.send_defineStream(sessionId, streamDefinition)
+    return self.recv_defineStream()
+
+  def send_defineStream(self, sessionId, streamDefinition):
+    self._oprot.writeMessageBegin('defineStream', TMessageType.CALL, self._seqid)
+    args = defineStream_args()
+    args.sessionId = sessionId
+    args.streamDefinition = streamDefinition
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_defineStream(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = defineStream_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.ade is not None:
+      raise result.ade
+    if result.mtd is not None:
+      raise result.mtd
+    if result.tde is not None:
+      raise result.tde
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "defineStream failed: unknown result");
+
+  def findStreamId(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    self.send_findStreamId(sessionId, streamName, streamVersion)
+    return self.recv_findStreamId()
+
+  def send_findStreamId(self, sessionId, streamName, streamVersion):
+    self._oprot.writeMessageBegin('findStreamId', TMessageType.CALL, self._seqid)
+    args = findStreamId_args()
+    args.sessionId = sessionId
+    args.streamName = streamName
+    args.streamVersion = streamVersion
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_findStreamId(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = findStreamId_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.tnde is not None:
+      raise result.tnde
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "findStreamId failed: unknown result");
+
+  def publish(self, eventBundle):
+    """
+    Parameters:
+     - eventBundle
+    """
+    self.send_publish(eventBundle)
+    self.recv_publish()
+
+  def send_publish(self, eventBundle):
+    self._oprot.writeMessageBegin('publish', TMessageType.CALL, self._seqid)
+    args = publish_args()
+    args.eventBundle = eventBundle
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_publish(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = publish_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.ue is not None:
+      raise result.ue
+    if result.se is not None:
+      raise result.se
+    return
+
+  def deleteStreamById(self, sessionId, streamId):
+    """
+    Parameters:
+     - sessionId
+     - streamId
+    """
+    self.send_deleteStreamById(sessionId, streamId)
+    return self.recv_deleteStreamById()
+
+  def send_deleteStreamById(self, sessionId, streamId):
+    self._oprot.writeMessageBegin('deleteStreamById', TMessageType.CALL, self._seqid)
+    args = deleteStreamById_args()
+    args.sessionId = sessionId
+    args.streamId = streamId
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_deleteStreamById(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = deleteStreamById_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamById failed: unknown result");
+
+  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    self.send_deleteStreamByNameVersion(sessionId, streamName, streamVersion)
+    return self.recv_deleteStreamByNameVersion()
+
+  def send_deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    self._oprot.writeMessageBegin('deleteStreamByNameVersion', TMessageType.CALL, self._seqid)
+    args = deleteStreamByNameVersion_args()
+    args.sessionId = sessionId
+    args.streamName = streamName
+    args.streamVersion = streamVersion
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_deleteStreamByNameVersion(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = deleteStreamByNameVersion_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamByNameVersion failed: unknown result");
+
+
+class Processor(Iface, TProcessor):
+  def __init__(self, handler):
+    self._handler = handler
+    self._processMap = {}
+    self._processMap["connect"] = Processor.process_connect
+    self._processMap["disconnect"] = Processor.process_disconnect
+    self._processMap["defineStream"] = Processor.process_defineStream
+    self._processMap["findStreamId"] = Processor.process_findStreamId
+    self._processMap["publish"] = Processor.process_publish
+    self._processMap["deleteStreamById"] = Processor.process_deleteStreamById
+    self._processMap["deleteStreamByNameVersion"] = Processor.process_deleteStreamByNameVersion
+
+  def process(self, iprot, oprot):
+    (name, type, seqid) = iprot.readMessageBegin()
+    if name not in self._processMap:
+      iprot.skip(TType.STRUCT)
+      iprot.readMessageEnd()
+      x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
+      oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
+      x.write(oprot)
+      oprot.writeMessageEnd()
+      oprot.trans.flush()
+      return
+    else:
+      self._processMap[name](self, seqid, iprot, oprot)
+    return True
+
+  def process_connect(self, seqid, iprot, oprot):
+    args = connect_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = connect_result()
+    try:
+      result.success = self._handler.connect(args.userName, args.password)
+    except ttypes.ThriftAuthenticationException, ae:
+      result.ae = ae
+    oprot.writeMessageBegin("connect", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_disconnect(self, seqid, iprot, oprot):
+    args = disconnect_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = disconnect_result()
+    self._handler.disconnect(args.sessionId)
+    oprot.writeMessageBegin("disconnect", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_defineStream(self, seqid, iprot, oprot):
+    args = defineStream_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = defineStream_result()
+    try:
+      result.success = self._handler.defineStream(args.sessionId, args.streamDefinition)
+    except ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ade:
+      result.ade = ade
+    except ttypes.ThriftMalformedStreamDefinitionException, mtd:
+      result.mtd = mtd
+    except ttypes.ThriftStreamDefinitionException, tde:
+      result.tde = tde
+    except ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("defineStream", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_findStreamId(self, seqid, iprot, oprot):
+    args = findStreamId_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = findStreamId_result()
+    try:
+      result.success = self._handler.findStreamId(args.sessionId, args.streamName, args.streamVersion)
+    except ttypes.ThriftNoStreamDefinitionExistException, tnde:
+      result.tnde = tnde
+    except ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("findStreamId", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_publish(self, seqid, iprot, oprot):
+    args = publish_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = publish_result()
+    try:
+      self._handler.publish(args.eventBundle)
+    except ttypes.ThriftUndefinedEventTypeException, ue:
+      result.ue = ue
+    except ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("publish", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_deleteStreamById(self, seqid, iprot, oprot):
+    args = deleteStreamById_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = deleteStreamById_result()
+    try:
+      result.success = self._handler.deleteStreamById(args.sessionId, args.streamId)
+    except ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("deleteStreamById", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_deleteStreamByNameVersion(self, seqid, iprot, oprot):
+    args = deleteStreamByNameVersion_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = deleteStreamByNameVersion_result()
+    try:
+      result.success = self._handler.deleteStreamByNameVersion(args.sessionId, args.streamName, args.streamVersion)
+    except ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("deleteStreamByNameVersion", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+
+# HELPER FUNCTIONS AND STRUCTURES
+
+class connect_args:
+  """
+  Attributes:
+   - userName
+   - password
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'userName', None, None, ), # 1
+    (2, TType.STRING, 'password', None, None, ), # 2
+  )
+
+  def __init__(self, userName=None, password=None,):
+    self.userName = userName
+    self.password = password
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.userName = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.password = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('connect_args')
+    if self.userName is not None:
+      oprot.writeFieldBegin('userName', TType.STRING, 1)
+      oprot.writeString(self.userName)
+      oprot.writeFieldEnd()
+    if self.password is not None:
+      oprot.writeFieldBegin('password', TType.STRING, 2)
+      oprot.writeString(self.password)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class connect_result:
+  """
+  Attributes:
+   - success
+   - ae
+  """
+
+  thrift_spec = (
+    (0, TType.STRING, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'ae', (ttypes.ThriftAuthenticationException, ttypes.ThriftAuthenticationException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, ae=None,):
+    self.success = success
+    self.ae = ae
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRING:
+          self.success = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.ae = ttypes.ThriftAuthenticationException()
+          self.ae.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('connect_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.STRING, 0)
+      oprot.writeString(self.success)
+      oprot.writeFieldEnd()
+    if self.ae is not None:
+      oprot.writeFieldBegin('ae', TType.STRUCT, 1)
+      self.ae.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class disconnect_args:
+  """
+  Attributes:
+   - sessionId
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+  )
+
+  def __init__(self, sessionId=None,):
+    self.sessionId = sessionId
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('disconnect_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class disconnect_result:
+
+  thrift_spec = (
+  )
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('disconnect_result')
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class defineStream_args:
+  """
+  Attributes:
+   - sessionId
+   - streamDefinition
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamDefinition', None, None, ), # 2
+  )
+
+  def __init__(self, sessionId=None, streamDefinition=None,):
+    self.sessionId = sessionId
+    self.streamDefinition = streamDefinition
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamDefinition = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('defineStream_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamDefinition is not None:
+      oprot.writeFieldBegin('streamDefinition', TType.STRING, 2)
+      oprot.writeString(self.streamDefinition)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class defineStream_result:
+  """
+  Attributes:
+   - success
+   - ade
+   - mtd
+   - tde
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.STRING, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'ade', (ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'mtd', (ttypes.ThriftMalformedStreamDefinitionException, ttypes.ThriftMalformedStreamDefinitionException.thrift_spec), None, ), # 2
+    (3, TType.STRUCT, 'tde', (ttypes.ThriftStreamDefinitionException, ttypes.ThriftStreamDefinitionException.thrift_spec), None, ), # 3
+    (4, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 4
+  )
+
+  def __init__(self, success=None, ade=None, mtd=None, tde=None, se=None,):
+    self.success = success
+    self.ade = ade
+    self.mtd = mtd
+    self.tde = tde
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRING:
+          self.success = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.ade = ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException()
+          self.ade.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.mtd = ttypes.ThriftMalformedStreamDefinitionException()
+          self.mtd.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRUCT:
+          self.tde = ttypes.ThriftStreamDefinitionException()
+          self.tde.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 4:
+        if ftype == TType.STRUCT:
+          self.se = ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('defineStream_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.STRING, 0)
+      oprot.writeString(self.success)
+      oprot.writeFieldEnd()
+    if self.ade is not None:
+      oprot.writeFieldBegin('ade', TType.STRUCT, 1)
+      self.ade.write(oprot)
+      oprot.writeFieldEnd()
+    if self.mtd is not None:
+      oprot.writeFieldBegin('mtd', TType.STRUCT, 2)
+      self.mtd.write(oprot)
+      oprot.writeFieldEnd()
+    if self.tde is not None:
+      oprot.writeFieldBegin('tde', TType.STRUCT, 3)
+      self.tde.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 4)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class findStreamId_args:
+  """
+  Attributes:
+   - sessionId
+   - streamName
+   - streamVersion
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamName', None, None, ), # 2
+    (3, TType.STRING, 'streamVersion', None, None, ), # 3
+  )
+
+  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
+    self.sessionId = sessionId
+    self.streamName = streamName
+    self.streamVersion = streamVersion
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamName = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRING:
+          self.streamVersion = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('findStreamId_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamName is not None:
+      oprot.writeFieldBegin('streamName', TType.STRING, 2)
+      oprot.writeString(self.streamName)
+      oprot.writeFieldEnd()
+    if self.streamVersion is not None:
+      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
+      oprot.writeString(self.streamVersion)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class findStreamId_result:
+  """
+  Attributes:
+   - success
+   - tnde
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.STRING, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'tnde', (ttypes.ThriftNoStreamDefinitionExistException, ttypes.ThriftNoStreamDefinitionExistException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
+  )
+
+  def __init__(self, success=None, tnde=None, se=None,):
+    self.success = success
+    self.tnde = tnde
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRING:
+          self.success = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.tnde = ttypes.ThriftNoStreamDefinitionExistException()
+          self.tnde.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.se = ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('findStreamId_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.STRING, 0)
+      oprot.writeString(self.success)
+      oprot.writeFieldEnd()
+    if self.tnde is not None:
+      oprot.writeFieldBegin('tnde', TType.STRUCT, 1)
+      self.tnde.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 2)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class publish_args:
+  """
+  Attributes:
+   - eventBundle
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRUCT, 'eventBundle', (Data.ttypes.ThriftEventBundle, Data.ttypes.ThriftEventBundle.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, eventBundle=None,):
+    self.eventBundle = eventBundle
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRUCT:
+          self.eventBundle = Data.ttypes.ThriftEventBundle()
+          self.eventBundle.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('publish_args')
+    if self.eventBundle is not None:
+      oprot.writeFieldBegin('eventBundle', TType.STRUCT, 1)
+      self.eventBundle.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class publish_result:
+  """
+  Attributes:
+   - ue
+   - se
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRUCT, 'ue', (ttypes.ThriftUndefinedEventTypeException, ttypes.ThriftUndefinedEventTypeException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
+  )
+
+  def __init__(self, ue=None, se=None,):
+    self.ue = ue
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRUCT:
+          self.ue = ttypes.ThriftUndefinedEventTypeException()
+          self.ue.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.se = ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('publish_result')
+    if self.ue is not None:
+      oprot.writeFieldBegin('ue', TType.STRUCT, 1)
+      self.ue.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 2)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamById_args:
+  """
+  Attributes:
+   - sessionId
+   - streamId
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamId', None, None, ), # 2
+  )
+
+  def __init__(self, sessionId=None, streamId=None,):
+    self.sessionId = sessionId
+    self.streamId = streamId
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamById_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamId is not None:
+      oprot.writeFieldBegin('streamId', TType.STRING, 2)
+      oprot.writeString(self.streamId)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamById_result:
+  """
+  Attributes:
+   - success
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.BOOL, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, se=None,):
+    self.success = success
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.BOOL:
+          self.success = iprot.readBool();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.se = ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamById_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.BOOL, 0)
+      oprot.writeBool(self.success)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 1)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamByNameVersion_args:
+  """
+  Attributes:
+   - sessionId
+   - streamName
+   - streamVersion
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamName', None, None, ), # 2
+    (3, TType.STRING, 'streamVersion', None, None, ), # 3
+  )
+
+  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
+    self.sessionId = sessionId
+    self.streamName = streamName
+    self.streamVersion = streamVersion
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamName = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRING:
+          self.streamVersion = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamByNameVersion_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamName is not None:
+      oprot.writeFieldBegin('streamName', TType.STRING, 2)
+      oprot.writeString(self.streamName)
+      oprot.writeFieldEnd()
+    if self.streamVersion is not None:
+      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
+      oprot.writeString(self.streamVersion)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamByNameVersion_result:
+  """
+  Attributes:
+   - success
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.BOOL, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, se=None,):
+    self.success = success
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.BOOL:
+          self.success = iprot.readBool();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.se = ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamByNameVersion_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.BOOL, 0)
+      oprot.writeBool(self.success)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 1)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
new file mode 100644
index 0000000..c321ae1
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
@@ -0,0 +1 @@
+__all__ = ['ttypes', 'constants', 'ThriftSecureEventTransmissionService']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
new file mode 100644
index 0000000..36943ba
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
@@ -0,0 +1,8 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
new file mode 100644
index 0000000..37ac241
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
@@ -0,0 +1,21 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
+from ..Data import ttypes
+from ..Exception import ttypes
+
+
+from ...thrift.transport import TTransport
+from ...thrift.protocol import TBinaryProtocol, TProtocol
+try:
+  from thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/__init__.py
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
new file mode 100644
index 0000000..325b05d
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
@@ -0,0 +1,111 @@
+# 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.
+
+import time
+import sys
+
+sys.path.append("gen")
+
+from gen.ThriftSecureEventTransmissionService import ThriftSecureEventTransmissionService
+from gen.Data.ttypes import ThriftEventBundle
+
+from thrift.transport import TSSLSocket
+from thrift.transport import TTransport
+from thrift.protocol import TBinaryProtocol
+
+
+# Define publisher class
+class Publisher:
+    client = None
+
+    def __init__(self, ip, port):
+        # Make SSL socket
+        self.socket = TSSLSocket.TSSLSocket(ip, port, False)
+        # Buffering is critical. Raw sockets are very slow
+        self.transport = TTransport.TBufferedTransport(self.socket)
+        # Wrap in a protocol
+        self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
+        self.sessionId = None
+        self.streamId = None
+
+    def connect(self, username, password):
+        # Create a client to use the protocol encoder
+        Publisher.client = ThriftSecureEventTransmissionService.Client(self.protocol)
+
+        # Make connection
+        self.socket.open()
+        self.transport.open()
+        self.sessionId = Publisher.client.connect(username, password)
+
+    def defineStream(self, streamDef):
+        # Create Stream Definition
+        self.streamId = Publisher.client.defineStream(self.sessionId, streamDef)
+
+    def publish(self, event):
+        # Build thrift event bundle
+        #event = EventBundle()
+        event.setSessionId(self.sessionId)
+        event.setEventNum(0)
+        event.addStringAttribute(self.streamId)
+        event.addLongAttribute(time.time() * 1000)
+        #event.addStringAttribute(msg)
+        # Publish
+        Publisher.client.publish(event.getEventBundle())
+
+    def disconnect(self):
+        # Disconnect
+        Publisher.client.disconnect(self.sessionId)
+        self.transport.close()
+        self.socket.close()
+
+
+class EventBundle:
+    __sessionId = ""
+    __eventNum = 0
+    __intAttributeList = []
+    __longAttributeList = []
+    __doubleAttributeList = []
+    __boolAttributeList = []
+    __stringAttributeList = []
+    __arbitraryDataMapMap = None
+
+    def setSessionId(self, sessionId):
+        self.__sessionId = sessionId
+
+    def setEventNum(self, num):
+        self.__eventNum = num
+
+    def addIntAttribute(self, attr):
+        self.__intAttributeList.append(attr)
+
+    def addLongAttribute(self, attr):
+        self.__longAttributeList.append(attr)
+
+    def addDoubleAttribute(self, attr):
+        self.__doubleAttributeList.append(attr)
+
+    def addBoolAttribute(self, attr):
+        self.__boolAttributeList.append(attr)
+
+    def addStringAttribute(self, attr):
+        self.__stringAttributeList.append(attr)
+
+    def getEventBundle(self):
+        return ThriftEventBundle(self.__sessionId, self.__eventNum, self.__intAttributeList,
+                                             self.__longAttributeList, self.__doubleAttributeList,
+                                             self.__boolAttributeList, self.__stringAttributeList,
+                                             self.__arbitraryDataMapMap)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py
new file mode 100644
index 0000000..da8d283
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+from os import path
+from SCons.Builder import Builder
+
+
+def scons_env(env, add=''):
+  opath = path.dirname(path.abspath('$TARGET'))
+  lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE'
+  cppbuild = Builder(action=lstr)
+  env.Append(BUILDERS={'ThriftCpp': cppbuild})
+
+
+def gen_cpp(env, dir, file):
+  scons_env(env)
+  suffixes = ['_types.h', '_types.cpp']
+  targets = map(lambda s: 'gen-cpp/' + file + s, suffixes)
+  return env.ThriftCpp(targets, dir + file + '.thrift')

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py
new file mode 100644
index 0000000..8a58d89
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+from protocol import TBinaryProtocol
+from transport import TTransport
+
+
+def serialize(thrift_object,
+              protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
+    transport = TTransport.TMemoryBuffer()
+    protocol = protocol_factory.getProtocol(transport)
+    thrift_object.write(protocol)
+    return transport.getvalue()
+
+
+def deserialize(base,
+                buf,
+                protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
+    transport = TTransport.TMemoryBuffer(buf)
+    protocol = protocol_factory.getProtocol(transport)
+    base.read(protocol)
+    return base

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py
new file mode 100644
index 0000000..8d9f5ed
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py
@@ -0,0 +1,153 @@
+#
+# 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.
+#
+
+from cStringIO import StringIO
+import logging
+import socket
+import struct
+
+from .transport import TTransport
+from .transport.TTransport import TTransportException
+
+from tornado import gen
+from tornado import iostream
+from tornado import netutil
+
+
+class TTornadoStreamTransport(TTransport.TTransportBase):
+    """a framed, buffered transport over a Tornado stream"""
+    def __init__(self, host, port, stream=None):
+        self.host = host
+        self.port = port
+        self.is_queuing_reads = False
+        self.read_queue = []
+        self.__wbuf = StringIO()
+
+        # servers provide a ready-to-go stream
+        self.stream = stream
+        if self.stream is not None:
+            self._set_close_callback()
+
+    # not the same number of parameters as TTransportBase.open
+    def open(self, callback):
+        logging.debug('socket connecting')
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
+        self.stream = iostream.IOStream(sock)
+
+        def on_close_in_connect(*_):
+            message = 'could not connect to {}:{}'.format(self.host, self.port)
+            raise TTransportException(
+                type=TTransportException.NOT_OPEN,
+                message=message)
+        self.stream.set_close_callback(on_close_in_connect)
+
+        def finish(*_):
+            self._set_close_callback()
+            callback()
+
+        self.stream.connect((self.host, self.port), callback=finish)
+
+    def _set_close_callback(self):
+        def on_close():
+            raise TTransportException(
+                type=TTransportException.END_OF_FILE,
+                message='socket closed')
+        self.stream.set_close_callback(self.close)
+
+    def close(self):
+        # don't raise if we intend to close
+        self.stream.set_close_callback(None)
+        self.stream.close()
+
+    def read(self, _):
+        # The generated code for Tornado shouldn't do individual reads -- only
+        # frames at a time
+        assert "you're doing it wrong" is True
+
+    @gen.engine
+    def readFrame(self, callback):
+        self.read_queue.append(callback)
+        logging.debug('read queue: %s', self.read_queue)
+
+        if self.is_queuing_reads:
+            # If a read is already in flight, then the while loop below should
+            # pull it from self.read_queue
+            return
+
+        self.is_queuing_reads = True
+        while self.read_queue:
+            next_callback = self.read_queue.pop()
+            result = yield gen.Task(self._readFrameFromStream)
+            next_callback(result)
+        self.is_queuing_reads = False
+
+    @gen.engine
+    def _readFrameFromStream(self, callback):
+        logging.debug('_readFrameFromStream')
+        frame_header = yield gen.Task(self.stream.read_bytes, 4)
+        frame_length, = struct.unpack('!i', frame_header)
+        logging.debug('received frame header, frame length = %i', frame_length)
+        frame = yield gen.Task(self.stream.read_bytes, frame_length)
+        logging.debug('received frame payload')
+        callback(frame)
+
+    def write(self, buf):
+        self.__wbuf.write(buf)
+
+    def flush(self, callback=None):
+        wout = self.__wbuf.getvalue()
+        wsz = len(wout)
+        # reset wbuf before write/flush to preserve state on underlying failure
+        self.__wbuf = StringIO()
+        # N.B.: Doing this string concatenation is WAY cheaper than making
+        # two separate calls to the underlying socket object. Socket writes in
+        # Python turn out to be REALLY expensive, but it seems to do a pretty
+        # good job of managing string buffer operations without excessive copies
+        buf = struct.pack("!i", wsz) + wout
+
+        logging.debug('writing frame length = %i', wsz)
+        self.stream.write(buf, callback)
+
+
+class TTornadoServer(netutil.TCPServer):
+    def __init__(self, processor, iprot_factory, oprot_factory=None,
+                 *args, **kwargs):
+        super(TTornadoServer, self).__init__(*args, **kwargs)
+
+        self._processor = processor
+        self._iprot_factory = iprot_factory
+        self._oprot_factory = (oprot_factory if oprot_factory is not None
+                               else iprot_factory)
+
+    def handle_stream(self, stream, address):
+        try:
+            host, port = address
+            trans = TTornadoStreamTransport(host=host, port=port, stream=stream)
+            oprot = self._oprot_factory.getProtocol(trans)
+
+            def next_pass():
+                if not trans.stream.closed():
+                    self._processor.process(trans, self._iprot_factory, oprot,
+                                            callback=next_pass)
+
+            next_pass()
+
+        except Exception:
+            logging.exception('thrift exception in handle_stream')
+            trans.close()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py
new file mode 100644
index 0000000..9890af7
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py
@@ -0,0 +1,170 @@
+#
+# 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.
+#
+
+import sys
+
+
+class TType:
+  STOP   = 0
+  VOID   = 1
+  BOOL   = 2
+  BYTE   = 3
+  I08    = 3
+  DOUBLE = 4
+  I16    = 6
+  I32    = 8
+  I64    = 10
+  STRING = 11
+  UTF7   = 11
+  STRUCT = 12
+  MAP    = 13
+  SET    = 14
+  LIST   = 15
+  UTF8   = 16
+  UTF16  = 17
+
+  _VALUES_TO_NAMES = ('STOP',
+                      'VOID',
+                      'BOOL',
+                      'BYTE',
+                      'DOUBLE',
+                      None,
+                      'I16',
+                      None,
+                      'I32',
+                      None,
+                     'I64',
+                     'STRING',
+                     'STRUCT',
+                     'MAP',
+                     'SET',
+                     'LIST',
+                     'UTF8',
+                     'UTF16')
+
+
+class TMessageType:
+  CALL = 1
+  REPLY = 2
+  EXCEPTION = 3
+  ONEWAY = 4
+
+
+class TProcessor:
+  """Base class for procsessor, which works on two streams."""
+
+  def process(iprot, oprot):
+    pass
+
+
+class TException(Exception):
+  """Base class for all thrift exceptions."""
+
+  # BaseException.message is deprecated in Python v[2.6,3.0)
+  if (2, 6, 0) <= sys.version_info < (3, 0):
+    def _get_message(self):
+      return self._message
+
+    def _set_message(self, message):
+      self._message = message
+    message = property(_get_message, _set_message)
+
+  def __init__(self, message=None):
+    Exception.__init__(self, message)
+    self.message = message
+
+
+class TApplicationException(TException):
+  """Application level thrift exceptions."""
+
+  UNKNOWN = 0
+  UNKNOWN_METHOD = 1
+  INVALID_MESSAGE_TYPE = 2
+  WRONG_METHOD_NAME = 3
+  BAD_SEQUENCE_ID = 4
+  MISSING_RESULT = 5
+  INTERNAL_ERROR = 6
+  PROTOCOL_ERROR = 7
+  INVALID_TRANSFORM = 8
+  INVALID_PROTOCOL = 9
+  UNSUPPORTED_CLIENT_TYPE = 10
+
+  def __init__(self, type=UNKNOWN, message=None):
+    TException.__init__(self, message)
+    self.type = type
+
+  def __str__(self):
+    if self.message:
+      return self.message
+    elif self.type == self.UNKNOWN_METHOD:
+      return 'Unknown method'
+    elif self.type == self.INVALID_MESSAGE_TYPE:
+      return 'Invalid message type'
+    elif self.type == self.WRONG_METHOD_NAME:
+      return 'Wrong method name'
+    elif self.type == self.BAD_SEQUENCE_ID:
+      return 'Bad sequence ID'
+    elif self.type == self.MISSING_RESULT:
+      return 'Missing result'
+    elif self.type == self.INTERNAL_ERROR:
+      return 'Internal error'
+    elif self.type == self.PROTOCOL_ERROR:
+      return 'Protocol error'
+    elif self.type == self.INVALID_TRANSFORM:
+      return 'Invalid transform'
+    elif self.type == self.INVALID_PROTOCOL:
+      return 'Invalid protocol'
+    elif self.type == self.UNSUPPORTED_CLIENT_TYPE:
+      return 'Unsupported client type'
+    else:
+      return 'Default (unknown) TApplicationException'
+
+  def read(self, iprot):
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString()
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.I32:
+          self.type = iprot.readI32()
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    oprot.writeStructBegin('TApplicationException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    if self.type is not None:
+      oprot.writeFieldBegin('type', TType.I32, 2)
+      oprot.writeI32(self.type)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py
new file mode 100644
index 0000000..48d659c
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+__all__ = ['Thrift', 'TSCons']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py
new file mode 100644
index 0000000..61b469b
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py
@@ -0,0 +1,81 @@
+#
+# 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.
+#
+
+from ..Thrift import *
+import TBinaryProtocol
+from ..transport import TTransport
+
+try:
+  import fastbinary
+except:
+  fastbinary = None
+
+
+class TBase(object):
+  __slots__ = []
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, getattr(self, key))
+              for key in self.__slots__]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    if not isinstance(other, self.__class__):
+      return False
+    for attr in self.__slots__:
+      my_val = getattr(self, attr)
+      other_val = getattr(other, attr)
+      if my_val != other_val:
+        return False
+    return True
+
+  def __ne__(self, other):
+    return not (self == other)
+
+  def read(self, iprot):
+    if (iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
+        isinstance(iprot.trans, TTransport.CReadableTransport) and
+        self.thrift_spec is not None and
+        fastbinary is not None):
+      fastbinary.decode_binary(self,
+                               iprot.trans,
+                               (self.__class__, self.thrift_spec))
+      return
+    iprot.readStruct(self, self.thrift_spec)
+
+  def write(self, oprot):
+    if (oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
+        self.thrift_spec is not None and
+        fastbinary is not None):
+      oprot.trans.write(
+        fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStruct(self, self.thrift_spec)
+
+
+class TExceptionBase(Exception):
+  # old style class so python2.4 can raise exceptions derived from this
+  #  This can't inherit from TBase because of that limitation.
+  __slots__ = []
+
+  __repr__ = TBase.__repr__.im_func
+  __eq__ = TBase.__eq__.im_func
+  __ne__ = TBase.__ne__.im_func
+  read = TBase.read.im_func
+  write = TBase.write.im_func

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
new file mode 100644
index 0000000..2cdc6b5
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
@@ -0,0 +1,261 @@
+#
+# 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.
+#
+
+from struct import pack, unpack
+
+from TProtocol import *
+
+
+class TBinaryProtocol(TProtocolBase):
+  """Binary implementation of the Thrift protocol driver."""
+
+  # NastyHaxx. Python 2.4+ on 32-bit machines forces hex constants to be
+  # positive, converting this into a long. If we hardcode the int value
+  # instead it'll stay in 32 bit-land.
+
+  # VERSION_MASK = 0xffff0000
+  VERSION_MASK = -65536
+
+  # VERSION_1 = 0x80010000
+  VERSION_1 = -2147418112
+
+  TYPE_MASK = 0x000000ff
+
+  def __init__(self, trans, strictRead=False, strictWrite=True):
+    TProtocolBase.__init__(self, trans)
+    self.strictRead = strictRead
+    self.strictWrite = strictWrite
+
+  def writeMessageBegin(self, name, type, seqid):
+    if self.strictWrite:
+      self.writeI32(TBinaryProtocol.VERSION_1 | type)
+      self.writeString(name)
+      self.writeI32(seqid)
+    else:
+      self.writeString(name)
+      self.writeByte(type)
+      self.writeI32(seqid)
+
+  def writeMessageEnd(self):
+    pass
+
+  def writeStructBegin(self, name):
+    pass
+
+  def writeStructEnd(self):
+    pass
+
+  def writeFieldBegin(self, name, type, id):
+    self.writeByte(type)
+    self.writeI16(id)
+
+  def writeFieldEnd(self):
+    pass
+
+  def writeFieldStop(self):
+    self.writeByte(TType.STOP)
+
+  def writeMapBegin(self, ktype, vtype, size):
+    self.writeByte(ktype)
+    self.writeByte(vtype)
+    self.writeI32(size)
+
+  def writeMapEnd(self):
+    pass
+
+  def writeListBegin(self, etype, size):
+    self.writeByte(etype)
+    self.writeI32(size)
+
+  def writeListEnd(self):
+    pass
+
+  def writeSetBegin(self, etype, size):
+    self.writeByte(etype)
+    self.writeI32(size)
+
+  def writeSetEnd(self):
+    pass
+
+  def writeBool(self, bool):
+    if bool:
+      self.writeByte(1)
+    else:
+      self.writeByte(0)
+
+  def writeByte(self, byte):
+    buff = pack("!b", byte)
+    self.trans.write(buff)
+
+  def writeI16(self, i16):
+    buff = pack("!h", i16)
+    self.trans.write(buff)
+
+  def writeI32(self, i32):
+    buff = pack("!i", i32)
+    self.trans.write(buff)
+
+  def writeI64(self, i64):
+    buff = pack("!q", i64)
+    self.trans.write(buff)
+
+  def writeDouble(self, dub):
+    buff = pack("!d", dub)
+    self.trans.write(buff)
+
+  def writeString(self, str):
+    self.writeI32(len(str))
+    self.trans.write(str)
+
+  def readMessageBegin(self):
+    sz = self.readI32()
+    if sz < 0:
+      version = sz & TBinaryProtocol.VERSION_MASK
+      if version != TBinaryProtocol.VERSION_1:
+        raise TProtocolException(
+          type=TProtocolException.BAD_VERSION,
+          message='Bad version in readMessageBegin: %d' % (sz))
+      type = sz & TBinaryProtocol.TYPE_MASK
+      name = self.readString()
+      seqid = self.readI32()
+    else:
+      if self.strictRead:
+        raise TProtocolException(type=TProtocolException.BAD_VERSION,
+                                 message='No protocol version header')
+      name = self.trans.readAll(sz)
+      type = self.readByte()
+      seqid = self.readI32()
+    return (name, type, seqid)
+
+  def readMessageEnd(self):
+    pass
+
+  def readStructBegin(self):
+    pass
+
+  def readStructEnd(self):
+    pass
+
+  def readFieldBegin(self):
+    type = self.readByte()
+    if type == TType.STOP:
+      return (None, type, 0)
+    id = self.readI16()
+    return (None, type, id)
+
+  def readFieldEnd(self):
+    pass
+
+  def readMapBegin(self):
+    ktype = self.readByte()
+    vtype = self.readByte()
+    size = self.readI32()
+    return (ktype, vtype, size)
+
+  def readMapEnd(self):
+    pass
+
+  def readListBegin(self):
+    etype = self.readByte()
+    size = self.readI32()
+    return (etype, size)
+
+  def readListEnd(self):
+    pass
+
+  def readSetBegin(self):
+    etype = self.readByte()
+    size = self.readI32()
+    return (etype, size)
+
+  def readSetEnd(self):
+    pass
+
+  def readBool(self):
+    byte = self.readByte()
+    if byte == 0:
+      return False
+    return True
+
+  def readByte(self):
+    buff = self.trans.readAll(1)
+    val, = unpack('!b', buff)
+    return val
+
+  def readI16(self):
+    buff = self.trans.readAll(2)
+    val, = unpack('!h', buff)
+    return val
+
+  def readI32(self):
+    buff = self.trans.readAll(4)
+    val, = unpack('!i', buff)
+    return val
+
+  def readI64(self):
+    buff = self.trans.readAll(8)
+    val, = unpack('!q', buff)
+    return val
+
+  def readDouble(self):
+    buff = self.trans.readAll(8)
+    val, = unpack('!d', buff)
+    return val
+
+  def readString(self):
+    len = self.readI32()
+    str = self.trans.readAll(len)
+    return str
+
+
+class TBinaryProtocolFactory:
+  def __init__(self, strictRead=False, strictWrite=True):
+    self.strictRead = strictRead
+    self.strictWrite = strictWrite
+
+  def getProtocol(self, trans):
+    prot = TBinaryProtocol(trans, self.strictRead, self.strictWrite)
+    return prot
+
+
+class TBinaryProtocolAccelerated(TBinaryProtocol):
+  """C-Accelerated version of TBinaryProtocol.
+
+  This class does not override any of TBinaryProtocol's methods,
+  but the generated code recognizes it directly and will call into
+  our C module to do the encoding, bypassing this object entirely.
+  We inherit from TBinaryProtocol so that the normal TBinaryProtocol
+  encoding can happen if the fastbinary module doesn't work for some
+  reason.  (TODO(dreiss): Make this happen sanely in more cases.)
+
+  In order to take advantage of the C module, just use
+  TBinaryProtocolAccelerated instead of TBinaryProtocol.
+
+  NOTE:  This code was contributed by an external developer.
+         The internal Thrift team has reviewed and tested it,
+         but we cannot guarantee that it is production-ready.
+         Please feel free to report bugs and/or success stories
+         to the public mailing list.
+  """
+  pass
+
+
+class TBinaryProtocolAcceleratedFactory:
+  def getProtocol(self, trans):
+    return TBinaryProtocolAccelerated(trans)


[09/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
new file mode 100644
index 0000000..74e142c
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
@@ -0,0 +1,118 @@
+#
+# 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.
+#
+
+
+import logging
+from multiprocessing import  Process, Value, Condition
+
+from TServer import TServer
+from ..transport.TTransport import TTransportException
+
+
+class TProcessPoolServer(TServer):
+    """Server with a fixed size pool of worker subprocesses to service requests
+
+    Note that if you need shared state between the handlers - it's up to you!
+    Written by Dvir Volk, doat.com
+    """
+    def __init__(self, *args):
+        TServer.__init__(self, *args)
+        self.numWorkers = 10
+        self.workers = []
+        self.isRunning = Value('b', False)
+        self.stopCondition = Condition()
+        self.postForkCallback = None
+
+    def setPostForkCallback(self, callback):
+        if not callable(callback):
+            raise TypeError("This is not a callback!")
+        self.postForkCallback = callback
+
+    def setNumWorkers(self, num):
+        """Set the number of worker threads that should be created"""
+        self.numWorkers = num
+
+    def workerProcess(self):
+        """Loop getting clients from the shared queue and process them"""
+        if self.postForkCallback:
+            self.postForkCallback()
+
+        while self.isRunning.value:
+            try:
+                client = self.serverTransport.accept()
+                self.serveClient(client)
+            except (KeyboardInterrupt, SystemExit):
+                return 0
+            except Exception, x:
+                logging.exception(x)
+
+    def serveClient(self, client):
+        """Process input/output from a client for as long as possible"""
+        itrans = self.inputTransportFactory.getTransport(client)
+        otrans = self.outputTransportFactory.getTransport(client)
+        iprot = self.inputProtocolFactory.getProtocol(itrans)
+        oprot = self.outputProtocolFactory.getProtocol(otrans)
+
+        try:
+            while True:
+                self.processor.process(iprot, oprot)
+        except TTransportException, tx:
+            pass
+        except Exception, x:
+            logging.exception(x)
+
+        itrans.close()
+        otrans.close()
+
+    def serve(self):
+        """Start workers and put into queue"""
+        # this is a shared state that can tell the workers to exit when False
+        self.isRunning.value = True
+
+        # first bind and listen to the port
+        self.serverTransport.listen()
+
+        # fork the children
+        for i in range(self.numWorkers):
+            try:
+                w = Process(target=self.workerProcess)
+                w.daemon = True
+                w.start()
+                self.workers.append(w)
+            except Exception, x:
+                logging.exception(x)
+
+        # wait until the condition is set by stop()
+        while True:
+            self.stopCondition.acquire()
+            try:
+                self.stopCondition.wait()
+                break
+            except (SystemExit, KeyboardInterrupt):
+                break
+            except Exception, x:
+                logging.exception(x)
+
+        self.isRunning.value = False
+
+    def stop(self):
+        self.isRunning.value = False
+        self.stopCondition.acquire()
+        self.stopCondition.notify()
+        self.stopCondition.release()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py
new file mode 100644
index 0000000..3e44107
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py
@@ -0,0 +1,269 @@
+#
+# 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.
+#
+
+import Queue
+import logging
+import os
+import sys
+import threading
+import traceback
+
+from ..Thrift import TProcessor
+from ..protocol import TBinaryProtocol
+from ..transport import TTransport
+
+
+class TServer:
+  """Base interface for a server, which must have a serve() method.
+
+  Three constructors for all servers:
+  1) (processor, serverTransport)
+  2) (processor, serverTransport, transportFactory, protocolFactory)
+  3) (processor, serverTransport,
+      inputTransportFactory, outputTransportFactory,
+      inputProtocolFactory, outputProtocolFactory)
+  """
+  def __init__(self, *args):
+    if (len(args) == 2):
+      self.__initArgs__(args[0], args[1],
+                        TTransport.TTransportFactoryBase(),
+                        TTransport.TTransportFactoryBase(),
+                        TBinaryProtocol.TBinaryProtocolFactory(),
+                        TBinaryProtocol.TBinaryProtocolFactory())
+    elif (len(args) == 4):
+      self.__initArgs__(args[0], args[1], args[2], args[2], args[3], args[3])
+    elif (len(args) == 6):
+      self.__initArgs__(args[0], args[1], args[2], args[3], args[4], args[5])
+
+  def __initArgs__(self, processor, serverTransport,
+                   inputTransportFactory, outputTransportFactory,
+                   inputProtocolFactory, outputProtocolFactory):
+    self.processor = processor
+    self.serverTransport = serverTransport
+    self.inputTransportFactory = inputTransportFactory
+    self.outputTransportFactory = outputTransportFactory
+    self.inputProtocolFactory = inputProtocolFactory
+    self.outputProtocolFactory = outputProtocolFactory
+
+  def serve(self):
+    pass
+
+
+class TSimpleServer(TServer):
+  """Simple single-threaded server that just pumps around one transport."""
+
+  def __init__(self, *args):
+    TServer.__init__(self, *args)
+
+  def serve(self):
+    self.serverTransport.listen()
+    while True:
+      client = self.serverTransport.accept()
+      itrans = self.inputTransportFactory.getTransport(client)
+      otrans = self.outputTransportFactory.getTransport(client)
+      iprot = self.inputProtocolFactory.getProtocol(itrans)
+      oprot = self.outputProtocolFactory.getProtocol(otrans)
+      try:
+        while True:
+          self.processor.process(iprot, oprot)
+      except TTransport.TTransportException, tx:
+        pass
+      except Exception, x:
+        logging.exception(x)
+
+      itrans.close()
+      otrans.close()
+
+
+class TThreadedServer(TServer):
+  """Threaded server that spawns a new thread per each connection."""
+
+  def __init__(self, *args, **kwargs):
+    TServer.__init__(self, *args)
+    self.daemon = kwargs.get("daemon", False)
+
+  def serve(self):
+    self.serverTransport.listen()
+    while True:
+      try:
+        client = self.serverTransport.accept()
+        t = threading.Thread(target=self.handle, args=(client,))
+        t.setDaemon(self.daemon)
+        t.start()
+      except KeyboardInterrupt:
+        raise
+      except Exception, x:
+        logging.exception(x)
+
+  def handle(self, client):
+    itrans = self.inputTransportFactory.getTransport(client)
+    otrans = self.outputTransportFactory.getTransport(client)
+    iprot = self.inputProtocolFactory.getProtocol(itrans)
+    oprot = self.outputProtocolFactory.getProtocol(otrans)
+    try:
+      while True:
+        self.processor.process(iprot, oprot)
+    except TTransport.TTransportException, tx:
+      pass
+    except Exception, x:
+      logging.exception(x)
+
+    itrans.close()
+    otrans.close()
+
+
+class TThreadPoolServer(TServer):
+  """Server with a fixed size pool of threads which service requests."""
+
+  def __init__(self, *args, **kwargs):
+    TServer.__init__(self, *args)
+    self.clients = Queue.Queue()
+    self.threads = 10
+    self.daemon = kwargs.get("daemon", False)
+
+  def setNumThreads(self, num):
+    """Set the number of worker threads that should be created"""
+    self.threads = num
+
+  def serveThread(self):
+    """Loop around getting clients from the shared queue and process them."""
+    while True:
+      try:
+        client = self.clients.get()
+        self.serveClient(client)
+      except Exception, x:
+        logging.exception(x)
+
+  def serveClient(self, client):
+    """Process input/output from a client for as long as possible"""
+    itrans = self.inputTransportFactory.getTransport(client)
+    otrans = self.outputTransportFactory.getTransport(client)
+    iprot = self.inputProtocolFactory.getProtocol(itrans)
+    oprot = self.outputProtocolFactory.getProtocol(otrans)
+    try:
+      while True:
+        self.processor.process(iprot, oprot)
+    except TTransport.TTransportException, tx:
+      pass
+    except Exception, x:
+      logging.exception(x)
+
+    itrans.close()
+    otrans.close()
+
+  def serve(self):
+    """Start a fixed number of worker threads and put client into a queue"""
+    for i in range(self.threads):
+      try:
+        t = threading.Thread(target=self.serveThread)
+        t.setDaemon(self.daemon)
+        t.start()
+      except Exception, x:
+        logging.exception(x)
+
+    # Pump the socket for clients
+    self.serverTransport.listen()
+    while True:
+      try:
+        client = self.serverTransport.accept()
+        self.clients.put(client)
+      except Exception, x:
+        logging.exception(x)
+
+
+class TForkingServer(TServer):
+  """A Thrift server that forks a new process for each request
+
+  This is more scalable than the threaded server as it does not cause
+  GIL contention.
+
+  Note that this has different semantics from the threading server.
+  Specifically, updates to shared variables will no longer be shared.
+  It will also not work on windows.
+
+  This code is heavily inspired by SocketServer.ForkingMixIn in the
+  Python stdlib.
+  """
+  def __init__(self, *args):
+    TServer.__init__(self, *args)
+    self.children = []
+
+  def serve(self):
+    def try_close(file):
+      try:
+        file.close()
+      except IOError, e:
+        logging.warning(e, exc_info=True)
+
+    self.serverTransport.listen()
+    while True:
+      client = self.serverTransport.accept()
+      try:
+        pid = os.fork()
+
+        if pid:  # parent
+          # add before collect, otherwise you race w/ waitpid
+          self.children.append(pid)
+          self.collect_children()
+
+          # Parent must close socket or the connection may not get
+          # closed promptly
+          itrans = self.inputTransportFactory.getTransport(client)
+          otrans = self.outputTransportFactory.getTransport(client)
+          try_close(itrans)
+          try_close(otrans)
+        else:
+          itrans = self.inputTransportFactory.getTransport(client)
+          otrans = self.outputTransportFactory.getTransport(client)
+
+          iprot = self.inputProtocolFactory.getProtocol(itrans)
+          oprot = self.outputProtocolFactory.getProtocol(otrans)
+
+          ecode = 0
+          try:
+            try:
+              while True:
+                self.processor.process(iprot, oprot)
+            except TTransport.TTransportException, tx:
+              pass
+            except Exception, e:
+              logging.exception(e)
+              ecode = 1
+          finally:
+            try_close(itrans)
+            try_close(otrans)
+
+          os._exit(ecode)
+
+      except TTransport.TTransportException, tx:
+        pass
+      except Exception, x:
+        logging.exception(x)
+
+  def collect_children(self):
+    while self.children:
+      try:
+        pid, status = os.waitpid(0, os.WNOHANG)
+      except os.error:
+        pid = None
+
+      if pid:
+        self.children.remove(pid)
+      else:
+        break

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py
new file mode 100644
index 0000000..1bf6e25
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+__all__ = ['TServer', 'TNonblockingServer']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py
new file mode 100644
index 0000000..9ef9535
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py
@@ -0,0 +1,147 @@
+#
+# 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.
+#
+
+import httplib
+import os
+import socket
+import sys
+import urllib
+import urlparse
+import warnings
+
+from TTransport import *
+
+
+class THttpClient(TTransportBase):
+  """Http implementation of TTransport base."""
+
+  def __init__(self, uri_or_host, port=None, path=None):
+    """THttpClient supports two different types constructor parameters.
+
+    THttpClient(host, port, path) - deprecated
+    THttpClient(uri)
+
+    Only the second supports https.
+    """
+    if port is not None:
+      warnings.warn(
+        "Please use the THttpClient('http://host:port/path') syntax",
+        DeprecationWarning,
+        stacklevel=2)
+      self.host = uri_or_host
+      self.port = port
+      assert path
+      self.path = path
+      self.scheme = 'http'
+    else:
+      parsed = urlparse.urlparse(uri_or_host)
+      self.scheme = parsed.scheme
+      assert self.scheme in ('http', 'https')
+      if self.scheme == 'http':
+        self.port = parsed.port or httplib.HTTP_PORT
+      elif self.scheme == 'https':
+        self.port = parsed.port or httplib.HTTPS_PORT
+      self.host = parsed.hostname
+      self.path = parsed.path
+      if parsed.query:
+        self.path += '?%s' % parsed.query
+    self.__wbuf = StringIO()
+    self.__http = None
+    self.__timeout = None
+    self.__custom_headers = None
+
+  def open(self):
+    if self.scheme == 'http':
+      self.__http = httplib.HTTP(self.host, self.port)
+    else:
+      self.__http = httplib.HTTPS(self.host, self.port)
+
+  def close(self):
+    self.__http.close()
+    self.__http = None
+
+  def isOpen(self):
+    return self.__http is not None
+
+  def setTimeout(self, ms):
+    if not hasattr(socket, 'getdefaulttimeout'):
+      raise NotImplementedError
+
+    if ms is None:
+      self.__timeout = None
+    else:
+      self.__timeout = ms / 1000.0
+
+  def setCustomHeaders(self, headers):
+    self.__custom_headers = headers
+
+  def read(self, sz):
+    return self.__http.file.read(sz)
+
+  def write(self, buf):
+    self.__wbuf.write(buf)
+
+  def __withTimeout(f):
+    def _f(*args, **kwargs):
+      orig_timeout = socket.getdefaulttimeout()
+      socket.setdefaulttimeout(args[0].__timeout)
+      result = f(*args, **kwargs)
+      socket.setdefaulttimeout(orig_timeout)
+      return result
+    return _f
+
+  def flush(self):
+    if self.isOpen():
+      self.close()
+    self.open()
+
+    # Pull data out of buffer
+    data = self.__wbuf.getvalue()
+    self.__wbuf = StringIO()
+
+    # HTTP request
+    self.__http.putrequest('POST', self.path)
+
+    # Write headers
+    self.__http.putheader('Host', self.host)
+    self.__http.putheader('Content-Type', 'application/x-thrift')
+    self.__http.putheader('Content-Length', str(len(data)))
+
+    if not self.__custom_headers or 'User-Agent' not in self.__custom_headers:
+      user_agent = 'Python/THttpClient'
+      script = os.path.basename(sys.argv[0])
+      if script:
+        user_agent = '%s (%s)' % (user_agent, urllib.quote(script))
+      self.__http.putheader('User-Agent', user_agent)
+
+    if self.__custom_headers:
+        for key, val in self.__custom_headers.iteritems():
+            self.__http.putheader(key, val)
+
+    self.__http.endheaders()
+
+    # Write payload
+    self.__http.send(data)
+
+    # Get reply to flush the request
+    self.code, self.message, self.headers = self.__http.getreply()
+
+  # Decorate if we know how to timeout
+  if hasattr(socket, 'getdefaulttimeout'):
+    flush = __withTimeout(flush)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
new file mode 100644
index 0000000..df35be4
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
@@ -0,0 +1,214 @@
+#
+# 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.
+#
+
+import os
+import socket
+import ssl
+
+import TSocket
+from TTransport import TTransportException
+
+
+class TSSLSocket(TSocket.TSocket):
+  """
+  SSL implementation of client-side TSocket
+
+  This class creates outbound sockets wrapped using the
+  python standard ssl module for encrypted connections.
+
+  The protocol used is set using the class variable
+  SSL_VERSION, which must be one of ssl.PROTOCOL_* and
+  defaults to  ssl.PROTOCOL_TLSv1 for greatest security.
+  """
+  SSL_VERSION = ssl.PROTOCOL_TLSv1
+
+  def __init__(self,
+               host='localhost',
+               port=9090,
+               validate=True,
+               ca_certs=None,
+               keyfile=None,
+               certfile=None,
+               unix_socket=None):
+    """Create SSL TSocket
+
+    @param validate: Set to False to disable SSL certificate validation
+    @type validate: bool
+    @param ca_certs: Filename to the Certificate Authority pem file, possibly a
+    file downloaded from: http://curl.haxx.se/ca/cacert.pem  This is passed to
+    the ssl_wrap function as the 'ca_certs' parameter.
+    @type ca_certs: str
+    @param keyfile: The private key
+    @type keyfile: str
+    @param certfile: The cert file
+    @type certfile: str
+    
+    Raises an IOError exception if validate is True and the ca_certs file is
+    None, not present or unreadable.
+    """
+    self.validate = validate
+    self.is_valid = False
+    self.peercert = None
+    if not validate:
+      self.cert_reqs = ssl.CERT_NONE
+    else:
+      self.cert_reqs = ssl.CERT_REQUIRED
+    self.ca_certs = ca_certs
+    self.keyfile = keyfile
+    self.certfile = certfile
+    if validate:
+      if ca_certs is None or not os.access(ca_certs, os.R_OK):
+        raise IOError('Certificate Authority ca_certs file "%s" '
+                      'is not readable, cannot validate SSL '
+                      'certificates.' % (ca_certs))
+    TSocket.TSocket.__init__(self, host, port, unix_socket)
+
+  def open(self):
+    try:
+      res0 = self._resolveAddr()
+      for res in res0:
+        sock_family, sock_type = res[0:2]
+        ip_port = res[4]
+        plain_sock = socket.socket(sock_family, sock_type)
+        self.handle = ssl.wrap_socket(plain_sock,
+                                      ssl_version=self.SSL_VERSION,
+                                      do_handshake_on_connect=True,
+                                      ca_certs=self.ca_certs,
+                                      keyfile=self.keyfile,
+                                      certfile=self.certfile,
+                                      cert_reqs=self.cert_reqs)
+        self.handle.settimeout(self._timeout)
+        try:
+          self.handle.connect(ip_port)
+        except socket.error, e:
+          if res is not res0[-1]:
+            continue
+          else:
+            raise e
+        break
+    except socket.error, e:
+      if self._unix_socket:
+        message = 'Could not connect to secure socket %s: %s' \
+                % (self._unix_socket, e)
+      else:
+        message = 'Could not connect to %s:%d: %s' % (self.host, self.port, e)
+      raise TTransportException(type=TTransportException.NOT_OPEN,
+                                message=message)
+    if self.validate:
+      self._validate_cert()
+
+  def _validate_cert(self):
+    """internal method to validate the peer's SSL certificate, and to check the
+    commonName of the certificate to ensure it matches the hostname we
+    used to make this connection.  Does not support subjectAltName records
+    in certificates.
+
+    raises TTransportException if the certificate fails validation.
+    """
+    cert = self.handle.getpeercert()
+    self.peercert = cert
+    if 'subject' not in cert:
+      raise TTransportException(
+        type=TTransportException.NOT_OPEN,
+        message='No SSL certificate found from %s:%s' % (self.host, self.port))
+    fields = cert['subject']
+    for field in fields:
+      # ensure structure we get back is what we expect
+      if not isinstance(field, tuple):
+        continue
+      cert_pair = field[0]
+      if len(cert_pair) < 2:
+        continue
+      cert_key, cert_value = cert_pair[0:2]
+      if cert_key != 'commonName':
+        continue
+      certhost = cert_value
+      # this check should be performed by some sort of Access Manager
+      if certhost == self.host:
+        # success, cert commonName matches desired hostname
+        self.is_valid = True
+        return
+      else:
+        raise TTransportException(
+          type=TTransportException.UNKNOWN,
+          message='Hostname we connected to "%s" doesn\'t match certificate '
+                  'provided commonName "%s"' % (self.host, certhost))
+    raise TTransportException(
+      type=TTransportException.UNKNOWN,
+      message='Could not validate SSL certificate from '
+              'host "%s".  Cert=%s' % (self.host, cert))
+
+
+class TSSLServerSocket(TSocket.TServerSocket):
+  """SSL implementation of TServerSocket
+
+  This uses the ssl module's wrap_socket() method to provide SSL
+  negotiated encryption.
+  """
+  SSL_VERSION = ssl.PROTOCOL_TLSv1
+
+  def __init__(self,
+               host=None,
+               port=9090,
+               certfile='cert.pem',
+               unix_socket=None):
+    """Initialize a TSSLServerSocket
+
+    @param certfile: filename of the server certificate, defaults to cert.pem
+    @type certfile: str
+    @param host: The hostname or IP to bind the listen socket to,
+                 i.e. 'localhost' for only allowing local network connections.
+                 Pass None to bind to all interfaces.
+    @type host: str
+    @param port: The port to listen on for inbound connections.
+    @type port: int
+    """
+    self.setCertfile(certfile)
+    TSocket.TServerSocket.__init__(self, host, port)
+
+  def setCertfile(self, certfile):
+    """Set or change the server certificate file used to wrap new connections.
+
+    @param certfile: The filename of the server certificate,
+                     i.e. '/etc/certs/server.pem'
+    @type certfile: str
+
+    Raises an IOError exception if the certfile is not present or unreadable.
+    """
+    if not os.access(certfile, os.R_OK):
+      raise IOError('No such certfile found: %s' % (certfile))
+    self.certfile = certfile
+
+  def accept(self):
+    plain_client, addr = self.handle.accept()
+    try:
+      client = ssl.wrap_socket(plain_client, certfile=self.certfile,
+                      server_side=True, ssl_version=self.SSL_VERSION)
+    except ssl.SSLError, ssl_exc:
+      # failed handshake/ssl wrap, close socket to client
+      plain_client.close()
+      # raise ssl_exc
+      # We can't raise the exception, because it kills most TServer derived
+      # serve() methods.
+      # Instead, return None, and let the TServer instance deal with it in
+      # other exception handling.  (but TSimpleServer dies anyway)
+      return None
+    result = TSocket.TSocket()
+    result.setHandle(client)
+    return result

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py
new file mode 100644
index 0000000..9e2b384
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py
@@ -0,0 +1,176 @@
+#
+# 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.
+#
+
+import errno
+import os
+import socket
+import sys
+
+from TTransport import *
+
+
+class TSocketBase(TTransportBase):
+  def _resolveAddr(self):
+    if self._unix_socket is not None:
+      return [(socket.AF_UNIX, socket.SOCK_STREAM, None, None,
+               self._unix_socket)]
+    else:
+      return socket.getaddrinfo(self.host,
+                                self.port,
+                                socket.AF_UNSPEC,
+                                socket.SOCK_STREAM,
+                                0,
+                                socket.AI_PASSIVE | socket.AI_ADDRCONFIG)
+
+  def close(self):
+    if self.handle:
+      self.handle.close()
+      self.handle = None
+
+
+class TSocket(TSocketBase):
+  """Socket implementation of TTransport base."""
+
+  def __init__(self, host='localhost', port=9090, unix_socket=None):
+    """Initialize a TSocket
+
+    @param host(str)  The host to connect to.
+    @param port(int)  The (TCP) port to connect to.
+    @param unix_socket(str)  The filename of a unix socket to connect to.
+                             (host and port will be ignored.)
+    """
+    self.host = host
+    self.port = port
+    self.handle = None
+    self._unix_socket = unix_socket
+    self._timeout = None
+
+  def setHandle(self, h):
+    self.handle = h
+
+  def isOpen(self):
+    return self.handle is not None
+
+  def setTimeout(self, ms):
+    if ms is None:
+      self._timeout = None
+    else:
+      self._timeout = ms / 1000.0
+
+    if self.handle is not None:
+      self.handle.settimeout(self._timeout)
+
+  def open(self):
+    try:
+      res0 = self._resolveAddr()
+      for res in res0:
+        self.handle = socket.socket(res[0], res[1])
+        self.handle.settimeout(self._timeout)
+        try:
+          self.handle.connect(res[4])
+        except socket.error, e:
+          if res is not res0[-1]:
+            continue
+          else:
+            raise e
+        break
+    except socket.error, e:
+      if self._unix_socket:
+        message = 'Could not connect to socket %s' % self._unix_socket
+      else:
+        message = 'Could not connect to %s:%d' % (self.host, self.port)
+      raise TTransportException(type=TTransportException.NOT_OPEN,
+                                message=message)
+
+  def read(self, sz):
+    try:
+      buff = self.handle.recv(sz)
+    except socket.error, e:
+      if (e.args[0] == errno.ECONNRESET and
+          (sys.platform == 'darwin' or sys.platform.startswith('freebsd'))):
+        # freebsd and Mach don't follow POSIX semantic of recv
+        # and fail with ECONNRESET if peer performed shutdown.
+        # See corresponding comment and code in TSocket::read()
+        # in lib/cpp/src/transport/TSocket.cpp.
+        self.close()
+        # Trigger the check to raise the END_OF_FILE exception below.
+        buff = ''
+      else:
+        raise
+    if len(buff) == 0:
+      raise TTransportException(type=TTransportException.END_OF_FILE,
+                                message='TSocket read 0 bytes')
+    return buff
+
+  def write(self, buff):
+    if not self.handle:
+      raise TTransportException(type=TTransportException.NOT_OPEN,
+                                message='Transport not open')
+    sent = 0
+    have = len(buff)
+    while sent < have:
+      plus = self.handle.send(buff)
+      if plus == 0:
+        raise TTransportException(type=TTransportException.END_OF_FILE,
+                                  message='TSocket sent 0 bytes')
+      sent += plus
+      buff = buff[plus:]
+
+  def flush(self):
+    pass
+
+
+class TServerSocket(TSocketBase, TServerTransportBase):
+  """Socket implementation of TServerTransport base."""
+
+  def __init__(self, host=None, port=9090, unix_socket=None):
+    self.host = host
+    self.port = port
+    self._unix_socket = unix_socket
+    self.handle = None
+
+  def listen(self):
+    res0 = self._resolveAddr()
+    for res in res0:
+      if res[0] is socket.AF_INET6 or res is res0[-1]:
+        break
+
+    # We need remove the old unix socket if the file exists and
+    # nobody is listening on it.
+    if self._unix_socket:
+      tmp = socket.socket(res[0], res[1])
+      try:
+        tmp.connect(res[4])
+      except socket.error, err:
+        eno, message = err.args
+        if eno == errno.ECONNREFUSED:
+          os.unlink(res[4])
+
+    self.handle = socket.socket(res[0], res[1])
+    self.handle.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+    if hasattr(self.handle, 'settimeout'):
+      self.handle.settimeout(None)
+    self.handle.bind(res[4])
+    self.handle.listen(128)
+
+  def accept(self):
+    client, addr = self.handle.accept()
+    result = TSocket()
+    result.setHandle(client)
+    return result

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py
new file mode 100644
index 0000000..ed023d5
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py
@@ -0,0 +1,330 @@
+#
+# 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.
+#
+
+from cStringIO import StringIO
+from struct import pack, unpack
+from ..Thrift import TException
+
+
+class TTransportException(TException):
+  """Custom Transport Exception class"""
+
+  UNKNOWN = 0
+  NOT_OPEN = 1
+  ALREADY_OPEN = 2
+  TIMED_OUT = 3
+  END_OF_FILE = 4
+
+  def __init__(self, type=UNKNOWN, message=None):
+    TException.__init__(self, message)
+    self.type = type
+
+
+class TTransportBase:
+  """Base class for Thrift transport layer."""
+
+  def isOpen(self):
+    pass
+
+  def open(self):
+    pass
+
+  def close(self):
+    pass
+
+  def read(self, sz):
+    pass
+
+  def readAll(self, sz):
+    buff = ''
+    have = 0
+    while (have < sz):
+      chunk = self.read(sz - have)
+      have += len(chunk)
+      buff += chunk
+
+      if len(chunk) == 0:
+        raise EOFError()
+
+    return buff
+
+  def write(self, buf):
+    pass
+
+  def flush(self):
+    pass
+
+
+# This class should be thought of as an interface.
+class CReadableTransport:
+  """base class for transports that are readable from C"""
+
+  # TODO(dreiss): Think about changing this interface to allow us to use
+  #               a (Python, not c) StringIO instead, because it allows
+  #               you to write after reading.
+
+  # NOTE: This is a classic class, so properties will NOT work
+  #       correctly for setting.
+  @property
+  def cstringio_buf(self):
+    """A cStringIO buffer that contains the current chunk we are reading."""
+    pass
+
+  def cstringio_refill(self, partialread, reqlen):
+    """Refills cstringio_buf.
+
+    Returns the currently used buffer (which can but need not be the same as
+    the old cstringio_buf). partialread is what the C code has read from the
+    buffer, and should be inserted into the buffer before any more reads.  The
+    return value must be a new, not borrowed reference.  Something along the
+    lines of self._buf should be fine.
+
+    If reqlen bytes can't be read, throw EOFError.
+    """
+    pass
+
+
+class TServerTransportBase:
+  """Base class for Thrift server transports."""
+
+  def listen(self):
+    pass
+
+  def accept(self):
+    pass
+
+  def close(self):
+    pass
+
+
+class TTransportFactoryBase:
+  """Base class for a Transport Factory"""
+
+  def getTransport(self, trans):
+    return trans
+
+
+class TBufferedTransportFactory:
+  """Factory transport that builds buffered transports"""
+
+  def getTransport(self, trans):
+    buffered = TBufferedTransport(trans)
+    return buffered
+
+
+class TBufferedTransport(TTransportBase, CReadableTransport):
+  """Class that wraps another transport and buffers its I/O.
+
+  The implementation uses a (configurable) fixed-size read buffer
+  but buffers all writes until a flush is performed.
+  """
+  DEFAULT_BUFFER = 4096
+
+  def __init__(self, trans, rbuf_size=DEFAULT_BUFFER):
+    self.__trans = trans
+    self.__wbuf = StringIO()
+    self.__rbuf = StringIO("")
+    self.__rbuf_size = rbuf_size
+
+  def isOpen(self):
+    return self.__trans.isOpen()
+
+  def open(self):
+    return self.__trans.open()
+
+  def close(self):
+    return self.__trans.close()
+
+  def read(self, sz):
+    ret = self.__rbuf.read(sz)
+    if len(ret) != 0:
+      return ret
+
+    self.__rbuf = StringIO(self.__trans.read(max(sz, self.__rbuf_size)))
+    return self.__rbuf.read(sz)
+
+  def write(self, buf):
+    self.__wbuf.write(buf)
+
+  def flush(self):
+    out = self.__wbuf.getvalue()
+    # reset wbuf before write/flush to preserve state on underlying failure
+    self.__wbuf = StringIO()
+    self.__trans.write(out)
+    self.__trans.flush()
+
+  # Implement the CReadableTransport interface.
+  @property
+  def cstringio_buf(self):
+    return self.__rbuf
+
+  def cstringio_refill(self, partialread, reqlen):
+    retstring = partialread
+    if reqlen < self.__rbuf_size:
+      # try to make a read of as much as we can.
+      retstring += self.__trans.read(self.__rbuf_size)
+
+    # but make sure we do read reqlen bytes.
+    if len(retstring) < reqlen:
+      retstring += self.__trans.readAll(reqlen - len(retstring))
+
+    self.__rbuf = StringIO(retstring)
+    return self.__rbuf
+
+
+class TMemoryBuffer(TTransportBase, CReadableTransport):
+  """Wraps a cStringIO object as a TTransport.
+
+  NOTE: Unlike the C++ version of this class, you cannot write to it
+        then immediately read from it.  If you want to read from a
+        TMemoryBuffer, you must either pass a string to the constructor.
+  TODO(dreiss): Make this work like the C++ version.
+  """
+
+  def __init__(self, value=None):
+    """value -- a value to read from for stringio
+
+    If value is set, this will be a transport for reading,
+    otherwise, it is for writing"""
+    if value is not None:
+      self._buffer = StringIO(value)
+    else:
+      self._buffer = StringIO()
+
+  def isOpen(self):
+    return not self._buffer.closed
+
+  def open(self):
+    pass
+
+  def close(self):
+    self._buffer.close()
+
+  def read(self, sz):
+    return self._buffer.read(sz)
+
+  def write(self, buf):
+    self._buffer.write(buf)
+
+  def flush(self):
+    pass
+
+  def getvalue(self):
+    return self._buffer.getvalue()
+
+  # Implement the CReadableTransport interface.
+  @property
+  def cstringio_buf(self):
+    return self._buffer
+
+  def cstringio_refill(self, partialread, reqlen):
+    # only one shot at reading...
+    raise EOFError()
+
+
+class TFramedTransportFactory:
+  """Factory transport that builds framed transports"""
+
+  def getTransport(self, trans):
+    framed = TFramedTransport(trans)
+    return framed
+
+
+class TFramedTransport(TTransportBase, CReadableTransport):
+  """Class that wraps another transport and frames its I/O when writing."""
+
+  def __init__(self, trans,):
+    self.__trans = trans
+    self.__rbuf = StringIO()
+    self.__wbuf = StringIO()
+
+  def isOpen(self):
+    return self.__trans.isOpen()
+
+  def open(self):
+    return self.__trans.open()
+
+  def close(self):
+    return self.__trans.close()
+
+  def read(self, sz):
+    ret = self.__rbuf.read(sz)
+    if len(ret) != 0:
+      return ret
+
+    self.readFrame()
+    return self.__rbuf.read(sz)
+
+  def readFrame(self):
+    buff = self.__trans.readAll(4)
+    sz, = unpack('!i', buff)
+    self.__rbuf = StringIO(self.__trans.readAll(sz))
+
+  def write(self, buf):
+    self.__wbuf.write(buf)
+
+  def flush(self):
+    wout = self.__wbuf.getvalue()
+    wsz = len(wout)
+    # reset wbuf before write/flush to preserve state on underlying failure
+    self.__wbuf = StringIO()
+    # N.B.: Doing this string concatenation is WAY cheaper than making
+    # two separate calls to the underlying socket object. Socket writes in
+    # Python turn out to be REALLY expensive, but it seems to do a pretty
+    # good job of managing string buffer operations without excessive copies
+    buf = pack("!i", wsz) + wout
+    self.__trans.write(buf)
+    self.__trans.flush()
+
+  # Implement the CReadableTransport interface.
+  @property
+  def cstringio_buf(self):
+    return self.__rbuf
+
+  def cstringio_refill(self, prefix, reqlen):
+    # self.__rbuf will already be empty here because fastbinary doesn't
+    # ask for a refill until the previous buffer is empty.  Therefore,
+    # we can start reading new frames immediately.
+    while len(prefix) < reqlen:
+      self.readFrame()
+      prefix += self.__rbuf.getvalue()
+    self.__rbuf = StringIO(prefix)
+    return self.__rbuf
+
+
+class TFileObjectTransport(TTransportBase):
+  """Wraps a file-like object to make it work as a Thrift transport."""
+
+  def __init__(self, fileobj):
+    self.fileobj = fileobj
+
+  def isOpen(self):
+    return True
+
+  def close(self):
+    self.fileobj.close()
+
+  def read(self, sz):
+    return self.fileobj.read(sz)
+
+  def write(self, buf):
+    self.fileobj.write(buf)
+
+  def flush(self):
+    self.fileobj.flush()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py
new file mode 100644
index 0000000..6cdb172
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py
@@ -0,0 +1,221 @@
+#
+# 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.
+#
+
+from cStringIO import StringIO
+
+from zope.interface import implements, Interface, Attribute
+from twisted.internet.protocol import Protocol, ServerFactory, ClientFactory, \
+    connectionDone
+from twisted.internet import defer
+from twisted.protocols import basic
+from twisted.python import log
+from twisted.web import server, resource, http
+
+import TTransport
+
+
+class TMessageSenderTransport(TTransport.TTransportBase):
+
+    def __init__(self):
+        self.__wbuf = StringIO()
+
+    def write(self, buf):
+        self.__wbuf.write(buf)
+
+    def flush(self):
+        msg = self.__wbuf.getvalue()
+        self.__wbuf = StringIO()
+        self.sendMessage(msg)
+
+    def sendMessage(self, message):
+        raise NotImplementedError
+
+
+class TCallbackTransport(TMessageSenderTransport):
+
+    def __init__(self, func):
+        TMessageSenderTransport.__init__(self)
+        self.func = func
+
+    def sendMessage(self, message):
+        self.func(message)
+
+
+class ThriftClientProtocol(basic.Int32StringReceiver):
+
+    MAX_LENGTH = 2 ** 31 - 1
+
+    def __init__(self, client_class, iprot_factory, oprot_factory=None):
+        self._client_class = client_class
+        self._iprot_factory = iprot_factory
+        if oprot_factory is None:
+            self._oprot_factory = iprot_factory
+        else:
+            self._oprot_factory = oprot_factory
+
+        self.recv_map = {}
+        self.started = defer.Deferred()
+
+    def dispatch(self, msg):
+        self.sendString(msg)
+
+    def connectionMade(self):
+        tmo = TCallbackTransport(self.dispatch)
+        self.client = self._client_class(tmo, self._oprot_factory)
+        self.started.callback(self.client)
+
+    def connectionLost(self, reason=connectionDone):
+        for k, v in self.client._reqs.iteritems():
+            tex = TTransport.TTransportException(
+                type=TTransport.TTransportException.END_OF_FILE,
+                message='Connection closed')
+            v.errback(tex)
+
+    def stringReceived(self, frame):
+        tr = TTransport.TMemoryBuffer(frame)
+        iprot = self._iprot_factory.getProtocol(tr)
+        (fname, mtype, rseqid) = iprot.readMessageBegin()
+
+        try:
+            method = self.recv_map[fname]
+        except KeyError:
+            method = getattr(self.client, 'recv_' + fname)
+            self.recv_map[fname] = method
+
+        method(iprot, mtype, rseqid)
+
+
+class ThriftServerProtocol(basic.Int32StringReceiver):
+
+    MAX_LENGTH = 2 ** 31 - 1
+
+    def dispatch(self, msg):
+        self.sendString(msg)
+
+    def processError(self, error):
+        self.transport.loseConnection()
+
+    def processOk(self, _, tmo):
+        msg = tmo.getvalue()
+
+        if len(msg) > 0:
+            self.dispatch(msg)
+
+    def stringReceived(self, frame):
+        tmi = TTransport.TMemoryBuffer(frame)
+        tmo = TTransport.TMemoryBuffer()
+
+        iprot = self.factory.iprot_factory.getProtocol(tmi)
+        oprot = self.factory.oprot_factory.getProtocol(tmo)
+
+        d = self.factory.processor.process(iprot, oprot)
+        d.addCallbacks(self.processOk, self.processError,
+            callbackArgs=(tmo,))
+
+
+class IThriftServerFactory(Interface):
+
+    processor = Attribute("Thrift processor")
+
+    iprot_factory = Attribute("Input protocol factory")
+
+    oprot_factory = Attribute("Output protocol factory")
+
+
+class IThriftClientFactory(Interface):
+
+    client_class = Attribute("Thrift client class")
+
+    iprot_factory = Attribute("Input protocol factory")
+
+    oprot_factory = Attribute("Output protocol factory")
+
+
+class ThriftServerFactory(ServerFactory):
+
+    implements(IThriftServerFactory)
+
+    protocol = ThriftServerProtocol
+
+    def __init__(self, processor, iprot_factory, oprot_factory=None):
+        self.processor = processor
+        self.iprot_factory = iprot_factory
+        if oprot_factory is None:
+            self.oprot_factory = iprot_factory
+        else:
+            self.oprot_factory = oprot_factory
+
+
+class ThriftClientFactory(ClientFactory):
+
+    implements(IThriftClientFactory)
+
+    protocol = ThriftClientProtocol
+
+    def __init__(self, client_class, iprot_factory, oprot_factory=None):
+        self.client_class = client_class
+        self.iprot_factory = iprot_factory
+        if oprot_factory is None:
+            self.oprot_factory = iprot_factory
+        else:
+            self.oprot_factory = oprot_factory
+
+    def buildProtocol(self, addr):
+        p = self.protocol(self.client_class, self.iprot_factory,
+            self.oprot_factory)
+        p.factory = self
+        return p
+
+
+class ThriftResource(resource.Resource):
+
+    allowedMethods = ('POST',)
+
+    def __init__(self, processor, inputProtocolFactory,
+        outputProtocolFactory=None):
+        resource.Resource.__init__(self)
+        self.inputProtocolFactory = inputProtocolFactory
+        if outputProtocolFactory is None:
+            self.outputProtocolFactory = inputProtocolFactory
+        else:
+            self.outputProtocolFactory = outputProtocolFactory
+        self.processor = processor
+
+    def getChild(self, path, request):
+        return self
+
+    def _cbProcess(self, _, request, tmo):
+        msg = tmo.getvalue()
+        request.setResponseCode(http.OK)
+        request.setHeader("content-type", "application/x-thrift")
+        request.write(msg)
+        request.finish()
+
+    def render_POST(self, request):
+        request.content.seek(0, 0)
+        data = request.content.read()
+        tmi = TTransport.TMemoryBuffer(data)
+        tmo = TTransport.TMemoryBuffer()
+
+        iprot = self.inputProtocolFactory.getProtocol(tmi)
+        oprot = self.outputProtocolFactory.getProtocol(tmo)
+
+        d = self.processor.process(iprot, oprot)
+        d.addCallback(self._cbProcess, request, tmo)
+        return server.NOT_DONE_YET

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
new file mode 100644
index 0000000..2bdfd14
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
@@ -0,0 +1,249 @@
+#
+# 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.
+#
+
+"""TZlibTransport provides a compressed transport and transport factory
+class, using the python standard library zlib module to implement
+data compression.
+"""
+
+from __future__ import division
+import zlib
+from cStringIO import StringIO
+
+from TTransport import TTransportBase, CReadableTransport
+
+
+class TZlibTransportFactory(object):
+  """Factory transport that builds zlib compressed transports.
+
+  This factory caches the last single client/transport that it was passed
+  and returns the same TZlibTransport object that was created.
+
+  This caching means the TServer class will get the _same_ transport
+  object for both input and output transports from this factory.
+  (For non-threaded scenarios only, since the cache only holds one object)
+
+  The purpose of this caching is to allocate only one TZlibTransport where
+  only one is really needed (since it must have separate read/write buffers),
+  and makes the statistics from getCompSavings() and getCompRatio()
+  easier to understand.
+  """
+  # class scoped cache of last transport given and zlibtransport returned
+  _last_trans = None
+  _last_z = None
+
+  def getTransport(self, trans, compresslevel=9):
+    """Wrap a transport, trans, with the TZlibTransport
+    compressed transport class, returning a new
+    transport to the caller.
+
+    @param compresslevel: The zlib compression level, ranging
+    from 0 (no compression) to 9 (best compression).  Defaults to 9.
+    @type compresslevel: int
+
+    This method returns a TZlibTransport which wraps the
+    passed C{trans} TTransport derived instance.
+    """
+    if trans == self._last_trans:
+      return self._last_z
+    ztrans = TZlibTransport(trans, compresslevel)
+    self._last_trans = trans
+    self._last_z = ztrans
+    return ztrans
+
+
+class TZlibTransport(TTransportBase, CReadableTransport):
+  """Class that wraps a transport with zlib, compressing writes
+  and decompresses reads, using the python standard
+  library zlib module.
+  """
+  # Read buffer size for the python fastbinary C extension,
+  # the TBinaryProtocolAccelerated class.
+  DEFAULT_BUFFSIZE = 4096
+
+  def __init__(self, trans, compresslevel=9):
+    """Create a new TZlibTransport, wrapping C{trans}, another
+    TTransport derived object.
+
+    @param trans: A thrift transport object, i.e. a TSocket() object.
+    @type trans: TTransport
+    @param compresslevel: The zlib compression level, ranging
+    from 0 (no compression) to 9 (best compression).  Default is 9.
+    @type compresslevel: int
+    """
+    self.__trans = trans
+    self.compresslevel = compresslevel
+    self.__rbuf = StringIO()
+    self.__wbuf = StringIO()
+    self._init_zlib()
+    self._init_stats()
+
+  def _reinit_buffers(self):
+    """Internal method to initialize/reset the internal StringIO objects
+    for read and write buffers.
+    """
+    self.__rbuf = StringIO()
+    self.__wbuf = StringIO()
+
+  def _init_stats(self):
+    """Internal method to reset the internal statistics counters
+    for compression ratios and bandwidth savings.
+    """
+    self.bytes_in = 0
+    self.bytes_out = 0
+    self.bytes_in_comp = 0
+    self.bytes_out_comp = 0
+
+  def _init_zlib(self):
+    """Internal method for setting up the zlib compression and
+    decompression objects.
+    """
+    self._zcomp_read = zlib.decompressobj()
+    self._zcomp_write = zlib.compressobj(self.compresslevel)
+
+  def getCompRatio(self):
+    """Get the current measured compression ratios (in,out) from
+    this transport.
+
+    Returns a tuple of:
+    (inbound_compression_ratio, outbound_compression_ratio)
+
+    The compression ratios are computed as:
+        compressed / uncompressed
+
+    E.g., data that compresses by 10x will have a ratio of: 0.10
+    and data that compresses to half of ts original size will
+    have a ratio of 0.5
+
+    None is returned if no bytes have yet been processed in
+    a particular direction.
+    """
+    r_percent, w_percent = (None, None)
+    if self.bytes_in > 0:
+      r_percent = self.bytes_in_comp / self.bytes_in
+    if self.bytes_out > 0:
+      w_percent = self.bytes_out_comp / self.bytes_out
+    return (r_percent, w_percent)
+
+  def getCompSavings(self):
+    """Get the current count of saved bytes due to data
+    compression.
+
+    Returns a tuple of:
+    (inbound_saved_bytes, outbound_saved_bytes)
+
+    Note: if compression is actually expanding your
+    data (only likely with very tiny thrift objects), then
+    the values returned will be negative.
+    """
+    r_saved = self.bytes_in - self.bytes_in_comp
+    w_saved = self.bytes_out - self.bytes_out_comp
+    return (r_saved, w_saved)
+
+  def isOpen(self):
+    """Return the underlying transport's open status"""
+    return self.__trans.isOpen()
+
+  def open(self):
+    """Open the underlying transport"""
+    self._init_stats()
+    return self.__trans.open()
+
+  def listen(self):
+    """Invoke the underlying transport's listen() method"""
+    self.__trans.listen()
+
+  def accept(self):
+    """Accept connections on the underlying transport"""
+    return self.__trans.accept()
+
+  def close(self):
+    """Close the underlying transport,"""
+    self._reinit_buffers()
+    self._init_zlib()
+    return self.__trans.close()
+
+  def read(self, sz):
+    """Read up to sz bytes from the decompressed bytes buffer, and
+    read from the underlying transport if the decompression
+    buffer is empty.
+    """
+    ret = self.__rbuf.read(sz)
+    if len(ret) > 0:
+      return ret
+    # keep reading from transport until something comes back
+    while True:
+      if self.readComp(sz):
+        break
+    ret = self.__rbuf.read(sz)
+    return ret
+
+  def readComp(self, sz):
+    """Read compressed data from the underlying transport, then
+    decompress it and append it to the internal StringIO read buffer
+    """
+    zbuf = self.__trans.read(sz)
+    zbuf = self._zcomp_read.unconsumed_tail + zbuf
+    buf = self._zcomp_read.decompress(zbuf)
+    self.bytes_in += len(zbuf)
+    self.bytes_in_comp += len(buf)
+    old = self.__rbuf.read()
+    self.__rbuf = StringIO(old + buf)
+    if len(old) + len(buf) == 0:
+      return False
+    return True
+
+  def write(self, buf):
+    """Write some bytes, putting them into the internal write
+    buffer for eventual compression.
+    """
+    self.__wbuf.write(buf)
+
+  def flush(self):
+    """Flush any queued up data in the write buffer and ensure the
+    compression buffer is flushed out to the underlying transport
+    """
+    wout = self.__wbuf.getvalue()
+    if len(wout) > 0:
+      zbuf = self._zcomp_write.compress(wout)
+      self.bytes_out += len(wout)
+      self.bytes_out_comp += len(zbuf)
+    else:
+      zbuf = ''
+    ztail = self._zcomp_write.flush(zlib.Z_SYNC_FLUSH)
+    self.bytes_out_comp += len(ztail)
+    if (len(zbuf) + len(ztail)) > 0:
+      self.__wbuf = StringIO()
+      self.__trans.write(zbuf + ztail)
+    self.__trans.flush()
+
+  @property
+  def cstringio_buf(self):
+    """Implement the CReadableTransport interface"""
+    return self.__rbuf
+
+  def cstringio_refill(self, partialread, reqlen):
+    """Implement the CReadableTransport interface for refill"""
+    retstring = partialread
+    if reqlen < self.DEFAULT_BUFFSIZE:
+      retstring += self.read(self.DEFAULT_BUFFSIZE)
+    while len(retstring) < reqlen:
+      retstring += self.read(reqlen - len(retstring))
+    self.__rbuf = StringIO(retstring)
+    return self.__rbuf

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py
new file mode 100644
index 0000000..c9596d9
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+__all__ = ['TTransport', 'TSocket', 'THttpClient', 'TZlibTransport']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/__init__.py
new file mode 100644
index 0000000..a595c84
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/__init__.py
@@ -0,0 +1,18 @@
+# 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.
+
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py
new file mode 100644
index 0000000..fc4bfc9
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py
@@ -0,0 +1,33 @@
+# 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.
+
+class DataPublisherException(Exception):
+    """
+    Exception to be used during log publishing operations
+    """
+
+    def __init__(self, msg):
+        super(self,  msg)
+        self.message = msg
+
+    def get_message(self):
+        """
+        The message provided when the exception is raised
+        :return: message
+        :rtype: str
+        """
+        return self.message

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/logpublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/logpublisher.py b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/logpublisher.py
new file mode 100644
index 0000000..050dd9e
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/datapublisher/logpublisher.py
@@ -0,0 +1,273 @@
+# 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.
+
+import os
+import datetime
+from threading import Thread, current_thread
+
+from ..databridge.agent import *
+from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
+from ..util import cartridgeagentutils, cartridgeagentconstants
+from exception.datapublisherexception import DataPublisherException
+
+
+class LogPublisher(Thread):
+
+    def __init__(self, file_path, stream_definition, tenant_id, alias, date_time, member_id):
+        Thread.__init__(self)
+
+        self.log = LogFactory().get_log(__name__)
+
+        self.file_path = file_path
+        self.thrift_publisher = ThriftPublisher(
+            DataPublisherConfiguration.get_instance().monitoring_server_ip,
+            DataPublisherConfiguration.get_instance().monitoring_server_port,
+            DataPublisherConfiguration.get_instance().admin_username,
+            DataPublisherConfiguration.get_instance().admin_password,
+            stream_definition)
+        self.tenant_id = tenant_id
+        self.alias = alias
+        self.datetime = date_time
+        self.member_id = member_id
+
+        self.terminated = False
+
+    def run(self):
+        if os.path.isfile(self.file_path) and os.access(self.file_path, os.R_OK):
+            self.log.info("Starting log publisher for file: " + self.file_path + ", thread: " + current_thread())
+            # open file and keep reading for new entries
+            read_file = open(self.file_path, "r")
+            read_file.seek(os.stat(self.file_path)[6])  # go to the end of the file
+
+            while not self.terminated:
+                where = read_file.tell()  # where the seeker is in the file
+                line = read_file.readline()   # read the current line
+                if not line:
+                    # no new line entered
+                    time.sleep(1)
+                    read_file.seek(where)  # set seeker
+                else:
+                    # new line detected, create event object
+                    event = ThriftEvent()
+                    event.metaData.append(self.member_id)
+                    event.payloadData.append(self.tenant_id)
+                    event.payloadData.append(self.alias)
+                    event.payloadData.append("")
+                    event.payloadData.append(self.datetime)
+                    event.payloadData.append("")
+                    event.payloadData.append(line)
+                    event.payloadData.append("")
+                    event.payloadData.append("")
+                    event.payloadData.append(self.member_id)
+                    event.payloadData.append("")
+
+                    self.thrift_publisher.publish(event)
+
+            self.thrift_publisher.disconnect()  # dicsonnect the publisher upon being terminated
+        else:
+            raise DataPublisherException("Unable to read the file at path %r" % self.file_path)
+
+    def terminate(self):
+        """
+        Allows the LogPublisher thread to be terminated to stop publishing to BAM/CEP. Allow a minimum of 1 second delay
+        to take effect.
+        """
+        self.terminated = True
+
+
+class LogPublisherManager(Thread):
+    """
+    A log publishing thread management thread which maintains a log publisher for each log file. Also defines a stream
+    definition and the BAM/CEP server information for a single publishing context.
+    """
+
+    @staticmethod
+    def define_stream():
+        """
+        Creates a stream definition for Log Publishing
+        :return: A StreamDefinition object with the required attributes added
+        :rtype : StreamDefinition
+        """
+        # stream definition
+        stream_definition = StreamDefinition()
+        valid_tenant_id = LogPublisherManager.get_valid_tenant_id(CartridgeAgentConfiguration().tenant_id)
+        alias = LogPublisherManager.get_alias(CartridgeAgentConfiguration().cluster_id)
+        stream_name = "logs." + valid_tenant_id + "." \
+                      + alias + "." + LogPublisherManager.get_current_date()
+        stream_version = "1.0.0"
+
+        stream_definition.name = stream_name
+        stream_definition.version = stream_version
+        stream_definition.description = "Apache Stratos Instance Log Publisher"
+        stream_definition.add_metadata_attribute("memberId", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("tenantID", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("serverName", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("appName", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("logTime", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("priority", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("message", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("logger", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("ip", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("instance", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("stacktrace", StreamDefinition.STRING)
+
+        return stream_definition
+
+    def __init__(self, logfile_paths):
+        Thread.__init__(self)
+        self.logfile_paths = logfile_paths
+        self.publishers = {}
+        self.ports = []
+        self.ports.append(DataPublisherConfiguration.get_instance().monitoring_server_port)
+        self.ports.append(DataPublisherConfiguration.get_instance().monitoring_server_secure_port)
+
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+        cartridgeagentutils.wait_until_ports_active(
+            DataPublisherConfiguration.get_instance().monitoring_server_ip,
+            self.ports,
+            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False)))
+
+        ports_active = cartridgeagentutils.check_ports_active(
+            DataPublisherConfiguration.get_instance().monitoring_server_ip,
+            self.ports)
+
+        if not ports_active:
+            raise DataPublisherException("Monitoring server not active, data publishing is aborted")
+
+        self.stream_definition = self.define_stream()
+
+    def run(self):
+        if self.logfile_paths is not None and len(self.logfile_paths):
+            for log_path in self.logfile_paths:
+                # thread for each log file
+                publisher = self.get_publisher(log_path)
+                publisher.start()
+
+    def get_publisher(self, log_path):
+        """
+        Retrieve the publisher for the specified log file path. Creates a new LogPublisher if one is not available
+        :return: The LogPublisher object
+        :rtype : LogPublisher
+        """
+        if log_path not in self.publishers:
+            self.publishers[log_path] = LogPublisher(log_path, self.stream_definition)
+
+        return self.publishers[log_path]
+
+    def terminate_publisher(self, log_path):
+        """
+        Terminates the LogPublisher thread associated with the specified log file
+        """
+        if log_path in self.publishers:
+            self.publishers[log_path].terminate()
+
+    def terminate_all_publishers(self):
+        """
+        Terminates all LogPublisher threads
+        """
+        for publisher in self.publishers:
+            publisher.terminate()
+
+    @staticmethod
+    def get_valid_tenant_id(tenant_id):
+        if tenant_id == cartridgeagentconstants.INVALID_TENANT_ID \
+                or tenant_id == cartridgeagentconstants.SUPER_TENANT_ID:
+            return "0"
+
+        return tenant_id
+
+    @staticmethod
+    def get_alias(cluster_id):
+        try:
+            alias = cluster_id.split("\\.")[0]
+        except:
+            alias = cluster_id
+
+        return alias
+
+    @staticmethod
+    def get_current_date():
+        """
+        Returns the current date formatted as yyyy-MM-dd
+        :return: Formatted date string
+        :rtype : str
+        """
+        return datetime.date.today().strftime(cartridgeagentconstants.DATE_FORMAT)
+
+
+class DataPublisherConfiguration:
+    """
+    A singleton implementation to access configuration information for data publishing to BAM/CEP
+    TODO: perfect singleton impl ex: Borg
+    """
+
+    __instance = None
+    log = LogFactory().get_log(__name__)
+
+    @staticmethod
+    def get_instance():
+        """
+        Singleton instance retriever
+        :return: Instance
+        :rtype : DataPublisherConfiguration
+        """
+        if DataPublisherConfiguration.__instance is None:
+            DataPublisherConfiguration.__instance = DataPublisherConfiguration()
+
+        return DataPublisherConfiguration.__instance
+
+    def __init__(self):
+        self.enabled = False
+        self.monitoring_server_ip = None
+        self.monitoring_server_port = None
+        self.monitoring_server_secure_port = None
+        self.admin_username = None
+        self.admin_password = None
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+        self.read_config()
+
+    def read_config(self):
+        self.enabled = True if self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_PUBLISHER_ENABLED, False).strip().lower() == "true" else False
+        if not self.enabled:
+            DataPublisherConfiguration.log.info("Data Publisher disabled")
+            return
+
+        DataPublisherConfiguration.log.info("Data Publisher enabled")
+
+        self.monitoring_server_ip = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_RECEIVER_IP, False)
+        if self.monitoring_server_ip is None or self.monitoring_server_ip.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_RECEIVER_IP)
+
+        self.monitoring_server_port = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_RECEIVER_PORT, False)
+        if self.monitoring_server_port is None or self.monitoring_server_port.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_RECEIVER_PORT)
+
+        self.monitoring_server_secure_port = self.cartridge_agent_config.read_property("monitoring.server.secure.port", False)
+        if self.monitoring_server_secure_port is None or self.monitoring_server_secure_port.strip() == "":
+            raise RuntimeError("System property not found: monitoring.server.secure.port")
+
+        self.admin_username = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_SERVER_ADMIN_USERNAME, False)
+        if self.admin_username is None or self.admin_username.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_SERVER_ADMIN_USERNAME)
+
+        self.admin_password = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_SERVER_ADMIN_PASSWORD, False)
+        if self.admin_password is None or self.admin_password.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_SERVER_ADMIN_PASSWORD)
+
+        DataPublisherConfiguration.log.info("Data Publisher configuration initialized")

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/event/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/__init__.py
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/events.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/events.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/events.py
new file mode 100644
index 0000000..024e1e4
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/notifier/events.py
@@ -0,0 +1,77 @@
+# 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.
+
+import json
+
+
+class ArtifactUpdatedEvent:
+    def __init__(self):
+        self.cluster_id = None
+        """ :type : str  """
+        self.status = None
+        """ :type : str  """
+        self.repo_username = None
+        """ :type : str  """
+        self.repo_password = None
+        """ :type : str  """
+        self.repo_url = None
+        """ :type : str  """
+        self.tenant_id = None
+        """ :type : int  """
+        self.commit_enabled = None
+        """ :type : bool  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = ArtifactUpdatedEvent()
+
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.status = json_obj["status"] if "status" in json_obj else None
+        instance.repo_username = json_obj["repoUserName"] if "repoUserName" in json_obj else None
+        instance.repo_password = json_obj["repoPassword"] if "repoPassword" in json_obj else None
+        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
+        instance.repo_url = json_obj["repoUrl"] if "repoUrl" in json_obj else ""
+        instance.commit_enabled = json_obj["commitEnabled"] if "commitEnabled" in json_obj else None
+
+        return instance
+
+
+class InstanceCleanupClusterEvent:
+    def __init__(self, cluster_id):
+        self.cluster_id = cluster_id
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        c_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+
+        return InstanceCleanupClusterEvent(c_id)
+
+
+class InstanceCleanupMemberEvent:
+    def __init__(self, member_id):
+        self.member_id = member_id
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        m_id = json_obj["memberId"] if "memberId" in json_obj else None
+
+        return InstanceCleanupMemberEvent(m_id)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/event/instance/status/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+


[26/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py b/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py
new file mode 100644
index 0000000..4ceb948
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/healthstatspublisher/healthstats.py
@@ -0,0 +1,246 @@
+# 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.
+
+from threading import Thread
+import time
+import psutil
+import os
+
+from abstracthealthstatisticspublisher import *
+from ..databridge.agent import *
+from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
+from ..util import cartridgeagentutils, cartridgeagentconstants
+
+
+class HealthStatisticsPublisherManager(Thread):
+    """
+    Read from an implementation of AbstractHealthStatisticsPublisher the value for memory usage and
+    load average and publishes them as ThriftEvents to a CEP server
+    """
+    STREAM_NAME = "cartridge_agent_health_stats"
+    STREAM_VERSION = "1.0.0"
+    STREAM_NICKNAME = "agent health stats"
+    STREAM_DESCRIPTION = "agent health stats"
+
+    def __init__(self, publish_interval):
+        """
+        Initializes a new HealthStatistsPublisherManager with a given number of seconds as the interval
+        :param int publish_interval: Number of seconds as the interval
+        :return: void
+        """
+        Thread.__init__(self)
+
+        self.log = LogFactory().get_log(__name__)
+
+        self.publish_interval = publish_interval
+        """:type : int"""
+
+        self.terminated = False
+
+        self.publisher = HealthStatisticsPublisher()
+        """:type : HealthStatisticsPublisher"""
+        # TODO: load plugins for the reader
+        self.stats_reader = DefaultHealthStatisticsReader()
+        """:type : AbstractHealthStatisticsReader"""
+
+    def run(self):
+        while not self.terminated:
+            time.sleep(self.publish_interval)
+
+            cartridge_stats = self.stats_reader.stat_cartridge_health()
+            self.log.debug("Publishing memory consumption: %r" % cartridge_stats.memory_usage)
+            self.publisher.publish_memory_usage(cartridge_stats.memory_usage)
+
+            self.log.debug("Publishing load average: %r" % cartridge_stats.load_avg)
+            self.publisher.publish_load_average(cartridge_stats.load_avg)
+
+        self.publisher.publisher.disconnect()
+
+
+class HealthStatisticsPublisher:
+    """
+    Publishes memory usage and load average to thrift server
+    """
+    log = LogFactory().get_log(__name__)
+
+    def __init__(self):
+
+        self.ports = []
+        self.ports.append(CEPPublisherConfiguration.get_instance().server_port)
+
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+        cartridgeagentutils.wait_until_ports_active(
+            CEPPublisherConfiguration.get_instance().server_ip,
+            self.ports,
+            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False)))
+        cep_active = cartridgeagentutils.check_ports_active(CEPPublisherConfiguration.get_instance().server_ip, self.ports)
+        if not cep_active:
+            raise CEPPublisherException("CEP server not active. Health statistics publishing aborted.")
+
+        self.stream_definition = HealthStatisticsPublisher.create_stream_definition()
+        HealthStatisticsPublisher.log.debug("Stream definition created: %r" % str(self.stream_definition))
+        self.publisher = ThriftPublisher(
+            CEPPublisherConfiguration.get_instance().server_ip,
+            CEPPublisherConfiguration.get_instance().server_port,
+            CEPPublisherConfiguration.get_instance().admin_username,
+            CEPPublisherConfiguration.get_instance().admin_password,
+            self.stream_definition)
+
+        HealthStatisticsPublisher.log.debug("HealthStatisticsPublisher initialized")
+
+    @staticmethod
+    def create_stream_definition():
+        """
+        Create a StreamDefinition for publishing to CEP
+        """
+        stream_def = StreamDefinition()
+        stream_def.name = HealthStatisticsPublisherManager.STREAM_NAME
+        stream_def.version = HealthStatisticsPublisherManager.STREAM_VERSION
+        stream_def.nickname = HealthStatisticsPublisherManager.STREAM_NICKNAME
+        stream_def.description = HealthStatisticsPublisherManager.STREAM_DESCRIPTION
+
+        stream_def.add_payloaddata_attribute("cluster_id", StreamDefinition.STRING)
+        stream_def.add_payloaddata_attribute("network_partition_id", StreamDefinition.STRING)
+        stream_def.add_payloaddata_attribute("member_id", StreamDefinition.STRING)
+        stream_def.add_payloaddata_attribute("partition_id", StreamDefinition.STRING)
+        stream_def.add_payloaddata_attribute("health_description", StreamDefinition.STRING)
+        stream_def.add_payloaddata_attribute("value", StreamDefinition.DOUBLE)
+
+        return stream_def
+
+    def publish_memory_usage(self, memory_usage):
+        """
+        Publishes the given memory usage value to the thrift server as a ThriftEvent
+        :param float memory_usage: memory usage
+        """
+
+        event = ThriftEvent()
+        event.payloadData.append(self.cartridge_agent_config.cluster_id)
+        event.payloadData.append(self.cartridge_agent_config.network_partition_id)
+        event.payloadData.append(self.cartridge_agent_config.member_id)
+        event.payloadData.append(self.cartridge_agent_config.partition_id)
+        event.payloadData.append(cartridgeagentconstants.MEMORY_CONSUMPTION)
+        event.payloadData.append(memory_usage)
+
+        HealthStatisticsPublisher.log.debug("Publishing cep event: [stream] %r [version] %r" % (self.stream_definition.name, self.stream_definition.version))
+        self.publisher.publish(event)
+
+    def publish_load_average(self, load_avg):
+        """
+        Publishes the given load average value to the thrift server as a ThriftEvent
+        :param float load_avg: load average value
+        """
+
+        event = ThriftEvent()
+        event.payloadData.append(self.cartridge_agent_config.cluster_id)
+        event.payloadData.append(self.cartridge_agent_config.network_partition_id)
+        event.payloadData.append(self.cartridge_agent_config.member_id)
+        event.payloadData.append(self.cartridge_agent_config.partition_id)
+        event.payloadData.append(cartridgeagentconstants.LOAD_AVERAGE)
+        event.payloadData.append(load_avg)
+
+        HealthStatisticsPublisher.log.debug("Publishing cep event: [stream] %r [version] %r" % (self.stream_definition.name, self.stream_definition.version))
+        self.publisher.publish(event)
+
+
+class DefaultHealthStatisticsReader(AbstractHealthStatisticsReader):
+    """
+    Default implementation of the AbstractHealthStatisticsReader
+    """
+
+    def __init__(self):
+        self.log = LogFactory().get_log(__name__)
+
+    def stat_cartridge_health(self):
+        cartridge_stats = CartridgeHealthStatistics()
+        cartridge_stats.memory_usage = DefaultHealthStatisticsReader.__read_mem_usage()
+        cartridge_stats.load_avg = DefaultHealthStatisticsReader.__read_load_avg()
+
+        self.log.debug("Memory read: %r, CPU read: %r" % (cartridge_stats.memory_usage, cartridge_stats.load_avg))
+        return cartridge_stats
+
+    @staticmethod
+    def __read_mem_usage():
+        return psutil.virtual_memory().percent
+
+    @staticmethod
+    def __read_load_avg():
+        (one, five, fifteen) = os.getloadavg()
+        return one
+
+
+class CEPPublisherConfiguration:
+    """
+    TODO: Extract common functionality
+    """
+
+    __instance = None
+    log = LogFactory().get_log(__name__)
+
+    @staticmethod
+    def get_instance():
+        """
+        Singleton instance retriever
+        :return: Instance
+        :rtype : CEPPublisherConfiguration
+        """
+        if CEPPublisherConfiguration.__instance is None:
+            CEPPublisherConfiguration.__instance = CEPPublisherConfiguration()
+
+        return CEPPublisherConfiguration.__instance
+
+    def __init__(self):
+        self.enabled = False
+        self.server_ip = None
+        self.server_port = None
+        self.admin_username = None
+        self.admin_password = None
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+        self.read_config()
+
+    def read_config(self):
+        self.enabled = True if self.cartridge_agent_config.read_property(
+           cartridgeagentconstants.CEP_PUBLISHER_ENABLED, False).strip().lower() == "true" else False
+        if not self.enabled:
+            CEPPublisherConfiguration.log.info("CEP Publisher disabled")
+            return
+
+        CEPPublisherConfiguration.log.info("CEP Publisher enabled")
+
+        self.server_ip = self.cartridge_agent_config.read_property(
+            cartridgeagentconstants.CEP_RECEIVER_IP, False)
+        if self.server_ip is None or self.server_ip.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_RECEIVER_IP)
+
+        self.server_port = self.cartridge_agent_config.read_property(
+            cartridgeagentconstants.CEP_RECEIVER_PORT, False)
+        if self.server_port is None or self.server_port.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_RECEIVER_PORT)
+
+        self.admin_username = self.cartridge_agent_config.read_property(
+            cartridgeagentconstants.CEP_SERVER_ADMIN_USERNAME, False)
+        if self.admin_username is None or self.admin_username.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_SERVER_ADMIN_USERNAME)
+
+        self.admin_password = self.cartridge_agent_config.read_property(
+            cartridgeagentconstants.CEP_SERVER_ADMIN_PASSWORD, False)
+        if self.admin_password is None or self.admin_password.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_SERVER_ADMIN_PASSWORD)
+
+        CEPPublisherConfiguration.log.info("CEP Publisher configuration initialized")

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/publisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/publisher/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/publisher/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/publisher/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py b/tools/python_cartridgeagent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py
new file mode 100644
index 0000000..1ce8ffb
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py
@@ -0,0 +1,165 @@
+# 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.
+
+import logging
+
+import paho.mqtt.publish as publish
+
+from .. event.instance.status.events import *
+from .. config.cartridgeagentconfiguration import CartridgeAgentConfiguration
+from .. util import cartridgeagentconstants
+from .. healthstatspublisher.healthstats import *
+from .. healthstatspublisher.abstracthealthstatisticspublisher import *
+
+
+log = LogFactory().get_log(__name__)
+
+started = False
+activated = False
+ready_to_shutdown = False
+maintenance = False
+
+publishers = {}
+""" :type : dict[str, EventPublisher] """
+
+
+def publish_instance_started_event():
+    global started, log
+    if not started:
+        log.info("Publishing instance started event")
+        service_name = CartridgeAgentConfiguration().service_name
+        cluster_id = CartridgeAgentConfiguration().cluster_id
+        network_partition_id = CartridgeAgentConfiguration().network_partition_id
+        parition_id = CartridgeAgentConfiguration().partition_id
+        member_id = CartridgeAgentConfiguration().member_id
+
+        instance_started_event = InstanceStartedEvent(service_name, cluster_id, network_partition_id, parition_id,
+                                                      member_id)
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_STARTED_EVENT)
+        publisher.publish(instance_started_event)
+        started = True
+        log.info("Instance started event published")
+    else:
+        log.warn("Instance already started")
+
+
+def publish_instance_activated_event():
+    global activated, log
+    if not activated:
+        log.info("Publishing instance activated event")
+        service_name = CartridgeAgentConfiguration().service_name
+        cluster_id = CartridgeAgentConfiguration().cluster_id
+        network_partition_id = CartridgeAgentConfiguration().network_partition_id
+        parition_id = CartridgeAgentConfiguration().partition_id
+        member_id = CartridgeAgentConfiguration().member_id
+
+        instance_activated_event = InstanceActivatedEvent(service_name, cluster_id, network_partition_id, parition_id,
+                                                          member_id)
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_ACTIVATED_EVENT)
+        publisher.publish(instance_activated_event)
+
+        log.info("Instance activated event published")
+        log.info("Starting health statistics notifier")
+
+        if CEPPublisherConfiguration.get_instance().enabled:
+            interval_default = 15  # seconds
+            interval = CartridgeAgentConfiguration().read_property("stats.notifier.interval", False)
+            if interval is not None and len(interval) > 0:
+                try:
+                    interval = int(interval)
+                except ValueError:
+                    interval = interval_default
+            else:
+                interval = interval_default
+
+            health_stats_publisher = HealthStatisticsPublisherManager(interval)
+            log.info("Starting Health statistics publisher with interval %r" % interval_default)
+            health_stats_publisher.start()
+        else:
+            log.warn("Statistics publisher is disabled")
+
+        activated = True
+        log.info("Health statistics notifier started")
+    else:
+        log.warn("Instance already activated")
+
+
+def publish_maintenance_mode_event():
+    global maintenance, log
+    if not maintenance:
+        log.info("Publishing instance maintenance mode event")
+
+        service_name = CartridgeAgentConfiguration().service_name
+        cluster_id = CartridgeAgentConfiguration().cluster_id
+        network_partition_id = CartridgeAgentConfiguration().network_partition_id
+        parition_id = CartridgeAgentConfiguration().partition_id
+        member_id = CartridgeAgentConfiguration().member_id
+
+        instance_maintenance_mode_event = InstanceMaintenanceModeEvent(service_name, cluster_id, network_partition_id, parition_id,
+                                                          member_id)
+
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_MAINTENANCE_MODE_EVENT)
+        publisher.publish(instance_maintenance_mode_event)
+
+        maintenance = True
+        log.info("Instance Maintenance mode event published")
+    else:
+        log.warn("Instance already in a Maintenance mode....")
+
+
+def publish_instance_ready_to_shutdown_event():
+    global ready_to_shutdown, log
+    if not ready_to_shutdown:
+        log.info("Publishing instance activated event")
+
+        service_name = CartridgeAgentConfiguration().service_name
+        cluster_id = CartridgeAgentConfiguration().cluster_id
+        network_partition_id = CartridgeAgentConfiguration().network_partition_id
+        parition_id = CartridgeAgentConfiguration().partition_id
+        member_id = CartridgeAgentConfiguration().member_id
+
+        instance_shutdown_event = InstanceReadyToShutdownEvent(service_name, cluster_id, network_partition_id, parition_id,
+                                                          member_id)
+
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_READY_TO_SHUTDOWN_EVENT)
+        publisher.publish(instance_shutdown_event)
+
+        ready_to_shutdown = True
+        log.info("Instance ReadyToShutDown event published")
+    else:
+        log.warn("Instance already in a ReadyToShutDown event....")
+
+
+def get_publisher(topic):
+    if topic not in publishers:
+        publishers[topic] = EventPublisher(topic)
+
+    return publishers[topic]
+
+
+class EventPublisher:
+    """
+    Handles publishing events to topics to the provided message broker
+    """
+    def __init__(self, topic):
+        self.__topic = topic
+
+    def publish(self, event):
+        mb_ip = CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_IP)
+        mb_port = CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_PORT)
+        payload = event.to_json()
+        publish.single(self.__topic, payload, hostname=mb_ip, port=mb_port)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/subscriber/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/subscriber/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/subscriber/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/subscriber/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/subscriber/eventsubscriber.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/subscriber/eventsubscriber.py b/tools/python_cartridgeagent/cartridgeagent/modules/subscriber/eventsubscriber.py
new file mode 100644
index 0000000..bc026dd
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/subscriber/eventsubscriber.py
@@ -0,0 +1,96 @@
+# 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.
+
+import threading
+import paho.mqtt.client as mqtt
+
+
+class EventSubscriber(threading.Thread):
+    """
+    Provides functionality to subscribe to a given topic on the stratos MB and
+    register event handlers for various events.
+    """
+
+    def __init__(self, topic, ip, port):
+        threading.Thread.__init__(self)
+
+        #{"ArtifactUpdateEvent" : onArtifactUpdateEvent()}
+        self.__event_handlers = {}
+
+        self.log = LogFactory().get_log(__name__)
+
+        self.__mb_client = None
+
+        self.__topic = topic
+
+        self.__subscribed = False
+
+        self.__ip = ip
+        self.__port = port
+
+    def run(self):
+        self.__mb_client = mqtt.Client()
+        self.__mb_client.on_connect = self.on_connect
+        self.__mb_client.on_message = self.on_message
+
+        self.log.debug("Connecting to the message broker with address %r:%r" % (self.__ip, self.__port))
+        self.__mb_client.connect(self.__ip, self.__port, 60)
+        self.__subscribed = True
+        self.__mb_client.loop_forever()
+
+    def register_handler(self, event, handler):
+        """
+        Adds an event handler function mapped to the provided event.
+        :param str event: Name of the event to attach the provided handler
+        :param handler: The handler function
+        :return: void
+        :rtype: void
+        """
+        self.__event_handlers[event] = handler
+        self.log.debug("Registered handler for event %r" % event)
+
+    def on_connect(self, client, userdata, flags, rc):
+        self.log.debug("Connected to message broker.")
+        self.__mb_client.subscribe(self.__topic)
+        self.log.debug("Subscribed to %r" % self.__topic)
+
+    def on_message(self, client, userdata, msg):
+        self.log.debug("Message received: %r:\n%r" % (msg.topic, msg.payload))
+
+        event = msg.topic.rpartition('/')[2]
+
+        if event in self.__event_handlers:
+            handler = self.__event_handlers[event]
+
+            try:
+                self.log.debug("Executing handler for event %r" % event)
+                handler(msg)
+            except:
+                self.log.exception("Error processing %r event" % event)
+        else:
+            self.log.debug("Event handler not found for event : %r" % event)
+
+    def is_subscribed(self):
+        """
+        Checks if this event subscriber is successfully subscribed to the provided topic
+        :return: True if subscribed, False if otherwise
+        :rtype: bool
+        """
+        return self.__subscribed
+
+
+from .. util.log import LogFactory
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/tenant/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/tenant/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/tenant/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/tenant/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/tenant/tenantcontext.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/tenant/tenantcontext.py b/tools/python_cartridgeagent/cartridgeagent/modules/tenant/tenantcontext.py
new file mode 100644
index 0000000..202bd35
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/tenant/tenantcontext.py
@@ -0,0 +1,184 @@
+# 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.
+
+class Tenant:
+    """
+    Object type representing the tenant details of a single tenant
+    """
+
+    def __init__(self, tenant_id,  tenant_domain):
+        self.tenant_id = tenant_id
+        """ :type : int """
+        self.tenant_domain = tenant_domain
+        """ :type : str """
+        self.service_name_subscription_map = {}
+        """ :type : dict[str, Subscription] """
+
+    def get_subscription(self, service_name):
+        """
+        Returns the Subscription object related to the provided service name
+        :param str service_name: service name to be retrieved
+        :return: Subscription of the service or None if the service name doesn't exist
+        :rtype: Subscription
+        """
+        if service_name in self.service_name_subscription_map:
+            return self.service_name_subscription_map[service_name]
+
+        return None
+
+    def is_subscribed(self, service_name):
+        """
+        Checks if the given service name has a subscription from this tenant
+        :param str service_name: name of the service to check
+        :return: True if the tenant is subscribed to the given service name, False if not
+        :rtype: bool
+        """
+        return service_name in self.service_name_subscription_map
+
+    def add_subscription(self, subscription):
+        """
+        Adds a subscription information entry on the subscription list for this tenant
+        :param Subscription subscription: Subscription information to be added
+        :return: void
+        :rtype: void
+        """
+        self.service_name_subscription_map[subscription.service_name] = subscription
+
+    def remove_subscription(self, service_name):
+        """
+        Removes the specified subscription details from the subscription list
+        :param str service_name: The service name of the subscription to be removed
+        :return: void
+        :rtype: void
+        """
+        if service_name in self.service_name_subscription_map:
+            self.service_name_subscription_map.pop(service_name)
+
+
+class Subscription:
+    """
+    Subscription information of a particular subscription to a service
+    """
+
+    def __init__(self, service_name, cluster_ids):
+        self.service_name = service_name
+        """ :type : str """
+        self.cluster_ids = cluster_ids
+        """ :type : list[str]  """
+        self.subscription_domain_map = {}
+        """ :type : dict[str, SubscriptionDomain]  """
+
+    def add_subscription_domain(self, domain_name, application_context):
+        """
+        Adds a subscription domain
+        :param str domain_name:
+        :param str application_context:
+        :return: void
+        :rtype: void
+        """
+        self.subscription_domain_map[domain_name] = SubscriptionDomain(domain_name, application_context)
+
+    def remove_subscription_domain(self, domain_name):
+        """
+        Removes the subscription domain of the specified domain name
+        :param str domain_name:
+        :return: void
+        :rtype: void
+        """
+        if domain_name in self.subscription_domain_map:
+            self.subscription_domain_map.pop(domain_name)
+
+    def subscription_domain_exists(self, domain_name):
+        """
+        Returns the SubscriptionDomain information of the specified domain name
+        :param str domain_name:
+        :return: SubscriptionDomain
+        :rtype: SubscriptionDomain
+        """
+        return domain_name in self.subscription_domain_map
+
+    def get_subscription_domains(self):
+        """
+        Returns the list of subscription domains of this subscription
+        :return: List of SubscriptionDomain objects
+        :rtype: list[SubscriptionDomain]
+        """
+        return self.subscription_domain_map.values()
+
+
+class SubscriptionDomain:
+    """
+    Represents a Subscription Domain
+    """
+
+    def __init__(self, domain_name, application_context):
+        self.domain_name = domain_name
+        """ :type : str  """
+        self.application_context = application_context
+        """ :type : str  """
+
+
+class TenantContext:
+    """
+    Handles and maintains a model of all the information related to tenants within this instance
+    """
+    tenants = {}
+    initialized = False
+    tenant_domains = {"carbon.super": Tenant(-1234, "carbon.super")}
+
+    @staticmethod
+    def add_tenant(tenant):
+        TenantContext.tenants[tenant.tenant_id] = tenant
+        TenantContext.tenant_domains[tenant.tenant_domain] = tenant
+
+    @staticmethod
+    def remove_tenant(tenant_id):
+        if tenant_id in TenantContext.tenants:
+            tenant = TenantContext.get_tenant(tenant_id)
+            TenantContext.tenants.pop(tenant.tenant_id)
+            TenantContext.tenant_domains.pop(tenant.tenant_domain)
+
+    @staticmethod
+    def update(tenants):
+        for tenant in tenants:
+            TenantContext.add_tenant(tenant)
+
+    @staticmethod
+    def get_tenant(tenant_id):
+        """
+        Gets the Tenant object of the provided tenant ID
+        :param int tenant_id:
+        :return: Tenant object of the provided tenant ID
+        :rtype: Tenant
+        """
+        if tenant_id in TenantContext.tenants:
+            return TenantContext.tenants[tenant_id]
+
+        return None
+
+    @staticmethod
+    def get_tenant_by_domain(tenant_domain):
+        """
+        Gets the Tenant object of the provided tenant domain
+        :param str tenant_domain:
+        :return: Tenant object of the provided tenant domain
+        :rtype: str
+        """
+        if tenant_domain in TenantContext.tenant_domains:
+            return TenantContext.tenant_domains[tenant_domain]
+
+        return None
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/topology/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/topology/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/topology/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/topology/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/topology/topologycontext.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/topology/topologycontext.py b/tools/python_cartridgeagent/cartridgeagent/modules/topology/topologycontext.py
new file mode 100644
index 0000000..5fe2ea4
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/topology/topologycontext.py
@@ -0,0 +1,454 @@
+# 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.
+
+from ..util import cartridgeagentconstants
+
+
+class Topology:
+    """
+    Represents the topology provided by the Cloud Controller
+    """
+
+    def __init__(self):
+        self.service_map = {}
+        """ :type : dict[str, Service]  """
+        self.initialized = False
+        """ :type : bool  """
+        self.json_str = None
+        """ :type : str  """
+
+    def get_services(self):
+        """
+        Provides the list of services on the topology
+        :return: The list of Service objects
+        :rtype: list[Service]
+        """
+        return self.service_map.values()
+
+    def get_service(self, service_name):
+        """
+        Provides the service information for the given service name
+        :param str service_name: service name to be retrieved
+        :return: Service object of the service, None if the provided service name is invalid
+        :rtype: Service
+        """
+        if service_name in self.service_map:
+            return self.service_map[service_name]
+
+        return None
+
+    def add_service(self, service):
+        """
+        Adds a service to the list of services on the topology
+
+        :param Service service:
+        :return: void
+        """
+        self.service_map[service.service_name] = service
+
+    def add_services(self, services):
+        """
+
+        :param list[Service] services:
+        :return: void
+        """
+        for service in services:
+            self.add_service(service)
+
+    def remove_service(self, service_name):
+        """
+        Removes the service of the provided service name
+        :param str service_name:
+        :return: void
+        """
+        if service_name in self.service_map:
+            self.service_map.pop(service_name)
+
+    def service_exists(self, service_name):
+        """
+        Checks if the service of the provided service name exists
+        :param str service_name:
+        :return: True if the service exists, False if otherwise
+        :rtype: bool
+        """
+        return service_name in self.service_map
+
+    def clear(self):
+        """
+        Clears the service information list
+        :return: void
+        """
+        self.service_map = {}
+
+    def __str__(self):
+        """
+        to string override
+        :return:
+        """
+        return "Topology [serviceMap= %r , initialized= %r ]" % (self.service_map, self.initialized)
+
+
+class Service:
+    """
+    Represents a service on the topology
+    """
+
+    def __init__(self, service_name, service_type):
+        self.service_name = service_name
+        """ :type : str  """
+        self.service_type = service_type
+        """ :type : str  """
+        self.cluster_id_cluster_map = {}
+        """ :type : dict[str, Cluster]  """
+        self.port_map = {}
+        """ :type : dict[str, Port]  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+
+    def get_clusters(self):
+        """
+        Provides the list of clusters in the particular service
+        :return: The list of Cluster objects
+        :rtype: list[Cluster]
+        """
+        return self.cluster_id_cluster_map.values()
+
+    def add_cluster(self, cluster):
+        """
+        Adds a cluster to the service
+        :param Cluster cluster: the cluster to be added
+        :return: void
+        """
+        self.cluster_id_cluster_map[cluster.cluster_id] = cluster
+
+    def remove_cluster(self, cluster_id):
+        if cluster_id in self.cluster_id_cluster_map:
+            self.cluster_id_cluster_map.pop(cluster_id)
+
+    def cluster_exists(self, cluster_id):
+        """
+        Checks if the cluster with the given cluster id exists for ther service
+        :param str cluster_id:
+        :return: True if the cluster for the given cluster id exists, False if otherwise
+        :rtype: bool
+        """
+        return cluster_id in self.cluster_id_cluster_map
+
+    def get_cluster(self, cluster_id):
+        """
+        Provides the Cluster information for the provided cluster id
+        :param str cluster_id: the cluster id to search for
+        :return: Cluster object for the given cluster id, None if the cluster id is invalid
+        :rtype: Cluster
+        """
+        if cluster_id in self.cluster_id_cluster_map:
+            return self.cluster_id_cluster_map[cluster_id]
+
+        return None
+
+    def get_ports(self):
+        """
+        Returns the list of ports in the particular service
+        :return: The list of Port object
+        :rtype: list[Port]
+        """
+        return self.port_map.values()
+
+    def get_port(self, proxy_port):
+        """
+        Provides the port information for the provided proxy port
+        :param str proxy_port:
+        :return: Port object for the provided port, None if port is invalid
+        :rtype: Port
+        """
+        if proxy_port in self.port_map:
+            return self.port_map[proxy_port]
+
+        return None
+
+    def add_port(self, port):
+        self.port_map[port.proxy] = port
+
+    def add_ports(self, ports):
+        for port in ports:
+            self.add_port(port)
+
+
+class Cluster:
+    """
+    Represents a cluster for a service
+    """
+
+    def __init__(self, service_name="", cluster_id="", deployment_policy_name="", autoscale_policy_name=""):
+        self.service_name = service_name
+        """ :type : str  """
+        self.cluster_id = cluster_id
+        """ :type : str  """
+        self.deployment_policy_name = deployment_policy_name
+        """ :type : str  """
+        self.autoscale_policy_name = autoscale_policy_name
+        """ :type : str  """
+        self.hostnames = []
+        """ :type : list[str]  """
+        self.member_map = {}
+        """ :type : dict[str, Member]  """
+
+        self.tenant_range = None
+        """ :type : str  """
+        self.is_lb_cluster = False
+        """ :type : bool  """
+        self.is_kubernetes_cluster = False
+        """ :type : bool  """
+        self.status = None
+        """ :type : str  """
+        self.load_balancer_algorithm_name = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+        self.member_list_json = None
+        """ :type : str  """
+
+    def add_hostname(self, hostname):
+        self.hostnames.append(hostname)
+
+    def set_tenant_range(self, tenant_range):
+        self.validate_tenant_range(tenant_range)
+        self.tenant_range = tenant_range
+
+    def get_members(self):
+        """
+        Provides the list of member information in the cluster
+        :return: The list of Member object
+        :rtype: list[Member]
+        """
+        return self.member_map.values()
+
+    def add_member(self, member):
+        self.member_map[member.member_id] = member
+
+    def remove_member(self, member_id):
+        if self.member_exists(member_id):
+            self.member_map.pop(member_id)
+
+    def get_member(self, member_id):
+        """
+        Provides the member information for the provided member id
+        :param str member_id:
+        :return: Member object for the provided member id, None if member id is invalid
+        :rtype: Member
+        """
+        if self.member_exists(member_id):
+            return self.member_map[member_id]
+
+        return None
+
+    def member_exists(self, member_id):
+        """
+        Checks if the member for the provided member id exists in this cluster
+        :param str member_id: member id to be searched
+        :return: True if the member exists, False if otherwise
+        :rtype: bool
+        """
+        return member_id in self.member_map
+
+    def __str__(self):
+        return "Cluster [serviceName=" + self.service_name + ", clusterId=" + self.cluster_id \
+               + ", autoscalePolicyName=" + self.autoscale_policy_name + ", deploymentPolicyName=" \
+               + self.deployment_policy_name + ", hostNames=" + self.hostnames + ", tenantRange=" + self.tenant_range \
+               + ", isLbCluster=" + self.is_lb_cluster + ", properties=" + self.properties + "]"
+
+    def tenant_id_in_range(self, tenant_id):
+        """
+        Check whether a given tenant id is in tenant range of the cluster.
+        :param str tenant_id: tenant id to be checked
+        :return: True if the tenant id is in tenant id range, False if otherwise
+        :rtype: bool
+        """
+        if self.tenant_range is None:
+            return False
+
+        if self.tenant_range == "*":
+            return True
+        else:
+            arr = self.tenant_range.split(cartridgeagentconstants.TENANT_RANGE_DELIMITER)
+            tenant_start = int(arr[0])
+            if tenant_start <= tenant_id:
+                tenant_end = arr[1]
+                if tenant_end == "*":
+                    return True
+                else:
+                    if tenant_id <= int(tenant_end):
+                        return True
+
+        return False
+
+    def validate_tenant_range(self, tenant_range):
+        """
+        Validates the tenant range to be either '*' or a delimeted range of numbers
+        :param str tenant_range: The tenant range string to be validated
+        :return: void if the provided tenant range is valid, RuntimeError if otherwise
+        :exception: RuntimeError if the tenant range is invalid
+        """
+        valid = False
+        if tenant_range == "*":
+            valid = True
+        else:
+            arr = tenant_range.split(cartridgeagentconstants.TENANT_RANGE_DELIMITER)
+            if len(arr) == 2:
+                if arr[0].isdigit() and arr[1].isdigit():
+                    valid = True
+                elif arr[0].isdigit() and arr[1] == "*":
+                    valid = True
+
+        if not valid:
+            raise RuntimeError("Tenant range %r is not valid" % tenant_range)
+
+
+class Member:
+    """
+    Represents a member on a particular cluster
+    """
+
+    def __init__(self, service_name="", cluster_id="", network_partition_id="", parition_id="", member_id=""):
+        self.service_name = service_name
+        """ :type : str  """
+        self.cluster_id = cluster_id
+        """ :type : str  """
+        self.network_partition_id = network_partition_id
+        """ :type : str  """
+        self.partition_id = parition_id
+        """ :type : str  """
+        self.member_id = member_id
+        """ :type : str  """
+        self.port_map = {}
+        """ :type : dict[str, Port]  """
+
+        self.member_public_ip = None
+        """ :type : str  """
+        self.status = None
+        """ :type : str  """
+        self.member_ip = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+        self.lb_cluster_id = None
+        """ :type : str  """
+        self.json_str = None
+        """ :type : str  """
+
+    def is_active(self):
+        """
+        Checks if the member is in active state
+        :return: True if active, False if otherwise
+        :rtype: bool
+        """
+        return self.status == MemberStatus.Activated
+
+    def get_ports(self):
+        """
+        Provides the list of the ports in the member
+        :return: List of Port objects
+        :rtype: list[Port]
+        """
+        return self.port_map.values()
+
+    def get_port(self, proxy):
+        """
+        Provides the port information for the given port id
+        :param str proxy: The port id
+        :return: Port object of the provided port id, None if otherwise
+        :rtype: Port
+        """
+        if proxy in self.port_map:
+            return self.port_map[proxy]
+
+        return None
+
+    def add_port(self, port):
+        self.port_map[port.proxy] = port
+
+    def add_ports(self, ports):
+        for port in ports:
+            self.add_port(port)
+
+
+class Port:
+    """
+    Represents a port on a particular member
+    """
+
+    def __init__(self, protocol, value, proxy):
+        self.protocol = protocol
+        """ :type : str  """
+        self.value = value
+        """ :type : str  """
+        self.proxy = proxy
+        """ :type : str  """
+
+    def __str__(self):
+        return "Port [protocol=%r, value=%r proxy=%r]" % (self.protocol, self.value, self.proxy)
+
+
+class ServiceType:
+    """
+    ServiceType enum
+    """
+    SingleTenant = 1
+    MultiTenant = 2
+
+
+class ClusterStatus:
+    """
+    ClusterStatus enum
+    """
+    Created = 1
+    In_Maintenance = 2
+    Removed = 3
+
+
+class MemberStatus:
+    """
+    MemberStatus enum
+    """
+    Created = 1
+    Starting = 2
+    Activated = 3
+    In_Maintenance = 4
+    ReadyToShutDown = 5
+    Terminated = 6
+    Suspended = 0
+    ShuttingDown = 0
+
+
+class TopologyContext:
+    """
+    Handles and maintains a model of the topology provided by the Cloud Controller
+    """
+    topology = None
+    # TODO: read write locks, Lock() and RLock()
+
+    @staticmethod
+    def get_topology():
+        #TODO: thread-safety missing
+        if TopologyContext.topology is None:
+            TopologyContext.topology = Topology()
+        return TopologyContext.topology
+
+    @staticmethod
+    def update(topology):
+        TopologyContext.topology = topology
+        TopologyContext.topology.initialized = True
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/util/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/util/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/util/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/util/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/util/asyncscheduledtask.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/util/asyncscheduledtask.py b/tools/python_cartridgeagent/cartridgeagent/modules/util/asyncscheduledtask.py
new file mode 100644
index 0000000..4ff0416
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/util/asyncscheduledtask.py
@@ -0,0 +1,71 @@
+# 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.
+
+import time
+from threading import Thread
+
+class AbstractAsyncScheduledTask:
+    """
+    Exposes the contract to follow to implement a scheduled task to be executed by the ScheduledExecutor
+    """
+
+    def execute_task(self):
+        """
+        Override this method and implement the task to be executed by the ScheduledExecutor with a specified
+        interval.
+        """
+        raise NotImplementedError
+
+
+class ScheduledExecutor(Thread):
+    """
+    Executes a given task with a given interval until being terminated
+    """
+
+    def __init__(self, delay, task):
+        """
+        Creates a ScheduledExecutor thread to handle interval based repeated execution of a given task of type
+        AbstractAsyncScheduledTask
+        :param int delay: The interval to keep between executions
+        :param AbstractAsyncScheduledTask task: The task to be implemented
+        :return:
+        """
+
+        Thread.__init__(self)
+        self.delay = delay
+        """ :type : int  """
+        self.task = task
+        """ :type : AbstractAsyncScheduledTask  """
+        self.terminated = False
+        """ :type : bool  """
+
+    def run(self):
+        """
+        Start the scheduled task with a sleep time of delay in between
+        :return:
+        """
+        while not self.terminated:
+            time.sleep(self.delay)
+            task_thread = Thread(target=self.task.execute_task)
+            task_thread.start()
+
+    def terminate(self):
+        """
+        Terminate the scheduled task. Allow a maximum of 'delay' seconds to be terminated.
+        :return: void
+        """
+        self.terminated = True
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentconstants.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentconstants.py b/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentconstants.py
new file mode 100644
index 0000000..70afb30
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentconstants.py
@@ -0,0 +1,135 @@
+# 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.
+
+PARAM_FILE_PATH = "param.file.path"
+EXTENSIONS_DIR = "extensions.dir"
+
+MB_IP = "mb.ip"
+MB_PORT = "mb.port"
+
+CARTRIDGE_KEY = "CARTRIDGE_KEY"
+APP_PATH = "APP_PATH"
+SERVICE_GROUP = "SERIVCE_GROUP"
+SERVICE_NAME = "SERVICE_NAME"
+CLUSTER_ID = "CLUSTER_ID"
+LB_CLUSTER_ID = "LB_CLUSTER_ID"
+NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID"
+PARTITION_ID = "PARTITION_ID"
+MEMBER_ID = "MEMBER_ID"
+TENANT_ID = "TENANT_ID"
+REPO_URL = "REPO_URL"
+PORTS = "PORTS"
+DEPLOYMENT = "DEPLOYMENT"
+MANAGER_SERVICE_TYPE = "MANAGER_SERVICE_TYPE"
+WORKER_SERVICE_TYPE = "WORKER_SERVICE_TYPE"
+PERSISTENCE_MAPPING = "PERSISTENCE_MAPPING"
+
+# stratos.sh environment variables keys
+LOG_FILE_PATHS = "LOG_FILE_PATHS"
+MEMORY_CONSUMPTION = "memory_consumption"
+LOAD_AVERAGE = "load_average"
+PORTS_NOT_OPEN = "ports_not_open"
+MULTITENANT = "MULTITENANT"
+CLUSTERING = "CLUSTERING"
+MIN_INSTANCE_COUNT = "MIN_COUNT"
+ENABLE_ARTIFACT_UPDATE = "enable.artifact.update"
+ARTIFACT_UPDATE_INTERVAL = "artifact.update.interval"
+COMMIT_ENABLED = "COMMIT_ENABLED"
+AUTO_COMMIT = "auto.commit"
+AUTO_CHECKOUT = "auto.checkout"
+LISTEN_ADDRESS = "listen.address"
+PROVIDER = "PROVIDER"
+INTERNAL = "internal"
+LB_PRIVATE_IP = "lb.private.ip"
+LB_PUBLIC_IP = "lb.public.ip"
+
+# stratos.sh extension points shell scripts names keys
+INSTANCE_STARTED_SCRIPT = "extension.instance.started"
+START_SERVERS_SCRIPT = "extension.start.servers"
+INSTANCE_ACTIVATED_SCRIPT = "extension.instance.activated"
+ARTIFACTS_UPDATED_SCRIPT = "extension.artifacts.updated"
+CLEAN_UP_SCRIPT = "extension.clean"
+MOUNT_VOLUMES_SCRIPT = "extension.mount.volumes"
+MEMBER_ACTIVATED_SCRIPT = "extension.member.activated"
+MEMBER_TERMINATED_SCRIPT = "extension.member.terminated"
+MEMBER_SUSPENDED_SCRIPT = "extension.member.suspended"
+MEMBER_STARTED_SCRIPT = "extension.member.started"
+COMPLETE_TOPOLOGY_SCRIPT = "extension.complete.topology"
+COMPLETE_TENANT_SCRIPT = "extension.complete.tenant"
+SUBSCRIPTION_DOMAIN_ADDED_SCRIPT = "extension.subscription.domain.added"
+SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT = "extension.subscription.domain.removed"
+ARTIFACTS_COPY_SCRIPT = "extension.artifacts.copy"
+TENANT_SUBSCRIBED_SCRIPT = "extension.tenant.subscribed"
+TENANT_UNSUBSCRIBED_SCRIPT = "extension.tenant.unsubscribed"
+
+SERVICE_GROUP_TOPOLOGY_KEY = "payload_parameter.SERIVCE_GROUP"
+CLUSTERING_TOPOLOGY_KEY = "payload_parameter.CLUSTERING"
+CLUSTERING_PRIMARY_KEY = "PRIMARY"
+
+SUPERTENANT_TEMP_PATH = "/tmp/-1234/"
+
+DEPLOYMENT_MANAGER = "manager"
+DEPLOYMENT_WORKER = "worker"
+DEPLOYMENT_DEFAULT = "default"
+SUPER_TENANT_REPO_PATH = "super.tenant.repository.path"
+TENANT_REPO_PATH = "tenant.repository.path"
+
+# topic names to subscribe
+INSTANCE_NOTIFIER_TOPIC = "instance/#"
+HEALTH_STAT_TOPIC = "health/#"
+TOPOLOGY_TOPIC = "topology/#"
+TENANT_TOPIC = "tenant/#"
+INSTANCE_STATUS_TOPIC = "instance/status/"
+
+#Messaging Model
+TENANT_RANGE_DELIMITER = "-"
+
+INSTANCE_STARTED_EVENT = "InstanceStartedEvent"
+INSTANCE_ACTIVATED_EVENT = "InstanceActivatedEvent"
+INSTANCE_MAINTENANCE_MODE_EVENT = "InstanceMaintenanceModeEvent"
+INSTANCE_READY_TO_SHUTDOWN_EVENT = "InstanceReadyToShutdownEvent"
+
+PUBLISHER_SERVICE_NAME = "publisher"
+APISTORE_SERVICE_NAME = "apistore"
+APIMANAGER_SERVICE_NAME = "apim"
+GATEWAY_SERVICE_NAME = "gatewaymgt"
+GATEWAY_MGT_SERVICE_NAME = "gateway"
+KEY_MANAGER_SERVICE_NAME = "keymanager"
+
+PRIMARY = "PRIMARY"
+MIN_COUNT = "MIN_COUNT"
+
+#multi tenant constants
+INVALID_TENANT_ID = "-1"
+SUPER_TENANT_ID = "-1234"
+
+DATE_FORMAT = "%Y.%m.%d"
+
+PORT_CHECK_TIMEOUT = "port.check.timeout"
+
+CEP_PUBLISHER_ENABLED = "cep.stats.publisher.enabled"
+CEP_RECEIVER_IP = "thrift.receiver.ip"
+CEP_RECEIVER_PORT = "thrift.receiver.port"
+CEP_SERVER_ADMIN_USERNAME = "thrift.server.admin.username"
+CEP_SERVER_ADMIN_PASSWORD = "thrift.server.admin.password"
+
+MONITORING_PUBLISHER_ENABLED = "enable.data.publisher"
+MONITORING_RECEIVER_IP = "monitoring.server.ip"
+MONITORING_RECEIVER_PORT = "monitoring.server.port"
+MONITORING_RECEIVER_SECURE_PORT = "monitoring.server.secure.port"
+MONITORING_SERVER_ADMIN_USERNAME = "monitoring.server.admin.username"
+MONITORING_SERVER_ADMIN_PASSWORD = "monitoring.server.admin.password"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentutils.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentutils.py b/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentutils.py
new file mode 100644
index 0000000..6ae89b1
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/util/cartridgeagentutils.py
@@ -0,0 +1,168 @@
+# 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.
+
+from Crypto.Cipher import AES
+import base64
+import os
+import time
+import socket
+import shutil
+
+#from log import LogFactory
+
+unpad = lambda s: s[0:-ord(s[-1])]
+
+#log = LogFactory().get_log(__name__)
+
+current_milli_time = lambda: int(round(time.time() * 1000))
+
+
+def decrypt_password(pass_str, secret):
+    """
+    Decrypts the given password using the given secret. The encryption is assumed to be done
+    without IV, in AES.
+    :param str pass_str: Encrypted password string in Base64 encoding
+    :param str secret: The secret string
+    :return: The decrypted password
+    :rtype: str
+    """
+
+    if pass_str is None or pass_str.strip() == "":
+        return pass_str.strip()
+
+    dec_pass = ""
+
+    try:
+        #log.debug("Decrypting password")
+        bdecoded_pass = base64.b64decode(pass_str)
+        #secret length should be 16
+        cipher = AES.new(secret, AES.MODE_ECB)
+        dec_pass = unpad(cipher.decrypt(bdecoded_pass))
+    except:
+        pass
+        #log.exception("Exception occurred while decrypting password")
+
+    #log.debug("Decrypted PWD: [%r]" % dec_pass)
+    return dec_pass
+
+
+def create_dir(path):
+    """
+    mkdir the provided path
+    :param path: The path to the directory to be made
+    :return: True if mkdir was successful, False if dir already exists
+    :rtype: bool
+    """
+    try:
+        os.mkdir(path)
+        #log.info("Successfully created directory [%r]" % path)
+        return True
+    except OSError:
+        pass
+        #log.exception("Directory creating failed in [%r]. Directory already exists. " % path)
+
+    return False
+
+
+def delete_folder_tree(path):
+    """
+    Completely deletes the provided folder
+    :param str path: Full path of the folder
+    :return: void
+    """
+    try:
+        shutil.rmtree(path)
+        #log.debug("Directory [%r] deleted." % path)
+    except OSError:
+        pass
+        #log.exception("Deletion of folder path %r failed." % path)
+
+
+def wait_until_ports_active(ip_address, ports, ports_check_timeout=600000):
+    """
+    Blocks until the given list of ports become active
+    :param str ip_address: Ip address of the member to be checked
+    :param list[str] ports: List of ports to be checked
+    :param int ports_check_timeout: The timeout in milliseconds, defaults to 1000*60*10
+    :return: void
+    """
+    if ports_check_timeout is None:
+        ports_check_timeout = 1000 * 60 * 10
+
+    #log.debug("Port check timeout: %r" % ports_check_timeout)
+
+    active = False
+    start_time = current_milli_time()
+    while not active:
+        #log.info("Waiting for ports to be active: [ip] %r [ports] %r" % (ip_address, ports))
+        active = check_ports_active(ip_address, ports)
+        end_time = current_milli_time()
+        duration = end_time - start_time
+
+        if duration > ports_check_timeout:
+            return
+
+        time.sleep(5)
+
+    #log.info("Ports activated: [ip] %r [ports] %r" % (ip_address, ports))
+
+
+def check_ports_active(ip_address, ports):
+    """
+    Checks the given list of port addresses for active state
+    :param str ip_address: Ip address of the member to be checked
+    :param list[str] ports: The list of ports to be checked
+    :return: True if the ports are active, False if at least one is not active
+    :rtype: bool
+    """
+    if len(ports) < 1:
+        raise RuntimeError("No ports found")
+
+    for port in ports:
+        s = socket.socket()
+        s.settimeout(5)
+        try:
+            s.connect((ip_address, int(port)))
+            #log.debug("Port %r is active" % port)
+            s.close()
+        except socket.error:
+            #log.debug("Print %r is not active" % port)
+            return False
+
+    return True
+
+
+def get_carbon_server_property(property_key):
+    """
+    Reads the carbon.xml file and returns the value for the property key.
+    TODO: Get carbon server xml location
+    :param str property_key: Property key to look for
+    :return: The value of the property, None if the property key is invalid or not present
+    :rtype : str
+    """
+
+    raise NotImplementedError
+
+
+def get_working_dir():
+    """
+    Returns the base directory of the cartridge agent.
+    :return: Base working dir path
+    :rtype : str
+    """
+    #"/path/to/cartridge-agent/modules/util/".split("modules") returns ["/path/to/cartridge-agent/", "/util"]
+    return os.path.abspath(os.path.dirname(__file__)).split("modules")[0]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/util/extensionutils.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/util/extensionutils.py b/tools/python_cartridgeagent/cartridgeagent/modules/util/extensionutils.py
new file mode 100644
index 0000000..6c58852
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/util/extensionutils.py
@@ -0,0 +1,494 @@
+# 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.
+
+import logging
+import os
+import subprocess
+import time
+
+from log import LogFactory
+from .. config import cartridgeagentconfiguration
+
+
+log = LogFactory().get_log(__name__)
+
+cartridge_agent_config = cartridgeagentconfiguration.CartridgeAgentConfiguration()
+
+
+def execute_copy_artifact_extension(source, destination):
+    try:
+        log.debug("Executing artifacts copy extension")
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.ARTIFACTS_COPY_SCRIPT, False)
+        command = prepare_command(script_name)
+
+        output, errors = execute_command(command + " " + source + " " + destination)
+        log.debug("Artifacts copy script returned: %r" % output)
+    except:
+        log.exception("Could not execute artifacts copy extension")
+
+
+def execute_instance_started_extension(env_params):
+    try:
+        log.debug("Executing instance started extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.INSTANCE_STARTED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Instance started script returned: %r" % output)
+    except:
+        log.exception("Could not execute instance started extension")
+
+
+def execute_instance_activated_extension():
+    try:
+        log.debug("Executing instance activated extension")
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.INSTANCE_ACTIVATED_SCRIPT, False)
+        command = prepare_command(script_name)
+
+        output, errors = execute_command(command)
+        log.debug("Instance activated script returned: %r" % output)
+    except:
+        log.exception("Could not execute instance activated extension")
+
+
+def execute_artifacts_updated_extension(env_params):
+    try:
+        log.debug("Executing artifacts updated extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.ARTIFACTS_UPDATED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Artifacts updated script returned: %r" % output)
+    except:
+        log.exception("Could not execute artifacts updated extension")
+
+
+def execute_subscription_domain_added_extension(env_params):
+    try:
+        log.debug("Executing subscription domain added extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.SUBSCRIPTION_DOMAIN_ADDED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Subscription domain added script returned: %r" % output)
+    except:
+        log.exception("Could not execute subscription domain added extension")
+
+
+def execute_subscription_domain_removed_extension(env_params):
+    try:
+        log.debug("Executing subscription domain removed extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Subscription domain removed script returned: %r" % output)
+    except:
+        log.exception("Could not execute subscription domain removed extension")
+
+
+def execute_start_servers_extension(env_params):
+    try:
+        log.debug("Executing start servers extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.START_SERVERS_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Start servers script returned: %r" % output)
+    except:
+        log.exception("Could not execute start servers extension")
+
+
+def execute_complete_topology_extension(env_params):
+    try:
+        log.debug("Executing complete topology extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.COMPLETE_TOPOLOGY_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Complete topology script returned: %r" % output)
+    except:
+        log.exception("Could not execute complete topology extension")
+
+
+def execute_complete_tenant_extension(env_params):
+    try:
+        log.debug("Executing complete tenant extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.COMPLETE_TENANT_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Complete tenant script returned: %r" % output)
+    except:
+        log.exception("Could not execute complete tenant extension")
+
+
+def execute_tenant_subscribed_extension(env_params):
+    try:
+        log.debug("Executing tenant subscribed extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.TENANT_SUBSCRIBED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Tenant subscribed script returned: %r" % output)
+    except:
+        log.exception("Could not execute tenant subscribed extension")
+
+
+def execute_tenant_unsubscribed_extension(env_params):
+    try:
+        log.debug("Executing tenant unsubscribed extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.TENANT_UNSUBSCRIBED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Tenant unsubscribed script returned: %r" % output)
+    except:
+        log.exception("Could not execute tenant unsubscribed extension")
+
+
+def execute_member_terminated_extension(env_params):
+    try:
+        log.debug("Executing member terminated extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.MEMBER_TERMINATED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Member terminated script returned: %r" % output)
+    except:
+        log.exception("Could not execute member terminated extension")
+
+
+def execute_member_suspended_extension(env_params):
+    try:
+        log.debug("Executing member suspended extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.MEMBER_SUSPENDED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Member suspended script returned: %r" % output)
+    except:
+        log.exception("Could not execute member suspended extension")
+
+
+def execute_member_started_extension(env_params):
+    try:
+        log.debug("Executing member started extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.MEMBER_STARTED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Member started script returned: %r" % output)
+    except:
+        log.exception("Could not execute member started extension")
+
+
+def wait_for_complete_topology():
+    while not TopologyContext.topology.initialized:
+        log.info("Waiting for complete topology event...")
+        time.sleep(5)
+
+
+def check_topology_consistency(service_name, cluster_id, member_id):
+    topology = TopologyContext.get_topology()
+    service = topology.get_service(service_name)
+    if service is None:
+        log.error("Service not found in topology [service] %r" % service_name)
+        return False
+
+    cluster = service.get_cluster(cluster_id)
+    if cluster is None:
+        log.error("Cluster id not found in topology [cluster] %r" % cluster_id)
+        return False
+
+    activated_member = cluster.get_member(member_id)
+    if activated_member is None:
+        log.error("Member id not found in topology [member] %r" % member_id)
+        return False
+
+    return True
+
+
+def is_relevant_member_event(service_name, cluster_id, lb_cluster_id):
+    cluster_id_in_payload = cartridge_agent_config.cluster_id
+    if cluster_id_in_payload is None:
+        return False
+
+    topology = TopologyContext.get_topology()
+    if topology is None or not topology.initialized:
+        return False
+
+    if cluster_id_in_payload == cluster_id:
+        return True
+
+    if cluster_id_in_payload == lb_cluster_id:
+        return True
+
+    service_group_in_payload = cartridge_agent_config.service_group
+    if service_group_in_payload is not None:
+        service_properties = topology.get_service(service_name).properties
+        if service_properties is None:
+            return False
+
+        member_service_group = service_properties[cartridgeagentconstants.SERVICE_GROUP_TOPOLOGY_KEY]
+        if member_service_group is not None and member_service_group == service_group_in_payload:
+            if service_name == cartridge_agent_config.service_name:
+                log.debug("Service names are same")
+                return True
+            elif cartridgeagentconstants.APISTORE_SERVICE_NAME == \
+                    cartridge_agent_config.service_name \
+                    and service_name == cartridgeagentconstants.PUBLISHER_SERVICE_NAME:
+                log.debug("Service name in payload is [store]. Serivce name in event is [%r] " % service_name)
+                return True
+            elif cartridgeagentconstants.PUBLISHER_SERVICE_NAME == \
+                    cartridge_agent_config.service_name \
+                    and service_name == cartridgeagentconstants.APISTORE_SERVICE_NAME:
+                log.debug("Service name in payload is [publisher]. Serivce name in event is [%r] " % service_name)
+                return True
+            elif cartridgeagentconstants.DEPLOYMENT_WORKER == \
+                    cartridge_agent_config.deployment \
+                    and service_name == cartridge_agent_config.manager_service_name:
+                log.debug("Deployment is worker. Worker's manager service name & service name in event are same")
+                return True
+            elif cartridgeagentconstants.DEPLOYMENT_MANAGER == \
+                    cartridge_agent_config.deployment  \
+                    and service_name == cartridge_agent_config.worker_service_name:
+                log.debug("Deployment is manager. Manager's worker service name & service name in event are same")
+                return True
+
+    return False
+
+
+def execute_volume_mount_extension(persistance_mappings_payload):
+    try:
+        log.debug("Executing volume mounting extension: [payload] %r" % persistance_mappings_payload)
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.MOUNT_VOLUMES_SCRIPT, False)
+        command = prepare_command(script_name)
+
+        output, errors = execute_command(command + " " + persistance_mappings_payload)
+        log.debug("Volume mount script returned: %r" % output)
+    except:
+        log.exception("Could not execute Volume mount extension")
+
+
+def execute_cleanup_extension():
+    try:
+        log.debug("Executing cleanup extension")
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.CLEAN_UP_SCRIPT, False)
+        command = prepare_command(script_name)
+
+        output, errors = execute_command(command)
+        log.debug("Cleanup script returned: %r" % output)
+    except:
+        log.exception("Could not execute Cleanup extension")
+
+
+def execute_member_activated_extension(env_params):
+    try:
+        log.debug("Executing member activated extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.MEMBER_ACTIVATED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Member activated script returned: %r" % output)
+    except:
+        log.exception("Could not execute member activated extension")
+
+
+def prepare_command(script_name):
+    extensions_dir = cartridge_agent_config.read_property(
+        cartridgeagentconstants.EXTENSIONS_DIR, False)
+    if extensions_dir.strip() == "":
+        raise RuntimeError("System property not found: %r" % cartridgeagentconstants.EXTENSIONS_DIR)
+
+    file_path = extensions_dir + script_name if str(extensions_dir).endswith("/") \
+        else extensions_dir + "/" + script_name
+
+    if os.path.isfile(file_path):
+        return file_path
+
+    raise IOError("Script file not found : %r" % file_path)
+
+
+def clean_process_parameters(params):
+    """
+    Removes any null valued parameters before passing them to the extension scripts
+    :param dict params:
+    :return: cleaned parameters
+    :rtype: dict
+    """
+    for key, value in params.items():
+        if value is None:
+            del params[key]
+
+    return params
+
+
+def add_payload_parameters(env_params):
+    """
+    Adds the common parameters to be used by the extension scripts
+    :param dict[str, str] env_params: Dictionary to be added
+    :return: Dictionary with updated parameters
+    :rtype: dict[str, str]
+    """
+    env_params["STRATOS_APP_PATH"] = cartridge_agent_config.app_path
+    env_params["STRATOS_PARAM_FILE_PATH"] = cartridge_agent_config.read_property(
+        cartridgeagentconstants.PARAM_FILE_PATH, False)
+    env_params["STRATOS_SERVICE_NAME"] = cartridge_agent_config.service_name
+    env_params["STRATOS_TENANT_ID"] = cartridge_agent_config.tenant_id
+    env_params["STRATOS_CARTRIDGE_KEY"] = cartridge_agent_config.cartridge_key
+    env_params["STRATOS_LB_CLUSTER_ID"] = cartridge_agent_config.lb_cluster_id
+    env_params["STRATOS_CLUSTER_ID"] = cartridge_agent_config.cluster_id
+    env_params["STRATOS_NETWORK_PARTITION_ID"] = \
+        cartridge_agent_config.network_partition_id
+    env_params["STRATOS_PARTITION_ID"] = cartridge_agent_config.partition_id
+    env_params["STRATOS_PERSISTENCE_MAPPINGS"] = \
+        cartridge_agent_config.persistence_mappings
+    env_params["STRATOS_REPO_URL"] = cartridge_agent_config.repo_url
+
+    lb_cluster_id_in_payload = cartridge_agent_config.lb_cluster_id
+    member_ips = get_lb_member_ip(lb_cluster_id_in_payload)
+    if member_ips is not None:
+        env_params["STRATOS_LB_IP"] = member_ips[0]
+        env_params["STRATOS_LB_PUBLIC_IP"] = member_ips[1]
+    else:
+        env_params["STRATOS_LB_IP"] = cartridge_agent_config.lb_private_ip
+        env_params["STRATOS_LB_PUBLIC_IP"] = cartridge_agent_config.lb_public_ip
+
+    topology = TopologyContext.get_topology()
+    if topology.initialized:
+        service = topology.get_service(cartridge_agent_config.service_name)
+        cluster = service.get_cluster(cartridge_agent_config.cluster_id)
+        member_id_in_payload = cartridge_agent_config.member_id
+        add_properties(service.properties, env_params, "SERVICE_PROPERTY")
+        add_properties(cluster.properties, env_params, "CLUSTER_PROPERTY")
+        add_properties(cluster.get_member(member_id_in_payload).properties, env_params, "MEMBER_PROPERTY")
+
+    return env_params
+
+
+def add_properties(properties, params, prefix):
+    """
+    Adds the given property list to the parameters list with given prefix in the parameter name
+    :param dict[str, str] properties: service properties
+    :param dict[str, str] params:
+    :param str prefix:
+    :return: dict[str, str]
+    """
+    if properties is None or properties.items() is None:
+        return
+
+    for key in properties:
+        params["STRATOS_" + prefix + "_" + key] = str(properties[key])
+        log.debug("Property added: [key] STRATOS_ " + prefix + "_" + key + "[value] " + properties[key])
+
+
+def get_lb_member_ip(lb_cluster_id):
+    topology = TopologyContext.get_topology()
+    services = topology.get_services()
+
+    for service in services:
+        clusters = service.get_clusters()
+        for cluster in clusters:
+            members = cluster.get_members()
+            for member in members:
+                if member.cluster_id == lb_cluster_id:
+                    return [member.member_ip, member.member_public_ip]
+
+    return None
+
+
+def execute_command(command, env_params=None):
+    """
+    Executes the given command string with given environment parameters
+    :param str command: Command with arguments to be executed
+    :param dict[str, str] env_params: Environment variables to be used
+    :return: output and error string tuple, RuntimeError if errors occur
+    :rtype: tuple
+    :exception: RuntimeError
+    """
+    os_env = os.environ.copy()
+    if env_params is not None:
+        os_env.update(env_params)
+
+    p = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os_env)
+    output, errors = p.communicate()
+    log.debug("output = %r" % output)
+    log.debug("error = %r" % errors)
+    if len(errors) > 0:
+        raise RuntimeError("Command execution failed: \n %r" % errors)
+
+    return output, errors
+
+
+from .. topology.topologycontext import *
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/util/log.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/util/log.py b/tools/python_cartridgeagent/cartridgeagent/modules/util/log.py
new file mode 100644
index 0000000..9bad214
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/util/log.py
@@ -0,0 +1,55 @@
+# 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.
+
+import logging
+import logging.config
+import os
+
+
+class LogFactory(object):
+    """
+    Singleton implementation for handling logging in CartridgeAgent
+    """
+    class __LogFactory:
+        def __init__(self):
+            self.logs = {}
+            logging_conf = os.path.abspath(os.path.dirname(__file__)).split("modules")[0] + "logging.ini"
+            logging.config.fileConfig(logging_conf)
+
+        def get_log(self, name):
+            if name not in self.logs:
+                self.logs[name] = logging.getLogger(name)
+
+            return self.logs[name]
+
+    instance = None
+
+    def __new__(cls, *args, **kwargs):
+        if not LogFactory.instance:
+            LogFactory.instance = LogFactory.__LogFactory()
+
+        return LogFactory.instance
+
+    def get_log(self, name):
+        """
+        Returns a logger class with the specified channel name. Creates a new logger if one doesn't exists for the
+        specified channel
+        :param str name: Channel name
+        :return: The logger class
+        :rtype: RootLogger
+        """
+        return self.instance.get_log(name)
\ No newline at end of file


[03/50] [abbrv] git commit: Fixed import error in databridge module, added log points

Posted by im...@apache.org.
Fixed import error in databridge module, added log points


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

Branch: refs/heads/master
Commit: 32d2ecc66544aea6117f9d5498b3c3c7ce24bdf8
Parents: 7cc189e
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Wed Oct 15 18:54:11 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Wed Oct 15 18:54:11 2014 +0530

----------------------------------------------------------------------
 .../cartridge-agent/modules/databridge/agent.py           | 10 +++++++---
 .../modules/databridge/thrift/publisher.py                |  4 +++-
 2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/32d2ecc6/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
index e5700a0..c4357df 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/agent.py
@@ -148,7 +148,6 @@ class ThriftPublisher:
         :param ThriftEvent event: The log event to be published
         :return: void
         """
-        ThriftPublisher.log.debug("ABOUT TO PUBLISH: POPULATING DATA")
         event_bundler = EventBundle()
         ThriftPublisher.assign_attributes(event.metaData, event_bundler)
         ThriftPublisher.assign_attributes(event.correlationData, event_bundler)
@@ -184,16 +183,21 @@ class ThriftPublisher:
         if attributes is not None and len(attributes) > 0:
             for attrib in attributes:
                 if isinstance(attrib, int):
+                    ThriftPublisher.log.debug("Int : %r" % attrib)
                     event_bundler.addIntAttribute(attrib)
                 elif isinstance(attrib, long):
+                    ThriftPublisher.log.debug("Long : %r" % attrib)
                     event_bundler.addLongAttribute(attrib)
                 elif isinstance(attrib, float):
+                    ThriftPublisher.log.debug("Float : %r" % attrib)
                     event_bundler.addDoubleAttribute(attrib)
                 elif isinstance(attrib, bool):
+                    ThriftPublisher.log.debug("Bool : %r" % attrib)
                     event_bundler.addBoolAttribute(attrib)
                 elif isinstance(attrib, str):
+                    ThriftPublisher.log.debug("Str : %r" % attrib)
                     event_bundler.addStringAttribute(attrib)
                 else:
                     ThriftPublisher.log.error("Undefined attribute type: %r" % attrib)
-
-        ThriftPublisher.log.debug("Empty attribute list")
+        else:
+            ThriftPublisher.log.debug("Empty attribute list")

http://git-wip-us.apache.org/repos/asf/stratos/blob/32d2ecc6/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
index 99d9f1f..b33c8ac 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/thrift/publisher.py
@@ -22,6 +22,7 @@ sys.path.append("gen")
 
 from gen.ThriftSecureEventTransmissionService import ThriftSecureEventTransmissionService
 from gen.ThriftSecureEventTransmissionService.ttypes import *
+from gen.Data.ttypes import ThriftEventBundle
 
 from thrift.transport import TSSLSocket
 from thrift.transport import TTransport
@@ -64,6 +65,7 @@ class Publisher:
         event.addStringAttribute(self.streamId)
         #event.addStringAttribute(msg)
         # Publish
+        print "TO THE WIRE!!! "
         Publisher.client.publish(event.getEventBundle())
 
     def disconnect(self):
@@ -105,7 +107,7 @@ class EventBundle:
         self.__stringAttributeList.append(attr)
 
     def getEventBundle(self):
-        return Data.ttypes.ThriftEventBundle(self.__sessionId, self.__eventNum, self.__intAttributeList,
+        return ThriftEventBundle(self.__sessionId, self.__eventNum, self.__intAttributeList,
                                              self.__longAttributeList, self.__doubleAttributeList,
                                              self.__boolAttributeList, self.__stringAttributeList,
                                              self.__arbitraryDataMapMap)


[47/50] [abbrv] git commit: Fixed Thrift session expiration after client time out to reconnect and continue publishing Fixed issues in git clone auth

Posted by im...@apache.org.
Fixed Thrift session expiration after client time out to reconnect and continue publishing
Fixed issues in git clone auth


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

Branch: refs/heads/master
Commit: e7a3c27867cfeec988b5673e3d4c3c989a0b8dee
Parents: 9a4e3a8
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Sun Oct 26 16:54:05 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Sun Oct 26 16:54:05 2014 +0530

----------------------------------------------------------------------
 .../modules/artifactmgt/git/agentgithandler.py  |  7 +++--
 .../cartridgeagent/modules/databridge/agent.py  | 17 +++++++++---
 .../modules/databridge/thrift/publisher.py      |  1 -
 .../cartridgeagent/testgit.py                   | 27 --------------------
 tools/python_cartridgeagent/test/asynctest.txt  |  2 +-
 tools/python_cartridgeagent/test/test_util.py   |  5 +++-
 6 files changed, 23 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
index d5d085c..7b5bbaf 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
@@ -208,7 +208,8 @@ class AgentGitHandler:
                 cartridgeagentutils.create_dir(repo_context.local_repo_path)
 
             #TODO: remove gittle stuff
-            auth = AgentGitHandler.create_auth_configuration(repo_context)
+            #auth = AgentGitHandler.create_auth_configuration(repo_context)
+            auth = None
 
             if auth is not None:
                 # authentication is required, use Gittle
@@ -404,6 +405,7 @@ class AgentGitHandler:
 
         AgentGitHandler.log.debug("Modified: %r" % str(modified))
 
+        # TODO: check for unpushed commits and push them too
         if not modified:
             AgentGitHandler.log.debug("No changes detected in the local repository for tenant " + tenant_id)
             return
@@ -440,7 +442,8 @@ class AgentGitHandler:
             # if result != 0:
             #     raise Exception
             #TODO: handle push failure scenarios
-            push_op.interact()
+            #push_op.interact()
+            push_op.expect(pexpect.EOF)
 
             AgentGitHandler.log.debug("Pushed artifacts for tenant : " + tenant_id)
         except:

http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
index d67be89..5d341dd 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
@@ -16,7 +16,9 @@
 # under the License.
 
 from thrift.publisher import *
+from thrift.gen.Exception.ttypes import ThriftSessionExpiredException
 from ..util.log import *
+import time
 
 
 class StreamDefinition:
@@ -161,7 +163,16 @@ class ThriftPublisher:
         ThriftPublisher.assign_attributes(event.correlationData, event_bundler)
         ThriftPublisher.assign_attributes(event.payloadData, event_bundler)
 
-        self.__publisher.publish(event_bundler)
+        try:
+            self.__publisher.publish(event_bundler)
+        except ThriftSessionExpiredException as ex:
+            self.log.debug("ThriftSession expired. Reconnecting")
+            self.__publisher.connect(self.username, self.password)
+            self.__publisher.defineStream(str(self.stream_definition))
+            self.stream_id = self.__publisher.streamId
+            self.log.debug("connected! stream ID: %r" % self.stream_id)
+            self.__publisher.publish(event_bundler)
+
         self.log.debug("Published event to thrift stream [%r]" % self.stream_id)
 
     def disconnect(self):
@@ -199,6 +210,4 @@ class ThriftPublisher:
                 elif isinstance(attrib, str):
                     event_bundler.addStringAttribute(attrib)
                 else:
-                    ThriftPublisher.log.error("Undefined attribute type: %r" % attrib)
-        else:
-            ThriftPublisher.log.debug("Empty attribute list")
+                    ThriftPublisher.log.error("Undefined attribute type: %r" % attrib)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
index dfe4aa2..3317404 100644
--- a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py
@@ -15,7 +15,6 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import time
 import sys
 
 sys.path.append("gen")

http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/cartridgeagent/testgit.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/testgit.py b/tools/python_cartridgeagent/cartridgeagent/testgit.py
deleted file mode 100644
index 0b38f83..0000000
--- a/tools/python_cartridgeagent/cartridgeagent/testgit.py
+++ /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.
-
-
-from modules.extensions.defaultextensionhandler import *
-from modules.event.instance.notifier.events import ArtifactUpdatedEvent
-
-event_msg = '{"clusterId":"newoice.php.domain","repoUserName":"chamilad","repoPassword":"eng3lhimm3lsonn3","repoURL":"https://github.com/chamilad/NeWoice","tenantId":"-1234","commitEnabled":false}'
-event = ArtifactUpdatedEvent.create_from_json(event_msg)
-
-extension_handler = DefaultExtensionHandler()
-extension_handler.on_artifact_updated_event(event)
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/test/asynctest.txt
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/asynctest.txt b/tools/python_cartridgeagent/test/asynctest.txt
index 75eddf2..b676e7d 100644
--- a/tools/python_cartridgeagent/test/asynctest.txt
+++ b/tools/python_cartridgeagent/test/asynctest.txt
@@ -1 +1 @@
-1413885854235.2659
\ No newline at end of file
+1414239655582.5959
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/test/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/test_util.py b/tools/python_cartridgeagent/test/test_util.py
index e7c42ac..63c0cc7 100644
--- a/tools/python_cartridgeagent/test/test_util.py
+++ b/tools/python_cartridgeagent/test/test_util.py
@@ -70,7 +70,10 @@ def test_decrypt_password_success():
     secret_key = "tvnw63ufg9gh5111"
     encrypted_password= "jP1lZ5xMlpLzu8MbY2Porg=="
 
-    assert cartridgeagentutils.decrypt_password(encrypted_password, secret_key) == plain_password, "Password decryption failed"
+    decrypted_password = cartridgeagentutils.decrypt_password(encrypted_password, secret_key)
+    #print decrypted_password
+
+    assert decrypted_password == plain_password, "Password decryption failed"
 
 
 def test_decrypt_password_failure():


[28/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
new file mode 100644
index 0000000..74e142c
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TProcessPoolServer.py
@@ -0,0 +1,118 @@
+#
+# 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.
+#
+
+
+import logging
+from multiprocessing import  Process, Value, Condition
+
+from TServer import TServer
+from ..transport.TTransport import TTransportException
+
+
+class TProcessPoolServer(TServer):
+    """Server with a fixed size pool of worker subprocesses to service requests
+
+    Note that if you need shared state between the handlers - it's up to you!
+    Written by Dvir Volk, doat.com
+    """
+    def __init__(self, *args):
+        TServer.__init__(self, *args)
+        self.numWorkers = 10
+        self.workers = []
+        self.isRunning = Value('b', False)
+        self.stopCondition = Condition()
+        self.postForkCallback = None
+
+    def setPostForkCallback(self, callback):
+        if not callable(callback):
+            raise TypeError("This is not a callback!")
+        self.postForkCallback = callback
+
+    def setNumWorkers(self, num):
+        """Set the number of worker threads that should be created"""
+        self.numWorkers = num
+
+    def workerProcess(self):
+        """Loop getting clients from the shared queue and process them"""
+        if self.postForkCallback:
+            self.postForkCallback()
+
+        while self.isRunning.value:
+            try:
+                client = self.serverTransport.accept()
+                self.serveClient(client)
+            except (KeyboardInterrupt, SystemExit):
+                return 0
+            except Exception, x:
+                logging.exception(x)
+
+    def serveClient(self, client):
+        """Process input/output from a client for as long as possible"""
+        itrans = self.inputTransportFactory.getTransport(client)
+        otrans = self.outputTransportFactory.getTransport(client)
+        iprot = self.inputProtocolFactory.getProtocol(itrans)
+        oprot = self.outputProtocolFactory.getProtocol(otrans)
+
+        try:
+            while True:
+                self.processor.process(iprot, oprot)
+        except TTransportException, tx:
+            pass
+        except Exception, x:
+            logging.exception(x)
+
+        itrans.close()
+        otrans.close()
+
+    def serve(self):
+        """Start workers and put into queue"""
+        # this is a shared state that can tell the workers to exit when False
+        self.isRunning.value = True
+
+        # first bind and listen to the port
+        self.serverTransport.listen()
+
+        # fork the children
+        for i in range(self.numWorkers):
+            try:
+                w = Process(target=self.workerProcess)
+                w.daemon = True
+                w.start()
+                self.workers.append(w)
+            except Exception, x:
+                logging.exception(x)
+
+        # wait until the condition is set by stop()
+        while True:
+            self.stopCondition.acquire()
+            try:
+                self.stopCondition.wait()
+                break
+            except (SystemExit, KeyboardInterrupt):
+                break
+            except Exception, x:
+                logging.exception(x)
+
+        self.isRunning.value = False
+
+    def stop(self):
+        self.isRunning.value = False
+        self.stopCondition.acquire()
+        self.stopCondition.notify()
+        self.stopCondition.release()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py
new file mode 100644
index 0000000..3e44107
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/TServer.py
@@ -0,0 +1,269 @@
+#
+# 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.
+#
+
+import Queue
+import logging
+import os
+import sys
+import threading
+import traceback
+
+from ..Thrift import TProcessor
+from ..protocol import TBinaryProtocol
+from ..transport import TTransport
+
+
+class TServer:
+  """Base interface for a server, which must have a serve() method.
+
+  Three constructors for all servers:
+  1) (processor, serverTransport)
+  2) (processor, serverTransport, transportFactory, protocolFactory)
+  3) (processor, serverTransport,
+      inputTransportFactory, outputTransportFactory,
+      inputProtocolFactory, outputProtocolFactory)
+  """
+  def __init__(self, *args):
+    if (len(args) == 2):
+      self.__initArgs__(args[0], args[1],
+                        TTransport.TTransportFactoryBase(),
+                        TTransport.TTransportFactoryBase(),
+                        TBinaryProtocol.TBinaryProtocolFactory(),
+                        TBinaryProtocol.TBinaryProtocolFactory())
+    elif (len(args) == 4):
+      self.__initArgs__(args[0], args[1], args[2], args[2], args[3], args[3])
+    elif (len(args) == 6):
+      self.__initArgs__(args[0], args[1], args[2], args[3], args[4], args[5])
+
+  def __initArgs__(self, processor, serverTransport,
+                   inputTransportFactory, outputTransportFactory,
+                   inputProtocolFactory, outputProtocolFactory):
+    self.processor = processor
+    self.serverTransport = serverTransport
+    self.inputTransportFactory = inputTransportFactory
+    self.outputTransportFactory = outputTransportFactory
+    self.inputProtocolFactory = inputProtocolFactory
+    self.outputProtocolFactory = outputProtocolFactory
+
+  def serve(self):
+    pass
+
+
+class TSimpleServer(TServer):
+  """Simple single-threaded server that just pumps around one transport."""
+
+  def __init__(self, *args):
+    TServer.__init__(self, *args)
+
+  def serve(self):
+    self.serverTransport.listen()
+    while True:
+      client = self.serverTransport.accept()
+      itrans = self.inputTransportFactory.getTransport(client)
+      otrans = self.outputTransportFactory.getTransport(client)
+      iprot = self.inputProtocolFactory.getProtocol(itrans)
+      oprot = self.outputProtocolFactory.getProtocol(otrans)
+      try:
+        while True:
+          self.processor.process(iprot, oprot)
+      except TTransport.TTransportException, tx:
+        pass
+      except Exception, x:
+        logging.exception(x)
+
+      itrans.close()
+      otrans.close()
+
+
+class TThreadedServer(TServer):
+  """Threaded server that spawns a new thread per each connection."""
+
+  def __init__(self, *args, **kwargs):
+    TServer.__init__(self, *args)
+    self.daemon = kwargs.get("daemon", False)
+
+  def serve(self):
+    self.serverTransport.listen()
+    while True:
+      try:
+        client = self.serverTransport.accept()
+        t = threading.Thread(target=self.handle, args=(client,))
+        t.setDaemon(self.daemon)
+        t.start()
+      except KeyboardInterrupt:
+        raise
+      except Exception, x:
+        logging.exception(x)
+
+  def handle(self, client):
+    itrans = self.inputTransportFactory.getTransport(client)
+    otrans = self.outputTransportFactory.getTransport(client)
+    iprot = self.inputProtocolFactory.getProtocol(itrans)
+    oprot = self.outputProtocolFactory.getProtocol(otrans)
+    try:
+      while True:
+        self.processor.process(iprot, oprot)
+    except TTransport.TTransportException, tx:
+      pass
+    except Exception, x:
+      logging.exception(x)
+
+    itrans.close()
+    otrans.close()
+
+
+class TThreadPoolServer(TServer):
+  """Server with a fixed size pool of threads which service requests."""
+
+  def __init__(self, *args, **kwargs):
+    TServer.__init__(self, *args)
+    self.clients = Queue.Queue()
+    self.threads = 10
+    self.daemon = kwargs.get("daemon", False)
+
+  def setNumThreads(self, num):
+    """Set the number of worker threads that should be created"""
+    self.threads = num
+
+  def serveThread(self):
+    """Loop around getting clients from the shared queue and process them."""
+    while True:
+      try:
+        client = self.clients.get()
+        self.serveClient(client)
+      except Exception, x:
+        logging.exception(x)
+
+  def serveClient(self, client):
+    """Process input/output from a client for as long as possible"""
+    itrans = self.inputTransportFactory.getTransport(client)
+    otrans = self.outputTransportFactory.getTransport(client)
+    iprot = self.inputProtocolFactory.getProtocol(itrans)
+    oprot = self.outputProtocolFactory.getProtocol(otrans)
+    try:
+      while True:
+        self.processor.process(iprot, oprot)
+    except TTransport.TTransportException, tx:
+      pass
+    except Exception, x:
+      logging.exception(x)
+
+    itrans.close()
+    otrans.close()
+
+  def serve(self):
+    """Start a fixed number of worker threads and put client into a queue"""
+    for i in range(self.threads):
+      try:
+        t = threading.Thread(target=self.serveThread)
+        t.setDaemon(self.daemon)
+        t.start()
+      except Exception, x:
+        logging.exception(x)
+
+    # Pump the socket for clients
+    self.serverTransport.listen()
+    while True:
+      try:
+        client = self.serverTransport.accept()
+        self.clients.put(client)
+      except Exception, x:
+        logging.exception(x)
+
+
+class TForkingServer(TServer):
+  """A Thrift server that forks a new process for each request
+
+  This is more scalable than the threaded server as it does not cause
+  GIL contention.
+
+  Note that this has different semantics from the threading server.
+  Specifically, updates to shared variables will no longer be shared.
+  It will also not work on windows.
+
+  This code is heavily inspired by SocketServer.ForkingMixIn in the
+  Python stdlib.
+  """
+  def __init__(self, *args):
+    TServer.__init__(self, *args)
+    self.children = []
+
+  def serve(self):
+    def try_close(file):
+      try:
+        file.close()
+      except IOError, e:
+        logging.warning(e, exc_info=True)
+
+    self.serverTransport.listen()
+    while True:
+      client = self.serverTransport.accept()
+      try:
+        pid = os.fork()
+
+        if pid:  # parent
+          # add before collect, otherwise you race w/ waitpid
+          self.children.append(pid)
+          self.collect_children()
+
+          # Parent must close socket or the connection may not get
+          # closed promptly
+          itrans = self.inputTransportFactory.getTransport(client)
+          otrans = self.outputTransportFactory.getTransport(client)
+          try_close(itrans)
+          try_close(otrans)
+        else:
+          itrans = self.inputTransportFactory.getTransport(client)
+          otrans = self.outputTransportFactory.getTransport(client)
+
+          iprot = self.inputProtocolFactory.getProtocol(itrans)
+          oprot = self.outputProtocolFactory.getProtocol(otrans)
+
+          ecode = 0
+          try:
+            try:
+              while True:
+                self.processor.process(iprot, oprot)
+            except TTransport.TTransportException, tx:
+              pass
+            except Exception, e:
+              logging.exception(e)
+              ecode = 1
+          finally:
+            try_close(itrans)
+            try_close(otrans)
+
+          os._exit(ecode)
+
+      except TTransport.TTransportException, tx:
+        pass
+      except Exception, x:
+        logging.exception(x)
+
+  def collect_children(self):
+    while self.children:
+      try:
+        pid, status = os.waitpid(0, os.WNOHANG)
+      except os.error:
+        pid = None
+
+      if pid:
+        self.children.remove(pid)
+      else:
+        break

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py
new file mode 100644
index 0000000..1bf6e25
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/server/__init__.py
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+__all__ = ['TServer', 'TNonblockingServer']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py
new file mode 100644
index 0000000..9ef9535
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/THttpClient.py
@@ -0,0 +1,147 @@
+#
+# 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.
+#
+
+import httplib
+import os
+import socket
+import sys
+import urllib
+import urlparse
+import warnings
+
+from TTransport import *
+
+
+class THttpClient(TTransportBase):
+  """Http implementation of TTransport base."""
+
+  def __init__(self, uri_or_host, port=None, path=None):
+    """THttpClient supports two different types constructor parameters.
+
+    THttpClient(host, port, path) - deprecated
+    THttpClient(uri)
+
+    Only the second supports https.
+    """
+    if port is not None:
+      warnings.warn(
+        "Please use the THttpClient('http://host:port/path') syntax",
+        DeprecationWarning,
+        stacklevel=2)
+      self.host = uri_or_host
+      self.port = port
+      assert path
+      self.path = path
+      self.scheme = 'http'
+    else:
+      parsed = urlparse.urlparse(uri_or_host)
+      self.scheme = parsed.scheme
+      assert self.scheme in ('http', 'https')
+      if self.scheme == 'http':
+        self.port = parsed.port or httplib.HTTP_PORT
+      elif self.scheme == 'https':
+        self.port = parsed.port or httplib.HTTPS_PORT
+      self.host = parsed.hostname
+      self.path = parsed.path
+      if parsed.query:
+        self.path += '?%s' % parsed.query
+    self.__wbuf = StringIO()
+    self.__http = None
+    self.__timeout = None
+    self.__custom_headers = None
+
+  def open(self):
+    if self.scheme == 'http':
+      self.__http = httplib.HTTP(self.host, self.port)
+    else:
+      self.__http = httplib.HTTPS(self.host, self.port)
+
+  def close(self):
+    self.__http.close()
+    self.__http = None
+
+  def isOpen(self):
+    return self.__http is not None
+
+  def setTimeout(self, ms):
+    if not hasattr(socket, 'getdefaulttimeout'):
+      raise NotImplementedError
+
+    if ms is None:
+      self.__timeout = None
+    else:
+      self.__timeout = ms / 1000.0
+
+  def setCustomHeaders(self, headers):
+    self.__custom_headers = headers
+
+  def read(self, sz):
+    return self.__http.file.read(sz)
+
+  def write(self, buf):
+    self.__wbuf.write(buf)
+
+  def __withTimeout(f):
+    def _f(*args, **kwargs):
+      orig_timeout = socket.getdefaulttimeout()
+      socket.setdefaulttimeout(args[0].__timeout)
+      result = f(*args, **kwargs)
+      socket.setdefaulttimeout(orig_timeout)
+      return result
+    return _f
+
+  def flush(self):
+    if self.isOpen():
+      self.close()
+    self.open()
+
+    # Pull data out of buffer
+    data = self.__wbuf.getvalue()
+    self.__wbuf = StringIO()
+
+    # HTTP request
+    self.__http.putrequest('POST', self.path)
+
+    # Write headers
+    self.__http.putheader('Host', self.host)
+    self.__http.putheader('Content-Type', 'application/x-thrift')
+    self.__http.putheader('Content-Length', str(len(data)))
+
+    if not self.__custom_headers or 'User-Agent' not in self.__custom_headers:
+      user_agent = 'Python/THttpClient'
+      script = os.path.basename(sys.argv[0])
+      if script:
+        user_agent = '%s (%s)' % (user_agent, urllib.quote(script))
+      self.__http.putheader('User-Agent', user_agent)
+
+    if self.__custom_headers:
+        for key, val in self.__custom_headers.iteritems():
+            self.__http.putheader(key, val)
+
+    self.__http.endheaders()
+
+    # Write payload
+    self.__http.send(data)
+
+    # Get reply to flush the request
+    self.code, self.message, self.headers = self.__http.getreply()
+
+  # Decorate if we know how to timeout
+  if hasattr(socket, 'getdefaulttimeout'):
+    flush = __withTimeout(flush)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
new file mode 100644
index 0000000..df35be4
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSSLSocket.py
@@ -0,0 +1,214 @@
+#
+# 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.
+#
+
+import os
+import socket
+import ssl
+
+import TSocket
+from TTransport import TTransportException
+
+
+class TSSLSocket(TSocket.TSocket):
+  """
+  SSL implementation of client-side TSocket
+
+  This class creates outbound sockets wrapped using the
+  python standard ssl module for encrypted connections.
+
+  The protocol used is set using the class variable
+  SSL_VERSION, which must be one of ssl.PROTOCOL_* and
+  defaults to  ssl.PROTOCOL_TLSv1 for greatest security.
+  """
+  SSL_VERSION = ssl.PROTOCOL_TLSv1
+
+  def __init__(self,
+               host='localhost',
+               port=9090,
+               validate=True,
+               ca_certs=None,
+               keyfile=None,
+               certfile=None,
+               unix_socket=None):
+    """Create SSL TSocket
+
+    @param validate: Set to False to disable SSL certificate validation
+    @type validate: bool
+    @param ca_certs: Filename to the Certificate Authority pem file, possibly a
+    file downloaded from: http://curl.haxx.se/ca/cacert.pem  This is passed to
+    the ssl_wrap function as the 'ca_certs' parameter.
+    @type ca_certs: str
+    @param keyfile: The private key
+    @type keyfile: str
+    @param certfile: The cert file
+    @type certfile: str
+    
+    Raises an IOError exception if validate is True and the ca_certs file is
+    None, not present or unreadable.
+    """
+    self.validate = validate
+    self.is_valid = False
+    self.peercert = None
+    if not validate:
+      self.cert_reqs = ssl.CERT_NONE
+    else:
+      self.cert_reqs = ssl.CERT_REQUIRED
+    self.ca_certs = ca_certs
+    self.keyfile = keyfile
+    self.certfile = certfile
+    if validate:
+      if ca_certs is None or not os.access(ca_certs, os.R_OK):
+        raise IOError('Certificate Authority ca_certs file "%s" '
+                      'is not readable, cannot validate SSL '
+                      'certificates.' % (ca_certs))
+    TSocket.TSocket.__init__(self, host, port, unix_socket)
+
+  def open(self):
+    try:
+      res0 = self._resolveAddr()
+      for res in res0:
+        sock_family, sock_type = res[0:2]
+        ip_port = res[4]
+        plain_sock = socket.socket(sock_family, sock_type)
+        self.handle = ssl.wrap_socket(plain_sock,
+                                      ssl_version=self.SSL_VERSION,
+                                      do_handshake_on_connect=True,
+                                      ca_certs=self.ca_certs,
+                                      keyfile=self.keyfile,
+                                      certfile=self.certfile,
+                                      cert_reqs=self.cert_reqs)
+        self.handle.settimeout(self._timeout)
+        try:
+          self.handle.connect(ip_port)
+        except socket.error, e:
+          if res is not res0[-1]:
+            continue
+          else:
+            raise e
+        break
+    except socket.error, e:
+      if self._unix_socket:
+        message = 'Could not connect to secure socket %s: %s' \
+                % (self._unix_socket, e)
+      else:
+        message = 'Could not connect to %s:%d: %s' % (self.host, self.port, e)
+      raise TTransportException(type=TTransportException.NOT_OPEN,
+                                message=message)
+    if self.validate:
+      self._validate_cert()
+
+  def _validate_cert(self):
+    """internal method to validate the peer's SSL certificate, and to check the
+    commonName of the certificate to ensure it matches the hostname we
+    used to make this connection.  Does not support subjectAltName records
+    in certificates.
+
+    raises TTransportException if the certificate fails validation.
+    """
+    cert = self.handle.getpeercert()
+    self.peercert = cert
+    if 'subject' not in cert:
+      raise TTransportException(
+        type=TTransportException.NOT_OPEN,
+        message='No SSL certificate found from %s:%s' % (self.host, self.port))
+    fields = cert['subject']
+    for field in fields:
+      # ensure structure we get back is what we expect
+      if not isinstance(field, tuple):
+        continue
+      cert_pair = field[0]
+      if len(cert_pair) < 2:
+        continue
+      cert_key, cert_value = cert_pair[0:2]
+      if cert_key != 'commonName':
+        continue
+      certhost = cert_value
+      # this check should be performed by some sort of Access Manager
+      if certhost == self.host:
+        # success, cert commonName matches desired hostname
+        self.is_valid = True
+        return
+      else:
+        raise TTransportException(
+          type=TTransportException.UNKNOWN,
+          message='Hostname we connected to "%s" doesn\'t match certificate '
+                  'provided commonName "%s"' % (self.host, certhost))
+    raise TTransportException(
+      type=TTransportException.UNKNOWN,
+      message='Could not validate SSL certificate from '
+              'host "%s".  Cert=%s' % (self.host, cert))
+
+
+class TSSLServerSocket(TSocket.TServerSocket):
+  """SSL implementation of TServerSocket
+
+  This uses the ssl module's wrap_socket() method to provide SSL
+  negotiated encryption.
+  """
+  SSL_VERSION = ssl.PROTOCOL_TLSv1
+
+  def __init__(self,
+               host=None,
+               port=9090,
+               certfile='cert.pem',
+               unix_socket=None):
+    """Initialize a TSSLServerSocket
+
+    @param certfile: filename of the server certificate, defaults to cert.pem
+    @type certfile: str
+    @param host: The hostname or IP to bind the listen socket to,
+                 i.e. 'localhost' for only allowing local network connections.
+                 Pass None to bind to all interfaces.
+    @type host: str
+    @param port: The port to listen on for inbound connections.
+    @type port: int
+    """
+    self.setCertfile(certfile)
+    TSocket.TServerSocket.__init__(self, host, port)
+
+  def setCertfile(self, certfile):
+    """Set or change the server certificate file used to wrap new connections.
+
+    @param certfile: The filename of the server certificate,
+                     i.e. '/etc/certs/server.pem'
+    @type certfile: str
+
+    Raises an IOError exception if the certfile is not present or unreadable.
+    """
+    if not os.access(certfile, os.R_OK):
+      raise IOError('No such certfile found: %s' % (certfile))
+    self.certfile = certfile
+
+  def accept(self):
+    plain_client, addr = self.handle.accept()
+    try:
+      client = ssl.wrap_socket(plain_client, certfile=self.certfile,
+                      server_side=True, ssl_version=self.SSL_VERSION)
+    except ssl.SSLError, ssl_exc:
+      # failed handshake/ssl wrap, close socket to client
+      plain_client.close()
+      # raise ssl_exc
+      # We can't raise the exception, because it kills most TServer derived
+      # serve() methods.
+      # Instead, return None, and let the TServer instance deal with it in
+      # other exception handling.  (but TSimpleServer dies anyway)
+      return None
+    result = TSocket.TSocket()
+    result.setHandle(client)
+    return result

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py
new file mode 100644
index 0000000..9e2b384
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TSocket.py
@@ -0,0 +1,176 @@
+#
+# 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.
+#
+
+import errno
+import os
+import socket
+import sys
+
+from TTransport import *
+
+
+class TSocketBase(TTransportBase):
+  def _resolveAddr(self):
+    if self._unix_socket is not None:
+      return [(socket.AF_UNIX, socket.SOCK_STREAM, None, None,
+               self._unix_socket)]
+    else:
+      return socket.getaddrinfo(self.host,
+                                self.port,
+                                socket.AF_UNSPEC,
+                                socket.SOCK_STREAM,
+                                0,
+                                socket.AI_PASSIVE | socket.AI_ADDRCONFIG)
+
+  def close(self):
+    if self.handle:
+      self.handle.close()
+      self.handle = None
+
+
+class TSocket(TSocketBase):
+  """Socket implementation of TTransport base."""
+
+  def __init__(self, host='localhost', port=9090, unix_socket=None):
+    """Initialize a TSocket
+
+    @param host(str)  The host to connect to.
+    @param port(int)  The (TCP) port to connect to.
+    @param unix_socket(str)  The filename of a unix socket to connect to.
+                             (host and port will be ignored.)
+    """
+    self.host = host
+    self.port = port
+    self.handle = None
+    self._unix_socket = unix_socket
+    self._timeout = None
+
+  def setHandle(self, h):
+    self.handle = h
+
+  def isOpen(self):
+    return self.handle is not None
+
+  def setTimeout(self, ms):
+    if ms is None:
+      self._timeout = None
+    else:
+      self._timeout = ms / 1000.0
+
+    if self.handle is not None:
+      self.handle.settimeout(self._timeout)
+
+  def open(self):
+    try:
+      res0 = self._resolveAddr()
+      for res in res0:
+        self.handle = socket.socket(res[0], res[1])
+        self.handle.settimeout(self._timeout)
+        try:
+          self.handle.connect(res[4])
+        except socket.error, e:
+          if res is not res0[-1]:
+            continue
+          else:
+            raise e
+        break
+    except socket.error, e:
+      if self._unix_socket:
+        message = 'Could not connect to socket %s' % self._unix_socket
+      else:
+        message = 'Could not connect to %s:%d' % (self.host, self.port)
+      raise TTransportException(type=TTransportException.NOT_OPEN,
+                                message=message)
+
+  def read(self, sz):
+    try:
+      buff = self.handle.recv(sz)
+    except socket.error, e:
+      if (e.args[0] == errno.ECONNRESET and
+          (sys.platform == 'darwin' or sys.platform.startswith('freebsd'))):
+        # freebsd and Mach don't follow POSIX semantic of recv
+        # and fail with ECONNRESET if peer performed shutdown.
+        # See corresponding comment and code in TSocket::read()
+        # in lib/cpp/src/transport/TSocket.cpp.
+        self.close()
+        # Trigger the check to raise the END_OF_FILE exception below.
+        buff = ''
+      else:
+        raise
+    if len(buff) == 0:
+      raise TTransportException(type=TTransportException.END_OF_FILE,
+                                message='TSocket read 0 bytes')
+    return buff
+
+  def write(self, buff):
+    if not self.handle:
+      raise TTransportException(type=TTransportException.NOT_OPEN,
+                                message='Transport not open')
+    sent = 0
+    have = len(buff)
+    while sent < have:
+      plus = self.handle.send(buff)
+      if plus == 0:
+        raise TTransportException(type=TTransportException.END_OF_FILE,
+                                  message='TSocket sent 0 bytes')
+      sent += plus
+      buff = buff[plus:]
+
+  def flush(self):
+    pass
+
+
+class TServerSocket(TSocketBase, TServerTransportBase):
+  """Socket implementation of TServerTransport base."""
+
+  def __init__(self, host=None, port=9090, unix_socket=None):
+    self.host = host
+    self.port = port
+    self._unix_socket = unix_socket
+    self.handle = None
+
+  def listen(self):
+    res0 = self._resolveAddr()
+    for res in res0:
+      if res[0] is socket.AF_INET6 or res is res0[-1]:
+        break
+
+    # We need remove the old unix socket if the file exists and
+    # nobody is listening on it.
+    if self._unix_socket:
+      tmp = socket.socket(res[0], res[1])
+      try:
+        tmp.connect(res[4])
+      except socket.error, err:
+        eno, message = err.args
+        if eno == errno.ECONNREFUSED:
+          os.unlink(res[4])
+
+    self.handle = socket.socket(res[0], res[1])
+    self.handle.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+    if hasattr(self.handle, 'settimeout'):
+      self.handle.settimeout(None)
+    self.handle.bind(res[4])
+    self.handle.listen(128)
+
+  def accept(self):
+    client, addr = self.handle.accept()
+    result = TSocket()
+    result.setHandle(client)
+    return result

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py
new file mode 100644
index 0000000..ed023d5
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTransport.py
@@ -0,0 +1,330 @@
+#
+# 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.
+#
+
+from cStringIO import StringIO
+from struct import pack, unpack
+from ..Thrift import TException
+
+
+class TTransportException(TException):
+  """Custom Transport Exception class"""
+
+  UNKNOWN = 0
+  NOT_OPEN = 1
+  ALREADY_OPEN = 2
+  TIMED_OUT = 3
+  END_OF_FILE = 4
+
+  def __init__(self, type=UNKNOWN, message=None):
+    TException.__init__(self, message)
+    self.type = type
+
+
+class TTransportBase:
+  """Base class for Thrift transport layer."""
+
+  def isOpen(self):
+    pass
+
+  def open(self):
+    pass
+
+  def close(self):
+    pass
+
+  def read(self, sz):
+    pass
+
+  def readAll(self, sz):
+    buff = ''
+    have = 0
+    while (have < sz):
+      chunk = self.read(sz - have)
+      have += len(chunk)
+      buff += chunk
+
+      if len(chunk) == 0:
+        raise EOFError()
+
+    return buff
+
+  def write(self, buf):
+    pass
+
+  def flush(self):
+    pass
+
+
+# This class should be thought of as an interface.
+class CReadableTransport:
+  """base class for transports that are readable from C"""
+
+  # TODO(dreiss): Think about changing this interface to allow us to use
+  #               a (Python, not c) StringIO instead, because it allows
+  #               you to write after reading.
+
+  # NOTE: This is a classic class, so properties will NOT work
+  #       correctly for setting.
+  @property
+  def cstringio_buf(self):
+    """A cStringIO buffer that contains the current chunk we are reading."""
+    pass
+
+  def cstringio_refill(self, partialread, reqlen):
+    """Refills cstringio_buf.
+
+    Returns the currently used buffer (which can but need not be the same as
+    the old cstringio_buf). partialread is what the C code has read from the
+    buffer, and should be inserted into the buffer before any more reads.  The
+    return value must be a new, not borrowed reference.  Something along the
+    lines of self._buf should be fine.
+
+    If reqlen bytes can't be read, throw EOFError.
+    """
+    pass
+
+
+class TServerTransportBase:
+  """Base class for Thrift server transports."""
+
+  def listen(self):
+    pass
+
+  def accept(self):
+    pass
+
+  def close(self):
+    pass
+
+
+class TTransportFactoryBase:
+  """Base class for a Transport Factory"""
+
+  def getTransport(self, trans):
+    return trans
+
+
+class TBufferedTransportFactory:
+  """Factory transport that builds buffered transports"""
+
+  def getTransport(self, trans):
+    buffered = TBufferedTransport(trans)
+    return buffered
+
+
+class TBufferedTransport(TTransportBase, CReadableTransport):
+  """Class that wraps another transport and buffers its I/O.
+
+  The implementation uses a (configurable) fixed-size read buffer
+  but buffers all writes until a flush is performed.
+  """
+  DEFAULT_BUFFER = 4096
+
+  def __init__(self, trans, rbuf_size=DEFAULT_BUFFER):
+    self.__trans = trans
+    self.__wbuf = StringIO()
+    self.__rbuf = StringIO("")
+    self.__rbuf_size = rbuf_size
+
+  def isOpen(self):
+    return self.__trans.isOpen()
+
+  def open(self):
+    return self.__trans.open()
+
+  def close(self):
+    return self.__trans.close()
+
+  def read(self, sz):
+    ret = self.__rbuf.read(sz)
+    if len(ret) != 0:
+      return ret
+
+    self.__rbuf = StringIO(self.__trans.read(max(sz, self.__rbuf_size)))
+    return self.__rbuf.read(sz)
+
+  def write(self, buf):
+    self.__wbuf.write(buf)
+
+  def flush(self):
+    out = self.__wbuf.getvalue()
+    # reset wbuf before write/flush to preserve state on underlying failure
+    self.__wbuf = StringIO()
+    self.__trans.write(out)
+    self.__trans.flush()
+
+  # Implement the CReadableTransport interface.
+  @property
+  def cstringio_buf(self):
+    return self.__rbuf
+
+  def cstringio_refill(self, partialread, reqlen):
+    retstring = partialread
+    if reqlen < self.__rbuf_size:
+      # try to make a read of as much as we can.
+      retstring += self.__trans.read(self.__rbuf_size)
+
+    # but make sure we do read reqlen bytes.
+    if len(retstring) < reqlen:
+      retstring += self.__trans.readAll(reqlen - len(retstring))
+
+    self.__rbuf = StringIO(retstring)
+    return self.__rbuf
+
+
+class TMemoryBuffer(TTransportBase, CReadableTransport):
+  """Wraps a cStringIO object as a TTransport.
+
+  NOTE: Unlike the C++ version of this class, you cannot write to it
+        then immediately read from it.  If you want to read from a
+        TMemoryBuffer, you must either pass a string to the constructor.
+  TODO(dreiss): Make this work like the C++ version.
+  """
+
+  def __init__(self, value=None):
+    """value -- a value to read from for stringio
+
+    If value is set, this will be a transport for reading,
+    otherwise, it is for writing"""
+    if value is not None:
+      self._buffer = StringIO(value)
+    else:
+      self._buffer = StringIO()
+
+  def isOpen(self):
+    return not self._buffer.closed
+
+  def open(self):
+    pass
+
+  def close(self):
+    self._buffer.close()
+
+  def read(self, sz):
+    return self._buffer.read(sz)
+
+  def write(self, buf):
+    self._buffer.write(buf)
+
+  def flush(self):
+    pass
+
+  def getvalue(self):
+    return self._buffer.getvalue()
+
+  # Implement the CReadableTransport interface.
+  @property
+  def cstringio_buf(self):
+    return self._buffer
+
+  def cstringio_refill(self, partialread, reqlen):
+    # only one shot at reading...
+    raise EOFError()
+
+
+class TFramedTransportFactory:
+  """Factory transport that builds framed transports"""
+
+  def getTransport(self, trans):
+    framed = TFramedTransport(trans)
+    return framed
+
+
+class TFramedTransport(TTransportBase, CReadableTransport):
+  """Class that wraps another transport and frames its I/O when writing."""
+
+  def __init__(self, trans,):
+    self.__trans = trans
+    self.__rbuf = StringIO()
+    self.__wbuf = StringIO()
+
+  def isOpen(self):
+    return self.__trans.isOpen()
+
+  def open(self):
+    return self.__trans.open()
+
+  def close(self):
+    return self.__trans.close()
+
+  def read(self, sz):
+    ret = self.__rbuf.read(sz)
+    if len(ret) != 0:
+      return ret
+
+    self.readFrame()
+    return self.__rbuf.read(sz)
+
+  def readFrame(self):
+    buff = self.__trans.readAll(4)
+    sz, = unpack('!i', buff)
+    self.__rbuf = StringIO(self.__trans.readAll(sz))
+
+  def write(self, buf):
+    self.__wbuf.write(buf)
+
+  def flush(self):
+    wout = self.__wbuf.getvalue()
+    wsz = len(wout)
+    # reset wbuf before write/flush to preserve state on underlying failure
+    self.__wbuf = StringIO()
+    # N.B.: Doing this string concatenation is WAY cheaper than making
+    # two separate calls to the underlying socket object. Socket writes in
+    # Python turn out to be REALLY expensive, but it seems to do a pretty
+    # good job of managing string buffer operations without excessive copies
+    buf = pack("!i", wsz) + wout
+    self.__trans.write(buf)
+    self.__trans.flush()
+
+  # Implement the CReadableTransport interface.
+  @property
+  def cstringio_buf(self):
+    return self.__rbuf
+
+  def cstringio_refill(self, prefix, reqlen):
+    # self.__rbuf will already be empty here because fastbinary doesn't
+    # ask for a refill until the previous buffer is empty.  Therefore,
+    # we can start reading new frames immediately.
+    while len(prefix) < reqlen:
+      self.readFrame()
+      prefix += self.__rbuf.getvalue()
+    self.__rbuf = StringIO(prefix)
+    return self.__rbuf
+
+
+class TFileObjectTransport(TTransportBase):
+  """Wraps a file-like object to make it work as a Thrift transport."""
+
+  def __init__(self, fileobj):
+    self.fileobj = fileobj
+
+  def isOpen(self):
+    return True
+
+  def close(self):
+    self.fileobj.close()
+
+  def read(self, sz):
+    return self.fileobj.read(sz)
+
+  def write(self, buf):
+    self.fileobj.write(buf)
+
+  def flush(self):
+    self.fileobj.flush()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py
new file mode 100644
index 0000000..6cdb172
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TTwisted.py
@@ -0,0 +1,221 @@
+#
+# 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.
+#
+
+from cStringIO import StringIO
+
+from zope.interface import implements, Interface, Attribute
+from twisted.internet.protocol import Protocol, ServerFactory, ClientFactory, \
+    connectionDone
+from twisted.internet import defer
+from twisted.protocols import basic
+from twisted.python import log
+from twisted.web import server, resource, http
+
+import TTransport
+
+
+class TMessageSenderTransport(TTransport.TTransportBase):
+
+    def __init__(self):
+        self.__wbuf = StringIO()
+
+    def write(self, buf):
+        self.__wbuf.write(buf)
+
+    def flush(self):
+        msg = self.__wbuf.getvalue()
+        self.__wbuf = StringIO()
+        self.sendMessage(msg)
+
+    def sendMessage(self, message):
+        raise NotImplementedError
+
+
+class TCallbackTransport(TMessageSenderTransport):
+
+    def __init__(self, func):
+        TMessageSenderTransport.__init__(self)
+        self.func = func
+
+    def sendMessage(self, message):
+        self.func(message)
+
+
+class ThriftClientProtocol(basic.Int32StringReceiver):
+
+    MAX_LENGTH = 2 ** 31 - 1
+
+    def __init__(self, client_class, iprot_factory, oprot_factory=None):
+        self._client_class = client_class
+        self._iprot_factory = iprot_factory
+        if oprot_factory is None:
+            self._oprot_factory = iprot_factory
+        else:
+            self._oprot_factory = oprot_factory
+
+        self.recv_map = {}
+        self.started = defer.Deferred()
+
+    def dispatch(self, msg):
+        self.sendString(msg)
+
+    def connectionMade(self):
+        tmo = TCallbackTransport(self.dispatch)
+        self.client = self._client_class(tmo, self._oprot_factory)
+        self.started.callback(self.client)
+
+    def connectionLost(self, reason=connectionDone):
+        for k, v in self.client._reqs.iteritems():
+            tex = TTransport.TTransportException(
+                type=TTransport.TTransportException.END_OF_FILE,
+                message='Connection closed')
+            v.errback(tex)
+
+    def stringReceived(self, frame):
+        tr = TTransport.TMemoryBuffer(frame)
+        iprot = self._iprot_factory.getProtocol(tr)
+        (fname, mtype, rseqid) = iprot.readMessageBegin()
+
+        try:
+            method = self.recv_map[fname]
+        except KeyError:
+            method = getattr(self.client, 'recv_' + fname)
+            self.recv_map[fname] = method
+
+        method(iprot, mtype, rseqid)
+
+
+class ThriftServerProtocol(basic.Int32StringReceiver):
+
+    MAX_LENGTH = 2 ** 31 - 1
+
+    def dispatch(self, msg):
+        self.sendString(msg)
+
+    def processError(self, error):
+        self.transport.loseConnection()
+
+    def processOk(self, _, tmo):
+        msg = tmo.getvalue()
+
+        if len(msg) > 0:
+            self.dispatch(msg)
+
+    def stringReceived(self, frame):
+        tmi = TTransport.TMemoryBuffer(frame)
+        tmo = TTransport.TMemoryBuffer()
+
+        iprot = self.factory.iprot_factory.getProtocol(tmi)
+        oprot = self.factory.oprot_factory.getProtocol(tmo)
+
+        d = self.factory.processor.process(iprot, oprot)
+        d.addCallbacks(self.processOk, self.processError,
+            callbackArgs=(tmo,))
+
+
+class IThriftServerFactory(Interface):
+
+    processor = Attribute("Thrift processor")
+
+    iprot_factory = Attribute("Input protocol factory")
+
+    oprot_factory = Attribute("Output protocol factory")
+
+
+class IThriftClientFactory(Interface):
+
+    client_class = Attribute("Thrift client class")
+
+    iprot_factory = Attribute("Input protocol factory")
+
+    oprot_factory = Attribute("Output protocol factory")
+
+
+class ThriftServerFactory(ServerFactory):
+
+    implements(IThriftServerFactory)
+
+    protocol = ThriftServerProtocol
+
+    def __init__(self, processor, iprot_factory, oprot_factory=None):
+        self.processor = processor
+        self.iprot_factory = iprot_factory
+        if oprot_factory is None:
+            self.oprot_factory = iprot_factory
+        else:
+            self.oprot_factory = oprot_factory
+
+
+class ThriftClientFactory(ClientFactory):
+
+    implements(IThriftClientFactory)
+
+    protocol = ThriftClientProtocol
+
+    def __init__(self, client_class, iprot_factory, oprot_factory=None):
+        self.client_class = client_class
+        self.iprot_factory = iprot_factory
+        if oprot_factory is None:
+            self.oprot_factory = iprot_factory
+        else:
+            self.oprot_factory = oprot_factory
+
+    def buildProtocol(self, addr):
+        p = self.protocol(self.client_class, self.iprot_factory,
+            self.oprot_factory)
+        p.factory = self
+        return p
+
+
+class ThriftResource(resource.Resource):
+
+    allowedMethods = ('POST',)
+
+    def __init__(self, processor, inputProtocolFactory,
+        outputProtocolFactory=None):
+        resource.Resource.__init__(self)
+        self.inputProtocolFactory = inputProtocolFactory
+        if outputProtocolFactory is None:
+            self.outputProtocolFactory = inputProtocolFactory
+        else:
+            self.outputProtocolFactory = outputProtocolFactory
+        self.processor = processor
+
+    def getChild(self, path, request):
+        return self
+
+    def _cbProcess(self, _, request, tmo):
+        msg = tmo.getvalue()
+        request.setResponseCode(http.OK)
+        request.setHeader("content-type", "application/x-thrift")
+        request.write(msg)
+        request.finish()
+
+    def render_POST(self, request):
+        request.content.seek(0, 0)
+        data = request.content.read()
+        tmi = TTransport.TMemoryBuffer(data)
+        tmo = TTransport.TMemoryBuffer()
+
+        iprot = self.inputProtocolFactory.getProtocol(tmi)
+        oprot = self.outputProtocolFactory.getProtocol(tmo)
+
+        d = self.processor.process(iprot, oprot)
+        d.addCallback(self._cbProcess, request, tmo)
+        return server.NOT_DONE_YET

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
new file mode 100644
index 0000000..2bdfd14
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/TZlibTransport.py
@@ -0,0 +1,249 @@
+#
+# 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.
+#
+
+"""TZlibTransport provides a compressed transport and transport factory
+class, using the python standard library zlib module to implement
+data compression.
+"""
+
+from __future__ import division
+import zlib
+from cStringIO import StringIO
+
+from TTransport import TTransportBase, CReadableTransport
+
+
+class TZlibTransportFactory(object):
+  """Factory transport that builds zlib compressed transports.
+
+  This factory caches the last single client/transport that it was passed
+  and returns the same TZlibTransport object that was created.
+
+  This caching means the TServer class will get the _same_ transport
+  object for both input and output transports from this factory.
+  (For non-threaded scenarios only, since the cache only holds one object)
+
+  The purpose of this caching is to allocate only one TZlibTransport where
+  only one is really needed (since it must have separate read/write buffers),
+  and makes the statistics from getCompSavings() and getCompRatio()
+  easier to understand.
+  """
+  # class scoped cache of last transport given and zlibtransport returned
+  _last_trans = None
+  _last_z = None
+
+  def getTransport(self, trans, compresslevel=9):
+    """Wrap a transport, trans, with the TZlibTransport
+    compressed transport class, returning a new
+    transport to the caller.
+
+    @param compresslevel: The zlib compression level, ranging
+    from 0 (no compression) to 9 (best compression).  Defaults to 9.
+    @type compresslevel: int
+
+    This method returns a TZlibTransport which wraps the
+    passed C{trans} TTransport derived instance.
+    """
+    if trans == self._last_trans:
+      return self._last_z
+    ztrans = TZlibTransport(trans, compresslevel)
+    self._last_trans = trans
+    self._last_z = ztrans
+    return ztrans
+
+
+class TZlibTransport(TTransportBase, CReadableTransport):
+  """Class that wraps a transport with zlib, compressing writes
+  and decompresses reads, using the python standard
+  library zlib module.
+  """
+  # Read buffer size for the python fastbinary C extension,
+  # the TBinaryProtocolAccelerated class.
+  DEFAULT_BUFFSIZE = 4096
+
+  def __init__(self, trans, compresslevel=9):
+    """Create a new TZlibTransport, wrapping C{trans}, another
+    TTransport derived object.
+
+    @param trans: A thrift transport object, i.e. a TSocket() object.
+    @type trans: TTransport
+    @param compresslevel: The zlib compression level, ranging
+    from 0 (no compression) to 9 (best compression).  Default is 9.
+    @type compresslevel: int
+    """
+    self.__trans = trans
+    self.compresslevel = compresslevel
+    self.__rbuf = StringIO()
+    self.__wbuf = StringIO()
+    self._init_zlib()
+    self._init_stats()
+
+  def _reinit_buffers(self):
+    """Internal method to initialize/reset the internal StringIO objects
+    for read and write buffers.
+    """
+    self.__rbuf = StringIO()
+    self.__wbuf = StringIO()
+
+  def _init_stats(self):
+    """Internal method to reset the internal statistics counters
+    for compression ratios and bandwidth savings.
+    """
+    self.bytes_in = 0
+    self.bytes_out = 0
+    self.bytes_in_comp = 0
+    self.bytes_out_comp = 0
+
+  def _init_zlib(self):
+    """Internal method for setting up the zlib compression and
+    decompression objects.
+    """
+    self._zcomp_read = zlib.decompressobj()
+    self._zcomp_write = zlib.compressobj(self.compresslevel)
+
+  def getCompRatio(self):
+    """Get the current measured compression ratios (in,out) from
+    this transport.
+
+    Returns a tuple of:
+    (inbound_compression_ratio, outbound_compression_ratio)
+
+    The compression ratios are computed as:
+        compressed / uncompressed
+
+    E.g., data that compresses by 10x will have a ratio of: 0.10
+    and data that compresses to half of ts original size will
+    have a ratio of 0.5
+
+    None is returned if no bytes have yet been processed in
+    a particular direction.
+    """
+    r_percent, w_percent = (None, None)
+    if self.bytes_in > 0:
+      r_percent = self.bytes_in_comp / self.bytes_in
+    if self.bytes_out > 0:
+      w_percent = self.bytes_out_comp / self.bytes_out
+    return (r_percent, w_percent)
+
+  def getCompSavings(self):
+    """Get the current count of saved bytes due to data
+    compression.
+
+    Returns a tuple of:
+    (inbound_saved_bytes, outbound_saved_bytes)
+
+    Note: if compression is actually expanding your
+    data (only likely with very tiny thrift objects), then
+    the values returned will be negative.
+    """
+    r_saved = self.bytes_in - self.bytes_in_comp
+    w_saved = self.bytes_out - self.bytes_out_comp
+    return (r_saved, w_saved)
+
+  def isOpen(self):
+    """Return the underlying transport's open status"""
+    return self.__trans.isOpen()
+
+  def open(self):
+    """Open the underlying transport"""
+    self._init_stats()
+    return self.__trans.open()
+
+  def listen(self):
+    """Invoke the underlying transport's listen() method"""
+    self.__trans.listen()
+
+  def accept(self):
+    """Accept connections on the underlying transport"""
+    return self.__trans.accept()
+
+  def close(self):
+    """Close the underlying transport,"""
+    self._reinit_buffers()
+    self._init_zlib()
+    return self.__trans.close()
+
+  def read(self, sz):
+    """Read up to sz bytes from the decompressed bytes buffer, and
+    read from the underlying transport if the decompression
+    buffer is empty.
+    """
+    ret = self.__rbuf.read(sz)
+    if len(ret) > 0:
+      return ret
+    # keep reading from transport until something comes back
+    while True:
+      if self.readComp(sz):
+        break
+    ret = self.__rbuf.read(sz)
+    return ret
+
+  def readComp(self, sz):
+    """Read compressed data from the underlying transport, then
+    decompress it and append it to the internal StringIO read buffer
+    """
+    zbuf = self.__trans.read(sz)
+    zbuf = self._zcomp_read.unconsumed_tail + zbuf
+    buf = self._zcomp_read.decompress(zbuf)
+    self.bytes_in += len(zbuf)
+    self.bytes_in_comp += len(buf)
+    old = self.__rbuf.read()
+    self.__rbuf = StringIO(old + buf)
+    if len(old) + len(buf) == 0:
+      return False
+    return True
+
+  def write(self, buf):
+    """Write some bytes, putting them into the internal write
+    buffer for eventual compression.
+    """
+    self.__wbuf.write(buf)
+
+  def flush(self):
+    """Flush any queued up data in the write buffer and ensure the
+    compression buffer is flushed out to the underlying transport
+    """
+    wout = self.__wbuf.getvalue()
+    if len(wout) > 0:
+      zbuf = self._zcomp_write.compress(wout)
+      self.bytes_out += len(wout)
+      self.bytes_out_comp += len(zbuf)
+    else:
+      zbuf = ''
+    ztail = self._zcomp_write.flush(zlib.Z_SYNC_FLUSH)
+    self.bytes_out_comp += len(ztail)
+    if (len(zbuf) + len(ztail)) > 0:
+      self.__wbuf = StringIO()
+      self.__trans.write(zbuf + ztail)
+    self.__trans.flush()
+
+  @property
+  def cstringio_buf(self):
+    """Implement the CReadableTransport interface"""
+    return self.__rbuf
+
+  def cstringio_refill(self, partialread, reqlen):
+    """Implement the CReadableTransport interface for refill"""
+    retstring = partialread
+    if reqlen < self.DEFAULT_BUFFSIZE:
+      retstring += self.read(self.DEFAULT_BUFFSIZE)
+    while len(retstring) < reqlen:
+      retstring += self.read(reqlen - len(retstring))
+    self.__rbuf = StringIO(retstring)
+    return self.__rbuf

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py
new file mode 100644
index 0000000..c9596d9
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/thrift/transport/__init__.py
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+__all__ = ['TTransport', 'TSocket', 'THttpClient', 'TZlibTransport']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/__init__.py
new file mode 100644
index 0000000..a595c84
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/__init__.py
@@ -0,0 +1,18 @@
+# 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.
+
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/exception/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/exception/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/exception/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py b/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py
new file mode 100644
index 0000000..fc4bfc9
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/exception/datapublisherexception.py
@@ -0,0 +1,33 @@
+# 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.
+
+class DataPublisherException(Exception):
+    """
+    Exception to be used during log publishing operations
+    """
+
+    def __init__(self, msg):
+        super(self,  msg)
+        self.message = msg
+
+    def get_message(self):
+        """
+        The message provided when the exception is raised
+        :return: message
+        :rtype: str
+        """
+        return self.message

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/logpublisher.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/logpublisher.py b/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/logpublisher.py
new file mode 100644
index 0000000..050dd9e
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/datapublisher/logpublisher.py
@@ -0,0 +1,273 @@
+# 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.
+
+import os
+import datetime
+from threading import Thread, current_thread
+
+from ..databridge.agent import *
+from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
+from ..util import cartridgeagentutils, cartridgeagentconstants
+from exception.datapublisherexception import DataPublisherException
+
+
+class LogPublisher(Thread):
+
+    def __init__(self, file_path, stream_definition, tenant_id, alias, date_time, member_id):
+        Thread.__init__(self)
+
+        self.log = LogFactory().get_log(__name__)
+
+        self.file_path = file_path
+        self.thrift_publisher = ThriftPublisher(
+            DataPublisherConfiguration.get_instance().monitoring_server_ip,
+            DataPublisherConfiguration.get_instance().monitoring_server_port,
+            DataPublisherConfiguration.get_instance().admin_username,
+            DataPublisherConfiguration.get_instance().admin_password,
+            stream_definition)
+        self.tenant_id = tenant_id
+        self.alias = alias
+        self.datetime = date_time
+        self.member_id = member_id
+
+        self.terminated = False
+
+    def run(self):
+        if os.path.isfile(self.file_path) and os.access(self.file_path, os.R_OK):
+            self.log.info("Starting log publisher for file: " + self.file_path + ", thread: " + current_thread())
+            # open file and keep reading for new entries
+            read_file = open(self.file_path, "r")
+            read_file.seek(os.stat(self.file_path)[6])  # go to the end of the file
+
+            while not self.terminated:
+                where = read_file.tell()  # where the seeker is in the file
+                line = read_file.readline()   # read the current line
+                if not line:
+                    # no new line entered
+                    time.sleep(1)
+                    read_file.seek(where)  # set seeker
+                else:
+                    # new line detected, create event object
+                    event = ThriftEvent()
+                    event.metaData.append(self.member_id)
+                    event.payloadData.append(self.tenant_id)
+                    event.payloadData.append(self.alias)
+                    event.payloadData.append("")
+                    event.payloadData.append(self.datetime)
+                    event.payloadData.append("")
+                    event.payloadData.append(line)
+                    event.payloadData.append("")
+                    event.payloadData.append("")
+                    event.payloadData.append(self.member_id)
+                    event.payloadData.append("")
+
+                    self.thrift_publisher.publish(event)
+
+            self.thrift_publisher.disconnect()  # dicsonnect the publisher upon being terminated
+        else:
+            raise DataPublisherException("Unable to read the file at path %r" % self.file_path)
+
+    def terminate(self):
+        """
+        Allows the LogPublisher thread to be terminated to stop publishing to BAM/CEP. Allow a minimum of 1 second delay
+        to take effect.
+        """
+        self.terminated = True
+
+
+class LogPublisherManager(Thread):
+    """
+    A log publishing thread management thread which maintains a log publisher for each log file. Also defines a stream
+    definition and the BAM/CEP server information for a single publishing context.
+    """
+
+    @staticmethod
+    def define_stream():
+        """
+        Creates a stream definition for Log Publishing
+        :return: A StreamDefinition object with the required attributes added
+        :rtype : StreamDefinition
+        """
+        # stream definition
+        stream_definition = StreamDefinition()
+        valid_tenant_id = LogPublisherManager.get_valid_tenant_id(CartridgeAgentConfiguration().tenant_id)
+        alias = LogPublisherManager.get_alias(CartridgeAgentConfiguration().cluster_id)
+        stream_name = "logs." + valid_tenant_id + "." \
+                      + alias + "." + LogPublisherManager.get_current_date()
+        stream_version = "1.0.0"
+
+        stream_definition.name = stream_name
+        stream_definition.version = stream_version
+        stream_definition.description = "Apache Stratos Instance Log Publisher"
+        stream_definition.add_metadata_attribute("memberId", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("tenantID", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("serverName", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("appName", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("logTime", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("priority", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("message", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("logger", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("ip", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("instance", StreamDefinition.STRING)
+        stream_definition.add_payloaddata_attribute("stacktrace", StreamDefinition.STRING)
+
+        return stream_definition
+
+    def __init__(self, logfile_paths):
+        Thread.__init__(self)
+        self.logfile_paths = logfile_paths
+        self.publishers = {}
+        self.ports = []
+        self.ports.append(DataPublisherConfiguration.get_instance().monitoring_server_port)
+        self.ports.append(DataPublisherConfiguration.get_instance().monitoring_server_secure_port)
+
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+        cartridgeagentutils.wait_until_ports_active(
+            DataPublisherConfiguration.get_instance().monitoring_server_ip,
+            self.ports,
+            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False)))
+
+        ports_active = cartridgeagentutils.check_ports_active(
+            DataPublisherConfiguration.get_instance().monitoring_server_ip,
+            self.ports)
+
+        if not ports_active:
+            raise DataPublisherException("Monitoring server not active, data publishing is aborted")
+
+        self.stream_definition = self.define_stream()
+
+    def run(self):
+        if self.logfile_paths is not None and len(self.logfile_paths):
+            for log_path in self.logfile_paths:
+                # thread for each log file
+                publisher = self.get_publisher(log_path)
+                publisher.start()
+
+    def get_publisher(self, log_path):
+        """
+        Retrieve the publisher for the specified log file path. Creates a new LogPublisher if one is not available
+        :return: The LogPublisher object
+        :rtype : LogPublisher
+        """
+        if log_path not in self.publishers:
+            self.publishers[log_path] = LogPublisher(log_path, self.stream_definition)
+
+        return self.publishers[log_path]
+
+    def terminate_publisher(self, log_path):
+        """
+        Terminates the LogPublisher thread associated with the specified log file
+        """
+        if log_path in self.publishers:
+            self.publishers[log_path].terminate()
+
+    def terminate_all_publishers(self):
+        """
+        Terminates all LogPublisher threads
+        """
+        for publisher in self.publishers:
+            publisher.terminate()
+
+    @staticmethod
+    def get_valid_tenant_id(tenant_id):
+        if tenant_id == cartridgeagentconstants.INVALID_TENANT_ID \
+                or tenant_id == cartridgeagentconstants.SUPER_TENANT_ID:
+            return "0"
+
+        return tenant_id
+
+    @staticmethod
+    def get_alias(cluster_id):
+        try:
+            alias = cluster_id.split("\\.")[0]
+        except:
+            alias = cluster_id
+
+        return alias
+
+    @staticmethod
+    def get_current_date():
+        """
+        Returns the current date formatted as yyyy-MM-dd
+        :return: Formatted date string
+        :rtype : str
+        """
+        return datetime.date.today().strftime(cartridgeagentconstants.DATE_FORMAT)
+
+
+class DataPublisherConfiguration:
+    """
+    A singleton implementation to access configuration information for data publishing to BAM/CEP
+    TODO: perfect singleton impl ex: Borg
+    """
+
+    __instance = None
+    log = LogFactory().get_log(__name__)
+
+    @staticmethod
+    def get_instance():
+        """
+        Singleton instance retriever
+        :return: Instance
+        :rtype : DataPublisherConfiguration
+        """
+        if DataPublisherConfiguration.__instance is None:
+            DataPublisherConfiguration.__instance = DataPublisherConfiguration()
+
+        return DataPublisherConfiguration.__instance
+
+    def __init__(self):
+        self.enabled = False
+        self.monitoring_server_ip = None
+        self.monitoring_server_port = None
+        self.monitoring_server_secure_port = None
+        self.admin_username = None
+        self.admin_password = None
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+        self.read_config()
+
+    def read_config(self):
+        self.enabled = True if self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_PUBLISHER_ENABLED, False).strip().lower() == "true" else False
+        if not self.enabled:
+            DataPublisherConfiguration.log.info("Data Publisher disabled")
+            return
+
+        DataPublisherConfiguration.log.info("Data Publisher enabled")
+
+        self.monitoring_server_ip = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_RECEIVER_IP, False)
+        if self.monitoring_server_ip is None or self.monitoring_server_ip.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_RECEIVER_IP)
+
+        self.monitoring_server_port = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_RECEIVER_PORT, False)
+        if self.monitoring_server_port is None or self.monitoring_server_port.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_RECEIVER_PORT)
+
+        self.monitoring_server_secure_port = self.cartridge_agent_config.read_property("monitoring.server.secure.port", False)
+        if self.monitoring_server_secure_port is None or self.monitoring_server_secure_port.strip() == "":
+            raise RuntimeError("System property not found: monitoring.server.secure.port")
+
+        self.admin_username = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_SERVER_ADMIN_USERNAME, False)
+        if self.admin_username is None or self.admin_username.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_SERVER_ADMIN_USERNAME)
+
+        self.admin_password = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_SERVER_ADMIN_PASSWORD, False)
+        if self.admin_password is None or self.admin_password.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_SERVER_ADMIN_PASSWORD)
+
+        DataPublisherConfiguration.log.info("Data Publisher configuration initialized")

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/event/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/__init__.py
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py
new file mode 100644
index 0000000..024e1e4
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py
@@ -0,0 +1,77 @@
+# 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.
+
+import json
+
+
+class ArtifactUpdatedEvent:
+    def __init__(self):
+        self.cluster_id = None
+        """ :type : str  """
+        self.status = None
+        """ :type : str  """
+        self.repo_username = None
+        """ :type : str  """
+        self.repo_password = None
+        """ :type : str  """
+        self.repo_url = None
+        """ :type : str  """
+        self.tenant_id = None
+        """ :type : int  """
+        self.commit_enabled = None
+        """ :type : bool  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        instance = ArtifactUpdatedEvent()
+
+        instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+        instance.status = json_obj["status"] if "status" in json_obj else None
+        instance.repo_username = json_obj["repoUserName"] if "repoUserName" in json_obj else None
+        instance.repo_password = json_obj["repoPassword"] if "repoPassword" in json_obj else None
+        instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None
+        instance.repo_url = json_obj["repoUrl"] if "repoUrl" in json_obj else ""
+        instance.commit_enabled = json_obj["commitEnabled"] if "commitEnabled" in json_obj else None
+
+        return instance
+
+
+class InstanceCleanupClusterEvent:
+    def __init__(self, cluster_id):
+        self.cluster_id = cluster_id
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        c_id = json_obj["clusterId"] if "clusterId" in json_obj else None
+
+        return InstanceCleanupClusterEvent(c_id)
+
+
+class InstanceCleanupMemberEvent:
+    def __init__(self, member_id):
+        self.member_id = member_id
+        """ :type : str  """
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        m_id = json_obj["memberId"] if "memberId" in json_obj else None
+
+        return InstanceCleanupMemberEvent(m_id)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/status/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/status/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/status/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/event/instance/status/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+


[24/50] [abbrv] git commit: Modified agentgithandler to use the scheduledservice and the abstractasyncscheduledtask classes

Posted by im...@apache.org.
Modified agentgithandler to use the scheduledservice and the abstractasyncscheduledtask classes


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

Branch: refs/heads/master
Commit: 3527184018067b8c699d7916fc75025577923301
Parents: 4446d24
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Mon Oct 20 15:45:24 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Mon Oct 20 15:45:24 2014 +0530

----------------------------------------------------------------------
 .../modules/artifactmgt/git/agentgithandler.py          | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/35271840/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
index 9e95be0..6da9c58 100644
--- a/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
@@ -24,7 +24,7 @@ from ... util.log import LogFactory
 from ... util import cartridgeagentutils, extensionutils, cartridgeagentconstants
 from gitrepository import GitRepository
 from ... config import cartridgeagentconfiguration
-from ... util.asyncscheduledtask import AsyncScheduledTask
+from ... util.asyncscheduledtask import AbstractAsyncScheduledTask, ScheduledExecutor
 from ... artifactmgt.repositoryinformation import RepositoryInformation
 
 class AgentGitHandler:
@@ -449,7 +449,7 @@ class AgentGitHandler:
         if repo_context.scheduled_update_task is None:
             #TODO: make thread safe
             artifact_update_task = ArtifactUpdateTask(repo_info, auto_checkout, auto_commit)
-            async_task = AsyncScheduledTask(update_interval, artifact_update_task)
+            async_task = ScheduledExecutor(update_interval, artifact_update_task)
 
             repo_context.scheduled_update_task = async_task
             async_task.start()
@@ -481,16 +481,18 @@ class AgentGitHandler:
         return True
 
 
-class ArtifactUpdateTask(Thread):
+class ArtifactUpdateTask(AbstractAsyncScheduledTask):
+    """
+    Checks if the autocheckout and autocommit are enabled and executes respective tasks
+    """
 
     def __init__(self, repo_info, auto_checkout, auto_commit):
         self.log = LogFactory().get_log(__name__)
-        Thread.__init__(self)
         self.repo_info = repo_info
         self.auto_checkout = auto_checkout
         self.auto_commit = auto_commit
 
-    def run(self):
+    def execute_task(self):
         try:
             if self.auto_checkout:
                 AgentGitHandler.checkout(self.repo_info)


[37/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
deleted file mode 100644
index b8c13c1..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
+++ /dev/null
@@ -1,1495 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ttypes import *
-from ...thrift.Thrift import TProcessor
-from ...thrift.transport import TTransport
-from ..Exception import ttypes
-from .. import Data
-
-try:
-  from ...thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-
-class Iface:
-  def connect(self, userName, password):
-    """
-    Parameters:
-     - userName
-     - password
-    """
-    pass
-
-  def disconnect(self, sessionId):
-    """
-    Parameters:
-     - sessionId
-    """
-    pass
-
-  def defineStream(self, sessionId, streamDefinition):
-    """
-    Parameters:
-     - sessionId
-     - streamDefinition
-    """
-    pass
-
-  def findStreamId(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    pass
-
-  def publish(self, eventBundle):
-    """
-    Parameters:
-     - eventBundle
-    """
-    pass
-
-  def deleteStreamById(self, sessionId, streamId):
-    """
-    Parameters:
-     - sessionId
-     - streamId
-    """
-    pass
-
-  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    pass
-
-
-class Client(Iface):
-  def __init__(self, iprot, oprot=None):
-    self._iprot = self._oprot = iprot
-    if oprot is not None:
-      self._oprot = oprot
-    self._seqid = 0
-
-  def connect(self, userName, password):
-    """
-    Parameters:
-     - userName
-     - password
-    """
-    self.send_connect(userName, password)
-    return self.recv_connect()
-
-  def send_connect(self, userName, password):
-    self._oprot.writeMessageBegin('connect', TMessageType.CALL, self._seqid)
-    args = connect_args()
-    args.userName = userName
-    args.password = password
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_connect(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = connect_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.ae is not None:
-      raise result.ae
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "connect failed: unknown result");
-
-  def disconnect(self, sessionId):
-    """
-    Parameters:
-     - sessionId
-    """
-    self.send_disconnect(sessionId)
-    self.recv_disconnect()
-
-  def send_disconnect(self, sessionId):
-    self._oprot.writeMessageBegin('disconnect', TMessageType.CALL, self._seqid)
-    args = disconnect_args()
-    args.sessionId = sessionId
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_disconnect(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = disconnect_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    return
-
-  def defineStream(self, sessionId, streamDefinition):
-    """
-    Parameters:
-     - sessionId
-     - streamDefinition
-    """
-    self.send_defineStream(sessionId, streamDefinition)
-    return self.recv_defineStream()
-
-  def send_defineStream(self, sessionId, streamDefinition):
-    self._oprot.writeMessageBegin('defineStream', TMessageType.CALL, self._seqid)
-    args = defineStream_args()
-    args.sessionId = sessionId
-    args.streamDefinition = streamDefinition
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_defineStream(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = defineStream_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.ade is not None:
-      raise result.ade
-    if result.mtd is not None:
-      raise result.mtd
-    if result.tde is not None:
-      raise result.tde
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "defineStream failed: unknown result");
-
-  def findStreamId(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    self.send_findStreamId(sessionId, streamName, streamVersion)
-    return self.recv_findStreamId()
-
-  def send_findStreamId(self, sessionId, streamName, streamVersion):
-    self._oprot.writeMessageBegin('findStreamId', TMessageType.CALL, self._seqid)
-    args = findStreamId_args()
-    args.sessionId = sessionId
-    args.streamName = streamName
-    args.streamVersion = streamVersion
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_findStreamId(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = findStreamId_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.tnde is not None:
-      raise result.tnde
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "findStreamId failed: unknown result");
-
-  def publish(self, eventBundle):
-    """
-    Parameters:
-     - eventBundle
-    """
-    self.send_publish(eventBundle)
-    self.recv_publish()
-
-  def send_publish(self, eventBundle):
-    self._oprot.writeMessageBegin('publish', TMessageType.CALL, self._seqid)
-    args = publish_args()
-    args.eventBundle = eventBundle
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_publish(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = publish_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.ue is not None:
-      raise result.ue
-    if result.se is not None:
-      raise result.se
-    return
-
-  def deleteStreamById(self, sessionId, streamId):
-    """
-    Parameters:
-     - sessionId
-     - streamId
-    """
-    self.send_deleteStreamById(sessionId, streamId)
-    return self.recv_deleteStreamById()
-
-  def send_deleteStreamById(self, sessionId, streamId):
-    self._oprot.writeMessageBegin('deleteStreamById', TMessageType.CALL, self._seqid)
-    args = deleteStreamById_args()
-    args.sessionId = sessionId
-    args.streamId = streamId
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_deleteStreamById(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = deleteStreamById_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamById failed: unknown result");
-
-  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    """
-    Parameters:
-     - sessionId
-     - streamName
-     - streamVersion
-    """
-    self.send_deleteStreamByNameVersion(sessionId, streamName, streamVersion)
-    return self.recv_deleteStreamByNameVersion()
-
-  def send_deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
-    self._oprot.writeMessageBegin('deleteStreamByNameVersion', TMessageType.CALL, self._seqid)
-    args = deleteStreamByNameVersion_args()
-    args.sessionId = sessionId
-    args.streamName = streamName
-    args.streamVersion = streamVersion
-    args.write(self._oprot)
-    self._oprot.writeMessageEnd()
-    self._oprot.trans.flush()
-
-  def recv_deleteStreamByNameVersion(self):
-    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
-    if mtype == TMessageType.EXCEPTION:
-      x = TApplicationException()
-      x.read(self._iprot)
-      self._iprot.readMessageEnd()
-      raise x
-    result = deleteStreamByNameVersion_result()
-    result.read(self._iprot)
-    self._iprot.readMessageEnd()
-    if result.success is not None:
-      return result.success
-    if result.se is not None:
-      raise result.se
-    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamByNameVersion failed: unknown result");
-
-
-class Processor(Iface, TProcessor):
-  def __init__(self, handler):
-    self._handler = handler
-    self._processMap = {}
-    self._processMap["connect"] = Processor.process_connect
-    self._processMap["disconnect"] = Processor.process_disconnect
-    self._processMap["defineStream"] = Processor.process_defineStream
-    self._processMap["findStreamId"] = Processor.process_findStreamId
-    self._processMap["publish"] = Processor.process_publish
-    self._processMap["deleteStreamById"] = Processor.process_deleteStreamById
-    self._processMap["deleteStreamByNameVersion"] = Processor.process_deleteStreamByNameVersion
-
-  def process(self, iprot, oprot):
-    (name, type, seqid) = iprot.readMessageBegin()
-    if name not in self._processMap:
-      iprot.skip(TType.STRUCT)
-      iprot.readMessageEnd()
-      x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
-      oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
-      x.write(oprot)
-      oprot.writeMessageEnd()
-      oprot.trans.flush()
-      return
-    else:
-      self._processMap[name](self, seqid, iprot, oprot)
-    return True
-
-  def process_connect(self, seqid, iprot, oprot):
-    args = connect_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = connect_result()
-    try:
-      result.success = self._handler.connect(args.userName, args.password)
-    except ttypes.ThriftAuthenticationException, ae:
-      result.ae = ae
-    oprot.writeMessageBegin("connect", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_disconnect(self, seqid, iprot, oprot):
-    args = disconnect_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = disconnect_result()
-    self._handler.disconnect(args.sessionId)
-    oprot.writeMessageBegin("disconnect", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_defineStream(self, seqid, iprot, oprot):
-    args = defineStream_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = defineStream_result()
-    try:
-      result.success = self._handler.defineStream(args.sessionId, args.streamDefinition)
-    except ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ade:
-      result.ade = ade
-    except ttypes.ThriftMalformedStreamDefinitionException, mtd:
-      result.mtd = mtd
-    except ttypes.ThriftStreamDefinitionException, tde:
-      result.tde = tde
-    except ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("defineStream", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_findStreamId(self, seqid, iprot, oprot):
-    args = findStreamId_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = findStreamId_result()
-    try:
-      result.success = self._handler.findStreamId(args.sessionId, args.streamName, args.streamVersion)
-    except ttypes.ThriftNoStreamDefinitionExistException, tnde:
-      result.tnde = tnde
-    except ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("findStreamId", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_publish(self, seqid, iprot, oprot):
-    args = publish_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = publish_result()
-    try:
-      self._handler.publish(args.eventBundle)
-    except ttypes.ThriftUndefinedEventTypeException, ue:
-      result.ue = ue
-    except ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("publish", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_deleteStreamById(self, seqid, iprot, oprot):
-    args = deleteStreamById_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = deleteStreamById_result()
-    try:
-      result.success = self._handler.deleteStreamById(args.sessionId, args.streamId)
-    except ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("deleteStreamById", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-  def process_deleteStreamByNameVersion(self, seqid, iprot, oprot):
-    args = deleteStreamByNameVersion_args()
-    args.read(iprot)
-    iprot.readMessageEnd()
-    result = deleteStreamByNameVersion_result()
-    try:
-      result.success = self._handler.deleteStreamByNameVersion(args.sessionId, args.streamName, args.streamVersion)
-    except ttypes.ThriftSessionExpiredException, se:
-      result.se = se
-    oprot.writeMessageBegin("deleteStreamByNameVersion", TMessageType.REPLY, seqid)
-    result.write(oprot)
-    oprot.writeMessageEnd()
-    oprot.trans.flush()
-
-
-# HELPER FUNCTIONS AND STRUCTURES
-
-class connect_args:
-  """
-  Attributes:
-   - userName
-   - password
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'userName', None, None, ), # 1
-    (2, TType.STRING, 'password', None, None, ), # 2
-  )
-
-  def __init__(self, userName=None, password=None,):
-    self.userName = userName
-    self.password = password
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.userName = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.password = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('connect_args')
-    if self.userName is not None:
-      oprot.writeFieldBegin('userName', TType.STRING, 1)
-      oprot.writeString(self.userName)
-      oprot.writeFieldEnd()
-    if self.password is not None:
-      oprot.writeFieldBegin('password', TType.STRING, 2)
-      oprot.writeString(self.password)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class connect_result:
-  """
-  Attributes:
-   - success
-   - ae
-  """
-
-  thrift_spec = (
-    (0, TType.STRING, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'ae', (ttypes.ThriftAuthenticationException, ttypes.ThriftAuthenticationException.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, success=None, ae=None,):
-    self.success = success
-    self.ae = ae
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.STRING:
-          self.success = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.ae = ttypes.ThriftAuthenticationException()
-          self.ae.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('connect_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.STRING, 0)
-      oprot.writeString(self.success)
-      oprot.writeFieldEnd()
-    if self.ae is not None:
-      oprot.writeFieldBegin('ae', TType.STRUCT, 1)
-      self.ae.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class disconnect_args:
-  """
-  Attributes:
-   - sessionId
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-  )
-
-  def __init__(self, sessionId=None,):
-    self.sessionId = sessionId
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('disconnect_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class disconnect_result:
-
-  thrift_spec = (
-  )
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('disconnect_result')
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class defineStream_args:
-  """
-  Attributes:
-   - sessionId
-   - streamDefinition
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamDefinition', None, None, ), # 2
-  )
-
-  def __init__(self, sessionId=None, streamDefinition=None,):
-    self.sessionId = sessionId
-    self.streamDefinition = streamDefinition
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamDefinition = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('defineStream_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamDefinition is not None:
-      oprot.writeFieldBegin('streamDefinition', TType.STRING, 2)
-      oprot.writeString(self.streamDefinition)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class defineStream_result:
-  """
-  Attributes:
-   - success
-   - ade
-   - mtd
-   - tde
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.STRING, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'ade', (ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'mtd', (ttypes.ThriftMalformedStreamDefinitionException, ttypes.ThriftMalformedStreamDefinitionException.thrift_spec), None, ), # 2
-    (3, TType.STRUCT, 'tde', (ttypes.ThriftStreamDefinitionException, ttypes.ThriftStreamDefinitionException.thrift_spec), None, ), # 3
-    (4, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 4
-  )
-
-  def __init__(self, success=None, ade=None, mtd=None, tde=None, se=None,):
-    self.success = success
-    self.ade = ade
-    self.mtd = mtd
-    self.tde = tde
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.STRING:
-          self.success = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.ade = ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException()
-          self.ade.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.mtd = ttypes.ThriftMalformedStreamDefinitionException()
-          self.mtd.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRUCT:
-          self.tde = ttypes.ThriftStreamDefinitionException()
-          self.tde.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 4:
-        if ftype == TType.STRUCT:
-          self.se = ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('defineStream_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.STRING, 0)
-      oprot.writeString(self.success)
-      oprot.writeFieldEnd()
-    if self.ade is not None:
-      oprot.writeFieldBegin('ade', TType.STRUCT, 1)
-      self.ade.write(oprot)
-      oprot.writeFieldEnd()
-    if self.mtd is not None:
-      oprot.writeFieldBegin('mtd', TType.STRUCT, 2)
-      self.mtd.write(oprot)
-      oprot.writeFieldEnd()
-    if self.tde is not None:
-      oprot.writeFieldBegin('tde', TType.STRUCT, 3)
-      self.tde.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 4)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class findStreamId_args:
-  """
-  Attributes:
-   - sessionId
-   - streamName
-   - streamVersion
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamName', None, None, ), # 2
-    (3, TType.STRING, 'streamVersion', None, None, ), # 3
-  )
-
-  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
-    self.sessionId = sessionId
-    self.streamName = streamName
-    self.streamVersion = streamVersion
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamName = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRING:
-          self.streamVersion = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('findStreamId_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamName is not None:
-      oprot.writeFieldBegin('streamName', TType.STRING, 2)
-      oprot.writeString(self.streamName)
-      oprot.writeFieldEnd()
-    if self.streamVersion is not None:
-      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
-      oprot.writeString(self.streamVersion)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class findStreamId_result:
-  """
-  Attributes:
-   - success
-   - tnde
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.STRING, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'tnde', (ttypes.ThriftNoStreamDefinitionExistException, ttypes.ThriftNoStreamDefinitionExistException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
-  )
-
-  def __init__(self, success=None, tnde=None, se=None,):
-    self.success = success
-    self.tnde = tnde
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.STRING:
-          self.success = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.tnde = ttypes.ThriftNoStreamDefinitionExistException()
-          self.tnde.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.se = ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('findStreamId_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.STRING, 0)
-      oprot.writeString(self.success)
-      oprot.writeFieldEnd()
-    if self.tnde is not None:
-      oprot.writeFieldBegin('tnde', TType.STRUCT, 1)
-      self.tnde.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 2)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class publish_args:
-  """
-  Attributes:
-   - eventBundle
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRUCT, 'eventBundle', (Data.ttypes.ThriftEventBundle, Data.ttypes.ThriftEventBundle.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, eventBundle=None,):
-    self.eventBundle = eventBundle
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRUCT:
-          self.eventBundle = Data.ttypes.ThriftEventBundle()
-          self.eventBundle.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('publish_args')
-    if self.eventBundle is not None:
-      oprot.writeFieldBegin('eventBundle', TType.STRUCT, 1)
-      self.eventBundle.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class publish_result:
-  """
-  Attributes:
-   - ue
-   - se
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRUCT, 'ue', (ttypes.ThriftUndefinedEventTypeException, ttypes.ThriftUndefinedEventTypeException.thrift_spec), None, ), # 1
-    (2, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
-  )
-
-  def __init__(self, ue=None, se=None,):
-    self.ue = ue
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRUCT:
-          self.ue = ttypes.ThriftUndefinedEventTypeException()
-          self.ue.read(iprot)
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRUCT:
-          self.se = ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('publish_result')
-    if self.ue is not None:
-      oprot.writeFieldBegin('ue', TType.STRUCT, 1)
-      self.ue.write(oprot)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 2)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamById_args:
-  """
-  Attributes:
-   - sessionId
-   - streamId
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamId', None, None, ), # 2
-  )
-
-  def __init__(self, sessionId=None, streamId=None,):
-    self.sessionId = sessionId
-    self.streamId = streamId
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamById_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamId is not None:
-      oprot.writeFieldBegin('streamId', TType.STRING, 2)
-      oprot.writeString(self.streamId)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamById_result:
-  """
-  Attributes:
-   - success
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.BOOL, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, success=None, se=None,):
-    self.success = success
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.BOOL:
-          self.success = iprot.readBool();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.se = ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamById_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.BOOL, 0)
-      oprot.writeBool(self.success)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 1)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamByNameVersion_args:
-  """
-  Attributes:
-   - sessionId
-   - streamName
-   - streamVersion
-  """
-
-  thrift_spec = (
-    None, # 0
-    (1, TType.STRING, 'sessionId', None, None, ), # 1
-    (2, TType.STRING, 'streamName', None, None, ), # 2
-    (3, TType.STRING, 'streamVersion', None, None, ), # 3
-  )
-
-  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
-    self.sessionId = sessionId
-    self.streamName = streamName
-    self.streamVersion = streamVersion
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.sessionId = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.STRING:
-          self.streamName = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      elif fid == 3:
-        if ftype == TType.STRING:
-          self.streamVersion = iprot.readString();
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamByNameVersion_args')
-    if self.sessionId is not None:
-      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
-      oprot.writeString(self.sessionId)
-      oprot.writeFieldEnd()
-    if self.streamName is not None:
-      oprot.writeFieldBegin('streamName', TType.STRING, 2)
-      oprot.writeString(self.streamName)
-      oprot.writeFieldEnd()
-    if self.streamVersion is not None:
-      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
-      oprot.writeString(self.streamVersion)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)
-
-class deleteStreamByNameVersion_result:
-  """
-  Attributes:
-   - success
-   - se
-  """
-
-  thrift_spec = (
-    (0, TType.BOOL, 'success', None, None, ), # 0
-    (1, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
-  )
-
-  def __init__(self, success=None, se=None,):
-    self.success = success
-    self.se = se
-
-  def read(self, iprot):
-    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
-      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
-      return
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 0:
-        if ftype == TType.BOOL:
-          self.success = iprot.readBool();
-        else:
-          iprot.skip(ftype)
-      elif fid == 1:
-        if ftype == TType.STRUCT:
-          self.se = ttypes.ThriftSessionExpiredException()
-          self.se.read(iprot)
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
-      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStructBegin('deleteStreamByNameVersion_result')
-    if self.success is not None:
-      oprot.writeFieldBegin('success', TType.BOOL, 0)
-      oprot.writeBool(self.success)
-      oprot.writeFieldEnd()
-    if self.se is not None:
-      oprot.writeFieldBegin('se', TType.STRUCT, 1)
-      self.se.write(oprot)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()
-
-  def validate(self):
-    return
-
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, value)
-      for key, value in self.__dict__.iteritems()]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
-
-  def __ne__(self, other):
-    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
deleted file mode 100644
index c321ae1..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-__all__ = ['ttypes', 'constants', 'ThriftSecureEventTransmissionService']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
deleted file mode 100644
index 36943ba..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
deleted file mode 100644
index 37ac241..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# Autogenerated by Thrift Compiler (0.9.1)
-#
-# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-#
-#  options string: py
-#
-
-from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
-from ..Data import ttypes
-from ..Exception import ttypes
-
-
-from ...thrift.transport import TTransport
-from ...thrift.protocol import TBinaryProtocol, TProtocol
-try:
-  from thrift.protocol import fastbinary
-except:
-  fastbinary = None
-
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/__init__.py
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/publisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/publisher.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/publisher.py
deleted file mode 100644
index 325b05d..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/publisher.py
+++ /dev/null
@@ -1,111 +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.
-
-import time
-import sys
-
-sys.path.append("gen")
-
-from gen.ThriftSecureEventTransmissionService import ThriftSecureEventTransmissionService
-from gen.Data.ttypes import ThriftEventBundle
-
-from thrift.transport import TSSLSocket
-from thrift.transport import TTransport
-from thrift.protocol import TBinaryProtocol
-
-
-# Define publisher class
-class Publisher:
-    client = None
-
-    def __init__(self, ip, port):
-        # Make SSL socket
-        self.socket = TSSLSocket.TSSLSocket(ip, port, False)
-        # Buffering is critical. Raw sockets are very slow
-        self.transport = TTransport.TBufferedTransport(self.socket)
-        # Wrap in a protocol
-        self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
-        self.sessionId = None
-        self.streamId = None
-
-    def connect(self, username, password):
-        # Create a client to use the protocol encoder
-        Publisher.client = ThriftSecureEventTransmissionService.Client(self.protocol)
-
-        # Make connection
-        self.socket.open()
-        self.transport.open()
-        self.sessionId = Publisher.client.connect(username, password)
-
-    def defineStream(self, streamDef):
-        # Create Stream Definition
-        self.streamId = Publisher.client.defineStream(self.sessionId, streamDef)
-
-    def publish(self, event):
-        # Build thrift event bundle
-        #event = EventBundle()
-        event.setSessionId(self.sessionId)
-        event.setEventNum(0)
-        event.addStringAttribute(self.streamId)
-        event.addLongAttribute(time.time() * 1000)
-        #event.addStringAttribute(msg)
-        # Publish
-        Publisher.client.publish(event.getEventBundle())
-
-    def disconnect(self):
-        # Disconnect
-        Publisher.client.disconnect(self.sessionId)
-        self.transport.close()
-        self.socket.close()
-
-
-class EventBundle:
-    __sessionId = ""
-    __eventNum = 0
-    __intAttributeList = []
-    __longAttributeList = []
-    __doubleAttributeList = []
-    __boolAttributeList = []
-    __stringAttributeList = []
-    __arbitraryDataMapMap = None
-
-    def setSessionId(self, sessionId):
-        self.__sessionId = sessionId
-
-    def setEventNum(self, num):
-        self.__eventNum = num
-
-    def addIntAttribute(self, attr):
-        self.__intAttributeList.append(attr)
-
-    def addLongAttribute(self, attr):
-        self.__longAttributeList.append(attr)
-
-    def addDoubleAttribute(self, attr):
-        self.__doubleAttributeList.append(attr)
-
-    def addBoolAttribute(self, attr):
-        self.__boolAttributeList.append(attr)
-
-    def addStringAttribute(self, attr):
-        self.__stringAttributeList.append(attr)
-
-    def getEventBundle(self):
-        return ThriftEventBundle(self.__sessionId, self.__eventNum, self.__intAttributeList,
-                                             self.__longAttributeList, self.__doubleAttributeList,
-                                             self.__boolAttributeList, self.__stringAttributeList,
-                                             self.__arbitraryDataMapMap)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py
deleted file mode 100644
index da8d283..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py
+++ /dev/null
@@ -1,35 +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.
-#
-
-from os import path
-from SCons.Builder import Builder
-
-
-def scons_env(env, add=''):
-  opath = path.dirname(path.abspath('$TARGET'))
-  lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE'
-  cppbuild = Builder(action=lstr)
-  env.Append(BUILDERS={'ThriftCpp': cppbuild})
-
-
-def gen_cpp(env, dir, file):
-  scons_env(env)
-  suffixes = ['_types.h', '_types.cpp']
-  targets = map(lambda s: 'gen-cpp/' + file + s, suffixes)
-  return env.ThriftCpp(targets, dir + file + '.thrift')

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py
deleted file mode 100644
index 8a58d89..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py
+++ /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.
-#
-
-from protocol import TBinaryProtocol
-from transport import TTransport
-
-
-def serialize(thrift_object,
-              protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
-    transport = TTransport.TMemoryBuffer()
-    protocol = protocol_factory.getProtocol(transport)
-    thrift_object.write(protocol)
-    return transport.getvalue()
-
-
-def deserialize(base,
-                buf,
-                protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
-    transport = TTransport.TMemoryBuffer(buf)
-    protocol = protocol_factory.getProtocol(transport)
-    base.read(protocol)
-    return base

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py
deleted file mode 100644
index 8d9f5ed..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py
+++ /dev/null
@@ -1,153 +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.
-#
-
-from cStringIO import StringIO
-import logging
-import socket
-import struct
-
-from .transport import TTransport
-from .transport.TTransport import TTransportException
-
-from tornado import gen
-from tornado import iostream
-from tornado import netutil
-
-
-class TTornadoStreamTransport(TTransport.TTransportBase):
-    """a framed, buffered transport over a Tornado stream"""
-    def __init__(self, host, port, stream=None):
-        self.host = host
-        self.port = port
-        self.is_queuing_reads = False
-        self.read_queue = []
-        self.__wbuf = StringIO()
-
-        # servers provide a ready-to-go stream
-        self.stream = stream
-        if self.stream is not None:
-            self._set_close_callback()
-
-    # not the same number of parameters as TTransportBase.open
-    def open(self, callback):
-        logging.debug('socket connecting')
-        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
-        self.stream = iostream.IOStream(sock)
-
-        def on_close_in_connect(*_):
-            message = 'could not connect to {}:{}'.format(self.host, self.port)
-            raise TTransportException(
-                type=TTransportException.NOT_OPEN,
-                message=message)
-        self.stream.set_close_callback(on_close_in_connect)
-
-        def finish(*_):
-            self._set_close_callback()
-            callback()
-
-        self.stream.connect((self.host, self.port), callback=finish)
-
-    def _set_close_callback(self):
-        def on_close():
-            raise TTransportException(
-                type=TTransportException.END_OF_FILE,
-                message='socket closed')
-        self.stream.set_close_callback(self.close)
-
-    def close(self):
-        # don't raise if we intend to close
-        self.stream.set_close_callback(None)
-        self.stream.close()
-
-    def read(self, _):
-        # The generated code for Tornado shouldn't do individual reads -- only
-        # frames at a time
-        assert "you're doing it wrong" is True
-
-    @gen.engine
-    def readFrame(self, callback):
-        self.read_queue.append(callback)
-        logging.debug('read queue: %s', self.read_queue)
-
-        if self.is_queuing_reads:
-            # If a read is already in flight, then the while loop below should
-            # pull it from self.read_queue
-            return
-
-        self.is_queuing_reads = True
-        while self.read_queue:
-            next_callback = self.read_queue.pop()
-            result = yield gen.Task(self._readFrameFromStream)
-            next_callback(result)
-        self.is_queuing_reads = False
-
-    @gen.engine
-    def _readFrameFromStream(self, callback):
-        logging.debug('_readFrameFromStream')
-        frame_header = yield gen.Task(self.stream.read_bytes, 4)
-        frame_length, = struct.unpack('!i', frame_header)
-        logging.debug('received frame header, frame length = %i', frame_length)
-        frame = yield gen.Task(self.stream.read_bytes, frame_length)
-        logging.debug('received frame payload')
-        callback(frame)
-
-    def write(self, buf):
-        self.__wbuf.write(buf)
-
-    def flush(self, callback=None):
-        wout = self.__wbuf.getvalue()
-        wsz = len(wout)
-        # reset wbuf before write/flush to preserve state on underlying failure
-        self.__wbuf = StringIO()
-        # N.B.: Doing this string concatenation is WAY cheaper than making
-        # two separate calls to the underlying socket object. Socket writes in
-        # Python turn out to be REALLY expensive, but it seems to do a pretty
-        # good job of managing string buffer operations without excessive copies
-        buf = struct.pack("!i", wsz) + wout
-
-        logging.debug('writing frame length = %i', wsz)
-        self.stream.write(buf, callback)
-
-
-class TTornadoServer(netutil.TCPServer):
-    def __init__(self, processor, iprot_factory, oprot_factory=None,
-                 *args, **kwargs):
-        super(TTornadoServer, self).__init__(*args, **kwargs)
-
-        self._processor = processor
-        self._iprot_factory = iprot_factory
-        self._oprot_factory = (oprot_factory if oprot_factory is not None
-                               else iprot_factory)
-
-    def handle_stream(self, stream, address):
-        try:
-            host, port = address
-            trans = TTornadoStreamTransport(host=host, port=port, stream=stream)
-            oprot = self._oprot_factory.getProtocol(trans)
-
-            def next_pass():
-                if not trans.stream.closed():
-                    self._processor.process(trans, self._iprot_factory, oprot,
-                                            callback=next_pass)
-
-            next_pass()
-
-        except Exception:
-            logging.exception('thrift exception in handle_stream')
-            trans.close()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py
deleted file mode 100644
index 9890af7..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py
+++ /dev/null
@@ -1,170 +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.
-#
-
-import sys
-
-
-class TType:
-  STOP   = 0
-  VOID   = 1
-  BOOL   = 2
-  BYTE   = 3
-  I08    = 3
-  DOUBLE = 4
-  I16    = 6
-  I32    = 8
-  I64    = 10
-  STRING = 11
-  UTF7   = 11
-  STRUCT = 12
-  MAP    = 13
-  SET    = 14
-  LIST   = 15
-  UTF8   = 16
-  UTF16  = 17
-
-  _VALUES_TO_NAMES = ('STOP',
-                      'VOID',
-                      'BOOL',
-                      'BYTE',
-                      'DOUBLE',
-                      None,
-                      'I16',
-                      None,
-                      'I32',
-                      None,
-                     'I64',
-                     'STRING',
-                     'STRUCT',
-                     'MAP',
-                     'SET',
-                     'LIST',
-                     'UTF8',
-                     'UTF16')
-
-
-class TMessageType:
-  CALL = 1
-  REPLY = 2
-  EXCEPTION = 3
-  ONEWAY = 4
-
-
-class TProcessor:
-  """Base class for procsessor, which works on two streams."""
-
-  def process(iprot, oprot):
-    pass
-
-
-class TException(Exception):
-  """Base class for all thrift exceptions."""
-
-  # BaseException.message is deprecated in Python v[2.6,3.0)
-  if (2, 6, 0) <= sys.version_info < (3, 0):
-    def _get_message(self):
-      return self._message
-
-    def _set_message(self, message):
-      self._message = message
-    message = property(_get_message, _set_message)
-
-  def __init__(self, message=None):
-    Exception.__init__(self, message)
-    self.message = message
-
-
-class TApplicationException(TException):
-  """Application level thrift exceptions."""
-
-  UNKNOWN = 0
-  UNKNOWN_METHOD = 1
-  INVALID_MESSAGE_TYPE = 2
-  WRONG_METHOD_NAME = 3
-  BAD_SEQUENCE_ID = 4
-  MISSING_RESULT = 5
-  INTERNAL_ERROR = 6
-  PROTOCOL_ERROR = 7
-  INVALID_TRANSFORM = 8
-  INVALID_PROTOCOL = 9
-  UNSUPPORTED_CLIENT_TYPE = 10
-
-  def __init__(self, type=UNKNOWN, message=None):
-    TException.__init__(self, message)
-    self.type = type
-
-  def __str__(self):
-    if self.message:
-      return self.message
-    elif self.type == self.UNKNOWN_METHOD:
-      return 'Unknown method'
-    elif self.type == self.INVALID_MESSAGE_TYPE:
-      return 'Invalid message type'
-    elif self.type == self.WRONG_METHOD_NAME:
-      return 'Wrong method name'
-    elif self.type == self.BAD_SEQUENCE_ID:
-      return 'Bad sequence ID'
-    elif self.type == self.MISSING_RESULT:
-      return 'Missing result'
-    elif self.type == self.INTERNAL_ERROR:
-      return 'Internal error'
-    elif self.type == self.PROTOCOL_ERROR:
-      return 'Protocol error'
-    elif self.type == self.INVALID_TRANSFORM:
-      return 'Invalid transform'
-    elif self.type == self.INVALID_PROTOCOL:
-      return 'Invalid protocol'
-    elif self.type == self.UNSUPPORTED_CLIENT_TYPE:
-      return 'Unsupported client type'
-    else:
-      return 'Default (unknown) TApplicationException'
-
-  def read(self, iprot):
-    iprot.readStructBegin()
-    while True:
-      (fname, ftype, fid) = iprot.readFieldBegin()
-      if ftype == TType.STOP:
-        break
-      if fid == 1:
-        if ftype == TType.STRING:
-          self.message = iprot.readString()
-        else:
-          iprot.skip(ftype)
-      elif fid == 2:
-        if ftype == TType.I32:
-          self.type = iprot.readI32()
-        else:
-          iprot.skip(ftype)
-      else:
-        iprot.skip(ftype)
-      iprot.readFieldEnd()
-    iprot.readStructEnd()
-
-  def write(self, oprot):
-    oprot.writeStructBegin('TApplicationException')
-    if self.message is not None:
-      oprot.writeFieldBegin('message', TType.STRING, 1)
-      oprot.writeString(self.message)
-      oprot.writeFieldEnd()
-    if self.type is not None:
-      oprot.writeFieldBegin('type', TType.I32, 2)
-      oprot.writeI32(self.type)
-      oprot.writeFieldEnd()
-    oprot.writeFieldStop()
-    oprot.writeStructEnd()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py
deleted file mode 100644
index 48d659c..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py
+++ /dev/null
@@ -1,20 +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.
-#
-
-__all__ = ['Thrift', 'TSCons']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py
deleted file mode 100644
index 61b469b..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py
+++ /dev/null
@@ -1,81 +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.
-#
-
-from ..Thrift import *
-import TBinaryProtocol
-from ..transport import TTransport
-
-try:
-  import fastbinary
-except:
-  fastbinary = None
-
-
-class TBase(object):
-  __slots__ = []
-
-  def __repr__(self):
-    L = ['%s=%r' % (key, getattr(self, key))
-              for key in self.__slots__]
-    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
-
-  def __eq__(self, other):
-    if not isinstance(other, self.__class__):
-      return False
-    for attr in self.__slots__:
-      my_val = getattr(self, attr)
-      other_val = getattr(other, attr)
-      if my_val != other_val:
-        return False
-    return True
-
-  def __ne__(self, other):
-    return not (self == other)
-
-  def read(self, iprot):
-    if (iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
-        isinstance(iprot.trans, TTransport.CReadableTransport) and
-        self.thrift_spec is not None and
-        fastbinary is not None):
-      fastbinary.decode_binary(self,
-                               iprot.trans,
-                               (self.__class__, self.thrift_spec))
-      return
-    iprot.readStruct(self, self.thrift_spec)
-
-  def write(self, oprot):
-    if (oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
-        self.thrift_spec is not None and
-        fastbinary is not None):
-      oprot.trans.write(
-        fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
-      return
-    oprot.writeStruct(self, self.thrift_spec)
-
-
-class TExceptionBase(Exception):
-  # old style class so python2.4 can raise exceptions derived from this
-  #  This can't inherit from TBase because of that limitation.
-  __slots__ = []
-
-  __repr__ = TBase.__repr__.im_func
-  __eq__ = TBase.__eq__.im_func
-  __ne__ = TBase.__ne__.im_func
-  read = TBase.read.im_func
-  write = TBase.write.im_func

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
deleted file mode 100644
index 2cdc6b5..0000000
--- a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
+++ /dev/null
@@ -1,261 +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.
-#
-
-from struct import pack, unpack
-
-from TProtocol import *
-
-
-class TBinaryProtocol(TProtocolBase):
-  """Binary implementation of the Thrift protocol driver."""
-
-  # NastyHaxx. Python 2.4+ on 32-bit machines forces hex constants to be
-  # positive, converting this into a long. If we hardcode the int value
-  # instead it'll stay in 32 bit-land.
-
-  # VERSION_MASK = 0xffff0000
-  VERSION_MASK = -65536
-
-  # VERSION_1 = 0x80010000
-  VERSION_1 = -2147418112
-
-  TYPE_MASK = 0x000000ff
-
-  def __init__(self, trans, strictRead=False, strictWrite=True):
-    TProtocolBase.__init__(self, trans)
-    self.strictRead = strictRead
-    self.strictWrite = strictWrite
-
-  def writeMessageBegin(self, name, type, seqid):
-    if self.strictWrite:
-      self.writeI32(TBinaryProtocol.VERSION_1 | type)
-      self.writeString(name)
-      self.writeI32(seqid)
-    else:
-      self.writeString(name)
-      self.writeByte(type)
-      self.writeI32(seqid)
-
-  def writeMessageEnd(self):
-    pass
-
-  def writeStructBegin(self, name):
-    pass
-
-  def writeStructEnd(self):
-    pass
-
-  def writeFieldBegin(self, name, type, id):
-    self.writeByte(type)
-    self.writeI16(id)
-
-  def writeFieldEnd(self):
-    pass
-
-  def writeFieldStop(self):
-    self.writeByte(TType.STOP)
-
-  def writeMapBegin(self, ktype, vtype, size):
-    self.writeByte(ktype)
-    self.writeByte(vtype)
-    self.writeI32(size)
-
-  def writeMapEnd(self):
-    pass
-
-  def writeListBegin(self, etype, size):
-    self.writeByte(etype)
-    self.writeI32(size)
-
-  def writeListEnd(self):
-    pass
-
-  def writeSetBegin(self, etype, size):
-    self.writeByte(etype)
-    self.writeI32(size)
-
-  def writeSetEnd(self):
-    pass
-
-  def writeBool(self, bool):
-    if bool:
-      self.writeByte(1)
-    else:
-      self.writeByte(0)
-
-  def writeByte(self, byte):
-    buff = pack("!b", byte)
-    self.trans.write(buff)
-
-  def writeI16(self, i16):
-    buff = pack("!h", i16)
-    self.trans.write(buff)
-
-  def writeI32(self, i32):
-    buff = pack("!i", i32)
-    self.trans.write(buff)
-
-  def writeI64(self, i64):
-    buff = pack("!q", i64)
-    self.trans.write(buff)
-
-  def writeDouble(self, dub):
-    buff = pack("!d", dub)
-    self.trans.write(buff)
-
-  def writeString(self, str):
-    self.writeI32(len(str))
-    self.trans.write(str)
-
-  def readMessageBegin(self):
-    sz = self.readI32()
-    if sz < 0:
-      version = sz & TBinaryProtocol.VERSION_MASK
-      if version != TBinaryProtocol.VERSION_1:
-        raise TProtocolException(
-          type=TProtocolException.BAD_VERSION,
-          message='Bad version in readMessageBegin: %d' % (sz))
-      type = sz & TBinaryProtocol.TYPE_MASK
-      name = self.readString()
-      seqid = self.readI32()
-    else:
-      if self.strictRead:
-        raise TProtocolException(type=TProtocolException.BAD_VERSION,
-                                 message='No protocol version header')
-      name = self.trans.readAll(sz)
-      type = self.readByte()
-      seqid = self.readI32()
-    return (name, type, seqid)
-
-  def readMessageEnd(self):
-    pass
-
-  def readStructBegin(self):
-    pass
-
-  def readStructEnd(self):
-    pass
-
-  def readFieldBegin(self):
-    type = self.readByte()
-    if type == TType.STOP:
-      return (None, type, 0)
-    id = self.readI16()
-    return (None, type, id)
-
-  def readFieldEnd(self):
-    pass
-
-  def readMapBegin(self):
-    ktype = self.readByte()
-    vtype = self.readByte()
-    size = self.readI32()
-    return (ktype, vtype, size)
-
-  def readMapEnd(self):
-    pass
-
-  def readListBegin(self):
-    etype = self.readByte()
-    size = self.readI32()
-    return (etype, size)
-
-  def readListEnd(self):
-    pass
-
-  def readSetBegin(self):
-    etype = self.readByte()
-    size = self.readI32()
-    return (etype, size)
-
-  def readSetEnd(self):
-    pass
-
-  def readBool(self):
-    byte = self.readByte()
-    if byte == 0:
-      return False
-    return True
-
-  def readByte(self):
-    buff = self.trans.readAll(1)
-    val, = unpack('!b', buff)
-    return val
-
-  def readI16(self):
-    buff = self.trans.readAll(2)
-    val, = unpack('!h', buff)
-    return val
-
-  def readI32(self):
-    buff = self.trans.readAll(4)
-    val, = unpack('!i', buff)
-    return val
-
-  def readI64(self):
-    buff = self.trans.readAll(8)
-    val, = unpack('!q', buff)
-    return val
-
-  def readDouble(self):
-    buff = self.trans.readAll(8)
-    val, = unpack('!d', buff)
-    return val
-
-  def readString(self):
-    len = self.readI32()
-    str = self.trans.readAll(len)
-    return str
-
-
-class TBinaryProtocolFactory:
-  def __init__(self, strictRead=False, strictWrite=True):
-    self.strictRead = strictRead
-    self.strictWrite = strictWrite
-
-  def getProtocol(self, trans):
-    prot = TBinaryProtocol(trans, self.strictRead, self.strictWrite)
-    return prot
-
-
-class TBinaryProtocolAccelerated(TBinaryProtocol):
-  """C-Accelerated version of TBinaryProtocol.
-
-  This class does not override any of TBinaryProtocol's methods,
-  but the generated code recognizes it directly and will call into
-  our C module to do the encoding, bypassing this object entirely.
-  We inherit from TBinaryProtocol so that the normal TBinaryProtocol
-  encoding can happen if the fastbinary module doesn't work for some
-  reason.  (TODO(dreiss): Make this happen sanely in more cases.)
-
-  In order to take advantage of the C module, just use
-  TBinaryProtocolAccelerated instead of TBinaryProtocol.
-
-  NOTE:  This code was contributed by an external developer.
-         The internal Thrift team has reviewed and tested it,
-         but we cannot guarantee that it is production-ready.
-         Please feel free to report bugs and/or success stories
-         to the public mailing list.
-  """
-  pass
-
-
-class TBinaryProtocolAcceleratedFactory:
-  def getProtocol(self, trans):
-    return TBinaryProtocolAccelerated(trans)


[31/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py
new file mode 100644
index 0000000..d76afca
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/ttypes.py
@@ -0,0 +1,320 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
+
+from ...thrift.transport import TTransport
+from ...thrift.protocol import TBinaryProtocol, TProtocol
+try:
+  from ...thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+
+class ThriftAttributeType:
+  INT = 0
+  LONG = 1
+  FLOAT = 2
+  DOUBLE = 3
+  BOOL = 4
+  STRING = 5
+
+  _VALUES_TO_NAMES = {
+    0: "INT",
+    1: "LONG",
+    2: "FLOAT",
+    3: "DOUBLE",
+    4: "BOOL",
+    5: "STRING",
+  }
+
+  _NAMES_TO_VALUES = {
+    "INT": 0,
+    "LONG": 1,
+    "FLOAT": 2,
+    "DOUBLE": 3,
+    "BOOL": 4,
+    "STRING": 5,
+  }
+
+
+class ThriftAttribute:
+  """
+  Attributes:
+   - name
+   - attributeType
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'name', None, None, ), # 1
+    (2, TType.I32, 'attributeType', None, None, ), # 2
+  )
+
+  def __init__(self, name=None, attributeType=None,):
+    self.name = name
+    self.attributeType = attributeType
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.name = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.I32:
+          self.attributeType = iprot.readI32();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftAttribute')
+    if self.name is not None:
+      oprot.writeFieldBegin('name', TType.STRING, 1)
+      oprot.writeString(self.name)
+      oprot.writeFieldEnd()
+    if self.attributeType is not None:
+      oprot.writeFieldBegin('attributeType', TType.I32, 2)
+      oprot.writeI32(self.attributeType)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftEventBundle:
+  """
+  Attributes:
+   - sessionId
+   - eventNum
+   - intAttributeList
+   - longAttributeList
+   - doubleAttributeList
+   - boolAttributeList
+   - stringAttributeList
+   - arbitraryDataMapMap
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.I32, 'eventNum', None, None, ), # 2
+    (3, TType.LIST, 'intAttributeList', (TType.I32,None), None, ), # 3
+    (4, TType.LIST, 'longAttributeList', (TType.I64,None), None, ), # 4
+    (5, TType.LIST, 'doubleAttributeList', (TType.DOUBLE,None), None, ), # 5
+    (6, TType.LIST, 'boolAttributeList', (TType.BOOL,None), None, ), # 6
+    (7, TType.LIST, 'stringAttributeList', (TType.STRING,None), None, ), # 7
+    (8, TType.MAP, 'arbitraryDataMapMap', (TType.I32,None,TType.MAP,(TType.STRING,None,TType.STRING,None)), None, ), # 8
+  )
+
+  def __init__(self, sessionId=None, eventNum=None, intAttributeList=None, longAttributeList=None, doubleAttributeList=None, boolAttributeList=None, stringAttributeList=None, arbitraryDataMapMap=None,):
+    self.sessionId = sessionId
+    self.eventNum = eventNum
+    self.intAttributeList = intAttributeList
+    self.longAttributeList = longAttributeList
+    self.doubleAttributeList = doubleAttributeList
+    self.boolAttributeList = boolAttributeList
+    self.stringAttributeList = stringAttributeList
+    self.arbitraryDataMapMap = arbitraryDataMapMap
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.I32:
+          self.eventNum = iprot.readI32();
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.LIST:
+          self.intAttributeList = []
+          (_etype3, _size0) = iprot.readListBegin()
+          for _i4 in xrange(_size0):
+            _elem5 = iprot.readI32();
+            self.intAttributeList.append(_elem5)
+          iprot.readListEnd()
+        else:
+          iprot.skip(ftype)
+      elif fid == 4:
+        if ftype == TType.LIST:
+          self.longAttributeList = []
+          (_etype9, _size6) = iprot.readListBegin()
+          for _i10 in xrange(_size6):
+            _elem11 = iprot.readI64();
+            self.longAttributeList.append(_elem11)
+          iprot.readListEnd()
+        else:
+          iprot.skip(ftype)
+      elif fid == 5:
+        if ftype == TType.LIST:
+          self.doubleAttributeList = []
+          (_etype15, _size12) = iprot.readListBegin()
+          for _i16 in xrange(_size12):
+            _elem17 = iprot.readDouble();
+            self.doubleAttributeList.append(_elem17)
+          iprot.readListEnd()
+        else:
+          iprot.skip(ftype)
+      elif fid == 6:
+        if ftype == TType.LIST:
+          self.boolAttributeList = []
+          (_etype21, _size18) = iprot.readListBegin()
+          for _i22 in xrange(_size18):
+            _elem23 = iprot.readBool();
+            self.boolAttributeList.append(_elem23)
+          iprot.readListEnd()
+        else:
+          iprot.skip(ftype)
+      elif fid == 7:
+        if ftype == TType.LIST:
+          self.stringAttributeList = []
+          (_etype27, _size24) = iprot.readListBegin()
+          for _i28 in xrange(_size24):
+            _elem29 = iprot.readString();
+            self.stringAttributeList.append(_elem29)
+          iprot.readListEnd()
+        else:
+          iprot.skip(ftype)
+      elif fid == 8:
+        if ftype == TType.MAP:
+          self.arbitraryDataMapMap = {}
+          (_ktype31, _vtype32, _size30 ) = iprot.readMapBegin()
+          for _i34 in xrange(_size30):
+            _key35 = iprot.readI32();
+            _val36 = {}
+            (_ktype38, _vtype39, _size37 ) = iprot.readMapBegin()
+            for _i41 in xrange(_size37):
+              _key42 = iprot.readString();
+              _val43 = iprot.readString();
+              _val36[_key42] = _val43
+            iprot.readMapEnd()
+            self.arbitraryDataMapMap[_key35] = _val36
+          iprot.readMapEnd()
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftEventBundle')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.eventNum is not None:
+      oprot.writeFieldBegin('eventNum', TType.I32, 2)
+      oprot.writeI32(self.eventNum)
+      oprot.writeFieldEnd()
+    if self.intAttributeList is not None:
+      oprot.writeFieldBegin('intAttributeList', TType.LIST, 3)
+      oprot.writeListBegin(TType.I32, len(self.intAttributeList))
+      for iter44 in self.intAttributeList:
+        oprot.writeI32(iter44)
+      oprot.writeListEnd()
+      oprot.writeFieldEnd()
+    if self.longAttributeList is not None:
+      oprot.writeFieldBegin('longAttributeList', TType.LIST, 4)
+      oprot.writeListBegin(TType.I64, len(self.longAttributeList))
+      for iter45 in self.longAttributeList:
+        oprot.writeI64(iter45)
+      oprot.writeListEnd()
+      oprot.writeFieldEnd()
+    if self.doubleAttributeList is not None:
+      oprot.writeFieldBegin('doubleAttributeList', TType.LIST, 5)
+      oprot.writeListBegin(TType.DOUBLE, len(self.doubleAttributeList))
+      for iter46 in self.doubleAttributeList:
+        oprot.writeDouble(iter46)
+      oprot.writeListEnd()
+      oprot.writeFieldEnd()
+    if self.boolAttributeList is not None:
+      oprot.writeFieldBegin('boolAttributeList', TType.LIST, 6)
+      oprot.writeListBegin(TType.BOOL, len(self.boolAttributeList))
+      for iter47 in self.boolAttributeList:
+        oprot.writeBool(iter47)
+      oprot.writeListEnd()
+      oprot.writeFieldEnd()
+    if self.stringAttributeList is not None:
+      oprot.writeFieldBegin('stringAttributeList', TType.LIST, 7)
+      oprot.writeListBegin(TType.STRING, len(self.stringAttributeList))
+      for iter48 in self.stringAttributeList:
+        oprot.writeString(iter48)
+      oprot.writeListEnd()
+      oprot.writeFieldEnd()
+    if self.arbitraryDataMapMap is not None:
+      oprot.writeFieldBegin('arbitraryDataMapMap', TType.MAP, 8)
+      oprot.writeMapBegin(TType.I32, TType.MAP, len(self.arbitraryDataMapMap))
+      for kiter49,viter50 in self.arbitraryDataMapMap.items():
+        oprot.writeI32(kiter49)
+        oprot.writeMapBegin(TType.STRING, TType.STRING, len(viter50))
+        for kiter51,viter52 in viter50.items():
+          oprot.writeString(kiter51)
+          oprot.writeString(viter52)
+        oprot.writeMapEnd()
+      oprot.writeMapEnd()
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py
new file mode 100644
index 0000000..adefd8e
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/__init__.py
@@ -0,0 +1 @@
+__all__ = ['ttypes', 'constants']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py
new file mode 100644
index 0000000..36943ba
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/constants.py
@@ -0,0 +1,8 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py
new file mode 100644
index 0000000..9fbb1ce
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Exception/ttypes.py
@@ -0,0 +1,473 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
+
+from ...thrift.transport import TTransport
+from ...thrift.protocol import TBinaryProtocol, TProtocol
+try:
+  from ...thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+
+
+class ThriftStreamDefinitionException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftStreamDefinitionException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftNoStreamDefinitionExistException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftNoStreamDefinitionExistException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftDifferentStreamDefinitionAlreadyDefinedException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftDifferentStreamDefinitionAlreadyDefinedException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftMalformedStreamDefinitionException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftMalformedStreamDefinitionException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftUndefinedEventTypeException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftUndefinedEventTypeException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftSessionExpiredException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftSessionExpiredException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class ThriftAuthenticationException(TException):
+  """
+  Attributes:
+   - message
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'message', None, None, ), # 1
+  )
+
+  def __init__(self, message=None,):
+    self.message = message
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('ThriftAuthenticationException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    if self.message is None:
+      raise TProtocol.TProtocolException(message='Required field message is unset!')
+    return
+
+
+  def __str__(self):
+    return repr(self)
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
new file mode 100755
index 0000000..0d18f58
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService-remote
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+import sys
+import pprint
+from urlparse import urlparse
+
+from thrift.transport import TTransport
+from thrift.transport import TSocket
+from thrift.transport import THttpClient
+from thrift.protocol import TBinaryProtocol
+from ThriftEventTransmissionService import ThriftEventTransmissionService
+from ThriftEventTransmissionService.ttypes import *
+
+
+if len(sys.argv) <= 1 or sys.argv[1] == '--help':
+  print ''
+  print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
+  print ''
+  print 'Functions:'
+  print '  string defineStream(string sessionId, string streamDefinition)'
+  print '  string findStreamId(string sessionId, string streamName, string streamVersion)'
+  print '  void publish(ThriftEventBundle eventBundle)'
+  print '  bool deleteStreamById(string sessionId, string streamId)'
+  print '  bool deleteStreamByNameVersion(string sessionId, string streamName, string streamVersion)'
+  print ''
+  sys.exit(0)
+
+pp = pprint.PrettyPrinter(indent = 2)
+host = 'localhost'
+port = 9090
+uri = ''
+framed = False
+http = False
+argi = 1
+
+if sys.argv[argi] == '-h':
+  parts = sys.argv[argi+1].split(':')
+  host = parts[0]
+  if len(parts) > 1:
+    port = int(parts[1])
+  argi += 2
+
+if sys.argv[argi] == '-u':
+  url = urlparse(sys.argv[argi+1])
+  parts = url[1].split(':')
+  host = parts[0]
+  if len(parts) > 1:
+    port = int(parts[1])
+  else:
+    port = 80
+  uri = url[2]
+  if url[4]:
+    uri += '?%s' % url[4]
+  http = True
+  argi += 2
+
+if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
+  framed = True
+  argi += 1
+
+cmd = sys.argv[argi]
+args = sys.argv[argi+1:]
+
+if http:
+  transport = THttpClient.THttpClient(host, port, uri)
+else:
+  socket = TSocket.TSocket(host, port)
+  if framed:
+    transport = TTransport.TFramedTransport(socket)
+  else:
+    transport = TTransport.TBufferedTransport(socket)
+protocol = TBinaryProtocol.TBinaryProtocol(transport)
+client = ThriftEventTransmissionService.Client(protocol)
+transport.open()
+
+if cmd == 'defineStream':
+  if len(args) != 2:
+    print 'defineStream requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.defineStream(args[0],args[1],))
+
+elif cmd == 'findStreamId':
+  if len(args) != 3:
+    print 'findStreamId requires 3 args'
+    sys.exit(1)
+  pp.pprint(client.findStreamId(args[0],args[1],args[2],))
+
+elif cmd == 'publish':
+  if len(args) != 1:
+    print 'publish requires 1 args'
+    sys.exit(1)
+  pp.pprint(client.publish(eval(args[0]),))
+
+elif cmd == 'deleteStreamById':
+  if len(args) != 2:
+    print 'deleteStreamById requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.deleteStreamById(args[0],args[1],))
+
+elif cmd == 'deleteStreamByNameVersion':
+  if len(args) != 3:
+    print 'deleteStreamByNameVersion requires 3 args'
+    sys.exit(1)
+  pp.pprint(client.deleteStreamByNameVersion(args[0],args[1],args[2],))
+
+else:
+  print 'Unrecognized method %s' % cmd
+  sys.exit(1)
+
+transport.close()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
new file mode 100644
index 0000000..4a5a252
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ThriftEventTransmissionService.py
@@ -0,0 +1,1143 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ttypes import *
+from ...thrift.Thrift import TProcessor
+from ...thrift.transport import TTransport
+
+try:
+  from ...thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+
+class Iface:
+  def defineStream(self, sessionId, streamDefinition):
+    """
+    Parameters:
+     - sessionId
+     - streamDefinition
+    """
+    pass
+
+  def findStreamId(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    pass
+
+  def publish(self, eventBundle):
+    """
+    Parameters:
+     - eventBundle
+    """
+    pass
+
+  def deleteStreamById(self, sessionId, streamId):
+    """
+    Parameters:
+     - sessionId
+     - streamId
+    """
+    pass
+
+  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    pass
+
+
+class Client(Iface):
+  def __init__(self, iprot, oprot=None):
+    self._iprot = self._oprot = iprot
+    if oprot is not None:
+      self._oprot = oprot
+    self._seqid = 0
+
+  def defineStream(self, sessionId, streamDefinition):
+    """
+    Parameters:
+     - sessionId
+     - streamDefinition
+    """
+    self.send_defineStream(sessionId, streamDefinition)
+    return self.recv_defineStream()
+
+  def send_defineStream(self, sessionId, streamDefinition):
+    self._oprot.writeMessageBegin('defineStream', TMessageType.CALL, self._seqid)
+    args = defineStream_args()
+    args.sessionId = sessionId
+    args.streamDefinition = streamDefinition
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_defineStream(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = defineStream_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.ade is not None:
+      raise result.ade
+    if result.mtd is not None:
+      raise result.mtd
+    if result.tde is not None:
+      raise result.tde
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "defineStream failed: unknown result");
+
+  def findStreamId(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    self.send_findStreamId(sessionId, streamName, streamVersion)
+    return self.recv_findStreamId()
+
+  def send_findStreamId(self, sessionId, streamName, streamVersion):
+    self._oprot.writeMessageBegin('findStreamId', TMessageType.CALL, self._seqid)
+    args = findStreamId_args()
+    args.sessionId = sessionId
+    args.streamName = streamName
+    args.streamVersion = streamVersion
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_findStreamId(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = findStreamId_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.tnde is not None:
+      raise result.tnde
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "findStreamId failed: unknown result");
+
+  def publish(self, eventBundle):
+    """
+    Parameters:
+     - eventBundle
+    """
+    self.send_publish(eventBundle)
+    self.recv_publish()
+
+  def send_publish(self, eventBundle):
+    self._oprot.writeMessageBegin('publish', TMessageType.CALL, self._seqid)
+    args = publish_args()
+    args.eventBundle = eventBundle
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_publish(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = publish_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.ue is not None:
+      raise result.ue
+    if result.se is not None:
+      raise result.se
+    return
+
+  def deleteStreamById(self, sessionId, streamId):
+    """
+    Parameters:
+     - sessionId
+     - streamId
+    """
+    self.send_deleteStreamById(sessionId, streamId)
+    return self.recv_deleteStreamById()
+
+  def send_deleteStreamById(self, sessionId, streamId):
+    self._oprot.writeMessageBegin('deleteStreamById', TMessageType.CALL, self._seqid)
+    args = deleteStreamById_args()
+    args.sessionId = sessionId
+    args.streamId = streamId
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_deleteStreamById(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = deleteStreamById_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamById failed: unknown result");
+
+  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    self.send_deleteStreamByNameVersion(sessionId, streamName, streamVersion)
+    return self.recv_deleteStreamByNameVersion()
+
+  def send_deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    self._oprot.writeMessageBegin('deleteStreamByNameVersion', TMessageType.CALL, self._seqid)
+    args = deleteStreamByNameVersion_args()
+    args.sessionId = sessionId
+    args.streamName = streamName
+    args.streamVersion = streamVersion
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_deleteStreamByNameVersion(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = deleteStreamByNameVersion_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamByNameVersion failed: unknown result");
+
+
+class Processor(Iface, TProcessor):
+  def __init__(self, handler):
+    self._handler = handler
+    self._processMap = {}
+    self._processMap["defineStream"] = Processor.process_defineStream
+    self._processMap["findStreamId"] = Processor.process_findStreamId
+    self._processMap["publish"] = Processor.process_publish
+    self._processMap["deleteStreamById"] = Processor.process_deleteStreamById
+    self._processMap["deleteStreamByNameVersion"] = Processor.process_deleteStreamByNameVersion
+
+  def process(self, iprot, oprot):
+    (name, type, seqid) = iprot.readMessageBegin()
+    if name not in self._processMap:
+      iprot.skip(TType.STRUCT)
+      iprot.readMessageEnd()
+      x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
+      oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
+      x.write(oprot)
+      oprot.writeMessageEnd()
+      oprot.trans.flush()
+      return
+    else:
+      self._processMap[name](self, seqid, iprot, oprot)
+    return True
+
+  def process_defineStream(self, seqid, iprot, oprot):
+    args = defineStream_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = defineStream_result()
+    try:
+      result.success = self._handler.defineStream(args.sessionId, args.streamDefinition)
+    except Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ade:
+      result.ade = ade
+    except Exception.ttypes.ThriftMalformedStreamDefinitionException, mtd:
+      result.mtd = mtd
+    except Exception.ttypes.ThriftStreamDefinitionException, tde:
+      result.tde = tde
+    except Exception.ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("defineStream", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_findStreamId(self, seqid, iprot, oprot):
+    args = findStreamId_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = findStreamId_result()
+    try:
+      result.success = self._handler.findStreamId(args.sessionId, args.streamName, args.streamVersion)
+    except Exception.ttypes.ThriftNoStreamDefinitionExistException, tnde:
+      result.tnde = tnde
+    except Exception.ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("findStreamId", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_publish(self, seqid, iprot, oprot):
+    args = publish_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = publish_result()
+    try:
+      self._handler.publish(args.eventBundle)
+    except Exception.ttypes.ThriftUndefinedEventTypeException, ue:
+      result.ue = ue
+    except Exception.ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("publish", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_deleteStreamById(self, seqid, iprot, oprot):
+    args = deleteStreamById_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = deleteStreamById_result()
+    try:
+      result.success = self._handler.deleteStreamById(args.sessionId, args.streamId)
+    except Exception.ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("deleteStreamById", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_deleteStreamByNameVersion(self, seqid, iprot, oprot):
+    args = deleteStreamByNameVersion_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = deleteStreamByNameVersion_result()
+    try:
+      result.success = self._handler.deleteStreamByNameVersion(args.sessionId, args.streamName, args.streamVersion)
+    except Exception.ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("deleteStreamByNameVersion", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+
+# HELPER FUNCTIONS AND STRUCTURES
+
+class defineStream_args:
+  """
+  Attributes:
+   - sessionId
+   - streamDefinition
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamDefinition', None, None, ), # 2
+  )
+
+  def __init__(self, sessionId=None, streamDefinition=None,):
+    self.sessionId = sessionId
+    self.streamDefinition = streamDefinition
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamDefinition = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('defineStream_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamDefinition is not None:
+      oprot.writeFieldBegin('streamDefinition', TType.STRING, 2)
+      oprot.writeString(self.streamDefinition)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class defineStream_result:
+  """
+  Attributes:
+   - success
+   - ade
+   - mtd
+   - tde
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.STRING, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'ade', (Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'mtd', (Exception.ttypes.ThriftMalformedStreamDefinitionException, Exception.ttypes.ThriftMalformedStreamDefinitionException.thrift_spec), None, ), # 2
+    (3, TType.STRUCT, 'tde', (Exception.ttypes.ThriftStreamDefinitionException, Exception.ttypes.ThriftStreamDefinitionException.thrift_spec), None, ), # 3
+    (4, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 4
+  )
+
+  def __init__(self, success=None, ade=None, mtd=None, tde=None, se=None,):
+    self.success = success
+    self.ade = ade
+    self.mtd = mtd
+    self.tde = tde
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRING:
+          self.success = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.ade = Exception.ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException()
+          self.ade.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.mtd = Exception.ttypes.ThriftMalformedStreamDefinitionException()
+          self.mtd.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRUCT:
+          self.tde = Exception.ttypes.ThriftStreamDefinitionException()
+          self.tde.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 4:
+        if ftype == TType.STRUCT:
+          self.se = Exception.ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('defineStream_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.STRING, 0)
+      oprot.writeString(self.success)
+      oprot.writeFieldEnd()
+    if self.ade is not None:
+      oprot.writeFieldBegin('ade', TType.STRUCT, 1)
+      self.ade.write(oprot)
+      oprot.writeFieldEnd()
+    if self.mtd is not None:
+      oprot.writeFieldBegin('mtd', TType.STRUCT, 2)
+      self.mtd.write(oprot)
+      oprot.writeFieldEnd()
+    if self.tde is not None:
+      oprot.writeFieldBegin('tde', TType.STRUCT, 3)
+      self.tde.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 4)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class findStreamId_args:
+  """
+  Attributes:
+   - sessionId
+   - streamName
+   - streamVersion
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamName', None, None, ), # 2
+    (3, TType.STRING, 'streamVersion', None, None, ), # 3
+  )
+
+  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
+    self.sessionId = sessionId
+    self.streamName = streamName
+    self.streamVersion = streamVersion
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamName = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRING:
+          self.streamVersion = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('findStreamId_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamName is not None:
+      oprot.writeFieldBegin('streamName', TType.STRING, 2)
+      oprot.writeString(self.streamName)
+      oprot.writeFieldEnd()
+    if self.streamVersion is not None:
+      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
+      oprot.writeString(self.streamVersion)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class findStreamId_result:
+  """
+  Attributes:
+   - success
+   - tnde
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.STRING, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'tnde', (Exception.ttypes.ThriftNoStreamDefinitionExistException, Exception.ttypes.ThriftNoStreamDefinitionExistException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
+  )
+
+  def __init__(self, success=None, tnde=None, se=None,):
+    self.success = success
+    self.tnde = tnde
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRING:
+          self.success = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.tnde = Exception.ttypes.ThriftNoStreamDefinitionExistException()
+          self.tnde.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.se = Exception.ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('findStreamId_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.STRING, 0)
+      oprot.writeString(self.success)
+      oprot.writeFieldEnd()
+    if self.tnde is not None:
+      oprot.writeFieldBegin('tnde', TType.STRUCT, 1)
+      self.tnde.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 2)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class publish_args:
+  """
+  Attributes:
+   - eventBundle
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRUCT, 'eventBundle', (Data.ttypes.ThriftEventBundle, Data.ttypes.ThriftEventBundle.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, eventBundle=None,):
+    self.eventBundle = eventBundle
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRUCT:
+          self.eventBundle = Data.ttypes.ThriftEventBundle()
+          self.eventBundle.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('publish_args')
+    if self.eventBundle is not None:
+      oprot.writeFieldBegin('eventBundle', TType.STRUCT, 1)
+      self.eventBundle.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class publish_result:
+  """
+  Attributes:
+   - ue
+   - se
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRUCT, 'ue', (Exception.ttypes.ThriftUndefinedEventTypeException, Exception.ttypes.ThriftUndefinedEventTypeException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
+  )
+
+  def __init__(self, ue=None, se=None,):
+    self.ue = ue
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRUCT:
+          self.ue = Exception.ttypes.ThriftUndefinedEventTypeException()
+          self.ue.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.se = Exception.ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('publish_result')
+    if self.ue is not None:
+      oprot.writeFieldBegin('ue', TType.STRUCT, 1)
+      self.ue.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 2)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamById_args:
+  """
+  Attributes:
+   - sessionId
+   - streamId
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamId', None, None, ), # 2
+  )
+
+  def __init__(self, sessionId=None, streamId=None,):
+    self.sessionId = sessionId
+    self.streamId = streamId
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamById_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamId is not None:
+      oprot.writeFieldBegin('streamId', TType.STRING, 2)
+      oprot.writeString(self.streamId)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamById_result:
+  """
+  Attributes:
+   - success
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.BOOL, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, se=None,):
+    self.success = success
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.BOOL:
+          self.success = iprot.readBool();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.se = Exception.ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamById_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.BOOL, 0)
+      oprot.writeBool(self.success)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 1)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamByNameVersion_args:
+  """
+  Attributes:
+   - sessionId
+   - streamName
+   - streamVersion
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamName', None, None, ), # 2
+    (3, TType.STRING, 'streamVersion', None, None, ), # 3
+  )
+
+  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
+    self.sessionId = sessionId
+    self.streamName = streamName
+    self.streamVersion = streamVersion
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamName = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRING:
+          self.streamVersion = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamByNameVersion_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamName is not None:
+      oprot.writeFieldBegin('streamName', TType.STRING, 2)
+      oprot.writeString(self.streamName)
+      oprot.writeFieldEnd()
+    if self.streamVersion is not None:
+      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
+      oprot.writeString(self.streamVersion)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamByNameVersion_result:
+  """
+  Attributes:
+   - success
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.BOOL, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'se', (Exception.ttypes.ThriftSessionExpiredException, Exception.ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, se=None,):
+    self.success = success
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.BOOL:
+          self.success = iprot.readBool();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.se = Exception.ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamByNameVersion_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.BOOL, 0)
+      oprot.writeBool(self.success)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 1)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
new file mode 100644
index 0000000..38575a6
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/__init__.py
@@ -0,0 +1 @@
+__all__ = ['ttypes', 'constants', 'ThriftEventTransmissionService']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
new file mode 100644
index 0000000..36943ba
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/constants.py
@@ -0,0 +1,8 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
new file mode 100644
index 0000000..37ac241
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftEventTransmissionService/ttypes.py
@@ -0,0 +1,21 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
+from ..Data import ttypes
+from ..Exception import ttypes
+
+
+from ...thrift.transport import TTransport
+from ...thrift.protocol import TBinaryProtocol, TProtocol
+try:
+  from thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
new file mode 100755
index 0000000..46757bf
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService-remote
@@ -0,0 +1,131 @@
+#!/usr/bin/env python
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+import sys
+import pprint
+from urlparse import urlparse
+
+from thrift.transport import TTransport
+from thrift.transport import TSocket
+from thrift.transport import THttpClient
+from thrift.protocol import TBinaryProtocol
+from ThriftSecureEventTransmissionService import ThriftSecureEventTransmissionService
+from ThriftSecureEventTransmissionService.ttypes import *
+
+
+if len(sys.argv) <= 1 or sys.argv[1] == '--help':
+  print ''
+  print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
+  print ''
+  print 'Functions:'
+  print '  string connect(string userName, string password)'
+  print '  void disconnect(string sessionId)'
+  print '  string defineStream(string sessionId, string streamDefinition)'
+  print '  string findStreamId(string sessionId, string streamName, string streamVersion)'
+  print '  void publish(ThriftEventBundle eventBundle)'
+  print '  bool deleteStreamById(string sessionId, string streamId)'
+  print '  bool deleteStreamByNameVersion(string sessionId, string streamName, string streamVersion)'
+  print ''
+  sys.exit(0)
+
+pp = pprint.PrettyPrinter(indent = 2)
+host = 'localhost'
+port = 9090
+uri = ''
+framed = False
+http = False
+argi = 1
+
+if sys.argv[argi] == '-h':
+  parts = sys.argv[argi+1].split(':')
+  host = parts[0]
+  if len(parts) > 1:
+    port = int(parts[1])
+  argi += 2
+
+if sys.argv[argi] == '-u':
+  url = urlparse(sys.argv[argi+1])
+  parts = url[1].split(':')
+  host = parts[0]
+  if len(parts) > 1:
+    port = int(parts[1])
+  else:
+    port = 80
+  uri = url[2]
+  if url[4]:
+    uri += '?%s' % url[4]
+  http = True
+  argi += 2
+
+if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
+  framed = True
+  argi += 1
+
+cmd = sys.argv[argi]
+args = sys.argv[argi+1:]
+
+if http:
+  transport = THttpClient.THttpClient(host, port, uri)
+else:
+  socket = TSocket.TSocket(host, port)
+  if framed:
+    transport = TTransport.TFramedTransport(socket)
+  else:
+    transport = TTransport.TBufferedTransport(socket)
+protocol = TBinaryProtocol.TBinaryProtocol(transport)
+client = ThriftSecureEventTransmissionService.Client(protocol)
+transport.open()
+
+if cmd == 'connect':
+  if len(args) != 2:
+    print 'connect requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.connect(args[0],args[1],))
+
+elif cmd == 'disconnect':
+  if len(args) != 1:
+    print 'disconnect requires 1 args'
+    sys.exit(1)
+  pp.pprint(client.disconnect(args[0],))
+
+elif cmd == 'defineStream':
+  if len(args) != 2:
+    print 'defineStream requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.defineStream(args[0],args[1],))
+
+elif cmd == 'findStreamId':
+  if len(args) != 3:
+    print 'findStreamId requires 3 args'
+    sys.exit(1)
+  pp.pprint(client.findStreamId(args[0],args[1],args[2],))
+
+elif cmd == 'publish':
+  if len(args) != 1:
+    print 'publish requires 1 args'
+    sys.exit(1)
+  pp.pprint(client.publish(eval(args[0]),))
+
+elif cmd == 'deleteStreamById':
+  if len(args) != 2:
+    print 'deleteStreamById requires 2 args'
+    sys.exit(1)
+  pp.pprint(client.deleteStreamById(args[0],args[1],))
+
+elif cmd == 'deleteStreamByNameVersion':
+  if len(args) != 3:
+    print 'deleteStreamByNameVersion requires 3 args'
+    sys.exit(1)
+  pp.pprint(client.deleteStreamByNameVersion(args[0],args[1],args[2],))
+
+else:
+  print 'Unrecognized method %s' % cmd
+  sys.exit(1)
+
+transport.close()


[07/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/healthstats.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/healthstats.py b/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/healthstats.py
new file mode 100644
index 0000000..4ceb948
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/healthstatspublisher/healthstats.py
@@ -0,0 +1,246 @@
+# 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.
+
+from threading import Thread
+import time
+import psutil
+import os
+
+from abstracthealthstatisticspublisher import *
+from ..databridge.agent import *
+from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration
+from ..util import cartridgeagentutils, cartridgeagentconstants
+
+
+class HealthStatisticsPublisherManager(Thread):
+    """
+    Read from an implementation of AbstractHealthStatisticsPublisher the value for memory usage and
+    load average and publishes them as ThriftEvents to a CEP server
+    """
+    STREAM_NAME = "cartridge_agent_health_stats"
+    STREAM_VERSION = "1.0.0"
+    STREAM_NICKNAME = "agent health stats"
+    STREAM_DESCRIPTION = "agent health stats"
+
+    def __init__(self, publish_interval):
+        """
+        Initializes a new HealthStatistsPublisherManager with a given number of seconds as the interval
+        :param int publish_interval: Number of seconds as the interval
+        :return: void
+        """
+        Thread.__init__(self)
+
+        self.log = LogFactory().get_log(__name__)
+
+        self.publish_interval = publish_interval
+        """:type : int"""
+
+        self.terminated = False
+
+        self.publisher = HealthStatisticsPublisher()
+        """:type : HealthStatisticsPublisher"""
+        # TODO: load plugins for the reader
+        self.stats_reader = DefaultHealthStatisticsReader()
+        """:type : AbstractHealthStatisticsReader"""
+
+    def run(self):
+        while not self.terminated:
+            time.sleep(self.publish_interval)
+
+            cartridge_stats = self.stats_reader.stat_cartridge_health()
+            self.log.debug("Publishing memory consumption: %r" % cartridge_stats.memory_usage)
+            self.publisher.publish_memory_usage(cartridge_stats.memory_usage)
+
+            self.log.debug("Publishing load average: %r" % cartridge_stats.load_avg)
+            self.publisher.publish_load_average(cartridge_stats.load_avg)
+
+        self.publisher.publisher.disconnect()
+
+
+class HealthStatisticsPublisher:
+    """
+    Publishes memory usage and load average to thrift server
+    """
+    log = LogFactory().get_log(__name__)
+
+    def __init__(self):
+
+        self.ports = []
+        self.ports.append(CEPPublisherConfiguration.get_instance().server_port)
+
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+        cartridgeagentutils.wait_until_ports_active(
+            CEPPublisherConfiguration.get_instance().server_ip,
+            self.ports,
+            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False)))
+        cep_active = cartridgeagentutils.check_ports_active(CEPPublisherConfiguration.get_instance().server_ip, self.ports)
+        if not cep_active:
+            raise CEPPublisherException("CEP server not active. Health statistics publishing aborted.")
+
+        self.stream_definition = HealthStatisticsPublisher.create_stream_definition()
+        HealthStatisticsPublisher.log.debug("Stream definition created: %r" % str(self.stream_definition))
+        self.publisher = ThriftPublisher(
+            CEPPublisherConfiguration.get_instance().server_ip,
+            CEPPublisherConfiguration.get_instance().server_port,
+            CEPPublisherConfiguration.get_instance().admin_username,
+            CEPPublisherConfiguration.get_instance().admin_password,
+            self.stream_definition)
+
+        HealthStatisticsPublisher.log.debug("HealthStatisticsPublisher initialized")
+
+    @staticmethod
+    def create_stream_definition():
+        """
+        Create a StreamDefinition for publishing to CEP
+        """
+        stream_def = StreamDefinition()
+        stream_def.name = HealthStatisticsPublisherManager.STREAM_NAME
+        stream_def.version = HealthStatisticsPublisherManager.STREAM_VERSION
+        stream_def.nickname = HealthStatisticsPublisherManager.STREAM_NICKNAME
+        stream_def.description = HealthStatisticsPublisherManager.STREAM_DESCRIPTION
+
+        stream_def.add_payloaddata_attribute("cluster_id", StreamDefinition.STRING)
+        stream_def.add_payloaddata_attribute("network_partition_id", StreamDefinition.STRING)
+        stream_def.add_payloaddata_attribute("member_id", StreamDefinition.STRING)
+        stream_def.add_payloaddata_attribute("partition_id", StreamDefinition.STRING)
+        stream_def.add_payloaddata_attribute("health_description", StreamDefinition.STRING)
+        stream_def.add_payloaddata_attribute("value", StreamDefinition.DOUBLE)
+
+        return stream_def
+
+    def publish_memory_usage(self, memory_usage):
+        """
+        Publishes the given memory usage value to the thrift server as a ThriftEvent
+        :param float memory_usage: memory usage
+        """
+
+        event = ThriftEvent()
+        event.payloadData.append(self.cartridge_agent_config.cluster_id)
+        event.payloadData.append(self.cartridge_agent_config.network_partition_id)
+        event.payloadData.append(self.cartridge_agent_config.member_id)
+        event.payloadData.append(self.cartridge_agent_config.partition_id)
+        event.payloadData.append(cartridgeagentconstants.MEMORY_CONSUMPTION)
+        event.payloadData.append(memory_usage)
+
+        HealthStatisticsPublisher.log.debug("Publishing cep event: [stream] %r [version] %r" % (self.stream_definition.name, self.stream_definition.version))
+        self.publisher.publish(event)
+
+    def publish_load_average(self, load_avg):
+        """
+        Publishes the given load average value to the thrift server as a ThriftEvent
+        :param float load_avg: load average value
+        """
+
+        event = ThriftEvent()
+        event.payloadData.append(self.cartridge_agent_config.cluster_id)
+        event.payloadData.append(self.cartridge_agent_config.network_partition_id)
+        event.payloadData.append(self.cartridge_agent_config.member_id)
+        event.payloadData.append(self.cartridge_agent_config.partition_id)
+        event.payloadData.append(cartridgeagentconstants.LOAD_AVERAGE)
+        event.payloadData.append(load_avg)
+
+        HealthStatisticsPublisher.log.debug("Publishing cep event: [stream] %r [version] %r" % (self.stream_definition.name, self.stream_definition.version))
+        self.publisher.publish(event)
+
+
+class DefaultHealthStatisticsReader(AbstractHealthStatisticsReader):
+    """
+    Default implementation of the AbstractHealthStatisticsReader
+    """
+
+    def __init__(self):
+        self.log = LogFactory().get_log(__name__)
+
+    def stat_cartridge_health(self):
+        cartridge_stats = CartridgeHealthStatistics()
+        cartridge_stats.memory_usage = DefaultHealthStatisticsReader.__read_mem_usage()
+        cartridge_stats.load_avg = DefaultHealthStatisticsReader.__read_load_avg()
+
+        self.log.debug("Memory read: %r, CPU read: %r" % (cartridge_stats.memory_usage, cartridge_stats.load_avg))
+        return cartridge_stats
+
+    @staticmethod
+    def __read_mem_usage():
+        return psutil.virtual_memory().percent
+
+    @staticmethod
+    def __read_load_avg():
+        (one, five, fifteen) = os.getloadavg()
+        return one
+
+
+class CEPPublisherConfiguration:
+    """
+    TODO: Extract common functionality
+    """
+
+    __instance = None
+    log = LogFactory().get_log(__name__)
+
+    @staticmethod
+    def get_instance():
+        """
+        Singleton instance retriever
+        :return: Instance
+        :rtype : CEPPublisherConfiguration
+        """
+        if CEPPublisherConfiguration.__instance is None:
+            CEPPublisherConfiguration.__instance = CEPPublisherConfiguration()
+
+        return CEPPublisherConfiguration.__instance
+
+    def __init__(self):
+        self.enabled = False
+        self.server_ip = None
+        self.server_port = None
+        self.admin_username = None
+        self.admin_password = None
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+        self.read_config()
+
+    def read_config(self):
+        self.enabled = True if self.cartridge_agent_config.read_property(
+           cartridgeagentconstants.CEP_PUBLISHER_ENABLED, False).strip().lower() == "true" else False
+        if not self.enabled:
+            CEPPublisherConfiguration.log.info("CEP Publisher disabled")
+            return
+
+        CEPPublisherConfiguration.log.info("CEP Publisher enabled")
+
+        self.server_ip = self.cartridge_agent_config.read_property(
+            cartridgeagentconstants.CEP_RECEIVER_IP, False)
+        if self.server_ip is None or self.server_ip.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_RECEIVER_IP)
+
+        self.server_port = self.cartridge_agent_config.read_property(
+            cartridgeagentconstants.CEP_RECEIVER_PORT, False)
+        if self.server_port is None or self.server_port.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_RECEIVER_PORT)
+
+        self.admin_username = self.cartridge_agent_config.read_property(
+            cartridgeagentconstants.CEP_SERVER_ADMIN_USERNAME, False)
+        if self.admin_username is None or self.admin_username.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_SERVER_ADMIN_USERNAME)
+
+        self.admin_password = self.cartridge_agent_config.read_property(
+            cartridgeagentconstants.CEP_SERVER_ADMIN_PASSWORD, False)
+        if self.admin_password is None or self.admin_password.strip() == "":
+            raise RuntimeError("System property not found: " + cartridgeagentconstants.CEP_SERVER_ADMIN_PASSWORD)
+
+        CEPPublisherConfiguration.log.info("CEP Publisher configuration initialized")

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/publisher/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/publisher/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/publisher/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/publisher/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py b/tools/python-cartridge-agent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py
new file mode 100644
index 0000000..1ce8ffb
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/publisher/cartridgeagentpublisher.py
@@ -0,0 +1,165 @@
+# 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.
+
+import logging
+
+import paho.mqtt.publish as publish
+
+from .. event.instance.status.events import *
+from .. config.cartridgeagentconfiguration import CartridgeAgentConfiguration
+from .. util import cartridgeagentconstants
+from .. healthstatspublisher.healthstats import *
+from .. healthstatspublisher.abstracthealthstatisticspublisher import *
+
+
+log = LogFactory().get_log(__name__)
+
+started = False
+activated = False
+ready_to_shutdown = False
+maintenance = False
+
+publishers = {}
+""" :type : dict[str, EventPublisher] """
+
+
+def publish_instance_started_event():
+    global started, log
+    if not started:
+        log.info("Publishing instance started event")
+        service_name = CartridgeAgentConfiguration().service_name
+        cluster_id = CartridgeAgentConfiguration().cluster_id
+        network_partition_id = CartridgeAgentConfiguration().network_partition_id
+        parition_id = CartridgeAgentConfiguration().partition_id
+        member_id = CartridgeAgentConfiguration().member_id
+
+        instance_started_event = InstanceStartedEvent(service_name, cluster_id, network_partition_id, parition_id,
+                                                      member_id)
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_STARTED_EVENT)
+        publisher.publish(instance_started_event)
+        started = True
+        log.info("Instance started event published")
+    else:
+        log.warn("Instance already started")
+
+
+def publish_instance_activated_event():
+    global activated, log
+    if not activated:
+        log.info("Publishing instance activated event")
+        service_name = CartridgeAgentConfiguration().service_name
+        cluster_id = CartridgeAgentConfiguration().cluster_id
+        network_partition_id = CartridgeAgentConfiguration().network_partition_id
+        parition_id = CartridgeAgentConfiguration().partition_id
+        member_id = CartridgeAgentConfiguration().member_id
+
+        instance_activated_event = InstanceActivatedEvent(service_name, cluster_id, network_partition_id, parition_id,
+                                                          member_id)
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_ACTIVATED_EVENT)
+        publisher.publish(instance_activated_event)
+
+        log.info("Instance activated event published")
+        log.info("Starting health statistics notifier")
+
+        if CEPPublisherConfiguration.get_instance().enabled:
+            interval_default = 15  # seconds
+            interval = CartridgeAgentConfiguration().read_property("stats.notifier.interval", False)
+            if interval is not None and len(interval) > 0:
+                try:
+                    interval = int(interval)
+                except ValueError:
+                    interval = interval_default
+            else:
+                interval = interval_default
+
+            health_stats_publisher = HealthStatisticsPublisherManager(interval)
+            log.info("Starting Health statistics publisher with interval %r" % interval_default)
+            health_stats_publisher.start()
+        else:
+            log.warn("Statistics publisher is disabled")
+
+        activated = True
+        log.info("Health statistics notifier started")
+    else:
+        log.warn("Instance already activated")
+
+
+def publish_maintenance_mode_event():
+    global maintenance, log
+    if not maintenance:
+        log.info("Publishing instance maintenance mode event")
+
+        service_name = CartridgeAgentConfiguration().service_name
+        cluster_id = CartridgeAgentConfiguration().cluster_id
+        network_partition_id = CartridgeAgentConfiguration().network_partition_id
+        parition_id = CartridgeAgentConfiguration().partition_id
+        member_id = CartridgeAgentConfiguration().member_id
+
+        instance_maintenance_mode_event = InstanceMaintenanceModeEvent(service_name, cluster_id, network_partition_id, parition_id,
+                                                          member_id)
+
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_MAINTENANCE_MODE_EVENT)
+        publisher.publish(instance_maintenance_mode_event)
+
+        maintenance = True
+        log.info("Instance Maintenance mode event published")
+    else:
+        log.warn("Instance already in a Maintenance mode....")
+
+
+def publish_instance_ready_to_shutdown_event():
+    global ready_to_shutdown, log
+    if not ready_to_shutdown:
+        log.info("Publishing instance activated event")
+
+        service_name = CartridgeAgentConfiguration().service_name
+        cluster_id = CartridgeAgentConfiguration().cluster_id
+        network_partition_id = CartridgeAgentConfiguration().network_partition_id
+        parition_id = CartridgeAgentConfiguration().partition_id
+        member_id = CartridgeAgentConfiguration().member_id
+
+        instance_shutdown_event = InstanceReadyToShutdownEvent(service_name, cluster_id, network_partition_id, parition_id,
+                                                          member_id)
+
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + cartridgeagentconstants.INSTANCE_READY_TO_SHUTDOWN_EVENT)
+        publisher.publish(instance_shutdown_event)
+
+        ready_to_shutdown = True
+        log.info("Instance ReadyToShutDown event published")
+    else:
+        log.warn("Instance already in a ReadyToShutDown event....")
+
+
+def get_publisher(topic):
+    if topic not in publishers:
+        publishers[topic] = EventPublisher(topic)
+
+    return publishers[topic]
+
+
+class EventPublisher:
+    """
+    Handles publishing events to topics to the provided message broker
+    """
+    def __init__(self, topic):
+        self.__topic = topic
+
+    def publish(self, event):
+        mb_ip = CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_IP)
+        mb_port = CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_PORT)
+        payload = event.to_json()
+        publish.single(self.__topic, payload, hostname=mb_ip, port=mb_port)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/eventsubscriber.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/eventsubscriber.py b/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/eventsubscriber.py
new file mode 100644
index 0000000..bc026dd
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/subscriber/eventsubscriber.py
@@ -0,0 +1,96 @@
+# 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.
+
+import threading
+import paho.mqtt.client as mqtt
+
+
+class EventSubscriber(threading.Thread):
+    """
+    Provides functionality to subscribe to a given topic on the stratos MB and
+    register event handlers for various events.
+    """
+
+    def __init__(self, topic, ip, port):
+        threading.Thread.__init__(self)
+
+        #{"ArtifactUpdateEvent" : onArtifactUpdateEvent()}
+        self.__event_handlers = {}
+
+        self.log = LogFactory().get_log(__name__)
+
+        self.__mb_client = None
+
+        self.__topic = topic
+
+        self.__subscribed = False
+
+        self.__ip = ip
+        self.__port = port
+
+    def run(self):
+        self.__mb_client = mqtt.Client()
+        self.__mb_client.on_connect = self.on_connect
+        self.__mb_client.on_message = self.on_message
+
+        self.log.debug("Connecting to the message broker with address %r:%r" % (self.__ip, self.__port))
+        self.__mb_client.connect(self.__ip, self.__port, 60)
+        self.__subscribed = True
+        self.__mb_client.loop_forever()
+
+    def register_handler(self, event, handler):
+        """
+        Adds an event handler function mapped to the provided event.
+        :param str event: Name of the event to attach the provided handler
+        :param handler: The handler function
+        :return: void
+        :rtype: void
+        """
+        self.__event_handlers[event] = handler
+        self.log.debug("Registered handler for event %r" % event)
+
+    def on_connect(self, client, userdata, flags, rc):
+        self.log.debug("Connected to message broker.")
+        self.__mb_client.subscribe(self.__topic)
+        self.log.debug("Subscribed to %r" % self.__topic)
+
+    def on_message(self, client, userdata, msg):
+        self.log.debug("Message received: %r:\n%r" % (msg.topic, msg.payload))
+
+        event = msg.topic.rpartition('/')[2]
+
+        if event in self.__event_handlers:
+            handler = self.__event_handlers[event]
+
+            try:
+                self.log.debug("Executing handler for event %r" % event)
+                handler(msg)
+            except:
+                self.log.exception("Error processing %r event" % event)
+        else:
+            self.log.debug("Event handler not found for event : %r" % event)
+
+    def is_subscribed(self):
+        """
+        Checks if this event subscriber is successfully subscribed to the provided topic
+        :return: True if subscribed, False if otherwise
+        :rtype: bool
+        """
+        return self.__subscribed
+
+
+from .. util.log import LogFactory
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/tenant/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/tenant/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/tenant/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/tenant/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/tenant/tenantcontext.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/tenant/tenantcontext.py b/tools/python-cartridge-agent/cartridgeagent/modules/tenant/tenantcontext.py
new file mode 100644
index 0000000..202bd35
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/tenant/tenantcontext.py
@@ -0,0 +1,184 @@
+# 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.
+
+class Tenant:
+    """
+    Object type representing the tenant details of a single tenant
+    """
+
+    def __init__(self, tenant_id,  tenant_domain):
+        self.tenant_id = tenant_id
+        """ :type : int """
+        self.tenant_domain = tenant_domain
+        """ :type : str """
+        self.service_name_subscription_map = {}
+        """ :type : dict[str, Subscription] """
+
+    def get_subscription(self, service_name):
+        """
+        Returns the Subscription object related to the provided service name
+        :param str service_name: service name to be retrieved
+        :return: Subscription of the service or None if the service name doesn't exist
+        :rtype: Subscription
+        """
+        if service_name in self.service_name_subscription_map:
+            return self.service_name_subscription_map[service_name]
+
+        return None
+
+    def is_subscribed(self, service_name):
+        """
+        Checks if the given service name has a subscription from this tenant
+        :param str service_name: name of the service to check
+        :return: True if the tenant is subscribed to the given service name, False if not
+        :rtype: bool
+        """
+        return service_name in self.service_name_subscription_map
+
+    def add_subscription(self, subscription):
+        """
+        Adds a subscription information entry on the subscription list for this tenant
+        :param Subscription subscription: Subscription information to be added
+        :return: void
+        :rtype: void
+        """
+        self.service_name_subscription_map[subscription.service_name] = subscription
+
+    def remove_subscription(self, service_name):
+        """
+        Removes the specified subscription details from the subscription list
+        :param str service_name: The service name of the subscription to be removed
+        :return: void
+        :rtype: void
+        """
+        if service_name in self.service_name_subscription_map:
+            self.service_name_subscription_map.pop(service_name)
+
+
+class Subscription:
+    """
+    Subscription information of a particular subscription to a service
+    """
+
+    def __init__(self, service_name, cluster_ids):
+        self.service_name = service_name
+        """ :type : str """
+        self.cluster_ids = cluster_ids
+        """ :type : list[str]  """
+        self.subscription_domain_map = {}
+        """ :type : dict[str, SubscriptionDomain]  """
+
+    def add_subscription_domain(self, domain_name, application_context):
+        """
+        Adds a subscription domain
+        :param str domain_name:
+        :param str application_context:
+        :return: void
+        :rtype: void
+        """
+        self.subscription_domain_map[domain_name] = SubscriptionDomain(domain_name, application_context)
+
+    def remove_subscription_domain(self, domain_name):
+        """
+        Removes the subscription domain of the specified domain name
+        :param str domain_name:
+        :return: void
+        :rtype: void
+        """
+        if domain_name in self.subscription_domain_map:
+            self.subscription_domain_map.pop(domain_name)
+
+    def subscription_domain_exists(self, domain_name):
+        """
+        Returns the SubscriptionDomain information of the specified domain name
+        :param str domain_name:
+        :return: SubscriptionDomain
+        :rtype: SubscriptionDomain
+        """
+        return domain_name in self.subscription_domain_map
+
+    def get_subscription_domains(self):
+        """
+        Returns the list of subscription domains of this subscription
+        :return: List of SubscriptionDomain objects
+        :rtype: list[SubscriptionDomain]
+        """
+        return self.subscription_domain_map.values()
+
+
+class SubscriptionDomain:
+    """
+    Represents a Subscription Domain
+    """
+
+    def __init__(self, domain_name, application_context):
+        self.domain_name = domain_name
+        """ :type : str  """
+        self.application_context = application_context
+        """ :type : str  """
+
+
+class TenantContext:
+    """
+    Handles and maintains a model of all the information related to tenants within this instance
+    """
+    tenants = {}
+    initialized = False
+    tenant_domains = {"carbon.super": Tenant(-1234, "carbon.super")}
+
+    @staticmethod
+    def add_tenant(tenant):
+        TenantContext.tenants[tenant.tenant_id] = tenant
+        TenantContext.tenant_domains[tenant.tenant_domain] = tenant
+
+    @staticmethod
+    def remove_tenant(tenant_id):
+        if tenant_id in TenantContext.tenants:
+            tenant = TenantContext.get_tenant(tenant_id)
+            TenantContext.tenants.pop(tenant.tenant_id)
+            TenantContext.tenant_domains.pop(tenant.tenant_domain)
+
+    @staticmethod
+    def update(tenants):
+        for tenant in tenants:
+            TenantContext.add_tenant(tenant)
+
+    @staticmethod
+    def get_tenant(tenant_id):
+        """
+        Gets the Tenant object of the provided tenant ID
+        :param int tenant_id:
+        :return: Tenant object of the provided tenant ID
+        :rtype: Tenant
+        """
+        if tenant_id in TenantContext.tenants:
+            return TenantContext.tenants[tenant_id]
+
+        return None
+
+    @staticmethod
+    def get_tenant_by_domain(tenant_domain):
+        """
+        Gets the Tenant object of the provided tenant domain
+        :param str tenant_domain:
+        :return: Tenant object of the provided tenant domain
+        :rtype: str
+        """
+        if tenant_domain in TenantContext.tenant_domains:
+            return TenantContext.tenant_domains[tenant_domain]
+
+        return None
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/topology/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/topology/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/topology/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/topology/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/topology/topologycontext.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/topology/topologycontext.py b/tools/python-cartridge-agent/cartridgeagent/modules/topology/topologycontext.py
new file mode 100644
index 0000000..5fe2ea4
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/topology/topologycontext.py
@@ -0,0 +1,454 @@
+# 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.
+
+from ..util import cartridgeagentconstants
+
+
+class Topology:
+    """
+    Represents the topology provided by the Cloud Controller
+    """
+
+    def __init__(self):
+        self.service_map = {}
+        """ :type : dict[str, Service]  """
+        self.initialized = False
+        """ :type : bool  """
+        self.json_str = None
+        """ :type : str  """
+
+    def get_services(self):
+        """
+        Provides the list of services on the topology
+        :return: The list of Service objects
+        :rtype: list[Service]
+        """
+        return self.service_map.values()
+
+    def get_service(self, service_name):
+        """
+        Provides the service information for the given service name
+        :param str service_name: service name to be retrieved
+        :return: Service object of the service, None if the provided service name is invalid
+        :rtype: Service
+        """
+        if service_name in self.service_map:
+            return self.service_map[service_name]
+
+        return None
+
+    def add_service(self, service):
+        """
+        Adds a service to the list of services on the topology
+
+        :param Service service:
+        :return: void
+        """
+        self.service_map[service.service_name] = service
+
+    def add_services(self, services):
+        """
+
+        :param list[Service] services:
+        :return: void
+        """
+        for service in services:
+            self.add_service(service)
+
+    def remove_service(self, service_name):
+        """
+        Removes the service of the provided service name
+        :param str service_name:
+        :return: void
+        """
+        if service_name in self.service_map:
+            self.service_map.pop(service_name)
+
+    def service_exists(self, service_name):
+        """
+        Checks if the service of the provided service name exists
+        :param str service_name:
+        :return: True if the service exists, False if otherwise
+        :rtype: bool
+        """
+        return service_name in self.service_map
+
+    def clear(self):
+        """
+        Clears the service information list
+        :return: void
+        """
+        self.service_map = {}
+
+    def __str__(self):
+        """
+        to string override
+        :return:
+        """
+        return "Topology [serviceMap= %r , initialized= %r ]" % (self.service_map, self.initialized)
+
+
+class Service:
+    """
+    Represents a service on the topology
+    """
+
+    def __init__(self, service_name, service_type):
+        self.service_name = service_name
+        """ :type : str  """
+        self.service_type = service_type
+        """ :type : str  """
+        self.cluster_id_cluster_map = {}
+        """ :type : dict[str, Cluster]  """
+        self.port_map = {}
+        """ :type : dict[str, Port]  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+
+    def get_clusters(self):
+        """
+        Provides the list of clusters in the particular service
+        :return: The list of Cluster objects
+        :rtype: list[Cluster]
+        """
+        return self.cluster_id_cluster_map.values()
+
+    def add_cluster(self, cluster):
+        """
+        Adds a cluster to the service
+        :param Cluster cluster: the cluster to be added
+        :return: void
+        """
+        self.cluster_id_cluster_map[cluster.cluster_id] = cluster
+
+    def remove_cluster(self, cluster_id):
+        if cluster_id in self.cluster_id_cluster_map:
+            self.cluster_id_cluster_map.pop(cluster_id)
+
+    def cluster_exists(self, cluster_id):
+        """
+        Checks if the cluster with the given cluster id exists for ther service
+        :param str cluster_id:
+        :return: True if the cluster for the given cluster id exists, False if otherwise
+        :rtype: bool
+        """
+        return cluster_id in self.cluster_id_cluster_map
+
+    def get_cluster(self, cluster_id):
+        """
+        Provides the Cluster information for the provided cluster id
+        :param str cluster_id: the cluster id to search for
+        :return: Cluster object for the given cluster id, None if the cluster id is invalid
+        :rtype: Cluster
+        """
+        if cluster_id in self.cluster_id_cluster_map:
+            return self.cluster_id_cluster_map[cluster_id]
+
+        return None
+
+    def get_ports(self):
+        """
+        Returns the list of ports in the particular service
+        :return: The list of Port object
+        :rtype: list[Port]
+        """
+        return self.port_map.values()
+
+    def get_port(self, proxy_port):
+        """
+        Provides the port information for the provided proxy port
+        :param str proxy_port:
+        :return: Port object for the provided port, None if port is invalid
+        :rtype: Port
+        """
+        if proxy_port in self.port_map:
+            return self.port_map[proxy_port]
+
+        return None
+
+    def add_port(self, port):
+        self.port_map[port.proxy] = port
+
+    def add_ports(self, ports):
+        for port in ports:
+            self.add_port(port)
+
+
+class Cluster:
+    """
+    Represents a cluster for a service
+    """
+
+    def __init__(self, service_name="", cluster_id="", deployment_policy_name="", autoscale_policy_name=""):
+        self.service_name = service_name
+        """ :type : str  """
+        self.cluster_id = cluster_id
+        """ :type : str  """
+        self.deployment_policy_name = deployment_policy_name
+        """ :type : str  """
+        self.autoscale_policy_name = autoscale_policy_name
+        """ :type : str  """
+        self.hostnames = []
+        """ :type : list[str]  """
+        self.member_map = {}
+        """ :type : dict[str, Member]  """
+
+        self.tenant_range = None
+        """ :type : str  """
+        self.is_lb_cluster = False
+        """ :type : bool  """
+        self.is_kubernetes_cluster = False
+        """ :type : bool  """
+        self.status = None
+        """ :type : str  """
+        self.load_balancer_algorithm_name = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+        self.member_list_json = None
+        """ :type : str  """
+
+    def add_hostname(self, hostname):
+        self.hostnames.append(hostname)
+
+    def set_tenant_range(self, tenant_range):
+        self.validate_tenant_range(tenant_range)
+        self.tenant_range = tenant_range
+
+    def get_members(self):
+        """
+        Provides the list of member information in the cluster
+        :return: The list of Member object
+        :rtype: list[Member]
+        """
+        return self.member_map.values()
+
+    def add_member(self, member):
+        self.member_map[member.member_id] = member
+
+    def remove_member(self, member_id):
+        if self.member_exists(member_id):
+            self.member_map.pop(member_id)
+
+    def get_member(self, member_id):
+        """
+        Provides the member information for the provided member id
+        :param str member_id:
+        :return: Member object for the provided member id, None if member id is invalid
+        :rtype: Member
+        """
+        if self.member_exists(member_id):
+            return self.member_map[member_id]
+
+        return None
+
+    def member_exists(self, member_id):
+        """
+        Checks if the member for the provided member id exists in this cluster
+        :param str member_id: member id to be searched
+        :return: True if the member exists, False if otherwise
+        :rtype: bool
+        """
+        return member_id in self.member_map
+
+    def __str__(self):
+        return "Cluster [serviceName=" + self.service_name + ", clusterId=" + self.cluster_id \
+               + ", autoscalePolicyName=" + self.autoscale_policy_name + ", deploymentPolicyName=" \
+               + self.deployment_policy_name + ", hostNames=" + self.hostnames + ", tenantRange=" + self.tenant_range \
+               + ", isLbCluster=" + self.is_lb_cluster + ", properties=" + self.properties + "]"
+
+    def tenant_id_in_range(self, tenant_id):
+        """
+        Check whether a given tenant id is in tenant range of the cluster.
+        :param str tenant_id: tenant id to be checked
+        :return: True if the tenant id is in tenant id range, False if otherwise
+        :rtype: bool
+        """
+        if self.tenant_range is None:
+            return False
+
+        if self.tenant_range == "*":
+            return True
+        else:
+            arr = self.tenant_range.split(cartridgeagentconstants.TENANT_RANGE_DELIMITER)
+            tenant_start = int(arr[0])
+            if tenant_start <= tenant_id:
+                tenant_end = arr[1]
+                if tenant_end == "*":
+                    return True
+                else:
+                    if tenant_id <= int(tenant_end):
+                        return True
+
+        return False
+
+    def validate_tenant_range(self, tenant_range):
+        """
+        Validates the tenant range to be either '*' or a delimeted range of numbers
+        :param str tenant_range: The tenant range string to be validated
+        :return: void if the provided tenant range is valid, RuntimeError if otherwise
+        :exception: RuntimeError if the tenant range is invalid
+        """
+        valid = False
+        if tenant_range == "*":
+            valid = True
+        else:
+            arr = tenant_range.split(cartridgeagentconstants.TENANT_RANGE_DELIMITER)
+            if len(arr) == 2:
+                if arr[0].isdigit() and arr[1].isdigit():
+                    valid = True
+                elif arr[0].isdigit() and arr[1] == "*":
+                    valid = True
+
+        if not valid:
+            raise RuntimeError("Tenant range %r is not valid" % tenant_range)
+
+
+class Member:
+    """
+    Represents a member on a particular cluster
+    """
+
+    def __init__(self, service_name="", cluster_id="", network_partition_id="", parition_id="", member_id=""):
+        self.service_name = service_name
+        """ :type : str  """
+        self.cluster_id = cluster_id
+        """ :type : str  """
+        self.network_partition_id = network_partition_id
+        """ :type : str  """
+        self.partition_id = parition_id
+        """ :type : str  """
+        self.member_id = member_id
+        """ :type : str  """
+        self.port_map = {}
+        """ :type : dict[str, Port]  """
+
+        self.member_public_ip = None
+        """ :type : str  """
+        self.status = None
+        """ :type : str  """
+        self.member_ip = None
+        """ :type : str  """
+        self.properties = {}
+        """ :type : dict[str, str]  """
+        self.lb_cluster_id = None
+        """ :type : str  """
+        self.json_str = None
+        """ :type : str  """
+
+    def is_active(self):
+        """
+        Checks if the member is in active state
+        :return: True if active, False if otherwise
+        :rtype: bool
+        """
+        return self.status == MemberStatus.Activated
+
+    def get_ports(self):
+        """
+        Provides the list of the ports in the member
+        :return: List of Port objects
+        :rtype: list[Port]
+        """
+        return self.port_map.values()
+
+    def get_port(self, proxy):
+        """
+        Provides the port information for the given port id
+        :param str proxy: The port id
+        :return: Port object of the provided port id, None if otherwise
+        :rtype: Port
+        """
+        if proxy in self.port_map:
+            return self.port_map[proxy]
+
+        return None
+
+    def add_port(self, port):
+        self.port_map[port.proxy] = port
+
+    def add_ports(self, ports):
+        for port in ports:
+            self.add_port(port)
+
+
+class Port:
+    """
+    Represents a port on a particular member
+    """
+
+    def __init__(self, protocol, value, proxy):
+        self.protocol = protocol
+        """ :type : str  """
+        self.value = value
+        """ :type : str  """
+        self.proxy = proxy
+        """ :type : str  """
+
+    def __str__(self):
+        return "Port [protocol=%r, value=%r proxy=%r]" % (self.protocol, self.value, self.proxy)
+
+
+class ServiceType:
+    """
+    ServiceType enum
+    """
+    SingleTenant = 1
+    MultiTenant = 2
+
+
+class ClusterStatus:
+    """
+    ClusterStatus enum
+    """
+    Created = 1
+    In_Maintenance = 2
+    Removed = 3
+
+
+class MemberStatus:
+    """
+    MemberStatus enum
+    """
+    Created = 1
+    Starting = 2
+    Activated = 3
+    In_Maintenance = 4
+    ReadyToShutDown = 5
+    Terminated = 6
+    Suspended = 0
+    ShuttingDown = 0
+
+
+class TopologyContext:
+    """
+    Handles and maintains a model of the topology provided by the Cloud Controller
+    """
+    topology = None
+    # TODO: read write locks, Lock() and RLock()
+
+    @staticmethod
+    def get_topology():
+        #TODO: thread-safety missing
+        if TopologyContext.topology is None:
+            TopologyContext.topology = Topology()
+        return TopologyContext.topology
+
+    @staticmethod
+    def update(topology):
+        TopologyContext.topology = topology
+        TopologyContext.topology.initialized = True
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/util/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/util/__init__.py
@@ -0,0 +1,16 @@
+# 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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py
new file mode 100644
index 0000000..9fdde1e
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/util/asyncscheduledtask.py
@@ -0,0 +1,50 @@
+# 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.
+
+import time
+from threading import Thread
+
+
+class AsyncScheduledTask(Thread):
+    """
+    Executes a given task with a given interval until being terminated
+    """
+
+    def __init__(self, delay, task):
+        Thread.__init__(self)
+        self.delay = delay
+        """ :type : int  """
+        self.task = task
+        """ :type : Thread  """
+        self.terminated = False
+        """ :type : bool  """
+
+    def run(self):
+        """
+        Start the scheuled task with a sleep time of delay in between
+        :return:
+        """
+        while not self.terminated:
+            time.sleep(self.delay)
+            self.task.start()
+
+    def terminate(self):
+        """
+        Terminate the scheduled task. Allow a maximum of 'delay' seconds to be terminated.
+        :return: void
+        """
+        self.terminated = True
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentconstants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentconstants.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentconstants.py
new file mode 100644
index 0000000..70afb30
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentconstants.py
@@ -0,0 +1,135 @@
+# 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.
+
+PARAM_FILE_PATH = "param.file.path"
+EXTENSIONS_DIR = "extensions.dir"
+
+MB_IP = "mb.ip"
+MB_PORT = "mb.port"
+
+CARTRIDGE_KEY = "CARTRIDGE_KEY"
+APP_PATH = "APP_PATH"
+SERVICE_GROUP = "SERIVCE_GROUP"
+SERVICE_NAME = "SERVICE_NAME"
+CLUSTER_ID = "CLUSTER_ID"
+LB_CLUSTER_ID = "LB_CLUSTER_ID"
+NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID"
+PARTITION_ID = "PARTITION_ID"
+MEMBER_ID = "MEMBER_ID"
+TENANT_ID = "TENANT_ID"
+REPO_URL = "REPO_URL"
+PORTS = "PORTS"
+DEPLOYMENT = "DEPLOYMENT"
+MANAGER_SERVICE_TYPE = "MANAGER_SERVICE_TYPE"
+WORKER_SERVICE_TYPE = "WORKER_SERVICE_TYPE"
+PERSISTENCE_MAPPING = "PERSISTENCE_MAPPING"
+
+# stratos.sh environment variables keys
+LOG_FILE_PATHS = "LOG_FILE_PATHS"
+MEMORY_CONSUMPTION = "memory_consumption"
+LOAD_AVERAGE = "load_average"
+PORTS_NOT_OPEN = "ports_not_open"
+MULTITENANT = "MULTITENANT"
+CLUSTERING = "CLUSTERING"
+MIN_INSTANCE_COUNT = "MIN_COUNT"
+ENABLE_ARTIFACT_UPDATE = "enable.artifact.update"
+ARTIFACT_UPDATE_INTERVAL = "artifact.update.interval"
+COMMIT_ENABLED = "COMMIT_ENABLED"
+AUTO_COMMIT = "auto.commit"
+AUTO_CHECKOUT = "auto.checkout"
+LISTEN_ADDRESS = "listen.address"
+PROVIDER = "PROVIDER"
+INTERNAL = "internal"
+LB_PRIVATE_IP = "lb.private.ip"
+LB_PUBLIC_IP = "lb.public.ip"
+
+# stratos.sh extension points shell scripts names keys
+INSTANCE_STARTED_SCRIPT = "extension.instance.started"
+START_SERVERS_SCRIPT = "extension.start.servers"
+INSTANCE_ACTIVATED_SCRIPT = "extension.instance.activated"
+ARTIFACTS_UPDATED_SCRIPT = "extension.artifacts.updated"
+CLEAN_UP_SCRIPT = "extension.clean"
+MOUNT_VOLUMES_SCRIPT = "extension.mount.volumes"
+MEMBER_ACTIVATED_SCRIPT = "extension.member.activated"
+MEMBER_TERMINATED_SCRIPT = "extension.member.terminated"
+MEMBER_SUSPENDED_SCRIPT = "extension.member.suspended"
+MEMBER_STARTED_SCRIPT = "extension.member.started"
+COMPLETE_TOPOLOGY_SCRIPT = "extension.complete.topology"
+COMPLETE_TENANT_SCRIPT = "extension.complete.tenant"
+SUBSCRIPTION_DOMAIN_ADDED_SCRIPT = "extension.subscription.domain.added"
+SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT = "extension.subscription.domain.removed"
+ARTIFACTS_COPY_SCRIPT = "extension.artifacts.copy"
+TENANT_SUBSCRIBED_SCRIPT = "extension.tenant.subscribed"
+TENANT_UNSUBSCRIBED_SCRIPT = "extension.tenant.unsubscribed"
+
+SERVICE_GROUP_TOPOLOGY_KEY = "payload_parameter.SERIVCE_GROUP"
+CLUSTERING_TOPOLOGY_KEY = "payload_parameter.CLUSTERING"
+CLUSTERING_PRIMARY_KEY = "PRIMARY"
+
+SUPERTENANT_TEMP_PATH = "/tmp/-1234/"
+
+DEPLOYMENT_MANAGER = "manager"
+DEPLOYMENT_WORKER = "worker"
+DEPLOYMENT_DEFAULT = "default"
+SUPER_TENANT_REPO_PATH = "super.tenant.repository.path"
+TENANT_REPO_PATH = "tenant.repository.path"
+
+# topic names to subscribe
+INSTANCE_NOTIFIER_TOPIC = "instance/#"
+HEALTH_STAT_TOPIC = "health/#"
+TOPOLOGY_TOPIC = "topology/#"
+TENANT_TOPIC = "tenant/#"
+INSTANCE_STATUS_TOPIC = "instance/status/"
+
+#Messaging Model
+TENANT_RANGE_DELIMITER = "-"
+
+INSTANCE_STARTED_EVENT = "InstanceStartedEvent"
+INSTANCE_ACTIVATED_EVENT = "InstanceActivatedEvent"
+INSTANCE_MAINTENANCE_MODE_EVENT = "InstanceMaintenanceModeEvent"
+INSTANCE_READY_TO_SHUTDOWN_EVENT = "InstanceReadyToShutdownEvent"
+
+PUBLISHER_SERVICE_NAME = "publisher"
+APISTORE_SERVICE_NAME = "apistore"
+APIMANAGER_SERVICE_NAME = "apim"
+GATEWAY_SERVICE_NAME = "gatewaymgt"
+GATEWAY_MGT_SERVICE_NAME = "gateway"
+KEY_MANAGER_SERVICE_NAME = "keymanager"
+
+PRIMARY = "PRIMARY"
+MIN_COUNT = "MIN_COUNT"
+
+#multi tenant constants
+INVALID_TENANT_ID = "-1"
+SUPER_TENANT_ID = "-1234"
+
+DATE_FORMAT = "%Y.%m.%d"
+
+PORT_CHECK_TIMEOUT = "port.check.timeout"
+
+CEP_PUBLISHER_ENABLED = "cep.stats.publisher.enabled"
+CEP_RECEIVER_IP = "thrift.receiver.ip"
+CEP_RECEIVER_PORT = "thrift.receiver.port"
+CEP_SERVER_ADMIN_USERNAME = "thrift.server.admin.username"
+CEP_SERVER_ADMIN_PASSWORD = "thrift.server.admin.password"
+
+MONITORING_PUBLISHER_ENABLED = "enable.data.publisher"
+MONITORING_RECEIVER_IP = "monitoring.server.ip"
+MONITORING_RECEIVER_PORT = "monitoring.server.port"
+MONITORING_RECEIVER_SECURE_PORT = "monitoring.server.secure.port"
+MONITORING_SERVER_ADMIN_USERNAME = "monitoring.server.admin.username"
+MONITORING_SERVER_ADMIN_PASSWORD = "monitoring.server.admin.password"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentutils.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentutils.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentutils.py
new file mode 100644
index 0000000..42a7dd5
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/util/cartridgeagentutils.py
@@ -0,0 +1,165 @@
+# 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.
+
+from Crypto.Cipher import AES
+import base64
+import os
+import time
+import socket
+import shutil
+
+from log import LogFactory
+
+unpad = lambda s: s[0:-ord(s[-1])]
+
+log = LogFactory().get_log(__name__)
+
+current_milli_time = lambda: int(round(time.time() * 1000))
+
+
+def decrypt_password(pass_str, secret):
+    """
+    Decrypts the given password using the given secret. The encryption is assumed to be done
+    without IV, in AES.
+    :param str pass_str: Encrypted password string in Base64 encoding
+    :param str secret: The secret string
+    :return: The decrypted password
+    :rtype: str
+    """
+
+    if pass_str is None or pass_str.strip() == "":
+        return pass_str.strip()
+
+    dec_pass = ""
+
+    try:
+        log.debug("Decrypting password")
+        bdecoded_pass = base64.b64decode(pass_str)
+        #secret length should be 16
+        cipher = AES.new(secret, AES.MODE_ECB)
+        dec_pass = unpad(cipher.decrypt(bdecoded_pass))
+    except:
+        log.exception("Exception occurred while decrypting password")
+
+    log.debug("Decrypted PWD: [%r]" % dec_pass)
+    return dec_pass
+
+
+def create_dir(path):
+    """
+    mkdir the provided path
+    :param path: The path to the directory to be made
+    :return: True if mkdir was successful, False if dir already exists
+    :rtype: bool
+    """
+    try:
+        os.mkdir(path)
+        log.info("Successfully created directory [%r]" % path)
+        return True
+    except OSError:
+        log.exception("Directory creating failed in [%r]. Directory already exists. " % path)
+
+    return False
+
+
+def delete_folder_tree(path):
+    """
+    Completely deletes the provided folder
+    :param str path: Full path of the folder
+    :return: void
+    """
+    try:
+        shutil.rmtree(path)
+        log.debug("Directory [%r] deleted." % path)
+    except OSError:
+        log.exception("Deletion of folder path %r failed." % path)
+
+
+def wait_until_ports_active(ip_address, ports, ports_check_timeout=600000):
+    """
+    Blocks until the given list of ports become active
+    :param str ip_address: Ip address of the member to be checked
+    :param list[str] ports: List of ports to be checked
+    :param int ports_check_timeout: The timeout in milliseconds, defaults to 1000*60*10
+    :return: void
+    """
+    if ports_check_timeout is None:
+        ports_check_timeout = 1000 * 60 * 10
+
+    log.debug("Port check timeout: %r" % ports_check_timeout)
+
+    active = False
+    start_time = current_milli_time()
+    while not active:
+        log.info("Waiting for ports to be active: [ip] %r [ports] %r" % (ip_address, ports))
+        active = check_ports_active(ip_address, ports)
+        end_time = current_milli_time()
+        duration = end_time - start_time
+
+        if duration > ports_check_timeout:
+            return
+
+        time.sleep(5)
+
+    log.info("Ports activated: [ip] %r [ports] %r" % (ip_address, ports))
+
+
+def check_ports_active(ip_address, ports):
+    """
+    Checks the given list of port addresses for active state
+    :param str ip_address: Ip address of the member to be checked
+    :param list[str] ports: The list of ports to be checked
+    :return: True if the ports are active, False if at least one is not active
+    :rtype: bool
+    """
+    if len(ports) < 1:
+        raise RuntimeError("No ports found")
+
+    for port in ports:
+        s = socket.socket()
+        s.settimeout(5)
+        try:
+            s.connect((ip_address, int(port)))
+            log.debug("Port %r is active" % port)
+            s.close()
+        except socket.error:
+            log.debug("Print %r is not active" % port)
+            return False
+
+    return True
+
+
+def get_carbon_server_property(property_key):
+    """
+    Reads the carbon.xml file and returns the value for the property key.
+    TODO: Get carbon server xml location
+    :param str property_key: Property key to look for
+    :return: The value of the property, None if the property key is invalid or not present
+    :rtype : str
+    """
+
+    raise NotImplementedError
+
+
+def get_working_dir():
+    """
+    Returns the base directory of the cartridge agent.
+    :return: Base working dir path
+    :rtype : str
+    """
+    #"/path/to/cartridge-agent/modules/util/".split("modules") returns ["/path/to/cartridge-agent/", "/util"]
+    return os.path.abspath(os.path.dirname(__file__)).split("modules")[0]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/util/extensionutils.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/extensionutils.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/extensionutils.py
new file mode 100644
index 0000000..6c58852
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/util/extensionutils.py
@@ -0,0 +1,494 @@
+# 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.
+
+import logging
+import os
+import subprocess
+import time
+
+from log import LogFactory
+from .. config import cartridgeagentconfiguration
+
+
+log = LogFactory().get_log(__name__)
+
+cartridge_agent_config = cartridgeagentconfiguration.CartridgeAgentConfiguration()
+
+
+def execute_copy_artifact_extension(source, destination):
+    try:
+        log.debug("Executing artifacts copy extension")
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.ARTIFACTS_COPY_SCRIPT, False)
+        command = prepare_command(script_name)
+
+        output, errors = execute_command(command + " " + source + " " + destination)
+        log.debug("Artifacts copy script returned: %r" % output)
+    except:
+        log.exception("Could not execute artifacts copy extension")
+
+
+def execute_instance_started_extension(env_params):
+    try:
+        log.debug("Executing instance started extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.INSTANCE_STARTED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Instance started script returned: %r" % output)
+    except:
+        log.exception("Could not execute instance started extension")
+
+
+def execute_instance_activated_extension():
+    try:
+        log.debug("Executing instance activated extension")
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.INSTANCE_ACTIVATED_SCRIPT, False)
+        command = prepare_command(script_name)
+
+        output, errors = execute_command(command)
+        log.debug("Instance activated script returned: %r" % output)
+    except:
+        log.exception("Could not execute instance activated extension")
+
+
+def execute_artifacts_updated_extension(env_params):
+    try:
+        log.debug("Executing artifacts updated extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.ARTIFACTS_UPDATED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Artifacts updated script returned: %r" % output)
+    except:
+        log.exception("Could not execute artifacts updated extension")
+
+
+def execute_subscription_domain_added_extension(env_params):
+    try:
+        log.debug("Executing subscription domain added extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.SUBSCRIPTION_DOMAIN_ADDED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Subscription domain added script returned: %r" % output)
+    except:
+        log.exception("Could not execute subscription domain added extension")
+
+
+def execute_subscription_domain_removed_extension(env_params):
+    try:
+        log.debug("Executing subscription domain removed extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Subscription domain removed script returned: %r" % output)
+    except:
+        log.exception("Could not execute subscription domain removed extension")
+
+
+def execute_start_servers_extension(env_params):
+    try:
+        log.debug("Executing start servers extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.START_SERVERS_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Start servers script returned: %r" % output)
+    except:
+        log.exception("Could not execute start servers extension")
+
+
+def execute_complete_topology_extension(env_params):
+    try:
+        log.debug("Executing complete topology extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.COMPLETE_TOPOLOGY_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Complete topology script returned: %r" % output)
+    except:
+        log.exception("Could not execute complete topology extension")
+
+
+def execute_complete_tenant_extension(env_params):
+    try:
+        log.debug("Executing complete tenant extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.COMPLETE_TENANT_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Complete tenant script returned: %r" % output)
+    except:
+        log.exception("Could not execute complete tenant extension")
+
+
+def execute_tenant_subscribed_extension(env_params):
+    try:
+        log.debug("Executing tenant subscribed extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.TENANT_SUBSCRIBED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Tenant subscribed script returned: %r" % output)
+    except:
+        log.exception("Could not execute tenant subscribed extension")
+
+
+def execute_tenant_unsubscribed_extension(env_params):
+    try:
+        log.debug("Executing tenant unsubscribed extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.TENANT_UNSUBSCRIBED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Tenant unsubscribed script returned: %r" % output)
+    except:
+        log.exception("Could not execute tenant unsubscribed extension")
+
+
+def execute_member_terminated_extension(env_params):
+    try:
+        log.debug("Executing member terminated extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.MEMBER_TERMINATED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Member terminated script returned: %r" % output)
+    except:
+        log.exception("Could not execute member terminated extension")
+
+
+def execute_member_suspended_extension(env_params):
+    try:
+        log.debug("Executing member suspended extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.MEMBER_SUSPENDED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Member suspended script returned: %r" % output)
+    except:
+        log.exception("Could not execute member suspended extension")
+
+
+def execute_member_started_extension(env_params):
+    try:
+        log.debug("Executing member started extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.MEMBER_STARTED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Member started script returned: %r" % output)
+    except:
+        log.exception("Could not execute member started extension")
+
+
+def wait_for_complete_topology():
+    while not TopologyContext.topology.initialized:
+        log.info("Waiting for complete topology event...")
+        time.sleep(5)
+
+
+def check_topology_consistency(service_name, cluster_id, member_id):
+    topology = TopologyContext.get_topology()
+    service = topology.get_service(service_name)
+    if service is None:
+        log.error("Service not found in topology [service] %r" % service_name)
+        return False
+
+    cluster = service.get_cluster(cluster_id)
+    if cluster is None:
+        log.error("Cluster id not found in topology [cluster] %r" % cluster_id)
+        return False
+
+    activated_member = cluster.get_member(member_id)
+    if activated_member is None:
+        log.error("Member id not found in topology [member] %r" % member_id)
+        return False
+
+    return True
+
+
+def is_relevant_member_event(service_name, cluster_id, lb_cluster_id):
+    cluster_id_in_payload = cartridge_agent_config.cluster_id
+    if cluster_id_in_payload is None:
+        return False
+
+    topology = TopologyContext.get_topology()
+    if topology is None or not topology.initialized:
+        return False
+
+    if cluster_id_in_payload == cluster_id:
+        return True
+
+    if cluster_id_in_payload == lb_cluster_id:
+        return True
+
+    service_group_in_payload = cartridge_agent_config.service_group
+    if service_group_in_payload is not None:
+        service_properties = topology.get_service(service_name).properties
+        if service_properties is None:
+            return False
+
+        member_service_group = service_properties[cartridgeagentconstants.SERVICE_GROUP_TOPOLOGY_KEY]
+        if member_service_group is not None and member_service_group == service_group_in_payload:
+            if service_name == cartridge_agent_config.service_name:
+                log.debug("Service names are same")
+                return True
+            elif cartridgeagentconstants.APISTORE_SERVICE_NAME == \
+                    cartridge_agent_config.service_name \
+                    and service_name == cartridgeagentconstants.PUBLISHER_SERVICE_NAME:
+                log.debug("Service name in payload is [store]. Serivce name in event is [%r] " % service_name)
+                return True
+            elif cartridgeagentconstants.PUBLISHER_SERVICE_NAME == \
+                    cartridge_agent_config.service_name \
+                    and service_name == cartridgeagentconstants.APISTORE_SERVICE_NAME:
+                log.debug("Service name in payload is [publisher]. Serivce name in event is [%r] " % service_name)
+                return True
+            elif cartridgeagentconstants.DEPLOYMENT_WORKER == \
+                    cartridge_agent_config.deployment \
+                    and service_name == cartridge_agent_config.manager_service_name:
+                log.debug("Deployment is worker. Worker's manager service name & service name in event are same")
+                return True
+            elif cartridgeagentconstants.DEPLOYMENT_MANAGER == \
+                    cartridge_agent_config.deployment  \
+                    and service_name == cartridge_agent_config.worker_service_name:
+                log.debug("Deployment is manager. Manager's worker service name & service name in event are same")
+                return True
+
+    return False
+
+
+def execute_volume_mount_extension(persistance_mappings_payload):
+    try:
+        log.debug("Executing volume mounting extension: [payload] %r" % persistance_mappings_payload)
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.MOUNT_VOLUMES_SCRIPT, False)
+        command = prepare_command(script_name)
+
+        output, errors = execute_command(command + " " + persistance_mappings_payload)
+        log.debug("Volume mount script returned: %r" % output)
+    except:
+        log.exception("Could not execute Volume mount extension")
+
+
+def execute_cleanup_extension():
+    try:
+        log.debug("Executing cleanup extension")
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.CLEAN_UP_SCRIPT, False)
+        command = prepare_command(script_name)
+
+        output, errors = execute_command(command)
+        log.debug("Cleanup script returned: %r" % output)
+    except:
+        log.exception("Could not execute Cleanup extension")
+
+
+def execute_member_activated_extension(env_params):
+    try:
+        log.debug("Executing member activated extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.MEMBER_ACTIVATED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Member activated script returned: %r" % output)
+    except:
+        log.exception("Could not execute member activated extension")
+
+
+def prepare_command(script_name):
+    extensions_dir = cartridge_agent_config.read_property(
+        cartridgeagentconstants.EXTENSIONS_DIR, False)
+    if extensions_dir.strip() == "":
+        raise RuntimeError("System property not found: %r" % cartridgeagentconstants.EXTENSIONS_DIR)
+
+    file_path = extensions_dir + script_name if str(extensions_dir).endswith("/") \
+        else extensions_dir + "/" + script_name
+
+    if os.path.isfile(file_path):
+        return file_path
+
+    raise IOError("Script file not found : %r" % file_path)
+
+
+def clean_process_parameters(params):
+    """
+    Removes any null valued parameters before passing them to the extension scripts
+    :param dict params:
+    :return: cleaned parameters
+    :rtype: dict
+    """
+    for key, value in params.items():
+        if value is None:
+            del params[key]
+
+    return params
+
+
+def add_payload_parameters(env_params):
+    """
+    Adds the common parameters to be used by the extension scripts
+    :param dict[str, str] env_params: Dictionary to be added
+    :return: Dictionary with updated parameters
+    :rtype: dict[str, str]
+    """
+    env_params["STRATOS_APP_PATH"] = cartridge_agent_config.app_path
+    env_params["STRATOS_PARAM_FILE_PATH"] = cartridge_agent_config.read_property(
+        cartridgeagentconstants.PARAM_FILE_PATH, False)
+    env_params["STRATOS_SERVICE_NAME"] = cartridge_agent_config.service_name
+    env_params["STRATOS_TENANT_ID"] = cartridge_agent_config.tenant_id
+    env_params["STRATOS_CARTRIDGE_KEY"] = cartridge_agent_config.cartridge_key
+    env_params["STRATOS_LB_CLUSTER_ID"] = cartridge_agent_config.lb_cluster_id
+    env_params["STRATOS_CLUSTER_ID"] = cartridge_agent_config.cluster_id
+    env_params["STRATOS_NETWORK_PARTITION_ID"] = \
+        cartridge_agent_config.network_partition_id
+    env_params["STRATOS_PARTITION_ID"] = cartridge_agent_config.partition_id
+    env_params["STRATOS_PERSISTENCE_MAPPINGS"] = \
+        cartridge_agent_config.persistence_mappings
+    env_params["STRATOS_REPO_URL"] = cartridge_agent_config.repo_url
+
+    lb_cluster_id_in_payload = cartridge_agent_config.lb_cluster_id
+    member_ips = get_lb_member_ip(lb_cluster_id_in_payload)
+    if member_ips is not None:
+        env_params["STRATOS_LB_IP"] = member_ips[0]
+        env_params["STRATOS_LB_PUBLIC_IP"] = member_ips[1]
+    else:
+        env_params["STRATOS_LB_IP"] = cartridge_agent_config.lb_private_ip
+        env_params["STRATOS_LB_PUBLIC_IP"] = cartridge_agent_config.lb_public_ip
+
+    topology = TopologyContext.get_topology()
+    if topology.initialized:
+        service = topology.get_service(cartridge_agent_config.service_name)
+        cluster = service.get_cluster(cartridge_agent_config.cluster_id)
+        member_id_in_payload = cartridge_agent_config.member_id
+        add_properties(service.properties, env_params, "SERVICE_PROPERTY")
+        add_properties(cluster.properties, env_params, "CLUSTER_PROPERTY")
+        add_properties(cluster.get_member(member_id_in_payload).properties, env_params, "MEMBER_PROPERTY")
+
+    return env_params
+
+
+def add_properties(properties, params, prefix):
+    """
+    Adds the given property list to the parameters list with given prefix in the parameter name
+    :param dict[str, str] properties: service properties
+    :param dict[str, str] params:
+    :param str prefix:
+    :return: dict[str, str]
+    """
+    if properties is None or properties.items() is None:
+        return
+
+    for key in properties:
+        params["STRATOS_" + prefix + "_" + key] = str(properties[key])
+        log.debug("Property added: [key] STRATOS_ " + prefix + "_" + key + "[value] " + properties[key])
+
+
+def get_lb_member_ip(lb_cluster_id):
+    topology = TopologyContext.get_topology()
+    services = topology.get_services()
+
+    for service in services:
+        clusters = service.get_clusters()
+        for cluster in clusters:
+            members = cluster.get_members()
+            for member in members:
+                if member.cluster_id == lb_cluster_id:
+                    return [member.member_ip, member.member_public_ip]
+
+    return None
+
+
+def execute_command(command, env_params=None):
+    """
+    Executes the given command string with given environment parameters
+    :param str command: Command with arguments to be executed
+    :param dict[str, str] env_params: Environment variables to be used
+    :return: output and error string tuple, RuntimeError if errors occur
+    :rtype: tuple
+    :exception: RuntimeError
+    """
+    os_env = os.environ.copy()
+    if env_params is not None:
+        os_env.update(env_params)
+
+    p = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os_env)
+    output, errors = p.communicate()
+    log.debug("output = %r" % output)
+    log.debug("error = %r" % errors)
+    if len(errors) > 0:
+        raise RuntimeError("Command execution failed: \n %r" % errors)
+
+    return output, errors
+
+
+from .. topology.topologycontext import *
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/util/log.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/util/log.py b/tools/python-cartridge-agent/cartridgeagent/modules/util/log.py
new file mode 100644
index 0000000..9bad214
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/util/log.py
@@ -0,0 +1,55 @@
+# 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.
+
+import logging
+import logging.config
+import os
+
+
+class LogFactory(object):
+    """
+    Singleton implementation for handling logging in CartridgeAgent
+    """
+    class __LogFactory:
+        def __init__(self):
+            self.logs = {}
+            logging_conf = os.path.abspath(os.path.dirname(__file__)).split("modules")[0] + "logging.ini"
+            logging.config.fileConfig(logging_conf)
+
+        def get_log(self, name):
+            if name not in self.logs:
+                self.logs[name] = logging.getLogger(name)
+
+            return self.logs[name]
+
+    instance = None
+
+    def __new__(cls, *args, **kwargs):
+        if not LogFactory.instance:
+            LogFactory.instance = LogFactory.__LogFactory()
+
+        return LogFactory.instance
+
+    def get_log(self, name):
+        """
+        Returns a logger class with the specified channel name. Creates a new logger if one doesn't exists for the
+        specified channel
+        :param str name: Channel name
+        :return: The logger class
+        :rtype: RootLogger
+        """
+        return self.instance.get_log(name)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/test/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/test/__init__.py b/tools/python-cartridge-agent/test/__init__.py
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/test/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/test/test_util.py b/tools/python-cartridge-agent/test/test_util.py
new file mode 100644
index 0000000..2439cf2
--- /dev/null
+++ b/tools/python-cartridge-agent/test/test_util.py
@@ -0,0 +1,4 @@
+from cartridgeagent.modules.util.asyncscheduledtask import AsyncScheduledTask
+
+def test_async_task():
+    assert True
\ No newline at end of file


[32/50] [abbrv] Renamed base module name to python_cartridgeagent Started decrypt password test

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/test/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/test/__init__.py b/tools/python-cartridge-agent/test/__init__.py
deleted file mode 100644
index 13a8339..0000000
--- a/tools/python-cartridge-agent/test/__init__.py
+++ /dev/null
@@ -1,16 +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.

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/test/asynctest.txt
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/test/asynctest.txt b/tools/python-cartridge-agent/test/asynctest.txt
deleted file mode 100644
index 623c418..0000000
--- a/tools/python-cartridge-agent/test/asynctest.txt
+++ /dev/null
@@ -1 +0,0 @@
-1413799652508.8130
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python-cartridge-agent/test/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/test/test_util.py b/tools/python-cartridge-agent/test/test_util.py
deleted file mode 100644
index f62b2e8..0000000
--- a/tools/python-cartridge-agent/test/test_util.py
+++ /dev/null
@@ -1,39 +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.
-
-from cartridgeagent.modules.util.asyncscheduledtask import *
-import time
-
-def test_async_task():
-    test_task = TestTask()
-    astask = ScheduledExecutor(2, test_task)
-    start_time = time.time() * 1000
-    astask.start()
-    time.sleep(3)
-    astask.terminate()
-    f = open("asynctest.txt", "r")
-    end_time = float(f.read())
-    assert (end_time - start_time) >= 2 * 1000, "Task was executed before specified delay"
-
-
-class TestTask(AbstractAsyncScheduledTask):
-
-    def execute_task(self):
-        with open("asynctest.txt", "w") as f:
-            f.seek(0)
-            f.truncate()
-            f.write("%1.4f" % (time.time()*1000))

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/__init__.py b/tools/python_cartridgeagent/__init__.py
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/__init__.py b/tools/python_cartridgeagent/cartridgeagent/__init__.py
new file mode 100644
index 0000000..d216be4
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/__init__.py
@@ -0,0 +1,16 @@
+# 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.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/agent.conf
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/agent.conf b/tools/python_cartridgeagent/cartridgeagent/agent.conf
new file mode 100644
index 0000000..5c087e9
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/agent.conf
@@ -0,0 +1,62 @@
+# 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.
+
+[agent]
+mb.ip                                 =MB-IP
+mb.port                               =MB-PORT
+listen.address                        =LISTEN_ADDR
+thrift.receiver.ip                    =CEP-IP
+thrift.receiver.port                  =CEP-PORT
+thrift.server.admin.username          =CEP-ADMIN-USERNAME
+thrift.server.admin.password          =CEP-ADMIN-PASSWORD
+param.file.path                       =/mnt/cartridge-agent/payload/launch-params
+extensions.dir                        =/mnt/cartridge-agent/extensions
+cep.stats.publisher.enabled           =ENABLE_HEALTH_PUBLISHER
+lb.private.ip                         =LB_PRIVATE_IP
+lb.public.ip                          =LB_PUBLIC_IP
+enable.artifact.update                =ENABLE_ARTFCT_UPDATE
+auto.commit                           =COMMIT_ENABLED
+auto.checkout                         =CHECKOUT_ENABLED
+artifact.update.interval              =ARTFCT_UPDATE_INT
+port.check.timeout                    =PORT_CHECK_TIMEOUT
+enable.data.publisher                 =ENABLE-DATA-PUBLISHER
+monitoring.server.ip                  =MONITORING-SERVER-IP
+monitoring.server.port                =MONITORING-SERVER-PORT
+monitoring.server.secure.port         =MONITORING-SERVER-SECURE-PORT
+monitoring.server.admin.username      =MONITORING-SERVER-ADMIN-USERNAME
+monitoring.server.admin.password      =MONITORING-SERVER-ADMIN-PASSWORD
+log.file.paths                        =LOG_FILE_PATHS
+APP_PATH                              =APP-PATH
+super.tenant.repository.path          =/repository/deployment/server/
+tenant.repository.path                =/repository/tenants/
+extension.instance.started            =instance-started.sh
+extension.start.servers               =start-servers.sh
+extension.instance.activated          =instance-activated.sh
+extension.artifacts.updated           =artifacts-updated.sh
+extension.clean                       =clean.sh
+extension.mount.volumes               =mount_volumes.sh
+extension.member.started              =member-started.sh
+extension.member.activated            =member-activated.sh
+extension.member.suspended            =member-suspended.sh
+extension.member.terminated           =member-terminated.sh
+extension.complete.topology           =complete-topology.sh
+extension.complete.tenant             =complete-tenant.sh
+extension.subscription.domain.added   =subscription-domain-added.sh
+extension.subscription.domain.removed =subscription-domain-removed.sh
+extension.artifacts.copy              =artifacts-copy.sh
+extension.tenant.subscribed           =tenant-subscribed.sh
+extension.tenant.unsubscribed         =tenant-unsubscribed.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/agent.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/agent.py b/tools/python_cartridgeagent/cartridgeagent/agent.py
new file mode 100644
index 0000000..9f1a972
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/agent.py
@@ -0,0 +1,343 @@
+#!/usr/bin/env python
+# 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.
+
+import threading
+
+from modules.exception.parameternotfoundexception import ParameterNotFoundException
+from modules.subscriber import eventsubscriber
+from modules.publisher import cartridgeagentpublisher
+from modules.event.instance.notifier.events import *
+from modules.event.tenant.events import *
+from modules.event.topology.events import *
+from modules.tenant.tenantcontext import *
+from modules.topology.topologycontext import *
+from modules.datapublisher.logpublisher import *
+from modules.config import cartridgeagentconfiguration
+from modules.extensions import defaultextensionhandler
+
+
+class CartridgeAgent(threading.Thread):
+    extension_handler = defaultextensionhandler.DefaultExtensionHandler()
+
+    def __init__(self):
+        threading.Thread.__init__(self)
+
+        mb_ip = cartridgeagentconfiguration.CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_IP)
+        mb_port = cartridgeagentconfiguration.CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_PORT)
+
+        self.__instance_event_subscriber = eventsubscriber.EventSubscriber(
+            cartridgeagentconstants.INSTANCE_NOTIFIER_TOPIC,
+            mb_ip,
+            mb_port)
+        self.__tenant_event_subscriber = eventsubscriber.EventSubscriber(
+            cartridgeagentconstants.TENANT_TOPIC,
+            mb_ip,
+            mb_port)
+        self.__topology_event_subscriber = eventsubscriber.EventSubscriber(
+            cartridgeagentconstants.TOPOLOGY_TOPIC,
+            mb_ip,
+            mb_port)
+
+        self.__tenant_context_initialized = False
+
+        self.log_publish_manager = None
+
+        self.terminated = False
+
+        self.log = LogFactory().get_log(__name__)
+
+        self.cartridge_agent_config = CartridgeAgentConfiguration()
+
+    def run(self):
+        self.log.info("Starting Cartridge Agent...")
+
+        #Check if required prpoerties are set
+        self.validate_required_properties()
+
+        #Start instance notifier listener thread
+        self.subscribe_to_topics_and_register_listeners()
+
+        #Start topology event receiver thread
+        self.register_topology_event_listeners()
+
+        #Start tenant event receiver thread
+        self.register_tenant_event_listeners()
+
+        #wait for intance spawned event
+        while not self.cartridge_agent_config.initialized:
+            self.log.debug("Waiting for Cartridge Agent to be initialized...")
+            time.sleep(1)
+
+        #Execute instance started shell script
+        CartridgeAgent.extension_handler.on_instance_started_event()
+
+        #Publish instance started event
+        cartridgeagentpublisher.publish_instance_started_event()
+
+        #Execute start servers extension
+        try:
+            CartridgeAgent.extension_handler.start_server_extension()
+        except:
+            self.log.exception("Error processing start servers event")
+
+        #Wait for all ports to be active
+        cartridgeagentutils.wait_until_ports_active(
+            self.cartridge_agent_config.listen_address,
+            self.cartridge_agent_config.ports,
+            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False))
+        )
+
+        # check if artifact management is required before publishing instance activated event
+        repo_url = self.cartridge_agent_config.repo_url
+        if repo_url is None or str(repo_url).strip() == "":
+            self.log.info("No artifact repository found")
+            CartridgeAgent.extension_handler.on_instance_activated_event()
+
+            cartridgeagentpublisher.publish_instance_activated_event()
+
+        persistence_mappping_payload = self.cartridge_agent_config.persistence_mappings
+        if persistence_mappping_payload is not None:
+            CartridgeAgent.extension_handler.volume_mount_extension(persistence_mappping_payload)
+
+        # start log publishing thread
+        if DataPublisherConfiguration.get_instance().enabled:
+            log_file_paths = self.cartridge_agent_config.log_file_paths
+            if log_file_paths is None:
+                self.log.exception("No valid log file paths found, no logs will be published")
+            else:
+                self.log_publish_manager = LogPublisherManager(log_file_paths)
+                self.log_publish_manager.start()
+
+        while not self.terminated:
+            time.sleep(1)
+
+        if DataPublisherConfiguration.get_instance().enabled:
+            self.log_publish_manager.terminate_all_publishers()
+
+    def terminate(self):
+        """
+        Allows the CartridgeAgent thread to be terminated
+
+        :return: void
+        """
+        self.terminated = True
+
+    def validate_required_properties(self):
+        """
+        Checks if required properties are set
+        :return: void
+        """
+        #PARAM_FILE_PATH
+        try:
+            self.cartridge_agent_config.read_property(cartridgeagentconstants.PARAM_FILE_PATH)
+        except ParameterNotFoundException:
+            self.log.error("System property not found: %r" % cartridgeagentconstants.PARAM_FILE_PATH)
+            return
+
+        #EXTENSIONS_DIR
+        try:
+            self.cartridge_agent_config.read_property(cartridgeagentconstants.EXTENSIONS_DIR)
+        except ParameterNotFoundException:
+            self.log.error("System property not found: %r" % cartridgeagentconstants.EXTENSIONS_DIR)
+            return
+        
+    def subscribe_to_topics_and_register_listeners(self):
+        self.log.debug("Starting instance notifier event message receiver thread")
+
+        self.__instance_event_subscriber.register_handler("ArtifactUpdatedEvent", self.on_artifact_updated)
+        self.__instance_event_subscriber.register_handler("InstanceCleanupMemberEvent", self.on_instance_cleanup_member)
+        self.__instance_event_subscriber.register_handler("InstanceCleanupClusterEvent", self.on_instance_cleanup_cluster)
+
+        self.__instance_event_subscriber.start()
+        self.log.info("Instance notifier event message receiver thread started")
+
+        # wait till subscribed to continue
+        while not self.__instance_event_subscriber.is_subscribed():
+            time.sleep(2)
+
+    def on_artifact_updated(self, msg):
+        event_obj = ArtifactUpdatedEvent.create_from_json(msg.payload)
+        CartridgeAgent.extension_handler.on_artifact_updated_event(event_obj)
+
+    def on_instance_cleanup_member(self, msg):
+        member_in_payload = self.cartridge_agent_config.member_id
+        event_obj = InstanceCleanupMemberEvent.create_from_json(msg.payload)
+        member_in_event = event_obj.member_id
+        if member_in_payload == member_in_event:
+            CartridgeAgent.extension_handler.on_instance_cleanup_member_event(event_obj)
+
+    def on_instance_cleanup_cluster(self, msg):
+        event_obj = InstanceCleanupClusterEvent.create_from_json(msg.payload)
+        cluster_in_payload = self.cartridge_agent_config.cluster_id
+        cluster_in_event = event_obj.cluster_id
+
+        if cluster_in_event == cluster_in_payload:
+            CartridgeAgent.extension_handler.on_instance_cleanup_cluster_event(event_obj)
+
+    def register_topology_event_listeners(self):
+        self.log.debug("Starting topology event message receiver thread")
+
+        self.__topology_event_subscriber.register_handler("MemberActivatedEvent", self.on_member_activated)
+        self.__topology_event_subscriber.register_handler("MemberTerminatedEvent", self.on_member_terminated)
+        self.__topology_event_subscriber.register_handler("MemberSuspendedEvent", self.on_member_suspended)
+        self.__topology_event_subscriber.register_handler("CompleteTopologyEvent", self.on_complete_topology)
+        self.__topology_event_subscriber.register_handler("MemberStartedEvent", self.on_member_started)
+        self.__topology_event_subscriber.register_handler("InstanceSpawnedEvent", self.on_instance_spawned)
+
+        self.__topology_event_subscriber.start()
+        self.log.info("Cartridge Agent topology receiver thread started")
+
+    def on_instance_spawned(self, msg):
+        self.log.debug("Instance spawned event received: %r" % msg.payload)
+        if self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = InstanceSpawnedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_instance_spawned_event(event_obj)
+        except:
+            self.log.exception("Error processing instance spawned event")
+
+    def on_member_activated(self, msg):
+        self.log.debug("Member activated event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = MemberActivatedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_member_activated_event(event_obj)
+        except:
+            self.log.exception("Error processing member activated event")
+
+    def on_member_terminated(self, msg):
+        self.log.debug("Member terminated event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = MemberTerminatedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_member_terminated_event(event_obj)
+        except:
+            self.log.exception("Error processing member terminated event")
+
+    def on_member_suspended(self, msg):
+        self.log.debug("Member suspended event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = MemberSuspendedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_member_suspended_event(event_obj)
+        except:
+            self.log.exception("Error processing member suspended event")
+
+    def on_complete_topology(self, msg):
+        if not self.cartridge_agent_config.initialized:
+            self.log.debug("Complete topology event received")
+            event_obj = CompleteTopologyEvent.create_from_json(msg.payload)
+            TopologyContext.update(event_obj.topology)
+            try:
+                CartridgeAgent.extension_handler.on_complete_topology_event(event_obj)
+            except:
+                self.log.exception("Error processing complete topology event")
+        else:
+            self.log.info("Complete topology event updating task disabled")
+
+    def on_member_started(self, msg):
+        self.log.debug("Member started event received: %r" % msg.payload)
+        if not self.cartridge_agent_config.initialized:
+            return
+
+        event_obj = MemberStartedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_member_started_event(event_obj)
+        except:
+            self.log.exception("Error processing member started event")
+
+    def register_tenant_event_listeners(self):
+        self.log.debug("Starting tenant event message receiver thread")
+        self.__tenant_event_subscriber.register_handler("SubscriptionDomainAddedEvent", self.on_subscription_domain_added)
+        self.__tenant_event_subscriber.register_handler("SubscriptionDomainsRemovedEvent", self.on_subscription_domain_removed)
+        self.__tenant_event_subscriber.register_handler("CompleteTenantEvent", self.on_complete_tenant)
+        self.__tenant_event_subscriber.register_handler("TenantSubscribedEvent", self.on_tenant_subscribed)
+        self.__tenant_event_subscriber.register_handler("TenantUnSubscribedEvent", self.on_tenant_unsubscribed)
+
+        self.__tenant_event_subscriber.start()
+        self.log.info("Tenant event message receiver thread started")
+
+    def on_subscription_domain_added(self, msg):
+        self.log.debug("Subscription domain added event received : %r" % msg.payload)
+        event_obj = SubscriptionDomainAddedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_subscription_domain_added_event(event_obj)
+        except:
+            self.log.exception("Error processing subscription domains added event")
+
+    def on_subscription_domain_removed(self, msg):
+        self.log.debug("Subscription domain removed event received : %r" % msg.payload)
+        event_obj = SubscriptionDomainRemovedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_subscription_domain_removed_event(event_obj)
+        except:
+            self.log.exception("Error processing subscription domains removed event")
+
+    def on_complete_tenant(self, msg):
+        if not self.__tenant_context_initialized:
+            self.log.debug("Complete tenant event received")
+            event_obj = CompleteTenantEvent.create_from_json(msg.payload)
+            TenantContext.update(event_obj.tenants)
+
+            try:
+                CartridgeAgent.extension_handler.on_complete_tenant_event(event_obj)
+                self.__tenant_context_initialized = True
+            except:
+                self.log.exception("Error processing complete tenant event")
+        else:
+            self.log.info("Complete tenant event updating task disabled")
+
+    def on_tenant_subscribed(self, msg):
+        self.log.debug("Tenant subscribed event received: %r" % msg.payload)
+        event_obj = TenantSubscribedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_tenant_subscribed_event(event_obj)
+        except:
+            self.log.exception("Error processing tenant subscribed event")
+
+    def on_tenant_unsubscribed(self, msg):
+        self.log.debug("Tenant unSubscribed event received: %r" % msg.payload)
+        event_obj = TenantUnsubscribedEvent.create_from_json(msg.payload)
+        try:
+            CartridgeAgent.extension_handler.on_tenant_unsubscribed_event(event_obj)
+        except:
+            self.log.exception("Error processing tenant unSubscribed event")
+
+
+def main():
+    cartridge_agent = CartridgeAgent()
+    log = LogFactory().get_log(__name__)
+
+    try:
+        log.debug("Starting cartridge agent")
+        cartridge_agent.start()
+    except:
+        log.exception("Cartridge Agent Exception")
+        cartridge_agent.terminate()
+
+
+if __name__ == "__main__":
+    main()

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/logging.ini
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/logging.ini b/tools/python_cartridgeagent/cartridgeagent/logging.ini
new file mode 100644
index 0000000..3e49a96
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/logging.ini
@@ -0,0 +1,52 @@
+# 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.
+
+
+[formatters]
+keys=default
+
+[formatter_default]
+format=%(asctime)s:%(levelname)s:%(message)s
+class=logging.Formatter
+
+[handlers]
+keys=console, error_file, log_file
+
+[handler_console]
+class=logging.StreamHandler
+formatter=default
+args=tuple()
+
+[handler_log_file]
+class=logging.FileHandler
+level=LOG_LEVEL
+formatter=default
+args=("agent.log", "w")
+
+[handler_error_file]
+class=logging.FileHandler
+level=ERROR
+formatter=default
+args=("error.log", "w")
+
+[loggers]
+keys=root
+
+[logger_root]
+level=LOG_LEVEL
+formatter=default
+handlers=console,error_file,log_file
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/__init__.py
new file mode 100644
index 0000000..d216be4
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/__init__.py
@@ -0,0 +1,16 @@
+# 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.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
new file mode 100644
index 0000000..6da9c58
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py
@@ -0,0 +1,503 @@
+# 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.
+
+from threading import current_thread, Thread
+from git import *
+from gittle import Gittle, GittleAuth  # GitPython and Gittle are both used at the time being for pros and cons of both
+import urllib2
+
+from ... util.log import LogFactory
+from ... util import cartridgeagentutils, extensionutils, cartridgeagentconstants
+from gitrepository import GitRepository
+from ... config import cartridgeagentconfiguration
+from ... util.asyncscheduledtask import AbstractAsyncScheduledTask, ScheduledExecutor
+from ... artifactmgt.repositoryinformation import RepositoryInformation
+
+class AgentGitHandler:
+    """
+    Handles all the git artifact management tasks related to a cartridge
+    """
+
+    log = LogFactory().get_log(__name__)
+
+    SUPER_TENANT_ID = -1234
+    SUPER_TENANT_REPO_PATH = "/repository/deployment/server/"
+    TENANT_REPO_PATH = "/repository/tenants/"
+
+    extension_handler = None
+
+    __git_repositories = {}
+    # (tenant_id => gitrepository.GitRepository)
+
+    cartridge_agent_config = cartridgeagentconfiguration.CartridgeAgentConfiguration()
+
+    @staticmethod
+    def checkout(repo_info):
+        """
+        Checks out the code from the remote repository.
+        If local repository path is empty, a clone operation is done.
+        If there is a cloned repository already on the local repository path, a pull operation
+        will be performed.
+        If there are artifacts not in the repository already on the local repository path,
+        they will be added to a git repository, the remote url added as origin, and then
+        a pull operation will be performed.
+
+        :param RepositoryInformation repo_info: The repository information object
+        :return: A tuple containing whether it was an initial clone or not, and the repository
+        context object
+        :rtype: tuple(bool, GitRepository)
+        """
+        repo_context = AgentGitHandler.get_repo_context(repo_info.tenant_id)
+        if repo_context is not None:
+            #has been previously cloned, this is not the subscription run
+            subscribe_run = False
+            if AgentGitHandler.is_valid_git_repository(repo_context):
+                AgentGitHandler.log.debug("Existing git repository detected for tenant %r, no clone required" % repo_info.tenant_id)
+                AgentGitHandler.pull(repo_context)
+            else:
+                if not os.listdir(repo_context.local_repo_path):
+                    #empty dir, clone
+                    repo_context.repo = AgentGitHandler.clone(repo_info)
+                else:
+                    #not empty
+                    if AgentGitHandler.sync_initial_local_artifacts(repo_context):
+                        AgentGitHandler.pull(repo_context)
+                    else:
+                        repo_context = None
+        else:
+            #subscribing run.. need to clone
+            subscribe_run = True
+            repo_context = AgentGitHandler.clone(repo_context)
+
+        return subscribe_run, repo_context
+
+    @staticmethod
+    def sync_initial_local_artifacts(repo_context):
+        #init git repo
+        AgentGitHandler.init(repo_context.local_repo_path)
+
+        # add remote repos
+        return AgentGitHandler.add_remote(repo_context)
+
+    @staticmethod
+    def add_remote(repo_context):
+        try:
+            #add origin remote
+            repo_context.repo.create_remote("origin", repo_context.repo_url)
+            #fetch branch details from origin
+            repo_context.repo.git.fetch()
+            #checkout master branch from origin/master as tracking
+            repo_context.repo.git.branch("-f", "--track", "master", "origin/master")
+            return True
+        except:
+            AgentGitHandler.log.exception("Error in adding remote origin %r for local repository %r"
+                                          % (repo_context.repo_url, repo_context.local_repo_path))
+            return False
+
+    @staticmethod
+    def init(path):
+        try:
+            repo = Gittle.init(path)
+            return repo
+        except:
+            AgentGitHandler.log.exception("Initializing local repo at %r failed" % path)
+            raise Exception("Initializing local repo at %r failed" % path)
+
+    @staticmethod
+    def is_valid_git_repository(repo_context):
+        if repo_context.cloned:
+            return True
+
+        for ref in repo_context.repo.refs:
+            try:
+                ref._get_object()
+            except ValueError:
+                return False
+
+        return True
+
+    @staticmethod
+    def pull(repo_context):
+        repo = Repo(repo_context.local_repo_path)
+        from ....agent import CartridgeAgent
+        AgentGitHandler.extension_handler = CartridgeAgent.extension_handler
+        try:
+            repo.git.checkout("master")
+            pull_output = repo.git.pull()
+            if "Already up-to-date." not in pull_output:
+                AgentGitHandler.log.debug("Artifacts were updated as a result of the pull operation, thread: %r - %r" % (current_thread().getName(), current_thread().ident))
+
+            AgentGitHandler.extension_handler.on_artifact_update_scheduler_event(repo_context.tenant_id)
+        except GitCommandError as ex:
+            if "fatal: Could not read from remote repository." in ex:
+                #invalid configuration, need to delete and reclone
+                AgentGitHandler.log.warn("Git pull unsuccessful for tenant %r, invalid configuration. %r" % (repo_context.tenant_id, ex))
+                cartridgeagentutils.delete_folder_tree(repo_context.local_repo_path)
+                AgentGitHandler.clone(RepositoryInformation(
+                    repo_context.repo_url,
+                    repo_context.repo_username,
+                    repo_context.repo_password,
+                    repo_context.local_repo_path,
+                    repo_context.tenant_id,
+                    repo_context.is_multitenant,
+                    repo_context.commit_enabled
+                ))
+                AgentGitHandler.extension_handler.on_artifact_update_scheduler_event(repo_context.tenant_id)
+            elif "error: Your local changes to the following files would be overwritten by merge:" in ex:
+                #conflict error
+                AgentGitHandler.log.warn("Git pull unsuccessful for tenant %r, conflicts detected." % repo_context.tenant_id)
+                #raise ex
+
+                """
+                0:'git pull' returned exit status 1: error: Your local changes to the following files would be overwritten by merge:
+                1:    README.md
+                2:    index.php
+                3:Please, commit your changes or stash them before you can merge.
+                4:Aborting
+                """
+                conflict_list = []
+                files_arr = str(ex).split("\n")
+                for file_index in range(1, len(files_arr) - 2):
+                    file_name = files_arr[file_index].strip()
+                    conflict_list.append(file_name)
+                    AgentGitHandler.log.debug("Added the file path %r to checkout from the remote repository" % file_name)
+
+                AgentGitHandler.checkout_individually(conflict_list, repo)
+            elif "fatal: unable to access " in ex:
+                #transport error
+                AgentGitHandler.log.exception("Accessing remote git repository %r failed for tenant %r" % (repo_context.repo_url, repo_context.tenant_id))
+            else:
+                AgentGitHandler.log.exception("Git pull operation for tenant %r failed" % repo_context.tenant_id)
+
+    @staticmethod
+    def checkout_individually(conflict_list, repo):
+        try:
+            for conflicted_file in conflict_list:
+                repo.git.checkout(conflicted_file)
+                AgentGitHandler.log.info("Checked out the conflicting files from the remote repository successfully")
+        except:
+            AgentGitHandler.log.exception("Checking out artifacts from index failed")
+
+    @staticmethod
+    def clone(repo_info):
+        repo_context = None
+        try:
+            repo_context = AgentGitHandler.create_git_repo_context(repo_info)
+            #create the directory if it doesn't exist
+            if not os.path.isdir(repo_context.local_repo_path):
+                cartridgeagentutils.create_dir(repo_context.local_repo_path)
+
+            auth = AgentGitHandler.create_auth_configuration(repo_context)
+
+            if auth is not None:
+                # authentication is required, use Gittle
+                gittle_repo = Gittle.clone(repo_context.repo_url, repo_context.local_repo_path, auth=auth)
+                repo = Repo(repo_context.local_repo_path)
+            else:
+                # authentication is not required, use GitPython
+                repo = Repo.clone_from(repo_context.repo_url, repo_context.local_repo_path)
+                gittle_repo = Gittle(repo_context.local_repo_path)
+
+            repo_context.cloned = True
+            repo_context.gittle_repo = gittle_repo
+            repo_context.repo  = repo
+            AgentGitHandler.add_repo_context(repo_context)
+            AgentGitHandler.log.info("Git clone operation for tenant %r successful" % repo_context.tenant_id)
+        except urllib2.URLError:
+            AgentGitHandler.log.exception("Accessing remote git repository failed for tenant %r" % repo_context.tenant_id)
+        except OSError:
+            AgentGitHandler.log.exception("Permission denied for repository path for tenant %r" % repo_context.tenant_id)
+        except:
+            AgentGitHandler.log.exception("Git clone operation for tenant %r failed" % repo_context.tenant_id)
+        finally:
+            return repo_context
+
+    @staticmethod
+    def create_auth_configuration(repo_context):
+        """
+        Creates a GittleAuth object based on the type of authorization
+        :param GitRepository repo_context: The repository context object
+        :return: GittleAuth object or None if no authorization needed
+        :rtype: GittleAuth
+        """
+        if repo_context.key_based_auth:
+            pkey = AgentGitHandler.get_private_key()
+            auth = GittleAuth(pkey=pkey)
+        elif repo_context.repo_username.strip() != "" and repo_context.repo_password.strip() != "":
+            auth = GittleAuth(username=repo_context.repo_username, password=repo_context.repo_password)
+        else:
+            auth = None
+
+        return auth
+
+    @staticmethod
+    def get_private_key():
+        """
+        Returns a file handler to the private key path specified by Carbon or default if not specified
+        by Carbon
+        :return: The file object of the private key file
+        :rtype: file
+        """
+        pkey_name = cartridgeagentutils.get_carbon_server_property("SshPrivateKeyName")
+        if pkey_name is  None:
+            pkey_name = "wso2"
+
+        pkey_path = cartridgeagentutils.get_carbon_server_property("SshPrivateKeyPath")
+        if pkey_path is None:
+            pkey_path = os.environ["HOME"] + "/.ssh"
+
+        if pkey_path.endswith("/"):
+            pkey_ptr = pkey_path + pkey_name
+        else:
+            pkey_ptr = pkey_path + "/" + pkey_name
+
+        pkey_file = open(pkey_ptr)
+
+        return pkey_file
+
+
+    @staticmethod
+    def add_repo_context(repo_context):
+        AgentGitHandler.__git_repositories[repo_context.tenant_id] = repo_context
+
+    @staticmethod
+    def get_repo_context(tenant_id):
+        """
+
+        :param int tenant_id:
+        :return: GitRepository object
+        :rtype: GitRepository
+        """
+        if tenant_id in AgentGitHandler.__git_repositories:
+            return AgentGitHandler.__git_repositories[tenant_id]
+
+        return None
+
+    @staticmethod
+    def remove_repo_context(tenant_id):
+        if tenant_id in AgentGitHandler.__git_repositories:
+            del AgentGitHandler.__git_repositories[tenant_id]
+
+    @staticmethod
+    def create_git_repo_context(repo_info):
+        repo_context = GitRepository()
+        repo_context.tenant_id = repo_info.tenant_id
+        repo_context.local_repo_path = AgentGitHandler.get_repo_path_for_tenant(
+            repo_info.tenant_id, repo_info.repo_path, repo_info.is_multitenant)
+        repo_context.repo_url = repo_info.repo_url
+        repo_context.repo_username = repo_info.repo_username
+        repo_context.repo_password = repo_info.repo_password
+        repo_context.is_multitenant = repo_info.is_multitenant
+        repo_context.commit_enabled = repo_info.commit_enabled
+
+        if AgentGitHandler.is_key_based_auth(repo_info.repo_url, repo_info.tenant_id):
+            repo_context.key_based_auth = True
+        else:
+            repo_context.key_based_auth = False
+
+        repo_context.cloned = False
+
+        repo_context.repo = None
+        repo_context.gittle_repo = None
+
+        return repo_context
+
+    @staticmethod
+    def is_key_based_auth(repo_url, tenant_id):
+        """
+        Checks if the given git repo has key based authentication
+        :param str repo_url: Git repository remote url
+        :param str tenant_id: Tenant ID
+        :return: True if key based, False otherwise
+        :rtype: bool
+        """
+        if repo_url.startswith("http://") or repo_url.startswith("https://"):
+            # username and password, not key based
+            return False
+        elif repo_url.startswith("git://github.com"):
+            # no auth required
+            return False
+        elif repo_url.startswith("ssh://") or "@" in repo_url:
+            # key based
+            return True
+        else:
+            AgentGitHandler.log.error("Invalid git URL provided for tenant " + tenant_id)
+            raise RuntimeError("Invalid git URL provided for tenant " + tenant_id)
+
+    @staticmethod
+    def get_repo_path_for_tenant(tenant_id, git_local_repo_path, is_multitenant):
+        repo_path = ""
+
+        if is_multitenant:
+            if tenant_id == AgentGitHandler.SUPER_TENANT_ID:
+                #super tenant, /repository/deploy/server/
+                super_tenant_repo_path = AgentGitHandler.cartridge_agent_config.super_tenant_repository_path
+                #"app_path"
+                repo_path += git_local_repo_path
+
+                if super_tenant_repo_path is not None  and super_tenant_repo_path != "":
+                    super_tenant_repo_path = super_tenant_repo_path if super_tenant_repo_path.startswith("/") else "/" + super_tenant_repo_path
+                    super_tenant_repo_path = super_tenant_repo_path if super_tenant_repo_path.endswith("/") else  super_tenant_repo_path + "/"
+                    #"app_path/repository/deploy/server/"
+                    repo_path += super_tenant_repo_path
+                else:
+                    #"app_path/repository/deploy/server/"
+                    repo_path += AgentGitHandler.SUPER_TENANT_REPO_PATH
+
+            else:
+                #normal tenant, /repository/tenants/tenant_id
+                tenant_repo_path = AgentGitHandler.cartridge_agent_config.tenant_repository_path
+                #"app_path"
+                repo_path += git_local_repo_path
+
+                if tenant_repo_path is not None and tenant_repo_path != "":
+                    tenant_repo_path = tenant_repo_path if tenant_repo_path.startswith("/") else "/" + tenant_repo_path
+                    tenant_repo_path = tenant_repo_path if tenant_repo_path.endswith("/") else tenant_repo_path + "/"
+                    #"app_path/repository/tenants/244653444"
+                    repo_path += tenant_repo_path + tenant_id
+                else:
+                    #"app_path/repository/tenants/244653444"
+                    repo_path += AgentGitHandler.TENANT_REPO_PATH + tenant_id
+
+                #tenant_dir_path = git_local_repo_path + AgentGitHandler.TENANT_REPO_PATH + tenant_id
+                cartridgeagentutils.create_dir(repo_path)
+        else:
+            #not multi tenant, app_path
+            repo_path = git_local_repo_path
+
+        AgentGitHandler.log.debug("Repo path returned : %r" % repo_path)
+        return repo_path
+
+    @staticmethod
+    def commit(repo_info):
+        """
+        Commits and pushes new artifacts to the remote repository
+        :param repo_info:
+        :return:
+        """
+        tenant_id = repo_info.tenant_id
+        repo_context = AgentGitHandler.get_repo_context(tenant_id)
+        gittle_repo = repo_context.gittle_repo
+        try:
+            modified = True if gittle_repo.modified_unstaged_files.count > 0 else False
+        except OSError:
+            # removed files
+            modified = True
+
+        if not modified:
+            AgentGitHandler.log.debug("No changes detected in the local repository for tenant " + tenant_id)
+            return
+
+        gittle_repo.stage(gittle_repo.untracked_files)
+        gittle_repo.stage(gittle_repo.removed_files)
+        gittle_repo.stage(gittle_repo.modified_unstaged_files)
+
+        #commit to local repositpory
+        commit_message = "tenant " + tenant_id + "'s artifacts committed to local repo at " + repo_context.local_repo_path
+
+        try:
+            commit_hash = gittle_repo.commit(name="First Author", email="author@example.org", message=commit_message)
+            AgentGitHandler.log.debug("Committed artifacts for tenant : " + tenant_id + " : " + commit_hash)
+        except:
+            AgentGitHandler.log.exception("Committing artifacts to local repository failed for tenant " + tenant_id)
+
+        #push to remote
+        try:
+            repo = repo_context.repo
+            #TODO: check key based authentication
+            credentialed_remote_url = AgentGitHandler.get_credentialed_remote_url(repo_context)
+            push_remote = repo.create_remote('push_remote', credentialed_remote_url)
+            push_remote.push()
+            AgentGitHandler.log.debug("Pushed artifacts for tenant : " + tenant_id)
+        except:
+            AgentGitHandler.log.exception("Pushing artifacts to remote repository failed for tenant " + tenant_id)
+
+    @staticmethod
+    def get_credentialed_remote_url(repo_context):
+        """
+        Creates a remote url including the credentials
+        :param repo_context:
+        :return:
+        """
+        username = repo_context.repo_username
+        password = repo_context.repo_password
+
+        raise NotImplementedError
+
+    @staticmethod
+    def schedule_artifact_update_scheduled_task(repo_info, auto_checkout, auto_commit, update_interval):
+        repo_context = AgentGitHandler.get_repo_context(repo_info.tenant_id)
+
+        if repo_context is None:
+            AgentGitHandler.log.error("Unable to schedule artifact sync task, repositoryContext null for tenant %r" % repo_info.tenant_id)
+            return
+
+        if repo_context.scheduled_update_task is None:
+            #TODO: make thread safe
+            artifact_update_task = ArtifactUpdateTask(repo_info, auto_checkout, auto_commit)
+            async_task = ScheduledExecutor(update_interval, artifact_update_task)
+
+            repo_context.scheduled_update_task = async_task
+            async_task.start()
+            AgentGitHandler.log.info("Scheduled Artifact Synchronization Task for path %r" % repo_context.local_repo_path)
+        else:
+            AgentGitHandler.log.info("Artifact Synchronization Task for path %r already scheduled" % repo_context.local_repo_path)
+
+    @staticmethod
+    def remove_repo(tenant_id):
+        repo_context = AgentGitHandler.get_repo_context(tenant_id)
+
+        #stop artifact update task
+        repo_context.scheduled_update_task.terminate()
+
+        #remove git contents
+        cartridgeagentutils.delete_folder_tree(repo_context.local_repo_path)
+
+        AgentGitHandler.remove_repo_context(tenant_id)
+
+        if tenant_id == -1234:
+            if AgentGitHandler.cartridge_agent_config.is_multitenant:
+                extensionutils.execute_copy_artifact_extension(
+                    cartridgeagentconstants.SUPERTENANT_TEMP_PATH,
+                    AgentGitHandler.cartridge_agent_config.app_path + "/repository/deployment/server/"
+                )
+
+        AgentGitHandler.log.info("git repository deleted for tenant %r" % repo_context.tenant_id)
+
+        return True
+
+
+class ArtifactUpdateTask(AbstractAsyncScheduledTask):
+    """
+    Checks if the autocheckout and autocommit are enabled and executes respective tasks
+    """
+
+    def __init__(self, repo_info, auto_checkout, auto_commit):
+        self.log = LogFactory().get_log(__name__)
+        self.repo_info = repo_info
+        self.auto_checkout = auto_checkout
+        self.auto_commit = auto_commit
+
+    def execute_task(self):
+        try:
+            if self.auto_checkout:
+                AgentGitHandler.checkout(self.repo_info)
+        except:
+            self.log.exception("Auto checkout task failed")
+
+        if self.auto_commit:
+            AgentGitHandler.commit(self.repo_info)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/gitrepository.py b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
new file mode 100644
index 0000000..98a8a44
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/gitrepository.py
@@ -0,0 +1,51 @@
+# 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.
+
+from ...util.asyncscheduledtask import AsyncScheduledTask
+from gittle import Gittle
+from git import *
+
+class GitRepository:
+    """
+    Represents a git repository inside a particular instance
+    """
+
+    def __init__(self):
+        self.repo_url = None
+        """ :type : str  """
+        self.local_repo_path = None
+        """ :type : str  """
+        self.cloned = False
+        """ :type : bool  """
+        self.repo = None
+        """ :type : git.repo.base.Repo  """
+        self.gittle_repo = None
+        """ :type : gittle.gittle.Gittle  """
+        self.tenant_id = None
+        """ :type : int  """
+        self.key_based_auth = False
+        """ :type : bool  """
+        self.repo_username = None
+        """ :type : str  """
+        self.repo_password = None
+        """ :type : str  """
+        self.is_multitenant = False
+        """ :type : bool  """
+        self.commit_enabled = False
+        """ :type : bool  """
+        self.scheduled_update_task = None
+        """:type : AsyncScheduledTask """
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/repositoryinformation.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/repositoryinformation.py b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/repositoryinformation.py
new file mode 100644
index 0000000..b67eada
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/repositoryinformation.py
@@ -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.
+
+class RepositoryInformation:
+    """
+    Holds repository information to be used in artifact management
+    """
+
+    def __init__(self, repo_url, repo_username, repo_password, repo_path, tenant_id, is_multitenant, commit_enabled):
+        self.repo_url = repo_url
+        """ :type : str  """
+        self.repo_username = repo_username
+        """ :type : str  """
+        self.repo_password = repo_password
+        """ :type : str  """
+        self.repo_path = repo_path
+        """ :type : str  """
+        self.tenant_id = tenant_id
+        """ :type : int  """
+        self.is_multitenant = is_multitenant
+        """ :type : bool  """
+        self.commit_enabled = commit_enabled
+        """ :type : bool  """
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/config/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/config/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/config/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/config/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/config/cartridgeagentconfiguration.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/config/cartridgeagentconfiguration.py b/tools/python_cartridgeagent/cartridgeagent/modules/config/cartridgeagentconfiguration.py
new file mode 100644
index 0000000..15871ba
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/config/cartridgeagentconfiguration.py
@@ -0,0 +1,346 @@
+# 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.
+
+import ConfigParser
+import os
+import socket
+
+from ..util.log import LogFactory
+
+
+class CartridgeAgentConfiguration:
+    """
+    Handles the configuration information of the particular Cartridge Agent
+    """
+    class __CartridgeAgentConfiguration:
+        def __init__(self):
+            # set log level
+            self.log = LogFactory().get_log(__name__)
+
+            self.payload_params = {}
+            self.properties = None
+
+            self.service_group = None
+            """ :type : str  """
+            self.is_clustered = False
+            """ :type : bool  """
+            self.service_name = None
+            """ :type : str  """
+            self.cluster_id = None
+            """ :type : str  """
+            self.network_partition_id = None
+            """ :type : str  """
+            self.partition_id = None
+            """ :type : str  """
+            self.member_id = None
+            """ :type : str  """
+            self.cartridge_key = None
+            """ :type : str  """
+            self.app_path = None
+            """ :type : str  """
+            self.repo_url = None
+            """ :type : str  """
+            self.ports = []
+            """ :type : list[str]  """
+            self.log_file_paths = []
+            """ :type : list[str]  """
+            self.is_multitenant = False
+            """ :type : bool  """
+            self.persistence_mappings = None
+            """ :type : str  """
+            self.is_commits_enabled = False
+            """ :type : bool  """
+            self.is_checkout_enabled = False
+            """ :type : bool  """
+            self.listen_address = None
+            """ :type : str  """
+            self.is_internal_repo = False
+            """ :type : bool  """
+            self.tenant_id = None
+            """ :type : str  """
+            self.lb_cluster_id = None
+            """ :type : str  """
+            self.min_count = None
+            """ :type : str  """
+            self.lb_private_ip = None
+            """ :type : str  """
+            self.lb_public_ip = None
+            """ :type : str  """
+            self.tenant_repository_path = None
+            """ :type : str  """
+            self.super_tenant_repository_path = None
+            """ :type : str  """
+            self.deployment = None
+            """ :type : str  """
+            self.manager_service_name = None
+            """ :type : str  """
+            self.worker_service_name = None
+            """ :type : str  """
+            self.is_primary = False
+            """ :type : bool  """
+
+            self.payload_params = {}
+            self.__read_conf_file()
+            self.__read_parameter_file()
+
+            self.initialized = False
+            """ :type : bool """
+
+            try:
+                self.service_group = self.payload_params[cartridgeagentconstants.SERVICE_GROUP] \
+                    if cartridgeagentconstants.SERVICE_GROUP in self.payload_params \
+                    else None
+
+                if cartridgeagentconstants.CLUSTERING in self.payload_params and \
+                        str(self.payload_params[cartridgeagentconstants.CLUSTERING]).strip().lower() == "true":
+                    self.is_clustered = True
+                else:
+                    self.is_clustered = False
+                # self.__isClustered = self.payload_params[
+                # cartridgeagentconstants.CLUSTERING] if cartridgeagentconstants.CLUSTERING in self.payload_params else None
+
+                self.service_name = self.read_property(cartridgeagentconstants.SERVICE_NAME)
+                self.cluster_id = self.read_property(cartridgeagentconstants.CLUSTER_ID)
+                self.network_partition_id = self.read_property(cartridgeagentconstants.NETWORK_PARTITION_ID, False)
+                self.partition_id = self.read_property(cartridgeagentconstants.PARTITION_ID, False)
+                self.member_id = self.get_member_id(cartridgeagentconstants.MEMBER_ID)
+                self.cartridge_key = self.read_property(cartridgeagentconstants.CARTRIDGE_KEY)
+                self.app_path = self.read_property(cartridgeagentconstants.APP_PATH, False)
+                self.repo_url = self.read_property(cartridgeagentconstants.REPO_URL, False)
+                self.ports = str(self.read_property(cartridgeagentconstants.PORTS)).split("|")
+
+                try:
+                    self.log_file_paths = str(
+                        self.read_property(cartridgeagentconstants.LOG_FILE_PATHS)).strip().split("|")
+                except ParameterNotFoundException as ex:
+                    self.log.debug("Cannot read log file path : %r" % ex.get_message())
+                    self.log_file_paths = None
+
+                is_multi_str = self.read_property(cartridgeagentconstants.MULTITENANT)
+                self.is_multitenant = True if str(is_multi_str).lower().strip() == "true" else False
+
+                try:
+                    self.persistence_mappings = self.read_property(
+                        cartridgeagentconstants.PERSISTENCE_MAPPING)
+                except ParameterNotFoundException as ex:
+                    self.log.debug("Cannot read persistence mapping : %r" % ex.get_message())
+                    self.persistence_mappings = None
+
+                try:
+                    is_commit_str = self.read_property(cartridgeagentconstants.COMMIT_ENABLED)
+                    self.is_commits_enabled = True if str(is_commit_str).lower().strip() == "true" else False
+                except ParameterNotFoundException:
+                    try:
+                        is_commit_str = self.read_property(cartridgeagentconstants.AUTO_COMMIT)
+                        self.is_commits_enabled = True if str(is_commit_str).lower().strip() == "true" else False
+                    except ParameterNotFoundException:
+                        self.log.info(
+                            "%r is not found and setting it to false" % cartridgeagentconstants.COMMIT_ENABLED)
+                        self.is_commits_enabled = False
+
+                auto_checkout_str = self.read_property(cartridgeagentconstants.AUTO_CHECKOUT, False)
+                self.is_checkout_enabled = True if str(auto_checkout_str).lower().strip() == "true" else False
+
+                self.listen_address = self.read_property(
+                    cartridgeagentconstants.LISTEN_ADDRESS, False)
+
+                try:
+                    int_repo_str = self.read_property(cartridgeagentconstants.PROVIDER)
+                    self.is_internal_repo = True if str(int_repo_str).strip().lower() == cartridgeagentconstants.INTERNAL else False
+                except ParameterNotFoundException:
+                    self.log.info(" INTERNAL payload parameter is not found")
+                    self.is_internal_repo = False
+
+                self.tenant_id = self.read_property(cartridgeagentconstants.TENANT_ID)
+                self.lb_cluster_id = self.read_property(cartridgeagentconstants.LB_CLUSTER_ID, False)
+                self.min_count = self.read_property(cartridgeagentconstants.MIN_INSTANCE_COUNT, False)
+                self.lb_private_ip = self.read_property(cartridgeagentconstants.LB_PRIVATE_IP, False)
+                self.lb_public_ip = self.read_property(cartridgeagentconstants.LB_PUBLIC_IP, False)
+                self.tenant_repository_path = self.read_property(cartridgeagentconstants.TENANT_REPO_PATH, False)
+                self.super_tenant_repository_path = self.read_property(cartridgeagentconstants.SUPER_TENANT_REPO_PATH, False)
+
+                try:
+                    self.deployment = self.read_property(
+                        cartridgeagentconstants.DEPLOYMENT)
+                except ParameterNotFoundException:
+                    self.deployment = None
+
+                # Setting worker-manager setup - manager service name
+                if self.deployment is None:
+                    self.manager_service_name = None
+
+                if str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower():
+                    self.manager_service_name = self.service_name
+
+                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
+                    self.deployment = self.read_property(
+                        cartridgeagentconstants.MANAGER_SERVICE_TYPE)
+
+                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_DEFAULT.lower():
+                    self.deployment = None
+                else:
+                    self.deployment = None
+
+                # Setting worker-manager setup - worker service name
+                if self.deployment is None:
+                    self.worker_service_name = None
+
+                if str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
+                    self.manager_service_name = self.service_name
+
+                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower():
+                    self.deployment = self.read_property(
+                        cartridgeagentconstants.WORKER_SERVICE_TYPE)
+
+                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_DEFAULT.lower():
+                    self.deployment = None
+                else:
+                    self.deployment = None
+
+                try:
+                    self.is_primary = self.read_property(
+                        cartridgeagentconstants.CLUSTERING_PRIMARY_KEY)
+                except ParameterNotFoundException:
+                    self.is_primary = None
+            except ParameterNotFoundException as ex:
+                raise RuntimeError(ex)
+
+            self.log.info("Cartridge agent configuration initialized")
+
+            self.log.debug("service-name: %r" % self.service_name)
+            self.log.debug("cluster-id: %r" % self.cluster_id)
+            self.log.debug(
+                "network-partition-id: %r" % self.network_partition_id)
+            self.log.debug("partition-id: %r" % self.partition_id)
+            self.log.debug("member-id: %r" % self.member_id)
+            self.log.debug("cartridge-key: %r" % self.cartridge_key)
+            self.log.debug("app-path: %r" % self.app_path)
+            self.log.debug("repo-url: %r" % self.repo_url)
+            self.log.debug("ports: %r" % str(self.ports))
+            self.log.debug("lb-private-ip: %r" % self.lb_private_ip)
+            self.log.debug("lb-public-ip: %r" % self.lb_public_ip)
+
+        def get_member_id(self, member_id_field):
+            """
+            Reads the member id from the payload file or configuration file. If neither of
+            these sources contain the member id, the hostname is assigned to it and returned.
+            :param str member_id_field: the key of the member id to lookup
+            :return: The member id
+            :rtype : str
+            """
+            try:
+                member_id = self.read_property(member_id_field)
+            except ParameterNotFoundException:
+                try:
+                    self.log.info("Reading hostname from container")
+                    member_id = socket.gethostname()
+                except:
+                    self.log.exception("Hostname can not be resolved")
+                    member_id = "unknown"
+
+            self.log.debug("MemberId  is taking the value of hostname : [" + member_id + "] ")
+            return member_id
+
+        def __read_conf_file(self):
+            """
+            Reads and stores the agent's configuration file
+            :return: void
+            """
+
+            conf_file_path = os.path.abspath(os.path.dirname(__file__)).split("modules")[0] + "agent.conf"
+            self.log.debug("Config file path : %r" % conf_file_path)
+            self.properties = ConfigParser.SafeConfigParser()
+            self.properties.read(conf_file_path)
+
+        def __read_parameter_file(self):
+            """
+            Reads the payload file of the cartridge and stores the values in a dictionary
+            :return: void
+            """
+
+            param_file = self.read_property(cartridgeagentconstants.PARAM_FILE_PATH, False)
+            self.log.debug("Param file path : %r" % param_file)
+
+            try:
+                if param_file is not None:
+                    metadata_file = open(param_file)
+                    metadata_payload_content = metadata_file.read()
+                    for param in metadata_payload_content.split(","):
+                        if param.strip() != "":
+                            param_value = param.strip().split("=")
+                            self.payload_params[param_value[0]] = param_value[1]
+
+                    # self.payload_params = dict(
+                    #     param.split("=") for param in metadata_payload_content.split(","))
+                    metadata_file.close()
+                else:
+                    self.log.error("File not found: %r" % param_file)
+            except:
+                self.log.exception(
+                    "Could not read launch parameter file, hence trying to read from System properties.")
+
+        def read_property(self, property_key, critical=True):
+            """
+            Returns the value of the provided property
+            :param str property_key: the name of the property to be read
+            :return: Value of the property,
+            :rtype: str
+            :exception: ParameterNotFoundException if the provided property cannot be found
+            """
+
+            if self.properties.has_option("agent", property_key):
+                self.log.debug("Has key: %r" % property_key)
+                temp_str = self.properties.get("agent", property_key)
+                if temp_str != "" and temp_str is not None:
+                    if str(temp_str).strip().lower() == "null":
+                        return ""
+                    else:
+                        return str(temp_str).strip()
+
+            if property_key in self.payload_params:
+                temp_str = self.payload_params[property_key]
+                if temp_str != "" and temp_str is not None:
+                    if str(temp_str).strip().lower() == "null":
+                        return ""
+                    else:
+                        return str(temp_str).strip()
+
+            if critical:
+                raise ParameterNotFoundException("Cannot find the value of required parameter: %r" % property_key)
+
+    instance = None
+    """ :type : __CartridgeAgentConfiguration"""
+
+    # def __new__(cls, *args, **kwargs):
+    #     if not CartridgeAgentConfiguration.instance:
+    #         CartridgeAgentConfiguration.instance = CartridgeAgentConfiguration.__CartridgeAgentConfiguration()
+    #
+    #     return CartridgeAgentConfiguration.instance
+
+    def __init__(self):
+        if not CartridgeAgentConfiguration.instance:
+            CartridgeAgentConfiguration.instance = CartridgeAgentConfiguration.__CartridgeAgentConfiguration()
+
+    def __getattr__(self, name):
+        return getattr(self.instance, name)
+
+    def __setattr__(self, name, value):
+        return setattr(self.instance, name, value)
+
+
+from ..exception.parameternotfoundexception import ParameterNotFoundException
+from ..util import cartridgeagentconstants

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
new file mode 100644
index 0000000..1859d8a
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py
@@ -0,0 +1,202 @@
+# 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.
+
+from thrift.publisher import *
+from ..util.log import *
+
+
+class StreamDefinition:
+    """
+    Represents a BAM/CEP stream definition
+    """
+
+    STRING = 'STRING'
+    DOUBLE = 'DOUBLE'
+    INT = 'INT'
+    LONG = 'LONG'
+    BOOL = 'BOOL'
+
+    def __init__(self):
+        self.name = None
+        """:type : str"""
+        self.version = None
+        """:type : str"""
+        self.nickname = None
+        """:type : str"""
+        self.description = None
+        """:type : str"""
+        self.meta_data = []
+        """:type : list[str]"""
+        self.correlation_data = []
+        """:type : list[str]"""
+        self.payload_data = []
+        """:type : list[str]"""
+        self.stream_id =  None
+        """ :type : str """
+
+    def add_metadata_attribute(self, attr_name, attr_type):
+        self.meta_data.append({"name": attr_name, "type": attr_type})
+
+    def add_payloaddata_attribute(self, attr_name, attr_type):
+        self.payload_data.append({"name": attr_name, "type": attr_type})
+
+    def add_correlationdata_attribute(self, attr_name, attr_type):
+        self.correlation_data.append({"name": attr_name, "type": attr_type})
+
+    def __str__(self):
+        """
+        To string override
+        """
+
+        json_str = "{"
+        json_str += "\"name\":\"" + self.name + "\","
+        json_str += "\"version\":\"" + self.version + "\","
+        json_str += "\"nickName\":\"" + self.nickname + "\","
+        json_str += "\"description\":\"" + self.description + "\","
+
+        # add metadata attributes if exists
+        if len(self.meta_data) > 0:
+            json_str += "\"metaData\":["
+            for metadatum in self.meta_data:
+                json_str += "{\"name\":\"" + metadatum["name"] + "\", \"type\": \"" + metadatum["type"] + "\"},"
+
+            json_str = json_str[:-1] + "],"
+
+        # add correlationdata attributes if exists
+        if len(self.correlation_data) > 0:
+            json_str += "\"correlationData\":["
+            for coredatum in self.correlation_data:
+                json_str += "{\"name\":\"" + coredatum["name"] + "\", \"type\": \"" + coredatum["type"] + "\"},"
+
+            json_str = json_str[:-1] + "],"
+
+        # add payloaddata attributes if exists
+        if len(self.payload_data) > 0:
+            json_str += "\"payloadData\":["
+            for payloaddatum in self.payload_data:
+                json_str += "{\"name\":\"" + payloaddatum["name"] + "\", \"type\": \"" + payloaddatum["type"] + "\"},"
+
+            json_str = json_str[:-1] + "],"
+
+        json_str = json_str[:-1] + "}"
+
+        return json_str
+
+
+class ThriftEvent:
+    """
+    Represents an event to be published to a BAM/CEP monitoring server
+    """
+    def __init__(self):
+        self.metaData = []
+        """:type : list[str]"""
+        self.correlationData = []
+        """:type : list[str]"""
+        self.payloadData = []
+        """:type : list[str]"""
+
+
+class ThriftPublisher:
+    """
+    Handles publishing events to BAM/CEP through thrift using the provided address and credentials
+    """
+    log = LogFactory().get_log(__name__)
+
+    def __init__(self, ip, port, username, password, stream_definition):
+        """
+        Initializes a ThriftPublisher object.
+
+        At initialization a ThriftPublisher connects and defines a stream definition. A connection
+        should be disconnected after all the publishing has been done.
+
+        :param str ip: IP address of the monitoring server
+        :param str port: Port of the monitoring server
+        :param str username: Username
+        :param str password: Password
+        :param StreamDefinition stream_definition: StreamDefinition object for this particular connection
+        :return: ThriftPublisher object
+        :rtype: ThriftPublisher
+        """
+        try:
+            port_number = int(port)
+        except ValueError:
+            raise RuntimeError("Port number for Thrift Publisher is invalid: %r" % port)
+
+        self.__publisher = Publisher(ip, port_number)
+        self.__publisher.connect(username, password)
+        self.__publisher.defineStream(str(stream_definition))
+
+        self.stream_definition = stream_definition
+        self.stream_id = self.__publisher.streamId
+        self.ip = ip
+        self.port = port
+        self.username = username
+        self.password = password
+
+    def publish(self, event):
+        """
+        Publishes the given event by creating the event bundle from the log event
+
+        :param ThriftEvent event: The log event to be published
+        :return: void
+        """
+        event_bundler = EventBundle()
+        ThriftPublisher.assign_attributes(event.metaData, event_bundler)
+        ThriftPublisher.assign_attributes(event.correlationData, event_bundler)
+        ThriftPublisher.assign_attributes(event.payloadData, event_bundler)
+
+        self.__publisher.publish(event_bundler)
+        self.log.debug("Published event to thrift stream [%r]" % self.stream_id)
+
+    def disconnect(self):
+        """
+        Disconnect the thrift publisher
+        :return: void
+        """
+        self.__publisher.disconnect()
+
+    @staticmethod
+    def assign_attributes(attributes, event_bundler):
+        """
+        Adds the given attributes to the given event bundler according to type of each attribute
+        :param list attributes: attributes to be assigned
+        :param EventBundle event_bundler: Event bundle to assign attributes to
+        :return: void
+        """
+
+        # __intAttributeList = []
+        # __longAttributeList = []
+        # __doubleAttributeList = []
+        # __boolAttributeList = []
+        # __stringAttributeList = []
+
+        if attributes is not None and len(attributes) > 0:
+            for attrib in attributes:
+                if isinstance(attrib, int):
+                    event_bundler.addIntAttribute(attrib)
+                elif isinstance(attrib, long):
+                    event_bundler.addLongAttribute(attrib)
+                elif isinstance(attrib, float):
+                    event_bundler.addDoubleAttribute(attrib)
+                elif isinstance(attrib, bool):
+                    event_bundler.addBoolAttribute(attrib)
+                elif isinstance(attrib, str):
+                    event_bundler.addStringAttribute(attrib)
+                else:
+                    ThriftPublisher.log.error("Undefined attribute type: %r" % attrib)
+        else:
+            ThriftPublisher.log.debug("Empty attribute list")

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/__init__.py
@@ -0,0 +1,17 @@
+# 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.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py
new file mode 100644
index 0000000..adefd8e
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/__init__.py
@@ -0,0 +1 @@
+__all__ = ['ttypes', 'constants']

http://git-wip-us.apache.org/repos/asf/stratos/blob/a11df3ed/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py
new file mode 100644
index 0000000..36943ba
--- /dev/null
+++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/gen/Data/constants.py
@@ -0,0 +1,8 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+


[40/50] [abbrv] git commit: Completed decrypt password test

Posted by im...@apache.org.
Completed decrypt password test


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

Branch: refs/heads/master
Commit: 5493e9976709702d49c06648422a48ea276527e5
Parents: a11df3e
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Tue Oct 21 01:13:18 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Tue Oct 21 01:13:18 2014 +0530

----------------------------------------------------------------------
 tools/python_cartridgeagent/test/asynctest.txt | 2 +-
 tools/python_cartridgeagent/test/test_util.py  | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/5493e997/tools/python_cartridgeagent/test/asynctest.txt
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/asynctest.txt b/tools/python_cartridgeagent/test/asynctest.txt
index 08b3931..4032a53 100644
--- a/tools/python_cartridgeagent/test/asynctest.txt
+++ b/tools/python_cartridgeagent/test/asynctest.txt
@@ -1 +1 @@
-1413809843291.4761
\ No newline at end of file
+1413834107419.9700
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/5493e997/tools/python_cartridgeagent/test/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python_cartridgeagent/test/test_util.py b/tools/python_cartridgeagent/test/test_util.py
index fd38c3e..63e93cf 100644
--- a/tools/python_cartridgeagent/test/test_util.py
+++ b/tools/python_cartridgeagent/test/test_util.py
@@ -46,10 +46,10 @@ def test_decrypt_password():
     #     return mocklog
     #
     # monkeypatch.delattr("LogFactory().get_log")
+    # TODO: enable logging in cartridgeagentutils
 
     plain_password = "plaintext"
-    secret_key = "secret"
-    encrypted_password= "v5UltRskmSGbwTIbXym7jQ=="
-    b64encoded_encrypted_password = "djVVbHRSc2ttU0did1RJYlh5bTdqUT09"
+    secret_key = "tvnw63ufg9gh5111"
+    encrypted_password= "jP1lZ5xMlpLzu8MbY2Porg=="
 
-    assert cartridgeagentutils.decrypt_password(b64encoded_encrypted_password, secret_key) == plain_password, "Password decryption failed"
\ No newline at end of file
+    assert cartridgeagentutils.decrypt_password(encrypted_password, secret_key) == plain_password, "Password decryption failed"
\ No newline at end of file


[20/50] [abbrv] git commit: Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
Renamed cartridge-agent module to cartridgeagent to follow python package naming
Added pytest test directory


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

Branch: refs/heads/master
Commit: bcddfbadea907d8d733d1b7c22c9e9d16911a6f5
Parents: 3423127
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Mon Oct 20 13:20:54 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Mon Oct 20 13:20:54 2014 +0530

----------------------------------------------------------------------
 .gitignore                                      |    3 +
 .../cartridge-agent/__init__.py                 |   16 -
 .../cartridge-agent/agent.conf                  |   62 -
 .../cartridge-agent/agent.py                    |  343 ----
 .../cartridge-agent/logging.ini                 |   52 -
 .../cartridge-agent/modules/__init__.py         |   16 -
 .../modules/artifactmgt/__init__.py             |   17 -
 .../modules/artifactmgt/git/__init__.py         |   17 -
 .../modules/artifactmgt/git/agentgithandler.py  |  501 ------
 .../modules/artifactmgt/git/gitrepository.py    |   51 -
 .../artifactmgt/repositoryinformation.py        |   37 -
 .../cartridge-agent/modules/config/__init__.py  |   17 -
 .../config/cartridgeagentconfiguration.py       |  346 ----
 .../modules/databridge/__init__.py              |   17 -
 .../cartridge-agent/modules/databridge/agent.py |  202 ---
 .../modules/databridge/thrift/__init__.py       |   17 -
 .../databridge/thrift/gen/Data/__init__.py      |    1 -
 .../databridge/thrift/gen/Data/constants.py     |    8 -
 .../databridge/thrift/gen/Data/ttypes.py        |  320 ----
 .../databridge/thrift/gen/Exception/__init__.py |    1 -
 .../thrift/gen/Exception/constants.py           |    8 -
 .../databridge/thrift/gen/Exception/ttypes.py   |  473 ------
 .../ThriftEventTransmissionService-remote       |  117 --
 .../ThriftEventTransmissionService.py           | 1143 -------------
 .../ThriftEventTransmissionService/__init__.py  |    1 -
 .../ThriftEventTransmissionService/constants.py |    8 -
 .../ThriftEventTransmissionService/ttypes.py    |   21 -
 .../ThriftSecureEventTransmissionService-remote |  131 --
 .../ThriftSecureEventTransmissionService.py     | 1495 ------------------
 .../__init__.py                                 |    1 -
 .../constants.py                                |    8 -
 .../ttypes.py                                   |   21 -
 .../modules/databridge/thrift/gen/__init__.py   |    0
 .../modules/databridge/thrift/publisher.py      |  111 --
 .../modules/databridge/thrift/thrift/TSCons.py  |   35 -
 .../databridge/thrift/thrift/TSerialization.py  |   38 -
 .../databridge/thrift/thrift/TTornado.py        |  153 --
 .../modules/databridge/thrift/thrift/Thrift.py  |  170 --
 .../databridge/thrift/thrift/__init__.py        |   20 -
 .../databridge/thrift/thrift/protocol/TBase.py  |   81 -
 .../thrift/thrift/protocol/TBinaryProtocol.py   |  261 ---
 .../thrift/thrift/protocol/TCompactProtocol.py  |  405 -----
 .../thrift/thrift/protocol/TJSONProtocol.py     |  552 -------
 .../thrift/thrift/protocol/TProtocol.py         |  406 -----
 .../thrift/thrift/protocol/__init__.py          |   20 -
 .../thrift/thrift/protocol/fastbinary.c         | 1219 --------------
 .../thrift/thrift/server/THttpServer.py         |   87 -
 .../thrift/thrift/server/TNonblockingServer.py  |  346 ----
 .../thrift/thrift/server/TProcessPoolServer.py  |  118 --
 .../databridge/thrift/thrift/server/TServer.py  |  269 ----
 .../databridge/thrift/thrift/server/__init__.py |   20 -
 .../thrift/thrift/transport/THttpClient.py      |  147 --
 .../thrift/thrift/transport/TSSLSocket.py       |  214 ---
 .../thrift/thrift/transport/TSocket.py          |  176 ---
 .../thrift/thrift/transport/TTransport.py       |  330 ----
 .../thrift/thrift/transport/TTwisted.py         |  221 ---
 .../thrift/thrift/transport/TZlibTransport.py   |  249 ---
 .../thrift/thrift/transport/__init__.py         |   20 -
 .../modules/datapublisher/__init__.py           |   18 -
 .../modules/datapublisher/exception/__init__.py |   17 -
 .../exception/datapublisherexception.py         |   33 -
 .../modules/datapublisher/logpublisher.py       |  273 ----
 .../cartridge-agent/modules/event/__init__.py   |    0
 .../modules/event/instance/__init__.py          |   16 -
 .../modules/event/instance/notifier/__init__.py |   17 -
 .../modules/event/instance/notifier/events.py   |   77 -
 .../modules/event/instance/status/__init__.py   |   17 -
 .../modules/event/instance/status/events.py     |   98 --
 .../modules/event/tenant/__init__.py            |   16 -
 .../modules/event/tenant/events.py              |  147 --
 .../modules/event/topology/__init__.py          |   17 -
 .../modules/event/topology/events.py            |  280 ----
 .../modules/exception/__init__.py               |   16 -
 .../exception/parameternotfoundexception.py     |   35 -
 .../modules/extensions/__init__.py              |   16 -
 .../extensions/abstractextensionhandler.py      |   78 -
 .../extensions/defaultextensionhandler.py       |  789 ---------
 .../modules/healthstatspublisher/__init__.py    |   16 -
 .../abstracthealthstatisticspublisher.py        |   62 -
 .../modules/healthstatspublisher/healthstats.py |  246 ---
 .../modules/publisher/__init__.py               |   16 -
 .../publisher/cartridgeagentpublisher.py        |  165 --
 .../modules/subscriber/__init__.py              |   17 -
 .../modules/subscriber/eventsubscriber.py       |   96 --
 .../cartridge-agent/modules/tenant/__init__.py  |   16 -
 .../modules/tenant/tenantcontext.py             |  184 ---
 .../modules/topology/__init__.py                |   16 -
 .../modules/topology/topologycontext.py         |  454 ------
 .../cartridge-agent/modules/util/__init__.py    |   16 -
 .../modules/util/asyncscheduledtask.py          |   50 -
 .../modules/util/cartridgeagentconstants.py     |  135 --
 .../modules/util/cartridgeagentutils.py         |  165 --
 .../modules/util/extensionutils.py              |  494 ------
 .../cartridge-agent/modules/util/log.py         |   55 -
 .../cartridgeagent/__init__.py                  |   16 +
 .../cartridgeagent/agent.conf                   |   62 +
 .../cartridgeagent/agent.py                     |  343 ++++
 .../cartridgeagent/logging.ini                  |   52 +
 .../cartridgeagent/modules/__init__.py          |   16 +
 .../modules/artifactmgt/__init__.py             |   17 +
 .../modules/artifactmgt/git/__init__.py         |   17 +
 .../modules/artifactmgt/git/agentgithandler.py  |  501 ++++++
 .../modules/artifactmgt/git/gitrepository.py    |   51 +
 .../artifactmgt/repositoryinformation.py        |   37 +
 .../cartridgeagent/modules/config/__init__.py   |   17 +
 .../config/cartridgeagentconfiguration.py       |  346 ++++
 .../modules/databridge/__init__.py              |   17 +
 .../cartridgeagent/modules/databridge/agent.py  |  202 +++
 .../modules/databridge/thrift/__init__.py       |   17 +
 .../databridge/thrift/gen/Data/__init__.py      |    1 +
 .../databridge/thrift/gen/Data/constants.py     |    8 +
 .../databridge/thrift/gen/Data/ttypes.py        |  320 ++++
 .../databridge/thrift/gen/Exception/__init__.py |    1 +
 .../thrift/gen/Exception/constants.py           |    8 +
 .../databridge/thrift/gen/Exception/ttypes.py   |  473 ++++++
 .../ThriftEventTransmissionService-remote       |  117 ++
 .../ThriftEventTransmissionService.py           | 1143 +++++++++++++
 .../ThriftEventTransmissionService/__init__.py  |    1 +
 .../ThriftEventTransmissionService/constants.py |    8 +
 .../ThriftEventTransmissionService/ttypes.py    |   21 +
 .../ThriftSecureEventTransmissionService-remote |  131 ++
 .../ThriftSecureEventTransmissionService.py     | 1495 ++++++++++++++++++
 .../__init__.py                                 |    1 +
 .../constants.py                                |    8 +
 .../ttypes.py                                   |   21 +
 .../modules/databridge/thrift/gen/__init__.py   |    0
 .../modules/databridge/thrift/publisher.py      |  111 ++
 .../modules/databridge/thrift/thrift/TSCons.py  |   35 +
 .../databridge/thrift/thrift/TSerialization.py  |   38 +
 .../databridge/thrift/thrift/TTornado.py        |  153 ++
 .../modules/databridge/thrift/thrift/Thrift.py  |  170 ++
 .../databridge/thrift/thrift/__init__.py        |   20 +
 .../databridge/thrift/thrift/protocol/TBase.py  |   81 +
 .../thrift/thrift/protocol/TBinaryProtocol.py   |  261 +++
 .../thrift/thrift/protocol/TCompactProtocol.py  |  405 +++++
 .../thrift/thrift/protocol/TJSONProtocol.py     |  552 +++++++
 .../thrift/thrift/protocol/TProtocol.py         |  406 +++++
 .../thrift/thrift/protocol/__init__.py          |   20 +
 .../thrift/thrift/protocol/fastbinary.c         | 1219 ++++++++++++++
 .../thrift/thrift/server/THttpServer.py         |   87 +
 .../thrift/thrift/server/TNonblockingServer.py  |  346 ++++
 .../thrift/thrift/server/TProcessPoolServer.py  |  118 ++
 .../databridge/thrift/thrift/server/TServer.py  |  269 ++++
 .../databridge/thrift/thrift/server/__init__.py |   20 +
 .../thrift/thrift/transport/THttpClient.py      |  147 ++
 .../thrift/thrift/transport/TSSLSocket.py       |  214 +++
 .../thrift/thrift/transport/TSocket.py          |  176 +++
 .../thrift/thrift/transport/TTransport.py       |  330 ++++
 .../thrift/thrift/transport/TTwisted.py         |  221 +++
 .../thrift/thrift/transport/TZlibTransport.py   |  249 +++
 .../thrift/thrift/transport/__init__.py         |   20 +
 .../modules/datapublisher/__init__.py           |   18 +
 .../modules/datapublisher/exception/__init__.py |   17 +
 .../exception/datapublisherexception.py         |   33 +
 .../modules/datapublisher/logpublisher.py       |  273 ++++
 .../cartridgeagent/modules/event/__init__.py    |    0
 .../modules/event/instance/__init__.py          |   16 +
 .../modules/event/instance/notifier/__init__.py |   17 +
 .../modules/event/instance/notifier/events.py   |   77 +
 .../modules/event/instance/status/__init__.py   |   17 +
 .../modules/event/instance/status/events.py     |   98 ++
 .../modules/event/tenant/__init__.py            |   16 +
 .../modules/event/tenant/events.py              |  147 ++
 .../modules/event/topology/__init__.py          |   17 +
 .../modules/event/topology/events.py            |  280 ++++
 .../modules/exception/__init__.py               |   16 +
 .../exception/parameternotfoundexception.py     |   35 +
 .../modules/extensions/__init__.py              |   16 +
 .../extensions/abstractextensionhandler.py      |   78 +
 .../extensions/defaultextensionhandler.py       |  789 +++++++++
 .../modules/healthstatspublisher/__init__.py    |   16 +
 .../abstracthealthstatisticspublisher.py        |   62 +
 .../modules/healthstatspublisher/healthstats.py |  246 +++
 .../modules/publisher/__init__.py               |   16 +
 .../publisher/cartridgeagentpublisher.py        |  165 ++
 .../modules/subscriber/__init__.py              |   17 +
 .../modules/subscriber/eventsubscriber.py       |   96 ++
 .../cartridgeagent/modules/tenant/__init__.py   |   16 +
 .../modules/tenant/tenantcontext.py             |  184 +++
 .../cartridgeagent/modules/topology/__init__.py |   16 +
 .../modules/topology/topologycontext.py         |  454 ++++++
 .../cartridgeagent/modules/util/__init__.py     |   16 +
 .../modules/util/asyncscheduledtask.py          |   50 +
 .../modules/util/cartridgeagentconstants.py     |  135 ++
 .../modules/util/cartridgeagentutils.py         |  165 ++
 .../modules/util/extensionutils.py              |  494 ++++++
 .../cartridgeagent/modules/util/log.py          |   55 +
 tools/python-cartridge-agent/test/__init__.py   |    0
 tools/python-cartridge-agent/test/test_util.py  |    4 +
 189 files changed, 15306 insertions(+), 15299 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index b310d6d..5fe1c80 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,6 @@ target/
 
 #Backup files
 *~
+
+#Python binary files
+*.pyc
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/__init__.py b/tools/python-cartridge-agent/cartridge-agent/__init__.py
deleted file mode 100644
index d216be4..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/__init__.py
+++ /dev/null
@@ -1,16 +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.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/agent.conf
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/agent.conf b/tools/python-cartridge-agent/cartridge-agent/agent.conf
deleted file mode 100644
index 5c087e9..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/agent.conf
+++ /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.
-
-[agent]
-mb.ip                                 =MB-IP
-mb.port                               =MB-PORT
-listen.address                        =LISTEN_ADDR
-thrift.receiver.ip                    =CEP-IP
-thrift.receiver.port                  =CEP-PORT
-thrift.server.admin.username          =CEP-ADMIN-USERNAME
-thrift.server.admin.password          =CEP-ADMIN-PASSWORD
-param.file.path                       =/mnt/cartridge-agent/payload/launch-params
-extensions.dir                        =/mnt/cartridge-agent/extensions
-cep.stats.publisher.enabled           =ENABLE_HEALTH_PUBLISHER
-lb.private.ip                         =LB_PRIVATE_IP
-lb.public.ip                          =LB_PUBLIC_IP
-enable.artifact.update                =ENABLE_ARTFCT_UPDATE
-auto.commit                           =COMMIT_ENABLED
-auto.checkout                         =CHECKOUT_ENABLED
-artifact.update.interval              =ARTFCT_UPDATE_INT
-port.check.timeout                    =PORT_CHECK_TIMEOUT
-enable.data.publisher                 =ENABLE-DATA-PUBLISHER
-monitoring.server.ip                  =MONITORING-SERVER-IP
-monitoring.server.port                =MONITORING-SERVER-PORT
-monitoring.server.secure.port         =MONITORING-SERVER-SECURE-PORT
-monitoring.server.admin.username      =MONITORING-SERVER-ADMIN-USERNAME
-monitoring.server.admin.password      =MONITORING-SERVER-ADMIN-PASSWORD
-log.file.paths                        =LOG_FILE_PATHS
-APP_PATH                              =APP-PATH
-super.tenant.repository.path          =/repository/deployment/server/
-tenant.repository.path                =/repository/tenants/
-extension.instance.started            =instance-started.sh
-extension.start.servers               =start-servers.sh
-extension.instance.activated          =instance-activated.sh
-extension.artifacts.updated           =artifacts-updated.sh
-extension.clean                       =clean.sh
-extension.mount.volumes               =mount_volumes.sh
-extension.member.started              =member-started.sh
-extension.member.activated            =member-activated.sh
-extension.member.suspended            =member-suspended.sh
-extension.member.terminated           =member-terminated.sh
-extension.complete.topology           =complete-topology.sh
-extension.complete.tenant             =complete-tenant.sh
-extension.subscription.domain.added   =subscription-domain-added.sh
-extension.subscription.domain.removed =subscription-domain-removed.sh
-extension.artifacts.copy              =artifacts-copy.sh
-extension.tenant.subscribed           =tenant-subscribed.sh
-extension.tenant.unsubscribed         =tenant-unsubscribed.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/agent.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/agent.py b/tools/python-cartridge-agent/cartridge-agent/agent.py
deleted file mode 100644
index 9f1a972..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/agent.py
+++ /dev/null
@@ -1,343 +0,0 @@
-#!/usr/bin/env python
-# 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.
-
-import threading
-
-from modules.exception.parameternotfoundexception import ParameterNotFoundException
-from modules.subscriber import eventsubscriber
-from modules.publisher import cartridgeagentpublisher
-from modules.event.instance.notifier.events import *
-from modules.event.tenant.events import *
-from modules.event.topology.events import *
-from modules.tenant.tenantcontext import *
-from modules.topology.topologycontext import *
-from modules.datapublisher.logpublisher import *
-from modules.config import cartridgeagentconfiguration
-from modules.extensions import defaultextensionhandler
-
-
-class CartridgeAgent(threading.Thread):
-    extension_handler = defaultextensionhandler.DefaultExtensionHandler()
-
-    def __init__(self):
-        threading.Thread.__init__(self)
-
-        mb_ip = cartridgeagentconfiguration.CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_IP)
-        mb_port = cartridgeagentconfiguration.CartridgeAgentConfiguration().read_property(cartridgeagentconstants.MB_PORT)
-
-        self.__instance_event_subscriber = eventsubscriber.EventSubscriber(
-            cartridgeagentconstants.INSTANCE_NOTIFIER_TOPIC,
-            mb_ip,
-            mb_port)
-        self.__tenant_event_subscriber = eventsubscriber.EventSubscriber(
-            cartridgeagentconstants.TENANT_TOPIC,
-            mb_ip,
-            mb_port)
-        self.__topology_event_subscriber = eventsubscriber.EventSubscriber(
-            cartridgeagentconstants.TOPOLOGY_TOPIC,
-            mb_ip,
-            mb_port)
-
-        self.__tenant_context_initialized = False
-
-        self.log_publish_manager = None
-
-        self.terminated = False
-
-        self.log = LogFactory().get_log(__name__)
-
-        self.cartridge_agent_config = CartridgeAgentConfiguration()
-
-    def run(self):
-        self.log.info("Starting Cartridge Agent...")
-
-        #Check if required prpoerties are set
-        self.validate_required_properties()
-
-        #Start instance notifier listener thread
-        self.subscribe_to_topics_and_register_listeners()
-
-        #Start topology event receiver thread
-        self.register_topology_event_listeners()
-
-        #Start tenant event receiver thread
-        self.register_tenant_event_listeners()
-
-        #wait for intance spawned event
-        while not self.cartridge_agent_config.initialized:
-            self.log.debug("Waiting for Cartridge Agent to be initialized...")
-            time.sleep(1)
-
-        #Execute instance started shell script
-        CartridgeAgent.extension_handler.on_instance_started_event()
-
-        #Publish instance started event
-        cartridgeagentpublisher.publish_instance_started_event()
-
-        #Execute start servers extension
-        try:
-            CartridgeAgent.extension_handler.start_server_extension()
-        except:
-            self.log.exception("Error processing start servers event")
-
-        #Wait for all ports to be active
-        cartridgeagentutils.wait_until_ports_active(
-            self.cartridge_agent_config.listen_address,
-            self.cartridge_agent_config.ports,
-            int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False))
-        )
-
-        # check if artifact management is required before publishing instance activated event
-        repo_url = self.cartridge_agent_config.repo_url
-        if repo_url is None or str(repo_url).strip() == "":
-            self.log.info("No artifact repository found")
-            CartridgeAgent.extension_handler.on_instance_activated_event()
-
-            cartridgeagentpublisher.publish_instance_activated_event()
-
-        persistence_mappping_payload = self.cartridge_agent_config.persistence_mappings
-        if persistence_mappping_payload is not None:
-            CartridgeAgent.extension_handler.volume_mount_extension(persistence_mappping_payload)
-
-        # start log publishing thread
-        if DataPublisherConfiguration.get_instance().enabled:
-            log_file_paths = self.cartridge_agent_config.log_file_paths
-            if log_file_paths is None:
-                self.log.exception("No valid log file paths found, no logs will be published")
-            else:
-                self.log_publish_manager = LogPublisherManager(log_file_paths)
-                self.log_publish_manager.start()
-
-        while not self.terminated:
-            time.sleep(1)
-
-        if DataPublisherConfiguration.get_instance().enabled:
-            self.log_publish_manager.terminate_all_publishers()
-
-    def terminate(self):
-        """
-        Allows the CartridgeAgent thread to be terminated
-
-        :return: void
-        """
-        self.terminated = True
-
-    def validate_required_properties(self):
-        """
-        Checks if required properties are set
-        :return: void
-        """
-        #PARAM_FILE_PATH
-        try:
-            self.cartridge_agent_config.read_property(cartridgeagentconstants.PARAM_FILE_PATH)
-        except ParameterNotFoundException:
-            self.log.error("System property not found: %r" % cartridgeagentconstants.PARAM_FILE_PATH)
-            return
-
-        #EXTENSIONS_DIR
-        try:
-            self.cartridge_agent_config.read_property(cartridgeagentconstants.EXTENSIONS_DIR)
-        except ParameterNotFoundException:
-            self.log.error("System property not found: %r" % cartridgeagentconstants.EXTENSIONS_DIR)
-            return
-        
-    def subscribe_to_topics_and_register_listeners(self):
-        self.log.debug("Starting instance notifier event message receiver thread")
-
-        self.__instance_event_subscriber.register_handler("ArtifactUpdatedEvent", self.on_artifact_updated)
-        self.__instance_event_subscriber.register_handler("InstanceCleanupMemberEvent", self.on_instance_cleanup_member)
-        self.__instance_event_subscriber.register_handler("InstanceCleanupClusterEvent", self.on_instance_cleanup_cluster)
-
-        self.__instance_event_subscriber.start()
-        self.log.info("Instance notifier event message receiver thread started")
-
-        # wait till subscribed to continue
-        while not self.__instance_event_subscriber.is_subscribed():
-            time.sleep(2)
-
-    def on_artifact_updated(self, msg):
-        event_obj = ArtifactUpdatedEvent.create_from_json(msg.payload)
-        CartridgeAgent.extension_handler.on_artifact_updated_event(event_obj)
-
-    def on_instance_cleanup_member(self, msg):
-        member_in_payload = self.cartridge_agent_config.member_id
-        event_obj = InstanceCleanupMemberEvent.create_from_json(msg.payload)
-        member_in_event = event_obj.member_id
-        if member_in_payload == member_in_event:
-            CartridgeAgent.extension_handler.on_instance_cleanup_member_event(event_obj)
-
-    def on_instance_cleanup_cluster(self, msg):
-        event_obj = InstanceCleanupClusterEvent.create_from_json(msg.payload)
-        cluster_in_payload = self.cartridge_agent_config.cluster_id
-        cluster_in_event = event_obj.cluster_id
-
-        if cluster_in_event == cluster_in_payload:
-            CartridgeAgent.extension_handler.on_instance_cleanup_cluster_event(event_obj)
-
-    def register_topology_event_listeners(self):
-        self.log.debug("Starting topology event message receiver thread")
-
-        self.__topology_event_subscriber.register_handler("MemberActivatedEvent", self.on_member_activated)
-        self.__topology_event_subscriber.register_handler("MemberTerminatedEvent", self.on_member_terminated)
-        self.__topology_event_subscriber.register_handler("MemberSuspendedEvent", self.on_member_suspended)
-        self.__topology_event_subscriber.register_handler("CompleteTopologyEvent", self.on_complete_topology)
-        self.__topology_event_subscriber.register_handler("MemberStartedEvent", self.on_member_started)
-        self.__topology_event_subscriber.register_handler("InstanceSpawnedEvent", self.on_instance_spawned)
-
-        self.__topology_event_subscriber.start()
-        self.log.info("Cartridge Agent topology receiver thread started")
-
-    def on_instance_spawned(self, msg):
-        self.log.debug("Instance spawned event received: %r" % msg.payload)
-        if self.cartridge_agent_config.initialized:
-            return
-
-        event_obj = InstanceSpawnedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_instance_spawned_event(event_obj)
-        except:
-            self.log.exception("Error processing instance spawned event")
-
-    def on_member_activated(self, msg):
-        self.log.debug("Member activated event received: %r" % msg.payload)
-        if not self.cartridge_agent_config.initialized:
-            return
-
-        event_obj = MemberActivatedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_member_activated_event(event_obj)
-        except:
-            self.log.exception("Error processing member activated event")
-
-    def on_member_terminated(self, msg):
-        self.log.debug("Member terminated event received: %r" % msg.payload)
-        if not self.cartridge_agent_config.initialized:
-            return
-
-        event_obj = MemberTerminatedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_member_terminated_event(event_obj)
-        except:
-            self.log.exception("Error processing member terminated event")
-
-    def on_member_suspended(self, msg):
-        self.log.debug("Member suspended event received: %r" % msg.payload)
-        if not self.cartridge_agent_config.initialized:
-            return
-
-        event_obj = MemberSuspendedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_member_suspended_event(event_obj)
-        except:
-            self.log.exception("Error processing member suspended event")
-
-    def on_complete_topology(self, msg):
-        if not self.cartridge_agent_config.initialized:
-            self.log.debug("Complete topology event received")
-            event_obj = CompleteTopologyEvent.create_from_json(msg.payload)
-            TopologyContext.update(event_obj.topology)
-            try:
-                CartridgeAgent.extension_handler.on_complete_topology_event(event_obj)
-            except:
-                self.log.exception("Error processing complete topology event")
-        else:
-            self.log.info("Complete topology event updating task disabled")
-
-    def on_member_started(self, msg):
-        self.log.debug("Member started event received: %r" % msg.payload)
-        if not self.cartridge_agent_config.initialized:
-            return
-
-        event_obj = MemberStartedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_member_started_event(event_obj)
-        except:
-            self.log.exception("Error processing member started event")
-
-    def register_tenant_event_listeners(self):
-        self.log.debug("Starting tenant event message receiver thread")
-        self.__tenant_event_subscriber.register_handler("SubscriptionDomainAddedEvent", self.on_subscription_domain_added)
-        self.__tenant_event_subscriber.register_handler("SubscriptionDomainsRemovedEvent", self.on_subscription_domain_removed)
-        self.__tenant_event_subscriber.register_handler("CompleteTenantEvent", self.on_complete_tenant)
-        self.__tenant_event_subscriber.register_handler("TenantSubscribedEvent", self.on_tenant_subscribed)
-        self.__tenant_event_subscriber.register_handler("TenantUnSubscribedEvent", self.on_tenant_unsubscribed)
-
-        self.__tenant_event_subscriber.start()
-        self.log.info("Tenant event message receiver thread started")
-
-    def on_subscription_domain_added(self, msg):
-        self.log.debug("Subscription domain added event received : %r" % msg.payload)
-        event_obj = SubscriptionDomainAddedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_subscription_domain_added_event(event_obj)
-        except:
-            self.log.exception("Error processing subscription domains added event")
-
-    def on_subscription_domain_removed(self, msg):
-        self.log.debug("Subscription domain removed event received : %r" % msg.payload)
-        event_obj = SubscriptionDomainRemovedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_subscription_domain_removed_event(event_obj)
-        except:
-            self.log.exception("Error processing subscription domains removed event")
-
-    def on_complete_tenant(self, msg):
-        if not self.__tenant_context_initialized:
-            self.log.debug("Complete tenant event received")
-            event_obj = CompleteTenantEvent.create_from_json(msg.payload)
-            TenantContext.update(event_obj.tenants)
-
-            try:
-                CartridgeAgent.extension_handler.on_complete_tenant_event(event_obj)
-                self.__tenant_context_initialized = True
-            except:
-                self.log.exception("Error processing complete tenant event")
-        else:
-            self.log.info("Complete tenant event updating task disabled")
-
-    def on_tenant_subscribed(self, msg):
-        self.log.debug("Tenant subscribed event received: %r" % msg.payload)
-        event_obj = TenantSubscribedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_tenant_subscribed_event(event_obj)
-        except:
-            self.log.exception("Error processing tenant subscribed event")
-
-    def on_tenant_unsubscribed(self, msg):
-        self.log.debug("Tenant unSubscribed event received: %r" % msg.payload)
-        event_obj = TenantUnsubscribedEvent.create_from_json(msg.payload)
-        try:
-            CartridgeAgent.extension_handler.on_tenant_unsubscribed_event(event_obj)
-        except:
-            self.log.exception("Error processing tenant unSubscribed event")
-
-
-def main():
-    cartridge_agent = CartridgeAgent()
-    log = LogFactory().get_log(__name__)
-
-    try:
-        log.debug("Starting cartridge agent")
-        cartridge_agent.start()
-    except:
-        log.exception("Cartridge Agent Exception")
-        cartridge_agent.terminate()
-
-
-if __name__ == "__main__":
-    main()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/logging.ini
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/logging.ini b/tools/python-cartridge-agent/cartridge-agent/logging.ini
deleted file mode 100644
index 3e49a96..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/logging.ini
+++ /dev/null
@@ -1,52 +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.
-
-
-[formatters]
-keys=default
-
-[formatter_default]
-format=%(asctime)s:%(levelname)s:%(message)s
-class=logging.Formatter
-
-[handlers]
-keys=console, error_file, log_file
-
-[handler_console]
-class=logging.StreamHandler
-formatter=default
-args=tuple()
-
-[handler_log_file]
-class=logging.FileHandler
-level=LOG_LEVEL
-formatter=default
-args=("agent.log", "w")
-
-[handler_error_file]
-class=logging.FileHandler
-level=ERROR
-formatter=default
-args=("error.log", "w")
-
-[loggers]
-keys=root
-
-[logger_root]
-level=LOG_LEVEL
-formatter=default
-handlers=console,error_file,log_file
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/__init__.py
deleted file mode 100644
index d216be4..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/__init__.py
+++ /dev/null
@@ -1,16 +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.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/agentgithandler.py b/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/agentgithandler.py
deleted file mode 100644
index 9e95be0..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/agentgithandler.py
+++ /dev/null
@@ -1,501 +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.
-
-from threading import current_thread, Thread
-from git import *
-from gittle import Gittle, GittleAuth  # GitPython and Gittle are both used at the time being for pros and cons of both
-import urllib2
-
-from ... util.log import LogFactory
-from ... util import cartridgeagentutils, extensionutils, cartridgeagentconstants
-from gitrepository import GitRepository
-from ... config import cartridgeagentconfiguration
-from ... util.asyncscheduledtask import AsyncScheduledTask
-from ... artifactmgt.repositoryinformation import RepositoryInformation
-
-class AgentGitHandler:
-    """
-    Handles all the git artifact management tasks related to a cartridge
-    """
-
-    log = LogFactory().get_log(__name__)
-
-    SUPER_TENANT_ID = -1234
-    SUPER_TENANT_REPO_PATH = "/repository/deployment/server/"
-    TENANT_REPO_PATH = "/repository/tenants/"
-
-    extension_handler = None
-
-    __git_repositories = {}
-    # (tenant_id => gitrepository.GitRepository)
-
-    cartridge_agent_config = cartridgeagentconfiguration.CartridgeAgentConfiguration()
-
-    @staticmethod
-    def checkout(repo_info):
-        """
-        Checks out the code from the remote repository.
-        If local repository path is empty, a clone operation is done.
-        If there is a cloned repository already on the local repository path, a pull operation
-        will be performed.
-        If there are artifacts not in the repository already on the local repository path,
-        they will be added to a git repository, the remote url added as origin, and then
-        a pull operation will be performed.
-
-        :param RepositoryInformation repo_info: The repository information object
-        :return: A tuple containing whether it was an initial clone or not, and the repository
-        context object
-        :rtype: tuple(bool, GitRepository)
-        """
-        repo_context = AgentGitHandler.get_repo_context(repo_info.tenant_id)
-        if repo_context is not None:
-            #has been previously cloned, this is not the subscription run
-            subscribe_run = False
-            if AgentGitHandler.is_valid_git_repository(repo_context):
-                AgentGitHandler.log.debug("Existing git repository detected for tenant %r, no clone required" % repo_info.tenant_id)
-                AgentGitHandler.pull(repo_context)
-            else:
-                if not os.listdir(repo_context.local_repo_path):
-                    #empty dir, clone
-                    repo_context.repo = AgentGitHandler.clone(repo_info)
-                else:
-                    #not empty
-                    if AgentGitHandler.sync_initial_local_artifacts(repo_context):
-                        AgentGitHandler.pull(repo_context)
-                    else:
-                        repo_context = None
-        else:
-            #subscribing run.. need to clone
-            subscribe_run = True
-            repo_context = AgentGitHandler.clone(repo_context)
-
-        return subscribe_run, repo_context
-
-    @staticmethod
-    def sync_initial_local_artifacts(repo_context):
-        #init git repo
-        AgentGitHandler.init(repo_context.local_repo_path)
-
-        # add remote repos
-        return AgentGitHandler.add_remote(repo_context)
-
-    @staticmethod
-    def add_remote(repo_context):
-        try:
-            #add origin remote
-            repo_context.repo.create_remote("origin", repo_context.repo_url)
-            #fetch branch details from origin
-            repo_context.repo.git.fetch()
-            #checkout master branch from origin/master as tracking
-            repo_context.repo.git.branch("-f", "--track", "master", "origin/master")
-            return True
-        except:
-            AgentGitHandler.log.exception("Error in adding remote origin %r for local repository %r"
-                                          % (repo_context.repo_url, repo_context.local_repo_path))
-            return False
-
-    @staticmethod
-    def init(path):
-        try:
-            repo = Gittle.init(path)
-            return repo
-        except:
-            AgentGitHandler.log.exception("Initializing local repo at %r failed" % path)
-            raise Exception("Initializing local repo at %r failed" % path)
-
-    @staticmethod
-    def is_valid_git_repository(repo_context):
-        if repo_context.cloned:
-            return True
-
-        for ref in repo_context.repo.refs:
-            try:
-                ref._get_object()
-            except ValueError:
-                return False
-
-        return True
-
-    @staticmethod
-    def pull(repo_context):
-        repo = Repo(repo_context.local_repo_path)
-        from ....agent import CartridgeAgent
-        AgentGitHandler.extension_handler = CartridgeAgent.extension_handler
-        try:
-            repo.git.checkout("master")
-            pull_output = repo.git.pull()
-            if "Already up-to-date." not in pull_output:
-                AgentGitHandler.log.debug("Artifacts were updated as a result of the pull operation, thread: %r - %r" % (current_thread().getName(), current_thread().ident))
-
-            AgentGitHandler.extension_handler.on_artifact_update_scheduler_event(repo_context.tenant_id)
-        except GitCommandError as ex:
-            if "fatal: Could not read from remote repository." in ex:
-                #invalid configuration, need to delete and reclone
-                AgentGitHandler.log.warn("Git pull unsuccessful for tenant %r, invalid configuration. %r" % (repo_context.tenant_id, ex))
-                cartridgeagentutils.delete_folder_tree(repo_context.local_repo_path)
-                AgentGitHandler.clone(RepositoryInformation(
-                    repo_context.repo_url,
-                    repo_context.repo_username,
-                    repo_context.repo_password,
-                    repo_context.local_repo_path,
-                    repo_context.tenant_id,
-                    repo_context.is_multitenant,
-                    repo_context.commit_enabled
-                ))
-                AgentGitHandler.extension_handler.on_artifact_update_scheduler_event(repo_context.tenant_id)
-            elif "error: Your local changes to the following files would be overwritten by merge:" in ex:
-                #conflict error
-                AgentGitHandler.log.warn("Git pull unsuccessful for tenant %r, conflicts detected." % repo_context.tenant_id)
-                #raise ex
-
-                """
-                0:'git pull' returned exit status 1: error: Your local changes to the following files would be overwritten by merge:
-                1:    README.md
-                2:    index.php
-                3:Please, commit your changes or stash them before you can merge.
-                4:Aborting
-                """
-                conflict_list = []
-                files_arr = str(ex).split("\n")
-                for file_index in range(1, len(files_arr) - 2):
-                    file_name = files_arr[file_index].strip()
-                    conflict_list.append(file_name)
-                    AgentGitHandler.log.debug("Added the file path %r to checkout from the remote repository" % file_name)
-
-                AgentGitHandler.checkout_individually(conflict_list, repo)
-            elif "fatal: unable to access " in ex:
-                #transport error
-                AgentGitHandler.log.exception("Accessing remote git repository %r failed for tenant %r" % (repo_context.repo_url, repo_context.tenant_id))
-            else:
-                AgentGitHandler.log.exception("Git pull operation for tenant %r failed" % repo_context.tenant_id)
-
-    @staticmethod
-    def checkout_individually(conflict_list, repo):
-        try:
-            for conflicted_file in conflict_list:
-                repo.git.checkout(conflicted_file)
-                AgentGitHandler.log.info("Checked out the conflicting files from the remote repository successfully")
-        except:
-            AgentGitHandler.log.exception("Checking out artifacts from index failed")
-
-    @staticmethod
-    def clone(repo_info):
-        repo_context = None
-        try:
-            repo_context = AgentGitHandler.create_git_repo_context(repo_info)
-            #create the directory if it doesn't exist
-            if not os.path.isdir(repo_context.local_repo_path):
-                cartridgeagentutils.create_dir(repo_context.local_repo_path)
-
-            auth = AgentGitHandler.create_auth_configuration(repo_context)
-
-            if auth is not None:
-                # authentication is required, use Gittle
-                gittle_repo = Gittle.clone(repo_context.repo_url, repo_context.local_repo_path, auth=auth)
-                repo = Repo(repo_context.local_repo_path)
-            else:
-                # authentication is not required, use GitPython
-                repo = Repo.clone_from(repo_context.repo_url, repo_context.local_repo_path)
-                gittle_repo = Gittle(repo_context.local_repo_path)
-
-            repo_context.cloned = True
-            repo_context.gittle_repo = gittle_repo
-            repo_context.repo  = repo
-            AgentGitHandler.add_repo_context(repo_context)
-            AgentGitHandler.log.info("Git clone operation for tenant %r successful" % repo_context.tenant_id)
-        except urllib2.URLError:
-            AgentGitHandler.log.exception("Accessing remote git repository failed for tenant %r" % repo_context.tenant_id)
-        except OSError:
-            AgentGitHandler.log.exception("Permission denied for repository path for tenant %r" % repo_context.tenant_id)
-        except:
-            AgentGitHandler.log.exception("Git clone operation for tenant %r failed" % repo_context.tenant_id)
-        finally:
-            return repo_context
-
-    @staticmethod
-    def create_auth_configuration(repo_context):
-        """
-        Creates a GittleAuth object based on the type of authorization
-        :param GitRepository repo_context: The repository context object
-        :return: GittleAuth object or None if no authorization needed
-        :rtype: GittleAuth
-        """
-        if repo_context.key_based_auth:
-            pkey = AgentGitHandler.get_private_key()
-            auth = GittleAuth(pkey=pkey)
-        elif repo_context.repo_username.strip() != "" and repo_context.repo_password.strip() != "":
-            auth = GittleAuth(username=repo_context.repo_username, password=repo_context.repo_password)
-        else:
-            auth = None
-
-        return auth
-
-    @staticmethod
-    def get_private_key():
-        """
-        Returns a file handler to the private key path specified by Carbon or default if not specified
-        by Carbon
-        :return: The file object of the private key file
-        :rtype: file
-        """
-        pkey_name = cartridgeagentutils.get_carbon_server_property("SshPrivateKeyName")
-        if pkey_name is  None:
-            pkey_name = "wso2"
-
-        pkey_path = cartridgeagentutils.get_carbon_server_property("SshPrivateKeyPath")
-        if pkey_path is None:
-            pkey_path = os.environ["HOME"] + "/.ssh"
-
-        if pkey_path.endswith("/"):
-            pkey_ptr = pkey_path + pkey_name
-        else:
-            pkey_ptr = pkey_path + "/" + pkey_name
-
-        pkey_file = open(pkey_ptr)
-
-        return pkey_file
-
-
-    @staticmethod
-    def add_repo_context(repo_context):
-        AgentGitHandler.__git_repositories[repo_context.tenant_id] = repo_context
-
-    @staticmethod
-    def get_repo_context(tenant_id):
-        """
-
-        :param int tenant_id:
-        :return: GitRepository object
-        :rtype: GitRepository
-        """
-        if tenant_id in AgentGitHandler.__git_repositories:
-            return AgentGitHandler.__git_repositories[tenant_id]
-
-        return None
-
-    @staticmethod
-    def remove_repo_context(tenant_id):
-        if tenant_id in AgentGitHandler.__git_repositories:
-            del AgentGitHandler.__git_repositories[tenant_id]
-
-    @staticmethod
-    def create_git_repo_context(repo_info):
-        repo_context = GitRepository()
-        repo_context.tenant_id = repo_info.tenant_id
-        repo_context.local_repo_path = AgentGitHandler.get_repo_path_for_tenant(
-            repo_info.tenant_id, repo_info.repo_path, repo_info.is_multitenant)
-        repo_context.repo_url = repo_info.repo_url
-        repo_context.repo_username = repo_info.repo_username
-        repo_context.repo_password = repo_info.repo_password
-        repo_context.is_multitenant = repo_info.is_multitenant
-        repo_context.commit_enabled = repo_info.commit_enabled
-
-        if AgentGitHandler.is_key_based_auth(repo_info.repo_url, repo_info.tenant_id):
-            repo_context.key_based_auth = True
-        else:
-            repo_context.key_based_auth = False
-
-        repo_context.cloned = False
-
-        repo_context.repo = None
-        repo_context.gittle_repo = None
-
-        return repo_context
-
-    @staticmethod
-    def is_key_based_auth(repo_url, tenant_id):
-        """
-        Checks if the given git repo has key based authentication
-        :param str repo_url: Git repository remote url
-        :param str tenant_id: Tenant ID
-        :return: True if key based, False otherwise
-        :rtype: bool
-        """
-        if repo_url.startswith("http://") or repo_url.startswith("https://"):
-            # username and password, not key based
-            return False
-        elif repo_url.startswith("git://github.com"):
-            # no auth required
-            return False
-        elif repo_url.startswith("ssh://") or "@" in repo_url:
-            # key based
-            return True
-        else:
-            AgentGitHandler.log.error("Invalid git URL provided for tenant " + tenant_id)
-            raise RuntimeError("Invalid git URL provided for tenant " + tenant_id)
-
-    @staticmethod
-    def get_repo_path_for_tenant(tenant_id, git_local_repo_path, is_multitenant):
-        repo_path = ""
-
-        if is_multitenant:
-            if tenant_id == AgentGitHandler.SUPER_TENANT_ID:
-                #super tenant, /repository/deploy/server/
-                super_tenant_repo_path = AgentGitHandler.cartridge_agent_config.super_tenant_repository_path
-                #"app_path"
-                repo_path += git_local_repo_path
-
-                if super_tenant_repo_path is not None  and super_tenant_repo_path != "":
-                    super_tenant_repo_path = super_tenant_repo_path if super_tenant_repo_path.startswith("/") else "/" + super_tenant_repo_path
-                    super_tenant_repo_path = super_tenant_repo_path if super_tenant_repo_path.endswith("/") else  super_tenant_repo_path + "/"
-                    #"app_path/repository/deploy/server/"
-                    repo_path += super_tenant_repo_path
-                else:
-                    #"app_path/repository/deploy/server/"
-                    repo_path += AgentGitHandler.SUPER_TENANT_REPO_PATH
-
-            else:
-                #normal tenant, /repository/tenants/tenant_id
-                tenant_repo_path = AgentGitHandler.cartridge_agent_config.tenant_repository_path
-                #"app_path"
-                repo_path += git_local_repo_path
-
-                if tenant_repo_path is not None and tenant_repo_path != "":
-                    tenant_repo_path = tenant_repo_path if tenant_repo_path.startswith("/") else "/" + tenant_repo_path
-                    tenant_repo_path = tenant_repo_path if tenant_repo_path.endswith("/") else tenant_repo_path + "/"
-                    #"app_path/repository/tenants/244653444"
-                    repo_path += tenant_repo_path + tenant_id
-                else:
-                    #"app_path/repository/tenants/244653444"
-                    repo_path += AgentGitHandler.TENANT_REPO_PATH + tenant_id
-
-                #tenant_dir_path = git_local_repo_path + AgentGitHandler.TENANT_REPO_PATH + tenant_id
-                cartridgeagentutils.create_dir(repo_path)
-        else:
-            #not multi tenant, app_path
-            repo_path = git_local_repo_path
-
-        AgentGitHandler.log.debug("Repo path returned : %r" % repo_path)
-        return repo_path
-
-    @staticmethod
-    def commit(repo_info):
-        """
-        Commits and pushes new artifacts to the remote repository
-        :param repo_info:
-        :return:
-        """
-        tenant_id = repo_info.tenant_id
-        repo_context = AgentGitHandler.get_repo_context(tenant_id)
-        gittle_repo = repo_context.gittle_repo
-        try:
-            modified = True if gittle_repo.modified_unstaged_files.count > 0 else False
-        except OSError:
-            # removed files
-            modified = True
-
-        if not modified:
-            AgentGitHandler.log.debug("No changes detected in the local repository for tenant " + tenant_id)
-            return
-
-        gittle_repo.stage(gittle_repo.untracked_files)
-        gittle_repo.stage(gittle_repo.removed_files)
-        gittle_repo.stage(gittle_repo.modified_unstaged_files)
-
-        #commit to local repositpory
-        commit_message = "tenant " + tenant_id + "'s artifacts committed to local repo at " + repo_context.local_repo_path
-
-        try:
-            commit_hash = gittle_repo.commit(name="First Author", email="author@example.org", message=commit_message)
-            AgentGitHandler.log.debug("Committed artifacts for tenant : " + tenant_id + " : " + commit_hash)
-        except:
-            AgentGitHandler.log.exception("Committing artifacts to local repository failed for tenant " + tenant_id)
-
-        #push to remote
-        try:
-            repo = repo_context.repo
-            #TODO: check key based authentication
-            credentialed_remote_url = AgentGitHandler.get_credentialed_remote_url(repo_context)
-            push_remote = repo.create_remote('push_remote', credentialed_remote_url)
-            push_remote.push()
-            AgentGitHandler.log.debug("Pushed artifacts for tenant : " + tenant_id)
-        except:
-            AgentGitHandler.log.exception("Pushing artifacts to remote repository failed for tenant " + tenant_id)
-
-    @staticmethod
-    def get_credentialed_remote_url(repo_context):
-        """
-        Creates a remote url including the credentials
-        :param repo_context:
-        :return:
-        """
-        username = repo_context.repo_username
-        password = repo_context.repo_password
-
-        raise NotImplementedError
-
-    @staticmethod
-    def schedule_artifact_update_scheduled_task(repo_info, auto_checkout, auto_commit, update_interval):
-        repo_context = AgentGitHandler.get_repo_context(repo_info.tenant_id)
-
-        if repo_context is None:
-            AgentGitHandler.log.error("Unable to schedule artifact sync task, repositoryContext null for tenant %r" % repo_info.tenant_id)
-            return
-
-        if repo_context.scheduled_update_task is None:
-            #TODO: make thread safe
-            artifact_update_task = ArtifactUpdateTask(repo_info, auto_checkout, auto_commit)
-            async_task = AsyncScheduledTask(update_interval, artifact_update_task)
-
-            repo_context.scheduled_update_task = async_task
-            async_task.start()
-            AgentGitHandler.log.info("Scheduled Artifact Synchronization Task for path %r" % repo_context.local_repo_path)
-        else:
-            AgentGitHandler.log.info("Artifact Synchronization Task for path %r already scheduled" % repo_context.local_repo_path)
-
-    @staticmethod
-    def remove_repo(tenant_id):
-        repo_context = AgentGitHandler.get_repo_context(tenant_id)
-
-        #stop artifact update task
-        repo_context.scheduled_update_task.terminate()
-
-        #remove git contents
-        cartridgeagentutils.delete_folder_tree(repo_context.local_repo_path)
-
-        AgentGitHandler.remove_repo_context(tenant_id)
-
-        if tenant_id == -1234:
-            if AgentGitHandler.cartridge_agent_config.is_multitenant:
-                extensionutils.execute_copy_artifact_extension(
-                    cartridgeagentconstants.SUPERTENANT_TEMP_PATH,
-                    AgentGitHandler.cartridge_agent_config.app_path + "/repository/deployment/server/"
-                )
-
-        AgentGitHandler.log.info("git repository deleted for tenant %r" % repo_context.tenant_id)
-
-        return True
-
-
-class ArtifactUpdateTask(Thread):
-
-    def __init__(self, repo_info, auto_checkout, auto_commit):
-        self.log = LogFactory().get_log(__name__)
-        Thread.__init__(self)
-        self.repo_info = repo_info
-        self.auto_checkout = auto_checkout
-        self.auto_commit = auto_commit
-
-    def run(self):
-        try:
-            if self.auto_checkout:
-                AgentGitHandler.checkout(self.repo_info)
-        except:
-            self.log.exception("Auto checkout task failed")
-
-        if self.auto_commit:
-            AgentGitHandler.commit(self.repo_info)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/gitrepository.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/gitrepository.py b/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/gitrepository.py
deleted file mode 100644
index 98a8a44..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/git/gitrepository.py
+++ /dev/null
@@ -1,51 +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.
-
-from ...util.asyncscheduledtask import AsyncScheduledTask
-from gittle import Gittle
-from git import *
-
-class GitRepository:
-    """
-    Represents a git repository inside a particular instance
-    """
-
-    def __init__(self):
-        self.repo_url = None
-        """ :type : str  """
-        self.local_repo_path = None
-        """ :type : str  """
-        self.cloned = False
-        """ :type : bool  """
-        self.repo = None
-        """ :type : git.repo.base.Repo  """
-        self.gittle_repo = None
-        """ :type : gittle.gittle.Gittle  """
-        self.tenant_id = None
-        """ :type : int  """
-        self.key_based_auth = False
-        """ :type : bool  """
-        self.repo_username = None
-        """ :type : str  """
-        self.repo_password = None
-        """ :type : str  """
-        self.is_multitenant = False
-        """ :type : bool  """
-        self.commit_enabled = False
-        """ :type : bool  """
-        self.scheduled_update_task = None
-        """:type : AsyncScheduledTask """
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/repositoryinformation.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/repositoryinformation.py b/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/repositoryinformation.py
deleted file mode 100644
index b67eada..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/artifactmgt/repositoryinformation.py
+++ /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.
-
-class RepositoryInformation:
-    """
-    Holds repository information to be used in artifact management
-    """
-
-    def __init__(self, repo_url, repo_username, repo_password, repo_path, tenant_id, is_multitenant, commit_enabled):
-        self.repo_url = repo_url
-        """ :type : str  """
-        self.repo_username = repo_username
-        """ :type : str  """
-        self.repo_password = repo_password
-        """ :type : str  """
-        self.repo_path = repo_path
-        """ :type : str  """
-        self.tenant_id = tenant_id
-        """ :type : int  """
-        self.is_multitenant = is_multitenant
-        """ :type : bool  """
-        self.commit_enabled = commit_enabled
-        """ :type : bool  """
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/config/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/config/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/config/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/config/__init__.py
+++ /dev/null
@@ -1,17 +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.
-

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py b/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py
deleted file mode 100644
index 15871ba..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py
+++ /dev/null
@@ -1,346 +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.
-
-import ConfigParser
-import os
-import socket
-
-from ..util.log import LogFactory
-
-
-class CartridgeAgentConfiguration:
-    """
-    Handles the configuration information of the particular Cartridge Agent
-    """
-    class __CartridgeAgentConfiguration:
-        def __init__(self):
-            # set log level
-            self.log = LogFactory().get_log(__name__)
-
-            self.payload_params = {}
-            self.properties = None
-
-            self.service_group = None
-            """ :type : str  """
-            self.is_clustered = False
-            """ :type : bool  """
-            self.service_name = None
-            """ :type : str  """
-            self.cluster_id = None
-            """ :type : str  """
-            self.network_partition_id = None
-            """ :type : str  """
-            self.partition_id = None
-            """ :type : str  """
-            self.member_id = None
-            """ :type : str  """
-            self.cartridge_key = None
-            """ :type : str  """
-            self.app_path = None
-            """ :type : str  """
-            self.repo_url = None
-            """ :type : str  """
-            self.ports = []
-            """ :type : list[str]  """
-            self.log_file_paths = []
-            """ :type : list[str]  """
-            self.is_multitenant = False
-            """ :type : bool  """
-            self.persistence_mappings = None
-            """ :type : str  """
-            self.is_commits_enabled = False
-            """ :type : bool  """
-            self.is_checkout_enabled = False
-            """ :type : bool  """
-            self.listen_address = None
-            """ :type : str  """
-            self.is_internal_repo = False
-            """ :type : bool  """
-            self.tenant_id = None
-            """ :type : str  """
-            self.lb_cluster_id = None
-            """ :type : str  """
-            self.min_count = None
-            """ :type : str  """
-            self.lb_private_ip = None
-            """ :type : str  """
-            self.lb_public_ip = None
-            """ :type : str  """
-            self.tenant_repository_path = None
-            """ :type : str  """
-            self.super_tenant_repository_path = None
-            """ :type : str  """
-            self.deployment = None
-            """ :type : str  """
-            self.manager_service_name = None
-            """ :type : str  """
-            self.worker_service_name = None
-            """ :type : str  """
-            self.is_primary = False
-            """ :type : bool  """
-
-            self.payload_params = {}
-            self.__read_conf_file()
-            self.__read_parameter_file()
-
-            self.initialized = False
-            """ :type : bool """
-
-            try:
-                self.service_group = self.payload_params[cartridgeagentconstants.SERVICE_GROUP] \
-                    if cartridgeagentconstants.SERVICE_GROUP in self.payload_params \
-                    else None
-
-                if cartridgeagentconstants.CLUSTERING in self.payload_params and \
-                        str(self.payload_params[cartridgeagentconstants.CLUSTERING]).strip().lower() == "true":
-                    self.is_clustered = True
-                else:
-                    self.is_clustered = False
-                # self.__isClustered = self.payload_params[
-                # cartridgeagentconstants.CLUSTERING] if cartridgeagentconstants.CLUSTERING in self.payload_params else None
-
-                self.service_name = self.read_property(cartridgeagentconstants.SERVICE_NAME)
-                self.cluster_id = self.read_property(cartridgeagentconstants.CLUSTER_ID)
-                self.network_partition_id = self.read_property(cartridgeagentconstants.NETWORK_PARTITION_ID, False)
-                self.partition_id = self.read_property(cartridgeagentconstants.PARTITION_ID, False)
-                self.member_id = self.get_member_id(cartridgeagentconstants.MEMBER_ID)
-                self.cartridge_key = self.read_property(cartridgeagentconstants.CARTRIDGE_KEY)
-                self.app_path = self.read_property(cartridgeagentconstants.APP_PATH, False)
-                self.repo_url = self.read_property(cartridgeagentconstants.REPO_URL, False)
-                self.ports = str(self.read_property(cartridgeagentconstants.PORTS)).split("|")
-
-                try:
-                    self.log_file_paths = str(
-                        self.read_property(cartridgeagentconstants.LOG_FILE_PATHS)).strip().split("|")
-                except ParameterNotFoundException as ex:
-                    self.log.debug("Cannot read log file path : %r" % ex.get_message())
-                    self.log_file_paths = None
-
-                is_multi_str = self.read_property(cartridgeagentconstants.MULTITENANT)
-                self.is_multitenant = True if str(is_multi_str).lower().strip() == "true" else False
-
-                try:
-                    self.persistence_mappings = self.read_property(
-                        cartridgeagentconstants.PERSISTENCE_MAPPING)
-                except ParameterNotFoundException as ex:
-                    self.log.debug("Cannot read persistence mapping : %r" % ex.get_message())
-                    self.persistence_mappings = None
-
-                try:
-                    is_commit_str = self.read_property(cartridgeagentconstants.COMMIT_ENABLED)
-                    self.is_commits_enabled = True if str(is_commit_str).lower().strip() == "true" else False
-                except ParameterNotFoundException:
-                    try:
-                        is_commit_str = self.read_property(cartridgeagentconstants.AUTO_COMMIT)
-                        self.is_commits_enabled = True if str(is_commit_str).lower().strip() == "true" else False
-                    except ParameterNotFoundException:
-                        self.log.info(
-                            "%r is not found and setting it to false" % cartridgeagentconstants.COMMIT_ENABLED)
-                        self.is_commits_enabled = False
-
-                auto_checkout_str = self.read_property(cartridgeagentconstants.AUTO_CHECKOUT, False)
-                self.is_checkout_enabled = True if str(auto_checkout_str).lower().strip() == "true" else False
-
-                self.listen_address = self.read_property(
-                    cartridgeagentconstants.LISTEN_ADDRESS, False)
-
-                try:
-                    int_repo_str = self.read_property(cartridgeagentconstants.PROVIDER)
-                    self.is_internal_repo = True if str(int_repo_str).strip().lower() == cartridgeagentconstants.INTERNAL else False
-                except ParameterNotFoundException:
-                    self.log.info(" INTERNAL payload parameter is not found")
-                    self.is_internal_repo = False
-
-                self.tenant_id = self.read_property(cartridgeagentconstants.TENANT_ID)
-                self.lb_cluster_id = self.read_property(cartridgeagentconstants.LB_CLUSTER_ID, False)
-                self.min_count = self.read_property(cartridgeagentconstants.MIN_INSTANCE_COUNT, False)
-                self.lb_private_ip = self.read_property(cartridgeagentconstants.LB_PRIVATE_IP, False)
-                self.lb_public_ip = self.read_property(cartridgeagentconstants.LB_PUBLIC_IP, False)
-                self.tenant_repository_path = self.read_property(cartridgeagentconstants.TENANT_REPO_PATH, False)
-                self.super_tenant_repository_path = self.read_property(cartridgeagentconstants.SUPER_TENANT_REPO_PATH, False)
-
-                try:
-                    self.deployment = self.read_property(
-                        cartridgeagentconstants.DEPLOYMENT)
-                except ParameterNotFoundException:
-                    self.deployment = None
-
-                # Setting worker-manager setup - manager service name
-                if self.deployment is None:
-                    self.manager_service_name = None
-
-                if str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower():
-                    self.manager_service_name = self.service_name
-
-                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
-                    self.deployment = self.read_property(
-                        cartridgeagentconstants.MANAGER_SERVICE_TYPE)
-
-                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_DEFAULT.lower():
-                    self.deployment = None
-                else:
-                    self.deployment = None
-
-                # Setting worker-manager setup - worker service name
-                if self.deployment is None:
-                    self.worker_service_name = None
-
-                if str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_WORKER.lower():
-                    self.manager_service_name = self.service_name
-
-                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_MANAGER.lower():
-                    self.deployment = self.read_property(
-                        cartridgeagentconstants.WORKER_SERVICE_TYPE)
-
-                elif str(self.deployment).lower() == cartridgeagentconstants.DEPLOYMENT_DEFAULT.lower():
-                    self.deployment = None
-                else:
-                    self.deployment = None
-
-                try:
-                    self.is_primary = self.read_property(
-                        cartridgeagentconstants.CLUSTERING_PRIMARY_KEY)
-                except ParameterNotFoundException:
-                    self.is_primary = None
-            except ParameterNotFoundException as ex:
-                raise RuntimeError(ex)
-
-            self.log.info("Cartridge agent configuration initialized")
-
-            self.log.debug("service-name: %r" % self.service_name)
-            self.log.debug("cluster-id: %r" % self.cluster_id)
-            self.log.debug(
-                "network-partition-id: %r" % self.network_partition_id)
-            self.log.debug("partition-id: %r" % self.partition_id)
-            self.log.debug("member-id: %r" % self.member_id)
-            self.log.debug("cartridge-key: %r" % self.cartridge_key)
-            self.log.debug("app-path: %r" % self.app_path)
-            self.log.debug("repo-url: %r" % self.repo_url)
-            self.log.debug("ports: %r" % str(self.ports))
-            self.log.debug("lb-private-ip: %r" % self.lb_private_ip)
-            self.log.debug("lb-public-ip: %r" % self.lb_public_ip)
-
-        def get_member_id(self, member_id_field):
-            """
-            Reads the member id from the payload file or configuration file. If neither of
-            these sources contain the member id, the hostname is assigned to it and returned.
-            :param str member_id_field: the key of the member id to lookup
-            :return: The member id
-            :rtype : str
-            """
-            try:
-                member_id = self.read_property(member_id_field)
-            except ParameterNotFoundException:
-                try:
-                    self.log.info("Reading hostname from container")
-                    member_id = socket.gethostname()
-                except:
-                    self.log.exception("Hostname can not be resolved")
-                    member_id = "unknown"
-
-            self.log.debug("MemberId  is taking the value of hostname : [" + member_id + "] ")
-            return member_id
-
-        def __read_conf_file(self):
-            """
-            Reads and stores the agent's configuration file
-            :return: void
-            """
-
-            conf_file_path = os.path.abspath(os.path.dirname(__file__)).split("modules")[0] + "agent.conf"
-            self.log.debug("Config file path : %r" % conf_file_path)
-            self.properties = ConfigParser.SafeConfigParser()
-            self.properties.read(conf_file_path)
-
-        def __read_parameter_file(self):
-            """
-            Reads the payload file of the cartridge and stores the values in a dictionary
-            :return: void
-            """
-
-            param_file = self.read_property(cartridgeagentconstants.PARAM_FILE_PATH, False)
-            self.log.debug("Param file path : %r" % param_file)
-
-            try:
-                if param_file is not None:
-                    metadata_file = open(param_file)
-                    metadata_payload_content = metadata_file.read()
-                    for param in metadata_payload_content.split(","):
-                        if param.strip() != "":
-                            param_value = param.strip().split("=")
-                            self.payload_params[param_value[0]] = param_value[1]
-
-                    # self.payload_params = dict(
-                    #     param.split("=") for param in metadata_payload_content.split(","))
-                    metadata_file.close()
-                else:
-                    self.log.error("File not found: %r" % param_file)
-            except:
-                self.log.exception(
-                    "Could not read launch parameter file, hence trying to read from System properties.")
-
-        def read_property(self, property_key, critical=True):
-            """
-            Returns the value of the provided property
-            :param str property_key: the name of the property to be read
-            :return: Value of the property,
-            :rtype: str
-            :exception: ParameterNotFoundException if the provided property cannot be found
-            """
-
-            if self.properties.has_option("agent", property_key):
-                self.log.debug("Has key: %r" % property_key)
-                temp_str = self.properties.get("agent", property_key)
-                if temp_str != "" and temp_str is not None:
-                    if str(temp_str).strip().lower() == "null":
-                        return ""
-                    else:
-                        return str(temp_str).strip()
-
-            if property_key in self.payload_params:
-                temp_str = self.payload_params[property_key]
-                if temp_str != "" and temp_str is not None:
-                    if str(temp_str).strip().lower() == "null":
-                        return ""
-                    else:
-                        return str(temp_str).strip()
-
-            if critical:
-                raise ParameterNotFoundException("Cannot find the value of required parameter: %r" % property_key)
-
-    instance = None
-    """ :type : __CartridgeAgentConfiguration"""
-
-    # def __new__(cls, *args, **kwargs):
-    #     if not CartridgeAgentConfiguration.instance:
-    #         CartridgeAgentConfiguration.instance = CartridgeAgentConfiguration.__CartridgeAgentConfiguration()
-    #
-    #     return CartridgeAgentConfiguration.instance
-
-    def __init__(self):
-        if not CartridgeAgentConfiguration.instance:
-            CartridgeAgentConfiguration.instance = CartridgeAgentConfiguration.__CartridgeAgentConfiguration()
-
-    def __getattr__(self, name):
-        return getattr(self.instance, name)
-
-    def __setattr__(self, name, value):
-        return setattr(self.instance, name, value)
-
-
-from ..exception.parameternotfoundexception import ParameterNotFoundException
-from ..util import cartridgeagentconstants

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridge-agent/modules/databridge/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/__init__.py b/tools/python-cartridge-agent/cartridge-agent/modules/databridge/__init__.py
deleted file mode 100644
index 2456923..0000000
--- a/tools/python-cartridge-agent/cartridge-agent/modules/databridge/__init__.py
+++ /dev/null
@@ -1,17 +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.
-


[22/50] [abbrv] git commit: Added asynctask test

Posted by im...@apache.org.
Added asynctask test


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

Branch: refs/heads/master
Commit: b5b6fb3fdebb53f4709ba8468c5e376f2ab989c1
Parents: 9982ae9
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Mon Oct 20 14:03:36 2014 +0530
Committer: Chamila de Alwis <ch...@wso2.com>
Committed: Mon Oct 20 14:03:36 2014 +0530

----------------------------------------------------------------------
 tools/python-cartridge-agent/test/asynctest.txt |  1 +
 tools/python-cartridge-agent/test/test_util.py  | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/b5b6fb3f/tools/python-cartridge-agent/test/asynctest.txt
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/test/asynctest.txt b/tools/python-cartridge-agent/test/asynctest.txt
new file mode 100644
index 0000000..ffae2e3
--- /dev/null
+++ b/tools/python-cartridge-agent/test/asynctest.txt
@@ -0,0 +1 @@
+1413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793
 552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.293
 61413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.2936141379
 3552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29
 361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.293614137
 93552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.2
 9361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413
 793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.
 29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.2936141
 3793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552
 .29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.293614
 13793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.2936141379355
 2.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361
 413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.293614137935
 52.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.29361413793552.2936
 1413793552.29361413793552.29361413793552.2936
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/b5b6fb3f/tools/python-cartridge-agent/test/test_util.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/test/test_util.py b/tools/python-cartridge-agent/test/test_util.py
index 2439cf2..c7ee884 100644
--- a/tools/python-cartridge-agent/test/test_util.py
+++ b/tools/python-cartridge-agent/test/test_util.py
@@ -1,4 +1,20 @@
 from cartridgeagent.modules.util.asyncscheduledtask import AsyncScheduledTask
+from threading import Thread
+import time
+
+def thread_worker():
+    f = open("asynctest.txt", "w")
+    f.write("%1.4f" % time.time() * 1000)
+    f.close()
 
 def test_async_task():
-    assert True
\ No newline at end of file
+    astask = AsyncScheduledTask(2, Thread(thread_worker()))
+    start_time = time.time() * 1000
+    astask.run()
+    time.sleep(3)
+    astask.terminate()
+    f = open("asynctest.txt")
+    end_time = float(f.read())
+    assert (end_time - start_time) >= 2 * 1000, "Task was executed before specified delay"
+
+


[11/50] [abbrv] Renamed cartridge-agent module to cartridgeagent to follow python package naming Added pytest test directory

Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
new file mode 100644
index 0000000..b8c13c1
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ThriftSecureEventTransmissionService.py
@@ -0,0 +1,1495 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ttypes import *
+from ...thrift.Thrift import TProcessor
+from ...thrift.transport import TTransport
+from ..Exception import ttypes
+from .. import Data
+
+try:
+  from ...thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+
+class Iface:
+  def connect(self, userName, password):
+    """
+    Parameters:
+     - userName
+     - password
+    """
+    pass
+
+  def disconnect(self, sessionId):
+    """
+    Parameters:
+     - sessionId
+    """
+    pass
+
+  def defineStream(self, sessionId, streamDefinition):
+    """
+    Parameters:
+     - sessionId
+     - streamDefinition
+    """
+    pass
+
+  def findStreamId(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    pass
+
+  def publish(self, eventBundle):
+    """
+    Parameters:
+     - eventBundle
+    """
+    pass
+
+  def deleteStreamById(self, sessionId, streamId):
+    """
+    Parameters:
+     - sessionId
+     - streamId
+    """
+    pass
+
+  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    pass
+
+
+class Client(Iface):
+  def __init__(self, iprot, oprot=None):
+    self._iprot = self._oprot = iprot
+    if oprot is not None:
+      self._oprot = oprot
+    self._seqid = 0
+
+  def connect(self, userName, password):
+    """
+    Parameters:
+     - userName
+     - password
+    """
+    self.send_connect(userName, password)
+    return self.recv_connect()
+
+  def send_connect(self, userName, password):
+    self._oprot.writeMessageBegin('connect', TMessageType.CALL, self._seqid)
+    args = connect_args()
+    args.userName = userName
+    args.password = password
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_connect(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = connect_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.ae is not None:
+      raise result.ae
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "connect failed: unknown result");
+
+  def disconnect(self, sessionId):
+    """
+    Parameters:
+     - sessionId
+    """
+    self.send_disconnect(sessionId)
+    self.recv_disconnect()
+
+  def send_disconnect(self, sessionId):
+    self._oprot.writeMessageBegin('disconnect', TMessageType.CALL, self._seqid)
+    args = disconnect_args()
+    args.sessionId = sessionId
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_disconnect(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = disconnect_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    return
+
+  def defineStream(self, sessionId, streamDefinition):
+    """
+    Parameters:
+     - sessionId
+     - streamDefinition
+    """
+    self.send_defineStream(sessionId, streamDefinition)
+    return self.recv_defineStream()
+
+  def send_defineStream(self, sessionId, streamDefinition):
+    self._oprot.writeMessageBegin('defineStream', TMessageType.CALL, self._seqid)
+    args = defineStream_args()
+    args.sessionId = sessionId
+    args.streamDefinition = streamDefinition
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_defineStream(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = defineStream_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.ade is not None:
+      raise result.ade
+    if result.mtd is not None:
+      raise result.mtd
+    if result.tde is not None:
+      raise result.tde
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "defineStream failed: unknown result");
+
+  def findStreamId(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    self.send_findStreamId(sessionId, streamName, streamVersion)
+    return self.recv_findStreamId()
+
+  def send_findStreamId(self, sessionId, streamName, streamVersion):
+    self._oprot.writeMessageBegin('findStreamId', TMessageType.CALL, self._seqid)
+    args = findStreamId_args()
+    args.sessionId = sessionId
+    args.streamName = streamName
+    args.streamVersion = streamVersion
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_findStreamId(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = findStreamId_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.tnde is not None:
+      raise result.tnde
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "findStreamId failed: unknown result");
+
+  def publish(self, eventBundle):
+    """
+    Parameters:
+     - eventBundle
+    """
+    self.send_publish(eventBundle)
+    self.recv_publish()
+
+  def send_publish(self, eventBundle):
+    self._oprot.writeMessageBegin('publish', TMessageType.CALL, self._seqid)
+    args = publish_args()
+    args.eventBundle = eventBundle
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_publish(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = publish_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.ue is not None:
+      raise result.ue
+    if result.se is not None:
+      raise result.se
+    return
+
+  def deleteStreamById(self, sessionId, streamId):
+    """
+    Parameters:
+     - sessionId
+     - streamId
+    """
+    self.send_deleteStreamById(sessionId, streamId)
+    return self.recv_deleteStreamById()
+
+  def send_deleteStreamById(self, sessionId, streamId):
+    self._oprot.writeMessageBegin('deleteStreamById', TMessageType.CALL, self._seqid)
+    args = deleteStreamById_args()
+    args.sessionId = sessionId
+    args.streamId = streamId
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_deleteStreamById(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = deleteStreamById_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamById failed: unknown result");
+
+  def deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    """
+    Parameters:
+     - sessionId
+     - streamName
+     - streamVersion
+    """
+    self.send_deleteStreamByNameVersion(sessionId, streamName, streamVersion)
+    return self.recv_deleteStreamByNameVersion()
+
+  def send_deleteStreamByNameVersion(self, sessionId, streamName, streamVersion):
+    self._oprot.writeMessageBegin('deleteStreamByNameVersion', TMessageType.CALL, self._seqid)
+    args = deleteStreamByNameVersion_args()
+    args.sessionId = sessionId
+    args.streamName = streamName
+    args.streamVersion = streamVersion
+    args.write(self._oprot)
+    self._oprot.writeMessageEnd()
+    self._oprot.trans.flush()
+
+  def recv_deleteStreamByNameVersion(self):
+    (fname, mtype, rseqid) = self._iprot.readMessageBegin()
+    if mtype == TMessageType.EXCEPTION:
+      x = TApplicationException()
+      x.read(self._iprot)
+      self._iprot.readMessageEnd()
+      raise x
+    result = deleteStreamByNameVersion_result()
+    result.read(self._iprot)
+    self._iprot.readMessageEnd()
+    if result.success is not None:
+      return result.success
+    if result.se is not None:
+      raise result.se
+    raise TApplicationException(TApplicationException.MISSING_RESULT, "deleteStreamByNameVersion failed: unknown result");
+
+
+class Processor(Iface, TProcessor):
+  def __init__(self, handler):
+    self._handler = handler
+    self._processMap = {}
+    self._processMap["connect"] = Processor.process_connect
+    self._processMap["disconnect"] = Processor.process_disconnect
+    self._processMap["defineStream"] = Processor.process_defineStream
+    self._processMap["findStreamId"] = Processor.process_findStreamId
+    self._processMap["publish"] = Processor.process_publish
+    self._processMap["deleteStreamById"] = Processor.process_deleteStreamById
+    self._processMap["deleteStreamByNameVersion"] = Processor.process_deleteStreamByNameVersion
+
+  def process(self, iprot, oprot):
+    (name, type, seqid) = iprot.readMessageBegin()
+    if name not in self._processMap:
+      iprot.skip(TType.STRUCT)
+      iprot.readMessageEnd()
+      x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name))
+      oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
+      x.write(oprot)
+      oprot.writeMessageEnd()
+      oprot.trans.flush()
+      return
+    else:
+      self._processMap[name](self, seqid, iprot, oprot)
+    return True
+
+  def process_connect(self, seqid, iprot, oprot):
+    args = connect_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = connect_result()
+    try:
+      result.success = self._handler.connect(args.userName, args.password)
+    except ttypes.ThriftAuthenticationException, ae:
+      result.ae = ae
+    oprot.writeMessageBegin("connect", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_disconnect(self, seqid, iprot, oprot):
+    args = disconnect_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = disconnect_result()
+    self._handler.disconnect(args.sessionId)
+    oprot.writeMessageBegin("disconnect", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_defineStream(self, seqid, iprot, oprot):
+    args = defineStream_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = defineStream_result()
+    try:
+      result.success = self._handler.defineStream(args.sessionId, args.streamDefinition)
+    except ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ade:
+      result.ade = ade
+    except ttypes.ThriftMalformedStreamDefinitionException, mtd:
+      result.mtd = mtd
+    except ttypes.ThriftStreamDefinitionException, tde:
+      result.tde = tde
+    except ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("defineStream", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_findStreamId(self, seqid, iprot, oprot):
+    args = findStreamId_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = findStreamId_result()
+    try:
+      result.success = self._handler.findStreamId(args.sessionId, args.streamName, args.streamVersion)
+    except ttypes.ThriftNoStreamDefinitionExistException, tnde:
+      result.tnde = tnde
+    except ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("findStreamId", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_publish(self, seqid, iprot, oprot):
+    args = publish_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = publish_result()
+    try:
+      self._handler.publish(args.eventBundle)
+    except ttypes.ThriftUndefinedEventTypeException, ue:
+      result.ue = ue
+    except ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("publish", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_deleteStreamById(self, seqid, iprot, oprot):
+    args = deleteStreamById_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = deleteStreamById_result()
+    try:
+      result.success = self._handler.deleteStreamById(args.sessionId, args.streamId)
+    except ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("deleteStreamById", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+  def process_deleteStreamByNameVersion(self, seqid, iprot, oprot):
+    args = deleteStreamByNameVersion_args()
+    args.read(iprot)
+    iprot.readMessageEnd()
+    result = deleteStreamByNameVersion_result()
+    try:
+      result.success = self._handler.deleteStreamByNameVersion(args.sessionId, args.streamName, args.streamVersion)
+    except ttypes.ThriftSessionExpiredException, se:
+      result.se = se
+    oprot.writeMessageBegin("deleteStreamByNameVersion", TMessageType.REPLY, seqid)
+    result.write(oprot)
+    oprot.writeMessageEnd()
+    oprot.trans.flush()
+
+
+# HELPER FUNCTIONS AND STRUCTURES
+
+class connect_args:
+  """
+  Attributes:
+   - userName
+   - password
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'userName', None, None, ), # 1
+    (2, TType.STRING, 'password', None, None, ), # 2
+  )
+
+  def __init__(self, userName=None, password=None,):
+    self.userName = userName
+    self.password = password
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.userName = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.password = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('connect_args')
+    if self.userName is not None:
+      oprot.writeFieldBegin('userName', TType.STRING, 1)
+      oprot.writeString(self.userName)
+      oprot.writeFieldEnd()
+    if self.password is not None:
+      oprot.writeFieldBegin('password', TType.STRING, 2)
+      oprot.writeString(self.password)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class connect_result:
+  """
+  Attributes:
+   - success
+   - ae
+  """
+
+  thrift_spec = (
+    (0, TType.STRING, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'ae', (ttypes.ThriftAuthenticationException, ttypes.ThriftAuthenticationException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, ae=None,):
+    self.success = success
+    self.ae = ae
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRING:
+          self.success = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.ae = ttypes.ThriftAuthenticationException()
+          self.ae.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('connect_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.STRING, 0)
+      oprot.writeString(self.success)
+      oprot.writeFieldEnd()
+    if self.ae is not None:
+      oprot.writeFieldBegin('ae', TType.STRUCT, 1)
+      self.ae.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class disconnect_args:
+  """
+  Attributes:
+   - sessionId
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+  )
+
+  def __init__(self, sessionId=None,):
+    self.sessionId = sessionId
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('disconnect_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class disconnect_result:
+
+  thrift_spec = (
+  )
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('disconnect_result')
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class defineStream_args:
+  """
+  Attributes:
+   - sessionId
+   - streamDefinition
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamDefinition', None, None, ), # 2
+  )
+
+  def __init__(self, sessionId=None, streamDefinition=None,):
+    self.sessionId = sessionId
+    self.streamDefinition = streamDefinition
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamDefinition = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('defineStream_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamDefinition is not None:
+      oprot.writeFieldBegin('streamDefinition', TType.STRING, 2)
+      oprot.writeString(self.streamDefinition)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class defineStream_result:
+  """
+  Attributes:
+   - success
+   - ade
+   - mtd
+   - tde
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.STRING, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'ade', (ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException, ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'mtd', (ttypes.ThriftMalformedStreamDefinitionException, ttypes.ThriftMalformedStreamDefinitionException.thrift_spec), None, ), # 2
+    (3, TType.STRUCT, 'tde', (ttypes.ThriftStreamDefinitionException, ttypes.ThriftStreamDefinitionException.thrift_spec), None, ), # 3
+    (4, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 4
+  )
+
+  def __init__(self, success=None, ade=None, mtd=None, tde=None, se=None,):
+    self.success = success
+    self.ade = ade
+    self.mtd = mtd
+    self.tde = tde
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRING:
+          self.success = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.ade = ttypes.ThriftDifferentStreamDefinitionAlreadyDefinedException()
+          self.ade.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.mtd = ttypes.ThriftMalformedStreamDefinitionException()
+          self.mtd.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRUCT:
+          self.tde = ttypes.ThriftStreamDefinitionException()
+          self.tde.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 4:
+        if ftype == TType.STRUCT:
+          self.se = ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('defineStream_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.STRING, 0)
+      oprot.writeString(self.success)
+      oprot.writeFieldEnd()
+    if self.ade is not None:
+      oprot.writeFieldBegin('ade', TType.STRUCT, 1)
+      self.ade.write(oprot)
+      oprot.writeFieldEnd()
+    if self.mtd is not None:
+      oprot.writeFieldBegin('mtd', TType.STRUCT, 2)
+      self.mtd.write(oprot)
+      oprot.writeFieldEnd()
+    if self.tde is not None:
+      oprot.writeFieldBegin('tde', TType.STRUCT, 3)
+      self.tde.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 4)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class findStreamId_args:
+  """
+  Attributes:
+   - sessionId
+   - streamName
+   - streamVersion
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamName', None, None, ), # 2
+    (3, TType.STRING, 'streamVersion', None, None, ), # 3
+  )
+
+  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
+    self.sessionId = sessionId
+    self.streamName = streamName
+    self.streamVersion = streamVersion
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamName = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRING:
+          self.streamVersion = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('findStreamId_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamName is not None:
+      oprot.writeFieldBegin('streamName', TType.STRING, 2)
+      oprot.writeString(self.streamName)
+      oprot.writeFieldEnd()
+    if self.streamVersion is not None:
+      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
+      oprot.writeString(self.streamVersion)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class findStreamId_result:
+  """
+  Attributes:
+   - success
+   - tnde
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.STRING, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'tnde', (ttypes.ThriftNoStreamDefinitionExistException, ttypes.ThriftNoStreamDefinitionExistException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
+  )
+
+  def __init__(self, success=None, tnde=None, se=None,):
+    self.success = success
+    self.tnde = tnde
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.STRING:
+          self.success = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.tnde = ttypes.ThriftNoStreamDefinitionExistException()
+          self.tnde.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.se = ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('findStreamId_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.STRING, 0)
+      oprot.writeString(self.success)
+      oprot.writeFieldEnd()
+    if self.tnde is not None:
+      oprot.writeFieldBegin('tnde', TType.STRUCT, 1)
+      self.tnde.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 2)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class publish_args:
+  """
+  Attributes:
+   - eventBundle
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRUCT, 'eventBundle', (Data.ttypes.ThriftEventBundle, Data.ttypes.ThriftEventBundle.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, eventBundle=None,):
+    self.eventBundle = eventBundle
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRUCT:
+          self.eventBundle = Data.ttypes.ThriftEventBundle()
+          self.eventBundle.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('publish_args')
+    if self.eventBundle is not None:
+      oprot.writeFieldBegin('eventBundle', TType.STRUCT, 1)
+      self.eventBundle.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class publish_result:
+  """
+  Attributes:
+   - ue
+   - se
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRUCT, 'ue', (ttypes.ThriftUndefinedEventTypeException, ttypes.ThriftUndefinedEventTypeException.thrift_spec), None, ), # 1
+    (2, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 2
+  )
+
+  def __init__(self, ue=None, se=None,):
+    self.ue = ue
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRUCT:
+          self.ue = ttypes.ThriftUndefinedEventTypeException()
+          self.ue.read(iprot)
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRUCT:
+          self.se = ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('publish_result')
+    if self.ue is not None:
+      oprot.writeFieldBegin('ue', TType.STRUCT, 1)
+      self.ue.write(oprot)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 2)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamById_args:
+  """
+  Attributes:
+   - sessionId
+   - streamId
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamId', None, None, ), # 2
+  )
+
+  def __init__(self, sessionId=None, streamId=None,):
+    self.sessionId = sessionId
+    self.streamId = streamId
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamById_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamId is not None:
+      oprot.writeFieldBegin('streamId', TType.STRING, 2)
+      oprot.writeString(self.streamId)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamById_result:
+  """
+  Attributes:
+   - success
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.BOOL, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, se=None,):
+    self.success = success
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.BOOL:
+          self.success = iprot.readBool();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.se = ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamById_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.BOOL, 0)
+      oprot.writeBool(self.success)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 1)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamByNameVersion_args:
+  """
+  Attributes:
+   - sessionId
+   - streamName
+   - streamVersion
+  """
+
+  thrift_spec = (
+    None, # 0
+    (1, TType.STRING, 'sessionId', None, None, ), # 1
+    (2, TType.STRING, 'streamName', None, None, ), # 2
+    (3, TType.STRING, 'streamVersion', None, None, ), # 3
+  )
+
+  def __init__(self, sessionId=None, streamName=None, streamVersion=None,):
+    self.sessionId = sessionId
+    self.streamName = streamName
+    self.streamVersion = streamVersion
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.sessionId = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.STRING:
+          self.streamName = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      elif fid == 3:
+        if ftype == TType.STRING:
+          self.streamVersion = iprot.readString();
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamByNameVersion_args')
+    if self.sessionId is not None:
+      oprot.writeFieldBegin('sessionId', TType.STRING, 1)
+      oprot.writeString(self.sessionId)
+      oprot.writeFieldEnd()
+    if self.streamName is not None:
+      oprot.writeFieldBegin('streamName', TType.STRING, 2)
+      oprot.writeString(self.streamName)
+      oprot.writeFieldEnd()
+    if self.streamVersion is not None:
+      oprot.writeFieldBegin('streamVersion', TType.STRING, 3)
+      oprot.writeString(self.streamVersion)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)
+
+class deleteStreamByNameVersion_result:
+  """
+  Attributes:
+   - success
+   - se
+  """
+
+  thrift_spec = (
+    (0, TType.BOOL, 'success', None, None, ), # 0
+    (1, TType.STRUCT, 'se', (ttypes.ThriftSessionExpiredException, ttypes.ThriftSessionExpiredException.thrift_spec), None, ), # 1
+  )
+
+  def __init__(self, success=None, se=None,):
+    self.success = success
+    self.se = se
+
+  def read(self, iprot):
+    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
+      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
+      return
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 0:
+        if ftype == TType.BOOL:
+          self.success = iprot.readBool();
+        else:
+          iprot.skip(ftype)
+      elif fid == 1:
+        if ftype == TType.STRUCT:
+          self.se = ttypes.ThriftSessionExpiredException()
+          self.se.read(iprot)
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
+      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStructBegin('deleteStreamByNameVersion_result')
+    if self.success is not None:
+      oprot.writeFieldBegin('success', TType.BOOL, 0)
+      oprot.writeBool(self.success)
+      oprot.writeFieldEnd()
+    if self.se is not None:
+      oprot.writeFieldBegin('se', TType.STRUCT, 1)
+      self.se.write(oprot)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()
+
+  def validate(self):
+    return
+
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, value)
+      for key, value in self.__dict__.iteritems()]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__
+
+  def __ne__(self, other):
+    return not (self == other)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
new file mode 100644
index 0000000..c321ae1
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/__init__.py
@@ -0,0 +1 @@
+__all__ = ['ttypes', 'constants', 'ThriftSecureEventTransmissionService']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
new file mode 100644
index 0000000..36943ba
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/constants.py
@@ -0,0 +1,8 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
new file mode 100644
index 0000000..37ac241
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/ThriftSecureEventTransmissionService/ttypes.py
@@ -0,0 +1,21 @@
+#
+# Autogenerated by Thrift Compiler (0.9.1)
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+#  options string: py
+#
+
+from ...thrift.Thrift import TType, TMessageType, TException, TApplicationException
+from ..Data import ttypes
+from ..Exception import ttypes
+
+
+from ...thrift.transport import TTransport
+from ...thrift.protocol import TBinaryProtocol, TProtocol
+try:
+  from thrift.protocol import fastbinary
+except:
+  fastbinary = None
+
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/gen/__init__.py
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/publisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/publisher.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/publisher.py
new file mode 100644
index 0000000..325b05d
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/publisher.py
@@ -0,0 +1,111 @@
+# 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.
+
+import time
+import sys
+
+sys.path.append("gen")
+
+from gen.ThriftSecureEventTransmissionService import ThriftSecureEventTransmissionService
+from gen.Data.ttypes import ThriftEventBundle
+
+from thrift.transport import TSSLSocket
+from thrift.transport import TTransport
+from thrift.protocol import TBinaryProtocol
+
+
+# Define publisher class
+class Publisher:
+    client = None
+
+    def __init__(self, ip, port):
+        # Make SSL socket
+        self.socket = TSSLSocket.TSSLSocket(ip, port, False)
+        # Buffering is critical. Raw sockets are very slow
+        self.transport = TTransport.TBufferedTransport(self.socket)
+        # Wrap in a protocol
+        self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
+        self.sessionId = None
+        self.streamId = None
+
+    def connect(self, username, password):
+        # Create a client to use the protocol encoder
+        Publisher.client = ThriftSecureEventTransmissionService.Client(self.protocol)
+
+        # Make connection
+        self.socket.open()
+        self.transport.open()
+        self.sessionId = Publisher.client.connect(username, password)
+
+    def defineStream(self, streamDef):
+        # Create Stream Definition
+        self.streamId = Publisher.client.defineStream(self.sessionId, streamDef)
+
+    def publish(self, event):
+        # Build thrift event bundle
+        #event = EventBundle()
+        event.setSessionId(self.sessionId)
+        event.setEventNum(0)
+        event.addStringAttribute(self.streamId)
+        event.addLongAttribute(time.time() * 1000)
+        #event.addStringAttribute(msg)
+        # Publish
+        Publisher.client.publish(event.getEventBundle())
+
+    def disconnect(self):
+        # Disconnect
+        Publisher.client.disconnect(self.sessionId)
+        self.transport.close()
+        self.socket.close()
+
+
+class EventBundle:
+    __sessionId = ""
+    __eventNum = 0
+    __intAttributeList = []
+    __longAttributeList = []
+    __doubleAttributeList = []
+    __boolAttributeList = []
+    __stringAttributeList = []
+    __arbitraryDataMapMap = None
+
+    def setSessionId(self, sessionId):
+        self.__sessionId = sessionId
+
+    def setEventNum(self, num):
+        self.__eventNum = num
+
+    def addIntAttribute(self, attr):
+        self.__intAttributeList.append(attr)
+
+    def addLongAttribute(self, attr):
+        self.__longAttributeList.append(attr)
+
+    def addDoubleAttribute(self, attr):
+        self.__doubleAttributeList.append(attr)
+
+    def addBoolAttribute(self, attr):
+        self.__boolAttributeList.append(attr)
+
+    def addStringAttribute(self, attr):
+        self.__stringAttributeList.append(attr)
+
+    def getEventBundle(self):
+        return ThriftEventBundle(self.__sessionId, self.__eventNum, self.__intAttributeList,
+                                             self.__longAttributeList, self.__doubleAttributeList,
+                                             self.__boolAttributeList, self.__stringAttributeList,
+                                             self.__arbitraryDataMapMap)

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py
new file mode 100644
index 0000000..da8d283
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSCons.py
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+from os import path
+from SCons.Builder import Builder
+
+
+def scons_env(env, add=''):
+  opath = path.dirname(path.abspath('$TARGET'))
+  lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE'
+  cppbuild = Builder(action=lstr)
+  env.Append(BUILDERS={'ThriftCpp': cppbuild})
+
+
+def gen_cpp(env, dir, file):
+  scons_env(env)
+  suffixes = ['_types.h', '_types.cpp']
+  targets = map(lambda s: 'gen-cpp/' + file + s, suffixes)
+  return env.ThriftCpp(targets, dir + file + '.thrift')

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py
new file mode 100644
index 0000000..8a58d89
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TSerialization.py
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+from protocol import TBinaryProtocol
+from transport import TTransport
+
+
+def serialize(thrift_object,
+              protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
+    transport = TTransport.TMemoryBuffer()
+    protocol = protocol_factory.getProtocol(transport)
+    thrift_object.write(protocol)
+    return transport.getvalue()
+
+
+def deserialize(base,
+                buf,
+                protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
+    transport = TTransport.TMemoryBuffer(buf)
+    protocol = protocol_factory.getProtocol(transport)
+    base.read(protocol)
+    return base

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py
new file mode 100644
index 0000000..8d9f5ed
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/TTornado.py
@@ -0,0 +1,153 @@
+#
+# 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.
+#
+
+from cStringIO import StringIO
+import logging
+import socket
+import struct
+
+from .transport import TTransport
+from .transport.TTransport import TTransportException
+
+from tornado import gen
+from tornado import iostream
+from tornado import netutil
+
+
+class TTornadoStreamTransport(TTransport.TTransportBase):
+    """a framed, buffered transport over a Tornado stream"""
+    def __init__(self, host, port, stream=None):
+        self.host = host
+        self.port = port
+        self.is_queuing_reads = False
+        self.read_queue = []
+        self.__wbuf = StringIO()
+
+        # servers provide a ready-to-go stream
+        self.stream = stream
+        if self.stream is not None:
+            self._set_close_callback()
+
+    # not the same number of parameters as TTransportBase.open
+    def open(self, callback):
+        logging.debug('socket connecting')
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
+        self.stream = iostream.IOStream(sock)
+
+        def on_close_in_connect(*_):
+            message = 'could not connect to {}:{}'.format(self.host, self.port)
+            raise TTransportException(
+                type=TTransportException.NOT_OPEN,
+                message=message)
+        self.stream.set_close_callback(on_close_in_connect)
+
+        def finish(*_):
+            self._set_close_callback()
+            callback()
+
+        self.stream.connect((self.host, self.port), callback=finish)
+
+    def _set_close_callback(self):
+        def on_close():
+            raise TTransportException(
+                type=TTransportException.END_OF_FILE,
+                message='socket closed')
+        self.stream.set_close_callback(self.close)
+
+    def close(self):
+        # don't raise if we intend to close
+        self.stream.set_close_callback(None)
+        self.stream.close()
+
+    def read(self, _):
+        # The generated code for Tornado shouldn't do individual reads -- only
+        # frames at a time
+        assert "you're doing it wrong" is True
+
+    @gen.engine
+    def readFrame(self, callback):
+        self.read_queue.append(callback)
+        logging.debug('read queue: %s', self.read_queue)
+
+        if self.is_queuing_reads:
+            # If a read is already in flight, then the while loop below should
+            # pull it from self.read_queue
+            return
+
+        self.is_queuing_reads = True
+        while self.read_queue:
+            next_callback = self.read_queue.pop()
+            result = yield gen.Task(self._readFrameFromStream)
+            next_callback(result)
+        self.is_queuing_reads = False
+
+    @gen.engine
+    def _readFrameFromStream(self, callback):
+        logging.debug('_readFrameFromStream')
+        frame_header = yield gen.Task(self.stream.read_bytes, 4)
+        frame_length, = struct.unpack('!i', frame_header)
+        logging.debug('received frame header, frame length = %i', frame_length)
+        frame = yield gen.Task(self.stream.read_bytes, frame_length)
+        logging.debug('received frame payload')
+        callback(frame)
+
+    def write(self, buf):
+        self.__wbuf.write(buf)
+
+    def flush(self, callback=None):
+        wout = self.__wbuf.getvalue()
+        wsz = len(wout)
+        # reset wbuf before write/flush to preserve state on underlying failure
+        self.__wbuf = StringIO()
+        # N.B.: Doing this string concatenation is WAY cheaper than making
+        # two separate calls to the underlying socket object. Socket writes in
+        # Python turn out to be REALLY expensive, but it seems to do a pretty
+        # good job of managing string buffer operations without excessive copies
+        buf = struct.pack("!i", wsz) + wout
+
+        logging.debug('writing frame length = %i', wsz)
+        self.stream.write(buf, callback)
+
+
+class TTornadoServer(netutil.TCPServer):
+    def __init__(self, processor, iprot_factory, oprot_factory=None,
+                 *args, **kwargs):
+        super(TTornadoServer, self).__init__(*args, **kwargs)
+
+        self._processor = processor
+        self._iprot_factory = iprot_factory
+        self._oprot_factory = (oprot_factory if oprot_factory is not None
+                               else iprot_factory)
+
+    def handle_stream(self, stream, address):
+        try:
+            host, port = address
+            trans = TTornadoStreamTransport(host=host, port=port, stream=stream)
+            oprot = self._oprot_factory.getProtocol(trans)
+
+            def next_pass():
+                if not trans.stream.closed():
+                    self._processor.process(trans, self._iprot_factory, oprot,
+                                            callback=next_pass)
+
+            next_pass()
+
+        except Exception:
+            logging.exception('thrift exception in handle_stream')
+            trans.close()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py
new file mode 100644
index 0000000..9890af7
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/Thrift.py
@@ -0,0 +1,170 @@
+#
+# 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.
+#
+
+import sys
+
+
+class TType:
+  STOP   = 0
+  VOID   = 1
+  BOOL   = 2
+  BYTE   = 3
+  I08    = 3
+  DOUBLE = 4
+  I16    = 6
+  I32    = 8
+  I64    = 10
+  STRING = 11
+  UTF7   = 11
+  STRUCT = 12
+  MAP    = 13
+  SET    = 14
+  LIST   = 15
+  UTF8   = 16
+  UTF16  = 17
+
+  _VALUES_TO_NAMES = ('STOP',
+                      'VOID',
+                      'BOOL',
+                      'BYTE',
+                      'DOUBLE',
+                      None,
+                      'I16',
+                      None,
+                      'I32',
+                      None,
+                     'I64',
+                     'STRING',
+                     'STRUCT',
+                     'MAP',
+                     'SET',
+                     'LIST',
+                     'UTF8',
+                     'UTF16')
+
+
+class TMessageType:
+  CALL = 1
+  REPLY = 2
+  EXCEPTION = 3
+  ONEWAY = 4
+
+
+class TProcessor:
+  """Base class for procsessor, which works on two streams."""
+
+  def process(iprot, oprot):
+    pass
+
+
+class TException(Exception):
+  """Base class for all thrift exceptions."""
+
+  # BaseException.message is deprecated in Python v[2.6,3.0)
+  if (2, 6, 0) <= sys.version_info < (3, 0):
+    def _get_message(self):
+      return self._message
+
+    def _set_message(self, message):
+      self._message = message
+    message = property(_get_message, _set_message)
+
+  def __init__(self, message=None):
+    Exception.__init__(self, message)
+    self.message = message
+
+
+class TApplicationException(TException):
+  """Application level thrift exceptions."""
+
+  UNKNOWN = 0
+  UNKNOWN_METHOD = 1
+  INVALID_MESSAGE_TYPE = 2
+  WRONG_METHOD_NAME = 3
+  BAD_SEQUENCE_ID = 4
+  MISSING_RESULT = 5
+  INTERNAL_ERROR = 6
+  PROTOCOL_ERROR = 7
+  INVALID_TRANSFORM = 8
+  INVALID_PROTOCOL = 9
+  UNSUPPORTED_CLIENT_TYPE = 10
+
+  def __init__(self, type=UNKNOWN, message=None):
+    TException.__init__(self, message)
+    self.type = type
+
+  def __str__(self):
+    if self.message:
+      return self.message
+    elif self.type == self.UNKNOWN_METHOD:
+      return 'Unknown method'
+    elif self.type == self.INVALID_MESSAGE_TYPE:
+      return 'Invalid message type'
+    elif self.type == self.WRONG_METHOD_NAME:
+      return 'Wrong method name'
+    elif self.type == self.BAD_SEQUENCE_ID:
+      return 'Bad sequence ID'
+    elif self.type == self.MISSING_RESULT:
+      return 'Missing result'
+    elif self.type == self.INTERNAL_ERROR:
+      return 'Internal error'
+    elif self.type == self.PROTOCOL_ERROR:
+      return 'Protocol error'
+    elif self.type == self.INVALID_TRANSFORM:
+      return 'Invalid transform'
+    elif self.type == self.INVALID_PROTOCOL:
+      return 'Invalid protocol'
+    elif self.type == self.UNSUPPORTED_CLIENT_TYPE:
+      return 'Unsupported client type'
+    else:
+      return 'Default (unknown) TApplicationException'
+
+  def read(self, iprot):
+    iprot.readStructBegin()
+    while True:
+      (fname, ftype, fid) = iprot.readFieldBegin()
+      if ftype == TType.STOP:
+        break
+      if fid == 1:
+        if ftype == TType.STRING:
+          self.message = iprot.readString()
+        else:
+          iprot.skip(ftype)
+      elif fid == 2:
+        if ftype == TType.I32:
+          self.type = iprot.readI32()
+        else:
+          iprot.skip(ftype)
+      else:
+        iprot.skip(ftype)
+      iprot.readFieldEnd()
+    iprot.readStructEnd()
+
+  def write(self, oprot):
+    oprot.writeStructBegin('TApplicationException')
+    if self.message is not None:
+      oprot.writeFieldBegin('message', TType.STRING, 1)
+      oprot.writeString(self.message)
+      oprot.writeFieldEnd()
+    if self.type is not None:
+      oprot.writeFieldBegin('type', TType.I32, 2)
+      oprot.writeI32(self.type)
+      oprot.writeFieldEnd()
+    oprot.writeFieldStop()
+    oprot.writeStructEnd()

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py
new file mode 100644
index 0000000..48d659c
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/__init__.py
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+__all__ = ['Thrift', 'TSCons']

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py
new file mode 100644
index 0000000..61b469b
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBase.py
@@ -0,0 +1,81 @@
+#
+# 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.
+#
+
+from ..Thrift import *
+import TBinaryProtocol
+from ..transport import TTransport
+
+try:
+  import fastbinary
+except:
+  fastbinary = None
+
+
+class TBase(object):
+  __slots__ = []
+
+  def __repr__(self):
+    L = ['%s=%r' % (key, getattr(self, key))
+              for key in self.__slots__]
+    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
+
+  def __eq__(self, other):
+    if not isinstance(other, self.__class__):
+      return False
+    for attr in self.__slots__:
+      my_val = getattr(self, attr)
+      other_val = getattr(other, attr)
+      if my_val != other_val:
+        return False
+    return True
+
+  def __ne__(self, other):
+    return not (self == other)
+
+  def read(self, iprot):
+    if (iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
+        isinstance(iprot.trans, TTransport.CReadableTransport) and
+        self.thrift_spec is not None and
+        fastbinary is not None):
+      fastbinary.decode_binary(self,
+                               iprot.trans,
+                               (self.__class__, self.thrift_spec))
+      return
+    iprot.readStruct(self, self.thrift_spec)
+
+  def write(self, oprot):
+    if (oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
+        self.thrift_spec is not None and
+        fastbinary is not None):
+      oprot.trans.write(
+        fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
+      return
+    oprot.writeStruct(self, self.thrift_spec)
+
+
+class TExceptionBase(Exception):
+  # old style class so python2.4 can raise exceptions derived from this
+  #  This can't inherit from TBase because of that limitation.
+  __slots__ = []
+
+  __repr__ = TBase.__repr__.im_func
+  __eq__ = TBase.__eq__.im_func
+  __ne__ = TBase.__ne__.im_func
+  read = TBase.read.im_func
+  write = TBase.write.im_func

http://git-wip-us.apache.org/repos/asf/stratos/blob/bcddfbad/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
new file mode 100644
index 0000000..2cdc6b5
--- /dev/null
+++ b/tools/python-cartridge-agent/cartridgeagent/modules/databridge/thrift/thrift/protocol/TBinaryProtocol.py
@@ -0,0 +1,261 @@
+#
+# 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.
+#
+
+from struct import pack, unpack
+
+from TProtocol import *
+
+
+class TBinaryProtocol(TProtocolBase):
+  """Binary implementation of the Thrift protocol driver."""
+
+  # NastyHaxx. Python 2.4+ on 32-bit machines forces hex constants to be
+  # positive, converting this into a long. If we hardcode the int value
+  # instead it'll stay in 32 bit-land.
+
+  # VERSION_MASK = 0xffff0000
+  VERSION_MASK = -65536
+
+  # VERSION_1 = 0x80010000
+  VERSION_1 = -2147418112
+
+  TYPE_MASK = 0x000000ff
+
+  def __init__(self, trans, strictRead=False, strictWrite=True):
+    TProtocolBase.__init__(self, trans)
+    self.strictRead = strictRead
+    self.strictWrite = strictWrite
+
+  def writeMessageBegin(self, name, type, seqid):
+    if self.strictWrite:
+      self.writeI32(TBinaryProtocol.VERSION_1 | type)
+      self.writeString(name)
+      self.writeI32(seqid)
+    else:
+      self.writeString(name)
+      self.writeByte(type)
+      self.writeI32(seqid)
+
+  def writeMessageEnd(self):
+    pass
+
+  def writeStructBegin(self, name):
+    pass
+
+  def writeStructEnd(self):
+    pass
+
+  def writeFieldBegin(self, name, type, id):
+    self.writeByte(type)
+    self.writeI16(id)
+
+  def writeFieldEnd(self):
+    pass
+
+  def writeFieldStop(self):
+    self.writeByte(TType.STOP)
+
+  def writeMapBegin(self, ktype, vtype, size):
+    self.writeByte(ktype)
+    self.writeByte(vtype)
+    self.writeI32(size)
+
+  def writeMapEnd(self):
+    pass
+
+  def writeListBegin(self, etype, size):
+    self.writeByte(etype)
+    self.writeI32(size)
+
+  def writeListEnd(self):
+    pass
+
+  def writeSetBegin(self, etype, size):
+    self.writeByte(etype)
+    self.writeI32(size)
+
+  def writeSetEnd(self):
+    pass
+
+  def writeBool(self, bool):
+    if bool:
+      self.writeByte(1)
+    else:
+      self.writeByte(0)
+
+  def writeByte(self, byte):
+    buff = pack("!b", byte)
+    self.trans.write(buff)
+
+  def writeI16(self, i16):
+    buff = pack("!h", i16)
+    self.trans.write(buff)
+
+  def writeI32(self, i32):
+    buff = pack("!i", i32)
+    self.trans.write(buff)
+
+  def writeI64(self, i64):
+    buff = pack("!q", i64)
+    self.trans.write(buff)
+
+  def writeDouble(self, dub):
+    buff = pack("!d", dub)
+    self.trans.write(buff)
+
+  def writeString(self, str):
+    self.writeI32(len(str))
+    self.trans.write(str)
+
+  def readMessageBegin(self):
+    sz = self.readI32()
+    if sz < 0:
+      version = sz & TBinaryProtocol.VERSION_MASK
+      if version != TBinaryProtocol.VERSION_1:
+        raise TProtocolException(
+          type=TProtocolException.BAD_VERSION,
+          message='Bad version in readMessageBegin: %d' % (sz))
+      type = sz & TBinaryProtocol.TYPE_MASK
+      name = self.readString()
+      seqid = self.readI32()
+    else:
+      if self.strictRead:
+        raise TProtocolException(type=TProtocolException.BAD_VERSION,
+                                 message='No protocol version header')
+      name = self.trans.readAll(sz)
+      type = self.readByte()
+      seqid = self.readI32()
+    return (name, type, seqid)
+
+  def readMessageEnd(self):
+    pass
+
+  def readStructBegin(self):
+    pass
+
+  def readStructEnd(self):
+    pass
+
+  def readFieldBegin(self):
+    type = self.readByte()
+    if type == TType.STOP:
+      return (None, type, 0)
+    id = self.readI16()
+    return (None, type, id)
+
+  def readFieldEnd(self):
+    pass
+
+  def readMapBegin(self):
+    ktype = self.readByte()
+    vtype = self.readByte()
+    size = self.readI32()
+    return (ktype, vtype, size)
+
+  def readMapEnd(self):
+    pass
+
+  def readListBegin(self):
+    etype = self.readByte()
+    size = self.readI32()
+    return (etype, size)
+
+  def readListEnd(self):
+    pass
+
+  def readSetBegin(self):
+    etype = self.readByte()
+    size = self.readI32()
+    return (etype, size)
+
+  def readSetEnd(self):
+    pass
+
+  def readBool(self):
+    byte = self.readByte()
+    if byte == 0:
+      return False
+    return True
+
+  def readByte(self):
+    buff = self.trans.readAll(1)
+    val, = unpack('!b', buff)
+    return val
+
+  def readI16(self):
+    buff = self.trans.readAll(2)
+    val, = unpack('!h', buff)
+    return val
+
+  def readI32(self):
+    buff = self.trans.readAll(4)
+    val, = unpack('!i', buff)
+    return val
+
+  def readI64(self):
+    buff = self.trans.readAll(8)
+    val, = unpack('!q', buff)
+    return val
+
+  def readDouble(self):
+    buff = self.trans.readAll(8)
+    val, = unpack('!d', buff)
+    return val
+
+  def readString(self):
+    len = self.readI32()
+    str = self.trans.readAll(len)
+    return str
+
+
+class TBinaryProtocolFactory:
+  def __init__(self, strictRead=False, strictWrite=True):
+    self.strictRead = strictRead
+    self.strictWrite = strictWrite
+
+  def getProtocol(self, trans):
+    prot = TBinaryProtocol(trans, self.strictRead, self.strictWrite)
+    return prot
+
+
+class TBinaryProtocolAccelerated(TBinaryProtocol):
+  """C-Accelerated version of TBinaryProtocol.
+
+  This class does not override any of TBinaryProtocol's methods,
+  but the generated code recognizes it directly and will call into
+  our C module to do the encoding, bypassing this object entirely.
+  We inherit from TBinaryProtocol so that the normal TBinaryProtocol
+  encoding can happen if the fastbinary module doesn't work for some
+  reason.  (TODO(dreiss): Make this happen sanely in more cases.)
+
+  In order to take advantage of the C module, just use
+  TBinaryProtocolAccelerated instead of TBinaryProtocol.
+
+  NOTE:  This code was contributed by an external developer.
+         The internal Thrift team has reviewed and tested it,
+         but we cannot guarantee that it is production-ready.
+         Please feel free to report bugs and/or success stories
+         to the public mailing list.
+  """
+  pass
+
+
+class TBinaryProtocolAcceleratedFactory:
+  def getProtocol(self, trans):
+    return TBinaryProtocolAccelerated(trans)