-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEZ-4352: Add a web ui interface for TezChild
- Loading branch information
1 parent
1084699
commit d5962df
Showing
8 changed files
with
283 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
tez-runtime-internals/src/main/java/org/apache/tez/runtime/web/TezChildWebController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.tez.runtime.web; | ||
|
||
import java.io.PrintWriter; | ||
|
||
import org.apache.hadoop.yarn.webapp.Controller; | ||
import org.apache.hadoop.yarn.webapp.MimeType; | ||
import org.apache.hadoop.yarn.webapp.View; | ||
import org.apache.tez.runtime.api.impl.ExecutionContextImpl; | ||
|
||
import com.google.inject.Inject; | ||
|
||
public class TezChildWebController extends Controller { | ||
|
||
@Inject | ||
public TezChildWebController(RequestContext requestContext) { | ||
super(requestContext); | ||
} | ||
|
||
@Override | ||
public void index() { | ||
ui(); | ||
} | ||
|
||
public void ui() { | ||
render(StaticTezChildView.class); | ||
} | ||
|
||
public static class StaticTezChildView extends View { | ||
@Inject | ||
private ExecutionContextImpl executionContext; | ||
|
||
@Override | ||
public void render() { | ||
response().setContentType(MimeType.HTML); | ||
PrintWriter pw = writer(); | ||
pw.write("<html><head><meta charset=\\\"utf-8\\\"><title>TezChild UI</title>"); | ||
pw.write("</head><body>"); | ||
pw.write(String.format("<h1>TezChild UI</h1> <h2>%s, %s</h2> %s :: %s :: %s", executionContext.getHostName(), | ||
executionContext.getContainerId(), getLink("jmx"), getLink("conf"), getLink("stacks"))); | ||
pw.write("</body></html>"); | ||
pw.flush(); | ||
} | ||
|
||
private String getLink(String path) { | ||
return "<a href=\"/" + path + "\">" + path + "</a>"; | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
tez-runtime-internals/src/main/java/org/apache/tez/runtime/web/TezChildWebUIService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.tez.runtime.web; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.net.NetUtils; | ||
import org.apache.hadoop.yarn.webapp.WebApp; | ||
import org.apache.hadoop.yarn.webapp.WebApps; | ||
import org.apache.tez.common.web.ServletToControllerAdapters.ConfServletController; | ||
import org.apache.tez.common.web.ServletToControllerAdapters.JMXJsonServletController; | ||
import org.apache.tez.common.web.ServletToControllerAdapters.StackServletController; | ||
import org.apache.tez.dag.api.TezConfiguration; | ||
import org.apache.tez.dag.api.TezUncheckedException; | ||
import org.apache.tez.runtime.api.ExecutionContext; | ||
import org.apache.tez.runtime.api.impl.ExecutionContextImpl; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TezChildWebUIService { | ||
private static final Logger LOG = LoggerFactory.getLogger(TezChildWebUIService.class); | ||
|
||
private Configuration conf; | ||
private ExecutionContext executionContext; | ||
private TezChildWebApp tezChildWebApp; | ||
private WebApp webApp; | ||
private String baseUrl = ""; //url without paths, like http://host:port | ||
|
||
public TezChildWebUIService(Configuration conf, ExecutionContext executionContext) { | ||
this.tezChildWebApp = new TezChildWebApp(executionContext); | ||
this.conf = conf; | ||
this.executionContext = executionContext; | ||
} | ||
|
||
public TezChildWebUIService start() { | ||
try { | ||
if (conf.get(TezConfiguration.TEZ_TASK_WEBSERVICE_PORT_RANGE) == null) { | ||
conf.set(TezConfiguration.TEZ_TASK_WEBSERVICE_PORT_RANGE, | ||
TezConfiguration.TEZ_TASK_WEBSERVICE_PORT_RANGE_DEFAULT); | ||
LOG.info( | ||
"Using default port range for WebUIService: " + conf.get(TezConfiguration.TEZ_TASK_WEBSERVICE_PORT_RANGE)); | ||
} | ||
this.webApp = WebApps.$for(this.tezChildWebApp).with(conf) | ||
.withPortRange(conf, TezConfiguration.TEZ_TASK_WEBSERVICE_PORT_RANGE).start(this.tezChildWebApp); | ||
InetSocketAddress address = webApp.getListenerAddress(); | ||
if (address != null) { | ||
String hostname = executionContext.getHostName(); | ||
InetSocketAddress bindAddress = NetUtils.createSocketAddrForHost(hostname, address.getPort()); | ||
final int port = address.getPort(); | ||
if (bindAddress.getAddress() != null && bindAddress.getAddress().getCanonicalHostName() != null) { | ||
hostname = bindAddress.getAddress().getCanonicalHostName(); | ||
} else { | ||
LOG.warn("Failed to resolve canonical hostname for " + hostname); | ||
} | ||
baseUrl = String.format("http://%s:%d", hostname, port); | ||
LOG.info("Instantiated TezChild WebUIService at " + baseUrl + "/ui"); | ||
} | ||
} catch (Exception e) { | ||
LOG.error("TezChild WebUIService failed to start.", e); | ||
throw new TezUncheckedException(e); | ||
} | ||
return this; | ||
} | ||
|
||
public void stop() { | ||
if (this.webApp != null) { | ||
LOG.debug("Stopping WebApp"); | ||
this.webApp.stop(); | ||
} | ||
} | ||
|
||
private static class TezChildWebApp extends WebApp { | ||
private ExecutionContext executionContext; | ||
|
||
TezChildWebApp(ExecutionContext executionContext) { | ||
this.executionContext = executionContext; | ||
} | ||
|
||
@Override | ||
public void setup() { | ||
bind(ExecutionContextImpl.class).toInstance((ExecutionContextImpl) executionContext); | ||
route("/", TezChildWebController.class, "ui"); | ||
route("/ui", TezChildWebController.class, "ui"); | ||
route("/jmx", JMXJsonServletController.class); | ||
route("/conf", ConfServletController.class); | ||
route("/stacks", StackServletController.class); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tez-runtime-internals/src/main/java/org/apache/tez/runtime/web/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
@InterfaceAudience.Private | ||
package org.apache.tez.runtime.web; | ||
import org.apache.hadoop.classification.InterfaceAudience; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters