Search in sources :

Example 1 with ApplicationInsightsComponent

use of com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent 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 java.io.IOException
 * @throws RestOperationException
 * @throws AzureCmdException
 */
public static void updateApplicationInsightsResourceRegistry(List<Subscription> subList) throws Exception {
    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> registryList = ApplicationInsightsResourceRegistry.getResourceListAsPerSub(sub.getId());
                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 (ApplicationInsightsComponent resource : resourceList) {
                    ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(resource, sub, true);
                    if (list.contains(resourceToAdd)) {
                        int index = ApplicationInsightsResourceRegistry.getResourceIndexAsPerKey(resource.instrumentationKey());
                        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.getName()), e);
            }
        }
    }
    ApplicationInsightsPreferences.save();
    ApplicationInsightsPreferences.setLoaded(true);
}
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) IOException(java.io.IOException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 2 with ApplicationInsightsComponent

use of com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent in project azure-tools-for-java by Microsoft.

the class AzureSDKManager method createInsightsResource.

public static ApplicationInsightsComponent createInsightsResource(@NotNull String subscriptionId, @NotNull String resourceGroupName, @NotNull String resourceName, @NotNull String location) throws IOException {
    final InsightsManager insightsManager = getInsightsManagerClient(subscriptionId);
    if (insightsManager == null) {
        // not signed in
        return null;
    }
    final Azure azure = AuthMethodManager.getInstance().getAzureClient(subscriptionId);
    if (!azure.resourceGroups().contain(resourceGroupName)) {
        azure.resourceGroups().define(resourceGroupName).withRegion(location).create();
    }
    return insightsManager.components().define(resourceName).withRegion(location).withExistingResourceGroup(resourceGroupName).withApplicationType(ApplicationType.WEB).withKind("web").create();
}
Also used : Azure(com.microsoft.azure.management.Azure) InsightsManager(com.microsoft.azure.management.applicationinsights.v2015_05_01.implementation.InsightsManager)

Example 3 with ApplicationInsightsComponent

use of com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent in project azure-tools-for-java by Microsoft.

the class AzureSDKManager method getOrCreateApplicationInsights.

// SDK will return existing application insights component when you create new one with existing name
// Use this method in case SDK service update their behavior
public static ApplicationInsightsComponent getOrCreateApplicationInsights(@NotNull String subscriptionId, @NotNull String resourceGroupName, @NotNull String resourceName, @NotNull String location) throws IOException {
    final InsightsManager insightsManager = getInsightsManagerClient(subscriptionId);
    if (insightsManager == null) {
        return null;
    }
    ApplicationInsightsComponent component = null;
    try {
        component = insightsManager.components().getByResourceGroup(resourceGroupName, resourceName);
    } catch (Exception e) {
    // SDK will throw exception when resource not found
    }
    return component != null ? component : createInsightsResource(subscriptionId, resourceGroupName, resourceName, location);
}
Also used : ApplicationInsightsComponent(com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent) InsightsManager(com.microsoft.azure.management.applicationinsights.v2015_05_01.implementation.InsightsManager) JsonParseException(com.google.gson.JsonParseException) IOException(java.io.IOException)

Example 4 with ApplicationInsightsComponent

use of com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent 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 5 with ApplicationInsightsComponent

use of com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent 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)

Aggregations

ApplicationInsightsComponent (com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent)5 ApplicationInsightsResource (com.microsoft.applicationinsights.preference.ApplicationInsightsResource)3 InsightsManager (com.microsoft.azure.management.applicationinsights.v2015_05_01.implementation.InsightsManager)2 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)2 IOException (java.io.IOException)2 JsonParseException (com.google.gson.JsonParseException)1 Azure (com.microsoft.azure.management.Azure)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)1 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)1