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);
}
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);
}
}
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;
}
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;
}
Aggregations