use of org.apache.ranger.audit.model.AuditEventBase in project ranger by apache.
the class DBAuditDestination method log.
/*
* (non-Javadoc)
*
* @see
* org.apache.ranger.audit.provider.AuditHandler#logger(java.util.Collection
* )
*/
@Override
public boolean log(Collection<AuditEventBase> events) {
boolean retValue = false;
logStatusIfRequired();
addTotalCount(events.size());
if (beginTransaction()) {
boolean isFailed = false;
for (AuditEventBase event : events) {
try {
event.persist(daoManager);
} catch (Throwable t) {
logger.error("Error persisting data. event=" + event, t);
isFailed = true;
break;
}
}
if (isFailed) {
retValue = false;
rollbackTransaction();
} else {
retValue = commitTransaction();
}
}
if (retValue) {
addSuccessCount(events.size());
} else {
addDeferredCount(events.size());
}
return retValue;
}
use of org.apache.ranger.audit.model.AuditEventBase in project ranger by apache.
the class FileAuditDestination method log.
/*
* (non-Javadoc)
*
* @see
* org.apache.ranger.audit.provider.AuditProvider#log(java.util.Collection)
*/
@Override
public boolean log(Collection<AuditEventBase> events) {
if (isStopped) {
addTotalCount(events.size());
addDeferredCount(events.size());
logError("log() called after stop was requested. name=" + getName());
return false;
}
List<String> jsonList = new ArrayList<String>();
for (AuditEventBase event : events) {
try {
jsonList.add(MiscUtil.stringify(event));
} catch (Throwable t) {
addTotalCount(1);
addFailedCount(1);
logFailedEvent(event);
logger.error("Error converting to JSON. event=" + event);
}
}
return logJSON(jsonList);
}
use of org.apache.ranger.audit.model.AuditEventBase in project ranger by apache.
the class HDFSAuditDestination method log.
/*
* (non-Javadoc)
*
* @see
* org.apache.ranger.audit.provider.AuditProvider#log(java.util.Collection)
*/
@Override
public boolean log(Collection<AuditEventBase> events) {
if (isStopped) {
logStatusIfRequired();
addTotalCount(events.size());
addDeferredCount(events.size());
logError("log() called after stop was requested. name=" + getName());
return false;
}
List<String> jsonList = new ArrayList<String>();
for (AuditEventBase event : events) {
try {
jsonList.add(MiscUtil.stringify(event));
} catch (Throwable t) {
logger.error("Error converting to JSON. event=" + event);
addTotalCount(1);
addFailedCount(1);
logFailedEvent(event);
}
}
return logJSON(jsonList);
}
use of org.apache.ranger.audit.model.AuditEventBase in project ranger by apache.
the class SolrAuditDestination method log.
@Override
public boolean log(Collection<AuditEventBase> events) {
boolean ret = false;
try {
logStatusIfRequired();
addTotalCount(events.size());
if (solrClient == null) {
connect();
if (solrClient == null) {
// Solr is still not initialized. So need return error
addDeferredCount(events.size());
return ret;
}
}
final Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
for (AuditEventBase event : events) {
AuthzAuditEvent authzEvent = (AuthzAuditEvent) event;
// Convert AuditEventBase to Solr document
SolrInputDocument document = toSolrDoc(authzEvent);
docs.add(document);
}
try {
final UpdateResponse response = SolrAppUtil.addDocsToSolr(solrClient, docs);
if (response.getStatus() != 0) {
addFailedCount(events.size());
logFailedEvent(events, response.toString());
} else {
addSuccessCount(events.size());
ret = true;
}
} catch (SolrException ex) {
addFailedCount(events.size());
logFailedEvent(events, ex);
}
} catch (Throwable t) {
addDeferredCount(events.size());
logError("Error sending message to Solr", t);
}
return ret;
}
use of org.apache.ranger.audit.model.AuditEventBase in project ranger by apache.
the class AsyncAuditProvider method dequeueEvent.
private AuditEventBase dequeueEvent() throws InterruptedException {
AuditEventBase ret = mQueue.poll();
while (ret == null) {
logSummaryIfRequired();
if (mMaxFlushInterval > 0) {
long timeTillNextFlush = getTimeTillNextFlush();
if (timeTillNextFlush <= 0) {
// force flush
break;
}
ret = mQueue.poll(timeTillNextFlush, TimeUnit.MILLISECONDS);
} else {
// Let's wake up for summary logging
long waitTime = intervalLogDurationMS - (System.currentTimeMillis() - lastIntervalLogTime);
waitTime = waitTime <= 0 ? intervalLogDurationMS : waitTime;
ret = mQueue.poll(waitTime, TimeUnit.MILLISECONDS);
}
}
if (ret != null) {
lifeTimeOutLogCount.incrementAndGet();
intervalOutLogCount.incrementAndGet();
}
logSummaryIfRequired();
return ret;
}
Aggregations