Search in sources :

Example 1 with ResourceEx

use of com.microsoft.azuretools.core.mvp.model.ResourceEx in project azure-tools-for-java by Microsoft.

the class CreateDeploymentForm method doOKAction.

@Override
protected void doOKAction() {
    deploymentName = deploymentNameTextField.getText();
    final AzureString title = AzureOperationBundle.title("arm|deployment.deploy", deploymentName);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        EventUtil.executeWithLog(TelemetryConstants.ARM, TelemetryConstants.CREATE_DEPLOYMENT, (operation -> {
            Subscription subs = (Subscription) subscriptionCb.getSelectedItem();
            com.microsoft.azure.management.Azure azure = AuthMethodManager.getInstance().getAzureClient(subs.getId());
            WithTemplate template;
            if (createNewRgButton.isSelected()) {
                rgName = rgNameTextFiled.getText();
                final Region region = (Region) regionCb.getSelectedItem();
                template = azure.deployments().define(deploymentName).withNewResourceGroup(rgNameTextFiled.getText(), com.microsoft.azure.management.resources.fluentcore.arm.Region.fromName(region.getName()));
            } else {
                ResourceGroup rg = (ResourceGroup) rgNameCb.getSelectedItem();
                List<ResourceEx<Deployment>> deployments = AzureMvpModel.getInstance().getDeploymentByRgName(subs.getId(), rg.getName());
                boolean isExist = deployments.parallelStream().anyMatch(deployment -> deployment.getResource().name().equals(deploymentName));
                if (isExist) {
                    throw new RuntimeException(DUPLICATED_DEPLOYMENT_NAME);
                }
                rgName = rg.getName();
                template = azure.deployments().define(deploymentName).withExistingResourceGroup(rg.getName());
            }
            String fileText = templateTextField.getText();
            String content = IOUtils.toString(new FileReader(fileText));
            String parametersPath = parametersTextField.getText();
            String parameters = StringUtils.isEmpty(parametersPath) ? "{}" : IOUtils.toString(new FileReader(parametersPath));
            parameters = DeploymentUtils.parseParameters(parameters);
            template.withTemplate(content).withParameters(parameters).withMode(DeploymentMode.INCREMENTAL).create();
            UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
            updateUI();
        }), (ex) -> {
            UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_FAIL + ", " + ex.getMessage(), MessageType.ERROR);
            updateUI();
        });
    }));
    close(DialogWrapper.OK_EXIT_CODE, true);
}
Also used : AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) Azure(com.microsoft.azure.toolkit.lib.Azure) NOTIFY_CREATE_DEPLOYMENT_FAIL(com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_FAIL) MessageType(com.intellij.openapi.ui.MessageType) SimpleListCellRenderer(com.intellij.ui.SimpleListCellRenderer) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) StringUtils(org.apache.commons.lang3.StringUtils) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) NOTIFY_CREATE_DEPLOYMENT_SUCCESS(com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_SUCCESS) StatusBar(com.intellij.openapi.wm.StatusBar) WithTemplate(com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate) ResourceManagementNode(com.microsoft.tooling.msservices.serviceexplorer.azure.arm.ResourceManagementNode) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) JComboBox(javax.swing.JComboBox) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx) WindowManager(com.intellij.openapi.wm.WindowManager) JRadioButton(javax.swing.JRadioButton) RegionComboBox(com.microsoft.azure.toolkit.intellij.common.component.RegionComboBox) IOUtils(org.apache.commons.io.IOUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureMvpModel(com.microsoft.azuretools.core.mvp.model.AzureMvpModel) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) JPanel(javax.swing.JPanel) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) JTextField(javax.swing.JTextField) AzureUIRefreshCore(com.microsoft.azuretools.utils.AzureUIRefreshCore) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Region(com.microsoft.azure.toolkit.lib.common.model.Region) DeploymentMode(com.microsoft.azure.management.resources.DeploymentMode) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) JComponent(javax.swing.JComponent) Deployment(com.microsoft.azure.management.resources.Deployment) ButtonGroup(javax.swing.ButtonGroup) UIUtils(com.microsoft.intellij.ui.util.UIUtils) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) JList(javax.swing.JList) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) EventType(com.microsoft.azuretools.telemetrywrapper.EventType) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) JLabel(javax.swing.JLabel) FileReader(java.io.FileReader) SubscriptionComboBox(com.microsoft.azure.toolkit.intellij.common.component.SubscriptionComboBox) BROWSE_TEMPLATE_SAMPLES(com.microsoft.azuretools.telemetry.TelemetryConstants.BROWSE_TEMPLATE_SAMPLES) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) WithTemplate(com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate) Region(com.microsoft.azure.toolkit.lib.common.model.Region) FileReader(java.io.FileReader) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)

Example 2 with ResourceEx

use of com.microsoft.azuretools.core.mvp.model.ResourceEx in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsNewDialog method populateResourceGroupValues.

private void populateResourceGroupValues(String subscriptionId, String valtoSet) {
    try {
        List<String> groupStringList = AzureMvpModel.getInstance().getResourceGroups(subscriptionId).stream().map(ResourceEx::getResource).map(ResourceGroup::getName).collect(Collectors.toList());
        if (groupStringList.size() > 0) {
            String[] groupArray = groupStringList.toArray(new String[groupStringList.size()]);
            comboGrp.removeAllItems();
            comboGrp.setModel(new DefaultComboBoxModel(groupArray));
            if (valtoSet == null || valtoSet.isEmpty() || !groupStringList.contains(valtoSet)) {
                comboGrp.setSelectedItem(groupArray[0]);
            } else {
                comboGrp.setSelectedItem(valtoSet);
            }
        }
    } catch (Exception ex) {
        AzurePlugin.log(message("getValuesErrMsg"), ex);
    }
}
Also used : AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx)

Example 3 with ResourceEx

use of com.microsoft.azuretools.core.mvp.model.ResourceEx in project azure-tools-for-java by Microsoft.

the class ContainerRegistryMvpModel method listContainerRegistries.

/**
 * Get Registry instances mapped by Subscription id.
 */
public List<ResourceEx<Registry>> listContainerRegistries(boolean force) {
    List<ResourceEx<Registry>> registryList = new ArrayList<>();
    List<Subscription> subscriptions = az(AzureAccount.class).account().getSelectedSubscriptions();
    for (Subscription sub : subscriptions) {
        registryList.addAll(listRegistryBySubscriptionId(sub.getId(), force));
    }
    return registryList;
}
Also used : ArrayList(java.util.ArrayList) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx)

Example 4 with ResourceEx

use of com.microsoft.azuretools.core.mvp.model.ResourceEx in project azure-tools-for-java by Microsoft.

the class ContainerRegistryMvpModel method listRegistryBySubscriptionId.

/**
 * Get Registry by subscription id.
 */
public List<ResourceEx<Registry>> listRegistryBySubscriptionId(@NotNull String sid, boolean force) {
    if (!force && subscriptionIdToRegistryMap.containsKey(sid)) {
        return subscriptionIdToRegistryMap.get(sid);
    }
    List<ResourceEx<Registry>> registryList = new ArrayList<>();
    Azure azure = AuthMethodManager.getInstance().getAzureClient(sid);
    for (Registry registry : azure.containerRegistries().list()) {
        registryList.add(new ResourceEx<>(registry, sid));
    }
    subscriptionIdToRegistryMap.put(sid, registryList);
    return registryList;
}
Also used : Azure(com.microsoft.azure.management.Azure) ArrayList(java.util.ArrayList) Registry(com.microsoft.azure.management.containerregistry.Registry) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx)

Aggregations

ResourceEx (com.microsoft.azuretools.core.mvp.model.ResourceEx)4 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)2 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)2 ArrayList (java.util.ArrayList)2 FileChooserDescriptorFactory (com.intellij.openapi.fileChooser.FileChooserDescriptorFactory)1 Project (com.intellij.openapi.project.Project)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 MessageType (com.intellij.openapi.ui.MessageType)1 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)1 StatusBar (com.intellij.openapi.wm.StatusBar)1 WindowManager (com.intellij.openapi.wm.WindowManager)1 HyperlinkLabel (com.intellij.ui.HyperlinkLabel)1 SimpleListCellRenderer (com.intellij.ui.SimpleListCellRenderer)1 Azure (com.microsoft.azure.management.Azure)1 Registry (com.microsoft.azure.management.containerregistry.Registry)1 Deployment (com.microsoft.azure.management.resources.Deployment)1 WithTemplate (com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate)1 DeploymentMode (com.microsoft.azure.management.resources.DeploymentMode)1 NOTIFY_CREATE_DEPLOYMENT_FAIL (com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_FAIL)1 NOTIFY_CREATE_DEPLOYMENT_SUCCESS (com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_SUCCESS)1