{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/comments/45583355","id":45583355,"diff_hunk":"@@ -0,0 +1,136 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+package org.apache.brooklyn.entity.webapp;\n+\n+import com.google.common.collect.ImmutableList;\n+import org.apache.brooklyn.api.entity.EntitySpec;\n+import org.apache.brooklyn.api.location.ProvisioningLocation;\n+import org.apache.brooklyn.core.effector.Effectors;\n+import org.apache.brooklyn.core.entity.Attributes;\n+import org.apache.brooklyn.core.internal.BrooklynProperties;\n+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;\n+import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;\n+import org.apache.brooklyn.entity.software.base.AllowsMigration;\n+import org.apache.brooklyn.test.EntityTestUtils;\n+import org.apache.brooklyn.test.HttpTestUtils;\n+import org.apache.brooklyn.test.support.TestResourceUnavailableException;\n+import org.apache.brooklyn.util.collections.MutableMap;\n+import org.reflections.Reflections;\n+import org.testng.annotations.BeforeMethod;\n+import org.testng.annotations.DataProvider;\n+import org.testng.annotations.Test;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.Set;\n+\n+// This test could extend AbstractEc2LiveTest but then it will not be able to be parametrized properly.\n+public class WebAppMigrationLiveTest extends BrooklynAppLiveTestSupport {\n+    private static final String PROVIDER = \"aws-ec2\";\n+    private static final String REGION_NAME = \"us-west-2\";\n+    private static final String LOCATION_SPEC = PROVIDER + (REGION_NAME == null ? \"\" : \":\" + REGION_NAME);\n+\n+    private BrooklynProperties brooklynProperties;\n+    private ProvisioningLocation amazonProvisioningLocation;\n+\n+    @Override\n+    @BeforeMethod(alwaysRun = true)\n+    public void setUp() throws Exception {\n+        brooklynProperties = BrooklynProperties.Factory.newDefault();\n+\n+        // EC2 setup obtained from AbstractEc2LiveTest\n+        brooklynProperties.remove(\"brooklyn.jclouds.\" + PROVIDER + \".image-description-regex\");\n+        brooklynProperties.remove(\"brooklyn.jclouds.\" + PROVIDER + \".image-name-regex\");\n+        brooklynProperties.remove(\"brooklyn.jclouds.\" + PROVIDER + \".image-id\");\n+        brooklynProperties.remove(\"brooklyn.jclouds.\" + PROVIDER + \".inboundPorts\");\n+        brooklynProperties.remove(\"brooklyn.jclouds.\" + PROVIDER + \".hardware-id\");\n+\n+        // Also removes scriptHeader (e.g. if doing `. ~/.bashrc` and `. ~/.profile`, then that can cause \"stdin: is not a tty\")\n+        brooklynProperties.remove(\"brooklyn.ssh.config.scriptHeader\");\n+        mgmt = new LocalManagementContextForTests(brooklynProperties);\n+        amazonProvisioningLocation = (ProvisioningLocation) mgmt.getLocationRegistry().resolve(LOCATION_SPEC);\n+        super.setUp();\n+    }\n+\n+    @DataProvider(name = \"webAppEntities\")\n+    public Object[][] webAppEntities() {\n+        Object[][] dataProviderResult;\n+\n+        Reflections reflections = new Reflections(\"org.apache.brooklyn.entity.webapp\");\n+        Set<Class<? extends JavaWebAppSoftwareProcess>> reflectionsSubTypesOfJavaWebAppSoftwareProcess =\n+                reflections.getSubTypesOf(org.apache.brooklyn.entity.webapp.JavaWebAppSoftwareProcess.class);\n+\n+        List<Object[]> webAppEntities = getEntitiesFromClasses(reflectionsSubTypesOfJavaWebAppSoftwareProcess);\n+        dataProviderResult = new Object[webAppEntities.size()][];\n+        webAppEntities.toArray(dataProviderResult);\n+\n+        return dataProviderResult;\n+    }\n+\n+\n+    private List<Object[]> getEntitiesFromClasses(Set<Class<? extends JavaWebAppSoftwareProcess>> clazzSet) {\n+        ArrayList<Object[]> entitiyList = new ArrayList<>();\n+\n+        for (Class clazz : clazzSet) {\n+            if (clazz.isInterface() && !clazz.getName().contains(\"JavaWebAppSoftwareProcess\")) {\n+                EntitySpec entity = EntitySpec.create(clazz);\n+                entitiyList.add(new Object[]{entity});\n+            }\n+\n+        }\n+\n+\n+        return entitiyList;\n+    }\n+\n+    private String getTestWar() {\n+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), \"/hello-world.war\");\n+        return \"classpath://hello-world.war\";\n+    }\n+\n+    @Test(groups = \"Live\", dataProvider = \"webAppEntities\")\n+    public void testMigration(EntitySpec<? extends JavaWebAppSoftwareProcess> webServerSpec) throws Exception {\n+        final JavaWebAppSoftwareProcess server = app.createAndManageChild(webServerSpec\n+                .addInitializer(new JavaWebAppMigrateEffector())\n+                .configure(JavaWebAppSoftwareProcess.OPEN_IPTABLES, true)\n+                .configure(\"war\", getTestWar()));\n+\n+        // Run the webserver in the premigration location\n+        app.start(ImmutableList.of(amazonProvisioningLocation));\n+        EntityTestUtils.assertAttributeEqualsEventually(server, Attributes.SERVICE_UP, Boolean.TRUE);\n+\n+        // Check if the WebServer is reachable in the premigration location\n+        String preMigrationUrl = server.getAttribute(JavaWebAppSoftwareProcess.ROOT_URL);\n+        HttpTestUtils.assertUrlReachable(preMigrationUrl);\n+\n+        // Start the migration process\n+        Effectors.invocation(AllowsMigration.MIGRATE, MutableMap.of(\"locationSpec\", LOCATION_SPEC), server).asTask().blockUntilEnded();","path":"software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/WebAppMigrationLiveTest.java","position":123,"original_position":123,"commit_id":"d6a226535b95f5706ce1c1903bee6bd173ed8f7e","original_commit_id":"d6a226535b95f5706ce1c1903bee6bd173ed8f7e","user":{"login":"adriannieto","id":7558172,"avatar_url":"https://avatars.githubusercontent.com/u/7558172?v=3","gravatar_id":"","url":"https://api.github.com/users/adriannieto","html_url":"https://github.com/adriannieto","followers_url":"https://api.github.com/users/adriannieto/followers","following_url":"https://api.github.com/users/adriannieto/following{/other_user}","gists_url":"https://api.github.com/users/adriannieto/gists{/gist_id}","starred_url":"https://api.github.com/users/adriannieto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adriannieto/subscriptions","organizations_url":"https://api.github.com/users/adriannieto/orgs","repos_url":"https://api.github.com/users/adriannieto/repos","events_url":"https://api.github.com/users/adriannieto/events{/privacy}","received_events_url":"https://api.github.com/users/adriannieto/received_events","type":"User","site_admin":false},"body":"Done.","created_at":"2015-11-23T09:25:41Z","updated_at":"2015-11-23T09:25:41Z","html_url":"https://github.com/apache/incubator-brooklyn/pull/924#discussion_r45583355","pull_request_url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/924","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/comments/45583355"},"html":{"href":"https://github.com/apache/incubator-brooklyn/pull/924#discussion_r45583355"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/924"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/924","id":46157683,"html_url":"https://github.com/apache/incubator-brooklyn/pull/924","diff_url":"https://github.com/apache/incubator-brooklyn/pull/924.diff","patch_url":"https://github.com/apache/incubator-brooklyn/pull/924.patch","issue_url":"https://api.github.com/repos/apache/incubator-brooklyn/issues/924","number":924,"state":"open","locked":false,"title":"Added basic migration capability to org.apache.brooklyn.entity.webapp.*","user":{"login":"adriannieto","id":7558172,"avatar_url":"https://avatars.githubusercontent.com/u/7558172?v=3","gravatar_id":"","url":"https://api.github.com/users/adriannieto","html_url":"https://github.com/adriannieto","followers_url":"https://api.github.com/users/adriannieto/followers","following_url":"https://api.github.com/users/adriannieto/following{/other_user}","gists_url":"https://api.github.com/users/adriannieto/gists{/gist_id}","starred_url":"https://api.github.com/users/adriannieto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adriannieto/subscriptions","organizations_url":"https://api.github.com/users/adriannieto/orgs","repos_url":"https://api.github.com/users/adriannieto/repos","events_url":"https://api.github.com/users/adriannieto/events{/privacy}","received_events_url":"https://api.github.com/users/adriannieto/received_events","type":"User","site_admin":false},"body":"This PR adds an Effector migrate(locationSpec) to Entities that override JavaWebAppSoftwareProcess. This Effector moves the Entity to a new location. Currently it doesn't support nested entities to be migrated. \r\n\r\nThis is a work in progress feature, my plan is to extend this support to non-clustered databases in the future.","created_at":"2015-09-28T13:41:19Z","updated_at":"2015-11-23T09:25:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a1cadfffdf5f3725b088c5b74c800dd11d5e4cd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/924/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/924/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-brooklyn/issues/924/comments","statuses_url":"https://api.github.com/repos/apache/incubator-brooklyn/statuses/d6a226535b95f5706ce1c1903bee6bd173ed8f7e","head":{"label":"adriannieto:feature/basic-migration","ref":"feature/basic-migration","sha":"d6a226535b95f5706ce1c1903bee6bd173ed8f7e","user":{"login":"adriannieto","id":7558172,"avatar_url":"https://avatars.githubusercontent.com/u/7558172?v=3","gravatar_id":"","url":"https://api.github.com/users/adriannieto","html_url":"https://github.com/adriannieto","followers_url":"https://api.github.com/users/adriannieto/followers","following_url":"https://api.github.com/users/adriannieto/following{/other_user}","gists_url":"https://api.github.com/users/adriannieto/gists{/gist_id}","starred_url":"https://api.github.com/users/adriannieto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adriannieto/subscriptions","organizations_url":"https://api.github.com/users/adriannieto/orgs","repos_url":"https://api.github.com/users/adriannieto/repos","events_url":"https://api.github.com/users/adriannieto/events{/privacy}","received_events_url":"https://api.github.com/users/adriannieto/received_events","type":"User","site_admin":false},"repo":{"id":34790253,"name":"incubator-brooklyn","full_name":"adriannieto/incubator-brooklyn","owner":{"login":"adriannieto","id":7558172,"avatar_url":"https://avatars.githubusercontent.com/u/7558172?v=3","gravatar_id":"","url":"https://api.github.com/users/adriannieto","html_url":"https://github.com/adriannieto","followers_url":"https://api.github.com/users/adriannieto/followers","following_url":"https://api.github.com/users/adriannieto/following{/other_user}","gists_url":"https://api.github.com/users/adriannieto/gists{/gist_id}","starred_url":"https://api.github.com/users/adriannieto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adriannieto/subscriptions","organizations_url":"https://api.github.com/users/adriannieto/orgs","repos_url":"https://api.github.com/users/adriannieto/repos","events_url":"https://api.github.com/users/adriannieto/events{/privacy}","received_events_url":"https://api.github.com/users/adriannieto/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/adriannieto/incubator-brooklyn","description":"Mirror of Apache Brooklyn","fork":true,"url":"https://api.github.com/repos/adriannieto/incubator-brooklyn","forks_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/forks","keys_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/teams","hooks_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/hooks","issue_events_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/issues/events{/number}","events_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/events","assignees_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/assignees{/user}","branches_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/branches{/branch}","tags_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/tags","blobs_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/statuses/{sha}","languages_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/languages","stargazers_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/stargazers","contributors_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/contributors","subscribers_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/subscribers","subscription_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/subscription","commits_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/contents/{+path}","compare_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/merges","archive_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/downloads","issues_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/issues{/number}","pulls_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/pulls{/number}","milestones_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/milestones{/number}","notifications_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/labels{/name}","releases_url":"https://api.github.com/repos/adriannieto/incubator-brooklyn/releases{/id}","created_at":"2015-04-29T11:33:34Z","updated_at":"2015-04-29T11:33:44Z","pushed_at":"2015-10-19T10:45:50Z","git_url":"git://github.com/adriannieto/incubator-brooklyn.git","ssh_url":"git@github.com:adriannieto/incubator-brooklyn.git","clone_url":"https://github.com/adriannieto/incubator-brooklyn.git","svn_url":"https://github.com/adriannieto/incubator-brooklyn","homepage":null,"size":251589,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"388668abb768a71b7f6758958d16bf4874fe3c19","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":19368221,"name":"incubator-brooklyn","full_name":"apache/incubator-brooklyn","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-brooklyn","description":"Mirror of Apache Brooklyn","fork":false,"url":"https://api.github.com/repos/apache/incubator-brooklyn","forks_url":"https://api.github.com/repos/apache/incubator-brooklyn/forks","keys_url":"https://api.github.com/repos/apache/incubator-brooklyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-brooklyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-brooklyn/teams","hooks_url":"https://api.github.com/repos/apache/incubator-brooklyn/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-brooklyn/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-brooklyn/events","assignees_url":"https://api.github.com/repos/apache/incubator-brooklyn/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-brooklyn/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-brooklyn/tags","blobs_url":"https://api.github.com/repos/apache/incubator-brooklyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-brooklyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-brooklyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-brooklyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-brooklyn/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-brooklyn/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-brooklyn/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-brooklyn/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-brooklyn/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-brooklyn/subscription","commits_url":"https://api.github.com/repos/apache/incubator-brooklyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-brooklyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-brooklyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-brooklyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-brooklyn/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-brooklyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-brooklyn/merges","archive_url":"https://api.github.com/repos/apache/incubator-brooklyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-brooklyn/downloads","issues_url":"https://api.github.com/repos/apache/incubator-brooklyn/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-brooklyn/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-brooklyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-brooklyn/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-brooklyn/releases{/id}","created_at":"2014-05-02T07:00:07Z","updated_at":"2015-11-19T05:46:35Z","pushed_at":"2015-11-23T01:00:26Z","git_url":"git://github.com/apache/incubator-brooklyn.git","ssh_url":"git@github.com:apache/incubator-brooklyn.git","clone_url":"https://github.com/apache/incubator-brooklyn.git","svn_url":"https://github.com/apache/incubator-brooklyn","homepage":null,"size":256841,"stargazers_count":125,"watchers_count":125,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":97,"mirror_url":"git://git.apache.org/incubator-brooklyn.git","open_issues_count":21,"forks":97,"open_issues":21,"watchers":125,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/924"},"html":{"href":"https://github.com/apache/incubator-brooklyn/pull/924"},"issue":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/issues/924"},"comments":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/issues/924/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/924/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/924/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/statuses/d6a226535b95f5706ce1c1903bee6bd173ed8f7e"}}}}