From 00de94b7b8adfe016bf0e8f576e67c03b3c03806 Mon Sep 17 00:00:00 2001 From: Jason King Date: Tue, 6 Dec 2011 16:14:02 +0000 Subject: [PATCH] Issue 695: Added ComputePoolCpuUsageDetail objects+service calls+tests --- .../cpu/ComputePoolCpuUsageDetail.java | 225 ++++++++++++++++++ .../cpu/VirtualMachineCpuUsageDetail.java | 199 ++++++++++++++++ .../resource/cpu/VirtualMachinesCpuUsage.java | 107 +++++++++ .../features/ResourceAsyncClient.java | 10 + .../features/ResourceClient.java | 28 +++ .../features/ResourceAsyncClientTest.java | 15 ++ .../features/ResourceClientLiveTest.java | 26 ++ ...putePoolCpuUsageDetailJAXBParsingTest.java | 145 +++++++++++ .../resources/computePoolCpuUsageDetail.xml | 28 +++ .../computePoolCpuUsageDetailNoDetail.xml | 17 ++ 10 files changed, 800 insertions(+) create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/ComputePoolCpuUsageDetail.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/VirtualMachineCpuUsageDetail.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/VirtualMachinesCpuUsage.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolCpuUsageDetailJAXBParsingTest.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/test/resources/computePoolCpuUsageDetail.xml create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/test/resources/computePoolCpuUsageDetailNoDetail.xml diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/ComputePoolCpuUsageDetail.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/ComputePoolCpuUsageDetail.java new file mode 100644 index 0000000000..434024c8a6 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/ComputePoolCpuUsageDetail.java @@ -0,0 +1,225 @@ +/** + * 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.tmrk.enterprisecloud.domain.resource.cpu; + +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.tmrk.enterprisecloud.domain.Action; +import org.jclouds.tmrk.enterprisecloud.domain.Link; +import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.net.URI; +import java.util.Date; +import java.util.Map; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * ComputePoolCpuUsageDetail is more than a simple wrapper as it extends Resource. + * + * @author Jason King + * + */ +@XmlRootElement(name = "ComputePoolCpuUsageDetail") +public class ComputePoolCpuUsageDetail extends Resource { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return new Builder().fromComputePoolCpuUsage(this); + } + + public static class Builder extends Resource.Builder { + private Date time; + private ResourceCapacity value; + private VirtualMachinesCpuUsage virtualMachinesCpuUsage; + + /** + * @see org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail#getTime + */ + public Builder time(Date time) { + this.time =(checkNotNull(time,"time")); + return this; + } + + /** + * @see org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail#getValue + */ + public Builder value(ResourceCapacity value) { + this.value =(checkNotNull(value,"value")); + return this; + } + + /** + * @see org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail#getVirtualMachinesCpuUsage + */ + public Builder virtualMachines(VirtualMachinesCpuUsage virtualMachinesCpuUsage) { + this.virtualMachinesCpuUsage =(checkNotNull(virtualMachinesCpuUsage,"virtualMachinesCpuUsage")); + return this; + } + + @Override + public ComputePoolCpuUsageDetail build() { + return new ComputePoolCpuUsageDetail(href, type, name, links, actions, time, value, virtualMachinesCpuUsage); + } + + public Builder fromComputePoolCpuUsage(ComputePoolCpuUsageDetail in) { + return fromResource(in).time(in.getTime()).value(in.getValue()).virtualMachines(in.getVirtualMachinesCpuUsage()); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(Resource in) { + return Builder.class.cast(super.fromResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder links(Set links) { + return Builder.class.cast(super.links(links)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder actions(Set actions) { + return Builder.class.cast(super.actions(actions)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromAttributes(Map attributes) { + return Builder.class.cast(super.fromAttributes(attributes)); + } + + } + + @XmlElement(name = "Time", required = true) + private Date time; + + @XmlElement(name = "Value", required = false) + private ResourceCapacity value; + + @XmlElement(name = "VirtualMachines", required = false) + private VirtualMachinesCpuUsage virtualMachinesCpuUsage; + + private ComputePoolCpuUsageDetail(URI href, String type, String name, Set links, Set actions, Date time, @Nullable ResourceCapacity value, @Nullable VirtualMachinesCpuUsage virtualMachinesCpuUsage) { + super(href, type, name, links, actions); + this.time = checkNotNull(time, "time"); + this.value = value; + this.virtualMachinesCpuUsage = virtualMachinesCpuUsage; + } + + private ComputePoolCpuUsageDetail() { + //For JAXB + } + + public Date getTime() { + return time; + } + + public ResourceCapacity getValue() { + return value; + } + + public VirtualMachinesCpuUsage getVirtualMachinesCpuUsage() { + return virtualMachinesCpuUsage; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + ComputePoolCpuUsageDetail that = (ComputePoolCpuUsageDetail) o; + + if (!time.equals(that.time)) return false; + if (value != null ? !value.equals(that.value) : that.value != null) + return false; + if (virtualMachinesCpuUsage != null ? !virtualMachinesCpuUsage.equals(that.virtualMachinesCpuUsage) : that.virtualMachinesCpuUsage != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + time.hashCode(); + result = 31 * result + (value != null ? value.hashCode() : 0); + result = 31 * result + (virtualMachinesCpuUsage != null ? virtualMachinesCpuUsage.hashCode() : 0); + return result; + } + + @Override + public String string() { + return super.string()+", time="+ time +", value="+value+", virtualMachinesCpuUsage="+ virtualMachinesCpuUsage; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/VirtualMachineCpuUsageDetail.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/VirtualMachineCpuUsageDetail.java new file mode 100644 index 0000000000..e01e4899c2 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/VirtualMachineCpuUsageDetail.java @@ -0,0 +1,199 @@ +/** + * 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.tmrk.enterprisecloud.domain.resource.cpu; + +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity; + +import javax.xml.bind.annotation.XmlElement; +import java.net.URI; +import java.util.Map; + +/** + * + * @author Jason King + * + */ +public class VirtualMachineCpuUsageDetail extends BaseNamedResource { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return new Builder().fromVirtualMachineCpuUsageDetai(this); + } + + public static class Builder extends BaseNamedResource.Builder { + private ResourceCapacity usage; + private int utilization; + private boolean deleted; + + /** + * @see VirtualMachineCpuUsageDetail#getUsage + */ + public Builder usage(ResourceCapacity usage) { + this.usage = usage; + return this; + } + + /** + * @see VirtualMachineCpuUsageDetail#getUtilization + */ + public Builder utilization(int utilization) { + this.utilization = utilization; + return this; + } + + /** + * @see VirtualMachineCpuUsageDetail#isDeleted + */ + public Builder deleted(boolean deleted) { + this.deleted = deleted; + return this; + } + + @Override + public VirtualMachineCpuUsageDetail build() { + return new VirtualMachineCpuUsageDetail(href, type, name, usage, utilization, deleted); + } + + public Builder fromVirtualMachineCpuUsageDetai(VirtualMachineCpuUsageDetail in) { + return fromNamedResource(in).usage(in.getUsage()); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromNamedResource(BaseNamedResource in) { + return Builder.class.cast(super.fromNamedResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromAttributes(Map attributes) { + return Builder.class.cast(super.fromAttributes(attributes)); + } + } + + @XmlElement(name = "Usage", required = false) + private ResourceCapacity usage; + + @XmlElement(name = "Utilization", required = true) + private int utilization; + + @XmlElement(name = "Deleted", required = false) + private boolean deleted; + + private VirtualMachineCpuUsageDetail(URI href, String type, String name, + @Nullable ResourceCapacity usage, int utilization, boolean deleted) { + super(href, type, name); + this.usage = usage; + this.utilization = utilization; + this.deleted = deleted; + } + + private VirtualMachineCpuUsageDetail() { + //For JAXB + } + + public ResourceCapacity getUsage() { + return usage; + } + + public int getUtilization() { + return utilization; + } + + public boolean isDeleted() { + return deleted; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + VirtualMachineCpuUsageDetail that = (VirtualMachineCpuUsageDetail) o; + + if (deleted != that.deleted) return false; + if (utilization != that.utilization) return false; + if (usage != null ? !usage.equals(that.usage) : that.usage != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (usage != null ? usage.hashCode() : 0); + result = 31 * result + utilization; + result = 31 * result + (deleted ? 1 : 0); + return result; + } + + @Override + public String string() { + return super.string()+", usage="+usage+", utilization="+utilization+", deleted="+deleted; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/VirtualMachinesCpuUsage.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/VirtualMachinesCpuUsage.java new file mode 100644 index 0000000000..b2212bfe98 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/cpu/VirtualMachinesCpuUsage.java @@ -0,0 +1,107 @@ +/** + * 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.tmrk.enterprisecloud.domain.resource.cpu; + +import com.google.common.collect.Sets; + +import javax.xml.bind.annotation.XmlElement; +import java.util.Collections; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Wraps individual VirtualMachineCpuUsageDetail elements. + * + * @author Jason King + */ +public class VirtualMachinesCpuUsage { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromCpuUsageDetails(this); + } + + public static class Builder { + + private Set virtualMachinesCpuUsageDetail = Sets.newLinkedHashSet(); + + /** + * @see VirtualMachinesCpuUsage#getVirtualMachinesCpuUsageDetail + */ + public Builder vmCpuUsageDetails(Set vmCpuUsageDetails) { + this.virtualMachinesCpuUsageDetail = Sets.newLinkedHashSet(checkNotNull(vmCpuUsageDetails, "vmCpuUsageDetails")); + return this; + } + + public Builder addVmCpuUsageDetail(VirtualMachineCpuUsageDetail vmCpuUsageDetail) { + virtualMachinesCpuUsageDetail.add(checkNotNull(vmCpuUsageDetail,"vmCpuUsageDetail")); + return this; + } + + public VirtualMachinesCpuUsage build() { + return new VirtualMachinesCpuUsage(virtualMachinesCpuUsageDetail); + } + + public Builder fromCpuUsageDetails(VirtualMachinesCpuUsage in) { + return vmCpuUsageDetails(in.getVirtualMachinesCpuUsageDetail()); + } + } + + private VirtualMachinesCpuUsage() { + //For JAXB and builder use + } + + private VirtualMachinesCpuUsage(Set virtualMachinesCpuUsageDetail) { + this.virtualMachinesCpuUsageDetail = Sets.newLinkedHashSet(virtualMachinesCpuUsageDetail); + } + + @XmlElement(name = "VirtualMachine", required=false) + private Set virtualMachinesCpuUsageDetail = Sets.newLinkedHashSet(); + + public Set getVirtualMachinesCpuUsageDetail() { + return Collections.unmodifiableSet(virtualMachinesCpuUsageDetail); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VirtualMachinesCpuUsage that = (VirtualMachinesCpuUsage) o; + + if (virtualMachinesCpuUsageDetail != null ? !virtualMachinesCpuUsageDetail.equals(that.virtualMachinesCpuUsageDetail) : that.virtualMachinesCpuUsageDetail != null) + return false; + + return true; + } + + @Override + public int hashCode() { + return virtualMachinesCpuUsageDetail != null ? virtualMachinesCpuUsageDetail.hashCode() : 0; + } + + public String toString() { + return "["+ virtualMachinesCpuUsageDetail.toString()+"]"; + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java index 4998fbbc0f..aa49071228 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java @@ -25,6 +25,7 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsage; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList; +import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -70,4 +71,13 @@ public interface ResourceAsyncClient { @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getComputePoolCpuUsage(@EndpointParam URI uri); + + /** + * @see ResourceClient#getComputePoolCpuUsageDetail + */ + @GET + @Consumes("application/vnd.tmrk.cloud.computePoolCpuUsageDetail") + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getComputePoolCpuUsageDetail(@EndpointParam URI uri); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java index a2f40e340c..3d7ee76268 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java @@ -22,6 +22,7 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsage; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList; +import org.jclouds.tmrk.enterprisecloud.domain.resource.cpu.ComputePoolCpuUsageDetail; import java.net.URI; import java.util.concurrent.TimeUnit; @@ -42,6 +43,7 @@ public interface ResourceClient { /** * The Get Resources Summary List call returns summary information regarding * resource utilization in the compute pools defined in an environment. + * * @param uri the uri of the call based upon the environment * e.g. /cloudapi/ecloud/computepools/environments/{id}/resourcesummarylist * @return the summary list @@ -51,6 +53,7 @@ public interface ResourceClient { /** * The Get Resources Summary call returns resource summary information regarding * a specified compute pool defined in an environment. + * * @param uri the uri of the call based upon the compute pool * e.g. /cloudapi/ecloud/computepools/{id}/resourcesummary * @return the summary @@ -62,10 +65,35 @@ public interface ResourceClient { * defined in an environment at five minute intervals for the 24 hours ending one hour * prior to the current time, rounded later. * For example, if current time is 11:22, the end time is 10:25. + * * @param uri the uri of the call based upon the compute pool * e.g. /cloudapi/ecloud/computepools/{id}/usage/cpu * @return The cpu usage for the compute pool */ ComputePoolCpuUsage getComputePoolCpuUsage(URI uri); + /** + * The Get Resources Usage Processor Detail call returns information regarding processor usage + * for a specified compute pool defined in an environment at the time in the URL query part, + * a specified five minute time interval within the 24 hours ending one hour prior to + * the current time, rounded later. + * For example, if current time is 11:22, the end time 10:25. + * The response includes usage of every virtual machine during the interval. + * + * Note: The query part is required and the time passed as the parameter must + * precisely match a time in the preceding 24 hours. + * + * Times are on five minute intervals starting on the hour. + * Available times are in