Search in sources :

Example 56 with AzureManager

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

the class ApplicationInsightsPreferencePage method loadInfoFirstTime.

private void loadInfoFirstTime() {
    try {
        if (AuthMethodManager.getInstance().isSignedIn()) {
            AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
            List<Subscription> subList = azureManager.getSelectedSubscriptions();
            if (subList.size() > 0) {
                // if (!ApplicationInsightsPreferences.isLoaded()) {
                // authenticated using AD. Proceed for updating application insights registry.
                ApplicationInsightsResourceRegistryEclipse.updateApplicationInsightsResourceRegistry(subList);
            } else {
                ApplicationInsightsResourceRegistryEclipse.keeepManuallyAddedList();
            }
        // } else {
        // // show list from preferences - getTableContent() does it. So nothing to handle here
        // }
        } else {
            // just show manually added list from preferences
            ApplicationInsightsResourceRegistryEclipse.keeepManuallyAddedList();
        }
    } catch (Exception ex) {
        Activator.getDefault().log(Messages.importErrMsg, ex);
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 57 with AzureManager

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

the class SettingsStep method prepare.

@Override
public JComponent prepare(WizardNavigationState wizardNavigationState) {
    rootPanel.revalidate();
    model.getCurrentNavigationState().NEXT.setEnabled(false);
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        azure = azureManager.getAzure(model.getSubscription().getId());
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().logError("An error occurred when trying to authenticate\n\n" + ex.getMessage(), ex);
    }
    fillResourceGroups();
    retrieveStorageAccounts();
    retrieveVirtualNetworks();
    retrievePublicIpAddresses();
    retrieveNetworkSecurityGroups();
    retrieveAvailabilitySets();
    return rootPanel;
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 58 with AzureManager

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

the class MachineSettingsStep method prepare.

@Override
public JComponent prepare(WizardNavigationState wizardNavigationState) {
    rootPanel.revalidate();
    boolean isLinux;
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        azure = azureManager.getAzure(model.getSubscription().getId());
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().logError("An error occurred when trying to authenticate\n\n" + ex.getMessage(), ex);
    }
    if (model.isKnownMachineImage()) {
        isLinux = model.getKnownMachineImage() instanceof KnownLinuxVirtualMachineImage;
    } else {
        isLinux = model.getVirtualMachineImage().osDiskImage().operatingSystem() == OperatingSystemTypes.LINUX;
    }
    if (isLinux) {
        certificateCheckBox.setEnabled(true);
        passwordCheckBox.setEnabled(true);
        certificateCheckBox.setSelected(false);
        passwordCheckBox.setSelected(true);
    } else {
        certificateCheckBox.setSelected(false);
        passwordCheckBox.setSelected(true);
        certificateCheckBox.setEnabled(false);
        passwordCheckBox.setEnabled(false);
    }
    validateEmptyFields();
    if (model.getRegion() != null && (vmSizeComboBox.getItemCount() == 0 || vmSizeComboBox.getItemAt(0).contains("<Loading...>"))) {
        vmSizeComboBox.setModel(new DefaultComboBoxModel(new String[] { "<Loading...>" }));
        final AzureString title = AzureOperationBundle.title("vm.list_sizes.region", model.getRegion().getName());
        AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
            final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
            progressIndicator.setIndeterminate(true);
            PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = azure.virtualMachines().sizes().listByRegion(model.getRegion().getName());
            sizes.sort((t0, t1) -> {
                if (t0.name().contains("Basic") && t1.name().contains("Basic")) {
                    return t0.name().compareTo(t1.name());
                } else if (t0.name().contains("Basic")) {
                    return -1;
                } else if (t1.name().contains("Basic")) {
                    return 1;
                }
                int coreCompare = Integer.valueOf(t0.numberOfCores()).compareTo(t1.numberOfCores());
                if (coreCompare == 0) {
                    return Integer.valueOf(t0.memoryInMB()).compareTo(t1.memoryInMB());
                } else {
                    return coreCompare;
                }
            });
            AzureTaskManager.getInstance().runAndWait(() -> {
                vmSizeComboBox.setModel(new DefaultComboBoxModel<>(sizes.stream().map(VirtualMachineSize::name).toArray(String[]::new)));
                selectDefaultSize();
            }, AzureTask.Modality.ANY);
        }));
    } else {
        selectDefaultSize();
    }
    return rootPanel;
}
Also used : AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) VMWizardModel(com.microsoft.azure.toolkit.intellij.vm.VMWizardModel) DocumentListener(javax.swing.event.DocumentListener) ActionListener(java.awt.event.ActionListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) WizardNavigationState(com.intellij.ui.wizard.WizardNavigationState) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) ItemListener(java.awt.event.ItemListener) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Azure(com.microsoft.azure.management.Azure) PagedList(com.microsoft.azure.PagedList) OperatingSystemTypes(com.microsoft.azure.management.compute.OperatingSystemTypes) Map(java.util.Map) Project(com.intellij.openapi.project.Project) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) DefaultLoader(com.microsoft.tooling.msservices.components.DefaultLoader) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) URI(java.net.URI) DocumentEvent(javax.swing.event.DocumentEvent) ProgressManager(com.intellij.openapi.progress.ProgressManager) ItemEvent(java.awt.event.ItemEvent) JXHyperlink(org.jdesktop.swingx.JXHyperlink) ActionEvent(java.awt.event.ActionEvent) java.awt(java.awt) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureWizardStep(com.microsoft.intellij.ui.components.AzureWizardStep) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) TelemetryProperties(com.microsoft.azuretools.telemetry.TelemetryProperties) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) WizardStep(com.intellij.ui.wizard.WizardStep) FileChooser(com.intellij.openapi.fileChooser.FileChooser) Consumer(com.intellij.util.Consumer) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) javax.swing(javax.swing) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) PagedList(com.microsoft.azure.PagedList) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask)

Example 59 with AzureManager

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

the class AzureSparkServerlessAccount method getJobManagementURI.

@Nullable
public URI getJobManagementURI() {
    if (getId() == null || subscription.getTenantId() == null) {
        log().warn(String.format("Can't get account ID or tenantID. AccountID:%s, tenantID:%s", getId(), subscription.getTenantId()));
        return null;
    }
    final AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    if (azureManager == null) {
        log().warn("Azure manager is null");
        return null;
    }
    final String url = azureManager.getPortalUrl() + REST_SEGMENT_JOB_MANAGEMENT_TENANTID + subscription.getTenantId() + REST_SEGMENT_JOB_MANAGEMENT_RESOURCE + getId() + REST_SEGMENT_JOB_MANAGEMENT_SUFFIX;
    return URI.create(url);
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable)

Example 60 with AzureManager

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

the class HDIEnvironment method getHDIEnvironment.

public static HDIEnvironment getHDIEnvironment() {
    AzureManager azureManager = null;
    Environment env = Environment.GLOBAL;
    azureManager = AuthMethodManager.getInstance().getAzureManager();
    if (azureManager != null) {
        env = azureManager.getEnvironment();
    }
    if (Environment.GLOBAL.equals(env)) {
        return HDIEnvironment.GLOBAL;
    } else if (Environment.CHINA.equals(env)) {
        return HDIEnvironment.CHINA;
    } else if (Environment.GERMAN.equals(env)) {
        return HDIEnvironment.GERMANY;
    } else if (Environment.US_GOVERNMENT.equals(env)) {
        return HDIEnvironment.US_GOVERNMENT;
    } else {
        return HDIEnvironment.GLOBAL;
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) Environment(com.microsoft.azuretools.authmanage.Environment)

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