use of org.apache.ranger.audit.destination.FileAuditDestination in project ranger by apache.
the class AuditProviderFactory method getProviderFromConfig.
private AuditHandler getProviderFromConfig(Properties props, String propPrefix, String providerName, AuditHandler consumer) {
AuditHandler provider = null;
String className = MiscUtil.getStringProperty(props, propPrefix + "." + BaseAuditHandler.PROP_CLASS_NAME);
if (className != null && !className.isEmpty()) {
try {
Class<?> handlerClass = Class.forName(className);
if (handlerClass.isAssignableFrom(AuditQueue.class)) {
// Queue class needs consumer
handlerClass.getDeclaredConstructor(AuditHandler.class).newInstance(consumer);
} else {
provider = (AuditHandler) Class.forName(className).newInstance();
}
} catch (Exception e) {
LOG.fatal("Can't instantiate audit class for providerName=" + providerName + ", className=" + className + ", propertyPrefix=" + propPrefix, e);
}
} else {
if (providerName.equals("file")) {
provider = new FileAuditDestination();
} else if (providerName.equalsIgnoreCase("hdfs")) {
provider = new HDFSAuditDestination();
} else if (providerName.equals("solr")) {
provider = new SolrAuditDestination();
} else if (providerName.equals("kafka")) {
provider = new KafkaAuditProvider();
} else if (providerName.equals("db")) {
provider = new DBAuditDestination();
} else if (providerName.equals("log4j")) {
provider = new Log4JAuditDestination();
} else if (providerName.equals("batch")) {
provider = new AuditBatchQueue(consumer);
} else if (providerName.equals("async")) {
provider = new AuditAsyncQueue(consumer);
} else {
LOG.error("Provider name doesn't have any class associated with it. providerName=" + providerName + ", propertyPrefix=" + propPrefix);
}
}
if (provider != null && provider instanceof AuditQueue) {
if (consumer == null) {
LOG.fatal("consumer can't be null for AuditQueue. queue=" + provider.getName() + ", propertyPrefix=" + propPrefix);
provider = null;
}
}
return provider;
}
Aggregations