@@ -53,7 +53,28 @@ $(document).ajaxStart(function () {
5353 $ . blockUI ( { message : '<h3>Loading Executors Page...</h3>' } ) ;
5454} ) ;
5555
56+ function findKubernetesServiceBaseURI ( ) {
57+ var k8sProxyPattern = '/api/v1/proxy/namespaces/' ;
58+ var k8sProxyPatternPos = document . baseURI . indexOf ( k8sProxyPattern ) ;
59+ if ( k8sProxyPatternPos > 0 ) {
60+ // Spark is running in a kubernetes cluster, and the web ui is served
61+ // through the kubectl proxy.
62+ var remaining = document . baseURI . substr ( k8sProxyPatternPos + k8sProxyPattern . length ) ;
63+ var urlSlashesCount = remaining . split ( '/' ) . length - 3 ;
64+ var words = document . baseURI . split ( '/' ) ;
65+ var baseURI = words . slice ( 0 , words . length - urlSlashesCount ) . join ( '/' ) ;
66+ return baseURI ;
67+ }
68+
69+ return null ;
70+ }
71+
5672function createTemplateURI ( appId ) {
73+ var kubernetesBaseURI = findKubernetesServiceBaseURI ( ) ;
74+ if ( kubernetesBaseURI ) {
75+ return kubernetesBaseURI + '/static/executorspage-template.html' ;
76+ }
77+
5778 var words = document . baseURI . split ( '/' ) ;
5879 var ind = words . indexOf ( "proxy" ) ;
5980 if ( ind > 0 ) {
@@ -69,6 +90,14 @@ function createTemplateURI(appId) {
6990}
7091
7192function getStandAloneppId ( cb ) {
93+ var kubernetesBaseURI = findKubernetesServiceBaseURI ( ) ;
94+ if ( kubernetesBaseURI ) {
95+ var appIdAndPort = kubernetesBaseURI . split ( '/' ) . slice ( - 1 ) [ 0 ] ;
96+ var appId = appIdAndPort . split ( ':' ) [ 0 ] ;
97+ cb ( appId ) ;
98+ return ;
99+ }
100+
72101 var words = document . baseURI . split ( '/' ) ;
73102 var ind = words . indexOf ( "proxy" ) ;
74103 if ( ind > 0 ) {
@@ -94,6 +123,11 @@ function getStandAloneppId(cb) {
94123}
95124
96125function createRESTEndPoint ( appId ) {
126+ var kubernetesBaseURI = findKubernetesServiceBaseURI ( ) ;
127+ if ( kubernetesBaseURI ) {
128+ return kubernetesBaseURI + "/api/v1/applications/" + appId + "/allexecutors" ;
129+ }
130+
97131 var words = document . baseURI . split ( '/' ) ;
98132 var ind = words . indexOf ( "proxy" ) ;
99133 if ( ind > 0 ) {
0 commit comments