You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2017/04/18 13:44:07 UTC

[1/3] brooklyn-server git commit: Renamed to MachineDetailsIntegrationTest

Repository: brooklyn-server
Updated Branches:
  refs/heads/master f3d2eed56 -> d5fbc654c


Renamed to MachineDetailsIntegrationTest


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

Branch: refs/heads/master
Commit: ee0cabde0e2da32a5ba60c2312432baa3e847b25
Parents: d407e5e
Author: Aled Sage <al...@gmail.com>
Authored: Tue Apr 18 10:03:13 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Apr 18 11:36:49 2017 +0100

----------------------------------------------------------------------
 .../location/MachineDetailsIntegrationTest.java | 83 ++++++++++++++++++++
 .../core/location/MachineDetailsTest.java       | 83 --------------------
 2 files changed, 83 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ee0cabde/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsIntegrationTest.java b/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsIntegrationTest.java
new file mode 100644
index 0000000..e54cb08
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsIntegrationTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.core.location;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.Arrays;
+
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.api.location.MachineDetails;
+import org.apache.brooklyn.api.location.OsDetails;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.location.BasicMachineDetails;
+import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class MachineDetailsIntegrationTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(MachineDetailsIntegrationTest.class);
+
+    TestApplication app;
+    ManagementContext mgmt;
+    SshMachineLocation host;
+
+    @BeforeMethod(alwaysRun=true)
+    public void setup() throws Exception {
+        app = TestApplication.Factory.newManagedInstanceForTests();
+        mgmt = app.getManagementContext();
+
+        LocalhostMachineProvisioningLocation localhost = mgmt.getLocationManager().createLocation(
+                LocationSpec.create(LocalhostMachineProvisioningLocation.class));
+        host = localhost.obtain();
+        app.start(Arrays.asList(host));
+    }
+
+    @AfterMethod(alwaysRun=true)
+    public void tearDown() throws Exception {
+        if (mgmt != null) Entities.destroyAll(mgmt);
+        mgmt = null;
+    }
+
+    @Test(groups = "Integration")
+    public void testGetMachineDetails() {
+        Task<BasicMachineDetails> detailsTask = app.getExecutionContext().submit(
+                BasicMachineDetails.taskForSshMachineLocation(host));
+        MachineDetails machine = detailsTask.getUnchecked();
+        LOG.info("Found the following on localhost: {}", machine);
+        assertNotNull(machine);
+        OsDetails details = machine.getOsDetails();
+        assertNotNull(details);
+        assertNotNull(details.getArch());
+        assertNotNull(details.getName());
+        assertNotNull(details.getVersion());
+        assertFalse(details.getArch().startsWith("architecture:"), "architecture prefix not removed from details");
+        assertFalse(details.getName().startsWith("name:"), "name prefix not removed from details");
+        assertFalse(details.getVersion().startsWith("version:"), "version prefix not removed from details");
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ee0cabde/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsTest.java b/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsTest.java
deleted file mode 100644
index d45547e..0000000
--- a/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.core.location;
-
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-
-import java.util.Arrays;
-
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.location.MachineDetails;
-import org.apache.brooklyn.api.location.OsDetails;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.mgmt.Task;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.location.BasicMachineDetails;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
-import org.apache.brooklyn.location.ssh.SshMachineLocation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-public class MachineDetailsTest {
-
-    private static final Logger LOG = LoggerFactory.getLogger(MachineDetailsTest.class);
-
-    TestApplication app;
-    ManagementContext mgmt;
-    SshMachineLocation host;
-
-    @BeforeMethod(alwaysRun=true)
-    public void setup() throws Exception {
-        app = TestApplication.Factory.newManagedInstanceForTests();
-        mgmt = app.getManagementContext();
-
-        LocalhostMachineProvisioningLocation localhost = mgmt.getLocationManager().createLocation(
-                LocationSpec.create(LocalhostMachineProvisioningLocation.class));
-        host = localhost.obtain();
-        app.start(Arrays.asList(host));
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (mgmt != null) Entities.destroyAll(mgmt);
-        mgmt = null;
-    }
-
-    @Test(groups = "Integration")
-    public void testGetMachineDetails() {
-        Task<BasicMachineDetails> detailsTask = app.getExecutionContext().submit(
-                BasicMachineDetails.taskForSshMachineLocation(host));
-        MachineDetails machine = detailsTask.getUnchecked();
-        LOG.info("Found the following on localhost: {}", machine);
-        assertNotNull(machine);
-        OsDetails details = machine.getOsDetails();
-        assertNotNull(details);
-        assertNotNull(details.getArch());
-        assertNotNull(details.getName());
-        assertNotNull(details.getVersion());
-        assertFalse(details.getArch().startsWith("architecture:"), "architecture prefix not removed from details");
-        assertFalse(details.getName().startsWith("name:"), "name prefix not removed from details");
-        assertFalse(details.getVersion().startsWith("version:"), "version prefix not removed from details");
-    }
-}


[3/3] brooklyn-server git commit: This closes #639

Posted by al...@apache.org.
This closes #639


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

Branch: refs/heads/master
Commit: d5fbc654cf7df574237c7eaea851b2c3241ccaaa
Parents: f3d2eed d292e3d
Author: Aled Sage <al...@gmail.com>
Authored: Tue Apr 18 14:43:50 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Apr 18 14:43:50 2017 +0100

----------------------------------------------------------------------
 .../core/location/BasicMachineDetails.java      | 30 ++++++-
 .../location/MachineDetailsIntegrationTest.java | 85 ++++++++++++++++++++
 .../core/location/MachineDetailsTest.java       | 83 -------------------
 .../ssh/SshMachineLocationIntegrationTest.java  |  7 ++
 .../location/ssh/SshMachineLocationTest.java    | 35 ++++++++
 5 files changed, 154 insertions(+), 86 deletions(-)
----------------------------------------------------------------------



[2/3] brooklyn-server git commit: BROOKLYN-475: fix machine-details parsing

Posted by al...@apache.org.
BROOKLYN-475: fix machine-details parsing


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

Branch: refs/heads/master
Commit: d292e3dbe37dfd7e32c081f755026b230758ca3b
Parents: ee0cabd
Author: Aled Sage <al...@gmail.com>
Authored: Tue Apr 18 11:35:48 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Apr 18 12:22:44 2017 +0100

----------------------------------------------------------------------
 .../core/location/BasicMachineDetails.java      | 30 +++++++++++++++--
 .../location/MachineDetailsIntegrationTest.java |  2 ++
 .../ssh/SshMachineLocationIntegrationTest.java  |  7 ++++
 .../location/ssh/SshMachineLocationTest.java    | 35 ++++++++++++++++++++
 4 files changed, 71 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d292e3db/core/src/main/java/org/apache/brooklyn/core/location/BasicMachineDetails.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/BasicMachineDetails.java b/core/src/main/java/org/apache/brooklyn/core/location/BasicMachineDetails.java
index b0a9bcd..93374c4 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/BasicMachineDetails.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/BasicMachineDetails.java
@@ -22,8 +22,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.util.AbstractMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.Immutable;
@@ -47,6 +49,7 @@ import com.google.common.base.CharMatcher;
 import com.google.common.base.Function;
 import com.google.common.base.Joiner;
 import com.google.common.base.Objects;
+import com.google.common.base.Optional;
 import com.google.common.base.Splitter;
 import com.google.common.base.Throwables;
 import com.google.common.collect.Maps;
@@ -146,10 +149,20 @@ public class BasicMachineDetails implements MachineDetails {
                     LOG.debug("Found following details at {}: {}", location, stdout);
                 }
 
-                Map<String,String> details = Maps.newHashMap(Splitter.on(CharMatcher.anyOf("\r\n"))
+                // See https://issues.apache.org/jira/browse/BROOKLYN-475:
+                // If using splitter.withKeyValueSeparator, it fails with "Chunk ... is not a valid entry" 
+                // if a line contains more than one ":"; therefore filter those out ourselves.
+                Iterable<String> lines = Splitter.on(CharMatcher.anyOf("\r\n"))
                         .omitEmptyStrings()
-                        .withKeyValueSeparator(":")
-                        .split(stdout));
+                        .split(stdout);
+
+                Map<String, String> details = Maps.newHashMap();
+                for (String line : lines) {
+                    Optional<Entry<String, String>> detail = splitLine(line, ":");
+                    if (detail.isPresent()) {
+                        details.put(detail.get().getKey(), detail.get().getValue());
+                    }
+                }
 
                 String name = details.remove("name");
                 String version = details.remove("version");
@@ -177,6 +190,17 @@ public class BasicMachineDetails implements MachineDetails {
                     return null;
                 }
             }
+            
+            private Optional<Map.Entry<String, String>> splitLine(String sequence, String separator) {
+                int index = sequence.indexOf(separator);
+                if (index < 0) {
+                    return Optional.absent(); // ignore
+                } else {
+                    String key = sequence.substring(0, index).trim();
+                    String value = sequence.substring(index+1).trim();
+                    return Optional.<Map.Entry<String, String>>of(new AbstractMap.SimpleEntry<>(key, value));
+                }
+            }
         };
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d292e3db/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsIntegrationTest.java b/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsIntegrationTest.java
index e54cb08..c2994f8 100644
--- a/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsIntegrationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/location/MachineDetailsIntegrationTest.java
@@ -41,6 +41,8 @@ import org.testng.annotations.Test;
 
 public class MachineDetailsIntegrationTest {
 
+    // See SshMachineLocationTest.testGetMachineDetails for an equivalent unit test
+    
     private static final Logger LOG = LoggerFactory.getLogger(MachineDetailsIntegrationTest.class);
 
     TestApplication app;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d292e3db/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationIntegrationTest.java b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationIntegrationTest.java
index 844df4a..c770527 100644
--- a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationIntegrationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationIntegrationTest.java
@@ -127,6 +127,13 @@ public class SshMachineLocationIntegrationTest extends SshMachineLocationTest {
         }
     }
 
+    // Overrides and disables super, because real machine won't give extra stdout
+    @Test(enabled=false)
+    @Override
+    public void testGetMachineDetailsWithExtraStdout() throws Exception {
+        throw new UnsupportedOperationException("Test disabled because real machine does not have extra stdout");
+    }
+
     @Test(groups = "Integration")
     public void testCopyFileTo() throws Exception {
         File dest = Os.newTempFile(getClass(), ".dest.tmp");

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d292e3db/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationTest.java b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationTest.java
index bac6018..d2f8645 100644
--- a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationTest.java
@@ -150,6 +150,41 @@ public class SshMachineLocationTest extends BrooklynAppUnitTestSupport {
     }
 
     @Test
+    public void testGetMachineDetailsWithExtraStdout() throws Exception {
+        String response = Joiner.on("\n").join(
+                "Last login: Fri Apr 14 08:01:37 2017 from 35.156.73.145",
+                "Line with no colons",
+                ": colon first",
+                "colon last:",
+                "name:MyCentOS",
+                "version:6.7",
+                "architecture:x86_64",
+                "ram:15948",
+                "cpus:4");
+        RecordingSshTool.setCustomResponse(".*uname.*", new CustomResponse(0, response, ""));
+
+        BasicExecutionManager execManager = new BasicExecutionManager("mycontextid");
+        BasicExecutionContext execContext = new BasicExecutionContext(execManager);
+        try {
+            MachineDetails details = execContext.submit(new Callable<MachineDetails>() {
+                @Override
+                public MachineDetails call() {
+                    return host.getMachineDetails();
+                }}).get();
+            LOG.info("machineDetails="+details);
+            assertNotNull(details);
+            
+            assertEquals(details.getOsDetails().getName(), "MyCentOS", "details="+details);
+            assertEquals(details.getOsDetails().getVersion(), "6.7", "details="+details);
+            assertEquals(details.getOsDetails().getArch(), "x86_64", "details="+details);
+            assertEquals(details.getHardwareDetails().getCpuCount(), Integer.valueOf(4), "details="+details);
+            assertEquals(details.getHardwareDetails().getRam(), Integer.valueOf(15948), "details="+details);
+        } finally {
+            execManager.shutdownNow();
+        }
+    }
+
+    @Test
     public void testSupplyingMachineDetails() throws Exception {
         MachineDetails machineDetails = new BasicMachineDetails(new BasicHardwareDetails(1, 1024), new BasicOsDetails("myname", "myarch", "myversion"));
         SshMachineLocation host2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)