mirror of https://github.com/apache/jclouds.git
Issue 695: Added Template, TemplateStorage,Template*Client, JAXB Test and Test files
This commit is contained in:
parent
1cf89c6b6f
commit
636dafe1d3
|
@ -0,0 +1,301 @@
|
||||||
|
/**
|
||||||
|
* 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.template;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.CustomizationOption;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Links;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <xs:complexType name="Template">
|
||||||
|
* @author Jason King
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@XmlRootElement(name = "Template")
|
||||||
|
public class Template extends BaseNamedResource<Template> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromTask(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends BaseNamedResource.Builder<Template> {
|
||||||
|
//TODO There are additional fields
|
||||||
|
protected Links links;
|
||||||
|
protected OperatingSystem operatingSystem;
|
||||||
|
protected String description;
|
||||||
|
//protected ComputeMatrix computeMatrix;
|
||||||
|
protected ConfigurationOptionRange processor;
|
||||||
|
protected ResourceCapacityRange memory;
|
||||||
|
protected TemplateStorage storage;
|
||||||
|
protected int networkAdapters;
|
||||||
|
protected CustomizationOption customization;
|
||||||
|
//protected DeviceLicensedSoftware licensedSoftware;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getLinks
|
||||||
|
*/
|
||||||
|
public Builder links(Links links) {
|
||||||
|
this.links = links;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getOperatingSystem
|
||||||
|
*/
|
||||||
|
public Builder operatingSystem(OperatingSystem operatingSystem) {
|
||||||
|
this.operatingSystem = operatingSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getDescription
|
||||||
|
*/
|
||||||
|
public Builder description(String description) {
|
||||||
|
this.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getProcessor
|
||||||
|
*/
|
||||||
|
public Builder processor(ConfigurationOptionRange processor) {
|
||||||
|
this.processor = processor;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getMemory
|
||||||
|
*/
|
||||||
|
public Builder memory(ResourceCapacityRange memory) {
|
||||||
|
this.memory = memory;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getStorage
|
||||||
|
*/
|
||||||
|
public Builder storage(TemplateStorage storage) {
|
||||||
|
this.storage = storage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getNetworkAdapters
|
||||||
|
*/
|
||||||
|
public Builder networkAdapters(int networkAdapters) {
|
||||||
|
this.networkAdapters = networkAdapters;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getCustomization
|
||||||
|
*/
|
||||||
|
public Builder customization(CustomizationOption customization) {
|
||||||
|
this.customization = customization;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Template build() {
|
||||||
|
return new Template(href, type, name, links, operatingSystem, description, processor, memory, storage, networkAdapters, customization);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromTask(Template in) {
|
||||||
|
return fromResource(in).description(in.getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromResource(BaseResource<Template> in) {
|
||||||
|
return Builder.class.cast(super.fromResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder name(String name) {
|
||||||
|
return Builder.class.cast(super.type(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Links", required = false)
|
||||||
|
protected Links links;
|
||||||
|
|
||||||
|
@XmlElement(name = "OperatingSystem", required = false)
|
||||||
|
protected OperatingSystem operatingSystem;
|
||||||
|
|
||||||
|
@XmlElement(name = "Description", required = false)
|
||||||
|
protected String description;
|
||||||
|
|
||||||
|
//protected ComputeMatrix computeMatrix;
|
||||||
|
|
||||||
|
@XmlElement(name = "Processor", required = false)
|
||||||
|
protected ConfigurationOptionRange processor;
|
||||||
|
|
||||||
|
@XmlElement(name = "Memory", required = false)
|
||||||
|
protected ResourceCapacityRange memory;
|
||||||
|
|
||||||
|
@XmlElement(name = "Storage", required = false)
|
||||||
|
protected TemplateStorage storage;
|
||||||
|
|
||||||
|
@XmlElement(name = "NetworkAdapters", required = false)
|
||||||
|
protected int networkAdapters;
|
||||||
|
|
||||||
|
@XmlElement(name = "Customization", required = false)
|
||||||
|
protected CustomizationOption customization;
|
||||||
|
|
||||||
|
//protected DeviceLicensedSoftware licensedSoftware;
|
||||||
|
|
||||||
|
private Template(URI href, String type, String name, @Nullable Links links, @Nullable OperatingSystem operatingSystem, @Nullable String description,
|
||||||
|
@Nullable ConfigurationOptionRange processor, @Nullable ResourceCapacityRange memory,
|
||||||
|
@Nullable TemplateStorage storage, @Nullable int networkAdapters, @Nullable CustomizationOption customization) {
|
||||||
|
super(href, type, name);
|
||||||
|
this.links = links;
|
||||||
|
this.operatingSystem = operatingSystem;
|
||||||
|
this.description = description;
|
||||||
|
this.processor = processor;
|
||||||
|
this.memory = memory;
|
||||||
|
this.storage = storage;
|
||||||
|
this.networkAdapters = networkAdapters;
|
||||||
|
this.customization = customization;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Template() {
|
||||||
|
//For JAXB
|
||||||
|
}
|
||||||
|
|
||||||
|
public Links getLinks() {
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationOptionRange getProcessor() {
|
||||||
|
return processor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceCapacityRange getMemory() {
|
||||||
|
return memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TemplateStorage getStorage() {
|
||||||
|
return storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNetworkAdapters() {
|
||||||
|
return networkAdapters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomizationOption getCustomization() {
|
||||||
|
return customization;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperatingSystem getOperatingSystem() {
|
||||||
|
return operatingSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
Template template = (Template) o;
|
||||||
|
|
||||||
|
if (networkAdapters != template.networkAdapters) return false;
|
||||||
|
if (customization != null ? !customization.equals(template.customization) : template.customization != null)
|
||||||
|
return false;
|
||||||
|
if (description != null ? !description.equals(template.description) : template.description != null)
|
||||||
|
return false;
|
||||||
|
if (links != null ? !links.equals(template.links) : template.links != null)
|
||||||
|
return false;
|
||||||
|
if (memory != null ? !memory.equals(template.memory) : template.memory != null)
|
||||||
|
return false;
|
||||||
|
if (operatingSystem != null ? !operatingSystem.equals(template.operatingSystem) : template.operatingSystem != null)
|
||||||
|
return false;
|
||||||
|
if (processor != null ? !processor.equals(template.processor) : template.processor != null)
|
||||||
|
return false;
|
||||||
|
if (storage != null ? !storage.equals(template.storage) : template.storage != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + (links != null ? links.hashCode() : 0);
|
||||||
|
result = 31 * result + (operatingSystem != null ? operatingSystem.hashCode() : 0);
|
||||||
|
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||||
|
result = 31 * result + (processor != null ? processor.hashCode() : 0);
|
||||||
|
result = 31 * result + (memory != null ? memory.hashCode() : 0);
|
||||||
|
result = 31 * result + (storage != null ? storage.hashCode() : 0);
|
||||||
|
result = 31 * result + networkAdapters;
|
||||||
|
result = 31 * result + (customization != null ? customization.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String string() {
|
||||||
|
return super.string()+", links="+ links+", operatingSystem="+ operatingSystem+
|
||||||
|
", description="+ description+", processor="+ processor+
|
||||||
|
", memory="+ memory+", storage="+ storage+
|
||||||
|
", networkAdapters="+ networkAdapters+", customization="+ customization;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,122 @@
|
||||||
|
/**
|
||||||
|
* 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.template;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <xs:complexType name="TemplateStorage">
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
public class TemplateStorage {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromTemplateStorage(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private ResourceCapacity size;
|
||||||
|
private double hourlyCost;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.template.TemplateStorage#getSize
|
||||||
|
*/
|
||||||
|
public Builder size(ResourceCapacity size) {
|
||||||
|
this.size = size;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.template.TemplateStorage#getHourlyCost
|
||||||
|
*/
|
||||||
|
public Builder hourlyCost(double hourlyCost) {
|
||||||
|
this.hourlyCost = hourlyCost;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TemplateStorage build() {
|
||||||
|
return new TemplateStorage(size, hourlyCost);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromTemplateStorage(TemplateStorage in) {
|
||||||
|
return size(in.getSize()).hourlyCost(in.getHourlyCost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Size", required = false)
|
||||||
|
private ResourceCapacity size;
|
||||||
|
|
||||||
|
@XmlElement(name = "HourlyCost", required = false)
|
||||||
|
private double hourlyCost;
|
||||||
|
|
||||||
|
private TemplateStorage(@Nullable ResourceCapacity size, double hourlyCost) {
|
||||||
|
this.size = size;
|
||||||
|
this.hourlyCost = hourlyCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TemplateStorage() {
|
||||||
|
//For JAXB
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceCapacity getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getHourlyCost() {
|
||||||
|
return hourlyCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
TemplateStorage that = (TemplateStorage) o;
|
||||||
|
|
||||||
|
if (Double.compare(that.hourlyCost, hourlyCost) != 0) return false;
|
||||||
|
if (size != null ? !size.equals(that.size) : that.size != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result;
|
||||||
|
long temp;
|
||||||
|
result = size != null ? size.hashCode() : 0;
|
||||||
|
temp = hourlyCost != +0.0d ? Double.doubleToLongBits(hourlyCost) : 0L;
|
||||||
|
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "[size="+ size +", hourlyCost="+ hourlyCost +"]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.template.Template;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to Templates(s) via their REST API.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.features.TemplateClient
|
||||||
|
* @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 TemplateAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.features.TemplateClient#getTemplate
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Consumes("application/vnd.tmrk.cloud.template")
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Template> getTemplate(@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.template.Template;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to Template(s).
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.features.TemplateAsyncClient
|
||||||
|
* @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 TemplateClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Get Templates by ID call returns information regarding a specified template defined in a compute pool
|
||||||
|
* @param uri the uri of the template
|
||||||
|
* @return the template
|
||||||
|
*/
|
||||||
|
Template getTemplate(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 TemplateAsyncClient}
|
||||||
|
*
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "TemplateAsyncClientTest")
|
||||||
|
public class TemplateAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<TemplateAsyncClient> {
|
||||||
|
|
||||||
|
public void testGetTemplate() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||||
|
Method method = TemplateAsyncClient.class.getMethod("getTemplate", URI.class);
|
||||||
|
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/templates/6/computepools/89"));
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/templates/6/computepools/89 HTTP/1.1");
|
||||||
|
assertNonPayloadHeadersEqual(httpRequest,
|
||||||
|
"Accept: application/vnd.tmrk.cloud.template\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<TemplateAsyncClient>> createTypeLiteral() {
|
||||||
|
return new TypeLiteral<RestAnnotationProcessor<TemplateAsyncClient>>() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.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.ConfigurationOptionRange;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.CustomizationOption;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Link;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.template.Template;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.template.TemplateStorage;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.features.TemplateAsyncClient;
|
||||||
|
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.net.URISyntaxException;
|
||||||
|
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 Templates
|
||||||
|
*
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "TemplateJAXBParsingTest")
|
||||||
|
public class TemplateJAXBParsingTest 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 testParseTemplate() throws Exception {
|
||||||
|
|
||||||
|
Method method = TemplateAsyncClient.class.getMethod("getTemplate", URI.class);
|
||||||
|
HttpRequest request = factory(TemplateAsyncClient.class).createRequest(method,new URI("/1"));
|
||||||
|
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||||
|
|
||||||
|
Function<HttpResponse, Template> parser = (Function<HttpResponse, Template>) RestAnnotationProcessor
|
||||||
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
|
InputStream is = getClass().getResourceAsStream("/template.xml");
|
||||||
|
Template template = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||||
|
|
||||||
|
assertLinks(template.getLinks().getLinks());
|
||||||
|
assertOperatingSystem(template.getOperatingSystem());
|
||||||
|
assertEquals(template.getDescription(),"");
|
||||||
|
assertProcessor(template.getProcessor());
|
||||||
|
assertMemory(template.getMemory());
|
||||||
|
assertStorage(template.getStorage());
|
||||||
|
assertEquals(template.getNetworkAdapters(),1);
|
||||||
|
assertCustomization(template.getCustomization());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertLinks(Set<Link> links) {
|
||||||
|
assertEquals(links.size(),1);
|
||||||
|
Link link = Iterables.getOnlyElement(links);
|
||||||
|
assertEquals(link.getName(),"Default Compute Pool");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertOperatingSystem(OperatingSystem os) throws URISyntaxException {
|
||||||
|
OperatingSystem expected = OperatingSystem.builder()
|
||||||
|
.href(new URI("/cloudapi/ecloud/operatingsystems/rhel5_64guest/computepools/89"))
|
||||||
|
.name("Red Hat Enterprise Linux 5 (64-bit)")
|
||||||
|
.type("application/vnd.tmrk.cloud.operatingSystem")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(os,expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertProcessor(ConfigurationOptionRange configuration) {
|
||||||
|
ConfigurationOptionRange expected = ConfigurationOptionRange.builder()
|
||||||
|
.minimum(1).maximum(8).stepFactor(1).build();
|
||||||
|
assertEquals(configuration, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertMemory(ResourceCapacityRange memory) {
|
||||||
|
ResourceCapacity min = ResourceCapacity.builder().value(256).unit("MB").build();
|
||||||
|
ResourceCapacity max = ResourceCapacity.builder().value(261120).unit("MB").build();
|
||||||
|
ResourceCapacity step = ResourceCapacity.builder().value(4).unit("MB").build();
|
||||||
|
ResourceCapacityRange expected = ResourceCapacityRange.builder()
|
||||||
|
.minimumSize(min).maximumSize(max).stepFactor(step).build();
|
||||||
|
|
||||||
|
assertEquals(memory, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertStorage(TemplateStorage storage) {
|
||||||
|
ResourceCapacity size = ResourceCapacity.builder().value(10).unit("GB").build();
|
||||||
|
TemplateStorage expected = TemplateStorage.builder().size(size).build();
|
||||||
|
assertEquals(storage, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertCustomization(CustomizationOption customization) {
|
||||||
|
CustomizationOption expected = CustomizationOption.builder()
|
||||||
|
.canPowerOn(false)
|
||||||
|
.passwordRequired(false)
|
||||||
|
.sshKeyRequired(true)
|
||||||
|
.type(CustomizationOption.CustomizationType.LINUX)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(customization, expected);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
<Template href="/cloudapi/ecloud/templates/6/computepools/89"
|
||||||
|
name="CentOS 5.5 x64" type="application/vnd.tmrk.cloud.template"
|
||||||
|
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>
|
||||||
|
<OperatingSystem
|
||||||
|
href="/cloudapi/ecloud/operatingsystems/rhel5_64guest/computepools/89"
|
||||||
|
name="Red Hat Enterprise Linux 5 (64-bit)"
|
||||||
|
type="application/vnd.tmrk.cloud.operatingSystem"/>
|
||||||
|
<Description/>
|
||||||
|
<Processor>
|
||||||
|
<Minimum>1</Minimum>
|
||||||
|
<Maximum>8</Maximum>
|
||||||
|
<StepFactor>1</StepFactor>
|
||||||
|
</Processor>
|
||||||
|
<Memory>
|
||||||
|
<MinimumSize>
|
||||||
|
<Unit>MB</Unit>
|
||||||
|
<Value>256</Value>
|
||||||
|
</MinimumSize>
|
||||||
|
<MaximumSize>
|
||||||
|
<Unit>MB</Unit>
|
||||||
|
<Value>261120</Value>
|
||||||
|
</MaximumSize>
|
||||||
|
<StepFactor>
|
||||||
|
<Unit>MB</Unit>
|
||||||
|
<Value>4</Value>
|
||||||
|
</StepFactor>
|
||||||
|
</Memory>
|
||||||
|
<Storage>
|
||||||
|
<Size>
|
||||||
|
<Unit>GB</Unit>
|
||||||
|
<Value>10</Value>
|
||||||
|
</Size>
|
||||||
|
</Storage>
|
||||||
|
<NetworkAdapters>1</NetworkAdapters>
|
||||||
|
<Customization>
|
||||||
|
<Type>Linux</Type>
|
||||||
|
<CanPowerOn>false</CanPowerOn>
|
||||||
|
<PasswordRequired>false</PasswordRequired>
|
||||||
|
<SshKeyRequired>true</SshKeyRequired>
|
||||||
|
</Customization>
|
||||||
|
</Template>
|
|
@ -0,0 +1,55 @@
|
||||||
|
<Templates href="/cloudapi/ecloud/templates/computepools/89"
|
||||||
|
type="application/vnd.tmrk.cloud.template; type=collection"
|
||||||
|
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>
|
||||||
|
<Families>
|
||||||
|
<Family>
|
||||||
|
<Name>Standard Templates</Name>
|
||||||
|
<Categories>
|
||||||
|
<Category>
|
||||||
|
<Name>OS Only</Name>
|
||||||
|
<OperatingSystems>
|
||||||
|
<OperatingSystem>
|
||||||
|
<Name>Windows</Name>
|
||||||
|
<Templates>
|
||||||
|
<Template
|
||||||
|
href="/cloudapi/ecloud/templates/2/computepools/89"
|
||||||
|
name="Windows Server 2003 R2 Standard x86 SP2"
|
||||||
|
type="application/vnd.tmrk.cloud.template"/>
|
||||||
|
<Template
|
||||||
|
href="/cloudapi/ecloud/templates/10/computepools/89"
|
||||||
|
name="Windows Server 2008 Standard SP2 x86"
|
||||||
|
type="application/vnd.tmrk.cloud.template"/>
|
||||||
|
<Template
|
||||||
|
href="/cloudapi/ecloud/templates/1/computepools/89"
|
||||||
|
name="Windows Server 2008 R2 Standard x64 RTM"
|
||||||
|
type="application/vnd.tmrk.cloud.template"/>
|
||||||
|
<Template
|
||||||
|
href="/cloudapi/ecloud/templates/9/computepools/89"
|
||||||
|
name="Windows Server 2008 Standard SP2 x64"
|
||||||
|
type="application/vnd.tmrk.cloud.template"/>
|
||||||
|
</Templates>
|
||||||
|
</OperatingSystem>
|
||||||
|
<OperatingSystem>
|
||||||
|
<Name>Linux</Name>
|
||||||
|
<Templates>
|
||||||
|
<Template
|
||||||
|
href="/cloudapi/ecloud/templates/5/computepools/89"
|
||||||
|
name="CentOS 5.5 x32"
|
||||||
|
type="application/vnd.tmrk.cloud.template"/>
|
||||||
|
<Template
|
||||||
|
href="/cloudapi/ecloud/templates/6/computepools/89"
|
||||||
|
name="CentOS 5.5 x64"
|
||||||
|
type="application/vnd.tmrk.cloud.template"/>
|
||||||
|
</Templates>
|
||||||
|
</OperatingSystem>
|
||||||
|
</OperatingSystems>
|
||||||
|
</Category>
|
||||||
|
</Categories>
|
||||||
|
</Family>
|
||||||
|
</Families>
|
||||||
|
</Templates>
|
Loading…
Reference in New Issue