Search in sources :

Example 6 with ApplicationInsightsResource

use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource in project azure-tools-for-java by Microsoft.

the class AIResourceChangeListener method initializeAIRegistry.

/**
 * initializeAIRegistry.
 */
public static void initializeAIRegistry(IProject iproject) {
    try {
        if (iproject.isOpen() && WebPropertyTester.isWebProj(iproject)) {
            String aiXMLPath;
            if (iproject.hasNature(Messages.natMaven)) {
                aiXMLPath = Messages.aiXMLPathMaven;
            } else {
                aiXMLPath = Messages.aiXMLPath;
            }
            AILibraryHandler handler = new AILibraryHandler();
            /*
                 * If ApplicationInsights.xml does not exits, then application insights might not have been configured.
                 * It will thrown FNF exception in that case, just catch it and log. Note : file.exists() check is not
                 * useful in this case as during project import generally file.exists() return false.
                 */
            handler.parseAIConfXmlPath(iproject.getFile(aiXMLPath).getLocation().toOSString());
            String key = handler.getAIInstrumentationKey();
            if (key != null && !key.isEmpty()) {
                String unknown = com.microsoft.applicationinsights.preference.Messages.unknown;
                List<ApplicationInsightsResource> list = ApplicationInsightsResourceRegistry.getAppInsightsResrcList();
                ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(key, key, unknown, unknown, unknown, unknown, false);
                if (!list.contains(resourceToAdd)) {
                    ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resourceToAdd);
                }
            }
        }
    } catch (Exception ex) {
        Activator.getDefault().log(Messages.resChangeErr);
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) CoreException(org.eclipse.core.runtime.CoreException) AILibraryHandler(com.microsoft.azuretools.core.applicationinsights.AILibraryHandler)

Example 7 with ApplicationInsightsResource

use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource in project azure-tools-for-java by Microsoft.

the class AppInsightsMngmtPanel method updateApplicationInsightsResourceRegistry.

public static void updateApplicationInsightsResourceRegistry(List<Subscription> subList, Project project) throws Exception {
    // remove all resourecs that were not manually added
    keeepManuallyAddedList(project);
    for (Subscription sub : subList) {
        if (sub.isSelected()) {
            try {
                // fetch resources available for particular subscription
                List<ApplicationInsightsComponent> resourceList = AzureSDKManager.getInsightsResources(sub.getId());
                // Removal logic
                List<ApplicationInsightsResource> importedList = ApplicationInsightsResourceRegistry.prepareAppResListFromRes(resourceList, sub);
                // Addition logic
                ApplicationInsightsResourceRegistry.getAppInsightsResrcList().addAll(importedList);
            } catch (Exception ex) {
                AzurePlugin.log("Error loading AppInsights information for subscription '" + sub.getName() + "'");
            }
        }
    }
    AzureSettings.getSafeInstance(project).saveAppInsights();
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) ApplicationInsightsComponent(com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 8 with ApplicationInsightsResource

use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsNewDialog method doOKAction.

@Override
protected void doOKAction() {
    final boolean grpNotSelected = Objects.isNull(comboGrp.getSelectedItem()) || ((String) comboGrp.getSelectedItem()).isEmpty();
    final boolean regNotSelected = Objects.isNull(comboReg.getSelectedItem()) || ((String) comboReg.getSelectedItem()).isEmpty();
    final boolean subNotSelected = comboSub.getSelectedItem() == null;
    if (txtName.getText().trim().isEmpty() || subNotSelected || (grpNotSelected && useExistingBtn.isSelected()) || (textGrp.getText().isEmpty() && createNewBtn.isSelected()) || regNotSelected) {
        if (subNotSelected || comboSub.getItemCount() <= 0) {
            PluginUtil.displayErrorDialog(message("aiErrTtl"), message("noSubErrMsg"));
        } else if (grpNotSelected || comboGrp.getItemCount() <= 0) {
            PluginUtil.displayErrorDialog(message("aiErrTtl"), message("noResGrpErrMsg"));
        } else {
            PluginUtil.displayErrorDialog(message("aiErrTtl"), message("nameEmptyMsg"));
        }
    } else {
        boolean isNewGroup = createNewBtn.isSelected();
        String resourceGroup = isNewGroup ? textGrp.getText() : (String) comboGrp.getSelectedItem();
        final AzureString title = AzureOperationBundle.title("ai.create.rg", txtName.getText(), resourceGroup);
        AzureTaskManager.getInstance().runInBackground(new AzureTask(null, title, false, () -> {
            try {
                ApplicationInsightsComponent resource = AzureSDKManager.createInsightsResource(currentSub, resourceGroup, isNewGroup, txtName.getText(), (String) comboReg.getSelectedItem());
                resourceToAdd = new ApplicationInsightsResource(resource, currentSub, true);
                if (onCreate != null) {
                    onCreate.run();
                }
            } catch (Exception ex) {
                PluginUtil.displayErrorDialogInAWTAndLog(message("aiErrTtl"), message("resCreateErrMsg"), ex);
            }
        }));
        super.doOKAction();
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) ApplicationInsightsComponent(com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 9 with ApplicationInsightsResource

use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsAddDialog method doOKAction.

@Override
protected void doOKAction() {
    boolean isValid = false;
    String key = txtKey.getText().trim();
    String name = txtName.getText().trim();
    if (key.isEmpty() || name.isEmpty()) {
        PluginUtil.displayErrorDialog(message("aiErrTtl"), message("aiEmptyMsg"));
    } else {
        int index = ApplicationInsightsResourceRegistry.getResourceIndexAsPerKey(key);
        if (index >= 0) {
            // registry already has an entry with same key. Show error
            ApplicationInsightsResource resource = ApplicationInsightsResourceRegistry.getAppInsightsResrcList().get(index);
            // error message can be more descriptive by adding subscription name after resource name.
            // might be useful in the scenarios where same resource name exists in different subscriptions
            PluginUtil.displayErrorDialog(message("aiErrTtl"), String.format(message("sameKeyErrMsg"), resource.getResourceName()));
        } else {
            ArrayList<String> resourceNameList = ApplicationInsightsResourceRegistry.getResourcesNames();
            if (resourceNameList.contains(name)) {
                // registry already has entry with same name. Show error
                PluginUtil.displayErrorDialog(message("aiErrTtl"), message("sameNameErrMsg"));
            } else {
                // check instrumentation key is valid or not and show error if its invalid.
                if (WAEclipseHelperMethods.isValidInstrumentationKey(key)) {
                    ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(name, key, message("unknown"), message("unknown"), message("unknown"), message("unknown"), false);
                    ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resourceToAdd);
                    AzureSettings.getSafeInstance(myProject).saveAppInsights();
                    isValid = true;
                } else {
                    PluginUtil.displayErrorDialog(message("aiErrTtl"), message("aiKeyErrMsg"));
                }
            }
        }
    }
    if (isValid) {
        super.doOKAction();
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource)

Example 10 with ApplicationInsightsResource

use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource in project azure-tools-for-java by Microsoft.

the class AppInsightsMngmtPanel method createNewDilaog.

private void createNewDilaog() {
    try {
        ApplicationManager.getApplication().invokeAndWait(new Runnable() {

            @Override
            public void run() {
                ApplicationInsightsNewDialog dialog = new ApplicationInsightsNewDialog();
                dialog.setOnCreate(() -> DefaultLoader.getIdeHelper().invokeLater(() -> {
                    ApplicationInsightsResource resource = ApplicationInsightsNewDialog.getResource();
                    if (resource != null && !ApplicationInsightsResourceRegistry.getAppInsightsResrcList().contains(resource)) {
                        ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resource);
                        AzureSettings.getSafeInstance(myProject).saveAppInsights();
                        ((InsightsTableModel) insightsTable.getModel()).setResources(getTableContent());
                        ((InsightsTableModel) insightsTable.getModel()).fireTableDataChanged();
                    }
                }));
                dialog.show();
            }
        }, ModalityState.defaultModalityState());
    } catch (Exception ex) {
        AzurePlugin.log(ex.getMessage(), ex);
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource)

Aggregations

ApplicationInsightsResource (com.microsoft.applicationinsights.preference.ApplicationInsightsResource)15 IOException (java.io.IOException)5 ApplicationInsightsComponent (com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent)3 Module (com.intellij.openapi.module.Module)2 Resource (com.microsoft.applicationinsights.management.rest.model.Resource)2 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)2 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)2 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)2 AILibraryHandler (com.microsoft.intellij.ui.libraries.AILibraryHandler)2 ArrayList (java.util.ArrayList)2 Preferences (org.osgi.service.prefs.Preferences)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 RestOperationException (com.microsoft.applicationinsights.management.rest.client.RestOperationException)1 ApplicationInsightsPageTableElement (com.microsoft.applicationinsights.preference.ApplicationInsightsPageTableElement)1 ApplicationInsightsPageTableElements (com.microsoft.applicationinsights.preference.ApplicationInsightsPageTableElements)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)1 AILibraryHandler (com.microsoft.azuretools.core.applicationinsights.AILibraryHandler)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1