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.util; 020 021import java.io.IOException; 022import java.util.Date; 023import java.util.Map; 024 025import org.apache.oozie.client.rest.RestConstants; 026import org.apache.oozie.command.CommandException; 027import org.apache.oozie.service.ConfigurationService; 028import org.apache.oozie.service.Services; 029import org.apache.oozie.service.XLogService; 030 031public class XLogAuditStreamer extends XLogStreamer { 032 public static final String STREAM_BUFFER_LEN = CONF_PREFIX + "audit.buffer.len"; 033 034 public XLogAuditStreamer(XLogFilter logFilter, Map<String, String[]> requestParameters) { 035 super(logFilter, Services.get().get(XLogService.class).getOozieAuditLogPath(), 036 Services.get().get(XLogService.class).getOozieAuditLogName(), 037 Services.get().get(XLogService.class).getOozieAuditLogRotation()); 038 this.requestParam = requestParameters; 039 bufferLen = ConfigurationService.getInt(STREAM_BUFFER_LEN, 3); 040 } 041 042 public XLogAuditStreamer(Map<String, String[]> requestParameters) throws CommandException { 043 this(new XLogAuditFilter(new XLogUserFilterParam(requestParameters)), requestParameters); 044 045 } 046 047 @Override 048 protected void calculateAndValidateDateRange(Date startTime, Date endTime) throws IOException { 049 logFilter.calculateAndCheckDates(startTime, endTime); 050 // no validate 051 } 052 053 @Override 054 public boolean isLogEnabled() { 055 return Services.get().get(XLogService.class).isAuditLogEnabled(); 056 } 057 058 @Override 059 public String getLogType() { 060 return RestConstants.JOB_SHOW_AUDIT_LOG; 061 } 062 063 @Override 064 public String getLogDisableMessage() { 065 return "Audit Log is disabled!!"; 066 } 067 068 public boolean shouldFlushOutput(int byteCountIgnored) { 069 // audit flush is done on number of lines written, not byte 070 this.totalDataWritten += 1; 071 if (this.totalDataWritten > getBufferLen()) { 072 this.totalDataWritten = 0; 073 return true; 074 } 075 else { 076 return false; 077 } 078 } 079}