Skip to content

Commit a05ca00

Browse files
authored
Merge pull request #6088 from microsoft/fixes/app-service
Fix validation and UI issues for app service
2 parents 193dbec + b69fc23 commit a05ca00

File tree

17 files changed

+133
-30
lines changed

17 files changed

+133
-30
lines changed

PluginsAndFeatures/AddLibrary/AppInsights/com.microsoft.applicationinsights.ui/src/main/java/com/microsoft/applicationinsights/ui/config/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ depLocation=dependencies/
1414
excp=Exception in getClasspathEntries
1515
azureSDKcontainerID=com.microsoft.azuretools.SDK_CONTAINER
1616
sdkID=com.microsoft.azuretools.sdk
17-
sdkJar=dependencies/azure-1.38.0.jar
17+
sdkJar=dependencies/azure-1.41.2.jar
1818
jstDep=org.eclipse.jst.component.dependency
1919
aiCheckBoxTxt=Enable telemetry with Application Insights
2020
webxmlPath=WebContent/WEB-INF/web.xml

PluginsAndFeatures/AddLibrary/AzureLibraries/com.microsoft.azuretools.wasdkjava.ui/src/main/java/com/microsoft/azuretools/wasdkjava/ui/classpath/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ lblVersion=Version :
77
libNotAvail=Library is not available.
88
notFound=Not found
99
sdkID=com.microsoft.azuretools.sdk
10-
sdkJar=dependencies/azure-1.38.0.jar
10+
sdkJar=dependencies/azure-1.41.2.jar
1111
title=Microsoft Azure Libraries for Java
1212
verNotAvail=The selected version is not available.
1313
version1=Microsoft Azure Libraries for Java, version %s.%s.%s

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.core/src/com/microsoft/azure/toolkit/eclipse/common/component/AzureComboBox.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public List<T> getItems() {
223223
}
224224

225225
protected synchronized void setItems(final List<? extends T> items) {
226-
AzureTaskManager.getInstance().runAndWait(() -> {
226+
AzureTaskManager.getInstance().runLater(() -> {
227227
if (this.isDisposed()) {
228228
return;
229229
}

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.core/src/com/microsoft/azure/toolkit/eclipse/common/component/resourcegroup/ResourceGroupComboBox.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected Control getExtension() {
9090
@Override
9191
public void widgetSelected(SelectionEvent e) {
9292
super.widgetSelected(e);
93-
ResourceGroupCreationDialog dialog = new ResourceGroupCreationDialog(ResourceGroupComboBox.this.getShell());
93+
ResourceGroupCreationDialog dialog = new ResourceGroupCreationDialog(ResourceGroupComboBox.this.getShell(), subscription);
9494
if (dialog.open() == Window.OK) {
9595
DraftResourceGroup resourceGroupDraft = dialog.getData();
9696
draftItems.add(0, resourceGroupDraft);

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.core/src/com/microsoft/azure/toolkit/eclipse/common/component/resourcegroup/ResourceGroupCreationDialog.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import java.util.Arrays;
88
import java.util.List;
99
import java.util.Optional;
10+
import java.util.regex.Pattern;
1011

12+
import org.apache.commons.lang3.StringUtils;
1113
import org.eclipse.jface.dialogs.IDialogConstants;
1214
import org.eclipse.swt.SWT;
1315
import org.eclipse.swt.layout.GridData;
@@ -16,22 +18,33 @@
1618
import org.eclipse.swt.widgets.Control;
1719
import org.eclipse.swt.widgets.Label;
1820
import org.eclipse.swt.widgets.Shell;
19-
import com.microsoft.azure.toolkit.eclipse.common.component.AzureTextInput;
21+
22+
import com.microsoft.azure.CloudException;
2023
import com.microsoft.azure.toolkit.eclipse.common.component.AzureDialog;
24+
import com.microsoft.azure.toolkit.eclipse.common.component.AzureTextInput;
25+
import com.microsoft.azure.toolkit.lib.Azure;
2126
import com.microsoft.azure.toolkit.lib.common.form.AzureForm;
2227
import com.microsoft.azure.toolkit.lib.common.form.AzureFormInput;
28+
import com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo;
29+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessageBundle;
30+
import com.microsoft.azure.toolkit.lib.common.model.Subscription;
31+
import com.microsoft.azure.toolkit.lib.resource.AzureGroup;
2332

2433
public class ResourceGroupCreationDialog extends AzureDialog<DraftResourceGroup> implements AzureForm<DraftResourceGroup> {
34+
private static final Pattern PATTERN = Pattern.compile("[a-z0-9._()-]+[a-z0-9_()-]$");
35+
2536
private AzureTextInput textName;
37+
private Subscription subscription;
2638

2739
/**
2840
* Create the dialog.
2941
*
3042
* @param parentShell
3143
*/
32-
public ResourceGroupCreationDialog(Shell parentShell) {
44+
public ResourceGroupCreationDialog(Shell parentShell, Subscription subscription) {
3345
super(parentShell);
3446
setShellStyle(SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.RESIZE);
47+
this.subscription = subscription;
3548
}
3649

3750
/**
@@ -47,9 +60,9 @@ protected Control createDialogArea(Composite parent) {
4760
gridLayout.marginWidth = 5;
4861

4962
Label lblNewLabel = new Label(container, SWT.WRAP);
50-
GridData gd_lblNewLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
51-
gd_lblNewLabel.widthHint = 160;
52-
lblNewLabel.setLayoutData(gd_lblNewLabel);
63+
GridData gdLblNewLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
64+
gdLblNewLabel.widthHint = 160;
65+
lblNewLabel.setLayoutData(gdLblNewLabel);
5366
lblNewLabel.setText("A resource group is a container that holds related resources for an Azure solution.");
5467

5568
Label lblName = new Label(container, SWT.NONE);
@@ -58,6 +71,7 @@ protected Control createDialogArea(Composite parent) {
5871
textName = new AzureTextInput(container, SWT.BORDER);
5972
textName.setRequired(true);
6073
textName.setLabeledBy(lblName);
74+
textName.addValidator(() -> validateResourceGroupName());
6175
GridData textGrid = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
6276
textGrid.widthHint = 257;
6377
textName.setLayoutData(textGrid);
@@ -102,4 +116,32 @@ public void setValue(DraftResourceGroup draft) {
102116
public List<AzureFormInput<?>> getInputs() {
103117
return Arrays.asList(textName);
104118
}
119+
120+
// Copied from com.microsoft.azure.toolkit.intellij.common.component.resourcegroup.ResourceGroupNameTextField
121+
private AzureValidationInfo validateResourceGroupName() {
122+
final String value = textName.getValue();
123+
// validate length
124+
int minLength = 1;
125+
int maxLength = 90;
126+
if (StringUtils.length(value) < minLength) {
127+
return AzureValidationInfo.builder().input(this)
128+
.message("The value must not be empty.")
129+
.type(AzureValidationInfo.Type.ERROR).build();
130+
} else if (StringUtils.length(value) > maxLength) {
131+
return AzureValidationInfo.error(AzureMessageBundle.message("common.resourceGroup.validate.length", maxLength).toString(), textName);
132+
}
133+
// validate special character
134+
if (!PATTERN.matcher(value).matches()) {
135+
return AzureValidationInfo.error(AzureMessageBundle.message("common.resourceGroup.validate.invalid").toString(), textName);
136+
}
137+
// validate availability
138+
try {
139+
if (!Azure.az(AzureGroup.class).checkNameAvailability(subscription.getId(), value)) {
140+
return AzureValidationInfo.builder().input(this).message(value + " already existed.").type(AzureValidationInfo.Type.ERROR).build();
141+
}
142+
} catch (CloudException e) {
143+
return AzureValidationInfo.builder().input(this).message(e.getMessage()).type(AzureValidationInfo.Type.ERROR).build();
144+
}
145+
return AzureValidationInfo.success(textName);
146+
}
105147
}

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.core/src/com/microsoft/azuretools/core/utils/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ err=Error
5656
prefFileName=WAEclipsePlugin
5757
bundleName=org.eclipse.core.runtime
5858
sdkLibBundleName=com.microsoftopentechnologies.windowsazure.tools.sdk
59-
sdkLibBaseJar=dependencies/azure-1.38.0.jar
59+
sdkLibBaseJar=dependencies/azure-1.41.2.jar
6060
SDKLocErrMsg=Error occurred while retrieving path of Azure libraries
6161
resCLExWkspRfrsh=Exception while refresh of workspace.
6262
cmhLblStrgAcc=Storage Accounts

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.webapp/src/com/microsoft/azure/toolkit/eclipse/appservice/CreateWebAppDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ protected Control createDialogArea(Composite parent) {
7979
SubscriptionComboBox subscriptionComboBox = subsAndResourceGroupPanel.getSubscriptionComboBox();
8080
subscriptionComboBox.addValueChangedListener(event -> {
8181
Subscription subs = subscriptionComboBox.getValue();
82+
instanceDetailPanel.setSubscription(subs);
8283
instanceDetailPanel.getRegionComboBox().setSubscription(subs);
8384
appServicePlanPanel.getServicePlanCombobox().setSubscription(subs);
8485
});

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.webapp/src/com/microsoft/azure/toolkit/eclipse/appservice/CreateWebAppInstanceDetailComposite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ public List<AzureFormInput<?>> getInputs() {
112112
return Arrays.asList(text, cbRuntime, cbRegion);
113113
}
114114

115-
public AzureValidationInfo validateAppName() {
115+
private AzureValidationInfo validateAppName() {
116116
if (subscription == null) {
117117
return AzureValidationInfo.success(text);
118118
}
119-
CheckNameAvailabilityResultEntity result = Azure.az(AzureAppService.class)
119+
final CheckNameAvailabilityResultEntity result = Azure.az(AzureAppService.class)
120120
.checkNameAvailability(subscription.getId(), text.getValue());
121121
return result.isAvailable() ? AzureValidationInfo.success(text)
122-
: AzureValidationInfo.error(result.getUnavailabilityReason(), text);
122+
: AzureValidationInfo.error(result.getUnavailabilityMessage(), text);
123123
}
124124

125125
@Override

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.webapp/src/com/microsoft/azure/toolkit/eclipse/appservice/platform/RuntimeComboBox.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ public RuntimeComboBox(Composite parent) {
2929
}
3030

3131
public RuntimeComboBox(Composite parent, List<Runtime> platformList) {
32-
super(parent);
33-
this.platformList = ListUtils.unmodifiableList(platformList);
32+
super(parent, false);
33+
setPlatformList(platformList);
3434
}
3535

3636
public void setPlatformList(final List<Runtime> platformList) {
3737
this.platformList = ListUtils.unmodifiableList(platformList);
38+
this.refreshItems();
3839
}
3940

4041
@Override

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.webapp/src/com/microsoft/azure/toolkit/eclipse/appservice/serviceplan/ServicePlanCreationDialog.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import com.microsoft.azure.toolkit.lib.appservice.model.PricingTier;
1212
import com.microsoft.azure.toolkit.lib.common.form.AzureForm;
1313
import com.microsoft.azure.toolkit.lib.common.form.AzureFormInput;
14+
import com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo;
15+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessageBundle;
1416
import org.eclipse.jface.dialogs.IDialogConstants;
1517
import org.eclipse.swt.SWT;
1618
import org.eclipse.swt.layout.GridData;
@@ -22,9 +24,11 @@
2224
import java.util.Optional;
2325

2426
public class ServicePlanCreationDialog extends AzureDialog<DraftServicePlan> implements AzureForm<DraftServicePlan> {
27+
private static final String APP_SERVICE_PLAN_NAME_PATTERN = "[a-zA-Z0-9\\-]{1,40}";
2528
private AzureTextInput text;
2629
private PricingTierCombobox pricingTierCombobox;
2730
private DraftServicePlan data;
31+
private List<PricingTier> pricingTiers = null;
2832

2933
public ServicePlanCreationDialog(Shell parentShell) {
3034
super(parentShell);
@@ -54,6 +58,7 @@ protected Control createDialogArea(Composite parent) {
5458

5559
text = new AzureTextInput(container, SWT.BORDER);
5660
text.setRequired(true);
61+
text.addValidator(() -> validateAppServicePlanName());
5762
GridData textGrid = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
5863
textGrid.widthHint = 257;
5964
text.setLabeledBy(lblName);
@@ -77,8 +82,6 @@ public void setPricingTier(List<PricingTier> pricingTiers) {
7782

7883
}
7984

80-
private List<PricingTier> pricingTiers = null;
81-
8285
public DraftServicePlan getData() {
8386
return data;
8487
}
@@ -117,4 +120,13 @@ public void setValue(DraftServicePlan draft) {
117120
public List<AzureFormInput<?>> getInputs() {
118121
return Arrays.asList(text, pricingTierCombobox);
119122
}
123+
124+
private AzureValidationInfo validateAppServicePlanName() {
125+
final String appServicePlan = text.getValue();
126+
if (!appServicePlan.matches(APP_SERVICE_PLAN_NAME_PATTERN)) {
127+
return AzureValidationInfo.error(AzureMessageBundle.message("appService.servicePlan.validate.invalidName",
128+
APP_SERVICE_PLAN_NAME_PATTERN).toString(), text);
129+
}
130+
return AzureValidationInfo.success(text);
131+
}
120132
}

0 commit comments

Comments
 (0)