Return-Path: X-Original-To: apmail-brooklyn-dev-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6BDA518432 for ; Mon, 23 Nov 2015 09:25:59 +0000 (UTC) Received: (qmail 56343 invoked by uid 500); 23 Nov 2015 09:25:59 -0000 Delivered-To: apmail-brooklyn-dev-archive@brooklyn.apache.org Received: (qmail 56309 invoked by uid 500); 23 Nov 2015 09:25:59 -0000 Mailing-List: contact dev-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list dev@brooklyn.incubator.apache.org Received: (qmail 56293 invoked by uid 99); 23 Nov 2015 09:25:59 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Nov 2015 09:25:59 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id AC3F01A0B7A for ; Mon, 23 Nov 2015 09:25:58 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.553 X-Spam-Level: X-Spam-Status: No, score=-0.553 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.554, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 0-YSRb6uDL4N for ; Mon, 23 Nov 2015 09:25:44 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id B616A441C9 for ; Mon, 23 Nov 2015 09:25:43 +0000 (UTC) Received: (qmail 56035 invoked by uid 99); 23 Nov 2015 09:25:43 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Nov 2015 09:25:43 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F3D0ADFF41; Mon, 23 Nov 2015 09:25:42 +0000 (UTC) From: adriannieto To: dev@brooklyn.incubator.apache.org Reply-To: dev@brooklyn.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-brooklyn pull request: Added basic migration capability ... Content-Type: text/plain Message-Id: <20151123092542.F3D0ADFF41@git1-us-west.apache.org> Date: Mon, 23 Nov 2015 09:25:42 +0000 (UTC) Github user adriannieto commented on a diff in the pull request: https://github.com/apache/incubator-brooklyn/pull/924#discussion_r45583355 --- Diff: software/webapp/src/test/java/org/apache/brooklyn/entity/webapp/WebAppMigrationLiveTest.java --- @@ -0,0 +1,136 @@ +/* + * 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.brooklyn.entity.webapp; + +import com.google.common.collect.ImmutableList; +import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.api.location.ProvisioningLocation; +import org.apache.brooklyn.core.effector.Effectors; +import org.apache.brooklyn.core.entity.Attributes; +import org.apache.brooklyn.core.internal.BrooklynProperties; +import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport; +import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; +import org.apache.brooklyn.entity.software.base.AllowsMigration; +import org.apache.brooklyn.test.EntityTestUtils; +import org.apache.brooklyn.test.HttpTestUtils; +import org.apache.brooklyn.test.support.TestResourceUnavailableException; +import org.apache.brooklyn.util.collections.MutableMap; +import org.reflections.Reflections; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +// This test could extend AbstractEc2LiveTest but then it will not be able to be parametrized properly. +public class WebAppMigrationLiveTest extends BrooklynAppLiveTestSupport { + private static final String PROVIDER = "aws-ec2"; + private static final String REGION_NAME = "us-west-2"; + private static final String LOCATION_SPEC = PROVIDER + (REGION_NAME == null ? "" : ":" + REGION_NAME); + + private BrooklynProperties brooklynProperties; + private ProvisioningLocation amazonProvisioningLocation; + + @Override + @BeforeMethod(alwaysRun = true) + public void setUp() throws Exception { + brooklynProperties = BrooklynProperties.Factory.newDefault(); + + // EC2 setup obtained from AbstractEc2LiveTest + brooklynProperties.remove("brooklyn.jclouds." + PROVIDER + ".image-description-regex"); + brooklynProperties.remove("brooklyn.jclouds." + PROVIDER + ".image-name-regex"); + brooklynProperties.remove("brooklyn.jclouds." + PROVIDER + ".image-id"); + brooklynProperties.remove("brooklyn.jclouds." + PROVIDER + ".inboundPorts"); + brooklynProperties.remove("brooklyn.jclouds." + PROVIDER + ".hardware-id"); + + // Also removes scriptHeader (e.g. if doing `. ~/.bashrc` and `. ~/.profile`, then that can cause "stdin: is not a tty") + brooklynProperties.remove("brooklyn.ssh.config.scriptHeader"); + mgmt = new LocalManagementContextForTests(brooklynProperties); + amazonProvisioningLocation = (ProvisioningLocation) mgmt.getLocationRegistry().resolve(LOCATION_SPEC); + super.setUp(); + } + + @DataProvider(name = "webAppEntities") + public Object[][] webAppEntities() { + Object[][] dataProviderResult; + + Reflections reflections = new Reflections("org.apache.brooklyn.entity.webapp"); + Set> reflectionsSubTypesOfJavaWebAppSoftwareProcess = + reflections.getSubTypesOf(org.apache.brooklyn.entity.webapp.JavaWebAppSoftwareProcess.class); + + List webAppEntities = getEntitiesFromClasses(reflectionsSubTypesOfJavaWebAppSoftwareProcess); + dataProviderResult = new Object[webAppEntities.size()][]; + webAppEntities.toArray(dataProviderResult); + + return dataProviderResult; + } + + + private List getEntitiesFromClasses(Set> clazzSet) { + ArrayList entitiyList = new ArrayList<>(); + + for (Class clazz : clazzSet) { + if (clazz.isInterface() && !clazz.getName().contains("JavaWebAppSoftwareProcess")) { + EntitySpec entity = EntitySpec.create(clazz); + entitiyList.add(new Object[]{entity}); + } + + } + + + return entitiyList; + } + + private String getTestWar() { + TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/hello-world.war"); + return "classpath://hello-world.war"; + } + + @Test(groups = "Live", dataProvider = "webAppEntities") + public void testMigration(EntitySpec webServerSpec) throws Exception { + final JavaWebAppSoftwareProcess server = app.createAndManageChild(webServerSpec + .addInitializer(new JavaWebAppMigrateEffector()) + .configure(JavaWebAppSoftwareProcess.OPEN_IPTABLES, true) + .configure("war", getTestWar())); + + // Run the webserver in the premigration location + app.start(ImmutableList.of(amazonProvisioningLocation)); + EntityTestUtils.assertAttributeEqualsEventually(server, Attributes.SERVICE_UP, Boolean.TRUE); + + // Check if the WebServer is reachable in the premigration location + String preMigrationUrl = server.getAttribute(JavaWebAppSoftwareProcess.ROOT_URL); + HttpTestUtils.assertUrlReachable(preMigrationUrl); + + // Start the migration process + Effectors.invocation(AllowsMigration.MIGRATE, MutableMap.of("locationSpec", LOCATION_SPEC), server).asTask().blockUntilEnded(); --- End diff -- Done. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---