You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2015/12/01 14:58:49 UTC

[4/5] stratos git commit: fixing http://stackoverflow.com/questions/9160227/dir-util-copy-tree-fails-after-shutil-rmtree, improving ScheduledExecutor and using str(tenant_id) in getting cached git repo objects

fixing http://stackoverflow.com/questions/9160227/dir-util-copy-tree-fails-after-shutil-rmtree, improving ScheduledExecutor and using str(tenant_id) in getting cached git repo objects


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

Branch: refs/heads/singup_deletion_cleanup
Commit: 11a35ed1d388a577b997cf30a3c5df745e717206
Parents: bfb50f4
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Tue Dec 1 16:26:41 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Tue Dec 1 16:26:41 2015 +0530

----------------------------------------------------------------------
 .../modules/artifactmgt/git/agentgithandler.py    | 12 ++++++++++++
 .../modules/util/asyncscheduledtask.py            |  5 +++--
 .../modules/util/cartridgeagentutils.py           |  9 ++++++++-
 .../plugins/DefaultArtifactCheckout.py            | 18 +++++++++++-------
 4 files changed, 34 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/11a35ed1/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 9b8658e..224ca31 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
@@ -21,6 +21,7 @@ import tempfile
 import urllib
 import os
 from distutils.dir_util import copy_tree
+import distutils.dir_util
 from threading import current_thread
 
 import constants
@@ -155,6 +156,9 @@ class AgentGitHandler:
                 "Cloning artifacts from URL: %s to temp location: %s" % (git_repo.repo_url, temp_repo_path))
             Repo.clone_from(git_repo.auth_url, temp_repo_path)
 
+            # clear the paths to get rid of the following bug in distutils:
+            # http://stackoverflow.com/questions/9160227/dir-util-copy-tree-fails-after-shutil-rmtree
+            distutils.dir_util._path_created = {}
             # move the cloned dir to application path
             copy_tree(temp_repo_path, git_repo.local_repo_path)
             AgentGitHandler.log.info("Git clone operation for tenant %s successful" % git_repo.tenant_id)
@@ -209,8 +213,16 @@ class AgentGitHandler:
 
     @staticmethod
     def clear_repo(tenant_id):
+        tenant_id = str(tenant_id)
+        AgentGitHandler.log.info ('########################## in clear_repo method...' + tenant_id)
         if tenant_id in AgentGitHandler.__git_repositories:
             del AgentGitHandler.__git_repositories[tenant_id]
+            AgentGitHandler.log.info('########################## cached repo object deleted for tenant ' +
+                  tenant_id)
+        if tenant_id in AgentGitHandler.__git_repositories:
+            AgentGitHandler.log.info('########################## cached repo object still exists for tenant ' + tenant_id)
+        else:
+            AgentGitHandler.log.info('########################## no cached obj found for ' + tenant_id)
 
     @staticmethod
     def create_git_repo(repo_info):

http://git-wip-us.apache.org/repos/asf/stratos/blob/11a35ed1/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/asyncscheduledtask.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/asyncscheduledtask.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/asyncscheduledtask.py
index f727414..5b54598 100644
--- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/asyncscheduledtask.py
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/asyncscheduledtask.py
@@ -61,8 +61,9 @@ class ScheduledExecutor(Thread):
         """
         while not self.terminated:
             time.sleep(self.delay)
-            task_thread = Thread(target=self.task.execute_task)
-            task_thread.start()
+            if not self.terminated:
+                task_thread = Thread(target=self.task.execute_task)
+                task_thread.start()
 
     def terminate(self):
         """

http://git-wip-us.apache.org/repos/asf/stratos/blob/11a35ed1/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/cartridgeagentutils.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/cartridgeagentutils.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/cartridgeagentutils.py
index c212a82..016692d 100644
--- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/cartridgeagentutils.py
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/cartridgeagentutils.py
@@ -122,8 +122,8 @@ def check_ports_active(ip_address, ports):
 
     return True
 
-class Utils (object):
 
+class Utils(object):
     @staticmethod
     def directory_exists(dir):
         """
@@ -176,6 +176,13 @@ class Utils (object):
         except OSError as e:
             log.error('Directory not moved. Error: %s' % e)
 
+    @staticmethod
+    def print_dictionary(dic):
+        for x in dic:
+            print (x)
+            for y in dic[x]:
+                print (y, ':', dic[x][y])
+
 class IncrementalCeilingListIterator(object):
     """
     Iterates through a given list and returns elements. At the end of the list if terminate_at_end is set to false,

http://git-wip-us.apache.org/repos/asf/stratos/blob/11a35ed1/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/plugins/DefaultArtifactCheckout.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/plugins/DefaultArtifactCheckout.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/plugins/DefaultArtifactCheckout.py
index 0a45d91..413090e 100644
--- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/plugins/DefaultArtifactCheckout.py
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/plugins/DefaultArtifactCheckout.py
@@ -83,6 +83,7 @@ class DefaultArtifactCheckout(IArtifactCheckoutPlugin):
                 git_repo.cloned = False
                 self.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.add_repo(git_repo)
                 self.log.debug("Git clone executed: [tenant-id] %s [repo-url] %s",
@@ -94,13 +95,7 @@ class DefaultArtifactCheckout(IArtifactCheckoutPlugin):
             self.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)
 
-            # copy default artifacts (if any) to a a temp location
-            # if directory name is dir, the backup directory name would be dir_backup
-            if self.initial_artifacts_exists(git_repo.local_repo_path):
-                self.log.info("Default artifacts exist at " + git_repo.local_repo_path)
-                self.backup_initial_artifacts(git_repo.local_repo_path)
-            else:
-                self.log.info("No default artifacts exist at " + git_repo.local_repo_path)
+            self.check_and_backup_initial_artifacts(git_repo.local_repo_path)
 
             try:
                 git_repo = AgentGitHandler.clone(git_repo)
@@ -114,6 +109,15 @@ class DefaultArtifactCheckout(IArtifactCheckoutPlugin):
                 AgentGitHandler.retry_clone(git_repo)
                 AgentGitHandler.add_repo(git_repo)
 
+    def check_and_backup_initial_artifacts(self, initial_artifact_dir):
+        # copy default artifacts (if any) to a a temp location
+        # if directory name is dir, the backup directory name would be dir_backup
+        if self.initial_artifacts_exists(initial_artifact_dir):
+            self.log.info("Default artifacts exist at " + initial_artifact_dir)
+            self.backup_initial_artifacts(initial_artifact_dir)
+        else:
+            self.log.info("No default artifacts exist at " + initial_artifact_dir)
+
     def initial_artifacts_exists(self, dir):
         try:
             return os.path.exists(dir) and os.listdir(dir)