Search in sources :

Example 26 with OnScheduled

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);
        }
    }
}
Also used : StateManager(org.apache.nifi.components.state.StateManager) HashMap(java.util.HashMap) StateMap(org.apache.nifi.components.state.StateMap) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 27 with OnScheduled

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);
    }
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) ProcessException(org.apache.nifi.processor.exception.ProcessException) IOException(java.io.IOException) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 28 with OnScheduled

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));
        }
    }
}
Also used : DistributedMapCacheClient(org.apache.nifi.distributed.cache.client.DistributedMapCacheClient) Column(org.apache.nifi.hbase.scan.Column) StateMap(org.apache.nifi.components.state.StateMap) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 29 with OnScheduled

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);
    }
}
Also used : JsonFullRowSerializer(org.apache.nifi.hbase.io.JsonFullRowSerializer) JsonQualifierAndValueRowSerializer(org.apache.nifi.hbase.io.JsonQualifierAndValueRowSerializer) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 30 with OnScheduled

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);
    }
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Aggregations

OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)59 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)12 ProcessException (org.apache.nifi.processor.exception.ProcessException)12 IOException (java.io.IOException)10 HashMap (java.util.HashMap)10 ComponentLog (org.apache.nifi.logging.ComponentLog)8 SSLContextService (org.apache.nifi.ssl.SSLContextService)7 Map (java.util.Map)6 SSLContext (javax.net.ssl.SSLContext)6 StateMap (org.apache.nifi.components.state.StateMap)5 FileInputStream (java.io.FileInputStream)4 PropertyValue (org.apache.nifi.components.PropertyValue)4 RestrictedSSLContextService (org.apache.nifi.ssl.RestrictedSSLContextService)4 InetAddress (java.net.InetAddress)3 CacheLoader (com.google.common.cache.CacheLoader)2 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)2 File (java.io.File)2 InputStream (java.io.InputStream)2 InetSocketAddress (java.net.InetSocketAddress)2 NetworkInterface (java.net.NetworkInterface)2