Skip to content
Permalink
Browse files
Follow-up to Glacier pull request reviews
* updating Javadocs
* minor style changes
  • Loading branch information
rcoedo authored and demobox committed Aug 3, 2014
1 parent 7ca9836 commit dd4fbb79f2fadb9409cd8a8bd0dc65ef8819801d
Showing 6 changed files with 44 additions and 66 deletions.
@@ -68,7 +68,8 @@ public interface GlacierClient extends Closeable {
*
* @param vaultName
* Name of the Vault being described.
* @return A VaultMetadata object containing all the information relevant to the vault.
* @return A VaultMetadata object containing all the information relevant to the vault if the vault exists,
* null otherwise.
* @see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-vault-get.html" />
*/
VaultMetadata describeVault(String vaultName);
@@ -242,7 +243,7 @@ public interface GlacierClient extends Closeable {
* Name of the target Vault for the job.
* @param jobId
* Job identifier.
* @return The job metadata.
* @return The job metadata if the job exists in the vault, null otherwise.
* @see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-describe-job-get.html" />
*/
JobMetadata describeJob(String vaultName, String jobId);
@@ -52,6 +52,7 @@

import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -196,10 +197,10 @@ public PageSet<? extends StorageMetadata> list(String container, ListContainerOp
if (pollingStrategy.get().waitForSuccess(container, jobId)) {
return archivesToBlobs.apply(sync.getInventoryRetrievalOutput(container, jobId));
}
return null;
} catch (InterruptedException e) {
throw new RuntimeException(e);
Throwables.propagate(e);
}
return null;
}

/**
@@ -216,11 +217,11 @@ public PageSet<? extends StorageMetadata> list(String container, ListContainerOp
*/
@Override
public boolean blobExists(String container, String key) {
return this.blobMetadata(container, key) != null;
return blobMetadata(container, key) != null;
}

/**
* Stores a blob in a container.
* Stores a blob in a container. The blob name will be ignored, since it's not supported by Glacier.
*
* @param container
* container name
@@ -266,20 +267,21 @@ public String putBlob(String container, Blob blob, PutOptions options) {
*/
@Override
public BlobMetadata blobMetadata(String container, String key) {
PageSet<? extends StorageMetadata> blobs = this.list(container, null);
for (StorageMetadata blob : blobs) {
PageSet<? extends StorageMetadata> blobMetadataSet = list(container, null);
for (StorageMetadata blob : blobMetadataSet) {
if (blob.getName().equals(key)) {
return (BlobMetadata) blob;
}
}
return null;
}

private ArchiveRetrievalJobRequest buildArchiveRetrievalRequest(String key, GetOptions getOptions) {
private static ArchiveRetrievalJobRequest buildArchiveRetrievalRequest(String key, GetOptions getOptions) {
ArchiveRetrievalJobRequest.Builder requestBuilder = ArchiveRetrievalJobRequest.builder().archiveId(key);
if (getOptions != null) {
checkArgument(getOptions.getRanges().size() <= 1);
if (getOptions.getRanges().size() == 1) {
int size = getOptions.getRanges().size();
checkArgument(size <= 1, "The number of ranges should be zero or one");
if (size == 1) {
requestBuilder.range(ContentRange.fromString(getOptions.getRanges().get(0)));
}
}
@@ -309,10 +311,10 @@ public Blob getBlob(String container, String key, GetOptions getOptions) {
blob.setPayload(sync.getJobOutput(container, jobId));
return blob;
}
return null;
} catch (InterruptedException e) {
throw new RuntimeException(e);
Throwables.propagate(e);
}
return null;
}

/**
@@ -16,10 +16,15 @@
*/
package org.jclouds.glacier.blobstore.functions;

import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
import org.jclouds.blobstore.domain.internal.PageSetImpl;
import org.jclouds.glacier.domain.ArchiveMetadata;
import org.jclouds.glacier.domain.ArchiveMetadataCollection;
import org.jclouds.io.MutableContentMetadata;
import org.jclouds.io.payloads.BaseMutableContentMetadata;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;
@@ -30,4 +35,18 @@ public class ArchiveMetadataCollectionToStorageMetadata implements Function<Arch
public PageSet<? extends StorageMetadata> apply(ArchiveMetadataCollection archives) {
return new PageSetImpl<StorageMetadata>(Iterables.transform(archives, new ArchiveMetadataToBlobMetadata()), null);
}

private static class ArchiveMetadataToBlobMetadata implements Function<ArchiveMetadata, MutableBlobMetadata> {
@Override
public MutableBlobMetadata apply(ArchiveMetadata from) {
MutableContentMetadata contentMetadata = new BaseMutableContentMetadata();
contentMetadata.setContentLength(from.getSize());

MutableBlobMetadata to = new MutableBlobMetadataImpl();
to.setName(from.getArchiveId());
to.setCreationDate(from.getCreationDate());
to.setContentMetadata(contentMetadata);
return to;
}
}
}

This file was deleted.

@@ -40,29 +40,22 @@ public class BasePollingStrategy implements PollingStrategy {
private final long initialWait;
private final long timeBetweenPolls;

public BasePollingStrategy(long initialWait, long timeBetweenPolls, GlacierClient client) {
public BasePollingStrategy(GlacierClient client, long initialWait, long timeBetweenPolls) {
this.client = checkNotNull(client, "client");
this.initialWait = initialWait;
this.timeBetweenPolls = timeBetweenPolls;
this.client = checkNotNull(client, "client");
}

@Inject
public BasePollingStrategy(GlacierClient client) {
this(DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS, client);
this(client, DEFAULT_INITIAL_WAIT, DEFAULT_TIME_BETWEEN_POLLS);
}

private boolean inProgress(String job, String vault) {
JobMetadata jobMetadata = client.describeJob(vault, job);
return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.IN_PROGRESS);
}

private void waitForJob(String job, String vault) throws InterruptedException {
Thread.sleep(initialWait);
while (inProgress(job, vault)) {
Thread.sleep(timeBetweenPolls);
}
}

private boolean succeeded(String job, String vault) {
JobMetadata jobMetadata = client.describeJob(vault, job);
return (jobMetadata != null) && (jobMetadata.getStatusCode() == JobStatus.SUCCEEDED);
@@ -74,7 +67,10 @@ public boolean waitForSuccess(String vault, String job) throws InterruptedExcept
if (client.describeJob(vault, job) == null) {
return false;
}
waitForJob(job, vault);
Thread.sleep(initialWait);
while (inProgress(job, vault)) {
Thread.sleep(timeBetweenPolls);
}
return succeeded(job, vault);
}

@@ -112,7 +112,8 @@ public void testListJobs() {
@Test(groups = {"live", "livelong", "longtest"}, dependsOnMethods = {"testInitiateJob", "testDescribeJob", "testListJobs"})
public void testWaitForSucceed() throws InterruptedException {
new BasePollingStrategy(api).waitForSuccess(VAULT_NAME, archiveRetrievalJob);
new BasePollingStrategy(0, DEFAULT_TIME_BETWEEN_POLLS, api).waitForSuccess(VAULT_NAME, inventoryRetrievalJob);
new BasePollingStrategy(api, 0, DEFAULT_TIME_BETWEEN_POLLS).waitForSuccess(VAULT_NAME,
inventoryRetrievalJob);
assertThat(api.describeJob(VAULT_NAME, archiveRetrievalJob).getStatusCode()).isEqualTo(JobStatus.SUCCEEDED);
assertThat(api.describeJob(VAULT_NAME, inventoryRetrievalJob).getStatusCode()).isEqualTo(JobStatus.SUCCEEDED);
}

0 comments on commit dd4fbb7

Please sign in to comment.