You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/02/10 16:23:51 UTC

stratos git commit: Updating python cartridge agent automation test and introducing maven profile live

Repository: stratos
Updated Branches:
  refs/heads/master 7f2182556 -> 1007ef752


Updating python cartridge agent automation test and introducing maven profile live


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

Branch: refs/heads/master
Commit: 1007ef7522ebfcc76c8025e5632790d642ad65e5
Parents: 7f21825
Author: Imesh Gunaratne <im...@apache.org>
Authored: Tue Feb 10 20:53:44 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Tue Feb 10 20:53:44 2015 +0530

----------------------------------------------------------------------
 .../pom.xml                                     | 39 +++++++++++-
 .../src/main/resources/cloud-services-desc.xml  | 20 ++++++
 .../test/PythonCartridgeAgentTest.java          | 66 +++++++++++++++-----
 .../src/test/resources/payload/launch-params    |  2 +-
 4 files changed, 109 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/1007ef75/components/org.apache.stratos.python.cartridge.agent.test/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent.test/pom.xml b/components/org.apache.stratos.python.cartridge.agent.test/pom.xml
index ef7a49d..d912683 100644
--- a/components/org.apache.stratos.python.cartridge.agent.test/pom.xml
+++ b/components/org.apache.stratos.python.cartridge.agent.test/pom.xml
@@ -26,9 +26,46 @@
 
     <modelVersion>4.0.0</modelVersion>
     <artifactId>org.apache.stratos.python.cartridge.agent.test</artifactId>
-    <packaging>pom</packaging>
+    <packaging>bundle</packaging>
     <name>Apache Stratos - Python Cartridge Agent Tests</name>
 
+    <profiles>
+        <profile>
+            <id>live</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <includes>
+                                <include>**/*/PythonCartridgeAgentTest.java</include>
+                            </includes>
+                            <systemPropertyVariables></systemPropertyVariables>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Name>${project.artifactId}</Bundle-Name>
+                        <DynamicImport-Package>*</DynamicImport-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
     <dependencies>
         <dependency>
              <groupId>junit</groupId>

http://git-wip-us.apache.org/repos/asf/stratos/blob/1007ef75/components/org.apache.stratos.python.cartridge.agent.test/src/main/resources/cloud-services-desc.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent.test/src/main/resources/cloud-services-desc.xml b/components/org.apache.stratos.python.cartridge.agent.test/src/main/resources/cloud-services-desc.xml
new file mode 100644
index 0000000..98cabe1
--- /dev/null
+++ b/components/org.apache.stratos.python.cartridge.agent.test/src/main/resources/cloud-services-desc.xml
@@ -0,0 +1,20 @@
+<!-- 
+  #  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.
+  -->
+<cloudServices xmlns="http://wso2.com/carbon/cloud/mgt/services">
+</cloudServices>

http://git-wip-us.apache.org/repos/asf/stratos/blob/1007ef75/components/org.apache.stratos.python.cartridge.agent.test/src/test/java/org/apache/stratos/python.cartridge.agent/test/PythonCartridgeAgentTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent.test/src/test/java/org/apache/stratos/python.cartridge.agent/test/PythonCartridgeAgentTest.java b/components/org.apache.stratos.python.cartridge.agent.test/src/test/java/org/apache/stratos/python.cartridge.agent/test/PythonCartridgeAgentTest.java
index 29df956..ba1128b 100644
--- a/components/org.apache.stratos.python.cartridge.agent.test/src/test/java/org/apache/stratos/python.cartridge.agent/test/PythonCartridgeAgentTest.java
+++ b/components/org.apache.stratos.python.cartridge.agent.test/src/test/java/org/apache/stratos/python.cartridge.agent/test/PythonCartridgeAgentTest.java
@@ -42,17 +42,27 @@ import java.util.List;
 import java.util.Properties;
 import java.util.UUID;
 
+import static junit.framework.Assert.assertTrue;
+
 public class PythonCartridgeAgentTest {
 
     private static final Log log = LogFactory.getLog(PythonCartridgeAgentTest.class);
 
     private static final String NEW_LINE = System.getProperty("line.separator");
+    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";
+    private static final String APP_ID = "application-1";
+    private static final String MEMBER_ID = "php.member-1";
+    private static final String CLUSTER_INSTANCE_ID = "cluster-1-instance-1";
+    private static final String NETWORK_PARTITION_ID = "network-partition-1";
+    private static final String PARTITION_ID = "partition-1";
+    private static final String TENANT_ID = "-1234";
 
     @BeforeClass
     public static void setUp(){
-        // Set jndi.properties.dir system property for initializing event receivers
+        // Set jndi.properties.dir system property for initializing event publishers and receivers
         System.setProperty("jndi.properties.dir", getResourcesFolderPath());
-        System.setProperty("mqtturl", "tcp://localhost:1883");
     }
 
     private static String getResourcesFolderPath() {
@@ -60,7 +70,7 @@ public class PythonCartridgeAgentTest {
         return StringUtils.removeEnd(path, File.separator);
     }
 
-    @Test
+    @Test(timeout = 300000)
     public void testPythonCartridgeAgent() {
 
         // Simulate CEP server socket
@@ -87,24 +97,27 @@ public class PythonCartridgeAgentTest {
                     }
                     if(line.contains("Artifact repository found")) {
                         ArtifactUpdatedEvent artifactUpdatedEvent = new ArtifactUpdatedEvent();
-                        artifactUpdatedEvent.setClusterId("php.php.domain");
-                        artifactUpdatedEvent.setTenantId("-1234");
+                        artifactUpdatedEvent.setClusterId(CLUSTER_ID);
+                        artifactUpdatedEvent.setTenantId(TENANT_ID);
                         artifactUpdatedEvent.setRepoURL("https://github.com/imesh/stratos-php-applications.git");
                         String topicName = MessagingUtil.getMessageTopicName(artifactUpdatedEvent);
                         EventPublisher eventPublisher = EventPublisherPool.getPublisher(topicName);
                         eventPublisher.publish(artifactUpdatedEvent);
                     }
-                    if (newLines.contains("Exception in thread") || newLines.contains("ERROR")) {
+                    if (line.contains("Exception in thread") || line.contains("ERROR")) {
                         break;
                     }
 
+                    if(line.contains("Git clone operation for tenant u'" + TENANT_ID + "' successful")) {
+                        assertTrue(true);
+                        return;
+                    }
+
                     log.info(line);
                 }
             }
             sleep(500);
         }
-
-        sleep(5000);
     }
 
     private void startServerSocket(final int port) {
@@ -122,17 +135,21 @@ public class PythonCartridgeAgentTest {
         socketThread.start();
     }
 
+    /**
+     * Create test topology
+     * @return
+     */
     private Topology createTestTopology() {
         Topology topology = new Topology();
         Service service = new Service("php", ServiceType.SingleTenant);
         topology.addService(service);
 
-        Cluster cluster = new Cluster(service.getServiceName(), "php.php.domain", "deployment-policy-1",
-                "autoscaling-policy-1", "application-1");
+        Cluster cluster = new Cluster(service.getServiceName(), CLUSTER_ID, DEPLOYMENT_POLICY_NAME,
+                AUTOSCALING_POLICY_NAME, APP_ID);
         service.addCluster(cluster);
 
-        Member member = new Member(service.getServiceName(), cluster.getClusterId(), "php.member-1",
-                "cluster-1-instance-1", "network-partition-1", "partition-1", System.currentTimeMillis());
+        Member member = new Member(service.getServiceName(), cluster.getClusterId(), MEMBER_ID,
+                CLUSTER_INSTANCE_ID, NETWORK_PARTITION_ID, PARTITION_ID, System.currentTimeMillis());
         member.setDefaultPrivateIP("10.0.0.1");
         member.setDefaultPublicIP("20.0.0.1");
         Properties properties = new Properties();
@@ -144,15 +161,21 @@ public class PythonCartridgeAgentTest {
         return topology;
     }
 
-    private List<String> getNewLines(List<String> outputLines, String output) {
+    /**
+     * Return new lines found in the output
+     * @param currentOutputLines current output lines
+     * @param output output
+     * @return
+     */
+    private List<String> getNewLines(List<String> currentOutputLines, String output) {
         List<String> newLines = new ArrayList<String>();
 
         if(StringUtils.isNotBlank(output)) {
             String [] lines = output.split(NEW_LINE);
             if(lines != null) {
                 for(String line : lines) {
-                    if(!outputLines.contains(line)) {
-                        outputLines.add(line);
+                    if(!currentOutputLines.contains(line)) {
+                        currentOutputLines.add(line);
                         newLines.add(line);
                     }
                 }
@@ -161,6 +184,10 @@ public class PythonCartridgeAgentTest {
         return newLines;
     }
 
+    /**
+     * Sleep current thread
+     * @param time
+     */
     private void sleep(long time) {
         try {
             Thread.sleep(time);
@@ -168,6 +195,10 @@ public class PythonCartridgeAgentTest {
         }
     }
 
+    /**
+     * Copy python agent distribution to a new folder, extract it and copy sample configuration files
+     * @return
+     */
     private String setupPythonAgent() {
         try {
             log.info("Setting up python cartridge agent...");
@@ -219,7 +250,7 @@ public class PythonCartridgeAgentTest {
 
                 @Override
                 public void onProcessFailed(ExecuteException e) {
-                    log.error(e);
+                    log.error("Process failed", e);
                 }
             });
             return outputStream;
@@ -229,6 +260,9 @@ public class PythonCartridgeAgentTest {
         }
     }
 
+    /**
+     * Implements isClosed() method
+     */
     private class ByteArrayOutputStreamLocal extends ByteArrayOutputStream  {
         private boolean closed;
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/1007ef75/components/org.apache.stratos.python.cartridge.agent.test/src/test/resources/payload/launch-params
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent.test/src/test/resources/payload/launch-params b/components/org.apache.stratos.python.cartridge.agent.test/src/test/resources/payload/launch-params
index 1f44a28..858d622 100644
--- a/components/org.apache.stratos.python.cartridge.agent.test/src/test/resources/payload/launch-params
+++ b/components/org.apache.stratos.python.cartridge.agent.test/src/test/resources/payload/launch-params
@@ -1 +1 @@
-APPLICATION_ID=application1,SERVICE_NAME=php,HOST_NAME=php.php.stratos.org,MULTITENANT=false,TENANT_ID=-1234,TENANT_RANGE=*,CARTRIDGE_ALIAS=php,CLUSTER_ID=php.php.domain,CLUSTER_INSTANCE_ID=single-cartridge-app-1,CARTRIDGE_KEY=PUjpXCLujDhYr5A6,DEPLOYMENT=default,REPO_URL=https://github.com/imesh/stratos-php-applications.git,PORTS=9080,PUPPET_IP=127.0.0.1,PUPPET_HOSTNAME=puppet.apache.stratos.org,PUPPET_ENV=false,MEMBER_ID=php.member-1,LB_CLUSTER_ID=null,NETWORK_PARTITION_ID=network-p1,PARTITION_ID=p1,APPLICATION_PATH=/tmp/stratos/app/path/,MIN_COUNT=1,INTERNAL=false,CLUSTERING_PRIMARY_KEY=A,LOG_FILE_PATHS=/tmp/temp.log,PERSISTENCE_MAPPING=null,MP_IP=192.168.1.4,MB_PORT=1883
\ No newline at end of file
+APPLICATION_ID=application1,SERVICE_NAME=php,HOST_NAME=php.php.stratos.org,MULTITENANT=false,TENANT_ID=-1234,TENANT_RANGE=*,CARTRIDGE_ALIAS=php,CLUSTER_ID=php.php.domain,CLUSTER_INSTANCE_ID=single-cartridge-app-1,CARTRIDGE_KEY=PUjpXCLujDhYr5A6,DEPLOYMENT=default,REPO_URL=https://github.com/imesh/stratos-php-applications.git,PORTS=9080,PUPPET_IP=127.0.0.1,PUPPET_HOSTNAME=puppet.apache.stratos.org,PUPPET_ENV=false,MEMBER_ID=php.member-1,LB_CLUSTER_ID=null,NETWORK_PARTITION_ID=network-p1,PARTITION_ID=p1,APPLICATION_PATH=/tmp/stratos-pca-test-app-path/,MIN_COUNT=1,INTERNAL=false,CLUSTERING_PRIMARY_KEY=A,LOG_FILE_PATHS=/tmp/temp.log,PERSISTENCE_MAPPING=null,MP_IP=192.168.1.4,MB_PORT=1883
\ No newline at end of file