You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2014/09/30 11:35:53 UTC

[04/12] git commit: JcloudsLocation: avoid NPE if node.getImageId null

JcloudsLocation: avoid NPE if node.getImageId null


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

Branch: refs/heads/master
Commit: 638809cb522f0524ffebc7a888e18f4423aaa6b8
Parents: 3e7aa47
Author: Aled Sage <al...@gmail.com>
Authored: Fri Sep 26 11:57:38 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Sep 26 15:25:37 2014 +0100

----------------------------------------------------------------------
 .../main/java/brooklyn/location/jclouds/JcloudsLocation.java  | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/638809cb/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
index a044710..da5f5dd 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -1135,7 +1135,8 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
      * Create the user immediately - executing ssh commands as required.
      */
     protected LoginCredentials createUser(ComputeService computeService, NodeMetadata node, Optional<HostAndPort> hostAndPortOverride, ConfigBag config) {
-        UserCreation userCreation = createUserStatements(computeService.getImage(node.getImageId()), config);
+        Image image = (node.getImageId() != null) ? computeService.getImage(node.getImageId()) : null;
+        UserCreation userCreation = createUserStatements(image, config);
         
         if (!userCreation.statements.isEmpty()) {
             org.jclouds.compute.domain.OsFamily osFamily = node.getOperatingSystem().getFamily();
@@ -1260,7 +1261,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
      * @param config Configuration for creating the VM
      * @return       The commands required to create the user, along with the expected login credentials.
      */
-    protected UserCreation createUserStatements(Image image, ConfigBag config) {
+    protected UserCreation createUserStatements(@Nullable Image image, ConfigBag config) {
         //NB: we ignore private key here because, by default we probably should not be installing it remotely;
         //also, it may not be valid for first login (it is created before login e.g. on amazon, so valid there;
         //but not elsewhere, e.g. on rackspace).
@@ -1268,7 +1269,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
         LoginCredentials loginCreds = null;
         String user = getUser(config);
         String explicitLoginUser = config.get(LOGIN_USER);
-        String loginUser = groovyTruth(explicitLoginUser) ? explicitLoginUser : (image.getDefaultCredentials() != null) ? image.getDefaultCredentials().identity : null;
+        String loginUser = groovyTruth(explicitLoginUser) ? explicitLoginUser : (image != null && image.getDefaultCredentials() != null) ? image.getDefaultCredentials().identity : null;
         Boolean dontCreateUser = config.get(DONT_CREATE_USER);
         Boolean grantUserSudo = config.get(GRANT_USER_SUDO);
         String publicKeyData = LocationConfigUtils.getPublicKeyData(config);