JcloudsLocation: call unmanage after createTemporarySshMachineLocation Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b987fb15 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b987fb15 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b987fb15
Branch: refs/heads/master Commit: b987fb159a0cc975bc1954eee3b89ed557394c7c Parents: 6b5f748 Author: Aled Sage <[email protected]> Authored: Tue May 30 11:13:17 2017 +0100 Committer: Aled Sage <[email protected]> Committed: Tue May 30 16:32:48 2017 +0100 ---------------------------------------------------------------------- .../brooklyn/location/jclouds/JcloudsLocation.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b987fb15/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java index 9fd4b36..7bce8f7 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java @@ -1727,7 +1727,9 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im LOG.warn("exit code {} when creating user for {}; usage may subsequently fail", exitcode, node); } } finally { - getManagementContext().getLocationManager().unmanage(sshLoc); + if (getManagementContext().getLocationManager().isManaged(sshLoc)) { + getManagementContext().getLocationManager().unmanage(sshLoc); + } Streams.closeQuietly(sshLoc); } } @@ -2901,11 +2903,9 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im } String getHostnameAws(HostAndPort hostAndPort, LoginCredentials userCredentials, ConfigBag setup) { - SshMachineLocation sshLocByIp = null; + // TODO messy way to get an SSH session + SshMachineLocation sshLocByIp = createTemporarySshMachineLocation(hostAndPort, userCredentials, setup); try { - // TODO messy way to get an SSH session - sshLocByIp = createTemporarySshMachineLocation(hostAndPort, userCredentials, setup); - ByteArrayOutputStream outStream = new ByteArrayOutputStream(); ByteArrayOutputStream errStream = new ByteArrayOutputStream(); int exitcode = sshLocByIp.execCommands( @@ -2921,6 +2921,9 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im } throw new IllegalStateException("Could not obtain aws-ec2 hostname for vm "+hostAndPort+"; exitcode="+exitcode+"; stdout="+outString+"; stderr="+new String(errStream.toByteArray())); } finally { + if (getManagementContext().getLocationManager().isManaged(sshLocByIp)) { + getManagementContext().getLocationManager().unmanage(sshLocByIp); + } Streams.closeQuietly(sshLocByIp); } }
