boscodurai commented on a change in pull request #42: DINF-1390 Added start of implementation for ElasticSearch write/searc… URL: https://github.com/apache/ranger/pull/42#discussion_r342399989
########## File path: agents-audit/src/main/java/org/apache/ranger/audit/destination/ElasticSearchAuditDestination.java ########## @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ranger.audit.destination; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpHost; +import org.apache.ranger.audit.model.AuditEventBase; +import org.apache.ranger.audit.model.AuthzAuditEvent; +import org.apache.ranger.audit.provider.MiscUtil; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestHighLevelClient; + +import java.util.*; + + +public class ElasticSearchAuditDestination extends AuditDestination { + private static final Log LOG = LogFactory.getLog(ElasticSearchAuditDestination.class); + + public static final String ELASTICSEARCH_URLS = "urls"; + public static final String ELASTICSEARCH_PORT = "port"; + public static final String ELASTICSEARCH_PROTOCOL = "protocol"; + + public ElasticSearchAuditDestination() { + } + + private volatile RestHighLevelClient client = null; + + @Override + public void init(Properties props, String propPrefix) { + LOG.info("init() called"); + super.init(props, propPrefix); + connect(); + } + + @Override + public void stop() { + super.stop(); + logStatus(); + } + + @Override + public boolean log(Collection<AuditEventBase> events) { + boolean ret = false; + try { + logStatusIfRequired(); + addTotalCount(events.size()); + + if (client == null) { + connect(); + if (client == null) { + // Solr is still not initialized. So need return error Review comment: We need to replace with Elastic Search ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
