001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.oozie.service; 020 021import org.apache.commons.lang.StringUtils; 022import org.apache.oozie.util.Instrumentable; 023import org.apache.oozie.util.Instrumentation; 024import org.apache.oozie.util.XLogStreamer; 025import java.io.IOException; 026import java.io.Writer; 027import java.util.Date; 028 029/** 030 * Service that performs streaming of log files over Web Services if enabled in XLogService 031 */ 032public class XLogStreamingService implements Service, Instrumentable { 033 034 035 /** 036 * Initialize the log streaming service. 037 * 038 * @param services services instance. 039 * @throws ServiceException thrown if the log streaming service could not be initialized. 040 */ 041 public void init(Services services) throws ServiceException { 042 } 043 044 /** 045 * Destroy the log streaming service. 046 */ 047 public void destroy() { 048 } 049 050 /** 051 * Return the public interface for log streaming service. 052 * 053 * @return {@link XLogStreamingService}. 054 */ 055 public Class<? extends Service> getInterface() { 056 return XLogStreamingService.class; 057 } 058 059 /** 060 * Instruments the log streaming service. 061 * 062 * @param instr instrumentation to use. 063 */ 064 public void instrument(Instrumentation instr) { 065 // nothing to instrument 066 } 067 068 069 /** 070 * Stream the log of a job. 071 * 072 * @param logStreamer the log streamer 073 * @param startTime start time for log events to filter. 074 * @param endTime end time for log events to filter. 075 * @param writer writer to stream the log to. 076 * @throws IOException Signals that an I/O exception has occurred. 077 */ 078 public void streamLog(XLogStreamer logStreamer, Date startTime, Date endTime, Writer writer) throws IOException { 079 streamLog(logStreamer, startTime, endTime, writer, true); 080 } 081 082 /** 083 * Stream log. 084 * 085 * @param logStreamer the log streamer 086 * @param startTime the start time 087 * @param endTime the end time 088 * @param writer the writer 089 * @param appendDebug the append debug 090 * @throws IOException Signals that an I/O exception has occurred. 091 */ 092 protected void streamLog(XLogStreamer logStreamer, Date startTime, Date endTime, Writer writer, boolean appendDebug) 093 throws IOException { 094 if (!logStreamer.isLogEnabled()) { 095 writer.write(logStreamer.getLogDisableMessage()); 096 return; 097 } 098 logStreamer.streamLog(writer, startTime, endTime, appendDebug); 099 } 100}