mirror of https://github.com/apache/jclouds.git
Merge pull request #191 from jsonking/695-1
Issue 695: Actions on virtual machine (poweron/off/tools mount/unmount). Template
This commit is contained in:
commit
be5d6be149
|
@ -81,11 +81,6 @@ public class Disks {
|
|||
this.disks = Sets.newLinkedHashSet(disks);
|
||||
}
|
||||
|
||||
public void setVirtualDisk(VirtualDisk disk) {
|
||||
checkNotNull(disk,"disk");
|
||||
this.disks.add(disk);
|
||||
}
|
||||
|
||||
public Set<VirtualDisk> getVirtualDisks() {
|
||||
return Collections.unmodifiableSet(disks);
|
||||
}
|
||||
|
|
|
@ -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,130 @@
|
|||
/**
|
||||
* 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.tmrk.enterprisecloud.domain.Link;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.Links;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="Templates">
|
||||
* @author Jason King
|
||||
*
|
||||
*/
|
||||
@XmlRootElement(name = "Templates")
|
||||
public class Templates extends BaseResource<Templates> {
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromTemplates(this);
|
||||
}
|
||||
|
||||
public static class Builder extends BaseResource.Builder<Templates> {
|
||||
private Links links = Links.builder().build();
|
||||
|
||||
/**
|
||||
* @see Templates#getLinks
|
||||
*/
|
||||
public Builder links(Set<Link> links) {
|
||||
this.links = Links.builder().links(checkNotNull(links,"links")).build();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Templates build() {
|
||||
return new Templates(href, type, links);
|
||||
}
|
||||
|
||||
public Builder fromTemplates(Templates in) {
|
||||
return fromResource(in).links(in.getLinks());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder fromResource(BaseResource<Templates> 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 fromAttributes(Map<String, String> attributes) {
|
||||
return Builder.class.cast(super.fromAttributes(attributes));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@XmlElement(name = "Links", required = true)
|
||||
private Links links = Links.builder().build();
|
||||
|
||||
public Templates(URI href, String type, Links links ) {
|
||||
super(href, type);
|
||||
this.links = checkNotNull(links, "links");
|
||||
}
|
||||
|
||||
protected Templates() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public Set<Link> getLinks() {
|
||||
return Collections.unmodifiableSet(links.getLinks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String string() {
|
||||
return super.string()+", links="+links;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* 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 org.jclouds.tmrk.enterprisecloud.domain.template.Templates;
|
||||
|
||||
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#getTemplates
|
||||
*/
|
||||
@GET
|
||||
@Consumes("application/vnd.tmrk.cloud.template; type=collection")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Templates> getTemplates(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @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,57 @@
|
|||
/**
|
||||
* 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 org.jclouds.tmrk.enterprisecloud.domain.template.Templates;
|
||||
|
||||
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 call returns information regarding templates defined in a compute pool.
|
||||
* Note that Templates are not a simple wrapper around template objects.
|
||||
* Once the desired template is located getTemplate must be called to retrieve all the attached information
|
||||
* @param uri compute pool identifier
|
||||
* @return the templates
|
||||
*/
|
||||
Templates getTemplates(URI uri);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
}
|
|
@ -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.Task;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||
|
@ -29,8 +30,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOpt
|
|||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
||||
import org.jclouds.tmrk.enterprisecloud.functions.ReturnEmptyVirtualMachinesOnNotFoundOr404;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.*;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
|
@ -91,4 +91,73 @@ public interface VirtualMachineAsyncClient {
|
|||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<HardwareConfiguration> getHardwareConfiguration(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#powerOn
|
||||
*/
|
||||
@POST
|
||||
@Path("/action/powerOn")
|
||||
@Consumes("application/vnd.tmrk.cloud.task")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Task> powerOn(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#powerOff
|
||||
*/
|
||||
@POST
|
||||
@Path("/action/powerOff")
|
||||
@Consumes("application/vnd.tmrk.cloud.task")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Task> powerOff(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#reboot
|
||||
*/
|
||||
@POST
|
||||
@Path("/action/reboot")
|
||||
@Consumes("application/vnd.tmrk.cloud.task")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Task> reboot(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#shutdown
|
||||
*/
|
||||
@POST
|
||||
@Path("/action/shutdown")
|
||||
@Consumes("application/vnd.tmrk.cloud.task")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Task> shutdown(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#mountTools
|
||||
*/
|
||||
@POST
|
||||
@Path("/tools/action/mount")
|
||||
@Consumes("application/vnd.tmrk.cloud.task")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Task> mountTools(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#unmountTools
|
||||
*/
|
||||
@POST
|
||||
@Path("/tools/action/unmount")
|
||||
@Consumes("application/vnd.tmrk.cloud.task")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Task> unmountTools(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#remove
|
||||
*/
|
||||
@DELETE
|
||||
@Consumes("application/vnd.tmrk.cloud.task")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Task> remove(@EndpointParam URI uri);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.tmrk.enterprisecloud.features;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||
|
@ -80,4 +81,70 @@ public interface VirtualMachineClient {
|
|||
*/
|
||||
HardwareConfiguration getHardwareConfiguration(URI uri);
|
||||
|
||||
/**
|
||||
* The Action Virtual Machines Power On call powers on a specified virtual machine.
|
||||
* If successful, the call returns the task that powered on the virtual machine.
|
||||
* Note: To power on requires a PoweredOn value of false.
|
||||
* @param uri the uri of the virtual machine
|
||||
* @return Task
|
||||
*/
|
||||
Task powerOn(URI uri);
|
||||
|
||||
/**
|
||||
* The Action Virtual Machines Power Off call powers off a specified virtual machine.
|
||||
* Power off simply terminates the virtual machine whereas
|
||||
* shutdown requests the virtual machine to end all processes and turn itself off
|
||||
* when all processes complete.
|
||||
* If successful, the call returns the task that powered off the virtual machine.
|
||||
* Note: To power off requires a PoweredOn value of true.
|
||||
* @param uri the uri of the virtual machine
|
||||
* @return Task
|
||||
*/
|
||||
Task powerOff(URI uri);
|
||||
|
||||
/**
|
||||
* The Action Virtual Machines Power Reboot call reboots a specified virtual machine.
|
||||
* If successful, the call returns the task that rebooted the virtual machine.
|
||||
* Note: To reboot requires a ToolsStatus value of Current or OutOfDate and a PoweredOn value of true.
|
||||
* @param uri the uri of the virtual machine
|
||||
* @return Task
|
||||
*/
|
||||
Task reboot(URI uri);
|
||||
|
||||
/**
|
||||
* The Action Virtual Machines Power Shutdown call shuts down a specified virtual machine.
|
||||
* Shutdown requests the virtual machine to end all processes and turn itself off when all processes complete whereas power off simply terminates the virtual machine.
|
||||
* If successful, the call returns the task that shut down the virtual machine.
|
||||
* Note: To shutdown requires a ToolsStatus value of Current or OutOfDate and a PoweredOn value of true.
|
||||
* @param uri the uri of the virtual machine
|
||||
* @return Task
|
||||
*/
|
||||
Task shutdown(URI uri);
|
||||
|
||||
/**
|
||||
* The Action Virtual Machines Tools Mount call mounts the virtual volume
|
||||
* for VMware Tools on a specified virtual machine.
|
||||
* If successful, the call returns the task that mounted the tools.
|
||||
* Note: To mount VMware Tools requires a PoweredOn value of true.
|
||||
* @param uri the uri of the virtual machine
|
||||
* @return Task
|
||||
*/
|
||||
Task mountTools(URI uri);
|
||||
|
||||
/**
|
||||
* The Action Virtual Machines Tools Unmount call unmounts the virtual volume for VMware Tools
|
||||
* on a specified virtual machine.
|
||||
* If successful, the call returns the task that unmounted the tools.
|
||||
* Note: To unmount VMware Tools requires a PoweredOn value of true.
|
||||
* @param uri the uri of the virtual machine
|
||||
* @return Task
|
||||
*/
|
||||
Task unmountTools(URI uri);
|
||||
|
||||
/**
|
||||
* * The Action Virtual Machines Remove call removes a specified virtual machine from the compute pool.
|
||||
* If successful, the call returns the task that removed the virtual machine.
|
||||
* Note: To remove a virtual machine requires a Status value of Deployed and a PoweredOn value of false.
|
||||
*/
|
||||
Task remove(URI uri);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* 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 testGetTemplates() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = TemplateAsyncClient.class.getMethod("getTemplates", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/templates/computepools/89"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/templates/computepools/89 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/vnd.tmrk.cloud.template; type=collection\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 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>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code TaskAsyncClient}
|
||||
* Tests annotation parsing of {@code VirtualMachineAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -109,6 +109,104 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
|
|||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("powerOn", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/action/powerOn HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\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 testPowerOff() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("powerOff", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/action/powerOff HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\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 testReboot() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("reboot", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/action/reboot HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\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 testShutdown() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("shutdown", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/action/shutdown HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\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 testMountTools() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("mountTools", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/tools/action/mount HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\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 testUnmountTools() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("unmountTools", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/tools/action/unmount HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\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 testRemove() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("remove", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "DELETE https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\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<VirtualMachineAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>>() {
|
||||
|
|
|
@ -0,0 +1,199 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.features;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.software.ToolsStatus;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code VirtualMachineClient} actions
|
||||
* @author Jason King
|
||||
*/
|
||||
@Test(groups = "live", testName = "VirtualMachineClientActionsLiveTest")
|
||||
public class VirtualMachineClientActionsLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTest {
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
super.setupClient();
|
||||
client = context.getApi().getVirtualMachineClient();
|
||||
}
|
||||
|
||||
//TODO: Need a create call to make this not dependent on existing vm
|
||||
private static final String vmURI = "/cloudapi/ecloud/virtualmachines/5504";
|
||||
|
||||
private VirtualMachineClient client;
|
||||
private VirtualMachine vm;
|
||||
|
||||
public void testPowerOn() throws Exception {
|
||||
vm = client.getVirtualMachine(new URI(vmURI));
|
||||
assertFalse(vm.isPoweredOn());
|
||||
|
||||
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
|
||||
if (!retryablePredicate.apply(client.powerOn(vm.getHref()))) {
|
||||
fail("Did not manage to finish powerOn task");
|
||||
}
|
||||
|
||||
vm = client.getVirtualMachine(vm.getHref());
|
||||
assertTrue(vm.isPoweredOn());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testPowerOn")
|
||||
public void testMountTools() {
|
||||
if (!mountTools(vm.getHref())) {
|
||||
fail("Did not manage to finish mount tools task");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testMountTools")
|
||||
public void testUnmountTools() {
|
||||
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
|
||||
if (!retryablePredicate.apply(client.unmountTools(vm.getHref()))) {
|
||||
fail("Did not manage finish unmount tools task");
|
||||
}
|
||||
//ToolsStatus remains in 'OutOfDate' after un-mounting.
|
||||
//There is no way to tell, other than to try un-mounting again.
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUnmountTools")
|
||||
public void testShutdown() {
|
||||
//Seems to work as ToolsStatus remains in OutOfDate state
|
||||
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
|
||||
if (!retryablePredicate.apply(client.shutdown(vm.getHref()))) {
|
||||
fail("Did not manage to finish shutdown task");
|
||||
}
|
||||
// Takes a while to powerOff
|
||||
retryablePredicate = new RetryablePredicate(poweredOff(), 1000*60);
|
||||
if (!retryablePredicate.apply(vm.getHref())) {
|
||||
fail("Did not manage to powerOff after shutdown");
|
||||
}
|
||||
|
||||
vm = client.getVirtualMachine(vm.getHref());
|
||||
assertFalse(vm.isPoweredOn());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testShutdown")
|
||||
public void testReboot() {
|
||||
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
|
||||
if (!retryablePredicate.apply(client.powerOn(vm.getHref()))) {
|
||||
fail("Did not manage to finish powerOn task");
|
||||
}
|
||||
|
||||
if (!mountTools(vm.getHref())) {
|
||||
fail("Did not manage to mount tools");
|
||||
}
|
||||
|
||||
retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
|
||||
if (!retryablePredicate.apply(client.reboot(vm.getHref()))) {
|
||||
fail("Did not manage to finish reboot task");
|
||||
}
|
||||
|
||||
vm = client.getVirtualMachine(vm.getHref());
|
||||
assertTrue(vm.isPoweredOn());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testReboot")
|
||||
public void testPowerOff() {
|
||||
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
|
||||
if (!retryablePredicate.apply(client.powerOff(vm.getHref()))) {
|
||||
fail("Did not manage to finish powerOff task");
|
||||
}
|
||||
|
||||
vm = client.getVirtualMachine(vm.getHref());
|
||||
assertFalse(vm.isPoweredOn());
|
||||
}
|
||||
|
||||
/* TODO: Not ready to delete the 5504 VM until I can create one.
|
||||
@Test(dependsOnMethods = "testPowerOff")
|
||||
public void testRemove() throws URISyntaxException {
|
||||
// Don't want to delete quite yet!
|
||||
RetryablePredicate retryablePredicate = new RetryablePredicate(taskFinished(), 1000*60);
|
||||
if (!retryablePredicate.apply(client.remove(vm.getHref()))) {
|
||||
fail("Did not manage to finish remove task");
|
||||
}
|
||||
|
||||
assertNull(client.getVirtualMachine(vm.getHref()));
|
||||
}
|
||||
*/
|
||||
|
||||
private boolean mountTools(URI uri) {
|
||||
// Wait for task to finish AND tools to get into currentOrOutOfDate state
|
||||
return new RetryablePredicate(taskFinished(), 1000*60).apply(client.mountTools(uri)) &&
|
||||
new RetryablePredicate(toolsCurrentOrOutOfDate(), 1000*60).apply(uri);
|
||||
}
|
||||
|
||||
// Probably generally useful
|
||||
private Predicate taskFinished() {
|
||||
return new Predicate<Task>() {
|
||||
@Override
|
||||
public boolean apply(Task task) {
|
||||
TaskClient taskClient = context.getApi().getTaskClient();
|
||||
task = taskClient.getTask(task.getHref());
|
||||
switch(task.getStatus()) {
|
||||
case QUEUED:
|
||||
case RUNNING:
|
||||
return false;
|
||||
case COMPLETE:
|
||||
case SUCCESS:
|
||||
return true;
|
||||
default:
|
||||
throw new RuntimeException("Task Failed:"+task.getHref()+", Status:"+task.getStatus());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Probably generally useful
|
||||
private Predicate toolsCurrentOrOutOfDate() {
|
||||
return new Predicate<URI>() {
|
||||
@Override
|
||||
public boolean apply(URI uri) {
|
||||
VirtualMachine virtualMachine = client.getVirtualMachine(uri);
|
||||
ToolsStatus toolsStatus = virtualMachine.getToolsStatus();
|
||||
switch(toolsStatus) {
|
||||
case NOT_INSTALLED:
|
||||
case NOT_RUNNING:
|
||||
return false;
|
||||
case CURRENT:
|
||||
case OUT_OF_DATE:
|
||||
return true;
|
||||
default:
|
||||
throw new RuntimeException("Unable to determine toolsStatus for:"+uri+", ToolsStatus:"+toolsStatus);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Predicate poweredOff() {
|
||||
return new Predicate<URI>() {
|
||||
@Override
|
||||
public boolean apply(URI uri) {
|
||||
VirtualMachine virtualMachine = client.getVirtualMachine(uri);
|
||||
return !virtualMachine.isPoweredOn();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -45,17 +45,14 @@ public class ReturnEmptyVirtualMachinesOnNotFoundOr404Test {
|
|||
}
|
||||
|
||||
public void testOn404() {
|
||||
VirtualMachines expected = VirtualMachines.builder().build();
|
||||
assertEquals(function.apply(new HttpResponseException("response exception", null, new HttpResponse(404, "404 message", null))), expected);
|
||||
}
|
||||
|
||||
public void testOnNotFound() {
|
||||
VirtualMachines expected = VirtualMachines.builder().build();
|
||||
assertEquals(function.apply(new ResourceNotFoundException()),expected);
|
||||
}
|
||||
|
||||
public void testOnNotFoundChained() {
|
||||
VirtualMachines expected = VirtualMachines.builder().build();
|
||||
assertEquals(function.apply(new RuntimeException(new ResourceNotFoundException())),expected);
|
||||
}
|
||||
|
||||
|
|
|
@ -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