Repository: stratos Updated Branches: refs/heads/stratos-4.1.x c59529a89 -> 2c8de71a3
Further improvements for STRATOS-1582: Update git credentials in PCA Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/2c8de71a Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/2c8de71a Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/2c8de71a Branch: refs/heads/stratos-4.1.x Commit: 2c8de71a397115cf07b94bb16022ed9d4d47bea3 Parents: c59529a Author: Akila Perera <[email protected]> Authored: Sat Oct 10 00:47:57 2015 +0530 Committer: Akila Perera <[email protected]> Committed: Sat Oct 10 00:48:33 2015 +0530 ---------------------------------------------------------------------- .../modules/artifactmgt/git/agentgithandler.py | 172 ++++++++++-------- .../modules/event/eventhandler.py | 180 ++++++++++--------- .../python/cartridge.agent/tests/test_git.py | 2 +- .../service-images/php/Dockerfile | 2 +- 4 files changed, 195 insertions(+), 161 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/2c8de71a/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 index 257575f..208d6fe 100644 --- 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 @@ -38,13 +38,16 @@ class AgentGitHandler: Handles all the git artifact management tasks related to a cartridge """ + def __init__(self): + pass + log = LogFactory().get_log(__name__) __git_repositories = {} # (tenant_id => GitRepository) @staticmethod - def checkout(repo_info): + def run_checkout_job(repo_info): """ Checks out the code from the remote repository. If local repository path is empty, a clone operation is done. @@ -60,11 +63,8 @@ class AgentGitHandler: :rtype: tuple(bool, bool) """ git_repo = AgentGitHandler.create_git_repo(repo_info) - updated = False if AgentGitHandler.get_repo(repo_info.tenant_id) 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) @@ -73,7 +73,7 @@ class AgentGitHandler: 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.error("Git pull operation failed: %s" % e) + AgentGitHandler.log.exception("Git pull operation failed: %s" % e) else: # not a valid repository, might've been corrupted. do a re-clone @@ -87,22 +87,21 @@ class AgentGitHandler: git_repo.tenant_id, git_repo.repo_url) else: # subscribing run.. need to clone - AgentGitHandler.log.debug("Cloning artifacts from %s for the first time to %s", - git_repo.repo_url, git_repo.local_repo_path) - subscribe_run = True - AgentGitHandler.log.debug("Executing git clone: [tenant-id] %s [repo-url] %s, [repo path] %s", - git_repo.tenant_id, git_repo.repo_url, git_repo.local_repo_path) + AgentGitHandler.log.info("Cloning artifacts from %s for the first time to %s", + git_repo.repo_url, git_repo.local_repo_path) + AgentGitHandler.log.info("Executing git clone: [tenant-id] %s [repo-url] %s, [repo path] %s", + git_repo.tenant_id, git_repo.repo_url, git_repo.local_repo_path) try: git_repo = AgentGitHandler.clone(git_repo) + AgentGitHandler.add_repo(git_repo) AgentGitHandler.log.debug("Git clone executed: [tenant-id] %s [repo-url] %s", git_repo.tenant_id, git_repo.repo_url) except GitRepositorySynchronizationException as e: - AgentGitHandler.log.error("Git clone operation failed: %s" % e) + AgentGitHandler.log.exception("Git clone operation failed: %s" % e) # If first git clone is failed, execute retry_clone operation AgentGitHandler.log.info("Retrying git clone operation...") AgentGitHandler.retry_clone(git_repo) - AgentGitHandler.add_repo(git_repo) - return subscribe_run, updated + AgentGitHandler.add_repo(git_repo) @staticmethod def sync_initial_local_artifacts(git_repo): @@ -162,28 +161,28 @@ class AgentGitHandler: @staticmethod def pull(git_repo): - # git reset to make sure no uncommitted changes are present before the pull, no conflicts will occur - (output, errors) = AgentGitHandler.execute_git_command(["status"], git_repo.local_repo_path) - # check if modified files are present modified = AgentGitHandler.has_modified_files(git_repo.local_repo_path) if modified: - AgentGitHandler.log.info("Unstaged files exist in working directory. Aborting git pull...") - return + if Config.is_commits_enabled: + AgentGitHandler.log.debug( + "Un-staged files exist in working directory. Aborting git pull for this iteration...") + return + else: + AgentGitHandler.log.warn("Changes detected in working directory but COMMIT_ENABLED is set to false!") + AgentGitHandler.log.warn("Attempting to reset the working directory") + AgentGitHandler.execute_git_command(["reset"], repo_path=git_repo.local_repo_path) # HEAD before pull (init_head, init_errors) = AgentGitHandler.execute_git_command(["rev-parse", "HEAD"], git_repo.local_repo_path) - try: - repo = Repo(git_repo.local_repo_path) - (output, errors) = AgentGitHandler.execute_git_command(["pull", "--rebase", "origin", "master"], - git_repo.local_repo_path) - AgentGitHandler.log.info("Git pull rebase executed in checkout job") - if repo.is_dirty(): - raise GitRepositorySynchronizationException("Git pull operation left the repository in dirty state") - except (GitCommandError, GitRepositorySynchronizationException) as e: - raise GitRepositorySynchronizationException("Git pull operation on %s for tenant %s failed: %s" % - (git_repo.repo_url, git_repo.tenant_id, e)) + repo = Repo(git_repo.local_repo_path) + AgentGitHandler.execute_git_command(["pull", "--rebase", "origin", "master"], git_repo.local_repo_path) + AgentGitHandler.log.debug("Git pull rebase executed in checkout job") + if repo.is_dirty(): + AgentGitHandler.log.error("Git pull operation in checkout job left the repository in dirty state") + AgentGitHandler.log.error( + "Git pull operation on remote %s for tenant %s failed" % (git_repo.repo_url, git_repo.tenant_id)) # HEAD after pull (end_head, end_errors) = AgentGitHandler.execute_git_command(["rev-parse", "HEAD"], git_repo.local_repo_path) @@ -234,8 +233,8 @@ class AgentGitHandler: AgentGitHandler.log.info( "Retrying attempt to git clone operation for tenant %s successful" % git_repo.tenant_id) git_clone_successful = True - except GitCommandError as e: - AgentGitHandler.log.warn("Retrying git clone attempt %s failed: %s" % (retry_attempts, e)) + except GitRepositorySynchronizationException as e: + AgentGitHandler.log.exception("Retrying git clone attempt %s failed: %s" % (retry_attempts, e)) if retry_attempts < max_retry_attempts: time.sleep(retry_interval) else: @@ -312,7 +311,7 @@ class AgentGitHandler: return repo_info.repo_url @staticmethod - def push(repo_info): + def run_commit_job(repo_info): """ Commits and pushes new artifacts to the remote repository :param repo_info: @@ -328,13 +327,16 @@ class AgentGitHandler: # 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) + # remove trailing new line character, if any + init_head = init_head.rstrip() + # stage all untracked files if AgentGitHandler.stage_all(git_repo.local_repo_path): - AgentGitHandler.log.info("Git staged untracked artifacts successfully") + AgentGitHandler.log.debug("Git staged untracked artifacts successfully") else: - AgentGitHandler.log.info("Git could not stage untracked artifacts") + AgentGitHandler.log.error("Git could not stage untracked artifacts") - # check if modified files are present + # check for changes in working directory modified = AgentGitHandler.has_modified_files(git_repo.local_repo_path) AgentGitHandler.log.debug("[Git] Modified: %s" % str(modified)) @@ -342,7 +344,7 @@ class AgentGitHandler: AgentGitHandler.log.debug("No changes detected in the local repository for tenant %s" % git_repo.tenant_id) return - # commit to local repositpory + # commit to local repository commit_message = "tenant [%s]'s artifacts committed to local repo at %s" \ % (git_repo.tenant_id, git_repo.local_repo_path) # TODO: set configuratble names, check if already configured @@ -353,46 +355,57 @@ class AgentGitHandler: 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) + (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 : %s : %s " % (git_repo.tenant_id, commit_hash)) + AgentGitHandler.log.debug("Committed artifacts for tenant: %s : %s " % (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)) + AgentGitHandler.log.error("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: - repo = Repo(git_repo.local_repo_path) - - # pull and rebase before pushing to remote repo - (output, errors) = AgentGitHandler.execute_git_command(["pull", "--rebase", "origin", "master"], - git_repo.local_repo_path) - AgentGitHandler.log.info("Git pull rebase executed before pushing to remote") - - push_info = repo.remotes.origin.push() - if str(push_info[0].summary) is "[rejected] (fetch first)": - # need to pull - repo.remotes.origin.pull() - if repo.is_dirty(): - # auto merge failed, need to reset - # TODO: what to do here? - raise GitRepositorySynchronizationException( - "Git pull before push operation left repository in dirty state.") - - # pull successful, now push - repo.remotes.origin.push() - AgentGitHandler.log.debug("Pushed artifacts for tenant : %s" % git_repo.tenant_id) - except (GitCommandError, GitRepositorySynchronizationException) as e: - # revert to initial commit hash - AgentGitHandler.execute_git_command(["reset", "--hard", init_head], git_repo.local_repo_path) + repo = Repo(git_repo.local_repo_path) + # pull and rebase before pushing to remote repo + AgentGitHandler.execute_git_command(["pull", "--rebase", "origin", "master"], git_repo.local_repo_path) + if repo.is_dirty(): + AgentGitHandler.log.error("Git pull operation in commit job left the repository in dirty state") + AgentGitHandler.log.error( + "Git pull rebase operation on remote %s for tenant %s failed" % (git_repo.repo_url, git_repo.tenant_id)) - raise GitRepositorySynchronizationException( - "Pushing artifacts to remote repository failed for tenant %s: %s" % (git_repo.tenant_id, e)) + AgentGitHandler.log.warn("The working directory will be reset to the last known good commit") + # revert to the initial commit + AgentGitHandler.execute_git_command(["reset", "--hard", init_head], git_repo.local_repo_path) + return + else: + # push to remote + try: + push_info_list = repo.remotes.origin.push() + if (len(push_info_list)) == 0: + AgentGitHandler.log.error("Failed to push artifacts to remote repo for tenant: %s remote: %s" % + (git_repo.tenant_id, git_repo.repo_url)) + # revert to the initial commit + AgentGitHandler.execute_git_command(["reset", "--hard", init_head], git_repo.local_repo_path) + return + + for push_info in push_info_list: + AgentGitHandler.log.debug("Push info summary: %s" % push_info.summary) + if push_info.flags & PushInfo.ERROR == PushInfo.ERROR: + AgentGitHandler.log.error("Failed to push artifacts to remote repo for tenant: %s remote: %s" % + (git_repo.tenant_id, git_repo.repo_url)) + # revert to the initial commit + AgentGitHandler.execute_git_command(["reset", "--hard", init_head], git_repo.local_repo_path) + return + AgentGitHandler.log.debug( + "Successfully pushed artifacts for tenant: %s remote: %s" % (git_repo.tenant_id, git_repo.repo_url)) + except Exception as e: + AgentGitHandler.log.error( + "Failed to push artifacts to remote repo for tenant: %s remote: %s exception: %s" % + (git_repo.tenant_id, git_repo.repo_url, e)) + # revert to the initial commit + AgentGitHandler.execute_git_command(["reset", "--hard", init_head], git_repo.local_repo_path) @staticmethod def has_modified_files(repo_path): @@ -433,8 +446,8 @@ class AgentGitHandler: async_task.start() AgentGitHandler.log.info("Scheduled artifact synchronization task for path %s" % git_repo.local_repo_path) else: - AgentGitHandler.log.info("Artifact synchronization task for path %s already scheduled" - % git_repo.local_repo_path) + AgentGitHandler.log.debug("Artifact synchronization task for path %s already scheduled" + % git_repo.local_repo_path) @staticmethod def remove_repo(tenant_id): @@ -447,7 +460,8 @@ class AgentGitHandler: try: GitUtils.delete_folder_tree(git_repo.local_repo_path) except GitRepositorySynchronizationException as e: - AgentGitHandler.log.exception("Repository folder not deleted: %s" % e) + AgentGitHandler.log.exception( + "Could not remove repository folder for tenant:%s %s" % (git_repo.tenant_id, e)) AgentGitHandler.clear_repo(tenant_id) AgentGitHandler.log.info("Git repository deleted for tenant %s" % git_repo.tenant_id) @@ -466,7 +480,7 @@ class AgentGitHandler: """ os_env = os.environ.copy() command.insert(0, "/usr/bin/git") - AgentGitHandler.log.info("Executing Git command: %s" % command) + AgentGitHandler.log.debug("Executing Git command: %s" % command) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os_env, cwd=repo_path) (output, errors) = p.communicate() AgentGitHandler.log.debug("Git command [output] %s" % str(output)) @@ -489,20 +503,24 @@ class ArtifactUpdateTask(AbstractAsyncScheduledTask): def execute_task(self): self.invocation_count += 1 + # DO NOT change this order. The commit job should run first here. + # This is because if the cloned location contain any un-tracked files then + # those files should be committed and pushed first if self.auto_commit: try: self.log.debug("Running commit job # %s" % self.invocation_count) - AgentGitHandler.push(self.repo_info) + AgentGitHandler.run_commit_job(self.repo_info) except GitRepositorySynchronizationException as e: self.log.exception("Auto commit failed: %s" % e) if self.auto_checkout: try: self.log.debug("Running checkout job # %s" % self.invocation_count) - AgentGitHandler.checkout(self.repo_info) - # TODO: run updated scheduler extension + AgentGitHandler.run_checkout_job(self.repo_info) + # TODO: move this to updated scheduler extension except GitRepositorySynchronizationException as e: self.log.exception("Auto checkout task failed: %s" % e) + self.log.debug("ArtifactUpdateTask completed # %s" % self.invocation_count) @@ -535,6 +553,10 @@ class GitUtils: """ Util methods required by the AgentGitHandler """ + + def __init__(self): + pass + log = LogFactory().get_log(__name__) @staticmethod @@ -547,7 +569,7 @@ class GitUtils: """ try: os.mkdir(path) - GitUtils.log.info("Successfully created directory [%s]" % path) + GitUtils.log.debug("Successfully created directory [%s]" % path) # return True except OSError as e: raise GitRepositorySynchronizationException("Directory creating failed in [%s]. " % e) http://git-wip-us.apache.org/repos/asf/stratos/blob/2c8de71a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/event/eventhandler.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/event/eventhandler.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/event/eventhandler.py index ca21a20..259d30d 100644 --- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/event/eventhandler.py +++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/event/eventhandler.py @@ -60,88 +60,99 @@ class EventHandler: def on_artifact_updated_event(self, artifacts_updated_event): self.__log.debug("Processing Artifact update event: [tenant] %s [cluster] %s [status] %s" % - (str(artifacts_updated_event.tenant_id), - artifacts_updated_event.cluster_id, - artifacts_updated_event.status)) + (str(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 = 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 = Config.app_path - - repo_password = None - if artifacts_updated_event.repo_password is not None: - secret = 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 = Config.is_multiTenant - commit_enabled = artifacts_updated_event.commit_enabled - - self.__log.info("Executing git checkout") + if (repo_url == "") or (cluster_id_payload is None) or (cluster_id_payload != cluster_id_event): + return - if local_repo_path is None: - raise GitRepositorySynchronizationException("Repository path is empty. Cannot perform Git operations.") + repo_password = None + if artifacts_updated_event.repo_password is not None: + secret = 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 = Config.is_multiTenant + commit_enabled = artifacts_updated_event.commit_enabled + + if Config.app_path is None: + raise GitRepositorySynchronizationException("Repository path is empty. Cannot perform Git operations.") + + # create repo object + local_repo_path = self.get_repo_path_for_tenant(str(tenant_id), Config.app_path, is_multitenant) + repo_info = Repository(repo_url, repo_username, repo_password, local_repo_path, tenant_id, commit_enabled) + new_git_repo = AgentGitHandler.create_git_repo(repo_info) + + # check whether this is the first artifact updated event for this tenant + existing_git_repo = AgentGitHandler.get_repo(repo_info.tenant_id) + if existing_git_repo is not None: + # check whether this event has updated credentials for git repo + if AgentGitHandler.is_valid_git_repository( + new_git_repo) and new_git_repo.repo_url != existing_git_repo.repo_url: + # add the new git_repo object with updated credentials to repo list + AgentGitHandler.add_repo(new_git_repo) + + # update the origin remote URL with new credentials + self.__log.info("Changes detected in git credentials for tenant: %s" % new_git_repo.tenant_id) + self.__log.debug("Updating git repo remote URL for tenant: %s with new remote URL: %s" % ( + new_git_repo.tenant_id, new_git_repo.repo_url)) + (output, errors) = AgentGitHandler.execute_git_command( + ["remote", "set-url", "origin", new_git_repo.repo_url], new_git_repo.local_repo_path) + if errors.strip() != "": + self.__log.error("Failed to update git repo remote URL for tenant: %s" % new_git_repo.tenant_id) + + self.__log.info("Executing checkout job on artifact updated event...") + try: + AgentGitHandler.run_checkout_job(repo_info) + except GitRepositorySynchronizationException as e: + self.__log.exception( + "Checkout job on artifact updated event failed for tenant: %s %s" % (repo_info.tenant_id, e)) + + # execute artifact updated extension + plugin_values = {"ARTIFACT_UPDATED_CLUSTER_ID": artifacts_updated_event.cluster_id, + "ARTIFACT_UPDATED_TENANT_ID": artifacts_updated_event.tenant_id, + "ARTIFACT_UPDATED_REPO_URL": artifacts_updated_event.repo_url, + "ARTIFACT_UPDATED_REPO_PASSWORD": artifacts_updated_event.repo_password, + "ARTIFACT_UPDATED_REPO_USERNAME": artifacts_updated_event.repo_username, + "ARTIFACT_UPDATED_STATUS": artifacts_updated_event.status} - # create repo object - local_repo_path = self.get_repo_path_for_tenant(str(tenant_id), local_repo_path, is_multitenant) - repo_info = Repository(repo_url, repo_username, repo_password, local_repo_path, tenant_id, commit_enabled) + try: + self.execute_event_extendables(constants.ARTIFACT_UPDATED_EVENT, plugin_values) + except ValueError: + self.__log.exception("Could not execute plugins for artifact updated event: %s" % ValueError) + + if existing_git_repo is None: + # publish instance activated event for single tenant subscription + publisher.publish_instance_activated_event(Config.health_stat_plugin) + + update_artifacts = Config.read_property(constants.ENABLE_ARTIFACT_UPDATE, True) + auto_commit = Config.is_commits_enabled + auto_checkout = Config.is_checkout_enabled + self.__log.info("ADC configuration: [update_artifacts] %s, [auto-commit] %s, [auto-checkout] %s", + update_artifacts, auto_commit, auto_checkout) + if update_artifacts: + try: + update_interval = int(Config.artifact_update_interval) + except ValueError: + self.__log.exception("Invalid artifact sync interval specified: %s" % ValueError) + update_interval = 10 - # checkout code - subscribe_run, updated = AgentGitHandler.checkout(repo_info) + self.__log.info("Artifact updating task enabled, update interval: %s seconds" % update_interval) - # execute artifact updated extension - plugin_values = {"ARTIFACT_UPDATED_CLUSTER_ID": artifacts_updated_event.cluster_id, - "ARTIFACT_UPDATED_TENANT_ID": artifacts_updated_event.tenant_id, - "ARTIFACT_UPDATED_REPO_URL": artifacts_updated_event.repo_url, - "ARTIFACT_UPDATED_REPO_PASSWORD": artifacts_updated_event.repo_password, - "ARTIFACT_UPDATED_REPO_USERNAME": artifacts_updated_event.repo_username, - "ARTIFACT_UPDATED_STATUS": artifacts_updated_event.status} + self.__log.info("Auto Commit is turned %s " % ("on" if auto_commit else "off")) + self.__log.info("Auto Checkout is turned %s " % ("on" if auto_checkout else "off")) - try: - self.execute_event_extendables(constants.ARTIFACT_UPDATED_EVENT, plugin_values) - except ValueError: - self.__log.exception("Could not execute plugins for artifact updated event: %s" % ValueError) - - if subscribe_run: - # publish instanceActivated - publisher.publish_instance_activated_event(Config.health_stat_plugin) - elif updated: - # updated on pull - self.on_artifact_update_scheduler_event(tenant_id) - - update_artifacts = Config.read_property(constants.ENABLE_ARTIFACT_UPDATE, False) - auto_commit = Config.is_commits_enabled - auto_checkout = Config.is_checkout_enabled - self.__log.info("ADC configuration: [update_artifacts] %s, [auto-commit] %s, [auto-checkout] %s", - update_artifacts, auto_commit, auto_checkout) - if update_artifacts: - try: - update_interval = int(Config.artifact_update_interval) - except ValueError: - self.__log.exception("Invalid artifact sync interval specified: %s" % ValueError) - update_interval = 10 - - self.__log.info("Artifact updating task enabled, update interval: %s seconds" % update_interval) - - self.__log.info("Auto Commit is turned %s " % ("on" if auto_commit else "off")) - self.__log.info("Auto Checkout is turned %s " % ("on" if auto_checkout else "off")) - - AgentGitHandler.schedule_artifact_update_task( - repo_info, - auto_checkout, - auto_commit, - update_interval) - - def on_artifact_update_scheduler_event(self, tenant_id): - self.__log.debug("Processing Artifact update scheduler event...") - plugin_values = {"ARTIFACT_UPDATED_TENANT_ID": str(tenant_id), - "ARTIFACT_UPDATED_SCHEDULER": str(True)} - - self.execute_event_extendables("ArtifactUpdateSchedulerEvent", plugin_values) + AgentGitHandler.schedule_artifact_update_task( + repo_info, + auto_checkout, + auto_commit, + update_interval) def on_instance_cleanup_cluster_event(self): self.__log.debug("Processing instance cleanup cluster event...") @@ -153,9 +164,9 @@ class EventHandler: def on_member_activated_event(self, member_activated_event): self.__log.debug("Processing Member activated event: [service] %r [cluster] %r [member] %r" - % (member_activated_event.service_name, - member_activated_event.cluster_id, - member_activated_event.member_id)) + % (member_activated_event.service_name, + member_activated_event.cluster_id, + member_activated_event.member_id)) member_initialized = self.is_member_initialized_in_topology( member_activated_event.service_name, @@ -218,7 +229,7 @@ class EventHandler: self.__log.debug("Member exists: %s" % member_exists) if member_exists: Config.initialized = True - self.markMemberAsInitialized(service_name_in_payload, cluster_id_in_payload, member_id_in_payload) + self.mark_member_as_initialized(service_name_in_payload, cluster_id_in_payload, member_id_in_payload) self.__log.info("Instance marked as initialized on member initialized event") else: raise Exception("Member [member-id] %s not found in topology while processing member initialized " @@ -238,8 +249,8 @@ class EventHandler: def on_member_terminated_event(self, member_terminated_event): self.__log.debug("Processing Member terminated event: [service] %s [cluster] %s [member] %s" % - (member_terminated_event.service_name, member_terminated_event.cluster_id, - member_terminated_event.member_id)) + (member_terminated_event.service_name, member_terminated_event.cluster_id, + member_terminated_event.member_id)) member_initialized = self.is_member_initialized_in_topology( member_terminated_event.service_name, @@ -255,8 +266,8 @@ class EventHandler: def on_member_suspended_event(self, member_suspended_event): self.__log.debug("Processing Member suspended event: [service] %s [cluster] %s [member] %s" % - (member_suspended_event.service_name, member_suspended_event.cluster_id, - member_suspended_event.member_id)) + (member_suspended_event.service_name, member_suspended_event.cluster_id, + member_suspended_event.member_id)) member_initialized = self.is_member_initialized_in_topology( member_suspended_event.service_name, @@ -272,8 +283,8 @@ class EventHandler: def on_member_started_event(self, member_started_event): self.__log.debug("Processing Member started event: [service] %s [cluster] %s [member] %s" % - (member_started_event.service_name, member_started_event.cluster_id, - member_started_event.member_id)) + (member_started_event.service_name, member_started_event.cluster_id, + member_started_event.member_id)) member_initialized = self.is_member_initialized_in_topology( member_started_event.service_name, @@ -365,7 +376,7 @@ class EventHandler: self.execute_event_extendables(constants.APPLICATION_SIGNUP_REMOVAL_EVENT, {}) def cleanup(self, event): - self.__log.debug("Executing cleaning up the data in the cartridge instance...") + self.__log.debug("Executing cleanup extension for event %s" % event) publisher.publish_maintenance_mode_event() @@ -522,7 +533,8 @@ class EventHandler: return True - def markMemberAsInitialized(self, service_name, cluster_id, member_id): + @staticmethod + def mark_member_as_initialized(service_name, cluster_id, member_id): topology = TopologyContext.get_topology() service = topology.get_service(service_name) if service is None: http://git-wip-us.apache.org/repos/asf/stratos/blob/2c8de71a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/tests/test_git.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/tests/test_git.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/tests/test_git.py index f201285..c1074aa 100644 --- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/tests/test_git.py +++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/tests/test_git.py @@ -33,7 +33,7 @@ def test_clone(input, expected): repo_string = f.read() repo_info = json.loads(repo_string, object_hook=repo_object_decoder) - sub_run, repo_context = AgentGitHandler.checkout(repo_info) + sub_run, repo_context = AgentGitHandler.run_checkout_job(repo_info) assert sub_run, "Not detected as subscription run" http://git-wip-us.apache.org/repos/asf/stratos/blob/2c8de71a/tools/docker-images/cartridge-docker-images/service-images/php/Dockerfile ---------------------------------------------------------------------- diff --git a/tools/docker-images/cartridge-docker-images/service-images/php/Dockerfile b/tools/docker-images/cartridge-docker-images/service-images/php/Dockerfile index 4ab0c8c..c14832d 100644 --- a/tools/docker-images/cartridge-docker-images/service-images/php/Dockerfile +++ b/tools/docker-images/cartridge-docker-images/service-images/php/Dockerfile @@ -25,7 +25,7 @@ MAINTAINER [email protected] # ---------------- # Install PHP # ---------------- -RUN apt-get update && apt-get install -y apache2 php5 zip stress +RUN apt-get update && apt-get install -y apache2 php5 zip stress vim RUN rm -f /etc/apache2/sites-enabled/000-default.conf ADD files/000-default.conf /etc/apache2/sites-enabled/000-default.conf
