use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getTableEntities.
@NotNull
public List<TableEntity> getTableEntities(@NotNull StorageAccount storageAccount, @NotNull Table table, @NotNull String filter) throws AzureCmdException {
List<TableEntity> teList = new ArrayList<TableEntity>();
try {
CloudTableClient client = getCloudTableClient(storageAccount);
String tableName = table.getName();
CloudTable cloudTable = client.getTableReference(tableName);
TableQuery<DynamicTableEntity> tableQuery = TableQuery.from(DynamicTableEntity.class);
if (!filter.isEmpty()) {
tableQuery.where(filter);
}
TableRequestOptions tro = new TableRequestOptions();
tro.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata);
for (DynamicTableEntity dte : cloudTable.execute(tableQuery, tro, null)) {
teList.add(getTableEntity(tableName, dte));
}
return teList;
} catch (Throwable t) {
throw new AzureCmdException("Error retrieving the Table Entity list", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method createQueue.
@NotNull
public Queue createQueue(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
try {
CloudQueueClient client = getCloudQueueClient(storageAccount);
CloudQueue cloudQueue = client.getQueueReference(queue.getName());
cloudQueue.createIfNotExists();
cloudQueue.downloadAttributes();
String uri = cloudQueue.getUri() != null ? cloudQueue.getUri().toString() : "";
long approximateMessageCount = cloudQueue.getApproximateMessageCount();
queue.setUri(uri);
queue.setApproximateMessageCount(approximateMessageCount);
return queue;
} catch (Throwable t) {
throw new AzureCmdException("Error creating the Queue", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class AddHDInsightAdditionalClusterImpl method getStorageAccount.
public static HDStorageAccount getStorageAccount(String clusterName, String storageName, String storageKey, String userName, String password) throws HDIException, AzureCmdException {
String responseMessage = getMessageByAmbari(clusterName, userName, password);
responseMessage = responseMessage.replace(" ", "");
if (StringHelper.isNullOrWhiteSpace(responseMessage)) {
throw new HDIException("Failed to get storage account");
}
Matcher matcher = PATTERN_DEFAULT_STORAGE.matcher(responseMessage);
String defaultContainer = "";
if (matcher.find()) {
defaultContainer = matcher.group(1);
}
if (StringHelper.isNullOrWhiteSpace(defaultContainer)) {
throw new HDIException("Failed to get default container for storage account");
}
HDStorageAccount account = new HDStorageAccount(null, storageName + BLOB_URL_SUFFIX, storageKey, true, defaultContainer);
//getting container to check the storage key is correct or not
try {
StorageClientSDKManager.getManager().getBlobContainers(account.getConnectionString());
} catch (AzureCmdException e) {
throw new AzureCmdException("Invalid Storage Key");
}
return account;
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class QueueFileEditor method createVirtualNode.
private FileEditorVirtualNode<EditorPart> createVirtualNode(final String name) {
final FileEditorVirtualNode<EditorPart> node = new FileEditorVirtualNode<EditorPart>(this, name);
node.addAction(REFRESH, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
fillGrid();
}
});
node.addAction(DEQUEUE, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
dequeueFirstMessage();
}
});
node.addAction(ADD, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
QueueMessageForm queueMessageForm = new QueueMessageForm(PluginUtil.getParentShell(), storageAccount, queue);
queueMessageForm.setOnAddedMessage(new Runnable() {
@Override
public void run() {
fillGrid();
}
});
queueMessageForm.open();
}
});
node.addAction(CLEAR_QUEUE, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
boolean optionDialog = DefaultLoader.getUIHelper().showConfirmation("Are you sure you want to clear the queue \"" + queue.getName() + "\"?", "Service explorer", new String[] { "Yes", "No" }, null);
if (optionDialog) {
DefaultLoader.getIdeHelper().runInBackground(null, "Clearing queue messages", false, true, "Clearing queue messages", new Runnable() {
public void run() {
/*try {
StorageClientSDKManager.getManager().clearQueue(storageAccount, queue);
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
fillGrid();
}
});
} catch (AzureCmdException e) {
DefaultLoader.getUIHelper().showException("Error clearing queue messages", e, "Service Explorer", false, true);
}*/
}
});
}
}
});
node.addAction(OPEN, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
viewMessageText();
}
});
return node;
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsResourceRegistryEclipse method updateApplicationInsightsResourceRegistry.
/**
* Method updates application insights registry by adding, removing or updating resources.
* @param client
* @throws IOException
* @throws RestOperationException
* @throws AzureCmdException
*/
public static void updateApplicationInsightsResourceRegistry(List<SubscriptionDetail> subList) throws Exception {
for (SubscriptionDetail sub : subList) {
if (sub.isSelected()) {
try {
// fetch resources available for particular subscription
List<Resource> resourceList = AzureSDKManager.getApplicationInsightsResources(sub);
// Removal logic
List<ApplicationInsightsResource> registryList = ApplicationInsightsResourceRegistry.getResourceListAsPerSub(sub.getSubscriptionId());
List<ApplicationInsightsResource> importedList = ApplicationInsightsResourceRegistry.prepareAppResListFromRes(resourceList, sub);
List<String> inUsekeyList = getInUseInstrumentationKeys();
for (ApplicationInsightsResource registryRes : registryList) {
if (!importedList.contains(registryRes)) {
String key = registryRes.getInstrumentationKey();
int index = ApplicationInsightsResourceRegistry.getResourceIndexAsPerKey(key);
if (inUsekeyList.contains(key)) {
// key is used by project but not present in
// cloud,
// so make it as manually added resource and not
// imported.
ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(key, key, Messages.unknown, Messages.unknown, Messages.unknown, Messages.unknown, false);
ApplicationInsightsResourceRegistry.getAppInsightsResrcList().set(index, resourceToAdd);
} else {
// key is not used by any project then delete
// it.
ApplicationInsightsResourceRegistry.getAppInsightsResrcList().remove(index);
}
}
}
// Addition logic
List<ApplicationInsightsResource> list = ApplicationInsightsResourceRegistry.getAppInsightsResrcList();
for (Resource resource : resourceList) {
ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(resource.getName(), resource.getInstrumentationKey(), sub.getSubscriptionName(), sub.getSubscriptionId(), resource.getLocation(), resource.getResourceGroup(), true);
if (list.contains(resourceToAdd)) {
int index = ApplicationInsightsResourceRegistry.getResourceIndexAsPerKey(resource.getInstrumentationKey());
ApplicationInsightsResource objectFromRegistry = list.get(index);
if (!objectFromRegistry.isImported()) {
ApplicationInsightsResourceRegistry.getAppInsightsResrcList().set(index, resourceToAdd);
}
} else {
ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resourceToAdd);
}
}
} catch (Exception e) {
Activator.getDefault().log(String.format(Messages.aiListErr, sub.getSubscriptionName()), e);
}
}
}
ApplicationInsightsPreferences.save();
ApplicationInsightsPreferences.setLoaded(true);
}
Aggregations