brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [21/50] [abbrv] brooklyn-server git commit: Added Windows process streams test
Date Mon, 01 Feb 2016 17:50:37 GMT
Added Windows process streams test

- refactored streams tests


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/6dfc6e6d
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/6dfc6e6d
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/6dfc6e6d

Branch: refs/heads/0.8.0-incubating
Commit: 6dfc6e6dc8564e89a8abb3dd77c5dd9d093fe5ed
Parents: e657945
Author: Valentin Aitken <valentin.aitken@cloudsoftcorp.com>
Authored: Mon Aug 24 17:24:13 2015 +0300
Committer: Valentin Aitken <valentin.aitken@cloudsoftcorp.com>
Committed: Fri Aug 28 10:52:47 2015 +0300

----------------------------------------------------------------------
 .../base/VanillaWindowsProcessWinRmDriver.java  |  15 ++-
 .../AbstractSoftwareProcessStreamsTest.java     | 116 +++++++++++++++++++
 ...ftwareProcessAndChildrenIntegrationTest.java |   2 -
 ...laSoftwareProcessStreamsIntegrationTest.java |  16 +--
 ...nillaWindowsProcessWinrmStreamsLiveTest.java | 101 ++++++----------
 5 files changed, 168 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6dfc6e6d/software/base/src/main/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinRmDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinRmDriver.java
b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinRmDriver.java
index 4bb59b9..640c0d0 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinRmDriver.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinRmDriver.java
@@ -18,12 +18,16 @@
  */
 package org.apache.brooklyn.entity.software.base;
 
+import io.cloudsoft.winrm4j.winrm.WinRmToolResponse;
 import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
 import org.apache.brooklyn.util.net.UserAndHostAndPort;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class VanillaWindowsProcessWinRmDriver extends AbstractSoftwareProcessWinRmDriver
implements VanillaWindowsProcessDriver {
+    private static final Logger LOG = LoggerFactory.getLogger(VanillaWindowsProcessWinRmDriver.class);
 
     public VanillaWindowsProcessWinRmDriver(EntityLocal entity, WinRmMachineLocation location)
{
         super(entity, location);
@@ -39,8 +43,7 @@ public class VanillaWindowsProcessWinRmDriver extends AbstractSoftwareProcessWin
     }
     
     @Override
-    public void preInstall() {
-        super.preInstall();
+    public void runPreInstallCommand(String preInstallCommand) {
         executeCommand(VanillaWindowsProcess.PRE_INSTALL_COMMAND, VanillaWindowsProcess.PRE_INSTALL_POWERSHELL_COMMAND,
true);
         if (entity.getConfig(VanillaWindowsProcess.PRE_INSTALL_REBOOT_REQUIRED)) {
             rebootAndWait();
@@ -72,8 +75,12 @@ public class VanillaWindowsProcessWinRmDriver extends AbstractSoftwareProcessWin
 
     @Override
     public boolean isRunning() {
-        return executeCommand(VanillaWindowsProcess.CHECK_RUNNING_COMMAND,
-                VanillaWindowsProcess.CHECK_RUNNING_POWERSHELL_COMMAND, false).getStatusCode()
== 0;
+        WinRmToolResponse runningCheck = executeCommand(VanillaWindowsProcess.CHECK_RUNNING_COMMAND,
+                VanillaWindowsProcess.CHECK_RUNNING_POWERSHELL_COMMAND, false);
+        if(runningCheck.getStatusCode() != 0) {
+            LOG.info(getEntity() + " isRunning check failed: exit code "  + runningCheck.getStatusCode()
+ "; " + runningCheck.getStdErr());
+        }
+        return runningCheck.getStatusCode() == 0;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6dfc6e6d/software/base/src/test/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessStreamsTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessStreamsTest.java
b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessStreamsTest.java
new file mode 100644
index 0000000..8f6fbba
--- /dev/null
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessStreamsTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.software.base;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.mgmt.HasTaskChildren;
+import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
+import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
+import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
+import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.util.core.task.TaskPredicates;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeMethod;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.testng.Assert.assertTrue;
+
+public abstract class AbstractSoftwareProcessStreamsTest extends BrooklynAppLiveTestSupport
{
+    private static final Logger log = LoggerFactory.getLogger(AbstractSoftwareProcessStreamsTest.class);
+
+    public abstract void testGetsStreams();
+
+    protected abstract Map<String, String> getCommands();
+
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        if (mgmt!=null) {
+            app = ApplicationBuilder.newManagedApp(TestApplication.class, mgmt);
+        } else {
+            mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault());
+            EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class)
+                    .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true);
+            app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+        }
+    }
+
+    protected String getStreamOrFail(Task<?> task, String streamType) {
+        String msg = "task="+task+"; stream="+streamType;
+        BrooklynTaskTags.WrappedStream stream = checkNotNull(BrooklynTaskTags.stream(task,
BrooklynTaskTags.STREAM_STDIN), "Stream null: " + msg);
+        return checkNotNull(stream.streamContents.get(), "Contents null: "+msg);
+    }
+
+    protected Optional<Task<?>> findTaskOrSubTask(Iterable<? extends Task<?>>
tasks, Predicate<? super Task<?>> matcher) {
+        List<String> taskNames = Lists.newArrayList();
+        Optional<Task<?>> result = findTaskOrSubTaskImpl(tasks, matcher, taskNames);
+        if (!result.isPresent() && log.isDebugEnabled()) {
+            log.debug("Task not found matching "+matcher+"; contender names were "+taskNames);
+        }
+        return result;
+    }
+
+    protected Optional<Task<?>> findTaskOrSubTaskImpl(Iterable<? extends Task<?>>
tasks, Predicate<? super Task<?>> matcher, List<String> taskNames) {
+        for (Task<?> task : tasks) {
+            if (matcher.apply(task)) return Optional.<Task<?>>of(task);
+
+            if (!(task instanceof HasTaskChildren)) {
+                return Optional.absent();
+            } else {
+                Optional<Task<?>> subResult = findTaskOrSubTask(((HasTaskChildren)
task).getChildren(), matcher);
+                if (subResult.isPresent()) return subResult;
+            }
+        }
+
+        return Optional.<Task<?>>absent();
+    }
+
+    protected <T extends SoftwareProcess> void assertStreams(T softwareProcessEntity)
{
+        Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt.getExecutionManager(),
softwareProcessEntity);
+
+        for (Map.Entry<String, String> entry : getCommands().entrySet()) {
+            String taskNameRegex = entry.getKey();
+            String echoed = entry.getValue();
+
+            Task<?> subTask = findTaskOrSubTask(tasks, TaskPredicates.displayNameMatches(StringPredicates.matchesRegex(taskNameRegex))).get();
+
+            String stdin = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_STDIN);
+            String stdout = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_STDOUT);
+            String stderr = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_STDERR);
+            String env = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_ENV);
+            String msg = "stdin="+stdin+"; stdout="+stdout+"; stderr="+stderr+"; env="+env;
+
+            assertTrue(stdin.contains("echo "+echoed), msg);
+            assertTrue(stdout.contains(echoed), msg);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6dfc6e6d/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessAndChildrenIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessAndChildrenIntegrationTest.java
b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessAndChildrenIntegrationTest.java
index 7a99642..f6e8bf0 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessAndChildrenIntegrationTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessAndChildrenIntegrationTest.java
@@ -26,8 +26,6 @@ import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.entity.software.base.SoftwareProcess;
-import org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess;
 import org.apache.brooklyn.entity.software.base.SoftwareProcess.ChildStartableMode;
 import org.apache.brooklyn.test.EntityTestUtils;
 import org.apache.brooklyn.util.core.ResourceUtils;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6dfc6e6d/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessStreamsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessStreamsIntegrationTest.java
b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessStreamsIntegrationTest.java
index 200cd11..d322a3c 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessStreamsIntegrationTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessStreamsIntegrationTest.java
@@ -81,19 +81,19 @@ public class VanillaSoftwareProcessStreamsIntegrationTest extends BrooklynAppUni
         app.start(ImmutableList.of(localhost));
 
         Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt.getExecutionManager(),
entity);
-        
+
         for (Map.Entry<String, String> entry : cmds.entrySet()) {
             String taskNameRegex = entry.getKey();
             String echoed = entry.getValue();
-            
+
             Task<?> subTask = findTaskOrSubTask(tasks, TaskPredicates.displayNameMatches(StringPredicates.matchesRegex(taskNameRegex))).get();
-            
+
             String stdin = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_STDIN);
             String stdout = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_STDOUT);
             String stderr = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_STDERR);
             String env = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_ENV);
             String msg = "stdin="+stdin+"; stdout="+stdout+"; stderr="+stderr+"; env="+env;
-            
+
             assertTrue(stdin.contains("echo "+echoed), msg);
             assertTrue(stdout.contains(echoed), msg);
         }
@@ -109,15 +109,15 @@ public class VanillaSoftwareProcessStreamsIntegrationTest extends BrooklynAppUni
         List<String> taskNames = Lists.newArrayList();
         Optional<Task<?>> result = findTaskOrSubTaskImpl(tasks, matcher, taskNames);
         if (!result.isPresent() && log.isDebugEnabled()) {
-            log.debug("Task not found matching "+matcher+"; contender names were "+taskNames);
+            log.debug("Task not found matching " + matcher + "; contender names were " +
taskNames);
         }
         return result;
     }
-    
+
     protected Optional<Task<?>> findTaskOrSubTaskImpl(Iterable<? extends Task<?>>
tasks, Predicate<? super Task<?>> matcher, List<String> taskNames) {
         for (Task<?> task : tasks) {
             if (matcher.apply(task)) return Optional.<Task<?>>of(task);
-        
+
             if (!(task instanceof HasTaskChildren)) {
                 return Optional.absent();
             } else {
@@ -125,7 +125,7 @@ public class VanillaSoftwareProcessStreamsIntegrationTest extends BrooklynAppUni
                 if (subResult.isPresent()) return subResult;
             }
         }
-        
+
         return Optional.<Task<?>>absent();
     }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6dfc6e6d/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinrmStreamsLiveTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinrmStreamsLiveTest.java
b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinrmStreamsLiveTest.java
index 94439b3..48c7f1c 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinrmStreamsLiveTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinrmStreamsLiveTest.java
@@ -18,92 +18,57 @@
  */
 package org.apache.brooklyn.entity.software.base;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.mgmt.Task;
-import org.apache.brooklyn.core.internal.BrooklynProperties;
-import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.util.core.task.TaskPredicates;
-import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.location.jclouds.JcloudsLocation;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import java.util.HashMap;
 import java.util.Map;
-import java.util.Set;
 
-import static org.testng.Assert.assertTrue;
-
-public class VanillaWindowsProcessWinrmStreamsLiveTest extends VanillaSoftwareProcessStreamsIntegrationTest
{
-    private Location machine;
+public class VanillaWindowsProcessWinrmStreamsLiveTest extends AbstractSoftwareProcessStreamsTest
{
+    private Location location;
 
     @BeforeMethod(alwaysRun=true)
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault());
-/*
-        JcloudsLocation loc = (JcloudsLocation) mgmt.getLocationRegistry().resolve("jclouds:aws-ec2:us-west-2",
ImmutableMap.of(
-                "inboundPorts", ImmutableList.of(5985, 3389),
-                "displayName", "AWS Oregon (Windows)",
-                "imageNameRegex", ".*Windows.*2012.*",
-                "hardwareId", "m3.medium",
-                "useJcloudsSshInit", false));
-        machine = (WinRmMachineLocation) loc.obtain();
-                */
-        // ImmutableMap.of supports at most 5 key pairs
-        Map<String, String> config = new HashMap<>();
-        config.put("hosts", "52.13.85.118:5985");
-        config.put("osFamily", "windows");
-        config.put("winrm", "52.13.85.118:5985");
-        config.put("user", "Administrator");
-        config.put("password", "q$p5g3(JSWs");
-        config.put("useJcloudsSshInit", "false");
-        config.put("byonIdentity", "dev12");
-        machine = mgmt.getLocationRegistry().resolve("byon", config);
+
+        Map<String, Object> config = ImmutableMap.<String, Object>builder()
+                .put("inboundPorts", ImmutableList.of(5985, 3389))
+                .put("osFamily", "windows")
+                .put("displayName", "AWS Oregon (Windows)")
+                .put("imageOwner", "801119661308")
+                .put("imageNameRegex", "Windows_Server-2012-R2_RTM-English-64Bit-Base-.*")
+                .put("hardwareId", "m3.medium")
+                .put("checkRunning.command", "echo true")
+                .put("useJcloudsSshInit", false)
+                .build();
+        location = ((JcloudsLocation)mgmt.getLocationRegistry().resolve("jclouds:aws-ec2:eu-west-1",
config)).obtain();
     }
 
     @Test(groups = "Live")
+    @Override
     public void testGetsStreams() {
-        Map<String, String> cmds = ImmutableMap.<String, String>builder()
-                .put("pre-install-command", "myPreInstall")
-                .put("ssh: installing.*", "myInstall")
-                .put("post-install-command", "myPostInstall")
-                .put("ssh: customizing.*", "myCustomizing")
-                .put("pre-launch-command", "myPreLaunch")
-                .put("ssh: launching.*", "myLaunch")
-                .put("post-launch-command", "myPostLaunch")
-                .build();
         VanillaWindowsProcess entity = app.createAndManageChild(EntitySpec.create(VanillaWindowsProcess.class)
-                .configure("id", "dev12")
-                .configure(VanillaSoftwareProcess.PRE_INSTALL_COMMAND, "echo " + cmds.get("pre-install-command"))
-                .configure(VanillaSoftwareProcess.INSTALL_COMMAND, "echo " + cmds.get("ssh:
installing.*"))
-                .configure(VanillaSoftwareProcess.POST_INSTALL_COMMAND, "echo " + cmds.get("post-install-command"))
-                .configure(VanillaSoftwareProcess.CUSTOMIZE_COMMAND, "echo " + cmds.get("ssh:
customizing.*"))
-                .configure(VanillaSoftwareProcess.PRE_LAUNCH_COMMAND, "echo " + cmds.get("pre-launch-command"))
-                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "echo " + cmds.get("ssh:
launching.*"))
-                .configure(VanillaSoftwareProcess.POST_LAUNCH_COMMAND, "echo " + cmds.get("post-launch-command"))
-                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "true"));
-//        app.start(ImmutableList.of(machine));
-
-        Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt.getExecutionManager(),
entity);
-
-        for (Map.Entry<String, String> entry : cmds.entrySet()) {
-            String taskNameRegex = entry.getKey();
-            String echoed = entry.getValue();
-
-            Task<?> subTask = findTaskOrSubTask(tasks, TaskPredicates.displayNameMatches(StringPredicates.matchesRegex(taskNameRegex))).get();
-
-            String stdin = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_STDIN);
-            String stdout = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_STDOUT);
-            String stderr = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_STDERR);
-            String env = getStreamOrFail(subTask, BrooklynTaskTags.STREAM_ENV);
-            String msg = "stdin="+stdin+"; stdout="+stdout+"; stderr="+stderr+"; env="+env;
+                .configure(VanillaSoftwareProcess.PRE_INSTALL_COMMAND, "echo " + getCommands().get("pre-install-command"))
+                .configure(VanillaSoftwareProcess.INSTALL_COMMAND, "echo " + getCommands().get("^install$"))
+                .configure(VanillaSoftwareProcess.CUSTOMIZE_COMMAND, "echo " + getCommands().get("^customize$"))
+                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "echo " + getCommands().get("^launch$"))
+                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "echo true"));
+        app.start(ImmutableList.of(location));
+        assertStreams(entity);
+    }
 
-            assertTrue(stdin.contains("echo "+echoed), msg);
-            assertTrue(stdout.contains(echoed), msg);
-        }
+    @Override
+    protected Map<String, String> getCommands() {
+        return ImmutableMap.<String, String>builder()
+                .put("pre-install-command", "myPreInstall")
+                .put("^install$", "myInstall")
+                .put("^customize$", "myCustomizing")
+                .put("^launch$", "myLaunch")
+                .build();
     }
 }


Mime
View raw message