Skip to content

Commit a0b9beb

Browse files
committed
Merge branch 'develop' into qianjin-sqlserver
# Conflicts: # Utils/azure-explorer-common/pom.xml # Utils/pom.xml
2 parents 9cad4b1 + b154ebc commit a0b9beb

File tree

18 files changed

+174
-348
lines changed

18 files changed

+174
-348
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/helpers/UIHelperImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,16 @@ public void openSpringCloudAppPropertyView(SpringCloudAppNode node) {
424424
showError(CANNOT_GET_FILE_EDITOR_MANAGER, UNABLE_TO_OPEN_EDITOR_WINDOW);
425425
return;
426426
}
427-
final String id = node.getAppId();
427+
final String id = node.getApp().entity().getId();
428428
final String subscription = getSubscriptionId(id);
429-
final String appName = node.getAppName();
429+
final String appName = node.getApp().name();
430430
final LightVirtualFile existing = searchExistingFile(fileEditorManager, SPRING_CLOUD_APP_PROPERTY_TYPE, id);
431431
final LightVirtualFile itemVirtualFile = Objects.isNull(existing) ? createVirtualFile(appName, subscription, id) : existing;
432432
if (Objects.isNull(existing)) {
433433
itemVirtualFile.setFileType(new AzureFileType(SPRING_CLOUD_APP_PROPERTY_TYPE, AzureIconLoader.loadIcon(AzureIconSymbol.SpringCloud.MODULE)));
434434
}
435435
AzureTaskManager.getInstance().runInModal(String.format("Loading properties of app(%s)", appName), () -> {
436-
final SpringCloudCluster cluster = Azure.az(AzureSpringCloud.class).subscription(subscription).cluster(node.getClusterName());
436+
final SpringCloudCluster cluster = node.getApp().getCluster();
437437
final SpringCloudApp app = Objects.requireNonNull(cluster).app(appName);
438438
itemVirtualFile.putUserData(SpringCloudAppPropertiesEditorProvider.APP_KEY, app);
439439
AzureTaskManager.getInstance().runLater(() -> fileEditorManager.openFile(itemVirtualFile, true, true));
@@ -489,7 +489,8 @@ public void openContainerRegistryPropertyView(@NotNull ContainerRegistryNode nod
489489
ContainerRegistryPropertyViewProvider.TYPE, resId);
490490
if (itemVirtualFile == null) {
491491
itemVirtualFile = createVirtualFile(registryName, sid, resId);
492-
AzureFileType fileType = new AzureFileType(ContainerRegistryPropertyViewProvider.TYPE, AzureIconLoader.loadIcon(AzureIconSymbol.ContainerRegistry.MODULE));
492+
AzureFileType fileType = new AzureFileType(ContainerRegistryPropertyViewProvider.TYPE,
493+
AzureIconLoader.loadIcon(AzureIconSymbol.ContainerRegistry.MODULE));
493494
itemVirtualFile.setFileType(fileType);
494495
}
495496
FileEditor[] editors = fileEditorManager.openFile(itemVirtualFile, true /*focusEditor*/, true /*searchForOpen*/);

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/ui/DeviceLoginUI.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
import lombok.Setter;
1515
import org.jetbrains.annotations.NotNull;
1616
import org.jetbrains.annotations.Nullable;
17-
import reactor.core.Disposable;
17+
18+
import java.util.concurrent.Future;
1819

1920

2021
public class DeviceLoginUI implements IDeviceLoginUI {
2122
private DeviceLoginWindow deviceLoginWindow;
2223

2324
@Setter
24-
private Disposable disposable;
25+
private Future future;
2526

2627
@Nullable
2728
@Override
@@ -45,8 +46,8 @@ public void closePrompt() {
4546

4647
@Override
4748
public void cancel() {
48-
if (disposable != null) {
49-
this.disposable.dispose();
49+
if (future != null) {
50+
this.future.cancel(true);
5051
}
5152
}
5253
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/ui/SignInWindow.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.intellij.openapi.fileChooser.FileChooser;
1111
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
1212
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
13+
import com.intellij.openapi.progress.ProcessCanceledException;
1314
import com.intellij.openapi.progress.ProgressIndicator;
1415
import com.intellij.openapi.progress.ProgressManager;
1516
import com.intellij.openapi.project.Project;
@@ -49,7 +50,6 @@
4950
import reactor.core.scheduler.Schedulers;
5051
import reactor.util.function.Tuple2;
5152
import rx.Single;
52-
import rx.exceptions.Exceptions;
5353

5454
import javax.swing.*;
5555
import java.awt.*;
@@ -58,6 +58,7 @@
5858
import java.util.List;
5959
import java.util.*;
6060
import java.util.concurrent.Callable;
61+
import java.util.concurrent.CancellationException;
6162
import java.util.concurrent.CompletableFuture;
6263
import java.util.stream.Stream;
6364

@@ -66,7 +67,6 @@
6667
public class SignInWindow extends AzureDialogWrapper {
6768
private static final Logger LOGGER = Logger.getInstance(SignInWindow.class);
6869
private static final String SIGN_IN_ERROR = "Sign In Error";
69-
private static final String USER_CANCEL = "user cancel";
7070

7171
private JPanel contentPane;
7272

@@ -215,21 +215,26 @@ public Single<AuthMethodDetails> login() {
215215
}
216216

217217
private static AuthMethodDetails checkCanceled(ProgressIndicator indicator, Mono<? extends AuthMethodDetails> mono) {
218-
CompletableFuture<AuthMethodDetails> loginFuture = new CompletableFuture<>();
218+
CompletableFuture<? extends AuthMethodDetails> future = mono.toFuture();
219219
Disposable disposable = Flux.interval(Duration.ofSeconds(1)).map(ts -> {
220-
if (indicator != null && indicator.isCanceled()) {
221-
IllegalStateException e = new IllegalStateException(USER_CANCEL);
222-
loginFuture.completeExceptionally(e);
223-
throw e;
220+
if (indicator != null) {
221+
indicator.checkCanceled();
224222
}
225223
return 1;
226-
}).onErrorResume(e -> Mono.empty()).subscribe();
227-
mono.doOnError(loginFuture::completeExceptionally).doOnSuccess(loginFuture::complete).doFinally(e -> disposable.dispose()).subscribe();
224+
}).onErrorResume(e -> {
225+
if (e instanceof ProcessCanceledException) {
226+
future.cancel(true);
227+
}
228+
return Mono.empty();
229+
}).subscribeOn(Schedulers.boundedElastic()).subscribe();
228230
try {
229-
return loginFuture.get();
230-
} catch (Throwable ex) {
231-
Throwable e = Exceptions.getFinalCause(ex);
232-
throw new AzureToolkitRuntimeException("Cannot login due to error: " + ex.getMessage(), ex);
231+
return future.get();
232+
} catch (CancellationException e) {
233+
return null;
234+
} catch (Throwable e) {
235+
throw new AzureToolkitRuntimeException("Cannot login due to error: " + e.getMessage(), e);
236+
} finally {
237+
disposable.dispose();
233238
}
234239
}
235240

@@ -334,25 +339,22 @@ private synchronized AuthMethodDetails doDeviceLogin() {
334339
final IDeviceLoginUI deviceLoginUI = CommonSettings.getUiFactory().getDeviceLoginUI();
335340
final AzureAccount az = com.microsoft.azure.toolkit.lib.Azure.az(AzureAccount.class);
336341
final Account account = az.loginAsync(AuthType.DEVICE_CODE, true).block();
337-
Disposable subscribe = account.continueLogin().doOnCancel(() -> {
338-
deviceCodeLoginFuture.completeExceptionally(new IllegalStateException("user cancel"));
339-
}).doOnSuccess(ac -> {
340-
deviceCodeLoginFuture.complete(fromAccountEntity(ac.getEntity()));
341-
}).doOnError(deviceCodeLoginFuture::completeExceptionally).doFinally(signal -> {
342-
deviceLoginUI.closePrompt();
343-
}).subscribe();
344-
deviceLoginUI.setDisposable(subscribe);
342+
343+
CompletableFuture<AuthMethodDetails> future =
344+
account.continueLogin().map(ac -> fromAccountEntity(ac.getEntity())).doFinally(signal -> {
345+
deviceLoginUI.closePrompt();
346+
}).toFuture();
347+
deviceLoginUI.setFuture(future);
345348
if (ApplicationManager.getApplication().isDispatchThread()) {
346349
deviceLoginUI.promptDeviceCode(((DeviceCodeAccount) account).getDeviceCode());
347350
} else {
348351
AzureTaskManager.getInstance().runAndWait(() ->
349352
deviceLoginUI.promptDeviceCode(((DeviceCodeAccount) account).getDeviceCode()));
350353
}
351-
return Mono.fromFuture(deviceCodeLoginFuture).block();
354+
return future.get();
352355

353356
} catch (Exception ex) {
354-
if (ex instanceof IllegalStateException && USER_CANCEL.equals(ex.getMessage())) {
355-
} else {
357+
if (!(ex instanceof CancellationException)) {
356358
ex.printStackTrace();
357359
ErrorWindow.show(project, ex.getMessage(), SIGN_IN_ERROR);
358360
}

Utils/azure-explorer-common/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@
123123
<groupId>com.microsoft.azure</groupId>
124124
<artifactId>azure-toolkit-sqlserver-lib</artifactId>
125125
</dependency>
126+
<dependency>
127+
<groupId>com.microsoft.azure</groupId>
128+
<artifactId>azure-toolkit-springcloud-lib</artifactId>
129+
</dependency>
126130
<dependency>
127131
<groupId>com.microsoft.azure.functions</groupId>
128132
<artifactId>azure-functions-java-library</artifactId>

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/azure/springcloud/SpringCloudAppEvent.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
package com.microsoft.tooling.msservices.serviceexplorer.azure.springcloud;
77

8-
import com.microsoft.azure.management.appplatform.v2020_07_01.implementation.AppResourceInner;
9-
import com.microsoft.azure.management.appplatform.v2020_07_01.implementation.DeploymentResourceInner;
8+
import com.microsoft.azure.toolkit.lib.springcloud.SpringCloudApp;
9+
import com.microsoft.azure.toolkit.lib.springcloud.SpringCloudDeployment;
10+
import org.apache.commons.lang3.StringUtils;
1011

1112
public class SpringCloudAppEvent {
1213
enum EventKind {
@@ -15,15 +16,17 @@ enum EventKind {
1516
private EventKind kind;
1617
private String id;
1718
private String clusterId;
18-
private AppResourceInner appInner;
19-
private DeploymentResourceInner deploymentInner;
19+
private SpringCloudApp app;
20+
private SpringCloudDeployment deployment;
2021

21-
public SpringCloudAppEvent(EventKind kind, String clusterId, AppResourceInner appInner, DeploymentResourceInner deploymentInner) {
22+
public SpringCloudAppEvent(EventKind kind, String clusterId, SpringCloudApp app) {
2223
this.kind = kind;
2324
this.clusterId = clusterId;
24-
this.appInner = appInner;
25-
this.id = appInner == null ? null : appInner.id();
26-
this.deploymentInner = deploymentInner;
25+
this.app = app;
26+
this.id = app == null ? null : app.entity().getId();
27+
if (StringUtils.isNotBlank(app.getActiveDeploymentName())) {
28+
this.deployment = app.deployment(app.getActiveDeploymentName());
29+
}
2730
}
2831

2932
public SpringCloudAppEvent(EventKind kind, String clusterId, String id) {
@@ -44,12 +47,12 @@ public String getClusterId() {
4447
return clusterId;
4548
}
4649

47-
public AppResourceInner getAppInner() {
48-
return appInner;
50+
public SpringCloudApp getApp() {
51+
return app;
4952
}
5053

51-
public DeploymentResourceInner getDeploymentInner() {
52-
return deploymentInner;
54+
public SpringCloudDeployment getDeployment() {
55+
return deployment;
5356
}
5457

5558
public boolean isDelete() {

0 commit comments

Comments
 (0)