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;
}
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();
}
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);
}
Aggregations