Search in sources :

Example 11 with OnEnabled

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

the class CSVRecordLookupService method onEnabled.

@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException {
    this.csvFile = context.getProperty(CSV_FILE).getValue();
    this.csvFormat = CSVFormat.Predefined.valueOf(context.getProperty(CSV_FORMAT).getValue()).getFormat();
    this.lookupKeyColumn = context.getProperty(LOOKUP_KEY_COLUMN).getValue();
    this.ignoreDuplicates = context.getProperty(IGNORE_DUPLICATES).asBoolean();
    this.watcher = new SynchronousFileWatcher(Paths.get(csvFile), new LastModifiedMonitor(), 30000L);
    try {
        loadCache();
    } catch (final IllegalStateException e) {
        throw new InitializationException(e.getMessage(), e);
    }
}
Also used : SynchronousFileWatcher(org.apache.nifi.util.file.monitor.SynchronousFileWatcher) InitializationException(org.apache.nifi.reporting.InitializationException) LastModifiedMonitor(org.apache.nifi.util.file.monitor.LastModifiedMonitor) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 12 with OnEnabled

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

the class SimpleCsvFileLookupService method onEnabled.

@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException, FileNotFoundException {
    this.csvFile = context.getProperty(CSV_FILE).getValue();
    this.csvFormat = CSVFormat.Predefined.valueOf(context.getProperty(CSV_FORMAT).getValue()).getFormat();
    this.lookupKeyColumn = context.getProperty(LOOKUP_KEY_COLUMN).getValue();
    this.lookupValueColumn = context.getProperty(LOOKUP_VALUE_COLUMN).getValue();
    this.ignoreDuplicates = context.getProperty(IGNORE_DUPLICATES).asBoolean();
    this.watcher = new SynchronousFileWatcher(Paths.get(csvFile), new LastModifiedMonitor(), 30000L);
    try {
        loadCache();
    } catch (final IllegalStateException e) {
        throw new InitializationException(e.getMessage(), e);
    }
}
Also used : SynchronousFileWatcher(org.apache.nifi.util.file.monitor.SynchronousFileWatcher) InitializationException(org.apache.nifi.reporting.InitializationException) LastModifiedMonitor(org.apache.nifi.util.file.monitor.LastModifiedMonitor) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 13 with OnEnabled

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

the class CommonsConfigurationLookupService method onEnabled.

@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
    final String config = context.getProperty(CONFIGURATION_FILE).getValue();
    final FileBasedBuilderParameters params = new Parameters().fileBased().setFile(new File(config));
    this.builder = new ReloadingFileBasedConfigurationBuilder<>(resultClass).configure(params);
    builder.addEventListener(ConfigurationBuilderEvent.CONFIGURATION_REQUEST, new EventListener<ConfigurationBuilderEvent>() {

        @Override
        public void onEvent(ConfigurationBuilderEvent event) {
            if (builder.getReloadingController().checkForReloading(null)) {
                getLogger().debug("Reloading " + config);
            }
        }
    });
    try {
        // Try getting configuration to see if there is any issue, for example wrong file format.
        // Then throw InitializationException to keep this service in 'Enabling' state.
        builder.getConfiguration();
    } catch (ConfigurationException e) {
        throw new InitializationException(e);
    }
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) FileBasedBuilderParameters(org.apache.commons.configuration2.builder.fluent.FileBasedBuilderParameters) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) FileBasedBuilderParameters(org.apache.commons.configuration2.builder.fluent.FileBasedBuilderParameters) ReloadingFileBasedConfigurationBuilder(org.apache.commons.configuration2.builder.ReloadingFileBasedConfigurationBuilder) InitializationException(org.apache.nifi.reporting.InitializationException) File(java.io.File) ConfigurationBuilderEvent(org.apache.commons.configuration2.builder.ConfigurationBuilderEvent) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 14 with OnEnabled

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

the class IPLookupService method onEnabled.

@OnEnabled
public void onEnabled(final ConfigurationContext context) throws IOException {
    databaseFile = context.getProperty(GEO_DATABASE_FILE).evaluateAttributeExpressions().getValue();
    final File dbFile = new File(databaseFile);
    final String dbFileChecksum = getChecksum(dbFile);
    loadDatabase(dbFile, dbFileChecksum);
    // initialize the last refresh attempt to the time the service was enabled
    databaseLastRefreshAttempt = System.currentTimeMillis();
}
Also used : File(java.io.File) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

Example 15 with OnEnabled

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

the class SchemaRegistryService method storeSchemaAccessStrategy.

@OnEnabled
public void storeSchemaAccessStrategy(final ConfigurationContext context) {
    this.configurationContext = context;
    final SchemaRegistry schemaRegistry = context.getProperty(SCHEMA_REGISTRY).asControllerService(SchemaRegistry.class);
    final PropertyDescriptor descriptor = getSchemaAcessStrategyDescriptor();
    final String schemaAccess = context.getProperty(descriptor).getValue();
    this.schemaAccessStrategy = getSchemaAccessStrategy(schemaAccess, schemaRegistry, context);
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) SchemaRegistry(org.apache.nifi.schemaregistry.services.SchemaRegistry) 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