You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/10/11 11:09:36 UTC

[11/50] [abbrv] git commit: Fixed exception handling for non critical parameter reading Fixed incorrect use of the configuration class Fixed minor issues in agent.py

Fixed exception handling for non critical parameter reading
Fixed incorrect use of the configuration class
Fixed minor issues in agent.py


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

Branch: refs/heads/master
Commit: 52e258b71ef613a405786482c645c8d3d66588e3
Parents: 126fa52
Author: Chamila de Alwis <ch...@wso2.com>
Authored: Mon Sep 29 19:26:57 2014 +0530
Committer: Nirmal Fernando <ni...@gmail.com>
Committed: Sat Oct 11 14:38:29 2014 +0530

----------------------------------------------------------------------
 .../broker/publish/EventPublisher.java          |  2 +-
 .../config/cartridgeagentconfiguration.py       |  2 +-
 .../extensions/defaultextensionhandler.py       | 16 ++++-----
 .../publisher/cartridgeagentpublisher.py        |  8 ++---
 .../modules/subscriber/eventsubscriber.py       | 16 +++++----
 .../modules/util/cartridgeagentconstants.py     |  2 +-
 .../modules/util/cartridgeagentutils.py         |  4 +--
 .../modules/util/extensionutils.py              | 38 ++++++++++----------
 8 files changed, 46 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/52e258b7/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/broker/publish/EventPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/broker/publish/EventPublisher.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/broker/publish/EventPublisher.java
index 2ba4df4..92ae4da 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/broker/publish/EventPublisher.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/broker/publish/EventPublisher.java
@@ -15,7 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */
+ */INSTANCE_STATUS_TOPIC
 
 package org.apache.stratos.messaging.broker.publish;
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/52e258b7/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py b/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py
index 32ff23f..3170e3d 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/config/cartridgeagentconfiguration.py
@@ -271,7 +271,7 @@ class CartridgeAgentConfiguration:
         :return: void
         """
 
-        param_file = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.PARAM_FILE_PATH)
+        param_file = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.PARAM_FILE_PATH, False)
 
         try:
             if param_file is not None:

http://git-wip-us.apache.org/repos/asf/stratos/blob/52e258b7/tools/python-cartridge-agent/cartridge-agent/modules/extensions/defaultextensionhandler.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/extensions/defaultextensionhandler.py b/tools/python-cartridge-agent/cartridge-agent/modules/extensions/defaultextensionhandler.py
index 96b6fd5..6d49d8f 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/extensions/defaultextensionhandler.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/extensions/defaultextensionhandler.py
@@ -56,7 +56,7 @@ class DefaultExtensionHandler(AbstractExtensionHandler):
 
             repo_username = artifacts_updated_event.repo_username
             tenant_id = artifacts_updated_event.tenant_id
-            is_multitenant = CartridgeAgentConfiguration.is_multitenant()
+            is_multitenant = CartridgeAgentConfiguration.is_multitenant
             commit_enabled = artifacts_updated_event.commit_enabled
 
             self.log.info("Executing git checkout")
@@ -82,15 +82,15 @@ class DefaultExtensionHandler(AbstractExtensionHandler):
                 # publish instanceActivated
                 cartridgeagentpublisher.publish_instance_activated_event()
 
-            update_artifacts = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.ENABLE_ARTIFACT_UPDATE)
+            update_artifacts = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.ENABLE_ARTIFACT_UPDATE, False)
             update_artifacts = True if str(update_artifacts).strip().lower() == "true" else False
             if update_artifacts:
-                auto_commit = CartridgeAgentConfiguration.is_commits_enabled()
-                auto_checkout = CartridgeAgentConfiguration.is_checkout_enabled()
+                auto_commit = CartridgeAgentConfiguration.is_commits_enabled
+                auto_checkout = CartridgeAgentConfiguration.is_checkout_enabled
 
                 try:
                     update_interval = len(
-                        CartridgeAgentConfiguration.read_property(cartridgeagentconstants.ARTIFACT_UPDATE_INTERVAL))
+                        CartridgeAgentConfiguration.read_property(cartridgeagentconstants.ARTIFACT_UPDATE_INTERVAL, False))
                 except ParameterNotFoundException:
                     self.log.exception("Invalid artifact sync interval specified ")
                     update_interval = 10
@@ -374,9 +374,9 @@ class DefaultExtensionHandler(AbstractExtensionHandler):
         extensionutils.wait_for_complete_topology()
         self.log.info("[start server extension] complete topology event received")
 
-        service_name_in_payload = CartridgeAgentConfiguration.service_name()
-        cluster_id_in_payload = CartridgeAgentConfiguration.cluster_id()
-        member_id_in_payload = CartridgeAgentConfiguration.member_id()
+        service_name_in_payload = CartridgeAgentConfiguration.service_name
+        cluster_id_in_payload = CartridgeAgentConfiguration.cluster_id
+        member_id_in_payload = CartridgeAgentConfiguration.member_id
 
         topology_consistant = extensionutils.check_topology_consistency(service_name_in_payload, cluster_id_in_payload, member_id_in_payload)
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/52e258b7/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py b/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
index 1ad437b..a862967 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/publisher/cartridgeagentpublisher.py
@@ -31,7 +31,7 @@ def publish_instance_started_event():
 
         instance_started_event = InstanceStartedEvent(service_name, cluster_id, network_partition_id, parition_id,
                                                       member_id)
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC)
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + "InstanceStartedEvent")
         publisher.publish(instance_started_event)
         started = True
         log.info("Instance started event published")
@@ -51,7 +51,7 @@ def publish_instance_activated_event():
 
         instance_activated_event = InstanceActivatedEvent(service_name, cluster_id, network_partition_id, parition_id,
                                                           member_id)
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC)
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + "InstanceActivatedEvent")
         publisher.publish(instance_activated_event)
 
         log.info("Instance activated event published")
@@ -78,7 +78,7 @@ def publish_maintenance_mode_event():
         instance_maintenance_mode_event = InstanceMaintenanceModeEvent(service_name, cluster_id, network_partition_id, parition_id,
                                                           member_id)
 
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC)
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + "InstanceMaintenanceModeEvent")
         publisher.publish(instance_maintenance_mode_event)
 
         maintenance = True
@@ -101,7 +101,7 @@ def publish_instance_ready_to_shutdown_event():
         instance_shutdown_event = InstanceReadyToShutdownEvent(service_name, cluster_id, network_partition_id, parition_id,
                                                           member_id)
 
-        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC)
+        publisher = get_publisher(cartridgeagentconstants.INSTANCE_STATUS_TOPIC + "InstanceReadyToShutdownEvent")
         publisher.publish(instance_shutdown_event)
 
         ready_to_shutdown = True

http://git-wip-us.apache.org/repos/asf/stratos/blob/52e258b7/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/eventsubscriber.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/eventsubscriber.py b/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/eventsubscriber.py
index 6d29a68..8d418fa 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/eventsubscriber.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/subscriber/eventsubscriber.py
@@ -60,13 +60,17 @@ class EventSubscriber(threading.Thread):
         self.log.debug("Message received: %r:\n%r" % (msg.topic, msg.payload))
 
         event = msg.topic.rpartition('/')[2]
-        handler = self.__event_handlers[event]
 
-        try:
-            self.log.debug("Executing handler for event %r" % event)
-            handler(msg)
-        except:
-            self.log.exception("Error processing %r event" % event)
+        if event in self.__event_handlers:
+            handler = self.__event_handlers[event]
+
+            try:
+                self.log.debug("Executing handler for event %r" % event)
+                handler(msg)
+            except:
+                self.log.exception("Error processing %r event" % event)
+        else:
+            self.log.debug("Event handler not found for event : %r" % event)
 
     def is_subscribed(self):
         """

http://git-wip-us.apache.org/repos/asf/stratos/blob/52e258b7/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentconstants.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentconstants.py b/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentconstants.py
index 3b7f6c8..3d6dea1 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentconstants.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentconstants.py
@@ -85,7 +85,7 @@ INSTANCE_NOTIFIER_TOPIC = "instance/#"
 HEALTH_STAT_TOPIC = "health/#"
 TOPOLOGY_TOPIC = "topology/#"
 TENANT_TOPIC = "tenant/#"
-INSTANCE_STATUS_TOPIC = "instance/#"
+INSTANCE_STATUS_TOPIC = "instance/status/"
 
 
 #Messaging Model

http://git-wip-us.apache.org/repos/asf/stratos/blob/52e258b7/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentutils.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentutils.py b/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentutils.py
index 8e47a37..efff3ec 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentutils.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/util/cartridgeagentutils.py
@@ -82,7 +82,7 @@ def wait_until_ports_active(ip_address, ports):
     :param list[str] ports: List of ports to be checked
     :return: void
     """
-    ports_check_timeout = CartridgeAgentConfiguration.read_property("port.check.timeout")
+    ports_check_timeout = CartridgeAgentConfiguration.read_property("port.check.timeout", critical=False)
     if ports_check_timeout is None:
         ports_check_timeout = 1000 * 60 * 10
 
@@ -119,7 +119,7 @@ def check_ports_active(ip_address, ports):
         s = socket.socket()
         s.settimeout(5)
         try:
-            s.connect(ip_address, port)
+            s.connect((ip_address, int(port)))
             log.debug("Port %r is active" % port)
             s.close()
         except socket.error:

http://git-wip-us.apache.org/repos/asf/stratos/blob/52e258b7/tools/python-cartridge-agent/cartridge-agent/modules/util/extensionutils.py
----------------------------------------------------------------------
diff --git a/tools/python-cartridge-agent/cartridge-agent/modules/util/extensionutils.py b/tools/python-cartridge-agent/cartridge-agent/modules/util/extensionutils.py
index 53b6ea8..8ce36ba 100644
--- a/tools/python-cartridge-agent/cartridge-agent/modules/util/extensionutils.py
+++ b/tools/python-cartridge-agent/cartridge-agent/modules/util/extensionutils.py
@@ -13,7 +13,7 @@ log = logging.getLogger(__name__)
 def execute_copy_artifact_extension(source, destination):
     try:
         log.debug("Executing artifacts copy extension")
-        script_name = cartridgeagentconstants.ARTIFACTS_COPY_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.ARTIFACTS_COPY_SCRIPT, False)
         command = prepare_command(script_name)
 
         output, errors = execute_command(command + " " + source + " " + destination)
@@ -26,7 +26,7 @@ def execute_instance_started_extension(env_params):
     try:
         log.debug("Executing instance started extension")
 
-        script_name = cartridgeagentconstants.INSTANCE_STARTED_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.INSTANCE_STARTED_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -40,7 +40,7 @@ def execute_instance_started_extension(env_params):
 def execute_instance_activated_extension():
     try:
         log.debug("Executing instance activated extension")
-        script_name = cartridgeagentconstants.INSTANCE_ACTIVATED_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.INSTANCE_ACTIVATED_SCRIPT, False)
         command = prepare_command(script_name)
 
         output, errors = execute_command(command)
@@ -53,7 +53,7 @@ def execute_artifacts_updated_extension(env_params):
     try:
         log.debug("Executing artifacts updated extension")
 
-        script_name = cartridgeagentconstants.ARTIFACTS_UPDATED_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.ARTIFACTS_UPDATED_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -68,7 +68,7 @@ def execute_subscription_domain_added_extension(env_params):
     try:
         log.debug("Executing subscription domain added extension")
 
-        script_name = cartridgeagentconstants.SUBSCRIPTION_DOMAIN_ADDED_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.SUBSCRIPTION_DOMAIN_ADDED_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -83,7 +83,7 @@ def execute_subscription_domain_removed_extension(env_params):
     try:
         log.debug("Executing subscription domain removed extension")
 
-        script_name = cartridgeagentconstants.SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.SUBSCRIPTION_DOMAIN_REMOVED_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -98,7 +98,7 @@ def execute_start_servers_extension(env_params):
     try:
         log.debug("Executing start servers extension")
 
-        script_name = cartridgeagentconstants.START_SERVERS_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.START_SERVERS_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -113,7 +113,7 @@ def execute_complete_topology_extension(env_params):
     try:
         log.debug("Executing complete topology extension")
 
-        script_name = cartridgeagentconstants.COMPLETE_TOPOLOGY_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.COMPLETE_TOPOLOGY_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -128,7 +128,7 @@ def execute_complete_tenant_extension(env_params):
     try:
         log.debug("Executing complete tenant extension")
 
-        script_name = cartridgeagentconstants.COMPLETE_TENANT_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.COMPLETE_TENANT_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -143,7 +143,7 @@ def execute_tenant_subscribed_extension(env_params):
     try:
         log.debug("Executing tenant subscribed extension")
 
-        script_name = cartridgeagentconstants.TENANT_SUBSCRIBED_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.TENANT_SUBSCRIBED_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -158,7 +158,7 @@ def execute_tenant_unsubscribed_extension(env_params):
     try:
         log.debug("Executing tenant unsubscribed extension")
 
-        script_name = cartridgeagentconstants.TENANT_UNSUBSCRIBED_SCRIPT
+        script_name = CartridgeAgentConfiguration.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)
@@ -173,7 +173,7 @@ def execute_member_terminated_extension(env_params):
     try:
         log.debug("Executing member terminated extension")
 
-        script_name = cartridgeagentconstants.MEMBER_TERMINATED_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.MEMBER_TERMINATED_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -188,7 +188,7 @@ def execute_member_suspended_extension(env_params):
     try:
         log.debug("Executing member suspended extension")
 
-        script_name = cartridgeagentconstants.MEMBER_SUSPENDED_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.MEMBER_SUSPENDED_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -202,7 +202,7 @@ def execute_member_started_extension(env_params):
     try:
         log.debug("Executing member started extension")
 
-        script_name = cartridgeagentconstants.MEMBER_STARTED_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.MEMBER_STARTED_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -284,7 +284,7 @@ def is_relevant_member_event(service_name, cluster_id, lb_cluster_id):
 def execute_volume_mount_extension(persistance_mappings_payload):
     try:
         log.debug("Executing volume mounting extension: [payload] %r" % persistance_mappings_payload)
-        script_name = cartridgeagentconstants.MOUNT_VOLUMES_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.MOUNT_VOLUMES_SCRIPT, False)
         command = prepare_command(script_name)
 
         output, errors = execute_command(command + " " + persistance_mappings_payload)
@@ -296,7 +296,7 @@ def execute_volume_mount_extension(persistance_mappings_payload):
 def execute_cleanup_extension():
     try:
         log.debug("Executing cleanup extension")
-        script_name = cartridgeagentconstants.CLEAN_UP_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.CLEAN_UP_SCRIPT, False)
         command = prepare_command(script_name)
 
         output, errors = execute_command(command)
@@ -309,7 +309,7 @@ def execute_member_activated_extension(env_params):
     try:
         log.debug("Executing member activated extension")
 
-        script_name = cartridgeagentconstants.MEMBER_ACTIVATED_SCRIPT
+        script_name = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.MEMBER_ACTIVATED_SCRIPT, False)
         command = prepare_command(script_name)
         env_params = add_payload_parameters(env_params)
         env_params = clean_process_parameters(env_params)
@@ -321,7 +321,7 @@ def execute_member_activated_extension(env_params):
 
 
 def prepare_command(script_name):
-    extensions_dir = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.EXTENSIONS_DIR)
+    extensions_dir = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.EXTENSIONS_DIR, False)
     if extensions_dir.strip() == "":
         raise RuntimeError("System property not found: %r" % cartridgeagentconstants.EXTENSIONS_DIR)
 
@@ -355,7 +355,7 @@ def add_payload_parameters(env_params):
     :rtype: dict[str, str]
     """
     env_params["STRATOS_APP_PATH"] = CartridgeAgentConfiguration.app_path
-    env_params["STRATOS_PARAM_FILE_PATH"] = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.PARAM_FILE_PATH)
+    env_params["STRATOS_PARAM_FILE_PATH"] = CartridgeAgentConfiguration.read_property(cartridgeagentconstants.PARAM_FILE_PATH, False)
     env_params["STRATOS_SERVICE_NAME"] = CartridgeAgentConfiguration.service_name
     env_params["STRATOS_TENANT_ID"] = CartridgeAgentConfiguration.tenant_id
     env_params["STRATOS_CARTRIDGE_KEY"] = CartridgeAgentConfiguration.cartridge_key