Removed unnecessary whitespaces and fixed formatting

This commit is contained in:
Ignasi Barrera 2014-07-14 10:53:08 +02:00
parent e94b878b28
commit 3b2f02b723
10 changed files with 74 additions and 70 deletions

View File

@ -80,7 +80,7 @@ public class AllocateAndAddFloatingIpToNode implements
String zoneId = node.getLocation().getParent().getId();
FloatingIPApi floatingIpApi = novaApi.getFloatingIPExtensionForZone(zoneId).get();
Optional<Set<String>> poolNames = input.get().getNovaTemplateOptions().get().getFloatingIpPoolNames();
Optional<FloatingIP> ip = allocateFloatingIPForNode(floatingIpApi, poolNames, node.getId());
if (!ip.isPresent()) {
throw new InsufficientResourcesException("Failed to allocate a FloatingIP for node(" + node.getId() + ")");
@ -95,40 +95,40 @@ public class AllocateAndAddFloatingIpToNode implements
/**
* Allocates a FloatingIP for a given Node
*
*
* @param floatingIpApi FloatingIPApi to create or query for a valid FloatingIP
* @param poolNames optional set of pool names from which we will attempt to allocate an IP from. Most cases this is null
* @param nodeID optional id of the Node we are trying to allocate a FloatingIP for. Used here only for logging purposes
* @return Optional<FloatingIP>
* @return Optional<FloatingIP>
*/
private Optional<FloatingIP> allocateFloatingIPForNode(FloatingIPApi floatingIpApi, Optional<Set<String>> poolNames, String nodeID) {
FloatingIP ip = null;
// 1.) Attempt to allocate from optionally passed poolNames
if (poolNames.isPresent()) {
for (String poolName : poolNames.get()){
for (String poolName : poolNames.get()) {
try {
logger.debug(">> allocating floating IP from pool %s for node(%s)", poolName, nodeID);
ip = floatingIpApi.allocateFromPool(poolName);
if (ip != null)
return Optional.of(ip);
} catch (InsufficientResourcesException ire){
} catch (InsufficientResourcesException ire) {
logger.trace("<< [%s] failed to allocate floating IP from pool %s for node(%s)", ire.getMessage(), poolName, nodeID);
}
}
}
// 2.) Attempt to allocate, if necessary, via 'create()' call
try {
logger.debug(">> creating floating IP for node(%s)", nodeID);
ip = floatingIpApi.create();
if(ip != null)
if (ip != null)
return Optional.of(ip);
} catch (InsufficientResourcesException ire){
} catch (InsufficientResourcesException ire) {
logger.trace("<< [%s] failed to create floating IP for node(%s)", ire.getMessage(), nodeID);
}
// 3.) If no IP was found make final attempt by searching through list of available IP's
logger.trace(">> searching for existing, unassigned floating IP for node(%s)", nodeID);
List<FloatingIP> unassignedIps = Lists.newArrayList(Iterables.filter(floatingIpApi.list(),
@ -145,7 +145,7 @@ public class AllocateAndAddFloatingIpToNode implements
ip = Iterables.getLast(unassignedIps);
return Optional.fromNullable(ip);
}
@Override
public String toString() {
return Objects.toStringHelper("AllocateAndAddFloatingIpToNode").toString();

View File

@ -23,15 +23,15 @@ import org.jclouds.compute.domain.NodeMetadata;
import com.google.common.util.concurrent.Atomics;
/**
* Simple data-structure for holding a NodeMetadata object along with a
* Simple data-structure for holding a NodeMetadata object along with a
* corresponding NovaTemplateOptions object.
*/
public class NodeAndNovaTemplateOptions {
private final AtomicReference<NodeMetadata> nodeMetadata;
private final AtomicReference<NovaTemplateOptions> novaTemplateOptions;
protected NodeAndNovaTemplateOptions(AtomicReference<NodeMetadata> nodeMetadata, AtomicReference<NovaTemplateOptions> novaTemplateOptions){
protected NodeAndNovaTemplateOptions(AtomicReference<NodeMetadata> nodeMetadata, AtomicReference<NovaTemplateOptions> novaTemplateOptions) {
this.nodeMetadata = nodeMetadata;
this.novaTemplateOptions = novaTemplateOptions;
}
@ -43,12 +43,12 @@ public class NodeAndNovaTemplateOptions {
public AtomicReference<NovaTemplateOptions> getNovaTemplateOptions() {
return novaTemplateOptions;
}
public static NodeAndNovaTemplateOptions newReference(AtomicReference<NodeMetadata> node, AtomicReference<NovaTemplateOptions> options){
public static NodeAndNovaTemplateOptions newReference(AtomicReference<NodeMetadata> node, AtomicReference<NovaTemplateOptions> options) {
return new NodeAndNovaTemplateOptions(node, options);
}
public static AtomicReference<NodeAndNovaTemplateOptions> newAtomicReference(AtomicReference<NodeMetadata> node, AtomicReference<NovaTemplateOptions> options){
public static AtomicReference<NodeAndNovaTemplateOptions> newAtomicReference(AtomicReference<NodeMetadata> node, AtomicReference<NovaTemplateOptions> options) {
return Atomics.newReference(NodeAndNovaTemplateOptions.newReference(node, options));
}
}

View File

@ -28,7 +28,6 @@ import java.util.Set;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.openstack.nova.v2_0.domain.Network;
import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
import org.jclouds.scriptbuilder.domain.Statement;
import com.google.common.base.Objects;
@ -145,7 +144,7 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
this.autoAssignFloatingIp = enable;
return this;
}
/**
* @see #getFloatingIpPoolNames()
*/
@ -200,7 +199,7 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
/**
* <h3>Note</h3>
*
* This requires that {@link NovaApi#getExtensionForZone(String)} to return
* This requires that {@link org.jclouds.openstack.nova.v2_0.NovaApi#getExtensionForZone(String)} to return
* {@link Optional#isPresent present}
*
* @return true if auto assignment of a floating ip to each vm is enabled
@ -211,16 +210,16 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
/**
* The floating IP pool name(s) to use when allocating a FloatingIP. Applicable
* only if #shouldAutoAssignFloatingIp() returns true. If not set will attempt to
* use whatever FloatingIP(s) can be found regardless of which pool they originated
* only if #shouldAutoAssignFloatingIp() returns true. If not set will attempt to
* use whatever FloatingIP(s) can be found regardless of which pool they originated
* from
*
*
* @return floating-ip-pool names to use
*/
public Optional<Set<String>> getFloatingIpPoolNames() {
return floatingIpPoolNames;
}
}
/**
* Specifies the keypair used to run instances with
* @return the keypair to be used
@ -228,11 +227,11 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
public String getKeyPairName() {
return keyPairName;
}
/**
* <h3>Note</h3>
*
* This requires that {@link NovaApi#getKeyPairExtensionForZone(String)} to return
* This requires that {@link org.jclouds.openstack.nova.v2_0.NovaApi#getKeyPairExtensionForZone(String)} to return
* {@link Optional#isPresent present}
*
* @return true if auto generation of keypairs is enabled
@ -256,21 +255,21 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
}
/**
* @see CreateServerOptions#getDiskConfig()
* @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getDiskConfig()
*/
public String getDiskConfig() {
return diskConfig;
}
/**
* @see CreateServerOptions#getConfigDrive()
* @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getConfigDrive()
*/
public boolean getConfigDrive() {
return configDrive;
}
/**
* @see CreateServerOptions#getNetworks()
* @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getNetworks()
*/
public Set<Network> getNovaNetworks() {
return novaNetworks;
@ -298,11 +297,11 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
*/
public NovaTemplateOptions floatingIpPoolNames(Iterable<String> floatingIpPoolNames) {
NovaTemplateOptions options = new NovaTemplateOptions();
return NovaTemplateOptions.class.cast(options.floatingIpPoolNames(floatingIpPoolNames));
}
return NovaTemplateOptions.class.cast(options.floatingIpPoolNames(floatingIpPoolNames));
}
/**
* @see NovaTemplateOptions#shouldGenerateKeyPair()
* @see NovaTemplateOptions#shouldGenerateKeyPair()
*/
public static NovaTemplateOptions generateKeyPair(boolean enable) {
return new NovaTemplateOptions().generateKeyPair(enable);
@ -638,7 +637,7 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
}
/**
* @see CreateServerOptions#getDiskConfig()
* @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getDiskConfig()
*/
public NovaTemplateOptions diskConfig(String diskConfig) {
this.diskConfig = diskConfig;
@ -651,7 +650,7 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
* normally be available through the metadata service by mounting this disk and reading files from it.
* To enable the config drive, set this parameter to "true".
* This has to be enabled for user data cases.
* @see CreateServerOptions#getConfigDrive()
* @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getConfigDrive()
*/
public NovaTemplateOptions configDrive(boolean configDrive) {
this.configDrive = configDrive;
@ -662,7 +661,7 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
* @param novaNetworks The list of network declarations.
* Nova-specific network declarations allow for specifying network UUIDs, port UUIDs, and fixed IPs.
* Unline {@link #networks(Iterable)} this supports setting additional network parameters and not just network UUIDs.
* @see CreateServerOptions#getNetworks()
* @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getNetworks()
*/
public NovaTemplateOptions novaNetworks(Set<Network> novaNetworks) {
this.novaNetworks = novaNetworks;

View File

@ -158,9 +158,9 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
ListenableFuture<AtomicReference<NodeMetadata>> future = super.createNodeInGroupWithNameAndTemplate(group, name, template);
final NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(template.getOptions());
if (templateOptions.shouldAutoAssignFloatingIp()) {
ListenableFuture<AtomicReference<NodeAndNovaTemplateOptions>> nodeAndNovaTemplateOptions = Futures.transform(future,
new Function<AtomicReference<NodeMetadata>, AtomicReference<NodeAndNovaTemplateOptions>>(){
ListenableFuture<AtomicReference<NodeAndNovaTemplateOptions>> nodeAndNovaTemplateOptions = Futures.transform(future,
new Function<AtomicReference<NodeMetadata>, AtomicReference<NodeAndNovaTemplateOptions>>() {
@Override
public AtomicReference<NodeAndNovaTemplateOptions> apply(AtomicReference<NodeMetadata> input) {

View File

@ -33,15 +33,12 @@ import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.domain.Network;
import org.jclouds.openstack.nova.v2_0.domain.Server;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.collect.ForwardingObject;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@ -208,7 +205,7 @@ public class CreateServerOptions implements MapBinder {
server.availabilityZone = availabilityZone;
if (userData != null)
server.user_data = base64().encode(userData);
if (configDrive == true)
if (configDrive)
server.configDrive = "true";
if (securityGroupNames.size() > 0) {
server.securityGroupNames = Sets.newLinkedHashSet();
@ -367,8 +364,8 @@ public class CreateServerOptions implements MapBinder {
* <p/>
* <h3>Note</h3>
* <p/>
* This requires that {@link NovaApi#getSecurityGroupExtensionForZone(String)} to return
* {@link Optional#isPresent present}
* This requires that {@link org.jclouds.openstack.nova.v2_0.NovaApi#getSecurityGroupExtensionForZone(String)} to return
* {@link com.google.common.base.Optional#isPresent present}
*/
public Set<String> getSecurityGroupNames() {
return securityGroupNames;
@ -413,9 +410,9 @@ public class CreateServerOptions implements MapBinder {
/**
* When you create a server from an image with the diskConfig value set to
* {@link Server#DISK_CONFIG_AUTO}, the server is built with a single partition that is expanded to
* {@link org.jclouds.openstack.nova.v2_0.domain.Server#DISK_CONFIG_AUTO}, the server is built with a single partition that is expanded to
* the disk size of the flavor selected. When you set the diskConfig attribute to
* {@link Server#DISK_CONFIG_MANUAL}, the server is built by using the partition scheme and file
* {@link org.jclouds.openstack.nova.v2_0.domain.Server#DISK_CONFIG_MANUAL}, the server is built by using the partition scheme and file
* system that is in the source image.
* <p/>
* If the target flavor disk is larger, remaining disk space is left unpartitioned. A server inherits the diskConfig

View File

@ -16,18 +16,18 @@
*/
package org.jclouds.openstack.nova.v2_0.predicates;
import com.google.common.base.Predicate;
import org.jclouds.openstack.nova.v2_0.domain.Server;
import org.jclouds.openstack.nova.v2_0.domain.ServerCreated;
import org.jclouds.openstack.nova.v2_0.features.ServerApi;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.jclouds.openstack.nova.v2_0.domain.Server.Status;
import static org.jclouds.openstack.nova.v2_0.domain.Server.Status.ACTIVE;
import static org.jclouds.openstack.nova.v2_0.domain.Server.Status.SHUTOFF;
import static org.jclouds.util.Predicates2.retry;
import org.jclouds.openstack.nova.v2_0.domain.Server;
import org.jclouds.openstack.nova.v2_0.domain.Server.Status;
import org.jclouds.openstack.nova.v2_0.features.ServerApi;
import com.google.common.base.Predicate;
/**
* This class tests to see if a Server or ServerCreated has reached a desired status. This class is most useful when
* paired with a RetryablePredicate as in the code below. Together these classes can be used to block execution until

View File

@ -58,7 +58,7 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer
host).name("Server 71592").status(Status.RUNNING).privateAddresses(ImmutableSet.of("10.4.27.237"))
.credentials(LoginCredentials.builder().password("foo").build()).build();
final NovaTemplateOptions options = NovaTemplateOptions.Builder.autoAssignFloatingIp(false);
HttpRequest createFloatingIP = HttpRequest.builder().method("POST").endpoint(
URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")).headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
@ -140,7 +140,7 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer
assertNotNull(optionsRef.get());
assertEquals(node1.getPublicAddresses(), ImmutableSet.of("10.0.0.5"));
}
public void testAllocateWhenAllocationFailsOn404LookupUnusedIpAddToServerAndUpdatesNodeMetadata() throws Exception {
HttpResponse createFloatingIPResponse = HttpResponse
.builder()

View File

@ -19,7 +19,6 @@ package org.jclouds.openstack.nova.v2_0.internal;
import java.util.Properties;
import java.util.Set;
import com.google.common.collect.*;
import org.jclouds.apis.BaseApiLiveTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.nova.v2_0.NovaApi;
@ -37,6 +36,10 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Throwables;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
/**
* Tests behavior of {@code NovaApi}

View File

@ -16,17 +16,22 @@
*/
package org.jclouds.openstack.nova.v2_0.predicates;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import static org.jclouds.openstack.nova.v2_0.domain.Server.Status.ACTIVE;
import static org.jclouds.openstack.nova.v2_0.domain.Server.Status.SHUTOFF;
import static org.jclouds.openstack.nova.v2_0.predicates.ServerPredicates.awaitActive;
import static org.jclouds.openstack.nova.v2_0.predicates.ServerPredicates.awaitShutoff;
import static org.jclouds.openstack.nova.v2_0.predicates.ServerPredicates.awaitStatus;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.features.ServerApi;
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
import org.testng.annotations.Test;
import static org.jclouds.openstack.nova.v2_0.domain.Server.Status.ACTIVE;
import static org.jclouds.openstack.nova.v2_0.domain.Server.Status.SHUTOFF;
import static org.jclouds.openstack.nova.v2_0.predicates.ServerPredicates.*;
import static org.testng.Assert.*;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
@Test(groups = "unit", testName = "ServerPredicatesMockTest")
public class ServerPredicatesMockTest extends BaseOpenStackMockTest<NovaApi> {
@ -41,7 +46,7 @@ public class ServerPredicatesMockTest extends BaseOpenStackMockTest<NovaApi> {
try {
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
ServerApi serverApi = novaApi.getServerApiForZone(("RegionOne"));
ServerApi serverApi = novaApi.getServerApiForZone("RegionOne");
boolean result = awaitActive(serverApi).apply("71752");
@ -66,7 +71,7 @@ public class ServerPredicatesMockTest extends BaseOpenStackMockTest<NovaApi> {
try {
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
ServerApi serverApi = novaApi.getServerApiForZone(("RegionOne"));
ServerApi serverApi = novaApi.getServerApiForZone("RegionOne");
boolean result = awaitShutoff(serverApi).apply("71752");
@ -88,7 +93,7 @@ public class ServerPredicatesMockTest extends BaseOpenStackMockTest<NovaApi> {
try {
NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova");
ServerApi serverApi = novaApi.getServerApiForZone(("RegionOne"));
ServerApi serverApi = novaApi.getServerApiForZone("RegionOne");
boolean result = awaitStatus(serverApi, ACTIVE, 3, 1).apply("71752");

View File

@ -28,11 +28,11 @@ public class InsufficientResourcesException extends RuntimeException {
public InsufficientResourcesException() {
super();
}
public InsufficientResourcesException(String arg0) {
super(arg0);
}
public InsufficientResourcesException(String arg0, Throwable arg1) {
super(arg0, arg1);
}