diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/AnonymousResource.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/AnonymousResource.java new file mode 100644 index 0000000000..0ffeb4cbe3 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/AnonymousResource.java @@ -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 { + + @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 { + + /** + * {@inheritDoc} + */ + @Override + public AnonymousResource build() { + return new AnonymousResource(href, type); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromBaseResource(BaseResource 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 in) { + return Builder.class.cast(super.fromAttributes(in)); + } + + } + + private AnonymousResource(URI href, String type) { + super(href, type); + } + + protected AnonymousResource() { + //For JAXB + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/ComputePoolPerformanceStatistic.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/ComputePoolPerformanceStatistic.java new file mode 100644 index 0000000000..8b4999b020 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/ComputePoolPerformanceStatistic.java @@ -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; + +/** + * + * @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; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/ComputePoolPerformanceStatistics.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/ComputePoolPerformanceStatistics.java new file mode 100644 index 0000000000..5a67b45ac0 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/resource/ComputePoolPerformanceStatistics.java @@ -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; + +/** + * + * @author Jason King + * + */ +@XmlRootElement(name = "ComputePoolPerformanceStatistics") +public class ComputePoolPerformanceStatistics extends Resource { + + @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 { + 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 in) { + return Builder.class.cast(super.fromBaseResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(Resource in) { + return Builder.class.cast(super.fromResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder links(Set links) { + return Builder.class.cast(super.links(links)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder actions(Set actions) { + return Builder.class.cast(super.actions(actions)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromAttributes(Map attributes) { + return Builder.class.cast(super.fromAttributes(attributes)); + } + + } + + @XmlElement(name = "Hourly", required = false) + ComputePoolPerformanceStatistic hourly; + + @XmlElement(name = "Daily", required = false) + ComputePoolPerformanceStatistic daily; + + private ComputePoolPerformanceStatistics(URI href, String type, String name, Set links, Set 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; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java index 5d0ea17397..6f9cff078f 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClient.java @@ -22,6 +22,7 @@ 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.cpu.ComputePoolCpuUsage; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList; @@ -110,4 +111,13 @@ public interface ResourceAsyncClient { @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getComputePoolStorageUsage(@EndpointParam URI uri); + + /** + * @see ResourceClient#getComputePoolPerformanceStatistics + */ + @GET + @Consumes("application/vnd.tmrk.cloud.computePoolPerformanceStatistics") + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getComputePoolPerformanceStatistics(@EndpointParam URI uri); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java index 812af819a1..6c435f7d8a 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/ResourceClient.java @@ -19,6 +19,7 @@ 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.cpu.ComputePoolCpuUsage; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummary; import org.jclouds.tmrk.enterprisecloud.domain.resource.ComputePoolResourceSummaryList; @@ -142,4 +143,13 @@ public interface ResourceClient { * @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); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClientTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClientTest.java index a54b706f87..6898e29f57 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClientTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/ResourceAsyncClientTest.java @@ -143,6 +143,22 @@ public class ResourceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncCl 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); + } + + @Override protected TypeLiteral> createTypeLiteral() { return new TypeLiteral>() { diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolPerformanceStatisticsJAXBParsingTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolPerformanceStatisticsJAXBParsingTest.java new file mode 100644 index 0000000000..f7731852c7 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/ComputePoolPerformanceStatisticsJAXBParsingTest.java @@ -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 contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo", + "credentialFoo", String.class, Integer.class, + ImmutableSet.of(new MockModule(), new NullLoggingModule(), new AbstractModule() { + + @Override + protected void configure() { + } + + @SuppressWarnings("unused") + @Provides + @Named("exception") + Set 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 parser = (Function) 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 links) { + assertEquals(links.size(),1); + Link link = Iterables.get(links, 0); + assertEquals(link.getName(),"Default Compute Pool"); + assertEquals(link.getRelationship(), Link.Relationship.UP); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/resources/computePoolPerformanceStatistics.xml b/sandbox-providers/tmrk-enterprisecloud/src/test/resources/computePoolPerformanceStatistics.xml new file mode 100644 index 0000000000..f7164d4740 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/resources/computePoolPerformanceStatistics.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + \ No newline at end of file