Search in sources :

Example 41 with StorageException

use of com.microsoft.azure.storage.StorageException in project zeppelin by apache.

the class AzureNotebookRepo method list.

@Override
public List<NoteInfo> list(AuthenticationInfo subject) throws IOException {
    List<NoteInfo> infos = new LinkedList<>();
    NoteInfo info = null;
    for (ListFileItem item : rootDir.listFilesAndDirectories()) {
        if (item.getClass() == CloudFileDirectory.class) {
            CloudFileDirectory dir = (CloudFileDirectory) item;
            try {
                if (dir.getFileReference("note.json").exists()) {
                    info = new NoteInfo(getNote(dir.getName()));
                    if (info != null) {
                        infos.add(info);
                    }
                }
            } catch (StorageException | URISyntaxException e) {
                String msg = "Error enumerating notebooks from Azure storage";
                LOG.error(msg, e);
            } catch (Exception e) {
                LOG.error(e.getMessage(), e);
            }
        }
    }
    return infos;
}
Also used : NoteInfo(org.apache.zeppelin.notebook.NoteInfo) ListFileItem(com.microsoft.azure.storage.file.ListFileItem) CloudFileDirectory(com.microsoft.azure.storage.file.CloudFileDirectory) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) LinkedList(java.util.LinkedList) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException)

Example 42 with StorageException

use of com.microsoft.azure.storage.StorageException in project zeppelin by apache.

the class AzureNotebookRepo method save.

@Override
public void save(Note note, AuthenticationInfo subject) throws IOException {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setPrettyPrinting();
    Gson gson = gsonBuilder.create();
    String json = gson.toJson(note);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(output);
    writer.write(json);
    writer.close();
    output.close();
    byte[] buffer = output.toByteArray();
    try {
        CloudFileDirectory dir = rootDir.getDirectoryReference(note.getId());
        dir.createIfNotExists();
        CloudFile cloudFile = dir.getFileReference("note.json");
        cloudFile.uploadFromByteArray(buffer, 0, buffer.length);
    } catch (URISyntaxException | StorageException e) {
        String msg = String.format("Error saving notebook %s to Azure storage", note.getId());
        LOG.error(msg, e);
        throw new IOException(msg, e);
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) CloudFileDirectory(com.microsoft.azure.storage.file.CloudFileDirectory) Gson(com.google.gson.Gson) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CloudFile(com.microsoft.azure.storage.file.CloudFile) OutputStreamWriter(java.io.OutputStreamWriter) StorageException(com.microsoft.azure.storage.StorageException) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 43 with StorageException

use of com.microsoft.azure.storage.StorageException in project azure-sdk-for-java by Azure.

the class ManageWebAppStorageAccountConnection method setUpStorageAccount.

private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) {
    try {
        CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
        // Create a blob service client
        CloudBlobClient blobClient = account.createCloudBlobClient();
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        container.createIfNotExists();
        BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
        // Include public access in the permissions object
        containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
        // Set the permissions on the container
        container.uploadPermissions(containerPermissions);
        return container;
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobContainerPermissions(com.microsoft.azure.storage.blob.BlobContainerPermissions) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 44 with StorageException

use of com.microsoft.azure.storage.StorageException in project azure-sdk-for-java by Azure.

the class ManageLinuxWebAppStorageAccountConnection method setUpStorageAccount.

private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) {
    try {
        CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
        // Create a blob service client
        CloudBlobClient blobClient = account.createCloudBlobClient();
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        container.createIfNotExists();
        BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
        // Include public access in the permissions object
        containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
        // Set the permissions on the container
        container.uploadPermissions(containerPermissions);
        return container;
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobContainerPermissions(com.microsoft.azure.storage.blob.BlobContainerPermissions) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 45 with StorageException

use of com.microsoft.azure.storage.StorageException in project camel by apache.

the class QueueServiceConsumer method poll.

@Override
protected int poll() throws Exception {
    Exchange exchange = super.getEndpoint().createExchange();
    try {
        LOG.trace("Retrieving a message");
        retrieveMessage(exchange);
        super.getAsyncProcessor().process(exchange);
        return 1;
    } catch (StorageException ex) {
        if (404 == ex.getHttpStatusCode()) {
            return 0;
        } else {
            throw ex;
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

StorageException (com.microsoft.azure.storage.StorageException)55 URISyntaxException (java.net.URISyntaxException)34 IOException (java.io.IOException)31 Path (org.apache.hadoop.fs.Path)13 FileNotFoundException (java.io.FileNotFoundException)10 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)10 CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)8 InputStream (java.io.InputStream)7 JsonParseException (com.fasterxml.jackson.core.JsonParseException)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)5 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)5 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)5 EOFException (java.io.EOFException)5 InvalidKeyException (java.security.InvalidKeyException)5 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)5 AccessCondition (com.microsoft.azure.storage.AccessCondition)4 BlobRequestOptions (com.microsoft.azure.storage.blob.BlobRequestOptions)4 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)4 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)4 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)4