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"));
}
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);
}
}
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;
}
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();
}
}
Aggregations