Repository: incubator-brooklyn Updated Branches: refs/heads/master 6d1e7ea38 -> e38b4b757
Support concurrent web app deploy effectors Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/d9a77018 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/d9a77018 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/d9a77018 Branch: refs/heads/master Commit: d9a770188f0437211af2d3e3f94e991d0901220a Parents: 6d1e7ea Author: Svetoslav Neykov <[email protected]> Authored: Wed Apr 22 17:23:41 2015 +0300 Committer: Svetoslav Neykov <[email protected]> Committed: Fri Apr 24 18:30:50 2015 +0300 ---------------------------------------------------------------------- .../entity/webapp/JavaWebAppSshDriver.java | 3 +- .../webapp/WebAppConcurrentDeployTest.java | 103 +++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d9a77018/software/webapp/src/main/java/brooklyn/entity/webapp/JavaWebAppSshDriver.java ---------------------------------------------------------------------- diff --git a/software/webapp/src/main/java/brooklyn/entity/webapp/JavaWebAppSshDriver.java b/software/webapp/src/main/java/brooklyn/entity/webapp/JavaWebAppSshDriver.java index da2af62..cd32b01 100644 --- a/software/webapp/src/main/java/brooklyn/entity/webapp/JavaWebAppSshDriver.java +++ b/software/webapp/src/main/java/brooklyn/entity/webapp/JavaWebAppSshDriver.java @@ -30,6 +30,7 @@ import brooklyn.location.basic.SshMachineLocation; import brooklyn.util.task.DynamicTasks; import brooklyn.util.task.Tasks; import brooklyn.util.task.ssh.SshTasks; +import brooklyn.util.text.Strings; import com.google.common.collect.ImmutableList; @@ -153,7 +154,7 @@ public abstract class JavaWebAppSshDriver extends JavaSoftwareProcessSshDriver i final String canonicalTargetName = getFilenameContextMapper().convertDeploymentTargetNameToFilename(targetName); final String dest = getDeployDir() + "/" + canonicalTargetName; //write to a .tmp so autodeploy is not triggered during upload - final String tmpDest = dest + ".tmp"; + final String tmpDest = dest + "." + Strings.makeRandomId(8) + ".tmp"; final String msg = String.format("deploying %s to %s:%s", new Object[]{url, getHostname(), dest}); log.info(entity + " " + msg); Tasks.setBlockingDetails(msg); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d9a77018/software/webapp/src/test/java/brooklyn/entity/webapp/WebAppConcurrentDeployTest.java ---------------------------------------------------------------------- diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/WebAppConcurrentDeployTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/WebAppConcurrentDeployTest.java new file mode 100644 index 0000000..72f36a8 --- /dev/null +++ b/software/webapp/src/test/java/brooklyn/entity/webapp/WebAppConcurrentDeployTest.java @@ -0,0 +1,103 @@ +/* + * 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 brooklyn.entity.webapp; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.Collection; + +import org.apache.http.client.HttpClient; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import brooklyn.entity.BrooklynAppUnitTestSupport; +import brooklyn.entity.basic.Attributes; +import brooklyn.entity.basic.BrooklynConfigKeys; +import brooklyn.entity.proxying.EntitySpec; +import brooklyn.entity.webapp.jboss.JBoss7Server; +import brooklyn.entity.webapp.tomcat.TomcatServer; +import brooklyn.location.Location; +import brooklyn.location.LocationSpec; +import brooklyn.location.basic.LocalhostMachineProvisioningLocation; +import brooklyn.management.Task; +import brooklyn.test.Asserts; +import brooklyn.test.EntityTestUtils; +import brooklyn.test.TestResourceUnavailableException; +import brooklyn.util.collections.MutableList; +import brooklyn.util.collections.MutableMap; +import brooklyn.util.http.HttpTool; +import brooklyn.util.http.HttpToolResponse; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +public class WebAppConcurrentDeployTest extends BrooklynAppUnitTestSupport { + private Location loc; + + @Override + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + super.setUp(); + app.config().set(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, false); +// tested on loc = mgmt.getLocationRegistry().resolve("byon:(hosts=\"hostname\")"); + loc = mgmt.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)); + } + + @DataProvider(name = "basicEntities") + public Object[][] basicEntities() { + return new Object[][]{ + {EntitySpec.create(TomcatServer.class)}, + // Hot Deploy not enabled? + // {EntitySpec.create(JBoss6Server.class)}, + {EntitySpec.create(JBoss7Server.class)}, + }; + } + + @Test(groups = "Live", dataProvider="basicEntities") + public void testConcurrentDeploys(EntitySpec<? extends JavaWebAppSoftwareProcess> webServerSpec) throws Exception { + JavaWebAppSoftwareProcess server = app.createAndManageChild(webServerSpec); + app.start(ImmutableList.of(loc)); + EntityTestUtils.assertAttributeEqualsEventually(server, Attributes.SERVICE_UP, Boolean.TRUE); + Collection<Task<Void>> deploys = MutableList.of(); + for (int i = 0; i < 5; i++) { + deploys.add(server.invoke(TomcatServer.DEPLOY, MutableMap.of("url", getTestWar(), "targetName", "/"))); + } + for(Task<Void> t : deploys) { + t.getUnchecked(); + } + + final HttpClient client = HttpTool.httpClientBuilder().build(); + final URI warUrl = URI.create(server.getAttribute(JavaWebAppSoftwareProcess.ROOT_URL)); + Asserts.succeedsEventually(new Runnable() { + @Override + public void run() { + HttpToolResponse resp = HttpTool.httpGet(client, warUrl, ImmutableMap.<String,String>of()); + assertEquals(resp.getResponseCode(), 200); + } + }); + } + + public String getTestWar() { + TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/hello-world.war"); + return "classpath://hello-world.war"; + } + +}
