Search in sources :

Example 1 with Blob

use of org.jclouds.blobstore.domain.Blob in project artifact-manager-s3-plugin by jenkinsci.

the class JCloudsBlobStoreTest method setup.

@Override
public void setup() throws Exception {
    tmpFile = tmp.newFile();
    FileUtils.writeStringToFile(tmpFile, "test");
    filePath = getPrefix() + tmpFile.getName();
    Blob blob = blobStore.blobBuilder(filePath).payload(tmpFile).build();
    LOGGER.log(Level.INFO, "Adding test blob {0} {1}", new String[] { getContainer(), filePath });
    blobStore.putBlob(getContainer(), blob);
    root = newJCloudsBlobStore(S3_DIR);
    subdir = newJCloudsBlobStore(getPrefix());
    vf = newJCloudsBlobStore(filePath);
    missingFilePath = getPrefix() + "missing";
    missing = newJCloudsBlobStore(missingFilePath);
}
Also used : Blob(org.jclouds.blobstore.domain.Blob)

Example 2 with Blob

use of org.jclouds.blobstore.domain.Blob in project jackrabbit-oak by apache.

the class CloudBlobStore method storeBlock.

/**
 * Uploads the block to the cloud service.
 */
@Override
protected void storeBlock(byte[] digest, int level, byte[] data) throws IOException {
    Preconditions.checkNotNull(context);
    String id = StringUtils.convertBytesToHex(digest);
    cache.put(id, data);
    org.jclouds.blobstore.BlobStore blobStore = context.getBlobStore();
    if (!blobStore.blobExists(cloudContainer, id)) {
        Map<String, String> metadata = Maps.newHashMap();
        metadata.put("level", String.valueOf(level));
        Blob blob = blobStore.blobBuilder(id).payload(data).userMetadata(metadata).build();
        String etag = blobStore.putBlob(cloudContainer, blob, multipart());
        LOG.debug("Blob " + id + " created with cloud tag : " + etag);
    } else {
        LOG.debug("Blob " + id + " already exists");
    }
}
Also used : Blob(org.jclouds.blobstore.domain.Blob)

Example 3 with Blob

use of org.jclouds.blobstore.domain.Blob in project whirr by apache.

the class BlobCache method putIfAbsent.

public synchronized void putIfAbsent(File file) throws FileNotFoundException {
    allocateContainer();
    BlobStore store = context.getBlobStore();
    if (!store.blobExists(container, file.getName())) {
        LOG.info("Uploading '{}' to '{}' blob cache.", file.getName(), container);
        Blob blob = context.getBlobStore().blobBuilder(container).name(file.getName()).payload(file).contentLength(file.length()).build();
        store.putBlob(container, blob, multipart());
    }
}
Also used : Blob(org.jclouds.blobstore.domain.Blob) BlobStore(org.jclouds.blobstore.BlobStore)

Example 4 with Blob

use of org.jclouds.blobstore.domain.Blob in project whirr by apache.

the class BlobClusterStateStore method save.

@Override
public void save(Cluster cluster) throws IOException {
    BlobStore store = context.getBlobStore();
    Blob blob = store.blobBuilder(blobName).payload(serialize(cluster)).build();
    store.putBlob(container, blob);
    LOG.info("Saved cluster state to '{}' ", context.getSigner().signGetBlob(container, blobName).getEndpoint().toString());
}
Also used : Blob(org.jclouds.blobstore.domain.Blob) BlobStore(org.jclouds.blobstore.BlobStore)

Example 5 with Blob

use of org.jclouds.blobstore.domain.Blob in project legacy-jclouds-examples by jclouds.

the class MainApp method main.

public static void main(String[] args) throws IOException {
    if (args.length < PARAMETERS)
        throw new IllegalArgumentException(INVALID_SYNTAX);
    // Args
    String provider = args[0];
    // note that you can check if a provider is present ahead of time
    checkArgument(contains(allKeys, provider), "provider %s not in supported list: %s", provider, allKeys);
    String identity = args[1];
    String credential = args[2];
    String containerName = args[3];
    // Init
    BlobStoreContext context = ContextBuilder.newBuilder(provider).credentials(identity, credential).buildView(BlobStoreContext.class);
    try {
        // Create Container
        BlobStore blobStore = context.getBlobStore();
        blobStore.createContainerInLocation(null, containerName);
        // Add Blob
        Blob blob = blobStore.blobBuilder("test").payload("testdata").build();
        blobStore.putBlob(containerName, blob);
        // List Container
        for (StorageMetadata resourceMd : blobStore.list()) {
            if (resourceMd.getType() == StorageType.CONTAINER || resourceMd.getType() == StorageType.FOLDER) {
                // Use Map API
                Map<String, InputStream> containerMap = context.createInputStreamMap(resourceMd.getName());
                System.out.printf("  %s: %s entries%n", resourceMd.getName(), containerMap.size());
            }
        }
        // Use Provider API
        if (context.getBackendType().getRawType().equals(RestContext.class)) {
            RestContext<?, ?> rest = context.unwrap();
            if (rest.getApi() instanceof S3Client) {
                RestContext<S3Client, S3AsyncClient> providerContext = context.unwrap();
                providerContext.getApi().getBucketLogging(containerName);
            } else if (rest.getApi() instanceof SwiftClient) {
                RestContext<SwiftClient, SwiftAsyncClient> providerContext = context.unwrap();
                providerContext.getApi().getObjectInfo(containerName, "test");
            } else if (rest.getApi() instanceof AzureBlobClient) {
                RestContext<AzureBlobClient, AzureBlobAsyncClient> providerContext = context.unwrap();
                providerContext.getApi().getBlobProperties(containerName, "test");
            } else if (rest.getApi() instanceof AtmosClient) {
                RestContext<AtmosClient, AtmosAsyncClient> providerContext = context.unwrap();
                providerContext.getApi().getSystemMetadata(containerName + "/test");
            }
        }
    } finally {
        // Close connecton
        context.close();
        System.exit(0);
    }
}
Also used : StorageMetadata(org.jclouds.blobstore.domain.StorageMetadata) Blob(org.jclouds.blobstore.domain.Blob) SwiftClient(org.jclouds.openstack.swift.SwiftClient) InputStream(java.io.InputStream) RestContext(org.jclouds.rest.RestContext) AtmosClient(org.jclouds.atmos.AtmosClient) S3AsyncClient(org.jclouds.s3.S3AsyncClient) BlobStoreContext(org.jclouds.blobstore.BlobStoreContext) S3Client(org.jclouds.s3.S3Client) AzureBlobClient(org.jclouds.azureblob.AzureBlobClient) BlobStore(org.jclouds.blobstore.BlobStore) AzureBlobAsyncClient(org.jclouds.azureblob.AzureBlobAsyncClient)

Aggregations

Blob (org.jclouds.blobstore.domain.Blob)20 IOException (java.io.IOException)9 BlobStore (org.jclouds.blobstore.BlobStore)6 BlobStoreContext (org.jclouds.blobstore.BlobStoreContext)4 File (java.io.File)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 Properties (java.util.Properties)3 BlobStoreContextFactory (org.jclouds.blobstore.BlobStoreContextFactory)3 StorageMetadata (org.jclouds.blobstore.domain.StorageMetadata)3 HttpResponseException (org.jclouds.http.HttpResponseException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayList (java.util.ArrayList)2 HttpRequest (org.jclouds.http.HttpRequest)2 AuthorizationException (org.jclouds.rest.AuthorizationException)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 HashCode (com.google.common.hash.HashCode)1 ByteSource (com.google.common.io.ByteSource)1