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 2014/10/09 00:45:54 UTC
[4/5] git commit: Support for supplying machine_details as config
Support for supplying machine_details as config
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/542d9927
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/542d9927
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/542d9927
Branch: refs/heads/master
Commit: 542d99273c404d6241e7bc0bee761fc33ce1f7ab
Parents: 2b9240b
Author: Aled Sage <al...@gmail.com>
Authored: Tue Oct 7 15:13:47 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Oct 8 23:30:18 2014 +0100
----------------------------------------------------------------------
.../location/basic/SshMachineLocation.java | 34 ++++++++++++--------
.../location/basic/SshMachineLocationTest.java | 13 ++++++--
.../jclouds/JcloudsSshMachineLocation.java | 4 +--
3 files changed, 33 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/542d9927/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java b/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
index 40ffc6f..90d917a 100644
--- a/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
+++ b/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
@@ -130,6 +130,10 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat
public static final ConfigKey<Duration> SSH_CACHE_EXPIRY_DURATION = ConfigKeys.newConfigKey(Duration.class,
"sshCacheExpiryDuration", "Expiry time for unused cached ssh connections", Duration.FIVE_MINUTES);
+ public static final ConfigKey<MachineDetails> MACHINE_DETAILS = ConfigKeys.newConfigKey(
+ MachineDetails.class,
+ "machineDetails");
+
@SetFromFlag
protected String user;
@@ -840,22 +844,24 @@ public class SshMachineLocation extends AbstractLocation implements MachineLocat
@Override
public MachineDetails getMachineDetails() {
- MachineDetails details = machineDetails;
- if (details == null) {
- // Or could just load and store several times
- Tasks.setBlockingDetails("Waiting for machine details");
- try {
- synchronized (machineDetailsLock) {
- details = machineDetails;
- if (details == null) {
- machineDetails = details = BasicMachineDetails.forSshMachineLocation(this);
- }
- }
- } finally {
- Tasks.resetBlockingDetails();
+ synchronized (machineDetailsLock) {
+ if (machineDetails == null) {
+ machineDetails = getConfig(MACHINE_DETAILS);
+ }
+ if (machineDetails == null) {
+ machineDetails = inferMachineDetails();
}
}
- return details;
+ return machineDetails;
+ }
+
+ protected MachineDetails inferMachineDetails() {
+ Tasks.setBlockingDetails("Waiting for machine details");
+ try {
+ return BasicMachineDetails.forSshMachineLocation(this);
+ } finally {
+ Tasks.resetBlockingDetails();
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/542d9927/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java b/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
index 5f20b6e..4ad23cc 100644
--- a/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
+++ b/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
@@ -22,6 +22,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
@@ -87,6 +88,7 @@ public class SshMachineLocationTest {
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
+ mgmt = new LocalManagementContextForTests();
host = new SshMachineLocation(MutableMap.of("address", Networking.getLocalHost()));
}
@@ -111,13 +113,20 @@ public class SshMachineLocationTest {
}
}
+ @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)
+ .configure(SshMachineLocation.MACHINE_DETAILS, machineDetails));
+
+ assertSame(host2.getMachineDetails(), machineDetails);
+ }
+
// Wow, this is hard to test (until I accepted creating the entity + effector)! Code smell?
// Need to call getMachineDetails in a DynamicSequentialTask so that the "innessential" takes effect,
// to not fail its caller. But to get one of those outside of an effector is non-obvious.
@Test(groups = "Integration")
public void testGetMachineIsInessentialOnFailure() throws Exception {
- ManagementContext mgmt = new LocalManagementContextForTests();
-
SshMachineLocation host2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
.configure("address", Networking.getLocalHost())
.configure(SshTool.PROP_TOOL_CLASS, FailingSshTool.class.getName()));
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/542d9927/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsSshMachineLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
index ae222bf..d218ec2 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
@@ -265,7 +265,7 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements Has
}
@Override
- public MachineDetails getMachineDetails() {
+ protected MachineDetails inferMachineDetails() {
Optional<String> name = Optional.absent();
Optional<String> version = Optional.absent();
Optional<String> architecture = Optional.absent();
@@ -311,7 +311,7 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements Has
"arch={}, ram={}, #cpus={}",
new Object[]{this, name, version, architecture, ram, cpus});
}
- return super.getMachineDetails();
+ return super.inferMachineDetails();
}
}