3838import com .microsoft .azuretools .azurecommons .helpers .StringHelper ;
3939import com .microsoft .azuretools .sdkmanage .AzureManager ;
4040import com .microsoft .tooling .msservices .components .DefaultLoader ;
41+
42+ import org .apache .commons .lang3 .StringUtils ;
4143import org .apache .commons .lang3 .exception .ExceptionUtils ;
4244import rx .Observable ;
4345
4951import java .util .stream .Collectors ;
5052import java .util .stream .Stream ;
5153
54+ import static java .util .Collections .emptyList ;
55+
5256public class ClusterManagerEx implements ILogger {
5357
5458 private static final String OSTYPE = "linux" ;
@@ -404,7 +408,7 @@ private void saveAdditionalClusters() {
404408 DefaultLoader .getIdeHelper ().setApplicationProperty (CommonConst .SQL_BIG_DATA_LIVY_LINK_CLUSTERS , sqlBigDatalivyLinkClustersJson );
405409 }
406410
407- List <IClusterDetail > loadAdditionalClusters () {
411+ synchronized List <IClusterDetail > loadAdditionalClusters () {
408412 List <IClusterDetail > hdiAdditionalClusters = new ArrayList <>();
409413 List <IClusterDetail > hdiAdditionalMfaClusters = new ArrayList <>();
410414 List <IClusterDetail > hdiLivyLinkClusters = new ArrayList <>();
@@ -416,26 +420,37 @@ List<IClusterDetail> loadAdditionalClusters() {
416420 String additionalMfaClustersJson = DefaultLoader .getIdeHelper ().getApplicationProperty (CommonConst .HDINSIGHT_ADDITIONAL_MFA_CLUSTERS );
417421 String livyLinkClustersJson = DefaultLoader .getIdeHelper ().getApplicationProperty (CommonConst .HDINSIGHT_LIVY_LINK_CLUSTERS );
418422 String sqlBigDataClustersJson = DefaultLoader .getIdeHelper ().getApplicationProperty (CommonConst .SQL_BIG_DATA_LIVY_LINK_CLUSTERS );
419- if (!StringHelper .isNullOrWhiteSpace (additionalClustersJson ) && !StringHelper .isNullOrWhiteSpace (livyLinkClustersJson )) {
420- try {
421- hdiAdditionalClusters = gson .fromJson (additionalClustersJson , new TypeToken <ArrayList <HDInsightAdditionalClusterDetail >>() {
422- }.getType ());
423- hdiAdditionalMfaClusters = gson .fromJson (additionalMfaClustersJson , new TypeToken <ArrayList <MfaHdiAdditionalClusterDetail >>() {
424- }.getType ());
425- hdiLivyLinkClusters = gson .fromJson (livyLinkClustersJson , new TypeToken <ArrayList <HDInsightLivyLinkClusterDetail >>() {
426- }.getType ());
427- sqlBigDataClusters = gson .fromJson (sqlBigDataClustersJson , new TypeToken <ArrayList <SqlBigDataLivyLinkClusterDetail >>() {
428- }.getType ());
429- } catch (JsonSyntaxException e ) {
430- isListAdditionalClusterSuccess = false ;
431- // clear local cache if we cannot get information from local json
432- DefaultLoader .getIdeHelper ().unsetApplicationProperty (CommonConst .HDINSIGHT_ADDITIONAL_CLUSTERS );
433- DefaultLoader .getIdeHelper ().unsetApplicationProperty (CommonConst .HDINSIGHT_ADDITIONAL_MFA_CLUSTERS );
434- DefaultLoader .getIdeHelper ().unsetApplicationProperty (CommonConst .HDINSIGHT_LIVY_LINK_CLUSTERS );
435- DefaultLoader .getIdeHelper ().unsetApplicationProperty (CommonConst .SQL_BIG_DATA_LIVY_LINK_CLUSTERS );
436- DefaultLoader .getUIHelper ().showException ("Failed to list linked clusters" , e , "List Linked Clusters" , false , true );
437- return new ArrayList <>();
438- }
423+
424+ try {
425+ hdiAdditionalClusters = StringUtils .isBlank (additionalClustersJson )
426+ ? emptyList ()
427+ : gson .fromJson (additionalClustersJson ,
428+ new TypeToken <ArrayList <HDInsightAdditionalClusterDetail >>() { }.getType ());
429+
430+ hdiAdditionalMfaClusters = StringUtils .isBlank (additionalMfaClustersJson )
431+ ? emptyList ()
432+ : gson .fromJson (additionalMfaClustersJson ,
433+ new TypeToken <ArrayList <MfaHdiAdditionalClusterDetail >>() { }.getType ());
434+
435+ hdiLivyLinkClusters = StringUtils .isBlank (livyLinkClustersJson )
436+ ? emptyList ()
437+ : gson .fromJson (livyLinkClustersJson ,
438+ new TypeToken <ArrayList <HDInsightLivyLinkClusterDetail >>() { }.getType ());
439+
440+ sqlBigDataClusters = StringUtils .isBlank (sqlBigDataClustersJson )
441+ ? emptyList ()
442+ : gson .fromJson (sqlBigDataClustersJson ,
443+ new TypeToken <ArrayList <SqlBigDataLivyLinkClusterDetail >>() { }.getType ());
444+
445+ } catch (JsonSyntaxException e ) {
446+ isListAdditionalClusterSuccess = false ;
447+ // clear local cache if we cannot get information from local json
448+ DefaultLoader .getIdeHelper ().unsetApplicationProperty (CommonConst .HDINSIGHT_ADDITIONAL_CLUSTERS );
449+ DefaultLoader .getIdeHelper ().unsetApplicationProperty (CommonConst .HDINSIGHT_ADDITIONAL_MFA_CLUSTERS );
450+ DefaultLoader .getIdeHelper ().unsetApplicationProperty (CommonConst .HDINSIGHT_LIVY_LINK_CLUSTERS );
451+ DefaultLoader .getIdeHelper ().unsetApplicationProperty (CommonConst .SQL_BIG_DATA_LIVY_LINK_CLUSTERS );
452+ DefaultLoader .getUIHelper ().showException ("Failed to list linked clusters" , e , "List Linked Clusters" , false , true );
453+ return new ArrayList <>();
439454 }
440455
441456 isListAdditionalClusterSuccess = true ;
0 commit comments