Example usage for org.apache.hadoop.yarn.logaggregation LogAggregationUtils getRemoteNodeLogFileForApp

List of usage examples for org.apache.hadoop.yarn.logaggregation LogAggregationUtils getRemoteNodeLogFileForApp

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.logaggregation LogAggregationUtils getRemoteNodeLogFileForApp.

Prototype

public static Path getRemoteNodeLogFileForApp(Path remoteRootLogDir, ApplicationId appId, String user,
        NodeId nodeId, String suffix) 

Source Link

Document

Constructs the full filename for an application's log file per node.

Usage

From source file:com.netflix.bdp.inviso.log.LogService.java

License:Apache License

@javax.ws.rs.Path("load/{owner}/{appId}/{containerId}/{nodeId}")
@GET//w  w  w.  j  a  v a 2  s.  com
@Produces("text/plain")
public Response log(@PathParam("owner") String owner, @PathParam("appId") String appId,
        @PathParam("containerId") String containerId, @PathParam("nodeId") String nodeId,
        @QueryParam("fs") String fs, @QueryParam("root") String root) throws IOException {

    Configuration conf = new Configuration();

    if (fs != null) {
        conf.set("fs.default.name", fs);
    }

    Path logRoot = new Path(
            conf.get(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR));

    if (root != null) {
        logRoot = new Path(root);
    }

    Path logPath = LogAggregationUtils.getRemoteNodeLogFileForApp(logRoot,
            ConverterUtils.toApplicationId(appId), owner, ConverterUtils.toNodeId(nodeId),
            LogAggregationUtils.getRemoteNodeLogDirSuffix(conf));

    AggregatedLogFormat.LogReader reader = new AggregatedLogFormat.LogReader(conf, logPath);

    LogKey key = new LogKey();

    DataInputStream in = reader.next(key);

    while (in != null && !key.toString().equals(containerId)) {
        key = new LogKey();
        in = reader.next(key);
    }

    if (in == null) {
        throw new WebApplicationException(404);
    }

    final DataInputStream fin = in;

    StreamingOutput stream = new StreamingOutput() {
        @Override
        public void write(OutputStream os) throws IOException, WebApplicationException {
            PrintStream out = new PrintStream(os);

            while (true) {
                try {
                    LogReader.readAContainerLogsForALogType(fin, out);
                    out.flush();
                } catch (EOFException e) {
                    break;
                }
            }
        }
    };

    return Response.ok(stream).build();
}