Skip to content

Commit 15566dc

Browse files
Merge pull request #6973 from microsoft/hanli-fixes-202209
Hanli fixes 202209
2 parents ff819d1 + 18c053e commit 15566dc

File tree

7 files changed

+102
-40
lines changed

7 files changed

+102
-40
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/appservice/AppServiceStreamingLogManager.java

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import com.microsoft.azure.toolkit.lib.Azure;
1414
import com.microsoft.azure.toolkit.lib.applicationinsights.ApplicationInsight;
1515
import com.microsoft.azure.toolkit.lib.applicationinsights.AzureApplicationInsights;
16-
import com.microsoft.azure.toolkit.lib.appservice.function.AzureFunctions;
17-
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionApp;
16+
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppBase;
17+
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppDeploymentSlotDraft;
1818
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppDraft;
1919
import com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig;
2020
import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem;
@@ -33,6 +33,7 @@
3333
import com.microsoft.azure.toolkit.lib.common.operation.OperationBundle;
3434
import com.microsoft.azure.toolkit.lib.common.task.AzureTask;
3535
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
36+
import lombok.Getter;
3637
import org.apache.commons.lang3.StringUtils;
3738
import reactor.core.publisher.Flux;
3839

@@ -70,8 +71,12 @@ public void showWebAppStreamingLog(Project project, String webAppId) {
7071
showAppServiceStreamingLog(project, webAppId, new WebAppLogStreaming(webAppId));
7172
}
7273

73-
public void showFunctionStreamingLog(Project project, String functionId) {
74-
showAppServiceStreamingLog(project, functionId, new FunctionLogStreaming(functionId));
74+
public void showFunctionStreamingLog(Project project, FunctionAppBase<?,?,?> app) {
75+
showAppServiceStreamingLog(project, app.getId(), new FunctionLogStreaming(app));
76+
}
77+
78+
public void showFunctionDeploymentSlotStreamingLog(Project project, FunctionAppBase<?,?,?> app) {
79+
showAppServiceStreamingLog(project, app.getId(), new FunctionDeploymentSlotLogStreaming(app));
7580
}
7681

7782
@AzureOperation(name = "appservice.close_log_stream.app", params = {"nameFromResourceId(appId)"}, type = AzureOperation.Type.SERVICE)
@@ -95,11 +100,6 @@ private void showAppServiceStreamingLog(Project project, String resourceId, ILog
95100
final String name = logStreaming.getTitle();
96101
final AppServiceStreamingLogConsoleView consoleView = getOrCreateConsoleView(project, resourceId);
97102
if (!consoleView.isActive()) {
98-
if (!logStreaming.isLogStreamingSupported()) {
99-
AzureTaskManager.getInstance().runLater(() -> AzureMessager.getMessager()
100-
.error(message("appService.logStreaming.hint.notSupport", name), NOT_SUPPORTED));
101-
return;
102-
}
103103
if (!logStreaming.isLogStreamingEnabled()) {
104104
// Enable Log Streaming if log streaming of target is not enabled
105105
final boolean userInput = AzureMessager.getMessager()
@@ -130,10 +130,6 @@ private AppServiceStreamingLogConsoleView getOrCreateConsoleView(Project project
130130
}
131131

132132
interface ILogStreaming {
133-
default boolean isLogStreamingSupported() {
134-
return true;
135-
}
136-
137133
boolean isLogStreamingEnabled();
138134

139135
void enableLogStreaming();
@@ -144,16 +140,17 @@ default boolean isLogStreamingSupported() {
144140
Flux<String> getStreamingLogContent();
145141
}
146142

147-
static class FunctionLogStreaming implements ILogStreaming {
143+
static abstract class AbstractFunctionLogStreaming implements ILogStreaming {
148144

149145
private static final String APPINSIGHTS_INSTRUMENTATIONKEY = "APPINSIGHTS_INSTRUMENTATIONKEY";
150146
private static final String APPLICATION_INSIGHT_PATTERN = "%s/#blade/AppInsightsExtension/QuickPulseBladeV2/ComponentId/%s/ResourceId/%s";
151147
private static final String MUST_CONFIGURE_APPLICATION_INSIGHTS = message("appService.logStreaming.error.noApplicationInsights");
152148

153-
private final FunctionApp functionApp;
149+
@Getter
150+
protected final FunctionAppBase<?, ?, ?> functionApp;
154151

155-
FunctionLogStreaming(final String resourceId) {
156-
this.functionApp = Azure.az(AzureFunctions.class).functionApp(resourceId);
152+
AbstractFunctionLogStreaming(final FunctionAppBase<?,?,?> functionApp) {
153+
this.functionApp = functionApp;
157154
}
158155

159156
@Override
@@ -164,15 +161,6 @@ public boolean isLogStreamingEnabled() {
164161
return operatingSystem == OperatingSystem.LINUX || isEnableApplicationLog;
165162
}
166163

167-
@Override
168-
public void enableLogStreaming() {
169-
final DiagnosticConfig diagnosticConfig = Optional.ofNullable(functionApp.getDiagnosticConfig()).orElseGet(DiagnosticConfig::new);
170-
diagnosticConfig.setEnableApplicationLog(true);
171-
final FunctionAppDraft draft = (FunctionAppDraft) functionApp.update();
172-
draft.setDiagnosticConfig(diagnosticConfig);
173-
draft.commit();
174-
}
175-
176164
@Override
177165
public String getTitle() {
178166
return functionApp.getName();
@@ -218,6 +206,38 @@ private String getApplicationInsightLiveMetricsUrl(ApplicationInsight target, St
218206
}
219207
}
220208

209+
static class FunctionLogStreaming extends AbstractFunctionLogStreaming {
210+
211+
FunctionLogStreaming(FunctionAppBase<?, ?, ?> functionApp) {
212+
super(functionApp);
213+
}
214+
215+
@Override
216+
public void enableLogStreaming() {
217+
final DiagnosticConfig diagnosticConfig = Optional.ofNullable(getFunctionApp().getDiagnosticConfig()).orElseGet(DiagnosticConfig::new);
218+
diagnosticConfig.setEnableApplicationLog(true);
219+
final FunctionAppDraft draft = (FunctionAppDraft) getFunctionApp().update();
220+
draft.setDiagnosticConfig(diagnosticConfig);
221+
draft.commit();
222+
}
223+
}
224+
225+
static class FunctionDeploymentSlotLogStreaming extends AbstractFunctionLogStreaming {
226+
227+
FunctionDeploymentSlotLogStreaming(FunctionAppBase<?,?,?> functionApp) {
228+
super(functionApp);
229+
}
230+
231+
@Override
232+
public void enableLogStreaming() {
233+
final DiagnosticConfig diagnosticConfig = Optional.ofNullable(getFunctionApp().getDiagnosticConfig()).orElseGet(DiagnosticConfig::new);
234+
diagnosticConfig.setEnableApplicationLog(true);
235+
final FunctionAppDeploymentSlotDraft draft = (FunctionAppDeploymentSlotDraft) getFunctionApp().update();
236+
draft.setDiagnosticConfig(diagnosticConfig);
237+
draft.commit();
238+
}
239+
}
240+
221241
static class WebAppLogStreaming implements ILogStreaming {
222242
private final WebApp webApp;
223243

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/appservice/action/StartStreamingLogsAction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.microsoft.azure.toolkit.intellij.legacy.appservice.AppServiceStreamingLogManager;
1010
import com.microsoft.azure.toolkit.lib.appservice.AppServiceAppBase;
1111
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionApp;
12+
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppDeploymentSlot;
1213
import com.microsoft.azure.toolkit.lib.appservice.webapp.WebApp;
1314
import com.microsoft.azure.toolkit.lib.appservice.webapp.WebAppDeploymentSlot;
1415
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
@@ -40,7 +41,9 @@ public void execute() {
4041
} else if (appService instanceof WebAppDeploymentSlot) {
4142
AppServiceStreamingLogManager.INSTANCE.showWebAppDeploymentSlotStreamingLog(project, resourceId);
4243
} else if (appService instanceof FunctionApp) {
43-
AppServiceStreamingLogManager.INSTANCE.showFunctionStreamingLog(project, resourceId);
44+
AppServiceStreamingLogManager.INSTANCE.showFunctionStreamingLog(project, (FunctionApp) appService);
45+
} else if (appService instanceof FunctionAppDeploymentSlot) {
46+
AppServiceStreamingLogManager.INSTANCE.showFunctionDeploymentSlotStreamingLog(project, (FunctionAppDeploymentSlot) appService);
4447
} else {
4548
AzureMessager.getMessager().error("Unsupported operation", "Unsupported operation");
4649
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/deploy/FunctionDeploymentSettingEditor.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@
1111
import com.microsoft.azure.toolkit.intellij.legacy.common.AzureSettingsEditor;
1212
import com.microsoft.azure.toolkit.intellij.legacy.function.runner.deploy.ui.FunctionDeploymentPanel;
1313
import com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo;
14+
import com.microsoft.azure.toolkit.lib.common.utils.TailingDebouncer;
1415
import org.jetbrains.annotations.NotNull;
1516
import reactor.core.scheduler.Schedulers;
1617

1718
import java.util.Objects;
19+
import java.util.Optional;
1820

1921
public class FunctionDeploymentSettingEditor extends AzureSettingsEditor<FunctionDeployConfiguration> {
2022

2123
private final FunctionDeploymentPanel mainPanel;
2224
private final FunctionDeployConfiguration functionDeployConfiguration;
2325

26+
private final TailingDebouncer debouncer = new TailingDebouncer(this::updateValidationInfo, 1000);
27+
2428
public FunctionDeploymentSettingEditor(Project project, @NotNull FunctionDeployConfiguration functionDeployConfiguration) {
2529
super(project);
2630
this.mainPanel = new FunctionDeploymentPanel(project, functionDeployConfiguration);
@@ -34,12 +38,22 @@ protected void applyEditorTo(@NotNull FunctionDeployConfiguration conf) throws C
3438
.filter(i -> !i.isValid())
3539
.findAny().orElse(null);
3640
if (Objects.nonNull(error)) {
37-
mainPanel.validateAllInputsAsync().subscribeOn(Schedulers.boundedElastic()).subscribe(ignore -> this.fireEditorStateChanged());
41+
this.debouncer.debounce();
3842
final String message = error.getType() == AzureValidationInfo.Type.PENDING ? "Validating..." : error.getMessage();
3943
throw new ConfigurationException(message);
4044
}
4145
}
4246

47+
private void updateValidationInfo() {
48+
this.mainPanel.validateAllInputsAsync()
49+
.subscribeOn(Schedulers.boundedElastic())
50+
.subscribe(info -> {
51+
if (info.isValid()) {
52+
this.fireEditorStateChanged();
53+
}
54+
});
55+
}
56+
4357
@Override
4458
@NotNull
4559
protected AzureSettingPanel<FunctionDeployConfiguration> getPanel() {

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/deploy/ui/FunctionDeploymentPanel.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,9 @@ private void onSelectFunctionSlot(final DeploymentSlotConfig value) {
186186
if (value == null) {
187187
return;
188188
}
189+
toggleDeploymentSlot(chkSlot.isSelected());
189190
if (chkSlot.isSelected()) {
190-
if (value.isNewCreate()) {
191-
appSettingsTable.clear();
192-
} else {
193-
loadAppSettings(getResourceId(functionAppComboBox.getValue(), value));
194-
}
191+
loadAppSettings(getResourceId(Objects.requireNonNull(functionAppComboBox.getValue()), value), value.isNewCreate());
195192
}
196193
}
197194

@@ -204,19 +201,20 @@ private void onSelectFunctionApp(final FunctionAppConfig value) {
204201
if (StringUtils.isEmpty(value.getResourceId())) {
205202
this.chkSlot.setSelected(false);
206203
}
204+
toggleDeploymentSlot(chkSlot.isSelected());
207205
this.cbDeploymentSlot.setAppService(value.getResourceId());
208206
if (!this.chkSlot.isSelected()) {
209-
loadAppSettings(getResourceId(value, null));
207+
loadAppSettings(getResourceId(value, null), StringUtils.isEmpty(value.getResourceId()));
210208
}
211209
}
212210

213-
private void loadAppSettings(@Nullable final String resourceId) {
211+
private void loadAppSettings(@Nullable final String resourceId, final boolean isNewResource) {
214212
if (StringUtils.equalsIgnoreCase(resourceId, this.appSettingsResourceId) && MapUtils.isNotEmpty(this.appSettingsTable.getAppSettings())) {
215213
return;
216214
}
217215
this.appSettingsResourceId = resourceId;
218216
this.appSettingsTable.loadAppSettings(() -> {
219-
final AbstractAzResource<?, ?, ?> resource = StringUtils.isBlank(resourceId) ? null : Azure.az().getById(resourceId);
217+
final AbstractAzResource<?, ?, ?> resource = StringUtils.isBlank(resourceId) || isNewResource ? null : Azure.az().getById(resourceId);
220218
return resource instanceof AppServiceAppBase<?, ?, ?> ? ((AppServiceAppBase<?, ?, ?>) resource).getAppSettings() : Collections.emptyMap();
221219
});
222220
}
@@ -250,9 +248,9 @@ private void onSlotCheckBoxChanged() {
250248
final DeploymentSlotConfig slot = cbDeploymentSlot.getValue();
251249
// reload app settings when switch slot configuration
252250
if (chkSlot.isSelected() && ObjectUtils.allNotNull(function, slot)) {
253-
loadAppSettings(getResourceId(functionAppComboBox.getValue(), slot));
251+
loadAppSettings(getResourceId(functionAppComboBox.getValue(), slot), slot.isNewCreate());
254252
} else if (!chkSlot.isSelected() && Objects.nonNull(function)) {
255-
loadAppSettings(getResourceId(functionAppComboBox.getValue(), null));
253+
loadAppSettings(getResourceId(functionAppComboBox.getValue(), null), StringUtils.isEmpty(function.getResourceId()));
256254
}
257255
}
258256

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/deploy/ui/components/DeploymentSlotComboBox.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected List<ExtendableTextComponent.Extension> getExtensions() {
7070

7171
private void createResource() {
7272
final List<DeploymentSlotConfig> existingSlots = this.getItems().stream()
73-
.filter(config -> StringUtils.isNoneBlank(config.getConfigurationSource()))
73+
.filter(config -> !config.isNewCreate())
7474
.collect(Collectors.toList());
7575
final DeploymentSlotCreationDialog dialog = new DeploymentSlotCreationDialog(project, existingSlots);
7676
dialog.setOkActionListener(config -> {
@@ -92,7 +92,7 @@ protected List<? extends DeploymentSlotConfig> loadItems() throws Exception {
9292
return Collections.emptyList();
9393
}
9494
final List<DeploymentSlotConfig> result = module.list().stream().map(slot ->
95-
DeploymentSlotConfig.builder().name(slot.getName()).build()).collect(Collectors.toList());
95+
DeploymentSlotConfig.builder().name(slot.getName()).newCreate(false).build()).collect(Collectors.toList());
9696
this.draftItems.stream().filter(config -> !result.contains(config)).forEach(result::add);
9797
return result;
9898
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/function/runner/deploy/ui/components/DeploymentSlotCreationDialog.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.microsoft.azure.toolkit.intellij.common.AzureTextInput;
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;
1415
import org.apache.commons.lang3.StringUtils;
1516
import org.jetbrains.annotations.Nullable;
1617

@@ -20,23 +21,29 @@
2021
import java.util.List;
2122
import java.util.stream.Collectors;
2223

24+
import static com.microsoft.azure.toolkit.intellij.common.AzureBundle.message;
25+
import static com.microsoft.intellij.util.ValidationUtils.isValidAppServiceName;
26+
2327
public class DeploymentSlotCreationDialog extends AzureDialog<DeploymentSlotConfig> implements AzureForm<DeploymentSlotConfig> {
2428
private static final String DO_NOT_CLONE_SETTINGS = "Do not clone settings";
2529
private static final String PARENT = "parent";
2630

2731
private AzureTextInput txtName;
2832
private AzureComboBox<String> cbConfigurationSource;
2933
private JPanel pnlRoot;
34+
private final List<DeploymentSlotConfig> existingSlots;
3035

3136
public DeploymentSlotCreationDialog(@Nullable Project project, @Nonnull List<DeploymentSlotConfig> existingSlots) {
3237
super(project);
38+
this.existingSlots = existingSlots;
3339
$$$setupUI$$$();
3440
this.cbConfigurationSource.setItemsLoader(() -> {
3541
final List<String> collect = existingSlots.stream().map(DeploymentSlotConfig::getName).collect(Collectors.toList());
3642
collect.add(0, PARENT);
3743
collect.add(DO_NOT_CLONE_SETTINGS);
3844
return collect;
3945
});
46+
this.txtName.addValidator(this::validateDeploymentSlotName);
4047
super.init();
4148
}
4249

@@ -62,6 +69,7 @@ public DeploymentSlotConfig getValue() {
6269
return DeploymentSlotConfig.builder()
6370
.name(txtName.getValue())
6471
.configurationSource(source)
72+
.newCreate(true)
6573
.build();
6674
}
6775

@@ -76,6 +84,24 @@ public List<AzureFormInput<?>> getInputs() {
7684
return Arrays.asList(txtName, cbConfigurationSource);
7785
}
7886

87+
private AzureValidationInfo validateDeploymentSlotName() {
88+
final String value = txtName.getValue();
89+
if (StringUtils.isEmpty(value)) {
90+
return AzureValidationInfo.error(message("appService.name.validate.empty"), txtName);
91+
}
92+
if (value.length() < 2 || value.length() > 60) {
93+
return AzureValidationInfo.error(message("appService.name.validate.length"), txtName);
94+
}
95+
if (!isValidAppServiceName(value)) {
96+
return AzureValidationInfo.error(message("appService.name.validate.invalidName"), txtName);
97+
}
98+
final DeploymentSlotConfig existingSlot = existingSlots.stream()
99+
.filter(slot -> StringUtils.equalsIgnoreCase(slot.getName(), value))
100+
.findFirst().orElse(null);
101+
return existingSlot == null ? AzureValidationInfo.success(txtName) :
102+
AzureValidationInfo.error(String.format("Slot with name (%s) already exists", value), txtName);
103+
}
104+
79105
void $$$setupUI$$$() {
80106
}
81107
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-guidance/src/main/java/com/microsoft/azure/toolkit/ide/guidance/view/components/SummaryPanel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public SummaryPanel(@Nonnull Phase phase) {
5555

5656
@Override
5757
public void addNotify() {
58+
super.addNotify();
5859
if (this.focused) {
5960
Optional.ofNullable(defaultButton).ifPresent(button -> Optional.ofNullable(getRootPane()).ifPresent(pane -> pane.setDefaultButton(button)));
6061
}

0 commit comments

Comments
 (0)