Skip to content

Commit ba37d9f

Browse files
committed
Deprecate storage explorer for HDInsight in IntelliJ
1 parent ab875cb commit ba37d9f

File tree

4 files changed

+47
-86
lines changed

4 files changed

+47
-86
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,19 @@
3939

4040
import javax.swing.*;
4141
import javax.swing.tree.TreePath;
42-
import java.awt.*;
4342
import java.beans.PropertyChangeListener;
4443
import java.beans.PropertyChangeSupport;
4544
import java.io.IOException;
4645
import java.lang.reflect.Constructor;
4746
import java.lang.reflect.InvocationTargetException;
48-
import java.net.URI;
49-
import java.net.URISyntaxException;
5047
import java.util.ArrayList;
5148
import java.util.List;
5249
import java.util.Map;
5350

5451
public class Node implements MvpView, BasicTelemetryProperty {
5552
private static final String CLICK_ACTION = "click";
56-
private static final String REST_SEGMENT_JOB_MANAGEMENT_TENANTID = "/#@";
57-
private static final String REST_SEGMENT_JOB_MANAGEMENT_RESOURCE = "/resource";
53+
public static final String REST_SEGMENT_JOB_MANAGEMENT_TENANTID = "/#@";
54+
public static final String REST_SEGMENT_JOB_MANAGEMENT_RESOURCE = "/resource";
5855
public static final String OPEN_RESOURCES_IN_PORTAL_FAILED = "Fail to open resources in portal.";
5956
public static final String OPEN_RESOURCES_IN_PORTAL_NOT_SUPPORTED = "Open browsers is not supported in current system";
6057

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/sdk/cluster/ClusterDetail.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public String getSparkVersion() {
144144
}
145145
}
146146

147+
public String getId() {
148+
return clusterRawInfo.getId();
149+
}
150+
147151
public String getState(){
148152
ClusterProperties clusterProperties = this.clusterRawInfo.getProperties();
149153
return clusterProperties == null ? null : clusterProperties.getClusterState();

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/serverexplore/hdinsightnode/StorageAccountFolderNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ protected void refreshItems() {
7474
clusterDetail.getConfigurationInfo();
7575

7676
Optional.ofNullable(clusterDetail.getStorageAccount())
77-
.map(defaultStorageAccount -> new StorageAccountNode(this, defaultStorageAccount, true))
77+
.map(defaultStorageAccount -> new StorageAccountNode(this, defaultStorageAccount, clusterDetail,true))
7878
.ifPresent(this::addChildNode);
7979

8080
List<HDStorageAccount> additionalStorageAccount = clusterDetail.getAdditionalStorageAccounts();
8181
if (additionalStorageAccount != null) {
8282
for (HDStorageAccount account : additionalStorageAccount) {
83-
addChildNode(new StorageAccountNode(this, account, false));
83+
addChildNode(new StorageAccountNode(this, account, clusterDetail, false));
8484
}
8585
}
8686
}

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/serverexplore/hdinsightnode/StorageAccountNode.java

Lines changed: 39 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -23,109 +23,69 @@
2323

2424
import com.microsoft.azure.hdinsight.common.CommonConst;
2525
import com.microsoft.azure.hdinsight.common.logger.ILogger;
26-
import com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount;
26+
import com.microsoft.azure.hdinsight.sdk.cluster.ClusterDetail;
27+
import com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail;
2728
import com.microsoft.azure.hdinsight.sdk.storage.IHDIStorageAccount;
2829
import com.microsoft.azure.hdinsight.sdk.storage.StorageAccountType;
29-
import com.microsoft.azure.storage.CloudStorageAccount;
30-
import com.microsoft.azure.storage.StorageException;
31-
import com.microsoft.azure.storage.blob.BlobContainerPermissions;
32-
import com.microsoft.azure.storage.blob.BlobContainerProperties;
33-
import com.microsoft.azure.storage.blob.CloudBlobContainer;
30+
import com.microsoft.azuretools.authmanage.AuthMethodManager;
3431
import com.microsoft.azuretools.azurecommons.helpers.AzureCmdException;
3532
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
36-
import com.microsoft.azuretools.azurecommons.helpers.StringHelper;
33+
import com.microsoft.azuretools.sdkmanage.AzureManager;
3734
import com.microsoft.azuretools.telemetry.AppInsightsConstants;
3835
import com.microsoft.azuretools.telemetry.TelemetryConstants;
3936
import com.microsoft.azuretools.telemetry.TelemetryProperties;
4037
import com.microsoft.tooling.msservices.components.DefaultLoader;
41-
import com.microsoft.tooling.msservices.model.storage.BlobContainer;
4238
import com.microsoft.tooling.msservices.serviceexplorer.Node;
43-
import com.microsoft.tooling.msservices.serviceexplorer.RefreshableNode;
44-
import org.apache.commons.lang3.exception.ExceptionUtils;
39+
import com.microsoft.tooling.msservices.serviceexplorer.NodeActionEvent;
40+
import com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener;
4541

46-
import java.net.URISyntaxException;
47-
import java.security.InvalidKeyException;
48-
import java.util.Calendar;
49-
import java.util.GregorianCalendar;
42+
import java.io.IOException;
5043
import java.util.HashMap;
5144
import java.util.Map;
52-
import java.util.stream.Stream;
53-
import java.util.stream.StreamSupport;
5445

55-
public class StorageAccountNode extends RefreshableNode implements TelemetryProperties, ILogger {
46+
public class StorageAccountNode extends Node implements TelemetryProperties, ILogger {
5647
private static final String STORAGE_ACCOUNT_MODULE_ID = StorageAccountNode.class.getName();
5748
private static final String ICON_PATH = CommonConst.StorageAccountIConPath;
5849
private static final String ADLS_ICON_PATH = CommonConst.ADLS_STORAGE_ACCOUNT_ICON_PATH;
5950
private static final String DEFAULT_STORAGE_FLAG = "(default)";
51+
private static final String REST_SEGMENT_STORAGE_ACCOUNT = "/storageaccounts";
6052

6153
private IHDIStorageAccount storageAccount;
54+
@NotNull
55+
private IClusterDetail clusterDetail;
6256

63-
public StorageAccountNode(Node parent, @NotNull IHDIStorageAccount storageAccount, boolean isDefaultStorageAccount) {
57+
public StorageAccountNode(Node parent, @NotNull IHDIStorageAccount storageAccount, @NotNull IClusterDetail clusterDetail, boolean isDefaultStorageAccount) {
6458
super(STORAGE_ACCOUNT_MODULE_ID, isDefaultStorageAccount ? storageAccount.getName() + DEFAULT_STORAGE_FLAG : storageAccount.getName(), parent, getIconPath(storageAccount));
6559
this.storageAccount = storageAccount;
60+
this.clusterDetail = clusterDetail;
61+
loadAdditionalActions();
6662
}
6763

68-
private Stream<BlobContainer> getBlobContainers(String connectionString) throws AzureCmdException {
69-
CloudStorageAccount cloudStorageAccount;
70-
try {
71-
cloudStorageAccount = CloudStorageAccount.parse(connectionString);
72-
} catch (URISyntaxException | InvalidKeyException e) {
73-
throw new AzureCmdException(e.getMessage());
74-
}
75-
76-
Iterable<CloudBlobContainer> containers = cloudStorageAccount.createCloudBlobClient().listContainers();
77-
return StreamSupport.stream(containers.spliterator(), false).map((container) -> {
78-
BlobContainerPermissions permissions = null ;
79-
String access = null;
80-
try {
81-
permissions = container.downloadPermissions();
82-
} catch (StorageException e) {
83-
// ignore the exception
84-
// We need not to know the permission since the HDInsight cluster itself do have 'write' access to storage
85-
}
86-
if (permissions != null) {
87-
access = permissions.getPublicAccess().toString();
88-
}
89-
String name = container.getName();
90-
String eTag = null;
91-
92-
String uri = container.getUri().toString();
93-
Calendar lastModified = new GregorianCalendar();
94-
BlobContainerProperties properties = container.getProperties();
95-
96-
if (properties != null) {
97-
eTag = properties.getEtag();
98-
lastModified.setTime(properties.getLastModified());
99-
}
100-
return new BlobContainer(name, uri, eTag, lastModified, access);
101-
});
102-
}
103-
104-
@Override
105-
protected void refreshItems() {
106-
try {
107-
if (storageAccount.getAccountType() == StorageAccountType.BLOB) {
108-
HDStorageAccount blobStorageAccount = (HDStorageAccount) storageAccount;
109-
String defaultContainer = blobStorageAccount.getDefaultContainer();
110-
final String connectionString = ((HDStorageAccount) storageAccount).getConnectionString();
111-
getBlobContainers(connectionString).forEach(blobContainer -> {
112-
addChildNode(new BlobContainerNode(this, blobStorageAccount, blobContainer, !StringHelper.isNullOrWhiteSpace(defaultContainer) && defaultContainer.equals(blobContainer.getName())));
113-
});
114-
} else {
115-
StringBuilder sb = new StringBuilder();
116-
sb.append("Can't refresh the storage account since unsupported storage account type: " + storageAccount.getAccountType() + "\n");
117-
sb.append("Account name: " + storageAccount.getName() + "\n");
118-
sb.append("Subscription ID: " + storageAccount.getSubscriptionId() + "\n");
119-
sb.append("Default storage schema: " + storageAccount.getDefaultStorageSchema() + "\n");
120-
sb.append("Default container or root path: " + storageAccount.getDefaultContainerOrRootPath() + "\n");
121-
log().warn(sb.toString());
122-
}
123-
} catch (Exception ex) {
124-
String exceptionMsg = ex.getCause() == null ? "" : ex.getCause().getMessage();
125-
String errorHint = String.format("Failed to load storage account %s. ", storageAccount.getName());
126-
log().warn(errorHint + ExceptionUtils.getStackTrace(ex));
127-
128-
DefaultLoader.getUIHelper().showError(errorHint + exceptionMsg, "HDInsight Explorer");
64+
protected void loadAdditionalActions() {
65+
if (clusterDetail instanceof ClusterDetail) {
66+
addAction("Open Storage in Azure Management Portal", new NodeActionListener() {
67+
@Override
68+
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
69+
try {
70+
final AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
71+
// not signed in
72+
if (azureManager == null) {
73+
return;
74+
}
75+
final String portalUrl = azureManager.getPortalUrl();
76+
final String tenantId = clusterDetail.getSubscription().getTenantId();
77+
String url = portalUrl
78+
+ REST_SEGMENT_JOB_MANAGEMENT_TENANTID
79+
+ tenantId
80+
+ REST_SEGMENT_JOB_MANAGEMENT_RESOURCE
81+
+ ((ClusterDetail) clusterDetail).getId()
82+
+ REST_SEGMENT_STORAGE_ACCOUNT;
83+
DefaultLoader.getIdeHelper().openLinkInBrowser(url);
84+
} catch (IOException ex) {
85+
throw new AzureCmdException(OPEN_RESOURCES_IN_PORTAL_FAILED, ex);
86+
}
87+
}
88+
});
12989
}
13090
}
13191

0 commit comments

Comments
 (0)