Search in sources :

Example 21 with OnEnabled

use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.

the class LivySessionController method onConfigured.

@OnEnabled
public void onConfigured(final ConfigurationContext context) {
    ComponentLog log = getLogger();
    final String livyHost = context.getProperty(LIVY_HOST).evaluateAttributeExpressions().getValue();
    final String livyPort = context.getProperty(LIVY_PORT).evaluateAttributeExpressions().getValue();
    final String sessionPoolSize = context.getProperty(SESSION_POOL_SIZE).evaluateAttributeExpressions().getValue();
    final String sessionKind = context.getProperty(SESSION_TYPE).getValue();
    final long sessionManagerStatusInterval = context.getProperty(SESSION_MGR_STATUS_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS);
    final String jars = context.getProperty(JARS).evaluateAttributeExpressions().getValue();
    final String files = context.getProperty(FILES).evaluateAttributeExpressions().getValue();
    sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    sslContext = sslContextService == null ? null : sslContextService.createSSLContext(SSLContextService.ClientAuth.NONE);
    connectTimeout = Math.toIntExact(context.getProperty(CONNECT_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS));
    this.livyUrl = "http" + (sslContextService != null ? "s" : "") + "://" + livyHost + ":" + livyPort;
    this.controllerKind = sessionKind;
    this.jars = jars;
    this.files = files;
    this.sessionPoolSize = Integer.valueOf(sessionPoolSize);
    this.enabled = true;
    livySessionManagerThread = new Thread(() -> {
        while (enabled) {
            try {
                manageSessions();
                Thread.sleep(sessionManagerStatusInterval);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                enabled = false;
            } catch (IOException ioe) {
                throw new ProcessException(ioe);
            }
        }
    });
    livySessionManagerThread.setName("Livy-Session-Manager-" + controllerKind);
    livySessionManagerThread.start();
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) SSLContextService(org.apache.nifi.ssl.SSLContextService) IOException(java.io.IOException) ComponentLog(org.apache.nifi.logging.ComponentLog) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 22 with OnEnabled

use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.

the class ScriptedLookupService method onEnabled.

@Override
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    synchronized (scriptingComponentHelper.isInitialized) {
        if (!scriptingComponentHelper.isInitialized.get()) {
            scriptingComponentHelper.createResources();
        }
    }
    super.onEnabled(context);
    // Call an non-interface method onEnabled(context), to allow a scripted LookupService the chance to set up as necessary
    final Invocable invocable = (Invocable) scriptEngine;
    if (configurationContext != null) {
        try {
            // Get the actual object from the script engine, versus the proxy stored in lookupService. The object may have additional methods,
            // where lookupService is a proxied interface
            final Object obj = scriptEngine.get("lookupService");
            if (obj != null) {
                try {
                    invocable.invokeMethod(obj, "onEnabled", context);
                } catch (final NoSuchMethodException nsme) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("Configured script LookupService does not contain an onEnabled() method.");
                    }
                }
            } else {
                throw new ScriptException("No LookupService was defined by the script.");
            }
        } catch (ScriptException se) {
            throw new ProcessException("Error executing onEnabled(context) method", se);
        }
    }
}
Also used : Invocable(javax.script.Invocable) ScriptException(javax.script.ScriptException) ProcessException(org.apache.nifi.processor.exception.ProcessException) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 23 with OnEnabled

use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.

the class GrokReader method preCompile.

@OnEnabled
public void preCompile(final ConfigurationContext context) throws GrokException, IOException {
    grok = new Grok();
    try (final InputStream in = getClass().getResourceAsStream(DEFAULT_PATTERN_NAME);
        final Reader reader = new InputStreamReader(in)) {
        grok.addPatternFromReader(reader);
    }
    if (context.getProperty(PATTERN_FILE).isSet()) {
        grok.addPatternFromFile(context.getProperty(PATTERN_FILE).evaluateAttributeExpressions().getValue());
    }
    grok.compile(context.getProperty(GROK_EXPRESSION).getValue());
    appendUnmatchedLine = context.getProperty(NO_MATCH_BEHAVIOR).getValue().equalsIgnoreCase(APPEND_TO_PREVIOUS_MESSAGE.getValue());
    this.recordSchemaFromGrok = createRecordSchema(grok);
    final String schemaAccess = context.getProperty(getSchemaAcessStrategyDescriptor()).getValue();
    if (STRING_FIELDS_FROM_GROK_EXPRESSION.getValue().equals(schemaAccess)) {
        this.recordSchema = recordSchemaFromGrok;
    } else {
        this.recordSchema = null;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Grok(io.thekraken.grok.api.Grok) InputStream(java.io.InputStream) RecordReader(org.apache.nifi.serialization.RecordReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 24 with OnEnabled

use of org.apache.nifi.annotation.lifecycle.OnEnabled in project nifi by apache.

the class JsonPathReader method compileJsonPaths.

@OnEnabled
public void compileJsonPaths(final ConfigurationContext context) {
    this.dateFormat = context.getProperty(DateTimeUtils.DATE_FORMAT).getValue();
    this.timeFormat = context.getProperty(DateTimeUtils.TIME_FORMAT).getValue();
    this.timestampFormat = context.getProperty(DateTimeUtils.TIMESTAMP_FORMAT).getValue();
    final LinkedHashMap<String, JsonPath> compiled = new LinkedHashMap<>();
    for (final PropertyDescriptor descriptor : context.getProperties().keySet()) {
        if (!descriptor.isDynamic()) {
            continue;
        }
        final String fieldName = descriptor.getName();
        final String expression = context.getProperty(descriptor).getValue();
        final JsonPath jsonPath = JsonPath.compile(expression);
        compiled.put(fieldName, jsonPath);
    }
    jsonPaths = compiled;
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) JsonPath(com.jayway.jsonpath.JsonPath) LinkedHashMap(java.util.LinkedHashMap) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Aggregations

OnEnabled (org.apache.nifi.annotation.lifecycle.OnEnabled)24 InitializationException (org.apache.nifi.reporting.InitializationException)7 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)4 ComponentLog (org.apache.nifi.logging.ComponentLog)4 SSLContextService (org.apache.nifi.ssl.SSLContextService)4 IOException (java.io.IOException)3 File (java.io.File)2 URI (java.net.URI)2 Map (java.util.Map)2 SSLContext (javax.net.ssl.SSLContext)2 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)2 ProcessException (org.apache.nifi.processor.exception.ProcessException)2 LastModifiedMonitor (org.apache.nifi.util.file.monitor.LastModifiedMonitor)2 SynchronousFileWatcher (org.apache.nifi.util.file.monitor.SynchronousFileWatcher)2 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)2 CouchbaseException (com.couchbase.client.core.CouchbaseException)1 JsonPath (com.jayway.jsonpath.JsonPath)1 Timestamper (com.metamx.tranquility.typeclass.Timestamper)1 MetadataClient (com.thinkbiganalytics.metadata.rest.client.MetadataClient)1 SpringContextService (com.thinkbiganalytics.nifi.core.api.spring.SpringContextService)1