Skip to content
Permalink
Browse files
JCLOUDS-457: Added list Multipart operations
Added listParts and listMultipartUploads operations to the Glacier
client.
  • Loading branch information
rcoedo authored and gaul committed Jun 23, 2014
1 parent 913b8c5 commit 8d55706d216cca6c99299a3600c7cf0e9e6cc7cc
Showing 12 changed files with 543 additions and 1 deletion.
@@ -38,12 +38,16 @@
import org.jclouds.glacier.binders.BindHashesToHeaders;
import org.jclouds.glacier.binders.BindMultipartTreeHashToHeaders;
import org.jclouds.glacier.binders.BindPartSizeToHeaders;
import org.jclouds.glacier.domain.MultipartUploadMetadata;
import org.jclouds.glacier.domain.PaginatedMultipartUploadCollection;
import org.jclouds.glacier.domain.PaginatedVaultCollection;
import org.jclouds.glacier.domain.VaultMetadata;
import org.jclouds.glacier.fallbacks.FalseOnIllegalArgumentException;
import org.jclouds.glacier.filters.RequestAuthorizeSignature;
import org.jclouds.glacier.functions.ParseArchiveIdHeader;
import org.jclouds.glacier.functions.ParseMultipartUploadIdHeader;
import org.jclouds.glacier.functions.ParseMultipartUploadListFromHttpContent;
import org.jclouds.glacier.functions.ParseMultipartUploadPartListFromHttpContent;
import org.jclouds.glacier.functions.ParseMultipartUploadTreeHashHeader;
import org.jclouds.glacier.functions.ParseVaultMetadataFromHttpContent;
import org.jclouds.glacier.functions.ParseVaultMetadataListFromHttpContent;
@@ -214,4 +218,48 @@ ListenableFuture<String> completeMultipartUpload(
ListenableFuture<Boolean> abortMultipartUpload(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName,
@PathParam("uploadId") String uploadId);

/**
* @see GlacierClient#listParts
*/
@Named("ListParts")
@GET
@Path("/-/vaults/{vault}/multipart-uploads/{uploadId}")
@ResponseParser(ParseMultipartUploadPartListFromHttpContent.class)
ListenableFuture<MultipartUploadMetadata> listParts(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName,
@PathParam("uploadId") String uploadId,
PaginationOptions options);

/**
* @see GlacierClient#listParts
*/
@Named("ListParts")
@GET
@Path("/-/vaults/{vault}/multipart-uploads/{uploadId}")
@ResponseParser(ParseMultipartUploadPartListFromHttpContent.class)
ListenableFuture<MultipartUploadMetadata> listParts(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName,
@PathParam("uploadId") String uploadId);

/**
* @see GlacierClient#listMultipartUploads
*/
@Named("ListMultipartUploads")
@GET
@Path("/-/vaults/{vault}/multipart-uploads")
@ResponseParser(ParseMultipartUploadListFromHttpContent.class)
ListenableFuture<PaginatedMultipartUploadCollection> listMultipartUploads(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName,
PaginationOptions options);

/**
* @see GlacierClient#listMultipartUploads
*/
@Named("ListMultipartUploads")
@GET
@Path("/-/vaults/{vault}/multipart-uploads")
@ResponseParser(ParseMultipartUploadListFromHttpContent.class)
ListenableFuture<PaginatedMultipartUploadCollection> listMultipartUploads(
@ParamValidators(VaultNameValidator.class) @PathParam("vault") String vaultName);
}
@@ -20,6 +20,8 @@
import java.net.URI;
import java.util.Map;

import org.jclouds.glacier.domain.MultipartUploadMetadata;
import org.jclouds.glacier.domain.PaginatedMultipartUploadCollection;
import org.jclouds.glacier.domain.PaginatedVaultCollection;
import org.jclouds.glacier.domain.VaultMetadata;
import org.jclouds.glacier.options.PaginationOptions;
@@ -180,4 +182,40 @@ public interface GlacierClient extends Closeable {
* @see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-multipart-abort-upload.html" />
*/
boolean abortMultipartUpload(String vaultName, String uploadId);

/**
* Lists the multipart upload parts.
*
* @param vaultName
* Name of the Vault where the archive is going to be stored.
* @param uploadId
* Multipart upload identifier.
* @param options
* Options used for pagination.
* @return A MultipartUploadMetadata, containing an iterable part list with a marker.
* @see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-multipart-list-parts.html" />
*/
MultipartUploadMetadata listParts(String vaultName, String uploadId, PaginationOptions options);

/**
* Lists the multipart upload parts.
*/
MultipartUploadMetadata listParts(String vaultName, String uploadId);

/**
* Lists the multipart uploads in a vault.
*
* @param vaultName
* Name of the Vault where the archive is going to be stored.
* @param options
* Options used for pagination.
* @return A PaginatedMultipartUploadCollection, containing an iterable multipart upload list with a marker.
* @see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-multipart-list-uploads.html" />
*/
PaginatedMultipartUploadCollection listMultipartUploads(String vaultName, PaginationOptions options);

/**
* Lists the multipart uploads in a vault.
*/
PaginatedMultipartUploadCollection listMultipartUploads(String vaultName);
}
@@ -0,0 +1,141 @@
/*
* 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 org.jclouds.collect.IterableWithMarker;
import org.jclouds.glacier.options.PaginationOptions;
import org.jclouds.javax.annotation.Nullable;

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

/**
* Defines the attributes needed for Multipart uploads. Extends IterableWithMarker to support requesting paginated
* multipart upload parts.
*/
public class MultipartUploadMetadata extends IterableWithMarker<PartMetadata> implements Comparable<MultipartUploadMetadata> {

@SerializedName("ArchiveDescription")
private final String archiveDescription;
@SerializedName("CreationDate")
private final Date creationDate;
@SerializedName("MultipartUploadId")
private final String multipartUploadId;
@SerializedName("PartSizeInBytes")
private final long partSizeInBytes;
@SerializedName("VaultARN")
private final String vaultARN;
@SerializedName("Parts")
private final Iterable<PartMetadata> parts;
@SerializedName("Marker")
private final String marker;

@ConstructorProperties({ "ArchiveDescription", "CreationDate", "MultipartUploadId", "PartSizeInBytes", "VaultARN",
"Parts", "Marker" })
public MultipartUploadMetadata(@Nullable String archiveDescription, Date creationDate, String multipartUploadId,
long partSizeInBytes, String vaultARN, @Nullable Iterable<PartMetadata> parts, @Nullable String marker) {
super();
this.archiveDescription = archiveDescription;
this.creationDate = (Date) checkNotNull(creationDate, "creationDate").clone();
this.multipartUploadId = checkNotNull(multipartUploadId, "multipartUploadId");
this.partSizeInBytes = partSizeInBytes;
this.vaultARN = checkNotNull(vaultARN, "vaultARN");
this.parts = parts;
this.marker = marker;
}

public String getArchiveDescription() {
return archiveDescription;
}

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

public String getMultipartUploadId() {
return multipartUploadId;
}

public long getPartSizeInBytes() {
return partSizeInBytes;
}

public long getPartSizeInMB() {
return partSizeInBytes >> 20;
}

public String getVaultARN() {
return vaultARN;
}

@Override
public Iterator<PartMetadata> iterator() {
return parts == null ? null : parts.iterator();
}

@Override
public Optional<Object> nextMarker() {
return Optional.<Object>fromNullable(marker);
}

public PaginationOptions nextPaginationOptions() {
return PaginationOptions.class.cast(nextMarker().get());
}

@Override
public int hashCode() {
return Objects.hashCode(this.archiveDescription, this.creationDate, this.multipartUploadId, this.partSizeInBytes,
this.vaultARN, this.marker, this.parts);
}

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

return Objects.equal(this.archiveDescription, other.archiveDescription)
&& Objects.equal(this.creationDate, other.creationDate)
&& Objects.equal(this.multipartUploadId, other.multipartUploadId)
&& Objects.equal(this.partSizeInBytes, other.partSizeInBytes)
&& Objects.equal(this.vaultARN, other.vaultARN)
&& Objects.equal(this.marker, other.marker)
&& Objects.equal(this.parts, other.parts);
}

@Override
public String toString() {
return "MultipartUploadMetadata [archiveDescription=" + archiveDescription + ", creationDate=" + creationDate
+ ", multipartUploadId=" + multipartUploadId + ", partSizeInBytes=" + partSizeInBytes + ", vaultARN="
+ vaultARN + ", marker=" + marker + ", parts=" + parts + "]";
}

@Override
public int compareTo(MultipartUploadMetadata o) {
return ComparisonChain.start().compare(this.creationDate, o.creationDate).result();
}
}
@@ -0,0 +1,60 @@
/*
* 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.Iterator;

import org.jclouds.collect.IterableWithMarker;
import org.jclouds.glacier.options.PaginationOptions;
import org.jclouds.javax.annotation.Nullable;

import com.google.common.base.Optional;
import com.google.gson.annotations.SerializedName;

/**
* Paginated collection used to store multipart upload lists.
*/
public class PaginatedMultipartUploadCollection extends IterableWithMarker<MultipartUploadMetadata> {

@SerializedName("UploadsList")
private final Iterable<MultipartUploadMetadata> uploads;
@SerializedName("Marker")
private final String marker;

@ConstructorProperties({ "UploadsList", "Marker" })
public PaginatedMultipartUploadCollection(Iterable<MultipartUploadMetadata> uploads, @Nullable String marker) {
this.uploads = checkNotNull(uploads, "uploads");
this.marker = marker;
}

@Override
public Iterator<MultipartUploadMetadata> iterator() {
return uploads.iterator();
}

@Override
public Optional<Object> nextMarker() {
return Optional.<Object>fromNullable(marker);
}

public PaginationOptions nextPaginationOptions() {
return PaginationOptions.class.cast(nextMarker().get());
}
}
@@ -0,0 +1,53 @@
/*
* 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 org.jclouds.glacier.util.ContentRange;

import com.google.common.hash.HashCode;
import com.google.gson.annotations.SerializedName;

/**
* Defines the attributes needed for a multipart upload part.
*/
public class PartMetadata {

@SerializedName("SHA256TreeHash")
private final HashCode treeHash;
@SerializedName("RangeInBytes")
private final ContentRange range;

@ConstructorProperties({ "SHA256TreeHash", "RangeInBytes" })
public PartMetadata(String treeHash, String range) {
super();
this.treeHash = HashCode.fromString(checkNotNull(treeHash, "treeHash"));
this.range = ContentRange.fromString(checkNotNull(range, "range"));
}

public ContentRange getRange() {
return range;
}

public HashCode getTreeHash() {
return treeHash;
}

}

0 comments on commit 8d55706

Please sign in to comment.