Merge branch 'master' of git://github.com/jclouds/jclouds into large-blob

This commit is contained in:
Tibor Kiss 2011-03-25 11:20:46 +01:00
commit f0b141f77d
45 changed files with 1861 additions and 164 deletions

View File

@ -56,6 +56,9 @@
<test.savvis-symphonyvpdc.apiversion>0.8</test.savvis-symphonyvpdc.apiversion>
<test.savvis-symphonyvpdc.identity>FIXME</test.savvis-symphonyvpdc.identity>
<test.savvis-symphonyvpdc.credential>FIXME</test.savvis-symphonyvpdc.credential>
<test.savvis-symphonyvpdc.email>FIXME</test.savvis-symphonyvpdc.email>
<test.savvis-symphonyvpdc.loginUser>FIXME</test.savvis-symphonyvpdc.loginUser>
<test.savvis-symphonyvpdc.loginPassword>FIXME</test.savvis-symphonyvpdc.loginPassword>
</properties>
<dependencies>
<dependency>
@ -100,6 +103,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jamesmurty.utils</groupId>
<artifactId>java-xmlbuilder</artifactId>
<version>0.3</version>
</dependency>
</dependencies>
<profiles>
<profile>
@ -134,6 +142,18 @@
<name>test.savvis-symphonyvpdc.credential</name>
<value>${test.savvis-symphonyvpdc.credential}</value>
</property>
<property>
<name>test.savvis-symphonyvpdc.email</name>
<value>${test.savvis-symphonyvpdc.email}</value>
</property>
<property>
<name>test.savvis-symphonyvpdc.loginUser</name>
<value>${test.savvis-symphonyvpdc.loginUser}</value>
</property>
<property>
<name>test.savvis-symphonyvpdc.loginPassword</name>
<value>${test.savvis-symphonyvpdc.loginPassword}</value>
</property>
<property>
<name>jclouds.compute.blacklist-nodes</name>
<value>${jclouds.compute.blacklist-nodes}</value>

View File

@ -25,6 +25,7 @@ import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.features.BrowsingAsyncClient;
import org.jclouds.savvis.vpdc.features.VMAsyncClient;
import org.jclouds.savvis.vpdc.internal.Org;
import com.google.inject.Provides;
@ -45,6 +46,12 @@ public interface VPDCAsyncClient {
@Delegate
BrowsingAsyncClient getBrowsingClient();
/**
* Provides asynchronous access to VM Operation features.
*/
@Delegate
VMAsyncClient getVMClient();
/**
*
* @return a listing of all orgs that the current user has access to.
@ -54,8 +61,8 @@ public interface VPDCAsyncClient {
Set<Resource> listOrgs();
/**
* predefined by default in the classpath resource {@code
* /savvis-symphonyvpdc/predefined_operatingsystems.json}
* predefined by default in the classpath resource
* {@code /savvis-symphonyvpdc/predefined_operatingsystems.json}
*
* @return the operating systems that are predefined in the provider
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/addSingleVM.html" />

View File

@ -27,6 +27,7 @@ import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.features.BrowsingClient;
import org.jclouds.savvis.vpdc.features.VMClient;
/**
* Provides synchronous access to VPDC.
@ -45,6 +46,12 @@ public interface VPDCClient {
@Delegate
BrowsingClient getBrowsingClient();
/**
* Provides synchronous access to VM Operation features.
*/
@Delegate
VMClient getVMClient();
/**
*
* @return a listing of all orgs that the current user has access to.
@ -52,8 +59,8 @@ public interface VPDCClient {
Set<Resource> listOrgs();
/**
* predefined by default in the classpath resource {@code
* /savvis-symphonyvpdc/predefined_operatingsystems.json}
* predefined by default in the classpath resource
* {@code /savvis-symphonyvpdc/predefined_operatingsystems.json}
*
* @return the operating systems that are predefined in the provider
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/addSingleVM.html" />

View File

@ -0,0 +1,201 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import javax.inject.Singleton;
import javax.ws.rs.core.MediaType;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.savvis.vpdc.domain.VMSpec;
import com.jamesmurty.utils.XMLBuilder;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class BindVMSpecToXmlPayload extends BindToStringPayload implements MapBinder {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
throw new IllegalStateException("BindVMSpecToXmlPayload needs parameters");
}
protected VMSpec findSpecInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof VMSpec) {
return (VMSpec) arg;
} else if (arg instanceof VMSpec[]) {
VMSpec[] configuration = (VMSpec[]) arg;
return (configuration.length > 0) ? configuration[0] : null;
}
}
return null;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
request = super.bindToRequest(request,
generateXml(findSpecInArgsOrNull(gRequest), postParams.get("name"), postParams.get("networkName")));
request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_XML);
return request;
}
public String generateXml(VMSpec spec, String name, String networkName) {
checkNotNull(spec, "VMSpec");
checkNotNull(name, "name");
checkNotNull(networkName, "networkName");
try {
XMLBuilder rootBuilder = buildRootForName(name);
addOperatingSystemSection(rootBuilder, spec.getOperatingSystem());
addVirtualHardwareSection(rootBuilder, name, networkName, spec);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
} catch (Exception e) {
return null;
}
}
void addVirtualHardwareSection(XMLBuilder rootBuilder, String name, String networkName, VMSpec spec) {
XMLBuilder virtualHardwareSectionBuilder = rootBuilder.e("ovf:VirtualHardwareSection");
virtualHardwareSectionBuilder.e("ovf:Info").t("Virtual Hardware");
addSystem(virtualHardwareSectionBuilder, name);
addItems(virtualHardwareSectionBuilder, spec, networkName);
}
void addItems(XMLBuilder virtualHardwareSectionBuilder, VMSpec spec, String networkName) {
//todo make this work with fractional, which I think means setting speed to half
addCPU(virtualHardwareSectionBuilder, (int)spec.getProcessorCount());
addMemory(virtualHardwareSectionBuilder, spec.getMemoryInGig());
addNetwork(virtualHardwareSectionBuilder, networkName);
addDisks(virtualHardwareSectionBuilder, spec);
}
private void addSystem(XMLBuilder virtualHardwareSectionBuilder, String name) {
XMLBuilder systemBuilder = virtualHardwareSectionBuilder.e("ovf:System");
systemBuilder.e("vssd:Description").t("Virtual Hardware Family");
systemBuilder.e("vssd:ElementName").t(name);
systemBuilder.e("vssd:InstanceID").t("1");
systemBuilder.e("vssd:VirtualSystemIdentifier").t(name);
}
private void addOperatingSystemSection(XMLBuilder rootBuilder, CIMOperatingSystem operatingSystem) {
XMLBuilder sectionBuilder = rootBuilder.e("ovf:OperatingSystemSection").a("ovf:id",
operatingSystem.getOsType().getCode() + "");
sectionBuilder.e("ovf:Info").t("Specifies the operating system installed");
sectionBuilder.e("ovf:Description").t(operatingSystem.getDescription());
}
private void addCPU(XMLBuilder sectionBuilder, int processorCount) {
XMLBuilder cpuBuilder = sectionBuilder.e("ovf:Item");
cpuBuilder.e("rasd:AllocationUnits").t("3 GHz");
cpuBuilder.e("rasd:Description").t("Number of Virtual CPUs");
cpuBuilder.e("rasd:ElementName").t(processorCount + " CPU");
cpuBuilder.e("rasd:InstanceID").t("1");
cpuBuilder.e("rasd:ResourceType").t(ResourceType.PROCESSOR.value());
cpuBuilder.e("rasd:VirtualQuantity").t(processorCount + "");
}
private void addMemory(XMLBuilder sectionBuilder, int memoryInGig) {
XMLBuilder memoryBuilder = sectionBuilder.e("ovf:Item");
memoryBuilder.e("rasd:AllocationUnits").t("Gigabytes");
memoryBuilder.e("rasd:Description").t("Memory Size");
memoryBuilder.e("rasd:ElementName").t("Memory");
memoryBuilder.e("rasd:InstanceID").t("2");
memoryBuilder.e("rasd:ResourceType").t(ResourceType.MEMORY.value());
memoryBuilder.e("rasd:VirtualQuantity").t(memoryInGig + "");
}
private void addNetwork(XMLBuilder sectionBuilder, String networkName) {
XMLBuilder networkBuilder = sectionBuilder.e("ovf:Item");
networkBuilder.e("rasd:Caption").t("false");
networkBuilder.e("rasd:Connection").t(networkName);
networkBuilder.e("rasd:ElementName").t("Network");
networkBuilder.e("rasd:InstanceID").t("3");
networkBuilder.e("rasd:ResourceType").t(ResourceType.ETHERNET_ADAPTER.value());
networkBuilder.e("rasd:VirtualQuantity").t("1");
}
private void addDisks(XMLBuilder sectionBuilder, VMSpec spec) {
XMLBuilder bootDiskBuilder = sectionBuilder.e("ovf:Item");
bootDiskBuilder.e("rasd:AllocationUnits").t("Gigabytes");
bootDiskBuilder.e("rasd:Caption").t("");
bootDiskBuilder.e("rasd:Description").t("Hard Disk");
bootDiskBuilder.e("rasd:ElementName").t(spec.getBootDeviceName());
bootDiskBuilder.e("rasd:HostResource").t("boot");
bootDiskBuilder.e("rasd:InstanceID").t("4");
bootDiskBuilder.e("rasd:ResourceType").t(ResourceType.BASE_PARTITIONABLE_UNIT.value());
bootDiskBuilder.e("rasd:VirtualQuantity").t(spec.getBootDiskSize() + "");
int instanceId = 5;
for (Entry<String, Integer> dataDisk : spec.getDataDiskDeviceNameToSizeInGig().entrySet()) {
XMLBuilder dataDiskBuilder = sectionBuilder.e("ovf:Item");
dataDiskBuilder.e("rasd:AllocationUnits").t("Gigabytes");
dataDiskBuilder.e("rasd:Caption").t("");
dataDiskBuilder.e("rasd:Description").t("Hard Disk");
dataDiskBuilder.e("rasd:ElementName").t(dataDisk.getKey());
dataDiskBuilder.e("rasd:HostResource").t("data");
dataDiskBuilder.e("rasd:InstanceID").t("" + instanceId++);
dataDiskBuilder.e("rasd:ResourceType").t(ResourceType.PARTITIONABLE_UNIT.value());
dataDiskBuilder.e("rasd:VirtualQuantity").t(dataDisk.getValue() + "");
}
}
protected XMLBuilder buildRootForName(String name) throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("vApp:VApp")
.a("xmlns:common", "http://schemas.dmtf.org/wbem/wscim/1/common")
.a("xmlns:vApp", "http://www.vmware.com/vcloud/v0.8")
.a("xmlns:rasd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.a("xmlns:vssd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData")
.a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1").a("name", name)
.a("type", "application/vnd.vmware.vcloud.vApp+xml").a("href", "");
return rootBuilder;
}
protected String ifNullDefaultTo(String value, String defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
}
}

View File

@ -25,7 +25,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.savvis.vpdc.domain.VApp;
import org.jclouds.savvis.vpdc.domain.VM;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
@ -38,15 +38,15 @@ import com.google.inject.Provides;
public class VPDCComputeServiceContextModule extends BaseComputeServiceContextModule {
@VisibleForTesting
public static final Map<VApp.Status, NodeState> VAPPSTATUS_TO_NODESTATE = ImmutableMap
.<VApp.Status, NodeState> builder().put(VApp.Status.OFF, NodeState.SUSPENDED)
.put(VApp.Status.ON, NodeState.RUNNING).put(VApp.Status.RESOLVED, NodeState.PENDING)
.put(VApp.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(VApp.Status.UNKNOWN, NodeState.UNRECOGNIZED)
.put(VApp.Status.SUSPENDED, NodeState.SUSPENDED).put(VApp.Status.UNRESOLVED, NodeState.PENDING).build();
public static final Map<VM.Status, NodeState> VAPPSTATUS_TO_NODESTATE = ImmutableMap
.<VM.Status, NodeState> builder().put(VM.Status.OFF, NodeState.SUSPENDED)
.put(VM.Status.ON, NodeState.RUNNING).put(VM.Status.RESOLVED, NodeState.PENDING)
.put(VM.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(VM.Status.UNKNOWN, NodeState.UNRECOGNIZED)
.put(VM.Status.SUSPENDED, NodeState.SUSPENDED).put(VM.Status.UNRESOLVED, NodeState.PENDING).build();
@Singleton
@Provides
protected Map<VApp.Status, NodeState> provideVAppStatusToNodeState() {
protected Map<VM.Status, NodeState> provideVAppStatusToNodeState() {
return VAPPSTATUS_TO_NODESTATE;
}

View File

@ -53,6 +53,8 @@ import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.domain.internal.VCloudSession;
import org.jclouds.savvis.vpdc.features.BrowsingAsyncClient;
import org.jclouds.savvis.vpdc.features.BrowsingClient;
import org.jclouds.savvis.vpdc.features.VMAsyncClient;
import org.jclouds.savvis.vpdc.features.VMClient;
import org.jclouds.savvis.vpdc.handlers.VPDCErrorHandler;
import org.jclouds.savvis.vpdc.internal.LoginAsyncClient;
import org.jclouds.savvis.vpdc.internal.VCloudToken;
@ -89,7 +91,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
@org.jclouds.savvis.vpdc.internal.Org
@Singleton
protected Set<org.jclouds.savvis.vpdc.domain.Resource> provideOrgs(Supplier<VCloudSession> cache,
@Named(PROPERTY_IDENTITY) String user) {
@Named(PROPERTY_IDENTITY) String user) {
VCloudSession discovery = cache.get();
checkState(discovery.getOrgs().size() > 0, "No orgs present for user: " + user);
return discovery.getOrgs();
@ -107,13 +109,14 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
@Provides
@Singleton
protected Predicate<String> successTester(Injector injector,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
return new RetryablePredicate<String>(injector.getInstance(TaskSuccess.class), completed);
}
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(BrowsingClient.class, BrowsingAsyncClient.class)//
.build();
.put(BrowsingClient.class, BrowsingAsyncClient.class)//
.put(VMClient.class, VMAsyncClient.class)//
.build();
public VPDCRestClientModule() {
super(VPDCClient.class, VPDCAsyncClient.class, DELEGATE_MAP);
@ -122,31 +125,33 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
@Singleton
@Provides
protected Set<CIMOperatingSystem> provideOperatingSystems(Json json, @Provider String providerName)
throws IOException {
return json.fromJson(Strings2.toStringAndClose(getClass().getResourceAsStream(
"/" + providerName + "/predefined_operatingsystems.json")), new TypeLiteral<Set<CIMOperatingSystem>>() {
}.getType());
throws IOException {
return json.fromJson(
Strings2.toStringAndClose(getClass().getResourceAsStream(
"/" + providerName + "/predefined_operatingsystems.json")),
new TypeLiteral<Set<CIMOperatingSystem>>() {
}.getType());
}
@Provides
@Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final LoginAsyncClient login) {
final LoginAsyncClient login) {
return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
new Supplier<VCloudSession>() {
new Supplier<VCloudSession>() {
@Override
public VCloudSession get() {
try {
return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
propagate(e);
assert false : e;
return null;
}
@Override
public VCloudSession get() {
try {
return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
propagate(e);
assert false : e;
return null;
}
}
});
});
}
@Override

View File

@ -0,0 +1,240 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.domain;
import java.net.URI;
/**
* API returns a firewall rule in a firewall service
*
* @author Kedar Dave
*/
public class FirewallRule extends Resource {
public static Builder builder() {
return new Builder();
}
public static class Builder extends Resource.Builder {
private String firewallType;
private boolean isEnabled;
private String source;
private String destination;
private String port;
private String policy;
private String description;
private boolean isLogged;
private String protocol;
@Override
public FirewallRule build() {
return new FirewallRule(id, name, type, href, firewallType, isEnabled, source, destination, port,
policy, description, isLogged, protocol);
}
public Builder firewallType(String firewallType) {
this.firewallType = firewallType;
return this;
}
public Builder isEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
return this;
}
public Builder source(String source) {
this.source = source;
return this;
}
public Builder destination(String destination) {
this.destination = destination;
return this;
}
public Builder port(String port) {
this.port = port;
return this;
}
public Builder policy(String policy) {
this.policy = policy;
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Builder isLogged(boolean isLogged) {
this.isLogged = isLogged;
return this;
}
public Builder protocol(String protocol) {
this.protocol = protocol;
return this;
}
public static Builder fromFirewallRule(FirewallRule in) {
return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref())
.firewallType(in.getFirewallType()).isEnabled(in.isEnabled()).source(in.getSource())
.destination(in.getDestination()).port(in.getPort()).policy(in.getPolicy()).description(in.getDescription())
.isLogged(in.isLogged()).protocol(in.getProtocol());
}
@Override
public Builder id(String id) {
return Builder.class.cast(super.id(id));
}
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
}
private final String firewallType;
private final boolean isEnabled;
private final String source;
private final String destination;
private final String port;
private final String policy;
private final String description;
private final boolean isLogged;
private final String protocol;
public FirewallRule(String id, String name, String type, URI href, String firewallType, boolean isEnabled,
String source, String destination, String port, String policy, String description, boolean isLogged, String protocol) {
super(id, name, type, href);
this.firewallType = firewallType;
this.isEnabled = isEnabled;
this.source = source;
this.destination = destination;
this.port = port;
this.policy = policy;
this.description = description;
this.isLogged = isLogged;
this.protocol = protocol;
}
@Override
public Builder toBuilder() {
return Builder.fromFirewallRule(this);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FirewallRule other = (FirewallRule) obj;
if (firewallType == null) {
if (other.firewallType != null)
return false;
} else if (!firewallType.equals(other.firewallType))
return false;
if (source == null) {
if (other.source != null)
return false;
} else if (!source.equals(other.source))
return false;
if (destination == null) {
if (other.destination != null)
return false;
} else if (!destination.equals(other.destination))
return false;
if (port == null) {
if (other.port != null)
return false;
} else if (!port.equals(other.port))
return false;
if (policy == null) {
if (other.policy != null)
return false;
} else if (!policy.equals(other.policy))
return false;
if (protocol == null) {
if (other.protocol != null)
return false;
} else if (!protocol.equals(other.protocol))
return false;
return true;
}
public boolean isEnabled() {
return isEnabled;
}
public String getSource() {
return source;
}
public String getDestination() {
return destination;
}
public String getFirewallType() {
return firewallType;
}
public String getPort() {
return port;
}
public String getPolicy() {
return policy;
}
public String getDescription() {
return description;
}
public boolean isLogged() {
return isLogged;
}
public String getProtocol() {
return protocol;
}
@Override
public String toString() {
return "[firewallType=" + firewallType + ", description=" + description + ", source=" + source + ", destination=" + destination
+ ", port=" + port + ", protocol=" + protocol + ", policy=" + policy + ", isLogged=" + isLogged;
}
}

View File

@ -0,0 +1,114 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* API returns the firewall service containing firewall rules for a given VDC
*
* @author Kedar Dave
*/
public class FirewallService extends Resource {
public static Builder builder() {
return new Builder();
}
public static class Builder extends Resource.Builder {
private boolean isEnabled;
private Set<FirewallRule> firewallRules = Sets.newLinkedHashSet();
@Override
public FirewallService build() {
return new FirewallService(id, name, type, href, isEnabled, firewallRules);
}
public Builder isEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
return this;
}
public Builder firewallRule(FirewallRule in) {
this.firewallRules.add(checkNotNull(in, "firewallRule"));
return this;
}
public Builder firewallRules(Set<FirewallRule> firewallRules) {
this.firewallRules.addAll(checkNotNull(firewallRules, "firewallRules"));
return this;
}
public static Builder fromFirewallService(FirewallService in) {
return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref())
.isEnabled(in.isEnabled()).firewallRules(in.getFirewallRules());
}
@Override
public Builder id(String id) {
return Builder.class.cast(super.id(id));
}
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
}
private final boolean isEnabled;
private final Set<FirewallRule> firewallRules;
public FirewallService(String id, String name, String type, URI href, boolean isEnabled, Set<FirewallRule> firewallRules) {
super(id, name, type, href);
this.isEnabled = isEnabled;
this.firewallRules = ImmutableSet.copyOf(checkNotNull(firewallRules, "firewallRules"));
}
@Override
public Builder toBuilder() {
return Builder.fromFirewallService(this);
}
public Set<FirewallRule> getFirewallRules() {
return firewallRules;
}
public boolean isEnabled() {
return isEnabled;
}
}

View File

@ -207,8 +207,9 @@ public class Task extends Resource {
@Override
public String toString() {
return "[status=" + status + ", startTime=" + startTime + ", endTime=" + endTime + ", owner=" + owner
+ ", result=" + result + ", error=" + error + "]";
return "[id=" + id + ", name=" + name + ", type=" + type + ", href=" + href + ", status=" + status
+ ", startTime=" + startTime + ", endTime=" + endTime + ", owner=" + owner + ", result=" + result
+ ", error=" + error + "]";
}
}

View File

@ -18,7 +18,7 @@ import com.google.common.collect.Sets;
*
* @author Adrian Cole
*/
public class VApp extends Resource {
public class VM extends Resource {
/**
* Objects such as vAppTemplate, vApp, and Vm have a status attribute whose value indicates the
* state of the object. Status for an object, such as a vAppTemplate or vApp, whose Children (Vm
@ -161,12 +161,12 @@ public class VApp extends Resource {
}
@Override
public VApp build() {
return new VApp(id, name, type, href, status, ipAddress, osType, osDescripton, networkSection,
public VM build() {
return new VM(id, name, type, href, status, ipAddress, osType, osDescripton, networkSection,
resourceAllocations);
}
public static Builder fromVApp(VApp in) {
public static Builder fromVApp(VM in) {
return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref())
.status(in.getStatus()).ipAddress(in.getIpAddress()).osType(in.getOsType())
.networkSection(in.getNetworkSection()).resourceAllocations(in.getResourceAllocations())
@ -202,7 +202,7 @@ public class VApp extends Resource {
private final NetworkSection networkSection;
private final Set<ResourceAllocationSettingData> resourceAllocations;
public VApp(String id, String name, String type, URI href, Status status, String ipAddress, Integer osType,
public VM(String id, String name, String type, URI href, Status status, String ipAddress, Integer osType,
String osDescripton, NetworkSection networkSection, Set<ResourceAllocationSettingData> resourceAllocations) {
super(id, name, type, href);
this.status = status;

View File

@ -0,0 +1,214 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.domain;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import org.jclouds.compute.domain.CIMOperatingSystem;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
/**
* A specification to launch a virtual machine
*
* @author Adrian Cole
*/
public class VMSpec {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private CIMOperatingSystem operatingSystem;
// TODO docs suggest fractions are possible, but xml isn't accepted on add
private float processorCount = 1f;
private int memoryInGig = 1;
private String bootDeviceName = "/";
// TODO doesn't seem to be changeable
private int bootDriveSize = 25;
private Map<String, Integer> dataDriveDeviceNameToSizeInGig = Maps.newLinkedHashMap();
public Builder operatingSystem(CIMOperatingSystem operatingSystem) {
this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem");
return this;
}
public Builder memoryInGig(int memoryInGig) {
checkArgument(memoryInGig > 0, "memoryInGig must be positive");
this.memoryInGig = memoryInGig;
return this;
}
public Builder processorCount(float processorCount) {
checkProcessorCount(processorCount);
this.processorCount = processorCount;
return this;
}
public Builder bootDeviceName(String bootDeviceName) {
this.bootDeviceName = checkNotNull(bootDeviceName, "bootDeviceName");
return this;
}
public Builder bootDiskSize(int bootDriveSize) {
checkArgument(bootDriveSize > 0, "bootDriveSize must be positive");
this.bootDriveSize = bootDriveSize;
return this;
}
public Builder addDataDrive(String dataDriveDeviceName, int sizeInGig) {
checkArgument(sizeInGig > 0, "sizeInGig must be positive");
this.dataDriveDeviceNameToSizeInGig.put(checkNotNull(dataDriveDeviceName, "dataDriveDeviceName"), sizeInGig);
return this;
}
public Builder addDataDrives(Map<String, Integer> dataDriveDeviceNameToSizeInGig) {
this.dataDriveDeviceNameToSizeInGig = ImmutableMap.copyOf(checkNotNull(dataDriveDeviceNameToSizeInGig,
"dataDriveDeviceNameToSizeInGig"));
return this;
}
public VMSpec build() {
return new VMSpec(operatingSystem, processorCount, memoryInGig, bootDeviceName, bootDriveSize,
dataDriveDeviceNameToSizeInGig);
}
public static Builder fromVMSpec(VMSpec in) {
return new Builder().operatingSystem(in.getOperatingSystem()).memoryInGig(in.getMemoryInGig())
.bootDeviceName(in.getBootDeviceName()).bootDiskSize(in.getBootDiskSize())
.addDataDrives(in.getDataDiskDeviceNameToSizeInGig()).processorCount(in.getProcessorCount());
}
}
static void checkProcessorCount(float processorCount) {
checkArgument(processorCount > 0, "processorCount must be positive and an increment of 0.5");
checkArgument(processorCount % .5 == 0, "processorCount must be an increment of 0.5");
}
private final CIMOperatingSystem operatingSystem;
private final float processorCount;
private final int memoryInGig;
private final String bootDeviceName;
private final int bootDriveSize;
private final Map<String, Integer> dataDriveDeviceNameToSizeInGig;
protected VMSpec(CIMOperatingSystem operatingSystem, float processorCount, int memoryInGig, String bootDeviceName,
int bootDriveSize, Map<String, Integer> dataDriveDeviceNameToSizeInGig) {
this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem not specified");
checkProcessorCount(processorCount);
this.processorCount = processorCount;
checkArgument(memoryInGig > 0, "memoryInGig must be positive");
this.memoryInGig = memoryInGig;
this.bootDeviceName = checkNotNull(bootDeviceName, "bootDeviceName name not specified");
checkArgument(bootDriveSize > 0, "bootDriveSize must be positive");
this.bootDriveSize = bootDriveSize;
this.dataDriveDeviceNameToSizeInGig = ImmutableMap.copyOf(checkNotNull(dataDriveDeviceNameToSizeInGig,
"dataDriveDeviceNameToSizeInGig"));
}
public CIMOperatingSystem getOperatingSystem() {
return operatingSystem;
}
public float getProcessorCount() {
return processorCount;
}
public int getMemoryInGig() {
return memoryInGig;
}
public Builder toBuilder() {
return Builder.fromVMSpec(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((bootDeviceName == null) ? 0 : bootDeviceName.hashCode());
result = prime * result + bootDriveSize;
result = prime * result
+ ((dataDriveDeviceNameToSizeInGig == null) ? 0 : dataDriveDeviceNameToSizeInGig.hashCode());
result = prime * result + memoryInGig;
result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode());
result = prime * result + Float.floatToIntBits(processorCount);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VMSpec other = (VMSpec) obj;
if (bootDeviceName == null) {
if (other.bootDeviceName != null)
return false;
} else if (!bootDeviceName.equals(other.bootDeviceName))
return false;
if (bootDriveSize != other.bootDriveSize)
return false;
if (dataDriveDeviceNameToSizeInGig == null) {
if (other.dataDriveDeviceNameToSizeInGig != null)
return false;
} else if (!dataDriveDeviceNameToSizeInGig.equals(other.dataDriveDeviceNameToSizeInGig))
return false;
if (memoryInGig != other.memoryInGig)
return false;
if (operatingSystem == null) {
if (other.operatingSystem != null)
return false;
} else if (!operatingSystem.equals(other.operatingSystem))
return false;
if (Float.floatToIntBits(processorCount) != Float.floatToIntBits(other.processorCount))
return false;
return true;
}
public String getBootDeviceName() {
return bootDeviceName;
}
public int getBootDiskSize() {
return bootDriveSize;
}
public Map<String, Integer> getDataDiskDeviceNameToSizeInGig() {
return dataDriveDeviceNameToSizeInGig;
}
@Override
public String toString() {
return "[operatingSystem=" + operatingSystem + ", processorCount=" + processorCount + ", memoryInGig="
+ memoryInGig + ", bootDeviceName=" + bootDeviceName + ", bootDriveSize=" + bootDriveSize
+ ", dataDriveDeviceNameToSizeInGig=" + dataDriveDeviceNameToSizeInGig + "]";
}
}

View File

@ -30,20 +30,22 @@ import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.savvis.vpdc.domain.FirewallService;
import org.jclouds.savvis.vpdc.domain.Network;
import org.jclouds.savvis.vpdc.domain.Org;
import org.jclouds.savvis.vpdc.domain.Task;
import org.jclouds.savvis.vpdc.domain.VApp;
import org.jclouds.savvis.vpdc.domain.VDC;
import org.jclouds.savvis.vpdc.domain.VM;
import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie;
import org.jclouds.savvis.vpdc.functions.DefaultOrgIfNull;
import org.jclouds.savvis.vpdc.options.BindGetVAppOptions;
import org.jclouds.savvis.vpdc.options.GetVAppOptions;
import org.jclouds.savvis.vpdc.options.BindGetVMOptions;
import org.jclouds.savvis.vpdc.options.GetVMOptions;
import org.jclouds.savvis.vpdc.xml.FirewallServiceHandler;
import org.jclouds.savvis.vpdc.xml.NetworkHandler;
import org.jclouds.savvis.vpdc.xml.OrgHandler;
import org.jclouds.savvis.vpdc.xml.TaskHandler;
import org.jclouds.savvis.vpdc.xml.VAppHandler;
import org.jclouds.savvis.vpdc.xml.VDCHandler;
import org.jclouds.savvis.vpdc.xml.VMHandler;
import com.google.common.util.concurrent.ListenableFuture;
@ -80,27 +82,27 @@ public interface BrowsingAsyncClient {
@PathParam("vpdcId") String vpdcId);
/**
* @see BrowsingClient#getNetworkInOrgAndVDC
* @see BrowsingClient#getNetworkInVDC
*/
@GET
@XMLResponseParser(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("org/{billingSiteId}/vdc/{vpdcId}/network/{network-tier-name}")
ListenableFuture<Network> getNetworkInOrgAndVDC(
ListenableFuture<Network> getNetworkInVDC(
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
@PathParam("vpdcId") String vpdcId, @PathParam("network-tier-name") String networkTierName);
/**
* @see BrowsingClient#getVAppInOrgAndVDC
* @see BrowsingClient#getVMInVDC
*/
@GET
@XMLResponseParser(VAppHandler.class)
@XMLResponseParser(VMHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}")
ListenableFuture<VApp> getVAppInOrgAndVDC(
ListenableFuture<VM> getVMInVDC(
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
@PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId,
@BinderParam(BindGetVAppOptions.class) GetVAppOptions... options);
@BinderParam(BindGetVMOptions.class) GetVMOptions... options);
/**
* @see BrowsingClient#getTask
@ -111,4 +113,14 @@ public interface BrowsingAsyncClient {
@Path("task/{taskId}")
ListenableFuture<Task> getTask(@PathParam("taskId") String taskId);
/**
* @see BrowsingClient#listFirewallRules
*/
@GET
@XMLResponseParser(FirewallServiceHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("org/{billingSiteId}/vdc/{vpdcId}/FirewallService")
ListenableFuture<FirewallService> listFirewallRules(@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
@PathParam("vpdcId") String vpdcId);
}

View File

@ -24,12 +24,13 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.savvis.vpdc.domain.FirewallService;
import org.jclouds.savvis.vpdc.domain.Network;
import org.jclouds.savvis.vpdc.domain.Org;
import org.jclouds.savvis.vpdc.domain.Task;
import org.jclouds.savvis.vpdc.domain.VApp;
import org.jclouds.savvis.vpdc.domain.VM;
import org.jclouds.savvis.vpdc.domain.VDC;
import org.jclouds.savvis.vpdc.options.GetVAppOptions;
import org.jclouds.savvis.vpdc.options.GetVMOptions;
/**
* Provides access to Symphony VPDC resources via their REST API.
@ -73,7 +74,7 @@ public interface BrowsingClient {
* @return network detail if it used any one deployed VM and NetworkConfigSection defines various
* network features such NAT Public IP, Gateway and Netmask, or null if not present
*/
Network getNetworkInOrgAndVDC(String billingSiteId, String vpdcId, String networkTierName);
Network getNetworkInVDC(String billingSiteId, String vpdcId, String networkTierName);
/**
* VAPP is a software solution, the API returns details of virtual machine configuration such as
@ -92,17 +93,31 @@ public interface BrowsingClient {
* machines, all of which are deployed, managed, and maintained as a unit, or null if not
* present
*/
VApp getVAppInOrgAndVDC(String billingSiteId, String vpdcId, String vAppId, GetVAppOptions... options);
VM getVMInVDC(String billingSiteId, String vpdcId, String vAppId, GetVMOptions... options);
/**
* Gets an existing task.
*
* @param taskId
* task id
* @return If the request is successful, caller could get the VApp/VMDK details as specified in
* @return If the request is successful, caller could get the VM/VMDK details as specified in
* the result element and if the request is not successful, caller would get empty
* VAPP/VMDK URL and respective validation (error) message.
*/
Task getTask(String taskId);
/**
* Gets Firewall Rules
*
* @param billingSiteId
* billing site Id, or null for default
* @param vpdcId
* vpdc Id
*
* @return If the request is successful, caller could get the firewall rules as specified in the
* result element and if the request is not successful, caller would get empty
* rules list and respective validation (error) message.
*/
FirewallService listFirewallRules(String billingSiteId, String vpdcId);
}

View File

@ -0,0 +1,78 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.features;
import javax.annotation.Nullable;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.savvis.vpdc.binders.BindVMSpecToXmlPayload;
import org.jclouds.savvis.vpdc.domain.Task;
import org.jclouds.savvis.vpdc.domain.VMSpec;
import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie;
import org.jclouds.savvis.vpdc.functions.DefaultOrgIfNull;
import org.jclouds.savvis.vpdc.xml.TaskHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to Symphony VPDC resources via their REST API.
* <p/>
*
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/index.html" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
@Path("v{jclouds.api-version}")
public interface VMAsyncClient {
/**
* @see VMClient#addVMIntoVDC
*/
@GET
@XMLResponseParser(TaskHandler.class)
@Path("org/{billingSiteId}/vdc/{vpdcId}/vApp/")
@MapBinder(BindVMSpecToXmlPayload.class)
ListenableFuture<Task> addVMIntoVDC(
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
@PathParam("vpdcId") String vpdcId, @PayloadParam("networkName") String networkTierName,
@PayloadParam("name") String vAppName, VMSpec spec);
/**
* @see VMClient#removeVMFromVDC
*/
@DELETE
@XMLResponseParser(TaskHandler.class)
@Path("org/{billingSiteId}/vdc/{vpdcId}/vApp/{vAppId}")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Task> removeVMFromVDC(
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
@PathParam("vpdcId") String vpdcId, @PathParam("vAppId") String vAppId);
}

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.features;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.savvis.vpdc.domain.Task;
import org.jclouds.savvis.vpdc.domain.VMSpec;
/**
* Provides access to Symphony VPDC resources via their REST API.
* <p/>
*
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VMClient {
/**
* Add/Deploy new VM into VDC
*
* @param billingSiteId
* billing site Id, or null for default
* @param vpdcId
* vpdc Id
* @param networkTierName
* network tier name
* @param spec
* how to
*
* @return VM in progress
*/
Task addVMIntoVDC(String billingSiteId, String vpdcId, String networkTierName, String name, VMSpec spec);
/**
* Remove a VM
* <p/>
* <h4>Pre-conditions:</h4>
*
* <ul>
* <li>No snapshot has been created for the VM.</li>
* <li>For Balanced profile, the VM must not be associated with any firewall rule and/or included
* in a load balancing pool.</li>
* </ul>
*
* @param billingSiteId
* @param vpdcId
* @param vAppId
* @return
*/
Task removeVMFromVDC(String billingSiteId, String vpdcId, String vAppId);
}

View File

@ -15,19 +15,19 @@ import org.jclouds.rest.Binder;
* @author Adrian Cole
*/
@Singleton
public class BindGetVAppOptions implements Binder {
public class BindGetVMOptions implements Binder {
private final Provider<UriBuilder> uriBuilder;
@Inject
public BindGetVAppOptions(Provider<UriBuilder> uriBuilder) {
public BindGetVMOptions(Provider<UriBuilder> uriBuilder) {
this.uriBuilder = uriBuilder;
}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(input instanceof GetVAppOptions[], "this binder is only valid for GetVAppOptions!");
GetVAppOptions[] options = GetVAppOptions[].class.cast(input);
checkArgument(input instanceof GetVMOptions[], "this binder is only valid for GetVAppOptions!");
GetVMOptions[] options = GetVMOptions[].class.cast(input);
if (options.length > 0 && options[0].isWithPowerState())
return (R) request.toBuilder().endpoint(
uriBuilder.get().uri(request.getEndpoint()).path("withpowerstate").build()).build();

View File

@ -30,21 +30,21 @@ package org.jclouds.savvis.vpdc.options;
* import static org.jclouds.savvis.vpdc.options.GetVAppOptions.Builder.*
* <p/>
*
* vApp = context.getApi().getBrowsingClient().getVAppInOrgAndVDC(orgId, vdcId, vAppId, withPowerState());
* vApp = context.getApi().getBrowsingClient().getVAppInVDC(orgId, vdcId, vAppId, withPowerState());
* <code>
*
* @author Adrian Cole
* @see <a href= "https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/getVAppPowerState.html"
* />
*/
public class GetVAppOptions {
public static final GetVAppOptions NONE = new GetVAppOptions();
public class GetVMOptions {
public static final GetVMOptions NONE = new GetVMOptions();
private boolean withPowerState;
/**
* The VM State is the real time state.
*/
public GetVAppOptions withPowerState() {
public GetVMOptions withPowerState() {
this.withPowerState = true;
return this;
}
@ -56,10 +56,10 @@ public class GetVAppOptions {
public static class Builder {
/**
* @see GetVAppOptions#withPowerState()
* @see GetVMOptions#withPowerState()
*/
public static GetVAppOptions withPowerState() {
GetVAppOptions options = new GetVAppOptions();
public static GetVMOptions withPowerState() {
GetVMOptions options = new GetVMOptions();
return options.withPowerState();
}

View File

@ -1,5 +1,7 @@
package org.jclouds.savvis.vpdc.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Resource;
import javax.inject.Singleton;
@ -30,13 +32,18 @@ public class TaskSuccess implements Predicate<String> {
}
public boolean apply(String taskId) {
logger.trace("looking for status on task %s", taskId);
Task task = client.getBrowsingClient().getTask(taskId);
logger.trace("%s: looking for status %s: currently: %s", task, Task.Status.SUCCESS, task.getStatus());
if (task.getStatus() == Task.Status.ERROR || task.getStatus() == Task.Status.NONE)
throw new RuntimeException("error on task: " + task.getHref() + " error: " + task.getError());
logger.trace("looking for status on task %s", checkNotNull(taskId, "taskId"));
Task task = refresh(taskId);
if (task == null)
return false;
logger.trace("%s: looking for task status %s: currently: %s", task.getId(), Task.Status.SUCCESS, task.getStatus());
if (task.getError() != null)
throw new IllegalStateException(String.format("task %s failed with exception %s", task.getId(), task
.getError().toString()));
return task.getStatus() == Task.Status.SUCCESS;
}
private Task refresh(String taskId) {
return client.getBrowsingClient().getTask(taskId);
}
}

View File

@ -0,0 +1,86 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.savvis.vpdc.domain.FirewallRule;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Kedar Dave
*/
public class FirewallRuleHandler extends ParseSax.HandlerWithResult<FirewallRule> {
protected StringBuilder currentText = new StringBuilder();
private FirewallRule.Builder builder = FirewallRule.builder();
public FirewallRule getResult() {
try {
return builder.build();
} finally {
builder = FirewallRule.builder();
}
}
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
String current = currentOrNull(currentText);
if (current != null) {
if (equalsOrSuffix(qName, "Type")) {
builder.firewallType(current);
} else if (equalsOrSuffix(qName, "IsEnabled")) {
builder.isEnabled(Boolean.parseBoolean(current));
} else if (equalsOrSuffix(qName, "Source")) {
builder.source(current);
} else if (equalsOrSuffix(qName, "Destination")) {
builder.destination(current);
} else if (equalsOrSuffix(qName, "Port")) {
builder.port(current);
} else if (equalsOrSuffix(qName, "Policy")) {
builder.policy(current);
} else if (equalsOrSuffix(qName, "Description")) {
builder.description(current);
} else if (equalsOrSuffix(qName, "Log")) {
builder.isLogged(Boolean.parseBoolean(current));
} else if (equalsOrSuffix(qName, "Tcp")) {
builder.protocol("Tcp");
} else if (qName.contains("Udp") || qName.contains("udp")) {
builder.protocol("Udp");
} else if (qName.contains("Icmp") || qName.contains("icmp") || qName.contains("Ping")
|| qName.contains("ping")) {
builder.protocol("Icmp-ping");
}
}
currentText = new StringBuilder();
}
@Override
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -0,0 +1,92 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.savvis.vpdc.domain.FirewallService;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Kedar Dave
*/
public class FirewallServiceHandler extends ParseSax.HandlerWithResult<FirewallService> {
protected StringBuilder currentText = new StringBuilder();
private FirewallRuleHandler firewallRuleHandler;
private FirewallService.Builder builder = FirewallService.builder();
boolean inFirewallService;
boolean inFirewallRule;
@Inject
public FirewallServiceHandler(FirewallRuleHandler firewallRuleHandler) {
this.firewallRuleHandler = firewallRuleHandler;
}
public FirewallService getResult() {
try {
return builder.build();
} finally {
builder = FirewallService.builder();
}
}
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (equalsOrSuffix(qName, "FirewallService")) {
inFirewallService = true;
} else if (equalsOrSuffix(qName, "FirewallRule")) {
inFirewallRule = true;
firewallRuleHandler.startElement(uri, localName, qName, attrs);
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (equalsOrSuffix(qName, "FirewallService")) {
inFirewallService = false;
} else if (equalsOrSuffix(qName, "FirewallRule")) {
builder.firewallRule(firewallRuleHandler.getResult());
inFirewallRule = false;
} else if (equalsOrSuffix(qName, "isEnabled")) {
if (inFirewallService) {
String current = currentOrNull(currentText);
if (current != null) {
builder.isEnabled(Boolean.parseBoolean(current));
}
}
}
if (inFirewallRule) {
firewallRuleHandler.endElement(uri, localName, qName);
}
currentText = new StringBuilder();
}
@Override
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
firewallRuleHandler.characters(ch, start, length);
}
}

View File

@ -22,6 +22,7 @@ package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull;
import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map;
@ -53,22 +54,22 @@ public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("Network")) {
if (equalsOrSuffix(qName, "Network")) {
// savvis doesn't add href in the header for some reason
if (!attributes.containsKey("href") && getRequest() != null)
attributes = ImmutableMap.<String, String> builder().putAll(attributes)
.put("href", getRequest().getEndpoint().toASCIIString()).build();
Resource org = newResource(attributes);
builder.name(org.getName()).type(org.getType()).id(org.getId()).href(org.getHref());
} else if (qName.endsWith("NatRule")) {
} else if (equalsOrSuffix(qName, "NatRule")) {
builder.internalToExternalNATRule(attributes.get("internalIP"), attributes.get("externalIP"));
}
}
public void endElement(String uri, String name, String qName) {
if (qName.endsWith("Gateway")) {
if (equalsOrSuffix(qName, "Gateway")) {
builder.gateway(currentOrNull(currentText));
} else if (qName.endsWith("Netmask")) {
} else if (equalsOrSuffix(qName, "Netmask")) {
builder.netmask(currentOrNull(currentText));
}
currentText = new StringBuilder();

View File

@ -22,6 +22,7 @@ package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull;
import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map;
@ -54,14 +55,14 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Org> {
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("Org")) {
if (equalsOrSuffix(qName, "Org")) {
// savvis doesn't add href in the header for some reason
if (!attributes.containsKey("href") && getRequest() != null)
attributes = ImmutableMap.<String, String> builder().putAll(attributes)
.put("href", getRequest().getEndpoint().toASCIIString()).build();
Resource org = newResource(attributes);
builder.name(org.getName()).type(org.getType()).id(org.getId()).href(org.getHref());
} else if (qName.endsWith("Link")) {
} else if (equalsOrSuffix(qName, "Link")) {
Link link = Link.class.cast(newResource(attributes));
if ("down".equals(link.getRel()))
builder.vDC(link);
@ -71,7 +72,7 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Org> {
}
public void endElement(String uri, String name, String qName) {
if (qName.endsWith("Description")) {
if (equalsOrSuffix(qName, "Description")) {
builder.description(currentOrNull(currentText));
}
currentText = new StringBuilder();

View File

@ -2,6 +2,7 @@ package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map;
import java.util.Set;
@ -32,7 +33,7 @@ public class OrgListHandler extends ParseSax.HandlerWithResult<Set<Resource>> {
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("Org")) {
if (equalsOrSuffix(qName, "Org")) {
org.add(newResource(attributes));
}
}

View File

@ -21,6 +21,7 @@ package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Date;
import java.util.Map;
@ -65,7 +66,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("Task")) {
if (equalsOrSuffix(qName, "Task")) {
Resource task = newResource(attributes);
builder.id(task.getId());
builder.type(task.getType());
@ -75,11 +76,11 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
if (attributes.containsKey("endTime"))
builder.endTime(parseDate(attributes.get("endTime")));
builder.status(Task.Status.fromValue(attributes.get("status")));
} else if (qName.endsWith("Owner")) {
} else if (equalsOrSuffix(qName, "Owner")) {
builder.owner(Utils.newResource(attributes));
} else if (qName.endsWith("Result")) {
} else if (equalsOrSuffix(qName, "Result")) {
builder.result(Utils.newResource(attributes));
} else if (qName.endsWith("Error")) {
} else if (equalsOrSuffix(qName, "Error")) {
builder.error(new TaskError(attributes.get("message"), Integer.parseInt(attributes.get("majorErrorCode")),
Integer.parseInt(attributes.get("minorErrorCode")), attributes.get("vendorSpecificErrorCode")));
}

View File

@ -19,6 +19,8 @@
package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Set;
import javax.inject.Inject;
@ -60,7 +62,7 @@ public class TasksListHandler extends ParseSax.HandlerWithResult<Set<Task>> {
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
taskHandler.endElement(uri, localName, qName);
if (qName.equals("Task")) {
if (equalsOrSuffix(qName, "Task")) {
this.tasks.add(taskHandler.getResult());
}
}

View File

@ -22,6 +22,7 @@ package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull;
import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map;
@ -54,24 +55,24 @@ public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("Vdc")) {
if (equalsOrSuffix(qName, "Vdc")) {
// savvis doesn't add href in the header for some reason
if (!attributes.containsKey("href") && getRequest() != null)
attributes = ImmutableMap.<String, String> builder().putAll(attributes)
.put("href", getRequest().getEndpoint().toASCIIString()).build();
Resource vDC = newResource(attributes);
builder.name(vDC.getName()).type(vDC.getType()).id(vDC.getId()).href(vDC.getHref());
} else if (qName.endsWith("Network")) {
} else if (equalsOrSuffix(qName, "Network")) {
builder.availableNetwork(newResource(attributes));
} else if (qName.endsWith("ResourceEntity")) {
} else if (equalsOrSuffix(qName, "ResourceEntity")) {
builder.resourceEntity(newResource(attributes));
}
}
public void endElement(String uri, String name, String qName) {
if (qName.endsWith("Description")) {
if (equalsOrSuffix(qName, "Description")) {
builder.description(currentOrNull(currentText));
} else if (qName.endsWith("OfferingTag")) {
} else if (equalsOrSuffix(qName, "OfferingTag")) {
builder.status(Status.fromValue(currentOrNull(currentText)));
}
currentText = new StringBuilder();

View File

@ -20,6 +20,7 @@
package org.jclouds.savvis.vpdc.xml;
import static org.jclouds.savvis.vpdc.util.Utils.newResource;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map;
@ -29,7 +30,7 @@ import org.jclouds.cim.xml.ResourceAllocationSettingDataHandler;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ovf.xml.NetworkSectionHandler;
import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.domain.VApp;
import org.jclouds.savvis.vpdc.domain.VM;
import org.jclouds.savvis.vpdc.util.Utils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@ -39,39 +40,39 @@ import com.google.common.collect.ImmutableMap;
/**
* @author Kedar Dave
*/
public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
public class VMHandler extends ParseSax.HandlerWithResult<VM> {
protected StringBuilder currentText = new StringBuilder();
private final NetworkSectionHandler networkSectionHandler;
private final ResourceAllocationSettingDataHandler allocationHandler;
@Inject
public VAppHandler(NetworkSectionHandler networkSectionHandler, ResourceAllocationSettingDataHandler allocationHandler) {
public VMHandler(NetworkSectionHandler networkSectionHandler, ResourceAllocationSettingDataHandler allocationHandler) {
this.networkSectionHandler = networkSectionHandler;
this.allocationHandler = allocationHandler;
}
private VApp.Builder builder = VApp.builder();
private VM.Builder builder = VM.builder();
protected boolean inOs;
public VApp getResult() {
public VM getResult() {
try {
return builder.build();
} finally {
builder = VApp.builder();
builder = VM.builder();
}
}
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = Utils.cleanseAttributes(attrs);
if (qName.endsWith("VApp")) {
if (equalsOrSuffix(qName, "VApp")) {
// savvis doesn't add href in the header for some reason
if (!attributes.containsKey("href") && getRequest() != null)
attributes = ImmutableMap.<String, String> builder().putAll(attributes)
.put("href", getRequest().getEndpoint().toASCIIString()).build();
Resource vApp = newResource(attributes);
builder.name(vApp.getName()).type(vApp.getType()).id(vApp.getId()).href(vApp.getHref());
builder.status(VApp.Status.fromValue(attributes.get("status")));
} else if (qName.endsWith("OperatingSystemSection")) {
builder.status(VM.Status.fromValue(attributes.get("status")));
} else if (equalsOrSuffix(qName, "OperatingSystemSection")) {
inOs = true;
if (attributes.containsKey("id"))
builder.osType(Integer.parseInt(attributes.get("id")));
@ -84,16 +85,16 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.endsWith("OperatingSystemSection")) {
if (equalsOrSuffix(qName, "OperatingSystemSection")) {
inOs = false;
} else if (inOs && qName.endsWith("Description")) {
} else if (inOs && equalsOrSuffix(qName, "Description")) {
builder.osDescripton(Utils.currentOrNull(currentText));
} else if (qName.endsWith("IpAddress")) {
} else if (equalsOrSuffix(qName, "IpAddress")) {
builder.ipAddress(Utils.currentOrNull(currentText));
} else if (qName.endsWith("NetworkSection")) {
} else if (equalsOrSuffix(qName, "NetworkSection")) {
networkSectionHandler.endElement(uri, localName, qName);
builder.networkSection(networkSectionHandler.getResult());
} else if (qName.endsWith("Item")) {
} else if (equalsOrSuffix(qName, "Item")) {
allocationHandler.endElement(uri, localName, qName);
builder.resourceAllocation(allocationHandler.getResult());
} else {

View File

@ -16,7 +16,7 @@
"osType": "RHEL"
},
{
"family": "RHEL_64",
"family": "RHEL",
"name": "rhel5_64Guest",
"version": "5",
"description": "Red Hat Enterprise Linux 5.x 64bit",

View File

@ -45,6 +45,7 @@ public class VPDCAsyncClientTest extends BaseVPDCAsyncClientTest<VPDCAsyncClient
public void testSync() {
assert syncClient.getBrowsingClient() != null;
assert syncClient.getVMClient() != null;
assertEquals(syncClient.listOrgs().size(), 1);
assertEquals(syncClient.listPredefinedOperatingSystems().size(), 3);
@ -52,6 +53,7 @@ public class VPDCAsyncClientTest extends BaseVPDCAsyncClientTest<VPDCAsyncClient
public void testAsync() {
assert asyncClient.getBrowsingClient() != null;
assert asyncClient.getVMClient() != null;
assertEquals(asyncClient.listOrgs().size(), 1);
assertEquals(asyncClient.listPredefinedOperatingSystems().size(), 3);

View File

@ -0,0 +1,66 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.binders;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Set;
import org.jclouds.cim.OSType;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.savvis.vpdc.domain.VMSpec;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.gson.Gson;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code BindVMSpecToXmlPayload}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class BindVMSpecToXmlPayloadTest {
public void test() throws IOException {
CIMOperatingSystem os = Iterables.find(new Gson().<Set<CIMOperatingSystem>> fromJson(
Strings2.toStringAndClose(getClass().getResourceAsStream(
"/savvis-symphonyvpdc/predefined_operatingsystems.json")),
new TypeLiteral<Set<CIMOperatingSystem>>() {
}.getType()), new Predicate<CIMOperatingSystem>() {
@Override
public boolean apply(CIMOperatingSystem arg0) {
return arg0.getOsType() == OSType.RHEL_64;
}
});
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-default.xml"));
VMSpec spec = VMSpec.builder().operatingSystem(os).build();
assertEquals(new BindVMSpecToXmlPayload().generateXml(spec, "DemoHost-1", "VM Tier01"), expected);
}
}

View File

@ -28,12 +28,16 @@ import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.savvis.vpdc.VPDCAsyncClient;
import org.jclouds.savvis.vpdc.VPDCClient;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VPDCClient}
@ -49,11 +53,12 @@ public class BaseVPDCClientLiveTest {
protected String credential;
protected String endpoint;
protected String apiversion;
protected Injector injector;
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
+ ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion");
}
@ -73,8 +78,13 @@ public class BaseVPDCClientLiveTest {
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
context = new RestContextFactory().createContext(provider, ImmutableSet.<Module> of(new Log4JLoggingModule()),
overrides);
// context = new RestContextFactory().createContext(provider, ImmutableSet.<Module> of(new
// Log4JLoggingModule()),
// overrides);
injector = new RestContextFactory().createContextBuilder(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector();
context = injector.getInstance(Key.get(new TypeLiteral<RestContext<VPDCClient, VPDCAsyncClient>>() {
}));
}
@AfterGroups(groups = "live")

View File

@ -26,12 +26,13 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.savvis.vpdc.options.GetVAppOptions;
import org.jclouds.savvis.vpdc.options.GetVMOptions;
import org.jclouds.savvis.vpdc.xml.FirewallServiceHandler;
import org.jclouds.savvis.vpdc.xml.NetworkHandler;
import org.jclouds.savvis.vpdc.xml.OrgHandler;
import org.jclouds.savvis.vpdc.xml.TaskHandler;
import org.jclouds.savvis.vpdc.xml.VAppHandler;
import org.jclouds.savvis.vpdc.xml.VDCHandler;
import org.jclouds.savvis.vpdc.xml.VMHandler;
import org.testng.annotations.Test;
import com.google.inject.TypeLiteral;
@ -105,7 +106,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
}
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getNetworkInOrgAndVDC", String.class, String.class,
Method method = BrowsingAsyncClient.class.getMethod("getNetworkInVDC", String.class, String.class,
String.class);
HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01");
@ -122,7 +123,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
}
public void testNetworkWhenOrgNull() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getNetworkInOrgAndVDC", String.class, String.class,
Method method = BrowsingAsyncClient.class.getMethod("getNetworkInVDC", String.class, String.class,
String.class);
HttpRequest request = processor.createRequest(method, (String) null, "22", "VM-Tier01");
@ -138,9 +139,9 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
checkFilters(request);
}
public void testVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getVAppInOrgAndVDC", String.class, String.class,
String.class, GetVAppOptions[].class);
public void testVM() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getVMInVDC", String.class, String.class,
String.class, GetVMOptions[].class);
HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01");
assertRequestLineEquals(request,
@ -149,16 +150,16 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertSaxResponseParserClassEquals(method, VMHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testVAppWithPowerState() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getVAppInOrgAndVDC", String.class, String.class,
String.class, GetVAppOptions[].class);
HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01", GetVAppOptions.Builder
public void testVMWithPowerState() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getVMInVDC", String.class, String.class,
String.class, GetVMOptions[].class);
HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01", GetVMOptions.Builder
.withPowerState());
assertRequestLineEquals(request,
@ -167,15 +168,15 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertSaxResponseParserClassEquals(method, VMHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
public void testVAppWhenOrgNull() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getVAppInOrgAndVDC", String.class, String.class,
String.class, GetVAppOptions[].class);
public void testVMWhenOrgNull() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("getVMInVDC", String.class, String.class,
String.class, GetVMOptions[].class);
HttpRequest request = processor.createRequest(method, (String) null, "22", "VM-Tier01");
assertRequestLineEquals(request,
@ -184,7 +185,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertSaxResponseParserClassEquals(method, VMHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
@ -205,6 +206,22 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
checkFilters(request);
}
public void testListFirewallRules() throws SecurityException, NoSuchMethodException, IOException {
Method method = BrowsingAsyncClient.class.getMethod("listFirewallRules", String.class, String.class);
HttpRequest request = processor.createRequest(method, "11", "22");
assertRequestLineEquals(request,
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/FirewallService HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, FirewallServiceHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<BrowsingAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<BrowsingAsyncClient>>() {

View File

@ -19,14 +19,19 @@
package org.jclouds.savvis.vpdc.features;
import static org.jclouds.savvis.vpdc.options.GetVAppOptions.Builder.withPowerState;
import static org.jclouds.savvis.vpdc.options.GetVMOptions.Builder.withPowerState;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Iterator;
import java.util.Set;
import org.jclouds.savvis.vpdc.domain.FirewallRule;
import org.jclouds.savvis.vpdc.domain.FirewallService;
import org.jclouds.savvis.vpdc.domain.Network;
import org.jclouds.savvis.vpdc.domain.Org;
import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.domain.VApp;
import org.jclouds.savvis.vpdc.domain.VM;
import org.jclouds.savvis.vpdc.domain.VDC;
import org.jclouds.savvis.vpdc.reference.VCloudMediaType;
import org.testng.annotations.BeforeGroups;
@ -60,7 +65,7 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
assertEquals(response.getType(), null);
assert response.getImages().size() >= 0;
assert response.getDescription() != null;
assert response.getVDCs().size() >= 1;
assert response.getVDCs().size() >= 0;
assertEquals(client.getOrg(response.getId()).toString(), response.toString());
}
}
@ -92,7 +97,7 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
for (Resource vdc : org.getVDCs()) {
VDC VDC = client.getVDCInOrg(org.getId(), vdc.getId());
for (Resource vApp : VDC.getAvailableNetworks()) {
Network response = client.getNetworkInOrgAndVDC(org.getId(), vdc.getId(), vApp.getId());
Network response = client.getNetworkInVDC(org.getId(), vdc.getId(), vApp.getId());
assertNotNull(response);
assertNotNull(response.getId());
assertNotNull(response.getHref());
@ -101,15 +106,15 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
assertNotNull(response.getNetmask());
assertNotNull(response.getGateway());
assertNotNull(response.getInternalToExternalNATRules());
assertEquals(client.getNetworkInOrgAndVDC(org.getId(), vdc.getId(), response.getId()).toString(),
assertEquals(client.getNetworkInVDC(org.getId(), vdc.getId(), response.getId()).toString(),
response.toString());
}
}
}
}
@Test
public void testVApp() throws Exception {
public void testVM() throws Exception {
for (Resource org1 : context.getApi().listOrgs()) {
Org org = client.getOrg(org1.getId());
for (Resource vdc : org.getVDCs()) {
@ -122,7 +127,7 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
}
})) {
VApp response = client.getVAppInOrgAndVDC(org.getId(), vdc.getId(), vApp.getId());
VM response = client.getVMInVDC(org.getId(), vdc.getId(), vApp.getId());
assertNotNull(response);
assertNotNull(response.getId());
assertNotNull(response.getHref());
@ -135,7 +140,7 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
assertNotNull(response.getNetworkSection());
assertNotNull(response.getResourceAllocations());
// power state is the only thing that should change
assertEquals(client.getVAppInOrgAndVDC(org.getId(), vdc.getId(), response.getId(), withPowerState())
assertEquals(client.getVMInVDC(org.getId(), vdc.getId(), response.getId(), withPowerState())
.toString().replaceFirst("status=[A-Z]+", ""), response.toString().replaceFirst(
"status=[A-Z]+", ""));
}
@ -143,4 +148,29 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
}
}
}
@Test
public void testGetFirewallRules() throws Exception {
for (Resource org1 : context.getApi().listOrgs()) {
Org org = client.getOrg(org1.getId());
for (Resource vdc : org.getVDCs()) {
FirewallService response = client.listFirewallRules(org.getId(), vdc.getId());
Set<FirewallRule> firewallRules = response.getFirewallRules();
if(firewallRules != null){
Iterator<FirewallRule> iter = firewallRules.iterator();
while(iter.hasNext()){
FirewallRule firewallRule = iter.next();
assertNotNull(firewallRule);
// these are null for firewall rules
assertEquals(response.getHref(), null);
assertEquals(response.getType(), null);
assertNotNull(firewallRule.getFirewallType());
assertNotNull(firewallRule.getProtocol());
assertNotNull(firewallRule.getSource());
assertNotNull(firewallRule.getDestination());
}
}
}
}
}
}

View File

@ -0,0 +1,103 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.features;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Set;
import org.jclouds.cim.OSType;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.savvis.vpdc.domain.VMSpec;
import org.jclouds.savvis.vpdc.xml.TaskHandler;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests annotation parsing of {@code VMAsyncClient}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class VMAsyncClientTest extends BaseVPDCAsyncClientTest<VMAsyncClient> {
public void testAddVMIntoVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VMAsyncClient.class.getMethod("addVMIntoVDC", String.class, String.class, String.class,
String.class, VMSpec.class);
CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral<Set<CIMOperatingSystem>>() {
})), new Predicate<CIMOperatingSystem>() {
@Override
public boolean apply(CIMOperatingSystem arg0) {
return arg0.getOsType() == OSType.RHEL_64;
}
});
HttpRequest request = processor.createRequest(method, "11", "22", "VM Tier01", "DemoHost-1", VMSpec.builder()
.operatingSystem(os).build());
assertRequestLineEquals(request,
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-default.xml")),
"application/xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(request);
}
public void testRemoveVM() throws SecurityException, NoSuchMethodException, IOException {
Method method = VMAsyncClient.class.getMethod("removeVMFromVDC", String.class, String.class, String.class);
HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01");
assertRequestLineEquals(request,
"DELETE https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/VM-Tier01 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(request);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<VMAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VMAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,160 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.features;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.cim.OSType;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.Credentials;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.domain.Task;
import org.jclouds.savvis.vpdc.domain.VM;
import org.jclouds.savvis.vpdc.domain.VMSpec;
import org.jclouds.savvis.vpdc.predicates.TaskSuccess;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.util.InetAddresses2;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.net.HostSpecifier;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
@Test(groups = "live")
public class VMClientLiveTest extends BaseVPDCClientLiveTest {
private VMClient client;
private Factory sshFactory;
private VM vm;
private RetryablePredicate<IPSocket> socketTester;
private RetryablePredicate<String> taskTester;
private String email = checkNotNull(System.getProperty("test." + provider + ".email"), "test." + provider + ".email");
private String username = checkNotNull(System.getProperty("test." + provider + ".loginUser"), "test." + provider
+ ".loginUser");
private String password = checkNotNull(System.getProperty("test." + provider + ".loginPassword"), "test." + provider
+ ".loginPassword");
@Override
@BeforeGroups(groups = { "live" })
public void setupClient() {
super.setupClient();
client = context.getApi().getVMClient();
sshFactory = injector.getInstance(SshClient.Factory.class);
socketTester = new RetryablePredicate<IPSocket>(injector.getInstance(SocketOpen.class), 130, 10, TimeUnit.SECONDS);// make
taskTester = new RetryablePredicate<String>(injector.getInstance(TaskSuccess.class), 650, 10, TimeUnit.SECONDS);
}
protected String prefix = System.getProperty("user.name");
private String billingSiteId;
private String vpdcId;
public void testCreateVirtualMachine() throws Exception {
billingSiteId = context.getApi().getBrowsingClient().getOrg(null).getId();// default
vpdcId = Iterables.find(context.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(),
new Predicate<Resource>() {
// try to find the first VDC owned by the current user
// check here for what the email property might be, or in
// the jclouds-wire.log
@Override
public boolean apply(Resource arg0) {
String description = context.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, arg0.getId())
.getDescription();
return description.indexOf(email) != -1;
}
}).getId();
String networkTierName = Iterables.get(
context.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId).getAvailableNetworks(), 0)
.getName();
String name = prefix;
CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral<Set<CIMOperatingSystem>>() {
})), new Predicate<CIMOperatingSystem>() {
@Override
public boolean apply(CIMOperatingSystem arg0) {
return arg0.getOsType() == OSType.RHEL_64;
}
});
System.out.printf("vpdcId %s, networkName %s, name %s, os %s%n", vpdcId, networkTierName, name, os);
// TODO: determine the sizes available in the VDC, for example there's
// a minimum size of boot disk, and also a preset combination of cpu count vs ram
Task task = client.addVMIntoVDC(billingSiteId, vpdcId, networkTierName, name, VMSpec.builder()
.operatingSystem(os).memoryInGig(2).build());
// make sure there's no error
assert task.getId() != null && task.getError() != null : task;
assert this.taskTester.apply(task.getId());
vm = context.getApi().getBrowsingClient().getVMInVDC(billingSiteId, vpdcId, task.getOwner().getId());
conditionallyCheckSSH();
}
private void conditionallyCheckSSH() {
assert HostSpecifier.isValid(vm.getIpAddress());
if (!InetAddresses2.isPrivateIPAddress(vm.getIpAddress())) {
// not sure if the network is public or not, so we have to test
IPSocket socket = new IPSocket(vm.getIpAddress(), 22);
System.err.printf("testing socket %s%n", socket);
System.err.printf("testing ssh %s%n", socket);
checkSSH(socket);
} else {
System.err.printf("skipping ssh %s, as private%n", vm.getIpAddress());
}
}
protected void checkSSH(IPSocket socket) {
socketTester.apply(socket);
SshClient client = sshFactory.create(socket, new Credentials(username, password));
try {
client.connect();
ExecResponse exec = client.exec("echo hello");
System.out.println(exec);
assertEquals(exec.getOutput().trim(), "hello");
} finally {
if (client != null)
client.disconnect();
}
}
@AfterGroups(groups = "live")
protected void tearDown() {
if (vm != null) {
assert taskTester.apply(client.removeVMFromVDC(billingSiteId, vpdcId, vm.getId()).getId()) : vm;
}
super.tearDown();
}
}

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.savvis.vpdc.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.savvis.vpdc.domain.FirewallRule;
import org.jclouds.savvis.vpdc.domain.FirewallService;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code FirewallServiceHandler and @code FirewallRuleHandler}
*
* @author Kedar Dave
*/
@Test(groups = "unit")
public class FirewallServiceHandlerTest {
/*new FirewallRule(null, null, null, null, "SERVER_TIER_FIREWALL", true, "internet" , "VM Tier01" ,
"22", "allow", "Server Tier Firewall Rule", false, "Tcp"),
new FirewallRule(null, null, null, null, "SERVER_TIER_FIREWALL", true, "VM Tier03" , "VM Tier03" ,
null, "allow", "Server Tier Firewall Rule", false, "Icmp-ping")));*/
public void test() {
InputStream is = getClass().getResourceAsStream("/firewallService.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
FirewallService result = factory.create(injector.getInstance(FirewallServiceHandler.class)).parse(is);
assertEquals(result.isEnabled(), false);
assertEquals(
result.getFirewallRules(),
ImmutableSet.<FirewallRule> of(
FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("internet")
.destination("VM Tier01").port("22").protocol("Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build(),
FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("VM Tier03")
.destination("VM Tier03").protocol("Icmp-ping").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build()));
}
}

View File

@ -57,4 +57,17 @@ public class OrgHandlerTest {
"down")).build().toString());
}
public void testOrgWithoutVDC() {
InputStream is = getClass().getResourceAsStream("/org_no_vdc.xml");
Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
Org result = factory.create(injector.getInstance(OrgHandler.class)).parse(is);
assertEquals(
result.toString(),
Org.builder()
.name("100000.0")
.description("SAVVISStation Integration Testing").build().toString());
}
}

View File

@ -37,6 +37,7 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task
.builder()
.id("21-1002")
.endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00"))
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.status(Task.Status.SUCCESS)
@ -70,6 +71,7 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task
.builder()
.id("21-1002")
.endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00"))
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.status(Task.Status.SUCCESS)
@ -103,10 +105,11 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task
.builder()
.id("6904")
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.status(Task.Status.RUNNING)
.type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/21-1002"))
.href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904"))
.owner(
Resource
.builder()
@ -136,31 +139,31 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task
.builder()
.id("6904")
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.id("113927-1005")
.startTime(dateService.iso8601DateParse("2011-03-24T20:37:34.000Z"))
.status(Task.Status.QUEUED)
.type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904"))
.href(URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/task/113927-1005"))
.owner(
Resource
.builder()
.id("2736")
.name("mockVpdc8")
.id("4253")
.name("Foo")
.type("application/vnd.vmware.vcloud.vdc+xml")
.href(URI
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736"))
.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/4253"))
.build())
.result(
Resource
.builder()
.id("1002")
.name("mock_vpdc_item_007")
.type("application/vnd.vmware.vcloud.catalogItem+xml")
.id("1005")
.name("adriancole")
.type("application/vnd.vmware.vcloud.vApp+xml")
.href(URI
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002"))
.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/4253/vApp/1005"))
.build()).build();
assertEquals(result.toString(), expects.toString());
assertEquals(result.getError(), null);
assert result.getId() != null;
}
public void testFailed() {
@ -203,12 +206,9 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task
.builder()
.id("6904-123")
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00"))
.status(Task.Status.ERROR)
.type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904-123"))
.error(
TaskError
.builder()
@ -228,12 +228,12 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);
Task expects = Task
.builder()
.id("6904-123")
.id("3904-1002")
.startTime(dateService.iso8601DateParse("2010-05-26T08:08:08.000+08:00"))
.endTime(dateService.iso8601DateParse("2010-05-26T08:09:09.000+08:00"))
.status(Task.Status.NONE)
.type("application/vnd.vmware.vcloud.task+xml")
.href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904-123"))
.href(URI.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/3904-1002"))
.error(
TaskError
.builder()

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svvs:FirewallService xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common"
xmlns:vApp="http://www.vmware.com/vcloud/v0.8"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
xmlns:svvs="http://schemas.api.sandbox.symphonyVPDC.savvis.net/vpdci">
<svvs:IsEnabled>false</svvs:IsEnabled>
<svvs:FirewallRule>
<svvs:IsEnabled>true</svvs:IsEnabled>
<svvs:Description>Server Tier Firewall Rule</svvs:Description>
<svvs:Type>SERVER_TIER_FIREWALL</svvs:Type>
<svvs:Log>no</svvs:Log>
<svvs:Policy>allow</svvs:Policy>
<svvs:Protocols>
<svvs:Tcp>true</svvs:Tcp>
</svvs:Protocols>
<svvs:Port>22</svvs:Port>
<svvs:Destination>VM Tier01</svvs:Destination>
<svvs:Source>internet</svvs:Source>
</svvs:FirewallRule>
<svvs:FirewallRule>
<svvs:IsEnabled>true</svvs:IsEnabled>
<svvs:Description>Server Tier Firewall Rule</svvs:Description>
<svvs:Type>SERVER_TIER_FIREWALL</svvs:Type>
<svvs:Log>no</svvs:Log>
<svvs:Policy>allow</svvs:Policy>
<svvs:Protocols>
<svvs:Icmp-ping>true</svvs:Icmp-ping>
</svvs:Protocols>
<svvs:Port></svvs:Port>
<svvs:Destination>VM Tier03</svvs:Destination>
<svvs:Source>VM Tier03</svvs:Source>
</svvs:FirewallRule>
</svvs:FirewallService>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vApp:Org xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:vApp="http://www.vmware.com/vcloud/v0.8" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" name="100000.0">
<vApp:Description>SAVVISStation Integration Testing</vApp:Description>
</vApp:Org>

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><vApp:TasksList xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:vApp="http://www.vmware.com/vcloud/v0.8" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"><vApp:Task status="error"><vApp:Error vendorSpecificErrorCode="1016" minorErrorCode="471" majorErrorCode="500" message="The vApp CPU : {3 GHz * 1} and Memory : {1} is not to be supported."/></vApp:Task></vApp:TasksList>

View File

@ -1,15 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vApp:TasksList xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common"
xmlns:vApp="http://www.vmware.com/vcloud/v0.8"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
<!--If Task status is queued, Savvis is not displaying endTime.-->
<vApp:Task startTime="2010-05-26T08:08:08.000+08:00" status="queued" type="application/vnd.vmware.vcloud.task+xml"
href="https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/6904">
<vApp:Owner name="mockVpdc8" type="application/vnd.vmware.vcloud.vdc+xml"
href="https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736"/>
<vApp:Result name="mock_vpdc_item_007" type="application/vnd.vmware.vcloud.catalogItem+xml"
href="https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002"/>
</vApp:Task>
</vApp:TasksList>
<vApp:TasksList xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:vApp="http://www.vmware.com/vcloud/v0.8" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
<vApp:Task startTime="2011-03-24T20:37:34.000Z" status="queued" href="https://api.symphonyVPDC.savvis.net/rest/api/v0.8/task/113927-1005">
<vApp:Owner name="Foo" type="application/vnd.vmware.vcloud.vdc+xml" href="https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/4253"/>
<vApp:Result name="adriancole" type="application/vnd.vmware.vcloud.vApp+xml" href="https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/4253/vApp/1005"/>
</vApp:Task>
</vApp:TasksList>

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><vApp:TasksList xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:vApp="http://www.vmware.com/vcloud/v0.8" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"><vApp:Task status="error"><vApp:Error vendorSpecificErrorCode="-1" minorErrorCode="0" majorErrorCode="500" message="Please finish your previously deployment for vpdcId:1619"/></vApp:Task></vApp:TasksList>

View File

@ -0,0 +1 @@
<vApp:VApp xmlns:vApp="http://www.vmware.com/vcloud/v0.8" xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" href="" name="DemoHost-1" type="application/vnd.vmware.vcloud.vApp+xml"><ovf:OperatingSystemSection ovf:id="80"><ovf:Info>Specifies the operating system installed</ovf:Info><ovf:Description>Red Hat Enterprise Linux 5.x 64bit</ovf:Description></ovf:OperatingSystemSection><ovf:VirtualHardwareSection><ovf:Info>Virtual Hardware</ovf:Info><ovf:System><vssd:Description>Virtual Hardware Family</vssd:Description><vssd:ElementName>DemoHost-1</vssd:ElementName><vssd:InstanceID>1</vssd:InstanceID><vssd:VirtualSystemIdentifier>DemoHost-1</vssd:VirtualSystemIdentifier></ovf:System><ovf:Item><rasd:AllocationUnits>3 GHz</rasd:AllocationUnits><rasd:Description>Number of Virtual CPUs</rasd:Description><rasd:ElementName>1 CPU</rasd:ElementName><rasd:InstanceID>1</rasd:InstanceID><rasd:ResourceType>3</rasd:ResourceType><rasd:VirtualQuantity>1</rasd:VirtualQuantity></ovf:Item><ovf:Item><rasd:AllocationUnits>Gigabytes</rasd:AllocationUnits><rasd:Description>Memory Size</rasd:Description><rasd:ElementName>Memory</rasd:ElementName><rasd:InstanceID>2</rasd:InstanceID><rasd:ResourceType>4</rasd:ResourceType><rasd:VirtualQuantity>1</rasd:VirtualQuantity></ovf:Item><ovf:Item><rasd:Caption>false</rasd:Caption><rasd:Connection>VM Tier01</rasd:Connection><rasd:ElementName>Network</rasd:ElementName><rasd:InstanceID>3</rasd:InstanceID><rasd:ResourceType>10</rasd:ResourceType><rasd:VirtualQuantity>1</rasd:VirtualQuantity></ovf:Item><ovf:Item><rasd:AllocationUnits>Gigabytes</rasd:AllocationUnits><rasd:Caption/><rasd:Description>Hard Disk</rasd:Description><rasd:ElementName>/</rasd:ElementName><rasd:HostResource>boot</rasd:HostResource><rasd:InstanceID>4</rasd:InstanceID><rasd:ResourceType>27</rasd:ResourceType><rasd:VirtualQuantity>25</rasd:VirtualQuantity></ovf:Item></ovf:VirtualHardwareSection></vApp:VApp>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vApp:Network xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:vApp="http://www.vmware.com/vcloud/v0.8"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" name="VM Tier01"
type="application/vnd.vmware.vcloud.network+xml">
<vApp:Configuration>
<vApp:Gateway>1.1.1.1</vApp:Gateway>
<vApp:Netmask>2.2.2.2</vApp:Netmask>
</vApp:Configuration>
<vApp:Features>
<vApp:FenceMode>allowInOut</vApp:FenceMode>
<vApp:Nat>
<vApp:NatRule internalIP="3.3.3.3" externalIP="4.4.4.4"/>
<vApp:NatRule internalIP="3.3.3.4" externalIP="4.4.4.5"/>
</vApp:Nat>
</vApp:Features>
</vApp:Network>