use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class StorageModule method refreshItems.
@Override
protected void refreshItems() throws AzureCmdException {
List<Pair<String, String>> failedSubscriptions = new ArrayList<>();
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return;
}
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
Set<String> sidList = subscriptionManager.getAccountSidList();
for (String sid : sidList) {
try {
Azure azure = azureManager.getAzure(sid);
List<com.microsoft.azure.management.storage.StorageAccount> storageAccounts = azure.storageAccounts().list();
for (StorageAccount sm : storageAccounts) {
addChildNode(new StorageNode(this, sid, sm));
}
} catch (Exception ex) {
failedSubscriptions.add(new ImmutablePair<>(sid, ex.getMessage()));
continue;
}
}
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("An error occurred when trying to load Storage Accounts\n\n" + ex.getMessage(), ex);
}
// load External Accounts
for (ClientStorageAccount clientStorageAccount : ExternalStorageHelper.getList(getProject())) {
ClientStorageAccount storageAccount = StorageClientSDKManager.getManager().getStorageAccount(clientStorageAccount.getConnectionString());
// addChildNode(new ExternalStorageNode(this, storageAccount));
}
if (!failedSubscriptions.isEmpty()) {
StringBuilder errorMessage = new StringBuilder("An error occurred when trying to load Storage Accounts for the subscriptions:\n\n");
for (Pair error : failedSubscriptions) {
errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n");
}
DefaultLoader.getUIHelper().logError("An error occurred when trying to load Storage Accounts\n\n" + errorMessage.toString(), null);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method dequeueFirstQueueMessage.
@NotNull
public QueueMessage dequeueFirstQueueMessage(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
String queueName = queue.getName();
CloudQueue cloudQueue = client.getQueueReference(queueName);
CloudQueueMessage cqm = cloudQueue.retrieveMessage();
String id = "";
String content = "";
Calendar insertionTime = new GregorianCalendar();
Calendar expirationTime = new GregorianCalendar();
int dequeueCount = 0;
if (cqm != null) {
id = Strings.nullToEmpty(cqm.getId());
content = Strings.nullToEmpty(cqm.getMessageContentAsString());
if (cqm.getInsertionTime() != null) {
insertionTime.setTime(cqm.getInsertionTime());
}
if (cqm.getExpirationTime() != null) {
expirationTime.setTime(cqm.getExpirationTime());
}
dequeueCount = cqm.getDequeueCount();
}
QueueMessage queueMessage = new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount);
if (cqm != null) {
cloudQueue.deleteMessage(cqm);
}
return queueMessage;
} catch (Throwable t) {
throw new AzureCmdException("Error dequeuing the first Queue Message", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method createTable.
@NotNull
public Table createTable(@NotNull StorageAccount storageAccount, @NotNull Table table) throws AzureCmdException {
try {
CloudTableClient client = getCloudTableClient(storageAccount);
CloudTable cloudTable = client.getTableReference(table.getName());
cloudTable.createIfNotExists();
String uri = cloudTable.getUri() != null ? cloudTable.getUri().toString() : "";
table.setUri(uri);
return table;
} catch (Throwable t) {
throw new AzureCmdException("Error creating the Table", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method deleteBlobContainer.
public void deleteBlobContainer(@NotNull StorageAccount storageAccount, @NotNull BlobContainer blobContainer) throws AzureCmdException {
try {
CloudBlobClient client = getCloudBlobClient(storageAccount);
CloudBlobContainer container = client.getContainerReference(blobContainer.getName());
container.deleteIfExists();
} catch (Throwable t) {
throw new AzureCmdException("Error deleting the Blob Container", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method clearQueue.
public void clearQueue(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
CloudQueue cloudQueue = client.getQueueReference(queue.getName());
cloudQueue.clear();
} catch (Throwable t) {
throw new AzureCmdException("Error clearing the Queue", t);
}
}
Aggregations