@@ -54,6 +54,17 @@ $(document).ajaxStart(function () {
5454 $ . blockUI ( { message : '<h3>Loading Executors Page...</h3>' } ) ;
5555} ) ;
5656
57+ // Return the OrgId part if it appears as the last part of the url.
58+ function getOrgIdPart ( words ) {
59+ var orgIdPart = words [ words . length - 1 ] ;
60+ // o= is the identifier of a OrgId part.
61+ if ( orgIdPart . includes ( "o=" ) ) {
62+ return orgIdPart ;
63+ }
64+ // If the url does not OrgId, return an empty string
65+ return "" ;
66+ }
67+
5768function createTemplateURI ( appId ) {
5869 var words = document . baseURI . split ( '/' ) ;
5970 var ind = words . indexOf ( "proxy" ) ;
@@ -66,6 +77,16 @@ function createTemplateURI(appId) {
6677 var baseURI = words . slice ( 0 , ind ) . join ( '/' ) + '/static/executorspage-template.html' ;
6778 return baseURI ;
6879 }
80+ ind = words . indexOf ( "sparkui" ) ;
81+ if ( ind > 0 ) {
82+ var orgIdPart = getOrgIdPart ( words ) ;
83+ // document.baseURI will look like https://<shard-url>/sparkui/<cluster-id>/driver-<spark-context-id>/....
84+ // words.slice(0, ind + 3).join('/') will give us https://<shard-url>/sparkui/<cluster-id>/driver-<spark-context-id>.
85+ // Note: If there is a OrgId, we should have executorspage-template.html?o=<OrgId> instead of
86+ // executorspage-template.html/?o=<OrgId>.
87+ var baseURI = words . slice ( 0 , ind + 3 ) . join ( '/' ) + '/static/executorspage-template.html' + orgIdPart ;
88+ return baseURI ;
89+ }
6990 return location . origin + "/static/executorspage-template.html" ;
7091}
7192
@@ -83,15 +104,32 @@ function getStandAloneppId(cb) {
83104 cb ( appId ) ;
84105 return ;
85106 }
86- //Looks like Web UI is running in standalone mode
87- //Let's get application-id using REST End Point
88- $ . getJSON ( location . origin + "/api/v1/applications" , function ( response , status , jqXHR ) {
89- if ( response && response . length > 0 ) {
90- var appId = response [ 0 ] . id
91- cb ( appId ) ;
92- return ;
93- }
94- } ) ;
107+ // A url from databricks.
108+ // https://<shard-url>/sparkui/<cluster-id>/driver-<spark-context-id>/executors/?o=<org-id>
109+ ind = words . indexOf ( "sparkui" )
110+ if ( ind > 0 ) {
111+ var orgIdPart = getOrgIdPart ( words ) ;
112+ // Re-construct the baseURI, e.g. baseURI will be
113+ // https://<shard-url>/sparkui/<cluster-id>/driver-<spark-context-id>
114+ var baseURI = words . slice ( 0 , ind + 3 ) . join ( "/" ) ;
115+ $ . getJSON ( baseURI + "/api/v1/applications/" + orgIdPart , function ( response , status , jqXHR ) {
116+ if ( response && response . length > 0 ) {
117+ var appId = response [ 0 ] . id
118+ cb ( appId ) ;
119+ return ;
120+ }
121+ } ) ;
122+ } else {
123+ //Looks like Web UI is running in standalone mode
124+ //Let's get application-id using REST End Point
125+ $ . getJSON ( location . origin + "/api/v1/applications" , function ( response , status , jqXHR ) {
126+ if ( response && response . length > 0 ) {
127+ var appId = response [ 0 ] . id
128+ cb ( appId ) ;
129+ return ;
130+ }
131+ } ) ;
132+ }
95133}
96134
97135function createRESTEndPoint ( appId ) {
@@ -113,6 +151,14 @@ function createRESTEndPoint(appId) {
113151 return newBaseURI + "/api/v1/applications/" + appId + "/" + attemptId + "/allexecutors" ;
114152 }
115153 }
154+ ind = words . indexOf ( "sparkui" ) ;
155+ if ( ind > 0 ) {
156+ var orgIdPart = getOrgIdPart ( words ) ;
157+ // Re-construct the baseURI, e.g. baseURI will be
158+ // https://<shard-url>/sparkui/<cluster-id>/driver-<spark-context-id>
159+ var baseURI = words . slice ( 0 , ind + 3 ) . join ( "/" ) ;
160+ return baseURI + "/api/v1/applications/" + appId + "/allexecutors/" + orgIdPart ;
161+ }
116162 return location . origin + "/api/v1/applications/" + appId + "/allexecutors" ;
117163}
118164
0 commit comments