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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations