mirror of https://github.com/apache/nifi.git
NIFI-11123: fix default value and update docs
This closes #6899. Signed-off-by: Tamas Palfy <tpalfy@apache.org>
This commit is contained in:
parent
869e2b3d66
commit
027e2b9bc1
|
@ -24,14 +24,40 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import org.apache.nifi.annotation.lifecycle.OnStopped;
|
import org.apache.nifi.annotation.lifecycle.OnStopped;
|
||||||
import org.apache.nifi.components.PropertyDescriptor;
|
import org.apache.nifi.components.PropertyDescriptor;
|
||||||
|
import org.apache.nifi.components.PropertyValue;
|
||||||
|
import org.apache.nifi.expression.ExpressionLanguageScope;
|
||||||
import org.apache.nifi.flowfile.FlowFile;
|
import org.apache.nifi.flowfile.FlowFile;
|
||||||
import org.apache.nifi.processor.ProcessContext;
|
import org.apache.nifi.processor.ProcessContext;
|
||||||
import org.apache.nifi.processor.ProcessSession;
|
import org.apache.nifi.processor.ProcessSession;
|
||||||
import org.apache.nifi.processor.exception.ProcessException;
|
import org.apache.nifi.processor.exception.ProcessException;
|
||||||
|
import org.apache.nifi.processor.util.StandardValidators;
|
||||||
|
|
||||||
public abstract class AbstractStartGcpVisionOperation<B extends com.google.protobuf.GeneratedMessageV3.Builder<B>> extends AbstractGcpVisionProcessor {
|
public abstract class AbstractStartGcpVisionOperation<B extends com.google.protobuf.GeneratedMessageV3.Builder<B>> extends AbstractGcpVisionProcessor {
|
||||||
|
public static final PropertyDescriptor FEATURE_TYPE = new PropertyDescriptor.Builder()
|
||||||
|
.name("vision-feature-type")
|
||||||
|
.displayName("Vision Feature Type")
|
||||||
|
.description("Type of GCP Vision Feature. The value of this property applies when the JSON Payload property is configured. " +
|
||||||
|
"The JSON Payload property value can use Expression Language to reference the value of ${vision-feature-type}")
|
||||||
|
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
|
||||||
|
.required(false)
|
||||||
|
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
|
||||||
|
.defaultValue("TEXT_DETECTION")
|
||||||
|
.build();
|
||||||
|
public static final PropertyDescriptor OUTPUT_BUCKET = new PropertyDescriptor.Builder()
|
||||||
|
.name("output-bucket")
|
||||||
|
.displayName("Output Bucket")
|
||||||
|
.description("Name of the GCS bucket where the output of the Vision job will be persisted. " +
|
||||||
|
"The value of this property applies when the JSON Payload property is configured. " +
|
||||||
|
"The JSON Payload property value can use Expression Language to reference the value of ${output-bucket}")
|
||||||
|
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
|
||||||
|
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
|
||||||
|
.required(false)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
|
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
|
||||||
|
@ -70,7 +96,18 @@ public abstract class AbstractStartGcpVisionOperation<B extends com.google.proto
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream getInputStreamFromProperty(ProcessContext context, FlowFile flowFile) {
|
private InputStream getInputStreamFromProperty(ProcessContext context, FlowFile flowFile) {
|
||||||
return new ByteArrayInputStream(context.getProperty(getJsonPayloadPropertyDescriptor()).evaluateAttributeExpressions(flowFile).getValue().getBytes(StandardCharsets.UTF_8));
|
Map<String, String> attributes = new HashMap<>();
|
||||||
|
attributes.put(OUTPUT_BUCKET.getName(), getAttributeValue(context, flowFile, OUTPUT_BUCKET.getName()));
|
||||||
|
attributes.put(FEATURE_TYPE.getName(), getAttributeValue(context, flowFile, FEATURE_TYPE.getName()));
|
||||||
|
final PropertyValue jsonPropertyValue = context.getProperty(getJsonPayloadPropertyDescriptor());
|
||||||
|
final String jsonPayload = jsonPropertyValue.evaluateAttributeExpressions(flowFile, attributes).getValue();
|
||||||
|
return new ByteArrayInputStream(jsonPayload.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getAttributeValue(ProcessContext context, FlowFile flowFile, String name) {
|
||||||
|
final String flowFileAttribute = flowFile.getAttribute(name);
|
||||||
|
final PropertyValue propertyValue = context.getProperty(name);
|
||||||
|
return flowFileAttribute == null ? propertyValue.getValue() : flowFileAttribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract B newBuilder();
|
abstract B newBuilder();
|
||||||
|
|
|
@ -56,12 +56,12 @@ public class StartGcpVisionAnnotateFilesOperation extends AbstractStartGcpVision
|
||||||
" \"mimeType\": \"application/pdf\"\n" +
|
" \"mimeType\": \"application/pdf\"\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"features\": [{\n" +
|
" \"features\": [{\n" +
|
||||||
" \"type\": \"DOCUMENT_TEXT_DETECTION\",\n" +
|
" \"type\": \"${vision-feature-type}\",\n" +
|
||||||
" \"maxResults\": 4\n" +
|
" \"maxResults\": 4\n" +
|
||||||
" }],\n" +
|
" }],\n" +
|
||||||
" \"outputConfig\": {\n" +
|
" \"outputConfig\": {\n" +
|
||||||
" \"gcsDestination\": {\n" +
|
" \"gcsDestination\": {\n" +
|
||||||
" \"uri\": \"gs://${gcs.bucket}/${filename}/\"\n" +
|
" \"uri\": \"gs://${output-bucket}/${filename}/\"\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"batchSize\": 2\n" +
|
" \"batchSize\": 2\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
|
@ -70,7 +70,7 @@ public class StartGcpVisionAnnotateFilesOperation extends AbstractStartGcpVision
|
||||||
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
|
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
|
||||||
.build();
|
.build();
|
||||||
private static final List<PropertyDescriptor> PROPERTIES = Collections.unmodifiableList(Arrays.asList(
|
private static final List<PropertyDescriptor> PROPERTIES = Collections.unmodifiableList(Arrays.asList(
|
||||||
JSON_PAYLOAD, GCP_CREDENTIALS_PROVIDER_SERVICE));
|
JSON_PAYLOAD, GCP_CREDENTIALS_PROVIDER_SERVICE, OUTPUT_BUCKET, FEATURE_TYPE));
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
|
public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
|
||||||
|
|
|
@ -55,13 +55,13 @@ public class StartGcpVisionAnnotateImagesOperation extends AbstractStartGcpVisio
|
||||||
" }\n" +
|
" }\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"features\": [{\n" +
|
" \"features\": [{\n" +
|
||||||
" \"type\": \"FACE_DETECTION\",\n" +
|
" \"type\": \"${vision-feature-type}\",\n" +
|
||||||
" \"maxResults\": 4\n" +
|
" \"maxResults\": 4\n" +
|
||||||
" }]\n" +
|
" }]\n" +
|
||||||
" }],\n" +
|
" }],\n" +
|
||||||
" \"outputConfig\": {\n" +
|
" \"outputConfig\": {\n" +
|
||||||
" \"gcsDestination\": {\n" +
|
" \"gcsDestination\": {\n" +
|
||||||
" \"uri\": \"gs://${gcs.bucket}/${filename}/\"\n" +
|
" \"uri\": \"gs://${output-bucket}/${filename}/\"\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
" \"batchSize\": 2\n" +
|
" \"batchSize\": 2\n" +
|
||||||
" }\n" +
|
" }\n" +
|
||||||
|
@ -69,7 +69,7 @@ public class StartGcpVisionAnnotateImagesOperation extends AbstractStartGcpVisio
|
||||||
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
|
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
|
||||||
.build();
|
.build();
|
||||||
private static final List<PropertyDescriptor> PROPERTIES = Collections.unmodifiableList(Arrays.asList(
|
private static final List<PropertyDescriptor> PROPERTIES = Collections.unmodifiableList(Arrays.asList(
|
||||||
JSON_PAYLOAD, GCP_CREDENTIALS_PROVIDER_SERVICE));
|
JSON_PAYLOAD, GCP_CREDENTIALS_PROVIDER_SERVICE, OUTPUT_BUCKET, FEATURE_TYPE));
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
|
public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
|
||||||
|
|
|
@ -55,12 +55,12 @@
|
||||||
"mimeType": "application/pdf"
|
"mimeType": "application/pdf"
|
||||||
},
|
},
|
||||||
"features": [{
|
"features": [{
|
||||||
"type": "DOCUMENT_TEXT_DETECTION",
|
"type": "${vision-feature-type}",
|
||||||
"maxResults": 4
|
"maxResults": 4
|
||||||
}],
|
}],
|
||||||
"outputConfig": {
|
"outputConfig": {
|
||||||
"gcsDestination": {
|
"gcsDestination": {
|
||||||
"uri": "gs://${gcs.bucket}/${filename}/"
|
"uri": "gs://${output-bucket}/${filename}/"
|
||||||
},
|
},
|
||||||
"batchSize": 2
|
"batchSize": 2
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,12 @@ You can find more details at <a href="https://cloud.google.com/vision/docs/featu
|
||||||
<p>Create the following flow</p>
|
<p>Create the following flow</p>
|
||||||
<img src="vision-annotate-files.png" style="height: 50%; width: 50%"/>
|
<img src="vision-annotate-files.png" style="height: 50%; width: 50%"/>
|
||||||
<p>
|
<p>
|
||||||
Keep the default value of JSON PAYLOAD property in StartGcpVisionAnnotateImagesOperation
|
<li>Create an input and output bucket</li>
|
||||||
|
<li>Make sure the input files(s) are available in the input GCS bucket</li>
|
||||||
|
<li>Set the bucket property of ListGCSBucket processor to your input bucket name</li>
|
||||||
|
<li>Keep the default value of JSON PAYLOAD property in StartGcpVisionAnnotateFilesOperation</li>
|
||||||
|
<li>Set the Output Bucket property to your output bucket name in StartGcpVisionAnnotateFilesOperation</li>
|
||||||
|
<li>Setup GCP Credentials Provider Service for all GCP related processor</li>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Execution steps:
|
Execution steps:
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
Prerequisites
|
Prerequisites
|
||||||
<ul>
|
<ul>
|
||||||
<li>Make sure Vision API is enabled and the account you are using has the right to use it</li>
|
<li>Make sure Vision API is enabled and the account you are using has the right to use it</li>
|
||||||
<li>Make sure thne input image(s) are available in a GCS bucket</li>
|
<li>Make sure the input image(s) are available in a GCS bucket under <code>/input</code> folder</li>
|
||||||
</ul>
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
<h3>Usage</h3>
|
<h3>Usage</h3>
|
||||||
|
@ -53,13 +53,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"features": [{
|
"features": [{
|
||||||
"type": "DOCUMENT_TEXT_DETECTION",
|
"type": "${vision-feature-type}",
|
||||||
"maxResults": 4
|
"maxResults": 4
|
||||||
}]
|
}]
|
||||||
}],
|
}],
|
||||||
"outputConfig": {
|
"outputConfig": {
|
||||||
"gcsDestination": {
|
"gcsDestination": {
|
||||||
"uri": "gs://${gcs.bucket}/${filename}/"
|
"uri": "gs://${output-bucket}/${filename}/"
|
||||||
},
|
},
|
||||||
"batchSize": 2
|
"batchSize": 2
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,14 @@ You can find more details at <a href="https://cloud.google.com/vision/docs/featu
|
||||||
<p>Create the following flow</p>
|
<p>Create the following flow</p>
|
||||||
<img src="vision-annotate-images.png" style="height: 50%; width: 50%"/>
|
<img src="vision-annotate-images.png" style="height: 50%; width: 50%"/>
|
||||||
<p>
|
<p>
|
||||||
Keep the default value of JSON PAYLOAD property in StartGcpVisionAnnotateImagesOperation
|
<ul>
|
||||||
|
<li>Create an input and output bucket</li>
|
||||||
|
<li>Make sure the input images(s) are available in the input GCS bucket</li>
|
||||||
|
<li>Set the bucket property of ListGCSBucket processor to your input bucket name</li>
|
||||||
|
<li>Keep the default value of JSON PAYLOAD property in StartGcpVisionAnnotateImagesOperation</li>
|
||||||
|
<li>Set the Output Bucket property to your output bucket name in StartGcpVisionAnnotateImagesOperation</li>
|
||||||
|
<li>Setup GCP Credentials Provider Service for all GCP related processor</li>
|
||||||
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Execution steps:
|
Execution steps:
|
||||||
|
|
Loading…
Reference in New Issue