Search in sources :

Example 1 with Resource

use of com.microsoft.applicationinsights.management.rest.model.Resource in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsResourceRegistry method prepareAppResListFromRes.

/**
	 * Prepare list of ApplicationInsightsResource using list of Resource.
	 * @param resourceList
	 * @param sub
	 * @return
	 */
public static List<ApplicationInsightsResource> prepareAppResListFromRes(List<Resource> resourceList, SubscriptionDetail sub) {
    List<ApplicationInsightsResource> list = new ArrayList<ApplicationInsightsResource>();
    for (Resource resource : resourceList) {
        ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(resource.getName(), resource.getInstrumentationKey(), sub.toString(), sub.getSubscriptionId(), resource.getLocation(), resource.getResourceGroup(), true);
        list.add(resourceToAdd);
    }
    return list;
}
Also used : Resource(com.microsoft.applicationinsights.management.rest.model.Resource)

Example 2 with Resource

use of com.microsoft.applicationinsights.management.rest.model.Resource in project azure-tools-for-java by Microsoft.

the class AppInsightsMngmtPanel method updateApplicationInsightsResourceRegistry.

public static void updateApplicationInsightsResourceRegistry(List<SubscriptionDetail> subList, Project project) throws Exception {
    // remove all resourecs that were not manually added
    keeepManuallyAddedList(project);
    for (SubscriptionDetail sub : subList) {
        if (sub.isSelected()) {
            try {
                // fetch resources available for particular subscription
                List<Resource> resourceList = AzureSDKManager.getApplicationInsightsResources(sub);
                // 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.getSubscriptionName() + "'");
            }
        }
    }
    AzureSettings.getSafeInstance(project).saveAppInsights();
}
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)

Example 3 with Resource

use of com.microsoft.applicationinsights.management.rest.model.Resource 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

Resource (com.microsoft.applicationinsights.management.rest.model.Resource)3 ApplicationInsightsResource (com.microsoft.applicationinsights.preference.ApplicationInsightsResource)2 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)2 RestOperationException (com.microsoft.applicationinsights.management.rest.client.RestOperationException)1 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)1 IOException (java.io.IOException)1