From a8a6cb083db5a36ec43e7c58ee1164169bfad7fc Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Tue, 3 Jul 2012 12:37:02 +0100 Subject: [PATCH] openstack: using Multimaps directly and relying on typeadapters to filter nulls from Maps --- .../nova/v2_0/domain/HostAggregate.java | 8 ++++---- .../openstack/nova/v2_0/domain/Image.java | 2 +- .../openstack/nova/v2_0/domain/Server.java | 18 ++++++------------ .../v2_0/domain/ServerWithSecurityGroups.java | 6 +++--- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostAggregate.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostAggregate.java index ad4d676968..b40f914337 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostAggregate.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostAggregate.java @@ -170,16 +170,16 @@ public class HostAggregate { @ConstructorProperties({ "id", "name", "availability_zone", "hosts", "operational_state", "created_at", "updated_at", "metadata" }) - protected HostAggregate(String id, String name, String availabilityZone, Set hosts, String state, Date created, - @Nullable Date updated, Map metadata) { + protected HostAggregate(String id, String name, String availabilityZone, @Nullable Set hosts, String state, Date created, + @Nullable Date updated, @Nullable Map metadata) { this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name"); this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone"); - this.hosts = ImmutableSet.copyOf(checkNotNull(hosts, "hosts")); + this.hosts = hosts == null ? ImmutableSet.of() : ImmutableSet.copyOf(hosts); this.state = checkNotNull(state, "state"); this.created = checkNotNull(created, "created"); this.updated = Optional.fromNullable(updated); - this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); + this.metadata = metadata == null ? ImmutableMap.of() : ImmutableMap.copyOf(metadata); } public String getId() { diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Image.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Image.java index 29b6265fd8..6e6b8aff9e 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Image.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Image.java @@ -228,7 +228,7 @@ public class Image extends Resource { this.minDisk = minDisk; this.minRam = minRam; this.server = server; - this.metadata = metadata == null ? ImmutableMap.of() : ImmutableMap.copyOf(Maps.filterValues(metadata, Predicates.notNull())); + this.metadata = metadata == null ? ImmutableMap.of() : ImmutableMap.copyOf(metadata); } @Nullable diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java index e113d2aeff..a80cb11286 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java @@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Date; import java.util.Map; -import java.util.Set; import javax.inject.Named; @@ -31,16 +30,12 @@ import org.jclouds.javax.annotation.Nullable; import org.jclouds.openstack.nova.v2_0.extensions.KeyPairClient; import org.jclouds.openstack.v2_0.domain.Link; import org.jclouds.openstack.v2_0.domain.Resource; -import org.jclouds.util.Multimaps2; -import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Optional; -import com.google.common.base.Predicates; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Maps; import com.google.common.collect.Multimap; /** @@ -254,7 +249,7 @@ public class Server extends Resource { public Server build() { return new Server(id, name, links, uuid, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, - status, image, flavor, keyName, configDrive, Multimaps2.toOldSchool(addresses), metadata, extendedStatus, + status, image, flavor, keyName, configDrive, addresses, metadata, extendedStatus, extendedAttributes, diskConfig); } @@ -305,7 +300,7 @@ public class Server extends Resource { private final String keyName; @Named("config_drive") private final String configDrive; - private final Map> addresses; + private final Multimap addresses; private final Map metadata; private final Optional extendedStatus; private final Optional extendedAttributes; @@ -318,7 +313,7 @@ public class Server extends Resource { protected Server(String id, @Nullable String name, java.util.Set links, @Nullable String uuid, String tenantId, String userId, @Nullable Date updated, Date created, @Nullable String hostId, @Nullable String accessIPv4, @Nullable String accessIPv6, Server.Status status, Resource image, Resource flavor, @Nullable String keyName, - @Nullable String configDrive, Map> addresses, Map metadata, + @Nullable String configDrive, Multimap addresses, Map metadata, @Nullable ServerExtendedStatus extendedStatus, @Nullable ServerExtendedAttributes extendedAttributes, @Nullable String diskConfig) { super(id, name, links); @@ -335,7 +330,7 @@ public class Server extends Resource { this.flavor = checkNotNull(flavor, "flavor"); this.keyName = Strings.emptyToNull(keyName); this.configDrive = Strings.emptyToNull(configDrive); - this.addresses = ImmutableMap.copyOf(checkNotNull(addresses, "addresses")); + this.addresses = ImmutableMultimap.copyOf(checkNotNull(addresses, "addresses")); this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); this.extendedStatus = Optional.fromNullable(extendedStatus); this.extendedAttributes = Optional.fromNullable(extendedAttributes); @@ -405,15 +400,14 @@ public class Server extends Resource { } public Map getMetadata() { - // in case this was assigned in gson - return ImmutableMap.copyOf(Maps.filterValues(this.metadata, Predicates.notNull())); + return metadata; } /** * @return the ip addresses assigned to the server */ public Multimap getAddresses() { - return Multimaps2.fromOldSchool(addresses); + return addresses; } /** diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerWithSecurityGroups.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerWithSecurityGroups.java index 3106f507fb..02ad5cf500 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerWithSecurityGroups.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerWithSecurityGroups.java @@ -30,11 +30,11 @@ import javax.inject.Named; import org.jclouds.javax.annotation.Nullable; import org.jclouds.openstack.v2_0.domain.Link; import org.jclouds.openstack.v2_0.domain.Resource; -import org.jclouds.util.Multimaps2; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; /** * Extended server returned by ServerWithSecurityGroupsClient @@ -71,7 +71,7 @@ public class ServerWithSecurityGroups extends Server { public ServerWithSecurityGroups build() { return new ServerWithSecurityGroups(id, name, links, uuid, tenantId, userId, updated, created, hostId, - accessIPv4, accessIPv6, status, image, flavor, keyName, configDrive, Multimaps2.toOldSchool(addresses), + accessIPv4, accessIPv6, status, image, flavor, keyName, configDrive, addresses, metadata, extendedStatus, extendedAttributes, diskConfig, securityGroupNames); } @@ -98,7 +98,7 @@ public class ServerWithSecurityGroups extends Server { String tenantId, String userId, Date updated, Date created, @Nullable String hostId, @Nullable String accessIPv4, @Nullable String accessIPv6, Server.Status status, Resource image, Resource flavor, @Nullable String keyName, @Nullable String configDrive, - Map> addresses, Map metadata, + Multimap addresses, Map metadata, @Nullable ServerExtendedStatus extendedStatus, @Nullable ServerExtendedAttributes extendedAttributes, @Nullable String diskConfig, Set securityGroupNames) { super(id, name, links, uuid, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, status, image, flavor, keyName, configDrive, addresses, metadata, extendedStatus, extendedAttributes, diskConfig);