compatible tags across 2.0 and 4.0

This commit is contained in:
Adrian Cole 2012-09-16 23:39:26 -07:00
parent 0be04f7952
commit bff49f8311
15 changed files with 353 additions and 176 deletions

View File

@ -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.<Class<? extends Module>>of(CloudStackRestClientModule.class, CloudStackComputeServiceContextModule.class));
.defaultModules(ImmutableSet.<Class<? extends Module>> builder()
.add(CloudStackParserModule.class)
.add(CloudStackRestClientModule.class)
.add(CloudStackComputeServiceContextModule.class).build());
}
@Override

View File

@ -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"));
}
}

View File

@ -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 <E> TypeAdapter<Iterable<E>> newIterableAdapter(final TypeAdapter<E> elementAdapter) {
return new TypeAdapter<Iterable<E>>() {
public void write(JsonWriter out, Iterable<E> value) throws IOException {
out.beginArray();
for (E element : value) {
elementAdapter.write(out, element);
}
out.endArray();
}
@SuppressWarnings("unchecked")
public Iterable<E> 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<E>) (val != null ? Splitter.on(',').split(val) : ImmutableSet.of());
} else {
Builder<E> builder = ImmutableList.<E> builder();
in.beginArray();
while (in.hasNext()) {
E element = elementAdapter.read(in);
if (element != null)
builder.add(element);
}
in.endArray();
return builder.build();
}
}
}.nullSafe();
}
}
}

View File

@ -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<CloudStackClien
@Override
protected void configure() {
bind(DateAdapter.class).to(CloudStackDateAdapter.class);
bind(new TypeLiteral<RestContext<CloudStackDomainClient, CloudStackDomainAsyncClient>>() {
}).to(new TypeLiteral<RestContextImpl<CloudStackDomainClient, CloudStackDomainAsyncClient>>() {
});

View File

@ -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<DiskOffering> {
protected String domainId;
protected int diskSize;
protected boolean customized;
protected String tags;
protected ImmutableSet.Builder<String> tags = ImmutableSet.<String>builder();
/**
* @see DiskOffering#getId()
@ -123,13 +125,21 @@ public class DiskOffering implements Comparable<DiskOffering> {
/**
* @see DiskOffering#getTags()
*/
public T tags(String tags) {
this.tags = tags;
public T tags(Iterable<String> tags) {
this.tags = ImmutableSet.<String>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<DiskOffering> {
private final String domainId;
private final int diskSize;
private final boolean customized;
private final String tags;
private final Set<String> 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<String> tags) {
this.id = checkNotNull(id, "id");
this.name = name;
this.displayText = displayText;
@ -177,7 +187,7 @@ public class DiskOffering implements Comparable<DiskOffering> {
this.domainId = domainId;
this.diskSize = diskSize;
this.customized = customized;
this.tags = tags;
this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet.<String> of();
}
/**
@ -244,8 +254,7 @@ public class DiskOffering implements Comparable<DiskOffering> {
/**
* @return the tags for the disk offering
*/
@Nullable
public String getTags() {
public Set<String> getTags() {
return this.tags;
}

View File

@ -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<Host> {
protected long diskSizeTotal;
protected String events;
protected boolean hasEnoughCapacity;
protected String hostTags;
protected ImmutableSet.Builder<String> tags = ImmutableSet.<String>builder();
protected String hypervisor;
protected String ipAddress;
protected boolean localStorageActive;
@ -319,13 +321,21 @@ public class Host implements Comparable<Host> {
}
/**
* @see Host#getHostTags()
* @see Host#getTags()
*/
public T hostTags(String hostTags) {
this.hostTags = hostTags;
public T tags(Iterable<String> tags) {
this.tags = ImmutableSet.<String>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<Host> {
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<Host> {
.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<Host> {
private final long diskSizeTotal;
private final String events;
private final boolean hasEnoughCapacity;
private final String hostTags;
private final Set<String> tags;
private final String hypervisor;
private final String ipAddress;
private final boolean localStorageActive;
@ -619,7 +629,7 @@ public class Host implements Comparable<Host> {
@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<String> 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<Host> {
this.diskSizeTotal = diskSizeTotal;
this.events = events;
this.hasEnoughCapacity = hasEnoughCapacity;
this.hostTags = hostTags;
this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet.<String> of();
this.hypervisor = hypervisor;
this.ipAddress = ipAddress;
this.localStorageActive = localStorageActive;
@ -752,11 +762,14 @@ public class Host implements Comparable<Host> {
return this.hasEnoughCapacity;
}
@Nullable
public String getHostTags() {
return this.hostTags;
/**
* @return the tags for the host
*/
public Set<String> getTags() {
return this.tags;
}
@Nullable
public String getHypervisor() {
return this.hypervisor;
@ -868,7 +881,7 @@ public class Host implements Comparable<Host> {
@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<Host> {
&& 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<Host> {
.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)

View File

@ -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<String> tags = ImmutableSet.<String>builder();
protected boolean securityGroupEnabled;
protected Set<? extends NetworkService> 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<String> tags) {
this.tags = ImmutableSet.<String>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<String> tags;
private final boolean securityGroupEnabled;
private final Set<? extends NetworkService> 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<? extends NetworkService> services) {
@Nullable String zoneId, @Nullable Iterable<String> tags, boolean securityGroupEnabled, Set<? extends NetworkService> 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.<String> 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<String> getTags() {
return this.tags;
}

View File

@ -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<NetworkOffering> {
protected TrafficType trafficType;
protected GuestIPType guestIPType;
protected int networkRate;
protected String tags;
protected ImmutableSet.Builder<String> tags = ImmutableSet.<String>builder();
/**
* @see NetworkOffering#getId()
@ -146,17 +148,26 @@ public class NetworkOffering implements Comparable<NetworkOffering> {
this.networkRate = networkRate;
return self();
}
/**
* @see NetworkOffering#getTags()
*/
public T tags(String tags) {
this.tags = tags;
public T tags(Iterable<String> tags) {
this.tags = ImmutableSet.<String>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<NetworkOffering> {
private final TrafficType trafficType;
private final GuestIPType guestIPType;
private final int networkRate;
private final String tags;
private final Set<String> 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<String> tags) {
this.id = checkNotNull(id, "id");
this.name = name;
this.displayText = displayText;
@ -211,7 +222,7 @@ public class NetworkOffering implements Comparable<NetworkOffering> {
this.trafficType = trafficType;
this.guestIPType = guestIPType;
this.networkRate = networkRate;
this.tags = tags;
this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet.<String> of();
}
/**
@ -302,8 +313,7 @@ public class NetworkOffering implements Comparable<NetworkOffering> {
/**
* @return the tags for the network offering
*/
@Nullable
public String getTags() {
public Set<String> getTags() {
return this.tags;
}

View File

@ -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<ServiceOffering> {
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<String> tags = ImmutableSet.of();
protected ImmutableSet.Builder<String> tags = ImmutableSet.<String>builder();
/**
* @see ServiceOffering#getId()
@ -161,11 +157,19 @@ public class ServiceOffering implements Comparable<ServiceOffering> {
/**
* @see ServiceOffering#getTags()
*/
public T tags(Set<String> tags) {
this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags"));
public T tags(Iterable<String> tags) {
this.tags = ImmutableSet.<String>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<ServiceOffering> {
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<ServiceOffering> {
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<ServiceOffering> {
.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<ServiceOffering> {
private final StorageType storageType;
private final Set<String> 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<String> 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<ServiceOffering> {
this.memory = memory;
this.haSupport = haSupport;
this.storageType = storageType;
this.tags = !(Strings.emptyToNull(tags) == null) ? ImmutableSet.copyOf(Splitter.on(',').split(tags))
: ImmutableSet.<String> of();
this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet.<String> 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<ServiceOffering> {
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<ServiceOffering> {
@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<ServiceOffering> {
&& 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<ServiceOffering> {
.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);
}

View File

@ -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<StoragePool> {
protected String id;
protected String name;
protected String path;
protected String tags;
protected ImmutableSet.Builder<String> tags = ImmutableSet.<String>builder();
protected StoragePool.State state;
protected StoragePool.Type type;
protected String zoneId;
@ -143,10 +145,18 @@ public class StoragePool implements Comparable<StoragePool> {
}
/**
* @see StoragePool#getTags()
* @see DiskOffering#getTags()
*/
public T tags(String tags) {
this.tags = tags;
public T tags(Iterable<String> tags) {
this.tags = ImmutableSet.<String>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<StoragePool> {
}
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<StoragePool> {
private final String id;
private final String name;
private final String path;
private final String tags;
private final Set<String> tags;
private final StoragePool.State state;
private final StoragePool.Type type;
private final String zoneId;
@ -318,11 +328,15 @@ public class StoragePool implements Comparable<StoragePool> {
@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<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) {
this.id = checkNotNull(id, "id");
this.name = name;
this.path = path;
this.tags = tags;
this.tags = tags != null ? ImmutableSet.copyOf(tags) : ImmutableSet.<String> of();
this.state = state;
this.type = type;
this.zoneId = zoneId;
@ -353,8 +367,7 @@ public class StoragePool implements Comparable<StoragePool> {
return this.path;
}
@Nullable
public String getTags() {
public Set<String> getTags() {
return this.tags;
}

View File

@ -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.<String>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.<String>emptySet()).osCategoryId("5"));

View File

@ -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<Host>, Set<Host>>
@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<Host>, Set<Host>>
.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(),

View File

@ -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<Set<StoragePool>> {
@Override
@ -54,7 +58,16 @@ public class ListStoragePoolsResponseTest extends BaseItemParserTest<Set<Storage
c.set(Calendar.SECOND, 6);
Date created = c.getTime();
StoragePool storagePool = StoragePool.builder().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(created).type(StoragePool.Type.NETWORK_FILESYSTEM).clusterId("1").clusterName("Xen Clust 1").diskSizeTotal(898356445184L).diskSizeAllocated(18276679680L).tags("").state(StoragePool.State.UP).build();
StoragePool storagePool = StoragePool.builder().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(created).type(StoragePool.Type.NETWORK_FILESYSTEM).clusterId("1").clusterName("Xen Clust 1")
.diskSizeTotal(898356445184L).diskSizeAllocated(18276679680L).tag("tag1").state(StoragePool.State.UP)
.build();
return ImmutableSet.of(storagePool);
}
@Override
protected Injector injector() {
return Guice.createInjector(new GsonModule(), new CloudStackParserModule());
}
}

View File

@ -23,7 +23,7 @@ import java.util.Date;
import java.util.Set;
import java.util.TimeZone;
import org.jclouds.cloudstack.config.CloudStackDateAdapter;
import org.jclouds.cloudstack.config.CloudStackParserModule;
import org.jclouds.cloudstack.domain.UsageRecord;
import org.jclouds.json.BaseSetParserTest;
import org.jclouds.json.config.GsonModule;
@ -69,17 +69,10 @@ public class ListUsageRecordsResponseTest extends BaseSetParserTest<UsageRecord>
.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());
}
}

View File

@ -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"} ] } }
{ "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"} ] } }