本文整理汇总了Java中org.apache.nifi.processor.exception.ProcessException类的典型用法代码示例。如果您正苦于以下问题:Java ProcessException类的具体用法?Java ProcessException怎么用?Java ProcessException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProcessException类属于org.apache.nifi.processor.exception包,在下文中一共展示了ProcessException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTrigger
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
final ProcessorLog log = this.getLogger();
final AtomicReference<String> value = new AtomicReference<>();
final Map<String, String> tessProperties = toProperties(context.getProperty(TESS_PROPERTIES).getValue());
final File tessDataDir = new File(context.getProperty(TESS_DATA).getValue());
System.getProperties().setProperty("jna.library.path", context.getProperty(JNI_PATH).getValue());
FlowFile flowfile = session.get();
if (null != flowfile) {
session.read(flowfile, in -> {
try {
value.set(TesseractUtil.INSTANCE.ocr(in, tessDataDir, tessProperties));
} catch (Exception e) {
log.error("Unable to ocr: " + e.getMessage(), e);
}
});
flowfile = session.write(flowfile, out -> {
out.write(value.get().getBytes());
out.flush();
});
session.transfer(flowfile, SUCCESS);
} else {
log.warn("NULL flow file");
}
}
示例2: rendezvousWithJms
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
/**
* Will construct JMS {@link Message} by extracting its body from the
* incoming {@link FlowFile}. {@link FlowFile} attributes that represent
* standard JMS headers will be extracted from the {@link FlowFile} and set
* as JMS headers on the newly constructed message. For the list of
* available message headers please see {@link JmsHeaders}. <br>
* <br>
* Upon success the incoming {@link FlowFile} is transferred to the'success'
* {@link Relationship} and upon failure FlowFile is penalized and
* transferred to the 'failure' {@link Relationship}
*
*/
@Override
protected void rendezvousWithJms(ProcessContext context, ProcessSession processSession) throws ProcessException {
FlowFile flowFile = processSession.get();
if (flowFile != null) {
try {
String destinationName = context.getProperty(DESTINATION).evaluateAttributeExpressions(flowFile).getValue();
this.targetResource.publish(destinationName, this.extractMessageBody(flowFile, processSession), flowFile.getAttributes());
processSession.transfer(flowFile, REL_SUCCESS);
processSession.getProvenanceReporter().send(flowFile, context.getProperty(DESTINATION).evaluateAttributeExpressions().getValue());
} catch (Exception e) {
processSession.transfer(flowFile, REL_FAILURE);
this.getLogger().error("Failed while sending message to JMS via " + this.targetResource, e);
context.yield();
}
}
}
示例3: onTrigger
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
ComponentLog logger = getLogger();
FlowFile flowFile = session.get();
// Create the flowfile, as it probably does not exist
if (flowFile == null)
flowFile = session.create();
// Get the data
String data = generateData(context.getProperty(PRINT_HEADER).asBoolean(), context.getProperty(LONG_TIMESTAMP).asBoolean(), context.getProperty(TIMEZONE).toString(), context.getProperty(DATA_FORMAT).getValue());
// Write the results back out to flow file
try{
flowFile = session.write(flowFile, out -> out.write(data.getBytes()));
session.getProvenanceReporter().create(flowFile);
session.transfer(flowFile, SUCCESS);
} catch (ProcessException ex) {
logger.error("Unable to write generated data out to flowfile. Error: ", ex);
}
}
示例4: onTrigger
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
List<FlowFile> incoming = session.get(batchSize);
if (incoming.isEmpty()) {
return;
}
/*
Each relationship can have multiple connections.
context.getAvailableRelationships().contains(PASS_THROUGH) will return true if all
PASS_THROUGH connections are available (not back pressured). So if a PASS_THROUGH
relationship has 2 connections with back pressure of 10 and 20 and only the 10's
connection is back pressured, contains(PASS_THROUGH) will return false
*/
final boolean isPassthroughClear = context.getAvailableRelationships().contains(PASS_THROUGH);
session.transfer(incoming, isPassthroughClear ? PASS_THROUGH : BACK_PRESSURED);
}
示例5: onTrigger
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
final ProcessorLog log = this.getLogger();
final AtomicReference<byte[]> value = new AtomicReference<>();
String preprocessingDef = context.getProperty(DEFINITIONS).getValue();
String tempDir = context.getProperty(TEMP_DIR).getValue();
String convertPath = context.getProperty(CONVERT_PATH).getValue();
CommandLine cli = CleaningOptions.parse(new DefaultParser(), CLIUtils.translateCommandline(preprocessingDef) );
final TextCleaner cleaner = CleaningOptions.createTextCleaner(cli, convertPath, tempDir);
FlowFile flowfile = session.get();
session.read(flowfile, in -> {
try {
value.set(cleaner.convert(in));
} catch (Exception e) {
value.set(IOUtils.toByteArray(in));
log.error("Unable to execute command: " + e.getMessage(), e);
}
});
flowfile = session.write(flowfile, out -> {
out.write(value.get());
out.flush();
});
session.transfer(flowfile, SUCCESS);
}
示例6: onTrigger
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext ctx, ProcessSession session) throws ProcessException {
FlowFile flowFile = session.get();
if (flowFile == null) {
return;
}
final DelegatedAuthorizationProviderService authProviderSvc = ctx.getProperty(AUTHORIZATION_PROVIDER_SERVICE_PROP).asControllerService(DelegatedAuthorizationProviderService.class);
final String tokenValueAttribute = ctx.getProperty(TOKEN_ATTRIBUTE_NAME_PROP).getValue();
final String tokenValue = flowFile.getAttribute(tokenValueAttribute);
if (StringUtils.isEmpty(tokenValue)) {
session.transfer(flowFile, UNAUTHORIZED_REL);
return;
}
session.adjustCounter(tokenValue, 1, false);
final AuthorizationToken authorizationToken = new StandardAuthorizationToken(tokenValue);
final Set<AuthorizationToken> authorizationTokens = authProviderSvc.getAuthorizationTokens();
session.transfer(flowFile, authorizationTokens.contains(authorizationToken) ? AUTHORIZED_REL : UNAUTHORIZED_REL);
}
示例7: setup
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
/**
* Performs setup operations when the processor is scheduled to run. This includes evaluating the processor's
* properties, as well as reloading the script (from file or the "Script Body" property)
*
* @param context the context in which to perform the setup operations
*/
@OnScheduled
public void setup(final ProcessContext context) {
scriptingComponentHelper.setupVariables(context);
// Create a script engine for each possible task
int maxTasks = context.getMaxConcurrentTasks();
scriptingComponentHelper.setup(maxTasks, getLogger());
scriptToRun = scriptingComponentHelper.getScriptBody();
try {
if (scriptToRun == null && scriptingComponentHelper.getScriptPath() != null) {
try (final FileInputStream scriptStream = new FileInputStream(scriptingComponentHelper.getScriptPath())) {
scriptToRun = IOUtils.toString(scriptStream, Charset.defaultCharset());
}
}
} catch (IOException ioe) {
throw new ProcessException(ioe);
}
}
示例8: onTrigger
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
FlowFile flowFile = session.get();
if (flowFile == null) {
return;
}
RenameJSONFieldsStreamCallback streamCallback = new RenameJSONFieldsStreamCallback();
flowFile = session.write(flowFile, streamCallback);
if (streamCallback.getError() != null) {
getLogger().error("Failed processing JSON for {}; routing to 'failure'",
new Object[]{flowFile}, streamCallback.getError());
session.transfer(flowFile, REL_FAILURE);
} else {
getLogger().info("Successfully processed JSON for {}; routing to 'success'",
new Object[]{flowFile});
session.transfer(flowFile, REL_SUCCESS);
session.getProvenanceReporter().modifyContent(flowFile);
}
}
示例9: validateAndParseJSONContent
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
Map<String, Object> validateAndParseJSONContent(ProcessSession processSession, FlowFile flowFile) throws JsonParseException {
final Map<String, Object> jsonContent = Maps.newHashMap();
try {
processSession.read(flowFile, new InputStreamCallback() {
@Override
public void process(InputStream in) throws IOException {
JsonParser jp = jsonFactory.createParser(in);
jsonContent.putAll(jp.readValueAs(Map.class));
}
});
} catch (ProcessException e) {
if (e.getCause() instanceof JsonParseException) {
throw (JsonParseException)e.getCause();
} else {
throw e;
}
}
return jsonContent;
}
示例10: onTrigger
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
// TODO Auto-generated method stub
FlowFile flowfile = session.get();
flowfile = session.putAttribute(flowfile, "Directory", "/home/sivaprakash/Siva/Edgent/NifiTestout");
session.transfer(flowfile,REL_SUCCESS);
}
示例11: onTrigger
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
// TODO Auto-generated method stub
FlowFile flowfile = session.get();
Map<String,String> attr =flowfile.getAttributes();
String batchID = flowfile.getAttribute("batchID");
if(attr.containsKey("fromEdgent")) {
//String imageId = flowfile.getAttribute("imageID");
if(batchMap.containsKey(batchID)) {
session.transfer(flowfile, REL_SUCCESS);
batchMap.put(batchID, "");
} else {
session.remove(flowfile);
}
}
else {
batchMap.put(batchID, "");
session.remove(flowfile);
}
session.commit();
// else
// {
// String url = flowfile.getAttribute("URL");
// urlMap.put(batchID,url);
// if(imageMap.containsKey(batchID)) {
// flowfile = session.putAttribute(flowfile, "imageID",imageMap.get(batchID));
// session.transfer(flowfile, REL_SUCCESS);
// imageMap.remove(batchID);
// batchMap.put(batchID, "");
// }
// else
// session.remove(flowfile);
// }
}
示例12: onTrigger
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
FlowFile flowFile = session.get();
if (flowFile == null) {
flowFile = session.create();
}
try {
flowFile.getAttributes();
flowFile = session.putAttribute(flowFile, "mime.type", "application/json");
flowFile = session.write(flowFile, new StreamCallback() {
@Override
public void process(InputStream inputStream, OutputStream outputStream) throws IOException {
Tika tika = new Tika();
String text = "";
try {
text = tika.parseToString(inputStream);
} catch (TikaException e) {
getLogger().error("Apache Tika failed to parse input " + e.getLocalizedMessage());
e.printStackTrace();
}
// TODO: wrap in JSON???
outputStream.write(text.getBytes());
}
});
session.transfer(flowFile, REL_SUCCESS);
session.commit();
} catch (final Throwable t) {
getLogger().error("Unable to process ExtractTextProcessor file " + t.getLocalizedMessage());
getLogger().error("{} failed to process due to {}; rolling back session", new Object[] { this, t });
throw t;
}
}
示例13: rendezvousWithJms
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
/**
* Will construct a {@link FlowFile} containing the body of the consumed JMS
* message (if {@link GetResponse} returned by {@link JMSConsumer} is not
* null) and JMS properties that came with message which are added to a
* {@link FlowFile} as attributes, transferring {@link FlowFile} to
* 'success' {@link Relationship}.
*/
@Override
protected void rendezvousWithJms(final ProcessContext context, final ProcessSession processSession) throws ProcessException {
final String destinationName = context.getProperty(DESTINATION).evaluateAttributeExpressions().getValue();
this.targetResource.consume(destinationName, new ConsumerCallback(){
@Override
public void accept(final JMSResponse response) {
if (response != null){
FlowFile flowFile = processSession.create();
flowFile = processSession.write(flowFile, new OutputStreamCallback() {
@Override
public void process(final OutputStream out) throws IOException {
out.write(response.getMessageBody());
}
});
Map<String, Object> jmsHeaders = response.getMessageHeaders();
Map<String, Object> jmsProperties = Collections.<String, Object>unmodifiableMap(response.getMessageProperties());
flowFile = ConsumeJMS.this.updateFlowFileAttributesWithJMSAttributes(jmsHeaders, flowFile, processSession);
flowFile = ConsumeJMS.this.updateFlowFileAttributesWithJMSAttributes(jmsProperties, flowFile, processSession);
flowFile = processSession.putAttribute(flowFile, JMS_SOURCE_DESTINATION_NAME, destinationName);
processSession.getProvenanceReporter().receive(flowFile, destinationName);
processSession.transfer(flowFile, REL_SUCCESS);
processSession.commit();
} else {
context.yield();
}
}
});
}
示例14: onTrigger
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
/**
* Builds target resource ({@link JMSPublisher} or {@link JMSConsumer}) upon
* first invocation while delegating to the sub-classes ( {@link PublishJMS}
* or {@link ConsumeJMS}) via
* {@link #rendezvousWithJms(ProcessContext, ProcessSession)} method.
*/
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
synchronized (this) {
this.buildTargetResource(context);
}
this.rendezvousWithJms(context, session);
}
示例15: getValue
import org.apache.nifi.processor.exception.ProcessException; //导入依赖的package包/类
@Override
public byte[] getValue(String reqTagname) throws ProcessException {
final ComponentLog logger = getLogger();
// TODO presently this method accepts a tag name as input and fetches a value for that tag
// A future version will need to be able to acquire a value from a specific time in the past
String serverResponse = "";
ReadValueId[] NodesToRead = {
new ReadValueId(NodeId.parseNodeId(reqTagname), Attributes.Value, null, null )
};
// Form OPC request
ReadRequest req = new ReadRequest();
req.setMaxAge(500.00);
req.setTimestampsToReturn(TimestampsToReturn.Both);
req.setRequestHeader(null);
req.setNodesToRead(NodesToRead);
// Submit OPC Read and handle response
try{
ReadResponse readResponse = mySession.Read(req);
DataValue[] values = readResponse.getResults();
// TODO need to check the result for errors and other quality issues
serverResponse = reqTagname + "," + values[0].getValue().toString() + ","+ values[0].getServerTimestamp().toString();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return serverResponse.getBytes();
}