Search in sources :

Example 6 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail 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 7 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class AppInsightsMngmtPanel method refreshDataForDialog.

public static void refreshDataForDialog() {
    try {
        Project project = PluginUtil.getSelectedProject();
        if (AuthMethodManager.getInstance().isSignedIn()) {
            List<SubscriptionDetail> subList = AuthMethodManager.getInstance().getAzureManager().getSubscriptionManager().getSubscriptionDetails();
            // authenticated using AD. Proceed for updating application insights registry.
            updateApplicationInsightsResourceRegistry(subList, project);
        } else {
            // Neither clear subscription list nor show sign in dialog as user may just want to add key manually.
            keeepManuallyAddedList(project);
        }
    } catch (Exception ex) {
        AzurePlugin.log(ex.getMessage());
    }
}
Also used : Project(com.intellij.openapi.project.Project) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail)

Example 8 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class AzureModelController method updateResourceGroupMaps.

public static synchronized void updateResourceGroupMaps(IProgressIndicator progressIndicator) throws IOException, CanceledByUserException, AuthException {
    AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    // not signed in
    if (azureManager == null) {
        return;
    }
    updateSubscriptionMaps(progressIndicator);
    AzureModel azureModel = AzureModel.getInstance();
    Map<ResourceGroup, List<WebApp>> rgwaMap = azureModel.createResourceGroupToWebAppMap();
    Map<ResourceGroup, List<AppServicePlan>> rgspMap = azureModel.createResourceGroupToAppServicePlanMap();
    for (SubscriptionDetail sd : azureModel.getSubscriptionToResourceGroupMap().keySet()) {
        if (progressIndicator != null && progressIndicator.isCanceled()) {
            clearAll();
            throw new CanceledByUserException();
        }
        List<ResourceGroup> rgList = azureModel.getSubscriptionToResourceGroupMap().get(sd);
        if (rgList.size() == 0) {
            System.out.println("no resource groups found!");
            continue;
        }
        Azure azure = azureManager.getAzure(sd.getSubscriptionId());
        updateResGrDependency(azure, rgList, progressIndicator, rgwaMap, rgspMap);
    }
    azureModel.setResourceGroupToWebAppMap(rgwaMap);
    azureModel.setResourceGroupToAppServicePlanMap(rgspMap);
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup)

Example 9 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class AzureModule method composeName.

private static String composeName() {
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureManager == null) {
            return BASE_MODULE_NAME + " (Not Signed In)";
        }
        SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
        List<SubscriptionDetail> subscriptionDetails = subscriptionManager.getSubscriptionDetails();
        List<SubscriptionDetail> selectedSubscriptions = subscriptionDetails.stream().filter(SubscriptionDetail::isSelected).collect(Collectors.toList());
        if (selectedSubscriptions.size() > 0) {
            return String.format("%s (%s)", BASE_MODULE_NAME, selectedSubscriptions.size() > 1 ? String.format("%s subscriptions", selectedSubscriptions.size()) : selectedSubscriptions.get(0).getSubscriptionName());
        }
    } catch (Exception e) {
        String msg = "An error occurred while getting the subscription list." + "\n" + "(Message from Azure:" + e.getMessage() + ")";
        DefaultLoader.getUIHelper().showException(msg, e, "MS Services - Error Getting Subscriptions", false, true);
    }
    return BASE_MODULE_NAME;
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 10 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class SDKJarsFilter method setData.

private void setData() {
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureManager == null) {
            return;
        }
        List<SubscriptionDetail> subList = azureManager.getSubscriptionManager().getSubscriptionDetails();
        if (subList.size() > 0 && !ApplicationInsightsPreferences.isLoaded()) {
            //				if (manager.authenticated()) {
            // authenticated using AD. Proceed for updating application insights registry.
            ApplicationInsightsResourceRegistryEclipse.updateApplicationInsightsResourceRegistry(subList);
        //				} else {
        // imported publish settings file. just show manually added list from preferences
        // Neither clear subscription list nor show sign in dialog as user may just want to add key manually.
        //					ApplicationInsightsResourceRegistryEclipse.keeepManuallyAddedList();
        //				}
        }
    } catch (Exception ex) {
        Activator.getDefault().log(ex.getMessage(), ex);
    }
    comboInstrumentationKey.removeAll();
    String[] array = ApplicationInsightsResourceRegistry.getResourcesNamesToDisplay();
    if (array.length > 0) {
        comboInstrumentationKey.setItems(array);
        comboInstrumentationKey.setText(array[0]);
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)52 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)17 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)13 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)13 IOException (java.io.IOException)9 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)7 Location (com.microsoft.azure.management.resources.Location)7 List (java.util.List)7 WebApp (com.microsoft.azure.management.appservice.WebApp)5 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Azure (com.microsoft.azure.management.Azure)4 Subscription (com.microsoft.azure.management.resources.Subscription)4 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)4 HashMap (java.util.HashMap)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridData (org.eclipse.swt.layout.GridData)4 Label (org.eclipse.swt.widgets.Label)4 AccessTokenAzureManager (com.microsoft.azuretools.sdkmanage.AccessTokenAzureManager)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3