Package org.jclouds.openstack.swift

Examples of org.jclouds.openstack.swift.CommonSwiftClient


      provider = System.getProperty("test.swift.provider", "swift");
   }

   @Test(groups = "live")
   public void testSetGetContainerMetadata() throws InterruptedException {
      CommonSwiftClient swift = view.utils().injector().getInstance(CommonSwiftClient.class);

      String containerName = getContainerName();
     
      assertTrue(swift.createContainer(containerName));
     
      ImmutableMap<String, String> metadata = ImmutableMap.<String, String> of(
            "key1", "value1",
            "key2", "value2");

      assertTrue(swift.setContainerMetadata(containerName, metadata));

      ContainerMetadata containerMetadata = swift.getContainerMetadata(containerName);
     
      assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
      assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
   }
View Full Code Here


      assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
   }

   @Test(groups = "live")
   public void testCreateDeleteContainerMetadata() throws InterruptedException {
      CommonSwiftClient swift = view.utils().injector().getInstance(CommonSwiftClient.class);

      String containerName = getContainerName();
      CreateContainerOptions options = CreateContainerOptions.Builder
         .withPublicAccess()
         .withMetadata(ImmutableMap.<String, String> of(
            "key1", "value1",
            "key2", "value2",
            "key3", "value3"));

      assertTrue(swift.createContainer(containerName, options));
     
      ContainerMetadata containerMetadata = swift.getContainerMetadata(containerName);
     
      assertEquals(containerMetadata.getMetadata().size(), 3);
      assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
      assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
      assertEquals(containerMetadata.getMetadata().get("key3"), "value3");

      assertTrue(swift.deleteContainerMetadata(containerName, ImmutableList.<String> of("key2","key3")));

      containerMetadata = swift.getContainerMetadata(containerName);
     
      assertEquals(containerMetadata.getMetadata().size(), 1);
      assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
   }
View Full Code Here

                                .getContentLength());
                        int parts = algorithm.getParts();
                        long chunkSize = algorithm.getChunkSize();
                        long remaining = algorithm.getRemaining();
                        if (parts > 0) {
                            CommonSwiftClient client = ablobstore.getContext().unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getApi();
                            final Map<Integer, ListenableFuture<String>> futureParts =
                                    new ConcurrentHashMap<Integer, ListenableFuture<String>>();
                            final Map<Integer, Exception> errorMap = Maps.newHashMap();
                            AtomicInteger errors = new AtomicInteger(0);
                            int maxRetries = Math.max(minRetries, parts * maxPercentRetries / 100);
                            int effectiveParts = remaining > 0 ? parts + 1 : parts;
                            try {
                                logger.debug(String.format("initiated multipart upload of %s to container %s" +
                                        " consisting from %s part (possible max. retries: %d)",
                                        key, container, effectiveParts, maxRetries));
                                // we need a bounded-blocking queue to control the amount of parallel jobs
                                ArrayBlockingQueue<Integer> activeParts = new ArrayBlockingQueue<Integer>(parallelDegree);
                                Queue<Part> toRetry = new ConcurrentLinkedQueue<Part>();
                                SortedMap<Integer, String> etags = new ConcurrentSkipListMap<Integer, String>();
                                CountDownLatch latch = new CountDownLatch(effectiveParts);
                                int part;
                                while ((part = algorithm.getNextPart()) <= parts) {
                                    Integer partKey = Integer.valueOf(part);
                                    activeParts.put(partKey);

                                    prepareUploadPart(container, blob, key, partKey, payload,
                                            algorithm.getNextChunkOffset(), chunkSize, etags,
                                            activeParts, futureParts, errors, maxRetries, errorMap, toRetry, latch,
                                            blob2Object);
                                }
                                if (remaining > 0) {
                                    Integer partKey = Integer.valueOf(part);
                                    activeParts.put(partKey);
                                    prepareUploadPart(container, blob, key, partKey, payload,
                                            algorithm.getNextChunkOffset(), remaining, etags,
                                            activeParts, futureParts, errors, maxRetries, errorMap, toRetry, latch,
                                            blob2Object);
                                }
                                latch.await();
                                // handling retries
                                while (errors.get() <= maxRetries && toRetry.size() > 0) {
                                    int atOnce = Math.min(Math.min(toRetry.size(), errors.get()), parallelDegree);
                                    CountDownLatch retryLatch = new CountDownLatch(atOnce);
                                    for (int i = 0; i < atOnce; i++) {
                                        Part failedPart = toRetry.poll();
                                        Integer partKey = Integer.valueOf(failedPart.getPart());
                                        activeParts.put(partKey);
                                        prepareUploadPart(container, blob, key, partKey, payload,
                                                failedPart.getOffset(), failedPart.getSize(), etags,
                                                activeParts, futureParts, errors, maxRetries, errorMap, toRetry, retryLatch,
                                                blob2Object);
                                    }
                                    retryLatch.await();
                                }
                                if (errors.get() > maxRetries) {
                                    throw new BlobRuntimeException(String.format(
                                            "Too many failed parts: %s while multipart upload of %s to container %s",
                                            errors.get(), key, container));
                                }

                                String eTag = client.putObjectManifest(container, key);
                                logger.debug(String.format("multipart upload of %s to container %s" +
                                        " successfully finished with %s retries", key, container, errors.get()));
                                return eTag;
                            } catch (Exception ex) {
                                RuntimeException rtex = Throwables2.getFirstThrowableOfType(ex, RuntimeException.class);
View Full Code Here

      provider = System.getProperty("test.swift.provider", "swift");
   }

   @Test(groups = "live")
   public void testSetGetContainerMetadata() throws InterruptedException {
      CommonSwiftClient swift = view.utils().injector().getInstance(CommonSwiftClient.class);

      String containerName = getContainerName();
     
      ImmutableMap<String, String> metadata = ImmutableMap.<String, String> of(
            "key1", "value1",
            "key2", "value2");

      assertTrue(swift.setContainerMetadata(containerName, metadata));

      ContainerMetadata containerMetadata = swift.getContainerMetadata(containerName);
     
      assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
      assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
   }
View Full Code Here

      assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
   }

   @Test(groups = "live")
   public void testCreateDeleteContainerMetadata() throws InterruptedException {
      CommonSwiftClient swift = view.utils().injector().getInstance(CommonSwiftClient.class);

      CreateContainerOptions options = CreateContainerOptions.Builder
         .withPublicAccess()
         .withMetadata(ImmutableMap.<String, String> of(
            "key1", "value1",
            "key2", "value2",
            "key3", "value3"));
     
      String containerName = getScratchContainerName();
      assertTrue(swift.createContainer(containerName, options));

      try {
         ContainerMetadata containerMetadata = swift.getContainerMetadata(containerName);

         assertEquals(containerMetadata.getMetadata().size(), 3);
         assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
         assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
         assertEquals(containerMetadata.getMetadata().get("key3"), "value3");

         assertTrue(swift.deleteContainerMetadata(containerName, ImmutableList.<String> of("key2","key3")));

         containerMetadata = swift.getContainerMetadata(containerName);

         assertEquals(containerMetadata.getMetadata().size(), 1);
         assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
      } finally {
         returnContainer(containerName);
View Full Code Here

                                .getContentLength());
                        int parts = algorithm.getParts();
                        long chunkSize = algorithm.getChunkSize();
                        long remaining = algorithm.getRemaining();
                        if (parts > 0) {
                            CommonSwiftClient client = ablobstore.getContext().unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getApi();
                            final Map<Integer, ListenableFuture<String>> futureParts =
                                    new ConcurrentHashMap<Integer, ListenableFuture<String>>();
                            final Map<Integer, Exception> errorMap = Maps.newHashMap();
                            AtomicInteger errors = new AtomicInteger(0);
                            int maxRetries = Math.max(minRetries, parts * maxPercentRetries / 100);
                            int effectiveParts = remaining > 0 ? parts + 1 : parts;
                            try {
                                logger.debug(String.format("initiated multipart upload of %s to container %s" +
                                        " consisting from %s part (possible max. retries: %d)",
                                        key, container, effectiveParts, maxRetries));
                                // we need a bounded-blocking queue to control the amount of parallel jobs
                                ArrayBlockingQueue<Integer> activeParts = new ArrayBlockingQueue<Integer>(parallelDegree);
                                Queue<Part> toRetry = new ConcurrentLinkedQueue<Part>();
                                SortedMap<Integer, String> etags = new ConcurrentSkipListMap<Integer, String>();
                                CountDownLatch latch = new CountDownLatch(effectiveParts);
                                int part;
                                while ((part = algorithm.getNextPart()) <= parts) {
                                    Integer partKey = Integer.valueOf(part);
                                    activeParts.put(partKey);

                                    prepareUploadPart(container, blob, key, partKey, payload,
                                            algorithm.getNextChunkOffset(), chunkSize, etags,
                                            activeParts, futureParts, errors, maxRetries, errorMap, toRetry, latch,
                                            blob2Object);
                                }
                                if (remaining > 0) {
                                    Integer partKey = Integer.valueOf(part);
                                    activeParts.put(partKey);
                                    prepareUploadPart(container, blob, key, partKey, payload,
                                            algorithm.getNextChunkOffset(), remaining, etags,
                                            activeParts, futureParts, errors, maxRetries, errorMap, toRetry, latch,
                                            blob2Object);
                                }
                                latch.await();
                                // handling retries
                                while (errors.get() <= maxRetries && toRetry.size() > 0) {
                                    int atOnce = Math.min(Math.min(toRetry.size(), errors.get()), parallelDegree);
                                    CountDownLatch retryLatch = new CountDownLatch(atOnce);
                                    for (int i = 0; i < atOnce; i++) {
                                        Part failedPart = toRetry.poll();
                                        Integer partKey = Integer.valueOf(failedPart.getPart());
                                        activeParts.put(partKey);
                                        prepareUploadPart(container, blob, key, partKey, payload,
                                                failedPart.getOffset(), failedPart.getSize(), etags,
                                                activeParts, futureParts, errors, maxRetries, errorMap, toRetry, retryLatch,
                                                blob2Object);
                                    }
                                    retryLatch.await();
                                }
                                if (errors.get() > maxRetries) {
                                    throw new BlobRuntimeException(String.format(
                                            "Too many failed parts: %s while multipart upload of %s to container %s",
                                            errors.get(), key, container));
                                }

                                String eTag = client.putObjectManifest(container, key);
                                logger.debug(String.format("multipart upload of %s to container %s" +
                                        " successfully finished with %s retries", key, container, errors.get()));
                                return eTag;
                            } catch (Exception ex) {
                                RuntimeException rtex = Throwables2.getFirstThrowableOfType(ex, RuntimeException.class);
View Full Code Here

      provider = System.getProperty("test.swift.provider", "swift");
   }

   @Test(groups = "live")
   public void testSetGetContainerMetadata() throws InterruptedException {
      CommonSwiftClient swift = view.utils().injector().getInstance(CommonSwiftClient.class);

      String containerName = getContainerName();
     
      assertTrue(swift.createContainer(containerName));
     
      ImmutableMap<String, String> metadata = ImmutableMap.<String, String> of(
            "key1", "value1",
            "key2", "value2");

      assertTrue(swift.setContainerMetadata(containerName, metadata));

      ContainerMetadata containerMetadata = swift.getContainerMetadata(containerName);
     
      assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
      assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
   }
View Full Code Here

      assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
   }

   @Test(groups = "live")
   public void testCreateDeleteContainerMetadata() throws InterruptedException {
      CommonSwiftClient swift = view.utils().injector().getInstance(CommonSwiftClient.class);

      String containerName = getContainerName();
      CreateContainerOptions options = CreateContainerOptions.Builder
         .withPublicAccess()
         .withMetadata(ImmutableMap.<String, String> of(
            "key1", "value1",
            "key2", "value2",
            "key3", "value3"));

      assertTrue(swift.createContainer(containerName, options));
     
      ContainerMetadata containerMetadata = swift.getContainerMetadata(containerName);
     
      assertEquals(containerMetadata.getMetadata().size(), 3);
      assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
      assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
      assertEquals(containerMetadata.getMetadata().get("key3"), "value3");

      assertTrue(swift.deleteContainerMetadata(containerName, ImmutableList.<String> of("key2","key3")));

      containerMetadata = swift.getContainerMetadata(containerName);
     
      assertEquals(containerMetadata.getMetadata().size(), 1);
      assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
   }
View Full Code Here

      provider = System.getProperty("test.swift.provider", "swift");
   }

   @Test(groups = "live")
   public void testSetGetContainerMetadata() throws InterruptedException {
      CommonSwiftClient swift = view.utils().injector().getInstance(CommonSwiftClient.class);

      String containerName = getContainerName();
     
      ImmutableMap<String, String> metadata = ImmutableMap.<String, String> of(
            "key1", "value1",
            "key2", "value2");

      assertTrue(swift.setContainerMetadata(containerName, metadata));

      ContainerMetadata containerMetadata = swift.getContainerMetadata(containerName);
     
      assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
      assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
   }
View Full Code Here

      assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
   }

   @Test(groups = "live")
   public void testCreateDeleteContainerMetadata() throws InterruptedException {
      CommonSwiftClient swift = view.utils().injector().getInstance(CommonSwiftClient.class);

      CreateContainerOptions options = CreateContainerOptions.Builder
         .withPublicAccess()
         .withMetadata(ImmutableMap.<String, String> of(
            "key1", "value1",
            "key2", "value2",
            "key3", "value3"));
     
      String containerName = getScratchContainerName();
      assertTrue(swift.createContainer(containerName, options));

      try {
         ContainerMetadata containerMetadata = swift.getContainerMetadata(containerName);

         assertEquals(containerMetadata.getMetadata().size(), 3);
         assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
         assertEquals(containerMetadata.getMetadata().get("key2"), "value2");
         assertEquals(containerMetadata.getMetadata().get("key3"), "value3");

         assertTrue(swift.deleteContainerMetadata(containerName, ImmutableList.<String> of("key2", "key3")));

         containerMetadata = swift.getContainerMetadata(containerName);

         assertEquals(containerMetadata.getMetadata().size(), 1);
         assertEquals(containerMetadata.getMetadata().get("key1"), "value1");
      } finally {
         returnContainer(containerName);
View Full Code Here

TOP

Related Classes of org.jclouds.openstack.swift.CommonSwiftClient

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.