Search in sources :

Example 6 with AzureManager

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

the class SubscriptionStep method loadSubscriptions.

private void loadSubscriptions() {
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureManager == null) {
            return;
        }
        /*
			 * if (manager.authenticated()) { String upn =
			 * manager.getUserInfo().getUniqueName();
			 * userInfoLabel.setText("Signed in as: " + (upn.contains("#") ?
			 * upn.split("#")[1] : upn)); } else { userInfoLabel.setText(""); }
			 */
        SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
        List<SubscriptionDetail> subscriptionDetails = subscriptionManager.getSubscriptionDetails();
        for (SubscriptionDetail subscription : subscriptionDetails) {
            if (subscription.isSelected()) {
                subscriptionComboBox.add(subscription.getSubscriptionName());
                subscriptionComboBox.setData(subscription.getSubscriptionName(), subscription);
            }
        }
        if (!subscriptionDetails.isEmpty()) {
            subscriptionComboBox.select(0);
            wizard.setSubscription((SubscriptionDetail) subscriptionComboBox.getData(subscriptionComboBox.getText()));
        }
        setPageComplete(!subscriptionDetails.isEmpty());
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().logError("An error occurred when trying to load Subscriptions\n\n" + ex.getMessage(), ex);
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager)

Example 7 with AzureManager

use of com.microsoft.azuretools.sdkmanage.AzureManager 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)

Example 8 with AzureManager

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

the class CreateArmStorageAccountForm method createStorageAccount.

private boolean createStorageAccount() {
    try {
        boolean isNewResourceGroup = createNewRadioButton.isSelected();
        final String resourceGroupName = isNewResourceGroup ? resourceGrpField.getText() : resourceGrpCombo.getSelectedItem().toString();
        AzureSDKManager.createStorageAccount(((SubscriptionDetail) subscriptionComboBox.getSelectedItem()).getSubscriptionId(), nameTextField.getText(), ((Location) regionComboBox.getSelectedItem()).name(), isNewResourceGroup, resourceGroupName, (Kind) accoountKindCombo.getSelectedItem(), (AccessTier) accessTeirComboBox.getSelectedItem(), (Boolean) encriptonComboBox.getSelectedItem(), replicationComboBox.getSelectedItem().toString());
        // update resource groups cache if new resource group was created when creating storage account
        if (createNewRadioButton.isSelected()) {
            AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
            // not signed in; does not matter what we return as storage account already created
            if (azureManager == null) {
                return true;
            }
            SubscriptionDetail subscriptionDetail = (SubscriptionDetail) subscriptionComboBox.getSelectedItem();
            ResourceGroup rg = azureManager.getAzure(subscriptionDetail.getSubscriptionId()).resourceGroups().getByName(resourceGroupName);
            AzureModelController.addNewResourceGroup(subscriptionDetail, rg);
        }
        DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

            @Override
            public void run() {
                if (onCreate != null) {
                    onCreate.run();
                }
            }
        });
        return true;
    } catch (Exception e) {
        String msg = "An error occurred while attempting to create the specified storage account in subscription " + ((SubscriptionDetail) subscriptionComboBox.getSelectedItem()).getSubscriptionId() + ".\n" + String.format(message("webappExpMsg"), e.getMessage());
        DefaultLoader.getIdeHelper().invokeAndWait(() -> DefaultLoader.getUIHelper().showException(msg, e, message("errTtl"), false, true));
        AzurePlugin.log(msg, e);
    }
    return false;
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup)

Example 9 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(final SubscriptionDetail subscription, Location region) {
    if (subscription == null) {
        //            loadRegions();
        accoountKindCombo.setModel(new DefaultComboBoxModel(Kind.values()));
        accoountKindCombo.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    fillPerformanceComboBox();
                    fillReplicationTypes();
                    boolean isBlobKind = e.getItem().equals(Kind.BLOB_STORAGE);
                    accessTeirComboBox.setVisible(isBlobKind);
                    accessTierLabel.setVisible(isBlobKind);
                }
            }
        });
        accessTeirComboBox.setModel(new DefaultComboBoxModel(AccessTier.values()));
        subscriptionComboBox.setEnabled(true);
        try {
            AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
            // not signed in
            if (azureManager == null) {
                return;
            }
            SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
            List<SubscriptionDetail> subscriptionDetails = subscriptionManager.getSubscriptionDetails();
            List<SubscriptionDetail> selectedSubscriptions = subscriptionDetails.stream().filter(SubscriptionDetail::isSelected).collect(Collectors.toList());
            subscriptionComboBox.setModel(new DefaultComboBoxModel<>(selectedSubscriptions.toArray(new SubscriptionDetail[selectedSubscriptions.size()])));
            if (selectedSubscriptions.size() > 0) {
                loadRegions();
            }
        } catch (Exception ex) {
            DefaultLoader.getUIHelper().logError("An error occurred when trying to load Subscriptions\n\n" + ex.getMessage(), ex);
        }
        subscriptionComboBox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent itemEvent) {
                loadRegions();
            }
        });
    } else {
        // if you create SA while creating VM
        this.subscription = subscription;
        subscriptionComboBox.addItem(subscription);
        // only General purpose accounts supported for VMs
        accoountKindCombo.addItem(Kind.STORAGE);
        accoountKindCombo.setEnabled(false);
        // Access tier is not available for General purpose accounts
        accessTeirComboBox.setVisible(false);
        accessTierLabel.setVisible(false);
        regionComboBox.addItem(region);
        regionComboBox.setEnabled(false);
        loadGroups();
    }
    //performanceComboBox.setModel(new DefaultComboBoxModel(SkuTier.values()));
    fillPerformanceComboBox();
    performanceComboBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                fillReplicationTypes();
            }
        }
    });
    replicationComboBox.setRenderer(new ListCellRendererWrapper<ReplicationTypes>() {

        @Override
        public void customize(JList jList, ReplicationTypes replicationTypes, int i, boolean b, boolean b1) {
            if (replicationTypes != null) {
                setText(replicationTypes.getDescription());
            }
        }
    });
    fillReplicationTypes();
}
Also used : ItemEvent(java.awt.event.ItemEvent) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) ReplicationTypes(com.microsoft.tooling.msservices.model.ReplicationTypes) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) ItemListener(java.awt.event.ItemListener)

Example 10 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(((VMWizardModel) model).getSubscription().getSubscriptionId());
    } 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().equals(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 (vmSizeComboBox.getItemCount() == 0) {
        vmSizeComboBox.setModel(new DefaultComboBoxModel(new String[] { "<Loading...>" }));
        ProgressManager.getInstance().run(new Task.Backgroundable(project, "Loading VM sizes...", false) {

            @Override
            public void run(@NotNull ProgressIndicator progressIndicator) {
                progressIndicator.setIndeterminate(true);
                PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = azure.virtualMachines().sizes().listByRegion(model.getRegion().name());
                Collections.sort(sizes, new Comparator<VirtualMachineSize>() {

                    @Override
                    public int compare(VirtualMachineSize t0, VirtualMachineSize 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;
                        }
                    }
                });
                ApplicationManager.getApplication().invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        vmSizeComboBox.setModel(new DefaultComboBoxModel<>(sizes.stream().map(VirtualMachineSize::name).toArray(String[]::new)));
                        selectDefaultSize();
                    }
                }, ModalityState.any());
            }
        });
    } else {
        selectDefaultSize();
    }
    return rootPanel;
}
Also used : Task(com.intellij.openapi.progress.Task) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) PagedList(com.microsoft.azure.PagedList) Comparator(java.util.Comparator) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Aggregations

AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)48 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)17 Azure (com.microsoft.azure.management.Azure)15 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)15 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)12 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)8 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)8 DockerHost (com.microsoft.azure.docker.model.DockerHost)6 Location (com.microsoft.azure.management.resources.Location)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 Subscription (com.microsoft.azure.management.resources.Subscription)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)3 KeyVaultClient (com.microsoft.azure.keyvault.KeyVaultClient)2 Network (com.microsoft.azure.management.network.Network)2 Kind (com.microsoft.azure.management.storage.Kind)2