mirror of https://github.com/apache/jclouds.git
Merge pull request #250 from jsonking/695-Terremark
Issue 695: Implemented LayoutClient plus initial implementation of createVirtualMachineFromTemplate
This commit is contained in:
commit
9394dc440f
|
@ -33,6 +33,12 @@ import org.jclouds.tmrk.enterprisecloud.features.*;
|
||||||
*/
|
*/
|
||||||
public interface TerremarkEnterpriseCloudAsyncClient {
|
public interface TerremarkEnterpriseCloudAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to Layout features.
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
LayoutAsyncClient getLayoutClient();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides asynchronous access to Location features.
|
* Provides asynchronous access to Location features.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -37,6 +37,12 @@ import org.jclouds.tmrk.enterprisecloud.features.*;
|
||||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||||
public interface TerremarkEnterpriseCloudClient {
|
public interface TerremarkEnterpriseCloudClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to Layout features.
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
LayoutClient getLayoutClient();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides synchronous access to Location features.
|
* Provides synchronous access to Location features.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,167 @@
|
||||||
|
/**
|
||||||
|
* 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.binders;
|
||||||
|
|
||||||
|
import com.jamesmurty.utils.XMLBuilder;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.Binder;
|
||||||
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSetting;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.WindowsCustomization;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For use with {@see VirtualMachineClient#createVirtualMachineFromTemplate}
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class BindCreateVirtualMachineKeyToXmlPayload implements Binder {
|
||||||
|
|
||||||
|
private final BindToStringPayload stringBinder;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BindCreateVirtualMachineKeyToXmlPayload(BindToStringPayload stringBinder) {
|
||||||
|
this.stringBinder = stringBinder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <R extends HttpRequest> R bindToRequest(R request, Object key) {
|
||||||
|
checkArgument(checkNotNull(key, "key") instanceof CreateVirtualMachine, "this binder is only valid for CreateOsTemplateVirtualMachineRequest instances!");
|
||||||
|
checkNotNull(request, "request");
|
||||||
|
CreateVirtualMachine vmData = CreateVirtualMachine.class.cast(key);
|
||||||
|
|
||||||
|
String payload = createXMLPayload(vmData);
|
||||||
|
return stringBinder.bindToRequest(request, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createXMLPayload(CreateVirtualMachine vmData) {
|
||||||
|
try {
|
||||||
|
Properties outputProperties = new Properties();
|
||||||
|
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||||
|
|
||||||
|
final String name = vmData.getName();
|
||||||
|
final String processorCount = Integer.toString(vmData.getProcessorCount());
|
||||||
|
final String memoryUnit = vmData.getMemory().getUnit();
|
||||||
|
final int memoryValue = ((Double)(vmData.getMemory().getValue())).intValue();
|
||||||
|
final Set<String> tags = vmData.getTags();
|
||||||
|
final String description = vmData.getDescription();
|
||||||
|
final LayoutRequest layout = vmData.getLayout();
|
||||||
|
final String poweredOn = Boolean.toString(vmData.isPoweredOn());
|
||||||
|
final AnonymousResource template = vmData.getTemplate();
|
||||||
|
|
||||||
|
XMLBuilder builder = XMLBuilder.create("CreateVirtualMachine").a("name",name)
|
||||||
|
.e("ProcessorCount").t(processorCount).up()
|
||||||
|
.e("Memory").e("Unit").t(memoryUnit).up()
|
||||||
|
.e("Value").t(Integer.toString(memoryValue)).up().up();
|
||||||
|
builder = layout(builder,layout);
|
||||||
|
builder.e("Description").t(description).up();
|
||||||
|
builder = tags(builder,tags);
|
||||||
|
builder = linuxCustomization(builder, vmData);
|
||||||
|
builder = windowsCustomization(builder, vmData);
|
||||||
|
builder.e("PoweredOn").t(poweredOn).up()
|
||||||
|
.e("Template").a("href",template.getHref().toString())
|
||||||
|
.a("type", template.getType()).up();
|
||||||
|
|
||||||
|
return builder.asString(outputProperties);
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (TransformerException t) {
|
||||||
|
throw new RuntimeException(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private XMLBuilder layout(XMLBuilder in, LayoutRequest layout) {
|
||||||
|
in = in.e("Layout");
|
||||||
|
if(layout.getGroup()!=null) {
|
||||||
|
in = in.e("Group").a("href",layout.getGroup().getHref().toString())
|
||||||
|
.a("type",layout.getGroup().getType()).up();
|
||||||
|
} else if (layout.getRow()!=null) {
|
||||||
|
checkNotNull(layout.getNewGroup(),"newGroup");
|
||||||
|
in = in.e("Row").a("href",layout.getRow().getHref().toString())
|
||||||
|
.a("type", layout.getRow().getType()).up()
|
||||||
|
.e("NewGroup").t(layout.getNewGroup()).up();
|
||||||
|
} else {
|
||||||
|
checkNotNull(layout.getNewRow(),"newRow");
|
||||||
|
checkNotNull(layout.getNewGroup(), "newGroup");
|
||||||
|
in = in.e("NewRow").t(layout.getNewRow()).up()
|
||||||
|
.e("NewGroup").t(layout.getNewGroup()).up();
|
||||||
|
}
|
||||||
|
return in.up();
|
||||||
|
}
|
||||||
|
|
||||||
|
private XMLBuilder tags(XMLBuilder in, Set<String> tags ) {
|
||||||
|
checkNotNull(tags,"tags");
|
||||||
|
in = in.e("Tags");
|
||||||
|
for(String tag: tags) {
|
||||||
|
in = in.e("Tag").t(tag).up();
|
||||||
|
}
|
||||||
|
return in.up();
|
||||||
|
}
|
||||||
|
|
||||||
|
private XMLBuilder linuxCustomization(XMLBuilder in, CreateVirtualMachine vmData) {
|
||||||
|
LinuxCustomization linuxCustomization = vmData.getLinuxCustomization();
|
||||||
|
if(linuxCustomization==null) return in;
|
||||||
|
if(vmData.getWindowsCustomization()!=null) throw new IllegalStateException("Cannot have linux and windows customizations");
|
||||||
|
|
||||||
|
in = in.e("LinuxCustomization")
|
||||||
|
.e("NetworkSettings")
|
||||||
|
.e("NetworkAdapterSettings");
|
||||||
|
for(NetworkAdapterSetting setting:linuxCustomization.getNetworkSettings().getNetworkAdapterSettings().getNetworkAdapterSettings()) {
|
||||||
|
in = networkAdapterSetting(in,setting);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO DNS Settings
|
||||||
|
String href = linuxCustomization.getSshKey().getHref().toString();
|
||||||
|
String type = linuxCustomization.getSshKey().getType();
|
||||||
|
return in.up().up().e("SshKey").a("href",href).a("type",type).up().up();
|
||||||
|
}
|
||||||
|
|
||||||
|
private XMLBuilder networkAdapterSetting(XMLBuilder builder, NetworkAdapterSetting setting) {
|
||||||
|
String href = setting.getNetwork().getHref().toString();
|
||||||
|
String name = setting.getNetwork().getName();
|
||||||
|
String type = setting.getNetwork().getType();
|
||||||
|
builder.e("NetworkAdapter")
|
||||||
|
.e("Network").a("href",href).a("name",name).a("type",type).up()
|
||||||
|
.e("IpAddress").t(setting.getIpAddress()).up();
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private XMLBuilder windowsCustomization(XMLBuilder builder, CreateVirtualMachine vmData) {
|
||||||
|
WindowsCustomization windowsCustomization = vmData.getWindowsCustomization();
|
||||||
|
if(windowsCustomization==null) return builder;
|
||||||
|
if(vmData.getLinuxCustomization()!=null) throw new IllegalStateException("Cannot have linux and windows customizations");
|
||||||
|
|
||||||
|
//TODO: Not implemented yet
|
||||||
|
throw new UnsupportedOperationException("windowsCustomization has not been implemented yet");
|
||||||
|
//return builder;
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,10 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.tmrk.enterprisecloud.config;
|
package org.jclouds.tmrk.enterprisecloud.config;
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import org.jclouds.http.HttpErrorHandler;
|
import org.jclouds.http.HttpErrorHandler;
|
||||||
import org.jclouds.http.HttpRetryHandler;
|
import org.jclouds.http.HttpRetryHandler;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
|
@ -36,11 +33,7 @@ import org.jclouds.tmrk.enterprisecloud.TerremarkEnterpriseCloudClient;
|
||||||
import org.jclouds.tmrk.enterprisecloud.features.*;
|
import org.jclouds.tmrk.enterprisecloud.features.*;
|
||||||
import org.jclouds.tmrk.enterprisecloud.handlers.TerremarkEnterpriseCloudErrorHandler;
|
import org.jclouds.tmrk.enterprisecloud.handlers.TerremarkEnterpriseCloudErrorHandler;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import java.util.Map;
|
||||||
import org.jclouds.util.Strings2;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the TerremarkEnterpriseCloud connection.
|
* Configures the TerremarkEnterpriseCloud connection.
|
||||||
|
@ -53,6 +46,7 @@ public class TerremarkEnterpriseCloudRestClientModule extends
|
||||||
RestClientModule<TerremarkEnterpriseCloudClient, TerremarkEnterpriseCloudAsyncClient> {
|
RestClientModule<TerremarkEnterpriseCloudClient, TerremarkEnterpriseCloudAsyncClient> {
|
||||||
|
|
||||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
|
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
|
||||||
|
.put(LayoutClient.class, LayoutAsyncClient.class)
|
||||||
.put(LocationClient.class, LocationAsyncClient.class)
|
.put(LocationClient.class, LocationAsyncClient.class)
|
||||||
.put(NetworkClient.class, NetworkAsyncClient.class)
|
.put(NetworkClient.class, NetworkAsyncClient.class)
|
||||||
.put(ResourceClient.class, ResourceAsyncClient.class)
|
.put(ResourceClient.class, ResourceAsyncClient.class)
|
||||||
|
|
|
@ -0,0 +1,183 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.tmrk.enterprisecloud.domain.layout;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Action;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Link;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DeviceLayout is more than a simple wrapper as it extends Resource.
|
||||||
|
* <xs:complexType name="DeviceLayoutType">
|
||||||
|
* @author Jason King
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@XmlRootElement(name = "DeviceLayout")
|
||||||
|
public class DeviceLayout extends Resource<DeviceLayout> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromTemplates(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends Resource.Builder<DeviceLayout> {
|
||||||
|
private Set<LayoutRow> rows = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DeviceLayout#getRows
|
||||||
|
*/
|
||||||
|
public Builder rows(Set<LayoutRow> rows) {
|
||||||
|
this.rows =(checkNotNull(rows,"rows"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceLayout build() {
|
||||||
|
return new DeviceLayout(href, type, name, links, actions, rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromTemplates(DeviceLayout in) {
|
||||||
|
return fromResource(in).rows(in.getRows());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromBaseResource(BaseResource<DeviceLayout> in) {
|
||||||
|
return Builder.class.cast(super.fromBaseResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromResource(Resource<DeviceLayout> in) {
|
||||||
|
return Builder.class.cast(super.fromResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder type(String type) {
|
||||||
|
return Builder.class.cast(super.type(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder href(URI href) {
|
||||||
|
return Builder.class.cast(super.href(href));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder name(String name) {
|
||||||
|
return Builder.class.cast(super.name(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder links(Set<Link> links) {
|
||||||
|
return Builder.class.cast(super.links(links));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder actions(Set<Action> actions) {
|
||||||
|
return Builder.class.cast(super.actions(actions));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromAttributes(Map<String, String> attributes) {
|
||||||
|
return Builder.class.cast(super.fromAttributes(attributes));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Rows", required = false)
|
||||||
|
private Rows rows = Rows.builder().build();
|
||||||
|
|
||||||
|
private DeviceLayout(URI href, String type, String name, Set<Link> links, Set<Action> actions, Set<LayoutRow> rows) {
|
||||||
|
super(href, type, name, links, actions);
|
||||||
|
this.rows = Rows.builder().rows(checkNotNull(rows,"rows")).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private DeviceLayout() {
|
||||||
|
//For JAXB
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<LayoutRow> getRows() {
|
||||||
|
return rows.getRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
DeviceLayout that = (DeviceLayout) o;
|
||||||
|
|
||||||
|
if (!rows.equals(that.rows)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + rows.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String string() {
|
||||||
|
return super.string()+", rows="+rows;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
/**
|
||||||
|
* 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.layout;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps individual LayoutGroup elements.
|
||||||
|
* <xs:complexType name="GroupsType">
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
public class Groups {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromGroups(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private Set<LayoutGroup> groups = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Groups#getGroups
|
||||||
|
*/
|
||||||
|
public Builder groups(Set<LayoutGroup> groups) {
|
||||||
|
this.groups = Sets.newLinkedHashSet(checkNotNull(groups, "groups"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addGroup(LayoutGroup group) {
|
||||||
|
groups.add(checkNotNull(group, "group"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Groups build() {
|
||||||
|
return new Groups(groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromGroups(Groups in) {
|
||||||
|
return groups(in.getGroups());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Groups() {
|
||||||
|
//For JAXB and builder use
|
||||||
|
}
|
||||||
|
|
||||||
|
private Groups(Set<LayoutGroup> entries) {
|
||||||
|
this.groups = Sets.newLinkedHashSet(entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Group", required=false)
|
||||||
|
private Set<LayoutGroup> groups = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
public Set<LayoutGroup> getGroups() {
|
||||||
|
return Collections.unmodifiableSet(groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
Groups tasks1 = (Groups) o;
|
||||||
|
|
||||||
|
if (!groups.equals(tasks1.groups)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return groups.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "["+ groups.toString()+"]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,9 +16,10 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
package org.jclouds.tmrk.enterprisecloud.domain.layout;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
|
|
@ -0,0 +1,206 @@
|
||||||
|
/**
|
||||||
|
* 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.layout;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Action;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Link;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReference;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReferences;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LayoutGroup is more than a simple wrapper as it extends Resource.
|
||||||
|
* <xs:complexType name="LayoutGroupType">
|
||||||
|
* @author Jason King
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LayoutGroup extends Resource<LayoutGroup> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromLayoutGroup(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends Resource.Builder<LayoutGroup> {
|
||||||
|
private int index;
|
||||||
|
private Set<VirtualMachineReference> virtualMachineReferences = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutGroup#getIndex
|
||||||
|
*/
|
||||||
|
public Builder index(int index) {
|
||||||
|
this.index = index;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutGroup#getVirtualMachineReferences()
|
||||||
|
*/
|
||||||
|
public Builder virtualMachineReferences(Set<VirtualMachineReference> virtualMachineReferences) {
|
||||||
|
this.virtualMachineReferences = Sets.newLinkedHashSet(checkNotNull(virtualMachineReferences, "virtualMachineReferences"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LayoutGroup build() {
|
||||||
|
return new LayoutGroup(href, type, name, links, actions, index,virtualMachineReferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromLayoutGroup(LayoutGroup in) {
|
||||||
|
return fromResource(in).index(in.getIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromBaseResource(BaseResource<LayoutGroup> in) {
|
||||||
|
return Builder.class.cast(super.fromBaseResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromResource(Resource<LayoutGroup> in) {
|
||||||
|
return Builder.class.cast(super.fromResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder type(String type) {
|
||||||
|
return Builder.class.cast(super.type(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder href(URI href) {
|
||||||
|
return Builder.class.cast(super.href(href));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder name(String name) {
|
||||||
|
return Builder.class.cast(super.name(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder links(Set<Link> links) {
|
||||||
|
return Builder.class.cast(super.links(links));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder actions(Set<Action> actions) {
|
||||||
|
return Builder.class.cast(super.actions(actions));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromAttributes(Map<String, String> attributes) {
|
||||||
|
return Builder.class.cast(super.fromAttributes(attributes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Index", required = false)
|
||||||
|
private int index;
|
||||||
|
|
||||||
|
@XmlElement(name = "VirtualMachines", required = false)
|
||||||
|
private VirtualMachineReferences virtualMachineReferences;
|
||||||
|
|
||||||
|
//TODO: PhysicalDevices
|
||||||
|
|
||||||
|
private LayoutGroup(URI href, String type, String name, Set<Link> links, Set<Action> actions,
|
||||||
|
int index, Set<VirtualMachineReference> virtualMachineReferences) {
|
||||||
|
super(href, type, name, links, actions);
|
||||||
|
this.index = index;
|
||||||
|
this.virtualMachineReferences = VirtualMachineReferences.builder().virtualMachineReferences(virtualMachineReferences).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private LayoutGroup() {
|
||||||
|
//For JAXB
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<VirtualMachineReference> getVirtualMachineReferences() {
|
||||||
|
return virtualMachineReferences.getVirtualMachineReferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
LayoutGroup that = (LayoutGroup) o;
|
||||||
|
|
||||||
|
if (index != that.index) return false;
|
||||||
|
if (!virtualMachineReferences.equals(that.virtualMachineReferences))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + index;
|
||||||
|
result = 31 * result + virtualMachineReferences.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String string() {
|
||||||
|
return super.string()+", index="+index+", virtualMachineReferences="+virtualMachineReferences;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
package org.jclouds.tmrk.enterprisecloud.domain.layout;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
|
|
@ -0,0 +1,200 @@
|
||||||
|
/**
|
||||||
|
* 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.layout;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Action;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Link;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LayoutRow is more than a simple wrapper as it extends Resource.
|
||||||
|
* <xs:complexType name="LayoutRowType">
|
||||||
|
* @author Jason King
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LayoutRow extends Resource<LayoutRow> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromLayoutRow(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends Resource.Builder<LayoutRow> {
|
||||||
|
private int index;
|
||||||
|
private Set<LayoutGroup> groups = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRow#getIndex
|
||||||
|
*/
|
||||||
|
public Builder index(int index) {
|
||||||
|
this.index = index;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Groups#getGroups
|
||||||
|
*/
|
||||||
|
public Builder groups(Set<LayoutGroup> groups) {
|
||||||
|
this.groups = Sets.newLinkedHashSet(checkNotNull(groups, "groups"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LayoutRow build() {
|
||||||
|
return new LayoutRow(href, type, name, links, actions, index, groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromLayoutRow(LayoutRow in) {
|
||||||
|
return fromResource(in).index(in.getIndex()).groups(in.getGroups());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromBaseResource(BaseResource<LayoutRow> in) {
|
||||||
|
return Builder.class.cast(super.fromBaseResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromResource(Resource<LayoutRow> in) {
|
||||||
|
return Builder.class.cast(super.fromResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder type(String type) {
|
||||||
|
return Builder.class.cast(super.type(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder href(URI href) {
|
||||||
|
return Builder.class.cast(super.href(href));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder name(String name) {
|
||||||
|
return Builder.class.cast(super.name(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder links(Set<Link> links) {
|
||||||
|
return Builder.class.cast(super.links(links));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder actions(Set<Action> actions) {
|
||||||
|
return Builder.class.cast(super.actions(actions));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromAttributes(Map<String, String> attributes) {
|
||||||
|
return Builder.class.cast(super.fromAttributes(attributes));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Index", required = false)
|
||||||
|
private int index;
|
||||||
|
|
||||||
|
@XmlElement(name = "Groups", required = false)
|
||||||
|
private Groups groups = Groups.builder().build();
|
||||||
|
|
||||||
|
private LayoutRow(URI href, String type, String name, Set<Link> links, Set<Action> actions, int index, Set<LayoutGroup> groups) {
|
||||||
|
super(href, type, name, links, actions);
|
||||||
|
this.index = index;
|
||||||
|
this.groups = Groups.builder().groups(groups).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private LayoutRow() {
|
||||||
|
//For JAXB
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<LayoutGroup> getGroups() {
|
||||||
|
return groups.getGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
LayoutRow layoutRow = (LayoutRow) o;
|
||||||
|
|
||||||
|
if (index != layoutRow.index) return false;
|
||||||
|
if (!groups.equals(layoutRow.groups)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + index;
|
||||||
|
result = 31 * result + groups.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String string() {
|
||||||
|
return super.string()+", index="+index+", groups="+groups;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
/**
|
||||||
|
* 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.layout;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps individual LayoutRow elements.
|
||||||
|
* <xs:complexType name="RowsType">
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
public class Rows {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromRows(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private Set<LayoutRow> rows = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Rows#getRows
|
||||||
|
*/
|
||||||
|
public Builder rows(Set<LayoutRow> rows) {
|
||||||
|
this.rows = Sets.newLinkedHashSet(checkNotNull(rows, "rows"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addRow(LayoutRow row) {
|
||||||
|
rows.add(checkNotNull(row,"row"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rows build() {
|
||||||
|
return new Rows(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromRows(Rows in) {
|
||||||
|
return rows(in.getRows());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rows() {
|
||||||
|
//For JAXB and builder use
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rows(Set<LayoutRow> entries) {
|
||||||
|
this.rows = Sets.newLinkedHashSet(entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Row", required=false)
|
||||||
|
private Set<LayoutRow> rows = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
public Set<LayoutRow> getRows() {
|
||||||
|
return Collections.unmodifiableSet(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
Rows tasks1 = (Rows) o;
|
||||||
|
|
||||||
|
if (!rows.equals(tasks1.rows)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return rows.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "["+ rows.toString()+"]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,7 +40,7 @@ public class LinuxCustomization {
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private NetworkSettings networkSettings;
|
private NetworkSettings networkSettings = NetworkSettings.builder().build();
|
||||||
private AnonymousResource sshKey;
|
private AnonymousResource sshKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class NetworkSettings {
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private NetworkAdapterSettings networkAdapterSettings;
|
private NetworkAdapterSettings networkAdapterSettings = NetworkAdapterSettings.builder().build();
|
||||||
private DnsSettings dnsSettings;
|
private DnsSettings dnsSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
package org.jclouds.tmrk.enterprisecloud.domain.vm;
|
package org.jclouds.tmrk.enterprisecloud.domain.vm;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.LayoutRequest;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.WindowsCustomization;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.WindowsCustomization;
|
||||||
|
@ -29,12 +30,14 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <xs:complexType name="CreateOsTemplateVirtualMachineRequestType">
|
* <xs:complexType name="CreateVirtualMachineType">
|
||||||
* @author Jason King
|
* @author Jason King
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@XmlRootElement(name = "CreateVirtualMachineRequest")
|
@XmlRootElement(name = "CreateVirtualMachineRequest")
|
||||||
public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineRequest {
|
public class CreateVirtualMachine extends CreateVirtualMachineRequest {
|
||||||
|
// Note that this class collapses both
|
||||||
|
// CreateOsTemplateVirtualMachineRequestType and CreateVirtualMachineType
|
||||||
|
// into the same class as the separate classes are not needed.
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
|
@ -49,14 +52,15 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR
|
||||||
return new Builder().fromCreateOsTemplateVirtualMachineRequest(this);
|
return new Builder().fromCreateOsTemplateVirtualMachineRequest(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder extends CreateVirtualMachineRequest.Builder<CreateOsTemplateVirtualMachineRequest> {
|
public static class Builder extends CreateVirtualMachineRequest.Builder<CreateVirtualMachine> {
|
||||||
|
|
||||||
private LinuxCustomization linuxCustomization;
|
private LinuxCustomization linuxCustomization;
|
||||||
private WindowsCustomization windowsCustomization;
|
private WindowsCustomization windowsCustomization;
|
||||||
private boolean poweredOn;
|
private boolean poweredOn;
|
||||||
|
private AnonymousResource template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.CreateOsTemplateVirtualMachineRequest#getLinuxCustomization
|
* @see CreateVirtualMachine#getLinuxCustomization
|
||||||
*/
|
*/
|
||||||
public Builder linuxCustomization(LinuxCustomization linuxCustomization) {
|
public Builder linuxCustomization(LinuxCustomization linuxCustomization) {
|
||||||
this.linuxCustomization = linuxCustomization;
|
this.linuxCustomization = linuxCustomization;
|
||||||
|
@ -64,7 +68,7 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.CreateOsTemplateVirtualMachineRequest#getWindowsCustomization
|
* @see CreateVirtualMachine#getWindowsCustomization
|
||||||
*/
|
*/
|
||||||
public Builder windowsCustomization(WindowsCustomization windowsCustomization) {
|
public Builder windowsCustomization(WindowsCustomization windowsCustomization) {
|
||||||
this.windowsCustomization = windowsCustomization;
|
this.windowsCustomization = windowsCustomization;
|
||||||
|
@ -73,13 +77,21 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.CreateOsTemplateVirtualMachineRequest#isPoweredOn
|
* @see CreateVirtualMachine#isPoweredOn
|
||||||
*/
|
*/
|
||||||
public Builder poweredOn(boolean poweredOn) {
|
public Builder poweredOn(boolean poweredOn) {
|
||||||
this.poweredOn = poweredOn;
|
this.poweredOn = poweredOn;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see CreateVirtualMachine#getTemplate
|
||||||
|
*/
|
||||||
|
public Builder template(AnonymousResource template) {
|
||||||
|
this.template = template;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see CreateVirtualMachineRequest#getName()
|
* @see CreateVirtualMachineRequest#getName()
|
||||||
*/
|
*/
|
||||||
|
@ -127,17 +139,18 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CreateOsTemplateVirtualMachineRequest build() {
|
public CreateVirtualMachine build() {
|
||||||
return new CreateOsTemplateVirtualMachineRequest(name, processorCount,memory,
|
return new CreateVirtualMachine(name, processorCount,memory,
|
||||||
description,layout,tags,
|
description,layout,tags,
|
||||||
linuxCustomization,windowsCustomization,poweredOn);
|
linuxCustomization,windowsCustomization,poweredOn, template);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder fromCreateOsTemplateVirtualMachineRequest(CreateOsTemplateVirtualMachineRequest in) {
|
public Builder fromCreateOsTemplateVirtualMachineRequest(CreateVirtualMachine in) {
|
||||||
return fromCreateVirtualMachineRequest(in)
|
return fromCreateVirtualMachineRequest(in)
|
||||||
.linuxCustomization(in.getLinuxCustomization())
|
.linuxCustomization(in.getLinuxCustomization())
|
||||||
.windowsCustomization(in.getWindowsCustomization())
|
.windowsCustomization(in.getWindowsCustomization())
|
||||||
.poweredOn(in.isPoweredOn());
|
.poweredOn(in.isPoweredOn())
|
||||||
|
.template(in.getTemplate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,18 +162,23 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR
|
||||||
|
|
||||||
@XmlElement(name = "PoweredOn", required = false)
|
@XmlElement(name = "PoweredOn", required = false)
|
||||||
private boolean poweredOn;
|
private boolean poweredOn;
|
||||||
|
|
||||||
|
@XmlElement(name = "Template", required = false)
|
||||||
private CreateOsTemplateVirtualMachineRequest(String name, int processorCount, ResourceCapacity memory,
|
private AnonymousResource template;
|
||||||
@Nullable String description,@Nullable LayoutRequest layout,@Nullable Set<String> tags,
|
|
||||||
@Nullable LinuxCustomization linuxCustomization, @Nullable WindowsCustomization windowsCustomization, boolean poweredOn) {
|
|
||||||
|
private CreateVirtualMachine(String name, int processorCount, ResourceCapacity memory,
|
||||||
|
@Nullable String description, @Nullable LayoutRequest layout, @Nullable Set<String> tags,
|
||||||
|
@Nullable LinuxCustomization linuxCustomization, @Nullable WindowsCustomization windowsCustomization,
|
||||||
|
boolean poweredOn, @Nullable AnonymousResource template) {
|
||||||
super(name,processorCount,memory,description,layout,tags);
|
super(name,processorCount,memory,description,layout,tags);
|
||||||
this.linuxCustomization = linuxCustomization;
|
this.linuxCustomization = linuxCustomization;
|
||||||
this.windowsCustomization = windowsCustomization;
|
this.windowsCustomization = windowsCustomization;
|
||||||
this.poweredOn = poweredOn;
|
this.poweredOn = poweredOn;
|
||||||
|
this.template = template;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CreateOsTemplateVirtualMachineRequest() {
|
protected CreateVirtualMachine() {
|
||||||
//For JAXB
|
//For JAXB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,16 +194,22 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR
|
||||||
return poweredOn;
|
return poweredOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AnonymousResource getTemplate() {
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
CreateOsTemplateVirtualMachineRequest that = (CreateOsTemplateVirtualMachineRequest) o;
|
CreateVirtualMachine that = (CreateVirtualMachine) o;
|
||||||
|
|
||||||
if (poweredOn != that.poweredOn) return false;
|
if (poweredOn != that.poweredOn) return false;
|
||||||
if (linuxCustomization != null ? !linuxCustomization.equals(that.linuxCustomization) : that.linuxCustomization != null)
|
if (linuxCustomization != null ? !linuxCustomization.equals(that.linuxCustomization) : that.linuxCustomization != null)
|
||||||
return false;
|
return false;
|
||||||
|
if (template != null ? !template.equals(that.template) : that.template != null)
|
||||||
|
return false;
|
||||||
if (windowsCustomization != null ? !windowsCustomization.equals(that.windowsCustomization) : that.windowsCustomization != null)
|
if (windowsCustomization != null ? !windowsCustomization.equals(that.windowsCustomization) : that.windowsCustomization != null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -197,11 +221,12 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR
|
||||||
int result = linuxCustomization != null ? linuxCustomization.hashCode() : 0;
|
int result = linuxCustomization != null ? linuxCustomization.hashCode() : 0;
|
||||||
result = 31 * result + (windowsCustomization != null ? windowsCustomization.hashCode() : 0);
|
result = 31 * result + (windowsCustomization != null ? windowsCustomization.hashCode() : 0);
|
||||||
result = 31 * result + (poweredOn ? 1 : 0);
|
result = 31 * result + (poweredOn ? 1 : 0);
|
||||||
|
result = 31 * result + (template != null ? template.hashCode() : 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String string() {
|
public String string() {
|
||||||
return super.string()+", linuxCustomization="+linuxCustomization+", windowsCustomization="+windowsCustomization+", poweredOn="+poweredOn;
|
return super.string()+", linuxCustomization="+linuxCustomization+", windowsCustomization="+windowsCustomization+", poweredOn="+poweredOn+", template="+template;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,7 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.domain.vm;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.LayoutRequest;
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.*;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.Layout;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
|
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.software.ToolsStatus;
|
import org.jclouds.tmrk.enterprisecloud.domain.software.ToolsStatus;
|
||||||
|
|
||||||
|
@ -99,14 +100,6 @@ public class VirtualMachine extends Resource<VirtualMachine> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see VirtualMachine#getToolsStatus()
|
|
||||||
*/
|
|
||||||
public Builder toolStatus(ToolsStatus toolsStatus) {
|
|
||||||
this.toolsStatus = toolsStatus;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see VirtualMachine#isCustomizationPending()
|
* @see VirtualMachine#isCustomizationPending()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,312 @@
|
||||||
|
/**
|
||||||
|
* 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.vm;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Action;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Link;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.software.ToolsStatus;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <xs:complexType name="VirtualMachineReferenceType">
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
public class VirtualMachineReference extends Resource<VirtualMachineReference> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromVirtualMachineReference(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends Resource.Builder<VirtualMachineReference> {
|
||||||
|
|
||||||
|
private VirtualMachine.VirtualMachineStatus status;
|
||||||
|
private int processorCount;
|
||||||
|
private ResourceCapacity memory;
|
||||||
|
private ResourceCapacity storage;
|
||||||
|
private NamedResource operatingSystem;
|
||||||
|
private boolean poweredOn;
|
||||||
|
private ToolsStatus toolsStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReference#getStatus()
|
||||||
|
*/
|
||||||
|
public Builder status(VirtualMachine.VirtualMachineStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReference#getProcessorCount()
|
||||||
|
*/
|
||||||
|
public Builder processorCount(int processorCount) {
|
||||||
|
this.processorCount = processorCount;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReference#getMemory()
|
||||||
|
*/
|
||||||
|
public Builder memory(ResourceCapacity memory) {
|
||||||
|
this.memory = memory;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReference#getStorage()
|
||||||
|
*/
|
||||||
|
public Builder storage(ResourceCapacity storage) {
|
||||||
|
this.storage = storage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReference#getOperatingSystem()
|
||||||
|
*/
|
||||||
|
public Builder operatingSystem(NamedResource operatingSystem) {
|
||||||
|
this.operatingSystem = operatingSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReference#isPoweredOn()
|
||||||
|
*/
|
||||||
|
public Builder poweredOn(boolean poweredOn) {
|
||||||
|
this.poweredOn = poweredOn;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReference#getToolsStatus()
|
||||||
|
*/
|
||||||
|
public Builder toolsStatus(ToolsStatus toolsStatus) {
|
||||||
|
this.toolsStatus = toolsStatus;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VirtualMachineReference build() {
|
||||||
|
return new VirtualMachineReference(href, type, name, links, actions,
|
||||||
|
status,processorCount,memory,storage,operatingSystem,
|
||||||
|
poweredOn,toolsStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromVirtualMachineReference(VirtualMachineReference in) {
|
||||||
|
return fromResource(in).status(in.getStatus())
|
||||||
|
.processorCount(in.getProcessorCount())
|
||||||
|
.memory(in.getMemory())
|
||||||
|
.storage(in.getStorage())
|
||||||
|
.operatingSystem(in.getOperatingSystem())
|
||||||
|
.poweredOn(in.isPoweredOn())
|
||||||
|
.toolsStatus(in.getToolsStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromBaseResource(BaseResource<VirtualMachineReference> in) {
|
||||||
|
return Builder.class.cast(super.fromBaseResource(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromResource(Resource<VirtualMachineReference> 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 links(Set<Link> links) {
|
||||||
|
return Builder.class.cast(super.links(links));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder actions(Set<Action> actions) {
|
||||||
|
return Builder.class.cast(super.actions(actions));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder name(String name) {
|
||||||
|
return Builder.class.cast(super.name(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder fromAttributes(Map<String, String> attributes) {
|
||||||
|
super.fromAttributes(attributes);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Status", required = false)
|
||||||
|
private VirtualMachine.VirtualMachineStatus status;
|
||||||
|
|
||||||
|
@XmlElement(name = "ProcessorCount", required = false)
|
||||||
|
private int processorCount;
|
||||||
|
|
||||||
|
@XmlElement(name = "Memory", required = false)
|
||||||
|
private ResourceCapacity memory;
|
||||||
|
|
||||||
|
@XmlElement(name = "Storage", required = false)
|
||||||
|
private ResourceCapacity storage;
|
||||||
|
|
||||||
|
@XmlElement(name = "OperatingSystem", required = false)
|
||||||
|
private NamedResource operatingSystem;
|
||||||
|
|
||||||
|
@XmlElement(name = "PoweredOn", required = false)
|
||||||
|
private boolean poweredOn;
|
||||||
|
|
||||||
|
@XmlElement(name = "ToolsStatus", required = false)
|
||||||
|
private ToolsStatus toolsStatus;
|
||||||
|
|
||||||
|
private VirtualMachineReference(URI href, String type, String name, Set<Link> links, Set<Action> actions,
|
||||||
|
@Nullable VirtualMachine.VirtualMachineStatus status, int processorCount, @Nullable ResourceCapacity memory,
|
||||||
|
@Nullable ResourceCapacity storage, @Nullable NamedResource operatingSystem, boolean poweredOn,
|
||||||
|
@Nullable ToolsStatus toolsStatus) {
|
||||||
|
super(href, type, name, links, actions);
|
||||||
|
this.status = status;
|
||||||
|
this.processorCount = processorCount;
|
||||||
|
this.memory = memory;
|
||||||
|
this.storage = storage;
|
||||||
|
this.operatingSystem = operatingSystem;
|
||||||
|
this.poweredOn = poweredOn;
|
||||||
|
this.toolsStatus = toolsStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
private VirtualMachineReference() {
|
||||||
|
//For JAXB
|
||||||
|
}
|
||||||
|
|
||||||
|
public VirtualMachine.VirtualMachineStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProcessorCount() {
|
||||||
|
return processorCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceCapacity getMemory() {
|
||||||
|
return memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceCapacity getStorage() {
|
||||||
|
return storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NamedResource getOperatingSystem() {
|
||||||
|
return operatingSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPoweredOn() {
|
||||||
|
return poweredOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToolsStatus getToolsStatus() {
|
||||||
|
return toolsStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
|
VirtualMachineReference that = (VirtualMachineReference) o;
|
||||||
|
|
||||||
|
if (poweredOn != that.poweredOn) return false;
|
||||||
|
if (processorCount != that.processorCount) return false;
|
||||||
|
if (memory != null ? !memory.equals(that.memory) : that.memory != null)
|
||||||
|
return false;
|
||||||
|
if (operatingSystem != null ? !operatingSystem.equals(that.operatingSystem) : that.operatingSystem != null)
|
||||||
|
return false;
|
||||||
|
if (status != that.status) return false;
|
||||||
|
if (storage != null ? !storage.equals(that.storage) : that.storage != null)
|
||||||
|
return false;
|
||||||
|
if (toolsStatus != that.toolsStatus) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = super.hashCode();
|
||||||
|
result = 31 * result + (status != null ? status.hashCode() : 0);
|
||||||
|
result = 31 * result + processorCount;
|
||||||
|
result = 31 * result + (memory != null ? memory.hashCode() : 0);
|
||||||
|
result = 31 * result + (storage != null ? storage.hashCode() : 0);
|
||||||
|
result = 31 * result + (operatingSystem != null ? operatingSystem.hashCode() : 0);
|
||||||
|
result = 31 * result + (poweredOn ? 1 : 0);
|
||||||
|
result = 31 * result + (toolsStatus != null ? toolsStatus.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String string() {
|
||||||
|
return super.string()+", status="+status+", processorCount="+processorCount+", memory="+memory+
|
||||||
|
", storage="+storage+", operatingSystem="+operatingSystem+", poweredOn="+poweredOn+
|
||||||
|
", toolsStatus="+toolsStatus;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
/**
|
||||||
|
* 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.vm;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps individual VirtualMachineReference elements.
|
||||||
|
* Needed because parsing is done with JAXB and it does not handle Generic collections
|
||||||
|
* <xs:complexType name="VirtualMachineReferencesType">
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
public class VirtualMachineReferences {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return new Builder().fromVirtualMachineReferencesReferences(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private Set<VirtualMachineReference> virtualMachineReferences = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReferences#getVirtualMachineReferences
|
||||||
|
*/
|
||||||
|
public Builder virtualMachineReferences(Set<VirtualMachineReference> virtualMachineReferences) {
|
||||||
|
this.virtualMachineReferences = Sets.newLinkedHashSet(checkNotNull(virtualMachineReferences, "virtualMachineReferences"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addVirtualMachineReference(VirtualMachineReference virtualMachineReference) {
|
||||||
|
virtualMachineReferences.add(checkNotNull(virtualMachineReference, "virtualMachineReference"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VirtualMachineReferences build() {
|
||||||
|
return new VirtualMachineReferences(virtualMachineReferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder fromVirtualMachineReferencesReferences(VirtualMachineReferences in) {
|
||||||
|
return virtualMachineReferences(in.getVirtualMachineReferences());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private VirtualMachineReferences() {
|
||||||
|
//For JAXB and builder use
|
||||||
|
}
|
||||||
|
|
||||||
|
private VirtualMachineReferences(Set<VirtualMachineReference> virtualMachineReference) {
|
||||||
|
this.virtualMachineReferences = Sets.newLinkedHashSet(virtualMachineReference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "VirtualMachine")
|
||||||
|
private Set<VirtualMachineReference> virtualMachineReferences = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
|
public Set<VirtualMachineReference> getVirtualMachineReferences() {
|
||||||
|
return Collections.unmodifiableSet(virtualMachineReferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
VirtualMachineReferences that = (VirtualMachineReferences) o;
|
||||||
|
|
||||||
|
if (virtualMachineReferences != null ? !virtualMachineReferences.equals(that.virtualMachineReferences) : that.virtualMachineReferences != null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return virtualMachineReferences != null ? virtualMachineReferences.hashCode() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "["+ virtualMachineReferences.toString()+"]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,7 +23,6 @@ import com.google.common.collect.Sets;
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
@ -81,7 +80,7 @@ public class VirtualMachines {
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "VirtualMachine")
|
@XmlElement(name = "VirtualMachine")
|
||||||
private LinkedHashSet<VirtualMachine> virtualMachines = Sets.newLinkedHashSet();
|
private Set<VirtualMachine> virtualMachines = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
public Set<VirtualMachine> getVirtualMachines() {
|
public Set<VirtualMachine> getVirtualMachines() {
|
||||||
return Collections.unmodifiableSet(virtualMachines);
|
return Collections.unmodifiableSet(virtualMachines);
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
* 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.layout.DeviceLayout;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to Layouts via their REST API.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see LayoutClient
|
||||||
|
* @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 LayoutAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see LayoutClient#getLayouts
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Consumes("application/vnd.tmrk.cloud.deviceLayout")
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<DeviceLayout> getLayouts(@EndpointParam URI uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see LayoutClient#getLayoutsInComputePool
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Consumes("application/vnd.tmrk.cloud.deviceLayout")
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<DeviceLayout> getLayoutsInComputePool(@EndpointParam URI uri);
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
* 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.layout.DeviceLayout;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to Location.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see LayoutAsyncClient
|
||||||
|
* @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 LayoutClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Get Layouts call returns information regarding the row and group of network hosts in an environment.
|
||||||
|
* Rows and groups allow aggregation of servers along logical boundaries defined by the organization.
|
||||||
|
* @param uri the uri based on the environment
|
||||||
|
* e.g. /cloudapi/ecloud/layout/environments/{id}
|
||||||
|
* @return the DeviceLayout
|
||||||
|
*/
|
||||||
|
DeviceLayout getLayouts(URI uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Get Layouts by Compute Pool call returns information regarding the row and group of network hosts
|
||||||
|
* for a specified compute pool in an environment.
|
||||||
|
* Rows and groups allow aggregation of servers along logical boundaries defined by the organization.
|
||||||
|
* @param uri the uri based on the compute pool
|
||||||
|
* e.g. /cloudapi/ecloud/layout/computePools/{id}
|
||||||
|
* @return the DeviceLayout
|
||||||
|
*/
|
||||||
|
DeviceLayout getLayoutsInComputePool(URI uri);
|
||||||
|
|
||||||
|
}
|
|
@ -22,15 +22,18 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
import org.jclouds.rest.annotations.*;
|
import org.jclouds.rest.annotations.*;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.binders.BindCreateVirtualMachineKeyToXmlPayload;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
||||||
import org.jclouds.tmrk.enterprisecloud.functions.ReturnEmptyVirtualMachinesOnNotFoundOr404;
|
import org.jclouds.tmrk.enterprisecloud.functions.ReturnEmptyVirtualMachinesOnNotFoundOr404;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,6 +95,15 @@ public interface VirtualMachineAsyncClient {
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<HardwareConfiguration> getHardwareConfiguration(@EndpointParam URI uri);
|
ListenableFuture<HardwareConfiguration> getHardwareConfiguration(@EndpointParam URI uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see VirtualMachineClient#createVirtualMachineFromTemplate
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Consumes("application/vnd.tmrk.cloud.virtualMachine")
|
||||||
|
@Produces(MediaType.APPLICATION_XML)
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<VirtualMachine> createVirtualMachineFromTemplate(@EndpointParam URI uri, @BinderParam(BindCreateVirtualMachineKeyToXmlPayload.class)CreateVirtualMachine request);
|
||||||
/**
|
/**
|
||||||
* @see VirtualMachineClient#powerOn
|
* @see VirtualMachineClient#powerOn
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,9 +22,7 @@ import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.*;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -81,6 +79,15 @@ public interface VirtualMachineClient {
|
||||||
*/
|
*/
|
||||||
HardwareConfiguration getHardwareConfiguration(URI uri);
|
HardwareConfiguration getHardwareConfiguration(URI uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Create Virtual Machines from Template call creates a new virtual machine from a template in the compute pool.
|
||||||
|
* If successful, the call returns information regarding the virtual machine that was created.
|
||||||
|
* @param uri the uri to create a virtual machine based upon the compute pool
|
||||||
|
* e.g. /cloudapi/ecloud/virtualMachines/computePools/{compute pool identifier}/action/createVirtualMachine
|
||||||
|
* @return the created virtual machine
|
||||||
|
*/
|
||||||
|
VirtualMachine createVirtualMachineFromTemplate(URI uri,CreateVirtualMachine request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Action Virtual Machines Power On call powers on a specified virtual machine.
|
* 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.
|
* If successful, the call returns the task that powered on the virtual machine.
|
||||||
|
|
|
@ -31,7 +31,7 @@ import java.net.URI;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code BindCreateSSHKeyToXmlPayloadTest}
|
* Tests behavior of {@code BindCreateSSHKeyToXmlPayload}
|
||||||
* @author Jason King
|
* @author Jason King
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "BindCreateSSHKeyToXmlPayloadTest")
|
@Test(groups = "unit", testName = "BindCreateSSHKeyToXmlPayloadTest")
|
||||||
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
/**
|
||||||
|
* 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.binders;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSetting;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSettings;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkSettings;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code BindCreateVirtualMachineKeyToXmlPayload}
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "BindCreateVirtualMachineKeyToXmlPayloadTest")
|
||||||
|
public class BindCreateVirtualMachineKeyToXmlPayloadTest {
|
||||||
|
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
public void testPayloadXmlContent() throws IOException {
|
||||||
|
String expected =
|
||||||
|
"<CreateVirtualMachine name='VirtualMachine2'>" +
|
||||||
|
"<ProcessorCount>2</ProcessorCount>" +
|
||||||
|
"<Memory><Unit>MB</Unit><Value>1024</Value></Memory>" +
|
||||||
|
"<Layout><Group href='/cloudapi/ecloud/layoutgroups/308' type='application/vnd.tmrk.cloud.layoutGroup'/></Layout>" +
|
||||||
|
"<Description>This is my first VM</Description>" +
|
||||||
|
"<Tags><Tag>Web</Tag></Tags>" +
|
||||||
|
"<LinuxCustomization>" +
|
||||||
|
"<NetworkSettings>" +
|
||||||
|
"<NetworkAdapterSettings>" +
|
||||||
|
"<NetworkAdapter>" +
|
||||||
|
"<Network href='/cloudapi/ecloud/networks/3936' name='10.146.204.64/28' type='application/vnd.tmrk.cloud.network'/>" +
|
||||||
|
"<IpAddress>10.146.204.68</IpAddress>" +
|
||||||
|
"</NetworkAdapter>" +
|
||||||
|
"</NetworkAdapterSettings>" +
|
||||||
|
"</NetworkSettings>" +
|
||||||
|
"<SshKey href='/cloudapi/ecloud/admin/sshkeys/77' type='application/vnd.tmrk.cloud.admin.sshKey'/>" +
|
||||||
|
"</LinuxCustomization>" +
|
||||||
|
"<PoweredOn>false</PoweredOn>" +
|
||||||
|
"<Template href='/cloudapi/ecloud/templates/6/computepools/89' type='application/vnd.tmrk.cloud.template'/>" +
|
||||||
|
"</CreateVirtualMachine>";
|
||||||
|
|
||||||
|
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
|
||||||
|
BindCreateVirtualMachineKeyToXmlPayload binder = injector
|
||||||
|
.getInstance(BindCreateVirtualMachineKeyToXmlPayload.class);
|
||||||
|
|
||||||
|
CreateVirtualMachine.Builder builder = CreateVirtualMachine.builder();
|
||||||
|
builder.name("VirtualMachine2")
|
||||||
|
.processorCount(2)
|
||||||
|
.memory(ResourceCapacity.builder().value(1024).unit("MB").build());
|
||||||
|
|
||||||
|
AnonymousResource group = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/layoutgroups/308")).type("application/vnd.tmrk.cloud.layoutGroup").build();
|
||||||
|
builder.layout(LayoutRequest.builder().group(group).build());
|
||||||
|
builder.description("This is my first VM");
|
||||||
|
builder.tags(ImmutableSet.of("Web"));
|
||||||
|
AnonymousResource sshKey = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/admin/sshkeys/77")).type("application/vnd.tmrk.cloud.admin.sshKey").build();
|
||||||
|
|
||||||
|
NamedResource network = NamedResource.builder()
|
||||||
|
.href(URI.create("/cloudapi/ecloud/networks/3936"))
|
||||||
|
.name("10.146.204.64/28")
|
||||||
|
.type("application/vnd.tmrk.cloud.network")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
NetworkAdapterSetting adapterSetting = NetworkAdapterSetting.builder()
|
||||||
|
.network(network)
|
||||||
|
.ipAddress("10.146.204.68")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
NetworkAdapterSettings adapterSettings = NetworkAdapterSettings.builder()
|
||||||
|
.addNetworkAdapterSetting(adapterSetting).build();
|
||||||
|
NetworkSettings networkSettings = NetworkSettings.builder().networkAdapterSettings(adapterSettings).build();
|
||||||
|
|
||||||
|
LinuxCustomization linuxCustomization = LinuxCustomization.builder()
|
||||||
|
.sshKey(sshKey)
|
||||||
|
.networkSettings(networkSettings)
|
||||||
|
.build();
|
||||||
|
builder.linuxCustomization(linuxCustomization);
|
||||||
|
|
||||||
|
AnonymousResource template = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/templates/6/computepools/89")).type("application/vnd.tmrk.cloud.template").build();
|
||||||
|
builder.template(template);
|
||||||
|
binder.bindToRequest(request, builder.build());
|
||||||
|
assertEquals(request.getPayload().getRawContent(), expected.replaceAll("'","\""));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
/**
|
||||||
|
* 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 LayoutAsyncClient}
|
||||||
|
*
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "LayoutAsyncClientTest")
|
||||||
|
public class LayoutAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<LayoutAsyncClient> {
|
||||||
|
|
||||||
|
public void testGetLayouts() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||||
|
testCall("getLayouts","/cloudapi/ecloud/layout/environments/77");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetLayoutsInComputePool() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||||
|
testCall("getLayoutsInComputePool","/cloudapi/ecloud/layout/computePools/89");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testCall(String methodName, String uri) throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||||
|
Method method = LayoutAsyncClient.class.getMethod(methodName, URI.class);
|
||||||
|
HttpRequest httpRequest = processor.createRequest(method, URI.create(uri));
|
||||||
|
|
||||||
|
String requestLine = String.format("GET https://services-beta.enterprisecloud.terremark.com%s HTTP/1.1",uri);
|
||||||
|
assertRequestLineEquals(httpRequest, requestLine);
|
||||||
|
assertNonPayloadHeadersEqual(httpRequest,
|
||||||
|
"Accept: application/vnd.tmrk.cloud.deviceLayout\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<LayoutAsyncClient>> createTypeLiteral() {
|
||||||
|
return new TypeLiteral<RestAnnotationProcessor<LayoutAsyncClient>>() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.tmrk.enterprisecloud.features;
|
||||||
|
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.DeviceLayout;
|
||||||
|
import org.testng.annotations.BeforeGroups;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code LayoutClient}
|
||||||
|
*
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "live", testName = "LayoutClientLiveTest")
|
||||||
|
public class LayoutClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTest {
|
||||||
|
@BeforeGroups(groups = { "live" })
|
||||||
|
public void setupClient() {
|
||||||
|
super.setupClient();
|
||||||
|
client = context.getApi().getLayoutClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
private LayoutClient client;
|
||||||
|
|
||||||
|
public void testGetLayouts() throws Exception {
|
||||||
|
DeviceLayout layout = client.getLayouts(URI.create("/cloudapi/ecloud/layout/environments/77"));
|
||||||
|
assertNotNull(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetMissingLayouts() {
|
||||||
|
assertNull(client.getLayouts(URI.create("/cloudapi/ecloud/layout/environments/-1")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetLayoutsInComputePool() throws Exception {
|
||||||
|
DeviceLayout layout = client.getLayouts(URI.create("/cloudapi/ecloud/layout/computepools/89"));
|
||||||
|
assertNotNull(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetMissingLayoutsInComputePool() {
|
||||||
|
assertNull(client.getLayouts(URI.create("/cloudapi/ecloud/layout/computepools/-1")));
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,10 +18,15 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.tmrk.enterprisecloud.features;
|
package org.jclouds.tmrk.enterprisecloud.features;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.network.*;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
||||||
|
@ -101,4 +106,47 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCreateVirtualMachineFromTemplate() throws Exception {
|
||||||
|
CreateVirtualMachine.Builder builder = CreateVirtualMachine.builder();
|
||||||
|
builder.name("VirtualMachine2")
|
||||||
|
.processorCount(2)
|
||||||
|
.memory(ResourceCapacity.builder().value(1024).unit("MB").build());
|
||||||
|
|
||||||
|
AnonymousResource group = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/layoutgroups/308")).type("application/vnd.tmrk.cloud.layoutGroup").build();
|
||||||
|
builder.layout(LayoutRequest.builder().group(group).build());
|
||||||
|
builder.description("This is my first VM");
|
||||||
|
builder.tags(ImmutableSet.of("Web"));
|
||||||
|
AnonymousResource sshKey = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/admin/sshkeys/77")).type("application/vnd.tmrk.cloud.admin.sshKey").build();
|
||||||
|
|
||||||
|
NamedResource network = NamedResource.builder()
|
||||||
|
.href(URI.create("/cloudapi/ecloud/networks/3936"))
|
||||||
|
.name("10.146.204.64/28")
|
||||||
|
.type("application/vnd.tmrk.cloud.network")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
NetworkAdapterSetting adapterSetting = NetworkAdapterSetting.builder()
|
||||||
|
.network(network)
|
||||||
|
.ipAddress("10.146.204.68")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
NetworkAdapterSettings adapterSettings = NetworkAdapterSettings.builder()
|
||||||
|
.addNetworkAdapterSetting(adapterSetting).build();
|
||||||
|
NetworkSettings networkSettings = NetworkSettings.builder().networkAdapterSettings(adapterSettings).build();
|
||||||
|
|
||||||
|
LinuxCustomization linuxCustomization = LinuxCustomization.builder()
|
||||||
|
.sshKey(sshKey)
|
||||||
|
.networkSettings(networkSettings)
|
||||||
|
.build();
|
||||||
|
builder.linuxCustomization(linuxCustomization);
|
||||||
|
|
||||||
|
AnonymousResource template = AnonymousResource.builder().href(URI.create("/cloudapi/ecloud/templates/6/computepools/89")).type("application/vnd.tmrk.cloud.template").build();
|
||||||
|
builder.template(template);
|
||||||
|
|
||||||
|
VirtualMachine vm = client.createVirtualMachineFromTemplate(URI.create("/cloudapi/ecloud/virtualMachines/computePools/89/action/createVirtualMachine"), builder.build());
|
||||||
|
assertNotNull(vm);
|
||||||
|
|
||||||
|
// TODO: Check that the VM is created OK.
|
||||||
|
// TODO: DNSSettings are missing
|
||||||
|
//client.remove(vm.getHref()); //remove once verified - there needs to be no running tasks.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
/**
|
||||||
|
* 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.NamedResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.DeviceLayout;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutGroup;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRow;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineReference;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.features.LayoutAsyncClient;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.jclouds.io.Payloads.newInputStreamPayload;
|
||||||
|
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
||||||
|
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of JAXB parsing for DeviceLayout
|
||||||
|
*
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "DeviceLayoutJAXBParsingTest")
|
||||||
|
public class DeviceLayoutJAXBParsingTest 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseDeviceLayoutWithJAXB() throws Exception {
|
||||||
|
Method method = LayoutAsyncClient.class.getMethod("getLayouts",URI.class);
|
||||||
|
HttpRequest request = factory(LayoutAsyncClient.class).createRequest(method, new URI("/1"));
|
||||||
|
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||||
|
|
||||||
|
Function<HttpResponse, DeviceLayout> parser = (Function<HttpResponse, DeviceLayout>) RestAnnotationProcessor
|
||||||
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
|
InputStream is = getClass().getResourceAsStream("/deviceLayout.xml");
|
||||||
|
DeviceLayout location = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||||
|
assertRows(location.getRows());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertRows(Set<LayoutRow> rows) {
|
||||||
|
assertEquals(rows.size(),1);
|
||||||
|
LayoutRow row = Iterables.getOnlyElement(rows);
|
||||||
|
assertEquals(row.getIndex(),1);
|
||||||
|
assertGroups(row.getGroups());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertGroups(Set<LayoutGroup> groups) {
|
||||||
|
assertEquals(groups.size(),1);
|
||||||
|
LayoutGroup group = Iterables.getOnlyElement(groups);
|
||||||
|
assertEquals(group.getIndex(), 33);
|
||||||
|
assertVirtualMachineReferences(group.getVirtualMachineReferences());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertVirtualMachineReferences(Set<VirtualMachineReference> virtualMachineReferences) {
|
||||||
|
assertEquals(virtualMachineReferences.size(), 1);
|
||||||
|
VirtualMachineReference vmReference = Iterables.getOnlyElement(virtualMachineReferences);
|
||||||
|
|
||||||
|
assertEquals(vmReference.getName(),"helloworld");
|
||||||
|
assertEquals(vmReference.getStatus(), VirtualMachine.VirtualMachineStatus.DEPLOYED);
|
||||||
|
assertEquals(vmReference.getProcessorCount(),1);
|
||||||
|
assertEquals(vmReference.getMemory(), ResourceCapacity.builder().value(384).unit("MB").build());
|
||||||
|
assertEquals(vmReference.getStorage(), ResourceCapacity.builder().value(10).unit("GB").build());
|
||||||
|
|
||||||
|
|
||||||
|
NamedResource expectedOs = NamedResource.builder().href(URI.create("/cloudapi/ecloud/operatingsystems/rhel5_64guest/computepools/89"))
|
||||||
|
.name("Red Hat Enterprise Linux 5 (64-bit)")
|
||||||
|
.type("application/vnd.tmrk.cloud.operatingSystem").build();
|
||||||
|
assertEquals(vmReference.getOperatingSystem(),expectedOs);
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,7 +35,7 @@ import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.rest.BaseRestClientTest;
|
import org.jclouds.rest.BaseRestClientTest;
|
||||||
import org.jclouds.rest.RestContextSpec;
|
import org.jclouds.rest.RestContextSpec;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.Layout;
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.Layout;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.VirtualDisk;
|
import org.jclouds.tmrk.enterprisecloud.domain.hardware.VirtualDisk;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
<SshKey name="newName">
|
|
||||||
<Default>false</Default>
|
|
||||||
<FingerPrint>123</FingerPrint>
|
|
||||||
</SshKey>
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
<DeviceLayout href="/cloudapi/ecloud/layout/environments/77"
|
||||||
|
type="application/vnd.tmrk.cloud.deviceLayout"
|
||||||
|
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/environments/77" name="Beta Environment 01"
|
||||||
|
type="application/vnd.tmrk.cloud.environment" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutrows/environments/77/action/createlayoutrow"
|
||||||
|
name="createLayoutRow"
|
||||||
|
type="application/vnd.tmrk.cloud.createLayoutRow"/>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutgroups/environments/77/action/createlayoutgroup"
|
||||||
|
name="createLayoutGroup"
|
||||||
|
type="application/vnd.tmrk.cloud.createLayoutGroup"/>
|
||||||
|
</Actions>
|
||||||
|
<Rows>
|
||||||
|
<Row href="/cloudapi/ecloud/layoutrows/285" name="test row"
|
||||||
|
type="application/vnd.tmrk.cloud.layoutRow">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/layout/environments/77"
|
||||||
|
name="Beta Environment 01"
|
||||||
|
type="application/vnd.tmrk.cloud.deviceLayout" rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutgroups/environments/77/action/createlayoutgroup"
|
||||||
|
name="createLayoutGroup"
|
||||||
|
type="application/vnd.tmrk.cloud.createLayoutGroup"/>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutrows/285" name="edit"
|
||||||
|
type="application/vnd.tmrk.cloud.layoutRow"/>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutrows/285/action/moveup"
|
||||||
|
name="moveUp" actionDisabled="disabled"/>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutrows/285/action/movedown"
|
||||||
|
name="moveDown" actionDisabled="disabled"/>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutrows/285" name="remove"
|
||||||
|
actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
<Index>1</Index>
|
||||||
|
<Groups>
|
||||||
|
<Group href="/cloudapi/ecloud/layoutgroups/308"
|
||||||
|
name="test group"
|
||||||
|
type="application/vnd.tmrk.cloud.layoutGroup">
|
||||||
|
<Links>
|
||||||
|
<Link href="/cloudapi/ecloud/layoutrows/285"
|
||||||
|
name="test row"
|
||||||
|
type="application/vnd.tmrk.cloud.layoutRow"
|
||||||
|
rel="up"/>
|
||||||
|
<Link href="/cloudapi/ecloud/layout/environments/77"
|
||||||
|
name="Beta Environment 01"
|
||||||
|
type="application/vnd.tmrk.cloud.deviceLayout"
|
||||||
|
rel="up"/>
|
||||||
|
</Links>
|
||||||
|
<Actions>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutgroups/308"
|
||||||
|
name="edit"
|
||||||
|
type="application/vnd.tmrk.cloud.layoutGroup"/>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutgroups/308/action/orderhigher"
|
||||||
|
name="orderHigher" actionDisabled="disabled"/>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutgroups/308/action/orderlower"
|
||||||
|
name="orderLower" actionDisabled="disabled"/>
|
||||||
|
<Action href="/cloudapi/ecloud/layoutgroups/308"
|
||||||
|
name="remove" actionDisabled="disabled"/>
|
||||||
|
</Actions>
|
||||||
|
<Index>33</Index>
|
||||||
|
<VirtualMachines>
|
||||||
|
<VirtualMachine
|
||||||
|
href="/cloudapi/ecloud/virtualmachines/5504"
|
||||||
|
name="helloworld"
|
||||||
|
type="application/vnd.tmrk.cloud.virtualMachine">
|
||||||
|
<Status>Deployed</Status>
|
||||||
|
<ProcessorCount>1</ProcessorCount>
|
||||||
|
<Memory>
|
||||||
|
<Unit>MB</Unit>
|
||||||
|
<Value>384</Value>
|
||||||
|
</Memory>
|
||||||
|
<Storage>
|
||||||
|
<Unit>GB</Unit>
|
||||||
|
<Value>10</Value>
|
||||||
|
</Storage>
|
||||||
|
<OperatingSystem
|
||||||
|
href="/cloudapi/ecloud/operatingsystems/rhel5_64guest/computepools/89"
|
||||||
|
name="Red Hat Enterprise Linux 5 (64-bit)"
|
||||||
|
type="application/vnd.tmrk.cloud.operatingSystem"/>
|
||||||
|
</VirtualMachine>
|
||||||
|
</VirtualMachines>
|
||||||
|
</Group>
|
||||||
|
</Groups>
|
||||||
|
</Row>
|
||||||
|
</Rows>
|
||||||
|
</DeviceLayout>
|
Loading…
Reference in New Issue