From 4445cdce8629cfed1340c21db5881eaff127db47 Mon Sep 17 00:00:00 2001 From: Roman Coedo Date: Sun, 13 Jul 2014 22:54:23 +0200 Subject: [PATCH 1/2] JCLOUDS-457: List containers and remove blob List containers and remove blob operations have been added. --- .../glacier/blobstore/GlacierBlobStore.java | 9 +++-- .../config/GlacierBlobStoreContextModule.java | 3 ++ ...natedVaultCollectionToStorageMetadata.java | 34 +++++++++++++++++++ .../VaultMetadataToStorageMetadata.java | 33 ++++++++++++++++++ .../strategy/ClearVaultStrategy.java | 30 ++++++++++++++++ 5 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 glacier/src/main/java/org/jclouds/glacier/blobstore/functions/PaginatedVaultCollectionToStorageMetadata.java create mode 100644 glacier/src/main/java/org/jclouds/glacier/blobstore/functions/VaultMetadataToStorageMetadata.java create mode 100644 glacier/src/main/java/org/jclouds/glacier/blobstore/strategy/ClearVaultStrategy.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 1600d222..15ebdc34 100644 --- a/glacier/src/main/java/org/jclouds/glacier/blobstore/GlacierBlobStore.java +++ b/glacier/src/main/java/org/jclouds/glacier/blobstore/GlacierBlobStore.java @@ -35,6 +35,7 @@ import org.jclouds.crypto.Crypto; import org.jclouds.domain.Location; import org.jclouds.glacier.GlacierClient; +import org.jclouds.glacier.blobstore.functions.PaginatedVaultCollectionToStorageMetadata; import org.jclouds.glacier.blobstore.strategy.MultipartUploadStrategy; import org.jclouds.javax.annotation.Nullable; @@ -46,12 +47,14 @@ public class GlacierBlobStore extends BaseBlobStore { private final GlacierClient sync; private final Crypto crypto; private final Provider multipartUploadStrategy; + private final PaginatedVaultCollectionToStorageMetadata vaultsToContainers; @Inject GlacierBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, @Memoized Supplier> locations, GlacierClient sync, Crypto crypto, - Provider multipartUploadStrategy) { + Provider multipartUploadStrategy, PaginatedVaultCollectionToStorageMetadata vaultsToContainers) { super(context, blobUtils, defaultLocation, locations); + this.vaultsToContainers = checkNotNull(vaultsToContainers, "vaultsToContainers"); this.multipartUploadStrategy = checkNotNull(multipartUploadStrategy, "multipartUploadStrategy"); this.sync = checkNotNull(sync, "sync"); this.crypto = checkNotNull(crypto, "crypto"); @@ -64,7 +67,7 @@ protected boolean deleteAndVerifyContainerGone(String container) { @Override public PageSet list() { - throw new UnsupportedOperationException(); + return vaultsToContainers.apply(sync.listVaults()); } @Override @@ -118,6 +121,6 @@ public Blob getBlob(String container, String key, GetOptions getOptions) { @Override public void removeBlob(String container, String key) { - throw new UnsupportedOperationException(); + sync.deleteArchive(container, key); } } diff --git a/glacier/src/main/java/org/jclouds/glacier/blobstore/config/GlacierBlobStoreContextModule.java b/glacier/src/main/java/org/jclouds/glacier/blobstore/config/GlacierBlobStoreContextModule.java index 302a3414..e330c533 100644 --- a/glacier/src/main/java/org/jclouds/glacier/blobstore/config/GlacierBlobStoreContextModule.java +++ b/glacier/src/main/java/org/jclouds/glacier/blobstore/config/GlacierBlobStoreContextModule.java @@ -19,8 +19,10 @@ import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.attr.ConsistencyModel; +import org.jclouds.blobstore.strategy.ClearListStrategy; import org.jclouds.glacier.blobstore.GlacierAsyncBlobStore; import org.jclouds.glacier.blobstore.GlacierBlobStore; +import org.jclouds.glacier.blobstore.strategy.ClearVaultStrategy; import org.jclouds.glacier.blobstore.strategy.MultipartUploadStrategy; import org.jclouds.glacier.blobstore.strategy.SlicingStrategy; import org.jclouds.glacier.blobstore.strategy.internal.BaseSlicingStrategy; @@ -36,5 +38,6 @@ protected void configure() { bind(AsyncBlobStore.class).to(GlacierAsyncBlobStore.class); bind(MultipartUploadStrategy.class).to(SequentialMultipartUploadStrategy.class); bind(SlicingStrategy.class).to(BaseSlicingStrategy.class); + bind(ClearListStrategy.class).to(ClearVaultStrategy.class); } } diff --git a/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/PaginatedVaultCollectionToStorageMetadata.java b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/PaginatedVaultCollectionToStorageMetadata.java new file mode 100644 index 00000000..e139d0fa --- /dev/null +++ b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/PaginatedVaultCollectionToStorageMetadata.java @@ -0,0 +1,34 @@ +/* + * 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.PaginatedVaultCollection; + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; + +public class PaginatedVaultCollectionToStorageMetadata implements Function> { + @Override + public PageSet apply(PaginatedVaultCollection vaults) { + return new PageSetImpl(Iterables.transform(vaults, new VaultMetadataToStorageMetadata()), + vaults.nextMarker().isPresent() ? (String) vaults.nextMarker().get() : null); + } +} diff --git a/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/VaultMetadataToStorageMetadata.java b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/VaultMetadataToStorageMetadata.java new file mode 100644 index 00000000..54e8ba39 --- /dev/null +++ b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/VaultMetadataToStorageMetadata.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.StorageMetadata; +import org.jclouds.blobstore.domain.StorageType; +import org.jclouds.blobstore.domain.internal.StorageMetadataImpl; +import org.jclouds.glacier.domain.VaultMetadata; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; + +public class VaultMetadataToStorageMetadata implements Function { + @Override + public StorageMetadata apply(VaultMetadata vault) { + return new StorageMetadataImpl(StorageType.CONTAINER, vault.getVaultARN(), vault.getVaultName(), null, null, null, + vault.getCreationDate(), vault.getLastInventoryDate(), ImmutableMap.of()); + } +} diff --git a/glacier/src/main/java/org/jclouds/glacier/blobstore/strategy/ClearVaultStrategy.java b/glacier/src/main/java/org/jclouds/glacier/blobstore/strategy/ClearVaultStrategy.java new file mode 100644 index 00000000..f378ec2f --- /dev/null +++ b/glacier/src/main/java/org/jclouds/glacier/blobstore/strategy/ClearVaultStrategy.java @@ -0,0 +1,30 @@ +/* + * 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.strategy; + +import org.jclouds.blobstore.options.ListContainerOptions; +import org.jclouds.blobstore.strategy.ClearListStrategy; + +import com.google.inject.Singleton; + +@Singleton +public class ClearVaultStrategy implements ClearListStrategy { + @Override + public void execute(String s, ListContainerOptions listContainerOptions) { + return; + } +} From b03a22e9ce345284bb644863f7dba5f9dc5f8781 Mon Sep 17 00:00:00 2001 From: Roman Coedo Date: Thu, 24 Jul 2014 23:40:22 +0200 Subject: [PATCH 2/2] Fix marker --- .../functions/PaginatedVaultCollectionToStorageMetadata.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/PaginatedVaultCollectionToStorageMetadata.java b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/PaginatedVaultCollectionToStorageMetadata.java index e139d0fa..67e4d9c9 100644 --- a/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/PaginatedVaultCollectionToStorageMetadata.java +++ b/glacier/src/main/java/org/jclouds/glacier/blobstore/functions/PaginatedVaultCollectionToStorageMetadata.java @@ -29,6 +29,6 @@ public class PaginatedVaultCollectionToStorageMetadata implements Function apply(PaginatedVaultCollection vaults) { return new PageSetImpl(Iterables.transform(vaults, new VaultMetadataToStorageMetadata()), - vaults.nextMarker().isPresent() ? (String) vaults.nextMarker().get() : null); + (String) vaults.nextMarker().orNull()); } }