diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaAsyncClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaAsyncClient.java index 0eb81ac7ab..f9f51ccc62 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaAsyncClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaAsyncClient.java @@ -41,7 +41,8 @@ import com.google.inject.Provides; *

* * @see NovaClient - * @see + * @see * @author Adrian Cole */ public interface NovaAsyncClient { @@ -53,53 +54,53 @@ public interface NovaAsyncClient { @Provides @Region Set getConfiguredRegions(); - + /** * Provides asynchronous access to Server features. */ @Delegate ServerAsyncClient getServerClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + /** * Provides asynchronous access to Flavor features. */ @Delegate FlavorAsyncClient getFlavorClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + /** * Provides asynchronous access to Extension features. */ @Delegate ExtensionAsyncClient getExtensionClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** * Provides asynchronous access to Image features. */ @Delegate ImageAsyncClient getImageClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** * Provides asynchronous access to Floating IP features. */ @Delegate Optional getFloatingIPExtensionForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** * Provides asynchronous access to Security Group features. */ @Delegate Optional getSecurityGroupClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** * Provides asynchronous access to Key Pair features. */ @Delegate Optional getKeyPairClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaClient.java index e2e899e48b..35f65c6d8b 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaClient.java @@ -43,7 +43,8 @@ import com.google.inject.Provides; *

* * @see NovaAsyncClient - * @see + * @see * @author Adrian Cole */ @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) @@ -55,54 +56,54 @@ public interface NovaClient { @Provides @Region Set getConfiguredRegions(); - + /** * Provides synchronous access to Server features. */ @Delegate ServerClient getServerClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** * Provides synchronous access to Flavor features. */ @Delegate FlavorClient getFlavorClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** * Provides synchronous access to Extension features. */ @Delegate ExtensionClient getExtensionClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); - + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + /** * Provides synchronous access to Image features. */ @Delegate ImageClient getImageClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** * Provides synchronous access to Floating IP features. */ @Delegate Optional getFloatingIPExtensionForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** * Provides synchronous access to Security Group features. */ @Delegate SecurityGroupClient getSecurityGroupClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); /** * Provides synchronous access to Key Pair features. */ @Delegate KeyPairClient getKeyPairClientForRegion( - @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region); } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaContextBuilder.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaContextBuilder.java index 89983f6f88..08eb18e0a4 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaContextBuilder.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/NovaContextBuilder.java @@ -29,11 +29,10 @@ import com.google.inject.Module; /** * A context builder for getting nova clients. - * + * * @author Adrian Cole */ -public class NovaContextBuilder extends ComputeServiceContextBuilder -{ +public class NovaContextBuilder extends ComputeServiceContextBuilder { public NovaContextBuilder(Properties props) { super(NovaClient.class, NovaAsyncClient.class, props); diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapter.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapter.java index 890d807d4c..5cb9b7a535 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapter.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapter.java @@ -42,12 +42,12 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; /** - * The adapter used by the NovaComputeServiceContextModule to interface the nova-specific domain model to the computeService generic domain model. - * + * The adapter used by the NovaComputeServiceContextModule to interface the + * nova-specific domain model to the computeService generic domain model. + * * @author Matt Stephenson */ -public class NovaComputeServiceAdapter implements ComputeServiceAdapter -{ +public class NovaComputeServiceAdapter implements ComputeServiceAdapter { private final NovaClient novaClient; private final ServerClient defaultLocationServerClient; @@ -55,15 +55,13 @@ public class NovaComputeServiceAdapter implements ComputeServiceAdapter regions; - @Inject - public NovaComputeServiceAdapter(NovaClient novaClient) - { + public NovaComputeServiceAdapter(NovaClient novaClient) { this.novaClient = novaClient; regions = novaClient.getConfiguredRegions(); - if (regions.isEmpty()) - { - throw new IllegalStateException("No regions exist for this compute service. The Nova compute service requires at least 1 region."); + if (regions.isEmpty()) { + throw new IllegalStateException( + "No regions exist for this compute service. The Nova compute service requires at least 1 region."); } String region = regions.iterator().next(); this.defaultLocationServerClient = novaClient.getServerClientForRegion(region); @@ -72,78 +70,68 @@ public class NovaComputeServiceAdapter implements ComputeServiceAdapter createNodeWithGroupEncodedIntoName(String tag, String name, Template template) - { - ServerClient serverClient = template.getLocation() != null ? novaClient.getServerClientForRegion(template.getLocation().getId()) : defaultLocationServerClient; + public NodeAndInitialCredentials createNodeWithGroupEncodedIntoName(String tag, String name, + Template template) { + ServerClient serverClient = template.getLocation() != null ? novaClient.getServerClientForRegion(template + .getLocation().getId()) : defaultLocationServerClient; // TODO: make NovaTemplateOptions with the following: // security group, key pair, floating ip (attach post server-create?) Server server = serverClient.createServer(name, template.getImage().getId(), template.getHardware().getId()); - return new NodeAndInitialCredentials(server, server.getId() + "", LoginCredentials.builder().password(server.getAdminPass()).build()); + return new NodeAndInitialCredentials(server, server.getId() + "", LoginCredentials.builder() + .password(server.getAdminPass()).build()); } @Override - public Iterable listHardwareProfiles() - { + public Iterable listHardwareProfiles() { return defaultFlavorClient.listFlavorsInDetail(); } @Override - public Iterable listImages() - { + public Iterable listImages() { return defaultImageClient.listImagesInDetail(); } @Override - public Iterable listLocations() - { - return Iterables.transform(novaClient.getConfiguredRegions(), new Function() - { + public Iterable listLocations() { + return Iterables.transform(novaClient.getConfiguredRegions(), new Function() { @Override - public Location apply(@Nullable String region) - { + public Location apply(@Nullable String region) { return new LocationBuilder().id(region).description(region).build(); } }); } @Override - public Server getNode(String id) - { + public Server getNode(String id) { return defaultLocationServerClient.getServer(id); } @Override - public void destroyNode(String id) - { + public void destroyNode(String id) { defaultLocationServerClient.deleteServer(id); } @Override - public void rebootNode(String id) - { + public void rebootNode(String id) { defaultLocationServerClient.rebootServer(id, RebootType.SOFT); } @Override - public void resumeNode(String id) - { + public void resumeNode(String id) { throw new UnsupportedOperationException("suspend not supported"); } @Override - public void suspendNode(String id) - { + public void suspendNode(String id) { throw new UnsupportedOperationException("suspend not supported"); } @Override - public Iterable listNodes() - { + public Iterable listNodes() { ImmutableSet.Builder servers = new ImmutableSet.Builder(); - for (String region : regions) - { + for (String region : regions) { servers.addAll(novaClient.getServerClientForRegion(region).listServersInDetail()); } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/config/NovaComputeServiceContextModule.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/config/NovaComputeServiceContextModule.java index 7304183ebb..39bce289a3 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/config/NovaComputeServiceContextModule.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/config/NovaComputeServiceContextModule.java @@ -41,32 +41,37 @@ import com.google.inject.TypeLiteral; /** * Module for building a compute service context for Nova - * + * * @author Matt Stephenson */ -public class NovaComputeServiceContextModule extends - ComputeServiceAdapterContextModule -{ - public NovaComputeServiceContextModule() - { +public class NovaComputeServiceContextModule + extends + ComputeServiceAdapterContextModule { + public NovaComputeServiceContextModule() { super(NovaClient.class, NovaAsyncClient.class); } @SuppressWarnings("unchecked") @Override - protected void configure() - { + protected void configure() { super.configure(); - bind(new TypeLiteral>(){}).to(NovaComputeServiceAdapter.class); + bind( + new TypeLiteral>() { + }).to(NovaComputeServiceAdapter.class); - bind(new TypeLiteral>(){}).to(ServerToNodeMetadata.class); + bind(new TypeLiteral>() { + }).to(ServerToNodeMetadata.class); - bind(new TypeLiteral>(){}).to(NovaImageToImage.class); - bind(new TypeLiteral>(){}).to(NovaImageToOperatingSystem.class); + bind(new TypeLiteral>() { + }).to(NovaImageToImage.class); + bind(new TypeLiteral>() { + }).to(NovaImageToOperatingSystem.class); - bind(new TypeLiteral>(){}).to(FlavorToHardware.class); + bind(new TypeLiteral>() { + }).to(FlavorToHardware.class); // we aren't converting location from a provider-specific type - bind(new TypeLiteral>(){}).to((Class)IdentityFunction.class); + bind(new TypeLiteral>() { + }).to((Class) IdentityFunction.class); } } \ No newline at end of file diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/FlavorToHardware.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/FlavorToHardware.java index 858b899130..c112ace145 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/FlavorToHardware.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/FlavorToHardware.java @@ -31,33 +31,27 @@ import com.google.common.base.Function; import com.google.common.base.Supplier; /** - * A function for transforming the nova specific Flavor object to the generic Hardware object. - * + * A function for transforming the nova specific Flavor object to the generic + * Hardware object. + * * @author Matt Stephenson */ -public class FlavorToHardware implements Function -{ - +public class FlavorToHardware implements Function { + private final Supplier defaultLocation; @Inject - public FlavorToHardware(Supplier defaultLocation) - { + public FlavorToHardware(Supplier defaultLocation) { this.defaultLocation = defaultLocation; } @Override - public Hardware apply(Flavor flavor) - { + public Hardware apply(Flavor flavor) { return new HardwareBuilder() - // TODO: scope id to region, if there's a chance for conflict - .id(flavor.getId()) - .providerId(flavor.getId()) - .name(flavor.getName()) - .ram(flavor.getRam()) - .processor(new Processor(flavor.getVcpus(), 1.0)) - .volume(new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true)) - .location(defaultLocation.get()) - .build(); + // TODO: scope id to region, if there's a chance for conflict + .id(flavor.getId()).providerId(flavor.getId()).name(flavor.getName()).ram(flavor.getRam()) + .processor(new Processor(flavor.getVcpus(), 1.0)) + .volume(new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true)).location(defaultLocation.get()) + .build(); } } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToImage.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToImage.java index e2fd03802c..df91f0d7c2 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToImage.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToImage.java @@ -29,33 +29,27 @@ import com.google.common.base.Function; import com.google.common.base.Supplier; /** - * A function for transforming a nova-specific Image into a generic Image object. - * + * A function for transforming a nova-specific Image into a generic Image + * object. + * * @author Matt Stephenson */ -public class NovaImageToImage implements Function -{ +public class NovaImageToImage implements Function { private final Function imageToOs; private final Supplier defaultLocation; @Inject - public NovaImageToImage(Function imageToOs, Supplier defaultLocation) - { + public NovaImageToImage(Function imageToOs, + Supplier defaultLocation) { this.imageToOs = imageToOs; this.defaultLocation = defaultLocation; } @Override - public Image apply(org.jclouds.openstack.nova.v1_1.domain.Image image) - { + public Image apply(org.jclouds.openstack.nova.v1_1.domain.Image image) { return new ImageBuilder() - // TODO: scope id to region, if there's a chance for conflict - .id(image.getId()) - .providerId(image.getId()) - .name(image.getName()) - .operatingSystem(imageToOs.apply(image)) - .description(image.getName()) - .location(defaultLocation.get()) - .build(); + // TODO: scope id to region, if there's a chance for conflict + .id(image.getId()).providerId(image.getId()).name(image.getName()).operatingSystem(imageToOs.apply(image)) + .description(image.getName()).location(defaultLocation.get()).build(); } } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToOperatingSystem.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToOperatingSystem.java index 4ae42910d5..6e79b1f8ba 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToOperatingSystem.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToOperatingSystem.java @@ -43,12 +43,12 @@ import com.google.common.base.Splitter; import com.google.common.collect.Iterables; /** - * A function for transforming a nova specific Image into a generic OperatingSystem object. - * + * A function for transforming a nova specific Image into a generic + * OperatingSystem object. + * * @author Matt Stephenson */ -public class NovaImageToOperatingSystem implements Function -{ +public class NovaImageToOperatingSystem implements Function { public static final Pattern DEFAULT_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)"); // Windows Server 2008 R2 x64 public static final Pattern WINDOWS_PATTERN = Pattern.compile("Windows (.*) (x[86][64])"); @@ -60,13 +60,11 @@ public class NovaImageToOperatingSystem implements Function> osVersionMap; @Inject - public NovaImageToOperatingSystem(Map> osVersionMap) - { + public NovaImageToOperatingSystem(Map> osVersionMap) { this.osVersionMap = osVersionMap; } - public OperatingSystem apply(final Image from) - { + public OperatingSystem apply(final Image from) { OsFamily osFamily = null; String osVersion = null; @@ -74,42 +72,31 @@ public class NovaImageToOperatingSystem implements Function imageNameParts = Splitter.on(CharMatcher.WHITESPACE).trimResults().split(imageName.toLowerCase()); + } else { + final Iterable imageNameParts = Splitter.on(CharMatcher.WHITESPACE).trimResults() + .split(imageName.toLowerCase()); - osFamily = Iterables.find(Arrays.asList(OsFamily.values()), new Predicate() - { + osFamily = Iterables.find(Arrays.asList(OsFamily.values()), new Predicate() { @Override - public boolean apply(@Nullable OsFamily osFamily) - { + public boolean apply(@Nullable OsFamily osFamily) { return Iterables.any(imageNameParts, Predicates.equalTo(osFamily.name().toLowerCase())); } }); } Matcher matcher = DEFAULT_PATTERN.matcher(imageName); - if (matcher.find() && matcher.groupCount() >= 3) - { + if (matcher.find() && matcher.groupCount() >= 3) { osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(3), osVersionMap); } } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerToNodeMetadata.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerToNodeMetadata.java index a1fb477dd0..cc75099af7 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerToNodeMetadata.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerToNodeMetadata.java @@ -18,8 +18,6 @@ */ package org.jclouds.openstack.nova.v1_1.compute.functions; -import java.util.Map; - import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.openstack.nova.v1_1.domain.Address; @@ -30,33 +28,30 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; /** - * A function for transforming a nova-specific Server into a generic NodeMetadata object. - * + * A function for transforming a nova-specific Server into a generic + * NodeMetadata object. + * * @author Matt Stephenson */ -public class ServerToNodeMetadata implements Function -{ +public class ServerToNodeMetadata implements Function { @Override - public NodeMetadata apply(Server server) - { + public NodeMetadata apply(Server server) { return new NodeMetadataBuilder() - // TODO: scope id to region, if there's a chance for conflict - .id(server.getId()) - .providerId(server.getId()) - .name(server.getName()) - .publicAddresses(Iterables.transform(server.getPublicAddresses(), new AddressToStringTransformationFunction())) - .privateAddresses(Iterables.transform(server.getPrivateAddresses(), new AddressToStringTransformationFunction())) - .state(server.getStatus().getNodeState()) - .userMetadata(ImmutableMap.copyOf(server.getMetadata())) - .build(); + // TODO: scope id to region, if there's a chance for conflict + .id(server.getId()) + .providerId(server.getId()) + .name(server.getName()) + .publicAddresses( + Iterables.transform(server.getPublicAddresses(), new AddressToStringTransformationFunction())) + .privateAddresses( + Iterables.transform(server.getPrivateAddresses(), new AddressToStringTransformationFunction())) + .state(server.getStatus().getNodeState()).userMetadata(ImmutableMap.copyOf(server.getMetadata())).build(); } - private class AddressToStringTransformationFunction implements Function - { + private class AddressToStringTransformationFunction implements Function { @Override - public String apply(Address address) - { + public String apply(Address address) { return address.getAddr(); } } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaParserModule.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaParserModule.java index 3978500918..63209fb4f0 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaParserModule.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaParserModule.java @@ -38,8 +38,7 @@ public class NovaParserModule extends AbstractModule { @Provides @Singleton public Map provideCustomAdapterBindings() { - return ImmutableMap.of( - ); + return ImmutableMap. of(); } @Override diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaRestClientModule.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaRestClientModule.java index 2f57e346c6..0dea102f98 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaRestClientModule.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/config/NovaRestClientModule.java @@ -57,15 +57,16 @@ import com.google.common.collect.ImmutableMap; @ConfiguresRestClient public class NovaRestClientModule extends RestClientModule { - public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// - .put(ServerClient.class, ServerAsyncClient.class)// - .put(FlavorClient.class, FlavorAsyncClient.class) - .put(ImageClient.class, ImageAsyncClient.class) - .put(ExtensionClient.class, ExtensionAsyncClient.class) - .put(FloatingIPClient.class, FloatingIPAsyncClient.class) - .put(SecurityGroupClient.class, SecurityGroupAsyncClient.class) - .put(KeyPairClient.class, KeyPairAsyncClient.class) - .build(); + public static final Map, Class> DELEGATE_MAP = ImmutableMap + ., Class> builder() + // + .put(ServerClient.class, ServerAsyncClient.class) + // + .put(FlavorClient.class, FlavorAsyncClient.class).put(ImageClient.class, ImageAsyncClient.class) + .put(ExtensionClient.class, ExtensionAsyncClient.class) + .put(FloatingIPClient.class, FloatingIPAsyncClient.class) + .put(SecurityGroupClient.class, SecurityGroupAsyncClient.class) + .put(KeyPairClient.class, KeyPairAsyncClient.class).build(); public NovaRestClientModule() { super(NovaClient.class, NovaAsyncClient.class, DELEGATE_MAP); @@ -80,8 +81,10 @@ public class NovaRestClientModule extends RestClientModule */ public class Extension extends Resource { @@ -78,7 +80,7 @@ public class Extension extends Resource { public Builder fromExtension(Extension in) { return fromResource(in).namespace(in.getNamespace()).alias(in.getAlias()).updated(in.getUpdated()) - .description(in.getDescription()); + .description(in.getDescription()); } /** @@ -119,8 +121,7 @@ public class Extension extends Resource { private Date updated; private String description; - protected Extension(String name, Set links, URI namespace, String alias, Date updated, - String description) { + protected Extension(String name, Set links, URI namespace, String alias, Date updated, String description) { super(alias, name, links); this.namespace = namespace; this.alias = alias; @@ -131,7 +132,7 @@ public class Extension extends Resource { public URI getNamespace() { return this.namespace; } - + @Override public String getId() { return this.alias; @@ -151,8 +152,8 @@ public class Extension extends Resource { @Override public String toString() { - return toStringHelper("").add("id", getId()).add("name", name).add("links", links).add("namespace", namespace).add( - "alias", alias).add("updated", updated).add("description", description).toString(); + return toStringHelper("").add("id", getId()).add("name", name).add("links", links).add("namespace", namespace) + .add("alias", alias).add("updated", updated).add("description", description).toString(); } } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java index a9d97767aa..1c372ddeee 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java @@ -58,12 +58,12 @@ public class Flavor extends Resource { this.disk = disk; return this; } - + public Builder vcpus(int vcpus) { this.vcpus = vcpus; return this; } - + public Flavor build() { return new Flavor(id, name, links, ram, disk, vcpus); } @@ -109,8 +109,7 @@ public class Flavor extends Resource { private int disk; private int vcpus; - protected Flavor(String id, String name, Set links, int ram, int disk, - int vcpus) { + protected Flavor(String id, String name, Set links, int ram, int disk, int vcpus) { super(id, name, links); this.ram = ram; this.disk = disk; @@ -131,8 +130,7 @@ public class Flavor extends Resource { @Override public String toString() { - return toStringHelper("").add("id", id).add("name", name) - .add("links", links).add("ram", ram).add("disk", disk) + return toStringHelper("").add("id", id).add("name", name).add("links", links).add("ram", ram).add("disk", disk) .add("vcpus", vcpus).toString(); } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/FloatingIP.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/FloatingIP.java index ebbbe6eb82..4bef33f85e 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/FloatingIP.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/FloatingIP.java @@ -25,8 +25,9 @@ import org.jclouds.javax.annotation.Nullable; import com.google.gson.annotations.SerializedName; /** - * A Floating IP is an IP address that can be created and associated with a Server instance. - * Floating IPs can also be disassociated and deleted from a Server instance. + * A Floating IP is an IP address that can be created and associated with a + * Server instance. Floating IPs can also be disassociated and deleted from a + * Server instance. * * @author Jeremy Daggett * @author chamerling @@ -71,8 +72,7 @@ public class FloatingIP implements Comparable { } public Builder fromFloatingIp(FloatingIP in) { - return id(in.getId()).ip(in.getIp()).fixedIp(in.getFixedIp()) - .instanceId(in.getInstanceId()); + return id(in.getId()).ip(in.getIp()).fixedIp(in.getFixedIp()).instanceId(in.getInstanceId()); } } @@ -84,8 +84,7 @@ public class FloatingIP implements Comparable { @SerializedName("instance_id") private String instanceId; - protected FloatingIP(String id, String ip, @Nullable String fixedIp, - @Nullable String instanceId) { + protected FloatingIP(String id, String ip, @Nullable String fixedIp, @Nullable String instanceId) { this.id = id; this.ip = ip; this.fixedIp = fixedIp; @@ -119,8 +118,7 @@ public class FloatingIP implements Comparable { int result = 1; result = prime * result + ((fixedIp == null) ? 0 : fixedIp.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result - + ((instanceId == null) ? 0 : instanceId.hashCode()); + result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode()); result = prime * result + ((ip == null) ? 0 : ip.hashCode()); return result; } @@ -159,8 +157,8 @@ public class FloatingIP implements Comparable { @Override public String toString() { - return toStringHelper("").add("id", id).add("ip", ip) - .add("fixedIp", fixedIp).add("instanceId", instanceId).toString(); + return toStringHelper("").add("id", id).add("ip", ip).add("fixedIp", fixedIp).add("instanceId", instanceId) + .toString(); } - + } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Image.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Image.java index 328844d91c..e9e025bd8a 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Image.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Image.java @@ -113,15 +113,13 @@ public class Image extends Resource { } public Image build() { - return new Image(id, name, links, updated, created, tenantId, userId, - status, progress, minDisk, minRam, server, metadata); + return new Image(id, name, links, updated, created, tenantId, userId, status, progress, minDisk, minRam, + server, metadata); } public Builder fromImage(Image in) { - return fromResource(in).status(in.getStatus()) - .updated(in.getUpdated()).created(in.getCreated()) - .progress(in.getProgress()).server(in.getServer()) - .metadata(in.getMetadata()); + return fromResource(in).status(in.getStatus()).updated(in.getUpdated()).created(in.getCreated()) + .progress(in.getProgress()).server(in.getServer()).metadata(in.getMetadata()); } /** @@ -170,10 +168,8 @@ public class Image extends Resource { private Resource server; private Map metadata = Maps.newHashMap(); - protected Image(String id, String name, Set links, Date updated, - Date created, String tenantId, String userId, ImageStatus status, - int progress, int minDisk, int minRam, Resource server, - Map metadata) { + protected Image(String id, String name, Set links, Date updated, Date created, String tenantId, String userId, + ImageStatus status, int progress, int minDisk, int minRam, Resource server, Map metadata) { super(id, name, links); this.updated = updated; this.created = created; @@ -229,12 +225,9 @@ public class Image extends Resource { @Override public String toString() { - return toStringHelper("").add("id", id).add("name", name) - .add("links", links).add("updated", updated) - .add("created", created).add("tenantId", tenantId) - .add("userId", userId).add("status", status) - .add("progress", progress).add("minDisk", minDisk) - .add("minRam", minRam).add("server", server) + return toStringHelper("").add("id", id).add("name", name).add("links", links).add("updated", updated) + .add("created", created).add("tenantId", tenantId).add("userId", userId).add("status", status) + .add("progress", progress).add("minDisk", minDisk).add("minRam", minRam).add("server", server) .add("metadata", metadata).toString(); } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/KeyPair.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/KeyPair.java index 35a7a5ade1..e48111a27c 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/KeyPair.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/KeyPair.java @@ -24,7 +24,7 @@ import org.jclouds.javax.annotation.Nullable; import com.google.gson.annotations.SerializedName; -public class KeyPair implements Comparable{ +public class KeyPair implements Comparable { public static Builder builder() { return new Builder(); } @@ -71,8 +71,7 @@ public class KeyPair implements Comparable{ } public Builder fromKeyPair(KeyPair in) { - return publicKey(in.getPublicKey()).privateKey(in.getPrivateKey()) - .userId(in.getUserId()).name(in.getName()) + return publicKey(in.getPublicKey()).privateKey(in.getPrivateKey()).userId(in.getUserId()).name(in.getName()) .fingerprint(in.getFingerprint()); } @@ -87,8 +86,7 @@ public class KeyPair implements Comparable{ String name; String fingerprint; - protected KeyPair(String publicKey, String privateKey, - @Nullable String userId, String name, String fingerprint) { + protected KeyPair(String publicKey, String privateKey, @Nullable String userId, String name, String fingerprint) { this.publicKey = publicKey; this.privateKey = privateKey; this.userId = userId; @@ -116,59 +114,57 @@ public class KeyPair implements Comparable{ return this.fingerprint; } - @Override - public int compareTo(KeyPair o) { - return this.fingerprint.compareTo(o.getFingerprint()); - } + @Override + public int compareTo(KeyPair o) { + return this.fingerprint.compareTo(o.getFingerprint()); + } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((publicKey == null) ? 0 : publicKey.hashCode()); - result = prime * result + ((privateKey == null) ? 0 : privateKey.hashCode()); - result = prime * result - + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((fingerprint == null) ? 0 : fingerprint.hashCode()); - return result; - } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((publicKey == null) ? 0 : publicKey.hashCode()); + result = prime * result + ((privateKey == null) ? 0 : privateKey.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((fingerprint == null) ? 0 : fingerprint.hashCode()); + return result; + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + KeyPair other = (KeyPair) obj; + if (publicKey == null) { + if (other.publicKey != null) return false; - if (getClass() != obj.getClass()) + } else if (!publicKey.equals(other.publicKey)) + return false; + if (privateKey == null) { + if (other.privateKey != null) return false; - KeyPair other = (KeyPair) obj; - if (publicKey == null) { - if (other.publicKey != null) - return false; - } else if (!publicKey.equals(other.publicKey)) + } else if (!privateKey.equals(other.privateKey)) + return false; + if (name == null) { + if (other.name != null) return false; - if (privateKey == null) { - if (other.privateKey != null) - return false; - } else if (!privateKey.equals(other.privateKey)) + } else if (!name.equals(other.name)) + return false; + if (fingerprint == null) { + if (other.fingerprint != null) return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (fingerprint == null) { - if (other.fingerprint != null) - return false; - } else if (!fingerprint.equals(other.fingerprint)) - return false; - return true; - } + } else if (!fingerprint.equals(other.fingerprint)) + return false; + return true; + } @Override public String toString() { - return toStringHelper("").add("publicKey", publicKey) - .add("privateKey", privateKey).add("userId", userId) + return toStringHelper("").add("publicKey", publicKey).add("privateKey", privateKey).add("userId", userId) .add("name", name).add("fingerprint", fingerprint).toString(); } } \ No newline at end of file diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/SecurityGroup.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/SecurityGroup.java index a2fc8894e8..09dedb722d 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/SecurityGroup.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/SecurityGroup.java @@ -23,15 +23,14 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Set; -import com.google.common.collect.ImmutableSet; import org.jclouds.javax.annotation.Nullable; +import com.google.common.collect.ImmutableSet; import com.google.gson.annotations.SerializedName; - /** * Defines a security group - * + * */ public class SecurityGroup { public static Builder builder() { @@ -43,7 +42,7 @@ public class SecurityGroup { } public static class Builder { - + private String id; private String tenantId; private String name; @@ -69,7 +68,7 @@ public class SecurityGroup { this.description = description; return this; } - + public Builder rules(Set rules) { this.rules = rules; return this; @@ -79,23 +78,22 @@ public class SecurityGroup { return new SecurityGroup(id, tenantId, name, description, rules); } - public Builder fromSecurityGroup(SecurityGroup in) { - return id(in.getId()).tenantId(in.getTenantId()).name(in.getName()) - .description(in.getDescription()).rules(in.getRules()); + return id(in.getId()).tenantId(in.getTenantId()).name(in.getName()).description(in.getDescription()) + .rules(in.getRules()); } - + } - + protected String id; @SerializedName("tenant_id") protected String tenantId; protected String name; protected String description; protected Set rules; - - protected SecurityGroup(String id, String tenantId, @Nullable String name, - @Nullable String description, Set rules) { + + protected SecurityGroup(String id, String tenantId, @Nullable String name, @Nullable String description, + Set rules) { this.id = id; this.tenantId = tenantId; this.name = name; @@ -118,18 +116,16 @@ public class SecurityGroup { public String getDescription() { return this.description; } - + public Set getRules() { return this.rules; } - - + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((rules == null) ? 0 : rules.hashCode()); @@ -176,9 +172,8 @@ public class SecurityGroup { @Override public String toString() { - return toStringHelper("").add("id", id).add("name", name) - .add("tenantId", tenantId).add("description", description).add("rules", rules) - .toString(); + return toStringHelper("").add("id", id).add("name", name).add("tenantId", tenantId) + .add("description", description).add("rules", rules).toString(); } } \ No newline at end of file diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/SecurityGroupRule.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/SecurityGroupRule.java index c976611e67..7618f3133e 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/SecurityGroupRule.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/SecurityGroupRule.java @@ -30,7 +30,7 @@ import com.google.gson.annotations.SerializedName; * */ public class SecurityGroupRule implements Comparable { - + public static enum IpProtocol { TCP, UDP, ICMP, UNRECOGNIZED; public String value() { @@ -50,8 +50,7 @@ public class SecurityGroupRule implements Comparable { } } } - - + public static Builder builder() { return new Builder(); } @@ -108,18 +107,15 @@ public class SecurityGroupRule implements Comparable { } public SecurityGroupRule build() { - return new SecurityGroupRule(id, fromPort, group, ipProtocol, toPort, - parentGroupId, ipRange); + return new SecurityGroupRule(id, fromPort, group, ipProtocol, toPort, parentGroupId, ipRange); } public Builder fromSecurityGroupRule(SecurityGroupRule in) { - return id(in.getId()).fromPort(in.getFromPort()).group(in.getGroup()) - .ipProtocol(in.getIpProtocol()).toPort(in.getToPort()).parentGroupId(in.getParentGroupId()) - .ipRange(in.getIpRange()); + return id(in.getId()).fromPort(in.getFromPort()).group(in.getGroup()).ipProtocol(in.getIpProtocol()) + .toPort(in.getToPort()).parentGroupId(in.getParentGroupId()).ipRange(in.getIpRange()); } } - protected String id; @SerializedName(value = "from_port") @@ -139,10 +135,9 @@ public class SecurityGroupRule implements Comparable { @SerializedName(value = "ip_range") protected Map ipRange; - - - protected SecurityGroupRule(String id, int fromPort, Map group, - IpProtocol ipProtocol, int toPort, String parentGroupId, Map ipRange) { + + protected SecurityGroupRule(String id, int fromPort, Map group, IpProtocol ipProtocol, int toPort, + String parentGroupId, Map ipRange) { this.id = id; this.fromPort = fromPort; this.group = group; @@ -171,20 +166,20 @@ public class SecurityGroupRule implements Comparable { public int getToPort() { return this.toPort; } - + public String getParentGroupId() { return this.parentGroupId; } - + public Map getIpRange() { return this.ipRange; } @Override public int compareTo(SecurityGroupRule o) { - return this.id.compareTo(o.getId()); + return this.id.compareTo(o.getId()); } - + @Override public int hashCode() { final int prime = 31; @@ -192,11 +187,9 @@ public class SecurityGroupRule implements Comparable { result = prime * result + fromPort; result = prime * result + ((group == null) ? 0 : group.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result - + ((ipProtocol == null) ? 0 : ipProtocol.hashCode()); + result = prime * result + ((ipProtocol == null) ? 0 : ipProtocol.hashCode()); result = prime * result + ((ipRange == null) ? 0 : ipRange.hashCode()); - result = prime * result - + ((parentGroupId == null) ? 0 : parentGroupId.hashCode()); + result = prime * result + ((parentGroupId == null) ? 0 : parentGroupId.hashCode()); result = prime * result + toPort; return result; } @@ -241,11 +234,9 @@ public class SecurityGroupRule implements Comparable { @Override public String toString() { - return toStringHelper("").add("id", id).add("fromPort", fromPort) - .add("group", group).add("ipProtocol", ipProtocol) - .add("toPort", toPort).add("parentGroupId", parentGroupId) + return toStringHelper("").add("id", id).add("fromPort", fromPort).add("group", group) + .add("ipProtocol", ipProtocol).add("toPort", toPort).add("parentGroupId", parentGroupId) .add("ipRange", ipRange).toString(); } - } \ No newline at end of file diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java index 2e6e2c770b..a34cc2df98 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java @@ -45,8 +45,8 @@ import com.google.common.collect.Multimap; import com.google.gson.annotations.SerializedName; /** - * A server is a virtual machine instance in the compute system. Flavor and image are requisite - * elements when creating a server. + * A server is a virtual machine instance in the compute system. Flavor and + * image are requisite elements when creating a server. * * @author Adrian Cole * @see privateAddresses) { - this.addresses.replaceValues(Address.Type.PRIVATE, ImmutableSet.copyOf(checkNotNull(privateAddresses, - "privateAddresses"))); + this.addresses.replaceValues(Address.Type.PRIVATE, + ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"))); return this; } @@ -210,8 +210,8 @@ public class Server extends Resource { * @see Server#getPublicAddresses() */ public Builder publicAddresses(Set

publicAddresses) { - this.addresses.replaceValues(Address.Type.PUBLIC, ImmutableSet.copyOf(checkNotNull(publicAddresses, - "publicAddresses"))); + this.addresses.replaceValues(Address.Type.PUBLIC, + ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"))); return this; } @@ -226,7 +226,7 @@ public class Server extends Resource { public Server build() { // return new Server(id, name, links, addresses); return new Server(id, name, links, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, status, - progress, image, flavor, adminPass, addresses, metadata); + progress, image, flavor, adminPass, addresses, metadata); } public Builder fromServer(Server in) { @@ -285,9 +285,9 @@ public class Server extends Resource { protected Map metadata; protected Server(String id, String name, Set links, String tenantId, String userId, Date updated, - Date created, String hostId, String accessIPv4, String accessIPv6, ServerStatus status, int progress, - Resource image, Resource flavor, String adminPass, Multimap addresses, - Map metadata) { + Date created, String hostId, String accessIPv4, String accessIPv6, ServerStatus status, int progress, + Resource image, Resource flavor, String adminPass, Multimap addresses, + Map metadata) { super(id, name, links); this.tenantId = tenantId; this.userId = userId; @@ -386,13 +386,13 @@ public class Server extends Resource { Set
publicAddresses = addresses.get(Address.Type.PUBLIC); Set
privateAddresses = addresses.get(Address.Type.PRIVATE); if (publicAddresses != null) { - returnMapBuilder.putAll(Address.Type.PUBLIC, Iterables.filter(publicAddresses, Predicates - .not(IsPrivateAddress.INSTANCE))); + returnMapBuilder.putAll(Address.Type.PUBLIC, + Iterables.filter(publicAddresses, Predicates.not(IsPrivateAddress.INSTANCE))); } if (privateAddresses != null) { returnMapBuilder.putAll(Address.Type.PRIVATE, Iterables.filter(privateAddresses, IsPrivateAddress.INSTANCE)); - returnMapBuilder.putAll(Address.Type.PUBLIC, Iterables.filter(privateAddresses, Predicates - .not(IsPrivateAddress.INSTANCE))); + returnMapBuilder.putAll(Address.Type.PUBLIC, + Iterables.filter(privateAddresses, Predicates.not(IsPrivateAddress.INSTANCE))); } ImmutableSetMultimap returnMap = returnMapBuilder.build(); @@ -415,10 +415,10 @@ public class Server extends Resource { @Override public String toString() { - return toStringHelper("").add("id", id).add("name", name).add("tenantId", tenantId).add("userId", userId).add( - "hostId", hostId).add("updated", updated).add("created", created).add("accessIPv4", accessIPv4).add( - "accessIPv6", accessIPv6).add("status", status).add("progress", progress).add("image", image).add( - "flavor", flavor).add("metadata", metadata).add("links", links).add("addresses", addresses).add( - "adminPass", adminPass).toString(); + return toStringHelper("").add("id", id).add("name", name).add("tenantId", tenantId).add("userId", userId) + .add("hostId", hostId).add("updated", updated).add("created", created).add("accessIPv4", accessIPv4) + .add("accessIPv6", accessIPv6).add("status", status).add("progress", progress).add("image", image) + .add("flavor", flavor).add("metadata", metadata).add("links", links).add("addresses", addresses) + .add("adminPass", adminPass).toString(); } } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/ServerStatus.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/ServerStatus.java index 799b614f41..722a7a1714 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/ServerStatus.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/ServerStatus.java @@ -32,25 +32,15 @@ import org.jclouds.compute.domain.NodeState; */ public enum ServerStatus { - ACTIVE (NodeState.RUNNING), - BUILD (NodeState.PENDING), - REBUILD (NodeState.PENDING), - SUSPENDED (NodeState.SUSPENDED), - RESIZE (NodeState.PENDING), - VERIFY_RESIZE(NodeState.PENDING), - REVERT_RESIZE(NodeState.PENDING), - PASSWORD (NodeState.PENDING), - REBOOT (NodeState.PENDING), - HARD_REBOOT (NodeState.PENDING), - DELETED (NodeState.TERMINATED), - UNKNOWN (NodeState.UNRECOGNIZED), - ERROR (NodeState.ERROR), - UNRECOGNIZED (NodeState.UNRECOGNIZED); + ACTIVE(NodeState.RUNNING), BUILD(NodeState.PENDING), REBUILD(NodeState.PENDING), SUSPENDED(NodeState.SUSPENDED), RESIZE( + NodeState.PENDING), VERIFY_RESIZE(NodeState.PENDING), REVERT_RESIZE(NodeState.PENDING), PASSWORD( + NodeState.PENDING), REBOOT(NodeState.PENDING), HARD_REBOOT(NodeState.PENDING), DELETED(NodeState.TERMINATED), UNKNOWN( + NodeState.UNRECOGNIZED), ERROR(NodeState.ERROR), UNRECOGNIZED(NodeState.UNRECOGNIZED); private final NodeState nodeState; ServerStatus(NodeState nodeState) { - this.nodeState = nodeState; + this.nodeState = nodeState; } public String value() { @@ -65,8 +55,7 @@ public enum ServerStatus { } } - public NodeState getNodeState() - { - return nodeState; - } + public NodeState getNodeState() { + return nodeState; + } } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/ExtensionNamespaces.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/ExtensionNamespaces.java index 725622493a..df97dda590 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/ExtensionNamespaces.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/ExtensionNamespaces.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.nova.v1_1.extensions; - /** * Extension namespaces * diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClient.java index 6c53a719e9..4429053883 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClient.java @@ -74,7 +74,7 @@ public interface FloatingIPClient { * @param address * the IP address to add * - * NOTE: Possibly move this to ServerClient? + * NOTE: Possibly move this to ServerClient? */ void addFloatingIP(String serverId, String address); @@ -86,7 +86,7 @@ public interface FloatingIPClient { * @param address * the IP address to remove * - * NOTE: Possibly move this to ServerClient? + * NOTE: Possibly move this to ServerClient? */ void removeFloatingIP(String serverId, String address); } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairAsyncClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairAsyncClient.java index 1635f50ad6..415a1490e9 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairAsyncClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairAsyncClient.java @@ -53,7 +53,9 @@ import com.google.common.util.concurrent.ListenableFuture; * @see KeyPairClient * @author Jeremy Daggett * @see ExtensionAsyncClient - * @see + * @see * @see * @see */ @@ -68,7 +70,6 @@ public interface KeyPairAsyncClient { @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture>> listKeyPairs(); - @POST @Path("/os-keypairs") @@ -85,12 +86,12 @@ public interface KeyPairAsyncClient { @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"keypair\":%7B\"name\":\"{name}\",\"public_key\":\"{publicKey}\"%7D%7D") ListenableFuture createKeyPairWithPublicKey(@PayloadParam("name") String name, - @PayloadParam("publicKey") String publicKey); + @PayloadParam("publicKey") String publicKey); @DELETE @Path("/os-keypairs/{name}") @ExceptionParser(ReturnFalseOnNotFoundOr404.class) @Consumes ListenableFuture deleteKeyPair(@PathParam("name") String name); - + } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClient.java index cca7c89bbd..ae58a7bdd6 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClient.java @@ -43,7 +43,7 @@ public interface KeyPairClient { * * @return all Key Pairs */ - Set> listKeyPairs(); + Set> listKeyPairs(); /** * Create a Key Pair. diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupAsyncClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupAsyncClient.java index f45b9070ff..9da280bd35 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupAsyncClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupAsyncClient.java @@ -52,7 +52,9 @@ import com.google.common.util.concurrent.ListenableFuture; * * @see SecurityGroupClient * @author Jeremy Daggett - * @see + * @see * @see * @see */ @@ -70,7 +72,7 @@ public interface SecurityGroupAsyncClient { @Path("/os-security-groups") @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture> listSecurityGroups(); - + /** * @see SecurityGroupClient#getSecurityGroup */ @@ -81,7 +83,6 @@ public interface SecurityGroupAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getSecurityGroup(@PathParam("id") String id); - /** * @see SecurityGroupClient#createSecurityGroup */ @@ -93,8 +94,7 @@ public interface SecurityGroupAsyncClient { @Produces(MediaType.APPLICATION_JSON) @Payload("%7B\"security_group\":%7B\"name\":\"{name}\",\"description\":\"{description}\"%7D%7D") ListenableFuture createSecurityGroup(@PayloadParam("name") String name, - @PayloadParam("description") String description); - + @PayloadParam("description") String description); /** * @see SecurityGroupClient#deleteSecurityGroup @@ -105,7 +105,6 @@ public interface SecurityGroupAsyncClient { @Consumes ListenableFuture deleteSecurityGroup(@PathParam("id") String id); - /** * @see SecurityGroupClient#createSecurityGroupRule */ @@ -115,17 +114,13 @@ public interface SecurityGroupAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Payload("%7B\"security_group_rule\":%7B\"ip_protocol\":\"{ip_protocol}\"," + - "\"from_port\":\"{from_port}\",\"to_port\":\"{to_port}\"," + - "\"cidr\":\"{cidr}\",\"group_id\":\"{group_id}\",\"parent_group_id\":\"{parent_group_id}\"%7D%7D") - ListenableFuture createSecurityGroupRule( - @PayloadParam("ip_protocol") String ip_protocol, - @PayloadParam("from_port") String from_port, - @PayloadParam("to_port") String to_port, - @PayloadParam("cidr") String cidr, - @PayloadParam("group_id") String group_id, - @PayloadParam("parent_group_id") String parent_group_id); - + @Payload("%7B\"security_group_rule\":%7B\"ip_protocol\":\"{ip_protocol}\"," + + "\"from_port\":\"{from_port}\",\"to_port\":\"{to_port}\"," + + "\"cidr\":\"{cidr}\",\"group_id\":\"{group_id}\",\"parent_group_id\":\"{parent_group_id}\"%7D%7D") + ListenableFuture createSecurityGroupRule(@PayloadParam("ip_protocol") String ip_protocol, + @PayloadParam("from_port") String from_port, @PayloadParam("to_port") String to_port, + @PayloadParam("cidr") String cidr, @PayloadParam("group_id") String group_id, + @PayloadParam("parent_group_id") String parent_group_id); /** * @see SecurityGroupClient#deleteSecurityGroupRule diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClient.java index fc14bf12ef..47dd9ae215 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClient.java @@ -61,22 +61,22 @@ public interface SecurityGroupClient { /** * Delete a Security Group. - * + * * @return */ Boolean deleteSecurityGroup(String id); /** * Create a Security Group Rule. - * + * * @return a new Security Group Rule */ SecurityGroupRule createSecurityGroupRule(String ip_protocol, String from_port, String to_port, String cidr, - String group_id, String parent_group_id); + String group_id, String parent_group_id); /** * Delete a Security Group Rule. - * + * * @return */ Boolean deleteSecurityGroupRule(String id); diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ExtensionAsyncClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ExtensionAsyncClient.java index 54973e2d03..37d099b85a 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ExtensionAsyncClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ExtensionAsyncClient.java @@ -42,7 +42,8 @@ import com.google.common.util.concurrent.ListenableFuture; *

* * @see ExtensionClient - * @see * @author Adrian Cole */ @@ -60,7 +61,6 @@ public interface ExtensionAsyncClient { @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture> listExtensions(); - /** * @see ExtensionClient#getExtensionByAlias */ diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClient.java index ce5b5bc413..e6109e3877 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClient.java @@ -29,7 +29,8 @@ import org.jclouds.openstack.nova.v1_1.domain.Extension; *

* * @see ExtensionClient - * @see * @author Adrian Cole */ diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/FlavorAsyncClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/FlavorAsyncClient.java index dccc23d220..887b7a7d90 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/FlavorAsyncClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/FlavorAsyncClient.java @@ -43,10 +43,11 @@ import com.google.common.util.concurrent.ListenableFuture; *

* * @see FlavorClient - * @see - * @author Jeremy Daggett - * TODO: Need a ListFlavorOptions class minDisk=minDiskInGB& minRam=minRamInMB& marker=markerID&limit=int + * @author Jeremy Daggett TODO: Need a ListFlavorOptions class + * minDisk=minDiskInGB& minRam=minRamInMB& marker=markerID&limit=int */ @SkipEncoding({ '/', '=' }) @RequestFilters(AuthenticateRequest.class) diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ImageClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ImageClient.java index 4d12af704a..84ec96194a 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ImageClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ImageClient.java @@ -30,7 +30,8 @@ import org.jclouds.openstack.nova.v1_1.domain.Image; *

* * @see ImageAsyncClient - * @see * @author Adrian Cole */ @@ -63,9 +64,10 @@ public interface ImageClient { /** * Delete the specified image * - * @param id id of the image + * @param id + * id of the image * @return server or null if not found */ void deleteImage(String id); - + } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ServerAsyncClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ServerAsyncClient.java index 6fb0ca4c92..994dd290df 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ServerAsyncClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ServerAsyncClient.java @@ -55,7 +55,8 @@ import com.google.common.util.concurrent.ListenableFuture; *

* * @see ServerClient - * @see * @author Adrian Cole */ @@ -93,14 +94,14 @@ public interface ServerAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getServer(@PathParam("id") String id); - /** - * @see ServerClient#deleteServer - */ - @DELETE - @Consumes - @ExceptionParser(ReturnFalseOnNotFoundOr404.class) - @Path("/servers/{id}") - ListenableFuture deleteServer(@PathParam("id") String id); + /** + * @see ServerClient#deleteServer + */ + @DELETE + @Consumes + @ExceptionParser(ReturnFalseOnNotFoundOr404.class) + @Path("/servers/{id}") + ListenableFuture deleteServer(@PathParam("id") String id); /** * @see ServerClient#rebootServer @@ -151,7 +152,7 @@ public interface ServerAsyncClient { @Path("/servers") @MapBinder(CreateServerOptions.class) ListenableFuture createServer(@PayloadParam("name") String name, @PayloadParam("imageRef") String imageRef, - @PayloadParam("flavorRef") String flavorRef, CreateServerOptions... options); + @PayloadParam("flavorRef") String flavorRef, CreateServerOptions... options); /** * @see ServerClient#rebuildServer @@ -162,7 +163,6 @@ public interface ServerAsyncClient { @MapBinder(RebuildServerOptions.class) ListenableFuture rebuildServer(@PathParam("id") String id, RebuildServerOptions... options); - /** * @see ServerClient#changeAdminPass */ diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ServerClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ServerClient.java index 38024c130e..9fe0c52f4b 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ServerClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ServerClient.java @@ -33,7 +33,8 @@ import org.jclouds.openstack.nova.v1_1.options.RebuildServerOptions; *

* * @see ServerAsyncClient - * @see * @author Adrian Cole */ @@ -65,91 +66,92 @@ public interface ServerClient { /** * Create a new server - * + * * @param name - * name of the server to create + * name of the server to create * @param imageRef - * reference to the image for the server to use + * reference to the image for the server to use * @param flavorRef - * reference to the flavor to use when creating the server + * reference to the flavor to use when creating the server * @param options - * optional parameters to be passed into the server creation request + * optional parameters to be passed into the server creation + * request * @return the newly created server */ Server createServer(String name, String imageRef, String flavorRef, CreateServerOptions... options); /** * Terminate and delete a server. - * + * * @param id * id of the server * @return True if successful, False otherwise */ Boolean deleteServer(String id); - /** - * Reboot a server. - * - * @param id - * id of the server - * @param rebootType - * The type of reboot to perform (Hard/Soft) - */ + /** + * Reboot a server. + * + * @param id + * id of the server + * @param rebootType + * The type of reboot to perform (Hard/Soft) + */ void rebootServer(String id, RebootType rebootType); - /** - * Resize a server to a new flavor size. - * - * @param id - * id of the server - * @param flavorId - * id of the new flavor to use - */ + /** + * Resize a server to a new flavor size. + * + * @param id + * id of the server + * @param flavorId + * id of the new flavor to use + */ void resizeServer(String id, String flavorId); - /** - * Confirm a resize operation. - * - * @param id - * id of the server + /** + * Confirm a resize operation. + * + * @param id + * id of the server */ void confirmResizeServer(String id); - /** - * Revert a resize operation. - * - * @param id - * id of the server - */ + /** + * Revert a resize operation. + * + * @param id + * id of the server + */ void revertResizeServer(String id); - /** - * Rebuild a server. - * - * @param id - * id of the server - * @param options - * Optional paramaters to the rebuilding operation. + /** + * Rebuild a server. + * + * @param id + * id of the server + * @param options + * Optional paramaters to the rebuilding operation. */ void rebuildServer(String id, RebuildServerOptions... options); - /** - * Change the administrative password to a server. - * - * @param id - * id of the server - * @param adminPass - * The new administrative password to use + /** + * Change the administrative password to a server. + * + * @param id + * id of the server + * @param adminPass + * The new administrative password to use */ void changeAdminPass(String id, String adminPass); - /** - * Rename a server. - * - * @param id - * id of the server - * @param newName - * The new name for the server + /** + * Rename a server. + * + * @param id + * id of the server + * @param newName + * The new name for the server */ void renameServer(String id, String newName); } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/handlers/NovaErrorHandler.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/handlers/NovaErrorHandler.java index ba60c0947a..d96ea6a8a5 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/handlers/NovaErrorHandler.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/handlers/NovaErrorHandler.java @@ -35,7 +35,7 @@ import org.jclouds.rest.ResourceNotFoundException; * @author Adrian Cole * */ -//TODO: is there error spec someplace? let's type errors, etc. +// TODO: is there error spec someplace? let's type errors, etc. @Singleton public class NovaErrorHandler implements HttpErrorHandler { @@ -45,22 +45,22 @@ public class NovaErrorHandler implements HttpErrorHandler { String message = data != null ? new String(data) : null; Exception exception = message != null ? new HttpResponseException(command, response, message) - : new HttpResponseException(command, response); + : new HttpResponseException(command, response); message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), - response.getStatusLine()); + response.getStatusLine()); switch (response.getStatusCode()) { - case 401: - case 403: - exception = new AuthorizationException(message, exception); - break; - case 404: - if (!command.getCurrentRequest().getMethod().equals("DELETE")) { - exception = new ResourceNotFoundException(message, exception); - } - break; - default: - exception = new HttpResponseException(command, response, message); - break; + case 401: + case 403: + exception = new AuthorizationException(message, exception); + break; + case 404: + if (!command.getCurrentRequest().getMethod().equals("DELETE")) { + exception = new ResourceNotFoundException(message, exception); + } + break; + default: + exception = new HttpResponseException(command, response, message); + break; } command.setException(exception); } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/options/CreateServerOptions.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/options/CreateServerOptions.java index c80cc16265..7f8395f0c0 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/options/CreateServerOptions.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/options/CreateServerOptions.java @@ -24,8 +24,8 @@ import static com.google.common.base.Preconditions.checkState; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import javax.inject.Inject; @@ -57,10 +57,12 @@ public class CreateServerOptions implements MapBinder { public File(String path, byte[] contents) { this.path = checkNotNull(path, "path"); this.contents = Base64.encodeBytes(checkNotNull(contents, "contents")); - checkArgument(path.getBytes().length < 255, String.format( - "maximum length of path is 255 bytes. Path specified %s is %d bytes", path, path.getBytes().length)); - checkArgument(contents.length < 10 * 1024, String.format( - "maximum size of the file is 10KB. Contents specified is %d bytes", contents.length)); + checkArgument( + path.getBytes().length < 255, + String.format("maximum length of path is 255 bytes. Path specified %s is %d bytes", path, + path.getBytes().length)); + checkArgument(contents.length < 10 * 1024, + String.format("maximum size of the file is 10KB. Contents specified is %d bytes", contents.length)); } public String getContents() { @@ -82,7 +84,7 @@ public class CreateServerOptions implements MapBinder { Map metadata; List personality; String key_name; - @SerializedName(value="security_groups") + @SerializedName(value = "security_groups") Set securityGroups; private ServerRequest(String name, String imageRef, String flavorRef) { @@ -102,90 +104,95 @@ public class CreateServerOptions implements MapBinder { @Override public R bindToRequest(R request, Map postParams) { ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present"), - checkNotNull(postParams.get("imageRef"), "imageRef parameter not present"), checkNotNull(postParams - .get("flavorRef"), "flavorRef parameter not present")); + checkNotNull(postParams.get("imageRef"), "imageRef parameter not present"), checkNotNull( + postParams.get("flavorRef"), "flavorRef parameter not present")); if (metadata.size() > 0) server.metadata = metadata; if (files.size() > 0) server.personality = files; if (keyName != null) - server.key_name = keyName; + server.key_name = keyName; if (securityGroups.size() > 0) { - server.securityGroups = Sets.newHashSet(); - for (String groupName : securityGroups) { - SecurityGroup group = SecurityGroup.builder().name(groupName).build(); - server.securityGroups.add(group); - } + server.securityGroups = Sets.newHashSet(); + for (String groupName : securityGroups) { + SecurityGroup group = SecurityGroup.builder().name(groupName).build(); + server.securityGroups.add(group); + } } if (adminPass != null) { - server.adminPass = adminPass; + server.adminPass = adminPass; } return bindToRequest(request, ImmutableMap.of("server", server)); } /** - * You may further customize a cloud server by injecting data into the file system of the cloud - * server itself. This is useful, for example, for inserting ssh keys, setting configuration - * files, or storing data that you want to retrieve from within the instance itself. It is - * intended to provide a minimal amount of launch-time personalization. If significant - * customization is required, a custom image should be created. The max size of the file path - * data is 255 bytes while the max size of the file contents is 10KB. Note that the file contents - * should be encoded as a Base64 string and the 10KB limit refers to the number of bytes in the - * decoded data not the number of characters in the encoded data. The maximum number of file - * path/content pairs that can be supplied is 5. Any existing files that match the specified file - * will be renamed to include the extension bak followed by a time stamp. For example, the file - * /etc/passwd will be backed up as /etc/passwd.bak.1246036261.5785. All files will have root and - * the root group as owner and group owner, respectively and will allow user and group read - * access only (-r--r-----). + * You may further customize a cloud server by injecting data into the file + * system of the cloud server itself. This is useful, for example, for + * inserting ssh keys, setting configuration files, or storing data that you + * want to retrieve from within the instance itself. It is intended to + * provide a minimal amount of launch-time personalization. If significant + * customization is required, a custom image should be created. The max size + * of the file path data is 255 bytes while the max size of the file contents + * is 10KB. Note that the file contents should be encoded as a Base64 string + * and the 10KB limit refers to the number of bytes in the decoded data not + * the number of characters in the encoded data. The maximum number of file + * path/content pairs that can be supplied is 5. Any existing files that + * match the specified file will be renamed to include the extension bak + * followed by a time stamp. For example, the file /etc/passwd will be backed + * up as /etc/passwd.bak.1246036261.5785. All files will have root and the + * root group as owner and group owner, respectively and will allow user and + * group read access only (-r--r-----). */ public CreateServerOptions withFile(String path, byte[] contents) { checkState(files.size() < 5, "maximum number of files allowed is 5"); files.add(new File(path, contents)); return this; } - + public CreateServerOptions withAdminPass(String adminPass) { - checkNotNull(adminPass, "adminPass"); - this.adminPass = adminPass; - return this; + checkNotNull(adminPass, "adminPass"); + this.adminPass = adminPass; + return this; } /** - * Custom cloud server metadata can also be supplied at launch time. This metadata is stored in - * the API system where it is retrievable by querying the API for server status. The maximum size - * of the metadata key and value is each 255 bytes and the maximum number of key-value pairs that - * can be supplied per server is 5. + * Custom cloud server metadata can also be supplied at launch time. This + * metadata is stored in the API system where it is retrievable by querying + * the API for server status. The maximum size of the metadata key and value + * is each 255 bytes and the maximum number of key-value pairs that can be + * supplied per server is 5. */ public CreateServerOptions withMetadata(Map metadata) { checkNotNull(metadata, "metadata"); - checkArgument(metadata.size() <= 5, "you cannot have more then 5 metadata values. You specified: " - + metadata.size()); + checkArgument(metadata.size() <= 5, + "you cannot have more then 5 metadata values. You specified: " + metadata.size()); for (Entry entry : metadata.entrySet()) { + checkArgument( + entry.getKey().getBytes().length < 255, + String.format("maximum length of metadata key is 255 bytes. Key specified %s is %d bytes", + entry.getKey(), entry.getKey().getBytes().length)); checkArgument(entry.getKey().getBytes().length < 255, String.format( - "maximum length of metadata key is 255 bytes. Key specified %s is %d bytes", entry.getKey(), entry - .getKey().getBytes().length)); - checkArgument(entry.getKey().getBytes().length < 255, String.format( - "maximum length of metadata value is 255 bytes. Value specified for %s (%s) is %d bytes", entry - .getKey(), entry.getValue(), entry.getValue().getBytes().length)); + "maximum length of metadata value is 255 bytes. Value specified for %s (%s) is %d bytes", + entry.getKey(), entry.getValue(), entry.getValue().getBytes().length)); } this.metadata = metadata; return this; } - /** - * A keypair name can be defined when creating a server. This key will be - * linked to the server and used to SSH connect to the machine - * - * @param keyName - * @return - */ + /** + * A keypair name can be defined when creating a server. This key will be + * linked to the server and used to SSH connect to the machine + * + * @param keyName + * @return + */ public CreateServerOptions withKeyName(String keyName) { - checkNotNull(keyName, "keyName"); - this.keyName = keyName; - return this; - } - + checkNotNull(keyName, "keyName"); + this.keyName = keyName; + return this; + } + /** * Defines the security group name to be used when creating a server. * @@ -193,11 +200,11 @@ public class CreateServerOptions implements MapBinder { * @return */ public CreateServerOptions withSecurityGroup(String groupName) { - checkNotNull(groupName, "groupName"); - this.securityGroups.add(groupName); - return this; - } - + checkNotNull(groupName, "groupName"); + this.securityGroups.add(groupName); + return this; + } + public static class Builder { /** @@ -207,11 +214,11 @@ public class CreateServerOptions implements MapBinder { CreateServerOptions options = new CreateServerOptions(); return options.withFile(path, contents); } - + public static CreateServerOptions withAdminPass(String adminPass) { - CreateServerOptions options = new CreateServerOptions(); - return options.withAdminPass(adminPass); - } + CreateServerOptions options = new CreateServerOptions(); + return options.withAdminPass(adminPass); + } /** * @see CreateServerOptions#withMetadata(Map) @@ -220,22 +227,22 @@ public class CreateServerOptions implements MapBinder { CreateServerOptions options = new CreateServerOptions(); return options.withMetadata(metadata); } - + /** * @see CreateServerOptions#withKeyName(String) */ public static CreateServerOptions withKeyName(String keyName) { - CreateServerOptions options = new CreateServerOptions(); - return options.withKeyName(keyName); - } - + CreateServerOptions options = new CreateServerOptions(); + return options.withKeyName(keyName); + } + /** * @see CreateServerOptions#withGroupName(String) */ public static CreateServerOptions withSecurityGroup(String name) { - CreateServerOptions options = new CreateServerOptions(); - return options.withSecurityGroup(name); - } + CreateServerOptions options = new CreateServerOptions(); + return options.withSecurityGroup(name); + } } @Override diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/PasswordAuthenticationExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/PasswordAuthenticationExpectTest.java index a1c9846fed..cecf3cb439 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/PasswordAuthenticationExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/PasswordAuthenticationExpectTest.java @@ -52,20 +52,24 @@ public class PasswordAuthenticationExpectTest extends BaseNovaClientExpectTest { } public void testListServersWhenResponseIs2xx() throws Exception { - HttpRequest listServers = HttpRequest.builder().method("GET").endpoint( - URI.create("https://compute.north.host/v1.1/3456/servers")).headers( - ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", - authToken).build()).build(); + HttpRequest listServers = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/servers")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - HttpResponse listServersResponse = HttpResponse.builder().statusCode(200).payload( - payloadFromResource("/server_list.json")).build(); + HttpResponse listServersResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/server_list.json")).build(); NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword, - responseWithKeystoneAccess, listServers, listServersResponse); - + responseWithKeystoneAccess, listServers, listServersResponse); + assertEquals(clientWhenServersExist.getConfiguredRegions(), ImmutableSet.of("North")); - - assertEquals(clientWhenServersExist.getServerClientForRegion("North").listServers().toString(), new ParseServerListTest().expected().toString()); + + assertEquals(clientWhenServersExist.getServerClientForRegion("North").listServers().toString(), + new ParseServerListTest().expected().toString()); } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceExpectTest.java index 414976244e..57bc4cc1f8 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceExpectTest.java @@ -41,16 +41,19 @@ import com.google.common.collect.ImmutableMultimap; public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTest { public void testListServersWhenResponseIs2xx() throws Exception { - HttpRequest listServers = HttpRequest.builder().method("GET").endpoint( - URI.create("https://compute.north.host/v1.1/3456/servers/detail")).headers( - ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", - authToken).build()).build(); + HttpRequest listServers = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/servers/detail")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - HttpResponse listServersResponse = HttpResponse.builder().statusCode(200).payload( - payloadFromResource("/server_list_details.json")).build(); + HttpResponse listServersResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/server_list_details.json")).build(); ComputeService clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, - responseWithKeystoneAccess, listServers, listServersResponse); + responseWithKeystoneAccess, listServers, listServersResponse); assertNotNull(clientWhenServersExist.listAssignableLocations()); assertEquals(clientWhenServersExist.listAssignableLocations().size(), 1); @@ -63,15 +66,18 @@ public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTe } public void testListServersWhenReponseIs404IsEmpty() throws Exception { - HttpRequest listServers = HttpRequest.builder().method("GET").endpoint( - URI.create("https://compute.north.host/v1.1/3456/servers/detail")).headers( - ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", - authToken).build()).build(); + HttpRequest listServers = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/servers/detail")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); HttpResponse listServersResponse = HttpResponse.builder().statusCode(404).build(); ComputeService clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, - responseWithKeystoneAccess, listServers, listServersResponse); + responseWithKeystoneAccess, listServers, listServersResponse); assertTrue(clientWhenNoServersExist.listNodes().isEmpty()); } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/FlavorToHardwareTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/FlavorToHardwareTest.java index 1475d64045..241d38080a 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/FlavorToHardwareTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/FlavorToHardwareTest.java @@ -26,7 +26,6 @@ import java.util.UUID; import org.jclouds.compute.domain.Hardware; import org.jclouds.domain.Location; -import org.jclouds.openstack.nova.v1_1.compute.functions.FlavorToHardware; import org.jclouds.openstack.nova.v1_1.domain.Flavor; import org.testng.annotations.Test; @@ -34,24 +33,17 @@ import com.google.common.base.Suppliers; /** * Tests the function used to transform Flavor objects into Hardware objects - * + * * @author Matt Stephenson */ -public class FlavorToHardwareTest -{ +public class FlavorToHardwareTest { @Test - public void testConversion() - { + public void testConversion() { UUID id = UUID.randomUUID(); - Flavor flavorToConvert = Flavor.builder() - .id(id.toString()) - .name("Test Flavor " + id) - .ram(262144) - .disk(10000) - .vcpus(16) - .build(); + Flavor flavorToConvert = Flavor.builder().id(id.toString()).name("Test Flavor " + id).ram(262144).disk(10000) + .vcpus(16).build(); - Hardware converted = new FlavorToHardware(Suppliers.ofInstance(null)).apply(flavorToConvert); + Hardware converted = new FlavorToHardware(Suppliers. ofInstance(null)).apply(flavorToConvert); assertEquals(converted.getName(), flavorToConvert.getName()); assertEquals(converted.getId(), flavorToConvert.getId()); @@ -60,7 +52,7 @@ public class FlavorToHardwareTest assertNotNull(converted.getProcessors()); assertFalse(converted.getProcessors().isEmpty()); - assertEquals(converted.getProcessors().iterator().next().getCores(), (double)flavorToConvert.getVcpus()); + assertEquals(converted.getProcessors().iterator().next().getCores(), (double) flavorToConvert.getVcpus()); assertNotNull(converted.getVolumes()); assertFalse(converted.getVolumes().isEmpty()); diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToImageTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToImageTest.java index 7d4d9ecebe..0ad68b9952 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToImageTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToImageTest.java @@ -27,7 +27,6 @@ import javax.annotation.Nullable; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; import org.jclouds.domain.Location; -import org.jclouds.openstack.nova.v1_1.compute.functions.NovaImageToImage; import org.jclouds.openstack.nova.v1_1.domain.Image; import org.testng.annotations.Test; @@ -36,18 +35,18 @@ import com.google.common.base.Suppliers; /** * Tests the function that transforms nova-specific images to generic images. - * + * * @author Matt Stephenson */ -public class NovaImageToImageTest -{ +public class NovaImageToImageTest { @Test - public void testConversion() - { + public void testConversion() { UUID id = UUID.randomUUID(); Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).build(); - OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86", "My Test OS", true); - NovaImageToImage converter = new NovaImageToImage(new MockImageToOsConverter(operatingSystem),Suppliers.ofInstance(null)); + OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86", + "My Test OS", true); + NovaImageToImage converter = new NovaImageToImage(new MockImageToOsConverter(operatingSystem), + Suppliers. ofInstance(null)); org.jclouds.compute.domain.Image convertedImage = converter.apply(novaImageToConvert); assertEquals(convertedImage.getId(), novaImageToConvert.getId()); @@ -57,25 +56,21 @@ public class NovaImageToImageTest assertEquals(convertedImage.getOperatingSystem(), operatingSystem); } - private class MockImageToOsConverter implements Function - { + private class MockImageToOsConverter implements Function { private final OperatingSystem operatingSystem; - public MockImageToOsConverter(OperatingSystem operatingSystem) - { + public MockImageToOsConverter(OperatingSystem operatingSystem) { this.operatingSystem = operatingSystem; } @Override - public OperatingSystem apply(@Nullable Image image) - { + public OperatingSystem apply(@Nullable Image image) { return operatingSystem; } @Override - public boolean equals(@Nullable Object o) - { + public boolean equals(@Nullable Object o) { return false; } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToOperatingSystemTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToOperatingSystemTest.java index 801a1322aa..e2a337b4f5 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToOperatingSystemTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/NovaImageToOperatingSystemTest.java @@ -30,7 +30,6 @@ import javax.annotation.Nullable; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; -import org.jclouds.openstack.nova.v1_1.compute.functions.NovaImageToOperatingSystem; import org.jclouds.openstack.nova.v1_1.domain.Image; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -40,20 +39,20 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; /** - * Tests for the function for transforming a nova specific Image into a generic OperatingSystem object. - * + * Tests for the function for transforming a nova specific Image into a generic + * OperatingSystem object. + * * @author Matt Stephenson */ -public class NovaImageToOperatingSystemTest -{ +public class NovaImageToOperatingSystemTest { @Test(dataProvider = "getOsFamilyValues") - public void testOsFamilyValues(OsFamily family) - { + public void testOsFamilyValues(OsFamily family) { Image imageToConvert = Image.builder().id("id-" + family.name()).name(family.name()).build(); - NovaImageToOperatingSystem converter = new NovaImageToOperatingSystem(new HashMap>()); + NovaImageToOperatingSystem converter = new NovaImageToOperatingSystem( + new HashMap>()); OperatingSystem convertedOs = converter.apply(imageToConvert); @@ -66,21 +65,18 @@ public class NovaImageToOperatingSystemTest } @DataProvider - public Object[][] getOsFamilyValues() - { - return Iterables.toArray(Iterables.transform(Arrays.asList(OsFamily.values()), new Function() - { - @Override - public Object[] apply(@Nullable OsFamily osFamily) - { - return new Object[]{osFamily}; - } - }), Object[].class); + public Object[][] getOsFamilyValues() { + return Iterables.toArray( + Iterables.transform(Arrays.asList(OsFamily.values()), new Function() { + @Override + public Object[] apply(@Nullable OsFamily osFamily) { + return new Object[] { osFamily }; + } + }), Object[].class); } @Test - public void testWindowsServer2008R2x64() - { + public void testWindowsServer2008R2x64() { String name = "Windows Server 2008 R2 x64"; Image imageToConvert = Image.builder().id("id-" + name).name(name).build(); @@ -101,8 +97,7 @@ public class NovaImageToOperatingSystemTest } @Test - public void testWindows98x86() - { + public void testWindows98x86() { String name = "Windows 98 x86"; Image imageToConvert = Image.builder().id("id-" + name).name(name).build(); @@ -123,13 +118,13 @@ public class NovaImageToOperatingSystemTest } @Test - public void testRHEL() - { + public void testRHEL() { String name = "Red Hat EL"; Image imageToConvert = Image.builder().id("id-" + name).name(name).build(); - NovaImageToOperatingSystem converter = new NovaImageToOperatingSystem(new HashMap>()); + NovaImageToOperatingSystem converter = new NovaImageToOperatingSystem( + new HashMap>()); OperatingSystem convertedOs = converter.apply(imageToConvert); @@ -142,13 +137,13 @@ public class NovaImageToOperatingSystemTest } @Test - public void testOEL() - { + public void testOEL() { String name = "Oracle EL"; Image imageToConvert = Image.builder().id("id-" + name).name(name).build(); - NovaImageToOperatingSystem converter = new NovaImageToOperatingSystem(new HashMap>()); + NovaImageToOperatingSystem converter = new NovaImageToOperatingSystem( + new HashMap>()); OperatingSystem convertedOs = converter.apply(imageToConvert); diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerToNodeMetadataTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerToNodeMetadataTest.java index ed2104157d..661c6de0f3 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerToNodeMetadataTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/compute/functions/ServerToNodeMetadataTest.java @@ -18,39 +18,32 @@ */ package org.jclouds.openstack.nova.v1_1.compute.functions; -import com.google.common.collect.ImmutableMap; - import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.util.UUID; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.openstack.nova.v1_1.compute.functions.ServerToNodeMetadata; import org.jclouds.openstack.nova.v1_1.domain.Address; import org.jclouds.openstack.nova.v1_1.domain.Server; import org.jclouds.openstack.nova.v1_1.domain.ServerStatus; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableMap; + /** - * Tests for the function for transforming a nova specific Server into a generic NodeMetadata object. - * + * Tests for the function for transforming a nova specific Server into a generic + * NodeMetadata object. + * * @author Matt Stephenson */ -public class ServerToNodeMetadataTest -{ +public class ServerToNodeMetadataTest { @Test - public void testConversion() - { + public void testConversion() { UUID id = UUID.randomUUID(); - Server serverToConvert = Server.builder() - .id(id.toString()) - .name("Test Server " + id) - .privateAddresses(Address.createV4("10.0.0.1")) - .publicAddresses(Address.createV4("1.0.1.1")) - .status(ServerStatus.ACTIVE) - .metadata(ImmutableMap.of("test", "testing")) - .build(); + Server serverToConvert = Server.builder().id(id.toString()).name("Test Server " + id) + .privateAddresses(Address.createV4("10.0.0.1")).publicAddresses(Address.createV4("1.0.1.1")) + .status(ServerStatus.ACTIVE).metadata(ImmutableMap.of("test", "testing")).build(); ServerToNodeMetadata converter = new ServerToNodeMetadata(); @@ -71,6 +64,6 @@ public class ServerToNodeMetadataTest assertNotNull(convertedNodeMetadata.getUserMetadata()); assertEquals(convertedNodeMetadata.getUserMetadata().size(), 1); - assertEquals(convertedNodeMetadata.getUserMetadata().get("test"),"testing"); + assertEquals(convertedNodeMetadata.getUserMetadata().get("test"), "testing"); } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientExpectTest.java index 1c345af2ca..286aabcddc 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientExpectTest.java @@ -37,149 +37,123 @@ import com.google.common.collect.ImmutableSet; /** * Tests annotation parsing of {@code FloatingIPAsyncClient} - * + * * @author Michael Arnold */ @Test(groups = "unit", testName = "FloatingIPClientExpectTest") public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest { - public void testListFloatingIPsWhenResponseIs2xx() throws Exception { - HttpRequest listFloatingIPs = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + public void testListFloatingIPsWhenResponseIs2xx() throws Exception { + HttpRequest listFloatingIPs = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/floatingip_list.json")).build(); + HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/floatingip_list.json")).build(); - NovaClient clientWhenFloatingIPsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listFloatingIPs, listFloatingIPsResponse); + NovaClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listFloatingIPs, listFloatingIPsResponse); - assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(), - ImmutableSet.of("North")); + assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(), ImmutableSet.of("North")); - assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get() - .listFloatingIPs().toString(), new ParseFloatingIPListTest().expected() - .toString()); - } - - public void testListFloatingIPsWhenResponseIs404() throws Exception { - HttpRequest listFloatingIPs = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().listFloatingIPs() + .toString(), new ParseFloatingIPListTest().expected().toString()); + } - HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(404) - .build(); + public void testListFloatingIPsWhenResponseIs404() throws Exception { + HttpRequest listFloatingIPs = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - NovaClient clientWhenNoServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listFloatingIPs, listFloatingIPsResponse); + HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(404).build(); - assertTrue(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get() - .listFloatingIPs().isEmpty()); - } - - public void testGetFloatingIPWhenResponseIs2xx() throws Exception { - HttpRequest getFloatingIP = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-floating-ips/1")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listFloatingIPs, listFloatingIPsResponse); - HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/floatingip_details.json")).build(); + assertTrue(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().listFloatingIPs().isEmpty()); + } - NovaClient clientWhenFloatingIPsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - getFloatingIP, getFloatingIPResponse); + public void testGetFloatingIPWhenResponseIs2xx() throws Exception { + HttpRequest getFloatingIP = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips/1")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get() - .getFloatingIP("1").toString(), - new ParseFloatingIPTest().expected().toString()); - } - - public void testGetFloatingIPWhenResponseIs404() throws Exception { - HttpRequest getFloatingIP = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-floating-ips/1")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/floatingip_details.json")).build(); - HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(404).build(); + NovaClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getFloatingIP, getFloatingIPResponse); - NovaClient clientWhenNoServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - getFloatingIP, getFloatingIPResponse); + assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1") + .toString(), new ParseFloatingIPTest().expected().toString()); + } - assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get() - .getFloatingIP("1")); - } + public void testGetFloatingIPWhenResponseIs404() throws Exception { + HttpRequest getFloatingIP = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips/1")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - public void testAllocateWhenResponseIs2xx() throws Exception { - HttpRequest allocateFloatingIP = HttpRequest - .builder() - .method("POST") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()) - .payload(payloadFromStringWithContentType("{}", "application/json")).build(); + HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(404).build(); - HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/floatingip_details.json")).build(); + NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getFloatingIP, getFloatingIPResponse); - NovaClient clientWhenFloatingIPsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - allocateFloatingIP, allocateFloatingIPResponse); + assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1")); + } - assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get() - .allocate().toString(), - new ParseFloatingIPTest().expected().toString()); + public void testAllocateWhenResponseIs2xx() throws Exception { + HttpRequest allocateFloatingIP = HttpRequest + .builder() + .method("POST") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()) + .payload(payloadFromStringWithContentType("{}", "application/json")).build(); - } + HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/floatingip_details.json")).build(); - public void testAllocateWhenResponseIs404() throws Exception { - HttpRequest allocateFloatingIP = HttpRequest - .builder() - .method("POST") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()) - .payload(payloadFromStringWithContentType("{}", "application/json")).build(); + NovaClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, allocateFloatingIP, allocateFloatingIPResponse); - HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(404).build(); + assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().allocate().toString(), + new ParseFloatingIPTest().expected().toString()); - NovaClient clientWhenNoServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - allocateFloatingIP, allocateFloatingIPResponse); + } + + public void testAllocateWhenResponseIs404() throws Exception { + HttpRequest allocateFloatingIP = HttpRequest + .builder() + .method("POST") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()) + .payload(payloadFromStringWithContentType("{}", "application/json")).build(); + + HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(404).build(); + + NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, allocateFloatingIP, allocateFloatingIPResponse); + + assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().allocate()); + } - assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get() - .allocate()); - } - } \ No newline at end of file diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientLiveTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientLiveTest.java index b4508bf549..ba093ab14e 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientLiveTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/FloatingIPClientLiveTest.java @@ -25,19 +25,18 @@ import static org.testng.Assert.assertTrue; import java.util.Set; -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; import org.jclouds.openstack.nova.v1_1.domain.Address; import org.jclouds.openstack.nova.v1_1.domain.FloatingIP; import org.jclouds.openstack.nova.v1_1.domain.Server; import org.jclouds.openstack.nova.v1_1.domain.ServerStatus; -import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient; import org.jclouds.openstack.nova.v1_1.features.FlavorClient; import org.jclouds.openstack.nova.v1_1.features.ImageClient; import org.jclouds.openstack.nova.v1_1.features.ServerClient; import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; import org.testng.annotations.Test; +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; /** @@ -48,7 +47,7 @@ import com.google.common.collect.Multimap; @Test(groups = "live", testName = "FloatingIPClientLiveTest") public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest { - private static final int INCONSISTENCY_WINDOW = 5000; + private static final int INCONSISTENCY_WINDOW = 5000; @Test public void testListFloatingIPs() throws Exception { @@ -62,140 +61,137 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest { assertTrue(response.size() >= 0); for (FloatingIP ip : response) { FloatingIP newDetails = client.getFloatingIP(ip.getId()); - - + assertEquals(newDetails.getId(), ip.getId()); assertEquals(newDetails.getIp(), ip.getIp()); assertEquals(newDetails.getFixedIp(), ip.getFixedIp()); assertEquals(newDetails.getInstanceId(), ip.getInstanceId()); - + } } } - - @Test - public void testAllocateAndDeallocateFloatingIPs() throws Exception { - for (String regionId : context.getApi().getConfiguredRegions()) { - Optional clientOption = context.getApi().getFloatingIPExtensionForRegion(regionId); - if (!clientOption.isPresent()) - continue; - FloatingIPClient client = clientOption.get(); - FloatingIP floatingIP = client.allocate(); - assertNotNull(floatingIP); - Set response = client.listFloatingIPs(); - boolean ipInSet = false; - for (FloatingIP ip : response) { - if (ip.getId().equals(floatingIP.getId())) ipInSet = true; + @Test + public void testAllocateAndDeallocateFloatingIPs() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + Optional clientOption = context.getApi().getFloatingIPExtensionForRegion(regionId); + if (!clientOption.isPresent()) + continue; + FloatingIPClient client = clientOption.get(); + FloatingIP floatingIP = client.allocate(); + assertNotNull(floatingIP); + + Set response = client.listFloatingIPs(); + boolean ipInSet = false; + for (FloatingIP ip : response) { + if (ip.getId().equals(floatingIP.getId())) + ipInSet = true; + } + assertTrue(ipInSet); + + client.deallocate(floatingIP.getId()); + + response = client.listFloatingIPs(); + ipInSet = false; + for (FloatingIP ip : response) { + if (ip.getId().equals(floatingIP.getId())) { + ipInSet = true; } - assertTrue(ipInSet); + } + assertFalse(ipInSet); + } + } - client.deallocate(floatingIP.getId()); + @Test + public void testAddAndRemoveFloatingIp() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + Optional clientOption = context.getApi().getFloatingIPExtensionForRegion(regionId); + if (!clientOption.isPresent()) + continue; + FloatingIPClient client = clientOption.get(); + ServerClient serverClient = context.getApi().getServerClientForRegion(regionId); + Server server = serverClient.createServer("test", imageIdForRegion(regionId), flavorRefForRegion(regionId)); + blockUntilServerActive(server.getId(), serverClient); + FloatingIP floatingIP = client.allocate(); + assertNotNull(floatingIP); + try { + client.addFloatingIP(server.getId(), floatingIP.getIp()); + assertEventually(new ServerHasFloatingIP(serverClient, server.getId(), floatingIP.getIp())); + } finally { + client.removeFloatingIP(server.getId(), floatingIP.getIp()); + serverClient.deleteServer(server.getId()); + } + } + } - response = client.listFloatingIPs(); - ipInSet = false; - for (FloatingIP ip : response) { - if (ip.getId().equals(floatingIP.getId())) { - ipInSet = true; - } + private String imageIdForRegion(String regionId) { + ImageClient imageClient = context.getApi().getImageClientForRegion(regionId); + return Iterables.getLast(imageClient.listImages()).getId(); + } + + private String flavorRefForRegion(String regionId) { + FlavorClient flavorClient = context.getApi().getFlavorClientForRegion(regionId); + return Iterables.getLast(flavorClient.listFlavors()).getId(); + } + + private void blockUntilServerActive(String serverId, ServerClient client) throws InterruptedException { + Server currentDetails = null; + for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.ACTIVE; currentDetails = client + .getServer(serverId)) { + System.out.printf("blocking on status active%n%s%n", currentDetails); + Thread.sleep(5 * 1000); + } + } + + protected static void assertEventually(Runnable assertion) { + long start = System.currentTimeMillis(); + AssertionError error = null; + for (int i = 0; i < 30; i++) { + try { + assertion.run(); + if (i > 0) + System.err.printf("%d attempts and %dms asserting %s%n", i + 1, System.currentTimeMillis() - start, + assertion.getClass().getSimpleName()); + return; + } catch (AssertionError e) { + error = e; + } + try { + Thread.sleep(INCONSISTENCY_WINDOW / 30); + } catch (InterruptedException e) { + } + } + if (error != null) + throw error; + + } + + public static final class ServerHasFloatingIP implements Runnable { + private final ServerClient client; + private final String serverId; + private final String floatingIP; + + public ServerHasFloatingIP(ServerClient serverClient, String serverId, String floatingIP) { + this.client = serverClient; + this.serverId = serverId; + this.floatingIP = floatingIP; + } + + public void run() { + try { + Server server = client.getServer(serverId); + boolean ipInServerAddresses = false; + Multimap addresses = server.getAddresses(); + for (Address address : addresses.values()) { + if (address.getAddr().equals(floatingIP)) { + ipInServerAddresses = true; + } } - assertFalse(ipInSet); - } - } - - - @Test - public void testAddAndRemoveFloatingIp() throws Exception { - for (String regionId : context.getApi().getConfiguredRegions()) { - Optional clientOption = context.getApi().getFloatingIPExtensionForRegion(regionId); - if (!clientOption.isPresent()) - continue; - FloatingIPClient client = clientOption.get(); - ServerClient serverClient = context.getApi().getServerClientForRegion(regionId); - Server server = serverClient.createServer("test", imageIdForRegion(regionId), flavorRefForRegion(regionId)); - blockUntilServerActive(server.getId(), serverClient); - FloatingIP floatingIP = client.allocate(); - assertNotNull(floatingIP); - try { - client.addFloatingIP(server.getId(), floatingIP.getIp()); - assertEventually(new ServerHasFloatingIP(serverClient, server.getId(), floatingIP.getIp())); - } - finally { - client.removeFloatingIP(server.getId(), floatingIP.getIp()); - serverClient.deleteServer(server.getId()); - } - } - } - - private String imageIdForRegion(String regionId) { - ImageClient imageClient = context.getApi().getImageClientForRegion(regionId); - return Iterables.getLast(imageClient.listImages()).getId(); - } - - private String flavorRefForRegion(String regionId) { - FlavorClient flavorClient = context.getApi().getFlavorClientForRegion(regionId); - return Iterables.getLast(flavorClient.listFlavors()).getId(); - } - - private void blockUntilServerActive(String serverId, ServerClient client) throws InterruptedException { - Server currentDetails = null; - for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != ServerStatus.ACTIVE; currentDetails = client - .getServer(serverId)) { - System.out.printf("blocking on status active%n%s%n", currentDetails); - Thread.sleep(5 * 1000); - } - } - - protected static void assertEventually(Runnable assertion) { - long start = System.currentTimeMillis(); - AssertionError error = null; - for (int i = 0; i < 30; i++) { - try { - assertion.run(); - if (i > 0) - System.err.printf("%d attempts and %dms asserting %s%n", i + 1, System.currentTimeMillis() - start, - assertion.getClass().getSimpleName()); - return; - } catch (AssertionError e) { - error = e; - } - try { - Thread.sleep(INCONSISTENCY_WINDOW / 30); - } catch (InterruptedException e) { - } - } - if (error != null) - throw error; - - } - - public static final class ServerHasFloatingIP implements Runnable { - private final ServerClient client; - private final String serverId; - private final String floatingIP; - - public ServerHasFloatingIP(ServerClient serverClient, String serverId, String floatingIP) { - this.client = serverClient; - this.serverId = serverId; - this.floatingIP = floatingIP; - } - - public void run() { - try { - Server server = client.getServer(serverId); - boolean ipInServerAddresses = false; - Multimapaddresses = server.getAddresses(); - for (Address address : addresses.values()){ - if (address.getAddr().equals(floatingIP)) { - ipInServerAddresses = true; - } - } - assertTrue(ipInServerAddresses); - } catch (Exception e) { - throw new AssertionError(e); - } - } - } + assertTrue(ipInServerAddresses); + } catch (Exception e) { + throw new AssertionError(e); + } + } + } } - diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientExpectTest.java index f6f3fdab33..bbf1f1b4a9 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientExpectTest.java @@ -18,8 +18,11 @@ */ package org.jclouds.openstack.nova.v1_1.extensions; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.net.URI; + import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.openstack.nova.v1_1.NovaClient; @@ -28,139 +31,120 @@ import org.jclouds.openstack.nova.v1_1.parse.ParseKeyPairListTest; import org.jclouds.openstack.nova.v1_1.parse.ParseKeyPairTest; import org.testng.annotations.Test; -import java.net.URI; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; /** * Tests annotation parsing of {@code KeyPairAsyncClient} - * + * * @author Michael Arnold */ @Test(groups = "unit", testName = "KeyPairClientExpectTest") -public class KeyPairClientExpectTest extends BaseNovaClientExpectTest { +public class KeyPairClientExpectTest extends BaseNovaClientExpectTest { - public void testListKeyPairsWhenResponseIs2xx() throws Exception { - HttpRequest listKeyPairs = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-keypairs")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + public void testListKeyPairsWhenResponseIs2xx() throws Exception { + HttpRequest listKeyPairs = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-keypairs")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/keypair_list.json")).build(); + HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/keypair_list.json")).build(); - NovaClient clientWhenServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listKeyPairs, listKeyPairsResponse); + NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listKeyPairs, listKeyPairsResponse); - assertEquals(clientWhenServersExist.getConfiguredRegions(), - ImmutableSet.of("North")); + assertEquals(clientWhenServersExist.getConfiguredRegions(), ImmutableSet.of("North")); - assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North") - .listKeyPairs().toString(), new ParseKeyPairListTest().expected() - .toString()); - } + assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North").listKeyPairs().toString(), + new ParseKeyPairListTest().expected().toString()); + } - public void testListKeyPairsWhenResponseIs404() throws Exception { - HttpRequest listKeyPairs = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-keypairs")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + public void testListKeyPairsWhenResponseIs404() throws Exception { + HttpRequest listKeyPairs = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-keypairs")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(404) - .build(); + HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(404).build(); - NovaClient clientWhenNoServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listKeyPairs, listKeyPairsResponse); + NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listKeyPairs, listKeyPairsResponse); - assertTrue(clientWhenNoServersExist.getKeyPairClientForRegion("North") - .listKeyPairs().isEmpty()); + assertTrue(clientWhenNoServersExist.getKeyPairClientForRegion("North").listKeyPairs().isEmpty()); - } + } - public void testCreateKeyPair() throws Exception { - HttpRequest createKeyPair = HttpRequest - .builder() - .method("POST") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-keypairs")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()) - .payload(payloadFromStringWithContentType("{\"keypair\":{\"name\":\"testkeypair\"}}", + public void testCreateKeyPair() throws Exception { + HttpRequest createKeyPair = HttpRequest + .builder() + .method("POST") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-keypairs")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()) + .payload(payloadFromStringWithContentType("{\"keypair\":{\"name\":\"testkeypair\"}}", "application/json")) + .build(); + + HttpResponse createKeyPairResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/keypair_created.json")).build(); + + NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, createKeyPair, createKeyPairResponse); + + assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North").createKeyPair("testkeypair").toString(), + new ParseKeyPairTest().expected().toString()); + + } + + public void testCreateKeyPairWithPublicKey() throws Exception { + HttpRequest createKeyPair = HttpRequest + .builder() + .method("POST") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-keypairs")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()) + .payload( + payloadFromStringWithContentType( + "{\"keypair\":{\"name\":\"testkeypair\",\"public_key\":\"ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n\"}}", "application/json")).build(); - HttpResponse createKeyPairResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/keypair_created.json")).build(); + HttpResponse createKeyPairResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/keypair_created.json")).build(); - NovaClient clientWhenServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - createKeyPair, createKeyPairResponse); + NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, createKeyPair, createKeyPairResponse); - assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North") - .createKeyPair("testkeypair").toString(), - new ParseKeyPairTest().expected().toString()); + assertEquals( + clientWhenServersExist + .getKeyPairClientForRegion("North") + .createKeyPairWithPublicKey( + "testkeypair", + "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n") + .toString(), new ParseKeyPairTest().expected().toString()); + } - } + public void testDeleteKeyPair() throws Exception { + HttpRequest deleteKeyPair = HttpRequest + .builder() + .method("DELETE") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-keypairs/testkeypair")) + .headers( + ImmutableMultimap. builder().put("Accept", "*/*").put("X-Auth-Token", authToken) + .build()).build(); - public void testCreateKeyPairWithPublicKey() throws Exception { - HttpRequest createKeyPair = HttpRequest - .builder() - .method("POST") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-keypairs")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()) - .payload(payloadFromStringWithContentType("{\"keypair\":{\"name\":\"testkeypair\",\"public_key\":\"ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n\"}}", - "application/json")).build(); + HttpResponse deleteKeyPairResponse = HttpResponse.builder().statusCode(202).build(); - HttpResponse createKeyPairResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/keypair_created.json")).build(); + NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, deleteKeyPair, deleteKeyPairResponse); - NovaClient clientWhenServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - createKeyPair, createKeyPairResponse); - - assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North") - .createKeyPairWithPublicKey("testkeypair", "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n") - .toString(), - new ParseKeyPairTest().expected().toString()); - } - - public void testDeleteKeyPair() throws Exception { - HttpRequest deleteKeyPair = HttpRequest - .builder() - .method("DELETE") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-keypairs/testkeypair")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "*/*") - .put("X-Auth-Token", authToken).build()).build(); - - - HttpResponse deleteKeyPairResponse = HttpResponse.builder().statusCode(202).build(); - - NovaClient clientWhenServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - deleteKeyPair, deleteKeyPairResponse); - - assertTrue(clientWhenServersExist.getKeyPairClientForRegion("North").deleteKeyPair("testkeypair")); - } + assertTrue(clientWhenServersExist.getKeyPairClientForRegion("North").deleteKeyPair("testkeypair")); + } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientLiveTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientLiveTest.java index be1797c75c..4ca6df07df 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientLiveTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientLiveTest.java @@ -18,64 +18,62 @@ */ package org.jclouds.openstack.nova.v1_1.extensions; -import org.jclouds.openstack.nova.v1_1.domain.KeyPair; -import org.jclouds.openstack.nova.v1_1.extensions.KeyPairClient; -import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; -import org.testng.annotations.Test; +import static org.testng.Assert.assertNotNull; import java.util.Map; import java.util.Set; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import org.jclouds.openstack.nova.v1_1.domain.KeyPair; +import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; +import org.testng.annotations.Test; /** * Tests behavior of {@code KeyPairClient} - * + * * @author Michael Arnold */ @Test(groups = "live", testName = "KeyPairClientLiveTest") -public class KeyPairClientLiveTest extends BaseNovaClientLiveTest { +public class KeyPairClientLiveTest extends BaseNovaClientLiveTest { - public void testListKeyPairs() throws Exception { - for (String regionId : context.getApi().getConfiguredRegions()) { - KeyPairClient client = context.getApi().getKeyPairClientForRegion(regionId); - Set> keyPairsList = client.listKeyPairs(); - assertNotNull(keyPairsList); - } - } - - public void testCreateAndDeleteKeyPair() throws Exception { - final String KEYPAIR_NAME = "testkp"; - for(String regionId : context.getApi().getConfiguredRegions()) { - KeyPairClient client = context.getApi().getKeyPairClientForRegion(regionId); - KeyPair keyPair = null; - try { - keyPair = client.createKeyPair(KEYPAIR_NAME); - assertNotNull(keyPair); - } finally { - if (keyPair != null) { - client.deleteKeyPair(KEYPAIR_NAME); - } - } - } - } - - public void testCreateAndDeleteKeyPairWithPublicKey() throws Exception { - final String KEYPAIR_NAME = "testkp"; - final String PUBLIC_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCrrBREFxz3002l1HuXz0+UOdJQ/mOYD5DiJwwB/TOybwIKQJPOxJWA9gBoo4k9dthTKBTaEYbzrll7iZcp59E80S6mNiAr3mUgi+x5Y8uyXeJ2Ws+h6peVyFVUu9epkwpcTd1GVfdcVWsTajwDz9+lxCDhl0RZKDFoT0scTxbj/w== nova@nv-aw2az2-api0002"; + public void testListKeyPairs() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + KeyPairClient client = context.getApi().getKeyPairClientForRegion(regionId); + Set> keyPairsList = client.listKeyPairs(); + assertNotNull(keyPairsList); + } + } - for(String regionId : context.getApi().getConfiguredRegions()) { - KeyPairClient client = context.getApi().getKeyPairClientForRegion(regionId); - KeyPair keyPair = null; - try { - keyPair = client.createKeyPairWithPublicKey(KEYPAIR_NAME, PUBLIC_KEY); - assertNotNull(keyPair); - } finally { - if (keyPair != null) { - client.deleteKeyPair(KEYPAIR_NAME); - } + public void testCreateAndDeleteKeyPair() throws Exception { + final String KEYPAIR_NAME = "testkp"; + for (String regionId : context.getApi().getConfiguredRegions()) { + KeyPairClient client = context.getApi().getKeyPairClientForRegion(regionId); + KeyPair keyPair = null; + try { + keyPair = client.createKeyPair(KEYPAIR_NAME); + assertNotNull(keyPair); + } finally { + if (keyPair != null) { + client.deleteKeyPair(KEYPAIR_NAME); } - } - } + } + } + } + + public void testCreateAndDeleteKeyPairWithPublicKey() throws Exception { + final String KEYPAIR_NAME = "testkp"; + final String PUBLIC_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCrrBREFxz3002l1HuXz0+UOdJQ/mOYD5DiJwwB/TOybwIKQJPOxJWA9gBoo4k9dthTKBTaEYbzrll7iZcp59E80S6mNiAr3mUgi+x5Y8uyXeJ2Ws+h6peVyFVUu9epkwpcTd1GVfdcVWsTajwDz9+lxCDhl0RZKDFoT0scTxbj/w== nova@nv-aw2az2-api0002"; + + for (String regionId : context.getApi().getConfiguredRegions()) { + KeyPairClient client = context.getApi().getKeyPairClientForRegion(regionId); + KeyPair keyPair = null; + try { + keyPair = client.createKeyPairWithPublicKey(KEYPAIR_NAME, PUBLIC_KEY); + assertNotNull(keyPair); + } finally { + if (keyPair != null) { + client.deleteKeyPair(KEYPAIR_NAME); + } + } + } + } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientExpectTest.java index 95eb35b188..c300674a39 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientExpectTest.java @@ -19,11 +19,11 @@ package org.jclouds.openstack.nova.v1_1.extensions; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; import java.net.URI; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.openstack.nova.v1_1.NovaClient; @@ -34,232 +34,188 @@ import org.jclouds.openstack.nova.v1_1.parse.ParseSecurityGroupListTest; import org.jclouds.openstack.nova.v1_1.parse.ParseSecurityGroupTest; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - /** * Tests annotation parsing of {@code SecurityGroupAsyncClient} - * + * * @author Michael Arnold */ @Test(groups = "unit", testName = "SecurityGroupClientExpectTest") public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest { - public void testListSecurityGroupsWhenResponseIs2xx() throws Exception { - HttpRequest listSecurityGroups = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-security-groups")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + public void testListSecurityGroupsWhenResponseIs2xx() throws Exception { + HttpRequest listSecurityGroups = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-security-groups")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - HttpResponse listSecurityGroupsResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/securitygroup_list.json")).build(); + HttpResponse listSecurityGroupsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/securitygroup_list.json")).build(); + NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listSecurityGroups, listSecurityGroupsResponse); - NovaClient clientWhenSecurityGroupsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listSecurityGroups, listSecurityGroupsResponse); + assertEquals(clientWhenSecurityGroupsExist.getConfiguredRegions(), ImmutableSet.of("North")); - assertEquals(clientWhenSecurityGroupsExist.getConfiguredRegions(), - ImmutableSet.of("North")); + assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North").listSecurityGroups() + .toString(), new ParseSecurityGroupListTest().expected().toString()); + } - assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North") - .listSecurityGroups().toString(), new ParseSecurityGroupListTest().expected() - .toString()); - } + public void testListSecurityGroupsWhenReponseIs404IsEmpty() throws Exception { + HttpRequest listListSecurityGroups = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-security-groups")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - public void testListSecurityGroupsWhenReponseIs404IsEmpty() throws Exception { - HttpRequest listListSecurityGroups = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-security-groups")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + HttpResponse listListSecurityGroupsResponse = HttpResponse.builder().statusCode(404).build(); - HttpResponse listListSecurityGroupsResponse = HttpResponse.builder().statusCode(404) - .build(); + NovaClient clientWhenNoSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listListSecurityGroups, listListSecurityGroupsResponse); - NovaClient clientWhenNoSecurityGroupsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listListSecurityGroups, listListSecurityGroupsResponse); + assertTrue(clientWhenNoSecurityGroupsExist.getSecurityGroupClientForRegion("North").listSecurityGroups() + .isEmpty()); + } - assertTrue(clientWhenNoSecurityGroupsExist.getSecurityGroupClientForRegion("North") - .listSecurityGroups().isEmpty()); - } + public void testGetSecurityGroupWhenResponseIs2xx() throws Exception { - public void testGetSecurityGroupWhenResponseIs2xx() throws Exception { + HttpRequest getSecurityGroup = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-security-groups/0")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - HttpRequest getSecurityGroup = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-security-groups/0")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + HttpResponse getSecurityGroupResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/securitygroup_details.json")).build(); - HttpResponse getSecurityGroupResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/securitygroup_details.json")).build(); + NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getSecurityGroup, getSecurityGroupResponse); - NovaClient clientWhenSecurityGroupsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - getSecurityGroup, getSecurityGroupResponse); + assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North").getSecurityGroup("0") + .toString(), new ParseSecurityGroupTest().expected().toString()); + } - assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North") - .getSecurityGroup("0").toString(), - new ParseSecurityGroupTest().expected().toString()); - } + public void testGetSecurityGroupWhenResponseIs404() throws Exception { + HttpRequest getSecurityGroup = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-security-groups/0")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - public void testGetSecurityGroupWhenResponseIs404() throws Exception { - HttpRequest getSecurityGroup = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-security-groups/0")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + HttpResponse getSecurityGroupResponse = HttpResponse.builder().statusCode(404).build(); - HttpResponse getSecurityGroupResponse = HttpResponse.builder().statusCode(404).build(); + NovaClient clientWhenNoSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getSecurityGroup, getSecurityGroupResponse); - NovaClient clientWhenNoSecurityGroupsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - getSecurityGroup, getSecurityGroupResponse); + assertNull(clientWhenNoSecurityGroupsExist.getSecurityGroupClientForRegion("North").getSecurityGroup("0")); - assertNull(clientWhenNoSecurityGroupsExist.getSecurityGroupClientForRegion("North").getSecurityGroup("0")); + } - } + public void testCreateSecurityGroupWhenResponseIs2xx() throws Exception { + HttpRequest createSecurityGroup = HttpRequest + .builder() + .method("POST") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-security-groups")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()) + .payload( + payloadFromStringWithContentType( + "{\"security_group\":{\"name\":\"name\",\"description\":\"description\"}}", "application/json")) + .build(); - public void testCreateSecurityGroupWhenResponseIs2xx() throws Exception { - HttpRequest createSecurityGroup = HttpRequest - .builder() - .method("POST") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-security-groups")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()) - .payload(payloadFromStringWithContentType("{\"security_group\":{\"name\":\"name\",\"description\":\"description\"}}", + HttpResponse createSecurityGroupResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/securitygroup_created.json")).build(); + + NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, createSecurityGroup, createSecurityGroupResponse); + + assertEquals( + clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North") + .createSecurityGroup("name", "description").toString(), createSecurityGroupExpected().toString()); + } + + public void testDeleteSecurityGroupWhenResponseIs2xx() throws Exception { + HttpRequest deleteSecurityGroup = HttpRequest + .builder() + .method("DELETE") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-security-groups/160")) + .headers( + ImmutableMultimap. builder().put("Accept", "*/*").put("X-Auth-Token", authToken) + .build()).build(); + + HttpResponse deleteSecurityGroupResponse = HttpResponse.builder().statusCode(202).build(); + + NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, deleteSecurityGroup, deleteSecurityGroupResponse); + + assertTrue(clientWhenServersExist.getSecurityGroupClientForRegion("North").deleteSecurityGroup("160")); + + } + + public void testCreateSecurityGroupRuleWhenResponseIs2xx() throws Exception { + HttpRequest createSecurityGroupRule = HttpRequest + .builder() + .method("POST") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-security-group-rules")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()) + .payload( + payloadFromStringWithContentType( + "{\"security_group_rule\":{\"ip_protocol\":\"tcp\",\"from_port\":\"80\",\"to_port\":\"8080\",\"cidr\":\"0.0.0.0/0\",\"group_id\":\"\",\"parent_group_id\":\"161\"}}", "application/json")).build(); - HttpResponse createSecurityGroupResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/securitygroup_created.json")).build(); + HttpResponse createSecurityGroupRuleResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/securitygrouprule_created.json")).build(); - NovaClient clientWhenSecurityGroupsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - createSecurityGroup, createSecurityGroupResponse); + NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, createSecurityGroupRule, createSecurityGroupRuleResponse); - assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North") - .createSecurityGroup("name", "description").toString(), - createSecurityGroupExpected().toString()); - } + assertEquals( + clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North") + .createSecurityGroupRule("tcp", "80", "8080", "0.0.0.0/0", "", "161").toString(), + createSecurityGroupRuleExpected().toString()); + } - public void testDeleteSecurityGroupWhenResponseIs2xx() throws Exception { - HttpRequest deleteSecurityGroup = HttpRequest - .builder() - .method("DELETE") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-security-groups/160")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "*/*") - .put("X-Auth-Token", authToken).build()).build(); + public void testDeleteSecurityGroupRuleWhenResponseIs2xx() throws Exception { + HttpRequest deleteSecurityGroupRule = HttpRequest + .builder() + .method("DELETE") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/os-security-group-rules/161")) + .headers( + ImmutableMultimap. builder().put("Accept", "*/*").put("X-Auth-Token", authToken) + .build()).build(); + HttpResponse deleteSecurityGroupRuleResponse = HttpResponse.builder().statusCode(202).build(); - HttpResponse deleteSecurityGroupResponse = HttpResponse.builder().statusCode(202).build(); + NovaClient clientWhenSecurityGroupsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, deleteSecurityGroupRule, deleteSecurityGroupRuleResponse); - NovaClient clientWhenServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - deleteSecurityGroup, deleteSecurityGroupResponse); + assertTrue(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North").deleteSecurityGroupRule("161")); - assertTrue(clientWhenServersExist.getSecurityGroupClientForRegion("North").deleteSecurityGroup("160")); + } - } + private SecurityGroup createSecurityGroupExpected() { + return SecurityGroup.builder().description("description").id("160").name("name") + .rules(ImmutableSet. of()).tenantId("dev_16767499955063").build(); + } - public void testCreateSecurityGroupRuleWhenResponseIs2xx() throws Exception { - HttpRequest createSecurityGroupRule = HttpRequest - .builder() - .method("POST") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-security-group-rules")) - .headers( - ImmutableMultimap.builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()) - .payload(payloadFromStringWithContentType("{\"security_group_rule\":{\"ip_protocol\":\"tcp\",\"from_port\":\"80\",\"to_port\":\"8080\",\"cidr\":\"0.0.0.0/0\",\"group_id\":\"\",\"parent_group_id\":\"161\"}}", - "application/json")).build(); - - - HttpResponse createSecurityGroupRuleResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/securitygrouprule_created.json")).build(); - - NovaClient clientWhenSecurityGroupsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - createSecurityGroupRule, createSecurityGroupRuleResponse); - - assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North") - .createSecurityGroupRule("tcp", "80", "8080", "0.0.0.0/0", "", "161").toString(), - createSecurityGroupRuleExpected().toString()); - } - - public void testDeleteSecurityGroupRuleWhenResponseIs2xx() throws Exception { - HttpRequest deleteSecurityGroupRule = HttpRequest - .builder() - .method("DELETE") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/os-security-group-rules/161")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "*/*") - .put("X-Auth-Token", authToken).build()).build(); - - - HttpResponse deleteSecurityGroupRuleResponse = HttpResponse.builder().statusCode(202).build(); - - NovaClient clientWhenSecurityGroupsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - deleteSecurityGroupRule, deleteSecurityGroupRuleResponse); - - assertTrue(clientWhenSecurityGroupsExist.getSecurityGroupClientForRegion("North") - .deleteSecurityGroupRule("161")); - - } - - private SecurityGroup createSecurityGroupExpected() { - return SecurityGroup - .builder() - .description("description") - .id("160") - .name("name") - .rules(ImmutableSet. of()) - .tenantId("dev_16767499955063") - .build(); - } - - private SecurityGroupRule createSecurityGroupRuleExpected() { - return SecurityGroupRule - .builder() - .fromPort(80) - .group(ImmutableMap. of()) - .id("218") - .ipProtocol(SecurityGroupRule.IpProtocol.TCP) - .ipRange(ImmutableMap.of("cidr","0.0.0.0/0")) - .parentGroupId("161") - .toPort(8080) - .build(); - } + private SecurityGroupRule createSecurityGroupRuleExpected() { + return SecurityGroupRule.builder().fromPort(80).group(ImmutableMap. of()).id("218") + .ipProtocol(SecurityGroupRule.IpProtocol.TCP).ipRange(ImmutableMap.of("cidr", "0.0.0.0/0")) + .parentGroupId("161").toPort(8080).build(); + } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java index e337bd167f..d306d31480 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java @@ -18,71 +18,71 @@ */ package org.jclouds.openstack.nova.v1_1.extensions; +import static org.testng.Assert.assertNotNull; + +import java.util.Set; + import org.jclouds.openstack.nova.v1_1.domain.SecurityGroup; import org.jclouds.openstack.nova.v1_1.domain.SecurityGroupRule; import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; import org.testng.annotations.Test; -import java.util.Set; - -import static org.testng.Assert.assertNotNull; - /** * Tests behavior of {@code SecurityGroupClient} - * + * * @author Michael Arnold */ @Test(groups = "live", testName = "SecurityGroupClientLiveTest") public class SecurityGroupClientLiveTest extends BaseNovaClientLiveTest { - public static final String SECURITY_GROUP_NAME = "testsg"; + public static final String SECURITY_GROUP_NAME = "testsg"; - public void listSecurityGroups() throws Exception { - for (String regionId : context.getApi().getConfiguredRegions()) { - SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId); - Set securityGroupsList = client.listSecurityGroups(); - assertNotNull(securityGroupsList); - } - } - - public void createGetAndDeleteSecurityGroup() throws Exception { - for(String regionId : context.getApi().getConfiguredRegions()) { - SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId); - SecurityGroup securityGroup = null; - String id; - try { - securityGroup = client.createSecurityGroup(SECURITY_GROUP_NAME, "test security group"); - assertNotNull(securityGroup); - id = securityGroup.getId(); - SecurityGroup theGroup = client.getSecurityGroup(id); - assertNotNull(theGroup); - } finally { - if (securityGroup != null) { - client.deleteSecurityGroup(securityGroup.getId()); - } + public void listSecurityGroups() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId); + Set securityGroupsList = client.listSecurityGroups(); + assertNotNull(securityGroupsList); + } + } + + public void createGetAndDeleteSecurityGroup() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId); + SecurityGroup securityGroup = null; + String id; + try { + securityGroup = client.createSecurityGroup(SECURITY_GROUP_NAME, "test security group"); + assertNotNull(securityGroup); + id = securityGroup.getId(); + SecurityGroup theGroup = client.getSecurityGroup(id); + assertNotNull(theGroup); + } finally { + if (securityGroup != null) { + client.deleteSecurityGroup(securityGroup.getId()); } - } - } + } + } + } - public void createAndDeleteSecurityGroupRule() throws Exception { - for(String regionId : context.getApi().getConfiguredRegions()) { - SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId); - SecurityGroup securityGroup = null; + public void createAndDeleteSecurityGroupRule() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId); + SecurityGroup securityGroup = null; - try { - securityGroup = client.createSecurityGroup(SECURITY_GROUP_NAME, "test security group"); - assertNotNull(securityGroup); + try { + securityGroup = client.createSecurityGroup(SECURITY_GROUP_NAME, "test security group"); + assertNotNull(securityGroup); - SecurityGroupRule rule = client.createSecurityGroupRule( - "tcp", "443", "443", "0.0.0.0/0", "", securityGroup.getId()); - assertNotNull(rule); + SecurityGroupRule rule = client.createSecurityGroupRule("tcp", "443", "443", "0.0.0.0/0", "", + securityGroup.getId()); + assertNotNull(rule); - } finally { - if (securityGroup != null) { - client.deleteSecurityGroup(securityGroup.getId()); - } + } finally { + if (securityGroup != null) { + client.deleteSecurityGroup(securityGroup.getId()); } - } + } + } - } + } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientExpectTest.java index 8becc98cd2..e2ec9e76f3 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientExpectTest.java @@ -47,48 +47,38 @@ public class ExtensionClientExpectTest extends BaseNovaClientExpectTest { HttpRequest listExtensions = HttpRequest .builder() .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/extensions")) + .endpoint(URI.create("https://compute.north.host/v1.1/3456/extensions")) .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") + ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); HttpResponse listExtensionsResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/extension_list.json")).build(); - NovaClient clientWhenExtensionsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listExtensions, listExtensionsResponse); + NovaClient clientWhenExtensionsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listExtensions, listExtensionsResponse); - assertEquals(clientWhenExtensionsExist.getConfiguredRegions(), - ImmutableSet.of("North")); + assertEquals(clientWhenExtensionsExist.getConfiguredRegions(), ImmutableSet.of("North")); - assertEquals(clientWhenExtensionsExist.getExtensionClientForRegion("North") - .listExtensions().toString(), new ParseExtensionListTest().expected() - .toString()); + assertEquals(clientWhenExtensionsExist.getExtensionClientForRegion("North").listExtensions().toString(), + new ParseExtensionListTest().expected().toString()); } public void testListExtensionsWhenReponseIs404IsEmpty() throws Exception { HttpRequest listExtensions = HttpRequest .builder() .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/extensions")) + .endpoint(URI.create("https://compute.north.host/v1.1/3456/extensions")) .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") + ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); - HttpResponse listExtensionsResponse = HttpResponse.builder().statusCode(404) - .build(); + HttpResponse listExtensionsResponse = HttpResponse.builder().statusCode(404).build(); - NovaClient clientWhenNoServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listExtensions, listExtensionsResponse); + NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listExtensions, listExtensionsResponse); - assertTrue(clientWhenNoServersExist.getExtensionClientForRegion("North") - .listExtensions().isEmpty()); + assertTrue(clientWhenNoServersExist.getExtensionClientForRegion("North").listExtensions().isEmpty()); } // TODO: gson deserializer for Multimap @@ -97,42 +87,35 @@ public class ExtensionClientExpectTest extends BaseNovaClientExpectTest { HttpRequest getExtension = HttpRequest .builder() .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/extensions/RS-PIE")) + .endpoint(URI.create("https://compute.north.host/v1.1/3456/extensions/RS-PIE")) .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") + ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); HttpResponse getExtensionResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/extension_details.json")).build(); - NovaClient clientWhenExtensionsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - getExtension, getExtensionResponse); + NovaClient clientWhenExtensionsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getExtension, getExtensionResponse); - assertEquals(clientWhenExtensionsExist.getExtensionClientForRegion("North") - .getExtensionByAlias("RS-PIE").toString(), - new ParseExtensionTest().expected().toString()); + assertEquals(clientWhenExtensionsExist.getExtensionClientForRegion("North").getExtensionByAlias("RS-PIE") + .toString(), new ParseExtensionTest().expected().toString()); } public void testGetExtensionByAliasWhenResponseIs404() throws Exception { HttpRequest getExtension = HttpRequest .builder() .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/extensions/RS-PIE")) + .endpoint(URI.create("https://compute.north.host/v1.1/3456/extensions/RS-PIE")) .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") + ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); HttpResponse getExtensionResponse = HttpResponse.builder().statusCode(404) .payload(payloadFromResource("/extension_details.json")).build(); - NovaClient clientWhenNoExtensionsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - getExtension, getExtensionResponse); + NovaClient clientWhenNoExtensionsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getExtension, getExtensionResponse); assertNull(clientWhenNoExtensionsExist.getExtensionClientForRegion("North").getExtensionByAlias("RS-PIE")); diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientLiveTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientLiveTest.java index 901601a8ff..b2baaa3715 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientLiveTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ExtensionClientLiveTest.java @@ -58,5 +58,5 @@ public class ExtensionClientLiveTest extends BaseNovaClientLiveTest { } } } - + } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientExpectTest.java index 9fe65ccb6c..554a7c0e1f 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientExpectTest.java @@ -47,48 +47,38 @@ public class FlavorClientExpectTest extends BaseNovaClientExpectTest { HttpRequest listFlavors = HttpRequest .builder() .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/flavors")) + .endpoint(URI.create("https://compute.north.host/v1.1/3456/flavors")) .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") + ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); HttpResponse listFlavorsResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/flavor_list.json")).build(); - NovaClient clientWhenFlavorsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listFlavors, listFlavorsResponse); + NovaClient clientWhenFlavorsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listFlavors, listFlavorsResponse); - assertEquals(clientWhenFlavorsExist.getConfiguredRegions(), - ImmutableSet.of("North")); + assertEquals(clientWhenFlavorsExist.getConfiguredRegions(), ImmutableSet.of("North")); - assertEquals(clientWhenFlavorsExist.getFlavorClientForRegion("North") - .listFlavors().toString(), new ParseFlavorListTest().expected() - .toString()); + assertEquals(clientWhenFlavorsExist.getFlavorClientForRegion("North").listFlavors().toString(), + new ParseFlavorListTest().expected().toString()); } public void testListFlavorsWhenReponseIs404IsEmpty() throws Exception { HttpRequest listFlavors = HttpRequest .builder() .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/flavors")) + .endpoint(URI.create("https://compute.north.host/v1.1/3456/flavors")) .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") + ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); - HttpResponse listFlavorsResponse = HttpResponse.builder().statusCode(404) - .build(); + HttpResponse listFlavorsResponse = HttpResponse.builder().statusCode(404).build(); - NovaClient clientWhenNoServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listFlavors, listFlavorsResponse); + NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listFlavors, listFlavorsResponse); - assertTrue(clientWhenNoServersExist.getFlavorClientForRegion("North") - .listFlavors().isEmpty()); + assertTrue(clientWhenNoServersExist.getFlavorClientForRegion("North").listFlavors().isEmpty()); } // TODO: gson deserializer for Multimap @@ -97,42 +87,36 @@ public class FlavorClientExpectTest extends BaseNovaClientExpectTest { HttpRequest getFlavor = HttpRequest .builder() .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/flavors/52415800-8b69-11e0-9b19-734f1195ff37")) + .endpoint(URI.create("https://compute.north.host/v1.1/3456/flavors/52415800-8b69-11e0-9b19-734f1195ff37")) .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") + ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); HttpResponse getFlavorResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/flavor_details.json")).build(); - NovaClient clientWhenFlavorsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - getFlavor, getFlavorResponse); + NovaClient clientWhenFlavorsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getFlavor, getFlavorResponse); - assertEquals(clientWhenFlavorsExist.getFlavorClientForRegion("North") - .getFlavor("52415800-8b69-11e0-9b19-734f1195ff37").toString(), - new ParseFlavorTest().expected().toString()); + assertEquals( + clientWhenFlavorsExist.getFlavorClientForRegion("North").getFlavor("52415800-8b69-11e0-9b19-734f1195ff37") + .toString(), new ParseFlavorTest().expected().toString()); } public void testGetFlavorWhenResponseIs404() throws Exception { HttpRequest getFlavor = HttpRequest .builder() .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/flavors/123")) + .endpoint(URI.create("https://compute.north.host/v1.1/3456/flavors/123")) .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") + ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()).build(); HttpResponse getFlavorResponse = HttpResponse.builder().statusCode(404) .payload(payloadFromResource("/flavor_details.json")).build(); - NovaClient clientWhenNoFlavorsExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - getFlavor, getFlavorResponse); + NovaClient clientWhenNoFlavorsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getFlavor, getFlavorResponse); assertNull(clientWhenNoFlavorsExist.getFlavorClientForRegion("North").getFlavor("123")); diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java index 2a637169fb..87296b18d8 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/FlavorClientLiveTest.java @@ -56,14 +56,14 @@ public class FlavorClientLiveTest extends BaseNovaClientLiveTest { } } } - + /** * Tests the listing of Flavors in detail (getFlavor() is tested too!) * * @throws Exception */ @Test - public void testListFlavorsInDetail() throws Exception { + public void testListFlavorsInDetail() throws Exception { for (String regionId : context.getApi().getConfiguredRegions()) { FlavorClient client = context.getApi().getFlavorClientForRegion(regionId); Set response = client.listFlavorsInDetail(); @@ -79,7 +79,7 @@ public class FlavorClientLiveTest extends BaseNovaClientLiveTest { assertEquals(newDetails.getVcpus(), flavor.getVcpus()); } } - + } - + } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientExpectTest.java index ccdbeae5aa..cf3a916831 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientExpectTest.java @@ -18,121 +18,106 @@ */ package org.jclouds.openstack.nova.v1_1.features; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.openstack.nova.v1_1.NovaClient; -import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest; -import org.jclouds.openstack.nova.v1_1.parse.ParseImageTest; -import org.jclouds.openstack.nova.v1_1.parse.ParseImageListTest; -import org.testng.annotations.Test; - -import java.net.URI; - import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import java.net.URI; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.nova.v1_1.NovaClient; +import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest; +import org.jclouds.openstack.nova.v1_1.parse.ParseImageListTest; +import org.jclouds.openstack.nova.v1_1.parse.ParseImageTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; + /** * Tests annotation parsing of {@code ImageAsyncClient} - * + * * @author Michael Arnold */ @Test(groups = "unit", testName = "ImageAsyncClientTest") -public class ImageClientExpectTest extends BaseNovaClientExpectTest { - public void testListImagesWhenResponseIs2xx() throws Exception { - HttpRequest listImages = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/images")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); +public class ImageClientExpectTest extends BaseNovaClientExpectTest { + public void testListImagesWhenResponseIs2xx() throws Exception { + HttpRequest listImages = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/images")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - HttpResponse listImagesResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/image_list.json")).build(); + HttpResponse listImagesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/image_list.json")).build(); - NovaClient clientWhenImagesExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listImages, listImagesResponse); + NovaClient clientWhenImagesExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listImages, listImagesResponse); - assertEquals(clientWhenImagesExist.getConfiguredRegions(), - ImmutableSet.of("North")); + assertEquals(clientWhenImagesExist.getConfiguredRegions(), ImmutableSet.of("North")); - assertEquals(clientWhenImagesExist.getImageClientForRegion("North") - .listImages().toString(), new ParseImageListTest().expected() - .toString()); - } - - public void testListImagesWhenReponseIs404IsEmpty() throws Exception { - HttpRequest listImages = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/images")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + assertEquals(clientWhenImagesExist.getImageClientForRegion("North").listImages().toString(), + new ParseImageListTest().expected().toString()); + } - HttpResponse listImagesResponse = HttpResponse.builder().statusCode(404).build(); + public void testListImagesWhenReponseIs404IsEmpty() throws Exception { + HttpRequest listImages = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/images")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - NovaClient clientWhenNoServersExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - listImages, listImagesResponse); + HttpResponse listImagesResponse = HttpResponse.builder().statusCode(404).build(); - assertTrue(clientWhenNoServersExist.getImageClientForRegion("North") - .listImages().isEmpty()); - } + NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, listImages, listImagesResponse); - public void testGetImageWhenResponseIs2xx() throws Exception { + assertTrue(clientWhenNoServersExist.getImageClientForRegion("North").listImages().isEmpty()); + } - HttpRequest getImage = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/images/52415800-8b69-11e0-9b19-734f5736d2a2")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + public void testGetImageWhenResponseIs2xx() throws Exception { - HttpResponse getImageResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/image_details.json")).build(); + HttpRequest getImage = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/images/52415800-8b69-11e0-9b19-734f5736d2a2")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - NovaClient clientWhenImagesExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - getImage, getImageResponse); + HttpResponse getImageResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/image_details.json")).build(); - assertEquals(clientWhenImagesExist.getImageClientForRegion("North") - .getImage("52415800-8b69-11e0-9b19-734f5736d2a2").toString(), - new ParseImageTest().expected().toString()); - } + NovaClient clientWhenImagesExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getImage, getImageResponse); - public void testGetImageWhenResponseIs404() throws Exception { - HttpRequest getImage = HttpRequest - .builder() - .method("GET") - .endpoint( - URI.create("https://compute.north.host/v1.1/3456/images/52415800-8b69-11e0-9b19-734f5736d2a2")) - .headers( - ImmutableMultimap. builder() - .put("Accept", "application/json") - .put("X-Auth-Token", authToken).build()).build(); + assertEquals( + clientWhenImagesExist.getImageClientForRegion("North").getImage("52415800-8b69-11e0-9b19-734f5736d2a2") + .toString(), new ParseImageTest().expected().toString()); + } - HttpResponse getImageResponse = HttpResponse.builder().statusCode(404).build(); + public void testGetImageWhenResponseIs404() throws Exception { + HttpRequest getImage = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/images/52415800-8b69-11e0-9b19-734f5736d2a2")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - NovaClient clientWhenNoImagesExist = requestsSendResponses( - keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, - getImage, getImageResponse); + HttpResponse getImageResponse = HttpResponse.builder().statusCode(404).build(); - assertNull(clientWhenNoImagesExist.getImageClientForRegion("North") - .getImage("52415800-8b69-11e0-9b19-734f5736d2a2")); + NovaClient clientWhenNoImagesExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, + responseWithKeystoneAccess, getImage, getImageResponse); - } + assertNull(clientWhenNoImagesExist.getImageClientForRegion("North").getImage( + "52415800-8b69-11e0-9b19-734f5736d2a2")); + } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java index b4bfc435a8..450bbbf4af 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java @@ -18,64 +18,65 @@ */ package org.jclouds.openstack.nova.v1_1.features; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.nova.v1_1.domain.Image; import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; import org.testng.annotations.Test; -import java.util.Set; - -import static org.testng.Assert.*; - /** * Tests behavior of {@code ImageClient} - * + * * @author Michael Arnold */ @Test(groups = "live", testName = "ImageClientLiveTest") public class ImageClientLiveTest extends BaseNovaClientLiveTest { - @Test - public void testListImages() throws Exception { - for (String regionId : context.getApi().getConfiguredRegions()) { - ImageClient client = context.getApi().getImageClientForRegion(regionId); - Set response = client.listImages(); - assertNotNull(response); - assertTrue(response.size() >= 0); - for (Resource image : response) { - Image newDetails = client.getImage(image.getId()); - assertNotNull(newDetails); - assertEquals(newDetails.getId(), image.getId()); - assertEquals(newDetails.getName(), image.getName()); - assertEquals(newDetails.getLinks(), image.getLinks()); - } - } - } + @Test + public void testListImages() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + ImageClient client = context.getApi().getImageClientForRegion(regionId); + Set response = client.listImages(); + assertNotNull(response); + assertTrue(response.size() >= 0); + for (Resource image : response) { + Image newDetails = client.getImage(image.getId()); + assertNotNull(newDetails); + assertEquals(newDetails.getId(), image.getId()); + assertEquals(newDetails.getName(), image.getName()); + assertEquals(newDetails.getLinks(), image.getLinks()); + } + } + } - @Test - public void testListImagesInDetail() throws Exception { - for (String regionId : context.getApi().getConfiguredRegions()) { - ImageClient client = context.getApi().getImageClientForRegion(regionId); - Set response = client.listImagesInDetail(); - assertNotNull(response); - assertTrue(response.size() >= 0); - for (Image image : response) { - Image newDetails = client.getImage(image.getId()); - assertNotNull(newDetails); - assertEquals(newDetails.getId(), image.getId()); - assertEquals(newDetails.getName(), image.getName()); - assertEquals(newDetails.getLinks(), image.getLinks()); - assertEquals(newDetails.getCreated(), image.getCreated()); - assertEquals(newDetails.getMinDisk(), image.getMinDisk()); - assertEquals(newDetails.getMinRam(), image.getMinRam()); - assertEquals(newDetails.getProgress(), image.getProgress()); - assertEquals(newDetails.getStatus(), image.getStatus()); - assertEquals(newDetails.getServer(), image.getServer()); - assertEquals(newDetails.getTenantId(), image.getTenantId()); - assertEquals(newDetails.getUpdated(), image.getUpdated()); - assertEquals(newDetails.getUserId(), image.getUserId()); - } - } - } + @Test + public void testListImagesInDetail() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + ImageClient client = context.getApi().getImageClientForRegion(regionId); + Set response = client.listImagesInDetail(); + assertNotNull(response); + assertTrue(response.size() >= 0); + for (Image image : response) { + Image newDetails = client.getImage(image.getId()); + assertNotNull(newDetails); + assertEquals(newDetails.getId(), image.getId()); + assertEquals(newDetails.getName(), image.getName()); + assertEquals(newDetails.getLinks(), image.getLinks()); + assertEquals(newDetails.getCreated(), image.getCreated()); + assertEquals(newDetails.getMinDisk(), image.getMinDisk()); + assertEquals(newDetails.getMinRam(), image.getMinRam()); + assertEquals(newDetails.getProgress(), image.getProgress()); + assertEquals(newDetails.getStatus(), image.getStatus()); + assertEquals(newDetails.getServer(), image.getServer()); + assertEquals(newDetails.getTenantId(), image.getTenantId()); + assertEquals(newDetails.getUpdated(), image.getUpdated()); + assertEquals(newDetails.getUserId(), image.getUserId()); + } + } + } } - diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientExpectTest.java index ddaf66b9ba..20e417ce96 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientExpectTest.java @@ -42,33 +42,39 @@ import com.google.common.collect.ImmutableSet; public class ServerClientExpectTest extends BaseNovaClientExpectTest { public void testListServersWhenResponseIs2xx() throws Exception { - HttpRequest listServers = HttpRequest.builder().method("GET").endpoint( - URI.create("https://compute.north.host/v1.1/3456/servers")).headers( - ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", - authToken).build()).build(); + HttpRequest listServers = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/servers")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); - HttpResponse listServersResponse = HttpResponse.builder().statusCode(200).payload( - payloadFromResource("/server_list.json")).build(); + HttpResponse listServersResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/server_list.json")).build(); NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, - responseWithKeystoneAccess, listServers, listServersResponse); + responseWithKeystoneAccess, listServers, listServersResponse); assertEquals(clientWhenServersExist.getConfiguredRegions(), ImmutableSet.of("North")); assertEquals(clientWhenServersExist.getServerClientForRegion("North").listServers().toString(), - new ParseServerListTest().expected().toString()); + new ParseServerListTest().expected().toString()); } public void testListServersWhenReponseIs404IsEmpty() throws Exception { - HttpRequest listServers = HttpRequest.builder().method("GET").endpoint( - URI.create("https://compute.north.host/v1.1/3456/servers")).headers( - ImmutableMultimap. builder().put("Accept", "application/json").put("X-Auth-Token", - authToken).build()).build(); + HttpRequest listServers = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("https://compute.north.host/v1.1/3456/servers")) + .headers( + ImmutableMultimap. builder().put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); HttpResponse listServersResponse = HttpResponse.builder().statusCode(404).build(); NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey, - responseWithKeystoneAccess, listServers, listServersResponse); + responseWithKeystoneAccess, listServers, listServersResponse); assertTrue(clientWhenNoServersExist.getServerClientForRegion("North").listServers().isEmpty()); } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaClientLiveTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaClientLiveTest.java index 836a5a65e7..18c7e793f3 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaClientLiveTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaClientLiveTest.java @@ -44,7 +44,6 @@ public class BaseNovaClientLiveTest extends BaseVersionedServiceLiveTest { public BaseNovaClientLiveTest() { provider = "openstack-nova"; } - protected RestContext context; @@ -53,7 +52,7 @@ public class BaseNovaClientLiveTest extends BaseVersionedServiceLiveTest { setupCredentials(); Properties overrides = setupProperties(); context = new RestContextFactory().createContext(provider, identity, credential, - ImmutableSet. of(new SLF4JLoggingModule(), new SshjSshClientModule()), overrides); + ImmutableSet. of(new SLF4JLoggingModule(), new SshjSshClientModule()), overrides); } @AfterGroups(groups = "live") diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaExpectTest.java index c3ee24c12d..4b327ec45e 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/internal/BaseNovaExpectTest.java @@ -37,12 +37,12 @@ public class BaseNovaExpectTest extends BaseRestClientExpectTest { public BaseNovaExpectTest() { provider = "openstack-nova"; keystoneAuthWithUsernameAndPassword = KeystoneFixture.INSTANCE.initialAuthWithUsernameAndPassword(identity, - credential); + credential); keystoneAuthWithAccessKeyAndSecretKey = KeystoneFixture.INSTANCE.initialAuthWithAccessKeyAndSecretKey(identity, - credential); + credential); authToken = KeystoneFixture.INSTANCE.getAuthToken(); responseWithKeystoneAccess = KeystoneFixture.INSTANCE.responseWithAccess(); // now, createContext arg will need tenant prefix - identity = KeystoneFixture.INSTANCE.getTenantName() + ":" + identity; + identity = KeystoneFixture.INSTANCE.getTenantName() + ":" + identity; } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionListNormalTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionListNormalTest.java index 0497073264..4baf1ee689 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionListNormalTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionListNormalTest.java @@ -52,48 +52,23 @@ public class ParseExtensionListNormalTest extends BaseSetParserTest { @SelectJson("extensions") @Consumes(MediaType.APPLICATION_JSON) public Set expected() { - return ImmutableSet - .of(Extension - .builder() - .alias("os-keypairs") - .name("Keypairs") - .namespace(URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1")) - .updated( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2011-08-08T00:00:00+00:00")) - .description("Keypair Support") - .build(), - Extension - .builder() - .alias("os-volumes") - .name("Volumes") - .namespace(URI.create("http://docs.openstack.org/ext/volumes/api/v1.1")) - .updated( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2011-03-25T00:00:00+00:00")) - .description("Volumes support") - .build(), - Extension - .builder() - .alias("security_groups") - .name("SecurityGroups") - .namespace(URI.create("http://docs.openstack.org/ext/securitygroups/api/v1.1")) - .updated( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2011-07-21T00:00:00+00:00")) - .description("Security group support") - .build(), - Extension - .builder() - .alias("os-floating-ips") - .name("Floating_ips") - .namespace(URI.create("http://docs.openstack.org/ext/floating_ips/api/v1.1")) - .updated( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2011-06-16T00:00:00+00:00")) - .description("Floating IPs support") - .build() - ); + return ImmutableSet.of( + Extension.builder().alias("os-keypairs").name("Keypairs") + .namespace(URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1")) + .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-08-08T00:00:00+00:00")) + .description("Keypair Support").build(), + Extension.builder().alias("os-volumes").name("Volumes") + .namespace(URI.create("http://docs.openstack.org/ext/volumes/api/v1.1")) + .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-03-25T00:00:00+00:00")) + .description("Volumes support").build(), + Extension.builder().alias("security_groups").name("SecurityGroups") + .namespace(URI.create("http://docs.openstack.org/ext/securitygroups/api/v1.1")) + .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-07-21T00:00:00+00:00")) + .description("Security group support").build(), + Extension.builder().alias("os-floating-ips").name("Floating_ips") + .namespace(URI.create("http://docs.openstack.org/ext/floating_ips/api/v1.1")) + .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-06-16T00:00:00+00:00")) + .description("Floating IPs support").build()); } protected Injector injector() { diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionListTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionListTest.java index b60b6f26eb..437f1b1c0a 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionListTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionListTest.java @@ -56,45 +56,31 @@ public class ParseExtensionListTest extends BaseSetParserTest { public Set expected() { return ImmutableSet .of(Extension - .builder() - .alias("RAX-PIE") - .name("Public Image Extension") - .namespace(URI.create("http://docs.rackspacecloud.com/servers/api/ext/pie/v1.0")) - .updated( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2011-01-22T13:25:27-06:00")) - .description("Adds the capability to share an image with other users.") - .links( - ImmutableSet.of( - Link.create( - Relation.DESCRIBEDBY, - "application/pdf", - URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-pie-20111111.pdf")), - Link.create( - Relation.DESCRIBEDBY, - "application/vnd.sun.wadl+xml", - URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-pie.wadl")))) - .build(), - Extension - .builder() - .alias("RAX-CBS") - .name("Cloud Block Storage") - .namespace(URI.create("http://docs.rackspacecloud.com/servers/api/ext/cbs/v1.0")) - .updated( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2011-01-12T11:22:33-06:00")) - .description("Allows mounting cloud block storage volumes.") - .links( - ImmutableSet.of( - Link.create( - Relation.DESCRIBEDBY, - "application/pdf", - URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-cbs-20111201.pdf")), - Link.create( - Relation.DESCRIBEDBY, - "application/vnd.sun.wadl+xml", - URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-cbs.wadl")))) - .build()); + .builder() + .alias("RAX-PIE") + .name("Public Image Extension") + .namespace(URI.create("http://docs.rackspacecloud.com/servers/api/ext/pie/v1.0")) + .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-01-22T13:25:27-06:00")) + .description("Adds the capability to share an image with other users.") + .links( + ImmutableSet.of( + Link.create(Relation.DESCRIBEDBY, "application/pdf", + URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-pie-20111111.pdf")), + Link.create(Relation.DESCRIBEDBY, "application/vnd.sun.wadl+xml", + URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-pie.wadl")))).build(), + Extension + .builder() + .alias("RAX-CBS") + .name("Cloud Block Storage") + .namespace(URI.create("http://docs.rackspacecloud.com/servers/api/ext/cbs/v1.0")) + .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-01-12T11:22:33-06:00")) + .description("Allows mounting cloud block storage volumes.") + .links( + ImmutableSet.of(Link.create(Relation.DESCRIBEDBY, "application/pdf", + URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-cbs-20111201.pdf")), + Link.create(Relation.DESCRIBEDBY, "application/vnd.sun.wadl+xml", + URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-cbs.wadl")))) + .build()); } protected Injector injector() { diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionTest.java index 53738aa06d..02c2dd1026 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseExtensionTest.java @@ -57,23 +57,15 @@ public class ParseExtensionTest extends BaseItemParserTest { .alias("RS-PIE") .name("Public Image Extension") .namespace(URI.create("http://docs.rackspacecloud.com/servers/api/ext/pie/v1.0")) - .updated( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2011-01-22T13:25:27-06:00")) + .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-01-22T13:25:27-06:00")) .description("Adds the capability to share an image with other users.") .links( ImmutableSet.of( - Link.create( - Relation.DESCRIBEDBY, - "application/pdf", + Link.create(Relation.DESCRIBEDBY, "application/pdf", URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-pie-20111111.pdf")), - Link.create( - Relation.DESCRIBEDBY, - "application/vnd.sun.wadl+xml", - URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-pie.wadl")))) - .build(); + Link.create(Relation.DESCRIBEDBY, "application/vnd.sun.wadl+xml", + URI.create("http://docs.rackspacecloud.com/servers/api/ext/cs-pie.wadl")))).build(); } - protected Injector injector() { return Guice.createInjector(new NovaParserModule(), new GsonModule()); diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFlavorListTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFlavorListTest.java index eb78746d73..0f92a1c75f 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFlavorListTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFlavorListTest.java @@ -27,8 +27,8 @@ import javax.ws.rs.core.MediaType; import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.domain.Link; -import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.domain.Link.Relation; +import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFloatingIPListTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFloatingIPListTest.java index 31f97b4fb2..d1d8765f0a 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFloatingIPListTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFloatingIPListTest.java @@ -18,9 +18,11 @@ */ package org.jclouds.openstack.nova.v1_1.parse; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Guice; -import com.google.inject.Injector; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; @@ -28,9 +30,9 @@ import org.jclouds.openstack.nova.v1_1.domain.FloatingIP; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; -import java.util.Set; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; /** * @@ -48,22 +50,8 @@ public class ParseFloatingIPListTest extends BaseSetParserTest { @SelectJson("floating_ips") @Consumes(MediaType.APPLICATION_JSON) public Set expected() { - return ImmutableSet - .of( - FloatingIP - .builder() - .id("1") - .instanceId("12") - .ip("10.0.0.3") - .fixedIp("11.0.0.1") - .build(), - FloatingIP - .builder() - .id("2") - .instanceId(null) - .ip("10.0.0.5") - .fixedIp(null) - .build()); + return ImmutableSet.of(FloatingIP.builder().id("1").instanceId("12").ip("10.0.0.3").fixedIp("11.0.0.1").build(), + FloatingIP.builder().id("2").instanceId(null).ip("10.0.0.5").fixedIp(null).build()); } protected Injector injector() { diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFloatingIPTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFloatingIPTest.java index 3abd25ead2..f3ed3fb129 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFloatingIPTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseFloatingIPTest.java @@ -18,8 +18,9 @@ */ package org.jclouds.openstack.nova.v1_1.parse; -import com.google.inject.Guice; -import com.google.inject.Injector; +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + import org.jclouds.json.BaseItemParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; @@ -27,8 +28,8 @@ import org.jclouds.openstack.nova.v1_1.domain.FloatingIP; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; +import com.google.inject.Guice; +import com.google.inject.Injector; /** * @author Michael Arnold @@ -45,13 +46,7 @@ public class ParseFloatingIPTest extends BaseItemParserTest { @SelectJson("floating_ip") @Consumes(MediaType.APPLICATION_JSON) public FloatingIP expected() { - return FloatingIP - .builder() - .id("1") - .instanceId("123") - .fixedIp("10.0.0.2") - .ip("10.0.0.3") - .build(); + return FloatingIP.builder().id("1").instanceId("123").fixedIp("10.0.0.2").ip("10.0.0.3").build(); } protected Injector injector() { diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseImageListTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseImageListTest.java index da4a4c63bd..45d20150ea 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseImageListTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseImageListTest.java @@ -27,8 +27,8 @@ import javax.ws.rs.core.MediaType; import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.domain.Link; -import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.domain.Link.Relation; +import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseImageTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseImageTest.java index 0f9e3e342c..2d15812c45 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseImageTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseImageTest.java @@ -27,8 +27,8 @@ import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.json.BaseItemParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.domain.Link; -import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.domain.Link.Relation; +import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; import org.jclouds.openstack.nova.v1_1.domain.Image; import org.jclouds.openstack.nova.v1_1.domain.ImageStatus; @@ -59,21 +59,17 @@ public class ParseImageTest extends BaseItemParserTest { .builder() .id("52415800-8b69-11e0-9b19-734f5736d2a2") .name("My Server Backup") - .updated( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2010-10-10T12:00:00Z")) - .created( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2010-08-10T12:00:00Z")) + .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-10-10T12:00:00Z")) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-08-10T12:00:00Z")) .tenantId("12345") .userId("joe") .status(ImageStatus.SAVING) .progress(80) .minDisk(5) .minRam(256) - .metadata(new ImmutableMap.Builder() - .put("ImageType", "Gold") - .put("ImageVersion", "1.5").build()) + .metadata( + new ImmutableMap.Builder().put("ImageType", "Gold").put("ImageVersion", "1.5") + .build()) .server( Resource .builder() diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairListTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairListTest.java index 10b921011b..8622e08a97 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairListTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairListTest.java @@ -18,59 +18,61 @@ */ package org.jclouds.openstack.nova.v1_1.parse; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Guice; -import com.google.inject.Injector; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + import org.jclouds.json.BaseParserTest; -import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; import org.jclouds.openstack.nova.v1_1.domain.KeyPair; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; /** - * + * * @author Michael Arnold */ @Test(groups = "unit", testName = "ParseKeyPairListTest") -public class ParseKeyPairListTest extends BaseParserTest { +public class ParseKeyPairListTest extends BaseParserTest { - @Override - public String resource() { - return "/keypair_list.json"; - } + @Override + public String resource() { + return "/keypair_list.json"; + } - @Override - @SelectJson("keypairs") - @Consumes(MediaType.APPLICATION_JSON) - public Set> expected() { - Map kp1 = new HashMap(); - kp1.put("keypair", KeyPair - .builder() - .publicKey("ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQCy9EC3O7Ff80vPEfAHDQob61PGwcpYc5KE7tEZnZhrB9n0NyHPRm0E0M+ls3fcTa04HDi+R0DzmRwoyhHQJyI658v8kWZZcuvFjKCcsgsSh/dzdX0xTreLIzSOzt5U7RnZYfshP5cmxtF99yrEY3M/swdin0L+fXsTSkR1B42STQ== nova@nv-aw2az1-api0001") - .name("default") - .fingerprint("ab:0c:f4:f3:54:c0:5d:3f:ed:62:ad:d3:94:7c:79:7c") - .build()); - Map kp2 = new HashMap(); - kp2.put("keypair", KeyPair - .builder() - .publicKey("ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001") - .name("testkeypair") - .fingerprint("d2:1f:c9:2b:d8:90:77:5f:15:64:27:e3:9f:77:1d:e4") - .build()); - return ImmutableSet.of(kp1,kp2); - } + @Override + @SelectJson("keypairs") + @Consumes(MediaType.APPLICATION_JSON) + public Set> expected() { + Map kp1 = new HashMap(); + kp1.put( + "keypair", + KeyPair + .builder() + .publicKey( + "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQCy9EC3O7Ff80vPEfAHDQob61PGwcpYc5KE7tEZnZhrB9n0NyHPRm0E0M+ls3fcTa04HDi+R0DzmRwoyhHQJyI658v8kWZZcuvFjKCcsgsSh/dzdX0xTreLIzSOzt5U7RnZYfshP5cmxtF99yrEY3M/swdin0L+fXsTSkR1B42STQ== nova@nv-aw2az1-api0001") + .name("default").fingerprint("ab:0c:f4:f3:54:c0:5d:3f:ed:62:ad:d3:94:7c:79:7c").build()); + Map kp2 = new HashMap(); + kp2.put( + "keypair", + KeyPair + .builder() + .publicKey( + "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001") + .name("testkeypair").fingerprint("d2:1f:c9:2b:d8:90:77:5f:15:64:27:e3:9f:77:1d:e4").build()); + return ImmutableSet.of(kp1, kp2); + } - protected Injector injector() { - return Guice.createInjector(new NovaParserModule(), new GsonModule()); - } + protected Injector injector() { + return Guice.createInjector(new NovaParserModule(), new GsonModule()); + } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairTest.java index 9901ba5f2d..2f3a4fceb7 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairTest.java @@ -18,47 +18,46 @@ */ package org.jclouds.openstack.nova.v1_1.parse; -import com.google.inject.Guice; -import com.google.inject.Injector; +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + import org.jclouds.json.BaseItemParserTest; -import org.jclouds.json.BaseParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; import org.jclouds.openstack.nova.v1_1.domain.KeyPair; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; +import com.google.inject.Guice; +import com.google.inject.Injector; /** - * + * * @author Michael Arnold */ @Test(groups = "unit", testName = "ParseKeyPairTest") public class ParseKeyPairTest extends BaseItemParserTest { - @Override - public String resource() { - return "/keypair_created.json"; - } + @Override + public String resource() { + return "/keypair_created.json"; + } - @Override - @SelectJson("keypair") - @Consumes(MediaType.APPLICATION_JSON) - public KeyPair expected() { - return KeyPair - .builder() - .publicKey("ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n") - .privateKey("-----BEGIN RSA PRIVATE KEY-----\nMIICXQIAAAKBgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABAC\nE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumA\nDSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQIDAQAB\nAoGAW8Ww+KbpQK8smcgCTr/RqcmsSI8VeL2hXjJvDq0L5WbyYuFdkanDvCztUVZn\nsmyfDtwAqZXB4Ct/dN1tY7m8QpdyRaKRW4Q+hghGCAQpsG7rYDdvwdEyvMaW5RA4\ntucQyajMNyQ/tozU3wMx/v8A7RvGcE9tqoG0WK1C3kBu95UCQQDrOd+joYDkvccz\nFIVu5gNPMXEh3fGGzDxk225UlvESquYLzfz4TfmuUjH4Z1BL3wRiwfJsrrjFkm33\njIidDE8PAkEA1qHjxuaIS1yz/rfzErmcOVNlbFHMP4ihjGTTvh1ZctXlNeLwzENQ\nEDaQV3IpUY1KQR6rxcWb5AXgfF9D9PYFpwJBANucAqGAbRgh3lJgPFtXP4u2O0tF\nLPOOxmvbOdybt6KYD4LB5AXmts77SlACFMNhCXUyYaT6UuOSXDyb5gfJsB0CQQC3\nFaGXKU9Z+doQjhlq/6mjvN/nZl80Uvh7Kgb1RVPoAU1kihGeLE0/h0vZTCiyyDNv\nGRqtucMg32J+tUTi0HpBAkAwHiCZMHMeJWHUwIwlRQY/dnR86FWobRl98ViF2rCL\nDHkDVOeIser3Q6zSqU5/m99lX6an5g8pAh/R5LqnOQZC\n-----END RSA PRIVATE KEY-----\n") - .name("testkeypair") - .userId("65649731189278") - .fingerprint("d2:1f:c9:2b:d8:90:77:5f:15:64:27:e3:9f:77:1d:e4") - .build(); - } + @Override + @SelectJson("keypair") + @Consumes(MediaType.APPLICATION_JSON) + public KeyPair expected() { + return KeyPair + .builder() + .publicKey( + "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n") + .privateKey( + "-----BEGIN RSA PRIVATE KEY-----\nMIICXQIAAAKBgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABAC\nE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumA\nDSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQIDAQAB\nAoGAW8Ww+KbpQK8smcgCTr/RqcmsSI8VeL2hXjJvDq0L5WbyYuFdkanDvCztUVZn\nsmyfDtwAqZXB4Ct/dN1tY7m8QpdyRaKRW4Q+hghGCAQpsG7rYDdvwdEyvMaW5RA4\ntucQyajMNyQ/tozU3wMx/v8A7RvGcE9tqoG0WK1C3kBu95UCQQDrOd+joYDkvccz\nFIVu5gNPMXEh3fGGzDxk225UlvESquYLzfz4TfmuUjH4Z1BL3wRiwfJsrrjFkm33\njIidDE8PAkEA1qHjxuaIS1yz/rfzErmcOVNlbFHMP4ihjGTTvh1ZctXlNeLwzENQ\nEDaQV3IpUY1KQR6rxcWb5AXgfF9D9PYFpwJBANucAqGAbRgh3lJgPFtXP4u2O0tF\nLPOOxmvbOdybt6KYD4LB5AXmts77SlACFMNhCXUyYaT6UuOSXDyb5gfJsB0CQQC3\nFaGXKU9Z+doQjhlq/6mjvN/nZl80Uvh7Kgb1RVPoAU1kihGeLE0/h0vZTCiyyDNv\nGRqtucMg32J+tUTi0HpBAkAwHiCZMHMeJWHUwIwlRQY/dnR86FWobRl98ViF2rCL\nDHkDVOeIser3Q6zSqU5/m99lX6an5g8pAh/R5LqnOQZC\n-----END RSA PRIVATE KEY-----\n") + .name("testkeypair").userId("65649731189278") + .fingerprint("d2:1f:c9:2b:d8:90:77:5f:15:64:27:e3:9f:77:1d:e4").build(); + } - - protected Injector injector() { - return Guice.createInjector(new NovaParserModule(), new GsonModule()); - } + protected Injector injector() { + return Guice.createInjector(new NovaParserModule(), new GsonModule()); + } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseSecurityGroupListTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseSecurityGroupListTest.java index dbd16cfe83..b149e0ed45 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseSecurityGroupListTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseSecurityGroupListTest.java @@ -18,10 +18,13 @@ */ package org.jclouds.openstack.nova.v1_1.parse; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Guice; -import com.google.inject.Injector; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; @@ -30,78 +33,46 @@ import org.jclouds.openstack.nova.v1_1.domain.SecurityGroupRule; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; /** - * + * * @author Michael Arnold */ @Test(groups = "unit", testName = "ParseSecurityGroupListTest") public class ParseSecurityGroupListTest extends BaseSetParserTest { - @Override - public String resource() { - return "/securitygroup_list.json"; - } + @Override + public String resource() { + return "/securitygroup_list.json"; + } - @Override - @SelectJson("security_groups") - @Consumes(MediaType.APPLICATION_JSON) - public Set expected() { + @Override + @SelectJson("security_groups") + @Consumes(MediaType.APPLICATION_JSON) + public Set expected() { - Map anyCidr = ImmutableMap. of("cidr", "0.0.0.0/0"); + Map anyCidr = ImmutableMap. of("cidr", "0.0.0.0/0"); - Set securityGroupRules = ImmutableSet. of( - SecurityGroupRule - .builder() - .fromPort(22) - .group(new HashMap()) - .ipProtocol(SecurityGroupRule.IpProtocol.TCP) - .toPort(22) - .parentGroupId("3") - .ipRange(anyCidr) - .id("107") - .build(), - SecurityGroupRule - .builder() - .fromPort(7600) - .group(new HashMap()) - .ipProtocol(SecurityGroupRule.IpProtocol.TCP) - .toPort(7600) - .parentGroupId("3") - .ipRange(anyCidr) - .id("118") - .build(), - SecurityGroupRule - .builder() - .fromPort(8084) - .group(new HashMap()) - .ipProtocol(SecurityGroupRule.IpProtocol.TCP) - .toPort(8084) - .parentGroupId("3") - .ipRange(anyCidr) - .id("119") - .build() - ); + Set securityGroupRules = ImmutableSet. of( + SecurityGroupRule.builder().fromPort(22).group(new HashMap()) + .ipProtocol(SecurityGroupRule.IpProtocol.TCP).toPort(22).parentGroupId("3").ipRange(anyCidr) + .id("107").build(), + SecurityGroupRule.builder().fromPort(7600).group(new HashMap()) + .ipProtocol(SecurityGroupRule.IpProtocol.TCP).toPort(7600).parentGroupId("3").ipRange(anyCidr) + .id("118").build(), + SecurityGroupRule.builder().fromPort(8084).group(new HashMap()) + .ipProtocol(SecurityGroupRule.IpProtocol.TCP).toPort(8084).parentGroupId("3").ipRange(anyCidr) + .id("119").build()); - return ImmutableSet - .of( - SecurityGroup - .builder() - .description("description1") - .id("1") - .tenantId("tenant1") - .rules(securityGroupRules) - .name("name1") - .build() - ); - } + return ImmutableSet.of(SecurityGroup.builder().description("description1").id("1").tenantId("tenant1") + .rules(securityGroupRules).name("name1").build()); + } - protected Injector injector() { - return Guice.createInjector(new NovaParserModule(), new GsonModule()); - } + protected Injector injector() { + return Guice.createInjector(new NovaParserModule(), new GsonModule()); + } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseSecurityGroupTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseSecurityGroupTest.java index 20d743e8c7..1779f300ed 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseSecurityGroupTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseSecurityGroupTest.java @@ -18,13 +18,13 @@ */ package org.jclouds.openstack.nova.v1_1.parse; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.inject.Guice; -import com.google.inject.Injector; +import java.util.HashMap; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + import org.jclouds.json.BaseItemParserTest; -import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; import org.jclouds.openstack.nova.v1_1.domain.SecurityGroup; @@ -32,63 +32,41 @@ import org.jclouds.openstack.nova.v1_1.domain.SecurityGroupRule; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; /** - * + * * @author Michael Arnold */ @Test(groups = "unit", testName = "ParseSecurityGroupTest") public class ParseSecurityGroupTest extends BaseItemParserTest { - @Override - public String resource() { - return "/securitygroup_details.json"; - } + @Override + public String resource() { + return "/securitygroup_details.json"; + } - @Override - @SelectJson("security_group") - @Consumes(MediaType.APPLICATION_JSON) - public SecurityGroup expected() { + @Override + @SelectJson("security_group") + @Consumes(MediaType.APPLICATION_JSON) + public SecurityGroup expected() { - Set securityGroupRules = ImmutableSet. of( - SecurityGroupRule - .builder() - .fromPort(22) - .group(new HashMap()) - .ipProtocol(SecurityGroupRule.IpProtocol.TCP) - .toPort(22) - .parentGroupId("28") - .ipRange(ImmutableMap.of("cidr", "10.2.6.0/24")) - .id("108") - .build(), - SecurityGroupRule - .builder() - .fromPort(22) - .group(ImmutableMap.of("tenant_id","admin", "name", "11111")) - .ipProtocol(SecurityGroupRule.IpProtocol.TCP) - .toPort(22) - .parentGroupId("28") - .ipRange(new HashMap()) - .id("109") - .build() - ); + Set securityGroupRules = ImmutableSet. of( + SecurityGroupRule.builder().fromPort(22).group(new HashMap()) + .ipProtocol(SecurityGroupRule.IpProtocol.TCP).toPort(22).parentGroupId("28") + .ipRange(ImmutableMap.of("cidr", "10.2.6.0/24")).id("108").build(), + SecurityGroupRule.builder().fromPort(22).group(ImmutableMap.of("tenant_id", "admin", "name", "11111")) + .ipProtocol(SecurityGroupRule.IpProtocol.TCP).toPort(22).parentGroupId("28") + .ipRange(new HashMap()).id("109").build()); - return SecurityGroup - .builder() - .description("description0") - .id("0") - .tenantId("tenant0") - .rules(securityGroupRules) - .name("name0") - .build(); - } + return SecurityGroup.builder().description("description0").id("0").tenantId("tenant0").rules(securityGroupRules) + .name("name0").build(); + } - protected Injector injector() { - return Guice.createInjector(new NovaParserModule(), new GsonModule()); - } + protected Injector injector() { + return Guice.createInjector(new NovaParserModule(), new GsonModule()); + } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseServerListTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseServerListTest.java index d130aefade..dc911c2515 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseServerListTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseServerListTest.java @@ -27,8 +27,8 @@ import javax.ws.rs.core.MediaType; import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.domain.Link; -import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.domain.Link.Relation; +import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; @@ -54,39 +54,30 @@ public class ParseServerListTest extends BaseSetParserTest { @Consumes(MediaType.APPLICATION_JSON) public Set expected() { return ImmutableSet - .of( - Resource - .builder() - .id("52415800-8b69-11e0-9b19-734f6af67565") - .name("sample-server") - .links( - Link - .create( - Relation.SELF, - URI - .create("http://servers.api.openstack.org/v1.1/1234/servers/52415800-8b69-11e0-9b19-734f6af67565")), - Link - .create( - Relation.BOOKMARK, - URI - .create("http://servers.api.openstack.org/1234/servers/52415800-8b69-11e0-9b19-734f6af67565"))) - .build(), - Resource - .builder() - .id("52415800-8b69-11e0-9b19-734f1f1350e5") - .name("sample-server2") - .links( - Link - .create( - Relation.SELF, - URI - .create("http://servers.api.openstack.org/v1.1/1234/servers/52415800-8b69-11e0-9b19-734f1f1350e5")), - Link - .create( - Relation.BOOKMARK, - URI - .create("http://servers.api.openstack.org/1234/servers/52415800-8b69-11e0-9b19-734f1f1350e5"))) - .build()); + .of(Resource + .builder() + .id("52415800-8b69-11e0-9b19-734f6af67565") + .name("sample-server") + .links( + Link.create( + Relation.SELF, + URI.create("http://servers.api.openstack.org/v1.1/1234/servers/52415800-8b69-11e0-9b19-734f6af67565")), + Link.create( + Relation.BOOKMARK, + URI.create("http://servers.api.openstack.org/1234/servers/52415800-8b69-11e0-9b19-734f6af67565"))) + .build(), + Resource + .builder() + .id("52415800-8b69-11e0-9b19-734f1f1350e5") + .name("sample-server2") + .links( + Link.create( + Relation.SELF, + URI.create("http://servers.api.openstack.org/v1.1/1234/servers/52415800-8b69-11e0-9b19-734f1f1350e5")), + Link.create( + Relation.BOOKMARK, + URI.create("http://servers.api.openstack.org/1234/servers/52415800-8b69-11e0-9b19-734f1f1350e5"))) + .build()); } protected Injector injector() { diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseServerTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseServerTest.java index 02e3e60b8c..5c211eb05e 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseServerTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseServerTest.java @@ -27,8 +27,8 @@ import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.json.BaseItemParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.openstack.domain.Link; -import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.domain.Link.Relation; +import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.nova.v1_1.config.NovaParserModule; import org.jclouds.openstack.nova.v1_1.domain.Address; import org.jclouds.openstack.nova.v1_1.domain.Server; @@ -61,12 +61,8 @@ public class ParseServerTest extends BaseItemParserTest { .tenantId("1234") .userId("5678") .name("sample-server") - .updated( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2010-10-10T12:00:00Z")) - .created( - new SimpleDateFormatDateService() - .iso8601SecondsDateParse("2010-08-10T12:00:00Z")) + .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-10-10T12:00:00Z")) + .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-08-10T12:00:00Z")) .hostId("e4d909c290d0fb1ca068ffaddf22cbd0") .accessIPv4("67.23.10.132") .accessIPv6("::babe:67.23.10.132") @@ -85,27 +81,25 @@ public class ParseServerTest extends BaseItemParserTest { Relation.BOOKMARK, URI.create("http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f6f006e54"))) .build()) - .flavor(Resource - .builder() - .id("52415800-8b69-11e0-9b19-734f216543fd") - .name("null") - .links( - Link.create( - Relation.SELF, - URI.create("http://servers.api.openstack.org/v1.1/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd")), - Link.create( - Relation.BOOKMARK, - URI.create("http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd"))) - .build()) - .metadata(new ImmutableMap.Builder() - .put("Server Label", "Web Head 1") + .flavor( + Resource + .builder() + .id("52415800-8b69-11e0-9b19-734f216543fd") + .name("null") + .links( + Link.create( + Relation.SELF, + URI.create("http://servers.api.openstack.org/v1.1/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd")), + Link.create( + Relation.BOOKMARK, + URI.create("http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd"))) + .build()) + .metadata( + new ImmutableMap.Builder().put("Server Label", "Web Head 1") .put("Image Version", "2.1").build()) - .publicAddresses(Address.createV4("67.23.10.132"), - Address.createV6("::babe:67.23.10.132"), - Address.createV4("67.23.10.131"), - Address.createV6("::babe:4317:0A83")) - .privateAddresses(Address.createV4("10.176.42.16"), - Address.createV6("::babe:10.176.42.16")).build(); + .publicAddresses(Address.createV4("67.23.10.132"), Address.createV6("::babe:67.23.10.132"), + Address.createV4("67.23.10.131"), Address.createV6("::babe:4317:0A83")) + .privateAddresses(Address.createV4("10.176.42.16"), Address.createV6("::babe:10.176.42.16")).build(); } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/predicates/ExtensionPredicatesTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/predicates/ExtensionPredicatesTest.java index 17e0beb003..eb0efa9262 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/predicates/ExtensionPredicatesTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/predicates/ExtensionPredicatesTest.java @@ -18,8 +18,10 @@ */ package org.jclouds.openstack.nova.v1_1.predicates; +import static org.jclouds.openstack.nova.v1_1.predicates.ExtensionPredicates.aliasEquals; +import static org.jclouds.openstack.nova.v1_1.predicates.ExtensionPredicates.namespaceEquals; + import java.net.URI; -import static org.jclouds.openstack.nova.v1_1.predicates.ExtensionPredicates.*; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.openstack.nova.v1_1.domain.Extension; @@ -31,10 +33,10 @@ import org.testng.annotations.Test; */ @Test(groups = "unit", testName = "ExtensionPredicatesTest") public class ExtensionPredicatesTest { - Extension ref = Extension.builder().alias("os-keypairs").name("Keypairs").namespace( - URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1")).updated( - new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-08-08T00:00:00+00:00")).description( - "Keypair Support").build(); + Extension ref = Extension.builder().alias("os-keypairs").name("Keypairs") + .namespace(URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1")) + .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-08-08T00:00:00+00:00")) + .description("Keypair Support").build(); @Test public void testAliasEqualsWhenEqual() {