Search in sources :

Example 41 with AzureCmdException

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

the class StorageClientSDKManager method createQueueMessage.

public void createQueueMessage(@NotNull StorageAccount storageAccount, @NotNull QueueMessage queueMessage, int timeToLiveInSeconds) throws AzureCmdException {
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        CloudQueue cloudQueue = client.getQueueReference(queueMessage.getQueueName());
        cloudQueue.addMessage(new CloudQueueMessage(queueMessage.getContent()), timeToLiveInSeconds, 0, null, null);
    } catch (Throwable t) {
        throw new AzureCmdException("Error creating the Queue Message", t);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 42 with AzureCmdException

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

the class StorageClientSDKManager method updateTableEntity.

@NotNull
public TableEntity updateTableEntity(@NotNull StorageAccount storageAccount, @NotNull TableEntity tableEntity) throws AzureCmdException {
    try {
        CloudTableClient client = getCloudTableClient(storageAccount);
        CloudTable cloudTable = client.getTableReference(tableEntity.getTableName());
        DynamicTableEntity entity = getDynamicTableEntity(tableEntity);
        TableRequestOptions tro = new TableRequestOptions();
        tro.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata);
        TableResult result = cloudTable.execute(TableOperation.replace(entity), tro, null);
        DynamicTableEntity resultEntity = result.getResultAsType();
        return getTableEntity(tableEntity.getTableName(), resultEntity);
    } catch (Throwable t) {
        throw new AzureCmdException("Error updating the Table Entity", t);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 43 with AzureCmdException

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

the class StorageClientSDKManager method uploadBlobFileContent.

public void uploadBlobFileContent(@NotNull String connectionString, @NotNull BlobContainer blobContainer, @NotNull String filePath, @NotNull InputStream content, CallableSingleArg<Void, Long> processBlock, long maxBlockSize, long length) throws AzureCmdException {
    try {
        CloudBlobClient client = getCloudBlobClient(connectionString);
        String containerName = blobContainer.getName();
        CloudBlobContainer container = client.getContainerReference(containerName);
        final CloudBlockBlob blob = container.getBlockBlobReference(filePath);
        long uploadedBytes = 0;
        ArrayList<BlockEntry> blockEntries = new ArrayList<BlockEntry>();
        while (uploadedBytes < length) {
            String blockId = Base64.encode(UUID.randomUUID().toString().getBytes());
            BlockEntry entry = new BlockEntry(blockId, BlockSearchMode.UNCOMMITTED);
            long blockSize = maxBlockSize;
            if (length - uploadedBytes <= maxBlockSize) {
                blockSize = length - uploadedBytes;
            }
            if (processBlock != null) {
                processBlock.call(uploadedBytes);
            }
            entry.setSize(blockSize);
            blockEntries.add(entry);
            blob.uploadBlock(entry.getId(), content, blockSize);
            uploadedBytes += blockSize;
        }
        blob.commitBlockList(blockEntries);
    } catch (Throwable t) {
        throw new AzureCmdException("Error uploading the Blob File content", t);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 44 with AzureCmdException

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

the class RestServiceManagerBaseImpl method getSSLConnection.

@NotNull
public HttpsURLConnection getSSLConnection(@NotNull String managementUrl, @NotNull String path, @NotNull ContentType contentType) throws AzureCmdException {
    try {
        URL myUrl = new URL(managementUrl + path);
        HttpsURLConnection conn = (HttpsURLConnection) myUrl.openConnection();
        conn.addRequestProperty(USER_AGENT_HEADER, getPlatformUserAgent());
        conn.addRequestProperty(TELEMETRY_HEADER, getPlatformUserAgent());
        conn.addRequestProperty(X_MS_VERSION_HEADER, AZURE_API_VERSION);
        conn.addRequestProperty(ACCEPT_HEADER, "");
        if (contentType != null) {
            conn.addRequestProperty(CONTENT_TYPE_HEADER, contentType.toString());
        }
        return conn;
    } catch (IOException e) {
        throw new AzureCmdException(e.getMessage(), e);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) URL(java.net.URL) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 45 with AzureCmdException

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

the class StorageClientSDKManager method createBlobFile.

@NotNull
public BlobFile createBlobFile(@NotNull ClientStorageAccount storageAccount, @NotNull BlobDirectory parentBlobDirectory, @NotNull BlobFile blobFile) throws AzureCmdException {
    try {
        CloudBlobClient client = getCloudBlobClient(storageAccount);
        String containerName = parentBlobDirectory.getContainerName();
        CloudBlobContainer container = client.getContainerReference(containerName);
        CloudBlobDirectory parentDirectory = container.getDirectoryReference(parentBlobDirectory.getPath());
        CloudBlob blob = getCloudBlob(parentDirectory, blobFile);
        blob.upload(new ByteArrayInputStream(new byte[0]), 0);
        return reloadBlob(blob, containerName, blobFile);
    } catch (Throwable t) {
        throw new AzureCmdException("Error creating the Blob File", t);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

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