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