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 2015/02/10 16:50:26 UTC
[08/17] stratos git commit: Moving python cartridge agent automation
tests to python cartridge agent component
http://git-wip-us.apache.org/repos/asf/stratos/blob/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/logging.ini
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/logging.ini b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/logging.ini
new file mode 100644
index 0000000..15cad9b
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/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 {%(filename)s:%(funcName)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=DEBUG
+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=DEBUG
+formatter=default
+handlers=console,error_file,log_file
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/__init__.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/__init__.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/__init__.py
new file mode 100644
index 0000000..d216be4
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/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/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/__init__.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/__init__.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/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/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/__init__.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/__init__.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/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/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/agentgithandler.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/agentgithandler.py
new file mode 100644
index 0000000..afa58dc
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/agentgithandler.py
@@ -0,0 +1,538 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT 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
+import os
+import pexpect
+import subprocess
+import shutil
+
+from ... util.log import LogFactory
+from ... util.asyncscheduledtask import AbstractAsyncScheduledTask, ScheduledExecutor
+from ... artifactmgt.repository import Repository
+from ... exception.gitrepositorysynchronizationexception import GitRepositorySynchronizationException
+
+
+class AgentGitHandler:
+ """
+ Handles all the git artifact management tasks related to a cartridge
+ """
+
+ log = LogFactory().get_log(__name__)
+
+ __git_repositories = {}
+ # (tenant_id => GitRepository)
+
+ @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 Repository repo_info: The repository information object
+ :return: A tuple containing whether it was an initial clone or not, and if the repo was updated on
+ subsequent calls or not
+ :rtype: tuple(bool, bool)
+ """
+ git_repo = AgentGitHandler.get_repo(repo_info.tenant_id)
+ updated = False
+ if git_repo is not None:
+ # has been previously cloned, this is not the subscription run
+ subscribe_run = False
+ if AgentGitHandler.is_valid_git_repository(git_repo):
+ AgentGitHandler.log.debug("Executing git pull: [tenant-id] %s [repo-url] %s",
+ git_repo.tenant_id, git_repo.repo_url)
+ try:
+ updated = AgentGitHandler.pull(git_repo)
+ AgentGitHandler.log.debug("Git pull executed: [tenant-id] %s [repo-url] %s",
+ git_repo.tenant_id, git_repo.repo_url)
+ except GitRepositorySynchronizationException as e:
+ AgentGitHandler.log.debug("Warning: Git Pull operation failed: %r" % e.get_message())
+
+ else:
+ # not a valid repository, might've been corrupted. do a re-clone
+ AgentGitHandler.log.debug("Local repository is not valid. Doing a re-clone to purify.")
+ git_repo.cloned = False
+ AgentGitHandler.log.debug("Executing git clone: [tenant-id] %s [repo-url] %s",
+ git_repo.tenant_id, git_repo.repo_url)
+ git_repo = AgentGitHandler.clone(git_repo)
+ updated = True
+ AgentGitHandler.log.debug("Git clone executed: [tenant-id] %s [repo-url] %s",
+ git_repo.tenant_id, git_repo.repo_url)
+ else:
+ # subscribing run.. need to clone
+ git_repo = AgentGitHandler.create_git_repo(repo_info)
+ AgentGitHandler.log.debug("Cloning artifacts from %s for the first time to %r",
+ git_repo.repo_url, git_repo.local_repo_path)
+ subscribe_run = True
+ AgentGitHandler.log.debug("Executing git clone: [tenant-id] %s [repo-url] %s",
+ git_repo.tenant_id, git_repo.repo_url)
+ git_repo = AgentGitHandler.clone(git_repo)
+ AgentGitHandler.log.debug("Git clone executed: [tenant-id] %s [repo-url] %s",
+ git_repo.tenant_id, git_repo.repo_url)
+
+ return subscribe_run, updated
+
+ @staticmethod
+ def sync_initial_local_artifacts(git_repo):
+ # init git repo
+ AgentGitHandler.init(git_repo.local_repo_path)
+
+ # add remote repos
+ return AgentGitHandler.add_remote(git_repo)
+
+ @staticmethod
+ def add_remote(git_repo):
+ # add origin remote
+ output, errors = AgentGitHandler.execute_git_command(["remote", "add", "origin", git_repo.repo_url],
+ git_repo.local_repo_path)
+ if len(output) > 0:
+ raise GitRepositorySynchronizationException("Error in adding remote origin %r for local repository %r"
+ % (git_repo.repo_url, git_repo.local_repo_path))
+
+ # fetch
+ output, errors = AgentGitHandler.execute_git_command(["fetch"], git_repo.local_repo_path)
+ if "Resolving deltas: 100%" not in output:
+ raise GitRepositorySynchronizationException(
+ "Error in fetching from remote origin %r for local repository %r"
+ % (git_repo.repo_url, git_repo.local_repo_path))
+
+ # checkout master
+ output, errors = AgentGitHandler.execute_git_command(["checkout", "master"], git_repo.local_repo_path)
+ if "Branch master set up to track remote branch master from origin." not in output:
+ raise GitRepositorySynchronizationException("Error in checking out master branch %r for local repository %r"
+ % (git_repo.repo_url, git_repo.local_repo_path))
+
+ return True
+
+ @staticmethod
+ def init(path):
+ output, errors = AgentGitHandler.execute_git_command(["init"], path)
+ if "Initialized empty Git repository in" not in output:
+ AgentGitHandler.log.exception("Initializing local repo at %r failed: %s" % (path, output))
+ raise Exception("Initializing local repo at %r failed" % path)
+
+ @staticmethod
+ def is_valid_git_repository(git_repo):
+ if git_repo.cloned:
+ return True
+
+ output, errors = AgentGitHandler.execute_git_command(["show-ref"], git_repo.local_repo_path)
+ if len(output) > 0:
+ refs = output.split("\n")
+ for ref in refs:
+ ref = ref.strip()
+ if len(ref) > 0:
+ ref = ref.split(" ")
+ try:
+ AgentGitHandler.execute_git_command(["show", ref[0].strip()], git_repo.local_repo_path)
+ except RuntimeError:
+ return False
+ return True
+ else:
+ return False
+
+ @staticmethod
+ def pull(git_repo):
+ # git reset to make sure no uncommitted changes are present before the pull, no conflicts will occur
+ AgentGitHandler.execute_git_command(["reset", "--hard"], git_repo.local_repo_path)
+
+ # HEAD before pull
+ (init_head, init_errors) = AgentGitHandler.execute_git_command(["rev-parse", "HEAD"], git_repo.local_repo_path)
+
+ pull_op = pexpect.spawn("git pull", cwd=git_repo.local_repo_path)
+ # TODO: auth
+ pull_output = pull_op.readlines()
+
+ # HEAD after pull
+ (end_head, end_errors) = AgentGitHandler.execute_git_command(["rev-parse", "HEAD"], git_repo.local_repo_path)
+
+ # check if HEAD was updated
+ if init_head != end_head:
+ AgentGitHandler.log.debug("Artifacts were updated as a result of the pull operation, thread: %r - %r" %
+ (current_thread().getName(), current_thread().ident))
+
+ return True
+ else:
+ # HEAD not updated, check reasons
+ for p in pull_output:
+ if "Already up-to-date." in p:
+ # nothing to update
+ AgentGitHandler.log.debug("Pull operation: Already up-to-date, thread: %r - %r" %
+ (current_thread().getName(), current_thread().ident))
+ return False
+
+ # not updated, something was wrong
+ raise GitRepositorySynchronizationException(
+ "Git pull operation on %r for tenant %r failed" % (git_repo.repo_url, git_repo.tenant_id))
+
+ @staticmethod
+ def clone(git_repo):
+ if os.path.isdir(git_repo.local_repo_path):
+ # delete and recreate local repo path if exists
+ GitUtils.delete_folder_tree(git_repo.local_repo_path)
+
+ clone_op = pexpect.spawn("git clone %s %s" % (git_repo.repo_url, git_repo.local_repo_path))
+ # Accepted repo url formats
+ # "https://host.com/path/to/repo.git"
+ # "https://username@host.org/path/to/repo.git"
+ # "https://username:password@host.org/path/to/repo.git" NOT RECOMMENDED
+ result = clone_op.expect(["Username for .*", "Password for .*", "Checking connectivity... done."])
+ if result == 0:
+ clone_op.sendline(git_repo.repo_username)
+ clone_op.expect("Password for .*")
+ clone_op.sendline(git_repo.repo_password)
+ clone_output = clone_op.readlines()
+ for p in clone_output:
+ if "Checking connectivity... done." in p:
+ git_repo.cloned = True
+ AgentGitHandler.add_repo(git_repo)
+ AgentGitHandler.log.info("Git clone operation for tenant %r successful" % git_repo.tenant_id)
+ clone_op.expect(pexpect.EOF)
+ return git_repo
+
+ if "remote: Repository not found." in p \
+ or "fatal: unable to access " in p \
+ or "Authentication failed for" in p:
+ raise GitRepositorySynchronizationException("Git clone operation failed for tenant %r: %r"
+ % (git_repo.tenant_id, p))
+
+ elif result == 1:
+ clone_op.sendline(git_repo.repo_password)
+ clone_output = clone_op.readlines()
+ for p in clone_output:
+ if "Checking connectivity... done." in p:
+ git_repo.cloned = True
+ AgentGitHandler.add_repo(git_repo)
+ AgentGitHandler.log.info("Git clone operation for tenant %r successful" % git_repo.tenant_id)
+ clone_op.expect(pexpect.EOF)
+ return git_repo
+
+ if "remote: Repository not found." in p \
+ or "fatal: unable to access " in p \
+ or "Authentication failed for" in p:
+ raise GitRepositorySynchronizationException("Git clone operation failed for tenant %r: %r"
+ % (git_repo.tenant_id, p))
+
+ elif result == 2:
+ git_repo.cloned = True
+ AgentGitHandler.add_repo(git_repo)
+ AgentGitHandler.log.info("Git clone operation for tenant %r successful" % git_repo.tenant_id)
+ clone_op.expect(pexpect.EOF)
+ return git_repo
+
+ @staticmethod
+ def add_repo(git_repo):
+ AgentGitHandler.__git_repositories[git_repo.tenant_id] = git_repo
+
+ @staticmethod
+ def get_repo(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 clear_repo(tenant_id):
+ if tenant_id in AgentGitHandler.__git_repositories:
+ del AgentGitHandler.__git_repositories[tenant_id]
+
+ @staticmethod
+ def create_git_repo(repo_info):
+ git_repo = GitRepository()
+ git_repo.tenant_id = repo_info.tenant_id
+ git_repo.local_repo_path = repo_info.repo_path
+ git_repo.repo_url = repo_info.repo_url
+ git_repo.repo_username = repo_info.repo_username
+ git_repo.repo_password = repo_info.repo_password
+ git_repo.is_multitenant = repo_info.is_multitenant
+ git_repo.commit_enabled = repo_info.commit_enabled
+
+ git_repo.cloned = False
+
+ return git_repo
+
+ @staticmethod
+ def push(repo_info):
+ """
+ Commits and pushes new artifacts to the remote repository
+ :param repo_info:
+ :return:
+ """
+
+ git_repo = AgentGitHandler.get_repo(repo_info.tenant_id)
+ if git_repo is None:
+ # not cloned yet
+ raise GitRepositorySynchronizationException("Not a valid repository to push from. Aborting")
+
+ # Get initial HEAD so in case if push fails it can be reverted to this hash
+ # This way, commit and push becomes an single operation. No intermediate state will be left behind.
+ (init_head, init_errors) = AgentGitHandler.execute_git_command(["rev-parse", "HEAD"], git_repo.local_repo_path)
+
+ # check if modified
+ modified, unstaged_files = AgentGitHandler.get_unstaged_files(git_repo.local_repo_path)
+
+ AgentGitHandler.log.debug("[Git] Modified: %r" % str(modified))
+
+ if not modified:
+ AgentGitHandler.log.debug("No changes detected in the local repository for tenant %r" % git_repo.tenant_id)
+ return
+
+ AgentGitHandler.stage_all(git_repo.local_repo_path)
+
+ # commit to local repositpory
+ commit_message = "tenant [%r]'s artifacts committed to local repo at %r" \
+ % (git_repo.tenant_id, git_repo.local_repo_path)
+ # TODO: set configuratble names
+ commit_name = git_repo.tenant_id
+ commit_email = "author@example.org"
+ # git config
+ AgentGitHandler.execute_git_command(["config", "user.email", commit_email], git_repo.local_repo_path)
+ AgentGitHandler.execute_git_command(["config", "user.name", commit_name], git_repo.local_repo_path)
+
+ # commit
+ (output, errors) = AgentGitHandler.execute_git_command(
+ ["commit", "-m", commit_message], git_repo.local_repo_path)
+ if errors.strip() == "":
+ commit_hash = AgentGitHandler.find_between(output, "[master", "]").strip()
+ AgentGitHandler.log.debug("Committed artifacts for tenant : %r : %r " % (git_repo.tenant_id, commit_hash))
+ else:
+ AgentGitHandler.log.exception("Committing artifacts to local repository failed for tenant: %s, Cause: %s"
+ % (git_repo.tenant_id, errors))
+ # revert to initial commit hash
+ AgentGitHandler.execute_git_command(["reset", "--hard", init_head], git_repo.local_repo_path)
+ return
+
+ # push to remote
+ try:
+ push_op = pexpect.spawn('git push origin master', cwd=git_repo.local_repo_path)
+ # push_op.logfile = sys.stdout
+ push_op.expect("Username for .*")
+ push_op.sendline(git_repo.repo_username)
+ push_op.expect("Password for .*")
+ push_op.sendline(git_repo.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()
+ push_op.expect(pexpect.EOF)
+
+ AgentGitHandler.log.debug("Pushed artifacts for tenant : %r" % git_repo.tenant_id)
+ except:
+ AgentGitHandler.log.exception("Pushing artifacts to remote repository failed for tenant %r"
+ % git_repo.tenant_id)
+ # revert to initial commit hash
+ AgentGitHandler.execute_git_command(["reset", "--hard", init_head], git_repo.local_repo_path)
+
+ @staticmethod
+ 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
+
+ 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_task(repo_info, auto_checkout, auto_commit, update_interval):
+ git_repo = AgentGitHandler.get_repo(repo_info.tenant_id)
+
+ if git_repo is None:
+ AgentGitHandler.log.error("Unable to schedule artifact sync task, repositoryContext null for tenant %r"
+ % repo_info.tenant_id)
+ return
+
+ if git_repo.scheduled_update_task is None:
+ artifact_update_task = ArtifactUpdateTask(repo_info, auto_checkout, auto_commit)
+ async_task = ScheduledExecutor(update_interval, artifact_update_task)
+
+ git_repo.scheduled_update_task = async_task
+ async_task.start()
+ AgentGitHandler.log.info("Scheduled Artifact Synchronization Task for path %r" % git_repo.local_repo_path)
+ else:
+ AgentGitHandler.log.info("Artifact Synchronization Task for path %r already scheduled"
+ % git_repo.local_repo_path)
+
+ @staticmethod
+ def remove_repo(tenant_id):
+ git_repo = AgentGitHandler.get_repo(tenant_id)
+
+ # stop artifact update task
+ git_repo.scheduled_update_task.terminate()
+
+ # remove git contents
+ try:
+ GitUtils.delete_folder_tree(git_repo.local_repo_path)
+ except GitRepositorySynchronizationException as e:
+ AgentGitHandler.log.exception("Repository folder not deleted: %r" % e.get_message())
+
+ AgentGitHandler.clear_repo(tenant_id)
+ AgentGitHandler.log.info("git repository deleted for tenant %r" % git_repo.tenant_id)
+
+ 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 str repo_path: Repository path to run the command on
+ :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):
+ """
+ Checks if the auto-checkout 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):
+ if self.auto_checkout:
+ try:
+ self.log.debug("Running checkout job")
+ AgentGitHandler.checkout(self.repo_info)
+ # TODO: run updated scheduler extension
+ except GitRepositorySynchronizationException as e:
+ self.log.exception("Auto checkout task failed: %r" % e.get_message())
+
+ if self.auto_commit:
+ try:
+ self.log.debug("Running commit job")
+ AgentGitHandler.push(self.repo_info)
+ except GitRepositorySynchronizationException as e:
+ self.log.exception("Auto commit failed: %r" % e.get_message())
+
+
+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.tenant_id = None
+ """ :type : int """
+ 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 : ScheduledExecutor """
+
+
+class GitUtils:
+ """
+ Util methods required by the AgentGitHandler
+ """
+ log = LogFactory().get_log(__name__)
+
+ @staticmethod
+ 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)
+ GitUtils.log.info("Successfully created directory [%r]" % path)
+ # return True
+ except OSError as e:
+ raise GitRepositorySynchronizationException("Directory creating failed in [%r]. " % e)
+
+ # return False
+
+ @staticmethod
+ def delete_folder_tree(path):
+ """
+ Completely deletes the provided folder
+ :param str path: Full path of the folder
+ :return: void
+ """
+ try:
+ shutil.rmtree(path)
+ GitUtils.log.debug("Directory [%r] deleted." % path)
+ except OSError:
+ raise GitRepositorySynchronizationException("Deletion of folder path %r failed." % path)
http://git-wip-us.apache.org/repos/asf/stratos/blob/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/repository.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/repository.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/repository.py
new file mode 100644
index 0000000..f2842b6
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/repository.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.
+
+
+class Repository:
+ """
+ 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/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/config/__init__.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/config/__init__.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/config/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/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/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/config/cartridgeagentconfiguration.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/config/cartridgeagentconfiguration.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/config/cartridgeagentconfiguration.py
new file mode 100644
index 0000000..afba9d2
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/config/cartridgeagentconfiguration.py
@@ -0,0 +1,379 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT 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
+ """ :type : ConfigParser.SafeConfigParser """
+
+ self.application_id = None
+ """ :type : str """
+ 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.cluster_instance_id = None
+ """ :type : str """
+ self.member_id = None
+ """ :type : str """
+ self.instance_id = None
+ """ :type : str """
+ self.network_partition_id = None
+ """ :type : str """
+ self.partition_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.dependant_cluster_id = None
+ """ :type : str """
+ self.export_metadata_keys = None
+ """ :type : str """
+ self.import_metadata_keys = None
+ """ :type : str """
+ self.is_primary = False
+ """ :type : bool """
+ self.artifact_update_interval = None
+ """ :type : str """
+
+ 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.application_id = self.read_property(cartridgeagentconstants.APPLICATION_ID)
+ self.service_name = self.read_property(cartridgeagentconstants.SERVICE_NAME)
+ self.cluster_id = self.read_property(cartridgeagentconstants.CLUSTER_ID)
+ self.cluster_instance_id= self.read_property(cartridgeagentconstants.CLUSTER_INSTANCE_ID, False)
+ self.member_id = self.read_property(cartridgeagentconstants.MEMBER_ID, False)
+ self.network_partition_id = self.read_property(cartridgeagentconstants.NETWORK_PARTITION_ID, False)
+ self.partition_id = self.read_property(cartridgeagentconstants.PARTITION_ID, False)
+ self.cartridge_key = self.read_property(cartridgeagentconstants.CARTRIDGE_KEY)
+ self.app_path = self.read_property(cartridgeagentconstants.APPLICATION_PATH, False)
+ self.repo_url = self.read_property(cartridgeagentconstants.REPO_URL, False)
+ self.ports = str(self.read_property(cartridgeagentconstants.PORTS)).split("|")
+ self.dependant_cluster_id = self.read_property(cartridgeagentconstants.DEPENDENCY_CLUSTER_IDS, False)
+ self.export_metadata_keys = self.read_property(cartridgeagentconstants.EXPORT_METADATA_KEYS, False)
+ self.import_metadata_keys = self.read_property(cartridgeagentconstants.IMPORT_METADATA_KEYS, False)
+
+
+ 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.INTERNAL)
+ self.is_internal_repo = True if str(int_repo_str).strip().lower() == "true" 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
+
+ try:
+ self.artifact_update_interval = self.read_property(cartridgeagentconstants.ARTIFACT_UPDATE_INTERVAL)
+ except ParameterNotFoundException:
+ self.artifact_update_interval = "10"
+
+ 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("cluster-instance-id: %r" % self.cluster_instance_id)
+ self.log.debug("member-id: %r" % self.member_id)
+ self.log.debug("network-partition-id: %r" % self.network_partition_id)
+ self.log.debug("partition-id: %r" % self.partition_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)
+ self.log.debug("dependant_cluster_id: %r" % self.dependant_cluster_id)
+ self.log.debug("export_metadata_keys: %r" % self.export_metadata_keys)
+ self.log.debug("import_metadata_keys: %r" % self.import_metadata_keys)
+ self.log.debug("artifact.update.interval: %r" % self.artifact_update_interval)
+
+ 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)
+ return member_id
+ except ParameterNotFoundException:
+ self.log.debug("Member id not found")
+ 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)
+
+ #set calculated values
+ param_file = os.path.abspath(os.path.dirname(__file__)).split("modules")[0] + "payload/launch-params"
+ self.properties.set("agent", cartridgeagentconstants.PARAM_FILE_PATH, param_file)
+
+ extensions_dir = os.path.abspath(os.path.dirname(__file__)).split("modules")[0] + "extensions"
+ self.properties.set("agent", cartridgeagentconstants.EXTENSIONS_DIR, extensions_dir)
+
+ 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):
+ temp_str = self.properties.get("agent", property_key)
+ self.log.debug("Reading property: %s = %s", property_key, temp_str)
+ 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]
+ self.log.debug("Reading payload parameter: %s = %s", property_key, temp_str)
+ 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/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/__init__.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/__init__.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/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/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/agent.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/agent.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/agent.py
new file mode 100644
index 0000000..a4ebfc2
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/agent.py
@@ -0,0 +1,227 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT 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 thrift.gen.Exception.ttypes import ThriftSessionExpiredException
+from ..util.log import *
+from ..exception.thriftreceiverofflineexception import ThriftReceiverOfflineException
+import time
+
+
+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_bundle = self.create_event_bundle(event)
+
+ try:
+ self.__publisher.publish(event_bundle)
+ self.log.debug("Published event to thrift stream [%r]" % self.stream_id)
+ except ThriftSessionExpiredException as ex:
+ self.log.debug("ThriftSession expired. Reconnecting")
+ self.__publisher.connect(self.username, self.password)
+ self.log.debug("connected! stream ID: %r" % self.stream_id)
+
+ self.publish(event)
+ except Exception as ex:
+ raise ThriftReceiverOfflineException(ex)
+
+ 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
+ :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)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/__init__.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/__init__.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/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/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Data/__init__.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Data/__init__.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Data/__init__.py
new file mode 100644
index 0000000..adefd8e
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Data/__init__.py
@@ -0,0 +1 @@
+__all__ = ['ttypes', 'constants']
http://git-wip-us.apache.org/repos/asf/stratos/blob/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Data/constants.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Data/constants.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Data/constants.py
new file mode 100644
index 0000000..36943ba
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/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
+#
+
http://git-wip-us.apache.org/repos/asf/stratos/blob/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Data/ttypes.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Data/ttypes.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Data/ttypes.py
new file mode 100644
index 0000000..d76afca
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/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/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Exception/__init__.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Exception/__init__.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Exception/__init__.py
new file mode 100644
index 0000000..adefd8e
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Exception/__init__.py
@@ -0,0 +1 @@
+__all__ = ['ttypes', 'constants']
http://git-wip-us.apache.org/repos/asf/stratos/blob/b11e4de2/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Exception/constants.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Exception/constants.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/databridge/thrift/gen/Exception/constants.py
new file mode 100644
index 0000000..36943ba
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/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
+#
+