Search in sources :

Example 1 with BlobCache

use of org.apache.whirr.util.BlobCache in project whirr by apache.

the class BlobCacheTest method testSelectBestLocation.

@Test
public void testSelectBestLocation() throws Exception {
    ClusterSpec spec = getTestClusterSpec();
    if (!spec.getProvider().equals("aws") && !spec.getProvider().equals("aws-ec2")) {
        // this test can be executed only on amazon but the internal
        return;
    // location selection mechanism should work for any cloud provider
    }
    spec.setTemplate(TemplateBuilderSpec.parse("locationId=eu-west-1"));
    BlobCache cache = BlobCache.getInstance(ComputeCache.INSTANCE, spec);
    assertThat(cache.getLocation().getId(), is("EU"));
}
Also used : BlobCache(org.apache.whirr.util.BlobCache) ClusterSpec(org.apache.whirr.ClusterSpec) Test(org.junit.Test)

Example 2 with BlobCache

use of org.apache.whirr.util.BlobCache in project whirr by apache.

the class BlobCacheTest method testSpecifyCacheContainerInConfig.

@Test
public void testSpecifyCacheContainerInConfig() throws Exception {
    ClusterSpec spec = getTestClusterSpec();
    BlobStoreContext context = BlobStoreContextBuilder.build(spec);
    String container = generateRandomContainerName(context);
    LOG.info("Created temporary container '{}'", container);
    try {
        spec.setBlobStoreCacheContainer(container);
        BlobCache cache = BlobCache.getInstance(ComputeCache.INSTANCE, spec);
        assertThat(cache.getContainer(), is(container));
        cache.dropAndClose();
        assertThat(context.getBlobStore().containerExists(container), is(true));
    } finally {
        LOG.info("Removing temporary container '{}'", container);
        context.getBlobStore().deleteContainer(container);
    }
}
Also used : BlobCache(org.apache.whirr.util.BlobCache) ClusterSpec(org.apache.whirr.ClusterSpec) BlobStoreContext(org.jclouds.blobstore.BlobStoreContext) Test(org.junit.Test)

Example 3 with BlobCache

use of org.apache.whirr.util.BlobCache in project whirr by apache.

the class ClusterActionHandlerSupport method prepareRemoteFileUrl.

/**
 * Prepare the file url for the remote machine.
 *
 * For public urls this function does nothing. For local urls it uploads the files to a
 * temporary blob cache and adds download statement.
 *
 * @param rawUrl    raw url as provided in the configuration file
 * @return  an URL visible to the install / configure scripts
 */
public static String prepareRemoteFileUrl(ClusterActionEvent event, String rawUrl) throws IOException {
    if (rawUrl != null && rawUrl.startsWith("file://")) {
        try {
            URI uri = new URI(rawUrl);
            File localFile = new File(uri);
            BlobCache cache = BlobCache.getInstance(event.getCompute(), event.getClusterSpec());
            cache.putIfAbsent(localFile);
            final String basePath = "/tmp/whirr/cache/files/";
            addStatement(event, cache.getAsSaveToStatement(basePath, uri));
            return "file://" + basePath + localFile.getName();
        } catch (URISyntaxException e) {
            throw new IOException(e);
        }
    } else if (rawUrl != null && rawUrl.startsWith("remote://")) {
        return rawUrl.replaceFirst("remote://", "file://");
    }
    return rawUrl;
}
Also used : BlobCache(org.apache.whirr.util.BlobCache) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Example 4 with BlobCache

use of org.apache.whirr.util.BlobCache in project whirr by apache.

the class BlobCacheTest method testBlobCacheUpload.

private void testBlobCacheUpload(String payload, ClusterSpec spec) throws Exception {
    File tempFile = createTemporaryFile(payload);
    BlobCache cache = BlobCache.getInstance(ComputeCache.INSTANCE, spec);
    try {
        cache.putIfAbsent(tempFile);
        HttpRequest req = cache.getSignedRequest(tempFile.getName());
        assertThat(readContent(req), is(payload));
        /* render download statement for visual test inspection */
        LOG.info(cache.getAsSaveToStatement("/tmp", tempFile.getName()).render(OsFamily.UNIX));
    } finally {
        BlobCache.dropAndCloseAll();
    }
}
Also used : HttpRequest(org.jclouds.http.HttpRequest) BlobCache(org.apache.whirr.util.BlobCache) File(java.io.File)

Aggregations

BlobCache (org.apache.whirr.util.BlobCache)4 File (java.io.File)2 ClusterSpec (org.apache.whirr.ClusterSpec)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 BlobStoreContext (org.jclouds.blobstore.BlobStoreContext)1 HttpRequest (org.jclouds.http.HttpRequest)1