[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-23 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/nifi/pull/2601


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-23 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r183491100
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -81,12 +87,21 @@
 description = "Adds the specified property name/value as a query 
parameter in the Elasticsearch URL used for processing")
 public class QueryElasticsearchHttp extends 
AbstractElasticsearchHttpProcessor {
 
+public enum QueryInfoRouteStrategy {
+NEVER,
--- End diff --

sorry check latest


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-23 Thread MikeThomsen
Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r183484904
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -81,12 +87,21 @@
 description = "Adds the specified property name/value as a query 
parameter in the Elasticsearch URL used for processing")
 public class QueryElasticsearchHttp extends 
AbstractElasticsearchHttpProcessor {
 
+public enum QueryInfoRouteStrategy {
+NEVER,
--- End diff --

Like NOHIT("noHits")


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-23 Thread MikeThomsen
Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r183484851
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -81,12 +87,21 @@
 description = "Adds the specified property name/value as a query 
parameter in the Elasticsearch URL used for processing")
 public class QueryElasticsearchHttp extends 
AbstractElasticsearchHttpProcessor {
 
+public enum QueryInfoRouteStrategy {
+NEVER,
--- End diff --

You need to set these to the values used in the AllowableValues.


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-23 Thread MikeThomsen
Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r183484608
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -267,32 +267,18 @@ public void setup(ProcessContext context) {
 
 @Override
 public void onPropertyModified(final PropertyDescriptor descriptor, 
final String oldValue, final String newValue) {
-final Set routeQueryInfoRels = new HashSet<>();
-routeQueryInfoRels.add(REL_SUCCESS);
-routeQueryInfoRels.add(REL_FAILURE);
-routeQueryInfoRels.add(REL_RETRY);
-
-final Set successRels = new HashSet<>();
-successRels.add(REL_SUCCESS);
-successRels.add(REL_FAILURE);
-successRels.add(REL_RETRY);
 
 if (ROUTING_QUERY_INFO_STRATEGY.equals(descriptor)) {
-if (ALWAYS.getValue().equalsIgnoreCase(newValue)) {
-routeQueryInfoRels.add(REL_QUERY_INFO);
-this.relationships = routeQueryInfoRels;
-
-this.queryInfoRouteStrategy = 
QueryInfoRouteStrategy.ALWAYS;
-} else if (NO_HITS.getValue().equalsIgnoreCase(newValue)) {
-routeQueryInfoRels.add(REL_QUERY_INFO);
-this.relationships = routeQueryInfoRels;
-
-this.queryInfoRouteStrategy = QueryInfoRouteStrategy.NOHIT;
-} else {
-this.relationships = successRels;
+final Set relationshipSet = new HashSet<>();
+relationshipSet.add(REL_SUCCESS);
+relationshipSet.add(REL_FAILURE);
+relationshipSet.add(REL_RETRY);
 
-this.queryInfoRouteStrategy = QueryInfoRouteStrategy.NEVER;
+if (ALWAYS.getValue().equalsIgnoreCase(newValue) || 
NO_HITS.getValue().equalsIgnoreCase(newValue)) {
+relationshipSet.add(REL_QUERY_INFO);
 }
+this.queryInfoRouteStrategy = 
QueryInfoRouteStrategy.valueOf(newValue);
--- End diff --

The newValue value does not correspond to the enum values, so it blows up 3 
unit tests.


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-23 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r183461688
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -267,30 +267,28 @@ public void setup(ProcessContext context) {
 
 @Override
 public void onPropertyModified(final PropertyDescriptor descriptor, 
final String oldValue, final String newValue) {
+final Set routeQueryInfoRels = new HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
+routeQueryInfoRels.add(REL_FAILURE);
+routeQueryInfoRels.add(REL_RETRY);
+
+final Set successRels = new HashSet<>();
--- End diff --

I thought the same thing.  Thanks for the feedback my latest did take that 
approach


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-23 Thread MikeThomsen
Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r183458816
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -267,30 +267,28 @@ public void setup(ProcessContext context) {
 
 @Override
 public void onPropertyModified(final PropertyDescriptor descriptor, 
final String oldValue, final String newValue) {
+final Set routeQueryInfoRels = new HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
+routeQueryInfoRels.add(REL_FAILURE);
+routeQueryInfoRels.add(REL_RETRY);
+
+final Set successRels = new HashSet<>();
--- End diff --

I don't think even needs to exist at this point because 
`routequeryInfoRels` effectively does all three use cases and only gets the 4th 
relationship based on the routing strategy. Might want to refactor that and 
change the name to be more appropriate to the overlap.


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-23 Thread MikeThomsen
Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r183458469
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -267,30 +267,28 @@ public void setup(ProcessContext context) {
 
 @Override
 public void onPropertyModified(final PropertyDescriptor descriptor, 
final String oldValue, final String newValue) {
+final Set routeQueryInfoRels = new HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
+routeQueryInfoRels.add(REL_FAILURE);
+routeQueryInfoRels.add(REL_RETRY);
+
+final Set successRels = new HashSet<>();
+successRels.add(REL_SUCCESS);
+successRels.add(REL_FAILURE);
+successRels.add(REL_RETRY);
+
 if (ROUTING_QUERY_INFO_STRATEGY.equals(descriptor)) {
 if (ALWAYS.getValue().equalsIgnoreCase(newValue)) {
--- End diff --

Not a deal breaker, but I actually had this location in mind.


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-23 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r183427371
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -237,6 +265,39 @@ public void setup(ProcessContext context) {
 super.setup(context);
 }
 
+@Override
+public void onPropertyModified(final PropertyDescriptor descriptor, 
final String oldValue, final String newValue) {
+if (ROUTING_QUERY_INFO_STRATEGY.equals(descriptor)) {
+if (ALWAYS.getValue().equalsIgnoreCase(newValue)) {
+final Set routeQueryInfoRels = new 
HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
--- End diff --

Thanks!  done


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-23 Thread MikeThomsen
Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r183417572
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -237,6 +265,39 @@ public void setup(ProcessContext context) {
 super.setup(context);
 }
 
+@Override
+public void onPropertyModified(final PropertyDescriptor descriptor, 
final String oldValue, final String newValue) {
+if (ROUTING_QUERY_INFO_STRATEGY.equals(descriptor)) {
+if (ALWAYS.getValue().equalsIgnoreCase(newValue)) {
+final Set routeQueryInfoRels = new 
HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
--- End diff --

You have a lot of duplicate code here. You could move:

```
final Set routeQueryInfoRels = new HashSet<>();
routeQueryInfoRels.add(REL_SUCCESS);
routeQueryInfoRels.add(REL_FAILURE);
routeQueryInfoRels.add(REL_RETRY);
```

to before the if/else if blocks and then add `REL_QUERY_INFO` only in those 
two blocks. Also the `this.relationships` assignment could be done there as 
well.


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-19 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r182733953
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttpNoHits.java
 ---
@@ -142,7 +142,7 @@ public void 
testQueryElasticsearchOnTrigger_Hits_NoHits() throws IOException {
 runner.assertValid();
 
 runner.setIncomingConnection(false);
-runAndVerify(3,1,0,true);
+runAndVerify(3,0,0,true);
--- End diff --

Nevermind, I didn't know what that parameter was for, zero is the correct 
value


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-18 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r182592328
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttpNoHits.java
 ---
@@ -142,7 +142,7 @@ public void 
testQueryElasticsearchOnTrigger_Hits_NoHits() throws IOException {
 runner.assertValid();
 
 runner.setIncomingConnection(false);
-runAndVerify(3,1,0,true);
+runAndVerify(3,0,0,true);
--- End diff --

It's been a long one, what scenario are you thinking about?


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-18 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r182589001
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttpNoHits.java
 ---
@@ -142,7 +142,7 @@ public void 
testQueryElasticsearchOnTrigger_Hits_NoHits() throws IOException {
 runner.assertValid();
 
 runner.setIncomingConnection(false);
-runAndVerify(3,1,0,true);
+runAndVerify(3,0,0,true);
--- End diff --

Should we run this with both 1 and 0 for coverage? I haven't looked into 
the parameter, just shooting from the hip :)


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-18 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r182582965
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -352,6 +414,15 @@ private int getPage(final Response getResponse, final 
URL url, final ProcessCont
 JsonNode responseJson = parseJsonResponse(new 
ByteArrayInputStream(bodyBytes));
 JsonNode hits = responseJson.get("hits").get("hits");
 
+if ( (hits.size() == 0 && queryInfoRouteStrategy == 
QueryInfoRouteStrategy.NOHIT)
--- End diff --

OK, you can check my fix


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-18 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r182499545
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -352,6 +414,15 @@ private int getPage(final Response getResponse, final 
URL url, final ProcessCont
 JsonNode responseJson = parseJsonResponse(new 
ByteArrayInputStream(bodyBytes));
 JsonNode hits = responseJson.get("hits").get("hits");
 
+if ( (hits.size() == 0 && queryInfoRouteStrategy == 
QueryInfoRouteStrategy.NOHIT)
--- End diff --

So, you are saying that, if you set it to NO_HITS and you get all 20 at a 
time, you get a query info on the last try?


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-18 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r182498324
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -352,6 +414,15 @@ private int getPage(final Response getResponse, final 
URL url, final ProcessCont
 JsonNode responseJson = parseJsonResponse(new 
ByteArrayInputStream(bodyBytes));
 JsonNode hits = responseJson.get("hits").get("hits");
 
+if ( (hits.size() == 0 && queryInfoRouteStrategy == 
QueryInfoRouteStrategy.NOHIT)
--- End diff --

This part doesn't quite work, not necessarily due to a logic error here, 
but it needs to be addressed either here or in the onTrigger do-while loop. If 
I don't set a limit and I set my page size to 20, then fetch all results (I 
have 100), then I get a flow file on the query-info connection. This is because 
the hitLimit variable is never set as the limit variable is always null, so we 
attempt to get all records starting from index 100, and zero are returned. 
However this code checks that hits.size() is zero (which it is the last time). 
No documents are output of course (due to the for-loop below), but the 
query-info flow file is sent. Perhaps this method needs to know the current 
total number of hits?


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-11 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r180783317
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -175,16 +197,21 @@
 .allowableValues(TARGET_FLOW_FILE_CONTENT, 
TARGET_FLOW_FILE_ATTRIBUTES)
 .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();
 
-private static final Set relationships;
+public static final PropertyDescriptor ROUTING_QUERY_INFO_STRATEGY = 
new PropertyDescriptor.Builder()
+.name("routing-query-info-strategy")
+.displayName("Routing Strategy for Query Info")
+.description("Specifies when to generate and route Query Info 
after a successful query")
+.expressionLanguageSupported(false)
--- End diff --

Fixed thanks


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-11 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r180773767
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -175,16 +197,21 @@
 .allowableValues(TARGET_FLOW_FILE_CONTENT, 
TARGET_FLOW_FILE_ATTRIBUTES)
 .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();
 
-private static final Set relationships;
+public static final PropertyDescriptor ROUTING_QUERY_INFO_STRATEGY = 
new PropertyDescriptor.Builder()
+.name("routing-query-info-strategy")
+.displayName("Routing Strategy for Query Info")
+.description("Specifies when to generate and route Query Info 
after a successful query")
+.expressionLanguageSupported(false)
--- End diff --

As of PR #2205 I believe this has to be changed from false to 
ExpressionLanguageScope.NONE


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-04 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r179217708
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -68,8 +72,10 @@
 + "To retrieve more records, use the ScrollElasticsearchHttp 
processor.")
 @WritesAttributes({
 @WritesAttribute(attribute = "filename", description = "The 
filename attribute is set to the document identifier"),
+@WritesAttribute(attribute = "es.hitCount", description = "The 
number of hits for a query"),
--- End diff --

nah, it is fine by me


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-04 Thread zenfenan
Github user zenfenan commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r179216547
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -68,8 +72,10 @@
 + "To retrieve more records, use the ScrollElasticsearchHttp 
processor.")
 @WritesAttributes({
 @WritesAttribute(attribute = "filename", description = "The 
filename attribute is set to the document identifier"),
+@WritesAttribute(attribute = "es.hitCount", description = "The 
number of hits for a query"),
--- End diff --

Just found out that some processors have used camel cases in writing 
attributes. Sorry about that. Feel free to revert back although `es.hitcount` 
itself looks good to me.


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-03 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178839932
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -175,16 +197,30 @@
 .allowableValues(TARGET_FLOW_FILE_CONTENT, 
TARGET_FLOW_FILE_ATTRIBUTES)
 .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();
 
-private static final Set relationships;
+public static final PropertyDescriptor ROUTING_QUERY_INFO_STRATEGY = 
new PropertyDescriptor.Builder()
+.name("routing-query-info-strategy")
+.displayName("Routing Strategy for Query Info")
+.description("Specifies when to generate and route Query Info 
after a successful query")
+.expressionLanguageSupported(false)
+.allowableValues(ALWAYS, NEVER, NO_HITS)
+.defaultValue(NEVER.getValue())
+.required(false)
+.build();
+
+public static final PropertyDescriptor INCLUDE_QUERY_IN_ATTRS = new 
PropertyDescriptor.Builder()
--- End diff --

done


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-03 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178824015
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -175,16 +197,30 @@
 .allowableValues(TARGET_FLOW_FILE_CONTENT, 
TARGET_FLOW_FILE_ATTRIBUTES)
 .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();
 
-private static final Set relationships;
+public static final PropertyDescriptor ROUTING_QUERY_INFO_STRATEGY = 
new PropertyDescriptor.Builder()
+.name("routing-query-info-strategy")
+.displayName("Routing Strategy for Query Info")
+.description("Specifies when to generate and route Query Info 
after a successful query")
+.expressionLanguageSupported(false)
+.allowableValues(ALWAYS, NEVER, NO_HITS)
+.defaultValue(NEVER.getValue())
+.required(false)
+.build();
+
+public static final PropertyDescriptor INCLUDE_QUERY_IN_ATTRS = new 
PropertyDescriptor.Builder()
--- End diff --

Having the attribute by default sounds fine to me, usually when we have a 
property to choose it's because the value in the attribute could be fairly 
large (such as a compound SQL query used in ExecuteSQL, e.g.).


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-03 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178822510
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -175,16 +197,30 @@
 .allowableValues(TARGET_FLOW_FILE_CONTENT, 
TARGET_FLOW_FILE_ATTRIBUTES)
 .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();
 
-private static final Set relationships;
+public static final PropertyDescriptor ROUTING_QUERY_INFO_STRATEGY = 
new PropertyDescriptor.Builder()
+.name("routing-query-info-strategy")
+.displayName("Routing Strategy for Query Info")
+.description("Specifies when to generate and route Query Info 
after a successful query")
+.expressionLanguageSupported(false)
+.allowableValues(ALWAYS, NEVER, NO_HITS)
+.defaultValue(NEVER.getValue())
+.required(false)
+.build();
+
+public static final PropertyDescriptor INCLUDE_QUERY_IN_ATTRS = new 
PropertyDescriptor.Builder()
--- End diff --

@mattyb149  thoughts?


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-03 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178822326
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -106,6 +121,13 @@
 + "based on the processor properties and the 
results of the fetch operation.")
 .build();
 
+public static final Relationship REL_QUERY_INFO = new 
Relationship.Builder()
+.name("query-info")
+.description(
+"Depending on the setting of the Generate Query Info 
property, a FlowFile is routed to this relationship with " +
--- End diff --

nice catch, fixed


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-03 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178821673
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -68,8 +72,10 @@
 + "To retrieve more records, use the ScrollElasticsearchHttp 
processor.")
 @WritesAttributes({
 @WritesAttribute(attribute = "filename", description = "The 
filename attribute is set to the document identifier"),
+@WritesAttribute(attribute = "es.hitCount", description = "The 
number of hits for a query"),
--- End diff --

done



---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-03 Thread zenfenan
Github user zenfenan commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178816076
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -68,8 +72,10 @@
 + "To retrieve more records, use the ScrollElasticsearchHttp 
processor.")
 @WritesAttributes({
 @WritesAttribute(attribute = "filename", description = "The 
filename attribute is set to the document identifier"),
+@WritesAttribute(attribute = "es.hitCount", description = "The 
number of hits for a query"),
--- End diff --

I believe, in general, it is a standard practice in the project to avoid 
casing `WritesAttributes` so shall we change it to `es.hit.count` or 
`es.hitcount` ?


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-03 Thread zenfenan
Github user zenfenan commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178816096
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -106,6 +121,13 @@
 + "based on the processor properties and the 
results of the fetch operation.")
 .build();
 
+public static final Relationship REL_QUERY_INFO = new 
Relationship.Builder()
+.name("query-info")
+.description(
+"Depending on the setting of the Generate Query Info 
property, a FlowFile is routed to this relationship with " +
--- End diff --

I believe "Generate Query Info" has to be changed to "Routing Strategy for 
Query Info".


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-03 Thread zenfenan
Github user zenfenan commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178817080
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -175,16 +197,30 @@
 .allowableValues(TARGET_FLOW_FILE_CONTENT, 
TARGET_FLOW_FILE_ATTRIBUTES)
 .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();
 
-private static final Set relationships;
+public static final PropertyDescriptor ROUTING_QUERY_INFO_STRATEGY = 
new PropertyDescriptor.Builder()
+.name("routing-query-info-strategy")
+.displayName("Routing Strategy for Query Info")
+.description("Specifies when to generate and route Query Info 
after a successful query")
+.expressionLanguageSupported(false)
+.allowableValues(ALWAYS, NEVER, NO_HITS)
+.defaultValue(NEVER.getValue())
+.required(false)
+.build();
+
+public static final PropertyDescriptor INCLUDE_QUERY_IN_ATTRS = new 
PropertyDescriptor.Builder()
--- End diff --

Should we really need to have a property for this? Writing the 
`es.query.url` as an attribute by default sounds safe to me. Thoughts?


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-02 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178641076
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -219,6 +256,39 @@ public void setup(ProcessContext context) {
 super.setup(context);
 }
 
+@Override
+public void onPropertyModified(final PropertyDescriptor descriptor, 
final String oldValue, final String newValue) {
+if (ROUTING_QUERY_INFO_STRATEGY.equals(descriptor)) {
+if (ALWAYS.getValue().equalsIgnoreCase(newValue)) {
+final Set routeQueryInfoRels = new 
HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
+routeQueryInfoRels.add(REL_FAILURE);
+routeQueryInfoRels.add(REL_RETRY);
+routeQueryInfoRels.add(REL_QUERY_INFO);
+this.relationships = routeQueryInfoRels;
+
+this.queryInfoRouteStrategy = 
QueryInfoRouteStrategy.ALWAYS;
+}else if (NO_HITS.getValue().equalsIgnoreCase(newValue)) {
+final Set routeQueryInfoRels = new 
HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
+routeQueryInfoRels.add(REL_FAILURE);
+routeQueryInfoRels.add(REL_RETRY);
+routeQueryInfoRels.add(REL_QUERY_INFO);
+this.relationships = routeQueryInfoRels;
+
+this.queryInfoRouteStrategy = QueryInfoRouteStrategy.NOHIT;
+}
+}else {
--- End diff --

I believe that will work. Also MockProcessContext calls onPropertyModified 
on set/removeProperty(), so you might be able to parlay that into a unit test 
to check that the relationship is available or not (but I'm not sure)


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-02 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178637480
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -219,6 +256,39 @@ public void setup(ProcessContext context) {
 super.setup(context);
 }
 
+@Override
+public void onPropertyModified(final PropertyDescriptor descriptor, 
final String oldValue, final String newValue) {
+if (ROUTING_QUERY_INFO_STRATEGY.equals(descriptor)) {
+if (ALWAYS.getValue().equalsIgnoreCase(newValue)) {
+final Set routeQueryInfoRels = new 
HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
+routeQueryInfoRels.add(REL_FAILURE);
+routeQueryInfoRels.add(REL_RETRY);
+routeQueryInfoRels.add(REL_QUERY_INFO);
+this.relationships = routeQueryInfoRels;
+
+this.queryInfoRouteStrategy = 
QueryInfoRouteStrategy.ALWAYS;
+}else if (NO_HITS.getValue().equalsIgnoreCase(newValue)) {
+final Set routeQueryInfoRels = new 
HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
+routeQueryInfoRels.add(REL_FAILURE);
+routeQueryInfoRels.add(REL_RETRY);
+routeQueryInfoRels.add(REL_QUERY_INFO);
+this.relationships = routeQueryInfoRels;
+
+this.queryInfoRouteStrategy = QueryInfoRouteStrategy.NOHIT;
+}
+}else {
--- End diff --

 if (ROUTING_QUERY_INFO_STRATEGY.equals(descriptor)) ?


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-02 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178635886
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -219,6 +256,39 @@ public void setup(ProcessContext context) {
 super.setup(context);
 }
 
+@Override
+public void onPropertyModified(final PropertyDescriptor descriptor, 
final String oldValue, final String newValue) {
+if (ROUTING_QUERY_INFO_STRATEGY.equals(descriptor)) {
+if (ALWAYS.getValue().equalsIgnoreCase(newValue)) {
+final Set routeQueryInfoRels = new 
HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
+routeQueryInfoRels.add(REL_FAILURE);
+routeQueryInfoRels.add(REL_RETRY);
+routeQueryInfoRels.add(REL_QUERY_INFO);
+this.relationships = routeQueryInfoRels;
+
+this.queryInfoRouteStrategy = 
QueryInfoRouteStrategy.ALWAYS;
+}else if (NO_HITS.getValue().equalsIgnoreCase(newValue)) {
+final Set routeQueryInfoRels = new 
HashSet<>();
+routeQueryInfoRels.add(REL_SUCCESS);
+routeQueryInfoRels.add(REL_FAILURE);
+routeQueryInfoRels.add(REL_RETRY);
+routeQueryInfoRels.add(REL_QUERY_INFO);
+this.relationships = routeQueryInfoRels;
+
+this.queryInfoRouteStrategy = QueryInfoRouteStrategy.NOHIT;
+}
+}else {
--- End diff --

This whole if-else should be wrapped in a check to see if the 
PropertyDescriptor is the Query Info Strategy property. Otherwise, changing any 
other property results in entering this final else clause, thereby resetting 
the Query Info Strategy to "Never".


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-02 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178636382
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttpNoHits.java
 ---
@@ -0,0 +1,365 @@
+/*
+ * 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.processors.elasticsearch;
+
+import static org.junit.Assert.assertEquals;
--- End diff --

Checkstyle violation here, unused import, please remove (and see my comment 
above about running your own style check before submitting the PR, definitely 
helps the review/merge process), please and thanks!


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-02 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2601#discussion_r178636130
  
--- Diff: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/main/java/org/apache/nifi/processors/elasticsearch/QueryElasticsearchHttp.java
 ---
@@ -255,6 +325,8 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 .evaluateAttributeExpressions(flowFile).getValue() : null;
 final boolean targetIsContent = 
context.getProperty(TARGET).getValue()
 .equals(TARGET_FLOW_FILE_CONTENT);
+final boolean includeQueryInAttrs = 
context.getProperty(INCLUDE_QUERY_IN_ATTRS).isSet() ?
--- End diff --

CheckStyle violation here, the ? should be on the next line. You can run 
your Maven build for the nifi-elasticsearch-bundle with the contrib-check 
profile activated (`-Pcontrib-check`) and it will run a style check for you.


---


[GitHub] nifi pull request #2601: NIFI-3576 Support for QueryInfo relationship, usefu...

2018-04-02 Thread ottobackwards
GitHub user ottobackwards opened a pull request:

https://github.com/apache/nifi/pull/2601

NIFI-3576 Support for QueryInfo relationship, useful for nohit queries

This pr adds a new relationship, and a property/strategy for when it is 
used.
The new relationship has an empty flow file with attributes about the 
query, right now the query string and the number of hits.

The relationship is dynamically made available based on the strategy 
selected:

Never : um, never send query information
Always: always send it
NoHit: Send it when there are no hits.



Thank you for submitting a contribution to Apache NiFi.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

### For all changes:
- [x] Is there a JIRA ticket associated with this PR? Is it referenced 
 in the commit message?

- [x] Does your PR title start with NIFI- where  is the JIRA number 
you are trying to resolve? Pay particular attention to the hyphen "-" character.

- [x] Has your PR been rebased against the latest commit within the target 
branch (typically master)?

- [x] Is your initial contribution a single, squashed commit?

### For code changes:
- [x] Have you ensured that the full suite of tests is executed via mvn 
-Pcontrib-check clean install at the root nifi folder?
- [x] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)? 
- [ ] If applicable, have you updated the LICENSE file, including the main 
LICENSE file under nifi-assembly?
- [ ] If applicable, have you updated the NOTICE file, including the main 
NOTICE file found under nifi-assembly?
- [x] If adding new Properties, have you added .displayName in addition to 
.name (programmatic access) for each of the new properties?

### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in 
which it is rendered?

### Note:
Please ensure that once the PR is submitted, you check travis-ci for build 
issues and submit an update to your PR as soon as possible.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/ottobackwards/nifi nohit-support

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/nifi/pull/2601.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #2601


commit ad1c4614104c541c68227658f784ec21f6e06694
Author: Otto Fowler 
Date:   2018-04-02T17:16:39Z

NIFI-3576 Support for QueryInfo relationship, can be used to track no-hits




---