|
38 | 38 | import com.intellij.openapi.wm.WindowManager; |
39 | 39 | import com.intellij.ui.HyperlinkLabel; |
40 | 40 | import com.microsoft.azure.management.Azure; |
| 41 | +import com.microsoft.azure.management.resources.Deployment; |
41 | 42 | import com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate; |
42 | 43 | import com.microsoft.azure.management.resources.DeploymentMode; |
43 | 44 | import com.microsoft.azure.management.resources.Location; |
44 | 45 | import com.microsoft.azure.management.resources.ResourceGroup; |
45 | 46 | import com.microsoft.azure.management.resources.fluentcore.arm.Region; |
46 | 47 | import com.microsoft.azuretools.authmanage.AuthMethodManager; |
47 | 48 | import com.microsoft.azuretools.authmanage.models.SubscriptionDetail; |
| 49 | +import com.microsoft.azuretools.core.mvp.model.AzureMvpModel; |
| 50 | +import com.microsoft.azuretools.core.mvp.model.ResourceEx; |
48 | 51 | import com.microsoft.azuretools.telemetry.TelemetryConstants; |
49 | 52 | import com.microsoft.azuretools.telemetrywrapper.EventType; |
50 | 53 | import com.microsoft.azuretools.telemetrywrapper.EventUtil; |
|
72 | 75 |
|
73 | 76 | public class CreateDeploymentForm extends DeploymentBaseForm { |
74 | 77 |
|
| 78 | + private static final String DUPLICATED_DEPLOYMENT_NAME = "A deployment with the same name already exists"; |
| 79 | + |
75 | 80 | private JPanel contentPane; |
76 | 81 | private JTextField rgNameTextFiled; |
77 | 82 | private JComboBox rgNameCb; |
@@ -153,6 +158,13 @@ public void run(@NotNull ProgressIndicator indicator) { |
153 | 158 | ((ElementWrapper<Region>) regionCb.getSelectedItem()).getValue()); |
154 | 159 | } else { |
155 | 160 | ResourceGroup rg = ((ElementWrapper<ResourceGroup>) rgNameCb.getSelectedItem()).getValue(); |
| 161 | + List<ResourceEx<Deployment>> deployments = AzureMvpModel.getInstance() |
| 162 | + .getDeploymentByRgName(subs.getSubscriptionId(), rg.name()); |
| 163 | + boolean isExist = deployments.parallelStream() |
| 164 | + .anyMatch(deployment -> deployment.getResource().name().equals(deploymentName)); |
| 165 | + if (isExist) { |
| 166 | + throw new RuntimeException(DUPLICATED_DEPLOYMENT_NAME); |
| 167 | + } |
156 | 168 | rgName = rg.name(); |
157 | 169 | template = azure.deployments().define(deploymentName).withExistingResourceGroup(rg); |
158 | 170 | } |
|
0 commit comments