You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2015/09/15 23:35:27 UTC

stratos git commit: Update PCA topology context on complete topology event, PCA integration test to cover the scenario

Repository: stratos
Updated Branches:
  refs/heads/stratos-4.1.x 37df2ef9c -> 477686c6a


Update PCA topology context on complete topology event, PCA integration test to cover the scenario


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

Branch: refs/heads/stratos-4.1.x
Commit: 477686c6ae5f5648357135bebac8e1aeb0067ee8
Parents: 37df2ef
Author: Akila Perera <ra...@gmail.com>
Authored: Wed Sep 16 03:05:05 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Wed Sep 16 03:05:05 2015 +0530

----------------------------------------------------------------------
 .../cartridge.agent/cartridge.agent/agent.py    |  5 +-
 .../tests/ADCMTAppTenantUserTestCase.java       |  2 +-
 .../integration/tests/ADCMTAppTestCase.java     |  2 +-
 .../agent/integration/tests/ADCTestCase.java    |  2 +-
 .../integration/tests/AgentStartupTestCase.java | 32 +++++++++--
 .../tests/PythonAgentIntegrationTest.java       | 15 +++++
 .../extensions/py/startup-test-handler.py       | 60 ++++++++++++++++++++
 .../py/startup-test-handler.yapsy-plugin        | 27 +++++++++
 8 files changed, 135 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/477686c6/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/agent.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/agent.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/agent.py
index 52f3b24..7b5dfaa 100644
--- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/agent.py
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/agent.py
@@ -249,13 +249,14 @@ class CartridgeAgent(threading.Thread):
         self.__event_handler.on_member_suspended_event(event_obj)
 
     def on_complete_topology(self, msg):
+        event_obj = CompleteTopologyEvent.create_from_json(msg.payload)
         if not TopologyContext.topology.initialized:
             self.__log.debug("Complete topology event received")
-            event_obj = CompleteTopologyEvent.create_from_json(msg.payload)
             TopologyContext.update(event_obj.topology)
             self.__event_handler.on_complete_topology_event(event_obj)
         else:
-            self.__log.debug("Complete topology event updating task disabled")
+            TopologyContext.update(event_obj.topology)
+            self.__log.debug("Topology context updated [topology] %r" % event_obj.topology.json_str)
 
     def on_member_started(self, msg):
         self.__log.debug("Member started event received: %r" % msg.payload)

http://git-wip-us.apache.org/repos/asf/stratos/blob/477686c6/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
index 048df0e..9705a22 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
@@ -39,7 +39,7 @@ import static junit.framework.Assert.assertTrue;
 
 public class ADCMTAppTenantUserTestCase extends PythonAgentIntegrationTest {
     private static final Log log = LogFactory.getLog(ADCMTAppTenantUserTestCase.class);
-    private static final int ADC_TIMEOUT = 180000;
+    private static final int ADC_TIMEOUT = 300000;
     private static final String APPLICATION_PATH = "/tmp/ADCMTAppTenantUserTestCase";
     private static final String CLUSTER_ID = "tomcat.domain";
     private static final String DEPLOYMENT_POLICY_NAME = "deployment-policy-4";

http://git-wip-us.apache.org/repos/asf/stratos/blob/477686c6/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
index e0636eb..caaf291 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
@@ -40,7 +40,7 @@ import static junit.framework.Assert.assertTrue;
 
 public class ADCMTAppTestCase extends PythonAgentIntegrationTest {
     private static final Log log = LogFactory.getLog(ADCMTAppTestCase.class);
-    private static final int ADC_TIMEOUT = 180000;
+    private static final int ADC_TIMEOUT = 300000;
     private static final String APPLICATION_PATH = "/tmp/ADCMTAppTestCase";
     private static final String CLUSTER_ID = "tomcat.domain";
     private static final String DEPLOYMENT_POLICY_NAME = "deployment-policy-3";

http://git-wip-us.apache.org/repos/asf/stratos/blob/477686c6/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
index 0ac54fa..7941e9f 100755
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
@@ -41,7 +41,7 @@ import static junit.framework.Assert.assertTrue;
 
 public class ADCTestCase extends PythonAgentIntegrationTest {
     private static final Log log = LogFactory.getLog(ADCTestCase.class);
-    private static final int ADC_TIMEOUT = 180000;
+    private static final int ADC_TIMEOUT = 300000;
     private static final String APPLICATION_PATH = "/tmp/ADCTestCase";
     private static final String CLUSTER_ID = "tomcat.domain";
     private static final String DEPLOYMENT_POLICY_NAME = "deployment-policy-2";

http://git-wip-us.apache.org/repos/asf/stratos/blob/477686c6/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
index 0b6a063..5243b43 100755
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
@@ -23,8 +23,10 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.common.domain.LoadBalancingIPType;
 import org.apache.stratos.messaging.domain.topology.*;
+import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.event.topology.CompleteTopologyEvent;
 import org.apache.stratos.messaging.event.topology.MemberInitializedEvent;
+import org.apache.stratos.messaging.listener.instance.status.InstanceActivatedEventListener;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -36,7 +38,7 @@ import java.util.Properties;
 
 public class AgentStartupTestCase extends PythonAgentIntegrationTest {
     private static final Log log = LogFactory.getLog(AgentStartupTestCase.class);
-    private static final int STARTUP_TIMEOUT = 180000;
+    private static final int STARTUP_TIMEOUT = 300000;
     private static final String CLUSTER_ID = "php.php.domain";
     private static final String DEPLOYMENT_POLICY_NAME = "deployment-policy-1";
     private static final String AUTOSCALING_POLICY_NAME = "autoscaling-policy-1";
@@ -48,6 +50,8 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest {
     private static final String TENANT_ID = "-1234";
     private static final String SERVICE_NAME = "php";
     private boolean startupTestCompleted = false;
+    private boolean topologyContextTestCompleted = false;
+    private Topology topology = createTestTopology();
 
     public AgentStartupTestCase() throws IOException {
     }
@@ -74,7 +78,8 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest {
         tearDown();
     }
 
-    @Test(timeOut = STARTUP_TIMEOUT)
+    @Test(timeOut = STARTUP_TIMEOUT, description = "Test PCA initialization, activation, health stat publishing and " +
+            "topology context update", groups = {"smoke"})
     public void testPythonCartridgeAgent() {
         startCommunicatorThread();
         Thread startupTestThread = new Thread(new Runnable() {
@@ -92,7 +97,6 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest {
                                 sleep(2000);
                                 // Send complete topology event
                                 log.info("Publishing complete topology event...");
-                                Topology topology = createTestTopology();
                                 CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology);
                                 publishEvent(completeTopologyEvent);
                                 log.info("Complete topology event published");
@@ -106,10 +110,15 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest {
                                 publishEvent(memberInitializedEvent);
                                 log.info("Member initialized event published");
                             }
-                            // TODO: properly mock the CEP server
+
                             if (line.contains("Published event to thrift stream")) {
                                 startupTestCompleted = true;
                             }
+
+                            // assert topology context update
+                            if (line.contains("Topology context update test passed!")) {
+                                topologyContextTestCompleted = true;
+                            }
                         }
                     }
                     sleep(1000);
@@ -119,7 +128,20 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest {
 
         startupTestThread.start();
 
-        while (!instanceStarted || !instanceActivated || !startupTestCompleted) {
+        instanceStatusEventReceiver.addEventListener(new InstanceActivatedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                log.info("Publishing complete topology with a new member...");
+                Member newMember = new Member(SERVICE_NAME, CLUSTER_ID, "new-member", CLUSTER_INSTANCE_ID,
+                        NETWORK_PARTITION_ID, PARTITION_ID, LoadBalancingIPType.Private, System.currentTimeMillis());
+                topology.getService(SERVICE_NAME).getCluster(CLUSTER_ID).addMember(newMember);
+                CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology);
+                publishEvent(completeTopologyEvent);
+                log.info("Complete topology event published with new member");
+            }
+        });
+
+        while (!instanceStarted || !instanceActivated || !startupTestCompleted || !topologyContextTestCompleted) {
             // wait until the instance activated event is received.
             // this will assert whether instance got activated within timeout period; no need for explicit assertions
             sleep(2000);

http://git-wip-us.apache.org/repos/asf/stratos/blob/477686c6/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
index 96ade59..f0d94d0 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
@@ -335,6 +335,21 @@ public class PythonAgentIntegrationTest {
             String destPayloadPath = destAgentPath + PATH_SEP + "payload";
             FileUtils.copyDirectory(new File(srcPayloadPath), new File(destPayloadPath));
 
+            // copy extensions directory if it exists
+            String srcExtensionPath = getTestCaseResourcesPath() + PATH_SEP + "extensions" + PATH_SEP + "bash";
+            File extensionsDirFile = new File(srcExtensionPath);
+            if (extensionsDirFile.exists()) {
+                FileUtils.copyDirectory(extensionsDirFile,
+                        new File(destAgentPath + PATH_SEP + "extensions" + PATH_SEP + "bash"));
+            }
+
+            // copy plugins directory if it exists
+            String srcPluginPath = getTestCaseResourcesPath() + PATH_SEP + "extensions" + PATH_SEP + "py";
+            File pluginsDirFile = new File(srcPluginPath);
+            if (pluginsDirFile.exists()) {
+                FileUtils.copyDirectory(pluginsDirFile, new File(destAgentPath + PATH_SEP + "plugins"));
+            }
+
             File extensionsPath = new File(destAgentPath + PATH_SEP + "extensions" + PATH_SEP + "bash");
             File[] extensions = extensionsPath.listFiles();
             log.info("Changing extension scripts permissions in: " + extensionsPath.getAbsolutePath());

http://git-wip-us.apache.org/repos/asf/stratos/blob/477686c6/products/python-cartridge-agent/modules/integration/test-integration/src/test/resources/AgentStartupTestCase/extensions/py/startup-test-handler.py
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/resources/AgentStartupTestCase/extensions/py/startup-test-handler.py b/products/python-cartridge-agent/modules/integration/test-integration/src/test/resources/AgentStartupTestCase/extensions/py/startup-test-handler.py
new file mode 100644
index 0000000..f220dc2
--- /dev/null
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/resources/AgentStartupTestCase/extensions/py/startup-test-handler.py
@@ -0,0 +1,60 @@
+# ------------------------------------------------------------------------
+#
+# Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
+#
+# Licensed 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
+#
+# ------------------------------------------------------------------------
+
+from plugins.contracts import ICartridgeAgentPlugin
+from modules.util.log import LogFactory
+from entity import *
+import time
+from threading import Thread
+
+
+class StartupTestHandler(ICartridgeAgentPlugin):
+    log = LogFactory().get_log(__name__)
+
+    def run_plugin(self, values):
+        StartupTestHandler.log.info("Topology: %r" % TopologyContext.topology.json_str)
+        thread = Thread(target=self.threaded_function)
+        thread.start()
+
+    def threaded_function(self):
+        memberFound = False
+        service_name = "php"
+        cluster_id = "php.php.domain"
+        member_id = "new-member"
+
+        while (not memberFound):
+            StartupTestHandler.log.info("Checking topology for new member...")
+            StartupTestHandler.log.info("Topology: %r" % TopologyContext.topology.json_str)
+            service = TopologyContext.topology.get_service(service_name)
+            if service is None:
+                StartupTestHandler.log.error("Service not found in topology [service] %r" % service_name)
+                return False
+
+            cluster = service.get_cluster(cluster_id)
+            if cluster is None:
+                StartupTestHandler.log.error("Cluster id not found in topology [cluster] %r" % cluster_id)
+                return False
+            StartupTestHandler.log.info("Member found in cluster: %r" % cluster.member_exists(member_id))
+
+            new_member = cluster.get_member(member_id)
+            if (new_member is not None):
+                StartupTestHandler.log.info("new-member was found in topology: %r" % new_member.to_json())
+                memberFound = True
+            time.sleep(5)
+
+        StartupTestHandler.log.info("Topology context update test passed!")

http://git-wip-us.apache.org/repos/asf/stratos/blob/477686c6/products/python-cartridge-agent/modules/integration/test-integration/src/test/resources/AgentStartupTestCase/extensions/py/startup-test-handler.yapsy-plugin
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/resources/AgentStartupTestCase/extensions/py/startup-test-handler.yapsy-plugin b/products/python-cartridge-agent/modules/integration/test-integration/src/test/resources/AgentStartupTestCase/extensions/py/startup-test-handler.yapsy-plugin
new file mode 100644
index 0000000..8bad385
--- /dev/null
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/resources/AgentStartupTestCase/extensions/py/startup-test-handler.yapsy-plugin
@@ -0,0 +1,27 @@
+# ------------------------------------------------------------------------
+#
+# Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
+#
+# Licensed 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
+#
+# ------------------------------------------------------------------------
+
+[Core]
+Name = startup-test-handler
+Module = startup-test-handler
+
+[Documentation]
+Description = InstanceActivatedEvent
+Author = Stratos
+Version = 0.1
+Website = stratos.apache.org