You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ch...@apache.org on 2015/11/20 17:19:19 UTC

stratos git commit: Stratos Manager - test case for repo/notify

Repository: stratos
Updated Branches:
  refs/heads/stratos-4.1.x a709cbce1 -> 885bf563f


Stratos Manager - test case for repo/notify


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

Branch: refs/heads/stratos-4.1.x
Commit: 885bf563f5dc355893b95b57c06ddf676ba3e264
Parents: a709cbc
Author: Chamila de Alwis <ch...@apache.org>
Authored: Fri Nov 20 21:42:40 2015 +0530
Committer: Chamila de Alwis <ch...@apache.org>
Committed: Fri Nov 20 21:42:40 2015 +0530

----------------------------------------------------------------------
 .../integration/common/RestConstants.java       |   1 +
 .../integration/tests/adc/GitHookTestCase.java  | 129 +++++++++++++++++++
 .../application-policy-1.json                   |  17 +++
 .../git-hook-test/applications/application.json |  25 ++++
 .../autoscaling-policy-1.json                   |  14 ++
 .../git-hook-test/cartridges/mock/php.json      |  51 ++++++++
 .../deployment-policy-1.json                    |  15 +++
 .../test/resources/git-hook-test/hook-req.json  |   5 +
 .../mock/network-partition-1.json               |  15 +++
 9 files changed, 272 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/885bf563/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/RestConstants.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/RestConstants.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/RestConstants.java
index 1778bb9..76ca673 100644
--- a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/RestConstants.java
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/RestConstants.java
@@ -34,6 +34,7 @@ public class RestConstants {
     public static final String APPLICATIONS_RUNTIME = "/runtime";
     public static final String APPLICATIONS_DEPLOY = "/deploy";
     public static final String APPLICATIONS_UNDEPLOY = "/undeploy";
+    public static final String REPO_NOTIFY = "/" + API + "/repo/notify";
 
     public static final String AUTOSCALING_POLICIES_PATH = "/autoscaling-policies/";
     public static final String AUTOSCALING_POLICIES_NAME = "autoscalingPolicy";

http://git-wip-us.apache.org/repos/asf/stratos/blob/885bf563/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/adc/GitHookTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/adc/GitHookTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/adc/GitHookTestCase.java
new file mode 100644
index 0000000..e931f8a
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/adc/GitHookTestCase.java
@@ -0,0 +1,129 @@
+/*
+ * 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.
+ */
+
+package org.apache.stratos.integration.tests.adc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.threading.StratosThreadPool;
+import org.apache.stratos.integration.common.RestConstants;
+import org.apache.stratos.integration.tests.StratosIntegrationTest;
+import org.apache.stratos.messaging.event.Event;
+import org.apache.stratos.messaging.listener.instance.notifier.ArtifactUpdateEventListener;
+import org.apache.stratos.messaging.message.receiver.instance.notifier.InstanceNotifierEventReceiver;
+import org.testng.annotations.Test;
+
+import java.net.URI;
+import java.util.concurrent.ExecutorService;
+
+import static org.testng.AssertJUnit.assertTrue;
+
+/**
+ * Test case to test the /repo/notify endpoint
+ */
+public class GitHookTestCase extends StratosIntegrationTest {
+
+    private static Log log = LogFactory.getLog(GitHookTestCase.class);
+    private static final String RESOURCES_PATH = "/git-hook-test";
+    private int artifactUpdateEvents = 0;
+
+    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"adc", "smoke"})
+    public void sendRepoNotify() throws Exception {
+        deployArtifacts();
+        ExecutorService eventListenerExecutorService = StratosThreadPool.getExecutorService(
+                                                                            "stratos.integration.test.git.thread.pool",
+                                                                            5);
+        final InstanceNotifierEventReceiver instanceNotifierEventReceiver = new InstanceNotifierEventReceiver();
+        eventListenerExecutorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                instanceNotifierEventReceiver.execute();
+            }
+        });
+
+        ArtifactUpdateEventListener artifactUpdateEventListener = new ArtifactUpdateEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                artifactUpdateEvents++;
+            }
+        };
+
+        instanceNotifierEventReceiver.addEventListener(artifactUpdateEventListener);
+
+        String gitHookFile = "hook-req.json";
+        restClient.doPost(
+                new URI(stratosBackendURL + RestConstants.REPO_NOTIFY),
+                restClient.getJsonStringFromFile(RESOURCES_PATH + "/" + gitHookFile));
+
+        while (artifactUpdateEvents < 2) {
+            log.debug("Waiting till artifact updated comes in... ");
+            Thread.sleep(1000);
+        }
+    }
+
+    private void deployArtifacts() throws Exception {
+        String autoscalingPolicyFile = "autoscaling-policy-1";
+        boolean autoscalingPolicyAdded = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyFile + ".json",
+                RestConstants.AUTOSCALING_POLICIES,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
+        assertTrue(autoscalingPolicyAdded);
+
+        String cartridgeFile = "php";
+        boolean cartridgeAdded = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeFile + ".json",
+                RestConstants.CARTRIDGES,
+                RestConstants.CARTRIDGES_NAME);
+        assertTrue(cartridgeAdded);
+
+        String networkPartitionFiile = "network-partition-1";
+        boolean networkPartitionAdded = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + networkPartitionFiile + ".json",
+                RestConstants.NETWORK_PARTITIONS,
+                RestConstants.NETWORK_PARTITIONS_NAME);
+        assertTrue(networkPartitionAdded);
+
+        String depPolicyFile = "deployment-policy-1";
+        boolean deploymentPolicyAdded = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + depPolicyFile + ".json",
+                RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
+        assertTrue(deploymentPolicyAdded);
+
+        String applicationFile = "application";
+        boolean applicationAdded = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + applicationFile + ".json",
+                RestConstants.APPLICATIONS,
+                RestConstants.APPLICATIONS_NAME);
+        assertTrue(applicationAdded);
+
+        String appPolicyFile = "application-policy-1";
+        boolean appPolicyAdded = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + appPolicyFile + ".json",
+                RestConstants.APPLICATION_POLICIES,
+                RestConstants.APPLICATION_POLICIES_NAME);
+        assertTrue(appPolicyAdded);
+
+
+        boolean appDeployed = restClient.deployEntity(
+                RestConstants.APPLICATIONS + "/" + "single-cartridge-app" + RestConstants.APPLICATIONS_DEPLOY + "/" + appPolicyFile,
+                RestConstants.APPLICATIONS_NAME);
+        assertTrue(appDeployed);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/885bf563/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/application-policies/application-policy-1.json
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/application-policies/application-policy-1.json b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/application-policies/application-policy-1.json
new file mode 100644
index 0000000..417b94f
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/application-policies/application-policy-1.json
@@ -0,0 +1,17 @@
+{
+    "id": "application-policy-1",
+    "algorithm": "one-after-another",
+    "networkPartitions": [
+        "network-partition-1"
+    ],
+    "properties": [
+        {
+            "name": "key-1",
+            "value": "value-1"
+        },
+        {
+            "name": "key-2",
+            "value": "value-2"
+        }
+    ]
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/885bf563/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/applications/application.json
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/applications/application.json b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/applications/application.json
new file mode 100644
index 0000000..4043e4f
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/applications/application.json
@@ -0,0 +1,25 @@
+{
+    "applicationId": "single-cartridge-app",
+    "alias": "single-cartridge-app",
+    "multiTenant": false,
+    "components": {
+        "cartridges": [
+            {
+                "type": "php",
+                "cartridgeMin": 1,
+                "cartridgeMax": 5,
+                "subscribableInfo": {
+                    "alias": "my-php",
+                    "autoscalingPolicy": "autoscaling-policy-1",
+                    "deploymentPolicy": "deployment-policy-1",
+                    "artifactRepository": {
+                        "privateRepo": false,
+                        "repoUrl": "https://github.com/lakwarus/single-cartridge.git",
+                        "repoUsername": "",
+                        "repoPassword": ""
+                    }
+                }
+            }
+        ]
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/885bf563/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/autoscaling-policies/autoscaling-policy-1.json
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/autoscaling-policies/autoscaling-policy-1.json b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/autoscaling-policies/autoscaling-policy-1.json
new file mode 100644
index 0000000..e5ac700
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/autoscaling-policies/autoscaling-policy-1.json
@@ -0,0 +1,14 @@
+{
+    "id": "autoscaling-policy-1",
+    "loadThresholds": {
+        "requestsInFlight": {
+            "threshold": 20
+        },
+        "memoryConsumption": {
+            "threshold": 70
+        },
+        "loadAverage": {
+            "threshold": 70
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/885bf563/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/cartridges/mock/php.json
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/cartridges/mock/php.json b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/cartridges/mock/php.json
new file mode 100644
index 0000000..5d53e3a
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/cartridges/mock/php.json
@@ -0,0 +1,51 @@
+{
+    "type": "php",
+    "provider": "apache",
+    "category": "framework",
+    "host": "php.stratos.org",
+    "displayName": "php",
+    "description": "php Cartridge",
+    "version": "7",
+    "multiTenant": "false",
+    "portMapping": [
+        {
+            "name": "http-80",
+            "protocol": "http",
+            "port": "8080",
+            "proxyPort": "8280"
+        },
+        {
+            "name": "http-22",
+            "protocol": "tcp",
+            "port": "22",
+            "proxyPort": "8222"
+        }
+    ],
+    "deployment": {
+    },
+    "iaasProvider": [
+        {
+            "type": "mock",
+            "imageId": "RegionOne/b4ca55e3-58ab-4937-82ce-817ebd10240e",
+            "networkInterfaces": [
+                {
+                    "networkUuid": "b55f009a-1cc6-4b17-924f-4ae0ee18db5e"
+                }
+            ],
+            "property": [
+                {
+                    "name": "instanceType",
+                    "value": "RegionOne/aa5f45a2-c6d6-419d-917a-9dd2e3888594"
+                },
+                {
+                    "name": "keyPair",
+                    "value": "reka"
+                },
+                {
+                    "name": "securityGroups",
+                    "value": "default"
+                }
+            ]
+        }
+    ]
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/885bf563/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/deployment-policies/deployment-policy-1.json
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/deployment-policies/deployment-policy-1.json b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/deployment-policies/deployment-policy-1.json
new file mode 100644
index 0000000..a434226
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/deployment-policies/deployment-policy-1.json
@@ -0,0 +1,15 @@
+{
+    "id": "deployment-policy-1",
+    "networkPartitions": [
+        {
+            "id": "network-partition-1",
+            "partitionAlgo": "one-after-another",
+            "partitions": [
+                {
+                    "id": "partition-1",
+                    "partitionMax": 20
+                }
+            ]
+        }
+    ]
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/885bf563/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/hook-req.json
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/hook-req.json b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/hook-req.json
new file mode 100644
index 0000000..e6eceee
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/hook-req.json
@@ -0,0 +1,5 @@
+{
+  "repository":{
+    "url":"https://github.com/lakwarus/single-cartridge.git"
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/885bf563/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/network-partitions/mock/network-partition-1.json
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/network-partitions/mock/network-partition-1.json b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/network-partitions/mock/network-partition-1.json
new file mode 100644
index 0000000..466da28
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/resources/git-hook-test/network-partitions/mock/network-partition-1.json
@@ -0,0 +1,15 @@
+{
+    "id": "network-partition-1",
+    "provider": "mock",
+    "partitions": [
+        {
+            "id": "partition-1",
+            "property": [
+                {
+                    "name": "region",
+                    "value": "default"
+                }
+            ]
+        }
+    ]
+}