本文整理汇总了Java中org.jclouds.blobstore.BlobStore类的典型用法代码示例。如果您正苦于以下问题:Java BlobStore类的具体用法?Java BlobStore怎么用?Java BlobStore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlobStore类属于org.jclouds.blobstore包,在下文中一共展示了BlobStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerAddress
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
private void registerAddress(String cluster, InetSocketAddress address) throws HekateException {
try (BlobStoreContext ctx = createContext()) {
BlobStore store = ctx.getBlobStore();
String file = cluster + '/' + AddressUtils.toFileName(address);
try {
if (!store.blobExists(container, file)) {
Blob blob = store.blobBuilder(file)
.type(StorageType.BLOB)
.payload(new byte[]{1})
.build();
store.putBlob(container, blob);
if (log.isInfoEnabled()) {
log.info("Registered address to the cloud store [container={}, file={}]", container, file);
}
}
} catch (ResourceNotFoundException | HttpResponseException e) {
throw new HekateException("Failed to register the seed node address to the cloud store "
+ "[container=" + container + ", file=" + file + ']', e);
}
}
}
示例2: unregisterAddress
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
private void unregisterAddress(String cluster, InetSocketAddress address) {
try (BlobStoreContext ctx = createContext()) {
BlobStore store = ctx.getBlobStore();
String file = cluster + '/' + AddressUtils.toFileName(address);
try {
if (store.blobExists(container, file)) {
store.removeBlob(container, file);
if (log.isInfoEnabled()) {
log.info("Unregistered address from the cloud store [container={}, file={}]", container, file);
}
}
} catch (ResourceNotFoundException | HttpResponseException e) {
if (log.isWarnEnabled()) {
log.warn("Failed to unregister the seed node address from the cloud store "
+ "[container={}, file={}, cause={}]", container, file, e.toString());
}
}
}
}
示例3: postSyncToCloud
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
/**
* Looks for {@link CloudPermissionFileAttribute CloudFilePermissionFileAttribute<BlobAccess>}
* from {@link CloudFileChannel#getCloudFileAttributes()} and applies these generically using JClouds.
* More specific behaviours can be achieved by extending/re-implementing this method.
*/
@Override
public void postSyncToCloud(CloudFileChannel cloudFileChannel, boolean writeMetadata) {
// Other options only apply if we are writing metadata
if (writeMetadata) {
FileAttributeLookupMap lookupMap = cloudFileChannel.getCloudFileAttributes();
@SuppressWarnings("unchecked")
CloudPermissionFileAttribute<BlobAccess> aclAttribute =
lookupMap.getFileAttributeOfType(CloudPermissionFileAttribute.class, BlobAccess.class);
if (aclAttribute != null) {
CloudPath path = cloudFileChannel.getPath();
LOG.info("Setting generic JClouds ACL attributes: path={}, access={}",
path, aclAttribute.value().name());
BlobStore blobStore = cloudFileChannel.getContext().getBlobStore();
blobStore.setBlobAccess(path.getContainerName(), path.getPathName(), aclAttribute.value());
} else {
LOG.debug("No ACL attibute set, no file post-sync action");
}
} else {
LOG.debug("No file post-sync action");
}
}
示例4: directoryContentsToString
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
public final String directoryContentsToString(String path) {
BlobStore blobStore = blobStoreContext.getBlobStore();
String marker = null;
ListContainerOptions opts = new ListContainerOptions().recursive();
if (StringUtils.isNotBlank(path)) {
opts.inDirectory(path);
}
StringBuilder ret = new StringBuilder((path == null ? "Container '" : "Directory '" + path)).append("' contains: [ ");
do {
if (marker != null) {
opts.afterMarker(marker);
}
PageSet<? extends StorageMetadata> page = blobStore.list(CONTAINER_NAME, opts);
page.forEach(
m -> ret.append('{').append(m.getName()).append(" (")
.append(m.getType() == StorageType.BLOB ? "FILE" : "DIRECTORY").append(")} "));
marker = page.getNextMarker();
} while (marker != null);
return ret.append(']').toString();
}
示例5: S3ProxyImpl
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
public S3ProxyImpl(String endpoint, S3Config s3Config) {
URI uri = URI.create(endpoint);
Properties properties = new Properties();
properties.setProperty("s3proxy.authorization", "none");
properties.setProperty("s3proxy.endpoint", endpoint);
properties.setProperty("jclouds.provider", "filesystem");
properties.setProperty("jclouds.filesystem.basedir", "/tmp/s3proxy");
ContextBuilder builder = ContextBuilder
.newBuilder("filesystem")
.credentials("x", "x")
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.overrides(properties);
BlobStoreContext context = builder.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();
s3Proxy = S3Proxy.builder().awsAuthentication(AuthenticationType.AWS_V2_OR_V4, "x", "x")
.endpoint(uri)
.keyStore("", "")
.blobStore(blobStore)
.ignoreUnknownHeaders(true)
.build();
client = new S3JerseyCopyPartClient(s3Config);
}
示例6: init
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
@Before
public void init() {
initMocks(this);
uploadS3Stream.retry = 5;
uploadS3Stream.s3Client = fakeS3Client;
fakeS3Client.setMakeItFailUpload(false);
fakeS3Client.setBaseFolder(baseDirectory);
fakeS3Client.setMakeItFailCompleteUpload(false);
Properties properties = new Properties();
properties.setProperty(FilesystemConstants.PROPERTY_BASEDIR, baseDirectory);
BlobStoreContext blobStoreContext = ContextBuilder.newBuilder("filesystem")
.overrides(properties)
.buildView(BlobStoreContext.class);
this.springCloudBlobStoreContext = new SpringCloudBlobStoreContext(blobStoreContext, bucketName);
uploadS3Stream.blobStoreContext = this.springCloudBlobStoreContext;
blobStoreContext.getBlobStore().createContainerInLocation(null, bucketName);
this.uploadS3Stream.setChunkSize(UploadS3StreamImpl.DEFAULT_CHUNK_SIZE);
BlobStore blobStore = springCloudBlobStoreContext.getBlobStore();
blob = blobStore.blobBuilder(fileName).build();
}
示例7: putContainer
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
@PUT
public Response putContainer(@NotNull @PathParam("container") String container,
@HeaderParam("X-Auth-Token") String authToken,
@HeaderParam("X-Container-Read") String readACL,
@HeaderParam("X-Container-write") String writeACL,
@HeaderParam("X-Container-Sync-To") String syncTo,
@HeaderParam("X-Container-Sync-Key") String syncKey,
@HeaderParam("X-Versions-Location") String versionsLocation,
@HeaderParam(HttpHeaders.CONTENT_TYPE) String contentType,
@HeaderParam("X-Detect-Content-Type") boolean detectContentType,
@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNoneMatch) {
Response.Status status;
BlobStore store = getBlobStore(authToken).get(container);
if (store.containerExists(container)) {
status = Response.Status.ACCEPTED;
} else {
createContainer(authToken, container);
status = Response.Status.CREATED;
}
return Response.status(status).build();
}
示例8: deleteContainer
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
@DELETE
public Response deleteContainer(@NotNull @PathParam("container") String container,
@HeaderParam("X-Auth-Token") String authToken) {
BlobStore store = getBlobStore(authToken).get(container);
if (!store.containerExists(container)) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (store.deleteContainerIfEmpty(container)) {
return Response.noContent().build();
} else {
return Response.status(Response.Status.CONFLICT)
.entity("<html><h1>Conflict</h1><p>There was a conflict when trying to complete your request.</p></html>")
.build();
}
}
示例9: getDLOSegments
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
private List<ManifestEntry> getDLOSegments(BlobStore blobStore, String container, String objectsPrefix) {
ListContainerOptions listOptions = new ListContainerOptions()
.recursive()
.prefix(objectsPrefix);
logger.debug("dlo prefix: {}", objectsPrefix);
Iterable<StorageMetadata> res = Utils.crawlBlobStore(blobStore, container, listOptions);
List<ManifestEntry> segments = new ArrayList<>();
for (StorageMetadata sm : res) {
if (sm.getName().startsWith(objectsPrefix)) {
ManifestEntry entry = new ManifestEntry();
entry.container = container;
entry.object = sm.getName();
entry.size_bytes = sm.getSize();
entry.etag = sm.getETag();
segments.add(entry);
} else {
throw new IllegalStateException(
String.format("list object %s from prefix %s", sm.getName(), objectsPrefix));
}
}
segments.forEach(e -> logger.debug("sub-object: {}", e));
return segments;
}
示例10: emulateCopyBlob
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
private String emulateCopyBlob(BlobStore blobStore, Response resp, BlobMetadata meta,
String destContainer, String destObject, CopyOptions options) {
Response.StatusType statusInfo = resp.getStatusInfo();
if (statusInfo.equals(Response.Status.OK)) {
ContentMetadata contentMetadata = meta.getContentMetadata();
Map<String, String> newMetadata = new HashMap<>();
newMetadata.putAll(meta.getUserMetadata());
newMetadata.putAll(options.userMetadata());
RESERVED_METADATA.forEach(s -> newMetadata.remove(s));
Blob blob = blobStore.blobBuilder(destObject)
.userMetadata(newMetadata)
.payload(new InputStreamPayload((InputStream) resp.getEntity()))
.contentLength(resp.getLength())
.contentDisposition(contentMetadata.getContentDisposition())
.contentEncoding(contentMetadata.getContentEncoding())
.contentType(contentMetadata.getContentType())
.contentLanguage(contentMetadata.getContentLanguage())
.build();
return blobStore.putBlob(destContainer, blob);
} else {
throw new ClientErrorException(statusInfo.getReasonPhrase(), statusInfo.getStatusCode());
}
}
示例11: validateManifest
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
private void validateManifest(ManifestEntry[] res, BlobStore blobStore, String authToken) {
Arrays.stream(res).parallel()
.forEach(s -> {
Response r = null;
try {
r = headObject(blobStore, authToken, s.container, s.object, null);
if (!r.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
throw new ClientErrorException(Response.Status.CONFLICT);
}
long size = Long.parseLong(r.getHeaderString(HttpHeaders.CONTENT_LENGTH));
String etag = r.getHeaderString(HttpHeaders.ETAG);
if (s.size_bytes != size || !eTagsEqual(s.etag, etag)) {
logger.error("400 bad request: {}/{} {} {} != {} {}",
s.container, s.object, s.etag, s.size_bytes, etag, size);
throw new ClientErrorException(Response.Status.BAD_REQUEST);
}
} finally {
if (r != null) {
r.close();
}
}
});
}
示例12: getMetadata
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
public static JsonObject getMetadata(BlobStore blobStore, String vault, String name) {
Blob blob;
try {
blob = blobStore.getBlob(vault, Util.getMetadataBlobName(name));
} catch (ContainerNotFoundException cnfe) {
return new JsonObject();
}
if (blob == null) {
return new JsonObject();
}
try (InputStream out = blob.getPayload().openStream()) {
JsonParser parser = new JsonParser();
return parser.parse(new InputStreamReader(out)).getAsJsonObject();
} catch (IOException io) {
return new JsonObject();
}
}
示例13: moveFile
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
/**
* Move a file from one AWS S3 folder to another.
*
* @param blobStore the blob store
* @param sourceKey the file source location
* @param destinationFolder the destination folder
* @return the destination key of the moved file
* @throws KeyNotFoundException if a key is not found
*/
@GuardedBy("ThreadLocal blobStore")
private String moveFile(final BlobStore blobStore, final String sourceKey,
final String destinationFolder) throws KeyNotFoundException {
final Blob blob = blobStore.getBlob(config.getS3().getBucket(), sourceKey);
if (blob != null) {
final String destinationKey = destinationFolder + "/"
+ sourceKey.substring(sourceKey.lastIndexOf('/') + 1);
blob.getMetadata().setName(destinationKey);
blobStore.putBlob(config.getS3().getBucket(), blob);
blobStore.removeBlob(config.getS3().getBucket(), sourceKey);
return destinationKey;
} else {
throw new KeyNotFoundException(sourceKey, config.getS3().getBucket(), "Error while moving file.");
}
}
示例14: handleContainerLocation
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
private void handleContainerLocation(HttpServletResponse response,
BlobStore blobStore, String containerName) throws IOException {
try (Writer writer = response.getWriter()) {
response.setContentType(XML_CONTENT_TYPE);
XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(
writer);
xml.writeStartDocument();
// TODO: using us-standard semantics but could emit actual location
xml.writeStartElement("LocationConstraint");
xml.writeDefaultNamespace(AWS_XMLNS);
xml.writeEndElement();
xml.flush();
} catch (XMLStreamException xse) {
throw new IOException(xse);
}
}
示例15: handleContainerDelete
import org.jclouds.blobstore.BlobStore; //导入依赖的package包/类
private static void handleContainerDelete(HttpServletResponse response,
BlobStore blobStore, String containerName)
throws IOException, S3Exception {
if (!blobStore.containerExists(containerName)) {
throw new S3Exception(S3ErrorCode.NO_SUCH_BUCKET);
}
String blobStoreType = getBlobStoreType(blobStore);
if (blobStoreType.equals("b2")) {
// S3 allows deleting a container with in-progress MPU while B2 does
// not. Explicitly cancel uploads for B2.
for (MultipartUpload mpu : blobStore.listMultipartUploads(
containerName)) {
blobStore.abortMultipartUpload(mpu);
}
}
if (!blobStore.deleteContainerIfEmpty(containerName)) {
throw new S3Exception(S3ErrorCode.BUCKET_NOT_EMPTY);
}
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}