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<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.preference.ApplicationInsightsResource 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);
}
use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource in project azure-tools-for-java by Microsoft.
the class AzurePlugin method initializeAIRegistry.
private void initializeAIRegistry() {
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) {
AzurePlugin.log(ex.getMessage(), ex);
}
}
use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource 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);
}
use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsPreferences method savePreferences.
/**
* Stores application insights resources list
* in preference file in the form of byte array.
*/
private void savePreferences() {
try {
Preferences prefs = PluginUtil.getPrefs(PREF_FILE);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput output = new ObjectOutputStream(buffer);
List<ApplicationInsightsResource> data = ApplicationInsightsResourceRegistry.getAppInsightsResrcList();
ApplicationInsightsResource[] dataArray = data.stream().filter(a -> !a.isImported()).sorted().toArray(ApplicationInsightsResource[]::new);
/*
* Sort list according to application insights resource name.
* Save only manually added resources
*/
try {
output.writeObject(dataArray);
} finally {
output.close();
}
prefs.putByteArray(PREF_KEY, buffer.toByteArray());
prefs.flush();
} catch (BackingStoreException e) {
Activator.getDefault().log(e.getMessage(), e);
} catch (IOException e) {
Activator.getDefault().log(e.getMessage(), e);
}
}
Aggregations