2323
2424import static com .microsoft .azuretools .telemetry .TelemetryConstants .HDINSIGHT ;
2525
26- import com .google .common .reflect .TypeToken ;
27- import com .google .gson .Gson ;
28- import com .microsoft .azure .hdinsight .common .ClusterManagerEx ;
29- import com .microsoft .azure .hdinsight .sdk .cluster .IClusterDetail ;
30- import com .microsoft .azure .hdinsight .sdk .common .AuthenticationException ;
31- import com .microsoft .azure .hdinsight .sdk .common .HDIException ;
32- import com .microsoft .azure .hdinsight .sdk .common .HttpResponse ;
33- import com .microsoft .azure .hdinsight .spark .common .SparkBatchSubmission ;
34- import com .microsoft .azure .hdinsight .spark .common .SparkSubmissionParameter ;
35- import com .microsoft .azure .hdinsight .spark .common .SparkSubmitResponse ;
36- import com .microsoft .azure .hdinsight .spark .jobs .JobUtils ;
37- import com .microsoft .azuretools .telemetrywrapper .EventType ;
38- import com .microsoft .azuretools .telemetrywrapper .EventUtil ;
39- import com .microsoft .tooling .msservices .components .DefaultLoader ;
40- import com .microsoft .azuretools .azurecommons .helpers .NotNull ;
41- import com .microsoft .azuretools .azurecommons .helpers .StringHelper ;
42- import com .microsoft .azuretools .telemetry .AppInsightsClient ;
43- import com .microsoft .azuretools .hdinsight .SparkSubmissionToolWindowView ;
44- import com .microsoft .azuretools .hdinsight .common2 .HDInsightUtil ;
45- import com .microsoft .azuretools .core .utils .Messages ;
46-
4726import java .io .File ;
4827import java .io .IOException ;
4928import java .lang .reflect .InvocationTargetException ;
6847import org .eclipse .jdt .ui .jarpackager .JarPackageData ;
6948import org .eclipse .swt .widgets .Display ;
7049
50+ import com .google .common .reflect .TypeToken ;
51+ import com .google .gson .Gson ;
52+ import com .microsoft .azure .hdinsight .common .ClusterManagerEx ;
53+ import com .microsoft .azure .hdinsight .sdk .cluster .ClusterDetail ;
54+ import com .microsoft .azure .hdinsight .sdk .cluster .IClusterDetail ;
55+ import com .microsoft .azure .hdinsight .sdk .common .AuthenticationException ;
56+ import com .microsoft .azure .hdinsight .sdk .common .HDIException ;
57+ import com .microsoft .azure .hdinsight .sdk .common .HttpResponse ;
58+ import com .microsoft .azure .hdinsight .spark .common .SparkBatchSubmission ;
59+ import com .microsoft .azure .hdinsight .spark .common .SparkSubmissionParameter ;
60+ import com .microsoft .azure .hdinsight .spark .common .SparkSubmitResponse ;
61+ import com .microsoft .azure .hdinsight .spark .jobs .JobUtils ;
62+ import com .microsoft .azuretools .azurecommons .helpers .NotNull ;
63+ import com .microsoft .azuretools .azurecommons .helpers .StringHelper ;
64+ import com .microsoft .azuretools .core .utils .Messages ;
65+ import com .microsoft .azuretools .hdinsight .SparkSubmissionToolWindowView ;
66+ import com .microsoft .azuretools .hdinsight .common2 .HDInsightUtil ;
67+ import com .microsoft .azuretools .telemetry .AppInsightsClient ;
68+ import com .microsoft .azuretools .telemetrywrapper .EventType ;
69+ import com .microsoft .azuretools .telemetrywrapper .EventUtil ;
70+ import com .microsoft .tooling .msservices .components .DefaultLoader ;
71+
7172public class SparkSubmitModel {
7273 // private static final String[] columns = {"Key", "Value", ""};
7374 private static final String SparkYarnLogUrlFormat = "%s/yarnui/hn/cluster/app/%s" ;
7475
7576 private List <IClusterDetail > cachedClusterDetails ;
7677
77- private Map <String , IClusterDetail > mapClusterNameToClusterDetail = new HashMap <>();
78-
79-
8078 private SparkSubmissionParameter submissionParameter ;
8179
8280 private Map <String , String > postEventProperty = new HashMap <>();
8381
8482 public SparkSubmitModel (@ NotNull List <IClusterDetail > cachedClusterDetails ) {
8583 this .cachedClusterDetails = cachedClusterDetails ;
86- setClusterDetailsMap (cachedClusterDetails );
8784 }
8885
8986 public SparkSubmissionParameter getSubmissionParameter () {
@@ -95,13 +92,6 @@ public boolean isLocalArtifact() {
9592 return submissionParameter .isLocalArtifact ();
9693 }
9794
98- public void setClusterDetailsMap (List <IClusterDetail > cachedClusterDetails ) {
99- mapClusterNameToClusterDetail .clear ();
100-
101- for (IClusterDetail clusterDetail : cachedClusterDetails ) {
102- mapClusterNameToClusterDetail .put (clusterDetail .getName (), clusterDetail );
103- }
104- }
10595 public void action (@ NotNull SparkSubmissionParameter submissionParameter ) {
10696 this .submissionParameter = submissionParameter ;
10797
@@ -303,17 +293,31 @@ private void submit() {
303293 DefaultLoader .getIdeHelper ().executeOnPooledThread (new Runnable () {
304294 @ Override
305295 public void run () {
306- IClusterDetail selectedClusterDetail = mapClusterNameToClusterDetail .get (submissionParameter .getClusterName ());
307- String selectedArtifactName = submissionParameter .getArtifactName ();
308-
309- //may get a new clusterDetail reference if cluster credentials expired
310- selectedClusterDetail = getClusterConfiguration (selectedClusterDetail , true );
311-
296+ // Validate the selected cluster
297+ String selectedClusterName = submissionParameter .getClusterName ();
298+ IClusterDetail selectedClusterDetail = ClusterManagerEx .getInstance ().getClusterDetailByName (selectedClusterName ).orElse (null );
312299 if (selectedClusterDetail == null ) {
313- HDInsightUtil .showErrorMessageOnSubmissionMessageWindow ("Selected Cluster can not found. Please login in first in HDInsight Explorer and try submit job again" );
300+ HDInsightUtil .showErrorMessageOnSubmissionMessageWindow ("Selected Cluster can not found. "
301+ + "Please login in first in HDInsight Explorer and try submit job again" );
314302 return ;
303+ } else if (ClusterManagerEx .getInstance ().isHdiReaderCluster (selectedClusterDetail )) {
304+ if (((ClusterDetail )selectedClusterDetail ).getHttpUserName () == null
305+ || ((ClusterDetail )selectedClusterDetail ).getHttpPassword () == null ) {
306+ HDInsightUtil .showErrorMessageOnSubmissionMessageWindow ("No Ambari permission to submit job to the selected cluster." );
307+ return ;
308+ }
309+ } else {
310+ //may get a new clusterDetail reference if cluster credentials expired
311+ selectedClusterDetail = getClusterConfiguration (selectedClusterDetail , true );
312+ if (selectedClusterDetail == null ) {
313+ HDInsightUtil .showErrorMessageOnSubmissionMessageWindow ("Selected Cluster can not found. "
314+ + "Please login in first in HDInsight Explorer and try submit job again" );
315+ return ;
316+ }
315317 }
316318
319+ String selectedArtifactName = submissionParameter .getArtifactName ();
320+
317321 try {
318322 uploadFileToCluster (selectedClusterDetail , selectedArtifactName );
319323 tryToCreateBatchSparkJob (selectedClusterDetail );
@@ -338,7 +342,7 @@ public void run() {
338342 }
339343 });
340344 }
341- //
345+
342346 private void postEventAction () {
343347 postEventProperty .clear ();
344348 postEventProperty .put ("ClusterName" , submissionParameter .getClusterName ());
0 commit comments