stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject stratos git commit: Add ApplicationSignUpRemovedEvent to cartridge agent
Date Thu, 05 Feb 2015 09:04:37 GMT
Repository: stratos
Updated Branches:
  refs/heads/master c43278ca3 -> 6dae006c3


Add ApplicationSignUpRemovedEvent to cartridge agent


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

Branch: refs/heads/master
Commit: 6dae006c3f2a5bda2c8e8657583d3af64abe97ac
Parents: c43278c
Author: Gayan Gunarathne <gayang@wso2.com>
Authored: Thu Feb 5 14:33:53 2015 +0530
Committer: Gayan Gunarathne <gayang@wso2.com>
Committed: Thu Feb 5 14:34:22 2015 +0530

----------------------------------------------------------------------
 .../cartridgeagent/cartridgeagent/agent.py      | 11 ++--
 .../modules/event/application/__init__.py       | 17 ++++++
 .../event/application/signup/__init__.py        | 17 ++++++
 .../modules/event/application/signup/events.py  | 62 ++++++++++++++++++++
 .../extensions/abstractextensionhandler.py      |  3 +
 .../extensions/defaultextensionhandler.py       | 17 +++++-
 .../modules/util/cartridgeagentconstants.py     |  1 +
 .../modules/util/extensionutils.py              | 16 +++++
 8 files changed, 139 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/6dae006c/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/agent.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/agent.py
b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/agent.py
index 1ffdec9..ae3fbed 100644
--- a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/agent.py
+++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/agent.py
@@ -18,6 +18,7 @@
 
 import threading
 import sys
+from cartridgeagent.cartridgeagent import modules
 
 from modules.exception.parameternotfoundexception import ParameterNotFoundException
 from modules.subscriber import eventsubscriber
@@ -25,6 +26,7 @@ from modules.publisher import cartridgeagentpublisher
 from modules.event.instance.notifier.events import *
 from modules.event.tenant.events import *
 from modules.event.topology.events import *
+from modules.event.application.signup.events import *
 from modules.tenant.tenantcontext import *
 from modules.topology.topologycontext import *
 from modules.datapublisher.logpublisher import *
@@ -281,6 +283,7 @@ class CartridgeAgent(threading.Thread):
         self.__tenant_event_subscriber.register_handler("CompleteTenantEvent", self.on_complete_tenant)
         self.__tenant_event_subscriber.register_handler("TenantSubscribedEvent", self.on_tenant_subscribed)
         self.__tenant_event_subscriber.register_handler("TenantUnSubscribedEvent", self.on_tenant_unsubscribed)
+        self.__tenant_event_subscriber.register_handler("ApplicationSignUpRemovedEvent",self.on_application_signup_removed)
 
         self.__tenant_event_subscriber.start()
         self.log.info("Tenant event message receiver thread started")
@@ -323,11 +326,11 @@ class CartridgeAgent(threading.Thread):
         except:
             self.log.exception("Error processing tenant subscribed event")
 
-    def on_tenant_unsubscribed(self, msg):
-        self.log.debug("Tenant unSubscribed event received: %r" % msg.payload)
-        event_obj = TenantUnsubscribedEvent.create_from_json(msg.payload)
+    def on_application_signup_removed(self, msg):
+        self.log.debug("Application signup removed event received: %r" % msg.payload)
+        event_obj = ApplicationSignUpRemovedEvent.create_from_json(msg.payload)
         try:
-            CartridgeAgent.extension_handler.on_tenant_unsubscribed_event(event_obj)
+            CartridgeAgent.extension_handler.on_application_signup_removal_event(event_obj)
         except:
             self.log.exception("Error processing tenant unSubscribed event")
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/6dae006c/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/__init__.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/__init__.py
b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/__init__.py
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/6dae006c/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/signup/__init__.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/signup/__init__.py
b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/signup/__init__.py
new file mode 100644
index 0000000..2456923
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/signup/__init__.py
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/6dae006c/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/signup/events.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/signup/events.py
b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/signup/events.py
new file mode 100644
index 0000000..ad38227
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/event/application/signup/events.py
@@ -0,0 +1,62 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import json
+
+
+class ApplicationSignUpAddedEvent:
+    def __init__(self):
+        self.applicationId = None
+        """ :type : str  """
+        self.tenantId = None
+        """ :type : str  """
+        self.clusterIds = None
+        """ :type : list[str]  """
+
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        applicationSignUp = ApplicationSignUpAddedEvent()
+
+        applicationSignUp.applicationId = json_obj["applicationId"] if "applicationId" in
json_obj else None
+        applicationSignUp.tenantId = json_obj["tenantId"] if "tenantId" in json_obj else
None
+        applicationSignUp.clusterIds = json_obj["clusterIds"] if "clusterIds" in json_obj
else None
+
+        return applicationSignUp
+
+
+class ApplicationSignUpRemovedEvent:
+    def __init__(self):
+        self.applicationId = None
+        """ :type : str  """
+        self.tenantId = None
+        """ :type : str  """
+        self.clusterIds = None
+        """ :type : list[str]  """
+
+
+    @staticmethod
+    def create_from_json(json_str):
+        json_obj = json.loads(json_str)
+        applicationSignUp = ApplicationSignUpRemovedEvent()
+
+        applicationSignUp.applicationId = json_obj["applicationId"] if "applicationId" in
json_obj else None
+        applicationSignUp.tenantId = json_obj["tenantId"] if "tenantId" in json_obj else
None
+
+        return applicationSignUp
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/6dae006c/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py
b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py
index 91f82a3..8b00dfc 100644
--- a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py
+++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py
@@ -76,3 +76,6 @@ class AbstractExtensionHandler:
 
     def on_tenant_unsubscribed_event(self, tenant_unsubscribed_event):
             raise NotImplementedError
+
+    def on_application_signup_removal_event(self, tenant_unsubscribed_event):
+        raise NotImplementedError

http://git-wip-us.apache.org/repos/asf/stratos/blob/6dae006c/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
index 82870d2..e18a8b5 100644
--- a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
+++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/extensions/defaultextensionhandler.py
@@ -359,7 +359,22 @@ class DefaultExtensionHandler(AbstractExtensionHandler):
             self.log.exception("Removing git repository failed: ")
         extensionutils.execute_tenant_unsubscribed_extension({})
 
-    def cleanup(self):
+    def on_application_signup_removal_event(self, application_signup_removal_event):
+
+        self.log.info(
+            "Tenant unsubscribed event received: [tenant] " + application_signup_removal_event.tenantId
+
+            " [application ID] " + application_signup_removal_event.applicationId
+        )
+
+        try:
+            if self.cartridge_agent_config.service_name == application_signup_removal_event.applicationId:
+                agentgithandler.AgentGitHandler.remove_repo(application_signup_removal_event.tenant_id)
+        except:
+            self.log.exception("Removing git repository failed: ")
+        extensionutils.execute_tenant_unsubscribed_extension({})
+
+
+def cleanup(self):
         self.log.info("Executing cleaning up the data in the cartridge instance...")
 
         cartridgeagentpublisher.publish_maintenance_mode_event()

http://git-wip-us.apache.org/repos/asf/stratos/blob/6dae006c/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/util/cartridgeagentconstants.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/util/cartridgeagentconstants.py
b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/util/cartridgeagentconstants.py
index 5898043..3f50efc 100644
--- a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/util/cartridgeagentconstants.py
+++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/util/cartridgeagentconstants.py
@@ -81,6 +81,7 @@ SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT = "extension.subscription.domain.removed"
 ARTIFACTS_COPY_SCRIPT = "extension.artifacts.copy"
 TENANT_SUBSCRIBED_SCRIPT = "extension.tenant.subscribed"
 TENANT_UNSUBSCRIBED_SCRIPT = "extension.tenant.unsubscribed"
+APPLICATION_SIGNUP_REMOVAL_SCRIPT = "extension.application.signup.removal"
 
 SERVICE_GROUP_TOPOLOGY_KEY = "payload_parameter.SERIVCE_GROUP"
 CLUSTERING_TOPOLOGY_KEY = "payload_parameter.CLUSTERING"

http://git-wip-us.apache.org/repos/asf/stratos/blob/6dae006c/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/util/extensionutils.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/util/extensionutils.py
b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/util/extensionutils.py
index a075cf7..d39104d 100644
--- a/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/util/extensionutils.py
+++ b/components/org.apache.stratos.python.cartridge.agent/cartridgeagent/cartridgeagent/modules/util/extensionutils.py
@@ -200,6 +200,22 @@ def execute_tenant_unsubscribed_extension(env_params):
         log.exception("Could not execute tenant unsubscribed extension")
 
 
+def execute_application_signup_removal_extension(env_params):
+    try:
+        log.debug("Executing tenant unsubscribed extension")
+
+        script_name = cartridge_agent_config.read_property(
+            cartridgeagentconstants.TENANT_UNSUBSCRIBED_SCRIPT, False)
+        command = prepare_command(script_name)
+        env_params = add_payload_parameters(env_params)
+        env_params = clean_process_parameters(env_params)
+
+        output, errors = execute_command(command, env_params)
+        log.debug("Application signup removal script returned: %r" % output)
+    except:
+        log.exception("Could not execute application signup removal extension")
+
+
 def execute_member_terminated_extension(env_params):
     try:
         log.debug("Executing member terminated extension")


Mime
View raw message