mirror of https://github.com/apache/jclouds.git
Issue 112: added configureNode and configureInternetService
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2497 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
8cea0a9d89
commit
040b3855ff
|
@ -35,10 +35,12 @@ import javax.ws.rs.Consumes;
|
|||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.Endpoint;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
|
@ -52,12 +54,16 @@ import org.jclouds.vcloud.domain.VDC;
|
|||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.functions.CatalogIdToUri;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.terremark.binders.BindInternetServiceConfigurationToXmlPayload;
|
||||
import org.jclouds.vcloud.terremark.binders.BindNodeConfigurationToXmlPayload;
|
||||
import org.jclouds.vcloud.terremark.binders.TerremarkBindInstantiateVAppTemplateParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
||||
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetServiceConfiguration;
|
||||
import org.jclouds.vcloud.terremark.domain.IpAddress;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
|
||||
import org.jclouds.vcloud.terremark.domain.Protocol;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
|
||||
|
@ -112,6 +118,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
|
||||
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
|
||||
@Consumes(VAPP_XML)
|
||||
@XMLResponseParser(TerremarkVAppHandler.class)
|
||||
@MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class)
|
||||
@Override
|
||||
|
@ -127,6 +134,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}/internetServices")
|
||||
@Produces(APPLICATION_XML)
|
||||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
@MapBinder(AddInternetServiceOptions.class)
|
||||
Future<? extends InternetService> addInternetServiceToVDC(@PathParam("vDCId") String vDCId,
|
||||
|
@ -140,6 +148,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}/internetServices")
|
||||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServicesHandler.class)
|
||||
Future<? extends SortedSet<InternetService>> getAllInternetServicesInVDC(
|
||||
@PathParam("vDCId") String vDCId);
|
||||
|
@ -151,6 +160,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/publicIps/{ipId}/InternetServices")
|
||||
@Produces(APPLICATION_XML)
|
||||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
@MapBinder(AddInternetServiceOptions.class)
|
||||
Future<? extends InternetService> addInternetServiceToExistingIp(
|
||||
|
@ -173,6 +183,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/publicIps/{ipId}/InternetServices")
|
||||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServicesHandler.class)
|
||||
Future<? extends SortedSet<InternetService>> getInternetServicesOnPublicIp(
|
||||
@PathParam("ipId") int ipId);
|
||||
|
@ -183,6 +194,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/publicIps/{ipId}")
|
||||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServicesHandler.class)
|
||||
Future<? extends SortedSet<InternetService>> getPublicIp(@PathParam("ipId") int ipId);
|
||||
|
||||
|
@ -192,6 +204,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}/publicIps")
|
||||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(PublicIpAddressesHandler.class)
|
||||
Future<? extends SortedSet<PublicIpAddress>> getPublicIpsAssociatedWithVDC(
|
||||
@PathParam("vDCId") String vDCId);
|
||||
|
@ -204,12 +217,26 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Path("/internetServices/{internetServiceId}")
|
||||
Future<Void> deleteInternetService(@PathParam("internetServiceId") int internetServiceId);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#configureInternetService
|
||||
*/
|
||||
@PUT
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/internetServices/{internetServiceId}")
|
||||
@Produces(APPLICATION_XML)
|
||||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
Future<? extends InternetService> configureInternetService(
|
||||
@PathParam("internetServiceId") int internetServiceId,
|
||||
@BinderParam(BindInternetServiceConfigurationToXmlPayload.class) InternetServiceConfiguration nodeConfiguration);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#getInternetService
|
||||
*/
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/internetServices/{internetServiceId}")
|
||||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
Future<? extends InternetService> getInternetService(
|
||||
@PathParam("internetServiceId") int internetServiceId);
|
||||
|
@ -221,6 +248,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/internetServices/{internetServiceId}/nodes")
|
||||
@Produces(APPLICATION_XML)
|
||||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(NodeHandler.class)
|
||||
@MapBinder(AddNodeOptions.class)
|
||||
Future<? extends Node> addNode(
|
||||
|
@ -236,6 +264,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/internetServices/{internetServiceId}/nodes")
|
||||
@XMLResponseParser(NodesHandler.class)
|
||||
@Consumes(APPLICATION_XML)
|
||||
Future<? extends SortedSet<Node>> getNodes(@PathParam("internetServiceId") int internetServiceId);
|
||||
|
||||
/**
|
||||
|
@ -245,8 +274,22 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/nodeServices/{nodeId}")
|
||||
@XMLResponseParser(NodeHandler.class)
|
||||
@Consumes(APPLICATION_XML)
|
||||
Future<? extends Node> getNode(@PathParam("nodeId") int nodeId);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#configureNode
|
||||
*/
|
||||
@PUT
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/nodeServices/{nodeId}")
|
||||
@Produces(APPLICATION_XML)
|
||||
@Consumes(APPLICATION_XML)
|
||||
@XMLResponseParser(NodeHandler.class)
|
||||
Future<? extends Node> configureNode(
|
||||
@PathParam("nodeId") int nodeId,
|
||||
@BinderParam(BindNodeConfigurationToXmlPayload.class) NodeConfiguration nodeConfiguration);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#deleteNode
|
||||
*/
|
||||
|
@ -273,6 +316,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}/options/compute")
|
||||
@XMLResponseParser(ComputeOptionsHandler.class)
|
||||
@Consumes(APPLICATION_XML)
|
||||
Future<? extends SortedSet<ComputeOptions>> getComputeOptionsOfVApp(
|
||||
@PathParam("vAppId") String vAppId);
|
||||
|
||||
|
@ -283,6 +327,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}/options/customization")
|
||||
@XMLResponseParser(CustomizationParametersHandler.class)
|
||||
@Consumes(APPLICATION_XML)
|
||||
Future<? extends CustomizationParameters> getCustomizationOptionsOfVApp(
|
||||
@PathParam("vAppId") String vAppId);
|
||||
|
||||
|
@ -293,6 +338,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/catalogItem/{catalogItemId}/options/compute")
|
||||
@XMLResponseParser(ComputeOptionsHandler.class)
|
||||
@Consumes(APPLICATION_XML)
|
||||
Future<? extends SortedSet<ComputeOptions>> getComputeOptionsOfCatalogItem(
|
||||
@PathParam("catalogItemId") String catalogItemId);
|
||||
|
||||
|
@ -303,8 +349,10 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/catalogItem/{catalogItemId}/options/customization")
|
||||
@XMLResponseParser(CustomizationParametersHandler.class)
|
||||
@Consumes(APPLICATION_XML)
|
||||
Future<? extends CustomizationParameters> getCustomizationOptionsOfCatalogItem(
|
||||
@PathParam("catalogItemId") String catalogItemId);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#getIpAddressesForNetwork
|
||||
*/
|
||||
|
|
|
@ -33,8 +33,10 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
|||
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
||||
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetServiceConfiguration;
|
||||
import org.jclouds.vcloud.terremark.domain.IpAddress;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
|
||||
import org.jclouds.vcloud.terremark.domain.Protocol;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
|
||||
|
@ -103,6 +105,9 @@ public interface TerremarkVCloudClient extends VCloudClient {
|
|||
|
||||
InternetService getInternetService(int internetServiceId);
|
||||
|
||||
InternetService configureInternetService(int internetServiceId,
|
||||
InternetServiceConfiguration nodeConfiguration);
|
||||
|
||||
SortedSet<InternetService> getAllInternetServicesInVDC(String vDCId);
|
||||
|
||||
/**
|
||||
|
@ -131,6 +136,8 @@ public interface TerremarkVCloudClient extends VCloudClient {
|
|||
|
||||
Node getNode(int nodeId);
|
||||
|
||||
Node configureNode(int nodeId, NodeConfiguration nodeConfiguration);
|
||||
|
||||
void deleteNode(int nodeId);
|
||||
|
||||
SortedSet<Node> getNodes(int internetServiceId);
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.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.Properties;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetServiceConfiguration;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindInternetServiceConfigurationToXmlPayload extends BindToStringPayload {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
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");
|
||||
InternetServiceConfiguration internetServiceConfiguration = (InternetServiceConfiguration) checkNotNull(
|
||||
input, "configuration");
|
||||
checkArgument(internetServiceConfiguration.getDescription() != null
|
||||
|| internetServiceConfiguration.getEnabled() != null
|
||||
|| internetServiceConfiguration.getName() != null || internetServiceConfiguration.getTimeout() != null, "no configuration set");
|
||||
try {
|
||||
super.bindToRequest(request, generateXml(internetServiceConfiguration));
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (FactoryConfigurationError e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (TransformerException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected String generateXml(InternetServiceConfiguration internetServiceConfiguration)
|
||||
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
|
||||
XMLBuilder rootBuilder = XMLBuilder.create("InternetService").a("xmlns",
|
||||
"urn:tmrk:vCloudExpress-1.0").a("xmlns:i",
|
||||
"http://www.w3.org/2001/XMLSchema-instance");
|
||||
if (internetServiceConfiguration.getDescription() != null)
|
||||
rootBuilder.e("Description").t(internetServiceConfiguration.getDescription());
|
||||
if (internetServiceConfiguration.getName() != null)
|
||||
rootBuilder.e("Name").t(internetServiceConfiguration.getName());
|
||||
if (internetServiceConfiguration.getEnabled() != null)
|
||||
rootBuilder.e("Enabled").t(internetServiceConfiguration.getEnabled());
|
||||
if (internetServiceConfiguration.getTimeout() != null)
|
||||
rootBuilder.e("Timeout").t(internetServiceConfiguration.getTimeout());
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
return rootBuilder.asString(outputProperties);
|
||||
}
|
||||
|
||||
protected String ifNullDefaultTo(String value, String defaultValue) {
|
||||
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.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.Properties;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindNodeConfigurationToXmlPayload extends BindToStringPayload {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
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");
|
||||
NodeConfiguration nodeConfiguration = (NodeConfiguration) checkNotNull(input,
|
||||
"nodeConfiguration");
|
||||
checkArgument(nodeConfiguration.getDescription() != null
|
||||
|| nodeConfiguration.getEnabled() != null || nodeConfiguration.getName() != null,
|
||||
"no configuration set");
|
||||
try {
|
||||
super.bindToRequest(request, generateXml(nodeConfiguration));
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (FactoryConfigurationError e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (TransformerException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected String generateXml(NodeConfiguration nodeConfiguration)
|
||||
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
|
||||
XMLBuilder rootBuilder = XMLBuilder.create("NodeService").a("xmlns",
|
||||
"urn:tmrk:vCloudExpress-1.0").a("xmlns:i",
|
||||
"http://www.w3.org/2001/XMLSchema-instance");
|
||||
if (nodeConfiguration.getDescription() != null)
|
||||
rootBuilder.e("Description").t(nodeConfiguration.getDescription());
|
||||
if (nodeConfiguration.getName() != null)
|
||||
rootBuilder.e("Name").t(nodeConfiguration.getName());
|
||||
if (nodeConfiguration.getEnabled() != null)
|
||||
rootBuilder.e("Enabled").t(nodeConfiguration.getEnabled());
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
return rootBuilder.asString(outputProperties);
|
||||
}
|
||||
|
||||
protected String ifNullDefaultTo(String value, String defaultValue) {
|
||||
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.domain;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class InternetServiceConfiguration extends NodeConfiguration {
|
||||
|
||||
private String timeout = null;
|
||||
|
||||
/**
|
||||
* One factor that affects the load balancing is the timeout, or persistence. The timeout is the
|
||||
* number of minutes that the task can remain idle on a given node before the underlying software
|
||||
* attempts to rebalance the node by possibly assigning that task to a different node. The
|
||||
* default timeout is one minute. You can change the value using this call.
|
||||
*/
|
||||
public InternetServiceConfiguration changeTimeoutTo(int timeout) {
|
||||
this.timeout = timeout + "";
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternetServiceConfiguration changeDescriptionTo(String description) {
|
||||
return (InternetServiceConfiguration) super.changeDescriptionTo(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternetServiceConfiguration changeNameTo(String name) {
|
||||
return (InternetServiceConfiguration) super.changeNameTo(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternetServiceConfiguration disableTraffic() {
|
||||
return (InternetServiceConfiguration) super.disableTraffic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternetServiceConfiguration enableTraffic() {
|
||||
return (InternetServiceConfiguration) super.enableTraffic();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
/**
|
||||
* @see InternetServiceConfiguration#changeTimeoutTo(int)
|
||||
*/
|
||||
public static InternetServiceConfiguration changeTimeoutTo(int timeout) {
|
||||
InternetServiceConfiguration options = new InternetServiceConfiguration();
|
||||
return options.changeTimeoutTo(timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InternetServiceConfiguration#changeNameTo(String)
|
||||
*/
|
||||
public static InternetServiceConfiguration changeNameTo(String name) {
|
||||
InternetServiceConfiguration options = new InternetServiceConfiguration();
|
||||
return options.changeNameTo(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InternetServiceConfiguration#changeDescriptionTo(String)
|
||||
*/
|
||||
public static InternetServiceConfiguration changeDescriptionTo(String description) {
|
||||
InternetServiceConfiguration options = new InternetServiceConfiguration();
|
||||
return options.changeDescriptionTo(description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InternetServiceConfiguration#enableTraffic()
|
||||
*/
|
||||
public static InternetServiceConfiguration enableTraffic() {
|
||||
InternetServiceConfiguration options = new InternetServiceConfiguration();
|
||||
return options.enableTraffic();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InternetServiceConfiguration#disableTraffic()
|
||||
*/
|
||||
public static InternetServiceConfiguration disableTraffic() {
|
||||
InternetServiceConfiguration options = new InternetServiceConfiguration();
|
||||
return options.disableTraffic();
|
||||
}
|
||||
}
|
||||
|
||||
public String getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.domain;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class NodeConfiguration {
|
||||
private String name = null;
|
||||
private String description = null;
|
||||
private String enabled = null;
|
||||
|
||||
public NodeConfiguration enableTraffic() {
|
||||
this.enabled = "true";
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeConfiguration disableTraffic() {
|
||||
this.enabled = "false";
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeConfiguration changeNameTo(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeConfiguration changeDescriptionTo(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
/**
|
||||
* @see NodeConfiguration#changeNameTo(String)
|
||||
*/
|
||||
public static NodeConfiguration changeNameTo(String name) {
|
||||
NodeConfiguration options = new NodeConfiguration();
|
||||
return options.changeNameTo(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NodeConfiguration#changeDescriptionTo(String)
|
||||
*/
|
||||
public static NodeConfiguration changeDescriptionTo(String description) {
|
||||
NodeConfiguration options = new NodeConfiguration();
|
||||
return options.changeDescriptionTo(description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NodeConfiguration#enableTraffic()
|
||||
*/
|
||||
public static NodeConfiguration enableTraffic() {
|
||||
NodeConfiguration options = new NodeConfiguration();
|
||||
return options.enableTraffic();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NodeConfiguration#disableTraffic()
|
||||
*/
|
||||
public static NodeConfiguration disableTraffic() {
|
||||
NodeConfiguration options = new NodeConfiguration();
|
||||
return options.disableTraffic();
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@
|
|||
package org.jclouds.vcloud.terremark;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -32,6 +33,7 @@ import java.util.concurrent.TimeoutException;
|
|||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetServiceConfiguration;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.jclouds.vcloud.terremark.domain.Protocol;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
|
@ -57,23 +59,23 @@ public class InternetServiceLiveTest {
|
|||
|
||||
@Test
|
||||
public void testGetAllInternetServices() throws Exception {
|
||||
SortedSet<InternetService> set = tmClient.getAllInternetServicesInVDC(tmClient
|
||||
.getDefaultVDC().getId());
|
||||
print(set);
|
||||
tmClient.getAllInternetServicesInVDC(tmClient.getDefaultVDC().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddInternetService() throws InterruptedException {
|
||||
public void testAddAndConfigureInternetService() throws InterruptedException {
|
||||
InternetService is = tmClient.addInternetServiceToVDC(tmClient.getDefaultVDC().getId(),
|
||||
"test-" + 22, Protocol.TCP, 22);
|
||||
is = tmClient.configureInternetService(is.getId(), new InternetServiceConfiguration()
|
||||
.changeNameTo("test-33"));
|
||||
assertEquals(is.getName(), "test-33");
|
||||
services.add(is);
|
||||
PublicIpAddress ip = is.getPublicIpAddress();
|
||||
// PublicIpAddress ip = is.getPublicIpAddress();
|
||||
// current bug in terremark
|
||||
// for (int port : new int[] { 80, 8080 }) {
|
||||
// services.add(tmClient.addInternetServiceToExistingIp(ip.getId(), "test-" + port,
|
||||
// Protocol.HTTP, port));
|
||||
// }
|
||||
print(tmClient.getInternetServicesOnPublicIp(ip.getId()));
|
||||
}
|
||||
|
||||
private void delete(SortedSet<InternetService> set) {
|
||||
|
@ -90,8 +92,7 @@ public class InternetServiceLiveTest {
|
|||
public void testGetAllPublicIps() throws Exception {
|
||||
for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(tmClient.getDefaultVDC()
|
||||
.getId())) {
|
||||
SortedSet<InternetService> set = tmClient.getInternetServicesOnPublicIp(ip.getId());
|
||||
print(set);
|
||||
tmClient.getInternetServicesOnPublicIp(ip.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +113,7 @@ public class InternetServiceLiveTest {
|
|||
|
||||
}
|
||||
|
||||
private void print(SortedSet<InternetService> set) {
|
||||
void print(SortedSet<InternetService> set) {
|
||||
for (InternetService service : set) {
|
||||
System.out.printf("%d (%s:%d%n)", service.getId(), service.getPublicIpAddress()
|
||||
.getAddress().getHostAddress(), service.getPort());
|
||||
|
|
|
@ -55,6 +55,8 @@ import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
|||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetServiceConfiguration;
|
||||
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
|
||||
import org.jclouds.vcloud.terremark.domain.Protocol;
|
||||
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
|
||||
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
||||
|
@ -82,11 +84,13 @@ import com.google.inject.TypeLiteral;
|
|||
*/
|
||||
@Test(groups = "unit", sequential = true, testName = "vcloud.TerremarkVCloudAsyncClientTest")
|
||||
public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVCloudAsyncClient> {
|
||||
|
||||
|
||||
public void testGetIpAddressesForNetwork() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getIpAddressesForNetwork", String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, "2");
|
||||
public void testGetIpAddressesForNetwork() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getIpAddressesForNetwork",
|
||||
String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"2");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/network/2/ipAddresses HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/xml\n");
|
||||
|
@ -99,7 +103,6 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
|
||||
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getDefaultVDC");
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method);
|
||||
|
@ -143,7 +146,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpMethod,
|
||||
"Content-Length: 1649\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 1649\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams-test.xml")));
|
||||
|
||||
|
@ -168,7 +171,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpMethod,
|
||||
"Content-Length: 1912\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 1912\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams-options-test.xml")));
|
||||
|
||||
|
@ -188,7 +191,8 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
"1", "name", Protocol.TCP, 22);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Accept: application/xml\nContent-Length: 303\nContent-Type: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-test2.xml")));
|
||||
|
||||
|
@ -208,7 +212,8 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
"1", "name", Protocol.TCP, 22, disabled().withDescription("yahoo"));
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Accept: application/xml\nContent-Length: 341\nContent-Type: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-options-test.xml")));
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -226,7 +231,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
"1");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/vdc/1/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -243,7 +248,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -281,7 +286,8 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Accept: application/xml\nContent-Length: 303\nContent-Type: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-test2.xml")));
|
||||
|
||||
|
@ -302,7 +308,8 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Accept: application/xml\nContent-Length: 341\nContent-Type: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-options-test.xml")));
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -320,7 +327,8 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
12, InetAddress.getByName("10.2.2.2"), "name", 22);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 298\nContent-Type: application/xml\n");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Accept: application/xml\nContent-Length: 298\nContent-Type: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService-test2.xml")));
|
||||
|
||||
|
@ -340,7 +348,8 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
.withDescription("yahoo"));
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 336\nContent-Type: application/xml\n");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Accept: application/xml\nContent-Length: 336\nContent-Type: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService-options-test.xml")));
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -356,7 +365,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/nodeServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -366,13 +375,54 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testConfigureNode() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("configureNode", int.class,
|
||||
NodeConfiguration.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12, new NodeConfiguration().changeDescriptionTo("eggs"));
|
||||
|
||||
assertRequestLineEquals(httpMethod, "PUT http://vcloud/nodeServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Accept: application/xml\nContent-Length: 145\nContent-Type: application/xml\n");
|
||||
assertPayloadEquals(
|
||||
httpMethod,
|
||||
"<NodeService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></NodeService>");
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testConfigureInternetService() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("configureInternetService",
|
||||
int.class, InternetServiceConfiguration.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12, new InternetServiceConfiguration().changeDescriptionTo("eggs"));
|
||||
|
||||
assertRequestLineEquals(httpMethod, "PUT http://vcloud/internetServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Accept: application/xml\nContent-Length: 153\nContent-Type: application/xml\n");
|
||||
assertPayloadEquals(
|
||||
httpMethod,
|
||||
"<InternetService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>eggs</Description></InternetService>");
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetNodes() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNodes", int.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -406,7 +456,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/vapp/12/options/compute HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -425,7 +475,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"GET http://vcloud/vapp/12/options/customization HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -442,8 +492,9 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/catalogItem/12/options/compute HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"GET http://vcloud/catalogItem/12/options/compute HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
@ -462,7 +513,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"GET http://vcloud/catalogItem/12/options/customization HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
|
|
|
@ -62,6 +62,7 @@ import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
|
|||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.IpAddress;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
|
||||
import org.jclouds.vcloud.terremark.domain.Protocol;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
|
||||
|
@ -272,6 +273,11 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
IOException {
|
||||
node = tmClient.addNode(is.getId(), Iterables.getLast(vApp.getNetworkToAddresses().values()),
|
||||
vApp.getName() + "-SSH", 22);
|
||||
|
||||
node = tmClient.configureNode(node.getId(), new NodeConfiguration().changeNameTo(vApp
|
||||
.getName()
|
||||
+ "-ssh"));
|
||||
assertEquals(node.getName(), vApp.getName() + "-ssh");
|
||||
publicIp = is.getPublicIpAddress().getAddress();
|
||||
doCheckPass(publicIp);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.jclouds.vcloud.VCloudPropertiesBuilder;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetServiceConfiguration;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code BindInternetServiceConfigurationToXmlPayload}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.BindInternetServiceConfigurationToXmlPayloadTest")
|
||||
public class BindInternetServiceConfigurationToXmlPayloadTest {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
Properties props = new Properties();
|
||||
Jsr330.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(),
|
||||
"properties"));
|
||||
}
|
||||
});
|
||||
|
||||
public void testChangeName() throws IOException {
|
||||
InternetServiceConfiguration config = new InternetServiceConfiguration()
|
||||
.changeNameTo("willie");
|
||||
String expectedPayload = "<InternetService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name></InternetService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
public void testChangeDescription() throws IOException {
|
||||
InternetServiceConfiguration config = new InternetServiceConfiguration()
|
||||
.changeDescriptionTo("description");
|
||||
String expectedPayload = "<InternetService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>description</Description></InternetService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
public void testChangeTimeout() throws IOException {
|
||||
InternetServiceConfiguration config = new InternetServiceConfiguration().changeTimeoutTo(3);
|
||||
String expectedPayload = "<InternetService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Timeout>3</Timeout></InternetService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
public void testEnableTraffic() throws IOException {
|
||||
InternetServiceConfiguration config = new InternetServiceConfiguration().enableTraffic();
|
||||
String expectedPayload = "<InternetService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Enabled>true</Enabled></InternetService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
public void testDisableTraffic() throws IOException {
|
||||
InternetServiceConfiguration config = new InternetServiceConfiguration().disableTraffic();
|
||||
String expectedPayload = "<InternetService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Enabled>false</Enabled></InternetService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
public void testTwoOptions() throws IOException {
|
||||
InternetServiceConfiguration config = new InternetServiceConfiguration().disableTraffic()
|
||||
.changeNameTo("willie");
|
||||
String expectedPayload = "<InternetService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>false</Enabled></InternetService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testNoOptions() throws IOException {
|
||||
InternetServiceConfiguration config = new InternetServiceConfiguration();
|
||||
String expectedPayload = "<InternetService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>false</Enabled></InternetService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
private void assertConfigMakesPayload(InternetServiceConfiguration config, String expectedPayload) {
|
||||
BindInternetServiceConfigurationToXmlPayload binder = injector
|
||||
.getInstance(BindInternetServiceConfigurationToXmlPayload.class);
|
||||
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
|
||||
.<String, String> create());
|
||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||
expect(request.getArgs()).andReturn(new Object[] { config }).atLeastOnce();
|
||||
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
|
||||
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce();
|
||||
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
||||
request.setPayload(expectedPayload);
|
||||
replay(request);
|
||||
binder.bindToRequest(request, config);
|
||||
verify(request);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.jclouds.vcloud.VCloudPropertiesBuilder;
|
||||
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code BindNodeConfigurationToXmlPayload}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.BindNodeConfigurationToXmlPayloadTest")
|
||||
public class BindNodeConfigurationToXmlPayloadTest {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
Properties props = new Properties();
|
||||
Jsr330.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(),
|
||||
"properties"));
|
||||
}
|
||||
});
|
||||
|
||||
public void testChangeName() throws IOException {
|
||||
NodeConfiguration config = new NodeConfiguration().changeNameTo("willie");
|
||||
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name></NodeService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
public void testChangeDescription() throws IOException {
|
||||
NodeConfiguration config = new NodeConfiguration().changeDescriptionTo("description");
|
||||
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Description>description</Description></NodeService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
public void testEnableTraffic() throws IOException {
|
||||
NodeConfiguration config = new NodeConfiguration().enableTraffic();
|
||||
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Enabled>true</Enabled></NodeService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
public void testDisableTraffic() throws IOException {
|
||||
NodeConfiguration config = new NodeConfiguration().disableTraffic();
|
||||
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Enabled>false</Enabled></NodeService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
public void testTwoOptions() throws IOException {
|
||||
NodeConfiguration config = new NodeConfiguration().disableTraffic().changeNameTo("willie");
|
||||
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>false</Enabled></NodeService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testNoOptions() throws IOException {
|
||||
NodeConfiguration config = new NodeConfiguration();
|
||||
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpress-1.0\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>false</Enabled></NodeService>";
|
||||
assertConfigMakesPayload(config, expectedPayload);
|
||||
}
|
||||
|
||||
private void assertConfigMakesPayload(NodeConfiguration config, String expectedPayload) {
|
||||
BindNodeConfigurationToXmlPayload binder = injector
|
||||
.getInstance(BindNodeConfigurationToXmlPayload.class);
|
||||
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
|
||||
.<String, String> create());
|
||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||
expect(request.getArgs()).andReturn(new Object[] { config }).atLeastOnce();
|
||||
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
|
||||
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce();
|
||||
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
||||
request.setPayload(expectedPayload);
|
||||
replay(request);
|
||||
binder.bindToRequest(request, config);
|
||||
verify(request);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue