Merge pull request #226 from jsonking/695-Terremark

Issue 695: StorageUsage objects and service calls + start of performance statistics
This commit is contained in:
Jason King 2011-12-07 11:38:05 -08:00
commit bcc4f8fa53
20 changed files with 2124 additions and 0 deletions

View File

@ -0,0 +1,95 @@
/**
* 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.internal;
import java.net.URI;
import java.util.Map;
/**
* A Resource with no name.
* @author Jason King
*
*/
public class AnonymousResource extends BaseResource<AnonymousResource> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromBaseResource(this);
}
public static class Builder extends BaseResource.Builder<AnonymousResource> {
/**
* {@inheritDoc}
*/
@Override
public AnonymousResource build() {
return new AnonymousResource(href, type);
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<AnonymousResource> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@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<String, String> in) {
return Builder.class.cast(super.fromAttributes(in));
}
}
private AnonymousResource(URI href, String type) {
super(href, type);
}
protected AnonymousResource() {
//For JAXB
}
}

View File

@ -0,0 +1,98 @@
/**
* 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.AnonymousResource;
import javax.xml.bind.annotation.XmlElement;
/**
* <xs:complexType name="ComputePoolPerformanceStatistic">
* @author Jason King
*
*/
public class ComputePoolPerformanceStatistic {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromComputePoolPerformanceStatistic(this);
}
public static class Builder {
private AnonymousResource cpu;
private AnonymousResource memory;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolPerformanceStatistic#getCpu
*/
public Builder cpu(AnonymousResource cpu) {
this.cpu = cpu;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolPerformanceStatistic#getMemory
*/
public Builder memory(AnonymousResource memory) {
this.memory = memory;
return this;
}
public ComputePoolPerformanceStatistic build() {
return new ComputePoolPerformanceStatistic(cpu, memory);
}
public Builder fromComputePoolPerformanceStatistic(ComputePoolPerformanceStatistic in) {
return cpu(in.getCpu()).memory(in.getMemory());
}
}
@XmlElement(name = "Cpu", required = false)
private AnonymousResource cpu;
@XmlElement(name = "Memory", required = false)
private AnonymousResource memory;
private ComputePoolPerformanceStatistic(@Nullable AnonymousResource cpu, @Nullable AnonymousResource memory) {
this.cpu = cpu;
this.memory = memory;
}
private ComputePoolPerformanceStatistic() {
//For JAXB
}
public AnonymousResource getCpu() {
return cpu;
}
public AnonymousResource getMemory() {
return memory;
}
@Override
public String toString() {
return "cpu="+cpu+", memory="+memory;
}
}

View File

@ -0,0 +1,202 @@
/**
* 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.Map;
import java.util.Set;
/**
* <xs:complexType name="ComputePoolPerformanceStatistics">
* @author Jason King
*
*/
@XmlRootElement(name = "ComputePoolPerformanceStatistics")
public class ComputePoolPerformanceStatistics extends Resource<ComputePoolPerformanceStatistics> {
@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<ComputePoolPerformanceStatistics> {
ComputePoolPerformanceStatistic hourly;
ComputePoolPerformanceStatistic daily;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolPerformanceStatistics#getHourly
*/
public Builder hourly(ComputePoolPerformanceStatistic hourly) {
this.hourly = hourly;
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolPerformanceStatistics#getDaily
*/
public Builder daily(ComputePoolPerformanceStatistic daily) {
this.daily = daily;
return this;
}
@Override
public ComputePoolPerformanceStatistics build() {
return new ComputePoolPerformanceStatistics(href, type, name, links, actions, hourly, daily);
}
public Builder fromComputePoolResourceSummary(ComputePoolPerformanceStatistics in) {
return fromResource(in).hourly(in.getHourly()).daily(in.getDaily());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<ComputePoolPerformanceStatistics> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<ComputePoolPerformanceStatistics> 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 = "Hourly", required = false)
ComputePoolPerformanceStatistic hourly;
@XmlElement(name = "Daily", required = false)
ComputePoolPerformanceStatistic daily;
private ComputePoolPerformanceStatistics(URI href, String type, String name, Set<Link> links, Set<Action> actions,
@Nullable ComputePoolPerformanceStatistic hourly, @Nullable ComputePoolPerformanceStatistic daily) {
super(href, type, name, links, actions);
this.hourly = hourly;
this.daily = daily;
}
private ComputePoolPerformanceStatistics() {
//For JAXB
}
public ComputePoolPerformanceStatistic getHourly() {
return hourly;
}
public ComputePoolPerformanceStatistic getDaily() {
return daily;
}
@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;
ComputePoolPerformanceStatistics that = (ComputePoolPerformanceStatistics) o;
if (daily != null ? !daily.equals(that.daily) : that.daily != null)
return false;
if (hourly != null ? !hourly.equals(that.hourly) : that.hourly != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (hourly != null ? hourly.hashCode() : 0);
result = 31 * result + (daily != null ? daily.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", hourly="+hourly+", daily="+daily;
}
}

View File

@ -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.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* <xs:complexType name="PerformanceStatistic">
* @author Jason King
*
*/
@XmlRootElement(name = "PerformanceStatistic")
public class PerformanceStatistic {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromPerformanceStatistic(this);
}
public static class Builder {
private Date time;
private ResourceCapacity used;
/**
* @see PerformanceStatistic#getTime
*/
public Builder time(Date time) {
this.time =(checkNotNull(time,"time"));
return this;
}
/**
* @see PerformanceStatistic#getUsed
*/
public Builder used(ResourceCapacity used) {
this.used =(checkNotNull(used,"used"));
return this;
}
public PerformanceStatistic build() {
return new PerformanceStatistic(time,used);
}
public Builder fromPerformanceStatistic(PerformanceStatistic in) {
return time(in.getTime()).used(in.getUsed());
}
}
@XmlElement(name = "Time", required = true)
private Date time;
@XmlElement(name = "Used", required = false)
private ResourceCapacity used;
private PerformanceStatistic(Date time, ResourceCapacity used) {
this.time = checkNotNull(time, "time");
this.used = used;
}
private PerformanceStatistic() {
//For JAXB
}
public Date getTime() {
return time;
}
public ResourceCapacity getUsed() {
return used;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PerformanceStatistic that = (PerformanceStatistic) o;
if (!time.equals(that.time)) return false;
if (used != null ? !used.equals(that.used) : that.used != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = time.hashCode();
result = 31 * result + (used != null ? used.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "[time="+time+", used="+used+"]";
}
}

View File

@ -0,0 +1,224 @@
/**
* 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;
/**
* PerformanceStatistics is more than a simple wrapper as it extends BaseResource.
* <xs:complexType name="PerformanceStatistics">
* @author Jason King
*
*/
@XmlRootElement(name = "PerformanceStatistics")
public class PerformanceStatistics extends Resource<PerformanceStatistics> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromPerformanceStatistics(this);
}
public static class Builder extends Resource.Builder<PerformanceStatistics> {
private Date startTime;
private Date endTime;
private VirtualMachinePerformanceStatistics statistics;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.PerformanceStatistics#getStartTime
*/
public Builder startTime(Date startTime) {
this.startTime =(checkNotNull(startTime,"startTime"));
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.PerformanceStatistics#getEndTime
*/
public Builder endTime(Date endTime) {
this.endTime =(checkNotNull(endTime,"endTime"));
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.PerformanceStatistics#getStatistics
*/
public Builder statistics(VirtualMachinePerformanceStatistics statistics) {
this.statistics =(checkNotNull(statistics,"statistics"));
return this;
}
@Override
public PerformanceStatistics build() {
return new PerformanceStatistics(href, type, name, links, actions, startTime, endTime, statistics);
}
public Builder fromPerformanceStatistics(PerformanceStatistics in) {
return fromResource(in).startTime(in.getStartTime()).endTime(in.getEndTime()).statistics(in.getStatistics());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<PerformanceStatistics> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<PerformanceStatistics> 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 = "VirtualMachines", required = false)
private VirtualMachinePerformanceStatistics statistics;
private PerformanceStatistics(URI href, String type, String name, Set<Link> links, Set<Action> actions,
Date startTime, Date endTime, @Nullable VirtualMachinePerformanceStatistics statistics) {
super(href, type, name, links, actions);
this.startTime = startTime;
this.endTime = endTime;
this.statistics = statistics;
}
private PerformanceStatistics() {
//For JAXB
}
public Date getStartTime() {
return startTime;
}
public Date getEndTime() {
return endTime;
}
public VirtualMachinePerformanceStatistics getStatistics() {
return statistics;
}
@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;
PerformanceStatistics that = (PerformanceStatistics) o;
if (!endTime.equals(that.endTime)) return false;
if (!startTime.equals(that.startTime)) return false;
if (statistics != null ? !statistics.equals(that.statistics) : that.statistics != 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 + (statistics != null ? statistics.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", startTime="+ startTime+", endTime="+ endTime+", statistics="+ statistics;
}
}

View File

@ -0,0 +1,184 @@
/**
* 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 com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
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 java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* VirtualMachinePerformanceStatistic is more than a simple wrapper as it extends BaseResource.
* <xs:complexType name="VirtualMachinePerformanceStatistic">
* @author Jason King
*
*/
public class VirtualMachinePerformanceStatistic extends Resource<VirtualMachinePerformanceStatistic> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromVirtualMachinePerformanceStatistic(this);
}
public static class Builder extends Resource.Builder<VirtualMachinePerformanceStatistic> {
private Set<PerformanceStatistic> statistics = Sets.newLinkedHashSet();
/**
* @see VirtualMachinePerformanceStatistic#getStatistics
*/
public Builder statistics(Set<PerformanceStatistic> statistics) {
this.statistics =(checkNotNull(statistics,"statistics"));
return this;
}
@Override
public VirtualMachinePerformanceStatistic build() {
return new VirtualMachinePerformanceStatistic(href, type, name, links, actions, statistics);
}
public Builder fromVirtualMachinePerformanceStatistic(VirtualMachinePerformanceStatistic in) {
return fromResource(in).statistics(in.getStatistics());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<VirtualMachinePerformanceStatistic> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<VirtualMachinePerformanceStatistic> 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 = "PerformanceStatistic", required = false)
private Set<PerformanceStatistic> statistics = Sets.newLinkedHashSet();
private VirtualMachinePerformanceStatistic(URI href, String type, String name, Set<Link> links, Set<Action> actions, Set<PerformanceStatistic> statistics) {
super(href, type, name, links, actions);
this.statistics = ImmutableSet.copyOf(statistics);
}
private VirtualMachinePerformanceStatistic() {
//For JAXB
}
public Set<PerformanceStatistic> getStatistics() {
return Collections.unmodifiableSet(statistics);
}
@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;
VirtualMachinePerformanceStatistic templates = (VirtualMachinePerformanceStatistic) o;
if (statistics != null ? !statistics.equals(templates.statistics) : templates.statistics != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (statistics != null ? statistics.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", statistics="+ statistics;
}
}

View File

@ -0,0 +1,102 @@
/**
* 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 com.google.common.collect.ImmutableSet;
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 VirtualMachinePerformanceStatistic elements.
* Needed because parsing is done with JAXB and it does not handle Generic collections
* @author Jason King
*/
public class VirtualMachinePerformanceStatistics {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromVirtualMachinePerformanceStatistics(this);
}
public static class Builder {
private Set<VirtualMachinePerformanceStatistic> virtualMachines = Sets.newLinkedHashSet();
/**
* @see VirtualMachinePerformanceStatistics#getVirtualMachinesPerformanceStatistics
*/
public Builder virtualMachines(Set<VirtualMachinePerformanceStatistic> virtualMachines) {
this.virtualMachines = Sets.newLinkedHashSet(checkNotNull(virtualMachines, "virtualMachines"));
return this;
}
public VirtualMachinePerformanceStatistics build() {
return new VirtualMachinePerformanceStatistics(virtualMachines);
}
public Builder fromVirtualMachinePerformanceStatistics(VirtualMachinePerformanceStatistics in) {
return virtualMachines(in.getVirtualMachinesPerformanceStatistics());
}
}
@XmlElement(name = "VirtualMachine", required = false)
private Set<VirtualMachinePerformanceStatistic> virtualMachines = Sets.newLinkedHashSet();
private VirtualMachinePerformanceStatistics() {
//For JAXB
}
private VirtualMachinePerformanceStatistics(Set<VirtualMachinePerformanceStatistic> virtualMachines) {
this.virtualMachines = ImmutableSet.copyOf(virtualMachines);
}
public Set<VirtualMachinePerformanceStatistic> getVirtualMachinesPerformanceStatistics() {
return Collections.unmodifiableSet(virtualMachines);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VirtualMachinePerformanceStatistics links1 = (VirtualMachinePerformanceStatistics) o;
if (!virtualMachines.equals(links1.virtualMachines)) return false;
return true;
}
@Override
public int hashCode() {
return virtualMachines.hashCode();
}
public String toString() {
return "["+ virtualMachines.toString()+"]";
}
}

View File

@ -0,0 +1,183 @@
/**
* 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.storage;
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.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* ComputePoolStorageUsageDetail is more than a simple wrapper as it extends Resource.
* <xs:complexType name="ComputePoolStorageUsageDetail">
* @author Jason King
*
*/
@XmlRootElement(name = "ComputePoolStorageUsageDetail")
public class ComputePoolStorageUsageDetail extends Resource<ComputePoolStorageUsageDetail> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromComputePoolStorageUsageDetail(this);
}
public static class Builder extends Resource.Builder<ComputePoolStorageUsageDetail> {
private ResourceCapacity allocated;
private VirtualMachinesStorageDetails virtualMachinesStorageDetails;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail#getAllocated
*/
public Builder allocated(ResourceCapacity allocated) {
this.allocated =(checkNotNull(allocated,"allocated"));
return this;
}
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail#getVirtualMachinesStorageDetails
*/
public Builder virtualMachines(VirtualMachinesStorageDetails virtualMachinesStorageDetails) {
this.virtualMachinesStorageDetails =(checkNotNull(virtualMachinesStorageDetails,"virtualMachinesStorageDetails"));
return this;
}
@Override
public ComputePoolStorageUsageDetail build() {
return new ComputePoolStorageUsageDetail(href, type, name, links, actions, allocated, virtualMachinesStorageDetails);
}
public Builder fromComputePoolStorageUsageDetail(ComputePoolStorageUsageDetail in) {
return fromResource(in).allocated(in.getAllocated()).virtualMachines(in.getVirtualMachinesStorageDetails());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<ComputePoolStorageUsageDetail> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<ComputePoolStorageUsageDetail> 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 = "Allocated", required = false)
private ResourceCapacity allocated;
@XmlElement(name = "VirtualMachines", required = false)
private VirtualMachinesStorageDetails virtualMachinesStorageDetails;
private ComputePoolStorageUsageDetail(URI href, String type, String name, Set<Link> links, Set<Action> actions, @Nullable ResourceCapacity allocated, @Nullable VirtualMachinesStorageDetails virtualMachinesStorageDetails) {
super(href, type, name, links, actions);
this.allocated = allocated;
this.virtualMachinesStorageDetails = virtualMachinesStorageDetails;
}
private ComputePoolStorageUsageDetail() {
//For JAXB
}
public ResourceCapacity getAllocated() {
return allocated;
}
public VirtualMachinesStorageDetails getVirtualMachinesStorageDetails() {
return virtualMachinesStorageDetails;
}
@Override
public String string() {
return super.string()+", allocated="+ allocated +", virtualMachinesStorageDetails="+ virtualMachinesStorageDetails;
}
}

View File

@ -0,0 +1,204 @@
/**
* 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.storage;
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.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* VirtualMachineStorageUsageDetail is more than a simple wrapper as it extends Resource.
* <xs:complexType name="VirtualMachineStorageUsageDetail">
* @author Jason King
*
*/
@XmlRootElement(name = "VirtualMachineStorageUsageDetail")
public class VirtualMachineStorageUsageDetail extends Resource<VirtualMachineStorageUsageDetail> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromVirtualMachineStorageUsageDetail(this);
}
public static class Builder extends Resource.Builder<VirtualMachineStorageUsageDetail> {
private int diskCount;
private ResourceCapacity allocated;
/**
* @see VirtualMachineStorageUsageDetail#getDiskCount
*/
public Builder diskCount(int diskCount) {
this.diskCount =(checkNotNull(diskCount,"diskCount"));
return this;
}
/**
* @see VirtualMachineStorageUsageDetail#getAllocated
*/
public Builder allocated(ResourceCapacity allocated) {
this.allocated =(checkNotNull(allocated,"allocated"));
return this;
}
@Override
public VirtualMachineStorageUsageDetail build() {
return new VirtualMachineStorageUsageDetail(href, type, name, links, actions, diskCount, allocated);
}
public Builder fromVirtualMachineStorageUsageDetail(VirtualMachineStorageUsageDetail in) {
return fromResource(in).diskCount(in.getDiskCount()).allocated(in.getAllocated());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromBaseResource(BaseResource<VirtualMachineStorageUsageDetail> in) {
return Builder.class.cast(super.fromBaseResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(Resource<VirtualMachineStorageUsageDetail> 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 = "DiskCount", required = true)
private int diskCount;
@XmlElement(name = "Allocated", required = false)
private ResourceCapacity allocated;
private VirtualMachineStorageUsageDetail(URI href, String type, String name, Set<Link> links, Set<Action> actions, int diskCount, @Nullable ResourceCapacity allocated) {
super(href, type, name, links, actions);
this.diskCount = diskCount;
this.allocated = allocated;
}
private VirtualMachineStorageUsageDetail() {
//For JAXB
}
public int getDiskCount() {
return diskCount;
}
public ResourceCapacity getAllocated() {
return allocated;
}
@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;
VirtualMachineStorageUsageDetail that = (VirtualMachineStorageUsageDetail) o;
if (diskCount != that.diskCount) return false;
if (allocated != null ? !allocated.equals(that.allocated) : that.allocated != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + diskCount;
result = 31 * result + (allocated != null ? allocated.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", diskCount="+ diskCount +", allocated="+ allocated;
}
}

View File

@ -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.storage;
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 VirtualMachineStorageUsageDetail elements.
* <xs:complexType name="StorageDetails_VirtualMachines">
* @author Jason King
*/
public class VirtualMachinesStorageDetails {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromStorageUsageDetails(this);
}
public static class Builder {
private Set<VirtualMachineStorageUsageDetail> virtualMachinesStorageUsageDetail = Sets.newLinkedHashSet();
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.resource.storage.VirtualMachinesStorageDetails#getVirtualMachinesStorageUsageDetail
*/
public Builder vmStorageUsageDetails(Set<VirtualMachineStorageUsageDetail> vmStorageUsageDetails) {
this.virtualMachinesStorageUsageDetail = Sets.newLinkedHashSet(checkNotNull(vmStorageUsageDetails, "vmStorageUsageDetails"));
return this;
}
public Builder addVmStorageUsageDetail(VirtualMachineStorageUsageDetail vmStorageUsageDetails) {
virtualMachinesStorageUsageDetail.add(checkNotNull(vmStorageUsageDetails,"vmStorageUsageDetails"));
return this;
}
public VirtualMachinesStorageDetails build() {
return new VirtualMachinesStorageDetails(virtualMachinesStorageUsageDetail);
}
public Builder fromStorageUsageDetails(VirtualMachinesStorageDetails in) {
return vmStorageUsageDetails(in.getVirtualMachinesStorageUsageDetail());
}
}
private VirtualMachinesStorageDetails() {
//For JAXB and builder use
}
private VirtualMachinesStorageDetails(Set<VirtualMachineStorageUsageDetail> virtualMachinesStorageUsageDetail) {
this.virtualMachinesStorageUsageDetail = Sets.newLinkedHashSet(virtualMachinesStorageUsageDetail);
}
@XmlElement(name = "VirtualMachine", required=false)
private Set<VirtualMachineStorageUsageDetail> virtualMachinesStorageUsageDetail = Sets.newLinkedHashSet();
public Set<VirtualMachineStorageUsageDetail> getVirtualMachinesStorageUsageDetail() {
return Collections.unmodifiableSet(virtualMachinesStorageUsageDetail);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VirtualMachinesStorageDetails that = (VirtualMachinesStorageDetails) o;
if (virtualMachinesStorageUsageDetail != null ? !virtualMachinesStorageUsageDetail.equals(that.virtualMachinesStorageUsageDetail) : that.virtualMachinesStorageUsageDetail != null)
return false;
return true;
}
@Override
public int hashCode() {
return virtualMachinesStorageUsageDetail != null ? virtualMachinesStorageUsageDetail.hashCode() : 0;
}
public String toString() {
return "["+ virtualMachinesStorageUsageDetail.toString()+"]";
}
}

View File

@ -22,12 +22,15 @@ 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.ComputePoolPerformanceStatistics;
import org.jclouds.tmrk.enterprisecloud.domain.resource.PerformanceStatistics;
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 org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@ -100,4 +103,31 @@ public interface ResourceAsyncClient {
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ComputePoolMemoryUsageDetail> getComputePoolMemoryUsageDetail(@EndpointParam URI uri);
/**
* @see ResourceClient#getComputePoolStorageUsage
*/
@GET
@Consumes("application/vnd.tmrk.cloud.computePoolStorageUsageDetail")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ComputePoolStorageUsageDetail> getComputePoolStorageUsage(@EndpointParam URI uri);
/**
* @see ResourceClient#getComputePoolPerformanceStatistics
*/
@GET
@Consumes("application/vnd.tmrk.cloud.computePoolPerformanceStatistics")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ComputePoolPerformanceStatistics> getComputePoolPerformanceStatistics(@EndpointParam URI uri);
/**
* @see ResourceClient#getDailyCpuPerformanceStatistics
*/
@GET
@Consumes("application/vnd.tmrk.cloud.performanceStatistics")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<PerformanceStatistics> getDailyCpuPerformanceStatistics(@EndpointParam URI uri);
}

View File

@ -19,12 +19,15 @@
package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.concurrent.Timeout;
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolPerformanceStatistics;
import org.jclouds.tmrk.enterprisecloud.domain.resource.PerformanceStatistics;
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 org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail;
import java.net.URI;
import java.util.concurrent.TimeUnit;
@ -131,4 +134,39 @@ public interface ResourceClient {
* @return the compute pool memory usage detail
*/
ComputePoolMemoryUsageDetail getComputePoolMemoryUsageDetail(URI uri);
/**
* The Get Resources Usage Storage call returns information regarding current storage usage
* for a specified compute pool defined in an environment for active virtual machines.
* The response includes usage of every active virtual machine.
* @param uri the uri of the call based upon the compute pool
* e.g. /cloudapi/ecloud/computepools/{id}/usage/storage
* @return the compute pool storage usage detail
*/
ComputePoolStorageUsageDetail getComputePoolStorageUsage(URI uri);
/**
* The Get Resources Performance Statistics call returns references to obtain
* the individual performance statistics reports in a compute pool.
* @param uri the uri of the call based upon the compute pool
* e.g. /cloudapi/ecloud/computepools/{id}/performanceStatistics
* @return
*/
ComputePoolPerformanceStatistics getComputePoolPerformanceStatistics(URI uri);
/**
* The Get Resources Performance Statistics Processor Daily call returns daily
* information regarding processor performance for a specified compute pool
*
* returns statistics for the previous seven days.
*
* The default endTime is midnight the beginning of the current day and the default
* startTime is midnight seven days prior to the endTime.
* For example, if the call is made at 2011-07-12T14:48:00Z, then startTime is 2011-07-05T00:00:00Z
* and endTime is 2011-07-12T00:00:00Z.
* @param uri uri the uri of the call based upon the compute pool
* e.g. /cloudapi/ecloud/computepools/{id}/usage/cpu/performanceStatistics/daily
* @return
*/
PerformanceStatistics getDailyCpuPerformanceStatistics(URI uri);
}

View File

@ -128,6 +128,51 @@ public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncCl
checkFilters(httpRequest);
}
public void testGetComputePoolStorageUsage() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = ResourceAsyncClient.class.getMethod("getComputePoolStorageUsage", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/computepools/89/usage/storage"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/computepools/89/usage/storage HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.computePoolStorageUsageDetail\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetComputePoolPerformanceStatistics() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = ResourceAsyncClient.class.getMethod("getComputePoolPerformanceStatistics", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/computepools/89/performancestatistics"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/computepools/89/performancestatistics HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.computePoolPerformanceStatistics\nx-tmrk-version: 2011-07-01\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetDailyCpuPerformanceStatistics() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
Method method = ResourceAsyncClient.class.getMethod("getDailyCpuPerformanceStatistics", URI.class);
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily"));
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest,
"Accept: application/vnd.tmrk.cloud.performanceStatistics\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>>() {

View File

@ -20,12 +20,14 @@ package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.resource.PerformanceStatistics;
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 org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsage;
import org.jclouds.tmrk.enterprisecloud.domain.resource.memory.ComputePoolMemoryUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -114,4 +116,14 @@ public class ResourceClientLiveTest extends BaseTerremarkEnterpriseCloudClientLi
ComputePoolMemoryUsageDetail detail = client.getComputePoolMemoryUsageDetail(uri);
assertNotNull(detail.getTime());
}
public void testGetComputePoolStorageUsage() throws Exception {
ComputePoolStorageUsageDetail usage = client.getComputePoolStorageUsage(URI.create("/cloudapi/ecloud/computepools/89/usage/storage"));
assertNotNull(usage);
}
public void testGetDailyCpuPerformanceStatistics() throws Exception {
PerformanceStatistics stats = client.getDailyCpuPerformanceStatistics(URI.create("/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily"));
assertNotNull(stats);
}
}

View File

@ -0,0 +1,117 @@
/**
* 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.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import org.jclouds.crypto.Crypto;
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.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolPerformanceStatistics;
import org.jclouds.tmrk.enterprisecloud.features.ResourceAsyncClient;
import org.testng.annotations.BeforeClass;
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 ComputePoolPerformanceStatistics
*
* @author Jason King
*/
@Test(groups = "unit", testName = "ComputePoolPerformanceStatisticsJAXBParsingTest")
public class ComputePoolPerformanceStatisticsJAXBParsingTest extends BaseRestClientTest {
@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);
}
public void testParseWithJAXB() throws Exception {
Method method = ResourceAsyncClient.class.getMethod("getComputePoolPerformanceStatistics", URI.class);
HttpRequest request = factory(ResourceAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, ComputePoolPerformanceStatistics> parser = (Function<HttpResponse, ComputePoolPerformanceStatistics>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/computePoolPerformanceStatistics.xml");
ComputePoolPerformanceStatistics stats = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertLinks(stats.getLinks());
assertEquals(stats.getHourly().getCpu(), createResource("cpu", "hourly"));
assertEquals(stats.getDaily().getCpu(), createResource("cpu", "daily"));
assertEquals(stats.getHourly().getMemory(), createResource("memory", "hourly"));
assertEquals(stats.getDaily().getMemory(), createResource("memory", "daily"));
}
private AnonymousResource createResource(String type, String period) {
return AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/computepools/89/usage/"+type+"/performancestatistics/"+period))
.type("application/vnd.tmrk.cloud.performanceStatistics")
.build();
}
private void assertLinks(Set<Link> links) {
assertEquals(links.size(),1);
Link link = Iterables.get(links, 0);
assertEquals(link.getName(),"Default Compute Pool");
assertEquals(link.getRelationship(), Link.Relationship.UP);
}
}

View File

@ -0,0 +1,120 @@
/**
* 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.common.collect.Iterables;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import org.jclouds.crypto.Crypto;
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.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.ComputePoolStorageUsageDetail;
import org.jclouds.tmrk.enterprisecloud.domain.resource.storage.VirtualMachineStorageUsageDetail;
import org.jclouds.tmrk.enterprisecloud.features.ResourceAsyncClient;
import org.testng.annotations.BeforeClass;
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 ComputePoolStorageUsageDetail
*
* @author Jason King
*/
@Test(groups = "unit", testName = "ComputePoolStorageUsageDetailJAXBParsingTest")
public class ComputePoolStorageUsageDetailJAXBParsingTest extends BaseRestClientTest {
@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);
}
public void testParseWithJAXB() throws Exception {
Method method = ResourceAsyncClient.class.getMethod("getComputePoolStorageUsage", URI.class);
HttpRequest request = factory(ResourceAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, ComputePoolStorageUsageDetail> parser = (Function<HttpResponse, ComputePoolStorageUsageDetail>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/computePoolStorageUsage.xml");
ComputePoolStorageUsageDetail storageUsageDetail = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertLinks(storageUsageDetail.getLinks());
assertEquals(storageUsageDetail.getAllocated(), ResourceCapacity.builder().value(10).unit("GB").build());
assertStorageDetails(storageUsageDetail.getVirtualMachinesStorageDetails().getVirtualMachinesStorageUsageDetail());
}
private void assertStorageDetails(Set<VirtualMachineStorageUsageDetail> virtualMachinesStorageUsageDetail) {
assertEquals(1, virtualMachinesStorageUsageDetail.size());
VirtualMachineStorageUsageDetail detail = Iterables.getOnlyElement(virtualMachinesStorageUsageDetail);
assertEquals(detail.getDiskCount(),1);
assertEquals(detail.getAllocated(), ResourceCapacity.builder().value(10).unit("GB").build());
}
private void assertLinks(Set<Link> links) {
assertEquals(links.size(),1);
Link link = Iterables.get(links, 0);
assertEquals(link.getName(),"Default Compute Pool");
assertEquals(link.getRelationship(), Link.Relationship.UP);
}
}

View File

@ -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.xml;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
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.resource.PerformanceStatistic;
import org.jclouds.tmrk.enterprisecloud.domain.resource.PerformanceStatistics;
import org.jclouds.tmrk.enterprisecloud.domain.resource.VirtualMachinePerformanceStatistic;
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;
import static org.testng.Assert.assertNotNull;
/**
* Tests behavior of JAXB parsing for PerformanceStatistics
*
* @author Jason King
*/
@Test(groups = "unit", testName = "PerformanceStatisticsJAXBParsingTest")
public class PerformanceStatisticsJAXBParsingTest 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);
}
public void testParseWithJAXB() throws Exception {
Method method = ResourceAsyncClient.class.getMethod("getDailyCpuPerformanceStatistics", URI.class);
HttpRequest request = factory(ResourceAsyncClient.class).createRequest(method,new URI("/1"));
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
Function<HttpResponse, PerformanceStatistics> parser = (Function<HttpResponse, PerformanceStatistics>) RestAnnotationProcessor
.createResponseParser(parserFactory, injector, method, request);
InputStream is = getClass().getResourceAsStream("/computePoolPerformanceStatisticsDaily.xml");
PerformanceStatistics statistics = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertEquals(statistics.getLinks().size(),2);
assertEquals(statistics.getStartTime(),dateService.iso8601DateParse("2011-11-30T00:00:00.0Z"));
assertEquals(statistics.getEndTime(),dateService.iso8601DateParse("2011-12-06T00:00:00.0Z"));
assertVirtalMachineStatistics(statistics.getStatistics().getVirtualMachinesPerformanceStatistics());
}
private void assertVirtalMachineStatistics(Set<VirtualMachinePerformanceStatistic> vmStatistics) {
assertEquals(vmStatistics.size(),1);
VirtualMachinePerformanceStatistic statistic = Iterables.getOnlyElement(vmStatistics);
assertEquals(statistic.getStatistics().size(), 7);
for(PerformanceStatistic stat: statistic.getStatistics()) {
assertNotNull(stat.getTime());
assertNotNull(stat.getUsed());
}
}
}

View File

@ -0,0 +1,22 @@
<ComputePoolPerformanceStatistics
href="/cloudapi/ecloud/computepools/89/performancestatistics"
type="application/vnd.tmrk.cloud.computePoolPerformanceStatistics"
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>
<Hourly>
<Cpu href="/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/hourly"
type="application/vnd.tmrk.cloud.performanceStatistics"/>
<Memory href="/cloudapi/ecloud/computepools/89/usage/memory/performancestatistics/hourly"
type="application/vnd.tmrk.cloud.performanceStatistics"/>
</Hourly>
<Daily>
<Cpu href="/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily"
type="application/vnd.tmrk.cloud.performanceStatistics"/>
<Memory href="/cloudapi/ecloud/computepools/89/usage/memory/performancestatistics/daily"
type="application/vnd.tmrk.cloud.performanceStatistics"/>
</Daily>
</ComputePoolPerformanceStatistics>

View File

@ -0,0 +1,70 @@
<PerformanceStatistics
href="/cloudapi/ecloud/computepools/89/usage/cpu/performancestatistics/daily?starttime=2011-11-30t00%3a00%3a00z&amp;endtime=2011-12-06t00%3a00%3a00z"
type="application/vnd.tmrk.cloud.performanceStatistics"
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"/>
<Link href="/cloudapi/ecloud/computepools/89/performancestatistics"
type="application/vnd.tmrk.cloud.computePoolPerformanceStatistics"
rel="up"/>
</Links>
<StartTime>2011-11-30T00:00:00Z</StartTime>
<EndTime>2011-12-06T00:00:00Z</EndTime>
<VirtualMachines>
<VirtualMachine href="/cloudapi/ecloud/virtualmachines/5504"
name="helloworld"
type="application/vnd.tmrk.cloud.virtualMachine">
<PerformanceStatistic>
<Time>2011-11-30T00:00:00Z</Time>
<Used>
<Unit>MHz</Unit>
<Value>43</Value>
</Used>
</PerformanceStatistic>
<PerformanceStatistic>
<Time>2011-12-01T00:00:00Z</Time>
<Used>
<Unit>MHz</Unit>
<Value>43</Value>
</Used>
</PerformanceStatistic>
<PerformanceStatistic>
<Time>2011-12-02T00:00:00Z</Time>
<Used>
<Unit>MHz</Unit>
<Value>42</Value>
</Used>
</PerformanceStatistic>
<PerformanceStatistic>
<Time>2011-12-03T00:00:00Z</Time>
<Used>
<Unit>MHz</Unit>
<Value>43</Value>
</Used>
</PerformanceStatistic>
<PerformanceStatistic>
<Time>2011-12-04T00:00:00Z</Time>
<Used>
<Unit>MHz</Unit>
<Value>44</Value>
</Used>
</PerformanceStatistic>
<PerformanceStatistic>
<Time>2011-12-05T00:00:00Z</Time>
<Used>
<Unit>MHz</Unit>
<Value>42</Value>
</Used>
</PerformanceStatistic>
<PerformanceStatistic>
<Time>2011-12-06T00:00:00Z</Time>
<Used>
<Unit>MHz</Unit>
<Value>43</Value>
</Used>
</PerformanceStatistic>
</VirtualMachine>
</VirtualMachines>
</PerformanceStatistics>

View File

@ -0,0 +1,25 @@
<ComputePoolStorageUsageDetail
href="/cloudapi/ecloud/computepools/89/usage/storage"
type="application/vnd.tmrk.cloud.computePoolStorageUsageDetail"
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>
<Allocated>
<Unit>GB</Unit>
<Value>10</Value>
</Allocated>
<VirtualMachines>
<VirtualMachine href="/cloudapi/ecloud/virtualmachines/5504"
name="helloworld"
type="application/vnd.tmrk.cloud.virtualMachine">
<DiskCount>1</DiskCount>
<Allocated>
<Unit>GB</Unit>
<Value>10</Value>
</Allocated>
</VirtualMachine>
</VirtualMachines>
</ComputePoolStorageUsageDetail>