Search in sources :

Example 36 with AzureManager

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

the class CreateVMWizard method setSubscription.

public void setSubscription(SubscriptionDetail subscription) {
    try {
        this.subscription = subscription;
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        azure = azureManager.getAzure(subscription.getSubscriptionId());
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().showException(ex.getMessage(), ex, "Error selecting subscription", true, false);
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) IOException(java.io.IOException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 37 with AzureManager

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

the class CreateArmStorageAccountForm method okPressed.

@Override
protected void okPressed() {
    if (nameTextField.getText().length() < 3 || nameTextField.getText().length() > 24 || !nameTextField.getText().matches("[a-z0-9]+")) {
        DefaultLoader.getUIHelper().showError("Invalid storage account name. The name should be between 3 and 24 characters long and " + "can contain only lowercase letters and numbers.", "Azure Explorer");
        return;
    }
    final boolean isNewResourceGroup = createNewRadioButton.getSelection();
    final String resourceGroupName = isNewResourceGroup ? resourceGrpField.getText() : resourceGrpCombo.getText();
    String replication = replicationComboBox.getData(replicationComboBox.getText()).toString();
    String region = ((Location) regionComboBox.getData(regionComboBox.getText())).name();
    Kind kind = (Kind) kindCombo.getData(kindCombo.getText());
    if (subscription == null) {
        String name = nameTextField.getText();
        AccessTier accessTier = (AccessTier) accessTierComboBox.getData(accessTierComboBox.getText());
        SubscriptionDetail subscriptionDetail = (SubscriptionDetail) subscriptionComboBox.getData(subscriptionComboBox.getText());
        setSubscription(subscriptionDetail);
        DefaultLoader.getIdeHelper().runInBackground(null, "Creating storage account", false, true, "Creating storage account " + name + "...", new Runnable() {

            @Override
            public void run() {
                try {
                    AzureSDKManager.createStorageAccount(subscriptionDetail.getSubscriptionId(), name, region, isNewResourceGroup, resourceGroupName, kind, accessTier, false, replication);
                    // update resource groups cache if new resource group was created when creating storage account
                    if (isNewResourceGroup) {
                        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
                        if (azureManager != null) {
                            ResourceGroup rg = azureManager.getAzure(subscriptionDetail.getSubscriptionId()).resourceGroups().getByName(resourceGroupName);
                            AzureModelController.addNewResourceGroup(subscriptionDetail, rg);
                        }
                    }
                    if (onCreate != null) {
                        onCreate.run();
                    }
                } catch (Exception e) {
                    DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            PluginUtil.displayErrorDialog(PluginUtil.getParentShell(), Messages.err, "An error occurred while creating the storage account: " + e.getMessage());
                        }
                    });
                }
            }
        });
    } else {
        //creating from 'create vm'
        newStorageAccount = new com.microsoft.tooling.msservices.model.storage.StorageAccount(nameTextField.getText(), subscription.getSubscriptionId());
        newStorageAccount.setResourceGroupName(resourceGroupName);
        newStorageAccount.setNewResourceGroup(isNewResourceGroup);
        newStorageAccount.setType(replication);
        newStorageAccount.setLocation(region);
        newStorageAccount.setKind(kind);
        if (onCreate != null) {
            onCreate.run();
        }
    }
    super.okPressed();
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) AccessTier(com.microsoft.azure.management.storage.AccessTier) InvocationTargetException(java.lang.reflect.InvocationTargetException) Kind(com.microsoft.azure.management.storage.Kind) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Location(com.microsoft.azure.management.resources.Location)

Example 38 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;
            }
            SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
            List<SubscriptionDetail> subscriptionDetails = subscriptionManager.getSubscriptionDetails();
            for (SubscriptionDetail sub : subscriptionDetails) {
                if (sub.isSelected()) {
                    subscriptionComboBox.add(sub.getSubscriptionName());
                    subscriptionComboBox.setData(sub.getSubscriptionName(), sub);
                }
            }
            subscriptionComboBox.addSelectionListener(new SelectionAdapter() {

                public void widgetSelected(SelectionEvent e) {
                    loadRegionsAndGroups();
                }
            });
            if (subscriptionDetails.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.getSubscriptionName());
        subscriptionComboBox.setData(subscription.getSubscriptionName(), subscription);
        subscriptionComboBox.select(0);
        // only General purpose accounts supported for VMs
        kindCombo.add("General purpose");
        kindCombo.setData(Kind.STORAGE);
        kindCombo.setEnabled(false);
        kindCombo.select(0);
        regionComboBox.add(region.displayName());
        regionComboBox.setData(region.displayName(), 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.management.storage.Kind) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 39 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<SubscriptionDetail> subList = azureManager.getSubscriptionManager().getSubscriptionDetails();
            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) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail)

Example 40 with AzureManager

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

the class ApplicationInsightsNewDialog method populateValues.

private void populateValues() {
    try {
        subscription.removeAll();
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        if (azureManager == null) {
            return;
        }
        List<SubscriptionDetail> subList = azureManager.getSubscriptionManager().getSubscriptionDetails();
        // check at least single subscription is associated with the account
        if (subList.size() > 0) {
            for (SubscriptionDetail sub : subList) {
                subscription.add(sub.getSubscriptionName());
                subscription.setData(sub.getSubscriptionName(), sub);
            }
            subscription.select(0);
            currentSub = subList.get(0);
            populateResourceGroupValues(currentSub.getSubscriptionId(), "");
            List<String> regionList = AzureSDKManager.getLocationsForApplicationInsights(currentSub);
            String[] regionArray = regionList.toArray(new String[regionList.size()]);
            region.setItems(regionArray);
            region.setText(regionArray[0]);
        }
        enableOkBtn();
    } catch (Exception ex) {
        Activator.getDefault().log(Messages.getValuesErrMsg, ex);
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail)

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