import static org.jclouds.cloudsigma.options.CloneDriveOptions.Builder.*; Payload payload = client.cloneDrive("drive-uuid","newName", size(2*1024*1024l));
@author Adrian Cole
public void testCloneDriveOptions() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(CloudSigmaAsyncClient.class, "cloneDrive", String.class, String.class,
CloneDriveOptions[].class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("sourceid", "newname",
new CloneDriveOptions().size(1024l)));
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/sourceid/clone HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, "name newname\nsize 1024", "text/plain", false);
}
protected void prepareDrive() {
client.destroyDrive(drive.getUuid());
drive = client.cloneDrive(imageId, drive.getName(),
new CloneDriveOptions().size(driveSize).tags("cat:mouse", "monkey:banana"));
// Block until the async clone operation has completed.
assert driveNotClaimed.apply(drive) : client.getDriveInfo(drive.getUuid());
DriveInfo clonedDrive = client.getDriveInfo(drive.getUuid());
System.err.println("after prepare" + clonedDrive);
affinityType = options.getDiskDriveAffinity();
}
logger.debug(">> imaging boot drive source(%s) bytes(%d) affinityType(%s)",
template.getImage().getId(), bootSize, affinityType);
DriveInfo drive = client.cloneDrive(template.getImage().getId(), template.getImage().getId(),
new CloneDriveOptions().size(bootSize).affinity(affinityType));
boolean success = driveNotClaimed.apply(drive);
logger.debug("<< image(%s) complete(%s)", drive.getUuid(), success);
if (!success) {
client.destroyDrive(drive.getUuid());
throw new IllegalStateException("could not image drive in time!");
affinityType = options.getDiskDriveAffinity();
}
logger.debug(">> imaging boot drive source(%s) bytes(%d) affinityType(%s)",
template.getImage().getId(), bootSize, affinityType);
DriveInfo drive = client.cloneDrive(template.getImage().getId(), template.getImage().getId(),
new CloneDriveOptions().size(bootSize).affinity(affinityType));
boolean success = driveNotClaimed.apply(drive);
logger.debug("<< image(%s) complete(%s)", drive.getUuid(), success);
if (!success) {
client.destroyDrive(drive.getUuid());
throw new IllegalStateException("could not image drive in time!");
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = GeneratedHttpRequest.class.cast(request);
CloneDriveOptions options = findOptionsInArgsOrNull(gRequest);
if (options != null) {
postParams = ImmutableMap.<String, Object> builder().putAll(postParams).putAll(options.getOptions()).build();
}
request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(Maps.transformValues(postParams, new Function<Object, String>() {
@Override
public String apply(Object input) {
}
protected void prepareDrive() {
client.destroyDrive(drive.getUuid());
drive = client.cloneDrive(imageId, drive.getName(),
new CloneDriveOptions().size(driveSize).tags("cat:mouse", "monkey:banana"));
// Block until the async clone operation has completed.
assert driveNotClaimed.apply(drive) : client.getDriveInfo(drive.getUuid());
DriveInfo clonedDrive = client.getDriveInfo(drive.getUuid());
System.err.println("after prepare" + clonedDrive);
assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected);
}
public void testWithSize() throws IOException {
String expected = "name newdrive\nsize 1024";
GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of(new CloneDriveOptions().size(1024)));
Map<String, Object> map = ImmutableMap.<String, Object> of("name", "newdrive");
assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected);
}
public void testCloneDriveOptions() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(CloudSigmaApi.class, "cloneDrive", String.class, String.class,
CloneDriveOptions[].class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("sourceid", "newname",
new CloneDriveOptions().size(1024l)));
assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/sourceid/clone HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
assertPayloadEquals(httpRequest, "name newname\nsize 1024", "text/plain", false);
affinityType = options.getDiskDriveAffinity();
}
logger.debug(">> imaging boot drive source(%s) bytes(%d) affinityType(%s)",
template.getImage().getId(), bootSize, affinityType);
DriveInfo drive = client.cloneDrive(template.getImage().getId(), template.getImage().getId(),
new CloneDriveOptions().size(bootSize).affinity(affinityType));
boolean success = driveNotClaimed.apply(drive);
logger.debug("<< image(%s) complete(%s)", drive.getUuid(), success);
if (!success) {
client.destroyDrive(drive.getUuid());
throw new IllegalStateException("could not image drive in time!");
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = GeneratedHttpRequest.class.cast(request);
CloneDriveOptions options = findOptionsInArgsOrNull(gRequest);
if (options != null) {
postParams = ImmutableMap.<String, Object> builder().putAll(postParams).putAll(options.getOptions()).build();
}
request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(Maps.transformValues(postParams, new Function<Object, String>() {
@Override
public String apply(Object input) {
Related Classes of org.jclouds.cloudsigma.options.CloneDriveOptions$Builder
Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.