Repository: stratos Updated Branches: refs/heads/master eac0d3036 -> 569394863
Adding Git clone retries for CA git handler Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/56939486 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/56939486 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/56939486 Branch: refs/heads/master Commit: 56939486350a00fdd2360ca1f2a113cc09a25e65 Parents: eac0d30 Author: lasinducharith <[email protected]> Authored: Sun Aug 2 10:43:02 2015 +0530 Committer: lasinducharith <[email protected]> Committed: Sun Aug 2 10:43:02 2015 +0530 ---------------------------------------------------------------------- .../cartridge.agent/cartridge.agent/agent.conf | 2 + .../cartridge.agent/constants.py | 2 + .../modules/artifactmgt/git/agentgithandler.py | 48 ++++++++++++++++++-- .../src/test/resources/agent.conf | 2 + .../python_agent/templates/agent.conf.erb | 2 + 5 files changed, 53 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/56939486/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/agent.conf ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/agent.conf b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/agent.conf index ec38d80..22d1deb 100644 --- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/agent.conf +++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/agent.conf @@ -30,6 +30,8 @@ enable.artifact.update =ENABLE_ARTFCT_UPDATE auto.commit =COMMIT_ENABLED auto.checkout =CHECKOUT_ENABLED artifact.update.interval =ARTFCT_UPDATE_INT +artifact.clone.retries =ARTFCT_CLONE_RETRIES +artifact.clone.interval =ARTFCT_CLONE_INT port.check.timeout =PORT_CHECK_TIMEOUT enable.data.publisher =ENABLE-DATA-PUBLISHER monitoring.server.ip =MONITORING-SERVER-IP http://git-wip-us.apache.org/repos/asf/stratos/blob/56939486/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/constants.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/constants.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/constants.py index 44e6700..5510659 100644 --- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/constants.py +++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/constants.py @@ -55,6 +55,8 @@ CLUSTERING = "CLUSTERING" MIN_INSTANCE_COUNT = "MIN_COUNT" ENABLE_ARTIFACT_UPDATE = "enable.artifact.update" ARTIFACT_UPDATE_INTERVAL = "artifact.update.interval" +ARTIFACT_CLONE_RETRIES = "artifact.clone.retries" +ARTIFACT_CLONE_INTERVAL = "artifact.clone.interval" COMMIT_ENABLED = "COMMIT_ENABLED" AUTO_COMMIT = "auto.commit" AUTO_CHECKOUT = "auto.checkout" http://git-wip-us.apache.org/repos/asf/stratos/blob/56939486/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 c00e07e..ea72266 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 @@ -19,8 +19,11 @@ from threading import current_thread import os import subprocess import shutil +import constants +import time from git import * +from config import Config from ... util.log import LogFactory from ... util.asyncscheduledtask import AbstractAsyncScheduledTask, ScheduledExecutor from ... artifactmgt.repository import Repository @@ -86,9 +89,14 @@ class AgentGitHandler: 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) - 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) + try: + 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) + except GitRepositorySynchronizationException as e: + AgentGitHandler.log.warn("Warning: Git clone operation failed. Retrying...") + # If first git clone is failed, execute retry_clone operation + AgentGitHandler.retry_clone(git_repo) return subscribe_run, updated @@ -197,6 +205,40 @@ class AgentGitHandler: raise GitRepositorySynchronizationException("Error while cloning repository: %s" % e) @staticmethod + def retry_clone(git_repo): + """Retry 'git clone' operation for defined number of attempts with defined intervals + """ + if os.path.isdir(git_repo.local_repo_path) and os.listdir(git_repo.local_repo_path) != []: + # delete and recreate local repo path if not empty dir + AgentGitHandler.log.debug("Local repository path not empty. Cleaning.") + GitUtils.delete_folder_tree(git_repo.local_repo_path) + GitUtils.create_dir(git_repo.local_repo_path) + + git_clone_successful = False + # Read properties from agent.conf + max_retry_attempts = int(Config.read_property(constants.ARTIFACT_CLONE_RETRIES, 5)) + retry_interval = int(Config.read_property(constants.ARTIFACT_CLONE_INTERVAL, 10)) + retry_attempts = 0 + + # Iterate until git clone is successful or reaches max retry attempts + while git_clone_successful is False and retry_attempts < max_retry_attempts: + try: + retry_attempts += 1 + Repo.clone_from(git_repo.repo_url, git_repo.local_repo_path) + AgentGitHandler.add_repo(git_repo) + 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" % retry_attempts) + if retry_attempts < max_retry_attempts: + time.sleep(retry_interval) + pass + else: + raise GitRepositorySynchronizationException("Error while retrying git clone: %s" % e) + + @staticmethod def add_repo(git_repo): AgentGitHandler.__git_repositories[git_repo.tenant_id] = git_repo http://git-wip-us.apache.org/repos/asf/stratos/blob/56939486/components/org.apache.stratos.python.cartridge.agent/src/test/resources/agent.conf ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/src/test/resources/agent.conf b/components/org.apache.stratos.python.cartridge.agent/src/test/resources/agent.conf index 8beaf7c..86603a0 100644 --- a/components/org.apache.stratos.python.cartridge.agent/src/test/resources/agent.conf +++ b/components/org.apache.stratos.python.cartridge.agent/src/test/resources/agent.conf @@ -30,6 +30,8 @@ enable.artifact.update =true auto.commit =false auto.checkout =true artifact.update.interval =15 +artifact.clone.retries =5 +artifact.clone.interval =10 port.check.timeout =600000 enable.data.publisher =false monitoring.server.ip =localhost http://git-wip-us.apache.org/repos/asf/stratos/blob/56939486/tools/puppet3/modules/python_agent/templates/agent.conf.erb ---------------------------------------------------------------------- diff --git a/tools/puppet3/modules/python_agent/templates/agent.conf.erb b/tools/puppet3/modules/python_agent/templates/agent.conf.erb index 55f420e..a088e3f 100644 --- a/tools/puppet3/modules/python_agent/templates/agent.conf.erb +++ b/tools/puppet3/modules/python_agent/templates/agent.conf.erb @@ -30,6 +30,8 @@ enable.artifact.update =true auto.commit =false auto.checkout =true artifact.update.interval =15 +artifact.clone.retries =5 +artifact.clone.interval =10 port.check.timeout =600000 enable.data.publisher =<%= @enable_log_publisher %> monitoring.server.ip =<%= @bam_ip %>
