Search in sources :

Example 16 with AzureCmdException

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);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 17 with AzureCmdException

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);
    }
}
Also used : CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 18 with AzureCmdException

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;
}
Also used : Matcher(java.util.regex.Matcher) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) HDStorageAccount(com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount)

Example 19 with AzureCmdException

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;
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NodeActionListener(com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener) NodeActionEvent(com.microsoft.tooling.msservices.serviceexplorer.NodeActionEvent) QueueMessageForm(com.microsoft.azuretools.azureexplorer.forms.QueueMessageForm) EditorPart(org.eclipse.ui.part.EditorPart)

Example 20 with AzureCmdException

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);
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) Resource(com.microsoft.applicationinsights.management.rest.model.Resource) ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) IOException(java.io.IOException) RestOperationException(com.microsoft.applicationinsights.management.rest.client.RestOperationException) 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