use of org.apache.nifi.annotation.lifecycle.OnScheduled in project nifi by apache.
the class AttributeRollingWindow method onScheduled.
@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
timeWindow = context.getProperty(TIME_WINDOW).asTimePeriod(TimeUnit.MILLISECONDS);
microBatchTime = context.getProperty(SUB_WINDOW_LENGTH).asTimePeriod(TimeUnit.MILLISECONDS);
if (microBatchTime == null || microBatchTime == 0) {
StateManager stateManager = context.getStateManager();
StateMap state = stateManager.getState(SCOPE);
HashMap<String, String> tempMap = new HashMap<>();
tempMap.putAll(state.toMap());
if (!tempMap.containsKey(COUNT_KEY)) {
tempMap.put(COUNT_KEY, "0");
context.getStateManager().setState(tempMap, SCOPE);
}
}
}
use of org.apache.nifi.annotation.lifecycle.OnScheduled in project nifi by apache.
the class PutIgniteCache method initializeIgniteDataStreamer.
/**
* Initialize ignite cache
*/
@OnScheduled
public final void initializeIgniteDataStreamer(ProcessContext context) throws ProcessException {
super.initializeIgniteCache(context);
if (getIgniteDataStreamer() != null) {
return;
}
getLogger().info("Creating Ignite Datastreamer");
try {
int perNodeParallelOperations = context.getProperty(DATA_STREAMER_PER_NODE_PARALLEL_OPERATIONS).asInteger();
int perNodeBufferSize = context.getProperty(DATA_STREAMER_PER_NODE_BUFFER_SIZE).asInteger();
int autoFlushFrequency = context.getProperty(DATA_STREAMER_AUTO_FLUSH_FREQUENCY).asInteger();
boolean allowOverride = context.getProperty(DATA_STREAMER_ALLOW_OVERRIDE).asBoolean();
igniteDataStreamer = getIgnite().dataStreamer(getIgniteCache().getName());
igniteDataStreamer.perNodeBufferSize(perNodeBufferSize);
igniteDataStreamer.perNodeParallelOperations(perNodeParallelOperations);
igniteDataStreamer.autoFlushFrequency(autoFlushFrequency);
igniteDataStreamer.allowOverwrite(allowOverride);
} catch (Exception e) {
getLogger().error("Failed to schedule PutIgnite due to {}", new Object[] { e }, e);
throw new ProcessException(e);
}
}
use of org.apache.nifi.annotation.lifecycle.OnScheduled in project nifi by apache.
the class GetHBase method parseColumns.
@OnScheduled
public void parseColumns(final ProcessContext context) throws IOException {
final StateMap stateMap = context.getStateManager().getState(Scope.CLUSTER);
if (stateMap.getVersion() < 0) {
// no state has been stored in the State Manager - check if we have state stored in the
// DistributedMapCacheClient service and migrate it if so
final DistributedMapCacheClient client = context.getProperty(DISTRIBUTED_CACHE_SERVICE).asControllerService(DistributedMapCacheClient.class);
final ScanResult scanResult = getState(client);
if (scanResult != null) {
storeState(scanResult, context.getStateManager());
}
clearState(client);
}
final String columnsValue = context.getProperty(COLUMNS).getValue();
final String[] columns = (columnsValue == null || columnsValue.isEmpty() ? new String[0] : columnsValue.split(","));
this.columns.clear();
for (final String column : columns) {
if (column.contains(":")) {
final String[] parts = column.split(":");
final byte[] cf = parts[0].getBytes(Charset.forName("UTF-8"));
final byte[] cq = parts[1].getBytes(Charset.forName("UTF-8"));
this.columns.add(new Column(cf, cq));
} else {
final byte[] cf = column.getBytes(Charset.forName("UTF-8"));
this.columns.add(new Column(cf, null));
}
}
}
use of org.apache.nifi.annotation.lifecycle.OnScheduled in project nifi by apache.
the class ScanHBase method onScheduled.
@OnScheduled
public void onScheduled(ProcessContext context) {
this.decodeCharset = Charset.forName(context.getProperty(DECODE_CHARSET).getValue());
this.encodeCharset = Charset.forName(context.getProperty(ENCODE_CHARSET).getValue());
final String jsonFormat = context.getProperty(JSON_FORMAT).getValue();
if (jsonFormat.equals(JSON_FORMAT_FULL_ROW.getValue())) {
this.serializer = new JsonFullRowSerializer(decodeCharset, encodeCharset);
} else {
this.serializer = new JsonQualifierAndValueRowSerializer(decodeCharset, encodeCharset);
}
}
use of org.apache.nifi.annotation.lifecycle.OnScheduled in project nifi by apache.
the class ExecuteGroovyScript method onScheduled.
/**
* 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 onScheduled(final ProcessContext context) {
// SCRIPT_FILE
this.scriptFile = asFile(context.getProperty(SCRIPT_FILE).evaluateAttributeExpressions().getValue());
// SCRIPT_BODY
this.scriptBody = context.getProperty(SCRIPT_BODY).getValue();
// ADD_CLASSPATH
this.addClasspath = context.getProperty(ADD_CLASSPATH).evaluateAttributeExpressions().getValue();
// evaluated from ${groovy.classes.path} global property
this.groovyClasspath = context.newPropertyValue(GROOVY_CLASSPATH).evaluateAttributeExpressions().getValue();
try {
// compile if needed
getGroovyScript();
} catch (Throwable t) {
getLogger().error("Load script failed: " + t);
throw new ProcessException("Load script failed: " + t, t);
}
try {
callScriptStatic("onStart", context);
} catch (Throwable t) {
getLogger().error("onStart failed: " + t);
throw new ProcessException("onStart failed: " + t, t);
}
}
Aggregations