Merge remote branch 'upstream/master'

This commit is contained in:
David Santiago 2011-04-02 02:26:15 -05:00
commit 85d0474068
16 changed files with 427 additions and 112 deletions

View File

@ -32,6 +32,7 @@ import org.jclouds.atmos.blobstore.functions.BlobToObject;
import org.jclouds.atmos.domain.AtmosObject; import org.jclouds.atmos.domain.AtmosObject;
import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
@ -44,19 +45,21 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
public class AtmosBlobRequestSigner implements BlobRequestSigner { public class AtmosBlobRequestSigner implements BlobRequestSigner {
private final RestAnnotationProcessor<AtmosAsyncClient> processor; private final RestAnnotationProcessor<AtmosAsyncClient> processor;
private final BlobToObject blobToObject; private final BlobToObject blobToObject;
private final BlobToHttpGetOptions blob2ObjectGetOptions;
private final Method getMethod; private final Method getMethod;
private final Method deleteMethod; private final Method deleteMethod;
private final Method createMethod; private final Method createMethod;
@Inject @Inject
public AtmosBlobRequestSigner(RestAnnotationProcessor<AtmosAsyncClient> processor, BlobToObject blobToObject) public AtmosBlobRequestSigner(RestAnnotationProcessor<AtmosAsyncClient> processor, BlobToObject blobToObject,
throws SecurityException, NoSuchMethodException { BlobToHttpGetOptions blob2ObjectGetOptions) throws SecurityException, NoSuchMethodException {
this.processor = checkNotNull(processor, "processor"); this.processor = checkNotNull(processor, "processor");
this.blobToObject = checkNotNull(blobToObject, "blobToObject"); this.blobToObject = checkNotNull(blobToObject, "blobToObject");
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.getMethod = AtmosAsyncClient.class.getMethod("readFile", String.class, GetOptions[].class); this.getMethod = AtmosAsyncClient.class.getMethod("readFile", String.class, GetOptions[].class);
this.deleteMethod = AtmosAsyncClient.class.getMethod("deletePath", String.class); this.deleteMethod = AtmosAsyncClient.class.getMethod("deletePath", String.class);
this.createMethod = AtmosAsyncClient.class.getMethod("createFile", String.class, AtmosObject.class); this.createMethod = AtmosAsyncClient.class.getMethod("createFile", String.class, AtmosObject.class);
} }
@Override @Override
@ -78,4 +81,10 @@ public class AtmosBlobRequestSigner implements BlobRequestSigner {
return checkNotNull(container, "container") + "/" + checkNotNull(name, "name"); return checkNotNull(container, "container") + "/" + checkNotNull(name, "name");
} }
@Override
public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) {
return cleanRequest(processor.createRequest(getMethod, getPath(container, name), blob2ObjectGetOptions
.apply(options)));
}
} }

View File

@ -27,15 +27,16 @@ import java.lang.reflect.Method;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.s3.S3AsyncClient; import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.blobstore.functions.BlobToObject; import org.jclouds.s3.blobstore.functions.BlobToObject;
import org.jclouds.s3.domain.S3Object; import org.jclouds.s3.domain.S3Object;
import org.jclouds.s3.options.PutObjectOptions; import org.jclouds.s3.options.PutObjectOptions;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.internal.RestAnnotationProcessor;
/** /**
* *
@ -45,15 +46,18 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
public class S3BlobRequestSigner implements BlobRequestSigner { public class S3BlobRequestSigner implements BlobRequestSigner {
private final RestAnnotationProcessor<S3AsyncClient> processor; private final RestAnnotationProcessor<S3AsyncClient> processor;
private final BlobToObject blobToObject; private final BlobToObject blobToObject;
private final BlobToHttpGetOptions blob2HttpGetOptions;
private final Method getMethod; private final Method getMethod;
private final Method deleteMethod; private final Method deleteMethod;
private final Method createMethod; private final Method createMethod;
@Inject @Inject
public S3BlobRequestSigner(RestAnnotationProcessor<S3AsyncClient> processor, BlobToObject blobToObject) public S3BlobRequestSigner(RestAnnotationProcessor<S3AsyncClient> processor, BlobToObject blobToObject,
throws SecurityException, NoSuchMethodException { BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException {
this.processor = checkNotNull(processor, "processor"); this.processor = checkNotNull(processor, "processor");
this.blobToObject = checkNotNull(blobToObject, "blobToObject"); this.blobToObject = checkNotNull(blobToObject, "blobToObject");
this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
this.getMethod = S3AsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class); this.getMethod = S3AsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class);
this.deleteMethod = S3AsyncClient.class.getMethod("deleteObject", String.class, String.class); this.deleteMethod = S3AsyncClient.class.getMethod("deleteObject", String.class, String.class);
this.createMethod = S3AsyncClient.class.getMethod("putObject", String.class, S3Object.class, this.createMethod = S3AsyncClient.class.getMethod("putObject", String.class, S3Object.class,
@ -76,4 +80,8 @@ public class S3BlobRequestSigner implements BlobRequestSigner {
return cleanRequest(processor.createRequest(deleteMethod, container, name)); return cleanRequest(processor.createRequest(deleteMethod, container, name));
} }
@Override
public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) {
return cleanRequest(processor.createRequest(getMethod, container, name, blob2HttpGetOptions.apply(options)));
}
} }

View File

@ -29,6 +29,7 @@ import javax.inject.Singleton;
import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
@ -44,16 +45,20 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
public class SwiftBlobRequestSigner implements BlobRequestSigner { public class SwiftBlobRequestSigner implements BlobRequestSigner {
private final RestAnnotationProcessor<CommonSwiftAsyncClient> processor; private final RestAnnotationProcessor<CommonSwiftAsyncClient> processor;
private final BlobToObject blobToObject; private final BlobToObject blobToObject;
private final BlobToHttpGetOptions blob2HttpGetOptions;
private final Method getMethod; private final Method getMethod;
private final Method deleteMethod; private final Method deleteMethod;
private final Method createMethod; private final Method createMethod;
@Inject @Inject
public SwiftBlobRequestSigner(RestAnnotationProcessor<CommonSwiftAsyncClient> processor, BlobToObject blobToObject) public SwiftBlobRequestSigner(RestAnnotationProcessor<CommonSwiftAsyncClient> processor, BlobToObject blobToObject,
throws SecurityException, NoSuchMethodException { BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException {
this.processor = checkNotNull(processor, "processor"); this.processor = checkNotNull(processor, "processor");
this.blobToObject = checkNotNull(blobToObject, "blobToObject"); this.blobToObject = checkNotNull(blobToObject, "blobToObject");
this.getMethod = CommonSwiftAsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class); this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
this.getMethod = CommonSwiftAsyncClient.class.getMethod("getObject", String.class, String.class,
GetOptions[].class);
this.deleteMethod = CommonSwiftAsyncClient.class.getMethod("removeObject", String.class, String.class); this.deleteMethod = CommonSwiftAsyncClient.class.getMethod("removeObject", String.class, String.class);
this.createMethod = CommonSwiftAsyncClient.class.getMethod("putObject", String.class, SwiftObject.class); this.createMethod = CommonSwiftAsyncClient.class.getMethod("putObject", String.class, SwiftObject.class);
@ -74,4 +79,8 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner {
return cleanRequest(processor.createRequest(deleteMethod, container, name)); return cleanRequest(processor.createRequest(deleteMethod, container, name));
} }
@Override
public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) {
return cleanRequest(processor.createRequest(getMethod, container, name, blob2HttpGetOptions.apply(options)));
}
} }

View File

@ -22,6 +22,7 @@ package org.jclouds.blobstore;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobBuilder; import org.jclouds.blobstore.domain.BlobBuilder;
import org.jclouds.blobstore.internal.RequestSigningUnsupported; import org.jclouds.blobstore.internal.RequestSigningUnsupported;
import org.jclouds.blobstore.options.GetOptions;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;
@ -47,6 +48,12 @@ public interface BlobRequestSigner {
*/ */
HttpRequest signGetBlob(String container, String name); HttpRequest signGetBlob(String container, String name);
/**
* @param options
* @see #signGetBlob(String, String)
*/
HttpRequest signGetBlob(String container, String name, GetOptions options);
/** /**
* gets a signed request, including headers as necessary, to delete a blob from an external * gets a signed request, including headers as necessary, to delete a blob from an external
* client. * client.

View File

@ -27,6 +27,8 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.options.GetOptions;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
@ -39,10 +41,12 @@ import org.jclouds.http.filters.BasicAuthentication;
public class TransientBlobRequestSigner implements BlobRequestSigner { public class TransientBlobRequestSigner implements BlobRequestSigner {
private final BasicAuthentication basicAuth; private final BasicAuthentication basicAuth;
private final BlobToHttpGetOptions blob2HttpGetOptions;
@Inject @Inject
public TransientBlobRequestSigner(BasicAuthentication basicAuth) { public TransientBlobRequestSigner(BasicAuthentication basicAuth, BlobToHttpGetOptions blob2HttpGetOptions) {
this.basicAuth = checkNotNull(basicAuth, "basicAuth"); this.basicAuth = checkNotNull(basicAuth, "basicAuth");
this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
} }
@Override @Override
@ -53,10 +57,10 @@ public class TransientBlobRequestSigner implements BlobRequestSigner {
@Override @Override
public HttpRequest signPutBlob(String container, Blob blob) { public HttpRequest signPutBlob(String container, Blob blob) {
HttpRequest request = HttpRequest.builder().method("PUT") HttpRequest request = HttpRequest.builder().method("PUT").endpoint(
.endpoint(URI.create(String.format("http://localhost/%s/%s", container, blob.getMetadata().getName()))) URI.create(String.format("http://localhost/%s/%s", container, blob.getMetadata().getName()))).payload(
.payload(blob.getPayload()) blob.getPayload()).headers(
.headers(HttpUtils.getContentHeadersFromMetadata(blob.getMetadata().getContentMetadata())).build(); HttpUtils.getContentHeadersFromMetadata(blob.getMetadata().getContentMetadata())).build();
return basicAuth.filter(request); return basicAuth.filter(request);
} }
@ -67,4 +71,12 @@ public class TransientBlobRequestSigner implements BlobRequestSigner {
return basicAuth.filter(request); return basicAuth.filter(request);
} }
@Override
public HttpRequest signGetBlob(String container, String name, GetOptions options) {
HttpRequest request = HttpRequest.builder().method("GET").endpoint(
URI.create(String.format("http://localhost/%s/%s", container, name))).headers(
blob2HttpGetOptions.apply(options).buildRequestHeaders()).build();
return basicAuth.filter(request);
}
} }

View File

@ -23,6 +23,7 @@ import javax.inject.Singleton;
import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.options.GetOptions;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
/** /**
@ -47,4 +48,9 @@ public class RequestSigningUnsupported implements BlobRequestSigner {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public HttpRequest signGetBlob(String container, String name, GetOptions options) {
throw new UnsupportedOperationException();
}
} }

View File

@ -19,6 +19,7 @@
package org.jclouds.blobstore.integration.internal; package org.jclouds.blobstore.integration.internal;
import static org.jclouds.blobstore.options.GetOptions.Builder.range;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
@ -73,6 +74,24 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
} }
} }
@Test
public void testSignGetUrlOptions() throws Exception {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = context.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
context.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = context.getSigner().signGetBlob(container, name, range(0, 1));
assertEquals(request.getFilters().size(), 0);
assertEquals(Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput()), "fo");
} finally {
returnContainer(container);
}
}
@Test @Test
public void testSignPutUrl() throws Exception { public void testSignPutUrl() throws Exception {
String name = "hello"; String name = "hello";

View File

@ -32,6 +32,7 @@ import org.jclouds.azureblob.blobstore.functions.BlobToAzureBlob;
import org.jclouds.azureblob.domain.AzureBlob; import org.jclouds.azureblob.domain.AzureBlob;
import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
@ -44,19 +45,21 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
public class AzureBlobRequestSigner implements BlobRequestSigner { public class AzureBlobRequestSigner implements BlobRequestSigner {
private final RestAnnotationProcessor<AzureBlobAsyncClient> processor; private final RestAnnotationProcessor<AzureBlobAsyncClient> processor;
private final BlobToAzureBlob blobToBlob; private final BlobToAzureBlob blobToBlob;
private final BlobToHttpGetOptions blob2HttpGetOptions;
private final Method getMethod; private final Method getMethod;
private final Method deleteMethod; private final Method deleteMethod;
private final Method createMethod; private final Method createMethod;
@Inject @Inject
public AzureBlobRequestSigner(RestAnnotationProcessor<AzureBlobAsyncClient> processor, BlobToAzureBlob blobToBlob) public AzureBlobRequestSigner(RestAnnotationProcessor<AzureBlobAsyncClient> processor, BlobToAzureBlob blobToBlob,
throws SecurityException, NoSuchMethodException { BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException {
this.processor = checkNotNull(processor, "processor"); this.processor = checkNotNull(processor, "processor");
this.blobToBlob = checkNotNull(blobToBlob, "blobToBlob"); this.blobToBlob = checkNotNull(blobToBlob, "blobToBlob");
this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
this.getMethod = AzureBlobAsyncClient.class.getMethod("getBlob", String.class, String.class, GetOptions[].class); this.getMethod = AzureBlobAsyncClient.class.getMethod("getBlob", String.class, String.class, GetOptions[].class);
this.deleteMethod = AzureBlobAsyncClient.class.getMethod("deleteBlob", String.class, String.class); this.deleteMethod = AzureBlobAsyncClient.class.getMethod("deleteBlob", String.class, String.class);
this.createMethod = AzureBlobAsyncClient.class.getMethod("putBlob", String.class, AzureBlob.class); this.createMethod = AzureBlobAsyncClient.class.getMethod("putBlob", String.class, AzureBlob.class);
} }
@Override @Override
@ -74,4 +77,8 @@ public class AzureBlobRequestSigner implements BlobRequestSigner {
return cleanRequest(processor.createRequest(deleteMethod, container, name)); return cleanRequest(processor.createRequest(deleteMethod, container, name));
} }
@Override
public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) {
return cleanRequest(processor.createRequest(getMethod, container, name, blob2HttpGetOptions.apply(options)));
}
} }

View File

@ -28,6 +28,7 @@ import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rimuhosting.miro.compute.config.RimuHostingComputeServiceContextModule; import org.jclouds.rimuhosting.miro.compute.config.RimuHostingComputeServiceContextModule;
import org.jclouds.rimuhosting.miro.config.RimuHostingRestClientModule;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Key; import com.google.inject.Key;
@ -47,8 +48,7 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole * @author Adrian Cole
* @see RimuHostingComputeServiceContext * @see RimuHostingComputeServiceContext
*/ */
public class RimuHostingContextBuilder extends public class RimuHostingContextBuilder extends ComputeServiceContextBuilder<RimuHostingClient, RimuHostingAsyncClient> {
ComputeServiceContextBuilder<RimuHostingClient, RimuHostingAsyncClient> {
public RimuHostingContextBuilder(Properties props) { public RimuHostingContextBuilder(Properties props) {
super(RimuHostingClient.class, RimuHostingAsyncClient.class, props); super(RimuHostingClient.class, RimuHostingAsyncClient.class, props);
@ -62,11 +62,13 @@ public class RimuHostingContextBuilder extends
@Override @Override
public ComputeServiceContext buildComputeServiceContext() { public ComputeServiceContext buildComputeServiceContext() {
// need the generic type information // need the generic type information
return (ComputeServiceContext) this return (ComputeServiceContext) this.buildInjector().getInstance(
.buildInjector() Key.get(new TypeLiteral<ComputeServiceContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
.getInstance(
Key
.get(new TypeLiteral<ComputeServiceContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
})); }));
} }
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new RimuHostingRestClientModule());
}
} }

View File

@ -101,6 +101,10 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
builder.imageId(from.getImageId() + ""); builder.imageId(from.getImageId() + "");
builder.operatingSystem(parseOperatingSystem(from, location)); builder.operatingSystem(parseOperatingSystem(from, location));
builder.hardware(null);// TODO builder.hardware(null);// TODO
if (from.getBillingData() != null && from.getBillingData().getDateCancelled() != null
&& RunningState.NOTRUNNING == from.getState())
builder.state(NodeState.TERMINATED);
else
builder.state(runningStateToNodeState.get(from.getState())); builder.state(runningStateToNodeState.get(from.getState()));
builder.publicAddresses(getPublicAddresses.apply(from)); builder.publicAddresses(getPublicAddresses.apply(from));
builder.credentials(credentialStore.get("node#" + from.getId())); builder.credentials(credentialStore.get("node#" + from.getId()));

View File

@ -0,0 +1,87 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.rimuhosting.miro.config;
import java.lang.reflect.Type;
import java.util.Date;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.date.DateService;
import org.jclouds.http.RequiresHttp;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rimuhosting.miro.RimuHostingAsyncClient;
import org.jclouds.rimuhosting.miro.RimuHostingClient;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
/**
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class RimuHostingRestClientModule extends RestClientModule<RimuHostingClient, RimuHostingAsyncClient> {
public RimuHostingRestClientModule() {
super(RimuHostingClient.class, RimuHostingAsyncClient.class);
}
@Override
protected void configure() {
bind(DateAdapter.class).to(RimuIso8601DateAdapter.class);
super.configure();
}
@Singleton
public static class RimuIso8601DateAdapter implements DateAdapter {
private final DateService dateService;
private final Json json;
private static class DateHolder {
String iso_format;
}
@Inject
private RimuIso8601DateAdapter(DateService dateService, Json json) {
this.dateService = dateService;
this.json = json;
}
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
throw new UnsupportedOperationException();
}
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
String toParse = json.toString();
DateHolder dateHolder = this.json.fromJson(toParse, DateHolder.class);
return (dateHolder.iso_format != null) ? dateService.iso8601SecondsDateParse(dateHolder.iso_format) : null;
}
}
}

View File

@ -32,90 +32,81 @@ import org.jclouds.rimuhosting.miro.domain.PricingPlan;
* *
* @author Ivan Meredith * @author Ivan Meredith
*/ */
public class NewServerData implements PostData{ public class NewServerData implements PostData {
public NewServerData(){} public NewServerData() {
}
public NewServerData(CreateOptions createOptions, PricingPlan pricingPlan){ public NewServerData(CreateOptions createOptions, PricingPlan pricingPlan) {
this.createOptions = createOptions; this.createOptions = createOptions;
if(pricingPlan != null){ if (pricingPlan != null) {
this.planId = pricingPlan.getId(); this.planId = pricingPlan.getId();
} }
} }
public NewServerData(CreateOptions createOptions, String pricingPlanId){ public NewServerData(CreateOptions createOptions, String pricingPlanId) {
this.createOptions = createOptions; this.createOptions = createOptions;
this.planId = pricingPlanId; this.planId = pricingPlanId;
} }
public NewServerData(CloneOptions cloneOptions){ public NewServerData(CloneOptions cloneOptions) {
this.cloneOptions = cloneOptions; this.cloneOptions = cloneOptions;
} }
/** /**
* Set the billing id if you want to control how it is billed.&nbsp; * Set the billing id if you want to control how it is billed.&nbsp; Else we will, for example,
* Else we will, for example, try to use, say, the credit card you used * try to use, say, the credit card you used on your last order that had a credit card.&nbsp; Or
* on your last order that had a credit card.&nbsp; Or use a wire * use a wire transfer method if you are using that on other orders.&nbsp; See the billing
* transfer method if you are using that on other orders.&nbsp; See the * methods resource for how to find what billing methods/ids you have setup on your identity.
* billing methods resource for how to find what billing methods/ids you
* have setup on your identity.
*/ */
@SerializedName("billing_oid") @SerializedName("billing_oid")
private Long billingId; private Long billingId;
/** /**
* The host server on which to setup the server.&nbsp; Typically you * The host server on which to setup the server.&nbsp; Typically you will want to leave this
* will want to leave this blank and let the API decide what is * blank and let the API decide what is best/available.&nbsp; And exception may be if you are a
* best/available.&nbsp; And exception may be if you are a customer with * customer with a dedicated server that is a VPS host with us.&nbsp; And in that case you may
* a dedicated server that is a VPS host with us.&nbsp; And in that case * want to force a VPS to be setup on a particular server of yours.
* you may want to force a VPS to be setup on a particular server of
* yours.
*/ */
@SerializedName("host_server_oid") @SerializedName("host_server_oid")
private String hostServerId; private String hostServerId;
/** /**
* These are the instantiation options.&nbsp; e.g. domain name, * These are the instantiation options.&nbsp; e.g. domain name, password, etc.&nbsp; Only provide
* password, etc.&nbsp; Only provide these if you are not cloning a VPS * these if you are not cloning a VPS (the vps_order_oid_to_clone setting). i.e. utually
* (the vps_order_oid_to_clone setting). i.e. utually exclusive to * exclusive to instantiation_via_clone_options
* instantiation_via_clone_options
*/ */
@SerializedName("instantiation_options") @SerializedName("instantiation_options")
private CreateOptions createOptions; private CreateOptions createOptions;
/** /**
* These are the instantiation options if you are creating a new VPS as * These are the instantiation options if you are creating a new VPS as a clone of an existing
* a clone of an existing VPS. Mutually exclusive to * VPS. Mutually exclusive to instantiation_options.
* instantiation_options.
*/ */
@SerializedName("instantiation_via_clone_options") @SerializedName("instantiation_via_clone_options")
private CloneOptions cloneOptions; private CloneOptions cloneOptions;
/** /**
* The number of IPs you need on the VPS and a justification for having * The number of IPs you need on the VPS and a justification for having more than one.&nbsp; Just
* more than one.&nbsp; Just leave blank for a single IP (which is all * leave blank for a single IP (which is all most servers need).
* most servers need).
*/ */
@SerializedName("ip_request") @SerializedName("ip_request")
private IpRequestData ipRequest; private IpRequestData ipRequest;
/** /**
* The pricing plan code you want to use.&nbsp; Per the pricing plans * The pricing plan code you want to use.&nbsp; Per the pricing plans resource.
* resource.
*/ */
@SerializedName("pricing_plan_code") @SerializedName("pricing_plan_code")
private String planId; private String planId;
/** /**
* To whom will the order belong? Leave this blank and we will assign it * To whom will the order belong? Leave this blank and we will assign it to you.&nbsp; If you set
* to you.&nbsp; If you set it and you do not have permissions on that * it and you do not have permissions on that user's identity you will get an error.
* user's identity you will get an error.
*/ */
@SerializedName("user_oid") @SerializedName("user_oid")
private Long userId; private Long userId;
/** /**
* Any particular memory/disk size overrides you want to make.&nbsp; If * Any particular memory/disk size overrides you want to make.&nbsp; If they are compatible with
* they are compatible with the pricing plan you selected we will use * the pricing plan you selected we will use them.&nbsp; We will calculate the cost based on the
* them.&nbsp; We will calculate the cost based on the resources we * resources we setup you up with.&nbsp; We can provision VPSs in most sizes, provided that the
* setup you up with.&nbsp; We can provision VPSs in most sizes, * host has space for them.&nbsp; The low contention plans are an exception.&nbsp; You will
* provided that the host has space for them.&nbsp; The low contention * likely need to use the provided memory and disk sizes.&nbsp; Since those plans are designed so
* plans are an exception.&nbsp; You will likely need to use the * there is a specific (small) number of VPSs per host.&nbsp; And having VPSs with 'odd' sizes
* provided memory and disk sizes.&nbsp; Since those plans are designed * stops them all fitting in 'neatly' (that's not a problem on the bigger-, non-low
* so there is a specific (small) number of VPSs per host.&nbsp; And * contention-plans.
* having VPSs with 'odd' sizes stops them all fitting in 'neatly'
* (that's not a problem on the bigger-, non-low contention-plans.
*/ */
@SerializedName("vps_paramters") @SerializedName("vps_paramters")
private ServerParameters serverParameters; private ServerParameters serverParameters;
@ -187,22 +178,22 @@ public class NewServerData implements PostData{
this.serverParameters = serverParameters; this.serverParameters = serverParameters;
} }
public void validate(){ public void validate() {
//bitwise XOR, works with boolean :) // bitwise XOR, works with boolean :)
assert(this.cloneOptions == null ^ this.createOptions == null); assert (this.cloneOptions == null ^ this.createOptions == null);
if(this.cloneOptions != null){ if (this.cloneOptions != null) {
this.cloneOptions.validate(); this.cloneOptions.validate();
} }
if(this.createOptions != null){ if (this.createOptions != null) {
this.createOptions.validate(); this.createOptions.validate();
assert(this.planId != null && this.planId.length() == 0); assert (this.planId != null && this.planId.length() == 0);
} }
if(this.ipRequest != null){ if (this.ipRequest != null) {
this.ipRequest.validate(); this.ipRequest.validate();
} }
if(this.serverParameters != null){ if (this.serverParameters != null) {
this.serverParameters.validate(); this.serverParameters.validate();
} }
} }

View File

@ -57,6 +57,8 @@ public class Server implements Comparable<Server> {
private String slug; private String slug;
@SerializedName("vps_parameters") @SerializedName("vps_parameters")
private ServerParameters serverParameters; private ServerParameters serverParameters;
@SerializedName("billing_info")
private BillingData billingData;
private DataCenter location; private DataCenter location;
@ -190,4 +192,37 @@ public class Server implements Comparable<Server> {
public List<MetaData> getMetaData() { public List<MetaData> getMetaData() {
return metaData; return metaData;
} }
public Boolean getOnDedicatedHardware() {
return onDedicatedHardware;
}
public BillingData getBillingData() {
return billingData;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Server other = (Server) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
} }

View File

@ -35,6 +35,7 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.rimuhosting.miro.binder.CreateServerOptions; import org.jclouds.rimuhosting.miro.binder.CreateServerOptions;
import org.jclouds.rimuhosting.miro.filters.RimuHostingAuthentication; import org.jclouds.rimuhosting.miro.filters.RimuHostingAuthentication;
import org.jclouds.rimuhosting.miro.functions.ParseRimuHostingException; import org.jclouds.rimuhosting.miro.functions.ParseRimuHostingException;
import org.jclouds.rimuhosting.miro.functions.ParseServersFromJsonResponse;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
@ -68,6 +69,21 @@ public class RimuHostingAsyncClientTest extends RestClientTest<RimuHostingAsyncC
} }
public void testGetServerList() throws SecurityException, NoSuchMethodException, IOException {
Method method = RimuHostingAsyncClient.class.getMethod("getServerList");
GeneratedHttpRequest<RimuHostingAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.rimuhosting.com/r/orders;include_inactive=N HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nHost: api.rimuhosting.com\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseServersFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ParseRimuHostingException.class);
checkFilters(httpRequest);
}
@Override @Override
protected void checkFilters(HttpRequest request) { protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1); assertEquals(request.getFilters().size(), 1);

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.rimuhosting.miro.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rimuhosting.miro.config.RimuHostingRestClientModule.RimuIso8601DateAdapter;
import org.jclouds.rimuhosting.miro.domain.Server;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ParseServerFromJsonResponseTest {
Injector i = Guice.createInjector(new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(RimuIso8601DateAdapter.class);
super.configure();
}
});
public void testCancelled() {
InputStream is = getClass().getResourceAsStream("/cancelled.json");
ParseServerFromJsonResponse parser = i.getInstance(ParseServerFromJsonResponse.class);
Server response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
assertEquals(response.getBillingData().getDateSuspended(), null);
assertEquals(response.getBillingData().getDateCancelled(), new SimpleDateFormatDateService()
.iso8601SecondsDateParse("2011-04-02T03:30:28Z"));
}
}

View File

@ -0,0 +1,38 @@
{ "get_order_response" : { "status_message" : null
, "status_code" : 200
, "response_created_time" : { "ms_since_epoch": 1301716709422, "iso_format" : "2011-04-02T03:58:29Z", "users_tz_offset_ms" : 46800000}
, "response_created_time_epoch_ms" : 1301716709422
, "error_info" : null
, "extended_error_infos" : null
, "response_type" : "OK"
, "human_readable_message" : "Information about rimuhosting.jcloudsr-eed"
, "redirect_uri" : null
, "response_display_duration_type" : "REGULAR"
, "about_order" : { "order_oid" : 721950181
, "domain_name" : "rimuhosting.jcloudsr-eed"
, "slug" : "order-721950181-rimuhosting-jcloudsr-e"
, "billing_oid" : 50081656
, "is_on_customers_own_physical_server" : false
, "vps_parameters" : { "memory_mb" : 1150
, "disk_space_mb" : 4096
, "disk_space_2_mb" : 0}
, "host_server_oid" : "324"
, "server_type" : "VPS"
, "data_transfer_allowance" : { "data_transfer_gb" : 75
, "data_transfer" : ""}
, "billing_info" : { "monthly_recurring_fee" : 44.95
, "monthly_recurring_amt" : { "amt" : 44.95
, "currency" : "CUR_USD"
, "amt_usd" : 44.95}
, "suspended_date" : null
, "prepaid_until" : null
, "order_date" : { "ms_since_epoch": 1301710569000, "iso_format" : "2011-04-02T02:16:09Z", "users_tz_offset_ms" : 46800000}
, "cancellation_date" : { "ms_since_epoch": 1301715028000, "iso_format" : "2011-04-02T03:30:28Z", "users_tz_offset_ms" : 46800000}}
, "location" : { "data_center_location_code" : "DCDALLAS"
, "data_center_location_name" : "Dallas"
, "data_center_location_country_2ltr" : "US"}
, "allocated_ips" : { "primary_ip" : "206.123.115.150"
, "secondary_ips" : []}
, "running_state" : "NOTRUNNING"
, "distro" : "ubuntu1004.64"
, "meta_data" : []}}}