mirror of https://github.com/apache/jclouds.git
Merge branch 'master' of git://github.com/jclouds/jclouds
This commit is contained in:
commit
4be6d796ac
|
@ -21,7 +21,6 @@ package org.jclouds.atmos.blobstore.integration;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
||||
|
@ -34,13 +33,12 @@ import org.testng.annotations.Test;
|
|||
public class AtmosContainerIntegrationLiveTest extends BaseContainerIntegrationTest {
|
||||
|
||||
@Override
|
||||
public void testListContainerMaxResults() throws InterruptedException,
|
||||
UnsupportedEncodingException {
|
||||
public void testListContainerMaxResults() throws InterruptedException {
|
||||
// Not currently working
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testListContainerMarker() throws InterruptedException, UnsupportedEncodingException {
|
||||
public void testListContainerMarker() throws InterruptedException {
|
||||
// Not currently working https://community.emc.com/thread/100545
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import static org.jclouds.s3.reference.S3Headers.COPY_SOURCE_IF_UNMODIFIED_SINCE
|
|||
import static org.jclouds.s3.reference.S3Headers.DEFAULT_AMAZON_HEADERTAG;
|
||||
import static org.jclouds.s3.reference.S3Headers.METADATA_DIRECTIVE;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -227,7 +226,7 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
|||
* @param eTag
|
||||
* hash representing the payload
|
||||
*/
|
||||
public CopyObjectOptions ifSourceETagMatches(String eTag) throws UnsupportedEncodingException {
|
||||
public CopyObjectOptions ifSourceETagMatches(String eTag) {
|
||||
checkState(getIfNoneMatch() == null, "ifETagDoesntMatch() is not compatible with ifETagMatches()");
|
||||
checkState(getIfModifiedSince() == null, "ifModifiedSince() is not compatible with ifETagMatches()");
|
||||
replaceHeader(COPY_SOURCE_IF_MATCH, String.format("\"%1$s\"", checkNotNull(eTag, "eTag")));
|
||||
|
@ -242,10 +241,8 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
|||
*
|
||||
* @param eTag
|
||||
* hash representing the payload
|
||||
* @throws UnsupportedEncodingException
|
||||
* if there was a problem converting this into an S3 eTag string
|
||||
*/
|
||||
public CopyObjectOptions ifSourceETagDoesntMatch(String eTag) throws UnsupportedEncodingException {
|
||||
public CopyObjectOptions ifSourceETagDoesntMatch(String eTag) {
|
||||
checkState(getIfMatch() == null, "ifETagMatches() is not compatible with ifETagDoesntMatch()");
|
||||
Preconditions.checkState(getIfUnmodifiedSince() == null,
|
||||
"ifUnmodifiedSince() is not compatible with ifETagDoesntMatch()");
|
||||
|
@ -307,7 +304,7 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
|||
/**
|
||||
* @see CopyObjectOptions#ifSourceETagMatches(String)
|
||||
*/
|
||||
public static CopyObjectOptions ifSourceETagMatches(String eTag) throws UnsupportedEncodingException {
|
||||
public static CopyObjectOptions ifSourceETagMatches(String eTag) {
|
||||
CopyObjectOptions options = new CopyObjectOptions();
|
||||
return options.ifSourceETagMatches(eTag);
|
||||
}
|
||||
|
@ -315,7 +312,7 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
|||
/**
|
||||
* @see CopyObjectOptions#ifSourceETagDoesntMatch(String)
|
||||
*/
|
||||
public static CopyObjectOptions ifSourceETagDoesntMatch(String eTag) throws UnsupportedEncodingException {
|
||||
public static CopyObjectOptions ifSourceETagDoesntMatch(String eTag) {
|
||||
CopyObjectOptions options = new CopyObjectOptions();
|
||||
return options.ifSourceETagDoesntMatch(eTag);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -155,7 +154,7 @@ public class CopyObjectOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagMatches() throws UnsupportedEncodingException {
|
||||
public void testIfETagMatches() {
|
||||
CopyObjectOptions options = new CopyObjectOptions();
|
||||
options.ifSourceETagMatches(etag);
|
||||
matchesHex(options.getIfMatch());
|
||||
|
@ -168,18 +167,18 @@ public class CopyObjectOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagMatchesStatic() throws UnsupportedEncodingException {
|
||||
public void testIfETagMatchesStatic() {
|
||||
CopyObjectOptions options = ifSourceETagMatches(etag);
|
||||
matchesHex(options.getIfMatch());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testIfETagMatchesNPE() throws UnsupportedEncodingException {
|
||||
public void testIfETagMatchesNPE() {
|
||||
ifSourceETagMatches(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testIfETagDoesntMatch() {
|
||||
CopyObjectOptions options = new CopyObjectOptions();
|
||||
options.ifSourceETagDoesntMatch(etag);
|
||||
matchesHex(options.getIfNoneMatch());
|
||||
|
@ -192,17 +191,17 @@ public class CopyObjectOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagDoesntMatchStatic() throws UnsupportedEncodingException {
|
||||
public void testIfETagDoesntMatchStatic() {
|
||||
CopyObjectOptions options = ifSourceETagDoesntMatch(etag);
|
||||
matchesHex(options.getIfNoneMatch());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testIfETagDoesntMatchNPE() throws UnsupportedEncodingException {
|
||||
public void testIfETagDoesntMatchNPE() {
|
||||
ifSourceETagDoesntMatch(null);
|
||||
}
|
||||
|
||||
private void matchesHex(String match) throws UnsupportedEncodingException {
|
||||
private void matchesHex(String match) {
|
||||
String expected = "\"" + etag + "\"";
|
||||
assertEquals(match, expected);
|
||||
}
|
||||
|
@ -213,13 +212,13 @@ public class CopyObjectOptionsTest {
|
|||
|
||||
}
|
||||
|
||||
public void testIfUnmodifiedAfterETagMatches() throws UnsupportedEncodingException {
|
||||
public void testIfUnmodifiedAfterETagMatches() {
|
||||
ifSourceETagMatches(etag).ifSourceUnmodifiedSince(now);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testIfUnmodifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testIfUnmodifiedAfterETagDoesntMatch() {
|
||||
ifSourceETagDoesntMatch(etag).ifSourceUnmodifiedSince(now);
|
||||
}
|
||||
|
||||
|
@ -230,49 +229,49 @@ public class CopyObjectOptionsTest {
|
|||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testIfModifiedAfterETagMatches() throws UnsupportedEncodingException {
|
||||
public void testIfModifiedAfterETagMatches() {
|
||||
ifSourceETagMatches(etag).ifSourceModifiedSince(now);
|
||||
|
||||
}
|
||||
|
||||
public void testIfModifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testIfModifiedAfterETagDoesntMatch() {
|
||||
ifSourceETagDoesntMatch(etag).ifSourceModifiedSince(now);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testETagMatchesAfterIfModified() throws UnsupportedEncodingException {
|
||||
public void testETagMatchesAfterIfModified() {
|
||||
ifSourceModifiedSince(now).ifSourceETagMatches(etag);
|
||||
|
||||
}
|
||||
|
||||
public void testETagMatchesAfterIfUnmodified() throws UnsupportedEncodingException {
|
||||
public void testETagMatchesAfterIfUnmodified() {
|
||||
ifSourceUnmodifiedSince(now).ifSourceETagMatches(etag);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testETagMatchesAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testETagMatchesAfterETagDoesntMatch() {
|
||||
ifSourceETagDoesntMatch(etag).ifSourceETagMatches(etag);
|
||||
}
|
||||
|
||||
public void testETagDoesntMatchAfterIfModified() throws UnsupportedEncodingException {
|
||||
public void testETagDoesntMatchAfterIfModified() {
|
||||
ifSourceModifiedSince(now).ifSourceETagDoesntMatch(etag);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testETagDoesntMatchAfterIfUnmodified() throws UnsupportedEncodingException {
|
||||
public void testETagDoesntMatchAfterIfUnmodified() {
|
||||
ifSourceUnmodifiedSince(now).ifSourceETagDoesntMatch(etag);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testETagDoesntMatchAfterETagMatches() throws UnsupportedEncodingException {
|
||||
public void testETagDoesntMatchAfterETagMatches() {
|
||||
ifSourceETagMatches(etag).ifSourceETagDoesntMatch(etag);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBuildRequestHeadersWhenMetadataNull() throws UnsupportedEncodingException {
|
||||
void testBuildRequestHeadersWhenMetadataNull() {
|
||||
CopyObjectOptions options = new CopyObjectOptions();
|
||||
options.setHeaderTag(DEFAULT_AMAZON_HEADERTAG);
|
||||
|
||||
|
@ -281,7 +280,7 @@ public class CopyObjectOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testBuildRequestHeaders() throws UnsupportedEncodingException {
|
||||
void testBuildRequestHeaders() {
|
||||
CopyObjectOptions options = ifSourceModifiedSince(now).ifSourceETagDoesntMatch(etag).overrideMetadataWith(
|
||||
goodMeta);
|
||||
options.setHeaderTag(DEFAULT_AMAZON_HEADERTAG);
|
||||
|
@ -310,7 +309,7 @@ public class CopyObjectOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testBuildRequestHeadersACL() throws UnsupportedEncodingException {
|
||||
void testBuildRequestHeadersACL() {
|
||||
CopyObjectOptions options = overrideAcl(CannedAccessPolicy.AUTHENTICATED_READ);
|
||||
options.setHeaderTag(DEFAULT_AMAZON_HEADERTAG);
|
||||
|
||||
|
|
|
@ -24,11 +24,10 @@ import static org.jclouds.s3.options.ListBucketOptions.Builder.maxResults;
|
|||
import static org.jclouds.s3.options.ListBucketOptions.Builder.withPrefix;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.jclouds.s3.reference.S3Constants;
|
||||
import org.jclouds.http.options.HttpRequestOptions;
|
||||
import org.jclouds.s3.reference.S3Constants;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
@ -47,7 +46,7 @@ public class ListBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPrefix() throws UnsupportedEncodingException {
|
||||
public void testPrefix() {
|
||||
ListBucketOptions options = new ListBucketOptions();
|
||||
options.withPrefix("test");
|
||||
assertEquals(options.buildQueryParameters().get(S3Constants.PREFIX), Collections
|
||||
|
@ -61,7 +60,7 @@ public class ListBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testOneOptionQueryString() throws UnsupportedEncodingException {
|
||||
public void testOneOptionQueryString() {
|
||||
ListBucketOptions options = new ListBucketOptions();
|
||||
options.withPrefix("test");
|
||||
Multimap<String, String> map = options.buildQueryParameters();
|
||||
|
@ -70,7 +69,7 @@ public class ListBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTwoOptionQueryString() throws UnsupportedEncodingException {
|
||||
public void testTwoOptionQueryString() {
|
||||
ListBucketOptions options = new ListBucketOptions();
|
||||
options.withPrefix("test").maxResults(1);
|
||||
Multimap<String, String> map = options.buildQueryParameters();
|
||||
|
@ -80,7 +79,7 @@ public class ListBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPrefixAndDelimiterUrlEncodingQueryString() throws UnsupportedEncodingException {
|
||||
public void testPrefixAndDelimiterUrlEncodingQueryString() {
|
||||
ListBucketOptions options = new ListBucketOptions();
|
||||
options.withPrefix("/test").delimiter("/");
|
||||
Multimap<String, String> map = options.buildQueryParameters();
|
||||
|
@ -97,19 +96,19 @@ public class ListBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPrefixStatic() throws UnsupportedEncodingException {
|
||||
public void testPrefixStatic() {
|
||||
ListBucketOptions options = withPrefix("test");
|
||||
assertEquals(options.buildQueryParameters().get(S3Constants.PREFIX), Collections
|
||||
.singletonList("test"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testPrefixNPE() throws UnsupportedEncodingException {
|
||||
public void testPrefixNPE() {
|
||||
withPrefix(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarker() throws UnsupportedEncodingException {
|
||||
public void testMarker() {
|
||||
ListBucketOptions options = new ListBucketOptions();
|
||||
options.afterMarker("test");
|
||||
assertEquals(options.buildQueryParameters().get(S3Constants.MARKER), Collections
|
||||
|
@ -123,14 +122,14 @@ public class ListBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMarkerStatic() throws UnsupportedEncodingException {
|
||||
public void testMarkerStatic() {
|
||||
ListBucketOptions options = afterMarker("test");
|
||||
assertEquals(options.buildQueryParameters().get(S3Constants.MARKER), Collections
|
||||
.singletonList("test"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testMarkerNPE() throws UnsupportedEncodingException {
|
||||
public void testMarkerNPE() {
|
||||
afterMarker(null);
|
||||
}
|
||||
|
||||
|
@ -161,7 +160,7 @@ public class ListBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDelimiter() throws UnsupportedEncodingException {
|
||||
public void testDelimiter() {
|
||||
ListBucketOptions options = new ListBucketOptions();
|
||||
options.delimiter("test");
|
||||
assertEquals(options.buildQueryParameters().get(S3Constants.DELIMITER), Collections
|
||||
|
@ -176,14 +175,14 @@ public class ListBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDelimiterStatic() throws UnsupportedEncodingException {
|
||||
public void testDelimiterStatic() {
|
||||
ListBucketOptions options = delimiter("test");
|
||||
assertEquals(options.buildQueryParameters().get(S3Constants.DELIMITER), Collections
|
||||
.singletonList("test"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testDelimiterNPE() throws UnsupportedEncodingException {
|
||||
public void testDelimiterNPE() {
|
||||
delimiter(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.s3.options;
|
|||
import static org.jclouds.s3.options.PutBucketOptions.Builder.withBucketAcl;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.jclouds.s3.domain.CannedAccessPolicy;
|
||||
import org.jclouds.s3.reference.S3Headers;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -50,7 +48,7 @@ public class PutBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testBuildRequestHeaders() throws UnsupportedEncodingException {
|
||||
void testBuildRequestHeaders() {
|
||||
|
||||
PutBucketOptions options = withBucketAcl(CannedAccessPolicy.AUTHENTICATED_READ);
|
||||
|
||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.s3.options;
|
|||
import static org.jclouds.s3.options.PutObjectOptions.Builder.withAcl;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.jclouds.s3.domain.CannedAccessPolicy;
|
||||
import org.jclouds.s3.reference.S3Headers;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -50,7 +48,7 @@ public class PutObjectOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testBuildRequestHeaders() throws UnsupportedEncodingException {
|
||||
void testBuildRequestHeaders() {
|
||||
|
||||
PutObjectOptions options = withAcl(CannedAccessPolicy.AUTHENTICATED_READ);
|
||||
options.setHeaderTag(S3Headers.DEFAULT_AMAZON_HEADERTAG);
|
||||
|
|
|
@ -28,7 +28,6 @@ import static org.testng.Assert.assertNull;
|
|||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
@ -36,6 +35,7 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jclouds.aws.domain.Region;
|
||||
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
||||
import org.jclouds.s3.S3Client;
|
||||
import org.jclouds.s3.domain.AccessControlList;
|
||||
import org.jclouds.s3.domain.AccessControlList.CanonicalUserGrantee;
|
||||
|
@ -50,7 +50,6 @@ import org.jclouds.s3.domain.ListBucketResponse;
|
|||
import org.jclouds.s3.domain.Payer;
|
||||
import org.jclouds.s3.domain.S3Object;
|
||||
import org.jclouds.s3.internal.StubS3AsyncClient;
|
||||
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -332,8 +331,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
public void testListBucketDelimiter() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
UnsupportedEncodingException {
|
||||
public void testListBucketDelimiter() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
String prefix = "apps";
|
||||
|
@ -350,8 +348,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
}
|
||||
|
||||
public void testListBucketPrefix() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
UnsupportedEncodingException {
|
||||
public void testListBucketPrefix() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
String prefix = "apps";
|
||||
|
@ -368,8 +365,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
}
|
||||
|
||||
public void testListBucketMaxResults() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
UnsupportedEncodingException {
|
||||
public void testListBucketMaxResults() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String bucketName = getContainerName();
|
||||
try {
|
||||
addAlphabetUnderRoot(bucketName);
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.s3.xml;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
@ -130,7 +129,7 @@ public class S3ParserTest extends PerformanceTest {
|
|||
|
||||
public static final String listContainerResult = "<ListContainerHandler xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Name>adrianjbosstest</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>3366</Key><LastModified>2009-03-12T02:00:13.000Z</LastModified><ETag>"9d7bb64e8e18ee34eec06dd2cf37b766"</ETag><Size>136</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents></ListContainerHandler>";
|
||||
|
||||
public void testCanParseListContainerResult() throws HttpException, UnsupportedEncodingException {
|
||||
public void testCanParseListContainerResult() throws HttpException {
|
||||
ListBucketResponse container = runParseListContainerResult();
|
||||
assert !container.isTruncated();
|
||||
assert container.getName().equals("adrianjbosstest");
|
||||
|
@ -161,7 +160,7 @@ public class S3ParserTest extends PerformanceTest {
|
|||
Strings2.toInputStream(successfulCopyObject200));
|
||||
}
|
||||
|
||||
public void testCanParseCopyObjectResult() throws HttpException, UnsupportedEncodingException {
|
||||
public void testCanParseCopyObjectResult() throws HttpException {
|
||||
ObjectMetadata metadata = runParseCopyObjectResult();
|
||||
Date expected = new SimpleDateFormatDateService().iso8601DateParse("2009-03-19T13:23:27.000Z");
|
||||
assertEquals(metadata.getLastModified(), expected);
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.jclouds.openstack.swift.options.ListContainerOptions.Builder.u
|
|||
import static org.jclouds.openstack.swift.options.ListContainerOptions.Builder.withPrefix;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.jclouds.http.options.HttpRequestOptions;
|
||||
|
@ -47,7 +46,7 @@ public class ListContainerOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPrefix() throws UnsupportedEncodingException {
|
||||
public void testPrefix() {
|
||||
ListContainerOptions options = new ListContainerOptions();
|
||||
options.withPrefix("test");
|
||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.PREFIX), Collections.singletonList("test"));
|
||||
|
@ -60,7 +59,7 @@ public class ListContainerOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testOneOptionQueryString() throws UnsupportedEncodingException {
|
||||
public void testOneOptionQueryString() {
|
||||
ListContainerOptions options = new ListContainerOptions();
|
||||
options.withPrefix("test");
|
||||
Multimap<String, String> map = options.buildQueryParameters();
|
||||
|
@ -69,7 +68,7 @@ public class ListContainerOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTwoOptionQueryString() throws UnsupportedEncodingException {
|
||||
public void testTwoOptionQueryString() {
|
||||
ListContainerOptions options = new ListContainerOptions();
|
||||
options.withPrefix("test").maxResults(1);
|
||||
Multimap<String, String> map = options.buildQueryParameters();
|
||||
|
@ -79,7 +78,7 @@ public class ListContainerOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPrefixAndPathUrlEncodingQueryString() throws UnsupportedEncodingException {
|
||||
public void testPrefixAndPathUrlEncodingQueryString() {
|
||||
ListContainerOptions options = new ListContainerOptions();
|
||||
options.withPrefix("/cloudfiles/test").underPath("/");
|
||||
Multimap<String, String> map = options.buildQueryParameters();
|
||||
|
@ -96,18 +95,18 @@ public class ListContainerOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPrefixStatic() throws UnsupportedEncodingException {
|
||||
public void testPrefixStatic() {
|
||||
ListContainerOptions options = withPrefix("test");
|
||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.PREFIX), Collections.singletonList("test"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testPrefixNPE() throws UnsupportedEncodingException {
|
||||
public void testPrefixNPE() {
|
||||
withPrefix(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarker() throws UnsupportedEncodingException {
|
||||
public void testMarker() {
|
||||
ListContainerOptions options = new ListContainerOptions();
|
||||
options.afterMarker("test");
|
||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.MARKER), Collections.singletonList("test"));
|
||||
|
@ -120,13 +119,13 @@ public class ListContainerOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMarkerStatic() throws UnsupportedEncodingException {
|
||||
public void testMarkerStatic() {
|
||||
ListContainerOptions options = afterMarker("test");
|
||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.MARKER), Collections.singletonList("test"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testMarkerNPE() throws UnsupportedEncodingException {
|
||||
public void testMarkerNPE() {
|
||||
afterMarker(null);
|
||||
}
|
||||
|
||||
|
@ -155,7 +154,7 @@ public class ListContainerOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPath() throws UnsupportedEncodingException {
|
||||
public void testPath() {
|
||||
ListContainerOptions options = new ListContainerOptions();
|
||||
options.underPath("test");
|
||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.PATH), Collections.singletonList("test"));
|
||||
|
@ -168,13 +167,13 @@ public class ListContainerOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPathStatic() throws UnsupportedEncodingException {
|
||||
public void testPathStatic() {
|
||||
ListContainerOptions options = underPath("test");
|
||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.PATH), Collections.singletonList("test"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testPathNPE() throws UnsupportedEncodingException {
|
||||
public void testPathNPE() {
|
||||
underPath(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.blobstore.options;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
@ -221,7 +220,7 @@ public class GetOptions {
|
|||
/**
|
||||
* @see GetOptions#ifETagMatches(String)
|
||||
*/
|
||||
public static GetOptions ifETagMatches(String eTag) throws UnsupportedEncodingException {
|
||||
public static GetOptions ifETagMatches(String eTag) {
|
||||
GetOptions options = new GetOptions();
|
||||
return options.ifETagMatches(eTag);
|
||||
}
|
||||
|
@ -229,7 +228,7 @@ public class GetOptions {
|
|||
/**
|
||||
* @see GetOptions#ifETagDoesntMatch(String)
|
||||
*/
|
||||
public static GetOptions ifETagDoesntMatch(String eTag) throws UnsupportedEncodingException {
|
||||
public static GetOptions ifETagDoesntMatch(String eTag) {
|
||||
GetOptions options = new GetOptions();
|
||||
return options.ifETagDoesntMatch(eTag);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.Arrays;
|
||||
|
@ -51,11 +50,11 @@ import javax.ws.rs.core.MediaType;
|
|||
|
||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.domain.BlobBuilder.PayloadBlobBuilder;
|
||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.blobstore.domain.PageSet;
|
||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
import org.jclouds.blobstore.domain.StorageType;
|
||||
import org.jclouds.blobstore.domain.BlobBuilder.PayloadBlobBuilder;
|
||||
import org.jclouds.concurrent.Futures;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.crypto.CryptoStreams;
|
||||
|
@ -268,7 +267,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testGetIfMatch() throws InterruptedException, UnsupportedEncodingException {
|
||||
public void testGetIfMatch() throws InterruptedException {
|
||||
String container = getContainerName();
|
||||
try {
|
||||
|
||||
|
@ -291,7 +290,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testGetIfNoneMatch() throws InterruptedException, UnsupportedEncodingException {
|
||||
public void testGetIfNoneMatch() throws InterruptedException {
|
||||
String container = getContainerName();
|
||||
try {
|
||||
|
||||
|
@ -304,7 +303,6 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
|
||||
try {
|
||||
context.getBlobStore().getBlob(container, name, ifETagDoesntMatch(goodETag));
|
||||
validateContent(container, name);
|
||||
} catch (HttpResponseException ex) {
|
||||
assertEquals(ex.getResponse().getStatusCode(), 304);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResu
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
@ -114,7 +113,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testListContainerMarker() throws InterruptedException, UnsupportedEncodingException {
|
||||
public void testListContainerMarker() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
addAlphabetUnderRoot(containerName);
|
||||
|
@ -137,7 +136,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testListRootUsesDelimiter() throws InterruptedException, UnsupportedEncodingException {
|
||||
public void testListRootUsesDelimiter() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
String prefix = "rootdelimeter";
|
||||
|
@ -153,7 +152,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testDirectory() throws InterruptedException, UnsupportedEncodingException {
|
||||
public void testDirectory() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
String directory = "directory";
|
||||
|
@ -230,7 +229,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testListContainerPrefix() throws InterruptedException, UnsupportedEncodingException {
|
||||
public void testListContainerPrefix() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
String prefix = "containerprefix";
|
||||
|
@ -247,7 +246,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testListContainerMaxResults() throws InterruptedException, UnsupportedEncodingException {
|
||||
public void testListContainerMaxResults() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
addAlphabetUnderRoot(containerName);
|
||||
|
@ -295,8 +294,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testListContainer() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
UnsupportedEncodingException {
|
||||
public void testListContainer() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
String containerName = getContainerName();
|
||||
try {
|
||||
add15UnderRoot(containerName);
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.io.File;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
@ -150,7 +149,7 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
|||
}
|
||||
|
||||
@Test(groups = { "integration", "live" })
|
||||
public void testDirectory() throws InterruptedException, UnsupportedEncodingException {
|
||||
public void testDirectory() throws InterruptedException {
|
||||
String containerName = getContainerName();
|
||||
String directory = "apps";
|
||||
Map<String, V> rootMap = createMap(context, containerName);
|
||||
|
|
|
@ -26,7 +26,6 @@ import static org.jclouds.blobstore.options.GetOptions.Builder.range;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -179,7 +178,7 @@ public class GetOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagMatches() throws UnsupportedEncodingException {
|
||||
public void testIfETagMatches() {
|
||||
GetOptions options = new GetOptions();
|
||||
options.ifETagMatches(etag);
|
||||
assertEquals(etag, options.getIfMatch());
|
||||
|
@ -192,18 +191,18 @@ public class GetOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagMatchesStatic() throws UnsupportedEncodingException {
|
||||
public void testIfETagMatchesStatic() {
|
||||
GetOptions options = ifETagMatches(etag);
|
||||
assertEquals(etag, options.getIfMatch());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testIfETagMatchesNPE() throws UnsupportedEncodingException {
|
||||
public void testIfETagMatchesNPE() {
|
||||
ifETagMatches(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testIfETagDoesntMatch() {
|
||||
GetOptions options = new GetOptions();
|
||||
options.ifETagDoesntMatch(etag);
|
||||
assertEquals(etag, options.getIfNoneMatch());
|
||||
|
@ -216,13 +215,13 @@ public class GetOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagDoesntMatchStatic() throws UnsupportedEncodingException {
|
||||
public void testIfETagDoesntMatchStatic() {
|
||||
GetOptions options = ifETagDoesntMatch(etag);
|
||||
assertEquals(etag, options.getIfNoneMatch());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testIfETagDoesntMatchNPE() throws UnsupportedEncodingException {
|
||||
public void testIfETagDoesntMatchNPE() {
|
||||
ifETagDoesntMatch(null);
|
||||
}
|
||||
|
||||
|
@ -232,13 +231,13 @@ public class GetOptionsTest {
|
|||
|
||||
}
|
||||
|
||||
public void testIfUnmodifiedAfterETagMatches() throws UnsupportedEncodingException {
|
||||
public void testIfUnmodifiedAfterETagMatches() {
|
||||
ifETagMatches(etag).ifUnmodifiedSince(now);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testIfUnmodifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testIfUnmodifiedAfterETagDoesntMatch() {
|
||||
ifETagDoesntMatch(etag).ifUnmodifiedSince(now);
|
||||
}
|
||||
|
||||
|
@ -249,44 +248,44 @@ public class GetOptionsTest {
|
|||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testIfModifiedAfterETagMatches() throws UnsupportedEncodingException {
|
||||
public void testIfModifiedAfterETagMatches() {
|
||||
ifETagMatches(etag).ifModifiedSince(now);
|
||||
|
||||
}
|
||||
|
||||
public void testIfModifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testIfModifiedAfterETagDoesntMatch() {
|
||||
ifETagDoesntMatch(etag).ifModifiedSince(now);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testETagMatchesAfterIfModified() throws UnsupportedEncodingException {
|
||||
public void testETagMatchesAfterIfModified() {
|
||||
ifModifiedSince(now).ifETagMatches(etag);
|
||||
|
||||
}
|
||||
|
||||
public void testETagMatchesAfterIfUnmodified() throws UnsupportedEncodingException {
|
||||
public void testETagMatchesAfterIfUnmodified() {
|
||||
ifUnmodifiedSince(now).ifETagMatches(etag);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testETagMatchesAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testETagMatchesAfterETagDoesntMatch() {
|
||||
ifETagDoesntMatch(etag).ifETagMatches(etag);
|
||||
}
|
||||
|
||||
public void testETagDoesntMatchAfterIfModified() throws UnsupportedEncodingException {
|
||||
public void testETagDoesntMatchAfterIfModified() {
|
||||
ifModifiedSince(now).ifETagDoesntMatch(etag);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testETagDoesntMatchAfterIfUnmodified() throws UnsupportedEncodingException {
|
||||
public void testETagDoesntMatchAfterIfUnmodified() {
|
||||
ifUnmodifiedSince(now).ifETagDoesntMatch(etag);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testETagDoesntMatchAfterETagMatches() throws UnsupportedEncodingException {
|
||||
public void testETagDoesntMatchAfterETagMatches() {
|
||||
ifETagMatches(etag).ifETagDoesntMatch(etag);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.http.functions;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* This object will parse the body of an HttpResponse and return the result of
|
||||
* type <T> back to the caller.
|
||||
* <p>
|
||||
* {@link JAXBContext} works with {@link Class} objects instead of {@link Type}.
|
||||
* This could be a limitation if we are trying to parse typed collections of
|
||||
* objects. However, when using JAXB we expect to have well formed XML documents
|
||||
* with one single root element, so the objects to parse should not be
|
||||
* collections but objects that wrap collections of elements, and that should
|
||||
* work fine.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseXMLWithJAXB<T> implements Function<HttpResponse, T> {
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected XMLParser xml;
|
||||
|
||||
protected final TypeLiteral<T> type;
|
||||
|
||||
@Inject
|
||||
public ParseXMLWithJAXB(final XMLParser xml, final TypeLiteral<T> type) {
|
||||
this.xml = xml;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T apply(final HttpResponse from) {
|
||||
InputStream xml = from.getPayload().getInput();
|
||||
try {
|
||||
return apply(xml);
|
||||
} catch (Exception e) {
|
||||
StringBuffer message = new StringBuffer();
|
||||
message.append("Error parsing input");
|
||||
logger.error(e, message.toString());
|
||||
throw new HttpResponseException(message.toString() + "\n" + from, null, from, e);
|
||||
} finally {
|
||||
releasePayload(from);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T apply(final InputStream stream) throws IOException {
|
||||
return (T) apply(stream, type.getRawType());
|
||||
}
|
||||
|
||||
public <V> V apply(final InputStream stream, final Class<V> type) throws IOException {
|
||||
try {
|
||||
return xml.fromXML(Strings2.toStringAndClose(stream), type);
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,6 @@ package org.jclouds.http.options;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
@ -161,8 +160,6 @@ public class GetOptions extends BaseHttpRequestOptions {
|
|||
*
|
||||
* @param eTag
|
||||
* hash representing the payload
|
||||
* @throws UnsupportedEncodingException
|
||||
* if there was a problem converting this into an S3 eTag string
|
||||
*/
|
||||
public GetOptions ifETagMatches(String eTag) {
|
||||
checkArgument(getIfNoneMatch() == null, "ifETagDoesntMatch() is not compatible with ifETagMatches()");
|
||||
|
@ -190,8 +187,6 @@ public class GetOptions extends BaseHttpRequestOptions {
|
|||
*
|
||||
* @param eTag
|
||||
* hash representing the payload
|
||||
* @throws UnsupportedEncodingException
|
||||
* if there was a problem converting this into an S3 eTag string
|
||||
*/
|
||||
public GetOptions ifETagDoesntMatch(String eTag) {
|
||||
checkArgument(getIfMatch() == null, "ifETagMatches() is not compatible with ifETagDoesntMatch()");
|
||||
|
|
|
@ -102,6 +102,21 @@ public class ModifyRequest {
|
|||
return (R) request.toBuilder().endpoint(builder.build()).build();
|
||||
}
|
||||
|
||||
public static <R extends HttpRequest> R addQueryParams(R request, Multimap<String, String> parameters, UriBuilder builder) {
|
||||
return addQueryParams(request, parameters, builder, request.getSkips());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <R extends HttpRequest> R addQueryParams(R request,
|
||||
Multimap<String, String> parameters, UriBuilder builder, char... skips) {
|
||||
builder.uri(request.getEndpoint());
|
||||
Multimap<String, String> map =
|
||||
org.jclouds.http.utils.ModifyRequest.parseQueryToMap(request.getEndpoint().getQuery());
|
||||
map.putAll(parameters);
|
||||
builder.replaceQuery(org.jclouds.http.utils.ModifyRequest.makeQueryLine(map, null, skips));
|
||||
return (R) request.toBuilder().endpoint(builder.build()).build();
|
||||
}
|
||||
|
||||
public static <R extends HttpRequest> R replaceMatrixParam(R request, String name, Object value, UriBuilder builder) {
|
||||
return replaceMatrixParam(request, name, new Object[] { value }, builder);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.rest.annotations;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
|
||||
/**
|
||||
* Shows the transformer type used to parse XML with the
|
||||
* {@link ParseXMLWithJAXB} parser in a HttpResponse.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Target(METHOD)
|
||||
@Retention(RUNTIME)
|
||||
public @interface JAXBResponseParser {
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.rest.binders;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
|
||||
/**
|
||||
* Exception thrown during the binding process.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class BindException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private HttpRequest request;
|
||||
|
||||
public BindException(final HttpRequest request) {
|
||||
super();
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public BindException(final HttpRequest request, final String message) {
|
||||
super(message);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public BindException(final HttpRequest request, final Throwable cause) {
|
||||
super(cause.getMessage(), cause);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public BindException(final HttpRequest request, final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
String msg = "Could not bind object to request" + request + ": ";
|
||||
return msg + super.getMessage();
|
||||
}
|
||||
|
||||
public HttpRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.rest.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.io.MutableContentMetadata;
|
||||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* Binds the request parameters to an XML formatted payload.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class BindToXMLPayload implements Binder {
|
||||
protected final XMLParser xmlParser;
|
||||
|
||||
@Inject
|
||||
public BindToXMLPayload(final XMLParser xmlParser) {
|
||||
this.xmlParser = checkNotNull(xmlParser, "xmlParser");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
|
||||
try {
|
||||
String xml = xmlParser.toXML(checkNotNull(input, "input"));
|
||||
request.setPayload(xml);
|
||||
MutableContentMetadata metadata = request.getPayload().getContentMetadata();
|
||||
if (contentTypeMustBeAdded(metadata)) {
|
||||
metadata.setContentType(MediaType.APPLICATION_XML);
|
||||
}
|
||||
return request;
|
||||
} catch (IOException ex) {
|
||||
throw new BindException(request, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean contentTypeMustBeAdded(final MutableContentMetadata metadata) {
|
||||
return Strings.isNullOrEmpty(metadata.getContentType())
|
||||
|| metadata.getContentType().equals("application/unknown");
|
||||
}
|
||||
}
|
|
@ -78,6 +78,7 @@ import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
|||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnInputStream;
|
||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
||||
|
@ -109,6 +110,7 @@ import org.jclouds.rest.annotations.EndpointParam;
|
|||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.FormParams;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MatrixParams;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
|
@ -789,6 +791,9 @@ public class RestAnnotationProcessor<T> {
|
|||
return Key.get((Class) IdentityFunction.class);
|
||||
} else if (getAcceptHeadersOrNull(method).contains(MediaType.APPLICATION_JSON)) {
|
||||
return getJsonParserKeyForMethod(method);
|
||||
} else if (getAcceptHeadersOrNull(method).contains(MediaType.APPLICATION_XML)
|
||||
|| method.isAnnotationPresent(JAXBResponseParser.class)) {
|
||||
return getJAXBParserKeyForMethod(method);
|
||||
} else if (method.getReturnType().equals(String.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureStringLiteral)) {
|
||||
return Key.get(ReturnStringIf2xx.class);
|
||||
|
@ -807,6 +812,13 @@ public class RestAnnotationProcessor<T> {
|
|||
return getJsonParserKeyForMethodAnType(method, returnVal);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Key<? extends Function<HttpResponse, ?>> getJAXBParserKeyForMethod(Method method) {
|
||||
Type returnVal = getReturnTypeForMethod(method);
|
||||
Type parserType = Types.newParameterizedType(ParseXMLWithJAXB.class, returnVal);
|
||||
return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType);
|
||||
}
|
||||
|
||||
public static Type getReturnTypeForMethod(Method method) {
|
||||
Type returnVal;
|
||||
if (method.getReturnType().getTypeParameters().length == 0) {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.xml.internal.JAXBParser;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* Parses XML documents.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@ImplementedBy(JAXBParser.class)
|
||||
public interface XMLParser {
|
||||
/** The default xml header. */
|
||||
public static final String DEFAULT_XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
|
||||
|
||||
/**
|
||||
* Serialize the object into xml.
|
||||
*/
|
||||
public String toXML(Object src) throws IOException;
|
||||
|
||||
/**
|
||||
* Serialize the object into xml, as the declared type.
|
||||
*/
|
||||
public <T> String toXML(Object src, Class<T> type) throws IOException;
|
||||
|
||||
/**
|
||||
* Deserialize the object from xml.
|
||||
*/
|
||||
public <T> T fromXML(String xml, Class<T> type) throws IOException;
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.xml.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
|
||||
/**
|
||||
* Parses XML documents using JAXB.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
* @see ParseXMLWithJAXB
|
||||
*/
|
||||
@Singleton
|
||||
public class JAXBParser implements XMLParser {
|
||||
@Override
|
||||
public String toXML(final Object src) throws IOException {
|
||||
return toXML(src, src.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> String toXML(final Object src, final Class<T> type) throws IOException {
|
||||
try {
|
||||
JAXBContext context = JAXBContext.newInstance(type);
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(src, writer);
|
||||
return writer.toString();
|
||||
} catch (JAXBException ex) {
|
||||
throw new IOException("Could not marshall object", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T fromXML(final String xml, final Class<T> type) throws IOException {
|
||||
try {
|
||||
StringReader reader = new StringReader(xml);
|
||||
JAXBContext context = JAXBContext.newInstance(type);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
return (T) unmarshaller.unmarshal(reader);
|
||||
} catch (Exception ex) {
|
||||
throw new IOException("Could not unmarshall document", ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,7 +28,6 @@ import static org.jclouds.http.options.GetOptions.Builder.tail;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
|
@ -205,7 +204,7 @@ public class GetOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagMatches() throws UnsupportedEncodingException {
|
||||
public void testIfETagMatches() {
|
||||
GetOptions options = new GetOptions();
|
||||
options.ifETagMatches(etag);
|
||||
matchesHex(options.getIfMatch());
|
||||
|
@ -218,18 +217,18 @@ public class GetOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagMatchesStatic() throws UnsupportedEncodingException {
|
||||
public void testIfETagMatchesStatic() {
|
||||
GetOptions options = ifETagMatches(etag);
|
||||
matchesHex(options.getIfMatch());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testIfETagMatchesNPE() throws UnsupportedEncodingException {
|
||||
public void testIfETagMatchesNPE() {
|
||||
ifETagMatches(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testIfETagDoesntMatch() {
|
||||
GetOptions options = new GetOptions();
|
||||
options.ifETagDoesntMatch(etag);
|
||||
matchesHex(options.getIfNoneMatch());
|
||||
|
@ -242,17 +241,17 @@ public class GetOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testIfETagDoesntMatchStatic() throws UnsupportedEncodingException {
|
||||
public void testIfETagDoesntMatchStatic() {
|
||||
GetOptions options = ifETagDoesntMatch(etag);
|
||||
matchesHex(options.getIfNoneMatch());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testIfETagDoesntMatchNPE() throws UnsupportedEncodingException {
|
||||
public void testIfETagDoesntMatchNPE() {
|
||||
ifETagDoesntMatch(null);
|
||||
}
|
||||
|
||||
private void matchesHex(String match) throws UnsupportedEncodingException {
|
||||
private void matchesHex(String match) {
|
||||
String expected = "\"" + etag + "\"";
|
||||
assertEquals(match, expected);
|
||||
}
|
||||
|
@ -263,13 +262,13 @@ public class GetOptionsTest {
|
|||
|
||||
}
|
||||
|
||||
public void testIfUnmodifiedAfterETagMatches() throws UnsupportedEncodingException {
|
||||
public void testIfUnmodifiedAfterETagMatches() {
|
||||
ifETagMatches(etag).ifUnmodifiedSince(now);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testIfUnmodifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testIfUnmodifiedAfterETagDoesntMatch() {
|
||||
ifETagDoesntMatch(etag).ifUnmodifiedSince(now);
|
||||
}
|
||||
|
||||
|
@ -280,44 +279,44 @@ public class GetOptionsTest {
|
|||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testIfModifiedAfterETagMatches() throws UnsupportedEncodingException {
|
||||
public void testIfModifiedAfterETagMatches() {
|
||||
ifETagMatches(etag).ifModifiedSince(now);
|
||||
|
||||
}
|
||||
|
||||
public void testIfModifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testIfModifiedAfterETagDoesntMatch() {
|
||||
ifETagDoesntMatch(etag).ifModifiedSince(now);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testETagMatchesAfterIfModified() throws UnsupportedEncodingException {
|
||||
public void testETagMatchesAfterIfModified() {
|
||||
ifModifiedSince(now).ifETagMatches(etag);
|
||||
|
||||
}
|
||||
|
||||
public void testETagMatchesAfterIfUnmodified() throws UnsupportedEncodingException {
|
||||
public void testETagMatchesAfterIfUnmodified() {
|
||||
ifUnmodifiedSince(now).ifETagMatches(etag);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testETagMatchesAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
||||
public void testETagMatchesAfterETagDoesntMatch() {
|
||||
ifETagDoesntMatch(etag).ifETagMatches(etag);
|
||||
}
|
||||
|
||||
public void testETagDoesntMatchAfterIfModified() throws UnsupportedEncodingException {
|
||||
public void testETagDoesntMatchAfterIfModified() {
|
||||
ifModifiedSince(now).ifETagDoesntMatch(etag);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testETagDoesntMatchAfterIfUnmodified() throws UnsupportedEncodingException {
|
||||
public void testETagDoesntMatchAfterIfUnmodified() {
|
||||
ifUnmodifiedSince(now).ifETagDoesntMatch(etag);
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testETagDoesntMatchAfterETagMatches() throws UnsupportedEncodingException {
|
||||
public void testETagDoesntMatchAfterETagMatches() {
|
||||
ifETagMatches(etag).ifETagDoesntMatch(etag);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.rest.binders;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessorTest.TestJAXBDomain;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
import org.jclouds.xml.internal.JAXBParser;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code BindToXMLPayload}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Test(groups = "unit", testName = "BindToXMLPayloadTest")
|
||||
public class BindToXMLPayloadTest {
|
||||
XMLParser xml = new JAXBParser();
|
||||
|
||||
@Test
|
||||
public void testBindJAXBObject() throws SecurityException, NoSuchMethodException {
|
||||
BindToXMLPayload binder = new BindToXMLPayload(xml);
|
||||
|
||||
// Build the object to bind
|
||||
TestJAXBDomain obj = new TestJAXBDomain();
|
||||
obj.setElem("Hello World");
|
||||
|
||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://momma")).build();
|
||||
request = binder.bindToRequest(request, obj);
|
||||
assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
|
||||
+ "<test><elem>Hello World</elem></test>");
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_XML);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeaderIsChangedIfNeeded() throws SecurityException, NoSuchMethodException {
|
||||
BindToXMLPayload binder = new BindToXMLPayload(xml);
|
||||
|
||||
// Build the object to bind
|
||||
TestJAXBDomain obj = new TestJAXBDomain();
|
||||
obj.setElem("Hello World");
|
||||
|
||||
// Add teh unknown content-type header to verify it is changed by the
|
||||
// binder
|
||||
Multimap<String, String> headers = ImmutableMultimap.<String, String> of("Content-type", "application/unknown");
|
||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://momma")).headers(headers)
|
||||
.build();
|
||||
|
||||
request = binder.bindToRequest(request, obj);
|
||||
assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
|
||||
+ "<test><elem>Hello World</elem></test>");
|
||||
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_XML);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testNullIsBad() {
|
||||
BindToXMLPayload binder = new BindToXMLPayload(xml);
|
||||
binder.bindToRequest(HttpRequest.builder().method("GET").endpoint(URI.create("http://momma")).build(), null);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = BindException.class)
|
||||
public void testInvalidObjectBinding() {
|
||||
BindToXMLPayload binder = new BindToXMLPayload(xml);
|
||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://momma")).build();
|
||||
request = binder.bindToRequest(request, new Object());
|
||||
}
|
||||
}
|
|
@ -72,6 +72,7 @@ import javax.ws.rs.Produces;
|
|||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.easymock.IArgumentMatcher;
|
||||
import org.eclipse.jetty.http.HttpHeaders;
|
||||
|
@ -91,6 +92,7 @@ import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
|||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnInputStream;
|
||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
||||
|
@ -120,6 +122,7 @@ import org.jclouds.rest.annotations.Endpoint;
|
|||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.FormParams;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MatrixParams;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
|
@ -142,6 +145,7 @@ import org.jclouds.rest.binders.BindToJsonPayload;
|
|||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.xml.XMLParser;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
|
@ -171,7 +175,8 @@ import com.sun.jersey.api.uri.UriBuilderImpl;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during
|
||||
// surefire
|
||||
@Test(groups = "unit", testName = "RestAnnotationProcessorTest")
|
||||
public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||
|
||||
|
@ -322,8 +327,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
private Injector injectorForClient() {
|
||||
|
||||
RestContextSpec<Caller, AsyncCaller> contextSpec = contextSpec("test", "http://localhost:9999", "1", "",
|
||||
"userfoo", null, Caller.class, AsyncCaller.class, ImmutableSet.<Module> of(new MockModule(),
|
||||
new NullLoggingModule(), new CallerCalleeModule()));
|
||||
"userfoo", null, Caller.class, AsyncCaller.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new CallerCalleeModule()));
|
||||
|
||||
return createContextBuilder(contextSpec).buildInjector();
|
||||
|
||||
|
@ -611,9 +616,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
Method method = TestPost.class.getMethod("postNonnull", String.class);
|
||||
try {
|
||||
HttpRequest request = factory(TestPost.class).createRequest(method);
|
||||
Assert
|
||||
.fail("call should have failed with illegal null parameter, not permitted " + request
|
||||
+ " to be created");
|
||||
Assert.fail("call should have failed with illegal null parameter, not permitted " + request + " to be created");
|
||||
} catch (NullPointerException e) {
|
||||
Assert.assertTrue(e.toString().indexOf("postNonnull parameter 1") >= 0,
|
||||
"Error message should have referred to 'parameter 1': " + e);
|
||||
|
@ -624,9 +627,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
Method method = TestPost.class.getMethod("postNonnull", String.class);
|
||||
try {
|
||||
HttpRequest request = factory(TestPost.class).createRequest(method, (String) null);
|
||||
Assert
|
||||
.fail("call should have failed with illegal null parameter, not permitted " + request
|
||||
+ " to be created");
|
||||
Assert.fail("call should have failed with illegal null parameter, not permitted " + request + " to be created");
|
||||
} catch (NullPointerException e) {
|
||||
Assert.assertTrue(e.toString().indexOf("postNonnull parameter 1") >= 0,
|
||||
"Error message should have referred to parameter 'parameter 1': " + e);
|
||||
|
@ -726,9 +727,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
try {
|
||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||
(String) null);
|
||||
Assert.fail("call should have failed with illegal null parameter, not permitted "+httpRequest+" to be created");
|
||||
Assert.fail("call should have failed with illegal null parameter, not permitted " + httpRequest
|
||||
+ " to be created");
|
||||
} catch (NullPointerException e) {
|
||||
Assert.assertTrue(e.toString().indexOf("fooble")>=0, "Error message should have referred to parameter 'fooble': "+e);
|
||||
Assert.assertTrue(e.toString().indexOf("fooble") >= 0,
|
||||
"Error message should have referred to parameter 'fooble': " + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -755,9 +758,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
try {
|
||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||
null, "foobledata");
|
||||
Assert.fail("call should have failed with illegal null parameter, not permitted "+httpRequest+" to be created");
|
||||
Assert.fail("call should have failed with illegal null parameter, not permitted " + httpRequest
|
||||
+ " to be created");
|
||||
} catch (NullPointerException e) {
|
||||
Assert.assertTrue(e.toString().indexOf("name")>=0, "Error message should have referred to parameter 'name': "+e);
|
||||
Assert.assertTrue(e.toString().indexOf("name") >= 0,
|
||||
"Error message should have referred to parameter 'name': " + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1012,8 +1017,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||
"foo", "bar"));
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||
ImmutableMap.of("foo", "bar"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -1028,8 +1033,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||
"foo", "bar"));
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||
ImmutableMap.of("foo", "bar"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -1044,8 +1049,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
||||
"foo", "bar"));
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||
ImmutableMap.of("foo", "bar"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -1064,7 +1069,6 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testUnwrapValueNamed() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestPut.class.getMethod("testUnwrapValueNamed");
|
||||
|
@ -1079,6 +1083,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), "bar");
|
||||
|
||||
}
|
||||
|
||||
public void testWrapWith() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestPut.class.getMethod("testWrapWith", String.class);
|
||||
HttpRequest request = factory(TestPut.class).createRequest(method, "bar");
|
||||
|
@ -1144,8 +1149,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
assertEquals(parser.apply(new HttpResponse(200, "ok",
|
||||
newStringPayload("{\"runit\":{\"runit\":[\"0.7.0\",\"0.7.1\"]}}"))), ImmutableSet.of("0.7.0", "0.7.1"));
|
||||
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{}}"))), ImmutableSet
|
||||
.<String> of());
|
||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{}}"))),
|
||||
ImmutableSet.<String> of());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -1164,7 +1169,6 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[]}"))), null);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSelectOnlyElement() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestPut.class.getMethod("selectOnlyElement");
|
||||
|
@ -1302,8 +1306,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
Method method = TestRequestFilter.class.getMethod("getOverride", HttpRequest.class);
|
||||
HttpRequest request = factory(TestRequestFilter.class).createRequest(
|
||||
method,
|
||||
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).headers(
|
||||
ImmutableMultimap.of("foo", "bar")).build());
|
||||
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost"))
|
||||
.headers(ImmutableMultimap.of("foo", "bar")).build());
|
||||
assertEquals(request.getFilters().size(), 1);
|
||||
assertEquals(request.getHeaders().size(), 1);
|
||||
assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class);
|
||||
|
@ -1485,7 +1489,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildTwoHeader() throws SecurityException, NoSuchMethodException {
|
||||
Method oneHeader = TestHeader.class.getMethod("twoHeader", String.class);
|
||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
||||
.getHeaders();
|
||||
|
@ -1503,7 +1507,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOneClassHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildOneClassHeader() throws SecurityException, NoSuchMethodException {
|
||||
Method oneHeader = TestClassHeader.class.getMethod("oneHeader", String.class);
|
||||
Multimap<String, String> headers = factory(TestClassHeader.class).createRequest(oneHeader,
|
||||
new Object[] { "robot" }).getHeaders();
|
||||
|
@ -1512,7 +1516,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOneHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildOneHeader() throws SecurityException, NoSuchMethodException {
|
||||
Method oneHeader = TestHeader.class.getMethod("oneHeader", String.class);
|
||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
||||
.getHeaders();
|
||||
|
@ -1521,7 +1525,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoHeaders() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildTwoHeaders() throws SecurityException, NoSuchMethodException {
|
||||
Method twoHeaders = TestHeader.class.getMethod("twoHeaders", String.class, String.class);
|
||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(twoHeaders,
|
||||
new Object[] { "robot", "eggs" }).getHeaders();
|
||||
|
@ -1530,8 +1534,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoHeadersOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
public void testBuildTwoHeadersOutOfOrder() throws SecurityException, NoSuchMethodException {
|
||||
Method twoHeadersOutOfOrder = TestHeader.class.getMethod("twoHeadersOutOfOrder", String.class, String.class);
|
||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(twoHeadersOutOfOrder,
|
||||
new Object[] { "robot", "eggs" }).getHeaders();
|
||||
|
@ -1546,10 +1549,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testQueryInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testQueryInOptions() throws SecurityException, NoSuchMethodException {
|
||||
Method oneQuery = TestQueryReplace.class.getMethod("queryInOptions", String.class, TestReplaceQueryOptions.class);
|
||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery,
|
||||
new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery();
|
||||
String query = factory(TestQueryReplace.class)
|
||||
.createRequest(oneQuery, new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
|
@ -1560,7 +1563,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@BinderParam(BindMapToMatrixParams.class) Map<String, String> options);
|
||||
}
|
||||
|
||||
public void testTestMapMatrixParams() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testTestMapMatrixParams() throws SecurityException, NoSuchMethodException {
|
||||
Method method = TestMapMatrixParams.class.getMethod("action", String.class, String.class, Map.class);
|
||||
HttpRequest request = factory(TestMapMatrixParams.class).createRequest(method,
|
||||
new Object[] { "robot", "kill", ImmutableMap.of("death", "slow") });
|
||||
|
@ -1602,7 +1605,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildTwoQuery() throws SecurityException, NoSuchMethodException {
|
||||
Method oneQuery = TestQueryReplace.class.getMethod("twoQuery", String.class);
|
||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||
.getQuery();
|
||||
|
@ -1618,7 +1621,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOneClassQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildOneClassQuery() throws SecurityException, NoSuchMethodException {
|
||||
Method oneQuery = TestClassQuery.class.getMethod("oneQuery", String.class);
|
||||
String query = factory(TestClassQuery.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||
.getQuery();
|
||||
|
@ -1626,7 +1629,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOneQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildOneQuery() throws SecurityException, NoSuchMethodException {
|
||||
Method oneQuery = TestQueryReplace.class.getMethod("oneQuery", String.class);
|
||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||
.getQuery();
|
||||
|
@ -1634,7 +1637,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoQuerys() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildTwoQuerys() throws SecurityException, NoSuchMethodException {
|
||||
Method twoQuerys = TestQueryReplace.class.getMethod("twoQuerys", String.class, String.class);
|
||||
String query = factory(TestQueryReplace.class).createRequest(twoQuerys, new Object[] { "robot", "eggs" })
|
||||
.getEndpoint().getQuery();
|
||||
|
@ -1642,11 +1645,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException {
|
||||
Method twoQuerysOutOfOrder = TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class, String.class);
|
||||
String query = factory(TestQueryReplace.class).createRequest(twoQuerysOutOfOrder,
|
||||
new Object[] { "robot", "eggs" }).getEndpoint().getQuery();
|
||||
String query = factory(TestQueryReplace.class)
|
||||
.createRequest(twoQuerysOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
|
@ -1657,11 +1659,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMatrixInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testMatrixInOptions() throws SecurityException, NoSuchMethodException {
|
||||
Method oneMatrix = TestMatrixReplace.class.getMethod("matrixInOptions", String.class,
|
||||
TestReplaceMatrixOptions.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix,
|
||||
new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
||||
String path = factory(TestMatrixReplace.class)
|
||||
.createRequest(oneMatrix, new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
|
@ -1699,7 +1701,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildTwoMatrix() throws SecurityException, NoSuchMethodException {
|
||||
Method oneMatrix = TestMatrixReplace.class.getMethod("twoMatrix", String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||
.getPath();
|
||||
|
@ -1716,7 +1718,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOneClassMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildOneClassMatrix() throws SecurityException, NoSuchMethodException {
|
||||
Method oneMatrix = TestClassMatrix.class.getMethod("oneMatrix", String.class);
|
||||
String path = factory(TestClassMatrix.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||
.getPath();
|
||||
|
@ -1724,7 +1726,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOneMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildOneMatrix() throws SecurityException, NoSuchMethodException {
|
||||
Method oneMatrix = TestMatrixReplace.class.getMethod("oneMatrix", String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||
.getPath();
|
||||
|
@ -1732,7 +1734,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoMatrixs() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildTwoMatrixs() throws SecurityException, NoSuchMethodException {
|
||||
Method twoMatrixs = TestMatrixReplace.class.getMethod("twoMatrixs", String.class, String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixs, new Object[] { "robot", "eggs" })
|
||||
.getEndpoint().getPath();
|
||||
|
@ -1740,12 +1742,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoMatrixsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
public void testBuildTwoMatrixsOutOfOrder() throws SecurityException, NoSuchMethodException {
|
||||
Method twoMatrixsOutOfOrder = TestMatrixReplace.class.getMethod("twoMatrixsOutOfOrder", String.class,
|
||||
String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixsOutOfOrder,
|
||||
new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||
String path = factory(TestMatrixReplace.class)
|
||||
.createRequest(twoMatrixsOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
|
@ -1807,8 +1808,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
public void testPutInputStreamPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
||||
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newInputStreamPayload(Strings2
|
||||
.toInputStream("whoops")));
|
||||
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(
|
||||
newInputStreamPayload(Strings2.toInputStream("whoops")));
|
||||
|
||||
calculateMD5(payloadEnclosing, crypto.md5());
|
||||
HttpRequest request = factory(TestQuery.class).createRequest(method, payloadEnclosing);
|
||||
|
@ -1950,8 +1951,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
|
||||
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
|
||||
GeneratedHttpRequest<TestTransformers> request = GeneratedHttpRequest.<TestTransformers> builder().method("GET")
|
||||
.endpoint(URI.create("http://localhost")).declaring(TestTransformers.class).javaMethod(method).args(
|
||||
new Object[] {}).build();
|
||||
.endpoint(URI.create("http://localhost")).declaring(TestTransformers.class).javaMethod(method)
|
||||
.args(new Object[] {}).build();
|
||||
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
||||
assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
|
||||
assertEquals(((ReturnStringIf200Context) transformer).request, request);
|
||||
|
@ -2023,8 +2024,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
assertEquals(request.getHeaders().size(), 2);
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost:9999"));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections.singletonList(dateService
|
||||
.rfc822DateFormat(date)));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE),
|
||||
Collections.singletonList(dateService.rfc822DateFormat(date)));
|
||||
}
|
||||
|
||||
public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
||||
|
@ -2037,8 +2038,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
assertEquals(request.getHeaders().size(), 2);
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost:9999"));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections.singletonList(dateService
|
||||
.rfc822DateFormat(date)));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE),
|
||||
Collections.singletonList(dateService.rfc822DateFormat(date)));
|
||||
}
|
||||
|
||||
public class PrefixOptions extends BaseHttpRequestOptions {
|
||||
|
@ -2380,7 +2381,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoForm() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildTwoForm() throws SecurityException, NoSuchMethodException {
|
||||
Method oneForm = TestFormReplace.class.getMethod("twoForm", String.class);
|
||||
Object form = factory(TestFormReplace.class).createRequest(oneForm, "robot").getPayload().getRawContent();
|
||||
assertEquals(form, "slash=/robot&hyphen=-robot");
|
||||
|
@ -2406,40 +2407,38 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testProvidesWithGeneric() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testProvidesWithGeneric() throws SecurityException, NoSuchMethodException {
|
||||
Set<String> set = injector.getInstance(AsyncClientFactory.class).create(TestClassForm.class).set();
|
||||
assertEquals(set, ImmutableSet.of("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProvidesWithGenericQualified() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
public void testProvidesWithGenericQualified() throws SecurityException, NoSuchMethodException {
|
||||
Set<String> set = injector.getInstance(AsyncClientFactory.class).create(TestClassForm.class).foo();
|
||||
assertEquals(set, ImmutableSet.of("bar"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testProvidesWithGenericQualifiedAuthorizationException() throws SecurityException,
|
||||
NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testProvidesWithGenericQualifiedAuthorizationException() throws SecurityException, NoSuchMethodException {
|
||||
injector.getInstance(AsyncClientFactory.class).create(TestClassForm.class).exception();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOneClassForm() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildOneClassForm() throws SecurityException, NoSuchMethodException {
|
||||
Method oneForm = TestClassForm.class.getMethod("oneForm", String.class);
|
||||
Object form = factory(TestClassForm.class).createRequest(oneForm, "robot").getPayload().getRawContent();
|
||||
assertEquals(form, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOneForm() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildOneForm() throws SecurityException, NoSuchMethodException {
|
||||
Method oneForm = TestFormReplace.class.getMethod("oneForm", String.class);
|
||||
Object form = factory(TestFormReplace.class).createRequest(oneForm, "robot").getPayload().getRawContent();
|
||||
assertEquals(form, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoForms() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||
public void testBuildTwoForms() throws SecurityException, NoSuchMethodException {
|
||||
Method twoForms = TestFormReplace.class.getMethod("twoForms", String.class, String.class);
|
||||
Object form = factory(TestFormReplace.class).createRequest(twoForms, "robot", "eggs").getPayload()
|
||||
.getRawContent();
|
||||
|
@ -2447,22 +2446,103 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException {
|
||||
Method twoFormsOutOfOrder = TestFormReplace.class.getMethod("twoFormsOutOfOrder", String.class, String.class);
|
||||
Object form = factory(TestFormReplace.class).createRequest(twoFormsOutOfOrder, "robot", "eggs").getPayload()
|
||||
.getRawContent();
|
||||
assertEquals(form, "x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
public interface TestJAXBResponseParser {
|
||||
@GET
|
||||
@Path("/jaxb/annotation")
|
||||
@JAXBResponseParser
|
||||
public ListenableFuture<TestJAXBDomain> jaxbGetWithAnnotation();
|
||||
|
||||
@GET
|
||||
@Path("/jaxb/header")
|
||||
@Consumes(MediaType.APPLICATION_XML)
|
||||
public ListenableFuture<TestJAXBDomain> jaxbGetWithAcceptHeader();
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "test")
|
||||
public static class TestJAXBDomain {
|
||||
private String elem;
|
||||
|
||||
public String getElem() {
|
||||
return elem;
|
||||
}
|
||||
|
||||
public void setElem(String elem) {
|
||||
this.elem = elem;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJAXBResponseParserWithAnnotation() throws SecurityException, NoSuchMethodException {
|
||||
RestAnnotationProcessor<TestJAXBResponseParser> processor = factory(TestJAXBResponseParser.class);
|
||||
Method method = TestJAXBResponseParser.class.getMethod("jaxbGetWithAnnotation");
|
||||
GeneratedHttpRequest<TestJAXBResponseParser> request = GeneratedHttpRequest.<TestJAXBResponseParser> builder()
|
||||
.method("GET").endpoint(URI.create("http://localhost")).declaring(TestJAXBResponseParser.class)
|
||||
.javaMethod(method).args(new Object[] {}).build();
|
||||
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
||||
assertEquals(transformer.getClass(), ParseXMLWithJAXB.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJAXBResponseParserWithAcceptHeader() throws SecurityException, NoSuchMethodException {
|
||||
RestAnnotationProcessor<TestJAXBResponseParser> processor = factory(TestJAXBResponseParser.class);
|
||||
Method method = TestJAXBResponseParser.class.getMethod("jaxbGetWithAcceptHeader");
|
||||
GeneratedHttpRequest<TestJAXBResponseParser> request = GeneratedHttpRequest.<TestJAXBResponseParser> builder()
|
||||
.method("GET").endpoint(URI.create("http://localhost")).declaring(TestJAXBResponseParser.class)
|
||||
.javaMethod(method).args(new Object[] {}).build();
|
||||
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
||||
assertEquals(transformer.getClass(), ParseXMLWithJAXB.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testJAXBResponseParserWithAnnotation() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestJAXBResponseParser.class.getMethod("jaxbGetWithAnnotation");
|
||||
HttpRequest request = factory(TestJAXBResponseParser.class).createRequest(method);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||
// now test that it works!
|
||||
|
||||
Function<HttpResponse, TestJAXBDomain> parser = (Function<HttpResponse, TestJAXBDomain>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
StringBuffer payload = new StringBuffer(XMLParser.DEFAULT_XML_HEADER);
|
||||
payload.append("<test><elem>Hello World</elem></test>");
|
||||
TestJAXBDomain domain = parser.apply(new HttpResponse(200, "ok", newStringPayload(payload.toString())));
|
||||
assertEquals(domain.getElem(), "Hello World");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testJAXBResponseParserWithAcceptHeader() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestJAXBResponseParser.class.getMethod("jaxbGetWithAcceptHeader");
|
||||
HttpRequest request = factory(TestJAXBResponseParser.class).createRequest(method);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||
// now test that it works!
|
||||
|
||||
Function<HttpResponse, TestJAXBDomain> parser = (Function<HttpResponse, TestJAXBDomain>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
StringBuffer payload = new StringBuffer(XMLParser.DEFAULT_XML_HEADER);
|
||||
payload.append("<test><elem>Hello World</elem></test>");
|
||||
TestJAXBDomain domain = parser.apply(new HttpResponse(200, "ok", newStringPayload(payload.toString())));
|
||||
assertEquals(domain.getElem(), "Hello World");
|
||||
}
|
||||
|
||||
DateService dateService = new SimpleDateFormatDateService();
|
||||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
|
||||
null, String.class, Integer.class, ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(),
|
||||
new AbstractModule() {
|
||||
null, String.class, Integer.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
@ -2470,8 +2550,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
}).toInstance(ImmutableSet.of("foo"));
|
||||
bind(new TypeLiteral<Set<String>>() {
|
||||
}).annotatedWith(Names.named("bar")).toInstance(ImmutableSet.of("bar"));
|
||||
bind(URI.class).annotatedWith(Localhost2.class).toInstance(
|
||||
URI.create("http://localhost:1111"));
|
||||
bind(URI.class).annotatedWith(Localhost2.class).toInstance(URI.create("http://localhost:1111"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
|
|
@ -20,8 +20,6 @@ package org.jclouds.util;
|
|||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -43,7 +41,7 @@ public class Strings2Test {
|
|||
assertEquals(Strings2.urlEncode("/read-tests/ tep", '/'), "/read-tests/%20tep");
|
||||
}
|
||||
|
||||
public void testReplaceTokens() throws UnsupportedEncodingException {
|
||||
public void testReplaceTokens() {
|
||||
assertEquals(Strings2.replaceTokens("hello {where}", ImmutableMap.of("where", "world")), "hello world");
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
extraction of appengine-java-sdk
|
||||
-->
|
||||
<appengine.applicationid>jclouds-tweetstore-spring</appengine.applicationid>
|
||||
<appengine.sdk.version>1.5.3</appengine.sdk.version>
|
||||
<appengine.sdk.version>1.5.5</appengine.sdk.version>
|
||||
<devappserver.address>localhost</devappserver.address>
|
||||
<devappserver.port>8088</devappserver.port>
|
||||
<jclouds.tweetstore.container>jclouds-tweetstore-spring</jclouds.tweetstore.container>
|
||||
|
@ -196,7 +196,7 @@
|
|||
<plugin>
|
||||
<groupId>net.kindleit</groupId>
|
||||
<artifactId>maven-gae-plugin</artifactId>
|
||||
<version>0.8.4</version>
|
||||
<version>0.9.1</version>
|
||||
<configuration>
|
||||
<serverId>google-appengine</serverId>
|
||||
<sdkDir>${appengine.sdk.root}</sdkDir>
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
extraction of appengine-java-sdk
|
||||
-->
|
||||
<appengine.applicationid>jclouds-tweetstore</appengine.applicationid>
|
||||
<appengine.sdk.version>1.5.3</appengine.sdk.version>
|
||||
<appengine.sdk.version>1.5.5</appengine.sdk.version>
|
||||
<devappserver.address>localhost</devappserver.address>
|
||||
<devappserver.port>8088</devappserver.port>
|
||||
<jclouds.tweetstore.container>jclouds-tweetstore</jclouds.tweetstore.container>
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.azureblob.blobstore.integration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
|
@ -34,7 +33,7 @@ import org.testng.annotations.Test;
|
|||
public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
|
||||
|
||||
@Override
|
||||
public void testGetIfMatch() throws InterruptedException, UnsupportedEncodingException {
|
||||
public void testGetIfMatch() throws InterruptedException {
|
||||
// this currently fails
|
||||
}
|
||||
|
||||
|
|
|
@ -160,6 +160,7 @@
|
|||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<threadCount>1</threadCount>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>test.virtualbox.endpoint</name>
|
||||
|
|
|
@ -19,13 +19,15 @@
|
|||
|
||||
package org.jclouds.virtualbox;
|
||||
|
||||
import org.jclouds.PropertiesBuilder;
|
||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
|
||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.jclouds.Constants.*;
|
||||
import org.jclouds.PropertiesBuilder;
|
||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||
|
||||
/**
|
||||
* Builds properties for VirtualBox integration.
|
||||
|
@ -51,7 +53,9 @@ public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
|
|||
properties.put(VirtualBoxConstants.VIRTUALBOX_PRESEED_URL, "http://dl.dropbox.com/u/693111/preseed.cfg");
|
||||
properties.put(VirtualBoxConstants.VIRTUALBOX_SNAPSHOT_DESCRIPTION, "jclouds-virtualbox-snaphot");
|
||||
properties.put(VirtualBoxConstants.VIRTUALBOX_HOSTNAME, "jclouds-virtualbox-kickstart-admin");
|
||||
properties.put(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, "<Esc><Esc><Enter> "
|
||||
properties
|
||||
.put(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE,
|
||||
"<Esc><Esc><Enter> "
|
||||
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
|
||||
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
||||
+ "hostname="
|
||||
|
@ -61,10 +65,8 @@ public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
|
|||
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
||||
+ "initrd=/install/initrd.gz -- <Enter>");
|
||||
|
||||
properties.put(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR, System.getProperty("user.home")
|
||||
+ File.separator
|
||||
+ System.getProperty("test.virtualbox.workingDir",
|
||||
"jclouds-virtualbox-test"));
|
||||
properties.put(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR, System.getProperty("user.home") + File.separator
|
||||
+ System.getProperty("test.virtualbox.workingDir", "jclouds-virtualbox-test"));
|
||||
|
||||
// TODO: Add more properties and use the wired properties from test code.
|
||||
properties.put(VirtualBoxConstants.VIRTUALBOX_DISTRO_ISO_NAME, "ubuntu-11.04-server-i386.iso");
|
||||
|
|
|
@ -19,19 +19,24 @@
|
|||
|
||||
package org.jclouds.virtualbox.compute;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_CREDENTIAL;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_GROUP;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_LOCATION;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_USERNAME;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.byon.Node;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.virtualbox_4_1.IGuestOSType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.*;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
|
||||
/**
|
||||
* Loads a node from a VirtualBox IMachine
|
||||
|
@ -53,16 +58,10 @@ public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
|
|||
public Node load(final String id) throws Exception {
|
||||
|
||||
if (id.equals("host")) {
|
||||
final Node hostNode = Node.builder().id("host")
|
||||
.name("host installing virtualbox")
|
||||
.hostname("localhost")
|
||||
.osFamily(OsFamily.LINUX.toString())
|
||||
.osDescription(System.getProperty("os.name"))
|
||||
.osVersion(System.getProperty("os.version"))
|
||||
.group("ssh")
|
||||
.username(System.getProperty("user.name"))
|
||||
.credentialUrl(privateKeyFile())
|
||||
.build();
|
||||
final Node hostNode = Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
|
||||
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
|
||||
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
|
||||
.credentialUrl(privateKeyFile()).build();
|
||||
return hostNode;
|
||||
}
|
||||
|
||||
|
@ -71,23 +70,14 @@ public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
|
|||
final String osTypeId = machine.getOSTypeId();
|
||||
final IGuestOSType guestOSType = manager.getVBox().getGuestOSType(osTypeId);
|
||||
|
||||
final Node node = Node.builder()
|
||||
.id(machine.getId())
|
||||
.name(machine.getName())
|
||||
.description(machine.getDescription())
|
||||
.loginPort(22)
|
||||
.group(System.getProperty(VIRTUALBOX_MACHINE_GROUP))
|
||||
final Node node = Node.builder().id(machine.getId()).name(machine.getName())
|
||||
.description(machine.getDescription()).loginPort(22).group(System.getProperty(VIRTUALBOX_MACHINE_GROUP))
|
||||
.username(System.getProperty(VIRTUALBOX_MACHINE_USERNAME))
|
||||
.credential(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
|
||||
.sudoPassword(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
|
||||
.locationId(System.getProperty(VIRTUALBOX_MACHINE_LOCATION))
|
||||
.os64Bit(guestOSType.getIs64Bit())
|
||||
.osArch(guestOSType.getDescription())
|
||||
.osFamily(guestOSType.getFamilyDescription())
|
||||
.osVersion(guestOSType.getId())
|
||||
.osDescription(guestOSType.getDescription())
|
||||
.hostname(ipAddress)
|
||||
.build();
|
||||
.locationId(System.getProperty(VIRTUALBOX_MACHINE_LOCATION)).os64Bit(guestOSType.getIs64Bit())
|
||||
.osArch(guestOSType.getDescription()).osFamily(guestOSType.getFamilyDescription())
|
||||
.osVersion(guestOSType.getId()).osDescription(guestOSType.getDescription()).hostname(ipAddress).build();
|
||||
|
||||
return node;
|
||||
|
||||
|
|
|
@ -19,10 +19,16 @@
|
|||
|
||||
package org.jclouds.virtualbox.compute;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Singleton;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
|
@ -30,15 +36,17 @@ import org.jclouds.domain.Credentials;
|
|||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.location.suppliers.JustProvider;
|
||||
import org.virtualbox_4_1.*;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Defines the connection between the
|
||||
|
@ -55,7 +63,8 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
|||
private Function<IMachine, Image> iMachineToImage;
|
||||
|
||||
@Inject
|
||||
public VirtualBoxComputeServiceAdapter(VirtualBoxManager manager, JustProvider justProvider, Function<IMachine, Image> iMachineToImage) {
|
||||
public VirtualBoxComputeServiceAdapter(VirtualBoxManager manager, JustProvider justProvider,
|
||||
Function<IMachine, Image> iMachineToImage) {
|
||||
this.iMachineToImage = iMachineToImage;
|
||||
this.manager = checkNotNull(manager, "manager");
|
||||
this.justProvider = checkNotNull(justProvider, "justProvider");
|
||||
|
|
|
@ -57,7 +57,8 @@ import com.google.inject.TypeLiteral;
|
|||
/**
|
||||
* @author Mattias Holmqvist, Andrea Turli
|
||||
*/
|
||||
public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapterContextModule<VirtualBoxManager, VirtualBoxManager, IMachine, IMachine, Image, Location> {
|
||||
public class VirtualBoxComputeServiceContextModule extends
|
||||
ComputeServiceAdapterContextModule<VirtualBoxManager, VirtualBoxManager, IMachine, IMachine, Image, Location> {
|
||||
|
||||
public VirtualBoxComputeServiceContextModule() {
|
||||
super(VirtualBoxManager.class, VirtualBoxManager.class);
|
||||
|
@ -65,8 +66,8 @@ public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapter
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected VirtualBoxManager createInstance(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity,
|
||||
@Named(Constants.PROPERTY_CREDENTIAL) String credential) {
|
||||
protected VirtualBoxManager createInstance(@Provider URI endpoint,
|
||||
@Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential) {
|
||||
|
||||
VirtualBoxManager manager = VirtualBoxManager.createInstance("");
|
||||
manager.connect(endpoint.toASCIIString(), identity, credential);
|
||||
|
@ -100,10 +101,8 @@ public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapter
|
|||
|
||||
@VisibleForTesting
|
||||
public static final Map<MachineState, NodeState> machineToNodeState = ImmutableMap
|
||||
.<MachineState, NodeState>builder()
|
||||
.put(MachineState.Running, NodeState.RUNNING)
|
||||
.put(MachineState.PoweredOff, NodeState.SUSPENDED)
|
||||
.put(MachineState.DeletingSnapshot, NodeState.PENDING)
|
||||
.<MachineState, NodeState> builder().put(MachineState.Running, NodeState.RUNNING)
|
||||
.put(MachineState.PoweredOff, NodeState.SUSPENDED).put(MachineState.DeletingSnapshot, NodeState.PENDING)
|
||||
.put(MachineState.DeletingSnapshotOnline, NodeState.PENDING)
|
||||
.put(MachineState.DeletingSnapshotPaused, NodeState.PENDING)
|
||||
.put(MachineState.FaultTolerantSyncing, NodeState.PENDING)
|
||||
|
@ -113,17 +112,12 @@ public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapter
|
|||
.put(MachineState.Stopping, NodeState.PENDING)
|
||||
.put(MachineState.Restoring, NodeState.PENDING)
|
||||
// TODO What to map these states to?
|
||||
.put(MachineState.FirstOnline, NodeState.PENDING)
|
||||
.put(MachineState.FirstTransient, NodeState.PENDING)
|
||||
.put(MachineState.LastOnline, NodeState.PENDING)
|
||||
.put(MachineState.LastTransient, NodeState.PENDING)
|
||||
.put(MachineState.Teleported, NodeState.PENDING)
|
||||
.put(MachineState.TeleportingIn, NodeState.PENDING)
|
||||
.put(MachineState.FirstOnline, NodeState.PENDING).put(MachineState.FirstTransient, NodeState.PENDING)
|
||||
.put(MachineState.LastOnline, NodeState.PENDING).put(MachineState.LastTransient, NodeState.PENDING)
|
||||
.put(MachineState.Teleported, NodeState.PENDING).put(MachineState.TeleportingIn, NodeState.PENDING)
|
||||
.put(MachineState.TeleportingPausedVM, NodeState.PENDING)
|
||||
|
||||
|
||||
.put(MachineState.Aborted, NodeState.ERROR)
|
||||
.put(MachineState.Stuck, NodeState.ERROR)
|
||||
.put(MachineState.Aborted, NodeState.ERROR).put(MachineState.Stuck, NodeState.ERROR)
|
||||
|
||||
.put(MachineState.Null, NodeState.UNRECOGNIZED).build();
|
||||
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.virtualbox.domain;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.jaxws.RuntimeFaultMsg;
|
||||
|
||||
/**
|
||||
* Maps the error codes in the Virtual Box Java API into enum values.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* To get the error code from a VBoxException, use:
|
||||
*
|
||||
* <pre>
|
||||
* try {
|
||||
* ...
|
||||
* ...
|
||||
* }
|
||||
* catch (VBoxException vboxException) {
|
||||
* RuntimeFaultMsg fault = (RuntimeFaultMsg) vboxException.getWrapped();
|
||||
* int faultCode = fault.getFaultInfo().getResultCode();
|
||||
* ErrorCode errorCode = ErrorCode.valueOf(faultCode);
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
public enum ErrorCode {
|
||||
|
||||
VBOX_E_OBJECT_NOT_FOUND(2159738881L), VBOX_E_INVALID_VM_STATE(2159738882L), VBOX_E_VM_ERROR(2159738883L), VBOX_E_FILE_ERROR(
|
||||
2159738884L), VBOX_E_IPRT_ERROR(2159738885L), VBOX_E_PDM_ERROR(2159738886L), VBOX_E_INVALID_OBJECT_STATE(
|
||||
2159738887L), VBOX_E_HOST_ERROR(2159738888L), VBOX_E_NOT_SUPPORTED(2159738889L), VBOX_E_XML_ERROR(2159738890L), VBOX_E_INVALID_SESSION_STATE(
|
||||
2159738891L), VBOX_E_OBJECT_IN_USE(2159738892L), VBOX_E_ACCESSDENIED(2147942405L), VBOX_E_POINTER(2147500035L), VBOX_E_FAIL(
|
||||
2147500037L), VBOX_E_NOTIMPL(2147500033L), VBOX_E_OUTOFMEMORY(2147942414L), VBOX_E_INVALIDARG(2147942487L), VBOX_E_UNEXPECTED(
|
||||
2147549183L), VBOX_E_UNKNOWN_ERROR_CODE(-1L), VBOX_E_ERROR_CODE_UNAVAILABLE(-2L);
|
||||
|
||||
private long code;
|
||||
|
||||
ErrorCode(long code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
private static Map<Long, ErrorCode> table = new HashMap<Long, ErrorCode>();
|
||||
|
||||
static {
|
||||
for (ErrorCode errorCode : ErrorCode.values()) {
|
||||
table.put(errorCode.code, errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ErrorCode from the fault code given by the VirtualBox API.
|
||||
*
|
||||
* @param vboxException
|
||||
* the exception to get the error code from.
|
||||
* @return an ErrorCode representing the given fault code.
|
||||
*/
|
||||
public static ErrorCode valueOf(VBoxException vboxException) {
|
||||
final Throwable wrapped = vboxException.getWrapped();
|
||||
if (wrapped instanceof RuntimeFaultMsg) {
|
||||
final RuntimeFaultMsg faultCode = (RuntimeFaultMsg) wrapped;
|
||||
final int resultCode = faultCode.getFaultInfo().getResultCode();
|
||||
final ErrorCode errorCode = table.get(unsignedIntToLong(resultCode));
|
||||
if (errorCode != null) {
|
||||
return errorCode;
|
||||
}
|
||||
return VBOX_E_UNKNOWN_ERROR_CODE;
|
||||
}
|
||||
return VBOX_E_ERROR_CODE_UNAVAILABLE;
|
||||
}
|
||||
|
||||
private static long unsignedIntToLong(int faultCode) {
|
||||
return faultCode & 0xffffffffL;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.virtualbox.domain;
|
||||
|
||||
public enum ExecutionType {
|
||||
|
||||
GUI("gui"), HEADLESS("headless"), SDL("sdl"), EMERGENCYSTOP("emergencystop");
|
||||
|
||||
private final String type;
|
||||
|
||||
ExecutionType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String stringValue() {
|
||||
return type;
|
||||
}
|
||||
}
|
|
@ -41,73 +41,73 @@ import com.google.common.collect.Maps;
|
|||
* Serializes to the following
|
||||
*
|
||||
* <pre>
|
||||
id: myTestId
|
||||
name: ubuntu-11.04-server-i386
|
||||
description: ubuntu 11.04 server (i386)
|
||||
os_arch: x86
|
||||
os_family: linux
|
||||
os_description: ubuntu
|
||||
os_version: 11.04
|
||||
iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
|
||||
keystroke_sequence: |
|
||||
<Esc><Esc><Enter>
|
||||
/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg
|
||||
debian-installer=en_US auto locale=en_US kbd-chooser/method=us
|
||||
hostname=vmName
|
||||
fb=false debconf/frontend=noninteractive
|
||||
keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
|
||||
initrd=/install/initrd.gz -- <Enter>
|
||||
preseed_cfg: |
|
||||
## Options to set on the command line
|
||||
d-i debian-installer/locale string en_US.utf8
|
||||
d-i console-setup/ask_detect boolean false
|
||||
d-i console-setup/layout string USA
|
||||
d-i netcfg/get_hostname string unassigned-hostname
|
||||
d-i netcfg/get_domain string unassigned-domain
|
||||
# Continue without a default route
|
||||
# Not working , specify a dummy in the DHCP
|
||||
d-i time/zone string UTC
|
||||
d-i clock-setup/utc-auto boolean true
|
||||
d-i clock-setup/utc boolean true
|
||||
d-i kbd-chooser/method select American English
|
||||
d-i netcfg/wireless_wep string
|
||||
d-i base-installer/kernel/override-image string linux-server
|
||||
# Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
|
||||
d-i debconf debconf/frontend select Noninteractive
|
||||
d-i pkgsel/install-language-support boolean false
|
||||
tasksel tasksel/first multiselect standard, ubuntu-server
|
||||
d-i partman-auto/method string lvm
|
||||
d-i partman-lvm/confirm boolean true
|
||||
d-i partman-lvm/device_remove_lvm boolean true
|
||||
d-i partman-auto/choose_recipe select atomic
|
||||
d-i partman/confirm_write_new_label boolean true
|
||||
d-i partman/confirm_nooverwrite boolean true
|
||||
d-i partman/choose_partition select finish
|
||||
d-i partman/confirm boolean true
|
||||
# Write the changes to disks and configure LVM?
|
||||
d-i partman-lvm/confirm boolean true
|
||||
d-i partman-lvm/confirm_nooverwrite boolean true
|
||||
d-i partman-auto-lvm/guided_size string max
|
||||
## Default user, we can get away with a recipe to change this
|
||||
d-i passwd/user-fullname string toor
|
||||
d-i passwd/username string toor
|
||||
d-i passwd/user-password password password
|
||||
d-i passwd/user-password-again password password
|
||||
d-i user-setup/encrypt-home boolean false
|
||||
d-i user-setup/allow-password-weak boolean true
|
||||
# Individual additional packages to install
|
||||
d-i pkgsel/include string openssh-server ntp
|
||||
# Whether to upgrade packages after debootstrap.
|
||||
# Allowed values: none, safe-upgrade, full-upgrade
|
||||
d-i pkgsel/upgrade select full-upgrade
|
||||
d-i grub-installer/only_debian boolean true
|
||||
d-i grub-installer/with_other_os boolean true
|
||||
d-i finish-install/reboot_in_progress note
|
||||
#For the update
|
||||
d-i pkgsel/update-policy select none
|
||||
# debconf-get-selections --install
|
||||
#Use mirror
|
||||
choose-mirror-bin mirror/http/proxy string
|
||||
* id: myTestId
|
||||
* name: ubuntu-11.04-server-i386
|
||||
* description: ubuntu 11.04 server (i386)
|
||||
* os_arch: x86
|
||||
* os_family: linux
|
||||
* os_description: ubuntu
|
||||
* os_version: 11.04
|
||||
* iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
|
||||
* keystroke_sequence: |
|
||||
* <Esc><Esc><Enter>
|
||||
* /install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg
|
||||
* debian-installer=en_US auto locale=en_US kbd-chooser/method=us
|
||||
* hostname=vmName
|
||||
* fb=false debconf/frontend=noninteractive
|
||||
* keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
|
||||
* initrd=/install/initrd.gz -- <Enter>
|
||||
* preseed_cfg: |
|
||||
* ## Options to set on the command line
|
||||
* d-i debian-installer/locale string en_US.utf8
|
||||
* d-i console-setup/ask_detect boolean false
|
||||
* d-i console-setup/layout string USA
|
||||
* d-i netcfg/get_hostname string unassigned-hostname
|
||||
* d-i netcfg/get_domain string unassigned-domain
|
||||
* # Continue without a default route
|
||||
* # Not working , specify a dummy in the DHCP
|
||||
* d-i time/zone string UTC
|
||||
* d-i clock-setup/utc-auto boolean true
|
||||
* d-i clock-setup/utc boolean true
|
||||
* d-i kbd-chooser/method select American English
|
||||
* d-i netcfg/wireless_wep string
|
||||
* d-i base-installer/kernel/override-image string linux-server
|
||||
* # Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
|
||||
* d-i debconf debconf/frontend select Noninteractive
|
||||
* d-i pkgsel/install-language-support boolean false
|
||||
* tasksel tasksel/first multiselect standard, ubuntu-server
|
||||
* d-i partman-auto/method string lvm
|
||||
* d-i partman-lvm/confirm boolean true
|
||||
* d-i partman-lvm/device_remove_lvm boolean true
|
||||
* d-i partman-auto/choose_recipe select atomic
|
||||
* d-i partman/confirm_write_new_label boolean true
|
||||
* d-i partman/confirm_nooverwrite boolean true
|
||||
* d-i partman/choose_partition select finish
|
||||
* d-i partman/confirm boolean true
|
||||
* # Write the changes to disks and configure LVM?
|
||||
* d-i partman-lvm/confirm boolean true
|
||||
* d-i partman-lvm/confirm_nooverwrite boolean true
|
||||
* d-i partman-auto-lvm/guided_size string max
|
||||
* ## Default user, we can get away with a recipe to change this
|
||||
* d-i passwd/user-fullname string toor
|
||||
* d-i passwd/username string toor
|
||||
* d-i passwd/user-password password password
|
||||
* d-i passwd/user-password-again password password
|
||||
* d-i user-setup/encrypt-home boolean false
|
||||
* d-i user-setup/allow-password-weak boolean true
|
||||
* # Individual additional packages to install
|
||||
* d-i pkgsel/include string openssh-server ntp
|
||||
* # Whether to upgrade packages after debootstrap.
|
||||
* # Allowed values: none, safe-upgrade, full-upgrade
|
||||
* d-i pkgsel/upgrade select full-upgrade
|
||||
* d-i grub-installer/only_debian boolean true
|
||||
* d-i grub-installer/with_other_os boolean true
|
||||
* d-i finish-install/reboot_in_progress note
|
||||
* #For the update
|
||||
* d-i pkgsel/update-policy select none
|
||||
* # debconf-get-selections --install
|
||||
* #Use mirror
|
||||
* choose-mirror-bin mirror/http/proxy string
|
||||
* </pre>
|
||||
*
|
||||
* @author Kelvin Kakugawa
|
||||
|
@ -143,14 +143,11 @@ public class YamlImage {
|
|||
return null;
|
||||
OsFamily family = parseOsFamilyOrUnrecognized(arg0.os_family);
|
||||
|
||||
OperatingSystem operatingSystem = OperatingSystem.builder()
|
||||
.description(arg0.os_description)
|
||||
.family(family)
|
||||
.version(arg0.os_version)
|
||||
.is64Bit(arg0.os_64bit)
|
||||
.build();
|
||||
OperatingSystem operatingSystem = OperatingSystem.builder().description(arg0.os_description).family(family)
|
||||
.version(arg0.os_version).is64Bit(arg0.os_64bit).build();
|
||||
|
||||
return new ImageBuilder().id(arg0.id).name(arg0.name).description(arg0.description).operatingSystem(operatingSystem).build();
|
||||
return new ImageBuilder().id(arg0.id).name(arg0.name).description(arg0.description)
|
||||
.operatingSystem(operatingSystem).build();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -19,10 +19,11 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
|
|
|
@ -19,13 +19,14 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
|
|
|
@ -19,12 +19,14 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.virtualbox_4_1.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.virtualbox_4_1.DeviceType.HardDisk;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
|
@ -37,7 +39,8 @@ public class AttachMediumToMachineIfNotAlreadyAttached implements Function<IMach
|
|||
private int device;
|
||||
private DeviceType deviceType;
|
||||
|
||||
public AttachMediumToMachineIfNotAlreadyAttached(String controllerIDE, IMedium hardDisk, int controllerPort, int device, DeviceType deviceType) {
|
||||
public AttachMediumToMachineIfNotAlreadyAttached(String controllerIDE, IMedium hardDisk, int controllerPort,
|
||||
int device, DeviceType deviceType) {
|
||||
this.controllerIDE = controllerIDE;
|
||||
this.hardDisk = hardDisk;
|
||||
this.controllerPort = controllerPort;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -19,14 +19,15 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import static org.virtualbox_4_1.NATProtocol.TCP;
|
||||
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.virtualbox_4_1.NATProtocol.TCP;
|
||||
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
|
|
|
@ -19,14 +19,14 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
|
|
|
@ -19,11 +19,17 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.virtualbox_4_1.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
|
@ -71,15 +77,18 @@ public class CreateMediumIfNotAlreadyExists implements Function<String, IMedium>
|
|||
private void createBaseStorage(IMedium hardDisk) {
|
||||
try {
|
||||
long size = 4L * 1024L * 1024L * 1024L - 4L;
|
||||
IProgress storageCreation = hardDisk.createBaseStorage(size, (long) org.virtualbox_4_1.jaxws.MediumVariant.STANDARD.ordinal());
|
||||
IProgress storageCreation = hardDisk.createBaseStorage(size,
|
||||
(long) org.virtualbox_4_1.jaxws.MediumVariant.STANDARD.ordinal());
|
||||
storageCreation.waitForCompletion(-1);
|
||||
} catch (VBoxException e) {
|
||||
if (fileNotFoundException(e)) {
|
||||
// File for medium could not be found. Something wrong with creation.
|
||||
// File for medium could not be found. Something wrong with
|
||||
// creation.
|
||||
hardDisk.deleteStorage();
|
||||
}
|
||||
if (!storageAlreadyExists(e)) {
|
||||
// Hard disk file was created but the storage had been created before that.
|
||||
// Hard disk file was created but the storage had been created
|
||||
// before that.
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
@ -90,8 +99,8 @@ public class CreateMediumIfNotAlreadyExists implements Function<String, IMedium>
|
|||
}
|
||||
|
||||
private boolean storageAlreadyExists(VBoxException e) {
|
||||
return e.getMessage().indexOf("VirtualBox error: Storage for the medium ") != -1 &&
|
||||
e.getMessage().indexOf("is already created") != -1;
|
||||
return e.getMessage().indexOf("VirtualBox error: Storage for the medium ") != -1
|
||||
&& e.getMessage().indexOf("is already created") != -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ public class IMachineToHardware implements Function<IMachine, Hardware> {
|
|||
public Hardware apply(@Nullable IMachine vm) {
|
||||
String osTypeId = vm.getOSTypeId();
|
||||
|
||||
|
||||
IGuestOSType guestOSType = virtualBoxManager.getVBox().getGuestOSType(osTypeId);
|
||||
Boolean is64Bit = guestOSType.getIs64Bit();
|
||||
HardwareBuilder hardwareBuilder = new HardwareBuilder();
|
||||
|
|
|
@ -58,8 +58,7 @@ public class IMachineToImage implements Function<IMachine, Image> {
|
|||
|
||||
IGuestOSType guestOSType = virtualboxManager.getVBox().getGuestOSType(from.getOSTypeId());
|
||||
OsFamily family = parseOsFamilyOrUnrecognized(guestOSType.getDescription());
|
||||
String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(),
|
||||
osVersionMap);
|
||||
String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(), osVersionMap);
|
||||
OperatingSystem os = OperatingSystem.builder().description(guestOSType.getDescription()).family(family)
|
||||
.version(version).is64Bit(guestOSType.getIs64Bit()).build();
|
||||
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
import org.jclouds.compute.options.RunScriptOptions;
|
||||
|
@ -28,9 +31,7 @@ import org.virtualbox_4_1.IGuestOSType;
|
|||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Get an IP address from an IMachine using arp of the host machine.
|
||||
|
@ -63,18 +64,25 @@ public class IMachineToIpAddress implements Function<IMachine, String> {
|
|||
IMachine hostMachine = manager.getVBox().findMachine(hostId);
|
||||
if (isOSX(hostMachine)) {
|
||||
if (simplifiedMacAddressOfClonedVM.contains("00"))
|
||||
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(simplifiedMacAddressOfClonedVM.indexOf("00"), simplifiedMacAddressOfClonedVM.indexOf("00") + 1).toString();
|
||||
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(
|
||||
simplifiedMacAddressOfClonedVM.indexOf("00"), simplifiedMacAddressOfClonedVM.indexOf("00") + 1)
|
||||
.toString();
|
||||
|
||||
if (simplifiedMacAddressOfClonedVM.contains("0"))
|
||||
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':' && simplifiedMacAddressOfClonedVM.indexOf("0") - 1 != ':')
|
||||
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(simplifiedMacAddressOfClonedVM.indexOf("0"), simplifiedMacAddressOfClonedVM.indexOf("0") + 1).toString();
|
||||
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':'
|
||||
&& simplifiedMacAddressOfClonedVM.indexOf("0") - 1 != ':')
|
||||
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(
|
||||
simplifiedMacAddressOfClonedVM.indexOf("0"), simplifiedMacAddressOfClonedVM.indexOf("0") + 1)
|
||||
.toString();
|
||||
}
|
||||
|
||||
// TODO: This is both shell-dependent and hard-coded. Needs to be fixed.
|
||||
ExecResponse execResponse = runScriptOnNode(hostId, "for i in {1..254} ; do ping -c 1 -t 1 192.168.2.$i & done", runAsRoot(false).wrapInInitScript(false));
|
||||
ExecResponse execResponse = runScriptOnNode(hostId, "for i in {1..254} ; do ping -c 1 -t 1 192.168.2.$i & done",
|
||||
runAsRoot(false).wrapInInitScript(false));
|
||||
System.out.println(execResponse);
|
||||
|
||||
String arpLine = runScriptOnNode(hostId, "arp -an | grep " + simplifiedMacAddressOfClonedVM, runAsRoot(false).wrapInInitScript(false)).getOutput();
|
||||
String arpLine = runScriptOnNode(hostId, "arp -an | grep " + simplifiedMacAddressOfClonedVM,
|
||||
runAsRoot(false).wrapInInitScript(false)).getOutput();
|
||||
String ipAddress = arpLine.substring(arpLine.indexOf("(") + 1, arpLine.indexOf(")"));
|
||||
System.out.println("IP address " + ipAddress);
|
||||
return ipAddress;
|
||||
|
|
|
@ -19,8 +19,19 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.jclouds.compute.domain.*;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
|
@ -31,12 +42,7 @@ import org.virtualbox_4_1.IMachine;
|
|||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata> {
|
||||
|
||||
|
@ -75,7 +81,6 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
|||
nodeMetadataBuilder.hostname(vm.getName());
|
||||
nodeMetadataBuilder.loginPort(18083);
|
||||
|
||||
|
||||
MachineState vmState = vm.getState();
|
||||
NodeState nodeState = machineToNodeState.get(vmState);
|
||||
if (nodeState == null)
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
||||
|
@ -36,7 +35,6 @@ import java.io.File;
|
|||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
import org.jclouds.compute.options.RunScriptOptions;
|
||||
|
@ -45,10 +43,17 @@ import org.jclouds.domain.Credentials;
|
|||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.ssh.SshException;
|
||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
|
||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||
import org.jclouds.virtualbox.settings.KeyboardScancodes;
|
||||
import org.virtualbox_4_1.*;
|
||||
import org.virtualbox_4_1.AccessMode;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.LockType;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Inject;
|
||||
|
@ -96,11 +101,15 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
@Override
|
||||
public IMachine apply(@Nullable String isoName) {
|
||||
|
||||
String port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
||||
String baseResource = ".";
|
||||
Server server = new StartJettyIfNotAlreadyRunning(port).apply(baseResource);
|
||||
// TODO: WTF :) this is a prerequisite, so check state as opposed to
|
||||
// starting.
|
||||
// ex checkState(endpoint accessible, "please start jetty on %s",
|
||||
// endpoint)
|
||||
// Server server = new
|
||||
// StartJettyIfNotAlreadyRunning(port).apply(baseResource);
|
||||
|
||||
IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(settingsFile, osTypeId, vmId, forceOverwrite, manager).apply(vmName);
|
||||
IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(settingsFile, osTypeId, vmId, forceOverwrite,
|
||||
manager).apply(vmName);
|
||||
|
||||
String defaultWorkingDir = System.getProperty("user.home") + "/jclouds-virtualbox-test";
|
||||
String workingDir = System.getProperty(VIRTUALBOX_WORKINGDIR, defaultWorkingDir);
|
||||
|
@ -136,13 +145,8 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
// Guest additions
|
||||
ensureGuestAdditionsMediumIsAttached(vmName, guestAdditionsDvdMedium);
|
||||
|
||||
IProgress prog = vm.launchVMProcess(manager.getSessionObject(), "gui", "");
|
||||
prog.waitForCompletion(-1);
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
propagate(e);
|
||||
}
|
||||
// Launch machine and wait for it to come online
|
||||
ensureMachineIsLaunched(vmName);
|
||||
|
||||
String installKeySequence = System.getProperty(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, defaultInstallSequence());
|
||||
sendKeyboardSequence(installKeySequence);
|
||||
|
@ -170,24 +174,33 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
}
|
||||
|
||||
});
|
||||
try {
|
||||
logger.debug("Stopping Jetty server...");
|
||||
server.stop();
|
||||
logger.debug("Jetty server stopped.");
|
||||
} catch (Exception e) {
|
||||
logger.error(e, "Could not stop Jetty server.");
|
||||
}
|
||||
// TODO: See above.
|
||||
// if you want to manage jetty, do it outside this class as it
|
||||
// has too many responsibilities otherwise. Allow this class to focus
|
||||
// solely on making an IMachine
|
||||
//
|
||||
// try {
|
||||
// logger.debug("Stopping Jetty server...");
|
||||
// server.stop();
|
||||
// logger.debug("Jetty server stopped.");
|
||||
// } catch (Exception e) {
|
||||
// logger.error(e, "Could not stop Jetty server.");
|
||||
// }
|
||||
return vm;
|
||||
}
|
||||
|
||||
private void ensureMachineIsLaunched(String vmName) {
|
||||
applyForMachine(manager, vmName, new LaunchMachineIfNotAlreadyRunning(manager, ExecutionType.GUI, ""));
|
||||
}
|
||||
|
||||
private void ensureGuestAdditionsMediumIsAttached(String vmName, final IMedium guestAdditionsDvdMedium) {
|
||||
lockMachineAndApply(manager, Write, vmName,
|
||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, guestAdditionsDvdMedium, 1, 1, DeviceType.DVD));
|
||||
lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE,
|
||||
guestAdditionsDvdMedium, 1, 1, DeviceType.DVD));
|
||||
}
|
||||
|
||||
private void ensureMachineHasHardDiskAttached(String vmName, IMedium hardDisk) {
|
||||
lockMachineAndApply(manager, Write, vmName,
|
||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, 0, 1, HardDisk));
|
||||
lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE,
|
||||
hardDisk, 0, 1, HardDisk));
|
||||
}
|
||||
|
||||
private void ensureMachineHasMemory(String vmName, final long memorySize) {
|
||||
|
@ -201,10 +214,12 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
private void ensureMachineHasAttachedDistroMedium(String isoName, String workingDir, String controllerIDE) {
|
||||
final String pathToIsoFile = checkFileExists(workingDir + "/" + isoName);
|
||||
final IMedium distroMedium = manager.getVBox().openMedium(pathToIsoFile, DVD, ReadOnly, forceOverwrite);
|
||||
lockMachineAndApply(manager, Write, vmName,
|
||||
new AttachDistroMediumToMachine(
|
||||
checkNotNull(controllerIDE, "controllerIDE"),
|
||||
checkNotNull(distroMedium, "distroMedium")));
|
||||
lockMachineAndApply(
|
||||
manager,
|
||||
Write,
|
||||
vmName,
|
||||
new AttachDistroMediumToMachine(checkNotNull(controllerIDE, "controllerIDE"), checkNotNull(distroMedium,
|
||||
"distroMedium")));
|
||||
}
|
||||
|
||||
public static String checkFileExists(String filePath) {
|
||||
|
@ -219,6 +234,21 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
new AddIDEControllerIfNotExists(checkNotNull(controllerIDE, "controllerIDE")));
|
||||
}
|
||||
|
||||
private <T> T applyForMachine(VirtualBoxManager manager, final String machineId, final Function<IMachine, T> function) {
|
||||
final IMachine immutableMachine = manager.getVBox().findMachine(machineId);
|
||||
return new Function<IMachine, T>() {
|
||||
@Override
|
||||
public T apply(IMachine machine) {
|
||||
return function.apply(machine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return function.toString();
|
||||
}
|
||||
}.apply(immutableMachine);
|
||||
}
|
||||
|
||||
public static <T> T lockMachineAndApply(VirtualBoxManager manager, final LockType type, final String machineId,
|
||||
final Function<IMachine, T> function) {
|
||||
return lockSessionOnMachineAndApply(manager, type, machineId, new Function<ISession, T>() {
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.virtualbox.functions;
|
||||
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Starts a machine using launchMachine() with the provided type and
|
||||
* environment.
|
||||
* <p/>
|
||||
* Note that launchMachine() may throw VBoxException with the following error
|
||||
* codes:
|
||||
* <p/>
|
||||
* VBOX_E_UNEXPECTED: Virtual machine not registered. VBOX_E_INVALIDARG: Invalid
|
||||
* session type type. VBOX_E_OBJECT_NOT_FOUND: No machine matching machineId
|
||||
* found. VBOX_E_INVALID_OBJECT_STATE: Session already open or being opened.
|
||||
* VBOX_E_IPRT_ERROR: Launching process for machine failed. VBOX_E_VM_ERROR:
|
||||
* Failed to assign machine to session.
|
||||
*
|
||||
* @author Mattias Holmqvist
|
||||
*
|
||||
* @see ErrorCode
|
||||
*/
|
||||
public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final VirtualBoxManager manager;
|
||||
private final ExecutionType type;
|
||||
private final String environment;
|
||||
|
||||
public LaunchMachineIfNotAlreadyRunning(VirtualBoxManager manager, ExecutionType type, String environment) {
|
||||
this.manager = manager;
|
||||
this.type = type;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void apply(@Nullable IMachine machine) {
|
||||
try {
|
||||
final IProgress progress = machine
|
||||
.launchVMProcess(manager.getSessionObject(), type.stringValue(), environment);
|
||||
progress.waitForCompletion(-1);
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
propagate(e);
|
||||
} catch (VBoxException e) {
|
||||
ErrorCode errorCode = ErrorCode.valueOf(e);
|
||||
switch (errorCode) {
|
||||
case VBOX_E_INVALID_OBJECT_STATE:
|
||||
logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). "
|
||||
+ "The machine might already be running.", errorCode);
|
||||
break;
|
||||
default:
|
||||
propagate(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,28 +1,4 @@
|
|||
package org.jclouds.virtualbox.functions.admin;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.virtualbox.domain.YamlImage;
|
||||
import org.yaml.snakeyaml.Loader;
|
||||
import org.yaml.snakeyaml.TypeDescription;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -39,7 +15,34 @@ import static com.google.common.base.Preconditions.checkState;
|
|||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.jclouds.virtualbox.functions.admin;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.virtualbox.domain.YamlImage;
|
||||
import org.yaml.snakeyaml.Loader;
|
||||
import org.yaml.snakeyaml.TypeDescription;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Andrea Turli
|
||||
*/
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions.admin;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -47,19 +49,26 @@ public class StartJettyIfNotAlreadyRunning implements Function<String, Server> {
|
|||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final Server jetty;
|
||||
private final int port;
|
||||
|
||||
public StartJettyIfNotAlreadyRunning(Server jetty, @Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) int port) {
|
||||
this.jetty = checkNotNull(jetty, "jetty");
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
// TODO: getting an instance of the Server object should really be done in
|
||||
// Guice, so inside a *Module class, perhaps as a @Provides method
|
||||
@Inject
|
||||
public StartJettyIfNotAlreadyRunning(
|
||||
@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) final String port) {
|
||||
this.port = Integer.parseInt(port);
|
||||
public StartJettyIfNotAlreadyRunning(@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) int port) {
|
||||
this(ServerJetty.getInstance().getServer(), port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server apply(@Nullable String baseResource) {
|
||||
final Server server = ServerJetty.getInstance().getServer();
|
||||
|
||||
if (!server.getState().equals(Server.STARTED) && !new InetSocketAddressConnect().apply(new IPSocket("localhost", port))) {
|
||||
if (!jetty.getState().equals(Server.STARTED)
|
||||
// TODO code smell = hard coding addresses or ports!!
|
||||
&& !new InetSocketAddressConnect().apply(new IPSocket("localhost", port))) {
|
||||
ResourceHandler resource_handler = new ResourceHandler();
|
||||
resource_handler.setDirectoriesListed(true);
|
||||
resource_handler.setWelcomeFiles(new String[] { "index.html" });
|
||||
|
@ -69,17 +78,17 @@ public class StartJettyIfNotAlreadyRunning implements Function<String, Server> {
|
|||
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
||||
server.setHandler(handlers);
|
||||
jetty.setHandler(handlers);
|
||||
|
||||
try {
|
||||
server.start();
|
||||
jetty.start();
|
||||
} catch (Exception e) {
|
||||
logger.error(e, "Server jetty could not be started at this %s", baseResource);
|
||||
}
|
||||
return server;
|
||||
return jetty;
|
||||
} else {
|
||||
logger.debug("Server jetty serving %s already running. Skipping start", baseResource);
|
||||
return server;
|
||||
return jetty;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,68 +19,74 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions.admin;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.cache.Cache;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class StartVBoxIfNotAlreadyRunning implements Function<URI, VirtualBoxManager> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
private ComputeServiceContext context;
|
||||
private String hostId;
|
||||
private Credentials credentials;
|
||||
|
||||
public StartVBoxIfNotAlreadyRunning(ComputeServiceContext context, String hostId, Credentials credentials) {
|
||||
this.context = context;
|
||||
this.hostId = hostId;
|
||||
this.credentials = credentials;
|
||||
private final ComputeService compute;
|
||||
private final VirtualBoxManager manager;
|
||||
private final Predicate<IPSocket> socketTester;
|
||||
private final String hostId;
|
||||
private final Credentials credentials;
|
||||
|
||||
public StartVBoxIfNotAlreadyRunning(ComputeService compute, VirtualBoxManager manager,
|
||||
Predicate<IPSocket> socketTester, String hostId, Credentials credentials) {
|
||||
this.compute = checkNotNull(compute, "compute");
|
||||
this.manager = checkNotNull(manager, "manager");
|
||||
this.socketTester = checkNotNull(socketTester, "socketTester");
|
||||
this.hostId = checkNotNull(hostId, "hostId");
|
||||
this.credentials = checkNotNull(credentials, "credentials");
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualBoxManager apply(@Nullable URI endpoint) {
|
||||
public VirtualBoxManager apply(URI endpoint) {
|
||||
checkState(compute.getNodeMetadata(hostId) != null, "compute service %s cannot locate node with id %s", compute,
|
||||
hostId);
|
||||
checkNotNull(endpoint, "endpoint to virtualbox websrvd is needed");
|
||||
|
||||
// TODO Really create new object here? Should we cache these instead?
|
||||
VirtualBoxManager manager = VirtualBoxManager.createInstance(hostId);
|
||||
|
||||
if (new InetSocketAddressConnect().apply(new IPSocket(endpoint.getHost(), endpoint.getPort()))) {
|
||||
if (socketTester.apply(new IPSocket(endpoint.getHost(), endpoint.getPort()))) {
|
||||
manager.connect(endpoint.toASCIIString(), credentials.identity, credentials.credential);
|
||||
return manager;
|
||||
}
|
||||
|
||||
logger.debug("disabling password access");
|
||||
context.getComputeService().runScriptOnNode(hostId, "VBoxManage setproperty websrvauthlibrary null", runAsRoot(false).wrapInInitScript(false));
|
||||
compute.runScriptOnNode(hostId, "VBoxManage setproperty websrvauthlibrary null", runAsRoot(false)
|
||||
.wrapInInitScript(false));
|
||||
logger.debug("starting vboxwebsrv");
|
||||
String vboxwebsrv = "vboxwebsrv -t 10000 -v -b";
|
||||
if (isOSX(hostId))
|
||||
vboxwebsrv = "cd /Applications/VirtualBox.app/Contents/MacOS/ && " + vboxwebsrv;
|
||||
|
||||
context.getComputeService().runScriptOnNode(hostId, vboxwebsrv, runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv"));
|
||||
compute.runScriptOnNode(hostId, vboxwebsrv, runAsRoot(false).wrapInInitScript(false).blockOnComplete(false)
|
||||
.nameTask("vboxwebsrv"));
|
||||
|
||||
manager.connect(endpoint.toASCIIString(), credentials.identity, credentials.credential);
|
||||
return manager;
|
||||
}
|
||||
|
||||
private boolean isOSX(String hostId) {
|
||||
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription().equals(
|
||||
"Mac OS X");
|
||||
return compute.getNodeMetadata(hostId).getOperatingSystem().getDescription().equals("Mac OS X");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.jclouds.virtualbox.settings;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -124,6 +125,7 @@ public class KeyboardScancodes {
|
|||
alphaToHex.put(")", "2a 0b aa 8b");
|
||||
return Collections.unmodifiableMap(alphaToHex);
|
||||
}
|
||||
|
||||
private static Map<String, String> createSpecialMap() {
|
||||
Map<String, String> special = new HashMap<String, String>();
|
||||
special.put("<Enter>", "1c 9c");
|
||||
|
|
|
@ -20,17 +20,27 @@
|
|||
package org.jclouds.virtualbox;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
|
||||
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
@ -58,6 +68,8 @@ public class BaseVirtualBoxClientLiveTest {
|
|||
}
|
||||
|
||||
protected ComputeServiceContext context;
|
||||
protected VirtualBoxManager manager;
|
||||
protected Server jetty;
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
|
@ -66,12 +78,34 @@ public class BaseVirtualBoxClientLiveTest {
|
|||
properties.setProperty(provider + ".apiversion", apiversion);
|
||||
context = new ComputeServiceContextFactory().createContext(provider, identity, credential,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()));
|
||||
jetty = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
||||
startVboxIfNotAlreadyRunning();
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
protected void tearDown() throws Exception {
|
||||
if (context != null)
|
||||
context.close();
|
||||
if (jetty != null)
|
||||
jetty.stop();
|
||||
// TODO: should we stop the vbox manager?
|
||||
}
|
||||
|
||||
private String basebaseResource = ".";
|
||||
// TODO: I'd not use 8080, maybe something like 28080
|
||||
// also update pom.xml so that this passes through
|
||||
private int port = Integer.parseInt(System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080"));
|
||||
|
||||
protected void startVboxIfNotAlreadyRunning() {
|
||||
Credentials localhostCredentials = new Credentials("toor", "password");
|
||||
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest("hostId", "localhost", "guestId",
|
||||
"localhost", localhostCredentials);
|
||||
|
||||
manager = new StartVBoxIfNotAlreadyRunning(localHostContext.getComputeService(),
|
||||
VirtualBoxManager.createInstance("hostId"), new InetSocketAddressConnect(), "hostId", localhostCredentials)
|
||||
.apply(URI.create(endpoint));
|
||||
|
||||
assert manager.getSessionObject().getState() == SessionState.Unlocked : "manager needs to be in unlocked state or all tests will fail!!: "
|
||||
+ manager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,12 @@
|
|||
|
||||
package org.jclouds.virtualbox.compute;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Guice;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
|
@ -44,11 +45,11 @@ import org.testng.annotations.Test;
|
|||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest")
|
||||
public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||
|
@ -64,8 +65,8 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
|||
super.setupClient();
|
||||
final VirtualBoxManager manager = getManager();
|
||||
Function<IMachine, Image> iMachineToImage = new IMachineToImage(manager, osVersionMap);
|
||||
adapter = new VirtualBoxComputeServiceAdapter(manager,
|
||||
new JustProvider(provider, URI.create(endpoint), ImmutableSet.<String>of()), iMachineToImage);
|
||||
adapter = new VirtualBoxComputeServiceAdapter(manager, new JustProvider(provider, URI.create(endpoint),
|
||||
ImmutableSet.<String> of()), iMachineToImage);
|
||||
}
|
||||
|
||||
protected VirtualBoxManager getManager() {
|
||||
|
@ -91,13 +92,14 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
|||
assert credentialStore.containsKey("node#" + machine.getId()) : "credentials to log into machine not found "
|
||||
+ machine;
|
||||
// TODO: what's the IP address?
|
||||
// assert InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) : machine;
|
||||
// assert
|
||||
// InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) :
|
||||
// machine;
|
||||
doConnectViaSsh(machine, credentialStore.get("node#" + machine.getId()));
|
||||
}
|
||||
|
||||
protected void doConnectViaSsh(IMachine machine, Credentials creds) {
|
||||
SshClient ssh = context.utils().sshFactory()
|
||||
.create(new IPSocket("//TODO", 22), creds);
|
||||
SshClient ssh = context.utils().sshFactory().create(new IPSocket("//TODO", 22), creds);
|
||||
try {
|
||||
ssh.connect();
|
||||
ExecResponse hello = ssh.exec("echo hello");
|
||||
|
@ -128,7 +130,7 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
|||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
protected void tearDown() throws Exception {
|
||||
if (machine != null)
|
||||
adapter.destroyNode(machine.getId() + "");
|
||||
super.tearDown();
|
||||
|
|
|
@ -19,9 +19,17 @@
|
|||
|
||||
package org.jclouds.virtualbox.compute;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.inject.Guice;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
|
@ -37,16 +45,9 @@ import org.virtualbox_4_1.IMachine;
|
|||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.easymock.classextension.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
@Test(groups = "unit")
|
||||
public class VirtualBoxComputeServiceAdapterTest {
|
||||
|
@ -83,7 +84,8 @@ public class VirtualBoxComputeServiceAdapterTest {
|
|||
replay(manager, justProvider, vBox, clonedMachine, imageMachine, osType);
|
||||
|
||||
Function<IMachine, Image> iMachineToImage = new IMachineToImage(manager, osMap);
|
||||
VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(manager, justProvider, iMachineToImage);
|
||||
VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(manager, justProvider,
|
||||
iMachineToImage);
|
||||
|
||||
Iterator<Image> iterator = adapter.listImages().iterator();
|
||||
Image image = Iterators.getOnlyElement(iterator);
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.virtualbox.compute;
|
||||
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Andrea Turli
|
||||
*/
|
||||
|
||||
@Test(groups = "live", testName = "VirtualBoxTemplateBuilderLiveTest")
|
||||
public class VirtualBoxTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
||||
|
||||
public VirtualBoxTemplateBuilderLiveTest() {
|
||||
provider = "virtualbox";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
|
||||
return Predicates.not(new Predicate<OsFamilyVersion64Bit>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(OsFamilyVersion64Bit input) {
|
||||
switch (input.family) {
|
||||
case UBUNTU:
|
||||
return input.version.equals("11.04") && !input.is64Bit;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateBuilder() {
|
||||
System.out.println(this.context.getComputeService().listImages());
|
||||
Template defaultTemplate = this.context.getComputeService().templateBuilder().build();
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> getIso3166Codes() {
|
||||
return ImmutableSet.<String> of();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,184 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.virtualbox.experiment;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
import org.jclouds.compute.options.RunScriptOptions;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
|
||||
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
|
||||
import org.testng.annotations.AfterSuite;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
public class SetupVirtualBoxForLiveTest {
|
||||
|
||||
private String provider = "virtualbox";
|
||||
private URI endpoint;
|
||||
private String apiVersion;
|
||||
|
||||
private String workingDir;
|
||||
|
||||
private URI gaIsoUrl;
|
||||
|
||||
private String gaIsoName;
|
||||
private URI distroIsoUrl;
|
||||
private String distroIsoName;
|
||||
|
||||
private ComputeServiceContext context;
|
||||
private String hostId = "host";
|
||||
private String guestId = "guest";
|
||||
private String majorVersion;
|
||||
private URI vboxDmg;
|
||||
private String vboxVersionName;
|
||||
private String basebaseResource;
|
||||
private String port;
|
||||
|
||||
private String vboxWebServerCredential;
|
||||
private String vboxWebServerIdentity;
|
||||
|
||||
public void setupCredentials() {
|
||||
endpoint = URI.create(System.getProperty("test." + provider + ".endpoint", "http://localhost:18083/"));
|
||||
apiVersion = System.getProperty("test." + provider + ".apiversion", "4.1.2r73507");
|
||||
majorVersion = Iterables.get(Splitter.on('r').split(apiVersion), 0);
|
||||
}
|
||||
|
||||
public Logger logger() {
|
||||
return context.utils().loggerFactory().getLogger("jclouds.compute");
|
||||
}
|
||||
|
||||
public void setupConfigurationProperties() {
|
||||
workingDir = System.getProperty("user.home") + File.separator
|
||||
+ System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test");
|
||||
if (new File(workingDir).mkdir())
|
||||
;
|
||||
gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_" + majorVersion + ".iso");
|
||||
gaIsoUrl = URI.create(System.getProperty("test." + provider + ".gaIsoUrl",
|
||||
"http://download.virtualbox.org/virtualbox/" + majorVersion + "/" + gaIsoName));
|
||||
|
||||
distroIsoName = System.getProperty("test." + provider + ".distroIsoName", "ubuntu-11.04-server-i386.iso");
|
||||
distroIsoUrl = URI.create(System.getProperty("test." + provider + ".distroIsoUrl",
|
||||
"http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso"));
|
||||
vboxDmg = URI.create(System.getProperty("test." + provider + ".vboxDmg",
|
||||
"http://download.virtualbox.org/virtualbox/4.1.2/VirtualBox-4.1.2-73507-OSX.dmg"));
|
||||
vboxVersionName = System.getProperty("test" + provider + ".vboxVersionName", "VirtualBox-4.1.2-73507-OSX.dmg");
|
||||
basebaseResource = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_BASE_RESOURCE, ".");
|
||||
port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
||||
vboxWebServerIdentity = System.getProperty(VirtualBoxConstants.VIRTUALBOX_WEBSERVER_IDENTITY, "toor");
|
||||
vboxWebServerCredential = System.getProperty(VirtualBoxConstants.VIRTUALBOX_WEBSERVER_CREDENTIAL, "12345");
|
||||
}
|
||||
|
||||
@BeforeSuite
|
||||
public void setupClient() throws Exception {
|
||||
context = TestUtils.computeServiceForLocalhostAndGuest();
|
||||
setupCredentials();
|
||||
setupConfigurationProperties();
|
||||
downloadFileUnlessPresent(distroIsoUrl, workingDir, distroIsoName);
|
||||
downloadFileUnlessPresent(gaIsoUrl, workingDir, gaIsoName);
|
||||
|
||||
installVbox();
|
||||
checkVboxVersionExpected();
|
||||
new StartVBoxIfNotAlreadyRunning(context, hostId, new Credentials(vboxWebServerIdentity, vboxWebServerCredential));
|
||||
new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
||||
}
|
||||
|
||||
@AfterSuite
|
||||
public void stopVboxWebServer() throws IOException {
|
||||
runScriptOnNode(hostId, "pidof vboxwebsrv | xargs kill");
|
||||
}
|
||||
|
||||
public void installVbox() throws Exception {
|
||||
if (runScriptOnNode(hostId, "VBoxManage --version", runAsRoot(false).wrapInInitScript(false)).getExitCode() != 0) {
|
||||
logger().debug("installing virtualbox");
|
||||
if (isOSX(hostId)) {
|
||||
downloadFileUnlessPresent(vboxDmg, workingDir, vboxVersionName);
|
||||
runScriptOnNode(hostId, "hdiutil attach " + workingDir + "/" + vboxVersionName);
|
||||
runScriptOnNode(hostId,
|
||||
"installer -pkg /Volumes/VirtualBox/VirtualBox.mpkg -target /Volumes/Macintosh\\ HD");
|
||||
} else {
|
||||
// TODO other platforms
|
||||
runScriptOnNode(hostId, "cat > /etc/apt/sources.list.d/TODO");
|
||||
runScriptOnNode(hostId,
|
||||
"wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -");
|
||||
runScriptOnNode(hostId, "apt-get update");
|
||||
runScriptOnNode(hostId, "apt-get --yes install virtualbox-4.1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkVboxVersionExpected() throws IOException, InterruptedException {
|
||||
logger().debug("checking virtualbox version");
|
||||
assertEquals(runScriptOnNode(hostId, "VBoxManage -version").getOutput().trim(), apiVersion);
|
||||
}
|
||||
|
||||
public boolean isOSX(String id) {
|
||||
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription().equals(
|
||||
"Mac OS X");
|
||||
}
|
||||
|
||||
public File downloadFileUnlessPresent(URI sourceURL, String destinationDir, String filename) throws Exception {
|
||||
|
||||
File iso = new File(destinationDir, filename);
|
||||
|
||||
if (!iso.exists()) {
|
||||
InputStream is = context.utils().http().get(sourceURL);
|
||||
checkNotNull(is, "%s not found", sourceURL);
|
||||
try {
|
||||
ByteStreams.copy(is, new FileOutputStream(iso));
|
||||
} finally {
|
||||
Closeables.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
return iso;
|
||||
}
|
||||
|
||||
public ExecResponse runScriptOnNode(String nodeId, String command, RunScriptOptions options) {
|
||||
ExecResponse toReturn = context.getComputeService().runScriptOnNode(nodeId, command, options);
|
||||
assert toReturn.getExitCode() == 0 : toReturn;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public ExecResponse runScriptOnNode(String nodeId, String command) {
|
||||
return runScriptOnNode(nodeId, command, wrapInInitScript(false));
|
||||
}
|
||||
|
||||
}
|
|
@ -18,10 +18,11 @@
|
|||
*/
|
||||
package org.jclouds.virtualbox.experiment;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.byon.Node;
|
||||
import org.jclouds.byon.config.CacheNodeStoreModule;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
|
@ -31,75 +32,48 @@ import org.jclouds.domain.Credentials;
|
|||
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
|
||||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
public static ComputeServiceContext computeServiceForLocalhostAndGuest() throws IOException {
|
||||
|
||||
Node host = Node.builder().id("host")
|
||||
.name("host installing virtualbox")
|
||||
.hostname("localhost")
|
||||
.osFamily(OsFamily.LINUX.toString())
|
||||
.osDescription(System.getProperty("os.name"))
|
||||
.osVersion(System.getProperty("os.version"))
|
||||
.group("ssh")
|
||||
.username(System.getProperty("user.name"))
|
||||
.credentialUrl(privateKeyFile())
|
||||
.build();
|
||||
Node guest = Node.builder().id("guest")
|
||||
.name("new guest")
|
||||
.hostname("localhost")
|
||||
.loginPort(2222)
|
||||
.osFamily(OsFamily.UBUNTU.toString())
|
||||
.osDescription("ubuntu/11.04")
|
||||
.osVersion(System.getProperty("11.04"))
|
||||
.group("guest")
|
||||
.username("toor")
|
||||
.sudoPassword("password")
|
||||
.credential("password")
|
||||
.build();
|
||||
Node host = Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
|
||||
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
|
||||
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
|
||||
.credentialUrl(privateKeyFile()).build();
|
||||
Node guest = Node.builder().id("guest").name("new guest").hostname("localhost").loginPort(2222)
|
||||
.osFamily(OsFamily.UBUNTU.toString()).osDescription("ubuntu/11.04").osVersion(System.getProperty("11.04"))
|
||||
.group("guest").username("toor").sudoPassword("password").credential("password").build();
|
||||
|
||||
final Map<String, Node> nodeMap = ImmutableMap.<String, Node>builder().put("host", host).put("guest", guest).build();
|
||||
final Map<String, Node> nodeMap = ImmutableMap.<String, Node> builder().put("host", host).put("guest", guest)
|
||||
.build();
|
||||
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module> of(
|
||||
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(nodeMap)));
|
||||
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(),
|
||||
new CacheNodeStoreModule(nodeMap)));
|
||||
}
|
||||
|
||||
public static ComputeServiceContext computeServiceForLocalhostAndGuest(String hostId, String hostname, String guestId, String guestHostname,
|
||||
Credentials guestLogin) throws IOException {
|
||||
public static ComputeServiceContext computeServiceForLocalhostAndGuest(String hostId, String hostname,
|
||||
String guestId, String guestHostname, Credentials guestLogin) {
|
||||
|
||||
Node host = Node.builder().id(hostId)
|
||||
.name("host installing virtualbox")
|
||||
.hostname(hostname)
|
||||
.osFamily(OsFamily.LINUX.toString())
|
||||
.osDescription(System.getProperty("os.name"))
|
||||
.osVersion(System.getProperty("os.version"))
|
||||
.group("ssh")
|
||||
.username(System.getProperty("user.name"))
|
||||
.credentialUrl(privateKeyFile())
|
||||
Node host = Node.builder().id(hostId).name("host installing virtualbox").hostname(hostname)
|
||||
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
|
||||
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
|
||||
.credentialUrl(privateKeyFile()).build();
|
||||
Node guest = Node.builder().id(guestId).name("new guest").hostname(guestHostname).loginPort(2222)
|
||||
.osFamily(OsFamily.UBUNTU.toString()).osDescription("ubuntu/11.04").osVersion(System.getProperty("11.04"))
|
||||
.group("jclouds-linux-image").username(guestLogin.identity).sudoPassword(guestLogin.credential)
|
||||
.credential(guestLogin.credential).build();
|
||||
|
||||
final Map<String, Node> nodeMap = ImmutableMap.<String, Node> builder().put(hostId, host).put(guestId, guest)
|
||||
.build();
|
||||
Node guest = Node.builder().id(guestId)
|
||||
.name("new guest")
|
||||
.hostname(guestHostname)
|
||||
.loginPort(2222)
|
||||
.osFamily(OsFamily.UBUNTU.toString())
|
||||
.osDescription("ubuntu/11.04")
|
||||
.osVersion(System.getProperty("11.04"))
|
||||
.group("jclouds-linux-image")
|
||||
.username(guestLogin.identity)
|
||||
.sudoPassword(guestLogin.credential)
|
||||
.credential(guestLogin.credential)
|
||||
.build();
|
||||
|
||||
|
||||
final Map<String, Node> nodeMap = ImmutableMap.<String, Node>builder().put(hostId, host).put(guestId, guest).build();
|
||||
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module> of(
|
||||
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(nodeMap)));
|
||||
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(),
|
||||
new CacheNodeStoreModule(nodeMap)));
|
||||
}
|
||||
|
||||
private static URI privateKeyFile() {
|
||||
|
@ -113,6 +87,7 @@ public class TestUtils {
|
|||
|
||||
public static ComputeServiceContext computeServiceForVirtualBox(Cache<String, Node> cache) {
|
||||
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module> of(
|
||||
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(cache)));
|
||||
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(),
|
||||
new CacheNodeStoreModule(cache)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -19,12 +19,16 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
|
@ -49,8 +53,8 @@ public class ApplyMemoryToMachineTest {
|
|||
@Test(expectedExceptions = VBoxException.class)
|
||||
public void testRethrowInvalidRamSizeError() throws Exception {
|
||||
// Mainly here for documentation purposes
|
||||
final String error = "VirtualBox error: Invalid RAM size: " +
|
||||
"3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)";
|
||||
final String error = "VirtualBox error: Invalid RAM size: "
|
||||
+ "3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)";
|
||||
|
||||
long memorySize = 1024l;
|
||||
IMachine machine = createMock(IMachine.class);
|
||||
|
|
|
@ -18,15 +18,18 @@
|
|||
*/
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
|
@ -67,7 +70,8 @@ public class AttachDistroMediumToMachineTest {
|
|||
errorBuilder.append("of this virtual machine (0x80BB000C)");
|
||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
||||
|
||||
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException);
|
||||
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
|
||||
isoAlreadyAttachedException);
|
||||
machine.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
|
||||
expectLastCall().andThrow(isoAttachedException);
|
||||
|
||||
|
@ -92,7 +96,8 @@ public class AttachDistroMediumToMachineTest {
|
|||
errorBuilder.append("Some other VBox error");
|
||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
||||
|
||||
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException);
|
||||
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
|
||||
isoAlreadyAttachedException);
|
||||
machine.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
|
||||
expectLastCall().andThrow(isoAttachedException);
|
||||
|
||||
|
@ -102,5 +107,4 @@ public class AttachDistroMediumToMachineTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,12 +19,23 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.*;
|
||||
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.easymock.EasyMock.anyLong;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.virtualbox_4_1.DeviceType.HardDisk;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
|
@ -54,7 +65,8 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
|||
machine.saveSettings();
|
||||
replay(manager, machine, vBox, hardDisk);
|
||||
|
||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk).apply(machine);
|
||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk)
|
||||
.apply(machine);
|
||||
|
||||
verify(machine);
|
||||
|
||||
|
@ -79,13 +91,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
|||
errorBuilder.append("of this virtual machine (0x80BB000C)");
|
||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
||||
|
||||
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException);
|
||||
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
|
||||
isoAlreadyAttachedException);
|
||||
machine.attachDevice(controllerIDE, controllerPort, device, HardDisk, hardDisk);
|
||||
expectLastCall().andThrow(isoAttachedException);
|
||||
|
||||
replay(manager, machine, vBox, hardDisk);
|
||||
|
||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk).apply(machine);
|
||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk)
|
||||
.apply(machine);
|
||||
|
||||
verify(machine);
|
||||
|
||||
|
@ -108,13 +122,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
|||
errorBuilder.append("Some other VBox error");
|
||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
||||
|
||||
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException);
|
||||
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
|
||||
isoAlreadyAttachedException);
|
||||
machine.attachDevice(controllerIDE, controllerPort, device, HardDisk, hardDisk);
|
||||
expectLastCall().andThrow(isoAttachedException);
|
||||
|
||||
replay(manager, machine, vBox, hardDisk);
|
||||
|
||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk).apply(machine);
|
||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk)
|
||||
.apply(machine);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -19,13 +19,20 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.*;
|
||||
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.virtualbox_4_1.NATProtocol.TCP;
|
||||
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INATEngine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
|
@ -60,8 +67,8 @@ public class AttachNATRedirectRuleToMachineTest {
|
|||
INetworkAdapter networkAdapter = createMock(INetworkAdapter.class);
|
||||
INATEngine natEngine = createMock(INATEngine.class);
|
||||
|
||||
String error = "VirtualBox error: Argument slot is invalid " +
|
||||
"(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)";
|
||||
String error = "VirtualBox error: Argument slot is invalid "
|
||||
+ "(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)";
|
||||
|
||||
VBoxException invalidSlotException = new VBoxException(createNiceMock(Throwable.class), error);
|
||||
expect(machine.getNetworkAdapter(adapterId)).andThrow(invalidSlotException);
|
||||
|
@ -73,5 +80,4 @@ public class AttachNATRedirectRuleToMachineTest {
|
|||
verify(machine, networkAdapter, natEngine);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,15 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static org.easymock.EasyMock.anyBoolean;
|
||||
import static org.easymock.EasyMock.eq;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
|
@ -26,10 +35,6 @@ import org.virtualbox_4_1.IVirtualBox;
|
|||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import static org.easymock.EasyMock.anyBoolean;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
|
@ -56,7 +61,8 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
vBox.findMachine(vmName);
|
||||
expectLastCall().andThrow(vBoxException);
|
||||
|
||||
expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn(createdMachine).anyTimes();
|
||||
expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn(
|
||||
createdMachine).anyTimes();
|
||||
|
||||
vBox.registerMachine(createdMachine);
|
||||
|
||||
|
@ -103,7 +109,6 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private String anyString() {
|
||||
|
|
|
@ -19,14 +19,23 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.*;
|
||||
|
||||
import static org.easymock.EasyMock.anyLong;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.testng.Assert.assertNotSame;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
|
@ -137,5 +146,4 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
|||
new CreateMediumIfNotAlreadyExists(manager, diskFormat, true).apply(adminDiskPath);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.virtualbox_4_1.VirtualBoxManager;
|
|||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
//@Test(groups = "live")
|
||||
public class IMachineToNodeMetadataTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
/**
|
||||
* @author Andrea Turli, Mattias Holmqvist
|
||||
*/
|
||||
|
||||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||
|
@ -47,6 +43,9 @@ import org.virtualbox_4_1.VirtualBoxManager;
|
|||
|
||||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
* @author Andrea Turli, Mattias Holmqvist
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "IsoToIMachineLiveTest")
|
||||
public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||
|
||||
|
@ -76,24 +75,16 @@ public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
public void testCreateImageMachineFromIso() throws Exception {
|
||||
|
||||
VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
|
||||
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId, "localhost", new Credentials("toor", "password"));
|
||||
IMachine imageMachine = new IsoToIMachine(manager,
|
||||
adminDisk,
|
||||
diskFormat,
|
||||
settingsFile,
|
||||
vmName,
|
||||
osTypeId,
|
||||
vmId,
|
||||
forceOverwrite,
|
||||
controllerIDE,
|
||||
localHostContext,
|
||||
hostId,
|
||||
guestId,
|
||||
new Credentials("toor", "password")).apply("ubuntu-11.04-server-i386.iso");
|
||||
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId,
|
||||
"localhost", new Credentials("toor", "password"));
|
||||
IMachine imageMachine = new IsoToIMachine(manager, adminDisk, diskFormat, settingsFile, vmName, osTypeId, vmId,
|
||||
forceOverwrite, controllerIDE, localHostContext, hostId, guestId, new Credentials("toor", "password"))
|
||||
.apply("ubuntu-11.04-server-i386.iso");
|
||||
|
||||
IMachineToImage iMachineToImage = new IMachineToImage(manager, map);
|
||||
Image newImage = iMachineToImage.apply(imageMachine);
|
||||
//TODO add the description to the cache of the images or serialize to YAML the image desc
|
||||
// TODO add the description to the cache of the images or serialize to
|
||||
// YAML the image desc
|
||||
Set<? extends Image> images = context.getComputeService().listImages();
|
||||
|
||||
assertTrue(any(images, equalTo(newImage)));
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.virtualbox.functions;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
@Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest")
|
||||
public class LaunchMachineIfNotAlreadyRunningTest {
|
||||
|
||||
@Test
|
||||
public void testDoNotLaunchIfAlreadyRunning() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
// VirtualBox error: The given session is busy (0x80BB0007)
|
||||
// VirtualBox error: The machine
|
||||
// 'jclouds-image-virtualbox-iso-to-machine-test' is not registered
|
||||
// (0x8000FFFF)
|
||||
|
||||
@Test
|
||||
public void testLaunchIfNotStarted() throws Exception {
|
||||
|
||||
final String type = "gui";
|
||||
final String environment = "";
|
||||
ISession session = createMock(ISession.class);
|
||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
||||
IMachine machine = createMock(IMachine.class);
|
||||
IProgress progress = createMock(IProgress.class);
|
||||
|
||||
expect(manager.getSessionObject()).andReturn(session);
|
||||
expect(machine.launchVMProcess(session, type, environment)).andReturn(progress);
|
||||
progress.waitForCompletion(-1);
|
||||
|
||||
replay(manager, machine, session, progress);
|
||||
|
||||
new LaunchMachineIfNotAlreadyRunning(manager, ExecutionType.GUI, "").apply(machine);
|
||||
|
||||
verify(manager, machine, session, progress);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,3 +1,22 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.virtualbox.functions.admin;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
@ -13,23 +32,6 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work for additional
|
||||
* information regarding copyright ownership. jclouds licenses this file to you
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* @author Andrea Turli
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
|
|
|
@ -19,36 +19,37 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions.admin;
|
||||
|
||||
/**
|
||||
* @author Andrea Turli
|
||||
*/
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
@Test(groups = "live", singleThreaded = true, testName = "StartJettyIfNotAlreadyRunningLiveTest")
|
||||
public class StartJettyIfNotAlreadyRunningLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||
/**
|
||||
* @author Andrea Turli
|
||||
*/
|
||||
@Test(groups = "unit", singleThreaded = true, testName = "StartJettyIfNotAlreadyRunningTest")
|
||||
public class StartJettyIfNotAlreadyRunningTest {
|
||||
|
||||
private String basebaseResource = ".";
|
||||
private String port = "8080";
|
||||
private int port = 8080;
|
||||
|
||||
@Test
|
||||
public void testLaunchJettyServer() throws Exception {
|
||||
Server server = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
||||
server.stop();
|
||||
assertEquals(server.getState(), server.STOPPED);
|
||||
public void testLaunchJettyServerWhenAlreadyRunningDoesntLaunchAgain() {
|
||||
Server jetty = createMock(Server.class);
|
||||
expect(jetty.getState()).andReturn(Server.STARTED);
|
||||
replay(jetty);
|
||||
|
||||
assertEquals(new StartJettyIfNotAlreadyRunning(jetty, port).apply(basebaseResource), jetty);
|
||||
verify(jetty);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchingSameJettyServer() throws Exception {
|
||||
Server server = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
||||
assertEquals(server.getState(), server.STARTED);
|
||||
Server sameServer = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
||||
sameServer.stop();
|
||||
public void testLaunchJettyServerWhenNotRunningStartsJettyOnCorrectHostPortAndBasedir() {
|
||||
// TODO: all yours!
|
||||
}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.virtualbox.functions.admin;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
@Test(groups = "live", singleThreaded = true, testName = "startVBoxIfNotAlreadyRunningLiveTest")
|
||||
public class StartVBoxIfNotAlreadyRunningLiveTest {
|
||||
|
||||
@Test
|
||||
public void testStartVbox() throws Exception {
|
||||
Credentials localhostCredentials = new Credentials("toor", "password");
|
||||
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest("hostId", "localhost", "guestId", "localhost", localhostCredentials);
|
||||
|
||||
URI endpointUri = URI.create("http://localhost:18083/");
|
||||
|
||||
VirtualBoxManager manager = new StartVBoxIfNotAlreadyRunning(localHostContext, "hostId", localhostCredentials).apply(endpointUri);
|
||||
|
||||
assertEquals(manager.getSessionObject().getState(), SessionState.Unlocked);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.virtualbox.functions.admin;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.ssh.ConfiguresSshClient;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
|
||||
@Test(groups = "unit", singleThreaded = true, testName = "StartVBoxIfNotAlreadyRunningTest")
|
||||
public class StartVBoxIfNotAlreadyRunningTest {
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testStartVboxThrowsIllegalStateExceptionIfTheNodeIdConfiguredIsntAround() throws Exception {
|
||||
|
||||
ComputeService compute = new ComputeServiceContextFactory().createContext("stub", "foo", "bar")
|
||||
.getComputeService();
|
||||
|
||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Predicate<IPSocket> socketTester = createMock(Predicate.class);
|
||||
String hostId = "hostId";
|
||||
URI endpointUri = URI.create("http://localhost:18083/");
|
||||
Credentials localhostCredentials = new Credentials("toor", "password");
|
||||
|
||||
manager.connect(endpointUri.toASCIIString(), localhostCredentials.identity, localhostCredentials.credential);
|
||||
|
||||
replay(socketTester);
|
||||
replay(manager);
|
||||
|
||||
new StartVBoxIfNotAlreadyRunning(compute, manager, socketTester, hostId, localhostCredentials).apply(endpointUri);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartVboxConnectsToManagerWhenPortAlreadyListening() throws Exception {
|
||||
|
||||
ComputeService compute = new ComputeServiceContextFactory().createContext("stub", "foo", "bar")
|
||||
.getComputeService();
|
||||
|
||||
// TODO: possibly better to use a defined name as opposed to an id, since
|
||||
// most compute services the id is not predictable.
|
||||
NodeMetadata node = Iterables.getOnlyElement(compute.createNodesInGroup("foo", 1));
|
||||
String hostId = node.getId();
|
||||
|
||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Predicate<IPSocket> socketTester = createMock(Predicate.class);
|
||||
URI endpointUri = URI.create("http://localhost:18083/");
|
||||
Credentials localhostCredentials = new Credentials("toor", "password");
|
||||
|
||||
expect(socketTester.apply(new IPSocket(endpointUri.getHost(), endpointUri.getPort()))).andReturn(true);
|
||||
manager.connect(endpointUri.toASCIIString(), localhostCredentials.identity, localhostCredentials.credential);
|
||||
|
||||
replay(socketTester);
|
||||
replay(manager);
|
||||
|
||||
assertEquals(
|
||||
new StartVBoxIfNotAlreadyRunning(compute, manager, socketTester, hostId, localhostCredentials)
|
||||
.apply(endpointUri),
|
||||
manager);
|
||||
|
||||
verify(socketTester);
|
||||
verify(manager);
|
||||
}
|
||||
|
||||
@ConfiguresSshClient
|
||||
static class StartingVBoxWhenNotRunningModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
SshClient.Factory factory = createMock(SshClient.Factory.class);
|
||||
SshClient client = createMock(SshClient.class);
|
||||
// NOTE we may want to switch to a node supplier so that we can predict
|
||||
// these values. Right now, it is node 2 since the above test made node
|
||||
// 1.
|
||||
IPSocket expectedSshSockectFor2ndCreatedNode = new IPSocket("144.175.1.2", 22);
|
||||
Credentials expectedCredentialsFor2ndCreatedNode = new Credentials("root", "password2");
|
||||
expect(factory.create(expectedSshSockectFor2ndCreatedNode, expectedCredentialsFor2ndCreatedNode)).andReturn(
|
||||
client).times(2);
|
||||
|
||||
expect(client.getUsername()).andReturn(expectedCredentialsFor2ndCreatedNode.identity).times(2);
|
||||
expect(client.getHostAddress()).andReturn(expectedSshSockectFor2ndCreatedNode.getAddress()).times(2);
|
||||
|
||||
client.disconnect();
|
||||
client.connect();
|
||||
expect(client.exec("VBoxManage setproperty websrvauthlibrary null\n")).andReturn(new ExecResponse("", "", 0));
|
||||
|
||||
client.disconnect();
|
||||
client.connect();
|
||||
expect(client.exec("vboxwebsrv -t 10000 -v -b\n")).andReturn(new ExecResponse("", "", 0));
|
||||
|
||||
replay(factory);
|
||||
replay(client);
|
||||
bind(SshClient.Factory.class).toInstance(factory);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartVboxDisablesPasswordAccessOnWebsrvauthlibraryStartsVboxwebsrvInBackgroundAndConnectsManagerWhenPortIsNotListening()
|
||||
throws Exception {
|
||||
ComputeService compute = new ComputeServiceContextFactory().createContext("stub", "foo", "bar",
|
||||
ImmutableSet.<Module> of(new StartingVBoxWhenNotRunningModule())).getComputeService();
|
||||
NodeMetadata node = Iterables.getOnlyElement(compute.createNodesInGroup("foo", 1));
|
||||
String hostId = node.getId();
|
||||
|
||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Predicate<IPSocket> socketTester = createMock(Predicate.class);
|
||||
Credentials localhostCredentials = new Credentials("toor", "password");
|
||||
URI endpointUri = URI.create("http://localhost:18083/");
|
||||
|
||||
expect(socketTester.apply(new IPSocket(endpointUri.getHost(), endpointUri.getPort()))).andReturn(false);
|
||||
|
||||
manager.connect(endpointUri.toASCIIString(), localhostCredentials.identity, localhostCredentials.credential);
|
||||
|
||||
replay(socketTester);
|
||||
replay(manager);
|
||||
|
||||
assertEquals(
|
||||
new StartVBoxIfNotAlreadyRunning(compute, manager, socketTester, hostId, localhostCredentials)
|
||||
.apply(endpointUri),
|
||||
manager);
|
||||
|
||||
verify(socketTester);
|
||||
verify(manager);
|
||||
}
|
||||
}
|
|
@ -20,8 +20,6 @@ package org.jclouds.scriptbuilder.util;
|
|||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||
import org.jclouds.scriptbuilder.domain.ShellToken;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -35,7 +33,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
@Test(groups = "unit")
|
||||
public class UtilsTest {
|
||||
|
||||
public void testReplaceTokens() throws UnsupportedEncodingException {
|
||||
public void testReplaceTokens() {
|
||||
assertEquals(Utils.replaceTokens("hello {where}", ImmutableMap.of("where", "world")),
|
||||
"hello world");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue