Skip to content

Commit

Permalink
JCLOUDS-457: Add list operation
Browse files Browse the repository at this point in the history
Now the BlobStore abstraction supports the list Operation
  • Loading branch information
Roman Coedo authored and gaul committed Jul 27, 2014
1 parent 8e924e7 commit 491057f
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
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;
Expand All @@ -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");
Expand Down Expand Up @@ -99,7 +107,15 @@ public boolean createContainerInLocation(@Nullable Location location, String con

@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
Expand All @@ -109,7 +125,7 @@ public boolean blobExists(String container, String key) {

@Override
public String putBlob(String container, Blob blob) {
return sync.uploadArchive(container, blob.getPayload(), blob.getMetadata().getName());
return sync.uploadArchive(container, blob.getPayload());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 491057f

Please sign in to comment.