Search in sources :

Example 11 with ApplicationInsightsResource

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

the class ApplicationInsightsResourceRegistryEclipse method keeepManuallyAddedList.

public static void keeepManuallyAddedList() {
    List<ApplicationInsightsResource> addedList = ApplicationInsightsResourceRegistry.getAddedResources();
    List<String> addedKeyList = new ArrayList<String>();
    for (ApplicationInsightsResource res : addedList) {
        addedKeyList.add(res.getInstrumentationKey());
    }
    List<String> inUsekeyList = getInUseInstrumentationKeys();
    for (String inUsekey : inUsekeyList) {
        if (!addedKeyList.contains(inUsekey)) {
            ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(inUsekey, inUsekey, Messages.unknown, Messages.unknown, Messages.unknown, Messages.unknown, false);
            addedList.add(resourceToAdd);
        }
    }
    ApplicationInsightsResourceRegistry.setAppInsightsResrcList(addedList);
    ApplicationInsightsPreferences.save();
    ApplicationInsightsPreferences.setLoaded(true);
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) ArrayList(java.util.ArrayList)

Example 12 with ApplicationInsightsResource

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

the class ApplicationInsightsPreferences method loadPreferences.

/**
 * Read and load preference file data.
 * Converts byte array format data to list of application insights resources.
 */
private void loadPreferences() {
    Preferences prefs = PluginUtil.getPrefs(PREF_FILE);
    try {
        byte[] data = prefs.getByteArray(PREF_KEY, null);
        if (data != null) {
            ByteArrayInputStream buffer = new ByteArrayInputStream(data);
            ObjectInput input = new ObjectInputStream(buffer);
            try {
                ApplicationInsightsResource[] resources = (ApplicationInsightsResource[]) input.readObject();
                for (ApplicationInsightsResource resource : resources) {
                    if (!ApplicationInsightsResourceRegistry.getAppInsightsResrcList().contains(resource)) {
                        ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resource);
                    }
                }
            } finally {
                input.close();
            }
        }
    } catch (IOException e) {
        Activator.getDefault().log(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        Activator.getDefault().log(e.getMessage(), e);
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(java.io.ObjectInput) IOException(java.io.IOException) Preferences(org.osgi.service.prefs.Preferences) ObjectInputStream(java.io.ObjectInputStream)

Example 13 with ApplicationInsightsResource

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

the class AppInsightsMngmtPanel method getTableContent.

private List<ApplicationInsightsPageTableElement> getTableContent() {
    AzureSettings.getSafeInstance(myProject).loadAppInsights();
    List<ApplicationInsightsResource> resourceList = ApplicationInsightsResourceRegistry.getAppInsightsResrcList();
    List<ApplicationInsightsPageTableElement> tableRowElements = new ArrayList<ApplicationInsightsPageTableElement>();
    for (ApplicationInsightsResource resource : resourceList) {
        if (resource != null) {
            ApplicationInsightsPageTableElement ele = new ApplicationInsightsPageTableElement();
            ele.setResourceName(resource.getResourceName());
            ele.setInstrumentationKey(resource.getInstrumentationKey());
            tableRowElements.add(ele);
        }
    }
    ApplicationInsightsPageTableElements elements = new ApplicationInsightsPageTableElements();
    elements.setElements(tableRowElements);
    return elements.getElements();
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) ApplicationInsightsPageTableElements(com.microsoft.applicationinsights.preference.ApplicationInsightsPageTableElements) ApplicationInsightsPageTableElement(com.microsoft.applicationinsights.preference.ApplicationInsightsPageTableElement) ArrayList(java.util.ArrayList)

Example 14 with ApplicationInsightsResource

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

the class AzureSettings method loadAppInsights.

public void loadAppInsights() {
    try {
        if (myState.appInsights != null) {
            byte[] data = Base64.decode(myState.appInsights.getBytes());
            ByteArrayInputStream buffer = new ByteArrayInputStream(data);
            ObjectInput input = new ObjectInputStream(buffer);
            try {
                ApplicationInsightsResource[] resources = (ApplicationInsightsResource[]) input.readObject();
                for (ApplicationInsightsResource resource : resources) {
                    if (!ApplicationInsightsResourceRegistry.getAppInsightsResrcList().contains(resource)) {
                        ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resource);
                    }
                }
            } finally {
                input.close();
            }
        }
    } catch (ClassNotFoundException ex) {
    // ignore - this happens because class package changed and settings were not updated
    } catch (Exception e) {
        log(message("err"), e);
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource)

Example 15 with ApplicationInsightsResource

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

the class AzurePlugin method initializeAIRegistry.

private void initializeAIRegistry(Project myProject) {
    try {
        AzureSettings.getSafeInstance(myProject).loadAppInsights();
        Module[] modules = ModuleManager.getInstance(myProject).getModules();
        for (Module module : modules) {
            if (module != null && module.isLoaded() && ModuleTypeId.JAVA_MODULE.equals(module.getOptionValue(Module.ELEMENT_TYPE))) {
                String aiXMLPath = String.format("%s%s%s", PluginUtil.getModulePath(module), File.separator, message("aiXMLPath"));
                if (new File(aiXMLPath).exists()) {
                    AILibraryHandler handler = new AILibraryHandler();
                    handler.parseAIConfXmlPath(aiXMLPath);
                    String key = handler.getAIInstrumentationKey();
                    if (key != null && !key.isEmpty()) {
                        String unknown = message("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);
                        }
                    }
                }
            }
        }
        AzureSettings.getSafeInstance(myProject).saveAppInsights();
    } catch (Exception ex) {
        // should ignore ProcessCanceledException
        if (Objects.isNull(ExceptionUtil.findCause(ex, ProcessCanceledException.class))) {
            AzurePlugin.log(ex.getMessage(), ex);
        }
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) Module(com.intellij.openapi.module.Module) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IOException(java.io.IOException) AILibraryHandler(com.microsoft.intellij.ui.libraries.AILibraryHandler)

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