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 static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
||||||
|
@ -34,13 +33,12 @@ import org.testng.annotations.Test;
|
||||||
public class AtmosContainerIntegrationLiveTest extends BaseContainerIntegrationTest {
|
public class AtmosContainerIntegrationLiveTest extends BaseContainerIntegrationTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void testListContainerMaxResults() throws InterruptedException,
|
public void testListContainerMaxResults() throws InterruptedException {
|
||||||
UnsupportedEncodingException {
|
|
||||||
// Not currently working
|
// Not currently working
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void testListContainerMarker() throws InterruptedException, UnsupportedEncodingException {
|
public void testListContainerMarker() throws InterruptedException {
|
||||||
// Not currently working https://community.emc.com/thread/100545
|
// 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.DEFAULT_AMAZON_HEADERTAG;
|
||||||
import static org.jclouds.s3.reference.S3Headers.METADATA_DIRECTIVE;
|
import static org.jclouds.s3.reference.S3Headers.METADATA_DIRECTIVE;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
@ -227,7 +226,7 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
||||||
* @param eTag
|
* @param eTag
|
||||||
* hash representing the payload
|
* 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(getIfNoneMatch() == null, "ifETagDoesntMatch() is not compatible with ifETagMatches()");
|
||||||
checkState(getIfModifiedSince() == null, "ifModifiedSince() 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")));
|
replaceHeader(COPY_SOURCE_IF_MATCH, String.format("\"%1$s\"", checkNotNull(eTag, "eTag")));
|
||||||
|
@ -242,10 +241,8 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
||||||
*
|
*
|
||||||
* @param eTag
|
* @param eTag
|
||||||
* hash representing the payload
|
* 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()");
|
checkState(getIfMatch() == null, "ifETagMatches() is not compatible with ifETagDoesntMatch()");
|
||||||
Preconditions.checkState(getIfUnmodifiedSince() == null,
|
Preconditions.checkState(getIfUnmodifiedSince() == null,
|
||||||
"ifUnmodifiedSince() is not compatible with ifETagDoesntMatch()");
|
"ifUnmodifiedSince() is not compatible with ifETagDoesntMatch()");
|
||||||
|
@ -307,7 +304,7 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
||||||
/**
|
/**
|
||||||
* @see CopyObjectOptions#ifSourceETagMatches(String)
|
* @see CopyObjectOptions#ifSourceETagMatches(String)
|
||||||
*/
|
*/
|
||||||
public static CopyObjectOptions ifSourceETagMatches(String eTag) throws UnsupportedEncodingException {
|
public static CopyObjectOptions ifSourceETagMatches(String eTag) {
|
||||||
CopyObjectOptions options = new CopyObjectOptions();
|
CopyObjectOptions options = new CopyObjectOptions();
|
||||||
return options.ifSourceETagMatches(eTag);
|
return options.ifSourceETagMatches(eTag);
|
||||||
}
|
}
|
||||||
|
@ -315,7 +312,7 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
||||||
/**
|
/**
|
||||||
* @see CopyObjectOptions#ifSourceETagDoesntMatch(String)
|
* @see CopyObjectOptions#ifSourceETagDoesntMatch(String)
|
||||||
*/
|
*/
|
||||||
public static CopyObjectOptions ifSourceETagDoesntMatch(String eTag) throws UnsupportedEncodingException {
|
public static CopyObjectOptions ifSourceETagDoesntMatch(String eTag) {
|
||||||
CopyObjectOptions options = new CopyObjectOptions();
|
CopyObjectOptions options = new CopyObjectOptions();
|
||||||
return options.ifSourceETagDoesntMatch(eTag);
|
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.assertNull;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -155,7 +154,7 @@ public class CopyObjectOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagMatches() throws UnsupportedEncodingException {
|
public void testIfETagMatches() {
|
||||||
CopyObjectOptions options = new CopyObjectOptions();
|
CopyObjectOptions options = new CopyObjectOptions();
|
||||||
options.ifSourceETagMatches(etag);
|
options.ifSourceETagMatches(etag);
|
||||||
matchesHex(options.getIfMatch());
|
matchesHex(options.getIfMatch());
|
||||||
|
@ -168,18 +167,18 @@ public class CopyObjectOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagMatchesStatic() throws UnsupportedEncodingException {
|
public void testIfETagMatchesStatic() {
|
||||||
CopyObjectOptions options = ifSourceETagMatches(etag);
|
CopyObjectOptions options = ifSourceETagMatches(etag);
|
||||||
matchesHex(options.getIfMatch());
|
matchesHex(options.getIfMatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testIfETagMatchesNPE() throws UnsupportedEncodingException {
|
public void testIfETagMatchesNPE() {
|
||||||
ifSourceETagMatches(null);
|
ifSourceETagMatches(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testIfETagDoesntMatch() {
|
||||||
CopyObjectOptions options = new CopyObjectOptions();
|
CopyObjectOptions options = new CopyObjectOptions();
|
||||||
options.ifSourceETagDoesntMatch(etag);
|
options.ifSourceETagDoesntMatch(etag);
|
||||||
matchesHex(options.getIfNoneMatch());
|
matchesHex(options.getIfNoneMatch());
|
||||||
|
@ -192,17 +191,17 @@ public class CopyObjectOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagDoesntMatchStatic() throws UnsupportedEncodingException {
|
public void testIfETagDoesntMatchStatic() {
|
||||||
CopyObjectOptions options = ifSourceETagDoesntMatch(etag);
|
CopyObjectOptions options = ifSourceETagDoesntMatch(etag);
|
||||||
matchesHex(options.getIfNoneMatch());
|
matchesHex(options.getIfNoneMatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testIfETagDoesntMatchNPE() throws UnsupportedEncodingException {
|
public void testIfETagDoesntMatchNPE() {
|
||||||
ifSourceETagDoesntMatch(null);
|
ifSourceETagDoesntMatch(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void matchesHex(String match) throws UnsupportedEncodingException {
|
private void matchesHex(String match) {
|
||||||
String expected = "\"" + etag + "\"";
|
String expected = "\"" + etag + "\"";
|
||||||
assertEquals(match, expected);
|
assertEquals(match, expected);
|
||||||
}
|
}
|
||||||
|
@ -213,13 +212,13 @@ public class CopyObjectOptionsTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIfUnmodifiedAfterETagMatches() throws UnsupportedEncodingException {
|
public void testIfUnmodifiedAfterETagMatches() {
|
||||||
ifSourceETagMatches(etag).ifSourceUnmodifiedSince(now);
|
ifSourceETagMatches(etag).ifSourceUnmodifiedSince(now);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalStateException.class)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testIfUnmodifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testIfUnmodifiedAfterETagDoesntMatch() {
|
||||||
ifSourceETagDoesntMatch(etag).ifSourceUnmodifiedSince(now);
|
ifSourceETagDoesntMatch(etag).ifSourceUnmodifiedSince(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,49 +229,49 @@ public class CopyObjectOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalStateException.class)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testIfModifiedAfterETagMatches() throws UnsupportedEncodingException {
|
public void testIfModifiedAfterETagMatches() {
|
||||||
ifSourceETagMatches(etag).ifSourceModifiedSince(now);
|
ifSourceETagMatches(etag).ifSourceModifiedSince(now);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIfModifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testIfModifiedAfterETagDoesntMatch() {
|
||||||
ifSourceETagDoesntMatch(etag).ifSourceModifiedSince(now);
|
ifSourceETagDoesntMatch(etag).ifSourceModifiedSince(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalStateException.class)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testETagMatchesAfterIfModified() throws UnsupportedEncodingException {
|
public void testETagMatchesAfterIfModified() {
|
||||||
ifSourceModifiedSince(now).ifSourceETagMatches(etag);
|
ifSourceModifiedSince(now).ifSourceETagMatches(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testETagMatchesAfterIfUnmodified() throws UnsupportedEncodingException {
|
public void testETagMatchesAfterIfUnmodified() {
|
||||||
ifSourceUnmodifiedSince(now).ifSourceETagMatches(etag);
|
ifSourceUnmodifiedSince(now).ifSourceETagMatches(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalStateException.class)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testETagMatchesAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testETagMatchesAfterETagDoesntMatch() {
|
||||||
ifSourceETagDoesntMatch(etag).ifSourceETagMatches(etag);
|
ifSourceETagDoesntMatch(etag).ifSourceETagMatches(etag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testETagDoesntMatchAfterIfModified() throws UnsupportedEncodingException {
|
public void testETagDoesntMatchAfterIfModified() {
|
||||||
ifSourceModifiedSince(now).ifSourceETagDoesntMatch(etag);
|
ifSourceModifiedSince(now).ifSourceETagDoesntMatch(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalStateException.class)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testETagDoesntMatchAfterIfUnmodified() throws UnsupportedEncodingException {
|
public void testETagDoesntMatchAfterIfUnmodified() {
|
||||||
ifSourceUnmodifiedSince(now).ifSourceETagDoesntMatch(etag);
|
ifSourceUnmodifiedSince(now).ifSourceETagDoesntMatch(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalStateException.class)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testETagDoesntMatchAfterETagMatches() throws UnsupportedEncodingException {
|
public void testETagDoesntMatchAfterETagMatches() {
|
||||||
ifSourceETagMatches(etag).ifSourceETagDoesntMatch(etag);
|
ifSourceETagMatches(etag).ifSourceETagDoesntMatch(etag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuildRequestHeadersWhenMetadataNull() throws UnsupportedEncodingException {
|
void testBuildRequestHeadersWhenMetadataNull() {
|
||||||
CopyObjectOptions options = new CopyObjectOptions();
|
CopyObjectOptions options = new CopyObjectOptions();
|
||||||
options.setHeaderTag(DEFAULT_AMAZON_HEADERTAG);
|
options.setHeaderTag(DEFAULT_AMAZON_HEADERTAG);
|
||||||
|
|
||||||
|
@ -281,7 +280,7 @@ public class CopyObjectOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuildRequestHeaders() throws UnsupportedEncodingException {
|
void testBuildRequestHeaders() {
|
||||||
CopyObjectOptions options = ifSourceModifiedSince(now).ifSourceETagDoesntMatch(etag).overrideMetadataWith(
|
CopyObjectOptions options = ifSourceModifiedSince(now).ifSourceETagDoesntMatch(etag).overrideMetadataWith(
|
||||||
goodMeta);
|
goodMeta);
|
||||||
options.setHeaderTag(DEFAULT_AMAZON_HEADERTAG);
|
options.setHeaderTag(DEFAULT_AMAZON_HEADERTAG);
|
||||||
|
@ -310,7 +309,7 @@ public class CopyObjectOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuildRequestHeadersACL() throws UnsupportedEncodingException {
|
void testBuildRequestHeadersACL() {
|
||||||
CopyObjectOptions options = overrideAcl(CannedAccessPolicy.AUTHENTICATED_READ);
|
CopyObjectOptions options = overrideAcl(CannedAccessPolicy.AUTHENTICATED_READ);
|
||||||
options.setHeaderTag(DEFAULT_AMAZON_HEADERTAG);
|
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.jclouds.s3.options.ListBucketOptions.Builder.withPrefix;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.jclouds.s3.reference.S3Constants;
|
|
||||||
import org.jclouds.http.options.HttpRequestOptions;
|
import org.jclouds.http.options.HttpRequestOptions;
|
||||||
|
import org.jclouds.s3.reference.S3Constants;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
@ -47,7 +46,7 @@ public class ListBucketOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrefix() throws UnsupportedEncodingException {
|
public void testPrefix() {
|
||||||
ListBucketOptions options = new ListBucketOptions();
|
ListBucketOptions options = new ListBucketOptions();
|
||||||
options.withPrefix("test");
|
options.withPrefix("test");
|
||||||
assertEquals(options.buildQueryParameters().get(S3Constants.PREFIX), Collections
|
assertEquals(options.buildQueryParameters().get(S3Constants.PREFIX), Collections
|
||||||
|
@ -61,7 +60,7 @@ public class ListBucketOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneOptionQueryString() throws UnsupportedEncodingException {
|
public void testOneOptionQueryString() {
|
||||||
ListBucketOptions options = new ListBucketOptions();
|
ListBucketOptions options = new ListBucketOptions();
|
||||||
options.withPrefix("test");
|
options.withPrefix("test");
|
||||||
Multimap<String, String> map = options.buildQueryParameters();
|
Multimap<String, String> map = options.buildQueryParameters();
|
||||||
|
@ -70,7 +69,7 @@ public class ListBucketOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTwoOptionQueryString() throws UnsupportedEncodingException {
|
public void testTwoOptionQueryString() {
|
||||||
ListBucketOptions options = new ListBucketOptions();
|
ListBucketOptions options = new ListBucketOptions();
|
||||||
options.withPrefix("test").maxResults(1);
|
options.withPrefix("test").maxResults(1);
|
||||||
Multimap<String, String> map = options.buildQueryParameters();
|
Multimap<String, String> map = options.buildQueryParameters();
|
||||||
|
@ -80,7 +79,7 @@ public class ListBucketOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrefixAndDelimiterUrlEncodingQueryString() throws UnsupportedEncodingException {
|
public void testPrefixAndDelimiterUrlEncodingQueryString() {
|
||||||
ListBucketOptions options = new ListBucketOptions();
|
ListBucketOptions options = new ListBucketOptions();
|
||||||
options.withPrefix("/test").delimiter("/");
|
options.withPrefix("/test").delimiter("/");
|
||||||
Multimap<String, String> map = options.buildQueryParameters();
|
Multimap<String, String> map = options.buildQueryParameters();
|
||||||
|
@ -97,19 +96,19 @@ public class ListBucketOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrefixStatic() throws UnsupportedEncodingException {
|
public void testPrefixStatic() {
|
||||||
ListBucketOptions options = withPrefix("test");
|
ListBucketOptions options = withPrefix("test");
|
||||||
assertEquals(options.buildQueryParameters().get(S3Constants.PREFIX), Collections
|
assertEquals(options.buildQueryParameters().get(S3Constants.PREFIX), Collections
|
||||||
.singletonList("test"));
|
.singletonList("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testPrefixNPE() throws UnsupportedEncodingException {
|
public void testPrefixNPE() {
|
||||||
withPrefix(null);
|
withPrefix(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarker() throws UnsupportedEncodingException {
|
public void testMarker() {
|
||||||
ListBucketOptions options = new ListBucketOptions();
|
ListBucketOptions options = new ListBucketOptions();
|
||||||
options.afterMarker("test");
|
options.afterMarker("test");
|
||||||
assertEquals(options.buildQueryParameters().get(S3Constants.MARKER), Collections
|
assertEquals(options.buildQueryParameters().get(S3Constants.MARKER), Collections
|
||||||
|
@ -123,14 +122,14 @@ public class ListBucketOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarkerStatic() throws UnsupportedEncodingException {
|
public void testMarkerStatic() {
|
||||||
ListBucketOptions options = afterMarker("test");
|
ListBucketOptions options = afterMarker("test");
|
||||||
assertEquals(options.buildQueryParameters().get(S3Constants.MARKER), Collections
|
assertEquals(options.buildQueryParameters().get(S3Constants.MARKER), Collections
|
||||||
.singletonList("test"));
|
.singletonList("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testMarkerNPE() throws UnsupportedEncodingException {
|
public void testMarkerNPE() {
|
||||||
afterMarker(null);
|
afterMarker(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +160,7 @@ public class ListBucketOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelimiter() throws UnsupportedEncodingException {
|
public void testDelimiter() {
|
||||||
ListBucketOptions options = new ListBucketOptions();
|
ListBucketOptions options = new ListBucketOptions();
|
||||||
options.delimiter("test");
|
options.delimiter("test");
|
||||||
assertEquals(options.buildQueryParameters().get(S3Constants.DELIMITER), Collections
|
assertEquals(options.buildQueryParameters().get(S3Constants.DELIMITER), Collections
|
||||||
|
@ -176,14 +175,14 @@ public class ListBucketOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelimiterStatic() throws UnsupportedEncodingException {
|
public void testDelimiterStatic() {
|
||||||
ListBucketOptions options = delimiter("test");
|
ListBucketOptions options = delimiter("test");
|
||||||
assertEquals(options.buildQueryParameters().get(S3Constants.DELIMITER), Collections
|
assertEquals(options.buildQueryParameters().get(S3Constants.DELIMITER), Collections
|
||||||
.singletonList("test"));
|
.singletonList("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testDelimiterNPE() throws UnsupportedEncodingException {
|
public void testDelimiterNPE() {
|
||||||
delimiter(null);
|
delimiter(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.s3.options;
|
||||||
import static org.jclouds.s3.options.PutBucketOptions.Builder.withBucketAcl;
|
import static org.jclouds.s3.options.PutBucketOptions.Builder.withBucketAcl;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
import org.jclouds.s3.domain.CannedAccessPolicy;
|
import org.jclouds.s3.domain.CannedAccessPolicy;
|
||||||
import org.jclouds.s3.reference.S3Headers;
|
import org.jclouds.s3.reference.S3Headers;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -50,7 +48,7 @@ public class PutBucketOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuildRequestHeaders() throws UnsupportedEncodingException {
|
void testBuildRequestHeaders() {
|
||||||
|
|
||||||
PutBucketOptions options = withBucketAcl(CannedAccessPolicy.AUTHENTICATED_READ);
|
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.jclouds.s3.options.PutObjectOptions.Builder.withAcl;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
import org.jclouds.s3.domain.CannedAccessPolicy;
|
import org.jclouds.s3.domain.CannedAccessPolicy;
|
||||||
import org.jclouds.s3.reference.S3Headers;
|
import org.jclouds.s3.reference.S3Headers;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -50,7 +48,7 @@ public class PutObjectOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuildRequestHeaders() throws UnsupportedEncodingException {
|
void testBuildRequestHeaders() {
|
||||||
|
|
||||||
PutObjectOptions options = withAcl(CannedAccessPolicy.AUTHENTICATED_READ);
|
PutObjectOptions options = withAcl(CannedAccessPolicy.AUTHENTICATED_READ);
|
||||||
options.setHeaderTag(S3Headers.DEFAULT_AMAZON_HEADERTAG);
|
options.setHeaderTag(S3Headers.DEFAULT_AMAZON_HEADERTAG);
|
||||||
|
|
|
@ -28,7 +28,6 @@ import static org.testng.Assert.assertNull;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -36,6 +35,7 @@ import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.aws.domain.Region;
|
import org.jclouds.aws.domain.Region;
|
||||||
|
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
||||||
import org.jclouds.s3.S3Client;
|
import org.jclouds.s3.S3Client;
|
||||||
import org.jclouds.s3.domain.AccessControlList;
|
import org.jclouds.s3.domain.AccessControlList;
|
||||||
import org.jclouds.s3.domain.AccessControlList.CanonicalUserGrantee;
|
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.Payer;
|
||||||
import org.jclouds.s3.domain.S3Object;
|
import org.jclouds.s3.domain.S3Object;
|
||||||
import org.jclouds.s3.internal.StubS3AsyncClient;
|
import org.jclouds.s3.internal.StubS3AsyncClient;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -332,8 +331,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListBucketDelimiter() throws InterruptedException, ExecutionException, TimeoutException,
|
public void testListBucketDelimiter() throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
UnsupportedEncodingException {
|
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
String prefix = "apps";
|
String prefix = "apps";
|
||||||
|
@ -350,8 +348,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListBucketPrefix() throws InterruptedException, ExecutionException, TimeoutException,
|
public void testListBucketPrefix() throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
UnsupportedEncodingException {
|
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
String prefix = "apps";
|
String prefix = "apps";
|
||||||
|
@ -368,8 +365,7 @@ public class BucketsLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListBucketMaxResults() throws InterruptedException, ExecutionException, TimeoutException,
|
public void testListBucketMaxResults() throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
UnsupportedEncodingException {
|
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
addAlphabetUnderRoot(bucketName);
|
addAlphabetUnderRoot(bucketName);
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.s3.xml;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Set;
|
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 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();
|
ListBucketResponse container = runParseListContainerResult();
|
||||||
assert !container.isTruncated();
|
assert !container.isTruncated();
|
||||||
assert container.getName().equals("adrianjbosstest");
|
assert container.getName().equals("adrianjbosstest");
|
||||||
|
@ -161,7 +160,7 @@ public class S3ParserTest extends PerformanceTest {
|
||||||
Strings2.toInputStream(successfulCopyObject200));
|
Strings2.toInputStream(successfulCopyObject200));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCanParseCopyObjectResult() throws HttpException, UnsupportedEncodingException {
|
public void testCanParseCopyObjectResult() throws HttpException {
|
||||||
ObjectMetadata metadata = runParseCopyObjectResult();
|
ObjectMetadata metadata = runParseCopyObjectResult();
|
||||||
Date expected = new SimpleDateFormatDateService().iso8601DateParse("2009-03-19T13:23:27.000Z");
|
Date expected = new SimpleDateFormatDateService().iso8601DateParse("2009-03-19T13:23:27.000Z");
|
||||||
assertEquals(metadata.getLastModified(), expected);
|
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.jclouds.openstack.swift.options.ListContainerOptions.Builder.withPrefix;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.jclouds.http.options.HttpRequestOptions;
|
import org.jclouds.http.options.HttpRequestOptions;
|
||||||
|
@ -47,7 +46,7 @@ public class ListContainerOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrefix() throws UnsupportedEncodingException {
|
public void testPrefix() {
|
||||||
ListContainerOptions options = new ListContainerOptions();
|
ListContainerOptions options = new ListContainerOptions();
|
||||||
options.withPrefix("test");
|
options.withPrefix("test");
|
||||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.PREFIX), Collections.singletonList("test"));
|
assertEquals(options.buildQueryParameters().get(SwiftConstants.PREFIX), Collections.singletonList("test"));
|
||||||
|
@ -60,7 +59,7 @@ public class ListContainerOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneOptionQueryString() throws UnsupportedEncodingException {
|
public void testOneOptionQueryString() {
|
||||||
ListContainerOptions options = new ListContainerOptions();
|
ListContainerOptions options = new ListContainerOptions();
|
||||||
options.withPrefix("test");
|
options.withPrefix("test");
|
||||||
Multimap<String, String> map = options.buildQueryParameters();
|
Multimap<String, String> map = options.buildQueryParameters();
|
||||||
|
@ -69,7 +68,7 @@ public class ListContainerOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTwoOptionQueryString() throws UnsupportedEncodingException {
|
public void testTwoOptionQueryString() {
|
||||||
ListContainerOptions options = new ListContainerOptions();
|
ListContainerOptions options = new ListContainerOptions();
|
||||||
options.withPrefix("test").maxResults(1);
|
options.withPrefix("test").maxResults(1);
|
||||||
Multimap<String, String> map = options.buildQueryParameters();
|
Multimap<String, String> map = options.buildQueryParameters();
|
||||||
|
@ -79,7 +78,7 @@ public class ListContainerOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrefixAndPathUrlEncodingQueryString() throws UnsupportedEncodingException {
|
public void testPrefixAndPathUrlEncodingQueryString() {
|
||||||
ListContainerOptions options = new ListContainerOptions();
|
ListContainerOptions options = new ListContainerOptions();
|
||||||
options.withPrefix("/cloudfiles/test").underPath("/");
|
options.withPrefix("/cloudfiles/test").underPath("/");
|
||||||
Multimap<String, String> map = options.buildQueryParameters();
|
Multimap<String, String> map = options.buildQueryParameters();
|
||||||
|
@ -96,18 +95,18 @@ public class ListContainerOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrefixStatic() throws UnsupportedEncodingException {
|
public void testPrefixStatic() {
|
||||||
ListContainerOptions options = withPrefix("test");
|
ListContainerOptions options = withPrefix("test");
|
||||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.PREFIX), Collections.singletonList("test"));
|
assertEquals(options.buildQueryParameters().get(SwiftConstants.PREFIX), Collections.singletonList("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testPrefixNPE() throws UnsupportedEncodingException {
|
public void testPrefixNPE() {
|
||||||
withPrefix(null);
|
withPrefix(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarker() throws UnsupportedEncodingException {
|
public void testMarker() {
|
||||||
ListContainerOptions options = new ListContainerOptions();
|
ListContainerOptions options = new ListContainerOptions();
|
||||||
options.afterMarker("test");
|
options.afterMarker("test");
|
||||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.MARKER), Collections.singletonList("test"));
|
assertEquals(options.buildQueryParameters().get(SwiftConstants.MARKER), Collections.singletonList("test"));
|
||||||
|
@ -120,13 +119,13 @@ public class ListContainerOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarkerStatic() throws UnsupportedEncodingException {
|
public void testMarkerStatic() {
|
||||||
ListContainerOptions options = afterMarker("test");
|
ListContainerOptions options = afterMarker("test");
|
||||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.MARKER), Collections.singletonList("test"));
|
assertEquals(options.buildQueryParameters().get(SwiftConstants.MARKER), Collections.singletonList("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testMarkerNPE() throws UnsupportedEncodingException {
|
public void testMarkerNPE() {
|
||||||
afterMarker(null);
|
afterMarker(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +154,7 @@ public class ListContainerOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPath() throws UnsupportedEncodingException {
|
public void testPath() {
|
||||||
ListContainerOptions options = new ListContainerOptions();
|
ListContainerOptions options = new ListContainerOptions();
|
||||||
options.underPath("test");
|
options.underPath("test");
|
||||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.PATH), Collections.singletonList("test"));
|
assertEquals(options.buildQueryParameters().get(SwiftConstants.PATH), Collections.singletonList("test"));
|
||||||
|
@ -168,13 +167,13 @@ public class ListContainerOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPathStatic() throws UnsupportedEncodingException {
|
public void testPathStatic() {
|
||||||
ListContainerOptions options = underPath("test");
|
ListContainerOptions options = underPath("test");
|
||||||
assertEquals(options.buildQueryParameters().get(SwiftConstants.PATH), Collections.singletonList("test"));
|
assertEquals(options.buildQueryParameters().get(SwiftConstants.PATH), Collections.singletonList("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testPathNPE() throws UnsupportedEncodingException {
|
public void testPathNPE() {
|
||||||
underPath(null);
|
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.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -221,7 +220,7 @@ public class GetOptions {
|
||||||
/**
|
/**
|
||||||
* @see GetOptions#ifETagMatches(String)
|
* @see GetOptions#ifETagMatches(String)
|
||||||
*/
|
*/
|
||||||
public static GetOptions ifETagMatches(String eTag) throws UnsupportedEncodingException {
|
public static GetOptions ifETagMatches(String eTag) {
|
||||||
GetOptions options = new GetOptions();
|
GetOptions options = new GetOptions();
|
||||||
return options.ifETagMatches(eTag);
|
return options.ifETagMatches(eTag);
|
||||||
}
|
}
|
||||||
|
@ -229,7 +228,7 @@ public class GetOptions {
|
||||||
/**
|
/**
|
||||||
* @see GetOptions#ifETagDoesntMatch(String)
|
* @see GetOptions#ifETagDoesntMatch(String)
|
||||||
*/
|
*/
|
||||||
public static GetOptions ifETagDoesntMatch(String eTag) throws UnsupportedEncodingException {
|
public static GetOptions ifETagDoesntMatch(String eTag) {
|
||||||
GetOptions options = new GetOptions();
|
GetOptions options = new GetOptions();
|
||||||
return options.ifETagDoesntMatch(eTag);
|
return options.ifETagDoesntMatch(eTag);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,6 @@ import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -51,11 +50,11 @@ import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder.PayloadBlobBuilder;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
import org.jclouds.blobstore.domain.StorageType;
|
||||||
import org.jclouds.blobstore.domain.BlobBuilder.PayloadBlobBuilder;
|
|
||||||
import org.jclouds.concurrent.Futures;
|
import org.jclouds.concurrent.Futures;
|
||||||
import org.jclouds.crypto.Crypto;
|
import org.jclouds.crypto.Crypto;
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
import org.jclouds.crypto.CryptoStreams;
|
||||||
|
@ -268,7 +267,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testGetIfMatch() throws InterruptedException, UnsupportedEncodingException {
|
public void testGetIfMatch() throws InterruptedException {
|
||||||
String container = getContainerName();
|
String container = getContainerName();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -291,7 +290,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testGetIfNoneMatch() throws InterruptedException, UnsupportedEncodingException {
|
public void testGetIfNoneMatch() throws InterruptedException {
|
||||||
String container = getContainerName();
|
String container = getContainerName();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -304,7 +303,6 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context.getBlobStore().getBlob(container, name, ifETagDoesntMatch(goodETag));
|
context.getBlobStore().getBlob(container, name, ifETagDoesntMatch(goodETag));
|
||||||
validateContent(container, name);
|
|
||||||
} catch (HttpResponseException ex) {
|
} catch (HttpResponseException ex) {
|
||||||
assertEquals(ex.getResponse().getStatusCode(), 304);
|
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 static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
@ -114,7 +113,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testListContainerMarker() throws InterruptedException, UnsupportedEncodingException {
|
public void testListContainerMarker() throws InterruptedException {
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
addAlphabetUnderRoot(containerName);
|
addAlphabetUnderRoot(containerName);
|
||||||
|
@ -137,7 +136,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testListRootUsesDelimiter() throws InterruptedException, UnsupportedEncodingException {
|
public void testListRootUsesDelimiter() throws InterruptedException {
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
String prefix = "rootdelimeter";
|
String prefix = "rootdelimeter";
|
||||||
|
@ -153,7 +152,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testDirectory() throws InterruptedException, UnsupportedEncodingException {
|
public void testDirectory() throws InterruptedException {
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
String directory = "directory";
|
String directory = "directory";
|
||||||
|
@ -230,7 +229,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testListContainerPrefix() throws InterruptedException, UnsupportedEncodingException {
|
public void testListContainerPrefix() throws InterruptedException {
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
String prefix = "containerprefix";
|
String prefix = "containerprefix";
|
||||||
|
@ -247,7 +246,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testListContainerMaxResults() throws InterruptedException, UnsupportedEncodingException {
|
public void testListContainerMaxResults() throws InterruptedException {
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
addAlphabetUnderRoot(containerName);
|
addAlphabetUnderRoot(containerName);
|
||||||
|
@ -295,8 +294,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testListContainer() throws InterruptedException, ExecutionException, TimeoutException,
|
public void testListContainer() throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
UnsupportedEncodingException {
|
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
add15UnderRoot(containerName);
|
add15UnderRoot(containerName);
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -150,7 +149,7 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testDirectory() throws InterruptedException, UnsupportedEncodingException {
|
public void testDirectory() throws InterruptedException {
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
String directory = "apps";
|
String directory = "apps";
|
||||||
Map<String, V> rootMap = createMap(context, containerName);
|
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.assertEquals;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
|
@ -179,7 +178,7 @@ public class GetOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagMatches() throws UnsupportedEncodingException {
|
public void testIfETagMatches() {
|
||||||
GetOptions options = new GetOptions();
|
GetOptions options = new GetOptions();
|
||||||
options.ifETagMatches(etag);
|
options.ifETagMatches(etag);
|
||||||
assertEquals(etag, options.getIfMatch());
|
assertEquals(etag, options.getIfMatch());
|
||||||
|
@ -192,18 +191,18 @@ public class GetOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagMatchesStatic() throws UnsupportedEncodingException {
|
public void testIfETagMatchesStatic() {
|
||||||
GetOptions options = ifETagMatches(etag);
|
GetOptions options = ifETagMatches(etag);
|
||||||
assertEquals(etag, options.getIfMatch());
|
assertEquals(etag, options.getIfMatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testIfETagMatchesNPE() throws UnsupportedEncodingException {
|
public void testIfETagMatchesNPE() {
|
||||||
ifETagMatches(null);
|
ifETagMatches(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testIfETagDoesntMatch() {
|
||||||
GetOptions options = new GetOptions();
|
GetOptions options = new GetOptions();
|
||||||
options.ifETagDoesntMatch(etag);
|
options.ifETagDoesntMatch(etag);
|
||||||
assertEquals(etag, options.getIfNoneMatch());
|
assertEquals(etag, options.getIfNoneMatch());
|
||||||
|
@ -216,13 +215,13 @@ public class GetOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagDoesntMatchStatic() throws UnsupportedEncodingException {
|
public void testIfETagDoesntMatchStatic() {
|
||||||
GetOptions options = ifETagDoesntMatch(etag);
|
GetOptions options = ifETagDoesntMatch(etag);
|
||||||
assertEquals(etag, options.getIfNoneMatch());
|
assertEquals(etag, options.getIfNoneMatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testIfETagDoesntMatchNPE() throws UnsupportedEncodingException {
|
public void testIfETagDoesntMatchNPE() {
|
||||||
ifETagDoesntMatch(null);
|
ifETagDoesntMatch(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,13 +231,13 @@ public class GetOptionsTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIfUnmodifiedAfterETagMatches() throws UnsupportedEncodingException {
|
public void testIfUnmodifiedAfterETagMatches() {
|
||||||
ifETagMatches(etag).ifUnmodifiedSince(now);
|
ifETagMatches(etag).ifUnmodifiedSince(now);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testIfUnmodifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testIfUnmodifiedAfterETagDoesntMatch() {
|
||||||
ifETagDoesntMatch(etag).ifUnmodifiedSince(now);
|
ifETagDoesntMatch(etag).ifUnmodifiedSince(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,44 +248,44 @@ public class GetOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testIfModifiedAfterETagMatches() throws UnsupportedEncodingException {
|
public void testIfModifiedAfterETagMatches() {
|
||||||
ifETagMatches(etag).ifModifiedSince(now);
|
ifETagMatches(etag).ifModifiedSince(now);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIfModifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testIfModifiedAfterETagDoesntMatch() {
|
||||||
ifETagDoesntMatch(etag).ifModifiedSince(now);
|
ifETagDoesntMatch(etag).ifModifiedSince(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testETagMatchesAfterIfModified() throws UnsupportedEncodingException {
|
public void testETagMatchesAfterIfModified() {
|
||||||
ifModifiedSince(now).ifETagMatches(etag);
|
ifModifiedSince(now).ifETagMatches(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testETagMatchesAfterIfUnmodified() throws UnsupportedEncodingException {
|
public void testETagMatchesAfterIfUnmodified() {
|
||||||
ifUnmodifiedSince(now).ifETagMatches(etag);
|
ifUnmodifiedSince(now).ifETagMatches(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testETagMatchesAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testETagMatchesAfterETagDoesntMatch() {
|
||||||
ifETagDoesntMatch(etag).ifETagMatches(etag);
|
ifETagDoesntMatch(etag).ifETagMatches(etag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testETagDoesntMatchAfterIfModified() throws UnsupportedEncodingException {
|
public void testETagDoesntMatchAfterIfModified() {
|
||||||
ifModifiedSince(now).ifETagDoesntMatch(etag);
|
ifModifiedSince(now).ifETagDoesntMatch(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testETagDoesntMatchAfterIfUnmodified() throws UnsupportedEncodingException {
|
public void testETagDoesntMatchAfterIfUnmodified() {
|
||||||
ifUnmodifiedSince(now).ifETagDoesntMatch(etag);
|
ifUnmodifiedSince(now).ifETagDoesntMatch(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testETagDoesntMatchAfterETagMatches() throws UnsupportedEncodingException {
|
public void testETagDoesntMatchAfterETagMatches() {
|
||||||
ifETagMatches(etag).ifETagDoesntMatch(etag);
|
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.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -161,8 +160,6 @@ public class GetOptions extends BaseHttpRequestOptions {
|
||||||
*
|
*
|
||||||
* @param eTag
|
* @param eTag
|
||||||
* hash representing the payload
|
* hash representing the payload
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
* if there was a problem converting this into an S3 eTag string
|
|
||||||
*/
|
*/
|
||||||
public GetOptions ifETagMatches(String eTag) {
|
public GetOptions ifETagMatches(String eTag) {
|
||||||
checkArgument(getIfNoneMatch() == null, "ifETagDoesntMatch() is not compatible with ifETagMatches()");
|
checkArgument(getIfNoneMatch() == null, "ifETagDoesntMatch() is not compatible with ifETagMatches()");
|
||||||
|
@ -190,8 +187,6 @@ public class GetOptions extends BaseHttpRequestOptions {
|
||||||
*
|
*
|
||||||
* @param eTag
|
* @param eTag
|
||||||
* hash representing the payload
|
* hash representing the payload
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
* if there was a problem converting this into an S3 eTag string
|
|
||||||
*/
|
*/
|
||||||
public GetOptions ifETagDoesntMatch(String eTag) {
|
public GetOptions ifETagDoesntMatch(String eTag) {
|
||||||
checkArgument(getIfMatch() == null, "ifETagMatches() is not compatible with ifETagDoesntMatch()");
|
checkArgument(getIfMatch() == null, "ifETagMatches() is not compatible with ifETagDoesntMatch()");
|
||||||
|
|
|
@ -101,6 +101,21 @@ public class ModifyRequest {
|
||||||
builder.replaceQuery(makeQueryLine(map, null, skips));
|
builder.replaceQuery(makeQueryLine(map, null, skips));
|
||||||
return (R) request.toBuilder().endpoint(builder.build()).build();
|
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) {
|
public static <R extends HttpRequest> R replaceMatrixParam(R request, String name, Object value, UriBuilder builder) {
|
||||||
return replaceMatrixParam(request, name, new Object[] { value }, 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.ParseJson;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
||||||
|
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.http.functions.ReturnInputStream;
|
import org.jclouds.http.functions.ReturnInputStream;
|
||||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
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.ExceptionParser;
|
||||||
import org.jclouds.rest.annotations.FormParams;
|
import org.jclouds.rest.annotations.FormParams;
|
||||||
import org.jclouds.rest.annotations.Headers;
|
import org.jclouds.rest.annotations.Headers;
|
||||||
|
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||||
import org.jclouds.rest.annotations.MapBinder;
|
import org.jclouds.rest.annotations.MapBinder;
|
||||||
import org.jclouds.rest.annotations.MatrixParams;
|
import org.jclouds.rest.annotations.MatrixParams;
|
||||||
import org.jclouds.rest.annotations.OnlyElement;
|
import org.jclouds.rest.annotations.OnlyElement;
|
||||||
|
@ -789,6 +791,9 @@ public class RestAnnotationProcessor<T> {
|
||||||
return Key.get((Class) IdentityFunction.class);
|
return Key.get((Class) IdentityFunction.class);
|
||||||
} else if (getAcceptHeadersOrNull(method).contains(MediaType.APPLICATION_JSON)) {
|
} else if (getAcceptHeadersOrNull(method).contains(MediaType.APPLICATION_JSON)) {
|
||||||
return getJsonParserKeyForMethod(method);
|
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)
|
} else if (method.getReturnType().equals(String.class)
|
||||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureStringLiteral)) {
|
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureStringLiteral)) {
|
||||||
return Key.get(ReturnStringIf2xx.class);
|
return Key.get(ReturnStringIf2xx.class);
|
||||||
|
@ -806,6 +811,13 @@ public class RestAnnotationProcessor<T> {
|
||||||
Type returnVal = getReturnTypeForMethod(method);
|
Type returnVal = getReturnTypeForMethod(method);
|
||||||
return getJsonParserKeyForMethodAnType(method, returnVal);
|
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) {
|
public static Type getReturnTypeForMethod(Method method) {
|
||||||
Type returnVal;
|
Type returnVal;
|
||||||
|
|
|
@ -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.assertEquals;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
|
@ -205,7 +204,7 @@ public class GetOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagMatches() throws UnsupportedEncodingException {
|
public void testIfETagMatches() {
|
||||||
GetOptions options = new GetOptions();
|
GetOptions options = new GetOptions();
|
||||||
options.ifETagMatches(etag);
|
options.ifETagMatches(etag);
|
||||||
matchesHex(options.getIfMatch());
|
matchesHex(options.getIfMatch());
|
||||||
|
@ -218,18 +217,18 @@ public class GetOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagMatchesStatic() throws UnsupportedEncodingException {
|
public void testIfETagMatchesStatic() {
|
||||||
GetOptions options = ifETagMatches(etag);
|
GetOptions options = ifETagMatches(etag);
|
||||||
matchesHex(options.getIfMatch());
|
matchesHex(options.getIfMatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testIfETagMatchesNPE() throws UnsupportedEncodingException {
|
public void testIfETagMatchesNPE() {
|
||||||
ifETagMatches(null);
|
ifETagMatches(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testIfETagDoesntMatch() {
|
||||||
GetOptions options = new GetOptions();
|
GetOptions options = new GetOptions();
|
||||||
options.ifETagDoesntMatch(etag);
|
options.ifETagDoesntMatch(etag);
|
||||||
matchesHex(options.getIfNoneMatch());
|
matchesHex(options.getIfNoneMatch());
|
||||||
|
@ -242,17 +241,17 @@ public class GetOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfETagDoesntMatchStatic() throws UnsupportedEncodingException {
|
public void testIfETagDoesntMatchStatic() {
|
||||||
GetOptions options = ifETagDoesntMatch(etag);
|
GetOptions options = ifETagDoesntMatch(etag);
|
||||||
matchesHex(options.getIfNoneMatch());
|
matchesHex(options.getIfNoneMatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testIfETagDoesntMatchNPE() throws UnsupportedEncodingException {
|
public void testIfETagDoesntMatchNPE() {
|
||||||
ifETagDoesntMatch(null);
|
ifETagDoesntMatch(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void matchesHex(String match) throws UnsupportedEncodingException {
|
private void matchesHex(String match) {
|
||||||
String expected = "\"" + etag + "\"";
|
String expected = "\"" + etag + "\"";
|
||||||
assertEquals(match, expected);
|
assertEquals(match, expected);
|
||||||
}
|
}
|
||||||
|
@ -263,13 +262,13 @@ public class GetOptionsTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIfUnmodifiedAfterETagMatches() throws UnsupportedEncodingException {
|
public void testIfUnmodifiedAfterETagMatches() {
|
||||||
ifETagMatches(etag).ifUnmodifiedSince(now);
|
ifETagMatches(etag).ifUnmodifiedSince(now);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testIfUnmodifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testIfUnmodifiedAfterETagDoesntMatch() {
|
||||||
ifETagDoesntMatch(etag).ifUnmodifiedSince(now);
|
ifETagDoesntMatch(etag).ifUnmodifiedSince(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,44 +279,44 @@ public class GetOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testIfModifiedAfterETagMatches() throws UnsupportedEncodingException {
|
public void testIfModifiedAfterETagMatches() {
|
||||||
ifETagMatches(etag).ifModifiedSince(now);
|
ifETagMatches(etag).ifModifiedSince(now);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIfModifiedAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testIfModifiedAfterETagDoesntMatch() {
|
||||||
ifETagDoesntMatch(etag).ifModifiedSince(now);
|
ifETagDoesntMatch(etag).ifModifiedSince(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testETagMatchesAfterIfModified() throws UnsupportedEncodingException {
|
public void testETagMatchesAfterIfModified() {
|
||||||
ifModifiedSince(now).ifETagMatches(etag);
|
ifModifiedSince(now).ifETagMatches(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testETagMatchesAfterIfUnmodified() throws UnsupportedEncodingException {
|
public void testETagMatchesAfterIfUnmodified() {
|
||||||
ifUnmodifiedSince(now).ifETagMatches(etag);
|
ifUnmodifiedSince(now).ifETagMatches(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testETagMatchesAfterETagDoesntMatch() throws UnsupportedEncodingException {
|
public void testETagMatchesAfterETagDoesntMatch() {
|
||||||
ifETagDoesntMatch(etag).ifETagMatches(etag);
|
ifETagDoesntMatch(etag).ifETagMatches(etag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testETagDoesntMatchAfterIfModified() throws UnsupportedEncodingException {
|
public void testETagDoesntMatchAfterIfModified() {
|
||||||
ifModifiedSince(now).ifETagDoesntMatch(etag);
|
ifModifiedSince(now).ifETagDoesntMatch(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testETagDoesntMatchAfterIfUnmodified() throws UnsupportedEncodingException {
|
public void testETagDoesntMatchAfterIfUnmodified() {
|
||||||
ifUnmodifiedSince(now).ifETagDoesntMatch(etag);
|
ifUnmodifiedSince(now).ifETagDoesntMatch(etag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testETagDoesntMatchAfterETagMatches() throws UnsupportedEncodingException {
|
public void testETagDoesntMatchAfterETagMatches() {
|
||||||
ifETagMatches(etag).ifETagDoesntMatch(etag);
|
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());
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -20,8 +20,6 @@ package org.jclouds.util;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -43,7 +41,7 @@ public class Strings2Test {
|
||||||
assertEquals(Strings2.urlEncode("/read-tests/ tep", '/'), "/read-tests/%20tep");
|
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");
|
assertEquals(Strings2.replaceTokens("hello {where}", ImmutableMap.of("where", "world")), "hello world");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
extraction of appengine-java-sdk
|
extraction of appengine-java-sdk
|
||||||
-->
|
-->
|
||||||
<appengine.applicationid>jclouds-tweetstore-spring</appengine.applicationid>
|
<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.address>localhost</devappserver.address>
|
||||||
<devappserver.port>8088</devappserver.port>
|
<devappserver.port>8088</devappserver.port>
|
||||||
<jclouds.tweetstore.container>jclouds-tweetstore-spring</jclouds.tweetstore.container>
|
<jclouds.tweetstore.container>jclouds-tweetstore-spring</jclouds.tweetstore.container>
|
||||||
|
@ -196,7 +196,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>net.kindleit</groupId>
|
<groupId>net.kindleit</groupId>
|
||||||
<artifactId>maven-gae-plugin</artifactId>
|
<artifactId>maven-gae-plugin</artifactId>
|
||||||
<version>0.8.4</version>
|
<version>0.9.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<serverId>google-appengine</serverId>
|
<serverId>google-appengine</serverId>
|
||||||
<sdkDir>${appengine.sdk.root}</sdkDir>
|
<sdkDir>${appengine.sdk.root}</sdkDir>
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
extraction of appengine-java-sdk
|
extraction of appengine-java-sdk
|
||||||
-->
|
-->
|
||||||
<appengine.applicationid>jclouds-tweetstore</appengine.applicationid>
|
<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.address>localhost</devappserver.address>
|
||||||
<devappserver.port>8088</devappserver.port>
|
<devappserver.port>8088</devappserver.port>
|
||||||
<jclouds.tweetstore.container>jclouds-tweetstore</jclouds.tweetstore.container>
|
<jclouds.tweetstore.container>jclouds-tweetstore</jclouds.tweetstore.container>
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
package org.jclouds.azureblob.blobstore.integration;
|
package org.jclouds.azureblob.blobstore.integration;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
@ -34,7 +33,7 @@ import org.testng.annotations.Test;
|
||||||
public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
|
public class AzureBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void testGetIfMatch() throws InterruptedException, UnsupportedEncodingException {
|
public void testGetIfMatch() throws InterruptedException {
|
||||||
// this currently fails
|
// this currently fails
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,7 @@
|
||||||
<goal>test</goal>
|
<goal>test</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<threadCount>1</threadCount>
|
||||||
<systemProperties>
|
<systemProperties>
|
||||||
<property>
|
<property>
|
||||||
<name>test.virtualbox.endpoint</name>
|
<name>test.virtualbox.endpoint</name>
|
||||||
|
|
|
@ -30,11 +30,11 @@ import com.google.inject.Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates compute service context for VirtualBox
|
* Creates compute service context for VirtualBox
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @author Mattias Holmqvist, Andrea Turli
|
||||||
*/
|
*/
|
||||||
public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBuilder<VirtualBoxManager> {
|
public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBuilder<VirtualBoxManager> {
|
||||||
|
|
||||||
public VirtualBoxContextBuilder(Properties properties) {
|
public VirtualBoxContextBuilder(Properties properties) {
|
||||||
super(VirtualBoxManager.class, properties);
|
super(VirtualBoxManager.class, properties);
|
||||||
}
|
}
|
||||||
|
@ -43,5 +43,5 @@ public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBui
|
||||||
protected void addContextModule(List<Module> modules) {
|
protected void addContextModule(List<Module> modules) {
|
||||||
modules.add(new VirtualBoxComputeServiceContextModule());
|
modules.add(new VirtualBoxComputeServiceContextModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,17 +19,19 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox;
|
package org.jclouds.virtualbox;
|
||||||
|
|
||||||
import org.jclouds.PropertiesBuilder;
|
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||||
|
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.jclouds.Constants.*;
|
import org.jclouds.PropertiesBuilder;
|
||||||
|
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds properties for VirtualBox integration.
|
* Builds properties for VirtualBox integration.
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
|
public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
|
||||||
|
@ -51,24 +53,24 @@ public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
|
||||||
properties.put(VirtualBoxConstants.VIRTUALBOX_PRESEED_URL, "http://dl.dropbox.com/u/693111/preseed.cfg");
|
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_SNAPSHOT_DESCRIPTION, "jclouds-virtualbox-snaphot");
|
||||||
properties.put(VirtualBoxConstants.VIRTUALBOX_HOSTNAME, "jclouds-virtualbox-kickstart-admin");
|
properties.put(VirtualBoxConstants.VIRTUALBOX_HOSTNAME, "jclouds-virtualbox-kickstart-admin");
|
||||||
properties.put(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, "<Esc><Esc><Enter> "
|
properties
|
||||||
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
|
.put(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE,
|
||||||
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
"<Esc><Esc><Enter> "
|
||||||
+ "hostname="
|
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
|
||||||
+ properties.get(VirtualBoxConstants.VIRTUALBOX_HOSTNAME)
|
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
||||||
+ " "
|
+ "hostname="
|
||||||
+ "fb=false debconf/frontend=noninteractive "
|
+ properties.get(VirtualBoxConstants.VIRTUALBOX_HOSTNAME)
|
||||||
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
+ " "
|
||||||
+ "initrd=/install/initrd.gz -- <Enter>");
|
+ "fb=false debconf/frontend=noninteractive "
|
||||||
|
+ "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.
|
// 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");
|
properties.put(VirtualBoxConstants.VIRTUALBOX_DISTRO_ISO_NAME, "ubuntu-11.04-server-i386.iso");
|
||||||
|
|
||||||
properties.put(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
properties.put(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
|
|
|
@ -19,23 +19,28 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.compute;
|
package org.jclouds.virtualbox.compute;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_CREDENTIAL;
|
||||||
import com.google.common.cache.CacheLoader;
|
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.byon.Node;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.virtualbox_4_1.IGuestOSType;
|
import org.virtualbox_4_1.IGuestOSType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import com.google.common.base.Function;
|
||||||
import java.net.URI;
|
import com.google.common.cache.CacheLoader;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a node from a VirtualBox IMachine
|
* Loads a node from a VirtualBox IMachine
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
|
public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
|
||||||
|
@ -53,16 +58,10 @@ public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
|
||||||
public Node load(final String id) throws Exception {
|
public Node load(final String id) throws Exception {
|
||||||
|
|
||||||
if (id.equals("host")) {
|
if (id.equals("host")) {
|
||||||
final Node hostNode = Node.builder().id("host")
|
final Node hostNode = Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
|
||||||
.name("host installing virtualbox")
|
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
|
||||||
.hostname("localhost")
|
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
|
||||||
.osFamily(OsFamily.LINUX.toString())
|
.credentialUrl(privateKeyFile()).build();
|
||||||
.osDescription(System.getProperty("os.name"))
|
|
||||||
.osVersion(System.getProperty("os.version"))
|
|
||||||
.group("ssh")
|
|
||||||
.username(System.getProperty("user.name"))
|
|
||||||
.credentialUrl(privateKeyFile())
|
|
||||||
.build();
|
|
||||||
return hostNode;
|
return hostNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,23 +70,14 @@ public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
|
||||||
final String osTypeId = machine.getOSTypeId();
|
final String osTypeId = machine.getOSTypeId();
|
||||||
final IGuestOSType guestOSType = manager.getVBox().getGuestOSType(osTypeId);
|
final IGuestOSType guestOSType = manager.getVBox().getGuestOSType(osTypeId);
|
||||||
|
|
||||||
final Node node = Node.builder()
|
final Node node = Node.builder().id(machine.getId()).name(machine.getName())
|
||||||
.id(machine.getId())
|
.description(machine.getDescription()).loginPort(22).group(System.getProperty(VIRTUALBOX_MACHINE_GROUP))
|
||||||
.name(machine.getName())
|
.username(System.getProperty(VIRTUALBOX_MACHINE_USERNAME))
|
||||||
.description(machine.getDescription())
|
.credential(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
|
||||||
.loginPort(22)
|
.sudoPassword(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
|
||||||
.group(System.getProperty(VIRTUALBOX_MACHINE_GROUP))
|
.locationId(System.getProperty(VIRTUALBOX_MACHINE_LOCATION)).os64Bit(guestOSType.getIs64Bit())
|
||||||
.username(System.getProperty(VIRTUALBOX_MACHINE_USERNAME))
|
.osArch(guestOSType.getDescription()).osFamily(guestOSType.getFamilyDescription())
|
||||||
.credential(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
|
.osVersion(guestOSType.getId()).osDescription(guestOSType.getDescription()).hostname(ipAddress).build();
|
||||||
.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();
|
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,16 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.compute;
|
package org.jclouds.virtualbox.compute;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import com.google.common.base.Predicate;
|
import static com.google.common.collect.Iterables.filter;
|
||||||
import com.google.common.base.Throwables;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import com.google.inject.Singleton;
|
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.ComputeServiceAdapter;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
|
@ -30,15 +36,17 @@ import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.location.suppliers.JustProvider;
|
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 com.google.common.base.Function;
|
||||||
import java.util.*;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import com.google.inject.Singleton;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the connection between the
|
* Defines the connection between the
|
||||||
|
@ -55,7 +63,8 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
private Function<IMachine, Image> iMachineToImage;
|
private Function<IMachine, Image> iMachineToImage;
|
||||||
|
|
||||||
@Inject
|
@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.iMachineToImage = iMachineToImage;
|
||||||
this.manager = checkNotNull(manager, "manager");
|
this.manager = checkNotNull(manager, "manager");
|
||||||
this.justProvider = checkNotNull(justProvider, "justProvider");
|
this.justProvider = checkNotNull(justProvider, "justProvider");
|
||||||
|
@ -77,8 +86,8 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
return manager.getVBox().getMachines();
|
return manager.getVBox().getMachines();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Image> listImages() {
|
public Iterable<Image> listImages() {
|
||||||
final Predicate<? super IMachine> imagePredicate = new Predicate<IMachine>() {
|
final Predicate<? super IMachine> imagePredicate = new Predicate<IMachine>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable IMachine iMachine) {
|
public boolean apply(@Nullable IMachine iMachine) {
|
||||||
|
@ -87,7 +96,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
};
|
};
|
||||||
final Iterable<IMachine> imageMachines = filter(manager.getVBox().getMachines(), imagePredicate);
|
final Iterable<IMachine> imageMachines = filter(manager.getVBox().getMachines(), imagePredicate);
|
||||||
return transform(imageMachines, iMachineToImage);
|
return transform(imageMachines, iMachineToImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -57,20 +57,21 @@ import com.google.inject.TypeLiteral;
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @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() {
|
public VirtualBoxComputeServiceContextModule() {
|
||||||
super(VirtualBoxManager.class, VirtualBoxManager.class);
|
super(VirtualBoxManager.class, VirtualBoxManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected VirtualBoxManager createInstance(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity,
|
protected VirtualBoxManager createInstance(@Provider URI endpoint,
|
||||||
@Named(Constants.PROPERTY_CREDENTIAL) String credential) {
|
@Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential) {
|
||||||
|
|
||||||
VirtualBoxManager manager = VirtualBoxManager.createInstance("");
|
VirtualBoxManager manager = VirtualBoxManager.createInstance("");
|
||||||
manager.connect(endpoint.toASCIIString(), identity, credential);
|
manager.connect(endpoint.toASCIIString(), identity, credential);
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
|
@ -100,31 +101,24 @@ public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapter
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final Map<MachineState, NodeState> machineToNodeState = ImmutableMap
|
public static final Map<MachineState, NodeState> machineToNodeState = ImmutableMap
|
||||||
.<MachineState, NodeState>builder()
|
.<MachineState, NodeState> builder().put(MachineState.Running, NodeState.RUNNING)
|
||||||
.put(MachineState.Running, NodeState.RUNNING)
|
.put(MachineState.PoweredOff, NodeState.SUSPENDED).put(MachineState.DeletingSnapshot, NodeState.PENDING)
|
||||||
.put(MachineState.PoweredOff, NodeState.SUSPENDED)
|
.put(MachineState.DeletingSnapshotOnline, NodeState.PENDING)
|
||||||
.put(MachineState.DeletingSnapshot, NodeState.PENDING)
|
.put(MachineState.DeletingSnapshotPaused, NodeState.PENDING)
|
||||||
.put(MachineState.DeletingSnapshotOnline, NodeState.PENDING)
|
.put(MachineState.FaultTolerantSyncing, NodeState.PENDING)
|
||||||
.put(MachineState.DeletingSnapshotPaused, NodeState.PENDING)
|
.put(MachineState.LiveSnapshotting, NodeState.PENDING)
|
||||||
.put(MachineState.FaultTolerantSyncing, NodeState.PENDING)
|
.put(MachineState.SettingUp, NodeState.PENDING)
|
||||||
.put(MachineState.LiveSnapshotting, NodeState.PENDING)
|
.put(MachineState.Starting, NodeState.PENDING)
|
||||||
.put(MachineState.SettingUp, NodeState.PENDING)
|
.put(MachineState.Stopping, NodeState.PENDING)
|
||||||
.put(MachineState.Starting, NodeState.PENDING)
|
.put(MachineState.Restoring, NodeState.PENDING)
|
||||||
.put(MachineState.Stopping, NodeState.PENDING)
|
// TODO What to map these states to?
|
||||||
.put(MachineState.Restoring, NodeState.PENDING)
|
.put(MachineState.FirstOnline, NodeState.PENDING).put(MachineState.FirstTransient, NodeState.PENDING)
|
||||||
// TODO What to map these states to?
|
.put(MachineState.LastOnline, NodeState.PENDING).put(MachineState.LastTransient, NodeState.PENDING)
|
||||||
.put(MachineState.FirstOnline, NodeState.PENDING)
|
.put(MachineState.Teleported, NodeState.PENDING).put(MachineState.TeleportingIn, NodeState.PENDING)
|
||||||
.put(MachineState.FirstTransient, NodeState.PENDING)
|
.put(MachineState.TeleportingPausedVM, 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.Null, NodeState.UNRECOGNIZED).build();
|
||||||
.put(MachineState.Stuck, NodeState.ERROR)
|
|
||||||
|
|
||||||
.put(MachineState.Null, NodeState.UNRECOGNIZED).build();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.jclouds.virtualbox.config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration properties used for interacting with VirtualBox instances.
|
* Configuration properties used for interacting with VirtualBox instances.
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @author Mattias Holmqvist, Andrea Turli
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -34,11 +34,11 @@ public interface VirtualBoxConstants {
|
||||||
public static final String VIRTUALBOX_SNAPSHOT_DESCRIPTION = "jclouds.virtualbox.snapshotDescription";
|
public static final String VIRTUALBOX_SNAPSHOT_DESCRIPTION = "jclouds.virtualbox.snapshotDescription";
|
||||||
|
|
||||||
public static final String VIRTUALBOX_INSTALLATION_KEY_SEQUENCE = "jclouds.virtualbox.installationkeysequence";
|
public static final String VIRTUALBOX_INSTALLATION_KEY_SEQUENCE = "jclouds.virtualbox.installationkeysequence";
|
||||||
|
|
||||||
public static final String VIRTUALBOX_HOSTNAME = "jclouds.virtualbox.hostname";
|
public static final String VIRTUALBOX_HOSTNAME = "jclouds.virtualbox.hostname";
|
||||||
|
|
||||||
public static final String VIRTUALBOX_WORKINGDIR = "jclouds.virtualbox.workingdir";
|
public static final String VIRTUALBOX_WORKINGDIR = "jclouds.virtualbox.workingdir";
|
||||||
|
|
||||||
public static final String VIRTUALBOX_ISOFILE = "jclouds.virtualbox.isofile";
|
public static final String VIRTUALBOX_ISOFILE = "jclouds.virtualbox.isofile";
|
||||||
|
|
||||||
public static final String VIRTUALBOX_MACHINE_GROUP = "jclouds.virtualbox.machinegroup";
|
public static final String VIRTUALBOX_MACHINE_GROUP = "jclouds.virtualbox.machinegroup";
|
||||||
|
|
|
@ -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
|
* Serializes to the following
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
id: myTestId
|
* id: myTestId
|
||||||
name: ubuntu-11.04-server-i386
|
* name: ubuntu-11.04-server-i386
|
||||||
description: ubuntu 11.04 server (i386)
|
* description: ubuntu 11.04 server (i386)
|
||||||
os_arch: x86
|
* os_arch: x86
|
||||||
os_family: linux
|
* os_family: linux
|
||||||
os_description: ubuntu
|
* os_description: ubuntu
|
||||||
os_version: 11.04
|
* os_version: 11.04
|
||||||
iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
|
* iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
|
||||||
keystroke_sequence: |
|
* keystroke_sequence: |
|
||||||
<Esc><Esc><Enter>
|
* <Esc><Esc><Enter>
|
||||||
/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg
|
* /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
|
* debian-installer=en_US auto locale=en_US kbd-chooser/method=us
|
||||||
hostname=vmName
|
* hostname=vmName
|
||||||
fb=false debconf/frontend=noninteractive
|
* fb=false debconf/frontend=noninteractive
|
||||||
keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
|
* keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
|
||||||
initrd=/install/initrd.gz -- <Enter>
|
* initrd=/install/initrd.gz -- <Enter>
|
||||||
preseed_cfg: |
|
* preseed_cfg: |
|
||||||
## Options to set on the command line
|
* ## Options to set on the command line
|
||||||
d-i debian-installer/locale string en_US.utf8
|
* d-i debian-installer/locale string en_US.utf8
|
||||||
d-i console-setup/ask_detect boolean false
|
* d-i console-setup/ask_detect boolean false
|
||||||
d-i console-setup/layout string USA
|
* d-i console-setup/layout string USA
|
||||||
d-i netcfg/get_hostname string unassigned-hostname
|
* d-i netcfg/get_hostname string unassigned-hostname
|
||||||
d-i netcfg/get_domain string unassigned-domain
|
* d-i netcfg/get_domain string unassigned-domain
|
||||||
# Continue without a default route
|
* # Continue without a default route
|
||||||
# Not working , specify a dummy in the DHCP
|
* # Not working , specify a dummy in the DHCP
|
||||||
d-i time/zone string UTC
|
* d-i time/zone string UTC
|
||||||
d-i clock-setup/utc-auto boolean true
|
* d-i clock-setup/utc-auto boolean true
|
||||||
d-i clock-setup/utc boolean true
|
* d-i clock-setup/utc boolean true
|
||||||
d-i kbd-chooser/method select American English
|
* d-i kbd-chooser/method select American English
|
||||||
d-i netcfg/wireless_wep string
|
* d-i netcfg/wireless_wep string
|
||||||
d-i base-installer/kernel/override-image string linux-server
|
* d-i base-installer/kernel/override-image string linux-server
|
||||||
# Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
|
* # Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
|
||||||
d-i debconf debconf/frontend select Noninteractive
|
* d-i debconf debconf/frontend select Noninteractive
|
||||||
d-i pkgsel/install-language-support boolean false
|
* d-i pkgsel/install-language-support boolean false
|
||||||
tasksel tasksel/first multiselect standard, ubuntu-server
|
* tasksel tasksel/first multiselect standard, ubuntu-server
|
||||||
d-i partman-auto/method string lvm
|
* d-i partman-auto/method string lvm
|
||||||
d-i partman-lvm/confirm boolean true
|
* d-i partman-lvm/confirm boolean true
|
||||||
d-i partman-lvm/device_remove_lvm boolean true
|
* d-i partman-lvm/device_remove_lvm boolean true
|
||||||
d-i partman-auto/choose_recipe select atomic
|
* d-i partman-auto/choose_recipe select atomic
|
||||||
d-i partman/confirm_write_new_label boolean true
|
* d-i partman/confirm_write_new_label boolean true
|
||||||
d-i partman/confirm_nooverwrite boolean true
|
* d-i partman/confirm_nooverwrite boolean true
|
||||||
d-i partman/choose_partition select finish
|
* d-i partman/choose_partition select finish
|
||||||
d-i partman/confirm boolean true
|
* d-i partman/confirm boolean true
|
||||||
# Write the changes to disks and configure LVM?
|
* # Write the changes to disks and configure LVM?
|
||||||
d-i partman-lvm/confirm boolean true
|
* d-i partman-lvm/confirm boolean true
|
||||||
d-i partman-lvm/confirm_nooverwrite boolean true
|
* d-i partman-lvm/confirm_nooverwrite boolean true
|
||||||
d-i partman-auto-lvm/guided_size string max
|
* d-i partman-auto-lvm/guided_size string max
|
||||||
## Default user, we can get away with a recipe to change this
|
* ## Default user, we can get away with a recipe to change this
|
||||||
d-i passwd/user-fullname string toor
|
* d-i passwd/user-fullname string toor
|
||||||
d-i passwd/username string toor
|
* d-i passwd/username string toor
|
||||||
d-i passwd/user-password password password
|
* d-i passwd/user-password password password
|
||||||
d-i passwd/user-password-again password password
|
* d-i passwd/user-password-again password password
|
||||||
d-i user-setup/encrypt-home boolean false
|
* d-i user-setup/encrypt-home boolean false
|
||||||
d-i user-setup/allow-password-weak boolean true
|
* d-i user-setup/allow-password-weak boolean true
|
||||||
# Individual additional packages to install
|
* # Individual additional packages to install
|
||||||
d-i pkgsel/include string openssh-server ntp
|
* d-i pkgsel/include string openssh-server ntp
|
||||||
# Whether to upgrade packages after debootstrap.
|
* # Whether to upgrade packages after debootstrap.
|
||||||
# Allowed values: none, safe-upgrade, full-upgrade
|
* # Allowed values: none, safe-upgrade, full-upgrade
|
||||||
d-i pkgsel/upgrade select full-upgrade
|
* d-i pkgsel/upgrade select full-upgrade
|
||||||
d-i grub-installer/only_debian boolean true
|
* d-i grub-installer/only_debian boolean true
|
||||||
d-i grub-installer/with_other_os boolean true
|
* d-i grub-installer/with_other_os boolean true
|
||||||
d-i finish-install/reboot_in_progress note
|
* d-i finish-install/reboot_in_progress note
|
||||||
#For the update
|
* #For the update
|
||||||
d-i pkgsel/update-policy select none
|
* d-i pkgsel/update-policy select none
|
||||||
# debconf-get-selections --install
|
* # debconf-get-selections --install
|
||||||
#Use mirror
|
* #Use mirror
|
||||||
choose-mirror-bin mirror/http/proxy string
|
* choose-mirror-bin mirror/http/proxy string
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author Kelvin Kakugawa
|
* @author Kelvin Kakugawa
|
||||||
|
@ -143,14 +143,11 @@ public class YamlImage {
|
||||||
return null;
|
return null;
|
||||||
OsFamily family = parseOsFamilyOrUnrecognized(arg0.os_family);
|
OsFamily family = parseOsFamilyOrUnrecognized(arg0.os_family);
|
||||||
|
|
||||||
OperatingSystem operatingSystem = OperatingSystem.builder()
|
OperatingSystem operatingSystem = OperatingSystem.builder().description(arg0.os_description).family(family)
|
||||||
.description(arg0.os_description)
|
.version(arg0.os_version).is64Bit(arg0.os_64bit).build();
|
||||||
.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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/**
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -19,10 +19,11 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
|
|
@ -19,13 +19,14 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_1.IMedium;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_1.VBoxException;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
|
|
@ -19,12 +19,14 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import org.virtualbox_4_1.*;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
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
|
* @author Mattias Holmqvist
|
||||||
|
@ -37,7 +39,8 @@ public class AttachMediumToMachineIfNotAlreadyAttached implements Function<IMach
|
||||||
private int device;
|
private int device;
|
||||||
private DeviceType deviceType;
|
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.controllerIDE = controllerIDE;
|
||||||
this.hardDisk = hardDisk;
|
this.hardDisk = hardDisk;
|
||||||
this.controllerPort = controllerPort;
|
this.controllerPort = controllerPort;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/**
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -19,14 +19,15 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.virtualbox_4_1.NATProtocol.TCP;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static org.virtualbox_4_1.NATProtocol.TCP;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
import org.virtualbox_4_1.INetworkAdapter;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.IMachine;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_1.IVirtualBox;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_1.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
@ -40,7 +40,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
||||||
private VirtualBoxManager manager;
|
private VirtualBoxManager manager;
|
||||||
|
|
||||||
public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(String settingsFile, String osTypeId, String vmId,
|
public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(String settingsFile, String osTypeId, String vmId,
|
||||||
boolean forceOverwrite, VirtualBoxManager manager) {
|
boolean forceOverwrite, VirtualBoxManager manager) {
|
||||||
this.settingsFile = settingsFile;
|
this.settingsFile = settingsFile;
|
||||||
this.osTypeId = osTypeId;
|
this.osTypeId = osTypeId;
|
||||||
this.vmId = vmId;
|
this.vmId = vmId;
|
||||||
|
|
|
@ -19,11 +19,17 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import org.virtualbox_4_1.*;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
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
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -71,15 +77,18 @@ public class CreateMediumIfNotAlreadyExists implements Function<String, IMedium>
|
||||||
private void createBaseStorage(IMedium hardDisk) {
|
private void createBaseStorage(IMedium hardDisk) {
|
||||||
try {
|
try {
|
||||||
long size = 4L * 1024L * 1024L * 1024L - 4L;
|
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);
|
storageCreation.waitForCompletion(-1);
|
||||||
} catch (VBoxException e) {
|
} catch (VBoxException e) {
|
||||||
if (fileNotFoundException(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();
|
hardDisk.deleteStorage();
|
||||||
}
|
}
|
||||||
if (!storageAlreadyExists(e)) {
|
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;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,8 +99,8 @@ public class CreateMediumIfNotAlreadyExists implements Function<String, IMedium>
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean storageAlreadyExists(VBoxException e) {
|
private boolean storageAlreadyExists(VBoxException e) {
|
||||||
return e.getMessage().indexOf("VirtualBox error: Storage for the medium ") != -1 &&
|
return e.getMessage().indexOf("VirtualBox error: Storage for the medium ") != -1
|
||||||
e.getMessage().indexOf("is already created") != -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) {
|
public Hardware apply(@Nullable IMachine vm) {
|
||||||
String osTypeId = vm.getOSTypeId();
|
String osTypeId = vm.getOSTypeId();
|
||||||
|
|
||||||
|
|
||||||
IGuestOSType guestOSType = virtualBoxManager.getVBox().getGuestOSType(osTypeId);
|
IGuestOSType guestOSType = virtualBoxManager.getVBox().getGuestOSType(osTypeId);
|
||||||
Boolean is64Bit = guestOSType.getIs64Bit();
|
Boolean is64Bit = guestOSType.getIs64Bit();
|
||||||
HardwareBuilder hardwareBuilder = new HardwareBuilder();
|
HardwareBuilder hardwareBuilder = new HardwareBuilder();
|
||||||
|
|
|
@ -58,8 +58,7 @@ public class IMachineToImage implements Function<IMachine, Image> {
|
||||||
|
|
||||||
IGuestOSType guestOSType = virtualboxManager.getVBox().getGuestOSType(from.getOSTypeId());
|
IGuestOSType guestOSType = virtualboxManager.getVBox().getGuestOSType(from.getOSTypeId());
|
||||||
OsFamily family = parseOsFamilyOrUnrecognized(guestOSType.getDescription());
|
OsFamily family = parseOsFamilyOrUnrecognized(guestOSType.getDescription());
|
||||||
String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(),
|
String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(), osVersionMap);
|
||||||
osVersionMap);
|
|
||||||
OperatingSystem os = OperatingSystem.builder().description(guestOSType.getDescription()).family(family)
|
OperatingSystem os = OperatingSystem.builder().description(guestOSType.getDescription()).family(family)
|
||||||
.version(version).is64Bit(guestOSType.getIs64Bit()).build();
|
.version(version).is64Bit(guestOSType.getIs64Bit()).build();
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,10 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.ComputeService;
|
||||||
import org.jclouds.compute.domain.ExecResponse;
|
import org.jclouds.compute.domain.ExecResponse;
|
||||||
import org.jclouds.compute.options.RunScriptOptions;
|
import org.jclouds.compute.options.RunScriptOptions;
|
||||||
|
@ -28,13 +31,11 @@ import org.virtualbox_4_1.IGuestOSType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an IP address from an IMachine using arp of the host machine.
|
* Get an IP address from an IMachine using arp of the host machine.
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @author Mattias Holmqvist, Andrea Turli
|
||||||
*/
|
*/
|
||||||
public class IMachineToIpAddress implements Function<IMachine, String> {
|
public class IMachineToIpAddress implements Function<IMachine, String> {
|
||||||
|
@ -63,18 +64,25 @@ public class IMachineToIpAddress implements Function<IMachine, String> {
|
||||||
IMachine hostMachine = manager.getVBox().findMachine(hostId);
|
IMachine hostMachine = manager.getVBox().findMachine(hostId);
|
||||||
if (isOSX(hostMachine)) {
|
if (isOSX(hostMachine)) {
|
||||||
if (simplifiedMacAddressOfClonedVM.contains("00"))
|
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.contains("0"))
|
||||||
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':' && simplifiedMacAddressOfClonedVM.indexOf("0") - 1 != ':')
|
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':'
|
||||||
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(simplifiedMacAddressOfClonedVM.indexOf("0"), simplifiedMacAddressOfClonedVM.indexOf("0") + 1).toString();
|
&& 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.
|
// 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);
|
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(")"));
|
String ipAddress = arpLine.substring(arpLine.indexOf("(") + 1, arpLine.indexOf(")"));
|
||||||
System.out.println("IP address " + ipAddress);
|
System.out.println("IP address " + ipAddress);
|
||||||
return ipAddress;
|
return ipAddress;
|
||||||
|
|
|
@ -19,8 +19,19 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState;
|
||||||
import org.jclouds.compute.domain.*;
|
|
||||||
|
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.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.LocationBuilder;
|
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.INetworkAdapter;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_1.MachineState;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import com.google.common.base.Function;
|
||||||
import javax.inject.Named;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState;
|
|
||||||
|
|
||||||
public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata> {
|
public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata> {
|
||||||
|
|
||||||
|
@ -57,7 +63,7 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
locationBuilder.id("");
|
locationBuilder.id("");
|
||||||
locationBuilder.scope(LocationScope.HOST);
|
locationBuilder.scope(LocationScope.HOST);
|
||||||
nodeMetadataBuilder.location(locationBuilder.build());
|
nodeMetadataBuilder.location(locationBuilder.build());
|
||||||
|
|
||||||
HardwareBuilder hardwareBuilder = new HardwareBuilder();
|
HardwareBuilder hardwareBuilder = new HardwareBuilder();
|
||||||
hardwareBuilder.ram(vm.getMemorySize().intValue());
|
hardwareBuilder.ram(vm.getMemorySize().intValue());
|
||||||
|
|
||||||
|
@ -75,7 +81,6 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
nodeMetadataBuilder.hostname(vm.getName());
|
nodeMetadataBuilder.hostname(vm.getName());
|
||||||
nodeMetadataBuilder.loginPort(18083);
|
nodeMetadataBuilder.loginPort(18083);
|
||||||
|
|
||||||
|
|
||||||
MachineState vmState = vm.getState();
|
MachineState vmState = vm.getState();
|
||||||
NodeState nodeState = machineToNodeState.get(vmState);
|
NodeState nodeState = machineToNodeState.get(vmState);
|
||||||
if (nodeState == null)
|
if (nodeState == null)
|
||||||
|
@ -90,8 +95,8 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
System.out.println("Interface: " + bridgedInterface);
|
System.out.println("Interface: " + bridgedInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
// nodeMetadataBuilder.imageId("");
|
// nodeMetadataBuilder.imageId("");
|
||||||
// nodeMetadataBuilder.group("");
|
// nodeMetadataBuilder.group("");
|
||||||
|
|
||||||
String provider = "virtualbox";
|
String provider = "virtualbox";
|
||||||
String identity = System.getProperty("test." + provider + ".identity", "administrator");
|
String identity = System.getProperty("test." + provider + ".identity", "administrator");
|
||||||
|
@ -101,5 +106,5 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
nodeMetadataBuilder.id(vm.getId());
|
nodeMetadataBuilder.id(vm.getId());
|
||||||
return nodeMetadataBuilder.build();
|
return nodeMetadataBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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.runAsRoot;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
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.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.Server;
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.ExecResponse;
|
import org.jclouds.compute.domain.ExecResponse;
|
||||||
import org.jclouds.compute.options.RunScriptOptions;
|
import org.jclouds.compute.options.RunScriptOptions;
|
||||||
|
@ -45,10 +43,17 @@ import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.ssh.SshException;
|
import org.jclouds.ssh.SshException;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||||
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
|
|
||||||
import org.jclouds.virtualbox.settings.KeyboardScancodes;
|
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.common.base.Function;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
@ -75,8 +80,8 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public IsoToIMachine(VirtualBoxManager manager, String adminDisk, String diskFormat, String settingsFile,
|
public IsoToIMachine(VirtualBoxManager manager, String adminDisk, String diskFormat, String settingsFile,
|
||||||
String vmName, String osTypeId, String vmId, boolean forceOverwrite, String controllerIDE,
|
String vmName, String osTypeId, String vmId, boolean forceOverwrite, String controllerIDE,
|
||||||
ComputeServiceContext context, String hostId, String guestId, Credentials credentials) {
|
ComputeServiceContext context, String hostId, String guestId, Credentials credentials) {
|
||||||
super();
|
super();
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.adminDisk = adminDisk;
|
this.adminDisk = adminDisk;
|
||||||
|
@ -96,11 +101,15 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
@Override
|
@Override
|
||||||
public IMachine apply(@Nullable String isoName) {
|
public IMachine apply(@Nullable String isoName) {
|
||||||
|
|
||||||
String port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
// TODO: WTF :) this is a prerequisite, so check state as opposed to
|
||||||
String baseResource = ".";
|
// starting.
|
||||||
Server server = new StartJettyIfNotAlreadyRunning(port).apply(baseResource);
|
// 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 defaultWorkingDir = System.getProperty("user.home") + "/jclouds-virtualbox-test";
|
||||||
String workingDir = System.getProperty(VIRTUALBOX_WORKINGDIR, defaultWorkingDir);
|
String workingDir = System.getProperty(VIRTUALBOX_WORKINGDIR, defaultWorkingDir);
|
||||||
|
@ -131,18 +140,13 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
|
|
||||||
String guestAdditionsDvd = workingDir + "/VBoxGuestAdditions_4.1.2.iso";
|
String guestAdditionsDvd = workingDir + "/VBoxGuestAdditions_4.1.2.iso";
|
||||||
final IMedium guestAdditionsDvdMedium = manager.getVBox().openMedium(guestAdditionsDvd, DeviceType.DVD,
|
final IMedium guestAdditionsDvdMedium = manager.getVBox().openMedium(guestAdditionsDvd, DeviceType.DVD,
|
||||||
AccessMode.ReadOnly, forceOverwrite);
|
AccessMode.ReadOnly, forceOverwrite);
|
||||||
|
|
||||||
// Guest additions
|
// Guest additions
|
||||||
ensureGuestAdditionsMediumIsAttached(vmName, guestAdditionsDvdMedium);
|
ensureGuestAdditionsMediumIsAttached(vmName, guestAdditionsDvdMedium);
|
||||||
|
|
||||||
IProgress prog = vm.launchVMProcess(manager.getSessionObject(), "gui", "");
|
// Launch machine and wait for it to come online
|
||||||
prog.waitForCompletion(-1);
|
ensureMachineIsLaunched(vmName);
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
propagate(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
String installKeySequence = System.getProperty(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, defaultInstallSequence());
|
String installKeySequence = System.getProperty(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, defaultInstallSequence());
|
||||||
sendKeyboardSequence(installKeySequence);
|
sendKeyboardSequence(installKeySequence);
|
||||||
|
@ -170,24 +174,33 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
try {
|
// TODO: See above.
|
||||||
logger.debug("Stopping Jetty server...");
|
// if you want to manage jetty, do it outside this class as it
|
||||||
server.stop();
|
// has too many responsibilities otherwise. Allow this class to focus
|
||||||
logger.debug("Jetty server stopped.");
|
// solely on making an IMachine
|
||||||
} catch (Exception e) {
|
//
|
||||||
logger.error(e, "Could not stop Jetty server.");
|
// 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;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureMachineIsLaunched(String vmName) {
|
||||||
|
applyForMachine(manager, vmName, new LaunchMachineIfNotAlreadyRunning(manager, ExecutionType.GUI, ""));
|
||||||
|
}
|
||||||
|
|
||||||
private void ensureGuestAdditionsMediumIsAttached(String vmName, final IMedium guestAdditionsDvdMedium) {
|
private void ensureGuestAdditionsMediumIsAttached(String vmName, final IMedium guestAdditionsDvdMedium) {
|
||||||
lockMachineAndApply(manager, Write, vmName,
|
lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE,
|
||||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, guestAdditionsDvdMedium, 1, 1, DeviceType.DVD));
|
guestAdditionsDvdMedium, 1, 1, DeviceType.DVD));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureMachineHasHardDiskAttached(String vmName, IMedium hardDisk) {
|
private void ensureMachineHasHardDiskAttached(String vmName, IMedium hardDisk) {
|
||||||
lockMachineAndApply(manager, Write, vmName,
|
lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE,
|
||||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, 0, 1, HardDisk));
|
hardDisk, 0, 1, HardDisk));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureMachineHasMemory(String vmName, final long memorySize) {
|
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) {
|
private void ensureMachineHasAttachedDistroMedium(String isoName, String workingDir, String controllerIDE) {
|
||||||
final String pathToIsoFile = checkFileExists(workingDir + "/" + isoName);
|
final String pathToIsoFile = checkFileExists(workingDir + "/" + isoName);
|
||||||
final IMedium distroMedium = manager.getVBox().openMedium(pathToIsoFile, DVD, ReadOnly, forceOverwrite);
|
final IMedium distroMedium = manager.getVBox().openMedium(pathToIsoFile, DVD, ReadOnly, forceOverwrite);
|
||||||
lockMachineAndApply(manager, Write, vmName,
|
lockMachineAndApply(
|
||||||
new AttachDistroMediumToMachine(
|
manager,
|
||||||
checkNotNull(controllerIDE, "controllerIDE"),
|
Write,
|
||||||
checkNotNull(distroMedium, "distroMedium")));
|
vmName,
|
||||||
|
new AttachDistroMediumToMachine(checkNotNull(controllerIDE, "controllerIDE"), checkNotNull(distroMedium,
|
||||||
|
"distroMedium")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String checkFileExists(String filePath) {
|
public static String checkFileExists(String filePath) {
|
||||||
|
@ -216,11 +231,26 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
|
|
||||||
public void ensureMachineHasIDEControllerNamed(String vmName, String controllerIDE) {
|
public void ensureMachineHasIDEControllerNamed(String vmName, String controllerIDE) {
|
||||||
lockMachineAndApply(manager, Write, checkNotNull(vmName, "vmName"),
|
lockMachineAndApply(manager, Write, checkNotNull(vmName, "vmName"),
|
||||||
new AddIDEControllerIfNotExists(checkNotNull(controllerIDE, "controllerIDE")));
|
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,
|
public static <T> T lockMachineAndApply(VirtualBoxManager manager, final LockType type, final String machineId,
|
||||||
final Function<IMachine, T> function) {
|
final Function<IMachine, T> function) {
|
||||||
return lockSessionOnMachineAndApply(manager, type, machineId, new Function<ISession, T>() {
|
return lockSessionOnMachineAndApply(manager, type, machineId, new Function<ISession, T>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -238,7 +268,7 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T lockSessionOnMachineAndApply(VirtualBoxManager manager, LockType type, String machineId,
|
public static <T> T lockSessionOnMachineAndApply(VirtualBoxManager manager, LockType type, String machineId,
|
||||||
Function<ISession, T> function) {
|
Function<ISession, T> function) {
|
||||||
try {
|
try {
|
||||||
ISession session = manager.getSessionObject();
|
ISession session = manager.getSessionObject();
|
||||||
IMachine immutableMachine = manager.getVBox().findMachine(machineId);
|
IMachine immutableMachine = manager.getVBox().findMachine(machineId);
|
||||||
|
@ -250,17 +280,17 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
}
|
}
|
||||||
} catch (VBoxException e) {
|
} catch (VBoxException e) {
|
||||||
throw new RuntimeException(String.format("error applying %s to %s with %s lock: %s", function, machineId,
|
throw new RuntimeException(String.format("error applying %s to %s with %s lock: %s", function, machineId,
|
||||||
type, e.getMessage()), e);
|
type, e.getMessage()), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String defaultInstallSequence() {
|
private String defaultInstallSequence() {
|
||||||
return "<Esc><Esc><Enter> "
|
return "<Esc><Esc><Enter> "
|
||||||
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
|
+ "/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 + " "
|
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + vmName + " "
|
||||||
+ "fb=false debconf/frontend=noninteractive "
|
+ "fb=false debconf/frontend=noninteractive "
|
||||||
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
||||||
+ "initrd=/install/initrd.gz -- <Enter>";
|
+ "initrd=/install/initrd.gz -- <Enter>";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendKeyboardSequence(String keyboardSequence) {
|
private void sendKeyboardSequence(String keyboardSequence) {
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -58,8 +58,8 @@ public class FileDownloadFromURI implements Function<URI, File> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FileDownloadFromURI(final ComputeServiceContext context,
|
public FileDownloadFromURI(final ComputeServiceContext context,
|
||||||
@Named(VIRTUALBOX_WORKINGDIR) final String workingDir,
|
@Named(VIRTUALBOX_WORKINGDIR) final String workingDir,
|
||||||
@Named(VirtualBoxConstants.VIRTUALBOX_ISOFILE) final String isoFile) {
|
@Named(VirtualBoxConstants.VIRTUALBOX_ISOFILE) final String isoFile) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.workingDir = workingDir;
|
this.workingDir = workingDir;
|
||||||
this.isoFile = isoFile;
|
this.isoFile = isoFile;
|
||||||
|
|
|
@ -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
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* 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
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* 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
|
* @author Andrea Turli
|
||||||
*/
|
*/
|
||||||
|
@ -53,12 +56,12 @@ public class ImageFromYamlStream implements Function<InputStream, Cache<String,
|
||||||
public static class Config {
|
public static class Config {
|
||||||
public List<YamlImage> images;
|
public List<YamlImage> images;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object construct(String data) {
|
private Object construct(String data) {
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
return yaml.load(data);
|
return yaml.load(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cache<String, Image> apply(InputStream source) {
|
public Cache<String, Image> apply(InputStream source) {
|
||||||
|
|
||||||
|
@ -74,15 +77,15 @@ public class ImageFromYamlStream implements Function<InputStream, Cache<String,
|
||||||
checkState(config.images != null, "missing images: collection");
|
checkState(config.images != null, "missing images: collection");
|
||||||
|
|
||||||
Map<String, Image> backingMap = Maps.uniqueIndex(Iterables.transform(config.images, YamlImage.toImage),
|
Map<String, Image> backingMap = Maps.uniqueIndex(Iterables.transform(config.images, YamlImage.toImage),
|
||||||
new Function<Image, String>() {
|
new Function<Image, String>() {
|
||||||
public String apply(Image image) {
|
public String apply(Image image) {
|
||||||
return image.getId();
|
return image.getId();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Cache<String, Image> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap)));
|
Cache<String, Image> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap)));
|
||||||
for (String node : backingMap.keySet())
|
for (String node : backingMap.keySet())
|
||||||
cache.getUnchecked(node);
|
cache.getUnchecked(node);
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions.admin;
|
package org.jclouds.virtualbox.functions.admin;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
@ -43,65 +45,72 @@ import com.google.inject.Singleton;
|
||||||
*/
|
*/
|
||||||
public class StartJettyIfNotAlreadyRunning implements Function<String, Server> {
|
public class StartJettyIfNotAlreadyRunning implements Function<String, Server> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
private final int port;
|
private final Server jetty;
|
||||||
|
private final int port;
|
||||||
|
|
||||||
@Inject
|
public StartJettyIfNotAlreadyRunning(Server jetty, @Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) int port) {
|
||||||
public StartJettyIfNotAlreadyRunning(
|
this.jetty = checkNotNull(jetty, "jetty");
|
||||||
@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) final String port) {
|
this.port = port;
|
||||||
this.port = Integer.parseInt(port);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// TODO: getting an instance of the Server object should really be done in
|
||||||
public Server apply(@Nullable String baseResource) {
|
// Guice, so inside a *Module class, perhaps as a @Provides method
|
||||||
final Server server = ServerJetty.getInstance().getServer();
|
@Inject
|
||||||
|
public StartJettyIfNotAlreadyRunning(@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) int port) {
|
||||||
|
this(ServerJetty.getInstance().getServer(), port);
|
||||||
|
}
|
||||||
|
|
||||||
if (!server.getState().equals(Server.STARTED) && !new InetSocketAddressConnect().apply(new IPSocket("localhost", port))) {
|
@Override
|
||||||
ResourceHandler resource_handler = new ResourceHandler();
|
public Server apply(@Nullable String baseResource) {
|
||||||
resource_handler.setDirectoriesListed(true);
|
if (!jetty.getState().equals(Server.STARTED)
|
||||||
resource_handler.setWelcomeFiles(new String[] { "index.html" });
|
// 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" });
|
||||||
|
|
||||||
resource_handler.setResourceBase(baseResource);
|
resource_handler.setResourceBase(baseResource);
|
||||||
logger.info("serving " + resource_handler.getBaseResource());
|
logger.info("serving " + resource_handler.getBaseResource());
|
||||||
|
|
||||||
HandlerList handlers = new HandlerList();
|
HandlerList handlers = new HandlerList();
|
||||||
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
||||||
server.setHandler(handlers);
|
jetty.setHandler(handlers);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server.start();
|
jetty.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e, "Server jetty could not be started at this %s", baseResource);
|
logger.error(e, "Server jetty could not be started at this %s", baseResource);
|
||||||
}
|
}
|
||||||
return server;
|
return jetty;
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Server jetty serving %s already running. Skipping start", baseResource);
|
logger.debug("Server jetty serving %s already running. Skipping start", baseResource);
|
||||||
return server;
|
return jetty;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
|
||||||
private static class ServerJetty {
|
|
||||||
private static ServerJetty instance;
|
|
||||||
private Server server;
|
|
||||||
private String port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
|
||||||
|
|
||||||
private ServerJetty() {
|
@Singleton
|
||||||
this.server = new Server(Integer.parseInt(port));
|
private static class ServerJetty {
|
||||||
}
|
private static ServerJetty instance;
|
||||||
|
private Server server;
|
||||||
|
private String port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
||||||
|
|
||||||
public static ServerJetty getInstance() {
|
private ServerJetty() {
|
||||||
if (instance == null)
|
this.server = new Server(Integer.parseInt(port));
|
||||||
instance = new ServerJetty();
|
}
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Server getServer() {
|
public static ServerJetty getInstance() {
|
||||||
return server;
|
if (instance == null)
|
||||||
}
|
instance = new ServerJetty();
|
||||||
}
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server getServer() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,68 +19,74 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions.admin;
|
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 java.net.URI;
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeService;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.net.IPSocket;
|
import org.jclouds.net.IPSocket;
|
||||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Function;
|
||||||
import javax.annotation.Resource;
|
import com.google.common.base.Predicate;
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
|
||||||
|
|
||||||
public class StartVBoxIfNotAlreadyRunning implements Function<URI, VirtualBoxManager> {
|
public class StartVBoxIfNotAlreadyRunning implements Function<URI, VirtualBoxManager> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
private ComputeServiceContext context;
|
|
||||||
private String hostId;
|
|
||||||
private Credentials credentials;
|
|
||||||
|
|
||||||
public StartVBoxIfNotAlreadyRunning(ComputeServiceContext context, String hostId, Credentials credentials) {
|
private final ComputeService compute;
|
||||||
this.context = context;
|
private final VirtualBoxManager manager;
|
||||||
this.hostId = hostId;
|
private final Predicate<IPSocket> socketTester;
|
||||||
this.credentials = credentials;
|
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
|
@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?
|
if (socketTester.apply(new IPSocket(endpoint.getHost(), endpoint.getPort()))) {
|
||||||
VirtualBoxManager manager = VirtualBoxManager.createInstance(hostId);
|
|
||||||
|
|
||||||
if (new InetSocketAddressConnect().apply(new IPSocket(endpoint.getHost(), endpoint.getPort()))) {
|
|
||||||
manager.connect(endpoint.toASCIIString(), credentials.identity, credentials.credential);
|
manager.connect(endpoint.toASCIIString(), credentials.identity, credentials.credential);
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("disabling password access");
|
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");
|
logger.debug("starting vboxwebsrv");
|
||||||
String vboxwebsrv = "vboxwebsrv -t 10000 -v -b";
|
String vboxwebsrv = "vboxwebsrv -t 10000 -v -b";
|
||||||
if (isOSX(hostId))
|
if (isOSX(hostId))
|
||||||
vboxwebsrv = "cd /Applications/VirtualBox.app/Contents/MacOS/ && " + vboxwebsrv;
|
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);
|
manager.connect(endpoint.toASCIIString(), credentials.identity, credentials.credential);
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOSX(String hostId) {
|
private boolean isOSX(String hostId) {
|
||||||
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription().equals(
|
return compute.getNodeMetadata(hostId).getOperatingSystem().getDescription().equals("Mac OS X");
|
||||||
"Mac OS X");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jclouds.virtualbox.settings;
|
package org.jclouds.virtualbox.settings;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -24,138 +25,139 @@ import java.util.Map;
|
||||||
|
|
||||||
public class KeyboardScancodes {
|
public class KeyboardScancodes {
|
||||||
|
|
||||||
// http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
|
// http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
|
||||||
|
|
||||||
public static final Map<String, String> NORMAL_KEYBOARD_BUTTON_MAP = createMap();
|
|
||||||
public static final Map<String, String> SPECIAL_KEYBOARD_BUTTON_MAP = createSpecialMap();
|
|
||||||
|
|
||||||
private static Map<String, String> createMap() {
|
public static final Map<String, String> NORMAL_KEYBOARD_BUTTON_MAP = createMap();
|
||||||
Map<String, String> alphaToHex = new HashMap<String, String>();
|
public static final Map<String, String> SPECIAL_KEYBOARD_BUTTON_MAP = createSpecialMap();
|
||||||
alphaToHex.put("1", "02 82");
|
|
||||||
alphaToHex.put("2", "03 83");
|
|
||||||
alphaToHex.put("3", "04 84");
|
|
||||||
alphaToHex.put("4", "05 85");
|
|
||||||
alphaToHex.put("5", "06 86");
|
|
||||||
alphaToHex.put("6", "07 87");
|
|
||||||
alphaToHex.put("7", "08 88");
|
|
||||||
alphaToHex.put("8", "09 89");
|
|
||||||
alphaToHex.put("9", "0a 8a");
|
|
||||||
alphaToHex.put("0", "0b 8b");
|
|
||||||
alphaToHex.put("-", "0c 8c");
|
|
||||||
alphaToHex.put("=", "0d 8d");
|
|
||||||
alphaToHex.put("Tab", "0f 8f");
|
|
||||||
alphaToHex.put("q", "10 90");
|
|
||||||
alphaToHex.put("w", "11 91");
|
|
||||||
alphaToHex.put("e", "12 92");
|
|
||||||
alphaToHex.put("r", "13 93");
|
|
||||||
alphaToHex.put("t", "14 94");
|
|
||||||
alphaToHex.put("y", "15 95");
|
|
||||||
alphaToHex.put("u", "16 96");
|
|
||||||
alphaToHex.put("i", "17 97");
|
|
||||||
alphaToHex.put("o", "18 98");
|
|
||||||
alphaToHex.put("p", "19 99");
|
|
||||||
|
|
||||||
alphaToHex.put("Q", "2a 10 aa");
|
private static Map<String, String> createMap() {
|
||||||
alphaToHex.put("W", "2a 11 aa");
|
Map<String, String> alphaToHex = new HashMap<String, String>();
|
||||||
alphaToHex.put("E", "2a 12 aa");
|
alphaToHex.put("1", "02 82");
|
||||||
alphaToHex.put("R", "2a 13 aa");
|
alphaToHex.put("2", "03 83");
|
||||||
alphaToHex.put("T", "2a 14 aa");
|
alphaToHex.put("3", "04 84");
|
||||||
alphaToHex.put("Y", "2a 15 aa");
|
alphaToHex.put("4", "05 85");
|
||||||
alphaToHex.put("U", "2a 16 aa");
|
alphaToHex.put("5", "06 86");
|
||||||
alphaToHex.put("I", "2a 17 aa");
|
alphaToHex.put("6", "07 87");
|
||||||
alphaToHex.put("O", "2a 18 aa");
|
alphaToHex.put("7", "08 88");
|
||||||
alphaToHex.put("P", "2a 19 aa");
|
alphaToHex.put("8", "09 89");
|
||||||
|
alphaToHex.put("9", "0a 8a");
|
||||||
|
alphaToHex.put("0", "0b 8b");
|
||||||
|
alphaToHex.put("-", "0c 8c");
|
||||||
|
alphaToHex.put("=", "0d 8d");
|
||||||
|
alphaToHex.put("Tab", "0f 8f");
|
||||||
|
alphaToHex.put("q", "10 90");
|
||||||
|
alphaToHex.put("w", "11 91");
|
||||||
|
alphaToHex.put("e", "12 92");
|
||||||
|
alphaToHex.put("r", "13 93");
|
||||||
|
alphaToHex.put("t", "14 94");
|
||||||
|
alphaToHex.put("y", "15 95");
|
||||||
|
alphaToHex.put("u", "16 96");
|
||||||
|
alphaToHex.put("i", "17 97");
|
||||||
|
alphaToHex.put("o", "18 98");
|
||||||
|
alphaToHex.put("p", "19 99");
|
||||||
|
|
||||||
alphaToHex.put("a", "1e 9e");
|
alphaToHex.put("Q", "2a 10 aa");
|
||||||
alphaToHex.put("s", "1f 9f");
|
alphaToHex.put("W", "2a 11 aa");
|
||||||
alphaToHex.put("d", "20 a0");
|
alphaToHex.put("E", "2a 12 aa");
|
||||||
alphaToHex.put("f", "21 a1");
|
alphaToHex.put("R", "2a 13 aa");
|
||||||
alphaToHex.put("g", "22 a2");
|
alphaToHex.put("T", "2a 14 aa");
|
||||||
alphaToHex.put("h", "23 a3");
|
alphaToHex.put("Y", "2a 15 aa");
|
||||||
alphaToHex.put("j", "24 a4");
|
alphaToHex.put("U", "2a 16 aa");
|
||||||
alphaToHex.put("k", "25 a5");
|
alphaToHex.put("I", "2a 17 aa");
|
||||||
alphaToHex.put("l", "26 a6");
|
alphaToHex.put("O", "2a 18 aa");
|
||||||
|
alphaToHex.put("P", "2a 19 aa");
|
||||||
|
|
||||||
alphaToHex.put("A", "2a 1e aa 9e");
|
alphaToHex.put("a", "1e 9e");
|
||||||
alphaToHex.put("S", "2a 1f aa 9f");
|
alphaToHex.put("s", "1f 9f");
|
||||||
alphaToHex.put("D", "2a 20 aa a0");
|
alphaToHex.put("d", "20 a0");
|
||||||
alphaToHex.put("F", "2a 21 aa a1");
|
alphaToHex.put("f", "21 a1");
|
||||||
alphaToHex.put("G", "2a 22 aa a2");
|
alphaToHex.put("g", "22 a2");
|
||||||
alphaToHex.put("H", "2a 23 aa a3");
|
alphaToHex.put("h", "23 a3");
|
||||||
alphaToHex.put("J", "2a 24 aa a4");
|
alphaToHex.put("j", "24 a4");
|
||||||
alphaToHex.put("K", "2a 25 aa a5");
|
alphaToHex.put("k", "25 a5");
|
||||||
alphaToHex.put("L", "2a 26 aa a6");
|
alphaToHex.put("l", "26 a6");
|
||||||
|
|
||||||
alphaToHex.put(");", "27 a7");
|
alphaToHex.put("A", "2a 1e aa 9e");
|
||||||
alphaToHex.put("\"", "2a 28 aa a8");
|
alphaToHex.put("S", "2a 1f aa 9f");
|
||||||
alphaToHex.put("\"", "28 a8");
|
alphaToHex.put("D", "2a 20 aa a0");
|
||||||
alphaToHex.put("\\", "2b ab");
|
alphaToHex.put("F", "2a 21 aa a1");
|
||||||
alphaToHex.put("|", "2a 2b aa 8b");
|
alphaToHex.put("G", "2a 22 aa a2");
|
||||||
alphaToHex.put("[", "1a 9a");
|
alphaToHex.put("H", "2a 23 aa a3");
|
||||||
alphaToHex.put("", "1b 9b");
|
alphaToHex.put("J", "2a 24 aa a4");
|
||||||
alphaToHex.put("<", "2a 33 aa b3");
|
alphaToHex.put("K", "2a 25 aa a5");
|
||||||
alphaToHex.put(">", "2a 34 aa b4");
|
alphaToHex.put("L", "2a 26 aa a6");
|
||||||
alphaToHex.put("$", "2a 05 aa 85");
|
|
||||||
alphaToHex.put("+", "2a 0d aa 8d");
|
|
||||||
|
|
||||||
alphaToHex.put("z", "2c ac");
|
alphaToHex.put(");", "27 a7");
|
||||||
alphaToHex.put("x", "2d ad");
|
alphaToHex.put("\"", "2a 28 aa a8");
|
||||||
alphaToHex.put("c", "2e ae");
|
alphaToHex.put("\"", "28 a8");
|
||||||
alphaToHex.put("v", "2f af");
|
alphaToHex.put("\\", "2b ab");
|
||||||
alphaToHex.put("b", "30 b0");
|
alphaToHex.put("|", "2a 2b aa 8b");
|
||||||
alphaToHex.put("n", "31 b1");
|
alphaToHex.put("[", "1a 9a");
|
||||||
alphaToHex.put("m", "32 b2");
|
alphaToHex.put("", "1b 9b");
|
||||||
alphaToHex.put("Z", "2a 2c aa ac");
|
alphaToHex.put("<", "2a 33 aa b3");
|
||||||
alphaToHex.put("X", "2a 2d aa ad");
|
alphaToHex.put(">", "2a 34 aa b4");
|
||||||
alphaToHex.put("C", "2a 2e aa ae");
|
alphaToHex.put("$", "2a 05 aa 85");
|
||||||
alphaToHex.put("V", "2a 2f aa af");
|
alphaToHex.put("+", "2a 0d aa 8d");
|
||||||
alphaToHex.put("B", "2a 30 aa b0");
|
|
||||||
alphaToHex.put("N", "2a 31 aa b1");
|
|
||||||
alphaToHex.put("M", "2a 32 aa b2");
|
|
||||||
|
|
||||||
alphaToHex.put(",", "33 b3");
|
alphaToHex.put("z", "2c ac");
|
||||||
alphaToHex.put(".", "34 b4");
|
alphaToHex.put("x", "2d ad");
|
||||||
alphaToHex.put("/", "35 b5");
|
alphaToHex.put("c", "2e ae");
|
||||||
alphaToHex.put(":", "2a 27 aa a7");
|
alphaToHex.put("v", "2f af");
|
||||||
alphaToHex.put("%", "2a 06 aa 86");
|
alphaToHex.put("b", "30 b0");
|
||||||
alphaToHex.put("_", "2a 0c aa 8c");
|
alphaToHex.put("n", "31 b1");
|
||||||
alphaToHex.put("&", "2a 08 aa 88");
|
alphaToHex.put("m", "32 b2");
|
||||||
alphaToHex.put("(", "2a 0a aa 8a");
|
alphaToHex.put("Z", "2a 2c aa ac");
|
||||||
alphaToHex.put(")", "2a 0b aa 8b");
|
alphaToHex.put("X", "2a 2d aa ad");
|
||||||
return Collections.unmodifiableMap(alphaToHex);
|
alphaToHex.put("C", "2a 2e aa ae");
|
||||||
}
|
alphaToHex.put("V", "2a 2f aa af");
|
||||||
private static Map<String, String> createSpecialMap() {
|
alphaToHex.put("B", "2a 30 aa b0");
|
||||||
Map<String, String> special = new HashMap<String, String>();
|
alphaToHex.put("N", "2a 31 aa b1");
|
||||||
special.put("<Enter>", "1c 9c");
|
alphaToHex.put("M", "2a 32 aa b2");
|
||||||
special.put("<Backspace>", "0e 8e");
|
|
||||||
special.put("<Spacebar>", "39 b9");
|
alphaToHex.put(",", "33 b3");
|
||||||
special.put("<Return>", "1c 9c");
|
alphaToHex.put(".", "34 b4");
|
||||||
special.put("<Esc>", "01 81");
|
alphaToHex.put("/", "35 b5");
|
||||||
special.put("<Tab>", "0f 8f");
|
alphaToHex.put(":", "2a 27 aa a7");
|
||||||
special.put("<KillX>", "1d 38 0e");
|
alphaToHex.put("%", "2a 06 aa 86");
|
||||||
special.put("<Wait>", "wait");
|
alphaToHex.put("_", "2a 0c aa 8c");
|
||||||
|
alphaToHex.put("&", "2a 08 aa 88");
|
||||||
special.put("<Up>", "48 c8");
|
alphaToHex.put("(", "2a 0a aa 8a");
|
||||||
special.put("<Down>", "50 d0");
|
alphaToHex.put(")", "2a 0b aa 8b");
|
||||||
special.put("<PageUp>", "49 c9");
|
return Collections.unmodifiableMap(alphaToHex);
|
||||||
special.put("<PageDown>", "51 d1");
|
}
|
||||||
special.put("<End>", "4f cf");
|
|
||||||
special.put("<Insert>", "52 d2");
|
private static Map<String, String> createSpecialMap() {
|
||||||
special.put("<Delete>", "53 d3");
|
Map<String, String> special = new HashMap<String, String>();
|
||||||
special.put("<Left>", "4b cb");
|
special.put("<Enter>", "1c 9c");
|
||||||
special.put("<Right>", "4d cd");
|
special.put("<Backspace>", "0e 8e");
|
||||||
special.put("<Home>", "47 c7");
|
special.put("<Spacebar>", "39 b9");
|
||||||
|
special.put("<Return>", "1c 9c");
|
||||||
special.put("<F1>", "3b");
|
special.put("<Esc>", "01 81");
|
||||||
special.put("<F2>", "3c");
|
special.put("<Tab>", "0f 8f");
|
||||||
special.put("<F3>", "3d");
|
special.put("<KillX>", "1d 38 0e");
|
||||||
special.put("<F4>", "3e");
|
special.put("<Wait>", "wait");
|
||||||
special.put("<F5>", "3f");
|
|
||||||
special.put("<F6>", "40");
|
special.put("<Up>", "48 c8");
|
||||||
special.put("<F7>", "41");
|
special.put("<Down>", "50 d0");
|
||||||
special.put("<F8>", "42");
|
special.put("<PageUp>", "49 c9");
|
||||||
special.put("<F9>", "43");
|
special.put("<PageDown>", "51 d1");
|
||||||
special.put("<F10>", "44");
|
special.put("<End>", "4f cf");
|
||||||
return Collections.unmodifiableMap(special);
|
special.put("<Insert>", "52 d2");
|
||||||
}
|
special.put("<Delete>", "53 d3");
|
||||||
|
special.put("<Left>", "4b cb");
|
||||||
|
special.put("<Right>", "4d cd");
|
||||||
|
special.put("<Home>", "47 c7");
|
||||||
|
|
||||||
|
special.put("<F1>", "3b");
|
||||||
|
special.put("<F2>", "3c");
|
||||||
|
special.put("<F3>", "3d");
|
||||||
|
special.put("<F4>", "3e");
|
||||||
|
special.put("<F5>", "3f");
|
||||||
|
special.put("<F6>", "40");
|
||||||
|
special.put("<F7>", "41");
|
||||||
|
special.put("<F8>", "42");
|
||||||
|
special.put("<F9>", "43");
|
||||||
|
special.put("<F10>", "44");
|
||||||
|
return Collections.unmodifiableMap(special);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,17 +20,27 @@
|
||||||
package org.jclouds.virtualbox;
|
package org.jclouds.virtualbox;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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 java.util.Properties;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||||
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
|
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
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.AfterGroups;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
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.common.collect.ImmutableSet;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
@ -58,6 +68,8 @@ public class BaseVirtualBoxClientLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ComputeServiceContext context;
|
protected ComputeServiceContext context;
|
||||||
|
protected VirtualBoxManager manager;
|
||||||
|
protected Server jetty;
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
@BeforeGroups(groups = { "live" })
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
|
@ -66,12 +78,34 @@ public class BaseVirtualBoxClientLiveTest {
|
||||||
properties.setProperty(provider + ".apiversion", apiversion);
|
properties.setProperty(provider + ".apiversion", apiversion);
|
||||||
context = new ComputeServiceContextFactory().createContext(provider, identity, credential,
|
context = new ComputeServiceContextFactory().createContext(provider, identity, credential,
|
||||||
ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()));
|
ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()));
|
||||||
|
jetty = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
||||||
|
startVboxIfNotAlreadyRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterGroups(groups = "live")
|
@AfterGroups(groups = "live")
|
||||||
protected void tearDown() {
|
protected void tearDown() throws Exception {
|
||||||
if (context != null)
|
if (context != null)
|
||||||
context.close();
|
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;
|
package org.jclouds.virtualbox.compute;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.testng.Assert.assertEquals;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import static org.testng.Assert.assertFalse;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Maps;
|
import java.net.URI;
|
||||||
import com.google.inject.Guice;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.domain.ExecResponse;
|
import org.jclouds.compute.domain.ExecResponse;
|
||||||
import org.jclouds.compute.domain.Image;
|
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.IMachine;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import java.net.URI;
|
import com.google.common.base.Function;
|
||||||
import java.util.Map;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import static org.testng.Assert.assertEquals;
|
import com.google.common.collect.Maps;
|
||||||
import static org.testng.Assert.assertFalse;
|
import com.google.inject.Guice;
|
||||||
|
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest")
|
||||||
public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest {
|
public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
|
@ -57,15 +58,15 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
||||||
private IMachine machine;
|
private IMachine machine;
|
||||||
private final Map<OsFamily, Map<String, String>> osVersionMap = new BaseComputeServiceContextModule() {
|
private final Map<OsFamily, Map<String, String>> osVersionMap = new BaseComputeServiceContextModule() {
|
||||||
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
||||||
.getInstance(Json.class));
|
.getInstance(Json.class));
|
||||||
|
|
||||||
@BeforeGroups(groups = {"live"})
|
@BeforeGroups(groups = { "live" })
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
final VirtualBoxManager manager = getManager();
|
final VirtualBoxManager manager = getManager();
|
||||||
Function<IMachine, Image> iMachineToImage = new IMachineToImage(manager, osVersionMap);
|
Function<IMachine, Image> iMachineToImage = new IMachineToImage(manager, osVersionMap);
|
||||||
adapter = new VirtualBoxComputeServiceAdapter(manager,
|
adapter = new VirtualBoxComputeServiceAdapter(manager, new JustProvider(provider, URI.create(endpoint),
|
||||||
new JustProvider(provider, URI.create(endpoint), ImmutableSet.<String>of()), iMachineToImage);
|
ImmutableSet.<String> of()), iMachineToImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected VirtualBoxManager getManager() {
|
protected VirtualBoxManager getManager() {
|
||||||
|
@ -89,15 +90,16 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
||||||
// check other things, like cpu correct, mem correct, image/os is correct
|
// check other things, like cpu correct, mem correct, image/os is correct
|
||||||
// (as possible)
|
// (as possible)
|
||||||
assert credentialStore.containsKey("node#" + machine.getId()) : "credentials to log into machine not found "
|
assert credentialStore.containsKey("node#" + machine.getId()) : "credentials to log into machine not found "
|
||||||
+ machine;
|
+ machine;
|
||||||
// TODO: what's the IP address?
|
// 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()));
|
doConnectViaSsh(machine, credentialStore.get("node#" + machine.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doConnectViaSsh(IMachine machine, Credentials creds) {
|
protected void doConnectViaSsh(IMachine machine, Credentials creds) {
|
||||||
SshClient ssh = context.utils().sshFactory()
|
SshClient ssh = context.utils().sshFactory().create(new IPSocket("//TODO", 22), creds);
|
||||||
.create(new IPSocket("//TODO", 22), creds);
|
|
||||||
try {
|
try {
|
||||||
ssh.connect();
|
ssh.connect();
|
||||||
ExecResponse hello = ssh.exec("echo hello");
|
ExecResponse hello = ssh.exec("echo hello");
|
||||||
|
@ -128,7 +130,7 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterGroups(groups = "live")
|
@AfterGroups(groups = "live")
|
||||||
protected void tearDown() {
|
protected void tearDown() throws Exception {
|
||||||
if (machine != null)
|
if (machine != null)
|
||||||
adapter.destroyNode(machine.getId() + "");
|
adapter.destroyNode(machine.getId() + "");
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
|
|
@ -19,9 +19,17 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.compute;
|
package org.jclouds.virtualbox.compute;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.easymock.EasyMock.expect;
|
||||||
import com.google.common.collect.Iterators;
|
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||||
import com.google.inject.Guice;
|
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.easymock.EasyMock;
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
@ -37,23 +45,16 @@ import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_1.IVirtualBox;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.google.common.base.Function;
|
||||||
import java.util.Iterator;
|
import com.google.common.collect.Iterators;
|
||||||
import java.util.List;
|
import com.google.inject.Guice;
|
||||||
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;
|
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class VirtualBoxComputeServiceAdapterTest {
|
public class VirtualBoxComputeServiceAdapterTest {
|
||||||
|
|
||||||
Map<OsFamily, Map<String, String>> osMap = new BaseComputeServiceContextModule() {
|
Map<OsFamily, Map<String, String>> osMap = new BaseComputeServiceContextModule() {
|
||||||
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
||||||
.getInstance(Json.class));
|
.getInstance(Json.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListImages() throws Exception {
|
public void testListImages() throws Exception {
|
||||||
|
@ -76,14 +77,15 @@ public class VirtualBoxComputeServiceAdapterTest {
|
||||||
|
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
expect(vBox.getMachines()).andReturn(machines).anyTimes();
|
expect(vBox.getMachines()).andReturn(machines).anyTimes();
|
||||||
expect(vBox.getGuestOSType(EasyMock.<String>anyObject())).andReturn(osType).anyTimes();
|
expect(vBox.getGuestOSType(EasyMock.<String> anyObject())).andReturn(osType).anyTimes();
|
||||||
expect(osType.getDescription()).andReturn("Ubuntu 10.04").anyTimes();
|
expect(osType.getDescription()).andReturn("Ubuntu 10.04").anyTimes();
|
||||||
expect(osType.getIs64Bit()).andReturn(true).anyTimes();
|
expect(osType.getIs64Bit()).andReturn(true).anyTimes();
|
||||||
|
|
||||||
replay(manager, justProvider, vBox, clonedMachine, imageMachine, osType);
|
replay(manager, justProvider, vBox, clonedMachine, imageMachine, osType);
|
||||||
|
|
||||||
Function<IMachine, Image> iMachineToImage = new IMachineToImage(manager, osMap);
|
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();
|
Iterator<Image> iterator = adapter.listImages().iterator();
|
||||||
Image image = Iterators.getOnlyElement(iterator);
|
Image image = Iterators.getOnlyElement(iterator);
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", testName = "VirtualBoxExperimentLiveTest")
|
@Test(groups = "live", testName = "VirtualBoxExperimentLiveTest")
|
||||||
public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest{
|
public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAndExperiment() {
|
public void testAndExperiment() {
|
||||||
|
|
|
@ -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;
|
package org.jclouds.virtualbox.experiment;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import java.io.IOException;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import java.net.URI;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import java.net.URISyntaxException;
|
||||||
import com.google.inject.Module;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.byon.Node;
|
import org.jclouds.byon.Node;
|
||||||
import org.jclouds.byon.config.CacheNodeStoreModule;
|
import org.jclouds.byon.config.CacheNodeStoreModule;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
@ -31,75 +32,48 @@ import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
|
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
|
||||||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.google.common.cache.Cache;
|
||||||
import java.net.URI;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import java.net.URISyntaxException;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import java.util.Map;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
public class TestUtils {
|
public class TestUtils {
|
||||||
|
|
||||||
public static ComputeServiceContext computeServiceForLocalhostAndGuest() throws IOException {
|
public static ComputeServiceContext computeServiceForLocalhostAndGuest() throws IOException {
|
||||||
|
|
||||||
Node host = Node.builder().id("host")
|
Node host = Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
|
||||||
.name("host installing virtualbox")
|
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
|
||||||
.hostname("localhost")
|
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
|
||||||
.osFamily(OsFamily.LINUX.toString())
|
.credentialUrl(privateKeyFile()).build();
|
||||||
.osDescription(System.getProperty("os.name"))
|
Node guest = Node.builder().id("guest").name("new guest").hostname("localhost").loginPort(2222)
|
||||||
.osVersion(System.getProperty("os.version"))
|
.osFamily(OsFamily.UBUNTU.toString()).osDescription("ubuntu/11.04").osVersion(System.getProperty("11.04"))
|
||||||
.group("ssh")
|
.group("guest").username("toor").sudoPassword("password").credential("password").build();
|
||||||
.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)
|
||||||
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module>of(
|
.build();
|
||||||
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(nodeMap)));
|
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module> of(
|
||||||
|
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(),
|
||||||
|
new CacheNodeStoreModule(nodeMap)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ComputeServiceContext computeServiceForLocalhostAndGuest(String hostId, String hostname, String guestId, String guestHostname,
|
public static ComputeServiceContext computeServiceForLocalhostAndGuest(String hostId, String hostname,
|
||||||
Credentials guestLogin) throws IOException {
|
String guestId, String guestHostname, Credentials guestLogin) {
|
||||||
|
|
||||||
Node host = Node.builder().id(hostId)
|
Node host = Node.builder().id(hostId).name("host installing virtualbox").hostname(hostname)
|
||||||
.name("host installing virtualbox")
|
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
|
||||||
.hostname(hostname)
|
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
|
||||||
.osFamily(OsFamily.LINUX.toString())
|
.credentialUrl(privateKeyFile()).build();
|
||||||
.osDescription(System.getProperty("os.name"))
|
Node guest = Node.builder().id(guestId).name("new guest").hostname(guestHostname).loginPort(2222)
|
||||||
.osVersion(System.getProperty("os.version"))
|
.osFamily(OsFamily.UBUNTU.toString()).osDescription("ubuntu/11.04").osVersion(System.getProperty("11.04"))
|
||||||
.group("ssh")
|
.group("jclouds-linux-image").username(guestLogin.identity).sudoPassword(guestLogin.credential)
|
||||||
.username(System.getProperty("user.name"))
|
.credential(guestLogin.credential).build();
|
||||||
.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)
|
||||||
final Map<String, Node> nodeMap = ImmutableMap.<String, Node>builder().put(hostId, host).put(guestId, guest).build();
|
.build();
|
||||||
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module>of(
|
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() {
|
private static URI privateKeyFile() {
|
||||||
|
@ -112,7 +86,8 @@ public class TestUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ComputeServiceContext computeServiceForVirtualBox(Cache<String, Node> cache) {
|
public static ComputeServiceContext computeServiceForVirtualBox(Cache<String, Node> cache) {
|
||||||
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module>of(
|
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
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -19,12 +19,16 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_1.VBoxException;
|
||||||
|
|
||||||
import static org.easymock.classextension.EasyMock.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -49,8 +53,8 @@ public class ApplyMemoryToMachineTest {
|
||||||
@Test(expectedExceptions = VBoxException.class)
|
@Test(expectedExceptions = VBoxException.class)
|
||||||
public void testRethrowInvalidRamSizeError() throws Exception {
|
public void testRethrowInvalidRamSizeError() throws Exception {
|
||||||
// Mainly here for documentation purposes
|
// Mainly here for documentation purposes
|
||||||
final String error = "VirtualBox error: Invalid RAM size: " +
|
final String error = "VirtualBox error: Invalid RAM size: "
|
||||||
"3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)";
|
+ "3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)";
|
||||||
|
|
||||||
long memorySize = 1024l;
|
long memorySize = 1024l;
|
||||||
IMachine machine = createMock(IMachine.class);
|
IMachine machine = createMock(IMachine.class);
|
||||||
|
|
|
@ -18,15 +18,18 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.functions;
|
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.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_1.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_1.IMedium;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_1.VBoxException;
|
||||||
|
|
||||||
import static org.easymock.classextension.EasyMock.*;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -67,7 +70,8 @@ public class AttachDistroMediumToMachineTest {
|
||||||
errorBuilder.append("of this virtual machine (0x80BB000C)");
|
errorBuilder.append("of this virtual machine (0x80BB000C)");
|
||||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
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);
|
machine.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
|
||||||
expectLastCall().andThrow(isoAttachedException);
|
expectLastCall().andThrow(isoAttachedException);
|
||||||
|
|
||||||
|
@ -92,7 +96,8 @@ public class AttachDistroMediumToMachineTest {
|
||||||
errorBuilder.append("Some other VBox error");
|
errorBuilder.append("Some other VBox error");
|
||||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
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);
|
machine.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
|
||||||
expectLastCall().andThrow(isoAttachedException);
|
expectLastCall().andThrow(isoAttachedException);
|
||||||
|
|
||||||
|
@ -102,5 +107,4 @@ public class AttachDistroMediumToMachineTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,23 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import static org.easymock.EasyMock.anyLong;
|
||||||
import org.virtualbox_4_1.*;
|
import static org.easymock.EasyMock.expect;
|
||||||
|
import static org.easymock.EasyMock.expectLastCall;
|
||||||
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.virtualbox_4_1.DeviceType.HardDisk;
|
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
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -54,7 +65,8 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
||||||
machine.saveSettings();
|
machine.saveSettings();
|
||||||
replay(manager, machine, vBox, hardDisk);
|
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);
|
verify(machine);
|
||||||
|
|
||||||
|
@ -79,13 +91,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
||||||
errorBuilder.append("of this virtual machine (0x80BB000C)");
|
errorBuilder.append("of this virtual machine (0x80BB000C)");
|
||||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
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);
|
machine.attachDevice(controllerIDE, controllerPort, device, HardDisk, hardDisk);
|
||||||
expectLastCall().andThrow(isoAttachedException);
|
expectLastCall().andThrow(isoAttachedException);
|
||||||
|
|
||||||
replay(manager, machine, vBox, hardDisk);
|
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);
|
verify(machine);
|
||||||
|
|
||||||
|
@ -108,13 +122,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
||||||
errorBuilder.append("Some other VBox error");
|
errorBuilder.append("Some other VBox error");
|
||||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
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);
|
machine.attachDevice(controllerIDE, controllerPort, device, HardDisk, hardDisk);
|
||||||
expectLastCall().andThrow(isoAttachedException);
|
expectLastCall().andThrow(isoAttachedException);
|
||||||
|
|
||||||
replay(manager, machine, vBox, hardDisk);
|
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
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -19,13 +19,20 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import static org.easymock.EasyMock.expect;
|
||||||
import org.virtualbox_4_1.*;
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
|
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||||
import static org.easymock.classextension.EasyMock.*;
|
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.NATProtocol.TCP;
|
||||||
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
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
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -60,8 +67,8 @@ public class AttachNATRedirectRuleToMachineTest {
|
||||||
INetworkAdapter networkAdapter = createMock(INetworkAdapter.class);
|
INetworkAdapter networkAdapter = createMock(INetworkAdapter.class);
|
||||||
INATEngine natEngine = createMock(INATEngine.class);
|
INATEngine natEngine = createMock(INATEngine.class);
|
||||||
|
|
||||||
String error = "VirtualBox error: Argument slot is invalid " +
|
String error = "VirtualBox error: Argument slot is invalid "
|
||||||
"(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)";
|
+ "(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)";
|
||||||
|
|
||||||
VBoxException invalidSlotException = new VBoxException(createNiceMock(Throwable.class), error);
|
VBoxException invalidSlotException = new VBoxException(createNiceMock(Throwable.class), error);
|
||||||
expect(machine.getNetworkAdapter(adapterId)).andThrow(invalidSlotException);
|
expect(machine.getNetworkAdapter(adapterId)).andThrow(invalidSlotException);
|
||||||
|
@ -73,5 +80,4 @@ public class AttachNATRedirectRuleToMachineTest {
|
||||||
verify(machine, networkAdapter, natEngine);
|
verify(machine, networkAdapter, natEngine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,15 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.easymock.EasyMock;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
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.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
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
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -55,9 +60,10 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
vBox.findMachine(vmName);
|
vBox.findMachine(vmName);
|
||||||
expectLastCall().andThrow(vBoxException);
|
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);
|
vBox.registerMachine(createdMachine);
|
||||||
|
|
||||||
replay(manager, vBox);
|
replay(manager, vBox);
|
||||||
|
@ -103,10 +109,9 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
|
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String anyString() {
|
private String anyString() {
|
||||||
return EasyMock.<String>anyObject();
|
return EasyMock.<String> anyObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,23 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.anyLong;
|
||||||
import static org.easymock.EasyMock.expect;
|
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 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
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -137,5 +146,4 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
||||||
new CreateMediumIfNotAlreadyExists(manager, diskFormat, true).apply(adminDiskPath);
|
new CreateMediumIfNotAlreadyExists(manager, diskFormat, true).apply(adminDiskPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
//@Test(groups = "live")
|
|
||||||
public class IMachineToNodeMetadataTest {
|
public class IMachineToNodeMetadataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -19,10 +19,6 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Andrea Turli, Mattias Holmqvist
|
|
||||||
*/
|
|
||||||
|
|
||||||
import static com.google.common.base.Predicates.equalTo;
|
import static com.google.common.base.Predicates.equalTo;
|
||||||
import static com.google.common.collect.Iterables.any;
|
import static com.google.common.collect.Iterables.any;
|
||||||
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||||
|
@ -47,13 +43,16 @@ import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andrea Turli, Mattias Holmqvist
|
||||||
|
*/
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "IsoToIMachineLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "IsoToIMachineLiveTest")
|
||||||
public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
|
|
||||||
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
|
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
|
||||||
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
||||||
.getInstance(Json.class));
|
.getInstance(Json.class));
|
||||||
|
|
||||||
private String settingsFile = null;
|
private String settingsFile = null;
|
||||||
private boolean forceOverwrite = true;
|
private boolean forceOverwrite = true;
|
||||||
private String vmId = "jclouds-image-iso-1";
|
private String vmId = "jclouds-image-iso-1";
|
||||||
|
@ -76,24 +75,16 @@ public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
public void testCreateImageMachineFromIso() throws Exception {
|
public void testCreateImageMachineFromIso() throws Exception {
|
||||||
|
|
||||||
VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
|
VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
|
||||||
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId, "localhost", new Credentials("toor", "password"));
|
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId,
|
||||||
IMachine imageMachine = new IsoToIMachine(manager,
|
"localhost", new Credentials("toor", "password"));
|
||||||
adminDisk,
|
IMachine imageMachine = new IsoToIMachine(manager, adminDisk, diskFormat, settingsFile, vmName, osTypeId, vmId,
|
||||||
diskFormat,
|
forceOverwrite, controllerIDE, localHostContext, hostId, guestId, new Credentials("toor", "password"))
|
||||||
settingsFile,
|
.apply("ubuntu-11.04-server-i386.iso");
|
||||||
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);
|
IMachineToImage iMachineToImage = new IMachineToImage(manager, map);
|
||||||
Image newImage = iMachineToImage.apply(imageMachine);
|
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();
|
Set<? extends Image> images = context.getComputeService().listImages();
|
||||||
|
|
||||||
assertTrue(any(images, equalTo(newImage)));
|
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;
|
package org.jclouds.virtualbox.functions.admin;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
@ -13,23 +32,6 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.collect.ImmutableMap;
|
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
|
* @author Andrea Turli
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
|
|
|
@ -19,36 +19,37 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions.admin;
|
package org.jclouds.virtualbox.functions.admin;
|
||||||
|
|
||||||
/**
|
import static org.easymock.EasyMock.expect;
|
||||||
* @author Andrea Turli
|
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 static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "StartJettyIfNotAlreadyRunningLiveTest")
|
* @author Andrea Turli
|
||||||
public class StartJettyIfNotAlreadyRunningLiveTest extends BaseVirtualBoxClientLiveTest {
|
*/
|
||||||
|
@Test(groups = "unit", singleThreaded = true, testName = "StartJettyIfNotAlreadyRunningTest")
|
||||||
|
public class StartJettyIfNotAlreadyRunningTest {
|
||||||
|
|
||||||
private String basebaseResource = ".";
|
private String basebaseResource = ".";
|
||||||
private String port = "8080";
|
private int port = 8080;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLaunchJettyServer() throws Exception {
|
public void testLaunchJettyServerWhenAlreadyRunningDoesntLaunchAgain() {
|
||||||
Server server = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
Server jetty = createMock(Server.class);
|
||||||
server.stop();
|
expect(jetty.getState()).andReturn(Server.STARTED);
|
||||||
assertEquals(server.getState(), server.STOPPED);
|
replay(jetty);
|
||||||
}
|
|
||||||
|
assertEquals(new StartJettyIfNotAlreadyRunning(jetty, port).apply(basebaseResource), jetty);
|
||||||
@Test
|
verify(jetty);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
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 static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
import org.jclouds.scriptbuilder.domain.OsFamily;
|
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||||
import org.jclouds.scriptbuilder.domain.ShellToken;
|
import org.jclouds.scriptbuilder.domain.ShellToken;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -35,7 +33,7 @@ import com.google.common.collect.ImmutableMap;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class UtilsTest {
|
public class UtilsTest {
|
||||||
|
|
||||||
public void testReplaceTokens() throws UnsupportedEncodingException {
|
public void testReplaceTokens() {
|
||||||
assertEquals(Utils.replaceTokens("hello {where}", ImmutableMap.of("where", "world")),
|
assertEquals(Utils.replaceTokens("hello {where}", ImmutableMap.of("where", "world")),
|
||||||
"hello world");
|
"hello world");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue