Skip to content

Commit 6b351f9

Browse files
KNOX-3249: Integrate new yarn scheduler-ui into KNOX homepage (#1178)
Co-authored by @Hean-Chhinling
1 parent be2b9a4 commit 6b351f9

7 files changed

Lines changed: 310 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with this
4+
* work for additional information regarding copyright ownership. The ASF
5+
* licenses this file to you under the Apache License, Version 2.0 (the
6+
* "License"); you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
package org.apache.knox.gateway.topology.discovery.cm.model.yarn;
18+
19+
public class YarnSchedulerUIServiceModelGenerator extends YarnUIServiceModelGenerator {
20+
public static final String SERVICE = "YARN-SCHEDULER-UI";
21+
public static final String SERVICE_TYPE = "YARN";
22+
public static final String ROLE_TYPE = "RESOURCEMANAGER";
23+
24+
@Override
25+
public String getService() {
26+
return SERVICE;
27+
}
28+
29+
@Override
30+
public String getServiceType() {
31+
return SERVICE_TYPE;
32+
}
33+
34+
@Override
35+
public String getRoleType() {
36+
return ROLE_TYPE;
37+
}
38+
39+
}

gateway-discovery-cm/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ org.apache.knox.gateway.topology.discovery.cm.model.yarn.ResourceManagerApiServi
5050
org.apache.knox.gateway.topology.discovery.cm.model.yarn.ResourceManagerUIServiceModelGenerator
5151
org.apache.knox.gateway.topology.discovery.cm.model.yarn.YarnUIServiceModelGenerator
5252
org.apache.knox.gateway.topology.discovery.cm.model.yarn.YarnUIv2ServiceModelGenerator
53+
org.apache.knox.gateway.topology.discovery.cm.model.yarn.YarnSchedulerUIServiceModelGenerator
5354
org.apache.knox.gateway.topology.discovery.cm.model.zeppelin.ZeppelinServiceModelGenerator
5455
org.apache.knox.gateway.topology.discovery.cm.model.zeppelin.ZeppelinUIServiceModelGenerator
5556
org.apache.knox.gateway.topology.discovery.cm.model.zeppelin.ZeppelinWSServiceModelGenerator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with this
4+
* work for additional information regarding copyright ownership. The ASF
5+
* licenses this file to you under the Apache License, Version 2.0 (the
6+
* "License"); you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
package org.apache.knox.gateway.topology.discovery.cm.model.yarn;
18+
19+
import com.cloudera.api.swagger.model.ApiConfigList;
20+
import com.cloudera.api.swagger.model.ApiRole;
21+
import com.cloudera.api.swagger.model.ApiService;
22+
import com.cloudera.api.swagger.model.ApiServiceConfig;
23+
import org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator;
24+
import org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGeneratorTest;
25+
import org.junit.Test;
26+
27+
import java.util.Collections;
28+
import java.util.HashMap;
29+
import java.util.Locale;
30+
import java.util.Map;
31+
32+
public class YarnSchedulerUIServiceModelGeneratorTest extends AbstractServiceModelGeneratorTest {
33+
34+
@Test
35+
public void testServiceModelMetadata() throws Exception {
36+
final Map<String, String> serviceConfig = Collections.emptyMap();
37+
38+
final Map<String, String> roleConfig = new HashMap<>();
39+
roleConfig.put(YarnSchedulerUIServiceModelGenerator.RM_HTTP_PORT, "8088");
40+
roleConfig.put(YarnSchedulerUIServiceModelGenerator.RM_HTTPS_PORT, "8090");
41+
42+
validateServiceModel(createServiceModel(serviceConfig, roleConfig), serviceConfig, roleConfig);
43+
}
44+
45+
@Override
46+
protected String getServiceType() {
47+
return YarnSchedulerUIServiceModelGenerator.SERVICE_TYPE;
48+
}
49+
50+
@Override
51+
protected String getRoleType() {
52+
return YarnSchedulerUIServiceModelGenerator.ROLE_TYPE;
53+
}
54+
55+
@Override
56+
protected ServiceModelGenerator newGenerator() {
57+
return new YarnSchedulerUIServiceModelGenerator(){
58+
@Override // To bypass the HDFS ssl_enable check
59+
protected String generateURL(ApiService service, ApiServiceConfig serviceConfig, ApiRole role,
60+
ApiConfigList roleConfig, ApiServiceConfig coreConfig) {
61+
62+
String hostname = role.getHostRef().getHostname();
63+
String port = getRoleConfigValue(roleConfig, YarnSchedulerUIServiceModelGenerator.RM_HTTP_PORT);
64+
65+
return String.format(Locale.getDefault(), "http://%s:%s", hostname, port);
66+
}
67+
};
68+
}
69+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<rules>
19+
<rule dir="IN" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/root" pattern="*://*:*/**/yarn-scheduler-ui/">
20+
<!-- Based path to display the homepage-->
21+
<rewrite template="{$serviceUrl[YARN-SCHEDULER-UI]}/scheduler-ui/"/>
22+
</rule>
23+
24+
<rule dir="IN" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/path" pattern="*://*:*/**/yarn-scheduler-ui/{**}">
25+
<!-- Taking the OUT rewritten rules back. Path only to request from /scheduler-ui/-->
26+
<rewrite template="{$serviceUrl[YARN-SCHEDULER-UI]}/scheduler-ui/{**}"/>
27+
</rule>
28+
29+
<rule dir="IN" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/query" pattern="*://*:*/**/yarn-scheduler-ui/{**}?{**}">
30+
<!-- Taking the OUT rewritten rules back. Query only to request from /scheduler-ui/-->
31+
<rewrite template="{$serviceUrl[YARN-SCHEDULER-UI]}/scheduler-ui/{**}?{**}"/>
32+
</rule>
33+
34+
<rule dir="IN" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/ws-cluster" pattern="*://*:*/**/yarn-scheduler-ui/ws/v1/cluster/{**}">
35+
<!-- Taking the OUT rewritten rules back. Path only to request to RM Rest API-->
36+
<rewrite template="{$serviceUrl[YARN-SCHEDULER-UI]}/ws/v1/cluster/{**}"/>
37+
</rule>
38+
39+
<rule dir="IN" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/ws-cluster-query" pattern="*://*:*/**/yarn-scheduler-ui/ws/v1/cluster/{**}?{**}">
40+
<!-- Taking the OUT rewritten rules back. Query only to request to RM Rest API-->
41+
<rewrite template="{$serviceUrl[YARN-SCHEDULER-UI]}/ws/v1/cluster/{**}?{**}"/>
42+
</rule>
43+
44+
<rule dir="IN" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/conf-query" pattern="*://*:*/**/yarn-scheduler-ui/conf?{**}">
45+
<!---This is for Scheduler UI calling conf?name=hadoop.security.authentication and conf?name=yarn.webapp.scheduler-ui.read-only.enable-->
46+
<rewrite template="{$serviceUrl[YARN-SCHEDULER-UI]}/conf?{**}"/>
47+
</rule>
48+
49+
<rule dir="OUT" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/site-base">
50+
<!-- Rewriting any UI path to put behind knox proxy -->
51+
<rewrite template="{$frontend[path]}/yarn-scheduler-ui/"/>
52+
</rule>
53+
54+
<rule dir="OUT" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/api-cluster">
55+
<!-- Rewriting any RestAPI path to put behind knox proxy -->
56+
<rewrite template="{$frontend[path]}/yarn-scheduler-ui/ws/v1/cluster"/>
57+
</rule>
58+
59+
<rule dir="OUT" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/assets">
60+
<!-- Rewriting relative path link in HTML to put behind KNOX proxy,
61+
E.g.from /assets/root-DBfchZlr.css to /gateway/cdp-proxy/yarn-scheduler-ui/assets/root-DBfchZlr.css
62+
-->
63+
<match pattern="/scheduler-ui/{**}">
64+
<rewrite template="{$frontend[path]}/yarn-scheduler-ui/{**}"/>
65+
</match>
66+
</rule>
67+
68+
<rule flow="OR" dir="OUT" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/api-cluster/wildcard">
69+
<!-- Rewriting Javascript RestAPI link behind KNOX proxy
70+
E.g. from ws/v1/cluster/scheduler-conf to /gateway/cdp-proxy/yarn-scheduler-ui/ws/v1/cluster/scheduler-conf
71+
-->
72+
<match pattern="/ws/v1/cluster/{**}?{**}">
73+
<rewrite template="{$frontend[path]}/yarn-scheduler-ui/ws/v1/cluster/{**}?{**}"/>
74+
</match>
75+
76+
<match pattern="/ws/v1/cluster/{**}">
77+
<rewrite template="{$frontend[path]}/yarn-scheduler-ui/ws/v1/cluster/{**}"/>
78+
</match>
79+
</rule>
80+
81+
<rule dir="OUT" name="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/conf">
82+
<!--Putting the /conf endpoint behind KNOX proxy -->
83+
<rewrite template="{$frontend[path]}/yarn-scheduler-ui/conf"/>
84+
</rule>
85+
86+
<filter name="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/index">
87+
<!--Filter out the link to put back behind knox proxy -->
88+
<content type="*/html">
89+
<apply path="/scheduler-ui" rule="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/site-base"/>
90+
<apply path="/scheduler-ui/.*" rule="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/assets"/>
91+
</content>
92+
<content type="application/javascript">
93+
<apply path="/scheduler-ui" rule="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/site-base"/>
94+
<apply path="/ws/v1/cluster" rule="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/api-cluster"/>
95+
<apply path="/ws/v1/cluster/.*" rule="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/api-cluster/wildcard"/>
96+
<apply path="/conf" rule="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/conf"/>
97+
</content>
98+
<content type="text/css">
99+
<apply path="/scheduler-ui/" rule="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/site-base"/>
100+
</content>
101+
</filter>
102+
103+
</rules>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<service role="YARN-SCHEDULER-UI" name="yarn-scheduler-ui" version="1.0.0">
20+
<metadata>
21+
<type>UI</type>
22+
<context>/yarn-scheduler-ui/</context>
23+
<shortDesc>YARN Scheduler UI</shortDesc>
24+
<description>A modern React-based web interface for managing and configuring the YARN Capacity Scheduler.</description>
25+
</metadata>
26+
<routes>
27+
<route path="/yarn-scheduler-ui/">
28+
<rewrite apply="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/root" to="request.url"/>
29+
<rewrite apply="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/index" to="response.body" />
30+
</route>
31+
32+
<route path="/yarn-scheduler-ui/**">
33+
<rewrite apply="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/path" to="request.url"/>
34+
<rewrite apply="YARN-SCHEDULER-UI/yarn-scheduler-ui/outbound/index" to="response.body"/>
35+
</route>
36+
37+
<route path="/yarn-scheduler-ui/ws/v1/cluster/**?**">
38+
<rewrite apply="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/ws-cluster-query" to="request.url"/>
39+
</route>
40+
41+
<route path="/yarn-scheduler-ui/ws/v1/cluster/**">
42+
<rewrite apply="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/ws-cluster" to="request.url"/>
43+
</route>
44+
45+
<route path="/yarn-scheduler-ui/conf?**">
46+
<rewrite apply="YARN-SCHEDULER-UI/yarn-scheduler-ui/inbound/conf-query" to="request.url"/>
47+
</route>
48+
</routes>
49+
50+
<dispatch classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch" ha-classname="org.apache.knox.gateway.rm.dispatch.RMSchedulerUIHaDispatch"/>
51+
</service>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with this
4+
* work for additional information regarding copyright ownership. The ASF
5+
* licenses this file to you under the Apache License, Version 2.0 (the
6+
* "License"); you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/package org.apache.knox.gateway.rm.dispatch;
17+
18+
import org.apache.knox.gateway.config.Configure;
19+
import org.apache.knox.gateway.ha.provider.HaProvider;
20+
import org.apache.knox.gateway.ha.provider.HaServiceConfig;
21+
22+
public class RMSchedulerUIHaDispatch extends RMHaBaseDispatcher{
23+
private static final String RESOURCE_ROLE = "YARN-SCHEDULER-UI";
24+
private HaProvider haProvider;
25+
26+
public RMSchedulerUIHaDispatch() {
27+
super();
28+
}
29+
30+
@Override
31+
@Configure
32+
public void setHaProvider(HaProvider haProvider) {
33+
this.haProvider = haProvider;
34+
}
35+
36+
@Override
37+
public void init() {
38+
super.init();
39+
if (haProvider != null) {
40+
super.setResourceRole(RESOURCE_ROLE);
41+
HaServiceConfig serviceConfig = haProvider.getHaDescriptor().getServiceConfig(RESOURCE_ROLE);
42+
super.setMaxFailoverAttempts(serviceConfig.getMaxFailoverAttempts());
43+
super.setFailoverSleep(serviceConfig.getFailoverSleep());
44+
super.setHaProvider(haProvider);
45+
}
46+
}
47+
}
3.64 MB
Loading

0 commit comments

Comments
 (0)