Search in sources :

Example 1 with TimelineWriteError

use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineWriteResponse.TimelineWriteError in project hadoop by apache.

the class FileSystemTimelineWriterImpl method write.

private synchronized void write(String clusterId, String userId, String flowName, String flowVersion, long flowRun, String appId, TimelineEntity entity, TimelineWriteResponse response) throws IOException {
    PrintWriter out = null;
    try {
        String dir = mkdirs(outputRoot, ENTITIES_DIR, clusterId, userId, escape(flowName), escape(flowVersion), String.valueOf(flowRun), appId, entity.getType());
        String fileName = dir + entity.getId() + TIMELINE_SERVICE_STORAGE_EXTENSION;
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName, true), "UTF-8")));
        out.println(TimelineUtils.dumpTimelineRecordtoJSON(entity));
        out.write("\n");
    } catch (IOException ioe) {
        TimelineWriteError error = new TimelineWriteError();
        error.setEntityId(entity.getId());
        error.setEntityType(entity.getType());
        /*
       * TODO: set an appropriate error code after PoC could possibly be:
       * error.setErrorCode(TimelineWriteError.IO_EXCEPTION);
       */
        response.addError(error);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) TimelineWriteError(org.apache.hadoop.yarn.api.records.timelineservice.TimelineWriteResponse.TimelineWriteError) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 TimelineWriteError (org.apache.hadoop.yarn.api.records.timelineservice.TimelineWriteResponse.TimelineWriteError)1