Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
JCLOUDS-457: Added the retrieve output operations
Now the Glacier client can retrieve data.
- Loading branch information
Showing
9 changed files
with
423 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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)); | ||
} | ||
} |
Oops, something went wrong.