Merge pull request #1232 from dkoper/master

makes fgcp live tests (at least most of them) pass again, and added @Named annotation on async api methods
This commit is contained in:
Adrian Cole 2013-01-23 10:20:18 -08:00
commit cafd3f9b08
14 changed files with 346 additions and 20 deletions

View File

@ -69,4 +69,51 @@ public class HttpRequestTest {
.builder().method("GET").endpoint("http://foo").payload(payload).build());
}
// the following caused issues for the fgcp provider
// (see RequestAuthenticator#addQueryParamsToRequest)
// base64 symbols should be url encoded in query param
// note that + ends up encoded as %20 (space), not %2B (plus)
public void testAddingBase64EncodedQueryParamCausingPlusToUrlEncodedSpaceConversion() {
String base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
URI uri = URI
.create("http://goo.com:443?header1=valueWithUrlEncoded%2BPlus");
HttpRequest request = HttpRequest.builder().method("GET").endpoint(uri)
// addQueryParam invocation causes %2B's in prev. params to
// convert to %20.
.addQueryParam("header2", base64Chars).build();
assertEquals(
request.getRequestLine(),
"GET http://goo.com:443?header1=valueWithUrlEncoded%20Plus&header2=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%20/%3D HTTP/1.1");
}
// note that + ends up encoded as %20 (space) in the first param, %2B (plus)
// in the last param and %2F converts back into slash
public void testAddBase64AndUrlEncodedQueryParams() {
String base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%2B%2F%3D";
URI uri = URI.create("http://goo.com:443?header1=" + base64Chars);
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint(uri)
// the addition of another param causes %2B's in prev. params to
// convert to %20.
.addQueryParam("header2", base64Chars)
.build();
assertEquals(
request.getRequestLine(),
"GET http://goo.com:443?header1=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%20/%3D&header2=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%2B/%3D HTTP/1.1");
}
// base64 symbols with newline separator should be url encoded in query param
public void testAddBase64EncodedQueryParamWithNewlines() {
String base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz\n0123456789%2B/=";
URI uri = URI.create("http://goo.com:443?header1=value1");
HttpRequest request = HttpRequest.builder().method("GET").endpoint(uri)
.addQueryParam("header2", base64Chars).build();
assertEquals(
request.getRequestLine(),
"GET http://goo.com:443?header1=value1&header2=ABCDEFGHIJKLMNOPQRSTUVWXYZ%0Aabcdefghijklmnopqrstuvwxyz%0A0123456789%2B/%3D HTTP/1.1");
}
}

View File

@ -51,6 +51,7 @@ import org.jclouds.domain.Credentials;
import org.jclouds.fujitsu.fgcp.reference.RequestParameters;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequest.Builder;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.internal.SignatureWire;
@ -87,8 +88,10 @@ public class RequestAuthenticator implements HttpRequestFilter, RequestSigner {
private final static String signatureMethod = "SHA1withRSA";
@Inject
public RequestAuthenticator(@TimeStamp Provider<Calendar> calendarProvider, SignatureForCredentials loader,
@org.jclouds.location.Provider Supplier<Credentials> creds, HttpUtils utils, SignatureWire signatureWire,
public RequestAuthenticator(@TimeStamp Provider<Calendar> calendarProvider,
SignatureForCredentials loader,
@org.jclouds.location.Provider Supplier<Credentials> creds,
HttpUtils utils, SignatureWire signatureWire,
@ApiVersion String apiVersion) {
this.calendarProvider = checkNotNull(calendarProvider);
this.creds = checkNotNull(creds, "creds");
@ -102,7 +105,8 @@ public class RequestAuthenticator implements HttpRequestFilter, RequestSigner {
* it is relatively expensive to create a new signing key. cache the relationship between current credentials so that
* the signer is only recalculated once.
*/
private static class SignatureForCredentials extends CacheLoader<Credentials, Signature> {
@VisibleForTesting
static class SignatureForCredentials extends CacheLoader<Credentials, Signature> {
private final Supplier<KeyStore> keyStore;
@Inject
@ -146,15 +150,8 @@ public class RequestAuthenticator implements HttpRequestFilter, RequestSigner {
.getLanguage() : Locale.ENGLISH.getLanguage();
if (HttpMethod.GET.equals(request.getMethod())) {
Multimap<String, String> decodedParams = queryParser().apply(request.getEndpoint().getRawQuery());
if (!decodedParams.containsKey(RequestParameters.VERSION)) {
decodedParams.put(RequestParameters.VERSION, apiVersion);
}
decodedParams.put(RequestParameters.LOCALE, lang);
decodedParams.put(RequestParameters.ACCESS_KEY_ID, accessKeyId);
decodedParams.put(RequestParameters.SIGNATURE, signature);
request = request.toBuilder().replaceQueryParams(decodedParams).build();
request = addQueryParamsToRequest(request, accessKeyId, signature,
lang);
} else {
String payload = request.getPayload().getRawContent().toString();
@ -173,10 +170,37 @@ public class RequestAuthenticator implements HttpRequestFilter, RequestSigner {
.build();
utils.logRequest(signatureLog, filteredRequest, ">>->");
return filteredRequest;
}
@VisibleForTesting
HttpRequest addQueryParamsToRequest(HttpRequest request, String accessKeyId,
String signature, String lang) {
// url encode "+" (which comes from base64 encoding) or else it may be
// converted into a %20 (space) which the API endpoint doesn't
// expect/accept.
accessKeyId = accessKeyId.replace("+", "%2B");
signature = signature.replace("+", "%2B");
Multimap<String, String> decodedParams = queryParser().apply(
request.getEndpoint().getRawQuery());
Builder<?> builder = request.toBuilder()
.endpoint(request.getEndpoint())
.method(request.getMethod());
if (!decodedParams.containsKey("Version")) {
builder.addQueryParam(RequestParameters.VERSION, apiVersion);
}
builder.addQueryParam(RequestParameters.LOCALE, lang)
.addQueryParam(RequestParameters.ACCESS_KEY_ID, accessKeyId)
// the addition of another param causes %2B's in prev. params to
// convert to %20. Needs to be addressed if there are cases where
// accessKeyId contains %2B's.
// So signature should be added last:
.addQueryParam(RequestParameters.SIGNATURE, signature);
return builder.build();
}
String createXmlElementWithValue(String payload, String tag, String value) {
String startTag = String.format("<%s>", tag);
String endTag = String.format("</%s>", tag);
@ -184,13 +208,12 @@ public class RequestAuthenticator implements HttpRequestFilter, RequestSigner {
return payload.replace(startTag + endTag, startTag + value + endTag);
}
@VisibleForTesting
public String sign(String stringToSign) {
String signed;
try {
Signature signer = signerCache.get(checkNotNull(creds.get(), "credential supplier returned null"));
signer.update(stringToSign.getBytes(UTF_8));
signed = base64().encode(signer.sign());
signed = base64().withSeparator("\n", 61).encode(signer.sign());
} catch (SignatureException e) {
throw new HttpException("error signing request", e);
} catch (ExecutionException e) {
@ -200,14 +223,16 @@ public class RequestAuthenticator implements HttpRequestFilter, RequestSigner {
}
@VisibleForTesting
public String generateAccessKeyId() {
String generateAccessKeyId() {
Calendar cal = calendarProvider.get();
String timezone = cal.getTimeZone().getDisplayName(Locale.ENGLISH);
String expires = String.valueOf(cal.getTime().getTime());
String signatureData = String.format("%s&%s&%s&%s", timezone, expires, signatureVersion, signatureMethod);
String accessKeyId = base64().encode(signatureData.getBytes(UTF_8));
return accessKeyId.replace("\n", "\r\n");
String accessKeyId = base64().withSeparator("\n", 61).encode(
signatureData.getBytes(UTF_8));
return accessKeyId;
}
@Override

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.fujitsu.fgcp.services;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
@ -50,6 +51,7 @@ import com.google.common.util.concurrent.ListenableFuture;
@Consumes(MediaType.TEXT_XML)
public interface AdditionalDiskAsyncApi {
@Named("GetVDiskStatus")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetVDiskStatus")
@ -57,6 +59,7 @@ public interface AdditionalDiskAsyncApi {
ListenableFuture<VDiskStatus> getStatus(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id);
@Named("GetVDiskAttributes")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetVDiskAttributes")
@ -64,6 +67,7 @@ public interface AdditionalDiskAsyncApi {
ListenableFuture<VDisk> get(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id);
@Named("UpdateVDiskAttribute")
@GET
@QueryParams(keys = "Action", values = "UpdateVDiskAttribute")
ListenableFuture<Void> update(
@ -71,24 +75,28 @@ public interface AdditionalDiskAsyncApi {
@QueryParam("attributeName") String name,
@QueryParam("attributeValue") String value);
@Named("BackupVDisk")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "BackupVDisk")
ListenableFuture<Void> backup(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id);
@Named("RestoreVDisk")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "RestoreVDisk")
ListenableFuture<Void> restore(@QueryParam("vsysId") String systemId,
@QueryParam("backupId") String backupId);
@Named("DestroyVDisk")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "DestroyVDisk")
ListenableFuture<Void> destroy(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String id);
@Named("DetachVDisk")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "DetachVDisk")
@ -96,6 +104,7 @@ public interface AdditionalDiskAsyncApi {
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vdiskId") String diskId,
@QueryParam("vserverId") String serverId);
@Named("DestroyVDiskBackup")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "DestroyVDiskBackup")

View File

@ -19,6 +19,8 @@
package org.jclouds.fujitsu.fgcp.services;
import java.util.Set;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
@ -54,30 +56,35 @@ import com.google.common.util.concurrent.ListenableFuture;
@Consumes(MediaType.TEXT_XML)
public interface BuiltinServerAsyncApi {
@Named("StartEFM")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "StartEFM")
ListenableFuture<Void> start(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id);
@Named("StopEFM")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "StopEFM")
ListenableFuture<Void> stop(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id);
@Named("DestroyEFM")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "DestroyEFM")
ListenableFuture<Void> destroy(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id);
@Named("BackupEFM")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "BackupEFM")
ListenableFuture<Void> backup(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id);
@Named("RestoreEFM")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "RestoreEFM")
@ -85,12 +92,14 @@ public interface BuiltinServerAsyncApi {
@BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id,
@QueryParam("backupId") String backupId);
@Named("ListEFMBackup")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "ListEFMBackup")
ListenableFuture<Set<BuiltinServerBackup>> listBackups(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id);
@Named("DestroyEFMBackup")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "DestroyEFMBackup")
@ -98,6 +107,7 @@ public interface BuiltinServerAsyncApi {
@BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id,
@QueryParam("backupId") String backupId);
@Named("GetEFMAttributes")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetEFMAttributes")
@ -105,6 +115,7 @@ public interface BuiltinServerAsyncApi {
ListenableFuture<BuiltinServer> get(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id);
@Named("UpdateEFMAttribute")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "UpdateEFMAttribute")
@ -113,6 +124,7 @@ public interface BuiltinServerAsyncApi {
@QueryParam("attributeName") String name,
@QueryParam("attributeValue") String value);
@Named("GetEFMStatus")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetEFMStatus")
@ -120,6 +132,7 @@ public interface BuiltinServerAsyncApi {
ListenableFuture<BuiltinServerStatus> getStatus(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id);
@Named("GetEFMConfiguration")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetEFMConfiguration")
@ -128,6 +141,7 @@ public interface BuiltinServerAsyncApi {
@BinderParam(BindAlsoToSystemId.class) @QueryParam("efmId") String id,
@QueryParam("configurationName") BuiltinServerConfiguration configuration);
// @Named("GetEFMConfiguration")
// @POST
// @JAXBResponseParser
// @QueryParams(keys = "Action", values = "GetEFMConfiguration")

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.fujitsu.fgcp.services;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
@ -47,12 +48,14 @@ import com.google.common.util.concurrent.ListenableFuture;
@Consumes(MediaType.TEXT_XML)
public interface DiskImageAsyncApi {
@Named("GetDiskImageAttributes")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetDiskImageAttributes")
@Transform(SingleElementResponseToElement.class)
ListenableFuture<DiskImage> get(@QueryParam("diskImageId") String id);
@Named("UpdateDiskImageAttribute")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "UpdateDiskImageAttribute")
@ -62,6 +65,7 @@ public interface DiskImageAsyncApi {
@QueryParam("attributeName") String name,
@QueryParam("attributeValue") String value);
@Named("UnregisterDiskImage")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "UnregisterDiskImage")

View File

@ -19,6 +19,8 @@
package org.jclouds.fujitsu.fgcp.services;
import java.util.Set;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.core.MediaType;
@ -48,6 +50,7 @@ import com.google.common.util.concurrent.ListenableFuture;
@Consumes(MediaType.TEXT_XML)
public interface FirewallAsyncApi extends BuiltinServerAsyncApi {
@Named("GetEFMConfiguration")
@POST
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetEFMConfiguration")

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.fujitsu.fgcp.services;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
@ -48,18 +49,21 @@ import com.google.common.util.concurrent.ListenableFuture;
@Consumes(MediaType.TEXT_XML)
public interface PublicIPAddressAsyncApi {
@Named("AttachPublicIP")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "AttachPublicIP")
ListenableFuture<Void> attach(@QueryParam("vsysId") String systemId,
@QueryParam("publicIp") String ip);
@Named("DetachPublicIP")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "DetachPublicIP")
ListenableFuture<Void> detach(@QueryParam("vsysId") String systemId,
@QueryParam("publicIp") String ip);
@Named("GetPublicIPStatus")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetPublicIPStatus")
@ -67,12 +71,14 @@ public interface PublicIPAddressAsyncApi {
ListenableFuture<PublicIPStatus> getStatus(
@QueryParam("publicIp") String ip);
@Named("GetPublicIPAttributes")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetPublicIPAttributes")
@Transform(SingleElementResponseToElement.class)
ListenableFuture<PublicIP> get(@QueryParam("publicIp") String ip);
@Named("FreePublicIP")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "FreePublicIP")

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.fujitsu.fgcp.services;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
@ -48,6 +49,7 @@ import com.google.common.util.concurrent.ListenableFuture;
@Consumes(MediaType.TEXT_XML)
public interface SystemTemplateAsyncApi {
@Named("GetVSYSDescriptorConfiguration")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetVSYSDescriptorConfiguration")
@ -55,6 +57,7 @@ public interface SystemTemplateAsyncApi {
ListenableFuture<VSystemDescriptor> get(
@QueryParam("vsysDescriptorId") String id);
@Named("UpdateVSYSDescriptorAttribute")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "UpdateVSYSDescriptorAttribute")
@ -63,12 +66,14 @@ public interface SystemTemplateAsyncApi {
@QueryParam("attributeName") String name,
@QueryParam("attributeValue") String value);
@Named("UnregisterVSYSDescriptor")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "UnregisterVSYSDescriptor")
ListenableFuture<Void> deregister(
@QueryParam("vsysDescriptorId") String id);
@Named("UnregisterPrivateVSYSDescriptor")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "UnregisterPrivateVSYSDescriptor")

View File

@ -20,6 +20,8 @@ package org.jclouds.fujitsu.fgcp.services;
import java.util.Map;
import java.util.Set;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
@ -58,6 +60,7 @@ import com.google.common.util.concurrent.ListenableFuture;
@Consumes(MediaType.TEXT_XML)
public interface VirtualDCAsyncApi {
@Named("CreateVSYS")
// @POST
@GET
@JAXBResponseParser
@ -74,12 +77,14 @@ public interface VirtualDCAsyncApi {
@QueryParam("vsysDescriptorId") String descriptorId,
@QueryParam("vsysName") String name);
@Named("ListVSYS")
@GET
@JAXBResponseParser
// @XMLResponseParser(VSYSListHandler.class)
@QueryParams(keys = "Action", values = "ListVSYS")
ListenableFuture<Set<VSystem>> listVirtualSystems();
@Named("ListServerType")
@GET
@JAXBResponseParser
// according to the manual it takes a 'String diskImageId' but value seems
@ -90,11 +95,13 @@ public interface VirtualDCAsyncApi {
// @XmlElement(type = ServerType.class)
ListenableFuture<Set<ServerType>> listServerTypes();
@Named("ListDiskImage")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "ListDiskImage")
ListenableFuture<Set<DiskImage>> listDiskImages();
@Named("ListDiskImage")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "ListDiskImage")
@ -107,11 +114,13 @@ public interface VirtualDCAsyncApi {
* @return
* @see VirtualSystemAsyncApi#listPublicIPs(String)
*/
@Named("ListPublicIP")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "ListPublicIP")
ListenableFuture<Map<PublicIP, String>> listPublicIPs();
@Named("AddAddressRange")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "AddAddressRange")
@ -119,6 +128,7 @@ public interface VirtualDCAsyncApi {
@QueryParam("pipFrom") String pipFrom,
@QueryParam("pipTo") String pipTo);
@Named("CreateAddressPool")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "CreateAddressPool")
@ -126,6 +136,7 @@ public interface VirtualDCAsyncApi {
@QueryParam("pipFrom") String pipFrom,
@QueryParam("pipTo") String pipTo);
@Named("DeleteAddressRange")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "DeleteAddressRange")
@ -133,16 +144,19 @@ public interface VirtualDCAsyncApi {
@QueryParam("pipFrom") String pipFrom,
@QueryParam("pipTo") String pipTo);
@Named("GetAddressRange")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetAddressRange")
ListenableFuture<Set<AddressRange>> getAddressRange();
@Named("ListVSYSDescriptor")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "ListVSYSDescriptor")
ListenableFuture<Set<VSystemDescriptor>> listVSYSDescriptor();
@Named("ListVSYSDescriptor")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "ListVSYSDescriptor")
@ -151,32 +165,38 @@ public interface VirtualDCAsyncApi {
@QueryParam("estimateFrom") int estimateFrom,
@QueryParam("estimateTo") int estimateTo);
@Named("GetEventLog")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetEventLog")
ListenableFuture<Set<EventLog>> getEventLogs();
@Named("GetEventLog")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetEventLog")
ListenableFuture<Set<EventLog>> getEventLogs(@QueryParam("all") boolean all);
@Named("GetInformation")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetInformation")
ListenableFuture<Set<Information>> getInformation();
@Named("GetInformation")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetInformation")
ListenableFuture<Set<Information>> getInformation(
@QueryParam("all") boolean all);
@Named("GetSystemUsage")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetSystemUsage")
ListenableFuture<Set<UsageInfo>> getSystemUsage();
@Named("GetSystemUsage")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetSystemUsage")

View File

@ -19,6 +19,8 @@
package org.jclouds.fujitsu.fgcp.services;
import java.util.Set;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@ -54,30 +56,35 @@ import com.google.common.util.concurrent.ListenableFuture;
@Consumes(MediaType.TEXT_XML)
public interface VirtualServerAsyncApi {
@Named("StartVServer")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "StartVServer")
ListenableFuture<Void> start(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id);
@Named("StopVServer")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "StopVServer")
ListenableFuture<Void> stop(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id);
@Named("StopVServer")
@GET
@JAXBResponseParser
@QueryParams(keys = { "Action", "force" }, values = { "StopVServer", "true" })
ListenableFuture<Void> stopForcefully(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id);
@Named("DestroyVServer")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "DestroyVServer")
ListenableFuture<Void> destroy(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id);
@Named("GetVServerAttributes")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetVServerAttributes")
@ -85,6 +92,7 @@ public interface VirtualServerAsyncApi {
ListenableFuture<VServer> get(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id);
@Named("GetVServerConfiguration")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetVServerConfiguration")
@ -92,6 +100,7 @@ public interface VirtualServerAsyncApi {
ListenableFuture<VServerWithDetails> getDetails(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id);
@Named("UpdateVServerAttribute")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "UpdateVServerAttribute")
@ -100,6 +109,7 @@ public interface VirtualServerAsyncApi {
@QueryParam("attributeName") String name,
@QueryParam("attributeValue") String value);
@Named("GetVServerStatus")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetVServerStatus")
@ -108,6 +118,7 @@ public interface VirtualServerAsyncApi {
ListenableFuture<VServerStatus> getStatus(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id);
@Named("GetVServerInitialPassword")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetVServerInitialPassword")
@ -115,6 +126,7 @@ public interface VirtualServerAsyncApi {
ListenableFuture<String> getInitialPassword(
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String id);
@Named("AttachVDisk")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "AttachVDisk")
@ -122,6 +134,7 @@ public interface VirtualServerAsyncApi {
@BinderParam(BindAlsoToSystemId.class) @QueryParam("vserverId") String serverId,
@QueryParam("vdiskId") String diskId);
@Named("GetPerformanceInformation")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetPerformanceInformation")
@ -129,6 +142,7 @@ public interface VirtualServerAsyncApi {
@BinderParam(BindAlsoToSystemId.class) @QueryParam("serverId") String id,
@QueryParam("interval") String interval);
@Named("GetPerformanceInformation")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetPerformanceInformation")
@ -137,6 +151,7 @@ public interface VirtualServerAsyncApi {
@QueryParam("dataType") String dataType,
@QueryParam("interval") String interval);
@Named("RegisterPrivateDiskImage")
@POST
@JAXBResponseParser
@QueryParams(keys = "Action", values = "RegisterPrivateDiskImage")

View File

@ -19,6 +19,8 @@
package org.jclouds.fujitsu.fgcp.services;
import java.util.Set;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
@ -56,23 +58,27 @@ import com.google.common.util.concurrent.ListenableFuture;
@Consumes(MediaType.TEXT_XML)
public interface VirtualSystemAsyncApi {
@Named("DestroyVSYS")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "DestroyVSYS")
ListenableFuture<Void> destroy(@QueryParam("vsysId") String id);
@Named("GetVSYSStatus")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetVSYSStatus")
@Transform(SingleElementResponseToElement.class)
ListenableFuture<VSystemStatus> getStatus(@QueryParam("vsysId") String id);
@Named("GetVSYSAttributes")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetVSYSAttributes")
@Transform(SingleElementResponseToElement.class)
ListenableFuture<VSystem> get(@QueryParam("vsysId") String id);
@Named("GetVSYSConfiguration")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "GetVSYSConfiguration")
@ -80,6 +86,7 @@ public interface VirtualSystemAsyncApi {
ListenableFuture<VSystemWithDetails> getDetails(
@QueryParam("vsysId") String id);
@Named("UpdateVSYSAttribute")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "UpdateVSYSAttribute")
@ -87,6 +94,7 @@ public interface VirtualSystemAsyncApi {
@QueryParam("attributeName") String name,
@QueryParam("attributeValue") String value);
@Named("UpdateVSYSConfiguration")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "UpdateVSYSConfiguration")
@ -94,6 +102,7 @@ public interface VirtualSystemAsyncApi {
@QueryParam("configurationName") String name,
@QueryParam("configurationValue") String value);
@Named("CreateVServer")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "CreateVServer")
@ -104,11 +113,13 @@ public interface VirtualSystemAsyncApi {
@QueryParam("diskImageId") String diskImageId,
@BinderParam(BindAlsoToSystemId.class) @QueryParam("networkId") String networkId);
@Named("ListVServer")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "ListVServer")
ListenableFuture<Set<VServer>> listServers(@QueryParam("vsysId") String id);
@Named("CreateVDisk")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "CreateVDisk")
@ -116,11 +127,13 @@ public interface VirtualSystemAsyncApi {
ListenableFuture<String> createDisk(@QueryParam("vsysId") String id,
@QueryParam("vdiskName") String name, @QueryParam("size") int size);
@Named("ListVDisk")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "ListVDisk")
ListenableFuture<Set<VDisk>> listDisks(@QueryParam("vsysId") String id);
@Named("AllocatePublicIP")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "AllocatePublicIP")
@ -131,6 +144,7 @@ public interface VirtualSystemAsyncApi {
* @return
* @see VirtualDCAsyncApi#listPublicIPs()
*/
@Named("ListPublicIP")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "ListPublicIP")
@ -138,6 +152,7 @@ public interface VirtualSystemAsyncApi {
ListenableFuture<Set<PublicIP>> listPublicIPs(
@QueryParam("vsysId") String id);
@Named("CreateEFM")
@GET
@JAXBResponseParser
// SLB is the only built-in server that can currently be created so
@ -148,12 +163,14 @@ public interface VirtualSystemAsyncApi {
@QueryParam("efmName") String name,
@BinderParam(BindAlsoToSystemId.class) @QueryParam("networkId") String networkId);
@Named("ListEFM")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "ListEFM")
ListenableFuture<Set<BuiltinServer>> listBuiltinServers(
@QueryParam("vsysId") String id, @QueryParam("efmType") String type);
@Named("StandByConsole")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "StandByConsole")
@ -161,6 +178,7 @@ public interface VirtualSystemAsyncApi {
ListenableFuture<String> standByConsole(@QueryParam("vsysId") String id,
@QueryParam("networkId") String networkId);
@Named("RegisterPrivateVSYSDescriptor")
@GET
@JAXBResponseParser
@QueryParams(keys = "Action", values = "RegisterPrivateVSYSDescriptor")

View File

@ -84,7 +84,7 @@ public abstract class FGCPBaseComputeServiceLiveTest extends
// before running it, start an SSL/VPN connection to the last updated vsys'
// DMZ.
// may also need to configure SNAT and FW rules to allow the VM to
// communicate out (53 for DNS, 80 for yum).
// communicate out (53/tcp-udp for DNS, 80/tcp for yum).
public void testAScriptExecutionAfterBootWithBasicTemplate()
throws Exception {
super.testAScriptExecutionAfterBootWithBasicTemplate();

View File

@ -0,0 +1,160 @@
package org.jclouds.fujitsu.fgcp.filters;
import static org.testng.Assert.assertEquals;
import java.security.KeyStore;
import java.util.Calendar;
import java.util.TimeZone;
import javax.inject.Provider;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.internal.SignatureWire;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
public class RequestAuthenticatorTest {
Provider<Calendar> calendarProvider = new Provider<Calendar>() {
public Calendar get() {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("Australia/Sydney"));
c.setTimeInMillis(1358747939000L); // Mon Jan 21 16:58:59 +1100 2013
return c;
}
};
Supplier<Credentials> creds = new Supplier<Credentials>() {
@Override
public Credentials get() {
return null;
}
};
Supplier<KeyStore> keystore = new Supplier<KeyStore>() {
public KeyStore get() {
return null;
}
};
RequestAuthenticator a = new RequestAuthenticator(calendarProvider,
new RequestAuthenticator.SignatureForCredentials(keystore), creds,
new HttpUtils(0, 0, 0, 0), new SignatureWire(), "");
@Test
public void testGenerateAccessKeyIdWithNewline() throws Exception {
String accessKeyId = a.generateAccessKeyId();
assertEquals(
accessKeyId,
"RWFzdGVybiBTdGFuZGFyZCBUaW1lIChOZXcgU291dGggV2FsZXMpJjEzNTg3N\nDc5MzkwMDAmMS4wJlNIQTF3aXRoUlNB");
}
@Test
public void testAddQueryParamsToRequest() throws Exception {
String accessKeyId = "accessKeyId";
String signature = "signature";
String lang = "en";
HttpRequest request = HttpRequest
.builder()
.endpoint(
"https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18")
.method("GET").build();
HttpRequest newRequest = a.addQueryParamsToRequest(request, accessKeyId,
signature, lang);
assertEquals(
newRequest.getRequestLine(),
"GET https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18&Locale=en&AccessKeyId=accessKeyId&Signature=signature HTTP/1.1");
}
@Test
public void testAddQueryParamsWithRealValuesToRequest() throws Exception {
String accessKeyId = "RWFzdGVybiBTdGFuZGFyZCBUaW1lIChOZXcgU291dGggV2FsZXMpJjEzNTg4M\nzg4OTgwNTcmMS4wJlNIQTF3aXRoUlNB";
String signature = "QFAmuZ0XyOjy6fmMLkMCH/xObY6Jhyltjo2hBcUrXHape8ecTmAlbCUO/+lKr\nQ3Qeu1cNqh8BXSnoc4vXR3aezR6V94aBlQ/4uowQuZP3S8yjnC0aPjWQ70JcB\nULR+qSGNmc97agOTMmIl4JJcukCBEEyLSzRDDe2ib2PqN11RA55GmAP/xx7qg\n0fj6ieauzuzImL1tJq03w0tPdCSuB6lnZe/81Z+Rbqwfl3kdGNBnV7YrdD3Qg\nRBDOKgA2okMlc5pzgk59i/O07ScfoJs7A58HnTZZ2KyVPFgHq6YGpCA2PqII6\nHUlqx6hkX9HFXIz+wz52gbSwBrqgloAw8w8Iw==";
String lang = "en";
HttpRequest request = HttpRequest
.builder()
.endpoint(
"https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18")
.method("GET").build();
HttpRequest newRequest = a.addQueryParamsToRequest(request, accessKeyId,
signature, lang);
assertEquals(
newRequest.getRequestLine(),
"GET https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18&Locale=en&AccessKeyId=RWFzdGVybiBTdGFuZGFyZCBUaW1lIChOZXcgU291dGggV2FsZXMpJjEzNTg4M%0Azg4OTgwNTcmMS4wJlNIQTF3aXRoUlNB&Signature=QFAmuZ0XyOjy6fmMLkMCH/xObY6Jhyltjo2hBcUrXHape8ecTmAlbCUO/%2BlKr%0AQ3Qeu1cNqh8BXSnoc4vXR3aezR6V94aBlQ/4uowQuZP3S8yjnC0aPjWQ70JcB%0AULR%2BqSGNmc97agOTMmIl4JJcukCBEEyLSzRDDe2ib2PqN11RA55GmAP/xx7qg%0A0fj6ieauzuzImL1tJq03w0tPdCSuB6lnZe/81Z%2BRbqwfl3kdGNBnV7YrdD3Qg%0ARBDOKgA2okMlc5pzgk59i/O07ScfoJs7A58HnTZZ2KyVPFgHq6YGpCA2PqII6%0AHUlqx6hkX9HFXIz%2Bwz52gbSwBrqgloAw8w8Iw%3D%3D HTTP/1.1");
}
@Test
public void testAddQueryParamsWithSlashes() throws Exception {
String accessKeyId = "accessKeyId";
String signature = "sig/na/ture";
String lang = "en";
HttpRequest request = HttpRequest
.builder()
.endpoint(
"https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18")
.method("GET").build();
HttpRequest newRequest = a.addQueryParamsToRequest(request, accessKeyId,
signature, lang);
assertEquals(
newRequest.getRequestLine(),
"GET https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18&Locale=en&AccessKeyId=accessKeyId&Signature=sig/na/ture HTTP/1.1");
}
@Test
public void testAddQueryParamsWithNewlines() throws Exception {
String accessKeyId = "accessKey\nId";
String signature = "sig\nna\nture";
String lang = "en";
HttpRequest request = HttpRequest
.builder()
.endpoint(
"https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18")
.method("GET").build();
HttpRequest newRequest = a.addQueryParamsToRequest(request, accessKeyId,
signature, lang);
assertEquals(
newRequest.getRequestLine(),
"GET https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18&Locale=en&AccessKeyId=accessKey%0AId&Signature=sig%0Ana%0Ature HTTP/1.1");
}
@Test
public void testAddQueryParamsWithPlus() throws Exception {
String accessKeyId = "accessKey+Id";
String signature = "sign+ature";
String lang = "en";
HttpRequest request = HttpRequest
.builder()
.endpoint(
"https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18")
.method("GET").build();
HttpRequest newRequest = a.addQueryParamsToRequest(request, accessKeyId,
signature, lang);
assertEquals(
newRequest.getRequestLine(),
// NOTE: AccessKeyId's "=" becomes a %20 (space) as explained in
// addQueryParamsToRequest().
"GET https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18&Locale=en&AccessKeyId=accessKey%20Id&Signature=sign%2Bature HTTP/1.1");
}
@Test
public void testAddQueryParamsWithBase64Symbols() throws Exception {
String accessKeyId = "accessKeyId\nWith/And+And=";
String signature = "signature\nWith/And+And=";
String lang = "en";
HttpRequest request = HttpRequest
.builder()
.endpoint(
"https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18")
.method("GET").build();
HttpRequest newRequest = a.addQueryParamsToRequest(request, accessKeyId,
signature, lang);
assertEquals(
newRequest.getRequestLine(),
"GET https://api.globalcloud.fujitsu.com.au/ovissapi/endpoint?Version=2012-02-18&Locale=en&AccessKeyId=accessKeyId%0AWith/And%20And%3D&Signature=signature%0AWith/And%2BAnd%3D HTTP/1.1");
}
}

View File

@ -95,7 +95,7 @@ public class BaseFGCPRestApiExpectTest extends
+ "&" + query
+ "&Locale=en"
+ "&AccessKeyId=R01ULTA5OjAwJjEyMzQ1Njc4OTAmMS4wJlNIQTF3aXRoUlNB"
+ "&Signature=G2rGfLAkbq0IURQfXIWYxj3BnMGbjRk4KPnZLAze3Lt4SMMRt8lkjqKvR5Cm%20nFpDN7J6IprVCCsIrRq5BqPeXT6xtWyb6qMNds2BAr1h/JePGs0UosOh2tgPUMSFlZwLVjgNyrSa2zeHA3AEHjF6H1jqcWXXqfCAD4SOHaNavk%3D");
+ "&Signature=G2rGfLAkbq0IURQfXIWYxj3BnMGbjRk4KPnZLAze3Lt4SMMRt8lkjqKvR5Cm%2B%0AnFpDN7J6IprVCCsIrRq5BqPeXT6xtWyb6qMNds2BAr1h/JePGs0UosOh2tgPU%0AMSFlZwLVjgNyrSa2zeHA3AEHjF6H1jqcWXXqfCAD4SOHaNavk%3D");
return HttpRequest
.builder()
.method("GET")