Repository: jclouds-labs-aws
Updated Branches:
  refs/heads/master 8e924e737 -> 491057f6d


JCLOUDS-457: Add list operation

Now the BlobStore abstraction supports the list Operation


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/commit/491057f6
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/tree/491057f6
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/diff/491057f6

Branch: refs/heads/master
Commit: 491057f6d36a43acf7064357ec928484842f3f40
Parents: 8e924e7
Author: Roman Coedo <[email protected]>
Authored: Wed Jul 23 23:55:19 2014 +0200
Committer: Andrew Gaul <[email protected]>
Committed: Sat Jul 26 23:18:47 2014 -0700

----------------------------------------------------------------------
 .../glacier/blobstore/GlacierBlobStore.java     | 22 +++++++++--
 ...hiveMetadataCollectionToStorageMetadata.java | 33 ++++++++++++++++
 .../ArchiveMetadataToBlobMetadata.java          | 41 ++++++++++++++++++++
 ...erOptionsToInventoryRetrievalJobRequest.java | 39 +++++++++++++++++++
 4 files changed, 132 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/blob/491057f6/glacier/src/main/java/org/jclouds/glacier/blobstore/GlacierBlobStore.java
----------------------------------------------------------------------
diff --git 
a/glacier/src/main/java/org/jclouds/glacier/blobstore/GlacierBlobStore.java 
b/glacier/src/main/java/org/jclouds/glacier/blobstore/GlacierBlobStore.java
index f8a4f2a..41535d4 100644
--- a/glacier/src/main/java/org/jclouds/glacier/blobstore/GlacierBlobStore.java
+++ b/glacier/src/main/java/org/jclouds/glacier/blobstore/GlacierBlobStore.java
@@ -39,6 +39,8 @@ import org.jclouds.collect.Memoized;
 import org.jclouds.crypto.Crypto;
 import org.jclouds.domain.Location;
 import org.jclouds.glacier.GlacierClient;
+import 
org.jclouds.glacier.blobstore.functions.ArchiveMetadataCollectionToStorageMetadata;
+import 
org.jclouds.glacier.blobstore.functions.ListContainerOptionsToInventoryRetrievalJobRequest;
 import 
org.jclouds.glacier.blobstore.functions.PaginatedVaultCollectionToStorageMetadata;
 import org.jclouds.glacier.blobstore.strategy.MultipartUploadStrategy;
 import org.jclouds.glacier.blobstore.strategy.PollingStrategy;
@@ -56,14 +58,20 @@ public class GlacierBlobStore extends BaseBlobStore {
    private final Provider<MultipartUploadStrategy> multipartUploadStrategy;
    private final Provider<PollingStrategy> pollingStrategy;
    private final PaginatedVaultCollectionToStorageMetadata vaultsToContainers;
+   private final ArchiveMetadataCollectionToStorageMetadata archivesToBlobs;
+   private final ListContainerOptionsToInventoryRetrievalJobRequest 
containerOptionsToInventoryRetrieval;
 
    @Inject
    GlacierBlobStore(BlobStoreContext context, BlobUtils blobUtils, 
Supplier<Location> defaultLocation,
                     @Memoized Supplier<Set<? extends Location>> locations, 
GlacierClient sync, Crypto crypto,
                     Provider<MultipartUploadStrategy> multipartUploadStrategy,
                     Provider<PollingStrategy> pollingStrategy,
-                    PaginatedVaultCollectionToStorageMetadata 
vaultsToContainers) {
+                    PaginatedVaultCollectionToStorageMetadata 
vaultsToContainers,
+                    ArchiveMetadataCollectionToStorageMetadata 
archivesToBlobs, ListContainerOptionsToInventoryRetrievalJobRequest 
containerOptionsToInventoryRetrieval) {
       super(context, blobUtils, defaultLocation, locations);
+      this.containerOptionsToInventoryRetrieval = 
checkNotNull(containerOptionsToInventoryRetrieval,
+            "containerOptionsToInventoryRetrieval");
+      this.archivesToBlobs = checkNotNull(archivesToBlobs, "archivesToBlobs");
       this.pollingStrategy = checkNotNull(pollingStrategy, "pollingStrategy");
       this.vaultsToContainers = checkNotNull(vaultsToContainers, 
"vaultsToContainers");
       this.multipartUploadStrategy = checkNotNull(multipartUploadStrategy, 
"multipartUploadStrategy");
@@ -99,7 +107,15 @@ public class GlacierBlobStore extends BaseBlobStore {
 
    @Override
    public PageSet<? extends StorageMetadata> list(String container, 
ListContainerOptions listContainerOptions) {
-      throw new UnsupportedOperationException();
+      String jobId = sync.initiateJob(container, 
containerOptionsToInventoryRetrieval.apply(listContainerOptions));
+      try {
+         if (pollingStrategy.get().waitForSuccess(container, jobId)) {
+            return 
archivesToBlobs.apply(sync.getInventoryRetrievalOutput(container, jobId));
+         }
+         return null;
+      } catch (InterruptedException e) {
+         throw new RuntimeException(e);
+      }
    }
 
    @Override
@@ -109,7 +125,7 @@ public class GlacierBlobStore extends BaseBlobStore {
 
    @Override
    public String putBlob(String container, Blob blob) {
-      return sync.uploadArchive(container, blob.getPayload(), 
blob.getMetadata().getName());
+      return sync.uploadArchive(container, blob.getPayload());
    }
 
    @Override

http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/blob/491057f6/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ArchiveMetadataCollectionToStorageMetadata.java
----------------------------------------------------------------------
diff --git 
a/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ArchiveMetadataCollectionToStorageMetadata.java
 
b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ArchiveMetadataCollectionToStorageMetadata.java
new file mode 100644
index 0000000..2df2016
--- /dev/null
+++ 
b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ArchiveMetadataCollectionToStorageMetadata.java
@@ -0,0 +1,33 @@
+/*
+ * 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.blobstore.functions;
+
+import org.jclouds.blobstore.domain.PageSet;
+import org.jclouds.blobstore.domain.StorageMetadata;
+import org.jclouds.blobstore.domain.internal.PageSetImpl;
+import org.jclouds.glacier.domain.ArchiveMetadataCollection;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+
+public class ArchiveMetadataCollectionToStorageMetadata implements 
Function<ArchiveMetadataCollection,
+      PageSet<? extends StorageMetadata>>  {
+   @Override
+   public PageSet<? extends StorageMetadata> apply(ArchiveMetadataCollection 
archives) {
+      return new PageSetImpl<StorageMetadata>(Iterables.transform(archives, 
new ArchiveMetadataToBlobMetadata()), null);
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/blob/491057f6/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ArchiveMetadataToBlobMetadata.java
----------------------------------------------------------------------
diff --git 
a/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ArchiveMetadataToBlobMetadata.java
 
b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ArchiveMetadataToBlobMetadata.java
new file mode 100644
index 0000000..255252a
--- /dev/null
+++ 
b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ArchiveMetadataToBlobMetadata.java
@@ -0,0 +1,41 @@
+/*
+ * 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.blobstore.functions;
+
+import org.jclouds.blobstore.domain.MutableBlobMetadata;
+import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
+import org.jclouds.glacier.domain.ArchiveMetadata;
+import org.jclouds.io.MutableContentMetadata;
+import org.jclouds.io.payloads.BaseMutableContentMetadata;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
+
+public 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.setUserMetadata(ImmutableMap.<String, String>of());
+      to.setContentMetadata(contentMetadata);
+      return to;
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-aws/blob/491057f6/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ListContainerOptionsToInventoryRetrievalJobRequest.java
----------------------------------------------------------------------
diff --git 
a/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ListContainerOptionsToInventoryRetrievalJobRequest.java
 
b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ListContainerOptionsToInventoryRetrievalJobRequest.java
new file mode 100644
index 0000000..4bf5297
--- /dev/null
+++ 
b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/ListContainerOptionsToInventoryRetrievalJobRequest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.blobstore.functions;
+
+import org.jclouds.blobstore.options.ListContainerOptions;
+import org.jclouds.glacier.domain.InventoryRetrievalJobRequest;
+
+import com.google.common.base.Function;
+
+public class ListContainerOptionsToInventoryRetrievalJobRequest implements 
Function<ListContainerOptions,
+      InventoryRetrievalJobRequest>  {
+   @Override
+   public InventoryRetrievalJobRequest apply(ListContainerOptions 
listContainerOptions) {
+      InventoryRetrievalJobRequest.Builder builder = 
InventoryRetrievalJobRequest.builder();
+      if (listContainerOptions != null) {
+         if (listContainerOptions.getMarker() != null) {
+            builder.marker(listContainerOptions.getMarker());
+         }
+         if (listContainerOptions.getMaxResults() != null) {
+            builder.limit(listContainerOptions.getMaxResults());
+         }
+      }
+      return builder.build();
+   }
+}

Reply via email to