Search in sources :

Example 36 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class AzureDockerHostsManager method subscriptionsChanged.

private static boolean subscriptionsChanged(AzureManager azureAuthManager) {
    try {
        SubscriptionManager subscriptionManager = azureAuthManager.getSubscriptionManager();
        List<SubscriptionDetail> subscriptions = subscriptionManager.getSubscriptionDetails();
        if (instance.subscriptionsMap == null || instance.subscriptionsMap.isEmpty()) {
            return true;
        }
        for (SubscriptionDetail subscriptionDetail : subscriptions) {
            if (subscriptionDetail.isSelected() != instance.subscriptionsMap.get(subscriptionDetail.getSubscriptionId()).isSelected)
                return true;
        }
        return false;
    } catch (Exception ignored) {
        return true;
    }
}
Also used : SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager)

Example 37 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail 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 SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail 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 SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class CreateRedisCacheForm method initWidgetListeners.

private void initWidgetListeners() {
    txtRedisName.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }

        @Override
        public void removeUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }

        @Override
        public void changedUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }
    });
    cbSubs.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            currentSub = (SubscriptionDetail) cbSubs.getSelectedItem();
            fillLocationsAndResourceGrps(currentSub);
            validateEmptyFields();
        }
    });
    rdoCreateNewGrp.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            txtNewResGrp.setVisible(true);
            cbUseExist.setVisible(false);
            newResGrp = true;
            validateEmptyFields();
        }
    });
    txtNewResGrp.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }

        @Override
        public void removeUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }

        @Override
        public void changedUpdate(DocumentEvent documentEvent) {
            validateEmptyFields();
        }
    });
    rdoUseExist.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            txtNewResGrp.setVisible(false);
            cbUseExist.setVisible(true);
            newResGrp = false;
            validateEmptyFields();
        }
    });
    cbUseExist.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            validateEmptyFields();
        }
    });
    cbLocations.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            validateEmptyFields();
        }
    });
    lblPricing.addMouseListener(new LinkListener(PRICING_LINK));
    cbPricing.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            validateEmptyFields();
        }
    });
    chkNoSSL.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (chkNoSSL.isSelected()) {
                noSSLPort = true;
            } else {
                noSSLPort = false;
            }
        }
    });
    cbLocations.setRenderer(new ListCellRendererWrapper<Object>() {

        @Override
        public void customize(JList jList, Object o, int i, boolean b, boolean b1) {
            if (o != null && (o instanceof Location)) {
                setText("  " + ((Location) o).displayName());
            }
        }
    });
}
Also used : DocumentListener(javax.swing.event.DocumentListener) MouseEvent(java.awt.event.MouseEvent) LinkListener(com.microsoft.intellij.helpers.LinkListener) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) DocumentEvent(javax.swing.event.DocumentEvent) ActionListener(java.awt.event.ActionListener) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) Location(com.microsoft.azure.management.resources.Location)

Example 40 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class AzureViewDockerDialog method initDefaultUIValues.

private void initDefaultUIValues(String updating) {
    // Docker VM info
    setTextField(dockerHostNameTextField, dockerHost.name);
    setTextField(dockerHostUrlTextField, dockerHost.apiUrl);
    setTextField(dockerHostSidTextField, dockerHost.sid);
    setSubscription(new SubscriptionDetail(dockerHost.sid, null, null, true));
    setTextField(dockerHostLocationTextField, dockerHost.hostVM.region);
    setTextField(dockerHostStatusTextField, (updating != null) ? dockerHost.state.toString() + updating : dockerHost.state.toString());
    // Docker VM settings
    setTextField(dockerHostOSTypeTextField, dockerHost.hostOSType.toString());
    // TODO: enable resizing of the current VM -> see VirtualMachine::availableSizes() and update.withSize();
    setTextField(dockerHostVMSizeTextField, (updating != null) ? dockerHost.hostVM.vmSize + updating : dockerHost.hostVM.vmSize);
    setTextField(dockerHostRGNameTextField, dockerHost.hostVM.resourceGroupName);
    setTextField(dockerHostVnetNameAddrTextField, String.format("%s (%s)", dockerHost.hostVM.vnetName, dockerHost.hostVM.vnetAddressSpace));
    setTextField(dockerHostSubnetNameAddrTextField, String.format("%s (%s)", dockerHost.hostVM.subnetName, dockerHost.hostVM.subnetAddressRange));
    setTextField(dockerHostPublicIpTextField, String.format("%s (%s)", dockerHost.hostVM.publicIp, dockerHost.hostVM.publicIpName));
    setTextField(dockerHostPrivateIpTextField, dockerHost.hostVM.privateIp);
    setTextField(dockerHostStorageNameTypeTextField, String.format("%s (%s)", dockerHost.hostVM.storageAccountName, dockerHost.hostVM.storageAccountType));
    // Docker VM log in settings
    dockerHostAuthUpdateHyperlink.setEnabled(!dockerHost.isUpdating);
    String username = (dockerHost.certVault != null && dockerHost.certVault.vmUsername != null) ? dockerHost.certVault.vmUsername : "-unknown-";
    setTextField(dockerHostUsernameTextField, (updating != null) ? username + updating : username);
    setTextField(dockerHostPwdLoginTextField, (updating != null) ? (dockerHost.hasPwdLogIn ? "Yes" : (dockerHost.certVault == null) ? "-unknown- " : "No") + updating : (dockerHost.hasPwdLogIn ? "Yes" : (dockerHost.certVault == null) ? "-unknown- " : "No"));
    setTextField(dockerHostSshLoginTextField, (updating != null) ? (dockerHost.hasSSHLogIn ? "Yes" : (dockerHost.certVault == null) ? "-unknown- " : "No") + updating : (dockerHost.hasSSHLogIn ? "Yes" : (dockerHost.certVault == null) ? "-unknown- " : "No"));
    dockerHostSshExportHyperlink.setEnabled(!dockerHost.isUpdating && dockerHost.hasSSHLogIn);
    // Docker Daemon settings
    setTextField(dockerHostTlsAuthTextField, (updating != null) ? (dockerHost.isTLSSecured ? "Using TLS certificates" : (dockerHost.certVault == null) ? "-unknown- " : "Open/unsecured access") + updating : (dockerHost.isTLSSecured ? "Using TLS certificates" : (dockerHost.certVault == null) ? "-unknown- " : "Open/unsecured access"));
    dockerHostTlsExportHyperlink.setEnabled(!dockerHost.isUpdating && dockerHost.isTLSSecured);
    setTextField(dockerHostPortTextField, (updating != null) ? dockerHost.port + updating : dockerHost.port);
    // Docker Keyvault settings
    if (dockerHost.certVault != null && dockerHost.hostVM.vaultName != null && !dockerHost.hostVM.vaultName.isEmpty() && dockerHost.certVault.uri != null && !dockerHost.certVault.uri.isEmpty()) {
        setTextField(dockerHostKeyvaultTextField, (updating != null) ? dockerHost.certVault.uri + updating : dockerHost.certVault.uri);
        dockerHostKeyvaultTextPane.setVisible(false);
    } else if (dockerHost.hostVM.vaultName != null && !dockerHost.hostVM.vaultName.isEmpty()) {
        setTextField(dockerHostKeyvaultTextField, String.format("Error reading http://%s.vault.azure.net", dockerHost.hostVM.vaultName));
        dockerHostKeyvaultTextPane.setVisible(true);
    } else {
        setTextField(dockerHostKeyvaultTextField, "Not using Key Vault");
        dockerHostKeyvaultTextPane.setVisible(false);
    }
    dockerHostKeyvaultTextPane.setFont(UIManager.getFont("Label.font"));
    exitCode = CLOSE_EXIT_CODE;
//    myClickApplyAction.setEnabled(!editableHost.originalDockerHost.equalsTo(dockerHost));
}
Also used : SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail)

Aggregations

SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)52 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)17 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)13 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)13 IOException (java.io.IOException)9 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)7 Location (com.microsoft.azure.management.resources.Location)7 List (java.util.List)7 WebApp (com.microsoft.azure.management.appservice.WebApp)5 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Azure (com.microsoft.azure.management.Azure)4 Subscription (com.microsoft.azure.management.resources.Subscription)4 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)4 HashMap (java.util.HashMap)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridData (org.eclipse.swt.layout.GridData)4 Label (org.eclipse.swt.widgets.Label)4 AccessTokenAzureManager (com.microsoft.azuretools.sdkmanage.AccessTokenAzureManager)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3