Search in sources :

Example 1 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 2 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 3 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)

Example 4 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().getSubscriptionId());
    } 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) IOException(java.io.IOException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 5 with AzureManager

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

the class AzureDockerUtils method refreshDockerSubscriptions.

public static Map<String, AzureDockerSubscription> refreshDockerSubscriptions(AzureManager azureAuthManager) {
    Map<String, AzureDockerSubscription> subsMap = new HashMap<>();
    try {
        if (DEBUG)
            System.out.format("Get AzureDockerHostsManage subscription details: %s\n", new Date().toString());
        SubscriptionManager subscriptionManager = azureAuthManager.getSubscriptionManager();
        List<SubscriptionDetail> subscriptions = subscriptionManager.getSubscriptionDetails();
        if (subscriptions != null) {
            if (DEBUG)
                System.out.format("Get AzureDockerHostsManage Docker subscription details: %s\n", new Date().toString());
            Observable.from(subscriptions).flatMap(subscriptionDetail -> {
                return Observable.create(new Observable.OnSubscribe<AzureDockerSubscription>() {

                    @Override
                    public void call(Subscriber<? super AzureDockerSubscription> dockerSubscriptionSubscriber) {
                        if (subscriptionDetail.isSelected()) {
                            AzureDockerSubscription dockerSubscription = new AzureDockerSubscription();
                            dockerSubscription.id = subscriptionDetail.getSubscriptionId();
                            try {
                                if (DEBUG)
                                    System.out.format("\tGet AzureDockerHostsManage Docker subscription: %s at %s\n", dockerSubscription.id, new Date().toString());
                                dockerSubscription.tid = subscriptionDetail.getTenantId();
                                dockerSubscription.name = subscriptionDetail.getSubscriptionName();
                                dockerSubscription.azureClient = azureAuthManager.getAzure(dockerSubscription.id);
                                dockerSubscription.keyVaultClient = azureAuthManager.getKeyVaultClient(subscriptionDetail.getTenantId());
                                dockerSubscription.isSelected = true;
                                if (AzureDockerUtils.hasServicePrincipalAzureManager(azureAuthManager)) {
                                    dockerSubscription.userId = null;
                                    dockerSubscription.servicePrincipalId = azureAuthManager.getCurrentUserId();
                                } else {
                                    dockerSubscription.userId = azureAuthManager.getCurrentUserId();
                                    dockerSubscription.servicePrincipalId = null;
                                }
                                dockerSubscriptionSubscriber.onNext(dockerSubscription);
                            } catch (Exception e) {
                                e.printStackTrace();
                                DefaultLoader.getUIHelper().showError(e.getMessage(), "Error Loading Subscription Details for " + dockerSubscription.id);
                            }
                        }
                        dockerSubscriptionSubscriber.onCompleted();
                    }
                }).subscribeOn(Schedulers.io());
            }).subscribeOn(Schedulers.io()).toBlocking().subscribe(new Action1<AzureDockerSubscription>() {

                @Override
                public void call(AzureDockerSubscription dockerSubscription) {
                    subsMap.put(dockerSubscription.id, dockerSubscription);
                }
            });
        }
        if (DEBUG)
            System.out.format("Get AzureDockerHostsManage locations: %s\n", new Date().toString());
        List<Subscription> azureSubscriptionList = azureAuthManager.getSubscriptions();
        for (Subscription subscription : azureSubscriptionList) {
            AzureDockerSubscription dockerSubscription = subsMap.get(subscription.subscriptionId());
            if (dockerSubscription != null) {
                List<String> locations = subscription.listLocations().stream().sorted(Comparator.comparing(Location::displayName)).map(o -> o.name().toLowerCase()).collect(Collectors.toList());
                dockerSubscription.locations = locations;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        DefaultLoader.getUIHelper().showError(e.getMessage(), "Error loading subscription details");
    }
    return subsMap;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) java.util(java.util) StorageAccount(com.microsoft.azure.management.storage.StorageAccount) URL(java.net.URL) Subnet(com.microsoft.azure.management.network.Subnet) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) Callable(java.util.concurrent.Callable) Action1(rx.functions.Action1) Location(com.microsoft.azure.management.resources.Location) Observable(rx.Observable) Azure(com.microsoft.azure.management.Azure) Network(com.microsoft.azure.management.network.Network) Func1(rx.functions.Func1) ServicePrincipalAzureManager(com.microsoft.azuretools.sdkmanage.ServicePrincipalAzureManager) Schedulers(rx.schedulers.Schedulers) DefaultLoader(com.microsoft.tooling.msservices.components.DefaultLoader) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) Vault(com.microsoft.azure.management.keyvault.Vault) Subscription(com.microsoft.azure.management.resources.Subscription) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) Subscriber(rx.Subscriber) AzureDockerCertVaultOps(com.microsoft.azure.docker.ops.AzureDockerCertVaultOps) AzureRegisterProviderNamespaces(com.microsoft.azuretools.utils.AzureRegisterProviderNamespaces) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) Pair(com.microsoft.azuretools.utils.Pair) CountDownLatch(java.util.concurrent.CountDownLatch) Action0(rx.functions.Action0) com.microsoft.azure.docker.model(com.microsoft.azure.docker.model) AzureDockerVMOps(com.microsoft.azure.docker.ops.AzureDockerVMOps) KeyVaultClient(com.microsoft.azure.keyvault.KeyVaultClient) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) Observable(rx.Observable) UnknownHostException(java.net.UnknownHostException) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) Subscription(com.microsoft.azure.management.resources.Subscription)

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