From bff49f8311cce1e45fe57e7e1fb43419b3af00ba Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 16 Sep 2012 23:39:26 -0700 Subject: [PATCH] compatible tags across 2.0 and 4.0 --- .../cloudstack/CloudStackApiMetadata.java | 6 +- .../config/CloudStackDateAdapter.java | 51 -------- .../config/CloudStackParserModule.java | 115 ++++++++++++++++++ .../config/CloudStackRestClientModule.java | 83 ++++++++++++- .../cloudstack/domain/DiskOffering.java | 29 +++-- .../org/jclouds/cloudstack/domain/Host.java | 45 ++++--- .../jclouds/cloudstack/domain/Network.java | 27 ++-- .../cloudstack/domain/NetworkOffering.java | 30 +++-- .../cloudstack/domain/ServiceOffering.java | 55 +++------ .../cloudstack/domain/StoragePool.java | 33 +++-- .../features/GlobalHostClientExpectTest.java | 6 +- .../parse/ListHostsResponseTest.java | 15 +-- .../parse/ListStoragePoolsResponseTest.java | 17 ++- .../parse/ListUsageRecordsResponseTest.java | 15 +-- .../resources/liststoragepoolsresponse.json | 2 +- 15 files changed, 353 insertions(+), 176 deletions(-) delete mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackDateAdapter.java create mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackParserModule.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java index cdb671f895..d0bf37c0b0 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackApiMetadata.java @@ -23,6 +23,7 @@ import java.util.Properties; import org.jclouds.apis.ApiMetadata; import org.jclouds.cloudstack.compute.config.CloudStackComputeServiceContextModule; +import org.jclouds.cloudstack.config.CloudStackParserModule; import org.jclouds.cloudstack.config.CloudStackRestClientModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.BaseRestApiMetadata; @@ -91,7 +92,10 @@ public class CloudStackApiMetadata extends BaseRestApiMetadata { .version("2.2") .view(TypeToken.of(CloudStackContext.class)) .defaultProperties(CloudStackApiMetadata.defaultProperties()) - .defaultModules(ImmutableSet.>of(CloudStackRestClientModule.class, CloudStackComputeServiceContextModule.class)); + .defaultModules(ImmutableSet.> builder() + .add(CloudStackParserModule.class) + .add(CloudStackRestClientModule.class) + .add(CloudStackComputeServiceContextModule.class).build()); } @Override diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackDateAdapter.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackDateAdapter.java deleted file mode 100644 index e0bc79b1d9..0000000000 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackDateAdapter.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudstack.config; - -import java.io.IOException; -import java.util.Date; - -import javax.inject.Inject; - -import org.jclouds.date.DateService; -import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; - -import com.google.gson.stream.JsonReader; - -/** - * Data adapter for the date formats used by CloudStack. - * - * Essentially this is a workaround for the CloudStack getUsage() API call returning a - * corrupted form of ISO-8601 dates, which have an unexpected pair of apostrophes, like - * 2011-12-12'T'00:00:00+00:00 - * - * @author Richard Downer - */ -public class CloudStackDateAdapter extends Iso8601DateAdapter { - - @Inject - private CloudStackDateAdapter(DateService dateService) { - super(dateService); - } - - public Date read(JsonReader reader) throws IOException { - return parseDate(reader.nextString().replaceAll("'T'", "T")); - } - -} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackParserModule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackParserModule.java new file mode 100644 index 0000000000..086529fc30 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackParserModule.java @@ -0,0 +1,115 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.config; + +import java.io.IOException; +import java.util.Date; + +import javax.inject.Inject; + +import org.jclouds.date.DateService; +import org.jclouds.json.config.GsonModule.DateAdapter; +import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import org.jclouds.json.internal.IgnoreNullIterableTypeAdapterFactory; + +import com.google.common.base.Splitter; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; +import com.google.common.collect.ImmutableSet; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; +import com.google.inject.AbstractModule; + +/** + * @author Adrian Cole + */ +public class CloudStackParserModule extends AbstractModule { + + @Override + protected void configure() { + bind(DateAdapter.class).to(CloudStackDateAdapter.class); + bind(IgnoreNullIterableTypeAdapterFactory.class).to(CommaDelimitedOKIgnoreNullIterableTypeAdapterFactory.class); + } + + /** + * Data adapter for the date formats used by CloudStack. + * + * Essentially this is a workaround for the CloudStack getUsage() API call returning a corrupted + * form of ISO-8601 dates, which have an unexpected pair of apostrophes, like + * 2011-12-12'T'00:00:00+00:00 + * + * @author Richard Downer + */ + public static class CloudStackDateAdapter extends Iso8601DateAdapter { + + @Inject + private CloudStackDateAdapter(DateService dateService) { + super(dateService); + } + + public Date read(JsonReader reader) throws IOException { + return parseDate(reader.nextString().replaceAll("'T'", "T")); + } + + } + + /** + * Handles types that were previously strings and now arrays (ex. tags) + * + * @author Adrian Cole + */ + public static class CommaDelimitedOKIgnoreNullIterableTypeAdapterFactory extends IgnoreNullIterableTypeAdapterFactory { + + @Override + protected TypeAdapter> newIterableAdapter(final TypeAdapter elementAdapter) { + return new TypeAdapter>() { + public void write(JsonWriter out, Iterable value) throws IOException { + out.beginArray(); + for (E element : value) { + elementAdapter.write(out, element); + } + out.endArray(); + } + + @SuppressWarnings("unchecked") + public Iterable read(JsonReader in) throws IOException { + // HACK as cloudstack changed a field from String to Set! + if (in.peek() == JsonToken.STRING) { + String val = Strings.emptyToNull(in.nextString()); + return (Iterable) (val != null ? Splitter.on(',').split(val) : ImmutableSet.of()); + } else { + Builder builder = ImmutableList. builder(); + in.beginArray(); + while (in.hasNext()) { + E element = elementAdapter.read(in); + if (element != null) + builder.add(element); + } + in.endArray(); + return builder.build(); + } + } + }.nullSafe(); + } + } + +} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java index 695d72864c..cbdb216c61 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java @@ -33,7 +33,86 @@ import org.jclouds.cloudstack.CloudStackDomainClient; import org.jclouds.cloudstack.CloudStackGlobalAsyncClient; import org.jclouds.cloudstack.CloudStackGlobalClient; import org.jclouds.cloudstack.domain.LoginResponse; -import org.jclouds.cloudstack.features.*; +import org.jclouds.cloudstack.features.AccountAsyncClient; +import org.jclouds.cloudstack.features.AccountClient; +import org.jclouds.cloudstack.features.AddressAsyncClient; +import org.jclouds.cloudstack.features.AddressClient; +import org.jclouds.cloudstack.features.AsyncJobAsyncClient; +import org.jclouds.cloudstack.features.AsyncJobClient; +import org.jclouds.cloudstack.features.ConfigurationAsyncClient; +import org.jclouds.cloudstack.features.ConfigurationClient; +import org.jclouds.cloudstack.features.DomainAccountAsyncClient; +import org.jclouds.cloudstack.features.DomainAccountClient; +import org.jclouds.cloudstack.features.DomainDomainAsyncClient; +import org.jclouds.cloudstack.features.DomainDomainClient; +import org.jclouds.cloudstack.features.DomainLimitAsyncClient; +import org.jclouds.cloudstack.features.DomainLimitClient; +import org.jclouds.cloudstack.features.DomainUserAsyncClient; +import org.jclouds.cloudstack.features.DomainUserClient; +import org.jclouds.cloudstack.features.EventAsyncClient; +import org.jclouds.cloudstack.features.EventClient; +import org.jclouds.cloudstack.features.FirewallAsyncClient; +import org.jclouds.cloudstack.features.FirewallClient; +import org.jclouds.cloudstack.features.GlobalAccountAsyncClient; +import org.jclouds.cloudstack.features.GlobalAccountClient; +import org.jclouds.cloudstack.features.GlobalAlertAsyncClient; +import org.jclouds.cloudstack.features.GlobalAlertClient; +import org.jclouds.cloudstack.features.GlobalCapacityAsyncClient; +import org.jclouds.cloudstack.features.GlobalCapacityClient; +import org.jclouds.cloudstack.features.GlobalConfigurationAsyncClient; +import org.jclouds.cloudstack.features.GlobalConfigurationClient; +import org.jclouds.cloudstack.features.GlobalDomainAsyncClient; +import org.jclouds.cloudstack.features.GlobalDomainClient; +import org.jclouds.cloudstack.features.GlobalHostAsyncClient; +import org.jclouds.cloudstack.features.GlobalHostClient; +import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient; +import org.jclouds.cloudstack.features.GlobalOfferingClient; +import org.jclouds.cloudstack.features.GlobalPodAsyncClient; +import org.jclouds.cloudstack.features.GlobalPodClient; +import org.jclouds.cloudstack.features.GlobalStoragePoolAsyncClient; +import org.jclouds.cloudstack.features.GlobalStoragePoolClient; +import org.jclouds.cloudstack.features.GlobalUsageAsyncClient; +import org.jclouds.cloudstack.features.GlobalUsageClient; +import org.jclouds.cloudstack.features.GlobalUserAsyncClient; +import org.jclouds.cloudstack.features.GlobalUserClient; +import org.jclouds.cloudstack.features.GlobalVlanAsyncClient; +import org.jclouds.cloudstack.features.GlobalVlanClient; +import org.jclouds.cloudstack.features.GlobalZoneAsyncClient; +import org.jclouds.cloudstack.features.GlobalZoneClient; +import org.jclouds.cloudstack.features.GuestOSAsyncClient; +import org.jclouds.cloudstack.features.GuestOSClient; +import org.jclouds.cloudstack.features.HypervisorAsyncClient; +import org.jclouds.cloudstack.features.HypervisorClient; +import org.jclouds.cloudstack.features.ISOAsyncClient; +import org.jclouds.cloudstack.features.ISOClient; +import org.jclouds.cloudstack.features.LimitAsyncClient; +import org.jclouds.cloudstack.features.LimitClient; +import org.jclouds.cloudstack.features.LoadBalancerAsyncClient; +import org.jclouds.cloudstack.features.LoadBalancerClient; +import org.jclouds.cloudstack.features.NATAsyncClient; +import org.jclouds.cloudstack.features.NATClient; +import org.jclouds.cloudstack.features.NetworkAsyncClient; +import org.jclouds.cloudstack.features.NetworkClient; +import org.jclouds.cloudstack.features.OfferingAsyncClient; +import org.jclouds.cloudstack.features.OfferingClient; +import org.jclouds.cloudstack.features.SSHKeyPairAsyncClient; +import org.jclouds.cloudstack.features.SSHKeyPairClient; +import org.jclouds.cloudstack.features.SecurityGroupAsyncClient; +import org.jclouds.cloudstack.features.SecurityGroupClient; +import org.jclouds.cloudstack.features.SessionAsyncClient; +import org.jclouds.cloudstack.features.SessionClient; +import org.jclouds.cloudstack.features.SnapshotAsyncClient; +import org.jclouds.cloudstack.features.SnapshotClient; +import org.jclouds.cloudstack.features.TemplateAsyncClient; +import org.jclouds.cloudstack.features.TemplateClient; +import org.jclouds.cloudstack.features.VMGroupAsyncClient; +import org.jclouds.cloudstack.features.VMGroupClient; +import org.jclouds.cloudstack.features.VirtualMachineAsyncClient; +import org.jclouds.cloudstack.features.VirtualMachineClient; +import org.jclouds.cloudstack.features.VolumeAsyncClient; +import org.jclouds.cloudstack.features.VolumeClient; +import org.jclouds.cloudstack.features.ZoneAsyncClient; +import org.jclouds.cloudstack.features.ZoneClient; import org.jclouds.cloudstack.filters.AddSessionKeyAndJSessionIdToRequest; import org.jclouds.cloudstack.filters.AuthenticationFilter; import org.jclouds.cloudstack.filters.QuerySigner; @@ -47,7 +126,6 @@ import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; -import org.jclouds.json.config.GsonModule.DateAdapter; import org.jclouds.location.Provider; import org.jclouds.location.suppliers.ImplicitLocationSupplier; import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone; @@ -147,7 +225,6 @@ public class CloudStackRestClientModule extends RestClientModule>() { }).to(new TypeLiteral>() { }); diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java index ba0a5874ed..97632e4e6e 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/DiskOffering.java @@ -22,11 +22,13 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Date; +import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** * Class DiskOffering @@ -54,7 +56,7 @@ public class DiskOffering implements Comparable { protected String domainId; protected int diskSize; protected boolean customized; - protected String tags; + protected ImmutableSet.Builder tags = ImmutableSet.builder(); /** * @see DiskOffering#getId() @@ -123,13 +125,21 @@ public class DiskOffering implements Comparable { /** * @see DiskOffering#getTags() */ - public T tags(String tags) { - this.tags = tags; + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); return self(); } - + + /** + * @see DiskOffering#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); + return self(); + } + public DiskOffering build() { - return new DiskOffering(id, name, displayText, created, domain, domainId, diskSize, customized, tags); + return new DiskOffering(id, name, displayText, created, domain, domainId, diskSize, customized, tags.build()); } public T fromDiskOffering(DiskOffering in) { @@ -161,14 +171,14 @@ public class DiskOffering implements Comparable { private final String domainId; private final int diskSize; private final boolean customized; - private final String tags; + private final Set tags; @ConstructorProperties({ "id", "name", "displaytext", "created", "domain", "domainid", "disksize", "iscustomized", "tags" }) protected DiskOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, @Nullable String domain, @Nullable String domainId, int diskSize, boolean customized, - @Nullable String tags) { + @Nullable Iterable tags) { this.id = checkNotNull(id, "id"); this.name = name; this.displayText = displayText; @@ -177,7 +187,7 @@ public class DiskOffering implements Comparable { this.domainId = domainId; this.diskSize = diskSize; this.customized = customized; - this.tags = tags; + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); } /** @@ -244,8 +254,7 @@ public class DiskOffering implements Comparable { /** * @return the tags for the disk offering */ - @Nullable - public String getTags() { + public Set getTags() { return this.tags; } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java index 7d9ea4a982..1cd4c6e15b 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Host.java @@ -24,11 +24,13 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Date; +import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** * Represents a host issued by Cloudstack @@ -149,7 +151,7 @@ public class Host implements Comparable { protected long diskSizeTotal; protected String events; protected boolean hasEnoughCapacity; - protected String hostTags; + protected ImmutableSet.Builder tags = ImmutableSet.builder(); protected String hypervisor; protected String ipAddress; protected boolean localStorageActive; @@ -319,13 +321,21 @@ public class Host implements Comparable { } /** - * @see Host#getHostTags() + * @see Host#getTags() */ - public T hostTags(String hostTags) { - this.hostTags = hostTags; + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); return self(); } - + + /** + * @see Host#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); + return self(); + } + /** * @see Host#getHypervisor() */ @@ -512,7 +522,7 @@ public class Host implements Comparable { public Host build() { - return new Host(id, allocationState, averageLoad, capabilities, clusterId, clusterName, clusterType, cpuAllocated, cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, created, disconnected, diskSizeAllocated, diskSizeTotal, events, hasEnoughCapacity, hostTags, hypervisor, ipAddress, localStorageActive, jobId, jobStatus, lastPinged, managementServerId, memoryAllocated, memoryTotal, memoryUsed, name, networkKbsRead, networkKbsWrite, osCategoryId, osCategoryName, podId, podName, removed, state, type, version, zoneId, zoneName); + return new Host(id, allocationState, averageLoad, capabilities, clusterId, clusterName, clusterType, cpuAllocated, cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, created, disconnected, diskSizeAllocated, diskSizeTotal, events, hasEnoughCapacity, tags.build(), hypervisor, ipAddress, localStorageActive, jobId, jobStatus, lastPinged, managementServerId, memoryAllocated, memoryTotal, memoryUsed, name, networkKbsRead, networkKbsWrite, osCategoryId, osCategoryName, podId, podName, removed, state, type, version, zoneId, zoneName); } public T fromHost(Host in) { @@ -535,7 +545,7 @@ public class Host implements Comparable { .diskSizeTotal(in.getDiskSizeTotal()) .events(in.getEvents()) .hasEnoughCapacity(in.isHasEnoughCapacity()) - .hostTags(in.getHostTags()) + .tags(in.getTags()) .hypervisor(in.getHypervisor()) .ipAddress(in.getIpAddress()) .localStorageActive(in.isLocalStorageActive()) @@ -587,7 +597,7 @@ public class Host implements Comparable { private final long diskSizeTotal; private final String events; private final boolean hasEnoughCapacity; - private final String hostTags; + private final Set tags; private final String hypervisor; private final String ipAddress; private final boolean localStorageActive; @@ -619,7 +629,7 @@ public class Host implements Comparable { @Nullable String clusterId, @Nullable String clusterName, @Nullable Host.ClusterType clusterType, @Nullable String cpuAllocated, int cpuNumber, int cpuSpeed, @Nullable String cpuUsed, float cpuWithOverProvisioning, @Nullable Date created, @Nullable Date disconnected, long diskSizeAllocated, - long diskSizeTotal, @Nullable String events, boolean hasEnoughCapacity, @Nullable String hostTags, + long diskSizeTotal, @Nullable String events, boolean hasEnoughCapacity, @Nullable Iterable tags, @Nullable String hypervisor, @Nullable String ipAddress, boolean localStorageActive, @Nullable String jobId, @Nullable AsyncJob.Status jobStatus, @Nullable Date lastPinged, @Nullable String managementServerId, long memoryAllocated, long memoryTotal, long memoryUsed, @Nullable String name, long networkKbsRead, long networkKbsWrite, @@ -644,7 +654,7 @@ public class Host implements Comparable { this.diskSizeTotal = diskSizeTotal; this.events = events; this.hasEnoughCapacity = hasEnoughCapacity; - this.hostTags = hostTags; + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); this.hypervisor = hypervisor; this.ipAddress = ipAddress; this.localStorageActive = localStorageActive; @@ -752,11 +762,14 @@ public class Host implements Comparable { return this.hasEnoughCapacity; } - @Nullable - public String getHostTags() { - return this.hostTags; + /** + * @return the tags for the host + */ + public Set getTags() { + return this.tags; } + @Nullable public String getHypervisor() { return this.hypervisor; @@ -868,7 +881,7 @@ public class Host implements Comparable { @Override public int hashCode() { - return Objects.hashCode(id, allocationState, averageLoad, capabilities, clusterId, clusterName, clusterType, cpuAllocated, cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, created, disconnected, diskSizeAllocated, diskSizeTotal, events, hasEnoughCapacity, hostTags, hypervisor, ipAddress, localStorageActive, jobId, jobStatus, lastPinged, managementServerId, memoryAllocated, memoryTotal, memoryUsed, name, networkKbsRead, networkKbsWrite, osCategoryId, osCategoryName, podId, podName, removed, state, type, version, zoneId, zoneName); + return Objects.hashCode(id, allocationState, averageLoad, capabilities, clusterId, clusterName, clusterType, cpuAllocated, cpuNumber, cpuSpeed, cpuUsed, cpuWithOverProvisioning, created, disconnected, diskSizeAllocated, diskSizeTotal, events, hasEnoughCapacity, tags, hypervisor, ipAddress, localStorageActive, jobId, jobStatus, lastPinged, managementServerId, memoryAllocated, memoryTotal, memoryUsed, name, networkKbsRead, networkKbsWrite, osCategoryId, osCategoryName, podId, podName, removed, state, type, version, zoneId, zoneName); } @Override @@ -894,7 +907,7 @@ public class Host implements Comparable { && Objects.equal(this.diskSizeTotal, that.diskSizeTotal) && Objects.equal(this.events, that.events) && Objects.equal(this.hasEnoughCapacity, that.hasEnoughCapacity) - && Objects.equal(this.hostTags, that.hostTags) + && Objects.equal(this.tags, that.tags) && Objects.equal(this.hypervisor, that.hypervisor) && Objects.equal(this.ipAddress, that.ipAddress) && Objects.equal(this.localStorageActive, that.localStorageActive) @@ -928,7 +941,7 @@ public class Host implements Comparable { .add("cpuSpeed", cpuSpeed).add("cpuUsed", cpuUsed).add("cpuWithOverProvisioning", cpuWithOverProvisioning) .add("created", created).add("disconnected", disconnected).add("diskSizeAllocated", diskSizeAllocated) .add("diskSizeTotal", diskSizeTotal).add("events", events).add("hasEnoughCapacity", hasEnoughCapacity) - .add("hostTags", hostTags).add("hypervisor", hypervisor).add("ipAddress", ipAddress) + .add("tags", tags).add("hypervisor", hypervisor).add("ipAddress", ipAddress) .add("localStorageActive", localStorageActive).add("jobId", jobId).add("jobStatus", jobStatus) .add("lastPinged", lastPinged).add("managementServerId", managementServerId).add("memoryAllocated", memoryAllocated) .add("memoryTotal", memoryTotal).add("memoryUsed", memoryUsed).add("name", name).add("networkKbsRead", networkKbsRead) diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java index 457edd049c..08dd4501d9 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Network.java @@ -30,6 +30,7 @@ import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; /** @@ -78,7 +79,7 @@ public class Network { protected String VLAN; protected TrafficType trafficType; protected String zoneId; - protected String tags; + protected ImmutableSet.Builder tags = ImmutableSet.builder(); protected boolean securityGroupEnabled; protected Set services = ImmutableSortedSet.of(); @@ -302,10 +303,19 @@ public class Network { /** * @see Network#getTags() */ - public T tags(String tags) { - this.tags = tags; + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); return self(); } + + /** + * @see Network#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); + return self(); + } + /** * @see Network#isSecurityGroupEnabled() @@ -324,7 +334,7 @@ public class Network { } public Network build() { - return new Network(id, account, broadcastDomainType, broadcastURI, displayText, DNS1, DNS2, domain, domainId, endIP, gateway, isDefault, isShared, isSystem, netmask, networkDomain, networkOfferingAvailability, networkOfferingDisplayText, networkOfferingId, networkOfferingName, related, startIP, name, state, guestIPType, VLAN, trafficType, zoneId, tags, securityGroupEnabled, services); + return new Network(id, account, broadcastDomainType, broadcastURI, displayText, DNS1, DNS2, domain, domainId, endIP, gateway, isDefault, isShared, isSystem, netmask, networkDomain, networkOfferingAvailability, networkOfferingDisplayText, networkOfferingId, networkOfferingName, related, startIP, name, state, guestIPType, VLAN, trafficType, zoneId, tags.build(), securityGroupEnabled, services); } public T fromNetwork(Network in) { @@ -397,7 +407,7 @@ public class Network { private final String VLAN; private final TrafficType trafficType; private final String zoneId; - private final String tags; + private final Set tags; private final boolean securityGroupEnabled; private final Set services; @@ -411,7 +421,7 @@ public class Network { @Nullable String networkOfferingDisplayText, @Nullable String networkOfferingId, @Nullable String networkOfferingName, @Nullable String related, @Nullable String startIP, @Nullable String name, @Nullable String state, @Nullable GuestIPType guestIPType, @Nullable String VLAN, @Nullable TrafficType trafficType, - @Nullable String zoneId, @Nullable String tags, boolean securityGroupEnabled, Set services) { + @Nullable String zoneId, @Nullable Iterable tags, boolean securityGroupEnabled, Set services) { this.id = checkNotNull(id, "id"); this.account = account; this.broadcastDomainType = broadcastDomainType; @@ -440,7 +450,7 @@ public class Network { this.VLAN = VLAN; this.trafficType = trafficType; this.zoneId = zoneId; - this.tags = tags; + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); this.securityGroupEnabled = securityGroupEnabled; this.services = ImmutableSortedSet.copyOf(services); } @@ -660,8 +670,7 @@ public class Network { /** * @return the tags for the Network */ - @Nullable - public String getTags() { + public Set getTags() { return this.tags; } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java index 876b5245d6..1ec0a857a9 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NetworkOffering.java @@ -22,11 +22,13 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Date; +import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** * Class NetworkOffering @@ -57,7 +59,7 @@ public class NetworkOffering implements Comparable { protected TrafficType trafficType; protected GuestIPType guestIPType; protected int networkRate; - protected String tags; + protected ImmutableSet.Builder tags = ImmutableSet.builder(); /** * @see NetworkOffering#getId() @@ -146,17 +148,26 @@ public class NetworkOffering implements Comparable { this.networkRate = networkRate; return self(); } - + /** * @see NetworkOffering#getTags() */ - public T tags(String tags) { - this.tags = tags; + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); return self(); } + + /** + * @see NetworkOffering#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); + return self(); + } + public NetworkOffering build() { - return new NetworkOffering(id, name, displayText, created, availability, maxConnections, isDefault, supportsVLAN, trafficType, guestIPType, networkRate, tags); + return new NetworkOffering(id, name, displayText, created, availability, maxConnections, isDefault, supportsVLAN, trafficType, guestIPType, networkRate, tags.build()); } public T fromNetworkOffering(NetworkOffering in) { @@ -194,12 +205,12 @@ public class NetworkOffering implements Comparable { private final TrafficType trafficType; private final GuestIPType guestIPType; private final int networkRate; - private final String tags; + private final Set tags; @ConstructorProperties({ "id", "name", "displaytext", "created", "availability", "maxconnections", "isdefault", "specifyvlan", "traffictype", "guestiptype", "networkrate", "tags" }) - protected NetworkOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, @Nullable NetworkOfferingAvailabilityType availability, @Nullable Integer maxConnections, boolean isDefault, boolean supportsVLAN, @Nullable TrafficType trafficType, @Nullable GuestIPType guestIPType, int networkRate, @Nullable String tags) { + protected NetworkOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, @Nullable NetworkOfferingAvailabilityType availability, @Nullable Integer maxConnections, boolean isDefault, boolean supportsVLAN, @Nullable TrafficType trafficType, @Nullable GuestIPType guestIPType, int networkRate, @Nullable Iterable tags) { this.id = checkNotNull(id, "id"); this.name = name; this.displayText = displayText; @@ -211,7 +222,7 @@ public class NetworkOffering implements Comparable { this.trafficType = trafficType; this.guestIPType = guestIPType; this.networkRate = networkRate; - this.tags = tags; + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); } /** @@ -302,8 +313,7 @@ public class NetworkOffering implements Comparable { /** * @return the tags for the network offering */ - @Nullable - public String getTags() { + public Set getTags() { return this.tags; } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java index b5bd47f365..e472da73c3 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/ServiceOffering.java @@ -26,11 +26,8 @@ import java.util.Set; import org.jclouds.javax.annotation.Nullable; -import com.google.common.base.Joiner; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.base.Splitter; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; /** @@ -63,12 +60,11 @@ public class ServiceOffering implements Comparable { protected boolean haSupport; protected StorageType storageType; protected boolean defaultUse; - protected String hostTags; protected boolean systemOffering; protected boolean cpuUseLimited; protected long networkRate; protected boolean systemVmType; - private Set tags = ImmutableSet.of(); + protected ImmutableSet.Builder tags = ImmutableSet.builder(); /** * @see ServiceOffering#getId() @@ -161,11 +157,19 @@ public class ServiceOffering implements Comparable { /** * @see ServiceOffering#getTags() */ - public T tags(Set tags) { - this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags")); + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); return self(); } - + + /** + * @see ServiceOffering#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); + return self(); + } + /** * @see ServiceOffering#isDefaultUse() */ @@ -174,14 +178,6 @@ public class ServiceOffering implements Comparable { return self(); } - /** - * @see ServiceOffering#getHostTags() - */ - public T hostTags(String hostTags) { - this.hostTags = hostTags; - return self(); - } - /** * @see ServiceOffering#isSystemOffering() */ @@ -216,7 +212,7 @@ public class ServiceOffering implements Comparable { public ServiceOffering build() { return new ServiceOffering(id, name, displayText, created, domain, domainId, cpuNumber, cpuSpeed, memory, haSupport, storageType, - Joiner.on(",").join(tags), defaultUse, hostTags, systemOffering, cpuUseLimited, networkRate, systemVmType); + tags.build(), defaultUse, systemOffering, cpuUseLimited, networkRate, systemVmType); } public T fromServiceOffering(ServiceOffering in) { @@ -234,7 +230,6 @@ public class ServiceOffering implements Comparable { .storageType(in.getStorageType()) .tags(in.getTags()) .defaultUse(in.isDefaultUse()) - .hostTags(in.getHostTags()) .systemOffering(in.isSystemOffering()) .cpuUseLimited(in.isCpuUseLimited()) .networkRate(in.getNetworkRate()) @@ -262,19 +257,18 @@ public class ServiceOffering implements Comparable { private final StorageType storageType; private final Set tags; private final boolean defaultUse; - private final String hostTags; private final boolean systemOffering; private final boolean cpuUseLimited; private final long networkRate; private final boolean systemVmType; @ConstructorProperties({ - "id", "name", "displaytext", "created", "domain", "domainid", "cpunumber", "cpuspeed", "memory", "offerha", "storagetype", "tags", "defaultuse", "hosttags", "issystem", "limitcpuuse", "networkrate", "systemvmtype" + "id", "name", "displaytext", "created", "domain", "domainid", "cpunumber", "cpuspeed", "memory", "offerha", "storagetype", "tags", "defaultuse", "issystem", "limitcpuuse", "networkrate", "systemvmtype" }) protected ServiceOffering(String id, @Nullable String name, @Nullable String displayText, @Nullable Date created, @Nullable String domain, @Nullable String domainId, int cpuNumber, int cpuSpeed, int memory, - boolean haSupport, @Nullable StorageType storageType, @Nullable String tags, boolean defaultUse, - @Nullable String hostTags, boolean systemOffering, boolean cpuUseLimited, long networkRate, boolean systemVmType) { + boolean haSupport, @Nullable StorageType storageType, @Nullable Iterable tags, boolean defaultUse, + boolean systemOffering, boolean cpuUseLimited, long networkRate, boolean systemVmType) { this.id = checkNotNull(id, "id"); this.name = name; this.displayText = displayText; @@ -286,10 +280,8 @@ public class ServiceOffering implements Comparable { this.memory = memory; this.haSupport = haSupport; this.storageType = storageType; - this.tags = !(Strings.emptyToNull(tags) == null) ? ImmutableSet.copyOf(Splitter.on(',').split(tags)) - : ImmutableSet. of(); + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); this.defaultUse = defaultUse; - this.hostTags = hostTags; this.systemOffering = systemOffering; this.cpuUseLimited = cpuUseLimited; this.networkRate = networkRate; @@ -389,14 +381,6 @@ public class ServiceOffering implements Comparable { return this.defaultUse; } - /** - * @return the host tag for the service offering - */ - @Nullable - public String getHostTags() { - return this.hostTags; - } - /** * @return whether this is a system vm offering */ @@ -427,7 +411,7 @@ public class ServiceOffering implements Comparable { @Override public int hashCode() { - return Objects.hashCode(id, name, displayText, created, domain, domainId, cpuNumber, cpuSpeed, memory, haSupport, storageType, tags, defaultUse, hostTags, systemOffering, cpuUseLimited, networkRate, systemVmType); + return Objects.hashCode(id, name, displayText, created, domain, domainId, cpuNumber, cpuSpeed, memory, haSupport, storageType, tags, defaultUse, systemOffering, cpuUseLimited, networkRate, systemVmType); } @Override @@ -448,7 +432,6 @@ public class ServiceOffering implements Comparable { && Objects.equal(this.storageType, that.storageType) && Objects.equal(this.getTags(), that.getTags()) && Objects.equal(this.defaultUse, that.defaultUse) - && Objects.equal(this.hostTags, that.hostTags) && Objects.equal(this.systemOffering, that.systemOffering) && Objects.equal(this.cpuUseLimited, that.cpuUseLimited) && Objects.equal(this.networkRate, that.networkRate) @@ -460,7 +443,7 @@ public class ServiceOffering implements Comparable { .add("id", id).add("name", name).add("displayText", displayText).add("created", created).add("domain", domain) .add("domainId", domainId).add("cpuNumber", cpuNumber).add("cpuSpeed", cpuSpeed).add("memory", memory) .add("haSupport", haSupport).add("storageType", storageType).add("tags", getTags()).add("defaultUse", defaultUse) - .add("hostTags", hostTags).add("systemOffering", systemOffering).add("cpuUseLimited", cpuUseLimited) + .add("systemOffering", systemOffering).add("cpuUseLimited", cpuUseLimited) .add("networkRate", networkRate).add("systemVmType", systemVmType); } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java index 5416c07c24..5c9a32775b 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/StoragePool.java @@ -22,12 +22,14 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.Date; +import java.util.Set; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.CaseFormat; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableSet; /** * Represents a storage pool in CloudStack @@ -102,7 +104,7 @@ public class StoragePool implements Comparable { protected String id; protected String name; protected String path; - protected String tags; + protected ImmutableSet.Builder tags = ImmutableSet.builder(); protected StoragePool.State state; protected StoragePool.Type type; protected String zoneId; @@ -143,10 +145,18 @@ public class StoragePool implements Comparable { } /** - * @see StoragePool#getTags() + * @see DiskOffering#getTags() */ - public T tags(String tags) { - this.tags = tags; + public T tags(Iterable tags) { + this.tags = ImmutableSet.builder().addAll(tags); + return self(); + } + + /** + * @see DiskOffering#getTags() + */ + public T tag(String tag) { + this.tags.add(tag); return self(); } @@ -263,7 +273,7 @@ public class StoragePool implements Comparable { } public StoragePool build() { - return new StoragePool(id, name, path, tags, state, type, zoneId, zoneName, podId, podName, clusterId, clusterName, created, diskSizeAllocated, diskSizeTotal, ipAddress, jobId, jobStatus); + return new StoragePool(id, name, path, tags.build(), state, type, zoneId, zoneName, podId, podName, clusterId, clusterName, created, diskSizeAllocated, diskSizeTotal, ipAddress, jobId, jobStatus); } public T fromStoragePool(StoragePool in) { @@ -299,7 +309,7 @@ public class StoragePool implements Comparable { private final String id; private final String name; private final String path; - private final String tags; + private final Set tags; private final StoragePool.State state; private final StoragePool.Type type; private final String zoneId; @@ -318,11 +328,15 @@ public class StoragePool implements Comparable { @ConstructorProperties({ "id", "name", "path", "tags", "state", "type", "zoneid", "zonename", "podid", "podname", "clusterid", "clustername", "created", "disksizeallocated", "disksizetotal", "ipaddress", "jobid", "jobstatus" }) - protected StoragePool(String id, @Nullable String name, @Nullable String path, @Nullable String tags, @Nullable StoragePool.State state, @Nullable StoragePool.Type type, @Nullable String zoneId, @Nullable String zoneName, @Nullable String podId, @Nullable String podName, @Nullable String clusterId, @Nullable String clusterName, @Nullable Date created, long diskSizeAllocated, long diskSizeTotal, @Nullable String ipAddress, @Nullable String jobId, @Nullable String jobStatus) { + protected StoragePool(String id, @Nullable String name, @Nullable String path, @Nullable Iterable tags, + @Nullable StoragePool.State state, @Nullable StoragePool.Type type, @Nullable String zoneId, + @Nullable String zoneName, @Nullable String podId, @Nullable String podName, @Nullable String clusterId, + @Nullable String clusterName, @Nullable Date created, long diskSizeAllocated, long diskSizeTotal, + @Nullable String ipAddress, @Nullable String jobId, @Nullable String jobStatus) { this.id = checkNotNull(id, "id"); this.name = name; this.path = path; - this.tags = tags; + this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet. of(); this.state = state; this.type = type; this.zoneId = zoneId; @@ -353,8 +367,7 @@ public class StoragePool implements Comparable { return this.path; } - @Nullable - public String getTags() { + public Set getTags() { return this.tags; } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java index 26c96b0ac6..1f17abdf83 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java @@ -65,7 +65,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00"); - Host host1 = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); + Host host1 = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00"); lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "GMT+02:00"); @@ -109,7 +109,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00"); - Host expected = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); + Host expected = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); Host actual = requestSendsResponse(request, response).addHost("1", "http://example.com", "XenServer", "fred", "sekrit", AddHostOptions.Builder.hostTags(Collections.emptySet()).allocationState(AllocationState.ENABLED).clusterId("1").clusterName("Xen Clust 1").podId("1")); @@ -129,7 +129,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTe Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00"); Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00"); - Host expected = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); + Host expected = Host.builder().id("1").name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId("1").zoneName("Dev Zone 1").podId("1").podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId("223098941760041").clusterId("1").clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build(); Host actual = requestSendsResponse(request, response).updateHost("1", UpdateHostOptions.Builder.allocationState(AllocationState.ENABLED).hostTags(Collections.emptySet()).osCategoryId("5")); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHostsResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHostsResponseTest.java index b857fd6e83..60f909659e 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHostsResponseTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHostsResponseTest.java @@ -22,17 +22,16 @@ import static org.testng.Assert.assertEquals; import java.util.Set; +import org.jclouds.cloudstack.config.CloudStackParserModule; import org.jclouds.cloudstack.domain.AllocationState; import org.jclouds.cloudstack.domain.Host; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.json.BaseParserTest; -import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; import com.google.inject.Guice; import com.google.inject.Injector; @@ -48,16 +47,7 @@ public class ListHostsResponseTest extends BaseParserTest, Set> @Override protected Injector injector() { - return Guice.createInjector(new GsonModule() { - - @Override - protected void configure() { - bind(DateAdapter.class).to(Iso8601DateAdapter.class); - super.configure(); - } - - }); - + return Guice.createInjector(new GsonModule(), new CloudStackParserModule()); } @Override @@ -102,7 +92,6 @@ public class ListHostsResponseTest extends BaseParserTest, Set> .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-11-26T23:28:36+0200")) .events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; " + "AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping") - .hostTags("") .hasEnoughCapacity(false) .allocationState(AllocationState.ENABLED).build(), diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java index 2c4f85dcd4..661afca398 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListStoragePoolsResponseTest.java @@ -23,18 +23,22 @@ import java.util.Date; import java.util.Set; import java.util.TimeZone; +import org.jclouds.cloudstack.config.CloudStackParserModule; import org.jclouds.cloudstack.domain.StoragePool; import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; /** * * @author Richard Downer */ -@Test(groups = "unit") +@Test(groups = "unit", testName = "ListStoragePoolsResponseTest") public class ListStoragePoolsResponseTest extends BaseItemParserTest> { @Override @@ -54,7 +58,16 @@ public class ListStoragePoolsResponseTest extends BaseItemParserTest .templateId("0").id("203").startDate(start).endDate(end).build()); } - + @Override protected Injector injector() { - return Guice.createInjector(new GsonModule() { - - @Override - protected void configure() { - bind(DateAdapter.class).to(CloudStackDateAdapter.class); - super.configure(); - } - - }); + return Guice.createInjector(new GsonModule(), new CloudStackParserModule()); } + } diff --git a/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json b/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json index deca7a28c7..dc3ae46444 100644 --- a/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json +++ b/apis/cloudstack/src/test/resources/liststoragepoolsresponse.json @@ -1 +1 @@ -{ "liststoragepoolsresponse" : { "count":1 ,"storagepool" : [ {"id":201,"zoneid":1,"zonename":"Dev Zone 1","podid":1,"podname":"Dev Pod 1","name":"NFS Pri 1","ipaddress":"10.26.26.165","path":"/mnt/nfs/cs_pri","created":"2011-11-26T23:33:06+0200","type":"NetworkFilesystem","clusterid":1,"clustername":"Xen Clust 1","disksizetotal":898356445184,"disksizeallocated":18276679680,"tags":"","state":"Up"} ] } } \ No newline at end of file +{ "liststoragepoolsresponse" : { "count":1 ,"storagepool" : [ {"id":201,"zoneid":1,"zonename":"Dev Zone 1","podid":1,"podname":"Dev Pod 1","name":"NFS Pri 1","ipaddress":"10.26.26.165","path":"/mnt/nfs/cs_pri","created":"2011-11-26T23:33:06+0200","type":"NetworkFilesystem","clusterid":1,"clustername":"Xen Clust 1","disksizetotal":898356445184,"disksizeallocated":18276679680,"tags":"tag1","state":"Up"} ] } } \ No newline at end of file