Search in sources :

Example 6 with Location

use of com.microsoft.azure.management.resources.Location in project azure-tools-for-java by Microsoft.

the class AzureModelController method updateSubscriptionMaps.

public static synchronized void updateSubscriptionMaps(IProgressIndicator progressIndicator) throws IOException, CanceledByUserException, AuthException {
    AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    // not signed in
    if (azureManager == null) {
        return;
    }
    if (progressIndicator != null && progressIndicator.isCanceled()) {
        clearAll();
        throw new CanceledByUserException();
    }
    AzureModel azureModel = AzureModel.getInstance();
    // to get regions we nees subscription objects
    if (progressIndicator != null)
        progressIndicator.setText("Reading subscription list...");
    List<Subscription> sl = azureManager.getSubscriptions();
    // convert to map to easier find by sid
    Map<String, Subscription> sidToSubscriptionMap = azureModel.createSidToSubscriptionMap();
    for (Subscription s : sl) {
        sidToSubscriptionMap.put(s.subscriptionId(), s);
    }
    azureModel.setSidToSubscriptionMap(sidToSubscriptionMap);
    Map<SubscriptionDetail, List<Location>> sdlocMap = azureModel.createSubscriptionToRegionMap();
    Map<SubscriptionDetail, List<ResourceGroup>> sdrgMap = azureModel.createSubscriptionToResourceGroupMap();
    SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
    subscriptionManager.addListener(subscriptionSelectionListener);
    List<SubscriptionDetail> sdl = subscriptionManager.getSubscriptionDetails();
    for (SubscriptionDetail sd : sdl) {
        if (!sd.isSelected())
            continue;
        if (progressIndicator != null && progressIndicator.isCanceled()) {
            clearAll();
            throw new CanceledByUserException();
        }
        System.out.println("sn : " + sd.getSubscriptionName());
        if (progressIndicator != null)
            progressIndicator.setText("Reading subscription '" + sd.getSubscriptionName() + "'");
        Azure azure = azureManager.getAzure(sd.getSubscriptionId());
        List<ResourceGroup> rgList = azure.resourceGroups().list();
        sdrgMap.put(sd, rgList);
        List<Location> locl = sidToSubscriptionMap.get(sd.getSubscriptionId()).listLocations();
        Collections.sort(locl, new Comparator<Location>() {

            @Override
            public int compare(Location lhs, Location rhs) {
                return lhs.displayName().compareTo(rhs.displayName());
            }
        });
        sdlocMap.put(sd, locl);
    }
    azureModel.setSubscriptionToResourceGroupMap(sdrgMap);
    azureModel.setSubscriptionToLocationMap(sdlocMap);
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) Subscription(com.microsoft.azure.management.resources.Subscription) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Location(com.microsoft.azure.management.resources.Location)

Example 7 with Location

use of com.microsoft.azure.management.resources.Location in project azure-tools-for-java by Microsoft.

the class AzureModelController method subscriptionSelectionChanged.

private static synchronized void subscriptionSelectionChanged(IProgressIndicator progressIndicator) throws IOException, AuthException {
    System.out.println("AzureModelController.subscriptionSelectionChanged: starting");
    AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    // not signed in
    if (azureManager == null) {
        System.out.println("AzureModelController.subscriptionSelectionChanged: azureManager == null -> return");
        return;
    }
    SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
    AzureModel azureModel = AzureModel.getInstance();
    Map<SubscriptionDetail, List<ResourceGroup>> srgMap = azureModel.getSubscriptionToResourceGroupMap();
    if (srgMap == null) {
        System.out.println("AzureModelController.subscriptionSelectionChanged: srgMap == null -> return");
        return;
    }
    Map<String, Subscription> sidToSubscriptionMap = azureModel.getSidToSubscriptionMap();
    if (sidToSubscriptionMap == null) {
        System.out.println("AzureModelController.subscriptionSelectionChanged: sidToSubscriptionMap == null -> return");
        return;
    }
    Map<ResourceGroup, List<WebApp>> rgwaMap = azureModel.getResourceGroupToWebAppMap();
    Map<ResourceGroup, List<AppServicePlan>> rgspMap = azureModel.getResourceGroupToAppServicePlanMap();
    System.out.println("AzureModelController.subscriptionSelectionChanged: getting subscription details...");
    List<SubscriptionDetail> sdl = subscriptionManager.getSubscriptionDetails();
    if (sdl == null) {
        System.out.println("AzureModelController.subscriptionSelectionChanged: sdl == null -> return");
        return;
    }
    for (SubscriptionDetail sd : sdl) {
        if (!srgMap.containsKey(sd)) {
            if (!sd.isSelected())
                continue;
            if (progressIndicator != null && progressIndicator.isCanceled()) {
                progressIndicator.setText("Cancelling...");
                clearAll();
                return;
            // FIXME: throw exception?
            }
            Azure azure = azureManager.getAzure(sd.getSubscriptionId());
            // subscription locations
            List<Subscription> sl = azureManager.getSubscriptions();
            System.out.println("Updating subscription locations");
            Subscription subscription = sidToSubscriptionMap.get(sd.getSubscriptionId());
            if (progressIndicator != null)
                progressIndicator.setText(String.format("Updating subscription '%s' locations...", subscription.displayName()));
            List<Location> locl = subscription.listLocations();
            Collections.sort(locl, new Comparator<Location>() {

                @Override
                public int compare(Location lhs, Location rhs) {
                    return lhs.displayName().compareTo(rhs.displayName());
                }
            });
            Map<SubscriptionDetail, List<Location>> sdlocMap = azureModel.getSubscriptionToLocationMap();
            sdlocMap.put(sd, locl);
            // resource group maps
            List<ResourceGroup> rgList = azure.resourceGroups().list();
            srgMap.put(sd, rgList);
            updateResGrDependency(azure, rgList, progressIndicator, rgwaMap, rgspMap);
        } else {
            // find and modify the key
            for (SubscriptionDetail sdk : srgMap.keySet()) {
                if (sdk.equals(sd)) {
                    sdk.setSelected(sd.isSelected());
                }
            }
        }
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) Subscription(com.microsoft.azure.management.resources.Subscription) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Location(com.microsoft.azure.management.resources.Location)

Example 8 with Location

use of com.microsoft.azure.management.resources.Location in project azure-tools-for-java by Microsoft.

the class SelectImageStep method fillRegions.

private void fillRegions() {
    regionComboBox.removeAll();
    List<Location> locations = AzureModel.getInstance().getSubscriptionToLocationMap().get(wizard.getSubscription()).stream().sorted(Comparator.comparing(Location::displayName)).collect(Collectors.toList());
    for (Location location : locations) {
        regionComboBox.add(location.displayName());
        regionComboBox.setData(location.displayName(), location);
    }
    if (locations.size() > 0) {
        regionComboBox.select(0);
        selectRegion();
    }
    regionComboBox.setEnabled(true);
    validateNext();
}
Also used : Location(com.microsoft.azure.management.resources.Location)

Example 9 with Location

use of com.microsoft.azure.management.resources.Location in project azure-tools-for-java by Microsoft.

the class AppServiceCreateDialog method fillAppServicePlanLocations.

protected void fillAppServicePlanLocations() {
    int i = comboSubscription.getSelectionIndex();
    if (i < 0) {
        // empty
        System.out.println("No subscription is selected");
        return;
    }
    comboAppServicePlanLocation.removeAll();
    binderAppServicePlanLocation = new ArrayList<Location>();
    //List<Location> locl = AzureModel.getInstance().getSubscriptionToLocationMap().get(binderSubscriptionDetails.get(i));
    Map<SubscriptionDetail, List<Location>> sdlocMap = AzureModel.getInstance().getSubscriptionToLocationMap();
    SubscriptionDetail sd = binderSubscriptionDetails.get(i);
    List<Location> locl = sdlocMap.get(sd);
    comboAppServicePlanLocation.add("<select location>");
    binderAppServicePlanLocation.add(null);
    for (Location loc : locl) {
        comboAppServicePlanLocation.add(loc.displayName());
        binderAppServicePlanLocation.add(loc);
    }
    if (comboAppServicePlanLocation.getItemCount() > 0) {
        comboAppServicePlanLocation.select(0);
    }
}
Also used : SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Location(com.microsoft.azure.management.resources.Location)

Example 10 with Location

use of com.microsoft.azure.management.resources.Location 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)

Aggregations

Location (com.microsoft.azure.management.resources.Location)13 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)7 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)5 Subscription (com.microsoft.azure.management.resources.Subscription)4 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)4 Azure (com.microsoft.azure.management.Azure)3 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 CloudException (com.microsoft.azure.CloudException)1 com.microsoft.azure.docker.model (com.microsoft.azure.docker.model)1 AzureDockerCertVaultOps (com.microsoft.azure.docker.ops.AzureDockerCertVaultOps)1 AzureDockerVMOps (com.microsoft.azure.docker.ops.AzureDockerVMOps)1 KeyVaultClient (com.microsoft.azure.keyvault.KeyVaultClient)1 VirtualMachinePublisher (com.microsoft.azure.management.compute.VirtualMachinePublisher)1 Vault (com.microsoft.azure.management.keyvault.Vault)1 Network (com.microsoft.azure.management.network.Network)1 Subnet (com.microsoft.azure.management.network.Subnet)1