/** * This implementation invokes {@link AtmosClient#createDirectory} * * @param container * directory name */ @Override public void createDirectory(String container, String directory) { sync.createDirectory(container + "/" + directory); }
public boolean apply(String in) { try { sync.deletePath(in); return !sync.pathExists(in); } catch (ContainerNotFoundException e) { return true; } } }, 3000).apply(path), "%s still exists after deleting!", path);
@Override public Boolean load(String arg0) throws Exception { return client.isPublic(arg0); } });
@Test(timeOut = 5 * 60 * 1000) public void testCreateDirectory() throws Exception { boolean created = false; while (!created) { privateDirectory = containerPrefix + new SecureRandom().nextInt(); try { created = getApi().createDirectory(privateDirectory) != null; } catch (UndeclaredThrowableException e) { HttpResponseException htpe = (HttpResponseException) e.getCause().getCause(); if (htpe.getResponse().getStatusCode() == 409) continue; throw e; } } BoundedSet<? extends DirectoryEntry> response = getApi().listDirectories(); for (DirectoryEntry id : response) { BoundedSet<? extends DirectoryEntry> r2 = getApi().listDirectory(id.getObjectName()); assert r2 != null; } }
/** * This implementation invokes {@link AtmosClient#headFile} */ @Override public BlobMetadata blobMetadata(String container, String key) { return object2BlobMd.apply(sync.headFile(container + "/" + key)); }
/** * This implementation invokes {@link AtmosClient#listDirectories} */ @Override public PageSet<? extends StorageMetadata> list() { return container2ResourceList.apply(sync.listDirectories()); }
/** * This implementation invokes {@link AtmosClient#readFile} */ @Override public Blob getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) { GetOptions httpOptions = blob2ObjectGetOptions.apply(options); return object2Blob.apply(sync.readFile(container + "/" + key, httpOptions)); }
public static String putBlob(final AtmosClient sync, Crypto crypto, BlobToObject blob2Object, String container, Blob blob, PutOptions options) { final String path = container + "/" + blob.getMetadata().getName(); final AtmosObject object = blob2Object.apply(blob); URI uri; try { uri = sync.createFile(container, object, options); } catch (KeyAlreadyExistsException e) { deletePathAndEnsureGone(sync, path); uri = sync.createFile(container, object, options); } // return object ID as the ETag String objectId = uri.getPath(); String prefix = "/rest/objects/"; checkState(objectId.startsWith(prefix), objectId); return objectId.substring(prefix.length()); }
/** * This implementation invokes {@link AtmosClient#listDirectory} */ @Override public PageSet<? extends StorageMetadata> list(String container, org.jclouds.blobstore.options.ListContainerOptions options) { container = AtmosUtils.adjustContainerIfDirOptionPresent(container, options); ListOptions nativeOptions = container2ContainerListOptions.apply(options); // until includeMeta() option works for namespace interface PageSet<? extends StorageMetadata> list = container2ResourceList.apply(sync.listDirectory(container, nativeOptions)); return options.isDetailed() ? fetchBlobMetadataProvider.get().setContainerName(container).apply(list) : list; }
/** * This implementation invokes {@link AtmosClient#pathExists} */ @Override public boolean containerExists(String container) { return sync.pathExists(container + "/"); }
private void checkSystemMetadataAndPutIfPresentReplaceStrategy(AtmosObject object) throws Exception { long time = System.currentTimeMillis(); boolean update = true; try { getApi().getSystemMetadata(privateDirectory + "/object"); } catch (KeyNotFoundException ex) { update = false; } try { if (update) getApi().updateFile(privateDirectory, object); else getApi().createFile(privateDirectory, object); System.err.printf("%s %s; %dms%n", update ? "updated" : "created", object.getPayload() instanceof InputStreamPayload ? "stream" : "string", System.currentTimeMillis() - time); } catch (Exception e) { String message = Throwables.getRootCause(e).getMessage(); System.err.printf("failure %s %s; %dms: [%s]%n", update ? "updating" : "creating", object.getPayload() instanceof InputStreamPayload ? "stream" : "string", System.currentTimeMillis() - time, message); throw e; } } }
/** * This implementation invokes {@link AtmosClient#deletePath} */ @Override public void removeBlob(String container, String key) { sync.deletePath(container + "/" + key); }
} else if (rest.getApi() instanceof AtmosClient) { RestContext<AtmosClient, AtmosAsyncClient> providerContext = context.unwrap(); providerContext.getApi().getSystemMetadata(containerName + "/test");
@Test(timeOut = 5 * 60 * 1000) public void testCreateDirectory() throws Exception { boolean created = false; while (!created) { privateDirectory = containerPrefix + new SecureRandom().nextInt(); try { created = getApi().createDirectory(privateDirectory) != null; } catch (UndeclaredThrowableException e) { HttpResponseException htpe = (HttpResponseException) e.getCause().getCause(); if (htpe.getResponse().getStatusCode() == 409) continue; throw e; } } BoundedSet<? extends DirectoryEntry> response = getApi().listDirectories(); for (DirectoryEntry id : response) { BoundedSet<? extends DirectoryEntry> r2 = getApi().listDirectory(id.getObjectName()); assert r2 != null; } // subsequent creation should fail assertNull(getApi().createDirectory(privateDirectory)); }
/** * This implementation invokes {@link AtmosClient#headFile} */ @Override public BlobMetadata blobMetadata(String container, String key) { return object2BlobMd.apply(sync.headFile(container + "/" + key)); }
/** * This implementation invokes {@link AtmosClient#listDirectories} */ @Override public PageSet<? extends StorageMetadata> list() { return container2ResourceList.apply(sync.listDirectories()); }
/** * This implementation invokes {@link AtmosClient#readFile} */ @Override public Blob getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) { GetOptions httpOptions = blob2ObjectGetOptions.apply(options); return object2Blob.apply(sync.readFile(container + "/" + key, httpOptions)); }
public static String putBlob(final AtmosClient sync, Crypto crypto, BlobToObject blob2Object, String container, Blob blob, PutOptions options) { final String path = container + "/" + blob.getMetadata().getName(); final AtmosObject object = blob2Object.apply(blob); try { sync.createFile(container, object, options); } catch(KeyAlreadyExistsException e) { deletePathAndEnsureGone(sync, path); sync.createFile(container, object, options); } return path; }
/** * This implementation invokes {@link AtmosClient#listDirectory} */ @Override public PageSet<? extends StorageMetadata> list(String container, org.jclouds.blobstore.options.ListContainerOptions options) { container = AtmosUtils.adjustContainerIfDirOptionPresent(container, options); ListOptions nativeOptions = container2ContainerListOptions.apply(options); // until includeMeta() option works for namespace interface PageSet<? extends StorageMetadata> list = container2ResourceList.apply(sync.listDirectory(container, nativeOptions)); return options.isDetailed() ? fetchBlobMetadataProvider.get().setContainerName(container).apply(list) : list; }
/** * This implementation invokes {@link AtmosClient#pathExists} */ @Override public boolean directoryExists(String container, String directory) { return sync.pathExists(container + "/" + directory + "/"); }