mirror of https://github.com/apache/jclouds.git
implemented nearly all drive functions for elastichosts
This commit is contained in:
parent
f7fe6aedc9
commit
6ee0b3548d
|
@ -22,14 +22,20 @@ package org.jclouds.elastichosts;
|
|||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
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.handlers.NewlineDelimitedStringHandler;
|
||||
import org.jclouds.elastichosts.binders.BindCreateDriveRequestToPlainTextString;
|
||||
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
||||
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;
|
||||
|
@ -49,31 +55,55 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
@RequestFilters(BasicAuthentication.class)
|
||||
@Consumes(MediaType.TEXT_PLAIN)
|
||||
public interface ElasticHostsAsyncClient {
|
||||
/*
|
||||
* TODO: define interface methods for ElasticHosts
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see ElasticHostsClient#listDrives()
|
||||
*/
|
||||
@GET
|
||||
@Path("/drives/list")
|
||||
@ResponseParser(NewlineDelimitedStringHandler.class)
|
||||
@ResponseParser(SplitNewlines.class)
|
||||
ListenableFuture<Set<String>> listDrives();
|
||||
|
||||
/**
|
||||
* @see ElasticHostsClient#get(long)
|
||||
* @see ElasticHostsClient#listStandardDrives()
|
||||
*/
|
||||
@GET
|
||||
@Path("/drives/standard/list")
|
||||
@ResponseParser(SplitNewlines.class)
|
||||
ListenableFuture<Set<String>> listStandardDrives();
|
||||
|
||||
/**
|
||||
* @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<String> getDriveInfo(@PathParam("uuid") String uuid);
|
||||
ListenableFuture<DriveInfo> getDriveInfo(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticHostsClient#delete
|
||||
* @see ElasticHostsClient#createDrive
|
||||
*/
|
||||
@DELETE
|
||||
@Path("/drives/{uuid}")
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
@Path("/drives/create")
|
||||
ListenableFuture<DriveInfo> createDrive(
|
||||
@BinderParam(BindCreateDriveRequestToPlainTextString.class) CreateDriveRequest createDrive);
|
||||
|
||||
/**
|
||||
* @see ElasticHostsClient#deleteDrive
|
||||
*/
|
||||
@POST
|
||||
@Path("/drives/{uuid}/destroy")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> deleteDrive(@PathParam("uuid") String uuid);
|
||||
ListenableFuture<Void> destroyDrive(@PathParam("uuid") String uuid);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ 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.DriveInfo;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to ElasticHosts.
|
||||
|
@ -35,17 +37,48 @@ import org.jclouds.concurrent.Timeout;
|
|||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface ElasticHostsClient {
|
||||
/**
|
||||
* list of drive uuids
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
String getDriveInfo(String uuid);
|
||||
|
||||
void deleteDrive(String uuid);
|
||||
DriveInfo getDriveInfo(String uuid);
|
||||
|
||||
/**
|
||||
* create a new drive
|
||||
*
|
||||
* @param createDrive
|
||||
* required parameters: name, size
|
||||
* @return newly created drive
|
||||
*/
|
||||
DriveInfo createDrive(CreateDriveRequest createDrive);
|
||||
|
||||
/**
|
||||
* Destroy a drive
|
||||
*
|
||||
* @param uuid
|
||||
* what to delete
|
||||
*/
|
||||
void destroyDrive(String uuid);
|
||||
|
||||
}
|
||||
|
|
|
@ -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.elastichosts.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
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.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class BindCreateDriveRequestToPlainTextString implements Binder {
|
||||
private final CreateDriveRequestToMap createDriveRequestToMap;
|
||||
private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
|
||||
@Inject
|
||||
public BindCreateDriveRequestToPlainTextString(CreateDriveRequestToMap createDriveRequestToMap,
|
||||
ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) {
|
||||
this.createDriveRequestToMap = createDriveRequestToMap;
|
||||
this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
}
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
checkArgument(payload instanceof CreateDriveRequest, "this binder is only valid for CreateDriveRequest!");
|
||||
CreateDriveRequest create = CreateDriveRequest.class.cast(payload);
|
||||
Map<String, String> map = createDriveRequestToMap.apply(create);
|
||||
request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map)));
|
||||
request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* 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.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* either 'exclusive' (the default) or 'shared' to allow multiple servers to access a drive
|
||||
* simultaneously
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum ClaimType {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
EXCLUSIVE,
|
||||
/**
|
||||
* allow multiple servers to access a drive simultaneously
|
||||
*/
|
||||
SHARED, UNRECOGNIZED;
|
||||
|
||||
public String value() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static ClaimType fromValue(String claim) {
|
||||
try {
|
||||
return valueOf(checkNotNull(claim, "claim").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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.elastichosts.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.elastichosts.domain.internal.BaseDrive;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class CreateDriveRequest extends BaseDrive {
|
||||
public static class Builder extends BaseDrive.Builder {
|
||||
private Set<String> avoid = ImmutableSet.of();
|
||||
|
||||
public Builder avoid(Iterable<String> avoid) {
|
||||
this.avoid = ImmutableSet.copyOf(checkNotNull(avoid, "avoid"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder claimType(ClaimType claimType) {
|
||||
return Builder.class.cast(super.claimType(claimType));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder encryptionCipher(String encryptionCipher) {
|
||||
return Builder.class.cast(super.encryptionCipher(encryptionCipher));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder name(String name) {
|
||||
return Builder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 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 CreateDriveRequest build() {
|
||||
return new CreateDriveRequest(name, size, claimType, readers, tags, userMetadata, encryptionCipher, avoid);
|
||||
}
|
||||
}
|
||||
|
||||
private final Set<String> avoid;
|
||||
|
||||
public CreateDriveRequest(String name, long size, @Nullable ClaimType claimType, Iterable<String> readers,
|
||||
Iterable<String> tags, Map<String, String> userMetadata, @Nullable String encryptionCipher,
|
||||
Iterable<String> avoid) {
|
||||
super(name, size, claimType, readers, tags, userMetadata, encryptionCipher);
|
||||
this.avoid = ImmutableSet.copyOf(checkNotNull(avoid, "avoid"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return list of existing drives to ensure this new drive is created on physical different
|
||||
* hardware than those existing drives
|
||||
*/
|
||||
public Set<String> getAvoid() {
|
||||
return avoid;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,567 @@
|
|||
/**
|
||||
*
|
||||
* 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.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.elastichosts.domain.internal.BaseDrive;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
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 description;
|
||||
private String uuid;
|
||||
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;
|
||||
|
||||
public Builder status(DriveStatus status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder user(String user) {
|
||||
this.user = user;
|
||||
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 uuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
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) {
|
||||
this.readBytes = readBytes;
|
||||
return this;
|
||||
}
|
||||
|
||||
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) {
|
||||
this.writeBytes = writeBytes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder writeRequests(Long writeRequests) {
|
||||
this.writeRequests = writeRequests;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder claimType(ClaimType claimType) {
|
||||
return Builder.class.cast(super.claimType(claimType));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder encryptionCipher(String encryptionCipher) {
|
||||
return Builder.class.cast(super.encryptionCipher(encryptionCipher));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder name(String name) {
|
||||
return Builder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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);
|
||||
}
|
||||
}
|
||||
|
||||
private final DriveStatus status;
|
||||
private final String user;
|
||||
@Nullable
|
||||
private final Boolean autoexpanding;
|
||||
@Nullable
|
||||
private final Integer bits;
|
||||
private final Set<String> claimed;
|
||||
@Nullable
|
||||
private final String description;
|
||||
@Nullable
|
||||
private final String uuid;
|
||||
@Nullable
|
||||
private final Set<String> driveType;
|
||||
@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;
|
||||
|
||||
public DriveInfo(DriveStatus status, String user, Boolean autoexpanding, Integer bits, Iterable<String> claimed,
|
||||
ClaimType claimType, String description, String drive, 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) {
|
||||
super(name, size, claimType, readers, tags, userMetadata, encryptionCipher);
|
||||
this.status = status;
|
||||
this.user = user;
|
||||
this.autoexpanding = autoexpanding;
|
||||
this.bits = bits;
|
||||
this.claimed = ImmutableSet.copyOf(claimed);
|
||||
this.description = description;
|
||||
this.uuid = drive;
|
||||
this.driveType = ImmutableSet.copyOf(driveType);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return current status of the drive
|
||||
*/
|
||||
public DriveStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return owner of the drive
|
||||
*/
|
||||
public String getUser() {
|
||||
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
|
||||
*/
|
||||
public Set<String> getClaimed() {
|
||||
return claimed;
|
||||
}
|
||||
|
||||
// TODO
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return uuid of the drive.
|
||||
*/
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
// TODO
|
||||
public Set<String> getDriveType() {
|
||||
return driveType;
|
||||
}
|
||||
|
||||
// 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
|
||||
* another imaging operation to complete first
|
||||
*/
|
||||
public String getImaging() {
|
||||
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() {
|
||||
return readBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Cumulative i/o byte/request count for each drive
|
||||
*/
|
||||
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() {
|
||||
return writeBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Cumulative i/o byte/request count for each drive
|
||||
*/
|
||||
public Long getWriteRequests() {
|
||||
return writeRequests;
|
||||
}
|
||||
|
||||
@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 + ((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 + ((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 + ((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());
|
||||
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 (claimed == null) {
|
||||
if (other.claimed != null)
|
||||
return false;
|
||||
} else if (!claimed.equals(other.claimed))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != 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))
|
||||
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))
|
||||
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))
|
||||
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))
|
||||
return false;
|
||||
if (writeRequests == null) {
|
||||
if (other.writeRequests != null)
|
||||
return false;
|
||||
} else if (!writeRequests.equals(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 + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
*
|
||||
* 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.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum DriveStatus {
|
||||
ACTIVE, INACTIVE, COPYING, IMAGING, UNRECOGNIZED;
|
||||
|
||||
public String value() {
|
||||
return name().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static DriveStatus fromValue(String status) {
|
||||
try {
|
||||
return valueOf(checkNotNull(status, "status").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
*
|
||||
* 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.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum DriveType {
|
||||
DISK, CDROM, SHARED, UNRECOGNIZED;
|
||||
|
||||
public String value() {
|
||||
return name().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static DriveType fromValue(String type) {
|
||||
try {
|
||||
return valueOf(checkNotNull(type, "type").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,230 @@
|
|||
/**
|
||||
*
|
||||
* 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.domain.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.elastichosts.domain.ClaimType;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.internal.util.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BaseDrive {
|
||||
public static class Builder {
|
||||
protected String name;
|
||||
protected long size;
|
||||
protected ClaimType claimType = ClaimType.EXCLUSIVE;
|
||||
protected Set<String> readers = ImmutableSet.of();
|
||||
protected Set<String> tags = ImmutableSet.of();
|
||||
protected Map<String, String> userMetadata = ImmutableMap.of();
|
||||
@Nullable
|
||||
protected String encryptionCipher;
|
||||
|
||||
public Builder claimType(ClaimType claimType) {
|
||||
this.claimType = claimType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder encryptionCipher(String encryptionCipher) {
|
||||
this.encryptionCipher = encryptionCipher;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder readers(Iterable<String> readers) {
|
||||
this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder size(long size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder tags(Iterable<String> tags) {
|
||||
this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder userMetadata(Map<String, String> userMetadata) {
|
||||
this.userMetadata = ImmutableMap.copyOf(checkNotNull(userMetadata, "userMetadata"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseDrive build() {
|
||||
return new BaseDrive(name, size, claimType, readers, tags, userMetadata, encryptionCipher);
|
||||
}
|
||||
}
|
||||
|
||||
protected final String name;
|
||||
protected final long size;
|
||||
protected final ClaimType claimType;
|
||||
protected final Set<String> readers;
|
||||
protected final Set<String> tags;
|
||||
protected final Map<String, String> userMetadata;
|
||||
@Nullable
|
||||
protected final String encryptionCipher;
|
||||
|
||||
public BaseDrive(String name, long size, @Nullable ClaimType claimType, Iterable<String> readers,
|
||||
Iterable<String> tags, Map<String, String> userMetadata, @Nullable String encryptionCipher) {
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.size = size;
|
||||
this.claimType = checkNotNull(claimType, "set claimType to exclusive, not null");
|
||||
this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
|
||||
this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags"));
|
||||
this.userMetadata = ImmutableMap.copyOf(checkNotNull(userMetadata, "userMetadata"));
|
||||
this.encryptionCipher = encryptionCipher;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return either 'exclusive' (the default) or 'shared' to allow multiple servers to access a
|
||||
* drive simultaneously
|
||||
*/
|
||||
@Nullable
|
||||
public ClaimType getClaimType() {
|
||||
return claimType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return either 'none' or 'aes-xts-plain' (the default)
|
||||
*/
|
||||
@Nullable
|
||||
public String getEncryptionCipher() {
|
||||
return encryptionCipher;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Drive name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return list of users allowed to read from a drive or 'ffffffff-ffff-ffff-ffff-ffffffffffff'
|
||||
* for all users
|
||||
*/
|
||||
public Set<String> getReaders() {
|
||||
return readers;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return size of drive in bytes
|
||||
*/
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return list of tags
|
||||
*/
|
||||
public Set<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return user-defined KEY VALUE pairs
|
||||
*/
|
||||
public Map<String, String> getUserMetadata() {
|
||||
return userMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
|
||||
result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((readers == null) ? 0 : readers.hashCode());
|
||||
result = prime * result + (int) (size ^ (size >>> 32));
|
||||
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
|
||||
result = prime * result + ((userMetadata == null) ? 0 : userMetadata.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
BaseDrive other = (BaseDrive) obj;
|
||||
if (claimType != other.claimType)
|
||||
return false;
|
||||
if (encryptionCipher == null) {
|
||||
if (other.encryptionCipher != null)
|
||||
return false;
|
||||
} else if (!encryptionCipher.equals(other.encryptionCipher))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (readers == null) {
|
||||
if (other.readers != null)
|
||||
return false;
|
||||
} else if (!readers.equals(other.readers))
|
||||
return false;
|
||||
if (size != other.size)
|
||||
return false;
|
||||
if (tags == null) {
|
||||
if (other.tags != null)
|
||||
return false;
|
||||
} else if (!tags.equals(other.tags))
|
||||
return false;
|
||||
if (userMetadata == null) {
|
||||
if (other.userMetadata != null)
|
||||
return false;
|
||||
} else if (!userMetadata.equals(other.userMetadata))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=" + name + ", size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", tags="
|
||||
+ tags + ", userMetadata=" + userMetadata + ", encryptionCipher=" + encryptionCipher + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
*
|
||||
* 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 com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elastichosts.domain.ClaimType;
|
||||
import org.jclouds.elastichosts.domain.internal.BaseDrive;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class BaseDriveToMap implements Function<BaseDrive, Map<String, String>> {
|
||||
@Override
|
||||
public Map<String, String> apply(BaseDrive from) {
|
||||
checkNotNull(from, "drive");
|
||||
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
||||
builder.put("name", from.getName());
|
||||
builder.put("size", from.getSize() + "");
|
||||
if (from.getClaimType() != ClaimType.EXCLUSIVE)
|
||||
builder.put("claim:type", from.getClaimType().toString());
|
||||
if (from.getReaders().size() != 0)
|
||||
builder.put("readers", Joiner.on(' ').join(from.getReaders()));
|
||||
if (from.getTags().size() != 0)
|
||||
builder.put("tags", Joiner.on(' ').join(from.getTags()));
|
||||
for (Entry<String, String> entry : from.getUserMetadata().entrySet())
|
||||
builder.put("user:" + entry.getKey(), entry.getValue());
|
||||
if (from.getEncryptionCipher() != null)
|
||||
builder.put("encryption:cipher", from.getEncryptionCipher());
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
*
|
||||
* 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 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.base.Joiner;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class CreateDriveRequestToMap implements Function<CreateDriveRequest, Map<String, String>> {
|
||||
private final BaseDriveToMap baseDriveToMap;
|
||||
|
||||
@Inject
|
||||
public CreateDriveRequestToMap(BaseDriveToMap baseDriveToMap) {
|
||||
this.baseDriveToMap = baseDriveToMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> apply(CreateDriveRequest from) {
|
||||
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
||||
builder.putAll(baseDriveToMap.apply(from));
|
||||
if (from.getAvoid().size() != 0)
|
||||
builder.put("avoid", Joiner.on(' ').join(from.getAvoid()));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -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.functions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elastichosts.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> {
|
||||
ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet setParser;
|
||||
|
||||
@Override
|
||||
public DriveInfo apply(HttpResponse response) {
|
||||
Set<DriveInfo> drives = setParser.apply(response);
|
||||
if (drives.size() == 0)
|
||||
return null;
|
||||
return Iterables.get(drives, 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
*
|
||||
* 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 java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elastichosts.domain.DriveInfo;
|
||||
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));
|
||||
}
|
||||
}
|
|
@ -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.elastichosts.functions;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ListOfKeyValuesDelimitedByBlankLinesToListOfMaps implements Function<String, List<Map<String, String>>> {
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> apply(String from) {
|
||||
List<Map<String, String>> maps = Lists.newArrayList();
|
||||
for (String listOfKeyValues : Splitter.on("\n\n").split(from)) {
|
||||
if (!"".equals(listOfKeyValues)) {
|
||||
Map<String, String> map = Maps.newLinkedHashMap();
|
||||
for (String keyValueLine : Splitter.on('\n').split(listOfKeyValues)) {
|
||||
if (!"".equals(keyValueLine)) {
|
||||
int firstIndex = keyValueLine.indexOf(' ');
|
||||
String key = keyValueLine.substring(0, firstIndex);
|
||||
String value = keyValueLine.substring(firstIndex + 1).replace("\\n", "\n");
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
if (map.size() != 0)
|
||||
maps.add(map);
|
||||
}
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
}
|
|
@ -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.elastichosts.functions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ListOfMapsToListOfKeyValuesDelimitedByBlankLines implements
|
||||
Function<Iterable<Map<String, String>>, String> {
|
||||
|
||||
@Override
|
||||
public String apply(Iterable<Map<String, String>> from) {
|
||||
return Joiner.on("\n\n").join(Iterables.transform(from, new Function<Map<String, String>, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(Map<String, String> from) {
|
||||
return Joiner.on('\n').withKeyValueSeparator(" ")
|
||||
.join(Maps.transformValues(from, new Function<String, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(String from) {
|
||||
return from.replace("\n", "\\n");
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
*
|
||||
* 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 java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
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;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo> {
|
||||
@Override
|
||||
public DriveInfo apply(Map<String, String> from) {
|
||||
if (from.size() == 0)
|
||||
return null;
|
||||
DriveInfo.Builder builder = new DriveInfo.Builder();
|
||||
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"))
|
||||
builder.writeRequests(new Long(from.get("write:requests")));
|
||||
if (from.containsKey("claim:type"))
|
||||
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();
|
||||
for (Entry<String, String> entry : from.entrySet()) {
|
||||
if (entry.getKey().startsWith("user:"))
|
||||
metadata.put(entry.getKey().substring(entry.getKey().indexOf(':') + 1), entry.getValue());
|
||||
}
|
||||
builder.userMetadata(metadata);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elastichosts.handlers;
|
||||
package org.jclouds.elastichosts.functions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -36,11 +36,11 @@ import com.google.common.collect.Sets;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class NewlineDelimitedStringHandler implements Function<HttpResponse, Set<String>> {
|
||||
public class SplitNewlines implements Function<HttpResponse, Set<String>> {
|
||||
private final ReturnStringIf2xx returnStringIf200;
|
||||
|
||||
@Inject
|
||||
NewlineDelimitedStringHandler(ReturnStringIf2xx returnStringIf200) {
|
||||
SplitNewlines(ReturnStringIf2xx returnStringIf200) {
|
||||
this.returnStringIf200 = returnStringIf200;
|
||||
}
|
||||
|
|
@ -25,11 +25,13 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jclouds.elastichosts.handlers.NewlineDelimitedStringHandler;
|
||||
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
||||
import org.jclouds.elastichosts.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
|
||||
import org.jclouds.elastichosts.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
|
||||
import org.jclouds.elastichosts.functions.SplitNewlines;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
@ -64,11 +66,12 @@ public class ElasticHostsAsyncClientTest extends RestClientTest<ElasticHostsAsyn
|
|||
assertRequestLineEquals(httpRequest, "GET https://api.elastichosts.com/drives/list HTTP/1.1");
|
||||
// for example, using basic authentication, we should get "only one"
|
||||
// header
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// TODO: insert expected response class, which probably extends ParseJson
|
||||
assertResponseParserClassEquals(method, httpRequest, NewlineDelimitedStringHandler.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -76,6 +79,36 @@ 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 testListDriveInfo() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticHostsAsyncClient.class.getMethod("listDriveInfo");
|
||||
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.elastichosts.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 = ElasticHostsAsyncClient.class.getMethod("getDriveInfo", String.class);
|
||||
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method, "uuid");
|
||||
|
@ -84,21 +117,36 @@ public class ElasticHostsAsyncClientTest extends RestClientTest<ElasticHostsAsyn
|
|||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// TODO: insert expected response class, which probably extends ParseJson
|
||||
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf2xx.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
// note that get methods should convert 404's to null
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testDeleteDrive() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticHostsAsyncClient.class.getMethod("deleteDrive", String.class);
|
||||
public void testCreateDrive() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticHostsAsyncClient.class.getMethod("createDrive", CreateDriveRequest.class);
|
||||
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new CreateDriveRequest.Builder().name("foo").size(10000l).build());
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST https://api.elastichosts.com/drives/create HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
||||
assertPayloadEquals(httpRequest, "name foo\nsize 10000", "text/plain", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testDestroyDrive() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ElasticHostsAsyncClient.class.getMethod("destroyDrive", String.class);
|
||||
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method, "uuid");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "DELETE https://api.elastichosts.com/drives/uuid HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "POST https://api.elastichosts.com/drives/uuid/destroy HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
|
|
@ -22,19 +22,24 @@ 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.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
||||
import org.jclouds.elastichosts.domain.DriveInfo;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
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.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
|
@ -45,7 +50,7 @@ import com.google.inject.Module;
|
|||
@Test(groups = "live", testName = "elastichosts.ElasticHostsClientLiveTest")
|
||||
public class ElasticHostsClientLiveTest {
|
||||
|
||||
private ElasticHostsClient connection;
|
||||
private ElasticHostsClient client;
|
||||
private RestContext<ElasticHostsClient, ElasticHostsAsyncClient> context;
|
||||
|
||||
protected String provider = "elastichosts";
|
||||
|
@ -85,7 +90,7 @@ public class ElasticHostsClientLiveTest {
|
|||
(Class) ElasticHostsContextBuilder.class, ImmutableSet.<Module> of(new Log4JLoggingModule())),
|
||||
overrides);
|
||||
|
||||
connection = context.getApi();
|
||||
client = context.getApi();
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
|
@ -96,15 +101,67 @@ public class ElasticHostsClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testListDrives() throws Exception {
|
||||
Set<String> drives = connection.listDrives();
|
||||
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 testGetDrive() throws Exception {
|
||||
Set<String> drives = connection.listDrives();
|
||||
for (String driveUUID : drives) {
|
||||
assertNotNull(connection.getDriveInfo(driveUUID));
|
||||
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";
|
||||
|
||||
@Test
|
||||
public void testCreateDestroy() throws Exception {
|
||||
try {
|
||||
findAndDestroyDrive();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
String uuid = null;
|
||||
try {
|
||||
|
||||
DriveInfo info = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(1024 * 1024l).build());
|
||||
assertNotNull(uuid = info.getUuid());
|
||||
assertEquals(info.getName(), prefix);
|
||||
assertEquals(info.getSize(), 1024 * 1024l);
|
||||
assertEquals(info, client.getDriveInfo(info.getUuid()));
|
||||
} finally {
|
||||
findAndDestroyDrive();
|
||||
}
|
||||
if (uuid != null)
|
||||
assertEquals(client.getDriveInfo(uuid), null);
|
||||
|
||||
}
|
||||
|
||||
protected void findAndDestroyDrive() {
|
||||
DriveInfo drive = Iterables.find(client.listDriveInfo(), new Predicate<DriveInfo>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(DriveInfo input) {
|
||||
return input.getName().equals(prefix);
|
||||
}
|
||||
|
||||
});
|
||||
client.destroyDrive(drive.getUuid());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
*
|
||||
* 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.binders;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.elastichosts.domain.ClaimType;
|
||||
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class BindCreateDriveRequestToPlainTextStringTest {
|
||||
|
||||
private static final BindCreateDriveRequestToPlainTextString FN = Guice.createInjector().getInstance(
|
||||
BindCreateDriveRequestToPlainTextString.class);
|
||||
|
||||
public void testSimple() {
|
||||
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
|
||||
FN.bindToRequest(request, new CreateDriveRequest.Builder().name("foo").size(100l).build());
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
|
||||
assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100");
|
||||
}
|
||||
|
||||
public void testComplete() throws IOException {
|
||||
CreateDriveRequest input = new CreateDriveRequest.Builder()
|
||||
.name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||
//
|
||||
.size(8589934592l)//
|
||||
.claimType(ClaimType.SHARED)//
|
||||
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
|
||||
.tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz"))//
|
||||
.encryptionCipher("aes-xts-plain").avoid(ImmutableSet.of("avoid1")).build();
|
||||
|
||||
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
|
||||
FN.bindToRequest(request, input);
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
|
||||
assertEquals(request.getPayload().getRawContent(),
|
||||
Utils.toStringAndClose(BindCreateDriveRequestToPlainTextStringTest.class
|
||||
.getResourceAsStream("/create_drive.txt")));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elastichosts.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.elastichosts.domain.ClaimType;
|
||||
import org.jclouds.elastichosts.domain.internal.BaseDrive;
|
||||
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 BaseDriveToMapTest {
|
||||
|
||||
private static final BaseDriveToMap BASEDRIVE_TO_MAP = new BaseDriveToMap();
|
||||
|
||||
public void testBasics() {
|
||||
assertEquals(BASEDRIVE_TO_MAP.apply(new BaseDrive.Builder().name("foo").size(100l).build()),
|
||||
ImmutableMap.of("name", "foo", "size", "100"));
|
||||
}
|
||||
|
||||
public void testComplete() throws IOException {
|
||||
BaseDrive one = new BaseDrive.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||
//
|
||||
.size(8589934592l)//
|
||||
.claimType(ClaimType.SHARED)//
|
||||
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
|
||||
.tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz"))//
|
||||
.encryptionCipher("aes-xts-plain").build();
|
||||
assertEquals(
|
||||
BASEDRIVE_TO_MAP.apply(one),
|
||||
ImmutableMap.builder().put("name", "Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||
.put("size", "8589934592").put("claim:type", "shared")
|
||||
.put("readers", "ffffffff-ffff-ffff-ffff-ffffffffffff").put("tags", "tag1 tag2")
|
||||
.put("user:foo", "bar").put("user:baz", "raz").put("encryption:cipher", "aes-xts-plain").build()
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
*
|
||||
* 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 java.io.IOException;
|
||||
|
||||
import org.jclouds.elastichosts.domain.ClaimType;
|
||||
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class CreateDriveRequestToMapTest {
|
||||
|
||||
private static final CreateDriveRequestToMap BASEDRIVE_TO_MAP = Guice.createInjector().getInstance(
|
||||
CreateDriveRequestToMap.class);
|
||||
|
||||
public void testBasics() {
|
||||
assertEquals(BASEDRIVE_TO_MAP.apply(new CreateDriveRequest.Builder().name("foo").size(100l).build()),
|
||||
ImmutableMap.of("name", "foo", "size", "100"));
|
||||
}
|
||||
|
||||
public void testComplete() throws IOException {
|
||||
CreateDriveRequest one = new CreateDriveRequest.Builder()
|
||||
.name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||
//
|
||||
.size(8589934592l)//
|
||||
.claimType(ClaimType.SHARED)//
|
||||
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
|
||||
.tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz"))//
|
||||
.encryptionCipher("aes-xts-plain").avoid(ImmutableSet.of("avoid1")).build();
|
||||
assertEquals(
|
||||
BASEDRIVE_TO_MAP.apply(one),
|
||||
ImmutableMap.builder().put("name", "Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||
.put("size", "8589934592").put("claim:type", "shared")
|
||||
.put("readers", "ffffffff-ffff-ffff-ffff-ffffffffffff").put("tags", "tag1 tag2")
|
||||
.put("user:foo", "bar").put("user:baz", "raz").put("encryption:cipher", "aes-xts-plain")
|
||||
.put("avoid", "avoid1").build()
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
}
|
|
@ -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.elastichosts.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.elastichosts.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("/drive.txt")))), ImmutableSet.<DriveInfo> of(MapToDriveInfoTest.ONE));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elastichosts.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class ListOfKeyValuesDelimitedByBlankLinesToListOfMapsTest {
|
||||
|
||||
private static final ListOfKeyValuesDelimitedByBlankLinesToListOfMaps FN = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps();
|
||||
|
||||
public void testNone() {
|
||||
assertEquals(FN.apply(""), Lists.newArrayList());
|
||||
assertEquals(FN.apply("\n\n\n"), Lists.newArrayList());
|
||||
}
|
||||
|
||||
public void testOneMap() {
|
||||
assertEquals(FN.apply("key1 value1\nkey2 value2"),
|
||||
ImmutableList.of(ImmutableMap.of("key1", "value1", "key2", "value2")));
|
||||
assertEquals(FN.apply("key1 value1\nkey2 value2\n\n"),
|
||||
ImmutableList.of(ImmutableMap.of("key1", "value1", "key2", "value2")));
|
||||
}
|
||||
|
||||
public void testValueEncodesNewlines() {
|
||||
assertEquals(FN.apply("key1 value1\\n\nkey2 value2"),
|
||||
ImmutableList.of(ImmutableMap.of("key1", "value1\n", "key2", "value2")));
|
||||
}
|
||||
|
||||
public void testTwoMaps() {
|
||||
assertEquals(
|
||||
FN.apply("key1 value1\nkey2 value2\n\nkey1 v1\nkey2 v2"),
|
||||
ImmutableList.of(ImmutableMap.of("key1", "value1", "key2", "value2"),
|
||||
ImmutableMap.of("key1", "v1", "key2", "v2")));
|
||||
assertEquals(
|
||||
FN.apply("key1 value1\nkey2 value2\n\nkey1 v1\nkey2 v2\n\n"),
|
||||
ImmutableList.of(ImmutableMap.of("key1", "value1", "key2", "value2"),
|
||||
ImmutableMap.of("key1", "v1", "key2", "v2")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
*
|
||||
* 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 java.util.Map;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class ListOfMapsToListOfKeyValuesDelimitedByBlankLinesTest {
|
||||
|
||||
private static final ListOfMapsToListOfKeyValuesDelimitedByBlankLines FN = new ListOfMapsToListOfKeyValuesDelimitedByBlankLines();
|
||||
|
||||
public void testNone() {
|
||||
assertEquals(FN.apply(ImmutableList.<Map<String, String>> of()), "");
|
||||
}
|
||||
|
||||
public void testOneMap() {
|
||||
assertEquals(
|
||||
FN.apply(ImmutableList.<Map<String, String>> of(ImmutableMap.of("key1", "value1", "key2", "value2"))),
|
||||
"key1 value1\nkey2 value2");
|
||||
}
|
||||
|
||||
public void testValueEncodesNewlines() {
|
||||
assertEquals(
|
||||
FN.apply(ImmutableList.<Map<String, String>> of(ImmutableMap.of("key1", "value1\n", "key2", "value2"))),
|
||||
"key1 value1\\n\nkey2 value2");
|
||||
}
|
||||
|
||||
public void testTwoMaps() {
|
||||
assertEquals(FN.apply(ImmutableList.<Map<String, String>> of(ImmutableMap.of("key1", "value1", "key2", "value2"),
|
||||
ImmutableMap.of("key1", "v1", "key2", "v2"))), "key1 value1\nkey2 value2\n\nkey1 v1\nkey2 v2");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
*
|
||||
* 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 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;
|
||||
|
||||
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)
|
||||
.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(
|
||||
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();
|
||||
|
||||
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("/drive.txt"))).get(0);
|
||||
|
||||
assertEquals(MAP_TO_DRIVE.apply(input), ONE);
|
||||
|
||||
}
|
||||
}
|
|
@ -17,14 +17,14 @@
|
|||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.elastichosts;
|
||||
package org.jclouds.elastichosts.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.elastichosts.handlers.NewlineDelimitedStringHandler;
|
||||
import org.jclouds.elastichosts.functions.SplitNewlines;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -39,14 +39,14 @@ import com.google.inject.Guice;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class NewlineDelimitedStringHandlerTest {
|
||||
public class SplitNewlinesTest {
|
||||
|
||||
static Function<HttpResponse, Set<String>> createParser() {
|
||||
return Guice.createInjector().getInstance(NewlineDelimitedStringHandler.class);
|
||||
return Guice.createInjector().getInstance(SplitNewlines.class);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
InputStream is = NewlineDelimitedStringHandlerTest.class.getResourceAsStream("/uuids.txt");
|
||||
InputStream is = SplitNewlinesTest.class.getResourceAsStream("/uuids.txt");
|
||||
Set<String> list = createParser().apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
||||
assertEquals(list, ImmutableSortedSet.of("7e8ab721-81c9-4cb9-a651-4cafbfe1501c",
|
||||
"ea6a8fdb-dab3-4d06-86c2-41a5835e6ed9", "74744450-d338-4087-b3b8-59b505110a57"));
|
|
@ -0,0 +1,9 @@
|
|||
name Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System
|
||||
size 8589934592
|
||||
claim:type shared
|
||||
readers ffffffff-ffff-ffff-ffff-ffffffffffff
|
||||
tags tag1 tag2
|
||||
user:foo bar
|
||||
user:baz raz
|
||||
encryption:cipher aes-xts-plain
|
||||
avoid avoid1
|
|
@ -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
|
|
@ -92,14 +92,14 @@
|
|||
<category name="jclouds.headers">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category><!--
|
||||
</category>
|
||||
|
||||
<category name="jclouds.wire">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
--><!-- ======================= -->
|
||||
<!-- ======================= -->
|
||||
<!-- Setup the Root category -->
|
||||
<!-- ======================= -->
|
||||
|
||||
|
|
Loading…
Reference in New Issue