Skip to content

Commit 733955b

Browse files
committed
Make the Storage Explorer workable with null storage account.
Signed-off-by: Wei Zhang <[email protected]>
1 parent 44c700a commit 733955b

File tree

8 files changed

+29
-10
lines changed

8 files changed

+29
-10
lines changed

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/common/ClusterManagerEx.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ synchronized Optional<List<IClusterDetail>> getSubscriptionHDInsightClustersOfTy
175175
}
176176
}
177177

178-
List<IClusterDetail> getHdinsightAdditionalClusterDetails() {
178+
public List<IClusterDetail> getHdinsightAdditionalClusterDetails() {
179179
return hdinsightAdditionalClusterDetails;
180180
}
181181

@@ -293,6 +293,7 @@ public synchronized void removeHDInsightAdditionalCluster(HDInsightAdditionalClu
293293
return 1: cluster already exist in current cluster list
294294
return 2: cluster is valid to add to cluster list but storage account is not default
295295
*/
296+
@Deprecated
296297
public int isHDInsightAdditionalStorageExist(String clusterName, String storageName) {
297298
final ImmutableList<IClusterDetail> cachedClusterDetails =
298299
Optional.of(ClusterMetaDataService.getInstance().getCachedClusterDetails())

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.microsoft.azure.hdinsight.sdk.storage.IHDIStorageAccount;
66
import com.microsoft.azuretools.authmanage.models.SubscriptionDetail;
77
import com.microsoft.azuretools.azurecommons.helpers.AzureCmdException;
8+
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
89

910
import java.io.IOException;
1011
import java.util.List;
@@ -120,6 +121,7 @@ public String getResourceGroup() {
120121
}
121122

122123
@Override
124+
@Nullable
123125
public IHDIStorageAccount getStorageAccount() throws HDIException {
124126
return null;
125127
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.microsoft.azuretools.authmanage.AuthMethodManager;
3131
import com.microsoft.azuretools.authmanage.Environment;
3232
import com.microsoft.azuretools.authmanage.models.SubscriptionDetail;
33+
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
3334
import com.microsoft.azuretools.sdkmanage.AzureManager;
3435

3536
import java.io.IOException;
@@ -43,9 +44,10 @@ public class HDInsightAdditionalClusterDetail implements IClusterDetail {
4344
private String passWord;
4445

4546
@Expose
47+
@Nullable
4648
private HDStorageAccount defaultStorageAccount;
4749

48-
public HDInsightAdditionalClusterDetail(String clusterName, String userName, String passWord, HDStorageAccount storageAccount) {
50+
public HDInsightAdditionalClusterDetail(String clusterName, String userName, String passWord, @Nullable HDStorageAccount storageAccount) {
4951
this.clusterName = clusterName;
5052
this.userName = userName;
5153
this.passWord = passWord;
@@ -139,6 +141,7 @@ public String getOSType() {
139141
}
140142

141143
@Override
144+
@Nullable
142145
public IHDIStorageAccount getStorageAccount() throws HDIException {
143146
return defaultStorageAccount;
144147
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.microsoft.azure.hdinsight.sdk.storage.IHDIStorageAccount;
2828
import com.microsoft.azuretools.authmanage.models.SubscriptionDetail;
2929
import com.microsoft.azuretools.azurecommons.helpers.AzureCmdException;
30+
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
3031

3132
import java.io.IOException;
3233
import java.util.List;
@@ -65,7 +66,7 @@ public interface IClusterDetail {
6566

6667
String getResourceGroup();
6768

68-
IHDIStorageAccount getStorageAccount() throws HDIException;
69+
@Nullable IHDIStorageAccount getStorageAccount() throws HDIException;
6970

7071
List<HDStorageAccount> getAdditionalStorageAccounts();
7172

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/sdk/storage/HDStorageAccount.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail;
2525
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
26+
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
2627
import com.microsoft.tooling.msservices.model.storage.ClientStorageAccount;
2728

2829
public class HDStorageAccount extends ClientStorageAccount implements IHDIStorageAccount {
@@ -31,7 +32,7 @@ public class HDStorageAccount extends ClientStorageAccount implements IHDIStorag
3132
private String defaultContainer;
3233
private IClusterDetail clusterDetail;
3334

34-
public HDStorageAccount(IClusterDetail clusterDetail, String fullStorageBlobName, String key, boolean isDefault, String defaultContainer) {
35+
public HDStorageAccount(@Nullable IClusterDetail clusterDetail, String fullStorageBlobName, String key, boolean isDefault, String defaultContainer) {
3536
super(getStorageShortName(fullStorageBlobName));
3637
this.setPrimaryKey(key);
3738
this.fullStorageBlobName = fullStorageBlobName;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.microsoft.azure.hdinsight.common.*;
2525
import com.microsoft.azure.hdinsight.sdk.cluster.*;
2626
import com.microsoft.azure.hdinsight.sdk.common.CommonConstant;
27+
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
2728
import com.microsoft.azuretools.azurecommons.helpers.StringHelper;
2829
import com.microsoft.azuretools.telemetry.AppInsightsConstants;
2930
import com.microsoft.azuretools.telemetry.TelemetryProperties;
@@ -43,9 +44,10 @@ public class ClusterNode extends RefreshableNode implements TelemetryProperties
4344
private static final String CLUSTER_MODULE_ID = ClusterNode.class.getName();
4445
private static final String ICON_PATH = CommonConst.ClusterIConPath;
4546

47+
@NotNull
4648
private IClusterDetail clusterDetail;
4749

48-
public ClusterNode(Node parent, IClusterDetail clusterDetail) {
50+
public ClusterNode(Node parent, @NotNull IClusterDetail clusterDetail) {
4951
super(CLUSTER_MODULE_ID, getClusterNameWitStatus(clusterDetail), parent, ICON_PATH, true);
5052
this.clusterDetail = clusterDetail;
5153
this.loadActions();
@@ -160,7 +162,7 @@ private static String getClusterNameWitStatus(IClusterDetail clusterDetail) {
160162
}
161163

162164
private void openUrlLink(String linkUrl) {
163-
if (clusterDetail != null && !StringHelper.isNullOrWhiteSpace(clusterDetail.getName())) {
165+
if (!StringHelper.isNullOrWhiteSpace(clusterDetail.getName())) {
164166
try {
165167
Desktop.getDesktop().browse(new URI(linkUrl));
166168
} catch (Exception exception) {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,24 @@
2424
import com.microsoft.azure.hdinsight.common.CommonConst;
2525
import com.microsoft.azure.hdinsight.sdk.cluster.IClusterDetail;
2626
import com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount;
27+
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
2728
import com.microsoft.tooling.msservices.components.DefaultLoader;
2829
import com.microsoft.azuretools.azurecommons.helpers.AzureCmdException;
2930
import com.microsoft.tooling.msservices.serviceexplorer.Node;
3031
import com.microsoft.tooling.msservices.serviceexplorer.RefreshableNode;
3132
import com.microsoft.tooling.msservices.serviceexplorer.azure.storage.asm.StorageNode;
3233

3334
import java.util.List;
35+
import java.util.Optional;
3436

3537
public class StorageAccountFolderNode extends RefreshableNode {
3638
private static final String STORAGE_ACCOUNT_FOLDER_MODULE_ID = StorageAccountFolderNode.class.getName();
3739
private static final String STORAGE_ACCOUNT_NAME = "Storage Accounts";
3840
private static final String ICON_PATH = CommonConst.StorageAccountFoldIConPath;
3941

42+
@NotNull
4043
private IClusterDetail clusterDetail;
41-
public StorageAccountFolderNode(Node parent, IClusterDetail clusterDetail) {
44+
public StorageAccountFolderNode(Node parent, @NotNull IClusterDetail clusterDetail) {
4245
super(STORAGE_ACCOUNT_FOLDER_MODULE_ID, STORAGE_ACCOUNT_NAME, parent, ICON_PATH);
4346
this.clusterDetail = clusterDetail;
4447
load(false);
@@ -47,10 +50,14 @@ public StorageAccountFolderNode(Node parent, IClusterDetail clusterDetail) {
4750
@Override
4851
protected void refreshItems()
4952
throws AzureCmdException {
50-
if (clusterDetail != null && !clusterDetail.isEmulator()) {
53+
if (!clusterDetail.isEmulator()) {
5154
try {
5255
clusterDetail.getConfigurationInfo();
53-
addChildNode(new StorageAccountNode(this, clusterDetail.getStorageAccount(), true));
56+
57+
Optional.ofNullable(clusterDetail.getStorageAccount())
58+
.map(defaultStorageAccount -> new StorageAccountNode(this, defaultStorageAccount, true))
59+
.ifPresent(this::addChildNode);
60+
5461
List<HDStorageAccount> additionalStorageAccount = clusterDetail.getAdditionalStorageAccounts();
5562
if (additionalStorageAccount != null) {
5663
for (HDStorageAccount account : additionalStorageAccount) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import com.microsoft.azure.storage.blob.BlobContainerProperties;
3232
import com.microsoft.azure.storage.blob.CloudBlobContainer;
3333
import com.microsoft.azuretools.azurecommons.helpers.AzureCmdException;
34+
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
35+
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
3436
import com.microsoft.azuretools.azurecommons.helpers.StringHelper;
3537
import com.microsoft.azuretools.telemetry.AppInsightsConstants;
3638
import com.microsoft.azuretools.telemetry.TelemetryProperties;
@@ -52,7 +54,7 @@ public class StorageAccountNode extends RefreshableNode implements TelemetryProp
5254

5355
private IHDIStorageAccount storageAccount;
5456

55-
public StorageAccountNode(Node parent, IHDIStorageAccount storageAccount, boolean isDefaultStorageAccount) {
57+
public StorageAccountNode(Node parent, @NotNull IHDIStorageAccount storageAccount, boolean isDefaultStorageAccount) {
5658
super(STORAGE_ACCOUNT_MODULE_ID, isDefaultStorageAccount ? storageAccount.getName() + DEFAULT_STORAGE_FLAG : storageAccount.getName(), parent, getIconPath(storageAccount));
5759
this.storageAccount = storageAccount;
5860
load(false);

0 commit comments

Comments
 (0)