Package org.jclouds.blobstore.options

Examples of org.jclouds.blobstore.options.ListContainerOptions


         blobstore.putBlob("foo", blobstore.blobBuilder(i + "").payload(i + "").build());
      }
      for (int i = 0; i < 1001; i++) {
         blobstore.putBlob("foo", blobstore.blobBuilder("dir/" + i + "").payload(i + "").build());
      }
      Iterable<? extends StorageMetadata> listing = concatter.execute("foo", new ListContainerOptions());
      // TODO: this looks broke.  seems we should have 1002 (1001 + directory foo), not 1003
      assertEquals(Iterables.size(listing), 1003);
      listing = concatter.execute("foo", ListContainerOptions.Builder.inDirectory("dir"));
      assertEquals(Iterables.size(listing), 1001);
      listing = concatter.execute("foo", ListContainerOptions.Builder.recursive());


      return blobStore.createContainerInLocation(new LocationBuilder().scope(LocationScope.REGION).id(region)
               .description(region).build(), name);
   }

   public ListenableFuture<ListBucketResponse> listBucket(final String name, ListBucketOptions... optionsList) {
      ListContainerOptions options = bucket2ContainerListOptions.apply(optionsList);
      return transform(blobStore.list(name, options), resource2BucketList, userExecutor);
   }

* @author Adrian Cole
*/
@Singleton
public class BucketToContainerListOptions implements Function<ListBucketOptions[], ListContainerOptions> {
   public ListContainerOptions apply(ListBucketOptions[] optionsList) {
      ListContainerOptions options = new ListContainerOptions();
      if (optionsList.length != 0) {
         if (optionsList[0].getDelimiter() == null) {
            options.recursive();
         } else if (!optionsList[0].getDelimiter().equals("/")) {
            throw new IllegalArgumentException("only '/' is allowed as a blobstore delimiter");
         }
         if (optionsList[0].getMarker() != null) {
            options.afterMarker(optionsList[0].getMarker());
         }
         if (optionsList[0].getMaxResults() != null) {
            options.maxResults(optionsList[0].getMaxResults());
         }
         if (optionsList[0].getPrefix() != null) {
            options.inDirectory(optionsList[0].getPrefix());
         }
      }
      return options;
   }

*/
@Singleton
public class ListOptionsToBlobStoreListOptions implements
         Function<org.jclouds.atmos.options.ListOptions[], ListContainerOptions> {
   public ListContainerOptions apply(org.jclouds.atmos.options.ListOptions[] optionsList) {
      ListContainerOptions options = new ListContainerOptions();
      if (optionsList.length != 0) {
         if (optionsList[0].getToken() != null) {
            options.afterMarker(optionsList[0].getToken());
         }
         if (optionsList[0].getLimit() != null) {
            options.maxResults(optionsList[0].getLimit());
         }
         if (optionsList[0].metaIncluded()) {
            options.withDetails();
         }
      }
      return options;
   }

    private void checkForContainerContent(final String containerName, Set<String> expectedBlobKeys) {
        checkForContainerContent(containerName, null, expectedBlobKeys);
    }

    private void checkForContainerContent(final String containerName, String inDirectory, Set<String> expectedBlobKeys) {
        ListContainerOptions options = ListContainerOptions.Builder.recursive();
        if (null != inDirectory && !"".equals(inDirectory))
            options.inDirectory(inDirectory);

        PageSet<? extends StorageMetadata> blobsRetrieved = blobStore.list(containerName, options);
        for (Iterator<? extends StorageMetadata> it = blobsRetrieved.iterator(); it.hasNext();) {
           // TODO: FluentIterable
           if (it.next().getType() != StorageType.BLOB) {

                    setProperty(LocationConstants.PROPERTY_ZONE, zone);
                }})
                .buildView(BlobStoreContext.class);
       
        BlobStore store = ctx.getBlobStore();
        ListContainerOptions options = new ListContainerOptions().maxResults(batchSize).afterMarker(lastMarker);
        PageSet<? extends StorageMetadata> pages = store.list(container, options);
       
        log.debug("Saw {} new files since {}", pages.size() == batchSize ? "many" : Integer.toString(pages.size()), lastMarker);
        boolean emptiness = getBlobsWithinRange(pages).isEmpty();

                }})
                .buildView(BlobStoreContext.class);

        // threadsafe according to https://jclouds.apache.org/documentation/userguide/blobstore-guide/
        BlobStore store = ctx.getBlobStore();
        ListContainerOptions options = new ListContainerOptions().maxResults(batchSize).afterMarker(lastMarker);
        PageSet<? extends StorageMetadata> pages = store.list(container, options);

        //Gets key within the time range specified
        NavigableMap<Long, String> mapWithinRange = getBlobsWithinRange(pages);

   @Override
   protected Object doExecute() throws Exception {
      BlobStore blobStore = getBlobStore();

      ListContainerOptions options = ListContainerOptions.Builder.recursive();
      if (directoryPath != null) {
         options = options.inDirectory(directoryPath);
      }

      while (true) {
         PageSet<? extends StorageMetadata> blobStoreMetadatas = blobStore.list(containerName, options);
         List<String> blobNames = Lists.newArrayList();

         for (StorageMetadata blobMetadata : blobStoreMetadatas) {
            String blobName = blobMetadata.getName();
            // do not add to cacheProvider since long lists will cause OutOfMemoryError
            blobNames.add(blobName);
         }

         Collections.sort(blobNames);
         for (String blobName : blobNames) {
            out.println(blobName);
         }

         String marker = blobStoreMetadatas.getNextMarker();
         if (marker == null) {
            break;
         }

         options = options.afterMarker(marker);
      }
      return null;
   }

        }
        assertThat(builder.build()).containsOnly("prefix");

        builder = ImmutableSet.builder();
        for (StorageMetadata metadata : s3BlobStore.list(containerName,
                new ListContainerOptions().recursive())) {
            builder.add(metadata.getName());
        }
        assertThat(builder.build()).containsOnly("prefix/blob1",
                "prefix/blob2");
    }

    }

    private void handleBlobList(HttpServletRequest request,
            HttpServletResponse response, String containerName)
            throws IOException {
        ListContainerOptions options = new ListContainerOptions();
        String delimiter = request.getParameter("delimiter");
        if (!(delimiter != null && delimiter.equals("/"))) {
            options = options.recursive();
        }
        String prefix = request.getParameter("prefix");
        if (prefix != null) {
            options = options.inDirectory(prefix);
        }
        String marker = request.getParameter("marker");
        if (marker != null) {
            options = options.afterMarker(request.getParameter("marker"));
        }
        int maxKeys = 1000;
        String maxKeysString = request.getParameter("max-keys");
        if (maxKeysString != null) {
            try {
                maxKeys = Integer.parseInt(maxKeysString);
            } catch (NumberFormatException nfe) {
                sendSimpleErrorResponse(response, S3ErrorCode.INVALID_ARGUMENT);
                return;
            }
        }
        options = options.maxResults(maxKeys);

        PageSet<? extends StorageMetadata> set;
        try {
            set = blobStore.list(containerName, options);
        } catch (ContainerNotFoundException cnfe) {

TOP

Related Classes of org.jclouds.blobstore.options.ListContainerOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.