split drive and server metrics for elastichosts/cloudsigma into separate objects

This commit is contained in:
Adrian Cole 2010-12-06 22:07:45 +00:00
parent 84b76c0606
commit 550cef78fa
33 changed files with 308 additions and 937 deletions

View File

@ -33,9 +33,9 @@ import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInf
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
import org.jclouds.elasticstack.CommonElasticStackAsyncClient;
import org.jclouds.elasticstack.ElasticStackClient;
import org.jclouds.elasticstack.binders.BindCreateDriveRequestToPlainTextString;
import org.jclouds.elasticstack.binders.BindDriveDataToPlainTextString;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.binders.BindDriveToPlainTextString;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.DriveData;
import org.jclouds.elasticstack.functions.SplitNewlines;
import org.jclouds.http.filters.BasicAuthentication;
@ -110,8 +110,7 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/create")
ListenableFuture<? extends DriveInfo> createDrive(
@BinderParam(BindCreateDriveRequestToPlainTextString.class) CreateDriveRequest createDrive);
ListenableFuture<? extends DriveInfo> createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive);
/**
* @see ElasticStackClient#setDriveData

View File

@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.concurrent.Timeout;
import org.jclouds.elasticstack.CommonElasticStackClient;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.DriveData;
/**
@ -76,7 +76,7 @@ public interface CloudSigmaClient extends CommonElasticStackClient {
* {@inheritDoc}
*/
@Override
DriveInfo createDrive(CreateDriveRequest createDrive);
DriveInfo createDrive(Drive createDrive);
/**
* {@inheritDoc}

View File

@ -21,18 +21,22 @@ package org.jclouds.cloudsigma.config;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jclouds.cloudsigma.CloudSigmaAsyncClient;
import org.jclouds.cloudsigma.CloudSigmaClient;
import org.jclouds.cloudsigma.functions.CreateDriveRequestToMap;
import org.jclouds.cloudsigma.functions.DriveDataToMap;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.domain.Device;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.DriveData;
import org.jclouds.elasticstack.domain.DriveMetrics;
import org.jclouds.elasticstack.domain.NIC;
import org.jclouds.elasticstack.domain.ServerMetrics;
import org.jclouds.elasticstack.functions.MapToDevices;
import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId;
import org.jclouds.elasticstack.functions.MapToDriveMetrics;
import org.jclouds.elasticstack.functions.MapToNICs;
import org.jclouds.elasticstack.functions.MapToServerMetrics;
import org.jclouds.elasticstack.handlers.ElasticStackErrorHandler;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.RequiresHttp;
@ -68,14 +72,20 @@ public class CloudSigmaRestClientModule extends RestClientModule<CloudSigmaClien
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<CreateDriveRequest, Map<String, String>>>() {
bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
}).to(CreateDriveRequestToMap.class);
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
}).to(DriveDataToMap.class);
bind(new TypeLiteral<Function<Map<String, String>, List<NIC>>>() {
}).to(MapToNICs.class);
bind(new TypeLiteral<Function<Map<String, String>, Set<Device>>>() {
bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends Device>>>() {
}).to(MapToDevices.class);
bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends DriveMetrics>>>() {
}).to(MapToDriveMetrics.class);
bind(new TypeLiteral<Function<Map<String, String>, ServerMetrics>>() {
}).to(MapToServerMetrics.class);
bind(new TypeLiteral<Function<Device, String>>() {
}).to(DeviceToId.class);
}
@Override

View File

@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Set;
import org.jclouds.elasticstack.domain.ClaimType;
import org.jclouds.elasticstack.domain.DriveMetrics;
import org.jclouds.elasticstack.domain.DriveStatus;
import com.google.common.collect.ImmutableSet;
@ -133,32 +134,9 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
* {@inheritDoc}
*/
@Override
public Builder readBytes(long readBytes) {
return Builder.class.cast(super.readBytes(readBytes));
}
public Builder metrics(DriveMetrics metrics) {
return Builder.class.cast(super.metrics(metrics));
/**
* {@inheritDoc}
*/
@Override
public Builder readRequests(long readRequests) {
return Builder.class.cast(super.readRequests(readRequests));
}
/**
* {@inheritDoc}
*/
@Override
public Builder writeBytes(long writeBytes) {
return Builder.class.cast(super.writeBytes(writeBytes));
}
/**
* {@inheritDoc}
*/
@Override
public Builder writeRequests(long writeRequests) {
return Builder.class.cast(super.writeRequests(writeRequests));
}
/**
@ -230,9 +208,7 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
.claimType(driveInfo.getClaimType()).readers(driveInfo.getReaders()).tags(driveInfo.getTags())
.userMetadata(driveInfo.getUserMetadata()).status(driveInfo.getStatus()).user(driveInfo.getUser())
.claimed(driveInfo.getClaimed()).encryptionCipher(driveInfo.getEncryptionCipher())
.imaging(driveInfo.getImaging()).readBytes(driveInfo.getReadBytes())
.readRequests(driveInfo.getReadRequests()).writeBytes(driveInfo.getWriteBytes())
.writeRequests(driveInfo.getWriteRequests());
.imaging(driveInfo.getImaging()).metrics(driveInfo.getMetrics());
}
/**
@ -241,8 +217,8 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
@Override
public DriveInfo build() {
return new DriveInfo(uuid, name, size, claimType, readers, tags, userMetadata, status, user, claimed,
encryptionCipher, imaging, readBytes, readRequests, writeBytes, writeRequests, autoexpanding, bits,
description, driveType, encryptionKey, free, installNotes, os, type, url);
encryptionCipher, imaging, metrics, autoexpanding, bits, description, driveType, encryptionKey, free,
installNotes, os, type, url);
}
}
@ -259,11 +235,11 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
public DriveInfo(String uuid, String name, long size, ClaimType claimType, Iterable<String> readers,
Iterable<String> tags, Map<String, String> userMetadata, DriveStatus status, String user, Set<String> claimed,
String encryptionCipher, String imaging, long readBytes, long readRequests, long writeBytes,
long writeRequests, Boolean autoexpanding, Integer bits, String description, Iterable<String> driveType,
String encryptionKey, Boolean free, String installNotes, String os, DriveType type, URI url) {
String encryptionCipher, String imaging, DriveMetrics metrics, Boolean autoexpanding, Integer bits,
String description, Iterable<String> driveType, String encryptionKey, Boolean free, String installNotes,
String os, DriveType type, URI url) {
super(uuid, name, size, claimType, readers, tags, userMetadata, status, user, claimed, encryptionCipher, imaging,
readBytes, readRequests, writeBytes, writeRequests);
metrics);
this.autoexpanding = autoexpanding;
this.bits = bits;
this.description = description;

View File

@ -26,7 +26,7 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.domain.Drive;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
@ -36,7 +36,7 @@ import com.google.common.collect.Maps;
* @author Adrian Cole
*/
@Singleton
public class CreateDriveRequestToMap implements Function<CreateDriveRequest, Map<String, String>> {
public class CreateDriveRequestToMap implements Function<Drive, Map<String, String>> {
private final org.jclouds.elasticstack.functions.CreateDriveRequestToMap baseDriveToMap;
@Inject
@ -45,7 +45,7 @@ public class CreateDriveRequestToMap implements Function<CreateDriveRequest, Map
}
@Override
public Map<String, String> apply(CreateDriveRequest from) {
public Map<String, String> apply(Drive from) {
return Maps.transformEntries(renameKey(baseDriveToMap.apply(from), "tags", "use"),
new Maps.EntryTransformer<String, String, String>() {

View File

@ -28,6 +28,7 @@ import java.util.Properties;
import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.DriveData;
import org.jclouds.elasticstack.functions.SplitNewlines;
import org.jclouds.http.HttpRequest;
@ -128,7 +129,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
}
public void testCreateDrive() throws SecurityException, NoSuchMethodException, IOException {
Method method = CloudSigmaAsyncClient.class.getMethod("createDrive", CreateDriveRequest.class);
Method method = CloudSigmaAsyncClient.class.getMethod("createDrive", Drive.class);
GeneratedHttpRequest<CloudSigmaAsyncClient> httpRequest = processor.createRequest(method,
new CreateDriveRequest.Builder().name("foo").tags(ImmutableList.of("production", "candy")).size(10000l).build());

View File

@ -28,6 +28,7 @@ import java.util.Map;
import org.jclouds.cloudsigma.domain.DriveInfo;
import org.jclouds.cloudsigma.domain.DriveType;
import org.jclouds.elasticstack.domain.ClaimType;
import org.jclouds.elasticstack.domain.DriveMetrics;
import org.jclouds.elasticstack.domain.DriveStatus;
import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps;
import org.jclouds.util.Utils;
@ -48,7 +49,9 @@ public class MapToDriveInfoTest {
.name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
.bits(64)
.url(URI.create("http://www.ubuntu.com"))
.readBytes(4096l)
.metrics(
new DriveMetrics.Builder().readBytes(4096l).writeBytes(8589938688l).readRequests(1l)
.writeRequests(2097153l).build())
.user("58ca3c1f-7629-4771-9b71-863f40153ba4")
.encryptionCipher("aes-xts-plain")
.encryptionKey("ba6c2a4897072e9f25920ed73bd522e9c10d89f30a215158cccf8d0f654ac643")
@ -56,7 +59,6 @@ public class MapToDriveInfoTest {
.uuid("b8171d28-755a-4271-b891-7998871a160e")
.installNotes("first line\n\n")
.os("linux")
.writeBytes(8589938688l)
.claimType(ClaimType.SHARED)
.claimed(
ImmutableSet.of(
@ -67,10 +69,8 @@ public class MapToDriveInfoTest {
"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();
@ -82,7 +82,8 @@ public class MapToDriveInfoTest {
}
public void testBasics() {
DriveInfo expects = new DriveInfo.Builder().name("foo").size(100l).build();
DriveInfo expects = new DriveInfo.Builder().name("foo").size(100l).metrics(new DriveMetrics.Builder().build())
.build();
assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.of("name", "foo", "size", "100")), expects);
}

View File

@ -28,9 +28,9 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.elasticstack.binders.BindCreateDriveRequestToPlainTextString;
import org.jclouds.elasticstack.binders.BindDriveDataToPlainTextString;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.binders.BindDriveToPlainTextString;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.DriveData;
import org.jclouds.elasticstack.domain.DriveInfo;
import org.jclouds.elasticstack.domain.ServerInfo;
@ -119,7 +119,7 @@ public interface CommonElasticStackAsyncClient {
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/create")
ListenableFuture<? extends DriveInfo> createDrive(
@BinderParam(BindCreateDriveRequestToPlainTextString.class) CreateDriveRequest createDrive);
@BinderParam(BindDriveToPlainTextString.class) Drive createDrive);
/**
* @see ElasticStackClient#setDriveData
@ -129,7 +129,7 @@ public interface CommonElasticStackAsyncClient {
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
@Path("/drives/{uuid}/set")
ListenableFuture<? extends DriveInfo> setDriveData(@PathParam("uuid") String uuid,
@BinderParam(BindDriveDataToPlainTextString.class) DriveData createDrive);
@BinderParam(BindDriveDataToPlainTextString.class) DriveData setDrive);
/**
* @see ElasticStackClient#destroyDrive

View File

@ -23,7 +23,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.DriveData;
import org.jclouds.elasticstack.domain.DriveInfo;
import org.jclouds.elasticstack.domain.ServerInfo;
@ -87,7 +87,7 @@ public interface CommonElasticStackClient {
* required parameters: name, size
* @return newly created drive
*/
DriveInfo createDrive(CreateDriveRequest createDrive);
DriveInfo createDrive(Drive createDrive);
/**
* set extra drive data

View File

@ -1,61 +0,0 @@
/**
*
* 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.elasticstack.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.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
@Singleton
public class BindCreateDriveRequestToPlainTextString implements Binder {
private final Function<CreateDriveRequest, Map<String, String>> createDriveRequestToMap;
private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines;
@Inject
public BindCreateDriveRequestToPlainTextString(Function<CreateDriveRequest, Map<String, String>> 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);
}
}

View File

@ -21,18 +21,22 @@ package org.jclouds.elasticstack.config;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jclouds.elasticstack.ElasticStackAsyncClient;
import org.jclouds.elasticstack.ElasticStackClient;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.domain.Device;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.DriveData;
import org.jclouds.elasticstack.domain.DriveMetrics;
import org.jclouds.elasticstack.domain.NIC;
import org.jclouds.elasticstack.domain.ServerMetrics;
import org.jclouds.elasticstack.functions.CreateDriveRequestToMap;
import org.jclouds.elasticstack.functions.DriveDataToMap;
import org.jclouds.elasticstack.functions.MapToDevices;
import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId;
import org.jclouds.elasticstack.functions.MapToDriveMetrics;
import org.jclouds.elasticstack.functions.MapToNICs;
import org.jclouds.elasticstack.functions.MapToServerMetrics;
import org.jclouds.elasticstack.handlers.ElasticStackErrorHandler;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.RequiresHttp;
@ -61,14 +65,20 @@ public class ElasticStackRestClientModule extends RestClientModule<ElasticStackC
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<CreateDriveRequest, Map<String, String>>>() {
bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
}).to(CreateDriveRequestToMap.class);
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
}).to(DriveDataToMap.class);
bind(new TypeLiteral<Function<Map<String, String>, List<NIC>>>() {
}).to(MapToNICs.class);
bind(new TypeLiteral<Function<Map<String, String>, Set<Device>>>() {
bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends Device>>>() {
}).to(MapToDevices.class);
bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends DriveMetrics>>>() {
}).to(MapToDriveMetrics.class);
bind(new TypeLiteral<Function<Map<String, String>, ServerMetrics>>() {
}).to(MapToServerMetrics.class);
bind(new TypeLiteral<Function<Device, String>>() {
}).to(DeviceToId.class);
}
@Override

View File

@ -35,16 +35,15 @@ public class BlockDevice extends Device {
@Override
public Device build() {
return new BlockDevice(uuid, mediaType, index, readBytes, readRequests, writeBytes, writeRequests);
return new BlockDevice(uuid, mediaType, index);
}
}
private final int index;
public BlockDevice(String driveUuid, MediaType mediaType, int index, long readBytes, long readRequests,
long writeBytes, long writeRequests) {
super(driveUuid, mediaType, readBytes, readRequests, writeBytes, writeRequests);
public BlockDevice(String driveUuid, MediaType mediaType, int index) {
super(driveUuid, mediaType);
checkArgument(index >= 0 && index < 8, "index must be between 0 and 7");
this.index = index;
}

View File

@ -26,7 +26,6 @@ import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.elasticstack.domain.internal.BaseDrive;
import com.google.common.collect.ImmutableSet;
@ -34,8 +33,8 @@ import com.google.common.collect.ImmutableSet;
*
* @author Adrian Cole
*/
public class CreateDriveRequest extends BaseDrive {
public static class Builder extends BaseDrive.Builder {
public class CreateDriveRequest extends Drive {
public static class Builder extends Drive.Builder {
private Set<String> avoid = ImmutableSet.of();

View File

@ -29,36 +29,12 @@ public abstract class Device {
public static abstract class Builder {
protected String uuid;
protected MediaType mediaType = MediaType.DISK;
protected long readBytes;
protected long readRequests;
protected long writeBytes;
protected long writeRequests;
public Builder mediaType(MediaType mediaType) {
this.mediaType = mediaType;
return this;
}
public Builder readBytes(long readBytes) {
this.readBytes = readBytes;
return this;
}
public Builder readRequests(long readRequests) {
this.readRequests = readRequests;
return this;
}
public Builder writeBytes(long writeBytes) {
this.writeBytes = writeBytes;
return this;
}
public Builder writeRequests(long writeRequests) {
this.writeRequests = writeRequests;
return this;
}
public Builder uuid(String uuid) {
this.uuid = uuid;
return this;
@ -69,19 +45,10 @@ public abstract class Device {
protected final String driveUuid;
protected final MediaType mediaType;
protected final long readBytes;
protected final long readRequests;
protected final long writeBytes;
protected final long writeRequests;
public Device(String driveUuid, MediaType mediaType, long readBytes, long readRequests, long writeBytes,
long writeRequests) {
public Device(String driveUuid, MediaType mediaType) {
this.driveUuid = checkNotNull(driveUuid, "driveUuid");
this.mediaType = checkNotNull(mediaType, "mediaType");
this.readBytes = readBytes;
this.readRequests = readRequests;
this.writeBytes = writeBytes;
this.writeRequests = writeRequests;
}
/**
@ -106,48 +73,12 @@ public abstract class Device {
return mediaType;
}
/**
*
* @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;
}
/**
*
* @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 = 1;
result = prime * result + ((driveUuid == null) ? 0 : driveUuid.hashCode());
result = prime * result + ((mediaType == null) ? 0 : mediaType.hashCode());
result = prime * result + (int) (readBytes ^ (readBytes >>> 32));
result = prime * result + (int) (readRequests ^ (readRequests >>> 32));
result = prime * result + (int) (writeBytes ^ (writeBytes >>> 32));
result = prime * result + (int) (writeRequests ^ (writeRequests >>> 32));
return result;
}
@ -167,20 +98,11 @@ public abstract class Device {
return false;
if (mediaType != other.mediaType)
return false;
if (readBytes != other.readBytes)
return false;
if (readRequests != other.readRequests)
return false;
if (writeBytes != other.writeBytes)
return false;
if (writeRequests != other.writeRequests)
return false;
return true;
}
@Override
public String toString() {
return "[driveUuid=" + driveUuid + ", mediaType=" + mediaType + ", readBytes=" + readBytes + ", readRequests="
+ readRequests + ", writeBytes=" + writeBytes + ", writeRequests=" + writeRequests + "]";
return "[driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]";
}
}

View File

@ -23,14 +23,13 @@ import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.elasticstack.domain.internal.BaseDrive;
/**
*
* @author Adrian Cole
*/
public class DriveData extends BaseDrive {
public static class Builder extends BaseDrive.Builder {
public class DriveData extends Drive {
public static class Builder extends Drive.Builder {
/**
* {@inheritDoc}

View File

@ -26,7 +26,6 @@ import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.elasticstack.domain.internal.BaseDrive;
import com.google.common.collect.ImmutableSet;
@ -34,8 +33,8 @@ import com.google.common.collect.ImmutableSet;
*
* @author Adrian Cole
*/
public class DriveInfo extends BaseDrive {
public static class Builder extends BaseDrive.Builder {
public class DriveInfo extends Drive {
public static class Builder extends Drive.Builder {
protected DriveStatus status;
protected String user;
@ -44,10 +43,7 @@ public class DriveInfo extends BaseDrive {
protected String encryptionCipher;
@Nullable
protected String imaging;
protected long readBytes;
protected long readRequests;
protected long writeBytes;
protected long writeRequests;
protected DriveMetrics metrics;
public Builder status(DriveStatus status) {
this.status = status;
@ -69,23 +65,8 @@ public class DriveInfo extends BaseDrive {
return this;
}
public Builder readBytes(long readBytes) {
this.readBytes = readBytes;
return this;
}
public Builder readRequests(long readRequests) {
this.readRequests = readRequests;
return this;
}
public Builder writeBytes(long writeBytes) {
this.writeBytes = writeBytes;
return this;
}
public Builder writeRequests(long writeRequests) {
this.writeRequests = writeRequests;
public Builder metrics(DriveMetrics metrics) {
this.metrics = metrics;
return this;
}
@ -155,9 +136,7 @@ public class DriveInfo extends BaseDrive {
.claimType(driveInfo.getClaimType()).readers(driveInfo.getReaders()).tags(driveInfo.getTags())
.userMetadata(driveInfo.getUserMetadata()).status(driveInfo.getStatus()).user(driveInfo.getUser())
.claimed(driveInfo.getClaimed()).encryptionCipher(driveInfo.getEncryptionCipher())
.imaging(driveInfo.getImaging()).readBytes(driveInfo.getReadBytes())
.readRequests(driveInfo.getReadRequests()).writeBytes(driveInfo.getWriteBytes())
.writeRequests(driveInfo.getWriteRequests());
.imaging(driveInfo.getImaging()).metrics(driveInfo.getMetrics());
}
/**
@ -166,7 +145,7 @@ public class DriveInfo extends BaseDrive {
@Override
public DriveInfo build() {
return new DriveInfo(uuid, name, size, claimType, readers, tags, userMetadata, status, user, claimed,
encryptionCipher, imaging, readBytes, readRequests, writeBytes, writeRequests);
encryptionCipher, imaging, metrics);
}
}
@ -178,24 +157,18 @@ public class DriveInfo extends BaseDrive {
protected final String encryptionCipher;
@Nullable
protected final String imaging;
protected final long readBytes;
protected final long readRequests;
protected final long writeBytes;
protected final long writeRequests;
protected final DriveMetrics metrics;
public DriveInfo(String uuid, String name, long size, ClaimType claimType, Iterable<String> readers,
Iterable<String> tags, Map<String, String> userMetadata, DriveStatus status, String user, Set<String> claimed,
String encryptionCipher, String imaging, long readBytes, long readRequests, long writeBytes, long writeRequests) {
String encryptionCipher, String imaging, DriveMetrics metrics) {
super(uuid, name, size, claimType, readers, tags, userMetadata);
this.status = status;
this.user = user;
this.claimed = ImmutableSet.copyOf(claimed);
this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed"));
this.encryptionCipher = encryptionCipher;
this.imaging = imaging;
this.readBytes = readBytes;
this.readRequests = readRequests;
this.writeBytes = writeBytes;
this.writeRequests = writeRequests;
this.metrics = checkNotNull(metrics, "metrics");
}
/**
@ -242,34 +215,10 @@ public class DriveInfo extends BaseDrive {
/**
*
* @return Cumulative i/o byte/request count for each drive
* @return i/o and request metrics for read and write ops
*/
public long getReadBytes() {
return readBytes;
}
/**
*
* @return Cumulative i/o byte/request count for each drive
*/
public long getReadRequests() {
return readRequests;
}
/**
*
* @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;
public DriveMetrics getMetrics() {
return metrics;
}
@Override
@ -277,14 +226,11 @@ public class DriveInfo extends BaseDrive {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((claimed == null) ? 0 : claimed.hashCode());
result = prime * result + ((metrics == null) ? 0 : metrics.hashCode());
result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.hashCode());
result = prime * result + ((imaging == null) ? 0 : imaging.hashCode());
result = prime * result + (int) (readBytes ^ (readBytes >>> 32));
result = prime * result + (int) (readRequests ^ (readRequests >>> 32));
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((user == null) ? 0 : user.hashCode());
result = prime * result + (int) (writeBytes ^ (writeBytes >>> 32));
result = prime * result + (int) (writeRequests ^ (writeRequests >>> 32));
return result;
}
@ -302,6 +248,11 @@ public class DriveInfo extends BaseDrive {
return false;
} else if (!claimed.equals(other.claimed))
return false;
if (metrics == null) {
if (other.metrics != null)
return false;
} else if (!metrics.equals(other.metrics))
return false;
if (encryptionCipher == null) {
if (other.encryptionCipher != null)
return false;
@ -312,10 +263,6 @@ public class DriveInfo extends BaseDrive {
return false;
} else if (!imaging.equals(other.imaging))
return false;
if (readBytes != other.readBytes)
return false;
if (readRequests != other.readRequests)
return false;
if (status != other.status)
return false;
if (user == null) {
@ -323,10 +270,6 @@ public class DriveInfo extends BaseDrive {
return false;
} else if (!user.equals(other.user))
return false;
if (writeBytes != other.writeBytes)
return false;
if (writeRequests != other.writeRequests)
return false;
return true;
}
@ -335,8 +278,7 @@ public class DriveInfo extends BaseDrive {
return "[size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", uuid=" + uuid + ", name="
+ name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", status=" + status + ", user=" + user
+ ", claimed=" + claimed + ", encryptionCipher=" + encryptionCipher + ", imaging=" + imaging
+ ", readBytes=" + readBytes + ", readRequests=" + readRequests + ", writeBytes=" + writeBytes
+ ", writeRequests=" + writeRequests + "]";
+ ", metrics=" + metrics + "]";
}
}

View File

@ -37,7 +37,7 @@ public class IDEDevice extends Device {
@Override
public Device build() {
return new IDEDevice(uuid, mediaType, bus, unit, readBytes, readRequests, writeBytes, writeRequests);
return new IDEDevice(uuid, mediaType, bus, unit);
}
}
@ -45,9 +45,8 @@ public class IDEDevice extends Device {
private final int bus;
private final int unit;
public IDEDevice(String driveUuid, MediaType mediaType, int bus, int unit, long readBytes, long readRequests,
long writeBytes, long writeRequests) {
super(driveUuid, mediaType, readBytes, readRequests, writeBytes, writeRequests);
public IDEDevice(String driveUuid, MediaType mediaType, int bus, int unit) {
super(driveUuid, mediaType);
checkArgument(bus == 0 || bus == 1, "bus must be 0 or 1");
checkArgument(unit == 0 || unit == 1, "unit must be 0 or 1");
this.bus = bus;

View File

@ -35,7 +35,7 @@ public class SCSIDevice extends Device {
@Override
public Device build() {
return new SCSIDevice(uuid, mediaType, unit, readBytes, readRequests, writeBytes, writeRequests);
return new SCSIDevice(uuid, mediaType, unit);
}
}
@ -43,9 +43,8 @@ public class SCSIDevice extends Device {
private final int bus = 0;
private final int unit;
public SCSIDevice(String driveUuid, MediaType mediaType, int unit, long readBytes, long readRequests,
long writeBytes, long writeRequests) {
super(driveUuid, mediaType, readBytes, readRequests, writeBytes, writeRequests);
public SCSIDevice(String driveUuid, MediaType mediaType, int unit) {
super(driveUuid, mediaType);
checkArgument(unit >= 0 && unit < 8, "unit must be between 0 and 7");
this.unit = unit;
}

View File

@ -19,121 +19,113 @@
package org.jclouds.elasticstack.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class ServerInfo extends Item {
public class ServerInfo extends Server {
public static class Builder extends Item.Builder {
protected int cpu;
protected Integer smp;
public static class Builder extends Server.Builder {
protected ServerStatus status;
protected int mem;
protected boolean persistent;
protected Date started;
protected Set<? extends Device> devices = ImmutableSet.of();
protected Set<String> bootDeviceIds = ImmutableSet.of();
protected List<NIC> nics = ImmutableList.of();
protected String user;
protected VNC vnc;
// TODO undocumented
protected String description;
protected long txPackets;
protected long tx;
protected long rxPackets;
protected long rx;
protected ServerMetrics metrics;
public Builder status(ServerStatus status) {
this.status = status;
return this;
}
public Builder cpu(int cpu) {
this.cpu = cpu;
return this;
}
public Builder smp(Integer smp) {
this.smp = smp;
return this;
}
public Builder mem(int mem) {
this.mem = mem;
return this;
}
public Builder persistent(boolean persistent) {
this.persistent = persistent;
return this;
}
public Builder started(Date started) {
this.started = started;
return this;
}
public Builder devices(Iterable<? extends Device> devices) {
this.devices = ImmutableSet.copyOf(checkNotNull(devices, "devices"));
return this;
}
public Builder bootDeviceIds(Iterable<String> bootDeviceIds) {
this.bootDeviceIds = ImmutableSet.copyOf(checkNotNull(bootDeviceIds, "bootDeviceIds"));
return this;
}
public Builder nics(Iterable<NIC> nics) {
this.nics = ImmutableList.copyOf(checkNotNull(nics, "nics"));
return this;
}
public Builder user(String user) {
this.user = user;
return this;
}
public Builder metrics(ServerMetrics metrics) {
this.metrics = metrics;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public Builder cpu(int cpu) {
return Builder.class.cast(super.cpu(cpu));
}
/**
* {@inheritDoc}
*/
@Override
public Builder smp(Integer smp) {
return Builder.class.cast(super.smp(smp));
}
/**
* {@inheritDoc}
*/
@Override
public Builder mem(int mem) {
return Builder.class.cast(super.mem(mem));
}
/**
* {@inheritDoc}
*/
@Override
public Builder persistent(boolean persistent) {
return Builder.class.cast(super.persistent(persistent));
}
/**
* {@inheritDoc}
*/
@Override
public Builder devices(Map<String, ? extends Device> devices) {
return Builder.class.cast(super.devices(devices));
}
/**
* {@inheritDoc}
*/
@Override
public Builder bootDeviceIds(Iterable<String> bootDeviceIds) {
return Builder.class.cast(super.bootDeviceIds(bootDeviceIds));
}
/**
* {@inheritDoc}
*/
@Override
public Builder nics(Iterable<NIC> nics) {
return Builder.class.cast(super.nics(nics));
}
/**
* {@inheritDoc}
*/
@Override
public Builder vnc(VNC vnc) {
this.vnc = vnc;
return this;
return Builder.class.cast(super.vnc(vnc));
}
/**
* {@inheritDoc}
*/
@Override
public Builder description(String description) {
this.description = description;
return this;
}
public Builder txPackets(long txPackets) {
this.txPackets = txPackets;
return this;
}
public Builder tx(long tx) {
this.tx = tx;
return this;
}
public Builder rxPackets(long rxPackets) {
this.rxPackets = rxPackets;
return this;
}
public Builder rx(long rx) {
this.rx = rx;
return this;
return Builder.class.cast(super.description(description));
}
/**
@ -169,76 +161,27 @@ public class ServerInfo extends Item {
}
public ServerInfo build() {
return new ServerInfo(uuid, name, cpu, smp, mem, status, persistent, started, devices, tags, bootDeviceIds,
userMetadata, nics, user, vnc, description, tx, txPackets, rx, rxPackets);
return new ServerInfo(uuid, name, cpu, smp, mem, persistent, devices, tags, bootDeviceIds, userMetadata, nics,
vnc, description, status, started, user, metrics);
}
}
protected final int cpu;
protected final Integer smp;
protected final int mem;
protected final ServerStatus status;
protected final boolean persistent;
@Nullable
protected final Date started;
protected final Set<? extends Device> devices;
protected final Set<String> bootDeviceIds;
@Nullable
protected final String user;
protected final List<NIC> nics;
protected final VNC vnc;
@Nullable
private final String description;
protected final long txPackets;
protected final long tx;
protected final long rxPackets;
protected final long rx;
protected final ServerMetrics metrics;
public ServerInfo(@Nullable String uuid, String name, int cpu, @Nullable Integer smp, int mem, ServerStatus status,
boolean persistent, @Nullable Date started, Iterable<? extends Device> devices,
Iterable<String> bootDeviceIds, Iterable<String> tags, Map<String, String> userMetadata, Iterable<NIC> nics,
@Nullable String user, VNC vnc, String description, long tx, long txPackets, long rx, long rxPackets) {
super(uuid, name, tags, userMetadata);
this.cpu = cpu;
this.smp = smp;
this.mem = mem;
public ServerInfo(String uuid, String name, int cpu, Integer smp, int mem, boolean persistent,
Map<String, ? extends Device> devices, Iterable<String> bootDeviceIds, Iterable<String> tags,
Map<String, String> userMetadata, Iterable<NIC> nics, VNC vnc, String description, ServerStatus status,
Date started, String user, @Nullable ServerMetrics metrics) {
super(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, vnc, description);
this.status = status;
this.persistent = persistent;
this.started = started;
this.devices = ImmutableSet.copyOf(checkNotNull(devices, "devices"));
this.bootDeviceIds = ImmutableSet.copyOf(checkNotNull(bootDeviceIds, "bootDeviceIds"));
this.nics = ImmutableList.copyOf(checkNotNull(nics, "nics"));
this.user = user;
this.vnc = checkNotNull(vnc, "vnc");
this.description = description;
this.txPackets = txPackets;
this.tx = tx;
this.rxPackets = rxPackets;
this.rx = rx;
}
/**
*
* @return CPU quota in core MHz.
*/
public int getCpu() {
return cpu;
}
/**
*
* @return number of virtual processors or null if calculated based on cpu.
*/
public Integer getSmp() {
return smp;
}
/**
*
* @return virtual memory size in MB.
*/
public int getMem() {
return mem;
this.metrics = metrics;
}
/**
@ -249,59 +192,18 @@ public class ServerInfo extends Item {
return status;
}
/**
*
* @return 'true' means that server will revert to a 'stopped' status on server stop or shutdown,
* rather than being destroyed automatically.
*/
public boolean isPersistent() {
return persistent;
}
/**
*
* @return set of devices present
*/
public Set<? extends Device> getDevices() {
return devices;
}
/**
*
* @return ids of the devices to boot, e.g. ide:0:0 or ide:1:0
* @see Device#getId()
*/
public Set<String> getBootDeviceIds() {
return bootDeviceIds;
}
public List<NIC> getNics() {
return nics;
}
// TODO undocumented
public Date getStarted() {
return started;
}
// TODO undocumented
public long getTxPackets() {
return txPackets;
}
// TODO undocumented
public long getTx() {
return tx;
}
// TODO undocumented
public long getRxPackets() {
return rxPackets;
}
// TODO undocumented
public long getRx() {
return rx;
/**
*
* @return metrics, if the server is running, or null
*/
@Nullable
public ServerMetrics getMetrics() {
return metrics;
}
// TODO undocumented
@ -313,35 +215,14 @@ public class ServerInfo extends Item {
return user;
}
public VNC getVnc() {
return vnc;
}
// TODO undocumented
public String getDescription() {
return description;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((bootDeviceIds == null) ? 0 : bootDeviceIds.hashCode());
result = prime * result + cpu;
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((devices == null) ? 0 : devices.hashCode());
result = prime * result + mem;
result = prime * result + ((nics == null) ? 0 : nics.hashCode());
result = prime * result + (persistent ? 1231 : 1237);
result = prime * result + (int) (rx ^ (rx >>> 32));
result = prime * result + (int) (rxPackets ^ (rxPackets >>> 32));
result = prime * result + ((smp == null) ? 0 : smp.hashCode());
result = prime * result + ((metrics == null) ? 0 : metrics.hashCode());
result = prime * result + ((started == null) ? 0 : started.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + (int) (tx ^ (tx >>> 32));
result = prime * result + (int) (txPackets ^ (txPackets >>> 32));
result = prime * result + ((user == null) ? 0 : user.hashCode());
result = prime * result + ((vnc == null) ? 0 : vnc.hashCode());
return result;
}
@ -354,40 +235,10 @@ public class ServerInfo extends Item {
if (getClass() != obj.getClass())
return false;
ServerInfo other = (ServerInfo) obj;
if (bootDeviceIds == null) {
if (other.bootDeviceIds != null)
if (metrics == null) {
if (other.metrics != null)
return false;
} else if (!bootDeviceIds.equals(other.bootDeviceIds))
return false;
if (cpu != other.cpu)
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (devices == null) {
if (other.devices != null)
return false;
} else if (!devices.equals(other.devices))
return false;
if (mem != other.mem)
return false;
if (nics == null) {
if (other.nics != null)
return false;
} else if (!nics.equals(other.nics))
return false;
if (persistent != other.persistent)
return false;
if (rx != other.rx)
return false;
if (rxPackets != other.rxPackets)
return false;
if (smp == null) {
if (other.smp != null)
return false;
} else if (!smp.equals(other.smp))
} else if (!metrics.equals(other.metrics))
return false;
if (started == null) {
if (other.started != null)
@ -396,30 +247,20 @@ public class ServerInfo extends Item {
return false;
if (status != other.status)
return false;
if (tx != other.tx)
return false;
if (txPackets != other.txPackets)
return false;
if (user == null) {
if (other.user != null)
return false;
} else if (!user.equals(other.user))
return false;
if (vnc == null) {
if (other.vnc != null)
return false;
} else if (!vnc.equals(other.vnc))
return false;
return true;
}
@Override
public String toString() {
return "[uuid=" + uuid + ", name=" + name + ", tags=" + tags + ", userMetadata=" + userMetadata
+ ", cpu=" + cpu + ", smp=" + smp + ", mem=" + mem + ", status=" + status + ", persistent=" + persistent
+ ", started=" + started + ", devices=" + devices + ", bootDeviceIds=" + bootDeviceIds + ", user=" + user
+ ", nics=" + nics + ", vnc=" + vnc + ", description=" + description + ", txPackets=" + txPackets + ", tx="
+ tx + ", rxPackets=" + rxPackets + ", rx=" + rx + "]";
return "[cpu=" + cpu + ", smp=" + smp + ", mem=" + mem + ", persistent=" + persistent + ", devices=" + devices
+ ", bootDeviceIds=" + bootDeviceIds + ", nics=" + nics + ", vnc=" + vnc + ", uuid=" + uuid + ", name="
+ name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", status=" + status + ", started="
+ started + ", user=" + user + ", metrics=" + metrics + "]";
}
}

View File

@ -1,221 +0,0 @@
/**
*
* 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.elasticstack.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.elasticstack.domain.ClaimType;
import org.jclouds.elasticstack.domain.Item;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class BaseDrive extends Item {
public static class Builder extends Item.Builder {
protected long size;
protected ClaimType claimType = ClaimType.EXCLUSIVE;
protected Set<String> readers = ImmutableSet.of();
public Builder claimType(ClaimType claimType) {
this.claimType = claimType;
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;
}
/**
* {@inheritDoc}
*/
@Override
public Builder uuid(String uuid) {
return Builder.class.cast(super.uuid(uuid));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder tags(Iterable<String> tags) {
return Builder.class.cast(super.tags(tags));
}
/**
* {@inheritDoc}
*/
@Override
public Builder userMetadata(Map<String, String> userMetadata) {
return Builder.class.cast(super.userMetadata(userMetadata));
}
public BaseDrive build() {
return new BaseDrive(uuid, name, size, claimType, readers, tags, userMetadata);
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
result = prime * result + ((readers == null) ? 0 : readers.hashCode());
result = prime * result + (int) (size ^ (size >>> 32));
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;
Builder other = (Builder) obj;
if (claimType != other.claimType)
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;
return true;
}
}
protected final long size;
protected final ClaimType claimType;
protected final Set<String> readers;
public BaseDrive(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType,
Iterable<String> readers, Iterable<String> tags, Map<String, String> userMetadata) {
super(uuid, name, tags, userMetadata);
this.size = size;
this.claimType = checkNotNull(claimType, "set claimType to exclusive, not null");
this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
}
/**
*
* @return either 'exclusive' (the default) or 'shared' to allow multiple servers to access a
* drive simultaneously
*/
@Nullable
public ClaimType getClaimType() {
return claimType;
}
/**
*
* @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;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((claimType == null) ? 0 : claimType.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 (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 "[uuid=" + uuid + ", name=" + name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", size="
+ size + ", claimType=" + claimType + ", readers=" + readers + "]";
}
}

View File

@ -26,8 +26,8 @@ import java.util.Map.Entry;
import javax.inject.Singleton;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.ClaimType;
import org.jclouds.elasticstack.domain.internal.BaseDrive;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
@ -38,9 +38,9 @@ import com.google.common.collect.ImmutableMap;
* @author Adrian Cole
*/
@Singleton
public class BaseDriveToMap implements Function<BaseDrive, Map<String, String>> {
public class BaseDriveToMap implements Function<Drive, Map<String, String>> {
@Override
public Map<String, String> apply(BaseDrive from) {
public Map<String, String> apply(Drive from) {
checkNotNull(from, "drive");
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
builder.put("name", from.getName());

View File

@ -25,6 +25,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.domain.Drive;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
@ -35,7 +36,7 @@ import com.google.common.collect.ImmutableMap;
* @author Adrian Cole
*/
@Singleton
public class CreateDriveRequestToMap implements Function<CreateDriveRequest, Map<String, String>> {
public class CreateDriveRequestToMap implements Function<Drive, Map<String, String>> {
private final BaseDriveToMap baseDriveToMap;
@Inject
@ -44,13 +45,16 @@ public class CreateDriveRequestToMap implements Function<CreateDriveRequest, Map
}
@Override
public Map<String, String> apply(CreateDriveRequest from) {
public Map<String, String> apply(Drive 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()));
if (from.getEncryptionCipher() != null)
builder.put("encryption:cipher", from.getEncryptionCipher());
if (from instanceof CreateDriveRequest) {
CreateDriveRequest create = CreateDriveRequest.class.cast(from);
if (create.getAvoid().size() != 0)
builder.put("avoid", Joiner.on(' ').join(create.getAvoid()));
if (create.getEncryptionCipher() != null)
builder.put("encryption:cipher", create.getEncryptionCipher());
}
return builder.build();
}
}

View File

@ -20,8 +20,8 @@
package org.jclouds.elasticstack.functions;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.elasticstack.domain.BlockDevice;
@ -33,21 +33,36 @@ import org.jclouds.elasticstack.domain.SCSIDevice;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Maps;
/**
*
* @author Adrian Cole
*/
@Singleton
public class MapToDevices implements Function<Map<String, String>, Set<Device>> {
public class MapToDevices implements Function<Map<String, String>, Map<String, ? extends Device>> {
@Singleton
public static class DeviceToId implements Function<Device, String> {
@Override
public String apply(Device input) {
return input.getId();
}
}
public Set<Device> apply(Map<String, String> from) {
private final Function<Device, String> deviceToId;
@Inject
public MapToDevices(Function<Device, String> deviceToId) {
this.deviceToId = deviceToId;
}
public Map<String, ? extends Device> apply(Map<String, String> from) {
Builder<Device> devices = ImmutableSet.builder();
addIDEDevices(from, devices);
addSCSIDevices(from, devices);
addBlockDevices(from, devices);
Set<Device> devicess = devices.build();
return devicess;
return Maps.uniqueIndex(devices.build(), deviceToId);
}
protected void addBlockDevices(Map<String, String> from, Builder<Device> devices) {
@ -80,14 +95,6 @@ public class MapToDevices implements Function<Map<String, String>, Set<Device>>
protected Device.Builder populateBuilder(Device.Builder deviceBuilder, String key, Map<String, String> from) {
deviceBuilder.uuid(from.get(key));
if (from.containsKey(key + ":read:bytes"))
deviceBuilder.readBytes(new Long(from.get(key + ":read:bytes")));
if (from.containsKey(key + ":read:requests"))
deviceBuilder.readRequests(new Long(from.get(key + ":read:requests")));
if (from.containsKey(key + ":write:bytes"))
deviceBuilder.writeBytes(new Long(from.get(key + ":write:bytes")));
if (from.containsKey(key + ":write:requests"))
deviceBuilder.writeRequests(new Long(from.get(key + ":write:requests")));
if (from.containsKey(key + ":media"))
deviceBuilder.mediaType(MediaType.fromValue(from.get(key + ":media")));
return deviceBuilder;

View File

@ -26,6 +26,7 @@ import javax.inject.Singleton;
import org.jclouds.elasticstack.domain.ClaimType;
import org.jclouds.elasticstack.domain.DriveInfo;
import org.jclouds.elasticstack.domain.DriveMetrics;
import org.jclouds.elasticstack.domain.DriveStatus;
import com.google.common.base.Function;
@ -48,17 +49,10 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
builder.tags(Splitter.on(' ').split(from.get("tags")));
if (from.containsKey("status"))
builder.status(DriveStatus.fromValue(from.get("status")));
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.metrics(buildMetrics(from));
builder.user(from.get("user"));
builder.encryptionCipher(from.get("encryption:cipher"));
builder.uuid(from.get("drive"));
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"))
@ -75,4 +69,17 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
builder.userMetadata(metadata);
return builder.build();
}
protected DriveMetrics buildMetrics(Map<String, String> from) {
DriveMetrics.Builder metricsBuilder = new DriveMetrics.Builder();
if (from.containsKey("read:bytes"))
metricsBuilder.readBytes(new Long(from.get("read:bytes")));
if (from.containsKey("read:requests"))
metricsBuilder.readRequests(new Long(from.get("read:requests")));
if (from.containsKey("write:bytes"))
metricsBuilder.writeBytes(new Long(from.get("write:bytes")));
if (from.containsKey("write:requests"))
metricsBuilder.writeRequests(new Long(from.get("write:requests")));
return metricsBuilder.build();
}
}

View File

@ -23,7 +23,6 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -31,6 +30,7 @@ import javax.inject.Singleton;
import org.jclouds.elasticstack.domain.Device;
import org.jclouds.elasticstack.domain.NIC;
import org.jclouds.elasticstack.domain.ServerInfo;
import org.jclouds.elasticstack.domain.ServerMetrics;
import org.jclouds.elasticstack.domain.ServerStatus;
import org.jclouds.elasticstack.domain.VNC;
@ -44,13 +44,15 @@ import com.google.common.collect.Maps;
*/
@Singleton
public class MapToServerInfo implements Function<Map<String, String>, ServerInfo> {
private final Function<Map<String, String>, Set<Device>> mapToDevices;
private final Function<Map<String, String>, Map<String, ? extends Device>> mapToDevices;
private final Function<Map<String, String>, ServerMetrics> mapToMetrics;
private final Function<Map<String, String>, List<NIC>> mapToNICs;
@Inject
public MapToServerInfo(Function<Map<String, String>, Set<Device>> mapToDevices,
Function<Map<String, String>, List<NIC>> mapToNICs) {
public MapToServerInfo(Function<Map<String, String>, Map<String, ? extends Device>> mapToDevices,
Function<Map<String, String>, ServerMetrics> mapToMetrics, Function<Map<String, String>, List<NIC>> mapToNICs) {
this.mapToDevices = mapToDevices;
this.mapToMetrics = mapToMetrics;
this.mapToNICs = mapToNICs;
}
@ -66,10 +68,6 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
builder.tags(Splitter.on(' ').split(from.get("tags")));
if (from.containsKey("status"))
builder.status(ServerStatus.fromValue(from.get("status")));
if (from.containsKey("tx:packets"))
builder.txPackets(new Long(from.get("tx:packets")));
if (from.containsKey("tx"))
builder.tx(new Long(from.get("tx")));
if (from.containsKey("smp") && !"auto".equals(from.get("smp")))
builder.smp(new Integer(from.get("smp")));
builder.cpu(Integer.parseInt(from.get("cpu")));
@ -80,10 +78,6 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
builder.uuid(from.get("server"));
builder.vnc(new VNC(from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("vnc:tls")
&& Boolean.valueOf(from.get("vnc:tls"))));
if (from.containsKey("rx:packets"))
builder.rxPackets(new Long(from.get("rx:packets")));
if (from.containsKey("rx"))
builder.rx(new Long(from.get("rx")));
if (from.containsKey("boot"))
builder.bootDeviceIds(Splitter.on(' ').split(from.get("boot")));
@ -93,9 +87,9 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
metadata.put(entry.getKey().substring(entry.getKey().indexOf(':') + 1), entry.getValue());
}
builder.userMetadata(metadata);
builder.nics(mapToNICs.apply(from));
builder.devices(mapToDevices.apply(from));
builder.metrics(mapToMetrics.apply(from));
return builder.build();
}
}

View File

@ -28,6 +28,7 @@ import java.util.Properties;
import javax.ws.rs.core.MediaType;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.DriveData;
import org.jclouds.elasticstack.domain.ImageConversionType;
import org.jclouds.elasticstack.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
@ -179,7 +180,7 @@ public class ElasticStackAsyncClientTest extends RestClientTest<ElasticStackAsyn
}
public void testCreateDrive() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticStackAsyncClient.class.getMethod("createDrive", CreateDriveRequest.class);
Method method = ElasticStackAsyncClient.class.getMethod("createDrive", Drive.class);
GeneratedHttpRequest<ElasticStackAsyncClient> httpRequest = processor.createRequest(method,
new CreateDriveRequest.Builder().name("foo").size(10000l).build());

View File

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

View File

@ -28,7 +28,7 @@ import java.util.Map;
import javax.ws.rs.core.MediaType;
import org.jclouds.elasticstack.domain.ClaimType;
import org.jclouds.elasticstack.domain.CreateDriveRequest;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.DriveData;
import org.jclouds.elasticstack.functions.CreateDriveRequestToMap;
import org.jclouds.elasticstack.functions.DriveDataToMap;
@ -54,7 +54,7 @@ public class BindDriveDataToPlainTextStringTest {
@Override
protected void configure() {
bind(new TypeLiteral<Function<CreateDriveRequest, Map<String, String>>>() {
bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
}).to(CreateDriveRequestToMap.class);
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
}).to(DriveDataToMap.class);

View File

@ -23,8 +23,8 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.elasticstack.domain.Drive;
import org.jclouds.elasticstack.domain.ClaimType;
import org.jclouds.elasticstack.domain.internal.BaseDrive;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -40,12 +40,12 @@ 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()),
assertEquals(BASEDRIVE_TO_MAP.apply(new Drive.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")
Drive one = new Drive.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
//
.size(8589934592l)//
.claimType(ClaimType.SHARED)//

View File

@ -23,10 +23,12 @@ import static org.testng.Assert.assertEquals;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jclouds.elasticstack.domain.Device;
import org.jclouds.elasticstack.domain.DriveMetrics;
import org.jclouds.elasticstack.domain.NIC;
import org.jclouds.elasticstack.domain.ServerMetrics;
import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
@ -49,8 +51,14 @@ public class KeyValuesDelimitedByBlankLinesToServerInfoTest {
protected void configure() {
bind(new TypeLiteral<Function<Map<String, String>, List<NIC>>>() {
}).to(MapToNICs.class);
bind(new TypeLiteral<Function<Map<String, String>, Set<Device>>>() {
bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends Device>>>() {
}).to(MapToDevices.class);
bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends DriveMetrics>>>() {
}).to(MapToDriveMetrics.class);
bind(new TypeLiteral<Function<Map<String, String>, ServerMetrics>>() {
}).to(MapToServerMetrics.class);
bind(new TypeLiteral<Function<Device, String>>() {
}).to(DeviceToId.class);
}
}).getInstance(KeyValuesDelimitedByBlankLinesToServerInfo.class);

View File

@ -23,11 +23,13 @@ import static org.testng.Assert.assertEquals;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jclouds.elasticstack.domain.Device;
import org.jclouds.elasticstack.domain.DriveMetrics;
import org.jclouds.elasticstack.domain.NIC;
import org.jclouds.elasticstack.domain.ServerInfo;
import org.jclouds.elasticstack.domain.ServerMetrics;
import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payloads;
import org.testng.annotations.Test;
@ -52,8 +54,14 @@ public class ListOfKeyValuesDelimitedByBlankLinesToServerInfoSetTest {
protected void configure() {
bind(new TypeLiteral<Function<Map<String, String>, List<NIC>>>() {
}).to(MapToNICs.class);
bind(new TypeLiteral<Function<Map<String, String>, Set<Device>>>() {
bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends Device>>>() {
}).to(MapToDevices.class);
bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends DriveMetrics>>>() {
}).to(MapToDriveMetrics.class);
bind(new TypeLiteral<Function<Map<String, String>, ServerMetrics>>() {
}).to(MapToServerMetrics.class);
bind(new TypeLiteral<Function<Device, String>>() {
}).to(DeviceToId.class);
}
}).getInstance(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class);

View File

@ -26,6 +26,7 @@ import java.util.Map;
import org.jclouds.elasticstack.domain.ClaimType;
import org.jclouds.elasticstack.domain.DriveInfo;
import org.jclouds.elasticstack.domain.DriveMetrics;
import org.jclouds.elasticstack.domain.DriveStatus;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
@ -42,11 +43,12 @@ public class MapToDriveInfoTest {
public static DriveInfo ONE = new DriveInfo.Builder()
.status(DriveStatus.ACTIVE)
.name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
.readBytes(4096l)
.metrics(
new DriveMetrics.Builder().readBytes(4096l).writeBytes(8589938688l).writeRequests(2097153l)
.readRequests(1l).build())
.user("58ca3c1f-7629-4771-9b71-863f40153ba4")
.encryptionCipher("aes-xts-plain")
.uuid("b8171d28-755a-4271-b891-7998871a160e")
.writeBytes(8589938688l)
.claimType(ClaimType.SHARED)
.claimed(
ImmutableSet.of(
@ -56,8 +58,6 @@ public class MapToDriveInfoTest {
"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"))//
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
.readRequests(1l)//
.writeRequests(2097153l)//
.size(8589934592l)//
.userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz")).build();
@ -68,7 +68,8 @@ public class MapToDriveInfoTest {
}
public void testBasics() {
DriveInfo expects = new DriveInfo.Builder().name("foo").size(100l).build();
DriveInfo expects = new DriveInfo.Builder().name("foo").size(100l).metrics(new DriveMetrics.Builder().build())
.build();
assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.of("name", "foo", "size", "100")), expects);
}

View File

@ -25,13 +25,16 @@ import java.io.IOException;
import java.util.Date;
import java.util.Map;
import org.jclouds.elasticstack.domain.DriveMetrics;
import org.jclouds.elasticstack.domain.IDEDevice;
import org.jclouds.elasticstack.domain.MediaType;
import org.jclouds.elasticstack.domain.Model;
import org.jclouds.elasticstack.domain.NIC;
import org.jclouds.elasticstack.domain.ServerInfo;
import org.jclouds.elasticstack.domain.ServerMetrics;
import org.jclouds.elasticstack.domain.ServerStatus;
import org.jclouds.elasticstack.domain.VNC;
import org.jclouds.elasticstack.functions.MapToDevices.DeviceToId;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
@ -64,10 +67,20 @@ public class MapToServerInfoTest {
ImmutableList.of("tcp/43594", "tcp/5902", "udp/5060", "tcp/5900", "tcp/5901", "tcp/21", "tcp/22",
"tcp/23", "tcp/25", "tcp/110", "tcp/143", "tcp/43595")).build()))
.devices(
ImmutableSet.of(new IDEDevice.Builder((int) 0, (int) 0).uuid("4af85ed3-0caa-4736-8a26-a33d7de0a122")
.readRequests(11154).readBytes(45686784).writeRequests(3698).writeBytes(15147008).build()
ImmutableMap.of("ide:0:0",
new IDEDevice.Builder((int) 0, (int) 0).uuid("4af85ed3-0caa-4736-8a26-a33d7de0a122").build()
)).tx(2550).txPackets(31).rx(455530).rxPackets(7583).build();
))
.metrics(
new ServerMetrics.Builder()
.tx(2550)
.txPackets(31)
.rx(455530)
.rxPackets(7583)
.driveMetrics(
ImmutableMap.of("ide:0:0", new DriveMetrics.Builder().readRequests(11154)
.readBytes(45686784).writeRequests(3698).writeBytes(15147008).build())).build())
.build();
public static ServerInfo TWO = new ServerInfo.Builder()
.status(ServerStatus.STOPPED)
@ -81,12 +94,16 @@ public class MapToServerInfoTest {
.vnc(new VNC("auto", "HWbjvrg2", false))
.nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).dhcp("auto").build()))
.devices(
ImmutableSet.of(new IDEDevice.Builder((int) 0, (int) 0).uuid("853bb98a-4fff-4c2f-a265-97c363f19ea5")
.mediaType(MediaType.CDROM).build()
ImmutableMap.of(
"ide:0:0",
new IDEDevice.Builder((int) 0, (int) 0).uuid("853bb98a-4fff-4c2f-a265-97c363f19ea5")
.mediaType(MediaType.CDROM).build()))
.metrics(
new ServerMetrics.Builder().driveMetrics(ImmutableMap.of("ide:0:0", new DriveMetrics.Builder().build()))
.build()).build();
)).build();
private static final MapToServerInfo MAP_TO_DRIVE = new MapToServerInfo(new MapToDevices(), new MapToNICs());
private static final MapToServerInfo MAP_TO_DRIVE = new MapToServerInfo(new MapToDevices(new DeviceToId()),
new MapToServerMetrics(new MapToDriveMetrics()), new MapToNICs());
public void testEmptyMapReturnsNull() {
assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.<String, String> of()), null);
@ -94,7 +111,7 @@ public class MapToServerInfoTest {
public void testBasics() {
ServerInfo expects = new ServerInfo.Builder().name("foo").uuid("hello").vnc(new VNC("auto", null, false))
.cpu(1000).mem(2048).build();
.cpu(1000).mem(2048).metrics(new ServerMetrics.Builder().build()).build();
assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.of("name", "foo", "server", "hello", "vnc:ip", "auto", "cpu",
"1000", "mem", "2048")), expects);
}