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 2016/01/05 16:47:30 UTC

[21/50] [abbrv] stratos git commit: initial changes for signup deletion

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/1570afda
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/1570afda
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/1570afda

Branch: refs/heads/stratos-4.1.x
Commit: 1570afda1334bc03868753a95b94f111af1ec191
Parents: 6189945
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Fri Nov 27 10:13:24 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Fri Dec 25 14:58:19 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/1570afda/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 15d3733..690285c 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
@@ -314,12 +315,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/1570afda/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 27cf99c..1dbf645 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)
+
+