From aa64e0d3e2eb3edede2cbfc2fb1c5dc93d8b3458 Mon Sep 17 00:00:00 2001 From: Andrea Turli Date: Thu, 25 Jun 2015 11:30:11 +0200 Subject: [PATCH] [NOVA] change some access modifiers to simplify the downstream provider impl modify the BasicAuthenticator in Keystone destroy node if creation timeouts --- .../functions/internal/BaseAuthenticator.java | 6 ++--- .../compute/NovaComputeServiceAdapter.java | 24 +++++++++++++++---- .../functions/ImageToOperatingSystem.java | 2 +- .../ServerInRegionToNodeMetadata.java | 4 ++-- ...sWithGroupEncodedIntoNameThenAddToSet.java | 6 ++--- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/BaseAuthenticator.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/BaseAuthenticator.java index 93ece91d13..3e4216a233 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/BaseAuthenticator.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/functions/internal/BaseAuthenticator.java @@ -64,10 +64,10 @@ public abstract class BaseAuthenticator implements Function> creating new server region(%s) name(%s) image(%s) flavor(%s) options(%s)", regionId, name, imageId, flavorId, options); - ServerCreated lightweightServer = novaApi.getServerApi(regionId).create(name, imageId, flavorId, options); + final ServerCreated lightweightServer = novaApi.getServerApi(regionId).create(name, imageId, flavorId, options); + if (!retry(new Predicate() { + @Override + public boolean apply(String serverId) { + Server server = novaApi.getServerApi(regionId).get(serverId); + return server != null && server.getAddresses() != null && !server.getAddresses().isEmpty(); + } + }, 30 * 60, 1, SECONDS).apply(lightweightServer.getId())) { + final String message = format("Server %s was not created within %sms so it will be destroyed.", name, "30 * 60"); + logger.warn(message); + destroyNode(lightweightServer.getId()); + throw new IllegalStateException(message); + } + logger.trace("<< server(%s)", lightweightServer.getId()); + Server server = novaApi.getServerApi(regionId).get(lightweightServer.getId()); - - logger.trace("<< server(%s)", server.getId()); - ServerInRegion serverInRegion = new ServerInRegion(server, regionId); if (!privateKey.isPresent() && lightweightServer.getAdminPass().isPresent()) credentialsBuilder.password(lightweightServer.getAdminPass().get()); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageToOperatingSystem.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageToOperatingSystem.java index 2781942c1f..4805a57f14 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageToOperatingSystem.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageToOperatingSystem.java @@ -57,7 +57,7 @@ public class ImageToOperatingSystem implements Function @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; - private final Map> osVersionMap; + protected final Map> osVersionMap; @Inject public ImageToOperatingSystem(Map> osVersionMap) { diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInRegionToNodeMetadata.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInRegionToNodeMetadata.java index 2134bb232b..e48554fbb7 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInRegionToNodeMetadata.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInRegionToNodeMetadata.java @@ -144,7 +144,7 @@ public class ServerInRegionToNodeMetadata implements Function isPrivateAddress = new Predicate
() { + public static final Predicate
isPrivateAddress = new Predicate
() { public boolean apply(Address in) { return InetAddresses2.IsPrivateIPAddress.INSTANCE.apply(in.getAddr()); } @@ -164,7 +164,7 @@ public class ServerInRegionToNodeMetadata implements Function { + public enum AddressToStringTransformationFunction implements Function { INSTANCE; @Override public String apply(Address address) { diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java index 8085c6c56d..9a4a482c63 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java @@ -64,9 +64,9 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT CreateNodesWithGroupEncodedIntoNameThenAddToSet { private final AllocateAndAddFloatingIpToNode createAndAddFloatingIpToNode; - private final LoadingCache securityGroupCache; - private final LoadingCache keyPairCache; - private final NovaApi novaApi; + protected final LoadingCache securityGroupCache; + protected final LoadingCache keyPairCache; + protected final NovaApi novaApi; @Inject protected ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet(