Search in sources :

Example 46 with AzureCmdException

use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method createBlobContainer.

@NotNull
public BlobContainer createBlobContainer(@NotNull String connectionString, @NotNull BlobContainer blobContainer) throws AzureCmdException {
    try {
        CloudBlobClient client = getCloudBlobClient(connectionString);
        CloudBlobContainer container = client.getContainerReference(blobContainer.getName());
        container.createIfNotExists();
        container.downloadAttributes();
        String uri = container.getUri() != null ? container.getUri().toString() : "";
        String eTag = "";
        Calendar lastModified = new GregorianCalendar();
        BlobContainerProperties properties = container.getProperties();
        if (properties != null) {
            eTag = Strings.nullToEmpty(properties.getEtag());
            if (properties.getLastModified() != null) {
                lastModified.setTime(properties.getLastModified());
            }
        }
        String publicReadAccessType = "";
        BlobContainerPermissions blobContainerPermissions = container.downloadPermissions();
        if (blobContainerPermissions != null && blobContainerPermissions.getPublicAccess() != null) {
            publicReadAccessType = blobContainerPermissions.getPublicAccess().toString();
        }
        blobContainer.setUri(uri);
        blobContainer.setETag(eTag);
        blobContainer.setLastModified(lastModified);
        blobContainer.setPublicReadAccessType(publicReadAccessType);
        return blobContainer;
    } catch (Throwable t) {
        throw new AzureCmdException("Error creating the Blob Container", t);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 47 with AzureCmdException

use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method getQueues.

@NotNull
public List<Queue> getQueues(@NotNull StorageAccount storageAccount) throws AzureCmdException {
    List<Queue> qList = new ArrayList<Queue>();
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        for (CloudQueue cloudQueue : client.listQueues(null, QueueListingDetails.ALL, null, null)) {
            String uri = cloudQueue.getUri() != null ? cloudQueue.getUri().toString() : "";
            qList.add(new Queue(Strings.nullToEmpty(cloudQueue.getName()), uri, cloudQueue.getApproximateMessageCount()));
        }
        return qList;
    } catch (Throwable t) {
        throw new AzureCmdException("Error retrieving the Queue list", t);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) Queue(com.microsoft.tooling.msservices.model.storage.Queue) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 48 with AzureCmdException

use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method createBlobDirectory.

@NotNull
public BlobDirectory createBlobDirectory(@NotNull StorageAccount storageAccount, @NotNull BlobDirectory parentBlobDirectory, @NotNull BlobDirectory blobDirectory) throws AzureCmdException {
    try {
        CloudBlobClient client = getCloudBlobClient(storageAccount);
        String containerName = parentBlobDirectory.getContainerName();
        CloudBlobContainer container = client.getContainerReference(containerName);
        CloudBlobDirectory parentDirectory = container.getDirectoryReference(parentBlobDirectory.getPath());
        CloudBlobDirectory directory = parentDirectory.getDirectoryReference(blobDirectory.getName());
        String uri = directory.getUri() != null ? directory.getUri().toString() : "";
        String path = Strings.nullToEmpty(directory.getPrefix());
        blobDirectory.setUri(uri);
        blobDirectory.setContainerName(containerName);
        blobDirectory.setPath(path);
        return blobDirectory;
    } catch (Throwable t) {
        throw new AzureCmdException("Error creating the Blob Directory", t);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 49 with AzureCmdException

use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method deleteQueue.

public void deleteQueue(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        CloudQueue cloudQueue = client.getQueueReference(queue.getName());
        cloudQueue.deleteIfExists();
    } catch (Throwable t) {
        throw new AzureCmdException("Error deleting the Queue", t);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 50 with AzureCmdException

use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.

the class StorageClientSDKManager method deleteTable.

public void deleteTable(@NotNull StorageAccount storageAccount, @NotNull Table table) throws AzureCmdException {
    try {
        CloudTableClient client = getCloudTableClient(storageAccount);
        CloudTable cloudTable = client.getTableReference(table.getName());
        cloudTable.deleteIfExists();
    } catch (Throwable t) {
        throw new AzureCmdException("Error deleting the Table", t);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Aggregations

AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)55 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)20 BlobFile (com.microsoft.tooling.msservices.model.storage.BlobFile)8 CloudQueue (com.microsoft.azure.storage.queue.CloudQueue)7 CloudQueueClient (com.microsoft.azure.storage.queue.CloudQueueClient)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Task (com.intellij.openapi.progress.Task)5 Azure (com.microsoft.azure.management.Azure)5 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)5 NodeActionEvent (com.microsoft.tooling.msservices.serviceexplorer.NodeActionEvent)5 NodeActionListener (com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener)5 IOException (java.io.IOException)5 BlobDirectory (com.microsoft.tooling.msservices.model.storage.BlobDirectory)4 BlobItem (com.microsoft.tooling.msservices.model.storage.BlobItem)4 ArrayList (java.util.ArrayList)4 CloudQueueMessage (com.microsoft.azure.storage.queue.CloudQueueMessage)3 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)3 BlobContainer (com.microsoft.tooling.msservices.model.storage.BlobContainer)3 FileInputStream (java.io.FileInputStream)3 SocketTimeoutException (java.net.SocketTimeoutException)3