use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource in project azure-tools-for-java by Microsoft.
the class AIResourceChangeListener method initializeAIRegistry.
/**
* initializeAIRegistry.
*/
public static void initializeAIRegistry(IProject iproject) {
try {
if (iproject.isOpen() && WebPropertyTester.isWebProj(iproject)) {
String aiXMLPath;
if (iproject.hasNature(Messages.natMaven)) {
aiXMLPath = Messages.aiXMLPathMaven;
} else {
aiXMLPath = Messages.aiXMLPath;
}
AILibraryHandler handler = new AILibraryHandler();
/*
* If ApplicationInsights.xml does not exits, then application insights might not have been configured.
* It will thrown FNF exception in that case, just catch it and log. Note : file.exists() check is not
* useful in this case as during project import generally file.exists() return false.
*/
handler.parseAIConfXmlPath(iproject.getFile(aiXMLPath).getLocation().toOSString());
String key = handler.getAIInstrumentationKey();
if (key != null && !key.isEmpty()) {
String unknown = com.microsoft.applicationinsights.preference.Messages.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);
}
}
}
} catch (Exception ex) {
Activator.getDefault().log(Messages.resChangeErr);
}
}
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<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();
}
use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource 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();
}
}
use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsAddDialog method doOKAction.
@Override
protected void doOKAction() {
boolean isValid = false;
String key = txtKey.getText().trim();
String name = txtName.getText().trim();
if (key.isEmpty() || name.isEmpty()) {
PluginUtil.displayErrorDialog(message("aiErrTtl"), message("aiEmptyMsg"));
} else {
int index = ApplicationInsightsResourceRegistry.getResourceIndexAsPerKey(key);
if (index >= 0) {
// registry already has an entry with same key. Show error
ApplicationInsightsResource resource = ApplicationInsightsResourceRegistry.getAppInsightsResrcList().get(index);
// error message can be more descriptive by adding subscription name after resource name.
// might be useful in the scenarios where same resource name exists in different subscriptions
PluginUtil.displayErrorDialog(message("aiErrTtl"), String.format(message("sameKeyErrMsg"), resource.getResourceName()));
} else {
ArrayList<String> resourceNameList = ApplicationInsightsResourceRegistry.getResourcesNames();
if (resourceNameList.contains(name)) {
// registry already has entry with same name. Show error
PluginUtil.displayErrorDialog(message("aiErrTtl"), message("sameNameErrMsg"));
} else {
// check instrumentation key is valid or not and show error if its invalid.
if (WAEclipseHelperMethods.isValidInstrumentationKey(key)) {
ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(name, key, message("unknown"), message("unknown"), message("unknown"), message("unknown"), false);
ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resourceToAdd);
AzureSettings.getSafeInstance(myProject).saveAppInsights();
isValid = true;
} else {
PluginUtil.displayErrorDialog(message("aiErrTtl"), message("aiKeyErrMsg"));
}
}
}
}
if (isValid) {
super.doOKAction();
}
}
use of com.microsoft.applicationinsights.preference.ApplicationInsightsResource in project azure-tools-for-java by Microsoft.
the class AppInsightsMngmtPanel method createNewDilaog.
private void createNewDilaog() {
try {
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
ApplicationInsightsNewDialog dialog = new ApplicationInsightsNewDialog();
dialog.setOnCreate(() -> DefaultLoader.getIdeHelper().invokeLater(() -> {
ApplicationInsightsResource resource = ApplicationInsightsNewDialog.getResource();
if (resource != null && !ApplicationInsightsResourceRegistry.getAppInsightsResrcList().contains(resource)) {
ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resource);
AzureSettings.getSafeInstance(myProject).saveAppInsights();
((InsightsTableModel) insightsTable.getModel()).setResources(getTableContent());
((InsightsTableModel) insightsTable.getModel()).fireTableDataChanged();
}
}));
dialog.show();
}
}, ModalityState.defaultModalityState());
} catch (Exception ex) {
AzurePlugin.log(ex.getMessage(), ex);
}
}
Aggregations