Search in sources :

Example 41 with OnScheduled

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

the class ScriptedReportingTask method setup.

/**
 * 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 ConfigurationContext context) {
    scriptingComponentHelper.setupVariables(context);
    // Create a script engine for each possible task
    scriptingComponentHelper.setup(1, getLogger());
    scriptToRun = scriptingComponentHelper.getScriptBody();
    try {
        String scriptPath = scriptingComponentHelper.getScriptPath();
        if (scriptToRun == null && scriptPath != null) {
            try (final FileInputStream scriptStream = new FileInputStream(scriptPath)) {
                scriptToRun = IOUtils.toString(scriptStream, Charset.defaultCharset());
            }
        }
    } catch (IOException ioe) {
        throw new ProcessException(ioe);
    }
    vmMetrics = VirtualMachineMetrics.getInstance();
}
Also used : ProcessException(org.apache.nifi.processor.exception.ProcessException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 42 with OnScheduled

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

the class AbstractSiteToSiteReportingTask method setup.

@OnScheduled
public void setup(final ConfigurationContext context) throws IOException {
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT).asControllerService(SSLContextService.class);
    final SSLContext sslContext = sslContextService == null ? null : sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
    final ComponentLog logger = getLogger();
    final EventReporter eventReporter = new EventReporter() {

        @Override
        public void reportEvent(final Severity severity, final String category, final String message) {
            switch(severity) {
                case WARNING:
                    logger.warn(message);
                    break;
                case ERROR:
                    logger.error(message);
                    break;
                default:
                    break;
            }
        }
    };
    final String destinationUrl = context.getProperty(DESTINATION_URL).evaluateAttributeExpressions().getValue();
    final SiteToSiteTransportProtocol mode = SiteToSiteTransportProtocol.valueOf(context.getProperty(TRANSPORT_PROTOCOL).getValue());
    final HttpProxy httpProxy = mode.equals(SiteToSiteTransportProtocol.RAW) || StringUtils.isEmpty(context.getProperty(HTTP_PROXY_HOSTNAME).getValue()) ? null : new HttpProxy(context.getProperty(HTTP_PROXY_HOSTNAME).getValue(), context.getProperty(HTTP_PROXY_PORT).asInteger(), context.getProperty(HTTP_PROXY_USERNAME).getValue(), context.getProperty(HTTP_PROXY_PASSWORD).getValue());
    siteToSiteClient = new SiteToSiteClient.Builder().urls(SiteToSiteRestApiClient.parseClusterUrls(destinationUrl)).portName(context.getProperty(PORT_NAME).getValue()).useCompression(context.getProperty(COMPRESS).asBoolean()).eventReporter(eventReporter).sslContext(sslContext).timeout(context.getProperty(TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS).transportProtocol(mode).httpProxy(httpProxy).build();
}
Also used : HttpProxy(org.apache.nifi.remote.protocol.http.HttpProxy) SSLContextService(org.apache.nifi.ssl.SSLContextService) RestrictedSSLContextService(org.apache.nifi.ssl.RestrictedSSLContextService) SSLContext(javax.net.ssl.SSLContext) SiteToSiteTransportProtocol(org.apache.nifi.remote.protocol.SiteToSiteTransportProtocol) ComponentLog(org.apache.nifi.logging.ComponentLog) EventReporter(org.apache.nifi.events.EventReporter) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 43 with OnScheduled

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

the class ListenLumberjack method onScheduled.

@Override
@OnScheduled
public void onScheduled(ProcessContext context) throws IOException {
    super.onScheduled(context);
    // wanted to ensure charset was already populated here
    lumberjackEncoder = new LumberjackEncoder();
}
Also used : LumberjackEncoder(org.apache.nifi.processors.lumberjack.frame.LumberjackEncoder) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 44 with OnScheduled

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

the class PutHiveStreaming method setup.

@OnScheduled
public void setup(final ProcessContext context) {
    ComponentLog log = getLogger();
    final Integer heartbeatInterval = context.getProperty(HEARTBEAT_INTERVAL).evaluateAttributeExpressions().asInteger();
    final String configFiles = context.getProperty(HIVE_CONFIGURATION_RESOURCES).getValue();
    hiveConfig = hiveConfigurator.getConfigurationFromFiles(configFiles);
    // If more than one concurrent task, force 'hcatalog.hive.client.cache.disabled' to true
    if (context.getMaxConcurrentTasks() > 1) {
        hiveConfig.setBoolean(CLIENT_CACHE_DISABLED_PROPERTY, true);
    }
    // add any dynamic properties to the Hive configuration
    for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) {
        final PropertyDescriptor descriptor = entry.getKey();
        if (descriptor.isDynamic()) {
            hiveConfig.set(descriptor.getName(), entry.getValue());
        }
    }
    hiveConfigurator.preload(hiveConfig);
    if (SecurityUtil.isSecurityEnabled(hiveConfig)) {
        final String explicitPrincipal = context.getProperty(kerberosProperties.getKerberosPrincipal()).evaluateAttributeExpressions().getValue();
        final String explicitKeytab = context.getProperty(kerberosProperties.getKerberosKeytab()).evaluateAttributeExpressions().getValue();
        final KerberosCredentialsService credentialsService = context.getProperty(KERBEROS_CREDENTIALS_SERVICE).asControllerService(KerberosCredentialsService.class);
        final String resolvedPrincipal;
        final String resolvedKeytab;
        if (credentialsService == null) {
            resolvedPrincipal = explicitPrincipal;
            resolvedKeytab = explicitKeytab;
        } else {
            resolvedPrincipal = credentialsService.getPrincipal();
            resolvedKeytab = credentialsService.getKeytab();
        }
        log.info("Hive Security Enabled, logging in as principal {} with keytab {}", new Object[] { resolvedPrincipal, resolvedKeytab });
        try {
            ugi = hiveConfigurator.authenticate(hiveConfig, resolvedPrincipal, resolvedKeytab);
        } catch (AuthenticationFailedException ae) {
            throw new ProcessException("Kerberos authentication failed for Hive Streaming", ae);
        }
        log.info("Successfully logged in as principal {} with keytab {}", new Object[] { resolvedPrincipal, resolvedKeytab });
    } else {
        ugi = null;
    }
    // milliseconds
    callTimeout = context.getProperty(CALL_TIMEOUT).evaluateAttributeExpressions().asInteger() * 1000;
    String timeoutName = "put-hive-streaming-%d";
    this.callTimeoutPool = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setNameFormat(timeoutName).build());
    sendHeartBeat.set(true);
    heartBeatTimer = new Timer();
    setupHeartBeatTimer(heartbeatInterval);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProcessException(org.apache.nifi.processor.exception.ProcessException) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) Timer(java.util.Timer) AuthenticationFailedException(org.apache.nifi.util.hive.AuthenticationFailedException) KerberosCredentialsService(org.apache.nifi.kerberos.KerberosCredentialsService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ComponentLog(org.apache.nifi.logging.ComponentLog) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 45 with OnScheduled

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

the class ExtractMediaMetadata method onScheduled.

@SuppressWarnings("unused")
@OnScheduled
public void onScheduled(ProcessContext context) {
    String metadataKeyFilterInput = context.getProperty(METADATA_KEY_FILTER).getValue();
    if (metadataKeyFilterInput != null && metadataKeyFilterInput.length() > 0) {
        metadataKeyFilterRef.set(Pattern.compile(metadataKeyFilterInput));
    } else {
        metadataKeyFilterRef.set(null);
    }
    autoDetectParser = new AutoDetectParser();
}
Also used : AutoDetectParser(org.apache.tika.parser.AutoDetectParser) 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