mirror of https://github.com/apache/jclouds.git
Issue 419: removed dependency between elasticstack and cloudsigma
This commit is contained in:
parent
90ee548e8d
commit
23b164ba3d
|
@ -61,7 +61,7 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-elasticstack</artifactId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -79,7 +79,14 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-elasticstack</artifactId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
|
|
|
@ -35,16 +35,14 @@ import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerIn
|
|||
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
|
||||
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet;
|
||||
import org.jclouds.cloudsigma.options.CloneDriveOptions;
|
||||
import org.jclouds.elasticstack.CommonElasticStackAsyncClient;
|
||||
import org.jclouds.elasticstack.ElasticStackClient;
|
||||
import org.jclouds.elasticstack.binders.BindDriveDataToPlainTextString;
|
||||
import org.jclouds.elasticstack.binders.BindDriveToPlainTextString;
|
||||
import org.jclouds.elasticstack.binders.BindServerToPlainTextString;
|
||||
import org.jclouds.elasticstack.domain.Drive;
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.domain.ServerInfo;
|
||||
import org.jclouds.elasticstack.functions.SplitNewlines;
|
||||
import org.jclouds.cloudsigma.binders.BindDriveDataToPlainTextString;
|
||||
import org.jclouds.cloudsigma.binders.BindDriveToPlainTextString;
|
||||
import org.jclouds.cloudsigma.binders.BindServerToPlainTextString;
|
||||
import org.jclouds.cloudsigma.domain.Drive;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
import org.jclouds.cloudsigma.domain.Server;
|
||||
import org.jclouds.cloudsigma.domain.ServerInfo;
|
||||
import org.jclouds.cloudsigma.functions.SplitNewlines;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
|
@ -53,6 +51,7 @@ import org.jclouds.rest.annotations.MapPayloadParam;
|
|||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
|
@ -60,16 +59,16 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
* Provides asynchronous access to CloudSigma via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see ElasticStackClient
|
||||
* @see CloudSigmaClient
|
||||
* @see <a href="TODO: insert URL of provider documentation" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Consumes(MediaType.TEXT_PLAIN)
|
||||
public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient {
|
||||
public interface CloudSigmaAsyncClient {
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listStandardDrives()
|
||||
* @see CloudSigmaClient#listStandardDrives
|
||||
*/
|
||||
@GET
|
||||
@Path("/drives/standard/list")
|
||||
|
@ -77,7 +76,7 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient {
|
|||
ListenableFuture<Set<String>> listStandardDrives();
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listStandardCds()
|
||||
* @see CloudSigmaClient#listStandardCds
|
||||
*/
|
||||
@GET
|
||||
@Path("/drives/standard/cd/list")
|
||||
|
@ -85,7 +84,7 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient {
|
|||
ListenableFuture<Set<String>> listStandardCds();
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listStandardImages()
|
||||
* @see CloudSigmaClient#listStandardImages
|
||||
*/
|
||||
@GET
|
||||
@Path("/drives/standard/img/list")
|
||||
|
@ -103,18 +102,16 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient {
|
|||
@MapPayloadParam("name") String newName, CloneDriveOptions... options);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see CloudSigmaClient#listDriveInfo
|
||||
*/
|
||||
@Override
|
||||
@GET
|
||||
@Path("/drives/info")
|
||||
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class)
|
||||
ListenableFuture<Set<? extends org.jclouds.elasticstack.domain.DriveInfo>> listDriveInfo();
|
||||
ListenableFuture<Set<? extends org.jclouds.cloudsigma.domain.DriveInfo>> listDriveInfo();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see CloudSigmaClient#getDriveInfo
|
||||
*/
|
||||
@Override
|
||||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
|
@ -122,9 +119,8 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient {
|
|||
ListenableFuture<? extends DriveInfo> getDriveInfo(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see CloudSigmaClient#createDrive
|
||||
*/
|
||||
@Override
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
|
@ -132,9 +128,8 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient {
|
|||
ListenableFuture<? extends DriveInfo> createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see CloudSigmaClient#setDriveData
|
||||
*/
|
||||
@Override
|
||||
@POST
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
@Path("/drives/{uuid}/set")
|
||||
|
@ -142,9 +137,8 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient {
|
|||
@BinderParam(BindDriveDataToPlainTextString.class) DriveData createDrive);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see CloudSigmaClient#createServer
|
||||
*/
|
||||
@Override
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class)
|
||||
|
@ -153,18 +147,16 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient {
|
|||
@BinderParam(BindServerToPlainTextString.class) Server createServer);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see CloudSigmaClient#listServerInfo
|
||||
*/
|
||||
@Override
|
||||
@GET
|
||||
@Path("/servers/info")
|
||||
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class)
|
||||
ListenableFuture<Set<? extends ServerInfo>> listServerInfo();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see CloudSigmaClient#getServerInfo
|
||||
*/
|
||||
@Override
|
||||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class)
|
||||
|
@ -172,13 +164,72 @@ public interface CloudSigmaAsyncClient extends CommonElasticStackAsyncClient {
|
|||
ListenableFuture<? extends ServerInfo> getServerInfo(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see CloudSigmaClient#setServerConfiguration
|
||||
*/
|
||||
@Override
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class)
|
||||
@Path("/servers/{uuid}/set")
|
||||
ListenableFuture<? extends ServerInfo> setServerConfiguration(@PathParam("uuid") String uuid,
|
||||
@BinderParam(BindServerToPlainTextString.class) Server setServer);
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#listServers
|
||||
*/
|
||||
@GET
|
||||
@Path("/servers/list")
|
||||
@ResponseParser(SplitNewlines.class)
|
||||
ListenableFuture<Set<String>> listServers();
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#destroyServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/destroy")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> destroyServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#startServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/start")
|
||||
ListenableFuture<Void> startServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#stopServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/stop")
|
||||
ListenableFuture<Void> stopServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#shutdownServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/shutdown")
|
||||
ListenableFuture<Void> shutdownServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#resetServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/reset")
|
||||
ListenableFuture<Void> resetServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#listDrives
|
||||
*/
|
||||
@GET
|
||||
@Path("/drives/list")
|
||||
@ResponseParser(SplitNewlines.class)
|
||||
ListenableFuture<Set<String>> listDrives();
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#destroyDrive
|
||||
*/
|
||||
@POST
|
||||
@Path("/drives/{uuid}/destroy")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> destroyDrive(@PathParam("uuid") String uuid);
|
||||
}
|
||||
|
|
|
@ -25,20 +25,157 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.jclouds.cloudsigma.domain.DriveInfo;
|
||||
import org.jclouds.cloudsigma.options.CloneDriveOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.elasticstack.CommonElasticStackClient;
|
||||
import org.jclouds.elasticstack.domain.Drive;
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.cloudsigma.domain.Drive;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
import org.jclouds.cloudsigma.domain.Server;
|
||||
import org.jclouds.cloudsigma.domain.ServerInfo;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudSigma.
|
||||
* <p/>
|
||||
*
|
||||
* @see CloudSigmaAsyncClient
|
||||
* @see <a href="TODO: insert URL of elasticstack documentation" />
|
||||
* @see <a href="TODO: insert URL of cloudsigma documentation" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface CloudSigmaClient extends CommonElasticStackClient {
|
||||
public interface CloudSigmaClient {
|
||||
/**
|
||||
* list of server uuids in your account
|
||||
*
|
||||
* @return or empty set if no servers are found
|
||||
*/
|
||||
Set<String> listServers();
|
||||
|
||||
/**
|
||||
* Get all servers info
|
||||
*
|
||||
* @return or empty set if no servers are found
|
||||
*/
|
||||
Set<? extends ServerInfo> listServerInfo();
|
||||
|
||||
/**
|
||||
* @param uuid
|
||||
* what to get
|
||||
* @return null, if not found
|
||||
*/
|
||||
ServerInfo getServerInfo(String uuid);
|
||||
|
||||
/**
|
||||
* create a new server
|
||||
*
|
||||
* @param server
|
||||
* @return newly created server
|
||||
*/
|
||||
ServerInfo createServer(Server server);
|
||||
|
||||
/**
|
||||
* set server configuration
|
||||
*
|
||||
* @param uuid
|
||||
* what server to change
|
||||
* @param serverData
|
||||
* what values to change
|
||||
* @return new data
|
||||
*/
|
||||
ServerInfo setServerConfiguration(String uuid, Server server);
|
||||
|
||||
/**
|
||||
* Destroy a server
|
||||
*
|
||||
* @param uuid
|
||||
* what to destroy
|
||||
*/
|
||||
void destroyServer(String uuid);
|
||||
|
||||
/**
|
||||
* Start a server
|
||||
*
|
||||
* @param uuid
|
||||
* what to start
|
||||
*/
|
||||
void startServer(String uuid);
|
||||
|
||||
/**
|
||||
* Stop a server
|
||||
* <p/>
|
||||
* Kills the server immediately, equivalent to a power failure. Server reverts to a stopped
|
||||
* status if it is persistent and is automatically destroyed otherwise.
|
||||
*
|
||||
* @param uuid
|
||||
* what to stop
|
||||
*/
|
||||
void stopServer(String uuid);
|
||||
|
||||
/**
|
||||
* Shutdown a server
|
||||
* <p/>
|
||||
* Sends the server an ACPI power-down event. Server reverts to a stopped status if it is
|
||||
* persistent and is automatically destroyed otherwise.
|
||||
* <h4>note</h4> behaviour on shutdown depends on how your server OS is set up to respond to an
|
||||
* ACPI power button signal.
|
||||
*
|
||||
* @param uuid
|
||||
* what to shutdown
|
||||
*/
|
||||
void shutdownServer(String uuid);
|
||||
|
||||
/**
|
||||
* Reset a server
|
||||
*
|
||||
* @param uuid
|
||||
* what to reset
|
||||
*/
|
||||
void resetServer(String uuid);
|
||||
|
||||
/**
|
||||
* list of drive uuids in your account
|
||||
*
|
||||
* @return or empty set if no drives are found
|
||||
*/
|
||||
Set<String> listDrives();
|
||||
|
||||
/**
|
||||
* Get all drives info
|
||||
*
|
||||
* @return or empty set if no drives are found
|
||||
*/
|
||||
Set<? extends DriveInfo> listDriveInfo();
|
||||
|
||||
/**
|
||||
* @param uuid
|
||||
* what to get
|
||||
* @return null, if not found
|
||||
*/
|
||||
DriveInfo getDriveInfo(String uuid);
|
||||
|
||||
/**
|
||||
* create a new drive
|
||||
*
|
||||
* @param createDrive
|
||||
* required parameters: name, size
|
||||
* @return newly created drive
|
||||
*/
|
||||
DriveInfo createDrive(Drive createDrive);
|
||||
|
||||
/**
|
||||
* set extra drive data
|
||||
*
|
||||
* @param uuid
|
||||
* what drive to change
|
||||
* @param driveData
|
||||
* what values to change
|
||||
* @return new data
|
||||
*/
|
||||
DriveInfo setDriveData(String uuid, DriveData driveData);
|
||||
|
||||
/**
|
||||
* Destroy a drive
|
||||
*
|
||||
* @param uuid
|
||||
* what to delete
|
||||
*/
|
||||
void destroyDrive(String uuid);
|
||||
|
||||
/**
|
||||
* list of drive uuids that are in the library
|
||||
|
@ -74,28 +211,5 @@ public interface CloudSigmaClient extends CommonElasticStackClient {
|
|||
*/
|
||||
DriveInfo cloneDrive(String sourceUuid, String newName, CloneDriveOptions... options);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Set<? extends DriveInfo> listDriveInfo();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
DriveInfo getDriveInfo(String uuid);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
DriveInfo createDrive(Drive createDrive);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
DriveInfo setDriveData(String uuid, DriveData driveData);
|
||||
|
||||
}
|
||||
|
|
|
@ -19,8 +19,10 @@
|
|||
|
||||
package org.jclouds.cloudsigma;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||
import static org.jclouds.cloudsigma.reference.CloudSigmaConstants.PROPERTY_VNC_PASSWORD;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -37,6 +39,7 @@ public class CloudSigmaPropertiesBuilder extends PropertiesBuilder {
|
|||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://api.cloudsigma.com");
|
||||
properties.setProperty(PROPERTY_API_VERSION, "1.0");
|
||||
properties.setProperty(PROPERTY_VNC_PASSWORD, "IL9vs34d");
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
@ -44,4 +47,11 @@ public class CloudSigmaPropertiesBuilder extends PropertiesBuilder {
|
|||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties build() {
|
||||
Properties props = super.build();
|
||||
checkArgument(props.getProperty(PROPERTY_VNC_PASSWORD).length() <= 8,
|
||||
"vnc passwords should be less that 8 characters!");
|
||||
return props;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import javax.ws.rs.core.MediaType;
|
|||
|
||||
import org.jclouds.cloudsigma.CloudSigmaAsyncClient;
|
||||
import org.jclouds.cloudsigma.options.CloneDriveOptions;
|
||||
import org.jclouds.elasticstack.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
import org.jclouds.cloudsigma.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.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.cloudsigma.domain.DriveData;
|
||||
import org.jclouds.cloudsigma.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 BindDriveDataToPlainTextString implements Binder {
|
||||
private final Function<DriveData, Map<String, String>> createDriveRequestToMap;
|
||||
private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
|
||||
@Inject
|
||||
public BindDriveDataToPlainTextString(Function<DriveData, Map<String, String>> createDriveRequestToMap,
|
||||
ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) {
|
||||
this.createDriveRequestToMap = createDriveRequestToMap;
|
||||
this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
}
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
checkArgument(payload instanceof DriveData, "this binder is only valid for DriveData!");
|
||||
DriveData create = DriveData.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,61 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.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.cloudsigma.domain.Drive;
|
||||
import org.jclouds.cloudsigma.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 BindDriveToPlainTextString implements Binder {
|
||||
private final Function<Drive, Map<String, String>> createDriveRequestToMap;
|
||||
private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
|
||||
@Inject
|
||||
public BindDriveToPlainTextString(Function<Drive, Map<String, String>> createDriveRequestToMap,
|
||||
ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) {
|
||||
this.createDriveRequestToMap = createDriveRequestToMap;
|
||||
this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
}
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
checkArgument(payload instanceof Drive, "this binder is only valid for Drive!");
|
||||
Drive create = Drive.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,61 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.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.cloudsigma.domain.Server;
|
||||
import org.jclouds.cloudsigma.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 BindServerToPlainTextString implements Binder {
|
||||
private final Function<Server, Map<String, String>> createServerRequestToMap;
|
||||
private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
|
||||
@Inject
|
||||
public BindServerToPlainTextString(Function<Server, Map<String, String>> createServerRequestToMap,
|
||||
ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) {
|
||||
this.createServerRequestToMap = createServerRequestToMap;
|
||||
this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||
}
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
checkArgument(payload instanceof Server, "this binder is only valid for Server!");
|
||||
Server create = Server.class.cast(payload);
|
||||
Map<String, String> map = createServerRequestToMap.apply(create);
|
||||
request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map)));
|
||||
request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
|
||||
}
|
||||
}
|
|
@ -24,22 +24,22 @@ import java.util.Map;
|
|||
|
||||
import org.jclouds.cloudsigma.CloudSigmaAsyncClient;
|
||||
import org.jclouds.cloudsigma.CloudSigmaClient;
|
||||
import org.jclouds.cloudsigma.functions.CreateDriveRequestToMap;
|
||||
import org.jclouds.cloudsigma.domain.Device;
|
||||
import org.jclouds.cloudsigma.domain.Drive;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
import org.jclouds.cloudsigma.domain.DriveMetrics;
|
||||
import org.jclouds.cloudsigma.domain.NIC;
|
||||
import org.jclouds.cloudsigma.domain.Server;
|
||||
import org.jclouds.cloudsigma.domain.ServerMetrics;
|
||||
import org.jclouds.cloudsigma.functions.BaseDriveToMap;
|
||||
import org.jclouds.cloudsigma.functions.DriveDataToMap;
|
||||
import org.jclouds.cloudsigma.functions.MapToDevices;
|
||||
import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId;
|
||||
import org.jclouds.cloudsigma.functions.MapToDriveMetrics;
|
||||
import org.jclouds.cloudsigma.functions.MapToNICs;
|
||||
import org.jclouds.cloudsigma.functions.MapToServerMetrics;
|
||||
import org.jclouds.cloudsigma.functions.ServerToMap;
|
||||
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.Server;
|
||||
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.cloudsigma.handlers.CloudSigmaErrorHandler;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.http.annotation.ClientError;
|
||||
|
@ -66,16 +66,16 @@ public class CloudSigmaRestClientModule extends RestClientModule<CloudSigmaClien
|
|||
|
||||
@Override
|
||||
protected void bindErrorHandlers() {
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ElasticStackErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ElasticStackErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ElasticStackErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(CloudSigmaErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(CloudSigmaErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(CloudSigmaErrorHandler.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
|
||||
}).to(CreateDriveRequestToMap.class);
|
||||
}).to(BaseDriveToMap.class);
|
||||
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
|
||||
}).to(DriveDataToMap.class);
|
||||
bind(new TypeLiteral<Function<Map<String, String>, List<NIC>>>() {
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BlockDevice extends Device {
|
||||
public static class Builder extends Device.Builder {
|
||||
private final int index;
|
||||
|
||||
public Builder(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device build() {
|
||||
return new BlockDevice(uuid, mediaType, index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final int index;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + index;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
BlockDevice other = (BlockDevice) obj;
|
||||
if (index != other.index)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return String.format("block:%d", index);
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + getId() + ", driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]";
|
||||
}
|
||||
}
|
|
@ -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.cloudsigma.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,162 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class CreateDriveRequest extends Drive {
|
||||
public static class Builder extends Drive.Builder {
|
||||
|
||||
private Set<String> avoid = ImmutableSet.of();
|
||||
|
||||
@Nullable
|
||||
private String encryptionCipher;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public Builder encryptionCipher(String encryptionCipher) {
|
||||
this.encryptionCipher = encryptionCipher;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 use(Iterable<String> use) {
|
||||
return Builder.class.cast(super.use(use));
|
||||
}
|
||||
|
||||
public CreateDriveRequest build() {
|
||||
return new CreateDriveRequest(name, size, claimType, readers, use, encryptionCipher, avoid);
|
||||
}
|
||||
}
|
||||
|
||||
private final Set<String> avoid;
|
||||
@Nullable
|
||||
private final String encryptionCipher;
|
||||
|
||||
public CreateDriveRequest(String name, long size, @Nullable ClaimType claimType, Iterable<String> readers,
|
||||
Iterable<String> use, @Nullable String encryptionCipher, Iterable<String> avoid) {
|
||||
super(null, name, size, claimType, readers, use);
|
||||
this.encryptionCipher = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return either 'none' or 'aes-xts-plain' (the default)
|
||||
*/
|
||||
@Nullable
|
||||
public String getEncryptionCipher() {
|
||||
return encryptionCipher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((avoid == null) ? 0 : avoid.hashCode());
|
||||
result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.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;
|
||||
CreateDriveRequest other = (CreateDriveRequest) obj;
|
||||
if (avoid == null) {
|
||||
if (other.avoid != null)
|
||||
return false;
|
||||
} else if (!avoid.equals(other.avoid))
|
||||
return false;
|
||||
if (encryptionCipher == null) {
|
||||
if (other.encryptionCipher != null)
|
||||
return false;
|
||||
} else if (!encryptionCipher.equals(other.encryptionCipher))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=" + name + ", size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", use=" + use
|
||||
+ ", avoid=" + avoid + ", encryptionCipher=" + encryptionCipher + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public abstract class Device {
|
||||
public static abstract class Builder {
|
||||
protected String uuid;
|
||||
protected MediaType mediaType = MediaType.DISK;
|
||||
|
||||
public Builder mediaType(MediaType mediaType) {
|
||||
this.mediaType = mediaType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder uuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract Device build();
|
||||
}
|
||||
|
||||
protected final String driveUuid;
|
||||
protected final MediaType mediaType;
|
||||
|
||||
public Device(String driveUuid, MediaType mediaType) {
|
||||
this.driveUuid = checkNotNull(driveUuid, "driveUuid");
|
||||
this.mediaType = checkNotNull(mediaType, "mediaType");
|
||||
}
|
||||
|
||||
/**
|
||||
* id generated based on the device bus, unit, and/or index numbers;
|
||||
*/
|
||||
public abstract String getId();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Drive UUID to connect as specified device.
|
||||
*/
|
||||
public String getDriveUuid() {
|
||||
return driveUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return set to 'cdrom' to simulate a cdrom, set to 'disk' or leave unset to simulate a hard
|
||||
* disk.
|
||||
*/
|
||||
public MediaType getMediaType() {
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
@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());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Device other = (Device) obj;
|
||||
if (driveUuid == null) {
|
||||
if (other.driveUuid != null)
|
||||
return false;
|
||||
} else if (!driveUuid.equals(other.driveUuid))
|
||||
return false;
|
||||
if (mediaType != other.mediaType)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Drive 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 use(Iterable<String> use) {
|
||||
return Builder.class.cast(super.use(use));
|
||||
}
|
||||
|
||||
public Drive build() {
|
||||
return new Drive(uuid, name, size, claimType, readers, use);
|
||||
}
|
||||
|
||||
@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 Drive(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType, Iterable<String> readers,
|
||||
Iterable<String> use) {
|
||||
super(uuid, name, use);
|
||||
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 + ((use == null) ? 0 : use.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;
|
||||
Drive other = (Drive) 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 (use == null) {
|
||||
if (other.use != null)
|
||||
return false;
|
||||
} else if (!use.equals(other.use))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[uuid=" + uuid + ", name=" + name + ", use=" + use + ", size=" + size + ", claimType=" + claimType
|
||||
+ ", readers=" + readers + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class DriveData extends Drive {
|
||||
public static class Builder extends Drive.Builder {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder claimType(ClaimType claimType) {
|
||||
return Builder.class.cast(super.claimType(claimType));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 use(Iterable<String> use) {
|
||||
return Builder.class.cast(super.use(use));
|
||||
}
|
||||
|
||||
public DriveData build() {
|
||||
return new DriveData(uuid, name, size, claimType, readers, use);
|
||||
}
|
||||
}
|
||||
|
||||
public DriveData(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType,
|
||||
Iterable<String> readers, Iterable<String> use) {
|
||||
super(uuid, name, size, claimType, readers, use);
|
||||
}
|
||||
}
|
|
@ -22,12 +22,9 @@ package org.jclouds.cloudsigma.domain;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.elasticstack.domain.ClaimType;
|
||||
import org.jclouds.elasticstack.domain.DriveMetrics;
|
||||
import org.jclouds.elasticstack.domain.DriveStatus;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
|
@ -35,8 +32,17 @@ import com.google.common.collect.ImmutableSet;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
|
||||
public static class Builder extends org.jclouds.elasticstack.domain.DriveInfo.Builder {
|
||||
public class DriveInfo extends Drive {
|
||||
public static class Builder extends Drive.Builder {
|
||||
|
||||
protected DriveStatus status;
|
||||
protected String user;
|
||||
protected Set<String> claimed = ImmutableSet.of();
|
||||
@Nullable
|
||||
protected String encryptionCipher;
|
||||
@Nullable
|
||||
protected String imaging;
|
||||
protected DriveMetrics metrics;
|
||||
private Boolean autoexpanding;
|
||||
private Integer bits;
|
||||
private String description;
|
||||
|
@ -48,6 +54,36 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
|
|||
private DriveType type;
|
||||
private URI url;
|
||||
|
||||
public Builder status(DriveStatus status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder user(String user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder claimed(Iterable<String> claimed) {
|
||||
this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder imaging(String imaging) {
|
||||
this.imaging = imaging;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder metrics(DriveMetrics metrics) {
|
||||
this.metrics = metrics;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder encryptionCipher(String encryptionCipher) {
|
||||
this.encryptionCipher = encryptionCipher;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder autoexpanding(Boolean autoexpanding) {
|
||||
this.autoexpanding = autoexpanding;
|
||||
return this;
|
||||
|
@ -98,55 +134,6 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder status(DriveStatus status) {
|
||||
return Builder.class.cast(super.status(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder user(String user) {
|
||||
return Builder.class.cast(super.user(user));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder claimed(Iterable<String> claimed) {
|
||||
return Builder.class.cast(super.claimed(claimed));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder imaging(String imaging) {
|
||||
return Builder.class.cast(super.imaging(imaging));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder metrics(DriveMetrics metrics) {
|
||||
return Builder.class.cast(super.metrics(metrics));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder encryptionCipher(String encryptionCipher) {
|
||||
return Builder.class.cast(super.encryptionCipher(encryptionCipher));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -191,24 +178,17 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder tags(Iterable<String> tags) {
|
||||
return Builder.class.cast(super.tags(tags));
|
||||
public Builder use(Iterable<String> use) {
|
||||
return Builder.class.cast(super.use(use));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder userMetadata(Map<String, String> userMetadata) {
|
||||
return Builder.class.cast(super.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
public static Builder fromDriveInfo(org.jclouds.elasticstack.domain.DriveInfo driveInfo) {
|
||||
return new Builder().uuid(driveInfo.getUuid()).name(driveInfo.getName()).size(driveInfo.getSize())
|
||||
.claimType(driveInfo.getClaimType()).readers(driveInfo.getReaders()).tags(driveInfo.getTags())
|
||||
.userMetadata(driveInfo.getUserMetadata()).status(driveInfo.getStatus()).user(driveInfo.getUser())
|
||||
.claimed(driveInfo.getClaimed()).encryptionCipher(driveInfo.getEncryptionCipher())
|
||||
.imaging(driveInfo.getImaging()).metrics(driveInfo.getMetrics());
|
||||
public static Builder fromDriveInfo(DriveInfo in) {
|
||||
return new Builder().uuid(in.getUuid()).name(in.getName()).size(in.getSize()).claimType(in.getClaimType())
|
||||
.readers(in.getReaders()).use(in.getUse()).status(in.getStatus()).user(in.getUser())
|
||||
.claimed(in.getClaimed()).encryptionCipher(in.getEncryptionCipher()).imaging(in.getImaging())
|
||||
.metrics(in.getMetrics()).autoexpanding(in.getAutoexpanding()).bits(in.getBits())
|
||||
.description(in.getDescription()).encryptionKey(in.getEncryptionKey()).free(in.getFree())
|
||||
.installNotes(in.getInstallNotes()).type(in.getType()).url(in.getUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,12 +196,21 @@ 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, metrics, autoexpanding, bits, description, driveType, encryptionKey, free,
|
||||
installNotes, os, type, url);
|
||||
}
|
||||
return new DriveInfo(uuid, name, size, claimType, readers, use, status, user, claimed, encryptionCipher,
|
||||
imaging, metrics, autoexpanding, bits, description, driveType, encryptionKey, free, installNotes, os,
|
||||
type, url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected final DriveStatus status;
|
||||
protected final String user;
|
||||
protected final Set<String> claimed;
|
||||
@Nullable
|
||||
protected final String encryptionCipher;
|
||||
@Nullable
|
||||
protected final String imaging;
|
||||
protected final DriveMetrics metrics;
|
||||
private final Boolean autoexpanding;
|
||||
private final Integer bits;
|
||||
private final String description;
|
||||
|
@ -234,12 +223,17 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
|
|||
private final URI url;
|
||||
|
||||
public DriveInfo(String uuid, String name, long size, ClaimType claimType, Iterable<String> readers,
|
||||
Iterable<String> tags, Map<String, String> userMetadata, DriveStatus status, String user, Set<String> claimed,
|
||||
String encryptionCipher, String imaging, 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,
|
||||
metrics);
|
||||
Iterable<String> use, DriveStatus status, String user, Set<String> claimed, 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, use);
|
||||
this.status = status;
|
||||
this.user = user;
|
||||
this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed"));
|
||||
this.encryptionCipher = encryptionCipher;
|
||||
this.imaging = imaging;
|
||||
this.metrics = checkNotNull(metrics, "metrics");
|
||||
this.autoexpanding = autoexpanding;
|
||||
this.bits = bits;
|
||||
this.description = description;
|
||||
|
@ -252,80 +246,54 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
|
|||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((autoexpanding == null) ? 0 : autoexpanding.hashCode());
|
||||
result = prime * result + ((bits == null) ? 0 : bits.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((driveType == null) ? 0 : driveType.hashCode());
|
||||
result = prime * result + ((encryptionKey == null) ? 0 : encryptionKey.hashCode());
|
||||
result = prime * result + ((free == null) ? 0 : free.hashCode());
|
||||
result = prime * result + ((installNotes == null) ? 0 : installNotes.hashCode());
|
||||
result = prime * result + ((os == null) ? 0 : os.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
||||
return result;
|
||||
/**
|
||||
*
|
||||
* @return current status of the drive
|
||||
*/
|
||||
public DriveStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DriveInfo other = (DriveInfo) obj;
|
||||
if (autoexpanding == null) {
|
||||
if (other.autoexpanding != null)
|
||||
return false;
|
||||
} else if (!autoexpanding.equals(other.autoexpanding))
|
||||
return false;
|
||||
if (bits == null) {
|
||||
if (other.bits != null)
|
||||
return false;
|
||||
} else if (!bits.equals(other.bits))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (driveType == null) {
|
||||
if (other.driveType != null)
|
||||
return false;
|
||||
} else if (!driveType.equals(other.driveType))
|
||||
return false;
|
||||
if (encryptionKey == null) {
|
||||
if (other.encryptionKey != null)
|
||||
return false;
|
||||
} else if (!encryptionKey.equals(other.encryptionKey))
|
||||
return false;
|
||||
if (free == null) {
|
||||
if (other.free != null)
|
||||
return false;
|
||||
} else if (!free.equals(other.free))
|
||||
return false;
|
||||
if (installNotes == null) {
|
||||
if (other.installNotes != null)
|
||||
return false;
|
||||
} else if (!installNotes.equals(other.installNotes))
|
||||
return false;
|
||||
if (os == null) {
|
||||
if (other.os != null)
|
||||
return false;
|
||||
} else if (!os.equals(other.os))
|
||||
return false;
|
||||
if (type != other.type)
|
||||
return false;
|
||||
if (url == null) {
|
||||
if (other.url != null)
|
||||
return false;
|
||||
} else if (!url.equals(other.url))
|
||||
return false;
|
||||
return true;
|
||||
/**
|
||||
*
|
||||
* @return owner of the drive
|
||||
*/
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return if drive is in use by a server, values are the server uuids
|
||||
*/
|
||||
public Set<String> getClaimed() {
|
||||
return claimed;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return either 'none' or 'aes-xts-plain' (the default)
|
||||
*/
|
||||
@Nullable
|
||||
public String getEncryptionCipher() {
|
||||
return encryptionCipher;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return i/o and request metrics for read and write ops
|
||||
*/
|
||||
public DriveMetrics getMetrics() {
|
||||
return metrics;
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
@ -373,19 +341,124 @@ public class DriveInfo extends org.jclouds.elasticstack.domain.DriveInfo {
|
|||
return type;
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", uuid=" + uuid + ", name="
|
||||
+ name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", autoexpanding=" + autoexpanding
|
||||
+ ", bits=" + bits + ", description=" + description + ", driveType=" + driveType + ", encryptionKey="
|
||||
+ encryptionKey + ", free=" + free + ", installNotes=" + installNotes + ", os=" + os + ", type=" + type
|
||||
+ ", url=" + url + "]";
|
||||
}
|
||||
|
||||
public URI getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
@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 + ((driveType == null) ? 0 : driveType.hashCode());
|
||||
result = prime * result + ((encryptionCipher == null) ? 0 : encryptionCipher.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 + ((metrics == null) ? 0 : metrics.hashCode());
|
||||
result = prime * result + ((os == null) ? 0 : os.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 + ((user == null) ? 0 : user.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 (driveType == null) {
|
||||
if (other.driveType != null)
|
||||
return false;
|
||||
} else if (!driveType.equals(other.driveType))
|
||||
return false;
|
||||
if (encryptionCipher == null) {
|
||||
if (other.encryptionCipher != null)
|
||||
return false;
|
||||
} else if (!encryptionCipher.equals(other.encryptionCipher))
|
||||
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 (metrics == null) {
|
||||
if (other.metrics != null)
|
||||
return false;
|
||||
} else if (!metrics.equals(other.metrics))
|
||||
return false;
|
||||
if (os == null) {
|
||||
if (other.os != null)
|
||||
return false;
|
||||
} else if (!os.equals(other.os))
|
||||
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 (user == null) {
|
||||
if (other.user != null)
|
||||
return false;
|
||||
} else if (!user.equals(other.user))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[size=" + size + ", claimType=" + claimType + ", readers=" + readers + ", uuid=" + uuid + ", name="
|
||||
+ name + ", use=" + use + ", status=" + status + ", user=" + user + ", claimed=" + claimed
|
||||
+ ", encryptionCipher=" + encryptionCipher + ", imaging=" + imaging + ", metrics=" + metrics + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class DriveMetrics {
|
||||
public static class Builder {
|
||||
protected long readBytes;
|
||||
protected long readRequests;
|
||||
protected long writeBytes;
|
||||
protected long writeRequests;
|
||||
|
||||
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 DriveMetrics build() {
|
||||
return new DriveMetrics(readBytes, readRequests, writeBytes, writeRequests);
|
||||
}
|
||||
}
|
||||
|
||||
protected final long readBytes;
|
||||
protected final long readRequests;
|
||||
protected final long writeBytes;
|
||||
protected final long writeRequests;
|
||||
|
||||
public DriveMetrics(long readBytes, long readRequests, long writeBytes, long writeRequests) {
|
||||
this.readBytes = readBytes;
|
||||
this.readRequests = readRequests;
|
||||
this.writeBytes = writeBytes;
|
||||
this.writeRequests = writeRequests;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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 + (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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DriveMetrics other = (DriveMetrics) obj;
|
||||
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 "[readBytes=" + readBytes + ", readRequests=" + readRequests + ", 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.cloudsigma.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().toLowerCase();
|
||||
}
|
||||
|
||||
@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,98 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class IDEDevice extends Device {
|
||||
public static class Builder extends Device.Builder {
|
||||
private final int bus;
|
||||
private final int unit;
|
||||
|
||||
public Builder(int bus, int unit) {
|
||||
this.bus = bus;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device build() {
|
||||
return new IDEDevice(uuid, mediaType, bus, unit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final int bus;
|
||||
private final int unit;
|
||||
|
||||
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;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + bus;
|
||||
result = prime * result + unit;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
IDEDevice other = (IDEDevice) obj;
|
||||
if (bus != other.bus)
|
||||
return false;
|
||||
if (unit != other.unit)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return String.format("ide:%d:%d", bus, unit);
|
||||
}
|
||||
|
||||
public int getBus() {
|
||||
return bus;
|
||||
}
|
||||
|
||||
public int getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + getId() + ", driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Item {
|
||||
public static class Builder {
|
||||
protected String uuid;
|
||||
protected String name;
|
||||
protected Set<String> use = ImmutableSet.of();
|
||||
|
||||
public Builder uuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder use(Iterable<String> use) {
|
||||
this.use = ImmutableSet.copyOf(checkNotNull(use, "use"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item build() {
|
||||
return new Item(uuid, name, use);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((use == null) ? 0 : use.hashCode());
|
||||
result = prime * result + ((uuid == null) ? 0 : uuid.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;
|
||||
Builder other = (Builder) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (use == null) {
|
||||
if (other.use != null)
|
||||
return false;
|
||||
} else if (!use.equals(other.use))
|
||||
return false;
|
||||
if (uuid == null) {
|
||||
if (other.uuid != null)
|
||||
return false;
|
||||
} else if (!uuid.equals(other.uuid))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected final String uuid;
|
||||
protected final String name;
|
||||
protected final Set<String> use;
|
||||
|
||||
public Item(@Nullable String uuid, String name, Iterable<String> use) {
|
||||
this.uuid = uuid;
|
||||
this.name = checkNotNull(name, "name");
|
||||
this.use = ImmutableSet.copyOf(checkNotNull(use, "use"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return uuid of the item.
|
||||
*/
|
||||
@Nullable
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return name of the item
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return list of use
|
||||
*/
|
||||
public Set<String> getUse() {
|
||||
return use;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((use == null) ? 0 : use.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;
|
||||
Item other = (Item) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (use == null) {
|
||||
if (other.use != null)
|
||||
return false;
|
||||
} else if (!use.equals(other.use))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[uuid=" + uuid + ", name=" + name + ", use=" + use + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Media type - set to 'cdrom' to simulate a cdrom, set to 'disk' or leave unset to simulate a hard
|
||||
* disk.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum MediaType {
|
||||
DISK, CDROM, UNRECOGNIZED;
|
||||
|
||||
public String value() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static MediaType fromValue(String type) {
|
||||
try {
|
||||
return valueOf(checkNotNull(type, "type").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum Model {
|
||||
E1000, RTl8139, VIRTIO, UNRECOGNIZED;
|
||||
|
||||
public String value() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static Model fromValue(String model) {
|
||||
try {
|
||||
return valueOf(checkNotNull(model, "model").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class NIC {
|
||||
public static class Builder {
|
||||
private String dhcp;
|
||||
private Model model;
|
||||
private String vlan;
|
||||
private String mac;
|
||||
// TODO cloudsigma specific
|
||||
private Set<String> block = ImmutableSet.of();
|
||||
|
||||
public Builder dhcp(String dhcp) {
|
||||
this.dhcp = dhcp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder model(Model model) {
|
||||
this.model = model;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vlan(String vlan) {
|
||||
this.vlan = vlan;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder mac(String mac) {
|
||||
this.mac = mac;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder block(Iterable<String> block) {
|
||||
this.block = ImmutableSet.copyOf(checkNotNull(block, "block"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public NIC build() {
|
||||
return new NIC(dhcp, model, vlan, mac, block);
|
||||
}
|
||||
}
|
||||
|
||||
private final String dhcp;
|
||||
private final Model model;
|
||||
private final String vlan;
|
||||
private final String mac;
|
||||
private final Set<String> block;
|
||||
|
||||
public NIC(@Nullable String dhcp, Model model, @Nullable String vlan, @Nullable String mac, Iterable<String> block) {
|
||||
this.dhcp = dhcp;
|
||||
this.model = checkNotNull(model, "model");
|
||||
this.vlan = vlan;
|
||||
this.mac = mac;
|
||||
this.block = ImmutableSet.copyOf(checkNotNull(block, "block"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The IP address offered by DHCP to network interface 0. If unset, no address is
|
||||
* offered. Set to 'auto' to allocate a temporary IP at boot.
|
||||
*/
|
||||
public String getDhcp() {
|
||||
return dhcp;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Create network interface with given type (use 'e1000' as default value; 'rtl8139' or
|
||||
* 'virtio' are also available).
|
||||
*/
|
||||
public Model getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The VLAN to which the network interface is attached.
|
||||
*/
|
||||
public String getVlan() {
|
||||
return vlan;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The MAC address of the network interface. If unset, a randomly generated address is
|
||||
* used. If set, should be unique on the VLAN.
|
||||
*/
|
||||
public String getMac() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
// TODO undocumented
|
||||
public Set<String> getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((block == null) ? 0 : block.hashCode());
|
||||
result = prime * result + ((dhcp == null) ? 0 : dhcp.hashCode());
|
||||
result = prime * result + ((mac == null) ? 0 : mac.hashCode());
|
||||
result = prime * result + ((model == null) ? 0 : model.hashCode());
|
||||
result = prime * result + ((vlan == null) ? 0 : vlan.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;
|
||||
NIC other = (NIC) obj;
|
||||
if (block == null) {
|
||||
if (other.block != null)
|
||||
return false;
|
||||
} else if (!block.equals(other.block))
|
||||
return false;
|
||||
if (dhcp == null) {
|
||||
if (other.dhcp != null)
|
||||
return false;
|
||||
} else if (!dhcp.equals(other.dhcp))
|
||||
return false;
|
||||
if (mac == null) {
|
||||
if (other.mac != null)
|
||||
return false;
|
||||
} else if (!mac.equals(other.mac))
|
||||
return false;
|
||||
if (model != other.model)
|
||||
return false;
|
||||
if (vlan == null) {
|
||||
if (other.vlan != null)
|
||||
return false;
|
||||
} else if (!vlan.equals(other.vlan))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[dhcp=" + dhcp + ", model=" + model + ", vlan=" + vlan + ", mac=" + mac + ", block=" + block + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class SCSIDevice extends Device {
|
||||
public static class Builder extends Device.Builder {
|
||||
private final int unit;
|
||||
|
||||
public Builder(int unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device build() {
|
||||
return new SCSIDevice(uuid, mediaType, unit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final int bus = 0;
|
||||
private final int unit;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + bus;
|
||||
result = prime * result + unit;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
SCSIDevice other = (SCSIDevice) obj;
|
||||
if (bus != other.bus)
|
||||
return false;
|
||||
if (unit != other.unit)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getBus() {
|
||||
return bus;
|
||||
}
|
||||
|
||||
public int getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return String.format("scsi:%d:%d", bus, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + getId() + ", driveUuid=" + driveUuid + ", mediaType=" + mediaType + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,293 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.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.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Server extends Item {
|
||||
|
||||
public static class Builder extends Item.Builder {
|
||||
protected int cpu;
|
||||
protected Integer smp;
|
||||
protected int mem;
|
||||
protected boolean persistent;
|
||||
protected Map<String, ? extends Device> devices = ImmutableMap.of();
|
||||
protected Set<String> bootDeviceIds = ImmutableSet.of();
|
||||
protected List<NIC> nics = ImmutableList.of();
|
||||
protected VNC vnc;
|
||||
// TODO cloudsigma specific
|
||||
protected String description;
|
||||
|
||||
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 devices(Map<String, ? extends Device> devices) {
|
||||
this.devices = ImmutableMap.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 vnc(VNC vnc) {
|
||||
this.vnc = vnc;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
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 use(Iterable<String> use) {
|
||||
return Builder.class.cast(super.use(use));
|
||||
}
|
||||
|
||||
public Server build() {
|
||||
return new Server(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, use, nics, vnc, description);
|
||||
}
|
||||
|
||||
public static Builder fromServer(Server in) {
|
||||
return new Builder().uuid(in.getUuid()).name(in.getName()).cpu(in.getCpu()).mem(in.getMem())
|
||||
.persistent(in.isPersistent()).description(in.getDescription()).devices(in.getDevices())
|
||||
.bootDeviceIds(in.getBootDeviceIds()).use(in.getUse()).nics(in.getNics()).vnc(in.getVnc());
|
||||
}
|
||||
}
|
||||
|
||||
protected final int cpu;
|
||||
protected final Integer smp;
|
||||
protected final int mem;
|
||||
protected final boolean persistent;
|
||||
@Nullable
|
||||
protected final Map<String, Device> devices;
|
||||
protected final Set<String> bootDeviceIds;
|
||||
protected final List<NIC> nics;
|
||||
protected final VNC vnc;
|
||||
@Nullable
|
||||
private final String description;
|
||||
|
||||
public Server(@Nullable String uuid, String name, int cpu, @Nullable Integer smp, int mem, boolean persistent,
|
||||
Map<String, ? extends Device> devices, Iterable<String> bootDeviceIds, Iterable<String> use,
|
||||
Iterable<NIC> nics, VNC vnc, String description) {
|
||||
super(uuid, name, use);
|
||||
this.cpu = cpu;
|
||||
this.smp = smp;
|
||||
this.mem = mem;
|
||||
this.persistent = persistent;
|
||||
this.devices = ImmutableMap.copyOf(checkNotNull(devices, "devices"));
|
||||
this.bootDeviceIds = ImmutableSet.copyOf(checkNotNull(bootDeviceIds, "bootDeviceIds"));
|
||||
this.nics = ImmutableList.copyOf(checkNotNull(nics, "nics"));
|
||||
this.vnc = checkNotNull(vnc, "vnc");
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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 devices present, mapped by id
|
||||
*/
|
||||
public Map<String, 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;
|
||||
}
|
||||
|
||||
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 + ((smp == null) ? 0 : smp.hashCode());
|
||||
result = prime * result + ((vnc == null) ? 0 : vnc.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;
|
||||
Server other = (Server) obj;
|
||||
if (bootDeviceIds == null) {
|
||||
if (other.bootDeviceIds != 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 (smp == null) {
|
||||
if (other.smp != null)
|
||||
return false;
|
||||
} else if (!smp.equals(other.smp))
|
||||
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 + ", use=" + use + ", cpu=" + cpu + ", smp=" + smp + ", mem=" + mem
|
||||
+ ", persistent=" + persistent + ", devices=" + devices + ", bootDeviceIds=" + bootDeviceIds + ", nics="
|
||||
+ nics + ", vnc=" + vnc + ", description=" + description + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,258 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ServerInfo extends Server {
|
||||
|
||||
public static class Builder extends Server.Builder {
|
||||
protected ServerStatus status;
|
||||
protected Date started;
|
||||
protected String user;
|
||||
protected ServerMetrics metrics;
|
||||
|
||||
public Builder status(ServerStatus status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder started(Date started) {
|
||||
this.started = started;
|
||||
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) {
|
||||
return Builder.class.cast(super.vnc(vnc));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder description(String description) {
|
||||
return Builder.class.cast(super.description(description));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 use(Iterable<String> use) {
|
||||
return Builder.class.cast(super.use(use));
|
||||
}
|
||||
|
||||
public ServerInfo build() {
|
||||
return new ServerInfo(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, use, nics, vnc,
|
||||
description, status, started, user, metrics);
|
||||
}
|
||||
}
|
||||
|
||||
protected final ServerStatus status;
|
||||
@Nullable
|
||||
protected final Date started;
|
||||
@Nullable
|
||||
protected final String user;
|
||||
protected final ServerMetrics metrics;
|
||||
|
||||
public ServerInfo(String uuid, String name, int cpu, Integer smp, int mem, boolean persistent,
|
||||
Map<String, ? extends Device> devices, Iterable<String> bootDeviceIds, Iterable<String> use,
|
||||
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, use, nics, vnc, description);
|
||||
this.status = status;
|
||||
this.started = started;
|
||||
this.user = user;
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return active | stopped | paused | dumped | dead
|
||||
*/
|
||||
public ServerStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
// TODO undocumented
|
||||
public Date getStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return metrics, if the server is running, or null
|
||||
*/
|
||||
@Nullable
|
||||
public ServerMetrics getMetrics() {
|
||||
return metrics;
|
||||
}
|
||||
|
||||
// TODO undocumented
|
||||
/**
|
||||
*
|
||||
* @return owner of the server.
|
||||
*/
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.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 + ((user == null) ? 0 : user.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;
|
||||
ServerInfo other = (ServerInfo) obj;
|
||||
if (metrics == null) {
|
||||
if (other.metrics != null)
|
||||
return false;
|
||||
} else if (!metrics.equals(other.metrics))
|
||||
return false;
|
||||
if (started == null) {
|
||||
if (other.started != null)
|
||||
return false;
|
||||
} else if (!started.equals(other.started))
|
||||
return false;
|
||||
if (status != other.status)
|
||||
return false;
|
||||
if (user == null) {
|
||||
if (other.user != null)
|
||||
return false;
|
||||
} else if (!user.equals(other.user))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[cpu=" + cpu + ", smp=" + smp + ", mem=" + mem + ", persistent=" + persistent + ", devices=" + devices
|
||||
+ ", bootDeviceIds=" + bootDeviceIds + ", nics=" + nics + ", vnc=" + vnc + ", uuid=" + uuid + ", name="
|
||||
+ name + ", use=" + use + ", status=" + status + ", started=" + started + ", user=" + user + ", metrics="
|
||||
+ metrics + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ServerMetrics {
|
||||
|
||||
public static class Builder {
|
||||
protected long txPackets;
|
||||
protected long tx;
|
||||
protected long rxPackets;
|
||||
protected long rx;
|
||||
protected Map<String, DriveMetrics> driveMetrics = ImmutableMap.<String, DriveMetrics> of();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public Builder driveMetrics(Map<String, ? extends DriveMetrics> driveMetrics) {
|
||||
this.driveMetrics = ImmutableMap.copyOf(checkNotNull(driveMetrics, "driveMetrics"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerMetrics build() {
|
||||
return new ServerMetrics(tx, txPackets, rx, rxPackets, driveMetrics);
|
||||
}
|
||||
}
|
||||
|
||||
protected final long txPackets;
|
||||
protected final long tx;
|
||||
protected final long rxPackets;
|
||||
protected final long rx;
|
||||
protected final Map<String, DriveMetrics> driveMetrics;
|
||||
|
||||
public ServerMetrics(long tx, long txPackets, long rx, long rxPackets, Map<String, DriveMetrics> driveMetrics) {
|
||||
this.txPackets = txPackets;
|
||||
this.tx = tx;
|
||||
this.rxPackets = rxPackets;
|
||||
this.rx = rx;
|
||||
this.driveMetrics = ImmutableMap.copyOf(checkNotNull(driveMetrics, "driveMetrics"));
|
||||
}
|
||||
|
||||
// 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 keyed on device id ex. {@code ide:0:0}
|
||||
*/
|
||||
public Map<String, DriveMetrics> getDriveMetrics() {
|
||||
return driveMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((driveMetrics == null) ? 0 : driveMetrics.hashCode());
|
||||
result = prime * result + (int) (rx ^ (rx >>> 32));
|
||||
result = prime * result + (int) (rxPackets ^ (rxPackets >>> 32));
|
||||
result = prime * result + (int) (tx ^ (tx >>> 32));
|
||||
result = prime * result + (int) (txPackets ^ (txPackets >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ServerMetrics other = (ServerMetrics) obj;
|
||||
if (driveMetrics == null) {
|
||||
if (other.driveMetrics != null)
|
||||
return false;
|
||||
} else if (!driveMetrics.equals(other.driveMetrics))
|
||||
return false;
|
||||
if (rx != other.rx)
|
||||
return false;
|
||||
if (rxPackets != other.rxPackets)
|
||||
return false;
|
||||
if (tx != other.tx)
|
||||
return false;
|
||||
if (txPackets != other.txPackets)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[ txPackets=" + txPackets + ", tx=" + tx + ", rxPackets=" + rxPackets + ", rx=" + rx + ", driveMetrics="
|
||||
+ driveMetrics + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public enum ServerStatus {
|
||||
ACTIVE, STOPPED, PAUSED, DUMPED, DEAD, UNRECOGNIZED;
|
||||
public String value() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static ServerStatus fromValue(String status) {
|
||||
try {
|
||||
return valueOf(checkNotNull(status, "status").toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.domain;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class VNC {
|
||||
@Nullable
|
||||
private final String ip;
|
||||
@Nullable
|
||||
private final String password;
|
||||
private final boolean tls;
|
||||
|
||||
public VNC(String ip, String password, boolean tls) {
|
||||
this.ip = ip;
|
||||
this.password = password;
|
||||
this.tls = tls;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return IP address for overlay VNC access on port 5900. Set to 'auto', to reuse nic:0:dhcp if
|
||||
* available, or otherwise allocate a temporary IP at boot.
|
||||
*/
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Password for VNC access. If unset, VNC is disabled.
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Set to 'on' to require VeNCrypt-style TLS auth in addition to the password. If this is
|
||||
* unset, only unencrypted VNC is available.
|
||||
*/
|
||||
public boolean isTls() {
|
||||
return tls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((ip == null) ? 0 : ip.hashCode());
|
||||
result = prime * result + ((password == null) ? 0 : password.hashCode());
|
||||
result = prime * result + (tls ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
VNC other = (VNC) obj;
|
||||
if (ip == null) {
|
||||
if (other.ip != null)
|
||||
return false;
|
||||
} else if (!ip.equals(other.ip))
|
||||
return false;
|
||||
if (password == null) {
|
||||
if (other.password != null)
|
||||
return false;
|
||||
} else if (!password.equals(other.password))
|
||||
return false;
|
||||
if (tls != other.tls)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[ip=" + ip + ", password=" + password + ", tls=" + tls + "]";
|
||||
}
|
||||
}
|
|
@ -19,40 +19,37 @@
|
|||
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import static org.jclouds.util.Utils.renameKey;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elasticstack.domain.Drive;
|
||||
import org.jclouds.cloudsigma.domain.ClaimType;
|
||||
import org.jclouds.cloudsigma.domain.Drive;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class CreateDriveRequestToMap implements Function<Drive, Map<String, String>> {
|
||||
private final org.jclouds.elasticstack.functions.CreateDriveRequestToMap baseDriveToMap;
|
||||
|
||||
@Inject
|
||||
public CreateDriveRequestToMap(org.jclouds.elasticstack.functions.CreateDriveRequestToMap baseDriveToMap) {
|
||||
this.baseDriveToMap = baseDriveToMap;
|
||||
}
|
||||
|
||||
public class BaseDriveToMap implements Function<Drive, Map<String, String>> {
|
||||
@Override
|
||||
public Map<String, String> apply(Drive from) {
|
||||
return Maps.transformEntries(renameKey(baseDriveToMap.apply(from), "tags", "use"),
|
||||
new Maps.EntryTransformer<String, String, String>() {
|
||||
|
||||
@Override
|
||||
public String transformEntry(String arg0, String arg1) {
|
||||
return "use".equals(arg0) ? arg1.replace(' ', ',') : arg1;
|
||||
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.getUse().size() != 0)
|
||||
builder.put("use", Joiner.on(' ').join(from.getUse()));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}); }
|
||||
}
|
|
@ -26,7 +26,7 @@ import java.util.Map;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
@ -36,15 +36,15 @@ import com.google.common.base.Function;
|
|||
*/
|
||||
@Singleton
|
||||
public class DriveDataToMap implements Function<DriveData, Map<String, String>> {
|
||||
private final org.jclouds.elasticstack.functions.DriveDataToMap baseDriveToMap;
|
||||
private final BaseDriveToMap baseDriveToMap;
|
||||
|
||||
@Inject
|
||||
public DriveDataToMap(org.jclouds.elasticstack.functions.DriveDataToMap baseDriveToMap) {
|
||||
public DriveDataToMap(BaseDriveToMap baseDriveToMap) {
|
||||
this.baseDriveToMap = baseDriveToMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> apply(DriveData from) {
|
||||
return renameKey(baseDriveToMap.apply(from), "tags", "use");
|
||||
return renameKey(baseDriveToMap.apply(from), "use", "use");
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ import java.util.Set;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elasticstack.domain.ServerInfo;
|
||||
import org.jclouds.cloudsigma.domain.ServerInfo;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
|
|
@ -25,7 +25,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.DriveInfo;
|
||||
import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps;
|
||||
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import 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;
|
||||
}
|
||||
}
|
|
@ -24,8 +24,8 @@ import java.util.Set;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elasticstack.domain.ServerInfo;
|
||||
import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps;
|
||||
import org.jclouds.cloudsigma.domain.ServerInfo;
|
||||
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
||||
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import 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,102 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.BlockDevice;
|
||||
import org.jclouds.cloudsigma.domain.Device;
|
||||
import org.jclouds.cloudsigma.domain.IDEDevice;
|
||||
import org.jclouds.cloudsigma.domain.MediaType;
|
||||
import org.jclouds.cloudsigma.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>, Map<String, ? extends Device>> {
|
||||
@Singleton
|
||||
public static class DeviceToId implements Function<Device, String> {
|
||||
@Override
|
||||
public String apply(Device input) {
|
||||
return input.getId();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return Maps.uniqueIndex(devices.build(), deviceToId);
|
||||
}
|
||||
|
||||
protected void addBlockDevices(Map<String, String> from, Builder<Device> devices) {
|
||||
BLOCK: for (int index : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
|
||||
String key = String.format("block:0:%d", index);
|
||||
if (!from.containsKey(key))
|
||||
break BLOCK;
|
||||
devices.add(populateBuilder(new BlockDevice.Builder(index), key, from).build());
|
||||
}
|
||||
}
|
||||
|
||||
protected void addSCSIDevices(Map<String, String> from, Builder<Device> devices) {
|
||||
SCSI: for (int unit : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
|
||||
String key = String.format("scsi:0:%d", unit);
|
||||
if (!from.containsKey(key))
|
||||
break SCSI;
|
||||
devices.add(populateBuilder(new SCSIDevice.Builder(unit), key, from).build());
|
||||
}
|
||||
}
|
||||
|
||||
protected void addIDEDevices(Map<String, String> from, Builder<Device> devices) {
|
||||
IDE: for (int bus : new int[] { 0, 1 })
|
||||
for (int unit : new int[] { 0, 1 }) {
|
||||
String key = String.format("ide:%d:%d", bus, unit);
|
||||
if (!from.containsKey(key))
|
||||
break IDE;
|
||||
devices.add(populateBuilder(new IDEDevice.Builder(bus, unit), key, from).build());
|
||||
}
|
||||
}
|
||||
|
||||
protected Device.Builder populateBuilder(Device.Builder deviceBuilder, String key, Map<String, String> from) {
|
||||
deviceBuilder.uuid(from.get(key));
|
||||
if (from.containsKey(key + ":media"))
|
||||
deviceBuilder.mediaType(MediaType.fromValue(from.get(key + ":media")));
|
||||
return deviceBuilder;
|
||||
}
|
||||
}
|
|
@ -21,15 +21,19 @@ package org.jclouds.cloudsigma.functions;
|
|||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.ClaimType;
|
||||
import org.jclouds.cloudsigma.domain.DriveInfo;
|
||||
import org.jclouds.cloudsigma.domain.DriveMetrics;
|
||||
import org.jclouds.cloudsigma.domain.DriveStatus;
|
||||
import org.jclouds.cloudsigma.domain.DriveType;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -37,20 +41,38 @@ import com.google.common.base.Splitter;
|
|||
*/
|
||||
@Singleton
|
||||
public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo> {
|
||||
private final org.jclouds.elasticstack.functions.MapToDriveInfo mapToDriveInfo;
|
||||
|
||||
@Inject
|
||||
public MapToDriveInfo(org.jclouds.elasticstack.functions.MapToDriveInfo mapToDriveInfo) {
|
||||
this.mapToDriveInfo = mapToDriveInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriveInfo apply(Map<String, String> from) {
|
||||
if (from.size() == 0)
|
||||
return null;
|
||||
DriveInfo.Builder builder = DriveInfo.Builder.fromDriveInfo(mapToDriveInfo.apply(from));
|
||||
if (from.size() == 0)
|
||||
return null;
|
||||
DriveInfo.Builder builder = new DriveInfo.Builder();
|
||||
builder.name(from.get("name"));
|
||||
if (from.containsKey("use"))
|
||||
builder.tags(Splitter.on(' ').split(from.get("use")));
|
||||
builder.use(Splitter.on(' ').split(from.get("use")));
|
||||
if (from.containsKey("status"))
|
||||
builder.status(DriveStatus.fromValue(from.get("status")));
|
||||
builder.metrics(buildMetrics(from));
|
||||
builder.user(from.get("user"));
|
||||
builder.encryptionCipher(from.get("encryption:cipher"));
|
||||
builder.uuid(from.get("drive"));
|
||||
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("readers"))
|
||||
builder.readers(Splitter.on(' ').split(from.get("readers")));
|
||||
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());
|
||||
}
|
||||
if (from.containsKey("use"))
|
||||
builder.use(Splitter.on(' ').split(from.get("use")));
|
||||
if (from.containsKey("bits"))
|
||||
builder.bits(new Integer(from.get("bits")));
|
||||
if (from.containsKey("url"))
|
||||
|
@ -69,4 +91,17 @@ public class MapToDriveInfo implements Function<Map<String, String>, DriveInfo>
|
|||
builder.type(DriveType.fromValue(from.get("type")));
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.DriveMetrics;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class MapToDriveMetrics implements Function<Map<String, String>, Map<String, ? extends DriveMetrics>> {
|
||||
|
||||
public Map<String, ? extends DriveMetrics> apply(Map<String, String> from) {
|
||||
Builder<String, DriveMetrics> builder = ImmutableMap.<String, DriveMetrics> builder();
|
||||
addIDEDevices(from, builder);
|
||||
addSCSIDevices(from, builder);
|
||||
addBlockDevices(from, builder);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected void addBlockDevices(Map<String, String> from, Builder<String, DriveMetrics> devices) {
|
||||
BLOCK: for (int index : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
|
||||
String key = String.format("block:0:%d", index);
|
||||
if (!from.containsKey(key))
|
||||
break BLOCK;
|
||||
devices.put(key, buildMetrics(key, from));
|
||||
}
|
||||
}
|
||||
|
||||
protected void addSCSIDevices(Map<String, String> from, Builder<String, DriveMetrics> devices) {
|
||||
SCSI: for (int unit : new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }) {
|
||||
String key = String.format("scsi:0:%d", unit);
|
||||
if (!from.containsKey(key))
|
||||
break SCSI;
|
||||
devices.put(key, buildMetrics(key, from));
|
||||
}
|
||||
}
|
||||
|
||||
protected void addIDEDevices(Map<String, String> from, Builder<String, DriveMetrics> devices) {
|
||||
IDE: for (int bus : new int[] { 0, 1 })
|
||||
for (int unit : new int[] { 0, 1 }) {
|
||||
String key = String.format("ide:%d:%d", bus, unit);
|
||||
if (!from.containsKey(key))
|
||||
break IDE;
|
||||
devices.put(key, buildMetrics(key, from));
|
||||
}
|
||||
}
|
||||
|
||||
protected DriveMetrics buildMetrics(String key, Map<String, String> from) {
|
||||
DriveMetrics.Builder builder = new DriveMetrics.Builder();
|
||||
if (from.containsKey(key + ":read:bytes"))
|
||||
builder.readBytes(new Long(from.get(key + ":read:bytes")));
|
||||
if (from.containsKey(key + ":read:requests"))
|
||||
builder.readRequests(new Long(from.get(key + ":read:requests")));
|
||||
if (from.containsKey(key + ":write:bytes"))
|
||||
builder.writeBytes(new Long(from.get(key + ":write:bytes")));
|
||||
if (from.containsKey(key + ":write:requests"))
|
||||
builder.writeRequests(new Long(from.get(key + ":write:requests")));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.Model;
|
||||
import org.jclouds.cloudsigma.domain.NIC;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class MapToNICs implements Function<Map<String, String>, List<NIC>> {
|
||||
|
||||
@Override
|
||||
public List<NIC> apply(Map<String, String> from) {
|
||||
ImmutableList.Builder<NIC> nics = ImmutableList.builder();
|
||||
NIC: for (int id : new int[] { 0, 1 }) {
|
||||
String key = String.format("nic:%d", id);
|
||||
if (!from.containsKey(key + ":model"))
|
||||
break NIC;
|
||||
NIC.Builder nicBuilder = new NIC.Builder();
|
||||
nicBuilder.dhcp(from.get(key + ":dhcp"));
|
||||
nicBuilder.model(Model.fromValue(from.get(key + ":model")));
|
||||
nicBuilder.vlan(from.get(key + ":vlan"));
|
||||
nicBuilder.mac(from.get(key + ":mac"));
|
||||
if (from.containsKey(key + ":block"))
|
||||
nicBuilder.block(Splitter.on(' ').split(from.get(key + ":block")));
|
||||
nics.add(nicBuilder.build());
|
||||
}
|
||||
return nics.build();
|
||||
}
|
||||
}
|
|
@ -27,12 +27,12 @@ import java.util.Map.Entry;
|
|||
import javax.inject.Inject;
|
||||
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;
|
||||
import org.jclouds.cloudsigma.domain.Device;
|
||||
import org.jclouds.cloudsigma.domain.NIC;
|
||||
import org.jclouds.cloudsigma.domain.ServerInfo;
|
||||
import org.jclouds.cloudsigma.domain.ServerMetrics;
|
||||
import org.jclouds.cloudsigma.domain.ServerStatus;
|
||||
import org.jclouds.cloudsigma.domain.VNC;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
|
@ -65,7 +65,7 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
|
|||
builder.description(from.get("description"));
|
||||
builder.persistent(Boolean.parseBoolean(from.get("persistent")));
|
||||
if (from.containsKey("use"))
|
||||
builder.tags(Splitter.on(' ').split(from.get("use")));
|
||||
builder.use(Splitter.on(' ').split(from.get("use")));
|
||||
if (from.containsKey("status"))
|
||||
builder.status(ServerStatus.fromValue(from.get("status")));
|
||||
if (from.containsKey("smp") && !"auto".equals(from.get("smp")))
|
||||
|
@ -86,7 +86,6 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
|
|||
if (entry.getKey().startsWith("user:"))
|
||||
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));
|
||||
|
|
|
@ -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.cloudsigma.functions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.DriveMetrics;
|
||||
import org.jclouds.cloudsigma.domain.ServerMetrics;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class MapToServerMetrics implements Function<Map<String, String>, ServerMetrics> {
|
||||
private final Function<Map<String, String>, Map<String, ? extends DriveMetrics>> mapToDriveMetrics;
|
||||
|
||||
@Inject
|
||||
public MapToServerMetrics(Function<Map<String, String>, Map<String, ? extends DriveMetrics>> mapToDriveMetrics) {
|
||||
this.mapToDriveMetrics = mapToDriveMetrics;
|
||||
}
|
||||
|
||||
public ServerMetrics apply(Map<String, String> from) {
|
||||
ServerMetrics.Builder metricsBuilder = new ServerMetrics.Builder();
|
||||
if (from.containsKey("tx:packets"))
|
||||
metricsBuilder.txPackets(new Long(from.get("tx:packets")));
|
||||
if (from.containsKey("tx"))
|
||||
metricsBuilder.tx(new Long(from.get("tx")));
|
||||
if (from.containsKey("rx:packets"))
|
||||
metricsBuilder.rxPackets(new Long(from.get("rx:packets")));
|
||||
if (from.containsKey("rx"))
|
||||
metricsBuilder.rx(new Long(from.get("rx")));
|
||||
metricsBuilder.driveMetrics(mapToDriveMetrics.apply(from));
|
||||
|
||||
ServerMetrics metrics = metricsBuilder.build();
|
||||
return metrics;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payload;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ReturnPayload implements Function<HttpResponse, Payload> {
|
||||
|
||||
public Payload apply(HttpResponse from) {
|
||||
return from.getPayload();
|
||||
}
|
||||
}
|
|
@ -26,9 +26,9 @@ import java.util.Map.Entry;
|
|||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elasticstack.domain.Device;
|
||||
import org.jclouds.elasticstack.domain.NIC;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.cloudsigma.domain.Device;
|
||||
import org.jclouds.cloudsigma.domain.NIC;
|
||||
import org.jclouds.cloudsigma.domain.Server;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
|
@ -74,10 +74,8 @@ public class ServerToMap implements Function<Server, Map<String, String>> {
|
|||
builder.put("vnc:password", from.getVnc().getPassword());
|
||||
if (from.getVnc().isTls())
|
||||
builder.put("vnc:tls", "on");
|
||||
if (from.getTags().size() != 0)
|
||||
builder.put("use", Joiner.on(' ').join(from.getTags()));
|
||||
for (Entry<String, String> entry : from.getUserMetadata().entrySet())
|
||||
builder.put("user:" + entry.getKey(), entry.getValue());
|
||||
if (from.getUse().size() != 0)
|
||||
builder.put("use", Joiner.on(' ').join(from.getUse()));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Sets.newTreeSet;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class SplitNewlines implements Function<HttpResponse, Set<String>> {
|
||||
private final ReturnStringIf2xx returnStringIf200;
|
||||
|
||||
@Inject
|
||||
SplitNewlines(ReturnStringIf2xx returnStringIf200) {
|
||||
this.returnStringIf200 = returnStringIf200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> apply(HttpResponse response) {
|
||||
return newTreeSet(filter(Splitter.on('\n').split(returnStringIf200.apply(response)), not(equalTo(""))));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.handlers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.util.Utils;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
/**
|
||||
* This will parse and set an appropriate exception on the command object.
|
||||
*
|
||||
* <p/>
|
||||
* Errors are returned with an appropriate HTTP status code, an X-Elastic- Error header specifying
|
||||
* the error type, and a text description in the HTTP body.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class CloudSigmaErrorHandler implements HttpErrorHandler {
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
public void handleError(HttpCommand command, HttpResponse response) {
|
||||
// it is important to always read fully and close streams
|
||||
String message = parseMessage(response);
|
||||
Exception exception = message != null ? new HttpResponseException(command, response, message)
|
||||
: new HttpResponseException(command, response);
|
||||
try {
|
||||
message = message != null ? message : String.format("%s -> %s", command.getRequest().getRequestLine(),
|
||||
response.getStatusLine());
|
||||
switch (response.getStatusCode()) {
|
||||
case 400:
|
||||
if ((command.getRequest().getEndpoint().getPath().endsWith("/info"))
|
||||
|| (message != null && message.indexOf("could not be found") != -1))
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
else
|
||||
exception = new IllegalArgumentException(message, exception);
|
||||
break;
|
||||
case 401:
|
||||
exception = new AuthorizationException(message, exception);
|
||||
break;
|
||||
case 404:
|
||||
if (!command.getRequest().getMethod().equals("DELETE")) {
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
}
|
||||
break;
|
||||
case 405:
|
||||
exception = new IllegalArgumentException(message, exception);
|
||||
break;
|
||||
case 409:
|
||||
exception = new IllegalStateException(message, exception);
|
||||
break;
|
||||
}
|
||||
} finally {
|
||||
if (response.getPayload() != null)
|
||||
Closeables.closeQuietly(response.getPayload().getInput());
|
||||
command.setException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public String parseMessage(HttpResponse response) {
|
||||
if (response.getPayload() == null)
|
||||
return null;
|
||||
try {
|
||||
return Utils.toStringAndClose(response.getPayload().getInput());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
response.getPayload().getInput().close();
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.predicates;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cloudsigma.CloudSigmaClient;
|
||||
import org.jclouds.cloudsigma.domain.DriveInfo;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class DriveClaimed implements Predicate<DriveInfo> {
|
||||
|
||||
private final CloudSigmaClient client;
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public DriveClaimed(CloudSigmaClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public boolean apply(DriveInfo drive) {
|
||||
logger.trace("looking for claims on drive %s", checkNotNull(drive, "drive"));
|
||||
drive = refresh(drive);
|
||||
if (drive == null)
|
||||
return false;
|
||||
logger.trace("%s: looking for drive claims: currently: %s", drive.getUuid(), drive.getClaimed());
|
||||
return drive.getClaimed().size() > 0;
|
||||
}
|
||||
|
||||
private DriveInfo refresh(DriveInfo drive) {
|
||||
return client.getDriveInfo(drive.getUuid());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.reference;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class CloudSigmaConstants {
|
||||
|
||||
/**
|
||||
* default VNC password used on new machines
|
||||
*/
|
||||
public static final String PROPERTY_VNC_PASSWORD = "jclouds.cloudsigma.vnc-password";
|
||||
|
||||
}
|
|
@ -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.cloudsigma.util;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.IDEDevice;
|
||||
import org.jclouds.cloudsigma.domain.Model;
|
||||
import org.jclouds.cloudsigma.domain.NIC;
|
||||
import org.jclouds.cloudsigma.domain.Server;
|
||||
import org.jclouds.cloudsigma.domain.VNC;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Servers {
|
||||
/**
|
||||
* Helper to create a small persistent server
|
||||
*
|
||||
* @param name
|
||||
* what to name the server
|
||||
* @param driveUuuid
|
||||
* id of the boot drive
|
||||
* @param vncPassword
|
||||
* password for vnc
|
||||
* @return a builder for a persistent 1Ghz 512m server with DHCP enabled network.
|
||||
*/
|
||||
public static Server.Builder small(String name, String driveUuuid, String vncPassword) {
|
||||
return new Server.Builder().name(name).cpu(1000).mem(512).persistent(true)
|
||||
.devices(ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(driveUuuid).build()))
|
||||
.bootDeviceIds(ImmutableSet.of("ide:0:0"))
|
||||
.nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).dhcp("auto").build()))
|
||||
.vnc(new VNC(null, vncPassword, false));
|
||||
}
|
||||
}
|
|
@ -30,12 +30,12 @@ import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerIn
|
|||
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
|
||||
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet;
|
||||
import org.jclouds.cloudsigma.options.CloneDriveOptions;
|
||||
import org.jclouds.elasticstack.binders.BindServerToPlainTextStringTest;
|
||||
import org.jclouds.elasticstack.domain.CreateDriveRequest;
|
||||
import org.jclouds.elasticstack.domain.Drive;
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.functions.SplitNewlines;
|
||||
import org.jclouds.cloudsigma.binders.BindServerToPlainTextStringTest;
|
||||
import org.jclouds.cloudsigma.domain.CreateDriveRequest;
|
||||
import org.jclouds.cloudsigma.domain.Drive;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
import org.jclouds.cloudsigma.domain.Server;
|
||||
import org.jclouds.cloudsigma.functions.SplitNewlines;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
|
@ -140,12 +140,12 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
|
|||
public void testCreateDrive() throws SecurityException, NoSuchMethodException, IOException {
|
||||
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)
|
||||
new CreateDriveRequest.Builder().name("foo").use(ImmutableList.of("production", "candy")).size(10000l)
|
||||
.build());
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/create HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
||||
assertPayloadEquals(httpRequest, "name foo\nsize 10000\nuse production,candy", "text/plain", false);
|
||||
assertPayloadEquals(httpRequest, "name foo\nsize 10000\nuse production candy", "text/plain", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -193,7 +193,7 @@ public class CloudSigmaAsyncClientTest extends RestClientTest<CloudSigmaAsyncCli
|
|||
public void testSetDriveData() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = CloudSigmaAsyncClient.class.getMethod("setDriveData", String.class, DriveData.class);
|
||||
GeneratedHttpRequest<CloudSigmaAsyncClient> httpRequest = processor.createRequest(method, "100",
|
||||
new DriveData.Builder().name("foo").size(10000l).tags(ImmutableList.of("production", "candy")).build());
|
||||
new DriveData.Builder().name("foo").size(10000l).use(ImmutableList.of("production", "candy")).build());
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/100/set HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
||||
|
|
|
@ -19,22 +19,52 @@
|
|||
|
||||
package org.jclouds.cloudsigma;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.cloudsigma.domain.ClaimType;
|
||||
import org.jclouds.cloudsigma.domain.CreateDriveRequest;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
import org.jclouds.cloudsigma.domain.DriveInfo;
|
||||
import org.jclouds.cloudsigma.domain.DriveStatus;
|
||||
import org.jclouds.cloudsigma.domain.DriveType;
|
||||
import org.jclouds.cloudsigma.domain.IDEDevice;
|
||||
import org.jclouds.cloudsigma.domain.Model;
|
||||
import org.jclouds.cloudsigma.domain.Server;
|
||||
import org.jclouds.cloudsigma.domain.ServerInfo;
|
||||
import org.jclouds.cloudsigma.domain.ServerStatus;
|
||||
import org.jclouds.cloudsigma.options.CloneDriveOptions;
|
||||
import org.jclouds.cloudsigma.predicates.DriveClaimed;
|
||||
import org.jclouds.cloudsigma.util.Servers;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.elasticstack.CommonElasticStackClientLiveTest;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.domain.ServerInfo;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.ssh.ExecResponse;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
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.base.Predicates;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CloudSigmaClient}
|
||||
|
@ -42,12 +72,277 @@ import com.google.common.collect.ImmutableSet;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", testName = "cloudsigma.CloudSigmaClientLiveTest")
|
||||
public class CloudSigmaClientLiveTest extends CommonElasticStackClientLiveTest<CloudSigmaClient, CloudSigmaAsyncClient> {
|
||||
public class CloudSigmaClientLiveTest {
|
||||
protected long driveSize = 8 * 1024 * 1024 * 1024l;
|
||||
protected int maxDriveImageTime = 300;
|
||||
protected String vncPassword = "Il0veVNC";
|
||||
protected CloudSigmaClient client;
|
||||
protected RestContext<CloudSigmaClient, CloudSigmaAsyncClient> context;
|
||||
protected Predicate<IPSocket> socketTester;
|
||||
|
||||
public CloudSigmaClientLiveTest() {
|
||||
provider = "cloudsigma";
|
||||
driveSize = 8 * 1024 * 1024 * 1024l;
|
||||
maxDriveImageTime = 300;
|
||||
protected String provider = "cloudsigma";
|
||||
protected String identity;
|
||||
protected String credential;
|
||||
protected String endpoint;
|
||||
protected String apiversion;
|
||||
protected Predicate<DriveInfo> driveNotClaimed;
|
||||
|
||||
protected void setupCredentials() {
|
||||
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
||||
credential = System.getProperty("test." + provider + ".credential");
|
||||
endpoint = System.getProperty("test." + provider + ".endpoint");
|
||||
apiversion = System.getProperty("test." + provider + ".apiversion");
|
||||
}
|
||||
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
|
||||
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
|
||||
overrides.setProperty(provider + ".identity", identity);
|
||||
if (credential != null)
|
||||
overrides.setProperty(provider + ".credential", credential);
|
||||
if (endpoint != null)
|
||||
overrides.setProperty(provider + ".endpoint", endpoint);
|
||||
if (apiversion != null)
|
||||
overrides.setProperty(provider + ".apiversion", apiversion);
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@BeforeGroups(groups = "live")
|
||||
public void setupClient() {
|
||||
setupCredentials();
|
||||
Properties overrides = setupProperties();
|
||||
// context = new ComputeServiceContextFactory().createContext(provider,
|
||||
// ImmutableSet.<Module> of(new Log4JLoggingModule()),
|
||||
// overrides).getProviderSpecificContext();
|
||||
context = new RestContextFactory().createContext(provider, ImmutableSet.<Module> of(new Log4JLoggingModule()),
|
||||
overrides);
|
||||
|
||||
client = context.getApi();
|
||||
driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), maxDriveImageTime,
|
||||
1, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), maxDriveImageTime, 1,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListServers() throws Exception {
|
||||
Set<String> servers = client.listServers();
|
||||
assertNotNull(servers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListServerInfo() throws Exception {
|
||||
Set<? extends ServerInfo> servers = client.listServerInfo();
|
||||
assertNotNull(servers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServer() throws Exception {
|
||||
for (String serverUUID : client.listServers()) {
|
||||
assert !"".equals(serverUUID);
|
||||
assertNotNull(client.getServerInfo(serverUUID));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListDrives() throws Exception {
|
||||
Set<String> drives = client.listDrives();
|
||||
assertNotNull(drives);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListDriveInfo() throws Exception {
|
||||
Set<? extends DriveInfo> drives = client.listDriveInfo();
|
||||
assertNotNull(drives);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDrive() throws Exception {
|
||||
for (String driveUUID : client.listDrives()) {
|
||||
assert !"".equals(driveUUID);
|
||||
assertNotNull(client.getDriveInfo(driveUUID));
|
||||
}
|
||||
}
|
||||
|
||||
protected String prefix = System.getProperty("user.name") + ".test";
|
||||
protected DriveInfo drive;
|
||||
|
||||
@Test
|
||||
public void testCreateDrive() throws Exception {
|
||||
drive = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(driveSize).build());
|
||||
checkCreatedDrive();
|
||||
|
||||
DriveInfo newInfo = client.getDriveInfo(drive.getUuid());
|
||||
checkDriveMatchesGet(newInfo);
|
||||
|
||||
}
|
||||
|
||||
protected void checkDriveMatchesGet(DriveInfo newInfo) {
|
||||
assertEquals(newInfo.getUuid(), drive.getUuid());
|
||||
assertEquals(newInfo.getType(), DriveType.DISK);
|
||||
}
|
||||
|
||||
protected void checkCreatedDrive() {
|
||||
assertNotNull(drive.getUuid());
|
||||
assertNotNull(drive.getUser());
|
||||
assertEquals(drive.getName(), prefix);
|
||||
assertEquals(drive.getSize(), driveSize);
|
||||
assertEquals(drive.getStatus(), DriveStatus.ACTIVE);
|
||||
// for some reason, these occasionally return as 4096,1
|
||||
// assertEquals(info.getReadBytes(), 0l);
|
||||
// assertEquals(info.getWriteBytes(), 0l);
|
||||
// assertEquals(info.getReadRequests(), 0l);
|
||||
// assertEquals(info.getWriteRequests(), 0l);
|
||||
assertEquals(drive.getEncryptionCipher(), "aes-xts-plain");
|
||||
assertEquals(drive.getType(), null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateDrive")
|
||||
public void testSetDriveData() throws Exception {
|
||||
|
||||
DriveInfo drive2 = client.setDriveData(
|
||||
drive.getUuid(),
|
||||
new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous")
|
||||
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))
|
||||
.use(ImmutableSet.of("networking", "security", "gateway")).build());
|
||||
|
||||
assertNotNull(drive2.getUuid(), drive.getUuid());
|
||||
assertEquals(drive2.getName(), "rediculous");
|
||||
assertEquals(drive2.getClaimType(), ClaimType.SHARED);
|
||||
assertEquals(drive2.getReaders(), ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"));
|
||||
assertEquals(drive2.getUse(), ImmutableSet.of("networking", "security", "gateway"));
|
||||
drive = drive2;
|
||||
}
|
||||
|
||||
protected ServerInfo server;
|
||||
|
||||
@Test(dependsOnMethods = "testSetDriveData")
|
||||
public void testCreateAndStartServer() throws Exception {
|
||||
Logger.getAnonymousLogger().info("preparing drive");
|
||||
prepareDrive();
|
||||
|
||||
Server serverRequest = Servers.small(prefix, drive.getUuid(), vncPassword).build();
|
||||
|
||||
Logger.getAnonymousLogger().info("starting server");
|
||||
server = client.createServer(serverRequest);
|
||||
client.startServer(server.getUuid());
|
||||
server = client.getServerInfo(server.getUuid());
|
||||
checkStartedServer();
|
||||
|
||||
Server newInfo = client.getServerInfo(server.getUuid());
|
||||
checkServerMatchesGet(newInfo);
|
||||
|
||||
}
|
||||
|
||||
protected void checkServerMatchesGet(Server newInfo) {
|
||||
assertEquals(newInfo.getUuid(), server.getUuid());
|
||||
}
|
||||
|
||||
protected void checkStartedServer() {
|
||||
System.out.println(new Gson().toJson(server));
|
||||
assertNotNull(server.getUuid());
|
||||
assertNotNull(server.getUser());
|
||||
assertEquals(server.getName(), prefix);
|
||||
assertEquals(server.isPersistent(), true);
|
||||
assertEquals(server.getDevices(),
|
||||
ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build()));
|
||||
assertEquals(server.getBootDeviceIds(), ImmutableSet.of("ide:0:0"));
|
||||
assertEquals(server.getNics().get(0).getDhcp(), server.getVnc().getIp());
|
||||
assertEquals(server.getNics().get(0).getModel(), Model.E1000);
|
||||
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateAndStartServer")
|
||||
public void testConnectivity() throws Exception {
|
||||
Logger.getAnonymousLogger().info("awaiting vnc");
|
||||
assert socketTester.apply(new IPSocket(server.getVnc().getIp(), 5900)) : server;
|
||||
Logger.getAnonymousLogger().info("awaiting ssh");
|
||||
assert socketTester.apply(new IPSocket(server.getNics().get(0).getDhcp(), 22)) : server;
|
||||
doConnectViaSsh(server, getSshCredentials(server));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testConnectivity")
|
||||
public void testLifeCycle() throws Exception {
|
||||
client.stopServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);
|
||||
|
||||
client.startServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);
|
||||
|
||||
client.resetServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);
|
||||
|
||||
client.shutdownServer(server.getUuid());
|
||||
// behavior on shutdown depends on how your server OS is set up to respond to an ACPI power
|
||||
// button signal
|
||||
assert (client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE || client.getServerInfo(
|
||||
server.getUuid()).getStatus() == ServerStatus.STOPPED);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testLifeCycle")
|
||||
public void testSetServerConfiguration() throws Exception {
|
||||
client.stopServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);
|
||||
|
||||
ServerInfo server2 = client.setServerConfiguration(
|
||||
server.getUuid(),
|
||||
Server.Builder.fromServer(server).name("rediculous")
|
||||
.use(ImmutableSet.of("networking", "security", "gateway")).build());
|
||||
|
||||
assertNotNull(server2.getUuid(), server.getUuid());
|
||||
assertEquals(server2.getName(), "rediculous");
|
||||
checkUse(server2);
|
||||
server = server2;
|
||||
}
|
||||
|
||||
protected void checkUse(ServerInfo server2) {
|
||||
// bug where use aren't updated
|
||||
assertEquals(server2.getUse(), ImmutableSet.<String> of());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testSetServerConfiguration")
|
||||
public void testDestroyServer() throws Exception {
|
||||
client.destroyServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()), null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testDestroyServer")
|
||||
public void testDestroyDrive() throws Exception {
|
||||
client.destroyDrive(drive.getUuid());
|
||||
assertEquals(client.getDriveInfo(drive.getUuid()), null);
|
||||
}
|
||||
|
||||
protected void doConnectViaSsh(Server server, Credentials creds) throws IOException {
|
||||
SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class)
|
||||
.create(new IPSocket(server.getVnc().getIp(), 22), creds);
|
||||
try {
|
||||
ssh.connect();
|
||||
ExecResponse hello = ssh.exec("echo hello");
|
||||
assertEquals(hello.getOutput().trim(), "hello");
|
||||
System.err.println(ssh.exec("df -k").getOutput());
|
||||
System.err.println(ssh.exec("mount").getOutput());
|
||||
System.err.println(ssh.exec("uname -a").getOutput());
|
||||
} finally {
|
||||
if (ssh != null)
|
||||
ssh.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
try {
|
||||
client.destroyServer(server.getUuid());
|
||||
} catch (Exception e) {
|
||||
// no need to check null or anything as we swallow all
|
||||
}
|
||||
try {
|
||||
client.destroyDrive(drive.getUuid());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
if (context != null)
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -68,24 +363,10 @@ public class CloudSigmaClientLiveTest extends CommonElasticStackClientLiveTest<C
|
|||
assertNotNull(drives);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkDriveMatchesGet(org.jclouds.elasticstack.domain.DriveInfo newInfo) {
|
||||
super.checkDriveMatchesGet(newInfo);
|
||||
assertEquals(DriveInfo.class.cast(newInfo).getType(), DriveType.DISK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkCreatedDrive() {
|
||||
super.checkCreatedDrive();
|
||||
assertEquals(DriveInfo.class.cast(drive).getType(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Credentials getSshCredentials(Server server) {
|
||||
return new Credentials("cloudsigma", "cloudsigma");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareDrive() {
|
||||
client.destroyDrive(drive.getUuid());
|
||||
drive = client.cloneDrive("0b060e09-d98b-44cc-95a4-7e3a22ba1b53", drive.getName(),
|
||||
|
@ -94,10 +375,4 @@ public class CloudSigmaClientLiveTest extends CommonElasticStackClientLiveTest<C
|
|||
System.err.println("after prepare" + client.getDriveInfo(drive.getUuid()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkTagsAndMetadata(ServerInfo server2) {
|
||||
// bug where tags aren't updated
|
||||
assertEquals(server2.getTags(), ImmutableSet.<String> of());
|
||||
assertEquals(server2.getUserMetadata(), ImmutableMap.<String, String> of());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.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.cloudsigma.domain.ClaimType;
|
||||
import org.jclouds.cloudsigma.domain.Drive;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
import org.jclouds.cloudsigma.functions.BaseDriveToMap;
|
||||
import org.jclouds.cloudsigma.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.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class BindDriveDataToPlainTextStringTest {
|
||||
|
||||
private static final BindDriveDataToPlainTextString FN = Guice.createInjector(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
|
||||
}).to(BaseDriveToMap.class);
|
||||
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
|
||||
}).to(DriveDataToMap.class);
|
||||
}
|
||||
|
||||
}).getInstance(BindDriveDataToPlainTextString.class);
|
||||
|
||||
public void testSimple() {
|
||||
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
|
||||
FN.bindToRequest(request, new DriveData.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 {
|
||||
DriveData input = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||
//
|
||||
.size(8589934592l)//
|
||||
.claimType(ClaimType.SHARED)//
|
||||
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
|
||||
.use(ImmutableSet.of("tag1", "tag2"))//
|
||||
.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(BindDriveDataToPlainTextStringTest.class.getResourceAsStream("/drive_data.txt")));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.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.cloudsigma.domain.ClaimType;
|
||||
import org.jclouds.cloudsigma.domain.CreateDriveRequest;
|
||||
import org.jclouds.cloudsigma.domain.Drive;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
import org.jclouds.cloudsigma.functions.BaseDriveToMap;
|
||||
import org.jclouds.cloudsigma.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.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class BindDriveToPlainTextStringTest {
|
||||
|
||||
private static final BindDriveToPlainTextString FN = Guice.createInjector(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<Function<Drive, Map<String, String>>>() {
|
||||
}).to(BaseDriveToMap.class);
|
||||
bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() {
|
||||
}).to(DriveDataToMap.class);
|
||||
}
|
||||
|
||||
}).getInstance(BindDriveToPlainTextString.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"))//
|
||||
.use(ImmutableSet.of("tag1", "tag2"))//
|
||||
.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(BindDriveToPlainTextStringTest.class
|
||||
.getResourceAsStream("/create_drive.txt")));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.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.cloudsigma.domain.IDEDevice;
|
||||
import org.jclouds.cloudsigma.domain.Model;
|
||||
import org.jclouds.cloudsigma.domain.NIC;
|
||||
import org.jclouds.cloudsigma.domain.Server;
|
||||
import org.jclouds.cloudsigma.domain.VNC;
|
||||
import org.jclouds.cloudsigma.functions.ServerToMap;
|
||||
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 BindServerToPlainTextStringTest {
|
||||
|
||||
public static String CREATED_SERVER;
|
||||
static {
|
||||
try {
|
||||
CREATED_SERVER = Utils.toStringAndClose(BindServerToPlainTextStringTest.class
|
||||
.getResourceAsStream("/create_server.txt"));
|
||||
} catch (IOException e) {
|
||||
CREATED_SERVER = null;
|
||||
}
|
||||
}
|
||||
public static final Server SERVER = new Server.Builder()
|
||||
.name("TestServer")
|
||||
.cpu(2000)
|
||||
.mem(1024)
|
||||
.devices(
|
||||
ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid("08c92dd5-70a0-4f51-83d2-835919d254df")
|
||||
.build())).bootDeviceIds(ImmutableSet.of("ide:0:0"))
|
||||
.nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000).
|
||||
|
||||
build())).vnc(new VNC(null, "XXXXXXXX", false)).build();
|
||||
private static final BindServerToPlainTextString FN = Guice.createInjector(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<Function<Server, Map<String, String>>>() {
|
||||
}).to(ServerToMap.class);
|
||||
bind(new TypeLiteral<Function<Server, Map<String, String>>>() {
|
||||
}).to(ServerToMap.class);
|
||||
}
|
||||
|
||||
}).getInstance(BindServerToPlainTextString.class);
|
||||
|
||||
public void testSimple() throws IOException {
|
||||
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
|
||||
FN.bindToRequest(request, SERVER);
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
|
||||
assertEquals(request.getPayload().getRawContent(), CREATED_SERVER);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.ClaimType;
|
||||
import org.jclouds.cloudsigma.domain.Drive;
|
||||
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 Drive.Builder().name("foo").size(100l).build()),
|
||||
ImmutableMap.of("name", "foo", "size", "100"));
|
||||
}
|
||||
|
||||
public void testComplete() throws IOException {
|
||||
Drive one = new Drive.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||
//
|
||||
.size(8589934592l)//
|
||||
.claimType(ClaimType.SHARED)//
|
||||
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
|
||||
.use(ImmutableSet.of("tag1", "tag2"))//
|
||||
.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("use", "tag1 tag2").build()
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
}
|
|
@ -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.cloudsigma.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.ClaimType;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
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 DriveDataToMapTest {
|
||||
|
||||
private static final DriveDataToMap BASEDRIVE_TO_MAP = Guice.createInjector().getInstance(DriveDataToMap.class);
|
||||
|
||||
public void testBasics() {
|
||||
assertEquals(BASEDRIVE_TO_MAP.apply(new DriveData.Builder().name("foo").size(100l).build()),
|
||||
ImmutableMap.of("name", "foo", "size", "100"));
|
||||
}
|
||||
|
||||
public void testComplete() throws IOException {
|
||||
DriveData one = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||
//
|
||||
.size(8589934592l)//
|
||||
.claimType(ClaimType.SHARED)//
|
||||
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
|
||||
.use(ImmutableSet.of("tag1", "tag2"))//
|
||||
.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("use", "tag1 tag2").build()
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
}
|
|
@ -45,6 +45,6 @@ public class KeyValuesDelimitedByBlankLinesToDriveInfoTest {
|
|||
|
||||
public void testOne() {
|
||||
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToDriveInfoTest.class
|
||||
.getResourceAsStream("/cloudsigma/drive.txt")))), MapToDriveInfoTest.ONE);
|
||||
.getResourceAsStream("/drive.txt")))), MapToDriveInfoTest.ONE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,15 +24,15 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
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.cloudsigma.domain.Device;
|
||||
import org.jclouds.cloudsigma.domain.DriveMetrics;
|
||||
import org.jclouds.cloudsigma.domain.NIC;
|
||||
import org.jclouds.cloudsigma.domain.ServerMetrics;
|
||||
import org.jclouds.cloudsigma.functions.MapToDevices;
|
||||
import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId;
|
||||
import org.jclouds.cloudsigma.functions.MapToDriveMetrics;
|
||||
import org.jclouds.cloudsigma.functions.MapToNICs;
|
||||
import org.jclouds.cloudsigma.functions.MapToServerMetrics;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.testng.annotations.Test;
|
||||
|
|
|
@ -47,6 +47,6 @@ public class ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSetTest {
|
|||
|
||||
public void testOne() {
|
||||
assertEquals(FN.apply(new HttpResponse(200, "", Payloads.newInputStreamPayload(MapToDriveInfoTest.class
|
||||
.getResourceAsStream("/cloudsigma/drive.txt")))), ImmutableSet.<DriveInfo> of(MapToDriveInfoTest.ONE));
|
||||
.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.cloudsigma.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")));
|
||||
}
|
||||
}
|
|
@ -24,16 +24,16 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
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.cloudsigma.domain.Device;
|
||||
import org.jclouds.cloudsigma.domain.DriveMetrics;
|
||||
import org.jclouds.cloudsigma.domain.NIC;
|
||||
import org.jclouds.cloudsigma.domain.ServerInfo;
|
||||
import org.jclouds.cloudsigma.domain.ServerMetrics;
|
||||
import org.jclouds.cloudsigma.functions.MapToDevices;
|
||||
import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId;
|
||||
import org.jclouds.cloudsigma.functions.MapToDriveMetrics;
|
||||
import org.jclouds.cloudsigma.functions.MapToNICs;
|
||||
import org.jclouds.cloudsigma.functions.MapToServerMetrics;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.testng.annotations.Test;
|
||||
|
|
|
@ -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.cloudsigma.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");
|
||||
}
|
||||
}
|
|
@ -25,12 +25,11 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.cloudsigma.domain.ClaimType;
|
||||
import org.jclouds.cloudsigma.domain.DriveInfo;
|
||||
import org.jclouds.cloudsigma.domain.DriveMetrics;
|
||||
import org.jclouds.cloudsigma.domain.DriveStatus;
|
||||
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;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -45,7 +44,7 @@ import com.google.common.collect.ImmutableSet;
|
|||
public class MapToDriveInfoTest {
|
||||
public static DriveInfo ONE = new DriveInfo.Builder()
|
||||
.status(DriveStatus.ACTIVE)
|
||||
.tags(ImmutableSet.of("networking", "security", "gateway"))
|
||||
.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"))
|
||||
|
@ -72,10 +71,9 @@ public class MapToDriveInfoTest {
|
|||
.free(true)//
|
||||
.type(DriveType.DISK)//
|
||||
.size(8589934592l)//
|
||||
.userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz")).build();
|
||||
.build();
|
||||
|
||||
private static final MapToDriveInfo MAP_TO_DRIVE = new MapToDriveInfo(
|
||||
new org.jclouds.elasticstack.functions.MapToDriveInfo());
|
||||
private static final MapToDriveInfo MAP_TO_DRIVE = new MapToDriveInfo();
|
||||
|
||||
public void testEmptyMapReturnsNull() {
|
||||
assertEquals(MAP_TO_DRIVE.apply(ImmutableMap.<String, String> of()), null);
|
||||
|
@ -90,7 +88,7 @@ public class MapToDriveInfoTest {
|
|||
public void testComplete() throws IOException {
|
||||
|
||||
Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply(
|
||||
Utils.toStringAndClose(MapToDriveInfoTest.class.getResourceAsStream("/cloudsigma/drive.txt"))).get(0);
|
||||
Utils.toStringAndClose(MapToDriveInfoTest.class.getResourceAsStream("/drive.txt"))).get(0);
|
||||
|
||||
assertEquals(MAP_TO_DRIVE.apply(input), ONE);
|
||||
|
||||
|
|
|
@ -25,21 +25,21 @@ 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.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps;
|
||||
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.cloudsigma.domain.DriveMetrics;
|
||||
import org.jclouds.cloudsigma.domain.IDEDevice;
|
||||
import org.jclouds.cloudsigma.domain.MediaType;
|
||||
import org.jclouds.cloudsigma.domain.Model;
|
||||
import org.jclouds.cloudsigma.domain.NIC;
|
||||
import org.jclouds.cloudsigma.domain.ServerInfo;
|
||||
import org.jclouds.cloudsigma.domain.ServerMetrics;
|
||||
import org.jclouds.cloudsigma.domain.ServerStatus;
|
||||
import org.jclouds.cloudsigma.domain.VNC;
|
||||
import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps;
|
||||
import org.jclouds.cloudsigma.functions.MapToDevices;
|
||||
import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId;
|
||||
import org.jclouds.cloudsigma.functions.MapToDriveMetrics;
|
||||
import org.jclouds.cloudsigma.functions.MapToNICs;
|
||||
import org.jclouds.cloudsigma.functions.MapToServerMetrics;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@ package org.jclouds.cloudsigma.functions;
|
|||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.elasticstack.domain.IDEDevice;
|
||||
import org.jclouds.elasticstack.domain.Model;
|
||||
import org.jclouds.elasticstack.domain.NIC;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.domain.VNC;
|
||||
import org.jclouds.cloudsigma.domain.IDEDevice;
|
||||
import org.jclouds.cloudsigma.domain.Model;
|
||||
import org.jclouds.cloudsigma.domain.NIC;
|
||||
import org.jclouds.cloudsigma.domain.Server;
|
||||
import org.jclouds.cloudsigma.domain.VNC;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cloudsigma.functions.SplitNewlines;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code NewlineDelimitedStringHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class SplitNewlinesTest {
|
||||
|
||||
static Function<HttpResponse, Set<String>> createParser() {
|
||||
return Guice.createInjector().getInstance(SplitNewlines.class);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
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,141 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.cloudsigma.handlers;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.reportMatcher;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.easymock.IArgumentMatcher;
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class CloudSigmaErrorHandlerTest {
|
||||
|
||||
@Test
|
||||
public void test400MakesIllegalArgumentException() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo"), 400, "", "Bad Request",
|
||||
IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test400MakesResourceNotFoundExceptionOnInfo() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo/info"), 400, "", "",
|
||||
ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test400MakesResourceNotFoundExceptionOnMessageNotFound() {
|
||||
assertCodeMakes(
|
||||
"GET",
|
||||
URI.create("https://cloudsigma.com/foo"),
|
||||
400,
|
||||
"",
|
||||
"errors:system Drive 8f9b42b1-26de-49ad-a3fd-d4fa06524339 could not be found. Please re-validate your entry.",
|
||||
ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test401MakesAuthorizationException() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo"), 401, "", "Unauthorized",
|
||||
AuthorizationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test404MakesResourceNotFoundException() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo"), 404, "", "Not Found",
|
||||
ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test405MakesIllegalArgumentException() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo"), 405, "", "Method Not Allowed",
|
||||
IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test409MakesIllegalStateException() {
|
||||
assertCodeMakes("GET", URI.create("https://cloudsigma.com/foo"), 409, "", "Conflict",
|
||||
IllegalStateException.class);
|
||||
}
|
||||
|
||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
|
||||
Class<? extends Exception> expected) {
|
||||
assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected);
|
||||
}
|
||||
|
||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
|
||||
String content, Class<? extends Exception> expected) {
|
||||
|
||||
CloudSigmaErrorHandler function = Guice.createInjector().getInstance(CloudSigmaErrorHandler.class);
|
||||
|
||||
HttpCommand command = createMock(HttpCommand.class);
|
||||
HttpRequest request = new HttpRequest(method, uri);
|
||||
HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Utils
|
||||
.toInputStream(content)));
|
||||
response.getPayload().getContentMetadata().setContentType(contentType);
|
||||
|
||||
expect(command.getRequest()).andReturn(request).atLeastOnce();
|
||||
command.setException(classEq(expected));
|
||||
|
||||
replay(command);
|
||||
|
||||
function.handleError(command, response);
|
||||
|
||||
verify(command);
|
||||
}
|
||||
|
||||
public static Exception classEq(final Class<? extends Exception> in) {
|
||||
reportMatcher(new IArgumentMatcher() {
|
||||
|
||||
@Override
|
||||
public void appendTo(StringBuffer buffer) {
|
||||
buffer.append("classEq(");
|
||||
buffer.append(in);
|
||||
buffer.append(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object arg) {
|
||||
return arg.getClass() == in;
|
||||
}
|
||||
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
name Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System
|
||||
size 8589934592
|
||||
claim:type shared
|
||||
readers ffffffff-ffff-ffff-ffff-ffffffffffff
|
||||
use tag1 tag2
|
|
@ -0,0 +1,11 @@
|
|||
name TestServer
|
||||
cpu 2000
|
||||
smp auto
|
||||
mem 1024
|
||||
persistent false
|
||||
boot ide:0:0
|
||||
ide:0:0 08c92dd5-70a0-4f51-83d2-835919d254df
|
||||
ide:0:0:media disk
|
||||
nic:0:model e1000
|
||||
vnc:ip auto
|
||||
vnc:password XXXXXXXX
|
|
@ -0,0 +1,5 @@
|
|||
name Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System
|
||||
size 8589934592
|
||||
claim:type shared
|
||||
readers ffffffff-ffff-ffff-ffff-ffffffffffff
|
||||
use tag1 tag2
|
|
@ -0,0 +1,170 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
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.
|
||||
====================================================================
|
||||
-->
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<!--
|
||||
For more configuration infromation and examples see the Apache
|
||||
Log4j website: http://logging.apache.org/log4j/
|
||||
-->
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
|
||||
debug="false">
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds-wire.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds-compute.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="SSHFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds-ssh.log" />
|
||||
<param name="Append" value="true" />
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||
|
||||
<!--
|
||||
The full pattern: Date MS Priority [Category]
|
||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="COMPUTEFILE" />
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCSSH" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="SSHFILE" />
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="FILE" />
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="WIREFILE" />
|
||||
</appender>
|
||||
|
||||
<!-- ================ -->
|
||||
<!-- Limit categories -->
|
||||
<!-- ================ -->
|
||||
|
||||
<category name="org.jclouds">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNC" />
|
||||
</category>
|
||||
|
||||
<category name="jclouds.headers">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
<category name="jclouds.ssh">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCSSH" />
|
||||
</category>
|
||||
|
||||
<category name="jclouds.wire">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNCWIRE" />
|
||||
</category>
|
||||
|
||||
<category name="jclouds.compute">
|
||||
<priority value="TRACE" />
|
||||
<appender-ref ref="ASYNCCOMPUTE" />
|
||||
</category>
|
||||
<!-- ======================= -->
|
||||
<!-- Setup the Root category -->
|
||||
<!-- ======================= -->
|
||||
|
||||
<root>
|
||||
<priority value="WARN" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
|
@ -0,0 +1,24 @@
|
|||
ide:0:0:write:requests 0
|
||||
boot ide:0:0
|
||||
vnc:password XXXXXXXX
|
||||
ide:0:0 403c9a86-0aab-4e47-aa95-e9768021c4c1
|
||||
ide:0:0:read:requests 0
|
||||
ide:0:0:read:bytes 0
|
||||
vnc:ip 83.222.249.221
|
||||
tx:packets 0
|
||||
tx 0
|
||||
rx 0
|
||||
smp 1
|
||||
mem 512
|
||||
nic:0:model e1000
|
||||
status active
|
||||
started 1292695612
|
||||
rx:packets 0
|
||||
user 2f6244eb-50bc-4403-847e-f03cc3706a1f
|
||||
ide:0:0:media disk
|
||||
name adriancole.test
|
||||
persistent true
|
||||
nic:0:block tcp/43594 tcp/5902 udp/5060 tcp/5900 tcp/5901 tcp/21 tcp/22 tcp/23 tcp/25 tcp/110 tcp/143 tcp/43595
|
||||
server bd98615a-6f74-4d63-ad1e-b13338b9356a
|
||||
ide:0:0:write:bytes 0
|
||||
cpu 1000
|
|
@ -0,0 +1,40 @@
|
|||
ide:0:0:write:requests 3698
|
||||
boot ide:0:0
|
||||
vnc:password HfHzVmLT
|
||||
ide:0:0 4af85ed3-0caa-4736-8a26-a33d7de0a122
|
||||
ide:0:0:read:requests 11154
|
||||
ide:0:0:read:bytes 45686784
|
||||
vnc:ip 46.20.114.124
|
||||
tx:packets 31
|
||||
tx 2550
|
||||
rx 455530
|
||||
smp 1
|
||||
mem 1024
|
||||
nic:0:model e1000
|
||||
status active
|
||||
started 1291493868
|
||||
rx:packets 7583
|
||||
user 2f6244eb-50bc-4403-847e-f03cc3706a1f
|
||||
name jo
|
||||
persistent true
|
||||
nic:0:block tcp/43594 tcp/5902 udp/5060 tcp/5900 tcp/5901 tcp/21 tcp/22 tcp/23 tcp/25 tcp/110 tcp/143 tcp/43595
|
||||
server f8bee9cd-8e4b-4a05-8593-1314e3bfe49b
|
||||
nic:0:dhcp 46.20.114.124
|
||||
ide:0:0:write:bytes 15147008
|
||||
cpu 2000
|
||||
|
||||
status stopped
|
||||
name Demo
|
||||
mem 1024
|
||||
boot ide:0:0
|
||||
vnc:password HWbjvrg2
|
||||
persistent true
|
||||
server 0f962616-2071-4173-be79-7dd084271edf
|
||||
smp auto
|
||||
nic:0:dhcp auto
|
||||
user 2f6244eb-50bc-4403-847e-f03cc3706a1f
|
||||
nic:0:model e1000
|
||||
vnc:ip auto
|
||||
ide:0:0 853bb98a-4fff-4c2f-a265-97c363f19ea5
|
||||
cpu 2000
|
||||
ide:0:0:media cdrom
|
|
@ -0,0 +1,3 @@
|
|||
7e8ab721-81c9-4cb9-a651-4cafbfe1501c
|
||||
ea6a8fdb-dab3-4d06-86c2-41a5835e6ed9
|
||||
74744450-d338-4087-b3b8-59b505110a57
|
|
@ -1,199 +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;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.elasticstack.binders.BindDriveDataToPlainTextString;
|
||||
import org.jclouds.elasticstack.binders.BindDriveToPlainTextString;
|
||||
import org.jclouds.elasticstack.binders.BindServerToPlainTextString;
|
||||
import org.jclouds.elasticstack.domain.Drive;
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.elasticstack.domain.DriveInfo;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.domain.ServerInfo;
|
||||
import org.jclouds.elasticstack.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
|
||||
import org.jclouds.elasticstack.functions.KeyValuesDelimitedByBlankLinesToServerInfo;
|
||||
import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
|
||||
import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet;
|
||||
import org.jclouds.elasticstack.functions.SplitNewlines;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to elasticstack via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see ElasticStackClient
|
||||
* @see <a href="TODO: insert URL of provider documentation" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Consumes(MediaType.TEXT_PLAIN)
|
||||
public interface CommonElasticStackAsyncClient {
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listServers()
|
||||
*/
|
||||
@GET
|
||||
@Path("/servers/list")
|
||||
@ResponseParser(SplitNewlines.class)
|
||||
ListenableFuture<Set<String>> listServers();
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listServerInfo()
|
||||
*/
|
||||
@GET
|
||||
@Path("/servers/info")
|
||||
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class)
|
||||
ListenableFuture<Set<? extends ServerInfo>> listServerInfo();
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#getServerInfo
|
||||
*/
|
||||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class)
|
||||
@Path("/servers/{uuid}/info")
|
||||
ListenableFuture<? extends ServerInfo> getServerInfo(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#createServer
|
||||
*/
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class)
|
||||
@Path("/servers/create/stopped")
|
||||
ListenableFuture<? extends ServerInfo> createServer(
|
||||
@BinderParam(BindServerToPlainTextString.class) Server createServer);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#setServerConfiguration
|
||||
*/
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class)
|
||||
@Path("/servers/{uuid}/set")
|
||||
ListenableFuture<? extends ServerInfo> setServerConfiguration(@PathParam("uuid") String uuid,
|
||||
@BinderParam(BindServerToPlainTextString.class) Server setServer);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#destroyServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/destroy")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> destroyServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#startServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/start")
|
||||
ListenableFuture<Void> startServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#stopServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/stop")
|
||||
ListenableFuture<Void> stopServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#shutdownServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/shutdown")
|
||||
ListenableFuture<Void> shutdownServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#resetServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/reset")
|
||||
ListenableFuture<Void> resetServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listDrives()
|
||||
*/
|
||||
@GET
|
||||
@Path("/drives/list")
|
||||
@ResponseParser(SplitNewlines.class)
|
||||
ListenableFuture<Set<String>> listDrives();
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listDriveInfo()
|
||||
*/
|
||||
@GET
|
||||
@Path("/drives/info")
|
||||
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class)
|
||||
ListenableFuture<Set<? extends DriveInfo>> listDriveInfo();
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#getDriveInfo
|
||||
*/
|
||||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
@Path("/drives/{uuid}/info")
|
||||
ListenableFuture<? extends DriveInfo> getDriveInfo(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#createDrive
|
||||
*/
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
@Path("/drives/create")
|
||||
ListenableFuture<? extends DriveInfo> createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#setDriveData
|
||||
*/
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
@Path("/drives/{uuid}/set")
|
||||
ListenableFuture<? extends DriveInfo> setDriveData(@PathParam("uuid") String uuid,
|
||||
@BinderParam(BindDriveDataToPlainTextString.class) DriveData setDrive);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#destroyDrive
|
||||
*/
|
||||
@POST
|
||||
@Path("/drives/{uuid}/destroy")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> destroyDrive(@PathParam("uuid") String uuid);
|
||||
|
||||
}
|
|
@ -1,179 +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;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.elasticstack.domain.Drive;
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.elasticstack.domain.DriveInfo;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.domain.ServerInfo;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to elasticstack.
|
||||
* <p/>
|
||||
*
|
||||
* @see ElasticStackAsyncClient
|
||||
* @see <a href="TODO: insert URL of elasticstack documentation" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface CommonElasticStackClient {
|
||||
/**
|
||||
* list of server uuids in your account
|
||||
*
|
||||
* @return or empty set if no servers are found
|
||||
*/
|
||||
Set<String> listServers();
|
||||
|
||||
/**
|
||||
* Get all servers info
|
||||
*
|
||||
* @return or empty set if no servers are found
|
||||
*/
|
||||
Set<? extends ServerInfo> listServerInfo();
|
||||
|
||||
/**
|
||||
* @param uuid
|
||||
* what to get
|
||||
* @return null, if not found
|
||||
*/
|
||||
ServerInfo getServerInfo(String uuid);
|
||||
|
||||
/**
|
||||
* create a new server
|
||||
*
|
||||
* @param server
|
||||
* @return newly created server
|
||||
*/
|
||||
ServerInfo createServer(Server server);
|
||||
|
||||
/**
|
||||
* set server configuration
|
||||
*
|
||||
* @param uuid
|
||||
* what server to change
|
||||
* @param serverData
|
||||
* what values to change
|
||||
* @return new data
|
||||
*/
|
||||
ServerInfo setServerConfiguration(String uuid, Server server);
|
||||
|
||||
/**
|
||||
* Destroy a server
|
||||
*
|
||||
* @param uuid
|
||||
* what to destroy
|
||||
*/
|
||||
void destroyServer(String uuid);
|
||||
|
||||
/**
|
||||
* Start a server
|
||||
*
|
||||
* @param uuid
|
||||
* what to start
|
||||
*/
|
||||
void startServer(String uuid);
|
||||
|
||||
/**
|
||||
* Stop a server
|
||||
* <p/>
|
||||
* Kills the server immediately, equivalent to a power failure. Server reverts to a stopped
|
||||
* status if it is persistent and is automatically destroyed otherwise.
|
||||
*
|
||||
* @param uuid
|
||||
* what to stop
|
||||
*/
|
||||
void stopServer(String uuid);
|
||||
|
||||
/**
|
||||
* Shutdown a server
|
||||
* <p/>
|
||||
* Sends the server an ACPI power-down event. Server reverts to a stopped status if it is
|
||||
* persistent and is automatically destroyed otherwise.
|
||||
* <h4>note</h4> behaviour on shutdown depends on how your server OS is set up to respond to an
|
||||
* ACPI power button signal.
|
||||
*
|
||||
* @param uuid
|
||||
* what to shutdown
|
||||
*/
|
||||
void shutdownServer(String uuid);
|
||||
|
||||
/**
|
||||
* Reset a server
|
||||
*
|
||||
* @param uuid
|
||||
* what to reset
|
||||
*/
|
||||
void resetServer(String uuid);
|
||||
|
||||
/**
|
||||
* list of drive uuids in your account
|
||||
*
|
||||
* @return or empty set if no drives are found
|
||||
*/
|
||||
Set<String> listDrives();
|
||||
|
||||
/**
|
||||
* Get all drives info
|
||||
*
|
||||
* @return or empty set if no drives are found
|
||||
*/
|
||||
Set<? extends DriveInfo> listDriveInfo();
|
||||
|
||||
/**
|
||||
* @param uuid
|
||||
* what to get
|
||||
* @return null, if not found
|
||||
*/
|
||||
DriveInfo getDriveInfo(String uuid);
|
||||
|
||||
/**
|
||||
* create a new drive
|
||||
*
|
||||
* @param createDrive
|
||||
* required parameters: name, size
|
||||
* @return newly created drive
|
||||
*/
|
||||
DriveInfo createDrive(Drive createDrive);
|
||||
|
||||
/**
|
||||
* set extra drive data
|
||||
*
|
||||
* @param uuid
|
||||
* what drive to change
|
||||
* @param driveData
|
||||
* what values to change
|
||||
* @return new data
|
||||
*/
|
||||
DriveInfo setDriveData(String uuid, DriveData driveData);
|
||||
|
||||
/**
|
||||
* Destroy a drive
|
||||
*
|
||||
* @param uuid
|
||||
* what to delete
|
||||
*/
|
||||
void destroyDrive(String uuid);
|
||||
|
||||
}
|
|
@ -19,19 +19,31 @@
|
|||
|
||||
package org.jclouds.elasticstack;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.elasticstack.binders.BindDriveDataToPlainTextString;
|
||||
import org.jclouds.elasticstack.binders.BindDriveToPlainTextString;
|
||||
import org.jclouds.elasticstack.binders.BindServerToPlainTextString;
|
||||
import org.jclouds.elasticstack.domain.Drive;
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.elasticstack.domain.DriveInfo;
|
||||
import org.jclouds.elasticstack.domain.ImageConversionType;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.domain.ServerInfo;
|
||||
import org.jclouds.elasticstack.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
|
||||
import org.jclouds.elasticstack.functions.KeyValuesDelimitedByBlankLinesToServerInfo;
|
||||
import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
|
||||
import org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet;
|
||||
import org.jclouds.elasticstack.functions.ReturnPayload;
|
||||
import org.jclouds.elasticstack.functions.SplitNewlines;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
|
@ -53,7 +65,140 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Consumes(MediaType.TEXT_PLAIN)
|
||||
public interface ElasticStackAsyncClient extends CommonElasticStackAsyncClient {
|
||||
public interface ElasticStackAsyncClient {
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listServers()
|
||||
*/
|
||||
@GET
|
||||
@Path("/servers/list")
|
||||
@ResponseParser(SplitNewlines.class)
|
||||
ListenableFuture<Set<String>> listServers();
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listServerInfo()
|
||||
*/
|
||||
@GET
|
||||
@Path("/servers/info")
|
||||
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class)
|
||||
ListenableFuture<Set<? extends ServerInfo>> listServerInfo();
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#getServerInfo
|
||||
*/
|
||||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class)
|
||||
@Path("/servers/{uuid}/info")
|
||||
ListenableFuture<? extends ServerInfo> getServerInfo(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#createServer
|
||||
*/
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class)
|
||||
@Path("/servers/create/stopped")
|
||||
ListenableFuture<? extends ServerInfo> createServer(
|
||||
@BinderParam(BindServerToPlainTextString.class) Server createServer);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#setServerConfiguration
|
||||
*/
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToServerInfo.class)
|
||||
@Path("/servers/{uuid}/set")
|
||||
ListenableFuture<? extends ServerInfo> setServerConfiguration(@PathParam("uuid") String uuid,
|
||||
@BinderParam(BindServerToPlainTextString.class) Server setServer);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#destroyServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/destroy")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> destroyServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#startServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/start")
|
||||
ListenableFuture<Void> startServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#stopServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/stop")
|
||||
ListenableFuture<Void> stopServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#shutdownServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/shutdown")
|
||||
ListenableFuture<Void> shutdownServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#resetServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{uuid}/reset")
|
||||
ListenableFuture<Void> resetServer(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listDrives()
|
||||
*/
|
||||
@GET
|
||||
@Path("/drives/list")
|
||||
@ResponseParser(SplitNewlines.class)
|
||||
ListenableFuture<Set<String>> listDrives();
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#listDriveInfo()
|
||||
*/
|
||||
@GET
|
||||
@Path("/drives/info")
|
||||
@ResponseParser(ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class)
|
||||
ListenableFuture<Set<? extends DriveInfo>> listDriveInfo();
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#getDriveInfo
|
||||
*/
|
||||
@GET
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
@Path("/drives/{uuid}/info")
|
||||
ListenableFuture<? extends DriveInfo> getDriveInfo(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#createDrive
|
||||
*/
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
@Path("/drives/create")
|
||||
ListenableFuture<? extends DriveInfo> createDrive(@BinderParam(BindDriveToPlainTextString.class) Drive createDrive);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#setDriveData
|
||||
*/
|
||||
@POST
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
@Path("/drives/{uuid}/set")
|
||||
ListenableFuture<? extends DriveInfo> setDriveData(@PathParam("uuid") String uuid,
|
||||
@BinderParam(BindDriveDataToPlainTextString.class) DriveData setDrive);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#destroyDrive
|
||||
*/
|
||||
@POST
|
||||
@Path("/drives/{uuid}/destroy")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> destroyDrive(@PathParam("uuid") String uuid);
|
||||
|
||||
/**
|
||||
* @see ElasticStackClient#createAndStartServer
|
||||
|
|
|
@ -19,9 +19,13 @@
|
|||
|
||||
package org.jclouds.elasticstack;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.elasticstack.domain.Drive;
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.elasticstack.domain.DriveInfo;
|
||||
import org.jclouds.elasticstack.domain.ImageConversionType;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.domain.ServerInfo;
|
||||
|
@ -36,7 +40,143 @@ import org.jclouds.io.Payload;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface ElasticStackClient extends CommonElasticStackClient {
|
||||
public interface ElasticStackClient {
|
||||
/**
|
||||
* list of server uuids in your account
|
||||
*
|
||||
* @return or empty set if no servers are found
|
||||
*/
|
||||
Set<String> listServers();
|
||||
|
||||
/**
|
||||
* Get all servers info
|
||||
*
|
||||
* @return or empty set if no servers are found
|
||||
*/
|
||||
Set<? extends ServerInfo> listServerInfo();
|
||||
|
||||
/**
|
||||
* @param uuid
|
||||
* what to get
|
||||
* @return null, if not found
|
||||
*/
|
||||
ServerInfo getServerInfo(String uuid);
|
||||
|
||||
/**
|
||||
* create a new server
|
||||
*
|
||||
* @param server
|
||||
* @return newly created server
|
||||
*/
|
||||
ServerInfo createServer(Server server);
|
||||
|
||||
/**
|
||||
* set server configuration
|
||||
*
|
||||
* @param uuid
|
||||
* what server to change
|
||||
* @param serverData
|
||||
* what values to change
|
||||
* @return new data
|
||||
*/
|
||||
ServerInfo setServerConfiguration(String uuid, Server server);
|
||||
|
||||
/**
|
||||
* Destroy a server
|
||||
*
|
||||
* @param uuid
|
||||
* what to destroy
|
||||
*/
|
||||
void destroyServer(String uuid);
|
||||
|
||||
/**
|
||||
* Start a server
|
||||
*
|
||||
* @param uuid
|
||||
* what to start
|
||||
*/
|
||||
void startServer(String uuid);
|
||||
|
||||
/**
|
||||
* Stop a server
|
||||
* <p/>
|
||||
* Kills the server immediately, equivalent to a power failure. Server reverts to a stopped
|
||||
* status if it is persistent and is automatically destroyed otherwise.
|
||||
*
|
||||
* @param uuid
|
||||
* what to stop
|
||||
*/
|
||||
void stopServer(String uuid);
|
||||
|
||||
/**
|
||||
* Shutdown a server
|
||||
* <p/>
|
||||
* Sends the server an ACPI power-down event. Server reverts to a stopped status if it is
|
||||
* persistent and is automatically destroyed otherwise.
|
||||
* <h4>note</h4> behaviour on shutdown depends on how your server OS is set up to respond to an
|
||||
* ACPI power button signal.
|
||||
*
|
||||
* @param uuid
|
||||
* what to shutdown
|
||||
*/
|
||||
void shutdownServer(String uuid);
|
||||
|
||||
/**
|
||||
* Reset a server
|
||||
*
|
||||
* @param uuid
|
||||
* what to reset
|
||||
*/
|
||||
void resetServer(String uuid);
|
||||
|
||||
/**
|
||||
* list of drive uuids in your account
|
||||
*
|
||||
* @return or empty set if no drives are found
|
||||
*/
|
||||
Set<String> listDrives();
|
||||
|
||||
/**
|
||||
* Get all drives info
|
||||
*
|
||||
* @return or empty set if no drives are found
|
||||
*/
|
||||
Set<? extends DriveInfo> listDriveInfo();
|
||||
|
||||
/**
|
||||
* @param uuid
|
||||
* what to get
|
||||
* @return null, if not found
|
||||
*/
|
||||
DriveInfo getDriveInfo(String uuid);
|
||||
|
||||
/**
|
||||
* create a new drive
|
||||
*
|
||||
* @param createDrive
|
||||
* required parameters: name, size
|
||||
* @return newly created drive
|
||||
*/
|
||||
DriveInfo createDrive(Drive createDrive);
|
||||
|
||||
/**
|
||||
* set extra drive data
|
||||
*
|
||||
* @param uuid
|
||||
* what drive to change
|
||||
* @param driveData
|
||||
* what values to change
|
||||
* @return new data
|
||||
*/
|
||||
DriveInfo setDriveData(String uuid, DriveData driveData);
|
||||
|
||||
/**
|
||||
* Destroy a drive
|
||||
*
|
||||
* @param uuid
|
||||
* what to delete
|
||||
*/
|
||||
void destroyDrive(String uuid);
|
||||
|
||||
/**
|
||||
* create and start a new server
|
||||
|
|
|
@ -37,7 +37,7 @@ public class ElasticStackPropertiesBuilder extends PropertiesBuilder {
|
|||
protected Properties defaultProperties() {
|
||||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_API_VERSION, "1.0");
|
||||
properties.setProperty(PROPERTY_API_VERSION, "IL9vs34d");
|
||||
properties.setProperty(PROPERTY_VNC_PASSWORD, "IL9vs34d");
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.jclouds.compute.domain.Volume;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.elasticstack.CommonElasticStackClient;
|
||||
import org.jclouds.elasticstack.ElasticStackAsyncClient;
|
||||
import org.jclouds.elasticstack.ElasticStackClient;
|
||||
import org.jclouds.elasticstack.compute.ElasticStackComputeServiceAdapter;
|
||||
|
@ -129,12 +128,6 @@ public class ElasticStackComputeServiceContextModule
|
|||
}.getType());
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected CommonElasticStackClient convert(ElasticStackClient in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<DriveInfo> supplyDriveUnclaimed(DriveClaimed driveClaimed,
|
||||
|
|
|
@ -46,8 +46,6 @@ public class Server extends Item {
|
|||
protected Set<String> bootDeviceIds = ImmutableSet.of();
|
||||
protected List<NIC> nics = ImmutableList.of();
|
||||
protected VNC vnc;
|
||||
// TODO cloudsigma specific
|
||||
protected String description;
|
||||
|
||||
public Builder cpu(int cpu) {
|
||||
this.cpu = cpu;
|
||||
|
@ -89,11 +87,6 @@ public class Server extends Item {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -127,15 +120,13 @@ public class Server extends Item {
|
|||
}
|
||||
|
||||
public Server build() {
|
||||
return new Server(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics,
|
||||
vnc, description);
|
||||
return new Server(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, vnc);
|
||||
}
|
||||
|
||||
public static Builder fromServer(Server in) {
|
||||
return new Builder().uuid(in.getUuid()).name(in.getName()).cpu(in.getCpu()).mem(in.getMem())
|
||||
.persistent(in.isPersistent()).description(in.getDescription()).devices(in.getDevices())
|
||||
.bootDeviceIds(in.getBootDeviceIds()).tags(in.getTags()).userMetadata(in.getUserMetadata())
|
||||
.nics(in.getNics()).vnc(in.getVnc());
|
||||
.persistent(in.isPersistent()).devices(in.getDevices()).bootDeviceIds(in.getBootDeviceIds())
|
||||
.tags(in.getTags()).userMetadata(in.getUserMetadata()).nics(in.getNics()).vnc(in.getVnc());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,12 +139,10 @@ public class Server extends Item {
|
|||
protected final Set<String> bootDeviceIds;
|
||||
protected final List<NIC> nics;
|
||||
protected final VNC vnc;
|
||||
@Nullable
|
||||
private final String description;
|
||||
|
||||
public Server(@Nullable String uuid, String name, int cpu, @Nullable 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) {
|
||||
Map<String, String> userMetadata, Iterable<NIC> nics, VNC vnc) {
|
||||
super(uuid, name, tags, userMetadata);
|
||||
this.cpu = cpu;
|
||||
this.smp = smp;
|
||||
|
@ -163,7 +152,6 @@ public class Server extends Item {
|
|||
this.bootDeviceIds = ImmutableSet.copyOf(checkNotNull(bootDeviceIds, "bootDeviceIds"));
|
||||
this.nics = ImmutableList.copyOf(checkNotNull(nics, "nics"));
|
||||
this.vnc = checkNotNull(vnc, "vnc");
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,18 +212,12 @@ public class Server extends Item {
|
|||
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());
|
||||
|
@ -261,11 +243,6 @@ public class Server extends Item {
|
|||
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;
|
||||
|
@ -297,8 +274,7 @@ public class Server extends Item {
|
|||
public String toString() {
|
||||
return "[uuid=" + uuid + ", name=" + name + ", tags=" + tags + ", userMetadata=" + userMetadata + ", cpu=" + cpu
|
||||
+ ", smp=" + smp + ", mem=" + mem + ", persistent=" + persistent + ", devices=" + devices
|
||||
+ ", bootDeviceIds=" + bootDeviceIds + ", nics=" + nics + ", vnc=" + vnc + ", description=" + description
|
||||
+ "]";
|
||||
+ ", bootDeviceIds=" + bootDeviceIds + ", nics=" + nics + ", vnc=" + vnc + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -120,14 +120,6 @@ public class ServerInfo extends Server {
|
|||
return Builder.class.cast(super.vnc(vnc));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder description(String description) {
|
||||
return Builder.class.cast(super.description(description));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -162,7 +154,7 @@ public class ServerInfo extends Server {
|
|||
|
||||
public ServerInfo build() {
|
||||
return new ServerInfo(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics,
|
||||
vnc, description, status, started, user, metrics);
|
||||
vnc, status, started, user, metrics);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,9 +167,9 @@ public class ServerInfo extends Server {
|
|||
|
||||
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);
|
||||
Map<String, String> userMetadata, Iterable<NIC> nics, VNC vnc, ServerStatus status, Date started, String user,
|
||||
@Nullable ServerMetrics metrics) {
|
||||
super(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, tags, userMetadata, nics, vnc);
|
||||
this.status = status;
|
||||
this.started = started;
|
||||
this.user = user;
|
||||
|
|
|
@ -62,7 +62,6 @@ public class MapToServerInfo implements Function<Map<String, String>, ServerInfo
|
|||
return null;
|
||||
ServerInfo.Builder builder = new ServerInfo.Builder();
|
||||
builder.name(from.get("name"));
|
||||
builder.description(from.get("description"));
|
||||
builder.persistent(Boolean.parseBoolean(from.get("persistent")));
|
||||
if (from.containsKey("tags"))
|
||||
builder.tags(Splitter.on(' ').split(from.get("tags")));
|
||||
|
|
|
@ -1,16 +1,35 @@
|
|||
/**
|
||||
*
|
||||
* 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.predicates;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.elasticstack.CommonElasticStackClient;
|
||||
import org.jclouds.elasticstack.ElasticStackClient;
|
||||
import org.jclouds.elasticstack.domain.DriveInfo;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -19,13 +38,13 @@ import com.google.inject.Inject;
|
|||
@Singleton
|
||||
public class DriveClaimed implements Predicate<DriveInfo> {
|
||||
|
||||
private final CommonElasticStackClient client;
|
||||
private final ElasticStackClient client;
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public DriveClaimed(CommonElasticStackClient client) {
|
||||
public DriveClaimed(ElasticStackClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,348 +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;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.elasticstack.domain.ClaimType;
|
||||
import org.jclouds.elasticstack.domain.CreateDriveRequest;
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.elasticstack.domain.DriveInfo;
|
||||
import org.jclouds.elasticstack.domain.DriveStatus;
|
||||
import org.jclouds.elasticstack.domain.IDEDevice;
|
||||
import org.jclouds.elasticstack.domain.Model;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.domain.ServerInfo;
|
||||
import org.jclouds.elasticstack.domain.ServerStatus;
|
||||
import org.jclouds.elasticstack.predicates.DriveClaimed;
|
||||
import org.jclouds.elasticstack.util.Servers;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.ssh.ExecResponse;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
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.base.Predicates;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CommonElasticStackClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true)
|
||||
public abstract class CommonElasticStackClientLiveTest<S extends CommonElasticStackClient, A extends CommonElasticStackAsyncClient> {
|
||||
|
||||
protected long driveSize = 1 * 1024 * 1024 * 1024l;
|
||||
protected int maxDriveImageTime = 120;
|
||||
protected String vncPassword = "Il0veVNC";
|
||||
protected S client;
|
||||
protected RestContext<S, A> context;
|
||||
protected Predicate<IPSocket> socketTester;
|
||||
|
||||
protected String provider = "elasticstack";
|
||||
protected String identity;
|
||||
protected String credential;
|
||||
protected String endpoint;
|
||||
protected String apiversion;
|
||||
protected Predicate<DriveInfo> driveNotClaimed;
|
||||
|
||||
protected void setupCredentials() {
|
||||
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
||||
credential = System.getProperty("test." + provider + ".credential");
|
||||
endpoint = System.getProperty("test." + provider + ".endpoint");
|
||||
apiversion = System.getProperty("test." + provider + ".apiversion");
|
||||
}
|
||||
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
|
||||
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
|
||||
overrides.setProperty(provider + ".identity", identity);
|
||||
if (credential != null)
|
||||
overrides.setProperty(provider + ".credential", credential);
|
||||
if (endpoint != null)
|
||||
overrides.setProperty(provider + ".endpoint", endpoint);
|
||||
if (apiversion != null)
|
||||
overrides.setProperty(provider + ".apiversion", apiversion);
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@BeforeGroups(groups = "live")
|
||||
public void setupClient() {
|
||||
setupCredentials();
|
||||
Properties overrides = setupProperties();
|
||||
context = new ComputeServiceContextFactory().createContext(provider,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
|
||||
|
||||
client = context.getApi();
|
||||
driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), maxDriveImageTime,
|
||||
1, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), maxDriveImageTime, 1,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListServers() throws Exception {
|
||||
Set<String> servers = client.listServers();
|
||||
assertNotNull(servers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListServerInfo() throws Exception {
|
||||
Set<? extends ServerInfo> servers = client.listServerInfo();
|
||||
assertNotNull(servers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServer() throws Exception {
|
||||
for (String serverUUID : client.listServers()) {
|
||||
assert !"".equals(serverUUID);
|
||||
assertNotNull(client.getServerInfo(serverUUID));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListDrives() throws Exception {
|
||||
Set<String> drives = client.listDrives();
|
||||
assertNotNull(drives);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListDriveInfo() throws Exception {
|
||||
Set<? extends DriveInfo> drives = client.listDriveInfo();
|
||||
assertNotNull(drives);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDrive() throws Exception {
|
||||
for (String driveUUID : client.listDrives()) {
|
||||
assert !"".equals(driveUUID);
|
||||
assertNotNull(client.getDriveInfo(driveUUID));
|
||||
}
|
||||
}
|
||||
|
||||
protected String prefix = System.getProperty("user.name") + ".test";
|
||||
protected DriveInfo drive;
|
||||
|
||||
@Test
|
||||
public void testCreateDrive() throws Exception {
|
||||
drive = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(driveSize).build());
|
||||
checkCreatedDrive();
|
||||
|
||||
DriveInfo newInfo = client.getDriveInfo(drive.getUuid());
|
||||
checkDriveMatchesGet(newInfo);
|
||||
|
||||
}
|
||||
|
||||
protected void checkDriveMatchesGet(DriveInfo newInfo) {
|
||||
assertEquals(newInfo.getUuid(), drive.getUuid());
|
||||
}
|
||||
|
||||
protected void checkCreatedDrive() {
|
||||
assertNotNull(drive.getUuid());
|
||||
assertNotNull(drive.getUser());
|
||||
assertEquals(drive.getName(), prefix);
|
||||
assertEquals(drive.getSize(), driveSize);
|
||||
assertEquals(drive.getStatus(), DriveStatus.ACTIVE);
|
||||
// for some reason, these occasionally return as 4096,1
|
||||
// assertEquals(info.getReadBytes(), 0l);
|
||||
// assertEquals(info.getWriteBytes(), 0l);
|
||||
// assertEquals(info.getReadRequests(), 0l);
|
||||
// assertEquals(info.getWriteRequests(), 0l);
|
||||
assertEquals(drive.getEncryptionCipher(), "aes-xts-plain");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateDrive")
|
||||
public void testSetDriveData() throws Exception {
|
||||
|
||||
DriveInfo drive2 = client.setDriveData(
|
||||
drive.getUuid(),
|
||||
new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous")
|
||||
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))
|
||||
.tags(ImmutableSet.of("networking", "security", "gateway"))
|
||||
.userMetadata(ImmutableMap.of("foo", "bar")).build());
|
||||
|
||||
assertNotNull(drive2.getUuid(), drive.getUuid());
|
||||
assertEquals(drive2.getName(), "rediculous");
|
||||
assertEquals(drive2.getClaimType(), ClaimType.SHARED);
|
||||
assertEquals(drive2.getReaders(), ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"));
|
||||
assertEquals(drive2.getTags(), ImmutableSet.of("networking", "security", "gateway"));
|
||||
assertEquals(drive2.getUserMetadata(), ImmutableMap.of("foo", "bar"));
|
||||
drive = drive2;
|
||||
}
|
||||
|
||||
protected ServerInfo server;
|
||||
|
||||
protected abstract void prepareDrive();
|
||||
|
||||
@Test(dependsOnMethods = "testSetDriveData")
|
||||
public void testCreateAndStartServer() throws Exception {
|
||||
Logger.getAnonymousLogger().info("preparing drive");
|
||||
prepareDrive();
|
||||
|
||||
Server serverRequest = Servers.small(prefix, drive.getUuid(), vncPassword).build();
|
||||
|
||||
Logger.getAnonymousLogger().info("starting server");
|
||||
server = client.createServer(serverRequest);
|
||||
client.startServer(server.getUuid());
|
||||
server = client.getServerInfo(server.getUuid());
|
||||
checkStartedServer();
|
||||
|
||||
Server newInfo = client.getServerInfo(server.getUuid());
|
||||
checkServerMatchesGet(newInfo);
|
||||
|
||||
}
|
||||
|
||||
protected void checkServerMatchesGet(Server newInfo) {
|
||||
assertEquals(newInfo.getUuid(), server.getUuid());
|
||||
}
|
||||
|
||||
protected void checkStartedServer() {
|
||||
System.out.println(new Gson().toJson(server));
|
||||
assertNotNull(server.getUuid());
|
||||
assertNotNull(server.getUser());
|
||||
assertEquals(server.getName(), prefix);
|
||||
assertEquals(server.isPersistent(), true);
|
||||
assertEquals(server.getDevices(),
|
||||
ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build()));
|
||||
assertEquals(server.getBootDeviceIds(), ImmutableSet.of("ide:0:0"));
|
||||
assertEquals(server.getNics().get(0).getDhcp(), server.getVnc().getIp());
|
||||
assertEquals(server.getNics().get(0).getModel(), Model.E1000);
|
||||
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateAndStartServer")
|
||||
public void testConnectivity() throws Exception {
|
||||
Logger.getAnonymousLogger().info("awaiting vnc");
|
||||
assert socketTester.apply(new IPSocket(server.getVnc().getIp(), 5900)) : server;
|
||||
Logger.getAnonymousLogger().info("awaiting ssh");
|
||||
assert socketTester.apply(new IPSocket(server.getNics().get(0).getDhcp(), 22)) : server;
|
||||
doConnectViaSsh(server, getSshCredentials(server));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testConnectivity")
|
||||
public void testLifeCycle() throws Exception {
|
||||
client.stopServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);
|
||||
|
||||
client.startServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);
|
||||
|
||||
client.resetServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);
|
||||
|
||||
client.shutdownServer(server.getUuid());
|
||||
// behavior on shutdown depends on how your server OS is set up to respond to an ACPI power
|
||||
// button signal
|
||||
assert (client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE || client.getServerInfo(
|
||||
server.getUuid()).getStatus() == ServerStatus.STOPPED);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testLifeCycle")
|
||||
public void testSetServerConfiguration() throws Exception {
|
||||
client.stopServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);
|
||||
|
||||
ServerInfo server2 = client.setServerConfiguration(
|
||||
server.getUuid(),
|
||||
Server.Builder.fromServer(server).name("rediculous")
|
||||
.tags(ImmutableSet.of("networking", "security", "gateway"))
|
||||
.userMetadata(ImmutableMap.of("foo", "bar")).build());
|
||||
|
||||
assertNotNull(server2.getUuid(), server.getUuid());
|
||||
assertEquals(server2.getName(), "rediculous");
|
||||
checkTagsAndMetadata(server2);
|
||||
server = server2;
|
||||
}
|
||||
|
||||
protected void checkTagsAndMetadata(ServerInfo server2) {
|
||||
assertEquals(server2.getTags(), ImmutableSet.of("networking", "security", "gateway"));
|
||||
assertEquals(server2.getUserMetadata(), ImmutableMap.of("foo", "bar"));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testSetServerConfiguration")
|
||||
public void testDestroyServer() throws Exception {
|
||||
client.destroyServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()), null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testDestroyServer")
|
||||
public void testDestroyDrive() throws Exception {
|
||||
client.destroyDrive(drive.getUuid());
|
||||
assertEquals(client.getDriveInfo(drive.getUuid()), null);
|
||||
}
|
||||
|
||||
protected void doConnectViaSsh(Server server, Credentials creds) throws IOException {
|
||||
SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class)
|
||||
.create(new IPSocket(server.getVnc().getIp(), 22), creds);
|
||||
try {
|
||||
ssh.connect();
|
||||
ExecResponse hello = ssh.exec("echo hello");
|
||||
assertEquals(hello.getOutput().trim(), "hello");
|
||||
System.err.println(ssh.exec("df -k").getOutput());
|
||||
System.err.println(ssh.exec("mount").getOutput());
|
||||
System.err.println(ssh.exec("uname -a").getOutput());
|
||||
} finally {
|
||||
if (ssh != null)
|
||||
ssh.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Credentials getSshCredentials(Server server);
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
try {
|
||||
client.destroyServer(server.getUuid());
|
||||
} catch (Exception e) {
|
||||
// no need to check null or anything as we swallow all
|
||||
}
|
||||
try {
|
||||
client.destroyDrive(drive.getUuid());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
if (context != null)
|
||||
context.close();
|
||||
}
|
||||
}
|
|
@ -19,27 +19,332 @@
|
|||
|
||||
package org.jclouds.elasticstack;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.elasticstack.domain.ClaimType;
|
||||
import org.jclouds.elasticstack.domain.CreateDriveRequest;
|
||||
import org.jclouds.elasticstack.domain.DriveData;
|
||||
import org.jclouds.elasticstack.domain.DriveInfo;
|
||||
import org.jclouds.elasticstack.domain.DriveStatus;
|
||||
import org.jclouds.elasticstack.domain.IDEDevice;
|
||||
import org.jclouds.elasticstack.domain.ImageConversionType;
|
||||
import org.jclouds.elasticstack.domain.Model;
|
||||
import org.jclouds.elasticstack.domain.Server;
|
||||
import org.jclouds.elasticstack.domain.ServerInfo;
|
||||
import org.jclouds.elasticstack.domain.ServerStatus;
|
||||
import org.jclouds.elasticstack.predicates.DriveClaimed;
|
||||
import org.jclouds.elasticstack.util.Servers;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.ssh.ExecResponse;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ElasticStackClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", testName = "elasticstack.ElasticStackClientLiveTest")
|
||||
public class ElasticStackClientLiveTest extends
|
||||
CommonElasticStackClientLiveTest<ElasticStackClient, ElasticStackAsyncClient> {
|
||||
public class ElasticStackClientLiveTest {
|
||||
|
||||
protected long driveSize = 1 * 1024 * 1024 * 1024l;
|
||||
protected int maxDriveImageTime = 120;
|
||||
protected String vncPassword = "Il0veVNC";
|
||||
protected ElasticStackClient client;
|
||||
protected RestContext<ElasticStackClient, ElasticStackAsyncClient> context;
|
||||
protected Predicate<IPSocket> socketTester;
|
||||
|
||||
protected String provider = "elasticstack";
|
||||
protected String identity;
|
||||
protected String credential;
|
||||
protected String endpoint;
|
||||
protected String apiversion;
|
||||
protected Predicate<DriveInfo> driveNotClaimed;
|
||||
|
||||
protected void setupCredentials() {
|
||||
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
||||
credential = System.getProperty("test." + provider + ".credential");
|
||||
endpoint = System.getProperty("test." + provider + ".endpoint");
|
||||
apiversion = System.getProperty("test." + provider + ".apiversion");
|
||||
}
|
||||
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
|
||||
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
|
||||
overrides.setProperty(provider + ".identity", identity);
|
||||
if (credential != null)
|
||||
overrides.setProperty(provider + ".credential", credential);
|
||||
if (endpoint != null)
|
||||
overrides.setProperty(provider + ".endpoint", endpoint);
|
||||
if (apiversion != null)
|
||||
overrides.setProperty(provider + ".apiversion", apiversion);
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@BeforeGroups(groups = "live")
|
||||
public void setupClient() {
|
||||
setupCredentials();
|
||||
Properties overrides = setupProperties();
|
||||
context = new ComputeServiceContextFactory().createContext(provider,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
|
||||
|
||||
client = context.getApi();
|
||||
driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), maxDriveImageTime,
|
||||
1, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), maxDriveImageTime, 1,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListServers() throws Exception {
|
||||
Set<String> servers = client.listServers();
|
||||
assertNotNull(servers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListServerInfo() throws Exception {
|
||||
Set<? extends ServerInfo> servers = client.listServerInfo();
|
||||
assertNotNull(servers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServer() throws Exception {
|
||||
for (String serverUUID : client.listServers()) {
|
||||
assert !"".equals(serverUUID);
|
||||
assertNotNull(client.getServerInfo(serverUUID));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListDrives() throws Exception {
|
||||
Set<String> drives = client.listDrives();
|
||||
assertNotNull(drives);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListDriveInfo() throws Exception {
|
||||
Set<? extends DriveInfo> drives = client.listDriveInfo();
|
||||
assertNotNull(drives);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDrive() throws Exception {
|
||||
for (String driveUUID : client.listDrives()) {
|
||||
assert !"".equals(driveUUID);
|
||||
assertNotNull(client.getDriveInfo(driveUUID));
|
||||
}
|
||||
}
|
||||
|
||||
protected String prefix = System.getProperty("user.name") + ".test";
|
||||
protected DriveInfo drive;
|
||||
|
||||
@Test
|
||||
public void testCreateDrive() throws Exception {
|
||||
drive = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(driveSize).build());
|
||||
checkCreatedDrive();
|
||||
|
||||
DriveInfo newInfo = client.getDriveInfo(drive.getUuid());
|
||||
checkDriveMatchesGet(newInfo);
|
||||
|
||||
}
|
||||
|
||||
protected void checkDriveMatchesGet(DriveInfo newInfo) {
|
||||
assertEquals(newInfo.getUuid(), drive.getUuid());
|
||||
}
|
||||
|
||||
protected void checkCreatedDrive() {
|
||||
assertNotNull(drive.getUuid());
|
||||
assertNotNull(drive.getUser());
|
||||
assertEquals(drive.getName(), prefix);
|
||||
assertEquals(drive.getSize(), driveSize);
|
||||
assertEquals(drive.getStatus(), DriveStatus.ACTIVE);
|
||||
// for some reason, these occasionally return as 4096,1
|
||||
// assertEquals(info.getReadBytes(), 0l);
|
||||
// assertEquals(info.getWriteBytes(), 0l);
|
||||
// assertEquals(info.getReadRequests(), 0l);
|
||||
// assertEquals(info.getWriteRequests(), 0l);
|
||||
assertEquals(drive.getEncryptionCipher(), "aes-xts-plain");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateDrive")
|
||||
public void testSetDriveData() throws Exception {
|
||||
|
||||
DriveInfo drive2 = client.setDriveData(
|
||||
drive.getUuid(),
|
||||
new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous")
|
||||
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))
|
||||
.tags(ImmutableSet.of("networking", "security", "gateway"))
|
||||
.userMetadata(ImmutableMap.of("foo", "bar")).build());
|
||||
|
||||
assertNotNull(drive2.getUuid(), drive.getUuid());
|
||||
assertEquals(drive2.getName(), "rediculous");
|
||||
assertEquals(drive2.getClaimType(), ClaimType.SHARED);
|
||||
assertEquals(drive2.getReaders(), ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"));
|
||||
assertEquals(drive2.getTags(), ImmutableSet.of("networking", "security", "gateway"));
|
||||
assertEquals(drive2.getUserMetadata(), ImmutableMap.of("foo", "bar"));
|
||||
drive = drive2;
|
||||
}
|
||||
|
||||
protected ServerInfo server;
|
||||
|
||||
@Test(dependsOnMethods = "testSetDriveData")
|
||||
public void testCreateAndStartServer() throws Exception {
|
||||
Logger.getAnonymousLogger().info("preparing drive");
|
||||
prepareDrive();
|
||||
|
||||
Server serverRequest = Servers.small(prefix, drive.getUuid(), vncPassword).build();
|
||||
|
||||
Logger.getAnonymousLogger().info("starting server");
|
||||
server = client.createServer(serverRequest);
|
||||
client.startServer(server.getUuid());
|
||||
server = client.getServerInfo(server.getUuid());
|
||||
checkStartedServer();
|
||||
|
||||
Server newInfo = client.getServerInfo(server.getUuid());
|
||||
checkServerMatchesGet(newInfo);
|
||||
|
||||
}
|
||||
|
||||
protected void checkServerMatchesGet(Server newInfo) {
|
||||
assertEquals(newInfo.getUuid(), server.getUuid());
|
||||
}
|
||||
|
||||
protected void checkStartedServer() {
|
||||
System.out.println(new Gson().toJson(server));
|
||||
assertNotNull(server.getUuid());
|
||||
assertNotNull(server.getUser());
|
||||
assertEquals(server.getName(), prefix);
|
||||
assertEquals(server.isPersistent(), true);
|
||||
assertEquals(server.getDevices(),
|
||||
ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build()));
|
||||
assertEquals(server.getBootDeviceIds(), ImmutableSet.of("ide:0:0"));
|
||||
assertEquals(server.getNics().get(0).getDhcp(), server.getVnc().getIp());
|
||||
assertEquals(server.getNics().get(0).getModel(), Model.E1000);
|
||||
assertEquals(server.getStatus(), ServerStatus.ACTIVE);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateAndStartServer")
|
||||
public void testConnectivity() throws Exception {
|
||||
Logger.getAnonymousLogger().info("awaiting vnc");
|
||||
assert socketTester.apply(new IPSocket(server.getVnc().getIp(), 5900)) : server;
|
||||
Logger.getAnonymousLogger().info("awaiting ssh");
|
||||
assert socketTester.apply(new IPSocket(server.getNics().get(0).getDhcp(), 22)) : server;
|
||||
doConnectViaSsh(server, getSshCredentials(server));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testConnectivity")
|
||||
public void testLifeCycle() throws Exception {
|
||||
client.stopServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);
|
||||
|
||||
client.startServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);
|
||||
|
||||
client.resetServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE);
|
||||
|
||||
client.shutdownServer(server.getUuid());
|
||||
// behavior on shutdown depends on how your server OS is set up to respond to an ACPI power
|
||||
// button signal
|
||||
assert (client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE || client.getServerInfo(
|
||||
server.getUuid()).getStatus() == ServerStatus.STOPPED);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testLifeCycle")
|
||||
public void testSetServerConfiguration() throws Exception {
|
||||
client.stopServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED);
|
||||
|
||||
ServerInfo server2 = client.setServerConfiguration(
|
||||
server.getUuid(),
|
||||
Server.Builder.fromServer(server).name("rediculous")
|
||||
.tags(ImmutableSet.of("networking", "security", "gateway"))
|
||||
.userMetadata(ImmutableMap.of("foo", "bar")).build());
|
||||
|
||||
assertNotNull(server2.getUuid(), server.getUuid());
|
||||
assertEquals(server2.getName(), "rediculous");
|
||||
checkTagsAndMetadata(server2);
|
||||
server = server2;
|
||||
}
|
||||
|
||||
protected void checkTagsAndMetadata(ServerInfo server2) {
|
||||
assertEquals(server2.getTags(), ImmutableSet.of("networking", "security", "gateway"));
|
||||
assertEquals(server2.getUserMetadata(), ImmutableMap.of("foo", "bar"));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testSetServerConfiguration")
|
||||
public void testDestroyServer() throws Exception {
|
||||
client.destroyServer(server.getUuid());
|
||||
assertEquals(client.getServerInfo(server.getUuid()), null);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testDestroyServer")
|
||||
public void testDestroyDrive() throws Exception {
|
||||
client.destroyDrive(drive.getUuid());
|
||||
assertEquals(client.getDriveInfo(drive.getUuid()), null);
|
||||
}
|
||||
|
||||
protected void doConnectViaSsh(Server server, Credentials creds) throws IOException {
|
||||
SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class)
|
||||
.create(new IPSocket(server.getVnc().getIp(), 22), creds);
|
||||
try {
|
||||
ssh.connect();
|
||||
ExecResponse hello = ssh.exec("echo hello");
|
||||
assertEquals(hello.getOutput().trim(), "hello");
|
||||
System.err.println(ssh.exec("df -k").getOutput());
|
||||
System.err.println(ssh.exec("mount").getOutput());
|
||||
System.err.println(ssh.exec("uname -a").getOutput());
|
||||
} finally {
|
||||
if (ssh != null)
|
||||
ssh.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
try {
|
||||
client.destroyServer(server.getUuid());
|
||||
} catch (Exception e) {
|
||||
// no need to check null or anything as we swallow all
|
||||
}
|
||||
try {
|
||||
client.destroyDrive(drive.getUuid());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
if (context != null)
|
||||
context.close();
|
||||
}
|
||||
|
||||
private DriveInfo drive2;
|
||||
private DriveInfo drive3;
|
||||
|
||||
|
@ -68,12 +373,10 @@ public class ElasticStackClientLiveTest extends
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Credentials getSshCredentials(Server server) {
|
||||
return new Credentials("toor", server.getVnc().getPassword());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareDrive() {
|
||||
System.err.println("before prepare" + client.getDriveInfo(drive.getUuid()));
|
||||
client.imageDrive("38df0986-4d85-4b76-b502-3878ffc80161", drive.getUuid(), ImageConversionType.GUNZIP);
|
||||
|
|
Loading…
Reference in New Issue