mirror of https://github.com/apache/jclouds.git
Issue 695: Added ComputePoolResourceSummary, associated objects, service call and tests
This commit is contained in:
parent
0dae767fa7
commit
5e854c8a6b
|
@ -39,6 +39,12 @@ public interface TerremarkEnterpriseCloudAsyncClient {
|
|||
@Delegate
|
||||
LocationAsyncClient getLocationClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Resource features.
|
||||
*/
|
||||
@Delegate
|
||||
ResourceAsyncClient getResourceClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Task features.
|
||||
*/
|
||||
|
|
|
@ -22,10 +22,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.LocationClient;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.TaskClient;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.TemplateClient;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineClient;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.*;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to TerremarkEnterpriseCloud.
|
||||
|
@ -46,6 +43,12 @@ public interface TerremarkEnterpriseCloudClient {
|
|||
@Delegate
|
||||
LocationClient getLocationClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Resource features.
|
||||
*/
|
||||
@Delegate
|
||||
ResourceClient getResourceClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Task features.
|
||||
*/
|
||||
|
|
|
@ -48,6 +48,7 @@ public class TerremarkEnterpriseCloudRestClientModule extends
|
|||
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
|
||||
.put(LocationClient.class, LocationAsyncClient.class)
|
||||
.put(ResourceClient.class, ResourceAsyncClient.class)
|
||||
.put(TaskClient.class, TaskAsyncClient.class)
|
||||
.put(VirtualMachineClient.class, VirtualMachineAsyncClient.class)
|
||||
.put(TemplateClient.class, TemplateAsyncClient.class)
|
||||
|
|
|
@ -0,0 +1,285 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
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 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;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="ComputePoolResourceSummary">
|
||||
* @author Jason King
|
||||
*
|
||||
*/
|
||||
@XmlRootElement(name = "ComputePoolResourceSummary")
|
||||
public class ComputePoolResourceSummary extends Resource<ComputePoolResourceSummary> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromComputePoolResourceSummary(this);
|
||||
}
|
||||
|
||||
public static class Builder extends Resource.Builder<ComputePoolResourceSummary> {
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
private CpuComputeResourceSummary cpu;
|
||||
private MemoryComputeResourceSummary memory;
|
||||
private StorageResourceSummary storage;
|
||||
private VirtualMachineResourceSummary virtualMachines;
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary#getStartTime
|
||||
*/
|
||||
public Builder startTime(Date startTime) {
|
||||
this.startTime = startTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary#getEndTime
|
||||
*/
|
||||
public Builder endTime(Date endTime) {
|
||||
this.endTime = endTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary#getCpu
|
||||
*/
|
||||
public Builder cpu(CpuComputeResourceSummary cpu) {
|
||||
this.cpu = cpu;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary#getMemory
|
||||
*/
|
||||
public Builder memory(MemoryComputeResourceSummary memory) {
|
||||
this.memory = memory;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary#getStorage
|
||||
*/
|
||||
public Builder storage(StorageResourceSummary storage) {
|
||||
this.storage = storage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary#getVirtualMachines
|
||||
*/
|
||||
public Builder virtualMachines(VirtualMachineResourceSummary virtualMachines) {
|
||||
this.virtualMachines = virtualMachines;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputePoolResourceSummary build() {
|
||||
return new ComputePoolResourceSummary(href, type, name, links, actions,
|
||||
startTime, endTime, cpu, memory, storage, virtualMachines);
|
||||
}
|
||||
|
||||
public Builder fromComputePoolResourceSummary(ComputePoolResourceSummary in) {
|
||||
return fromResource(in).startTime(in.getStartTime()).endTime(in.getEndTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder fromBaseResource(BaseResource<ComputePoolResourceSummary> in) {
|
||||
return Builder.class.cast(super.fromBaseResource(in));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder fromResource(Resource<ComputePoolResourceSummary> 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<Link> links) {
|
||||
return Builder.class.cast(super.links(links));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder actions(Set<Action> actions) {
|
||||
return Builder.class.cast(super.actions(actions));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder fromAttributes(Map<String, String> attributes) {
|
||||
return Builder.class.cast(super.fromAttributes(attributes));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@XmlElement(name = "StartTime", required = true)
|
||||
private Date startTime;
|
||||
|
||||
@XmlElement(name = "EndTime", required = true)
|
||||
private Date endTime;
|
||||
|
||||
@XmlElement(name = "Cpu", required = false)
|
||||
private CpuComputeResourceSummary cpu;
|
||||
|
||||
@XmlElement(name = "Memory", required = false)
|
||||
private MemoryComputeResourceSummary memory;
|
||||
|
||||
@XmlElement(name = "Storage", required = false)
|
||||
private StorageResourceSummary storage;
|
||||
|
||||
@XmlElement(name = "VirtualMachines", required = false)
|
||||
private VirtualMachineResourceSummary virtualMachines;
|
||||
|
||||
private ComputePoolResourceSummary(URI href, String type, String name, Set<Link> links, Set<Action> actions, Date startTime, Date completedTime,
|
||||
@Nullable CpuComputeResourceSummary cpu, @Nullable MemoryComputeResourceSummary memory, @Nullable StorageResourceSummary storage, @Nullable VirtualMachineResourceSummary virtualMachines) {
|
||||
super(href, type, name, links, actions);
|
||||
this.startTime = checkNotNull(startTime, "startTime");
|
||||
this.endTime = checkNotNull(endTime, "endTime");
|
||||
this.cpu = cpu;
|
||||
this.memory = memory;
|
||||
this.storage = storage;
|
||||
this.virtualMachines = virtualMachines;
|
||||
}
|
||||
|
||||
private ComputePoolResourceSummary() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public Date getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public Date getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public CpuComputeResourceSummary getCpu() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
public MemoryComputeResourceSummary getMemory() {
|
||||
return memory;
|
||||
}
|
||||
|
||||
public StorageResourceSummary getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public VirtualMachineResourceSummary getVirtualMachines() {
|
||||
return virtualMachines;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
ComputePoolResourceSummary that = (ComputePoolResourceSummary) o;
|
||||
|
||||
if (cpu != null ? !cpu.equals(that.cpu) : that.cpu != null) return false;
|
||||
if (!endTime.equals(that.endTime)) return false;
|
||||
if (memory != null ? !memory.equals(that.memory) : that.memory != null)
|
||||
return false;
|
||||
if (!startTime.equals(that.startTime)) return false;
|
||||
if (storage != null ? !storage.equals(that.storage) : that.storage != null)
|
||||
return false;
|
||||
if (virtualMachines != null ? !virtualMachines.equals(that.virtualMachines) : that.virtualMachines != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + startTime.hashCode();
|
||||
result = 31 * result + endTime.hashCode();
|
||||
result = 31 * result + (cpu != null ? cpu.hashCode() : 0);
|
||||
result = 31 * result + (memory != null ? memory.hashCode() : 0);
|
||||
result = 31 * result + (storage != null ? storage.hashCode() : 0);
|
||||
result = 31 * result + (virtualMachines != null ? virtualMachines.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String string() {
|
||||
return super.string()+", startTime="+startTime+", endTime="+endTime+", cpu="+cpu+", memory="+memory+", storage="+storage+", virtualMachines="+virtualMachines;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="ComputeResourceSummary">
|
||||
* @author Jason King
|
||||
*/
|
||||
public class ComputeResourceSummary {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromComputeResourceSummary(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
protected ResourceCapacity allocated;
|
||||
protected ResourceCapacity consumed;
|
||||
protected ResourceCapacity purchased;
|
||||
protected int utilization;
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputeResourceSummary#getAllocated
|
||||
*/
|
||||
public Builder allocated(ResourceCapacity allocated) {
|
||||
this.allocated = allocated;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputeResourceSummary#getConsumed
|
||||
*/
|
||||
public Builder consumed(ResourceCapacity consumed) {
|
||||
this.consumed = consumed;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputeResourceSummary#getPurchased
|
||||
*/
|
||||
public Builder purchased(ResourceCapacity purchased) {
|
||||
this.purchased = purchased;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputeResourceSummary#getUtilization
|
||||
*/
|
||||
public Builder utilization(int utilization) {
|
||||
this.utilization = utilization;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ComputeResourceSummary build() {
|
||||
return new ComputeResourceSummary(allocated,consumed,purchased,utilization);
|
||||
}
|
||||
|
||||
public Builder fromComputeResourceSummary(ComputeResourceSummary in) {
|
||||
return allocated(in.getAllocated()).consumed(in.getConsumed()).purchased(in.getPurchased()).utilization(in.getUtilization());
|
||||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "Allocated", required = false)
|
||||
private ResourceCapacity allocated;
|
||||
|
||||
@XmlElement(name = "Consumed", required = false)
|
||||
private ResourceCapacity consumed;
|
||||
|
||||
@XmlElement(name = "Purchased", required = false)
|
||||
private ResourceCapacity purchased;
|
||||
|
||||
@XmlElement(name = "Utilization", required = false)
|
||||
private int utilization;
|
||||
|
||||
protected ComputeResourceSummary(@Nullable ResourceCapacity allocated, @Nullable ResourceCapacity consumed, @Nullable ResourceCapacity purchased, int utilization) {
|
||||
this.allocated = allocated;
|
||||
this.consumed = consumed;
|
||||
this.purchased = purchased;
|
||||
this.utilization = utilization;
|
||||
}
|
||||
|
||||
protected ComputeResourceSummary() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public ResourceCapacity getAllocated() {
|
||||
return allocated;
|
||||
}
|
||||
|
||||
public ResourceCapacity getConsumed() {
|
||||
return consumed;
|
||||
}
|
||||
|
||||
public ResourceCapacity getPurchased() {
|
||||
return purchased;
|
||||
}
|
||||
|
||||
public int getUtilization() {
|
||||
return utilization;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ComputeResourceSummary that = (ComputeResourceSummary) o;
|
||||
|
||||
if (utilization != that.utilization) return false;
|
||||
if (allocated != null ? !allocated.equals(that.allocated) : that.allocated != null)
|
||||
return false;
|
||||
if (consumed != null ? !consumed.equals(that.consumed) : that.consumed != null)
|
||||
return false;
|
||||
if (purchased != null ? !purchased.equals(that.purchased) : that.purchased != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = allocated != null ? allocated.hashCode() : 0;
|
||||
result = 31 * result + (consumed != null ? consumed.hashCode() : 0);
|
||||
result = 31 * result + (purchased != null ? purchased.hashCode() : 0);
|
||||
result = 31 * result + utilization;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[%s]",string());
|
||||
}
|
||||
|
||||
protected String string() {
|
||||
return "allocated="+ allocated +", consumed="+consumed+", purchased="+purchased+", utilization="+utilization;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="CpuComputeResourceSummary">
|
||||
* @author Jason King
|
||||
*/
|
||||
public class CpuComputeResourceSummary extends ComputeResourceSummary {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromCpuComputeResourceSummary(this);
|
||||
}
|
||||
|
||||
public static class Builder extends ComputeResourceSummary.Builder {
|
||||
|
||||
protected int count;
|
||||
protected int poweredOnCount;
|
||||
|
||||
public Builder allocated(ResourceCapacity allocated) {
|
||||
return Builder.class.cast(super.allocated(allocated));
|
||||
}
|
||||
|
||||
public Builder consumed(ResourceCapacity consumed) {
|
||||
return Builder.class.cast(super.consumed(consumed));
|
||||
}
|
||||
|
||||
public Builder purchased(ResourceCapacity purchased) {
|
||||
return Builder.class.cast(super.purchased(purchased));
|
||||
}
|
||||
|
||||
public Builder utilization(int utilization) {
|
||||
return Builder.class.cast(super.utilization(utilization));
|
||||
}
|
||||
|
||||
public Builder count(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder poweredOnCount(int poweredOnCount) {
|
||||
this.poweredOnCount = poweredOnCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CpuComputeResourceSummary build() {
|
||||
return new CpuComputeResourceSummary(allocated,consumed,purchased,utilization,count,poweredOnCount);
|
||||
}
|
||||
|
||||
public Builder fromCpuComputeResourceSummary(CpuComputeResourceSummary in) {
|
||||
return allocated(in.getAllocated()).consumed(in.getConsumed()).purchased(in.getPurchased()).utilization(in.getUtilization())
|
||||
.count(in.getCount()).poweredOnCount(in.getPoweredOnCount());
|
||||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "Count", required = false)
|
||||
private int count;
|
||||
|
||||
@XmlElement(name = "PoweredOnCount", required = false)
|
||||
private int poweredOnCount;
|
||||
|
||||
private CpuComputeResourceSummary(@Nullable ResourceCapacity allocated, @Nullable ResourceCapacity consumed, @Nullable ResourceCapacity purchased, int utilization, int count, int poweredOnCount) {
|
||||
super(allocated,consumed,purchased,utilization);
|
||||
this.count = count;
|
||||
this.poweredOnCount = poweredOnCount;
|
||||
}
|
||||
|
||||
private CpuComputeResourceSummary() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getPoweredOnCount() {
|
||||
return poweredOnCount;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
CpuComputeResourceSummary that = (CpuComputeResourceSummary) o;
|
||||
|
||||
if (count != that.count) return false;
|
||||
if (poweredOnCount != that.poweredOnCount) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + count;
|
||||
result = 31 * result + poweredOnCount;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String string() {
|
||||
return super.string()+", count="+count+", poweredOnCount="+poweredOnCount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="MemoryComputeResourceSummary">
|
||||
* @author Jason King
|
||||
*/
|
||||
public class MemoryComputeResourceSummary extends ComputeResourceSummary {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromMemoryComputeResourceSummary(this);
|
||||
}
|
||||
|
||||
public static class Builder extends ComputeResourceSummary.Builder {
|
||||
|
||||
public Builder allocated(ResourceCapacity allocated) {
|
||||
return Builder.class.cast(super.allocated(allocated));
|
||||
}
|
||||
|
||||
public Builder consumed(ResourceCapacity consumed) {
|
||||
return Builder.class.cast(super.consumed(consumed));
|
||||
}
|
||||
|
||||
public Builder purchased(ResourceCapacity purchased) {
|
||||
return Builder.class.cast(super.purchased(purchased));
|
||||
}
|
||||
|
||||
public Builder utilization(int utilization) {
|
||||
return Builder.class.cast(super.utilization(utilization));
|
||||
}
|
||||
|
||||
public MemoryComputeResourceSummary build() {
|
||||
return new MemoryComputeResourceSummary(allocated,consumed,purchased,utilization);
|
||||
}
|
||||
|
||||
public Builder fromMemoryComputeResourceSummary(MemoryComputeResourceSummary in) {
|
||||
return allocated(in.getAllocated()).consumed(in.getConsumed()).purchased(in.getPurchased()).utilization(in.getUtilization());
|
||||
}
|
||||
}
|
||||
|
||||
private MemoryComputeResourceSummary(@Nullable ResourceCapacity allocated, @Nullable ResourceCapacity consumed, @Nullable ResourceCapacity purchased, int utilization) {
|
||||
super(allocated,consumed,purchased,utilization);
|
||||
}
|
||||
|
||||
private MemoryComputeResourceSummary() {
|
||||
//For JAXB
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="StorageResourceSummary">
|
||||
* @author Jason King
|
||||
*/
|
||||
public class StorageResourceSummary {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromStorageResourceSummary(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private ResourceCapacity purchased;
|
||||
private ResourceCapacity used;
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.StorageResourceSummary#getPurchased
|
||||
*/
|
||||
public Builder purchased(ResourceCapacity purchased) {
|
||||
this.purchased = purchased;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.StorageResourceSummary#getUsed
|
||||
*/
|
||||
public Builder used(ResourceCapacity used) {
|
||||
this.used = used;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StorageResourceSummary build() {
|
||||
return new StorageResourceSummary(purchased,used);
|
||||
}
|
||||
|
||||
public Builder fromStorageResourceSummary(StorageResourceSummary in) {
|
||||
return purchased(in.getPurchased()).used(in.getUsed());
|
||||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "Purchased", required = false)
|
||||
private ResourceCapacity purchased;
|
||||
|
||||
@XmlElement(name = "Used", required = false)
|
||||
private ResourceCapacity used;
|
||||
|
||||
protected StorageResourceSummary(@Nullable ResourceCapacity purchased, @Nullable ResourceCapacity used) {
|
||||
this.purchased = purchased;
|
||||
this.used = used;
|
||||
}
|
||||
|
||||
protected StorageResourceSummary() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public ResourceCapacity getPurchased() {
|
||||
return purchased;
|
||||
}
|
||||
|
||||
public ResourceCapacity getUsed() {
|
||||
return used;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
StorageResourceSummary that = (StorageResourceSummary) o;
|
||||
|
||||
if (purchased != null ? !purchased.equals(that.purchased) : that.purchased != null)
|
||||
return false;
|
||||
if (used != null ? !used.equals(that.used) : that.used != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = purchased != null ? purchased.hashCode() : 0;
|
||||
result = 31 * result + (used != null ? used.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[%s]",string());
|
||||
}
|
||||
|
||||
protected String string() {
|
||||
return "purchased="+purchased+", used="+ used;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="VirtualMachineResourceSummary">
|
||||
* @author Jason King
|
||||
*/
|
||||
public class VirtualMachineResourceSummary extends ComputeResourceSummary {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromVirtualMachineResourceSummary(this);
|
||||
}
|
||||
|
||||
public static class Builder extends ComputeResourceSummary.Builder {
|
||||
|
||||
protected int count;
|
||||
protected int poweredOnCount;
|
||||
|
||||
public Builder allocated(ResourceCapacity allocated) {
|
||||
return Builder.class.cast(super.allocated(allocated));
|
||||
}
|
||||
|
||||
public Builder consumed(ResourceCapacity consumed) {
|
||||
return Builder.class.cast(super.consumed(consumed));
|
||||
}
|
||||
|
||||
public Builder purchased(ResourceCapacity purchased) {
|
||||
return Builder.class.cast(super.purchased(purchased));
|
||||
}
|
||||
|
||||
public Builder utilization(int utilization) {
|
||||
return Builder.class.cast(super.utilization(utilization));
|
||||
}
|
||||
|
||||
public Builder count(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder poweredOnCount(int poweredOnCount) {
|
||||
this.poweredOnCount = poweredOnCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VirtualMachineResourceSummary build() {
|
||||
return new VirtualMachineResourceSummary(allocated,consumed,purchased,utilization,count,poweredOnCount);
|
||||
}
|
||||
|
||||
public Builder fromVirtualMachineResourceSummary(VirtualMachineResourceSummary in) {
|
||||
return allocated(in.getAllocated()).consumed(in.getConsumed()).purchased(in.getPurchased()).utilization(in.getUtilization())
|
||||
.count(in.getCount()).poweredOnCount(in.getPoweredOnCount());
|
||||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "Count", required = false)
|
||||
private int count;
|
||||
|
||||
@XmlElement(name = "PoweredOnCount", required = false)
|
||||
private int poweredOnCount;
|
||||
|
||||
private VirtualMachineResourceSummary(@Nullable ResourceCapacity allocated, @Nullable ResourceCapacity consumed, @Nullable ResourceCapacity purchased, int utilization, int count, int poweredOnCount) {
|
||||
super(allocated,consumed,purchased,utilization);
|
||||
this.count = count;
|
||||
this.poweredOnCount = poweredOnCount;
|
||||
}
|
||||
|
||||
private VirtualMachineResourceSummary() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getPoweredOnCount() {
|
||||
return poweredOnCount;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
VirtualMachineResourceSummary that = (VirtualMachineResourceSummary) o;
|
||||
|
||||
if (count != that.count) return false;
|
||||
if (poweredOnCount != that.poweredOnCount) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + count;
|
||||
result = 31 * result + poweredOnCount;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String string() {
|
||||
return super.string()+", count="+count+", poweredOnCount="+poweredOnCount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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.features;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.*;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to various Resources via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see ResourceClient
|
||||
* @see <a href=
|
||||
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
|
||||
* />
|
||||
* @author Jason King
|
||||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Headers(keys = "x-tmrk-version", values = "{jclouds.api-version}")
|
||||
public interface ResourceAsyncClient {
|
||||
|
||||
/**
|
||||
* @see ResourceClient#getResourceSummary
|
||||
*/
|
||||
@GET
|
||||
@Consumes("application/vnd.tmrk.cloud.computePoolResourceSummary")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<ComputePoolResourceSummary> getResourceSummary(@EndpointParam URI uri);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* 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.features;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to various Resources.
|
||||
* <p/>
|
||||
*
|
||||
* @see ResourceAsyncClient
|
||||
* @see <a href=
|
||||
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
|
||||
* />
|
||||
* @author Jason King
|
||||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
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 compute pool
|
||||
* @return the summary
|
||||
*/
|
||||
ComputePoolResourceSummary getResourceSummary(URI uri);
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* 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.features;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code ResourceAsyncClient}
|
||||
*
|
||||
* @author Jason King
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ResourceAsyncClient")
|
||||
public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<ResourceAsyncClient> {
|
||||
|
||||
public void testGetResourceSummary() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = ResourceAsyncClient.class.getMethod("getResourceSummary", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/computepools/89/resourcesummary"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/computepools/89/resourcesummary HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/vnd.tmrk.cloud.computePoolResourceSummary\nx-tmrk-version: 2011-07-01\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<ResourceAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<ResourceAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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.features;
|
||||
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ResourceClient}
|
||||
*
|
||||
* @author Jason King
|
||||
*/
|
||||
@Test(groups = "live", testName = "ResourceClientLiveTest")
|
||||
public class ResourceClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTest {
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
super.setupClient();
|
||||
client = context.getApi().getResourceClient();
|
||||
}
|
||||
|
||||
private ResourceClient client;
|
||||
|
||||
public void testGetResourceSummary() throws Exception {
|
||||
ComputePoolResourceSummary resourceSummary = client.getResourceSummary(URI.create("/cloudapi/ecloud/computepools/89/resourcesummary"));
|
||||
assertNotNull(resourceSummary);
|
||||
}
|
||||
|
||||
public void testMissingResourceSummary() {
|
||||
assertNull(client.getResourceSummary(URI.create("/cloudapi/ecloud/computepools/-1/resourcesummary")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
/**
|
||||
* 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.xml;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.BaseRestClientTest;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.resource.*;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.ResourceAsyncClient;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Named;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.io.Payloads.newInputStreamPayload;
|
||||
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
||||
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of JAXB parsing for ComputePoolResourceSummary
|
||||
*
|
||||
* @author Jason King
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ComputePoolResourceSummaryJAXBParsingTest")
|
||||
public class ComputePoolResourceSummaryJAXBParsingTest extends BaseRestClientTest {
|
||||
|
||||
private SimpleDateFormatDateService dateService;
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
dateService = new SimpleDateFormatDateService();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
|
||||
"credentialFoo", String.class, Integer.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Named("exception")
|
||||
Set<String> exception() {
|
||||
throw new AuthorizationException();
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
injector = createContextBuilder(contextSpec).buildInjector();
|
||||
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
||||
crypto = injector.getInstance(Crypto.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseLocationWithJAXB() throws Exception {
|
||||
Method method = ResourceAsyncClient.class.getMethod("getResourceSummary",URI.class);
|
||||
HttpRequest request = factory(ResourceAsyncClient.class).createRequest(method, new URI("/1"));
|
||||
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||
|
||||
Function<HttpResponse, ComputePoolResourceSummary> parser = (Function<HttpResponse, ComputePoolResourceSummary>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/computePoolResourceSummary.xml");
|
||||
ComputePoolResourceSummary summary = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||
assertEquals(summary.getStartTime(),dateService.iso8601DateParse("2011-12-04T18:55:00.0Z"));
|
||||
assertEquals(summary.getEndTime(),dateService.iso8601DateParse("2011-12-05T18:55:00.0Z"));
|
||||
|
||||
assertCpu(summary.getCpu());
|
||||
assertMemory(summary.getMemory());
|
||||
assertStorage(summary.getStorage());
|
||||
assertVirtualMachines(summary.getVirtualMachines());
|
||||
}
|
||||
|
||||
private void assertCpu(CpuComputeResourceSummary cpu) {
|
||||
CpuComputeResourceSummary expected = CpuComputeResourceSummary.builder()
|
||||
.allocated(ResourceCapacity.builder().value(2.7).unit("GHz").build())
|
||||
.consumed(ResourceCapacity.builder().value(59).unit("MHz").build())
|
||||
.purchased(ResourceCapacity.builder().value(5).unit("GHz").build())
|
||||
.utilization(2)
|
||||
.build();
|
||||
assertEquals(cpu,expected);
|
||||
}
|
||||
|
||||
private void assertMemory(MemoryComputeResourceSummary memory) {
|
||||
MemoryComputeResourceSummary expected = MemoryComputeResourceSummary.builder()
|
||||
.allocated(ResourceCapacity.builder().value(0.4).unit("GB").build())
|
||||
.consumed(ResourceCapacity.builder().value(404).unit("MB").build())
|
||||
.purchased(ResourceCapacity.builder().value(10).unit("GB").build())
|
||||
.utilization(4)
|
||||
.build();
|
||||
assertEquals(memory,expected);
|
||||
}
|
||||
|
||||
private void assertStorage(StorageResourceSummary storage) {
|
||||
StorageResourceSummary expected = StorageResourceSummary.builder()
|
||||
.purchased(ResourceCapacity.builder().value(250).unit("GB").build())
|
||||
.used(ResourceCapacity.builder().value(10).unit("GB").build())
|
||||
.build();
|
||||
assertEquals(storage,expected);
|
||||
}
|
||||
|
||||
private void assertVirtualMachines(VirtualMachineResourceSummary virtualMachines) {
|
||||
VirtualMachineResourceSummary expected = VirtualMachineResourceSummary.builder()
|
||||
.count(1)
|
||||
.poweredOnCount(1)
|
||||
.build();
|
||||
assertEquals(virtualMachines, expected);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<ComputePoolResourceSummary
|
||||
href="/cloudapi/ecloud/computepools/89/resourcesummary"
|
||||
type="application/vnd.tmrk.cloud.computePoolResourceSummary"
|
||||
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Links>
|
||||
<Link href="/cloudapi/ecloud/computepools/89"
|
||||
name="Default Compute Pool"
|
||||
type="application/vnd.tmrk.cloud.computePool" rel="up"/>
|
||||
</Links>
|
||||
<StartTime>2011-12-04T18:55:00Z</StartTime>
|
||||
<EndTime>2011-12-05T18:55:00Z</EndTime>
|
||||
<Cpu>
|
||||
<Allocated>
|
||||
<Unit>GHz</Unit>
|
||||
<Value>2.7</Value>
|
||||
</Allocated>
|
||||
<Consumed>
|
||||
<Unit>MHz</Unit>
|
||||
<Value>59</Value>
|
||||
</Consumed>
|
||||
<Purchased>
|
||||
<Unit>GHz</Unit>
|
||||
<Value>5</Value>
|
||||
</Purchased>
|
||||
<Utilization>2</Utilization>
|
||||
</Cpu>
|
||||
<Memory>
|
||||
<Allocated>
|
||||
<Unit>GB</Unit>
|
||||
<Value>0.4</Value>
|
||||
</Allocated>
|
||||
<Consumed>
|
||||
<Unit>MB</Unit>
|
||||
<Value>404</Value>
|
||||
</Consumed>
|
||||
<Purchased>
|
||||
<Unit>GB</Unit>
|
||||
<Value>10</Value>
|
||||
</Purchased>
|
||||
<Utilization>4</Utilization>
|
||||
</Memory>
|
||||
<Storage>
|
||||
<Purchased>
|
||||
<Unit>GB</Unit>
|
||||
<Value>250</Value>
|
||||
</Purchased>
|
||||
<Used>
|
||||
<Unit>GB</Unit>
|
||||
<Value>10</Value>
|
||||
</Used>
|
||||
</Storage>
|
||||
<VirtualMachines>
|
||||
<Count>1</Count>
|
||||
<PoweredOnCount>1</PoweredOnCount>
|
||||
</VirtualMachines>
|
||||
</ComputePoolResourceSummary>
|
|
@ -0,0 +1,64 @@
|
|||
<ComputePoolResourceSummaryList
|
||||
href="/cloudapi/ecloud/computepools/environments/77/resourcesummarylist"
|
||||
type="application/vnd.tmrk.cloud.computePoolResourceSummary; type=collection"
|
||||
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Links>
|
||||
<Link href="/cloudapi/ecloud/environments/77" name="Beta Environment 01"
|
||||
type="application/vnd.tmrk.cloud.environment" rel="up"/>
|
||||
</Links>
|
||||
<ComputePoolResourceSummary
|
||||
href="/cloudapi/ecloud/computepools/89/resourcesummary"
|
||||
type="application/vnd.tmrk.cloud.computePoolResourceSummary">
|
||||
<Links>
|
||||
<Link href="/cloudapi/ecloud/computepools/89"
|
||||
name="Default Compute Pool"
|
||||
type="application/vnd.tmrk.cloud.computePool" rel="up"/>
|
||||
</Links>
|
||||
<StartTime>2011-12-04T18:55:00Z</StartTime>
|
||||
<EndTime>2011-12-05T18:55:00Z</EndTime>
|
||||
<Cpu>
|
||||
<Allocated>
|
||||
<Unit>GHz</Unit>
|
||||
<Value>2.7</Value>
|
||||
</Allocated>
|
||||
<Consumed>
|
||||
<Unit>MHz</Unit>
|
||||
<Value>59</Value>
|
||||
</Consumed>
|
||||
<Purchased>
|
||||
<Unit>GHz</Unit>
|
||||
<Value>5</Value>
|
||||
</Purchased>
|
||||
<Utilization>2</Utilization>
|
||||
</Cpu>
|
||||
<Memory>
|
||||
<Allocated>
|
||||
<Unit>GB</Unit>
|
||||
<Value>0.4</Value>
|
||||
</Allocated>
|
||||
<Consumed>
|
||||
<Unit>MB</Unit>
|
||||
<Value>404</Value>
|
||||
</Consumed>
|
||||
<Purchased>
|
||||
<Unit>GB</Unit>
|
||||
<Value>10</Value>
|
||||
</Purchased>
|
||||
<Utilization>4</Utilization>
|
||||
</Memory>
|
||||
<Storage>
|
||||
<Purchased>
|
||||
<Unit>GB</Unit>
|
||||
<Value>250</Value>
|
||||
</Purchased>
|
||||
<Used>
|
||||
<Unit>GB</Unit>
|
||||
<Value>10</Value>
|
||||
</Used>
|
||||
</Storage>
|
||||
<VirtualMachines>
|
||||
<Count>1</Count>
|
||||
<PoweredOnCount>1</PoweredOnCount>
|
||||
</VirtualMachines>
|
||||
</ComputePoolResourceSummary>
|
||||
</ComputePoolResourceSummaryList>
|
Loading…
Reference in New Issue