[
https://issues.apache.org/jira/browse/NIFI-4325?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16403654#comment-16403654
]
ASF GitHub Bot commented on NIFI-4325:
--------------------------------------
Github user JPercivall commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2113#discussion_r175264989
--- Diff:
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/main/java/org/apache/nifi/elasticsearch/ElasticSearchClientServiceImpl.java
---
@@ -0,0 +1,255 @@
+/*
+ * 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.nifi.elasticsearch;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.entity.ContentType;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.nio.entity.NStringEntity;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.controller.ControllerServiceInitializationContext;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.ssl.SSLContextService;
+import org.elasticsearch.client.Response;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.client.RestClientBuilder;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.security.KeyStore;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class ElasticSearchClientServiceImpl extends
AbstractControllerService implements ElasticSearchClientService {
+ private ObjectMapper mapper = new ObjectMapper();
+
+ private List<PropertyDescriptor> properties;
+
+ private RestClient client;
+
+ private String url;
+
+ @Override
+ protected void init(ControllerServiceInitializationContext config) {
+ properties = new ArrayList<>();
+ properties.add(ElasticSearchClientService.HTTP_HOSTS);
+ properties.add(ElasticSearchClientService.USERNAME);
+ properties.add(ElasticSearchClientService.PASSWORD);
+
properties.add(ElasticSearchClientService.PROP_SSL_CONTEXT_SERVICE);
+ properties.add(ElasticSearchClientService.CONNECT_TIMEOUT);
+ properties.add(ElasticSearchClientService.SOCKET_TIMEOUT);
+ properties.add(ElasticSearchClientService.RETRY_TIMEOUT);
+ }
+
+ @Override
+ protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return properties;
+ }
+
+ @OnEnabled
+ public void onEnabled(final ConfigurationContext context) throws
InitializationException {
+ try {
+ setupClient(context);
+ } catch (Exception ex) {
+ getLogger().error("Could not initialize ElasticSearch
client.", ex);
+ throw new InitializationException(ex);
+ }
+ }
+
+ @OnDisabled
+ public void onDisabled() throws IOException {
+ this.client.close();
+ this.url = null;
+ }
+
+ private void setupClient(ConfigurationContext context) throws
Exception {
--- End diff --
Try to avoid "throws Exception". Looks like the only one thrown is
"MalformedURLException".
> Create a new ElasticSearch processor that supports the JSON DSL
> ---------------------------------------------------------------
>
> Key: NIFI-4325
> URL: https://issues.apache.org/jira/browse/NIFI-4325
> Project: Apache NiFi
> Issue Type: Improvement
> Reporter: Mike Thomsen
> Priority: Minor
>
> The existing ElasticSearch processors use the Lucene-style syntax for
> querying, not the JSON DSL. A new processor is needed that can take a full
> JSON query and execute it. It should also support aggregation queries in this
> syntax. A user needs to be able to take a query as-is from Kibana and drop it
> into NiFi and have it just run.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)