Skip to content
Permalink
Browse files
JCLOUDS-457: Added the retrieve output operations
Now the Glacier client can retrieve data.
  • Loading branch information
rcoedo authored and gaul committed Jun 30, 2014
1 parent 174b62b commit 17249cf7364a1a0b06dd4ef9e68632f5abdb8eb0
Showing 9 changed files with 423 additions and 0 deletions.
@@ -32,13 +32,15 @@

import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.blobstore.attr.BlobScope;
import org.jclouds.glacier.binders.BindArchiveOutputRangeToHeaders;
import org.jclouds.glacier.binders.BindArchiveSizeToHeaders;
import org.jclouds.glacier.binders.BindContentRangeToHeaders;
import org.jclouds.glacier.binders.BindDescriptionToHeaders;
import org.jclouds.glacier.binders.BindHashesToHeaders;
import org.jclouds.glacier.binders.BindJobRequestToJsonPayload;
import org.jclouds.glacier.binders.BindMultipartTreeHashToHeaders;
import org.jclouds.glacier.binders.BindPartSizeToHeaders;
import org.jclouds.glacier.domain.ArchiveMetadataCollection;
import org.jclouds.glacier.domain.JobMetadata;
import org.jclouds.glacier.domain.JobRequest;
import org.jclouds.glacier.domain.MultipartUploadMetadata;
@@ -48,7 +50,9 @@
import org.jclouds.glacier.domain.VaultMetadata;
import org.jclouds.glacier.fallbacks.FalseOnIllegalArgumentException;
import org.jclouds.glacier.filters.RequestAuthorizeSignature;
import org.jclouds.glacier.functions.GetPayloadFromHttpContent;
import org.jclouds.glacier.functions.ParseArchiveIdHeader;
import org.jclouds.glacier.functions.ParseArchiveMetadataCollectionFromHttpContent;
import org.jclouds.glacier.functions.ParseJobIdHeader;
import org.jclouds.glacier.functions.ParseJobMetadataFromHttpContent;
import org.jclouds.glacier.functions.ParseJobMetadataListFromHttpContent;
@@ -313,4 +317,38 @@ ListenableFuture<PaginatedJobCollection> listJobs(
@ResponseParser(ParseJobMetadataListFromHttpContent.class)
ListenableFuture<PaginatedJobCollection> listJobs(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName);

/**
* @see GlacierClient#getJobOutput
*/
@Named("GetJobOutput")
@GET
@Path("/-/vaults/{vault}/jobs/{job}/output")
@ResponseParser(GetPayloadFromHttpContent.class)
ListenableFuture<Payload> getJobOutput(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName,
@PathParam("job") String jobId,
@BinderParam(BindArchiveOutputRangeToHeaders.class) ContentRange range);

/**
* @see GlacierClient#getJobOutput
*/
@Named("GetJobOutput")
@GET
@Path("/-/vaults/{vault}/jobs/{job}/output")
@ResponseParser(GetPayloadFromHttpContent.class)
ListenableFuture<Payload> getJobOutput(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName,
@PathParam("job") String jobId);

/**
* @see GlacierClient#getInventoryRetrievalOutput
*/
@Named("GetInventoryRetrievalOutput")
@GET
@Path("/-/vaults/{vault}/jobs/{job}/output")
@ResponseParser(ParseArchiveMetadataCollectionFromHttpContent.class)
ListenableFuture<ArchiveMetadataCollection> getInventoryRetrievalOutput(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName,
@PathParam("job") String jobId);
}
@@ -20,6 +20,7 @@
import java.net.URI;
import java.util.Map;

import org.jclouds.glacier.domain.ArchiveMetadataCollection;
import org.jclouds.glacier.domain.JobMetadata;
import org.jclouds.glacier.domain.JobRequest;
import org.jclouds.glacier.domain.MultipartUploadMetadata;
@@ -262,4 +263,42 @@ public interface GlacierClient extends Closeable {
* Lists jobs.
*/
PaginatedJobCollection listJobs(String vaultName);

/**
* Downloads part of the output of an archive retrieval job.
*
* @param vaultName
* Name of the target Vault for the job.
* @param jobId
* Job identifier.
* @param range
* The range of bytes to retrieve from the output.
* @return The content data.
* @see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-job-output-get.html" />
*/
Payload getJobOutput(String vaultName, String jobId, ContentRange range);

/**
* Downloads the output of an archive retrieval job.
*
* @param vaultName
* Name of the target Vault for the job.
* @param jobId
* Job identifier.
* @return The content data.
* @see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-job-output-get.html" />
*/
Payload getJobOutput(String vaultName, String jobId);

/**
* Downloads the output of an inventory retrieval job.
*
* @param vaultName
* Name of the target Vault for the job.
* @param jobId
* Job identifier.
* @return The ArchiveMetadata collection
* @see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-job-output-get.html" />
*/
ArchiveMetadataCollection getInventoryRetrievalOutput(String vaultName, String jobId);
}
@@ -0,0 +1,40 @@
/*
* 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.glacier.binders;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import org.jclouds.glacier.util.ContentRange;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;

/**
* Binds the ContentRange to the request headers.
*/
public class BindArchiveOutputRangeToHeaders implements Binder {

@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(input instanceof ContentRange, "This binder is only valid for ContentRange");
checkNotNull(request, "request");
ContentRange range = ContentRange.class.cast(input);
return (R) request.toBuilder().addHeader("Range", "bytes=" + range.toString()).build();
}

}
@@ -0,0 +1,103 @@
/*
* 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.glacier.domain;

import static com.google.common.base.Preconditions.checkNotNull;

import java.beans.ConstructorProperties;
import java.util.Date;

import org.jclouds.javax.annotation.Nullable;

import com.google.common.base.Objects;
import com.google.common.collect.ComparisonChain;
import com.google.common.hash.HashCode;
import com.google.gson.annotations.SerializedName;

public class ArchiveMetadata implements Comparable<ArchiveMetadata> {

@SerializedName("ArchiveId")
private final String archiveId;
@SerializedName("ArchiveDescription")
private final String description;
@SerializedName("CreationDate")
private final Date creationDate;
@SerializedName("Size")
private final long size;
@SerializedName("SHA256TreeHash")
private final HashCode treeHash;

@ConstructorProperties({ "ArchiveId", "ArchiveDescription", "CreationDate", "Size", "SHA256TreeHash" })
public ArchiveMetadata(String archiveId, @Nullable String description, Date creationDate, long size, String hashCode) {
this.archiveId = checkNotNull(archiveId, "archiveId");
this.description = description;
this.creationDate = (Date) checkNotNull(creationDate, "creationDate").clone();
this.size = size;
this.treeHash = HashCode.fromString(checkNotNull(hashCode, "hashCode"));
}

public String getArchiveId() {
return archiveId;
}

public String getDescription() {
return description;
}

public Date getCreationDate() {
return (Date) creationDate.clone();
}

public long getSize() {
return size;
}

public HashCode getTreeHash() {
return treeHash;
}

@Override
public int hashCode() {
return Objects.hashCode(this.archiveId, this.description, this.creationDate, this.size, this.treeHash);
}

@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ArchiveMetadata other = (ArchiveMetadata) obj;

return Objects.equal(this.archiveId, other.archiveId)
&& Objects.equal(this.description, other.description)
&& Objects.equal(this.creationDate, other.creationDate)
&& Objects.equal(this.treeHash, other.treeHash)
&& Objects.equal(this.size, other.size);
}

@Override
public String toString() {
return "ArchiveMetadata [archiveId=" + archiveId + ", description=" + description
+ ", creationDate=" + creationDate + ", treeHash=" + treeHash + ", size=" + size + "]";
}

@Override
public int compareTo(ArchiveMetadata o) {
return ComparisonChain.start().compare(this.archiveId, o.archiveId).result();
}
}
@@ -0,0 +1,57 @@
/*
* 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.glacier.domain;

import static com.google.common.base.Preconditions.checkNotNull;

import java.beans.ConstructorProperties;
import java.util.Date;
import java.util.Iterator;

import com.google.common.collect.FluentIterable;
import com.google.gson.annotations.SerializedName;


public class ArchiveMetadataCollection extends FluentIterable<ArchiveMetadata>{

@SerializedName("ArchiveList")
private final Iterable<ArchiveMetadata> archives;
@SerializedName("VaultARN")
private final String vaultARN;
@SerializedName("InventoryDate")
private final Date inventoryDate;

@ConstructorProperties({ "ArchiveList", "VaultARN", "InventoryDate" })
public ArchiveMetadataCollection(Iterable<ArchiveMetadata> archives, String vaultARN, Date inventoryDate) {
this.archives = checkNotNull(archives, "archives");
this.vaultARN = checkNotNull(vaultARN, "vaultARN");
this.inventoryDate = (Date) checkNotNull(inventoryDate, "inventoryDate").clone();
}

@Override
public Iterator<ArchiveMetadata> iterator() {
return archives.iterator();
}

public String getVaultARN() {
return vaultARN;
}

public Date getInventoryDate() {
return (Date) inventoryDate.clone();
}
}
@@ -0,0 +1,36 @@
/*
* 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.glacier.functions;

import org.jclouds.http.HttpException;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payload;

import com.google.common.base.Function;

/**
* Gets the payload from the http response.
*/
public class GetPayloadFromHttpContent implements Function<HttpResponse, Payload> {

@Override
public Payload apply(HttpResponse from) {
if (from.getPayload() == null)
throw new HttpException("Did not receive payload");
return from.getPayload();
}
}
@@ -0,0 +1,32 @@
/*
* 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.glacier.functions;

import org.jclouds.glacier.domain.ArchiveMetadataCollection;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;

import com.google.inject.Inject;
import com.google.inject.TypeLiteral;

public class ParseArchiveMetadataCollectionFromHttpContent extends ParseJson<ArchiveMetadataCollection> {

@Inject
public ParseArchiveMetadataCollectionFromHttpContent(Json json) {
super(json, TypeLiteral.get(ArchiveMetadataCollection.class));
}
}

0 comments on commit 17249cf

Please sign in to comment.