Search in sources :

Example 51 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class BlobExplorerFileEditor method addSubscriptionSelectionListener.

private void addSubscriptionSelectionListener() {
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureManager == null) {
            return;
        }
        azureManager.getSubscriptionManager().addListener(new ISubscriptionSelectionListener() {

            @Override
            public void update(boolean isSignedOut) {
                if (isSignedOut) {
                    Object openedFile = DefaultLoader.getUIHelper().getOpenedFile(project, storageAccount, blobContainer);
                    if (openedFile != null) {
                        DefaultLoader.getIdeHelper().closeFile(project, openedFile);
                    }
                }
            }
        });
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().logError(ex.getMessage(), ex);
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) ISubscriptionSelectionListener(com.microsoft.azuretools.authmanage.ISubscriptionSelectionListener) SocketTimeoutException(java.net.SocketTimeoutException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 52 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class AppInsightsMngmtPanel method loadInfoFirstTime.

private void loadInfoFirstTime() {
    try {
        if (AuthMethodManager.getInstance().isSignedIn()) {
            AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
            List<Subscription> subList = azureManager.getSelectedSubscriptions();
            if (subList.size() > 0) {
                updateApplicationInsightsResourceRegistry(subList, myProject);
            } else {
                // 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.
                keeepManuallyAddedList(myProject);
            }
        } else {
            // just show manually added list from preferences
            keeepManuallyAddedList(myProject);
        }
    } catch (Exception ex) {
        AzurePlugin.log(ex.getMessage(), ex);
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 53 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class SelectSubscriptionsAction method selectSubscriptions.

public static Single<List<SubscriptionDetail>> selectSubscriptions(Project project) {
    final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
    final AzureManager manager = authMethodManager.getAzureManager();
    if (manager == null) {
        return Single.fromCallable(() -> null);
    }
    final SubscriptionManager subscriptionManager = manager.getSubscriptionManager();
    return loadSubscriptions(subscriptionManager, project).switchMap((subs) -> selectSubscriptions(project, subs)).toSingle().doOnSuccess((subs) -> Optional.ofNullable(subs).ifPresent(subscriptionManager::setSubscriptionDetails));
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager)

Example 54 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class CreateArmStorageAccountForm method fillFields.

public void fillFields() {
    if (subscription == null) {
        try {
            subscriptionComboBox.setEnabled(true);
            AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
            // not signed in
            if (azureManager == null) {
                return;
            }
            List<Subscription> subscriptions = azureManager.getSelectedSubscriptions();
            for (Subscription sub : subscriptions) {
                if (sub.isSelected()) {
                    subscriptionComboBox.add(sub.getName());
                    subscriptionComboBox.setData(sub.getName(), sub);
                }
            }
            subscriptionComboBox.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    loadRegionsAndGroups();
                }
            });
            if (subscriptions.size() > 0) {
                subscriptionComboBox.select(0);
                loadRegionsAndGroups();
            }
        } catch (Exception e) {
            PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), Messages.err, "An error occurred while loading subscriptions.", e);
        }
        for (Map.Entry<String, Kind> entry : ACCOUNT_KIND.entrySet()) {
            kindCombo.add(entry.getKey());
            kindCombo.setData(entry.getKey(), entry.getValue());
        }
        kindCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                fillPerformanceComboBox();
                fillReplicationTypes();
                showAccessTier();
            }
        });
        kindCombo.select(1);
        showAccessTier();
    } else {
        // create form create VM form
        subscriptionComboBox.setEnabled(false);
        subscriptionComboBox.add(subscription.getName());
        subscriptionComboBox.setData(subscription.getName(), subscription);
        subscriptionComboBox.select(0);
        // only General purpose accounts supported for VMs
        kindCombo.add("General purpose v1");
        kindCombo.setData("General purpose v1", Kind.STORAGE);
        kindCombo.setEnabled(false);
        kindCombo.select(0);
        regionComboBox.add(region.getLabel());
        regionComboBox.setData(region.getLabel(), region);
        regionComboBox.setEnabled(false);
        regionComboBox.select(0);
        loadGroups();
    // loadRegions();
    }
    fillPerformanceComboBox();
    // performanceCombo.select(0);
    performanceCombo.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            fillReplicationTypes();
        }
    });
    fillReplicationTypes();
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Kind(com.microsoft.azure.toolkit.lib.storage.model.Kind) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 55 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.

the class AIProjConfigWizardDialog method setData.

private void setData() {
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureManager == null || !AuthMethodManager.getInstance().isSignedIn()) {
            return;
        }
        List<Subscription> subList = azureManager.getSelectedSubscriptions();
        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) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)61 Azure (com.microsoft.azure.management.Azure)17 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)16 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)14 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)12 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)9 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)8 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)8 DockerHost (com.microsoft.azure.docker.model.DockerHost)6 IOException (java.io.IOException)5 AuthMethodManager (com.microsoft.azuretools.authmanage.AuthMethodManager)4 ArrayList (java.util.ArrayList)4 AzureDockerImageInstance (com.microsoft.azure.docker.model.AzureDockerImageInstance)3 EditableDockerHost (com.microsoft.azure.docker.model.EditableDockerHost)3 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)3 Network (com.microsoft.azure.management.network.Network)3 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)3 File (java.io.File)3 HashMap (java.util.HashMap)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2