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:46 UTC

[1/5] stratos git commit: initial changes for signup deletion

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 <is...@apache.org>
Authored: Fri Nov 27 10:13:24 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
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)
+
+


[3/5] stratos git commit: Merge branch 'stratos-4.1.x' into singup_deletion_cleanup

Posted by is...@apache.org.
Merge branch 'stratos-4.1.x' into singup_deletion_cleanup


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

Branch: refs/heads/singup_deletion_cleanup
Commit: bfb50f4b3a8711091e633de0fb0877d3aa14530a
Parents: dbd2f07 64f05a5
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Tue Dec 1 11:08:38 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Tue Dec 1 11:08:38 2015 +0530

----------------------------------------------------------------------
 .../AutoscalerTopologyEventReceiver.java        |  277 ++--
 .../services/impl/AutoscalerServiceImpl.java    |   38 +-
 .../cluster/ClusterStatusActiveProcessor.java   |   22 +-
 .../group/GroupStatusActiveProcessor.java       |   84 +-
 .../processor/group/GroupStatusProcessor.java   |   10 +-
 .../group/GroupStatusTerminatedProcessor.java   |   42 +-
 .../CloudControllerServiceComponent.java        |    2 +-
 .../messaging/topology/TopologyBuilder.java     |   67 +-
 .../publisher/ThriftStatisticsPublisher.java    |   31 +-
 .../test/ThriftClientConfigParserTest.java      |   73 +-
 .../test/ThriftStatisticsPublisherTest.java     |   70 ++
 .../src/test/resources/thrift-client-config.xml |   53 +-
 .../domain/application/Application.java         |   11 +-
 .../processor/MessageProcessorChain.java        |    2 +
 .../ApplicationCreatedMessageProcessor.java     |   25 +-
 .../ApplicationDeletedMessageProcessor.java     |   12 +-
 ...cationInstanceActivatedMessageProcessor.java |   42 +-
 ...licationInstanceCreatedMessageProcessor.java |   25 +-
 ...tionInstanceInactivatedMessageProcessor.java |   40 +-
 ...ationInstanceTerminatedMessageProcessor.java |   25 +-
 ...tionInstanceTerminatingMessageProcessor.java |   41 +-
 .../ApplicationsMessageProcessorChain.java      |   38 +-
 .../ApplicationSignUpMessageProcessorChain.java |   13 +
 ...rStatusClusterActivatedMessageProcessor.java |   10 +-
 ...StatusClusterInactivateMessageProcessor.java |   10 +-
 ...sClusterInstanceCreatedMessageProcessor.java |   10 +-
 ...usterStatusClusterResetMessageProcessor.java |   10 +-
 ...StatusClusterTerminatedMessageProcessor.java |   10 +-
 ...tatusClusterTerminatingMessageProcessor.java |   10 +-
 .../ClusterStatusMessageProcessorChain.java     |   18 +
 .../DomainMappingMessageProcessorChain.java     |   11 +
 .../stat/HealthStatMessageProcessorChain.java   |   41 +-
 .../InitializerMessageProcessorChain.java       |   15 +
 .../InstanceNotifierMessageProcessorChain.java  |   12 +
 .../InstanceStatusMessageProcessorChain.java    |   14 +
 .../tenant/TenantMessageProcessorChain.java     |   14 +
 .../topology/TopologyMessageProcessorChain.java |   48 +
 .../ApplicationsEventMessageDelegator.java      |    4 +
 .../application/ApplicationsEventReceiver.java  |    4 +
 .../notifier/InstanceNotifierEventReceiver.java |   62 +-
 .../metadata/service/api/MetadataApi.java       |   18 +-
 .../metadata/service/registry/DataStore.java    |   21 +-
 .../service/registry/MetadataApiRegistry.java   |   37 +-
 .../iaas/internal/MockIaasServiceComponent.java |    6 -
 .../iaas/services/impl/MockIaasServiceImpl.java |   65 +-
 .../iaas/services/impl/MockIaasServiceUtil.java |   23 -
 .../mock/iaas/services/impl/MockInstance.java   |  187 ++-
 .../publisher/MockHealthStatisticsNotifier.java |   56 +-
 .../mock/iaas/test/MockIaasServiceTest.java     |  149 ++-
 .../src/test/resources/jndi.properties          |   22 +
 .../src/test/resources/thrift-client-config.xml |   50 +
 .../cartridge.agent/cartridge.agent/agent.py    |   62 +-
 .../cartridge.agent/healthstats.py              |   16 +-
 .../modules/artifactmgt/git/agentgithandler.py  |    7 +-
 .../modules/event/eventhandler.py               | 1180 +++++++++---------
 .../modules/util/cartridgeagentutils.py         |    4 +-
 .../plugins/DefaultArtifactCheckout.py          |    6 +-
 .../cartridge.agent/publisher.py                |   72 +-
 .../cartridge.agent/subscriber.py               |    8 +-
 .../rest/endpoint/api/StratosApiV41Utils.java   |    6 +-
 extensions/cep/modules/distribution/pom.xml     |   10 +
 .../modules/distribution/src/assembly/bin.xml   |    9 +
 .../stratos-cep-extension/wso2cep-3.1.0/pom.xml |    2 +-
 extensions/cep/pom.xml                          |    2 +-
 .../artifacts/metering-dashboard/capps/pom.xml  |   14 +-
 .../monitoring-dashboard/capps/pom.xml          |   12 -
 .../scaling_decision_1.0.0.json                 |    4 +-
 .../load-balancer/modules/aws-extension/pom.xml |    2 +-
 pom.xml                                         |   12 +-
 .../integration/tests/ADCExtensionTestCase.java |   32 +-
 .../tests/ADCMTAppTenantUserTestCase.java       |   47 +-
 .../integration/tests/ADCMTAppTestCase.java     |   46 +-
 .../agent/integration/tests/ADCTestCase.java    |   44 +-
 .../tests/ADCValidationTestCase.java            |  163 +++
 .../integration/tests/AgentStartupTestCase.java |   44 +-
 .../integration/tests/CEPHAModeTestCase.java    |   63 +-
 .../tests/MessageBrokerHATestCase.java          |   68 +-
 .../tests/PythonAgentIntegrationTest.java       |   82 +-
 .../resources/ADCValidationTestCase/agent.conf  |   46 +
 .../resources/ADCValidationTestCase/logging.ini |   52 +
 .../ADCValidationTestCase/payload/launch-params |    1 +
 .../MessageBrokerHATestCase/agent.conf          |    2 +-
 .../src/test/resources/log4j.properties         |    2 +-
 .../src/test/resources/test-suite-all.xml       |    1 +
 .../src/test/resources/test-suite-smoke.xml     |    2 +
 .../integration/common/RestConstants.java       |    1 +
 .../common/StratosTestServerManager.java        |  102 +-
 .../integration/common/TopologyHandler.java     |  511 +++++---
 .../integration/common/rest/RestClient.java     |   61 +-
 .../tests/StratosIntegrationTest.java           |    5 +-
 .../integration/tests/adc/GitHookTestCase.java  |  108 +-
 .../ApplicationBurstingTestCase.java            |  145 +--
 .../ApplicationStartupOrderTestCase.java        |  165 +--
 .../application/ApplicationUpdateTestCase.java  |  131 +-
 .../application/GroupStartupOrderTestCase.java  |  229 ++--
 .../GroupTerminationBehaviorTestCase.java       |  196 ++-
 .../application/MetadataServiceTestCase.java    |   32 +-
 ...PartitionOneAfterAnotherClusterTestCase.java |  148 ++-
 .../PartitionRoundRobinClusterTestCase.java     |  129 +-
 .../SampleApplicationStartupTestCase.java       |   46 +-
 .../application/SampleApplicationsTestCase.java |  401 +++---
 .../SingleClusterScalingTestCase.java           |  131 +-
 .../tests/cartridge/CartridgeGroupTestCase.java |  241 ++++
 .../tests/cartridge/CartridgeTestCase.java      |  183 +++
 .../tests/group/CartridgeGroupTestCase.java     |  251 ----
 .../tests/group/CartridgeTestCase.java          |  183 ---
 .../tests/iaas/IaaSProviderTestCase.java        |   28 +-
 .../iaas/IaasProviderAttributeTestCase.java     |   61 +-
 .../policies/ApplicationPolicyTestCase.java     |  111 +-
 .../policies/AutoscalingPolicyTestCase.java     |    5 +-
 .../policies/DeploymentPolicyTestCase.java      |    7 +-
 .../policies/NetworkPartitionTestCase.java      |    7 +-
 .../server/StratosServerRestartTestCase.java    |   90 +-
 .../integration/tests/users/TenantTestCase.java |    8 +-
 .../integration/tests/users/UserTestCase.java   |    5 +-
 .../src/test/resources/common/log4j.properties  |   14 +-
 .../src/test/resources/test-suite-all.xml       |    4 +-
 .../src/test/resources/test-suite-smoke.xml     |    2 +-
 118 files changed, 4338 insertions(+), 3506 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/bfb50f4b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/stratos/blob/bfb50f4b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/util/cartridgeagentutils.py
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/stratos/blob/bfb50f4b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/plugins/DefaultArtifactCheckout.py
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/plugins/DefaultArtifactCheckout.py
index 52648a1,27cf99c..0a45d91
--- 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
@@@ -113,19 -101,3 +113,19 @@@ class DefaultArtifactCheckout(IArtifact
                  self.log.info("Retrying git clone operation...")
                  AgentGitHandler.retry_clone(git_repo)
                  AgentGitHandler.add_repo(git_repo)
 +
 +    def initial_artifacts_exists(self, dir):
 +        try:
 +            return os.path.exists(dir) and os.listdir(dir)
 +        except OSError as e:
 +            self.log.error('Unable to check if directory exists | non-empty, error: %s' % e)
 +            return False
 +
 +    def backup_initial_artifacts(self, src):
 +        self.log.info('Initial artifacts exists, taking backup to ' + Utils.strip_trailing_slash(src)
 +                      + constants.BACKUP_DIR_SUFFIX +
 +                      ' directory')
 +        try:
 +            shutil.copytree(src, Utils.strip_trailing_slash(src) + constants.BACKUP_DIR_SUFFIX)
 +        except OSError as e:
-             self.log.error('Directory not copied. Error: %s' % e)
++            self.log.error('Directory not copied. Error: %s' % e)


[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

Posted by is...@apache.org.
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)


[2/5] stratos git commit: initial changes for restoring initial artifacts after signup removal

Posted by is...@apache.org.
initial changes for restoring initial artifacts after signup removal


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

Branch: refs/heads/singup_deletion_cleanup
Commit: dbd2f07f1a2395a5256e2439595242ff8d521abe
Parents: 2951b41
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Tue Dec 1 11:07:56 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Tue Dec 1 11:07:56 2015 +0530

----------------------------------------------------------------------
 .../cartridge.agent/constants.py                |  2 +
 .../modules/artifactmgt/git/agentgithandler.py  | 22 ++++----
 .../modules/util/cartridgeagentutils.py         | 55 ++++++++++++++++++++
 .../plugins/DefaultArtifactCheckout.py          | 34 +++++++-----
 4 files changed, 86 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/dbd2f07f/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 cd2ce36..4672579 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
@@ -140,3 +140,5 @@ MONITORING_RECEIVER_PORT = "monitoring.server.port"
 MONITORING_RECEIVER_SECURE_PORT = "monitoring.server.secure.port"
 MONITORING_SERVER_ADMIN_USERNAME = "monitoring.server.admin.username"
 MONITORING_SERVER_ADMIN_PASSWORD = "monitoring.server.admin.password"
+
+BACKUP_DIR_SUFFIX = "_backup"

http://git-wip-us.apache.org/repos/asf/stratos/blob/dbd2f07f/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 2cb4c38..7546619 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,10 +28,10 @@ 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
+from ...util.cartridgeagentutils import Utils
 
 
 class AgentGitHandler:
@@ -315,7 +315,9 @@ class AgentGitHandler:
                 "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)
+        if Utils.directory_exists(Utils.strip_trailing_slash(git_repo.local_repo_path) +
+                                          constants.BACKUP_DIR_SUFFIX):
+            AgentGitHandler.restore_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)
@@ -323,19 +325,13 @@ class AgentGitHandler:
         return True
 
     @staticmethod
-    def restore_default_artifacts (default_artifact_backup_location, local_repo_path):
+    def restore_default_artifacts(default_dir):
         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)
+            Utils.move_directory(Utils.strip_trailing_slash(default_dir) + constants.BACKUP_DIR_SUFFIX, default_dir)
+            AgentGitHandler.log.info('Restored contents from backup location ' +Utils.strip_trailing_slash(default_dir)
+                                     + constants.BACKUP_DIR_SUFFIX)
         except OSError as e:
-            AgentGitHandler.log.error('Contents of ' + default_artifact_backup_location + ' not restored. Error: %s' % e)
+            AgentGitHandler.log.error('Contents of ' + default_dir + ' not restored. Error: %s' % e)
 
     @staticmethod
     def execute_git_command(command, repo_path):

http://git-wip-us.apache.org/repos/asf/stratos/blob/dbd2f07f/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 ebd6889..74c7e75 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
@@ -21,6 +21,8 @@ import time
 import socket
 import string
 import hashlib
+import shutil
+import os
 
 from log import LogFactory
 
@@ -120,6 +122,59 @@ def check_ports_active(ip_address, ports):
 
     return True
 
+class Utils (object):
+
+    @staticmethod
+    def directory_exists(dir):
+        """
+        Checks if the given directory exists
+        :param dir: directory to check
+        :return: True if the directory dir exists, else False
+        :rtype: bool
+        """
+        try:
+            return os.path.isdir(dir)
+        except OSError as e:
+            log.error("Unable to check directory existance [%s]" % e)
+            return False
+
+    @staticmethod
+    def copy_directory(src, destination):
+        """
+        Copies if the directory 'src' to 'destination'
+        :param src: location of directory to copy
+        :param destination: new directory location
+        """
+        try:
+            shutil.copytree(src, destination)
+            log.debug("Directory [%s] copied to [%s]" % (src, destination))
+        except OSError as e:
+            log.error('Directory not copied. Error: %s' % e)
+
+    @staticmethod
+    def strip_trailing_slash(string):
+        """
+        If the string has a trailing '/', removes it
+        :param string: string to check
+        :return: string without a trailing '/'
+        :rtype: string
+        """
+        if string.endswith('/'):
+            return string[:-1]
+        return string
+
+    @staticmethod
+    def move_directory(src, destination):
+        """
+        Moves if the directory 'src' to 'destination'
+        :param src: location of directory to move
+        :param destination: new directory location
+        """
+        try:
+            shutil.move(src, destination)
+            log.debug("Directory [%s] moved to [%s]" % (src, destination))
+        except OSError as e:
+            log.error('Directory not moved. Error: %s' % e)
 
 class IncrementalCeilingListIterator(object):
     """

http://git-wip-us.apache.org/repos/asf/stratos/blob/dbd2f07f/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 1bef17b..52648a1 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
@@ -17,12 +17,12 @@
 
 from plugins.contracts import IArtifactCheckoutPlugin
 from modules.util.log import LogFactory
+from modules.util.cartridgeagentutils import Utils
 from modules.artifactmgt.git.agentgithandler import AgentGitHandler
 from config import Config
 import constants
 from exception import *
 import shutil
-import errno
 import os
 
 
@@ -94,8 +94,13 @@ 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 /tmp/default_artifacts
-            self.backupDefaultArtifacts(git_repo.local_repo_path, "/tmp/default_artifacts")
+            # 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)
 
             try:
                 git_repo = AgentGitHandler.clone(git_repo)
@@ -109,17 +114,18 @@ class DefaultArtifactCheckout(IArtifactCheckoutPlugin):
                 AgentGitHandler.retry_clone(git_repo)
                 AgentGitHandler.add_repo(git_repo)
 
-    def backupDefaultArtifacts(src, dest):
+    def initial_artifacts_exists(self, dir):
         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)
+            return os.path.exists(dir) and os.listdir(dir)
         except OSError as e:
-            self.log.error('Directory not copied. Error: %s' % e)
-
+            self.log.error('Unable to check if directory exists | non-empty, error: %s' % e)
+            return False
 
+    def backup_initial_artifacts(self, src):
+        self.log.info('Initial artifacts exists, taking backup to ' + Utils.strip_trailing_slash(src)
+                      + constants.BACKUP_DIR_SUFFIX +
+                      ' directory')
+        try:
+            shutil.copytree(src, Utils.strip_trailing_slash(src) + constants.BACKUP_DIR_SUFFIX)
+        except OSError as e:
+            self.log.error('Directory not copied. Error: %s' % e)
\ No newline at end of file


[5/5] stratos git commit: adding comments

Posted by is...@apache.org.
adding comments


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

Branch: refs/heads/singup_deletion_cleanup
Commit: 7fc829e1aa02de84fdb65220090e804a245aae83
Parents: 11a35ed
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Tue Dec 1 17:07:23 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Tue Dec 1 17:07:23 2015 +0530

----------------------------------------------------------------------
 .../modules/artifactmgt/git/agentgithandler.py  | 21 ++++++++++----------
 .../plugins/DefaultArtifactCheckout.py          |  7 +++++++
 2 files changed, 17 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/7fc829e1/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 224ca31..743bcd6 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
@@ -214,15 +214,9 @@ 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)
+            AgentGitHandler.log.debug('Cached repo object deleted for tenant ' + tenant_id)
 
     @staticmethod
     def create_git_repo(repo_info):
@@ -338,13 +332,18 @@ class AgentGitHandler:
         return True
 
     @staticmethod
-    def restore_default_artifacts(default_dir):
+    def restore_default_artifacts(initial_artifact_dir):
+        """
+        Restores the initial artifacts from the previously taken backup, if the backup exists
+
+        :param initial_artifact_dir: path to local artifact directory
+        """
         try:
-            Utils.move_directory(Utils.strip_trailing_slash(default_dir) + constants.BACKUP_DIR_SUFFIX, default_dir)
-            AgentGitHandler.log.info('Restored contents from backup location ' +Utils.strip_trailing_slash(default_dir)
+            Utils.move_directory(Utils.strip_trailing_slash(initial_artifact_dir) + constants.BACKUP_DIR_SUFFIX, initial_artifact_dir)
+            AgentGitHandler.log.info('Restored contents from backup location ' + Utils.strip_trailing_slash(initial_artifact_dir)
                                      + constants.BACKUP_DIR_SUFFIX)
         except OSError as e:
-            AgentGitHandler.log.error('Contents of ' + default_dir + ' not restored. Error: %s' % e)
+            AgentGitHandler.log.error('Contents of ' + initial_artifact_dir + ' not restored. Error: %s' % e)
 
     @staticmethod
     def execute_git_command(command, repo_path):

http://git-wip-us.apache.org/repos/asf/stratos/blob/7fc829e1/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 413090e..1b7baa0 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
@@ -110,6 +110,13 @@ class DefaultArtifactCheckout(IArtifactCheckoutPlugin):
                 AgentGitHandler.add_repo(git_repo)
 
     def check_and_backup_initial_artifacts(self, initial_artifact_dir):
+        """
+        verifies if there are any default artifacts by checking the 'initial_artifact_dir' and
+        whether its empty, and takes a backup to a directory  initial_artifact_dir_backup in the
+        same location
+
+        :param initial_artifact_dir: path to local artifact directory
+        """
         # 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):