Repository: stratos
Updated Branches:
  refs/heads/singup_deletion_cleanup [created] 7fc829e1a


initial changes for signup deletion


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

Branch: refs/heads/singup_deletion_cleanup
Commit: 2951b419ad2a3ce0b143d20f01efee5a0b47860a
Parents: 4e868f2
Author: Isuru Haththotuwa <[email protected]>
Authored: Fri Nov 27 10:13:24 2015 +0530
Committer: Isuru Haththotuwa <[email protected]>
Committed: Fri Nov 27 10:13:24 2015 +0530

----------------------------------------------------------------------
 .../modules/artifactmgt/git/agentgithandler.py  | 19 +++++++++++++++++
 .../plugins/DefaultArtifactCheckout.py          | 22 ++++++++++++++++++++
 2 files changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/2951b419/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 c283011..2cb4c38 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
@@ -28,6 +28,7 @@ import time
 from config import Config
 from exception import GitRepositorySynchronizationException
 from git import *
+import errno
 
 from ...util.asyncscheduledtask import AbstractAsyncScheduledTask, 
ScheduledExecutor
 from ...util.log import LogFactory
@@ -313,12 +314,30 @@ class AgentGitHandler:
             AgentGitHandler.log.exception(
                 "Could not remove repository folder for tenant:%s  %s" % 
(git_repo.tenant_id, e))
 
+        # restore default artifacts
+        AgentGitHandler.restore_default_artifacts("/tmp/default_artifacts", 
git_repo.local_repo_path)
+
         AgentGitHandler.clear_repo(tenant_id)
         AgentGitHandler.log.info("Git repository deleted for tenant %s" % 
git_repo.tenant_id)
 
         return True
 
     @staticmethod
+    def restore_default_artifacts (default_artifact_backup_location, 
local_repo_path):
+        try:
+            if os.path.isdir(default_artifact_backup_location):
+                # first remove all the artifacts in the local_repo_path
+                if os.listdir(local_repo_path):
+                    # non-empty
+                    filelist = [f for f in os.listdir(local_repo_path)]
+                    for f in filelist:
+                        GitUtils.delete_folder_tree(local_repo_path + '/' + f)
+            AgentGitHandler.log.info('Restoring default artifacts from ' + 
default_artifact_backup_location + ' to ' + local_repo_path)
+            shutil.copytree(default_artifact_backup_location, local_repo_path)
+        except OSError as e:
+            AgentGitHandler.log.error('Contents of ' + 
default_artifact_backup_location + ' not restored. Error: %s' % e)
+
+    @staticmethod
     def execute_git_command(command, repo_path):
         """
         Executes the given command string with given environment parameters

http://git-wip-us.apache.org/repos/asf/stratos/blob/2951b419/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 c25d0e8..1bef17b 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
@@ -21,6 +21,9 @@ from modules.artifactmgt.git.agentgithandler import 
AgentGitHandler
 from config import Config
 import constants
 from exception import *
+import shutil
+import errno
+import os
 
 
 class DefaultArtifactCheckout(IArtifactCheckoutPlugin):
@@ -90,6 +93,10 @@ class DefaultArtifactCheckout(IArtifactCheckoutPlugin):
                           git_repo.repo_url, git_repo.local_repo_path)
             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 /tmp/default_artifacts
+            self.backupDefaultArtifacts(git_repo.local_repo_path, 
"/tmp/default_artifacts")
+
             try:
                 git_repo = AgentGitHandler.clone(git_repo)
                 AgentGitHandler.add_repo(git_repo)
@@ -101,3 +108,18 @@ class DefaultArtifactCheckout(IArtifactCheckoutPlugin):
                 self.log.info("Retrying git clone operation...")
                 AgentGitHandler.retry_clone(git_repo)
                 AgentGitHandler.add_repo(git_repo)
+
+    def backupDefaultArtifacts(src, dest):
+        try:
+            if not os.path.isdir(src):
+                self.log.info ('Direcotry ' + src + ' does not exist')
+                return
+            if os.path.isdir(dest):
+                self.log.info('Directory ' + dest + ' already exists, will 
delete')
+                shutil.rmtree(dest)
+            self.log.info('Copying default artifacts from ' + src + ' to ' + 
dest)
+            shutil.copytree(src, dest)
+        except OSError as e:
+            self.log.error('Directory not copied. Error: %s' % e)
+
+

Reply via email to