Issue 412: split cloudsigma and elastichosts apis

This commit is contained in:
Adrian Cole 2010-12-01 22:41:25 +00:00
parent 989500ded6
commit 243fcfab81
47 changed files with 2333 additions and 742 deletions

View File

@ -106,7 +106,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>r06</version>
<version>r07</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>

View File

@ -21,7 +21,9 @@ package org.jclouds.util;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.not;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.base.Splitter.on;
import static com.google.common.base.Throwables.getCausalChain;
@ -32,6 +34,7 @@ import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.filterKeys;
import static com.google.common.io.ByteStreams.toByteArray;
import static com.google.common.io.Closeables.closeQuietly;
import static org.jclouds.util.Patterns.CHAR_TO_PATTERN;
@ -70,6 +73,8 @@ import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.io.OutputSupplier;
@ -84,6 +89,32 @@ import com.google.inject.spi.Message;
*/
public class Utils {
/**
* If the supplied map contains the key {@code k1}, its value will be assigned to the key
* {@code k2}. Note that this doesn't modify the input map.
*
* @param <V>
* type of value the map holds
* @param in
* the map you wish to make a copy of
* @param k1
* old key
* @param k2
* new key
* @return copy of the map with the value of the key re-routed, or the original, if it {@code k1}
* wasn't present.
*/
public static <V> Map<String, V> renameKey(Map<String, V> in, String k1, String k2) {
if (in.containsKey(k1)) {
Builder<String, V> builder = ImmutableMap.builder();
builder.putAll(filterKeys(in, not(equalTo(k1))));
V tags = in.get(k1);
builder.put(k2, tags);
in = builder.build();
}
return in;
}
public static <K, V> Supplier<Map<K, V>> composeMapSupplier(Iterable<Supplier<Map<K, V>>> suppliers) {
return new ListMapSupplier<K, V>(suppliers);
}

View File

@ -89,6 +89,12 @@ bluelock-vcdirector.propertiesbuilder=org.jclouds.vcloud.bluelock.BlueLockVCloud
gogrid.propertiesbuilder=org.jclouds.gogrid.GoGridPropertiesBuilder
gogrid.contextbuilder=org.jclouds.gogrid.GoGridContextBuilder
elastichosts.propertiesbuilder=org.jclouds.elastichosts.ElasticHostsPropertiesBuilder
elastichosts.contextbuilder=org.jclouds.elastichosts.ElasticHostsContextBuilder
cloudsigma.propertiesbuilder=org.jclouds.cloudsigma.CloudSigmaPropertiesBuilder
cloudsigma.contextbuilder=org.jclouds.cloudsigma.CloudSigmaContextBuilder
ibmdev.propertiesbuilder=org.jclouds.ibmdev.IBMDeveloperCloudPropertiesBuilder
ibmdev.contextbuilder=org.jclouds.ibmdev.IBMDeveloperCloudContextBuilder

View File

@ -23,6 +23,7 @@ import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import org.jclouds.domain.Credentials;
@ -42,6 +43,15 @@ import com.google.inject.spi.Message;
*/
@Test(groups = "unit", testName = "jclouds.UtilsTest")
public class UtilsTest {
public void testRenameKeyWhenNotFound() {
Map<String, String> nothing = ImmutableMap.of();
assertEquals(Utils.renameKey(nothing, "foo", "bar"), nothing);
}
public void testRenameKeyWhenFound() {
Map<String, String> nothing = ImmutableMap.of("foo", "bar");
assertEquals(Utils.renameKey(nothing, "foo", "bar"), ImmutableMap.of("bar", "bar"));
}
public void testOverridingCredentialsWhenOverridingIsNull() {
Credentials defaultCredentials = new Credentials("foo", "bar");
@ -69,7 +79,7 @@ public class UtilsTest {
assertEquals(Utils.overrideCredentialsIfSupplied(defaultCredentials, overridingCredentials), new Credentials(
"foo", "bar"));
}
public void testGetCause() {
AuthorizationException aex = createMock(AuthorizationException.class);
Message message = new Message(ImmutableList.of(), "test", aex);

View File

@ -28,7 +28,7 @@
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-elastichosts</artifactId>

View File

@ -0,0 +1,125 @@
/**
*
* 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.cloudsigma;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
import org.jclouds.elastichosts.CommonElasticHostsAsyncClient;
import org.jclouds.elastichosts.ElasticHostsClient;
import org.jclouds.elastichosts.binders.BindCreateDriveRequestToPlainTextString;
import org.jclouds.elastichosts.binders.BindDriveDataToPlainTextString;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.functions.SplitNewlines;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to CloudSigma via their REST API.
* <p/>
*
* @see ElasticHostsClient
* @see <a href="TODO: insert URL of provider documentation" />
* @author Adrian Cole
*/
@RequestFilters(BasicAuthentication.class)
@Consumes(MediaType.TEXT_PLAIN)
public interface CloudSigmaAsyncClient extends CommonElasticHostsAsyncClient {
/**
* @see ElasticHostsClient#listStandardDrives()
*/
@GET
@Path("/drives/standard/list")
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listStandardDrives();
/**
* @see ElasticHostsClient#listStandardCds()
*/
@GET
@Path("/drives/standard/cd/list")
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listStandardCds();
/**
* @see ElasticHostsClient#listStandardImages()
*/
@GET
@Path("/drives/standard/img/list")
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listStandardImages();
/**
* @see ElasticHostsClient#listDriveInfo()
*/
@Override
@GET
@Path("/drives/info")
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class)
ListenableFuture<Set<? extends org.jclouds.elastichosts.domain.DriveInfo>> listDriveInfo();
/**
* @see ElasticHostsClient#getDriveInfo
*/
@Override
@GET
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/{uuid}/info")
ListenableFuture<? extends DriveInfo> getDriveInfo(@PathParam("uuid") String uuid);
/**
* @see ElasticHostsClient#createDrive
*/
@Override
@POST
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/create")
ListenableFuture<? extends DriveInfo> createDrive(
@BinderParam(BindCreateDriveRequestToPlainTextString.class) CreateDriveRequest createDrive);
/**
* @see ElasticHostsClient#setDriveData
*/
@POST
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/{uuid}/set")
ListenableFuture<? extends DriveInfo> setDriveData(@PathParam("uuid") String uuid,
@BinderParam(BindDriveDataToPlainTextString.class) DriveData createDrive);
}

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.cloudsigma;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.concurrent.Timeout;
import org.jclouds.elastichosts.CommonElasticHostsClient;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
/**
* Provides synchronous access to CloudSigma.
* <p/>
*
* @see CloudSigmaAsyncClient
* @see <a href="TODO: insert URL of ElasticHosts documentation" />
* @author Adrian Cole
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface CloudSigmaClient extends CommonElasticHostsClient {
/**
* list of drive uuids that are in the library
*
* @return or empty set if no drives are found
*/
Set<String> listStandardDrives();
/**
* list of cd uuids that are in the library
*
* @return or empty set if no cds are found
*/
Set<String> listStandardCds();
/**
* list of image uuids that are in the library
*
* @return or empty set if no images are found
*/
Set<String> listStandardImages();
/**
* {@inheritDoc}
*/
@Override
Set<? extends DriveInfo> listDriveInfo();
/**
* {@inheritDoc}
*/
@Override
DriveInfo getDriveInfo(String uuid);
/**
* {@inheritDoc}
*/
@Override
DriveInfo createDrive(CreateDriveRequest createDrive);
/**
* {@inheritDoc}
*/
@Override
DriveInfo setDriveData(String uuid, DriveData driveData);
}

View File

@ -0,0 +1,45 @@
/**
*
* 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.cloudsigma;
import java.util.List;
import java.util.Properties;
import org.jclouds.cloudsigma.config.CloudSigmaRestClientModule;
import org.jclouds.rest.RestContextBuilder;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
*/
public class CloudSigmaContextBuilder extends
RestContextBuilder<CloudSigmaClient, CloudSigmaAsyncClient> {
public CloudSigmaContextBuilder(Properties props) {
super(CloudSigmaClient.class, CloudSigmaAsyncClient.class, props);
}
protected void addClientModule(List<Module> modules) {
modules.add(new CloudSigmaRestClientModule());
}
}

View File

@ -0,0 +1,47 @@
/**
*
* 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.cloudsigma;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
/**
* Builds properties used in CloudSigma Clients
*
* @author Adrian Cole
*/
public class CloudSigmaPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "https://api.cloudsigma.com");
properties.setProperty(PROPERTY_API_VERSION, "1.0");
return properties;
}
public CloudSigmaPropertiesBuilder(Properties properties) {
super(properties);
}
}

View File

@ -0,0 +1,76 @@
/**
*
* 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.cloudsigma.config;
import java.util.Map;
import org.jclouds.cloudsigma.CloudSigmaAsyncClient;
import org.jclouds.cloudsigma.CloudSigmaClient;
import org.jclouds.cloudsigma.functions.CreateDriveRequestToMap;
import org.jclouds.cloudsigma.functions.DriveDataToMap;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.handlers.ElasticHostsErrorHandler;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
/**
* Configures the CloudSigma connection.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class CloudSigmaRestClientModule extends RestClientModule<CloudSigmaClient, CloudSigmaAsyncClient> {
public CloudSigmaRestClientModule() {
super(CloudSigmaClient.class, CloudSigmaAsyncClient.class);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ElasticHostsErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ElasticHostsErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ElasticHostsErrorHandler.class);
}
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<CreateDriveRequest, Map<String, String>>>() {
}).to(CreateDriveRequestToMap.class);
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
}).to(DriveDataToMap.class);
}
@Override
protected void bindRetryHandlers() {
// TODO
}
}

View File

@ -0,0 +1,415 @@
/**
*
* 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.cloudsigma.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import org.jclouds.elastichosts.domain.ClaimType;
import org.jclouds.elastichosts.domain.DriveStatus;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class DriveInfo extends org.jclouds.elastichosts.domain.DriveInfo {
public static class Builder extends org.jclouds.elastichosts.domain.DriveInfo.Builder {
private Boolean autoexpanding;
private Integer bits;
private String description;
private Set<String> driveType = ImmutableSet.of();
private String encryptionKey;
private Boolean free;
private String installNotes;
private String os;
private DriveType type;
private URI url;
public Builder autoexpanding(Boolean autoexpanding) {
this.autoexpanding = autoexpanding;
return this;
}
public Builder bits(Integer bits) {
this.bits = bits;
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Builder driveType(Iterable<String> driveType) {
this.driveType = ImmutableSet.copyOf(checkNotNull(driveType, "driveType"));
return this;
}
public Builder encryptionKey(String encryptionKey) {
this.encryptionKey = encryptionKey;
return this;
}
public Builder free(Boolean free) {
this.free = free;
return this;
}
public Builder installNotes(String installNotes) {
this.installNotes = installNotes;
return this;
}
public Builder os(String os) {
this.os = os;
return this;
}
public Builder type(DriveType type) {
this.type = type;
return this;
}
public Builder url(URI url) {
this.url = url;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public Builder status(DriveStatus status) {
return Builder.class.cast(super.status(status));
}
/**
* {@inheritDoc}
*/
@Override
public Builder user(String user) {
return Builder.class.cast(super.user(user));
}
/**
* {@inheritDoc}
*/
@Override
public Builder claimed(Iterable<String> claimed) {
return Builder.class.cast(super.claimed(claimed));
}
/**
* {@inheritDoc}
*/
@Override
public Builder imaging(String imaging) {
return Builder.class.cast(super.imaging(imaging));
}
/**
* {@inheritDoc}
*/
@Override
public Builder readBytes(long readBytes) {
return Builder.class.cast(super.readBytes(readBytes));
}
/**
* {@inheritDoc}
*/
@Override
public Builder readRequests(long readRequests) {
return Builder.class.cast(super.readRequests(readRequests));
}
/**
* {@inheritDoc}
*/
@Override
public Builder writeBytes(long writeBytes) {
return Builder.class.cast(super.writeBytes(writeBytes));
}
/**
* {@inheritDoc}
*/
@Override
public Builder writeRequests(long writeRequests) {
return Builder.class.cast(super.writeRequests(writeRequests));
}
/**
* {@inheritDoc}
*/
@Override
public Builder encryptionCipher(String encryptionCipher) {
return Builder.class.cast(super.encryptionCipher(encryptionCipher));
}
/**
* {@inheritDoc}
*/
@Override
public Builder claimType(ClaimType claimType) {
return Builder.class.cast(super.claimType(claimType));
}
/**
* {@inheritDoc}
*/
@Override
public Builder readers(Iterable<String> readers) {
return Builder.class.cast(super.readers(readers));
}
/**
* {@inheritDoc}
*/
@Override
public Builder size(long size) {
return Builder.class.cast(super.size(size));
}
/**
* {@inheritDoc}
*/
@Override
public Builder uuid(String uuid) {
return Builder.class.cast(super.uuid(uuid));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder tags(Iterable<String> tags) {
return Builder.class.cast(super.tags(tags));
}
/**
* {@inheritDoc}
*/
@Override
public Builder userMetadata(Map<String, String> userMetadata) {
return Builder.class.cast(super.userMetadata(userMetadata));
}
public static Builder fromDriveInfo(org.jclouds.elastichosts.domain.DriveInfo driveInfo) {
return new Builder().uuid(driveInfo.getUuid()).name(driveInfo.getName()).size(driveInfo.getSize())
.claimType(driveInfo.getClaimType()).readers(driveInfo.getReaders()).tags(driveInfo.getTags())
.userMetadata(driveInfo.getUserMetadata()).status(driveInfo.getStatus()).user(driveInfo.getUser())
.claimed(driveInfo.getClaimed()).encryptionCipher(driveInfo.getEncryptionCipher())
.imaging(driveInfo.getImaging()).readBytes(driveInfo.getReadBytes())
.readRequests(driveInfo.getReadRequests()).writeBytes(driveInfo.getWriteBytes())
.writeRequests(driveInfo.getWriteRequests());
}
/**
* {@inheritDoc}
*/
@Override
public DriveInfo build() {
return new DriveInfo(uuid, name, size, claimType, readers, tags, userMetadata, status, user, claimed,
encryptionCipher, imaging, readBytes, readRequests, writeBytes, writeRequests, autoexpanding, bits,
description, driveType, encryptionKey, free, installNotes, os, type, url);
}
}
private final Boolean autoexpanding;
private final Integer bits;
private final String description;
private final ImmutableSet<String> driveType;
private final String encryptionKey;
private final Boolean free;
private final String installNotes;
private final String os;
private final DriveType type;
private final URI url;
public DriveInfo(String uuid, String name, long size, ClaimType claimType, Iterable<String> readers,
Iterable<String> tags, Map<String, String> userMetadata, DriveStatus status, String user, Set<String> claimed,
String encryptionCipher, String imaging, long readBytes, long readRequests, long writeBytes,
long writeRequests, Boolean autoexpanding, Integer bits, String description, Iterable<String> driveType,
String encryptionKey, Boolean free, String installNotes, String os, DriveType type, URI url) {
super(uuid, name, size, claimType, readers, tags, userMetadata, status, user, claimed, encryptionCipher, imaging,
readBytes, readRequests, writeBytes, writeRequests);
this.autoexpanding = autoexpanding;
this.bits = bits;
this.description = description;
this.driveType = ImmutableSet.copyOf(driveType);
this.encryptionKey = encryptionKey;
this.free = free;
this.installNotes = installNotes;
this.os = os;
this.type = type;
this.url = url;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((autoexpanding == null) ? 0 : autoexpanding.hashCode());
result = prime * result + ((bits == null) ? 0 : bits.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((driveType == null) ? 0 : driveType.hashCode());
result = prime * result + ((encryptionKey == null) ? 0 : encryptionKey.hashCode());
result = prime * result + ((free == null) ? 0 : free.hashCode());
result = prime * result + ((installNotes == null) ? 0 : installNotes.hashCode());
result = prime * result + ((os == null) ? 0 : os.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((url == null) ? 0 : url.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
DriveInfo other = (DriveInfo) obj;
if (autoexpanding == null) {
if (other.autoexpanding != null)
return false;
} else if (!autoexpanding.equals(other.autoexpanding))
return false;
if (bits == null) {
if (other.bits != null)
return false;
} else if (!bits.equals(other.bits))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (driveType == null) {
if (other.driveType != null)
return false;
} else if (!driveType.equals(other.driveType))
return false;
if (encryptionKey == null) {
if (other.encryptionKey != null)
return false;
} else if (!encryptionKey.equals(other.encryptionKey))
return false;
if (free == null) {
if (other.free != null)
return false;
} else if (!free.equals(other.free))
return false;
if (installNotes == null) {
if (other.installNotes != null)
return false;
} else if (!installNotes.equals(other.installNotes))
return false;
if (os == null) {
if (other.os != null)
return false;
} else if (!os.equals(other.os))
return false;
if (type != other.type)
return false;
if (url == null) {
if (other.url != null)
return false;
} else if (!url.equals(other.url))
return false;
return true;
}
// TODO
public Boolean getAutoexpanding() {
return autoexpanding;
}
// TODO
public Integer getBits() {
return bits;
}
// TODO undocumented
public String getDescription() {
return description;
}
// TODO
public Set<String> getDriveType() {
return driveType;
}
// TODO
public String getEncryptionKey() {
return encryptionKey;
}
// TODO
public Boolean getFree() {
return free;
}
// TODO
public String getInstallNotes() {
return installNotes;
}
// TODO
public String getOs() {
return os;
}
// TODO
public DriveType getType() {
return type;
}
// TODO
@Override
public String toString() {
return "[size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", uuid=" + uuid + ", name="
+ name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", autoexpanding=" + autoexpanding
+ ", bits=" + bits + ", description=" + description + ", driveType=" + driveType + ", encryptionKey="
+ encryptionKey + ", free=" + free + ", installNotes=" + installNotes + ", os=" + os + ", type=" + type
+ ", url=" + url + "]";
}
public URI getUrl() {
return url;
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.elastichosts.domain;
package org.jclouds.cloudsigma.domain;
import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -0,0 +1,58 @@
/**
*
* 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.cloudsigma.functions;
import static org.jclouds.util.Utils.renameKey;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
/**
*
* @author Adrian Cole
*/
@Singleton
public class CreateDriveRequestToMap implements Function<CreateDriveRequest, Map<String, String>> {
private final org.jclouds.elastichosts.functions.CreateDriveRequestToMap baseDriveToMap;
@Inject
public CreateDriveRequestToMap(org.jclouds.elastichosts.functions.CreateDriveRequestToMap baseDriveToMap) {
this.baseDriveToMap = baseDriveToMap;
}
@Override
public Map<String, String> apply(CreateDriveRequest from) {
return Maps.transformEntries(renameKey(baseDriveToMap.apply(from), "tags", "use"),
new Maps.EntryTransformer<String, String, String>() {
@Override
public String transformEntry(String arg0, String arg1) {
return "use".equals(arg0) ? arg1.replace(' ', ',') : arg1;
}
}); }
}

View File

@ -0,0 +1,59 @@
/**
*
* 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.cloudsigma.functions;
import static org.jclouds.util.Utils.renameKey;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.elastichosts.domain.DriveData;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
/**
*
* @author Adrian Cole
*/
@Singleton
public class DriveDataToMap implements Function<DriveData, Map<String, String>> {
private final org.jclouds.elastichosts.functions.DriveDataToMap baseDriveToMap;
@Inject
public DriveDataToMap(org.jclouds.elastichosts.functions.DriveDataToMap baseDriveToMap) {
this.baseDriveToMap = baseDriveToMap;
}
@Override
public Map<String, String> apply(DriveData from) {
return Maps.transformEntries(renameKey(baseDriveToMap.apply(from), "tags", "use"),
new Maps.EntryTransformer<String, String, String>() {
@Override
public String transformEntry(String arg0, String arg1) {
return "use".equals(arg0) ? arg1.replace(' ', ',') : arg1;
}
});
}
}

View File

@ -0,0 +1,53 @@
/**
*
* 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.cloudsigma.functions;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.http.HttpResponse;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class KeyValuesDelimitedByBlankLinesToDriveInfo implements Function<HttpResponse, DriveInfo> {
private final ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet setParser;
@Inject
public KeyValuesDelimitedByBlankLinesToDriveInfo(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet setParser) {
this.setParser = setParser;
}
@Override
public DriveInfo apply(HttpResponse response) {
Set<DriveInfo> drives = setParser.apply(response);
if (drives.size() == 0)
return null;
return Iterables.get(drives, 0);
}
}

View File

@ -0,0 +1,61 @@
/**
*
* 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.cloudsigma.functions;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.elastichosts.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ReturnStringIf2xx;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet implements Function<HttpResponse, Set<DriveInfo>> {
private final ReturnStringIf2xx returnStringIf200;
private final ListOfKeyValuesDelimitedByBlankLinesToListOfMaps mapConverter;
private final MapToDriveInfo mapToDrive;
@Inject
ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet(ReturnStringIf2xx returnStringIf200,
ListOfKeyValuesDelimitedByBlankLinesToListOfMaps mapConverter, MapToDriveInfo mapToDrive) {
this.returnStringIf200 = returnStringIf200;
this.mapConverter = mapConverter;
this.mapToDrive = mapToDrive;
}
@Override
public Set<DriveInfo> apply(HttpResponse response) {
String text = returnStringIf200.apply(response);
if (text == null || text.trim().equals(""))
return ImmutableSet.<DriveInfo> of();
return ImmutableSet.copyOf(Iterables.transform(mapConverter.apply(text), mapToDrive));
}
}

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.cloudsigma.functions;
import java.net.URI;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.cloudsigma.domain.DriveType;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
/**
*
* @author Adrian Cole
*/
@Singleton
public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo> {
private final org.jclouds.elastichosts.functions.MapToDriveInfo mapToDriveInfo;
@Inject
public MapToDriveInfo(org.jclouds.elastichosts.functions.MapToDriveInfo mapToDriveInfo) {
this.mapToDriveInfo = mapToDriveInfo;
}
@Override
public DriveInfo apply(Map<String, String> from) {
if (from.size() == 0)
return null;
DriveInfo.Builder builder = DriveInfo.Builder.fromDriveInfo(mapToDriveInfo.apply(from));
if (from.containsKey("use"))
builder.tags(Splitter.on(',').split(from.get("use")));
if (from.containsKey("bits"))
builder.bits(new Integer(from.get("bits")));
if (from.containsKey("url"))
builder.url(URI.create(from.get("url")));
builder.encryptionKey(from.get("encryption:key"));
builder.description(from.get("description"));
builder.installNotes(from.get("install_notes"));
builder.os(from.get("os"));
if (from.containsKey("drive_type"))
builder.driveType(Splitter.on(',').split(from.get("drive_type")));
if (from.containsKey("autoexpanding"))
builder.autoexpanding(new Boolean(from.get("autoexpanding")));
if (from.containsKey("free"))
builder.free(new Boolean(from.get("free")));
if (from.containsKey("type"))
builder.type(DriveType.fromValue(from.get("type")));
return builder.build();
}
}

View File

@ -0,0 +1,114 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.elastichosts;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.elastichosts.binders.BindCreateDriveRequestToPlainTextString;
import org.jclouds.elastichosts.binders.BindDriveDataToPlainTextString;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.domain.DriveInfo;
import org.jclouds.elastichosts.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
import org.jclouds.elastichosts.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
import org.jclouds.elastichosts.functions.SplitNewlines;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to ElasticHosts via their REST API.
* <p/>
*
* @see ElasticHostsClient
* @see <a href="TODO: insert URL of provider documentation" />
* @author Adrian Cole
*/
@RequestFilters(BasicAuthentication.class)
@Consumes(MediaType.TEXT_PLAIN)
public interface CommonElasticHostsAsyncClient {
/**
* @see ElasticHostsClient#listDrives()
*/
@GET
@Path("/drives/list")
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listDrives();
/**
* @see ElasticHostsClient#listDriveInfo()
*/
@GET
@Path("/drives/info")
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class)
ListenableFuture<Set<? extends DriveInfo>> listDriveInfo();
/**
* @see ElasticHostsClient#getDriveInfo
*/
@GET
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/{uuid}/info")
ListenableFuture<? extends DriveInfo> getDriveInfo(@PathParam("uuid") String uuid);
/**
* @see ElasticHostsClient#createDrive
*/
@POST
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/create")
ListenableFuture<? extends DriveInfo> createDrive(
@BinderParam(BindCreateDriveRequestToPlainTextString.class) CreateDriveRequest createDrive);
/**
* @see ElasticHostsClient#setDriveData
*/
@POST
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/{uuid}/set")
ListenableFuture<? extends DriveInfo> setDriveData(@PathParam("uuid") String uuid,
@BinderParam(BindDriveDataToPlainTextString.class) DriveData createDrive);
/**
* @see ElasticHostsClient#destroyDrive
*/
@POST
@Path("/drives/{uuid}/destroy")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> destroyDrive(@PathParam("uuid") String uuid);
}

View File

@ -0,0 +1,90 @@
/**
*
* 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.elastichosts;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.domain.DriveInfo;
/**
* Provides synchronous access to ElasticHosts.
* <p/>
*
* @see ElasticHostsAsyncClient
* @see <a href="TODO: insert URL of ElasticHosts documentation" />
* @author Adrian Cole
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface CommonElasticHostsClient {
/**
* list of drive uuids in your account
*
* @return or empty set if no drives are found
*/
Set<String> listDrives();
/**
* Get all drives info
*
* @return or empty set if no drives are found
*/
Set<? extends DriveInfo> listDriveInfo();
/**
* @param uuid
* what to get
* @return null, if not found
*/
DriveInfo getDriveInfo(String uuid);
/**
* create a new drive
*
* @param createDrive
* required parameters: name, size
* @return newly created drive
*/
DriveInfo createDrive(CreateDriveRequest createDrive);
/**
* set extra drive data
*
* @param uuid
* what drive to change
* @param driveData
* what values to change
* @return new data
*/
DriveInfo setDriveData(String uuid, DriveData driveData);
/**
* Destroy a drive
*
* @param uuid
* what to delete
*/
void destroyDrive(String uuid);
}

View File

@ -19,8 +19,6 @@
package org.jclouds.elastichosts;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@ -29,17 +27,9 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.elastichosts.binders.BindCreateDriveRequestToPlainTextString;
import org.jclouds.elastichosts.binders.BindDriveDataToPlainTextString;
import org.jclouds.elastichosts.binders.BindReadDriveOptionsToPath;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.domain.DriveInfo;
import org.jclouds.elastichosts.domain.ImageConversionType;
import org.jclouds.elastichosts.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
import org.jclouds.elastichosts.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
import org.jclouds.elastichosts.functions.ReturnPayload;
import org.jclouds.elastichosts.functions.SplitNewlines;
import org.jclouds.elastichosts.options.ReadDriveOptions;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.io.Payload;
@ -62,84 +52,7 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@RequestFilters(BasicAuthentication.class)
@Consumes(MediaType.TEXT_PLAIN)
public interface ElasticHostsAsyncClient {
/**
* @see ElasticHostsClient#listDrives()
*/
@GET
@Path("/drives/list")
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listDrives();
/**
* @see ElasticHostsClient#listStandardDrives()
*/
@GET
@Path("/drives/standard/list")
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listStandardDrives();
/**
* @see ElasticHostsClient#listStandardCds()
*/
@GET
@Path("/drives/standard/cd/list")
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listStandardCds();
/**
* @see ElasticHostsClient#listStandardImages()
*/
@GET
@Path("/drives/standard/img/list")
@ResponseParser(SplitNewlines.class)
ListenableFuture<Set<String>> listStandardImages();
/**
* @see ElasticHostsClient#listDriveInfo()
*/
@GET
@Path("/drives/info")
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class)
ListenableFuture<Set<DriveInfo>> listDriveInfo();
/**
* @see ElasticHostsClient#getDriveInfo
*/
@GET
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/{uuid}/info")
ListenableFuture<DriveInfo> getDriveInfo(@PathParam("uuid") String uuid);
/**
* @see ElasticHostsClient#createDrive
*/
@POST
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/create")
ListenableFuture<DriveInfo> createDrive(
@BinderParam(BindCreateDriveRequestToPlainTextString.class) CreateDriveRequest createDrive);
/**
* @see ElasticHostsClient#setDriveData
*/
@POST
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/{uuid}/set")
ListenableFuture<DriveInfo> setDriveData(@PathParam("uuid") String uuid,
@BinderParam(BindDriveDataToPlainTextString.class) DriveData createDrive);
/**
* @see ElasticHostsClient#destroyDrive
*/
@POST
@Path("/drives/{uuid}/destroy")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> destroyDrive(@PathParam("uuid") String uuid);
public interface ElasticHostsAsyncClient extends CommonElasticHostsAsyncClient {
/**
* @see ElasticHostsClient#imageDrive(String,String)

View File

@ -19,13 +19,9 @@
package org.jclouds.elastichosts;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.domain.DriveInfo;
import org.jclouds.elastichosts.domain.ImageConversionType;
import org.jclouds.elastichosts.options.ReadDriveOptions;
import org.jclouds.io.Payload;
@ -38,77 +34,8 @@ import org.jclouds.io.Payload;
* @see <a href="TODO: insert URL of ElasticHosts documentation" />
* @author Adrian Cole
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface ElasticHostsClient {
/**
* list of drive uuids in your account
*
* @return or empty set if no drives are found
*/
Set<String> listDrives();
/**
* list of drive uuids that are in the library
*
* @return or empty set if no drives are found
*/
Set<String> listStandardDrives();
/**
* list of cd uuids that are in the library
*
* @return or empty set if no cds are found
*/
Set<String> listStandardCds();
/**
* list of image uuids that are in the library
*
* @return or empty set if no images are found
*/
Set<String> listStandardImages();
/**
* Get all drives info
*
* @return or empty set if no drives are found
*/
Set<DriveInfo> listDriveInfo();
/**
* @param uuid
* what to get
* @return null, if not found
*/
DriveInfo getDriveInfo(String uuid);
/**
* create a new drive
*
* @param createDrive
* required parameters: name, size
* @return newly created drive
*/
DriveInfo createDrive(CreateDriveRequest createDrive);
/**
* set extra drive data
*
* @param uuid
* what drive to change
* @param driveData
* what values to change
* @return new data
*/
DriveInfo setDriveData(String uuid, DriveData driveData);
/**
* Destroy a drive
*
* @param uuid
* what to delete
*/
void destroyDrive(String uuid);
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface ElasticHostsClient extends CommonElasticHostsClient {
/**
* Image a drive from another drive. The actual imaging process is asynchronous, with progress

View File

@ -20,7 +20,6 @@
package org.jclouds.elastichosts;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import java.util.Properties;
@ -35,7 +34,6 @@ public class ElasticHostsPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "https://api.elastichosts.com");
properties.setProperty(PROPERTY_API_VERSION, "1.0");
return properties;
}

View File

@ -28,11 +28,11 @@ import javax.inject.Singleton;
import javax.ws.rs.core.MediaType;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.functions.CreateDriveRequestToMap;
import org.jclouds.elastichosts.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
/**
@ -41,11 +41,11 @@ import com.google.common.collect.ImmutableSet;
*/
@Singleton
public class BindCreateDriveRequestToPlainTextString implements Binder {
private final CreateDriveRequestToMap createDriveRequestToMap;
private final Function<CreateDriveRequest, Map<String, String>> createDriveRequestToMap;
private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines;
@Inject
public BindCreateDriveRequestToPlainTextString(CreateDriveRequestToMap createDriveRequestToMap,
public BindCreateDriveRequestToPlainTextString(Function<CreateDriveRequest, Map<String, String>> createDriveRequestToMap,
ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) {
this.createDriveRequestToMap = createDriveRequestToMap;
this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines;

View File

@ -28,11 +28,11 @@ import javax.inject.Singleton;
import javax.ws.rs.core.MediaType;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.functions.DriveDataToMap;
import org.jclouds.elastichosts.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
/**
@ -41,11 +41,11 @@ import com.google.common.collect.ImmutableSet;
*/
@Singleton
public class BindDriveDataToPlainTextString implements Binder {
private final DriveDataToMap createDriveRequestToMap;
private final Function<DriveData, Map<String, String>> createDriveRequestToMap;
private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines;
@Inject
public BindDriveDataToPlainTextString(DriveDataToMap createDriveRequestToMap,
public BindDriveDataToPlainTextString(Function<DriveData, Map<String, String>> createDriveRequestToMap,
ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) {
this.createDriveRequestToMap = createDriveRequestToMap;
this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines;

View File

@ -19,8 +19,14 @@
package org.jclouds.elastichosts.config;
import java.util.Map;
import org.jclouds.elastichosts.ElasticHostsAsyncClient;
import org.jclouds.elastichosts.ElasticHostsClient;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.functions.CreateDriveRequestToMap;
import org.jclouds.elastichosts.functions.DriveDataToMap;
import org.jclouds.elastichosts.handlers.ElasticHostsErrorHandler;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.RequiresHttp;
@ -30,6 +36,9 @@ import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
/**
* Configures the ElasticHosts connection.
*
@ -37,13 +46,21 @@ import org.jclouds.rest.config.RestClientModule;
*/
@RequiresHttp
@ConfiguresRestClient
public class ElasticHostsRestClientModule extends
RestClientModule<ElasticHostsClient, ElasticHostsAsyncClient> {
public class ElasticHostsRestClientModule extends RestClientModule<ElasticHostsClient, ElasticHostsAsyncClient> {
public ElasticHostsRestClientModule() {
super(ElasticHostsClient.class, ElasticHostsAsyncClient.class);
}
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<CreateDriveRequest, Map<String, String>>>() {
}).to(CreateDriveRequestToMap.class);
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
}).to(DriveDataToMap.class);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ElasticHostsErrorHandler.class);

View File

@ -21,7 +21,6 @@ package org.jclouds.elastichosts.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
@ -37,26 +36,18 @@ import com.google.common.collect.ImmutableSet;
*/
public class DriveInfo extends BaseDrive {
public static class Builder extends BaseDrive.Builder {
private DriveStatus status;
private String user;
private Boolean autoexpanding;
private Integer bits;
private Set<String> claimed = ImmutableSet.of();
private String encryptionCipher;
private String description;
private Set<String> driveType = ImmutableSet.of();
private String encryptionKey;
private Boolean free;
private String imaging;
private String installNotes;
private String os;
private Long readBytes;
private Long readRequests;
private DriveType type;
private URI url;
private Set<String> use = ImmutableSet.of();
private Long writeBytes;
private Long writeRequests;
protected DriveStatus status;
protected String user;
protected Set<String> claimed = ImmutableSet.of();
@Nullable
protected String encryptionCipher;
@Nullable
protected String imaging;
protected long readBytes;
protected long readRequests;
protected long writeBytes;
protected long writeRequests;
public Builder status(DriveStatus status) {
this.status = status;
@ -68,91 +59,41 @@ public class DriveInfo extends BaseDrive {
return this;
}
public Builder autoexpanding(Boolean autoexpanding) {
this.autoexpanding = autoexpanding;
return this;
}
public Builder bits(Integer bits) {
this.bits = bits;
return this;
}
public Builder claimed(Iterable<String> claimed) {
this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed"));
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Builder driveType(Iterable<String> driveType) {
this.driveType = ImmutableSet.copyOf(checkNotNull(driveType, "driveType"));
return this;
}
public Builder encryptionKey(String encryptionKey) {
this.encryptionKey = encryptionKey;
return this;
}
public Builder free(Boolean free) {
this.free = free;
return this;
}
public Builder imaging(String imaging) {
this.imaging = imaging;
return this;
}
public Builder installNotes(String installNotes) {
this.installNotes = installNotes;
return this;
}
public Builder os(String os) {
this.os = os;
return this;
}
public Builder readBytes(Long readBytes) {
public Builder readBytes(long readBytes) {
this.readBytes = readBytes;
return this;
}
public Builder readRequests(Long readRequests) {
public Builder readRequests(long readRequests) {
this.readRequests = readRequests;
return this;
}
public Builder type(DriveType type) {
this.type = type;
return this;
}
public Builder url(URI url) {
this.url = url;
return this;
}
public Builder use(Iterable<String> use) {
this.use = ImmutableSet.copyOf(checkNotNull(use, "use"));
return this;
}
public Builder writeBytes(Long writeBytes) {
public Builder writeBytes(long writeBytes) {
this.writeBytes = writeBytes;
return this;
}
public Builder writeRequests(Long writeRequests) {
public Builder writeRequests(long writeRequests) {
this.writeRequests = writeRequests;
return this;
}
public Builder encryptionCipher(String encryptionCipher) {
this.encryptionCipher = encryptionCipher;
return this;
}
/**
* {@inheritDoc}
*/
@ -161,11 +102,6 @@ public class DriveInfo extends BaseDrive {
return Builder.class.cast(super.claimType(claimType));
}
public Builder encryptionCipher(String encryptionCipher) {
this.encryptionCipher = encryptionCipher;
return this;
}
/**
* {@inheritDoc}
*/
@ -214,79 +150,50 @@ public class DriveInfo extends BaseDrive {
return Builder.class.cast(super.userMetadata(userMetadata));
}
public static Builder fromDriveInfo(DriveInfo driveInfo) {
return new Builder().uuid(driveInfo.getUuid()).name(driveInfo.getName()).size(driveInfo.getSize())
.claimType(driveInfo.getClaimType()).readers(driveInfo.getReaders()).tags(driveInfo.getTags())
.userMetadata(driveInfo.getUserMetadata()).status(driveInfo.getStatus()).user(driveInfo.getUser())
.claimed(driveInfo.getClaimed()).encryptionCipher(driveInfo.getEncryptionCipher())
.imaging(driveInfo.getImaging()).readBytes(driveInfo.getReadBytes())
.readRequests(driveInfo.getReadRequests()).writeBytes(driveInfo.getWriteBytes())
.writeRequests(driveInfo.getWriteRequests());
}
/**
* {@inheritDoc}
*/
@Override
public DriveInfo build() {
return new DriveInfo(status, user, autoexpanding, bits, claimed, claimType, description, uuid, driveType,
encryptionCipher, encryptionKey, free, imaging, installNotes, name, os, readers, readBytes,
readRequests, size, tags, type, url, use, userMetadata, writeBytes, writeRequests);
return new DriveInfo(uuid, name, size, claimType, readers, tags, userMetadata, status, user, claimed,
encryptionCipher, imaging, readBytes, readRequests, writeBytes, writeRequests);
}
}
private final DriveStatus status;
private final String user;
protected final DriveStatus status;
protected final String user;
protected final Set<String> claimed;
@Nullable
private final Boolean autoexpanding;
protected final String encryptionCipher;
@Nullable
private final Integer bits;
private final Set<String> claimed;
@Nullable
private final String description;
@Nullable
private final Set<String> driveType;
@Nullable
private final String encryptionCipher;
@Nullable
private final String encryptionKey;
@Nullable
private final Boolean free;
@Nullable
private final String imaging;
@Nullable
private final String installNotes;
@Nullable
private final String os;
@Nullable
private final Long readBytes;
@Nullable
private final Long readRequests;
@Nullable
private final DriveType type;
@Nullable
private final URI url;
@Nullable
private final Set<String> use;
@Nullable
private final Long writeBytes;
@Nullable
private final Long writeRequests;
protected final String imaging;
protected final long readBytes;
protected final long readRequests;
protected final long writeBytes;
protected final long writeRequests;
public DriveInfo(DriveStatus status, String user, Boolean autoexpanding, Integer bits, Iterable<String> claimed,
ClaimType claimType, String description, String uuid, Iterable<String> driveType, String encryptionCipher,
String encryptionKey, Boolean free, String imaging, String installNotes, String name, String os,
Iterable<String> readers, Long readBytes, Long readRequests, Long size, Iterable<String> tags, DriveType type,
URI url, Iterable<String> use, Map<String, String> userMetadata, Long writeBytes, Long writeRequests) {
public DriveInfo(String uuid, String name, long size, ClaimType claimType, Iterable<String> readers,
Iterable<String> tags, Map<String, String> userMetadata, DriveStatus status, String user, Set<String> claimed,
String encryptionCipher, String imaging, long readBytes, long readRequests, long writeBytes, long writeRequests) {
super(uuid, name, size, claimType, readers, tags, userMetadata);
this.status = status;
this.user = user;
this.autoexpanding = autoexpanding;
this.bits = bits;
this.claimed = ImmutableSet.copyOf(claimed);
this.description = description;
this.driveType = ImmutableSet.copyOf(driveType);
this.encryptionCipher = encryptionCipher;
this.encryptionKey = encryptionKey;
this.free = free;
this.imaging = imaging;
this.installNotes = installNotes;
this.os = os;
this.readBytes = readBytes;
this.readRequests = readRequests;
this.type = type;
this.url = url;
this.use = ImmutableSet.copyOf(use);
this.writeBytes = writeBytes;
this.writeRequests = writeRequests;
}
@ -307,16 +214,6 @@ public class DriveInfo extends BaseDrive {
return user;
}
// TODO
public Boolean getAutoexpanding() {
return autoexpanding;
}
// TODO
public Integer getBits() {
return bits;
}
/**
*
* @return if drive is in use by a server, values are the server uuids
@ -325,16 +222,6 @@ public class DriveInfo extends BaseDrive {
return claimed;
}
// TODO undocumented
public String getDescription() {
return description;
}
// TODO
public Set<String> getDriveType() {
return driveType;
}
/**
*
* @return either 'none' or 'aes-xts-plain' (the default)
@ -344,16 +231,6 @@ public class DriveInfo extends BaseDrive {
return encryptionCipher;
}
// TODO
public String getEncryptionKey() {
return encryptionKey;
}
// TODO
public Boolean getFree() {
return free;
}
/**
*
* @return percentage completed of drive imaging if this is underway, or 'queued' if waiting for
@ -363,21 +240,11 @@ public class DriveInfo extends BaseDrive {
return imaging;
}
// TODO
public String getInstallNotes() {
return installNotes;
}
// TODO
public String getOs() {
return os;
}
/**
*
* @return Cumulative i/o byte/request count for each drive
*/
public Long getReadBytes() {
public long getReadBytes() {
return readBytes;
}
@ -385,31 +252,15 @@ public class DriveInfo extends BaseDrive {
*
* @return Cumulative i/o byte/request count for each drive
*/
public Long getReadRequests() {
public long getReadRequests() {
return readRequests;
}
// TODO
public DriveType getType() {
return type;
}
// TODO
public URI getUrl() {
return url;
}
// TODO is this the same as tags?
public Set<String> getUse() {
return use;
}
/**
*
* @return Cumulative i/o byte/request count for each drive
*/
public Long getWriteBytes() {
public long getWriteBytes() {
return writeBytes;
}
@ -417,7 +268,7 @@ public class DriveInfo extends BaseDrive {
*
* @return Cumulative i/o byte/request count for each drive
*/
public Long getWriteRequests() {
public long getWriteRequests() {
return writeRequests;
}
@ -425,26 +276,15 @@ public class DriveInfo extends BaseDrive {
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((autoexpanding == null) ? 0 : autoexpanding.hashCode());
result = prime * result + ((bits == null) ? 0 : bits.hashCode());
result = prime * result + ((claimed == null) ? 0 : claimed.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
result = prime * result + ((driveType == null) ? 0 : driveType.hashCode());
result = prime * result + ((encryptionKey == null) ? 0 : encryptionKey.hashCode());
result = prime * result + ((free == null) ? 0 : free.hashCode());
result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode());
result = prime * result + ((imaging == null) ? 0 : imaging.hashCode());
result = prime * result + ((installNotes == null) ? 0 : installNotes.hashCode());
result = prime * result + ((os == null) ? 0 : os.hashCode());
result = prime * result + ((readBytes == null) ? 0 : readBytes.hashCode());
result = prime * result + ((readRequests == null) ? 0 : readRequests.hashCode());
result = prime * result + (int) (readBytes ^ (readBytes >>> 32));
result = prime * result + (int) (readRequests ^ (readRequests >>> 32));
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((url == null) ? 0 : url.hashCode());
result = prime * result + ((use == null) ? 0 : use.hashCode());
result = prime * result + ((user == null) ? 0 : user.hashCode());
result = prime * result + ((writeBytes == null) ? 0 : writeBytes.hashCode());
result = prime * result + ((writeRequests == null) ? 0 : writeRequests.hashCode());
result = prime * result + (int) (writeBytes ^ (writeBytes >>> 32));
result = prime * result + (int) (writeRequests ^ (writeRequests >>> 32));
return result;
}
@ -457,112 +297,46 @@ public class DriveInfo extends BaseDrive {
if (getClass() != obj.getClass())
return false;
DriveInfo other = (DriveInfo) obj;
if (autoexpanding == null) {
if (other.autoexpanding != null)
return false;
} else if (!autoexpanding.equals(other.autoexpanding))
return false;
if (bits == null) {
if (other.bits != null)
return false;
} else if (!bits.equals(other.bits))
return false;
if (claimed == null) {
if (other.claimed != null)
return false;
} else if (!claimed.equals(other.claimed))
return false;
if (description == null) {
if (other.description != null)
if (encryptionCipher == null) {
if (other.encryptionCipher != null)
return false;
} else if (!description.equals(other.description))
return false;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
if (driveType == null) {
if (other.driveType != null)
return false;
} else if (!driveType.equals(other.driveType))
return false;
if (encryptionKey == null) {
if (other.encryptionKey != null)
return false;
} else if (!encryptionKey.equals(other.encryptionKey))
return false;
if (free == null) {
if (other.free != null)
return false;
} else if (!free.equals(other.free))
} else if (!encryptionCipher.equals(other.encryptionCipher))
return false;
if (imaging == null) {
if (other.imaging != null)
return false;
} else if (!imaging.equals(other.imaging))
return false;
if (installNotes == null) {
if (other.installNotes != null)
return false;
} else if (!installNotes.equals(other.installNotes))
if (readBytes != other.readBytes)
return false;
if (os == null) {
if (other.os != null)
return false;
} else if (!os.equals(other.os))
return false;
if (readBytes == null) {
if (other.readBytes != null)
return false;
} else if (!readBytes.equals(other.readBytes))
return false;
if (readRequests == null) {
if (other.readRequests != null)
return false;
} else if (!readRequests.equals(other.readRequests))
if (readRequests != other.readRequests)
return false;
if (status != other.status)
return false;
if (type != other.type)
return false;
if (url == null) {
if (other.url != null)
return false;
} else if (!url.equals(other.url))
return false;
if (use == null) {
if (other.use != null)
return false;
} else if (!use.equals(other.use))
return false;
if (user == null) {
if (other.user != null)
return false;
} else if (!user.equals(other.user))
return false;
if (writeBytes == null) {
if (other.writeBytes != null)
return false;
} else if (!writeBytes.equals(other.writeBytes))
if (writeBytes != other.writeBytes)
return false;
if (writeRequests == null) {
if (other.writeRequests != null)
return false;
} else if (!writeRequests.equals(other.writeRequests))
if (writeRequests != other.writeRequests)
return false;
return true;
}
@Override
public String toString() {
return "[name=" + name + ", size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", tags="
+ tags + ", userMetadata=" + userMetadata + ", encryptionCipher=" + encryptionCipher + ", status=" + status
+ ", user=" + user + ", autoexpanding=" + autoexpanding + ", bits=" + bits + ", claimed=" + claimed
+ ", description=" + description + ", drive=" + uuid + ", driveType=" + driveType + ", encryptionKey="
+ encryptionKey + ", free=" + free + ", imaging=" + imaging + ", installNotes=" + installNotes + ", os="
+ os + ", readBytes=" + readBytes + ", readRequests=" + readRequests + ", type=" + type + ", url=" + url
+ ", use=" + use + ", writeBytes=" + writeBytes + ", writeRequests=" + writeRequests + "]";
return "[size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", uuid=" + uuid + ", name="
+ name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", status=" + status + ", user=" + user
+ ", claimed=" + claimed + ", encryptionCipher=" + encryptionCipher + ", imaging=" + imaging
+ ", readBytes=" + readBytes + ", readRequests=" + readRequests + ", writeBytes=" + writeBytes
+ ", writeRequests=" + writeRequests + "]";
}
}

View File

@ -19,7 +19,6 @@
package org.jclouds.elastichosts.functions;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
@ -28,7 +27,6 @@ import javax.inject.Singleton;
import org.jclouds.elastichosts.domain.ClaimType;
import org.jclouds.elastichosts.domain.DriveInfo;
import org.jclouds.elastichosts.domain.DriveStatus;
import org.jclouds.elastichosts.domain.DriveType;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
@ -45,26 +43,18 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
if (from.size() == 0)
return null;
DriveInfo.Builder builder = new DriveInfo.Builder();
builder.name(from.get("name"));
if (from.containsKey("tags"))
builder.tags(Splitter.on(' ').split(from.get("tags")));
if (from.containsKey("status"))
builder.status(DriveStatus.fromValue(from.get("status")));
if (from.containsKey("use"))
builder.use(Splitter.on(',').split(from.get("use")));
builder.name(from.get("name"));
if (from.containsKey("bits"))
builder.bits(new Integer(from.get("bits")));
if (from.containsKey("url"))
builder.url(URI.create(from.get("url")));
if (from.containsKey("read:bytes"))
builder.readBytes(new Long(from.get("read:bytes")));
if (from.containsKey("read:requests"))
builder.readRequests(new Long(from.get("read:requests")));
builder.user(from.get("user"));
builder.encryptionCipher(from.get("encryption:cipher"));
builder.encryptionKey(from.get("encryption:key"));
builder.description(from.get("description"));
builder.uuid(from.get("drive"));
builder.installNotes(from.get("install_notes"));
builder.os(from.get("os"));
if (from.containsKey("write:bytes"))
builder.writeBytes(new Long(from.get("write:bytes")));
if (from.containsKey("write:requests"))
@ -73,16 +63,8 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
builder.claimType(ClaimType.fromValue(from.get("claim:type")));
if (from.containsKey("claimed"))
builder.claimed(Splitter.on(' ').split(from.get("claimed")));
if (from.containsKey("drive_type"))
builder.driveType(Splitter.on(',').split(from.get("drive_type")));
if (from.containsKey("autoexpanding"))
builder.autoexpanding(new Boolean(from.get("autoexpanding")));
if (from.containsKey("readers"))
builder.readers(Splitter.on(' ').split(from.get("readers")));
if (from.containsKey("free"))
builder.free(new Boolean(from.get("free")));
if (from.containsKey("type"))
builder.type(DriveType.fromValue(from.get("type")));
if (from.containsKey("size"))
builder.size(new Long(from.get("size")));
Map<String, String> metadata = Maps.newLinkedHashMap();

View File

@ -19,6 +19,11 @@
package org.jclouds.elastichosts.functions;
import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Sets.newTreeSet;
import java.util.Set;
import javax.inject.Inject;
@ -29,7 +34,6 @@ import org.jclouds.http.functions.ReturnStringIf2xx;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
import com.google.common.collect.Sets;
/**
*
@ -46,6 +50,6 @@ public class SplitNewlines implements Function<HttpResponse, Set<String>> {
@Override
public Set<String> apply(HttpResponse response) {
return Sets.newTreeSet(Splitter.on('\n').split(returnStringIf200.apply(response)));
return newTreeSet(filter(Splitter.on('\n').split(returnStringIf200.apply(response)), not(equalTo(""))));
}
}

View File

@ -61,7 +61,10 @@ public class ElasticHostsErrorHandler implements HttpErrorHandler {
response.getStatusLine());
switch (response.getStatusCode()) {
case 400:
exception = new IllegalArgumentException(message, exception);
if (message != null && message.indexOf("could not be found") != -1)
exception = new ResourceNotFoundException(message, exception);
else
exception = new IllegalArgumentException(message, exception);
break;
case 401:
exception = new AuthorizationException(message, exception);

View File

@ -0,0 +1,180 @@
/**
*
* 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.cloudsigma;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Properties;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.functions.SplitNewlines;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.inject.TypeLiteral;
/**
* Tests annotation parsing of {@code CloudSigmaAsyncClient}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "cloudsigma.CloudSigmaAsyncClientTest")
public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncClient> {
public void testListStandardDrives() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("listStandardDrives");
GeneratedHttpRequest<CloudSigmaAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/standard/list HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testListStandardCds() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("listStandardCds");
GeneratedHttpRequest<CloudSigmaAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/standard/cd/list HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testListStandardImages() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("listStandardImages");
GeneratedHttpRequest<CloudSigmaAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/standard/img/list HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testListDriveInfo() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("listDriveInfo");
GeneratedHttpRequest<CloudSigmaAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/info HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testGetDriveInfo() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("getDriveInfo", String.class);
GeneratedHttpRequest<CloudSigmaAsyncClient> httpRequest = processor.createRequest(method, "uuid");
assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/uuid/info HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testCreateDrive() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("createDrive", CreateDriveRequest.class);
GeneratedHttpRequest<CloudSigmaAsyncClient> httpRequest = processor.createRequest(method,
new CreateDriveRequest.Builder().name("foo").tags(ImmutableList.of("production", "candy")).size(10000l).build());
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/create HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, "name foo\nsize 10000\nuse production,candy", "text/plain", false);
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testSetDriveData() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("setDriveData", String.class, DriveData.class);
GeneratedHttpRequest<CloudSigmaAsyncClient> httpRequest = processor.createRequest(method, "100",
new DriveData.Builder().name("foo").size(10000l).tags(ImmutableList.of("production", "candy")).build());
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/100/set HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, "name foo\nsize 10000\nuse production,candy", "text/plain", false);
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<CloudSigmaAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<CloudSigmaAsyncClient>>() {
};
}
@Override
public RestContextSpec<CloudSigmaClient, CloudSigmaAsyncClient> createContextSpec() {
return new RestContextFactory().createContextSpec("cloudsigma", "foo", "bar", new Properties());
}
}

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.cloudsigma;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Set;
import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.cloudsigma.domain.DriveType;
import org.jclouds.elastichosts.CommonElasticHostsClientLiveTest;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code CloudSigmaClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "cloudsigma.CloudSigmaClientLiveTest")
public class CloudSigmaClientLiveTest extends CommonElasticHostsClientLiveTest<CloudSigmaClient, CloudSigmaAsyncClient> {
public CloudSigmaClientLiveTest() {
provider = "cloudsigma";
}
@Test
public void testListStandardDrives() throws Exception {
Set<String> drives = client.listStandardDrives();
assertNotNull(drives);
}
@Test
public void testListStandardCds() throws Exception {
Set<String> drives = client.listStandardCds();
assertNotNull(drives);
}
@Test
public void testListStandardImages() throws Exception {
Set<String> drives = client.listStandardImages();
assertNotNull(drives);
}
@Override
protected void checkDriveMatchesGet(org.jclouds.elastichosts.domain.DriveInfo newInfo) {
super.checkDriveMatchesGet(newInfo);
assertEquals(DriveInfo.class.cast(newInfo).getType(), DriveType.DISK);
}
@Override
protected void checkCreatedDrive() {
super.checkCreatedDrive();
assertEquals(DriveInfo.class.cast(info).getType(), null);
}
}

View File

@ -0,0 +1,47 @@
/**
*
* 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.cloudsigma;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*
*/
@Test(groups = "unit")
public class ProvidersInPropertiesTest {
@Test
public void testSupportedProviders() {
Iterable<String> providers = Utils.getSupportedProviders();
assert Iterables.contains(providers, "cloudsigma") : providers;
}
//
// @Test
// public void testSupportedComputeServiceProviders() {
// Iterable<String> providers = ComputeServiceUtils.getSupportedProviders();
// assert Iterables.contains(providers, "cloudsigma") : providers;
// }
}

View File

@ -0,0 +1,50 @@
/**
*
* 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.cloudsigma.functions;
import static org.testng.Assert.assertEquals;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
import com.google.inject.Guice;
/**
*
* @author Adrian Cole
*/
@Test(groups = { "unit" })
public class KeyValuesDelimitedByBlankLinesToDriveInfoTest {
private static final KeyValuesDelimitedByBlankLinesToDriveInfo FN = Guice.createInjector().getInstance(
KeyValuesDelimitedByBlankLinesToDriveInfo.class);
public void testNone() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload(""))), null);
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload("\n\n"))), null);
assertEquals(FN.apply(new HttpResponse(200, "", null)), null);
}
public void testOne() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToDriveInfoTest.class
.getResourceAsStream("/cloudsigma/drive.txt")))), MapToDriveInfoTest.ONE);
}
}

View File

@ -0,0 +1,52 @@
/**
*
* 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.cloudsigma.functions;
import static org.testng.Assert.assertEquals;
import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
/**
*
* @author Adrian Cole
*/
@Test(groups = { "unit" })
public class ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest {
private static final ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet FN = Guice.createInjector().getInstance(
ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class);
public void testNone() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload(""))), ImmutableSet.<DriveInfo> of());
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload("\n\n"))), ImmutableSet.<DriveInfo> of());
assertEquals(FN.apply(new HttpResponse(200, "", null)), ImmutableSet.<DriveInfo> of());
}
public void testOne() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToDriveInfoTest.class
.getResourceAsStream("/cloudsigma/drive.txt")))), ImmutableSet.<DriveInfo> of(MapToDriveInfoTest.ONE));
}
}

View File

@ -0,0 +1,97 @@
/**
*
* 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.cloudsigma.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.cloudsigma.domain.DriveType;
import org.jclouds.elastichosts.domain.ClaimType;
import org.jclouds.elastichosts.domain.DriveStatus;
import org.jclouds.elastichosts.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
@Test(groups = { "unit" })
public class MapToDriveInfoTest {
public static DriveInfo ONE = new DriveInfo.Builder()
.status(DriveStatus.ACTIVE)
.tags(ImmutableSet.of("networking", "security", "gateway"))
.name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
.bits(64)
.url(URI.create("http://www.ubuntu.com"))
.readBytes(4096l)
.user("58ca3c1f-7629-4771-9b71-863f40153ba4")
.encryptionCipher("aes-xts-plain")
.encryptionKey("ba6c2a4897072e9f25920ed73bd522e9c10d89f30a215158cccf8d0f654ac643")
.description("The Ubuntu Linux distribution brings the spirit of Ubuntu to the software world.")
.uuid("b8171d28-755a-4271-b891-7998871a160e")
.installNotes("first line\n\n")
.os("linux")
.writeBytes(8589938688l)
.claimType(ClaimType.SHARED)
.claimed(
ImmutableSet.of(
"00109617-2c6b-424b-9cfa-5b572c17bafe:guest:692cd1c7-a863-4a22-8170-fc6e6feb68af:ide:0:0",
"00031836-a624-4b22-bc7d-41ff8977087b:guest:a1414360-7c24-4730-8c97-180bf7775a71:ide:0:0",
"0002c6df-a1d2-4d1d-96f0-f95405a28183:guest:386f1cc7-affc-49c1-82a5-2f8e412170e4:ide:0:0",
"00031836-a624-4b22-bc7d-41ff8977087b:guest:17b076be-430d-4a76-9df3-b9896fec82a5:ide:0:0",
"000663ee-9fb6-4461-90f6-01327a4aff07:guest:f83b519f-feab-42cf-859c-f61495681ada:ide:0:1"))//
.driveType(ImmutableSet.of("installcd", "livecd"))//
.autoexpanding(false).readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
.readRequests(1l)//
.free(true)//
.type(DriveType.DISK)//
.writeRequests(2097153l)//
.size(8589934592l)//
.userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz")).build();
private static final MapToDriveInfo MAP_TO_DRIVE = new MapToDriveInfo(
new org.jclouds.elastichosts.functions.MapToDriveInfo());
public void testEmptyMapReturnsNull() {
assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.<String, String> of()), null);
}
public void testBasics() {
DriveInfo expects = new DriveInfo.Builder().name("foo").size(100l).build();
assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.of("name", "foo", "size", "100")), expects);
}
public void testComplete() throws IOException {
Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply(
Utils.toStringAndClose(MapToDriveInfoTest.class.getResourceAsStream("/cloudsigma/drive.txt"))).get(0);
assertEquals(MAP_TO_DRIVE.apply(input), ONE);
}
}

View File

@ -0,0 +1,176 @@
/**
*
* 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.elastichosts;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Properties;
import java.util.Set;
import org.jclouds.Constants;
import org.jclouds.elastichosts.domain.ClaimType;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.domain.DriveInfo;
import org.jclouds.elastichosts.domain.DriveStatus;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextFactory;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Tests behavior of {@code CommonElasticHostsClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true)
public abstract class CommonElasticHostsClientLiveTest<S extends CommonElasticHostsClient, A extends CommonElasticHostsAsyncClient> {
protected S client;
protected RestContext<S, A> context;
protected String provider = "elastichosts";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = System.getProperty("test." + provider + ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion");
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
if (credential != null)
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@BeforeGroups(groups = "live")
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
context = new RestContextFactory().createContext(provider, ImmutableSet.<Module> of(new Log4JLoggingModule()),
overrides);
client = context.getApi();
}
@AfterGroups(groups = "live")
void tearDown() {
if (context != null)
context.close();
}
@Test
public void testListDrives() throws Exception {
Set<String> drives = client.listDrives();
assertNotNull(drives);
}
@Test
public void testListDriveInfo() throws Exception {
Set<? extends DriveInfo> drives = client.listDriveInfo();
assertNotNull(drives);
}
@Test
public void testGetDrive() throws Exception {
for (String driveUUID : client.listDrives()) {
assert !"".equals(driveUUID);
assertNotNull(client.getDriveInfo(driveUUID));
}
}
protected String prefix = System.getProperty("user.name") + ".test";
protected DriveInfo info;
@Test
public void testCreate() throws Exception {
info = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(4 * 1024 * 1024l).build());
checkCreatedDrive();
DriveInfo newInfo = client.getDriveInfo(info.getUuid());
checkDriveMatchesGet(newInfo);
}
protected void checkDriveMatchesGet(DriveInfo newInfo) {
assertEquals(newInfo.getUuid(), info.getUuid());
}
protected void checkCreatedDrive() {
assertNotNull(info.getUuid());
assertNotNull(info.getUser());
assertEquals(info.getName(), prefix);
assertEquals(info.getSize(), 4 * 1024 * 1024l);
assertEquals(info.getStatus(), DriveStatus.ACTIVE);
// for some reason, these occasionally return as 4096,1
// assertEquals(info.getReadBytes(), 0l);
// assertEquals(info.getWriteBytes(), 0l);
// assertEquals(info.getReadRequests(), 0l);
// assertEquals(info.getWriteRequests(), 0l);
assertEquals(info.getEncryptionCipher(), "aes-xts-plain");
}
@Test(dependsOnMethods = "testCreate")
public void testSetDriveData() throws Exception {
DriveInfo info2 = client.setDriveData(
info.getUuid(),
new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous")
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))
.tags(ImmutableSet.of("networking", "security", "gateway"))
.userMetadata(ImmutableMap.of("foo", "bar")).build());
assertNotNull(info2.getUuid(), info.getUuid());
assertEquals(info2.getName(), "rediculous");
assertEquals(info2.getClaimType(), ClaimType.SHARED);
assertEquals(info2.getReaders(), ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"));
assertEquals(info2.getTags(), ImmutableSet.of("networking", "security", "gateway"));
assertEquals(info2.getUserMetadata(), ImmutableMap.of("foo", "bar"));
info = info2;
}
@Test(dependsOnMethods = "testSetDriveData")
public void testDestroyDrive() throws Exception {
client.destroyDrive(info.getUuid());
assertEquals(client.getDriveInfo(info.getUuid()), null);
}
}

View File

@ -19,11 +19,11 @@
package org.jclouds.elastichosts;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Properties;
import javax.ws.rs.core.MediaType;
@ -41,6 +41,7 @@ import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
@ -48,6 +49,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.inject.TypeLiteral;
@ -75,7 +77,7 @@ public class ElasticHostsAsyncClientTest extends RestClientTest<ElasticHostsAsyn
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest,
"Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
"Accept: text/plain\nAuthorization: Basic Zm9vOmJhcg==\n");
assertPayloadEquals(httpRequest, null, null, false);
// TODO: insert expected response class, which probably extends ParseJson
@ -87,51 +89,6 @@ public class ElasticHostsAsyncClientTest extends RestClientTest<ElasticHostsAsyn
}
public void testListStandardDrives() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticHostsAsyncClient.class.getMethod("listStandardDrives");
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.elastichosts.com/drives/standard/list HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testListStandardCds() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticHostsAsyncClient.class.getMethod("listStandardCds");
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.elastichosts.com/drives/standard/cd/list HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testListStandardImages() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticHostsAsyncClient.class.getMethod("listStandardImages");
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET https://api.elastichosts.com/drives/standard/img/list HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testListDriveInfo() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticHostsAsyncClient.class.getMethod("listDriveInfo");
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method);
@ -183,11 +140,11 @@ public class ElasticHostsAsyncClientTest extends RestClientTest<ElasticHostsAsyn
public void testSetDriveData() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticHostsAsyncClient.class.getMethod("setDriveData", String.class, DriveData.class);
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method, "100",
new DriveData.Builder().name("foo").size(10000l).build());
new DriveData.Builder().name("foo").size(10000l).tags(ImmutableList.of("production", "candy")).build());
assertRequestLineEquals(httpRequest, "POST https://api.elastichosts.com/drives/100/set HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, "name foo\nsize 10000", "text/plain", false);
assertPayloadEquals(httpRequest, "name foo\nsize 10000\ntags production candy", "text/plain", false);
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class);
assertSaxResponseParserClassEquals(method, null);
@ -324,7 +281,8 @@ public class ElasticHostsAsyncClientTest extends RestClientTest<ElasticHostsAsyn
@Override
public RestContextSpec<ElasticHostsClient, ElasticHostsAsyncClient> createContextSpec() {
return contextSpec("elastichosts", "https://api.elastichosts.com", "1.0", "identity", "credential",
ElasticHostsClient.class, ElasticHostsAsyncClient.class);
Properties props = new Properties();
props.setProperty("elastichosts.endpoint", "https://api.elastichosts.com");
return new RestContextFactory().createContextSpec("elastichosts", "foo", "bar", props);
}
}

View File

@ -19,165 +19,57 @@
package org.jclouds.elastichosts;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.rest.RestContextFactory.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContext;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
import org.jclouds.Constants;
import org.jclouds.elastichosts.domain.ClaimType;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.domain.DriveInfo;
import org.jclouds.elastichosts.options.ReadDriveOptions;
import org.jclouds.io.Payloads;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.util.Utils;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Module;
/**
* Tests behavior of {@code ElasticHostsClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "elastichosts.ElasticHostsClientLiveTest")
public class ElasticHostsClientLiveTest {
private ElasticHostsClient client;
private RestContext<ElasticHostsClient, ElasticHostsAsyncClient> context;
protected String provider = "elastichosts";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = System.getProperty("test." + provider + ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion");
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
if (credential != null)
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
context = createContext(
contextSpec(provider, endpoint, "1.0", identity, credential, ElasticHostsClient.class,
ElasticHostsAsyncClient.class, (Class) ElasticHostsPropertiesBuilder.class,
(Class) ElasticHostsContextBuilder.class, ImmutableSet.<Module> of(new Log4JLoggingModule())),
overrides);
client = context.getApi();
}
@AfterGroups(groups = "live")
void tearDown() {
if (context != null)
context.close();
}
@Test
public void testListDrives() throws Exception {
Set<String> drives = client.listDrives();
assertNotNull(drives);
}
@Test
public void testListDriveInfo() throws Exception {
Set<DriveInfo> drives = client.listDriveInfo();
assertNotNull(drives);
}
@Test
public void testListStandardDrives() throws Exception {
Set<String> drives = client.listStandardDrives();
assertNotNull(drives);
}
@Test
public void testListStandardCds() throws Exception {
Set<String> drives = client.listStandardCds();
assertNotNull(drives);
}
@Test
public void testListStandardImages() throws Exception {
Set<String> drives = client.listStandardImages();
assertNotNull(drives);
}
@Test
public void testGetDrive() throws Exception {
for (String driveUUID : client.listDrives()) {
assertNotNull(client.getDriveInfo(driveUUID));
}
for (String driveUUID : client.listStandardDrives()) {
assertNotNull(client.getDriveInfo(driveUUID));
}
}
private String prefix = System.getProperty("user.name") + ".test";
private DriveInfo info;
public class ElasticHostsClientLiveTest extends
CommonElasticHostsClientLiveTest<ElasticHostsClient, ElasticHostsAsyncClient> {
private DriveInfo info2;
@Test
@Override
public void testGetDrive() throws Exception {
super.testGetDrive();
}
@Override
public void testCreate() throws Exception {
try {
findAndDestroyDrive(prefix);
} catch (Exception e) {
super.testCreate();
}
}
info = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(4 * 1024 * 1024l).build());
assertNotNull(info.getUuid());
assertEquals(info.getName(), prefix);
assertEquals(info.getSize(), 4 * 1024 * 1024l);
assertEquals(info, client.getDriveInfo(info.getUuid()));
@Override
public void testSetDriveData() throws Exception {
super.testSetDriveData();
}
@Override
public void testDestroyDrive() throws Exception {
super.testDestroyDrive();
}
@Test(dependsOnMethods = "testCreate")
public void testWeCanReadAndWriteToDrive() throws IOException {
client.writeDrive(info.getUuid(), Payloads.newStringPayload("foo"));
assertEquals(Utils.toStringAndClose(client.readDrive(info.getUuid()).getInput()), "foo");
assertEquals(Utils.toStringAndClose(client.readDrive(info.getUuid(), ReadDriveOptions.Builder.offset(0).size(3))
.getInput()), "foo");
}
@Test(dependsOnMethods = "testWeCanReadAndWriteToDrive")
public void testWeCopyADriveContentsViaGzip() throws IOException {
try {
findAndDestroyDrive(prefix + "2");
} catch (Exception e) {
}
try {
info2 = client.createDrive(new CreateDriveRequest.Builder().name(prefix + "2").size(4 * 1024 * 1024l).build());
client.imageDrive(info.getUuid(), info2.getUuid());
@ -186,46 +78,9 @@ public class ElasticHostsClientLiveTest {
System.err.println("state " + client.getDriveInfo(info2.getUuid()));
assertEquals(Utils.toStringAndClose(client.readDrive(info2.getUuid()).getInput()), "foo");
} finally {
findAndDestroyDrive(prefix + "2");
client.destroyDrive(info2.getUuid());
}
}
@Test(dependsOnMethods = "testCreate")
public void testSetDriveData() throws Exception {
DriveInfo info2 = client.setDriveData(
info.getUuid(),
new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous")
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))
.tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar")).build());
assertNotNull(info2.getUuid(), info.getUuid());
assertEquals(info.getName(), "rediculous");
assertEquals(info.getClaimType(), ClaimType.SHARED);
assertEquals(info.getReaders(), ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"));
assertEquals(info.getTags(), ImmutableSet.of("tag1", "tag2"));
assertEquals(info.getUserMetadata(), ImmutableMap.of("foo", "bar"));
}
@Test(dependsOnMethods = "testSetDriveData")
public void testDestroyDrive() throws Exception {
findAndDestroyDrive(prefix);
assertEquals(client.getDriveInfo(info.getUuid()), null);
}
protected void findAndDestroyDrive(final String prefix) {
DriveInfo drive = Iterables.find(client.listDriveInfo(), new Predicate<DriveInfo>() {
@Override
public boolean apply(DriveInfo input) {
return input.getName().equals(prefix);
}
});
client.destroyDrive(drive.getUuid());
}
}

View File

@ -0,0 +1,47 @@
/**
*
* 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.elastichosts;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*
*/
@Test(groups = "unit")
public class ProvidersInPropertiesTest {
@Test
public void testSupportedProviders() {
Iterable<String> providers = Utils.getSupportedProviders();
assert Iterables.contains(providers, "elastichosts") : providers;
}
//
// @Test
// public void testSupportedComputeServiceProviders() {
// Iterable<String> providers = ComputeServiceUtils.getSupportedProviders();
// assert Iterables.contains(providers, "cloudsigma") : providers;
// }
}

View File

@ -23,18 +23,25 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import javax.ws.rs.core.MediaType;
import org.jclouds.elastichosts.domain.ClaimType;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.functions.CreateDriveRequestToMap;
import org.jclouds.elastichosts.functions.DriveDataToMap;
import org.jclouds.http.HttpRequest;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.TypeLiteral;
/**
*
@ -43,8 +50,17 @@ import com.google.inject.Guice;
@Test(groups = { "unit" })
public class BindCreateDriveRequestToPlainTextStringTest {
private static final BindCreateDriveRequestToPlainTextString FN = Guice.createInjector().getInstance(
BindCreateDriveRequestToPlainTextString.class);
private static final BindCreateDriveRequestToPlainTextString FN = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(new TypeLiteral<Function<CreateDriveRequest, Map<String, String>>>() {
}).to(CreateDriveRequestToMap.class);
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
}).to(DriveDataToMap.class);
}
}).getInstance(BindCreateDriveRequestToPlainTextString.class);
public void testSimple() {
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));

View File

@ -23,18 +23,25 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import javax.ws.rs.core.MediaType;
import org.jclouds.elastichosts.domain.ClaimType;
import org.jclouds.elastichosts.domain.CreateDriveRequest;
import org.jclouds.elastichosts.domain.DriveData;
import org.jclouds.elastichosts.functions.CreateDriveRequestToMap;
import org.jclouds.elastichosts.functions.DriveDataToMap;
import org.jclouds.http.HttpRequest;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.TypeLiteral;
/**
*
@ -43,8 +50,17 @@ import com.google.inject.Guice;
@Test(groups = { "unit" })
public class BindDriveDataToPlainTextStringTest {
private static final BindDriveDataToPlainTextString FN = Guice.createInjector().getInstance(
BindDriveDataToPlainTextString.class);
private static final BindDriveDataToPlainTextString FN = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(new TypeLiteral<Function<CreateDriveRequest, Map<String, String>>>() {
}).to(CreateDriveRequestToMap.class);
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
}).to(DriveDataToMap.class);
}
}).getInstance(BindDriveDataToPlainTextString.class);
public void testSimple() {
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
@ -66,8 +82,7 @@ public class BindDriveDataToPlainTextStringTest {
FN.bindToRequest(request, input);
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
assertEquals(request.getPayload().getRawContent(),
Utils.toStringAndClose(BindDriveDataToPlainTextStringTest.class
.getResourceAsStream("/drive_data.txt")));
Utils.toStringAndClose(BindDriveDataToPlainTextStringTest.class.getResourceAsStream("/drive_data.txt")));
}
}

View File

@ -0,0 +1,50 @@
/**
*
* 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.elastichosts.functions;
import static org.testng.Assert.assertEquals;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
import com.google.inject.Guice;
/**
*
* @author Adrian Cole
*/
@Test(groups = { "unit" })
public class KeyValuesDelimitedByBlankLinesToDriveInfoTest {
private static final KeyValuesDelimitedByBlankLinesToDriveInfo FN = Guice.createInjector().getInstance(
KeyValuesDelimitedByBlankLinesToDriveInfo.class);
public void testNone() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload(""))), null);
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newStringPayload("\n\n"))), null);
assertEquals(FN.apply(new HttpResponse(200, "", null)), null);
}
public void testOne() {
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToDriveInfoTest.class
.getResourceAsStream("/drive.txt")))), MapToDriveInfoTest.ONE);
}
}

View File

@ -22,13 +22,11 @@ package org.jclouds.elastichosts.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import org.jclouds.elastichosts.domain.ClaimType;
import org.jclouds.elastichosts.domain.DriveInfo;
import org.jclouds.elastichosts.domain.DriveStatus;
import org.jclouds.elastichosts.domain.DriveType;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
@ -43,18 +41,11 @@ import com.google.common.collect.ImmutableSet;
public class MapToDriveInfoTest {
public static DriveInfo ONE = new DriveInfo.Builder()
.status(DriveStatus.ACTIVE)
.use(ImmutableSet.of("networking", "security", "gateway"))
.name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
.bits(64)
.url(URI.create("http://www.ubuntu.com"))
.readBytes(4096l)
.user("58ca3c1f-7629-4771-9b71-863f40153ba4")
.encryptionCipher("aes-xts-plain")
.encryptionKey("ba6c2a4897072e9f25920ed73bd522e9c10d89f30a215158cccf8d0f654ac643")
.description("The Ubuntu Linux distribution brings the spirit of Ubuntu to the software world.")
.uuid("b8171d28-755a-4271-b891-7998871a160e")
.installNotes("first line\n\n")
.os("linux")
.writeBytes(8589938688l)
.claimType(ClaimType.SHARED)
.claimed(
@ -64,11 +55,8 @@ public class MapToDriveInfoTest {
"0002c6df-a1d2-4d1d-96f0-f95405a28183:guest:386f1cc7-affc-49c1-82a5-2f8e412170e4:ide:0:0",
"00031836-a624-4b22-bc7d-41ff8977087b:guest:17b076be-430d-4a76-9df3-b9896fec82a5:ide:0:0",
"000663ee-9fb6-4461-90f6-01327a4aff07:guest:f83b519f-feab-42cf-859c-f61495681ada:ide:0:1"))//
.driveType(ImmutableSet.of("installcd", "livecd"))//
.autoexpanding(false).readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
.readRequests(1l)//
.free(true)//
.type(DriveType.DISK)//
.writeRequests(2097153l)//
.size(8589934592l)//
.userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz")).build();

View File

@ -52,6 +52,12 @@ public class ElasticHostsErrorHandlerTest {
IllegalArgumentException.class);
}
@Test
public void test400MakesResourceNotFoundExceptionOnMessageNotFound() {
assertCodeMakes("GET", URI.create("https://elastichosts.com/foo"), 400, "", "errors:system Drive 8f9b42b1-26de-49ad-a3fd-d4fa06524339 could not be found. Please re-validate your entry.",
ResourceNotFoundException.class);
}
@Test
public void test401MakesAuthorizationException() {
assertCodeMakes("GET", URI.create("https://elastichosts.com/foo"), 401, "", "Unauthorized",

View File

@ -0,0 +1,26 @@
status active
use networking,security,gateway
name Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System
bits 64
url http://www.ubuntu.com
read:bytes 4096
user 58ca3c1f-7629-4771-9b71-863f40153ba4
encryption:cipher aes-xts-plain
encryption:key ba6c2a4897072e9f25920ed73bd522e9c10d89f30a215158cccf8d0f654ac643
description The Ubuntu Linux distribution brings the spirit of Ubuntu to the software world.
drive b8171d28-755a-4271-b891-7998871a160e
install_notes first line\n\n
os linux
write:bytes 8589938688
claim:type shared
claimed 00109617-2c6b-424b-9cfa-5b572c17bafe:guest:692cd1c7-a863-4a22-8170-fc6e6feb68af:ide:0:0 00031836-a624-4b22-bc7d-41ff8977087b:guest:a1414360-7c24-4730-8c97-180bf7775a71:ide:0:0 0002c6df-a1d2-4d1d-96f0-f95405a28183:guest:386f1cc7-affc-49c1-82a5-2f8e412170e4:ide:0:0 00031836-a624-4b22-bc7d-41ff8977087b:guest:17b076be-430d-4a76-9df3-b9896fec82a5:ide:0:0 000663ee-9fb6-4461-90f6-01327a4aff07:guest:f83b519f-feab-42cf-859c-f61495681ada:ide:0:1
drive_type installcd,livecd
autoexpanding false
readers ffffffff-ffff-ffff-ffff-ffffffffffff
read:requests 1
free true
type disk
write:requests 2097153
size 8589934592
user:foo bar
user:baz raz

View File

@ -1,25 +1,14 @@
status active
use networking,security,gateway
name Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System
bits 64
url http://www.ubuntu.com
read:bytes 4096
user 58ca3c1f-7629-4771-9b71-863f40153ba4
encryption:cipher aes-xts-plain
encryption:key ba6c2a4897072e9f25920ed73bd522e9c10d89f30a215158cccf8d0f654ac643
description The Ubuntu Linux distribution brings the spirit of Ubuntu to the software world.
drive b8171d28-755a-4271-b891-7998871a160e
install_notes first line\n\n
os linux
write:bytes 8589938688
claim:type shared
claimed 00109617-2c6b-424b-9cfa-5b572c17bafe:guest:692cd1c7-a863-4a22-8170-fc6e6feb68af:ide:0:0 00031836-a624-4b22-bc7d-41ff8977087b:guest:a1414360-7c24-4730-8c97-180bf7775a71:ide:0:0 0002c6df-a1d2-4d1d-96f0-f95405a28183:guest:386f1cc7-affc-49c1-82a5-2f8e412170e4:ide:0:0 00031836-a624-4b22-bc7d-41ff8977087b:guest:17b076be-430d-4a76-9df3-b9896fec82a5:ide:0:0 000663ee-9fb6-4461-90f6-01327a4aff07:guest:f83b519f-feab-42cf-859c-f61495681ada:ide:0:1
drive_type installcd,livecd
autoexpanding false
readers ffffffff-ffff-ffff-ffff-ffffffffffff
read:requests 1
free true
type disk
write:requests 2097153
size 8589934592
user:foo bar

View File

@ -1,3 +1,3 @@
7e8ab721-81c9-4cb9-a651-4cafbfe1501c
ea6a8fdb-dab3-4d06-86c2-41a5835e6ed9
74744450-d338-4087-b3b8-59b505110a57
74744450-d338-4087-b3b8-59b505110a57