org.apache.nifi.annotation.lifecycle.OnEnabled Java Examples

The following examples show how to use org.apache.nifi.annotation.lifecycle.OnEnabled. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoDBLookupService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    this.lookupValueField = context.getProperty(LOOKUP_VALUE_FIELD).getValue();
    this.controllerService = context.getProperty(CONTROLLER_SERVICE).asControllerService(MongoDBClientService.class);

    this.schemaNameProperty = context.getProperty(SchemaAccessUtils.SCHEMA_NAME).getValue();

    this.databaseName = context.getProperty(DATABASE_NAME).evaluateAttributeExpressions().getValue();
    this.collection   = context.getProperty(COLLECTION_NAME).evaluateAttributeExpressions().getValue();

    String configuredProjection = context.getProperty(PROJECTION).isSet()
        ? context.getProperty(PROJECTION).getValue()
        : null;
    if (!StringUtils.isBlank(configuredProjection)) {
        projection = Document.parse(configuredProjection);
    }

    super.onEnabled(context);
}
 
Example #2
Source File: CSVReader.java    From nifi with Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void storeStaticProperties(final ConfigurationContext context) {
    this.context = context;

    this.csvParser = context.getProperty(CSV_PARSER).getValue();
    this.dateFormat = context.getProperty(DateTimeUtils.DATE_FORMAT).getValue();
    this.timeFormat = context.getProperty(DateTimeUtils.TIME_FORMAT).getValue();
    this.timestampFormat = context.getProperty(DateTimeUtils.TIMESTAMP_FORMAT).getValue();
    this.firstLineIsHeader = context.getProperty(CSVUtils.FIRST_LINE_IS_HEADER).asBoolean();
    this.ignoreHeader = context.getProperty(CSVUtils.IGNORE_CSV_HEADER).asBoolean();
    this.charSet = context.getProperty(CSVUtils.CHARSET).getValue();

    // Ensure that if we are deriving schema from header that we always treat the first line as a header,
    // regardless of the 'First Line is Header' property
    final String accessStrategy = context.getProperty(SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY).getValue();
    if (HEADER_DERIVED.getValue().equals(accessStrategy) || SchemaInferenceUtil.INFER_SCHEMA.getValue().equals(accessStrategy)) {
        this.firstLineIsHeader = true;
    }

    if (!CSVUtils.isDynamicCSVFormat(context)) {
        this.csvFormat = CSVUtils.createCSVFormat(context, Collections.emptyMap());
    } else {
        this.csvFormat = null;
    }
}
 
Example #3
Source File: CouchbaseClusterService.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Establish a connection to a Couchbase cluster.
 * @param context the configuration context
 * @throws InitializationException if unable to connect a Couchbase cluster
 */
@OnEnabled
public void onConfigured(final ConfigurationContext context) throws InitializationException {

    bucketPasswords = new HashMap<>();
    for(PropertyDescriptor p : context.getProperties().keySet()){
        if(p.isDynamic() && p.getName().startsWith(DYNAMIC_PROP_BUCKET_PASSWORD)){
            String bucketName = p.getName().substring(DYNAMIC_PROP_BUCKET_PASSWORD.length());
            String password = context.getProperty(p).evaluateAttributeExpressions().getValue();
            bucketPasswords.put(bucketName, password);
        }
    }

    final String userName = context.getProperty(USER_NAME).evaluateAttributeExpressions().getValue();
    final String userPassword = context.getProperty(USER_PASSWORD).evaluateAttributeExpressions().getValue();

    try {
        cluster = CouchbaseCluster.fromConnectionString(context.getProperty(CONNECTION_STRING).evaluateAttributeExpressions().getValue());
        if (!StringUtils.isEmpty(userName) && !StringUtils.isEmpty(userPassword)) {
            cluster.authenticate(userName, userPassword);
        }
    } catch(CouchbaseException e) {
        throw new InitializationException(e);
    }
}
 
Example #4
Source File: JMSConnectionFactoryProvider.java    From solace-integration-guides with Apache License 2.0 6 votes vote down vote up
/**
 *
 */
@OnEnabled
public void enable(ConfigurationContext context) throws InitializationException {
    try {
        if (!this.configured) {
            if (logger.isInfoEnabled()) {
                logger.info("Configuring " + this.getClass().getSimpleName() + " for '"
                        + context.getProperty(CONNECTION_FACTORY_IMPL).evaluateAttributeExpressions().getValue() + "' to be connected to '"
                        + BROKER_URI + "'");
            }
            // will load user provided libraries/resources on the classpath
            Utils.addResourcesToClasspath(context.getProperty(CLIENT_LIB_DIR_PATH).evaluateAttributeExpressions().getValue());

            this.createConnectionFactoryInstance(context);

            this.setConnectionFactoryProperties(context);
        }
        this.configured = true;
    } catch (Exception e) {
        logger.error("Failed to configure " + this.getClass().getSimpleName(), e);
        this.configured = false;
        throw new IllegalStateException(e);
    }
}
 
Example #5
Source File: AbstractEasyRulesEngineController.java    From nifi with Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
    final String rulesFile = context.getProperty(RULES_FILE_PATH).getValue();
    final String rulesBody = context.getProperty(RULES_BODY).getValue();
    final String rulesFileType = context.getProperty(RULES_FILE_TYPE).getValue();
    rulesFileFormat = context.getProperty(RULES_FILE_FORMAT).getValue();
    ignoreConditionErrors = context.getProperty(IGNORE_CONDITION_ERRORS).asBoolean();
    filterRules = context.getProperty(FILTER_RULES_MISSING_FACTS).asBoolean();

    try{
        if(StringUtils.isEmpty(rulesFile)){
            rules = RulesFactory.createRulesFromString(rulesBody, rulesFileType, rulesFileFormat);
        }else{
            rules = RulesFactory.createRulesFromFile(rulesFile, rulesFileType, rulesFileFormat);
        }
    } catch (Exception fex){
        throw new InitializationException(fex);
    }
}
 
Example #6
Source File: HBase_1_1_2_ClientService.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * As of Apache NiFi 1.5.0, due to changes made to
 * {@link SecurityUtil#loginKerberos(Configuration, String, String)}, which is used by this
 * class to authenticate a principal with Kerberos, HBase controller services no longer
 * attempt relogins explicitly.  For more information, please read the documentation for
 * {@link SecurityUtil#loginKerberos(Configuration, String, String)}.
 * <p/>
 * In previous versions of NiFi, a {@link org.apache.nifi.hadoop.KerberosTicketRenewer} was started
 * when the HBase controller service was enabled.  The use of a separate thread to explicitly relogin could cause
 * race conditions with the implicit relogin attempts made by hadoop/HBase code on a thread that references the same
 * {@link UserGroupInformation} instance.  One of these threads could leave the
 * {@link javax.security.auth.Subject} in {@link UserGroupInformation} to be cleared or in an unexpected state
 * while the other thread is attempting to use the {@link javax.security.auth.Subject}, resulting in failed
 * authentication attempts that would leave the HBase controller service in an unrecoverable state.
 *
 * @see SecurityUtil#loginKerberos(Configuration, String, String)
 */
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException, InterruptedException {
    this.connection = createConnection(context);

    // connection check
    if (this.connection != null) {
        final Admin admin = this.connection.getAdmin();
        if (admin != null) {
            admin.listTableNames();

            final ClusterStatus clusterStatus = admin.getClusterStatus();
            if (clusterStatus != null) {
                final ServerName master = clusterStatus.getMaster();
                if (master != null) {
                    masterAddress = master.getHostAndPort();
                } else {
                    masterAddress = null;
                }
            }
        }
    }
}
 
Example #7
Source File: CouchbaseClusterService.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Establish a connection to a Couchbase cluster.
 * @param context the configuration context
 * @throws InitializationException if unable to connect a Couchbase cluster
 */
@OnEnabled
public void onConfigured(final ConfigurationContext context) throws InitializationException {

    for(PropertyDescriptor p : context.getProperties().keySet()){
        if(p.isDynamic() && p.getName().startsWith(DYNAMIC_PROP_BUCKET_PASSWORD)){
            String bucketName = p.getName().substring(DYNAMIC_PROP_BUCKET_PASSWORD.length());
            String password = context.getProperty(p).getValue();
            bucketPasswords.put(bucketName, password);
        }
    }
    try {
        cluster = CouchbaseCluster.fromConnectionString(context.getProperty(CONNECTION_STRING).getValue());
    } catch(CouchbaseException e) {
        throw new InitializationException(e);
    }
}
 
Example #8
Source File: HBase_2_ClientService.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * As of Apache NiFi 1.5.0, due to changes made to
 * {@link SecurityUtil#loginKerberos(Configuration, String, String)}, which is used by this
 * class to authenticate a principal with Kerberos, HBase controller services no longer
 * attempt relogins explicitly.  For more information, please read the documentation for
 * {@link SecurityUtil#loginKerberos(Configuration, String, String)}.
 * <p/>
 * In previous versions of NiFi, a {@link org.apache.nifi.hadoop.KerberosTicketRenewer} was started
 * when the HBase controller service was enabled.  The use of a separate thread to explicitly relogin could cause
 * race conditions with the implicit relogin attempts made by hadoop/HBase code on a thread that references the same
 * {@link UserGroupInformation} instance.  One of these threads could leave the
 * {@link javax.security.auth.Subject} in {@link UserGroupInformation} to be cleared or in an unexpected state
 * while the other thread is attempting to use the {@link javax.security.auth.Subject}, resulting in failed
 * authentication attempts that would leave the HBase controller service in an unrecoverable state.
 *
 * @see SecurityUtil#loginKerberos(Configuration, String, String)
 */
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException, InterruptedException {
    this.connection = createConnection(context);

    // connection check
    if (this.connection != null) {
        final Admin admin = this.connection.getAdmin();
        if (admin != null) {
            admin.listTableNames();

            final ClusterStatus clusterStatus = admin.getClusterStatus();
            if (clusterStatus != null) {
                final ServerName master = clusterStatus.getMaster();
                if (master != null) {
                    masterAddress = master.getHostAndPort();
                } else {
                    masterAddress = null;
                }
            }
        }
    }
}
 
Example #9
Source File: JMSConnectionFactoryProvider.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 *
 */
@OnEnabled
public void enable(ConfigurationContext context) throws InitializationException {
    try {
        if (!this.configured) {
            if (logger.isInfoEnabled()) {
                logger.info("Configuring " + this.getClass().getSimpleName() + " for '"
                        + context.getProperty(CONNECTION_FACTORY_IMPL).evaluateAttributeExpressions().getValue() + "' to be connected to '"
                        + BROKER_URI + "'");
            }
            // will load user provided libraries/resources on the classpath
            Utils.addResourcesToClasspath(context.getProperty(CLIENT_LIB_DIR_PATH).evaluateAttributeExpressions().getValue());

            this.createConnectionFactoryInstance(context);

            this.setConnectionFactoryProperties(context);
        }
        this.configured = true;
    } catch (Exception e) {
        logger.error("Failed to configure " + this.getClass().getSimpleName(), e);
        this.configured = false;
        throw new IllegalStateException(e);
    }
}
 
Example #10
Source File: JsonPathReader.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #11
Source File: StandardS3EncryptionService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void onConfigured(final ConfigurationContext context) throws InitializationException {
    final String newStrategyName = context.getProperty(ENCRYPTION_STRATEGY).getValue();
    final String newKeyValue = context.getProperty(ENCRYPTION_VALUE).evaluateAttributeExpressions().getValue();
    final S3EncryptionStrategy newEncryptionStrategy = NAMED_STRATEGIES.get(newStrategyName);
    String newKmsRegion = null;

    if (context.getProperty(KMS_REGION) != null ) {
        newKmsRegion = context.getProperty(KMS_REGION).getValue();
    }

    if (newEncryptionStrategy == null) {
        final String msg = "No encryption strategy found for name: " + strategyName;
        logger.warn(msg);
        throw new InitializationException(msg);
    }

    strategyName = newStrategyName;
    encryptionStrategy = newEncryptionStrategy;
    keyValue = newKeyValue;
    kmsRegion = newKmsRegion;
}
 
Example #12
Source File: StandardHttpContextMap.java    From nifi with Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void onConfigured(final ConfigurationContext context) {
    maxSize = context.getProperty(MAX_OUTSTANDING_REQUESTS).asInteger();
    executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        @Override
        public Thread newThread(final Runnable r) {
            final Thread thread = Executors.defaultThreadFactory().newThread(r);
            thread.setName("StandardHttpContextMap-" + getIdentifier());
            return thread;
        }
    });

    maxRequestNanos = context.getProperty(REQUEST_EXPIRATION).asTimePeriod(TimeUnit.NANOSECONDS);
    final long scheduleNanos = Math.min(maxRequestNanos / 2, CLEANUP_MAX_DELAY_NANOS);
    executor.scheduleWithFixedDelay(new CleanupExpiredRequests(), scheduleNanos, scheduleNanos, TimeUnit.NANOSECONDS);
}
 
Example #13
Source File: StandardSSLContextService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void onConfigured(final ConfigurationContext context) throws InitializationException {
    configContext = context;

    final Collection<ValidationResult> results = new ArrayList<>();
    results.addAll(validateStore(context.getProperties(), KeystoreValidationGroup.KEYSTORE));
    results.addAll(validateStore(context.getProperties(), KeystoreValidationGroup.TRUSTSTORE));

    if (!results.isEmpty()) {
        final StringBuilder sb = new StringBuilder(this + " is not valid due to:");
        for (final ValidationResult result : results) {
            sb.append("\n").append(result.toString());
        }
        throw new InitializationException(sb.toString());
    }
}
 
Example #14
Source File: ConfluentSchemaRegistry.java    From nifi with Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    final List<String> baseUrls = getBaseURLs(context);
    final int timeoutMillis = context.getProperty(TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();

    final SSLContext sslContext;
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT).asControllerService(SSLContextService.class);
    if (sslContextService == null) {
        sslContext = null;
    } else {
        sslContext = sslContextService.createSSLContext(ClientAuth.REQUIRED);
    }

    final SchemaRegistryClient restClient = new RestSchemaRegistryClient(baseUrls, timeoutMillis, sslContext, getLogger());

    final int cacheSize = context.getProperty(CACHE_SIZE).asInteger();
    final long cacheExpiration = context.getProperty(CACHE_EXPIRATION).asTimePeriod(TimeUnit.NANOSECONDS).longValue();

    client = new CachingSchemaRegistryClient(restClient, cacheSize, cacheExpiration);
}
 
Example #15
Source File: CommonsConfigurationLookupService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
    final String config = context.getProperty(CONFIGURATION_FILE).evaluateAttributeExpressions().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);
    }
}
 
Example #16
Source File: HBase_1_1_2_ClientService.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException, InterruptedException {
    this.connection = createConnection(context);

    // connection check
    if (this.connection != null) {
        final Admin admin = this.connection.getAdmin();
        if (admin != null) {
            admin.listTableNames();
        }

        // if we got here then we have a successful connection, so if we have a ugi then start a renewer
        if (ugi != null) {
            final String id = getClass().getSimpleName();
            renewer = SecurityUtil.startTicketRenewalThread(id, ugi, TICKET_RENEWAL_PERIOD, getLogger());
        }
    }
}
 
Example #17
Source File: Neo4JCypherClientService.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    try {
        neo4JDriver = getDriver(context);
    } catch(Exception e) {
        getLogger().error("Error while getting connection " + e.getLocalizedMessage(),e);
        throw new ProcessException("Error while getting connection" + e.getLocalizedMessage(),e);
    }
    getLogger().info("Neo4JCypherExecutor connection created for url {}",
            new Object[] {connectionUrl});
}
 
Example #18
Source File: IPLookupService.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #19
Source File: ActionHandlerLookup.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    final Map<String,PropertyContextActionHandler> serviceMap = new HashMap<>();

    for (final PropertyDescriptor descriptor : context.getProperties().keySet()) {
        if (descriptor.isDynamic()) {
            final PropertyContextActionHandler propertyContextActionHandler = context.getProperty(descriptor).asControllerService(PropertyContextActionHandler.class);
            serviceMap.put(descriptor.getName(), propertyContextActionHandler);
        }
    }

    actionHandlerMap = Collections.unmodifiableMap(serviceMap);
}
 
Example #20
Source File: StandardProxyConfigurationService.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnEnabled
public void setConfiguredValues(final ConfigurationContext context) {
    configuration = new ProxyConfiguration();
    configuration.setProxyType(Proxy.Type.valueOf(context.getProperty(PROXY_TYPE).getValue()));
    configuration.setProxyServerHost(context.getProperty(PROXY_SERVER_HOST).evaluateAttributeExpressions().getValue());
    configuration.setProxyServerPort(context.getProperty(PROXY_SERVER_PORT).evaluateAttributeExpressions().asInteger());
    configuration.setProxyUserName(context.getProperty(PROXY_USER_NAME).evaluateAttributeExpressions().getValue());
    configuration.setProxyUserPassword(context.getProperty(PROXY_USER_PASSWORD).evaluateAttributeExpressions().getValue());
}
 
Example #21
Source File: JsonRecordSetWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    prettyPrint = context.getProperty(PRETTY_PRINT_JSON).asBoolean();

    final NullSuppression suppression;
    final String suppressNullValue = context.getProperty(SUPPRESS_NULLS).getValue();
    if (ALWAYS_SUPPRESS.getValue().equals(suppressNullValue)) {
        suppression = NullSuppression.ALWAYS_SUPPRESS;
    } else if (SUPPRESS_MISSING.getValue().equals(suppressNullValue)) {
        suppression = NullSuppression.SUPPRESS_MISSING;
    } else {
        suppression = NullSuppression.NEVER_SUPPRESS;
    }
    this.nullSuppression = suppression;

    String outputGroupingValue = context.getProperty(OUTPUT_GROUPING).getValue();
    final OutputGrouping grouping;
    if(OUTPUT_ONELINE.getValue().equals(outputGroupingValue)) {
        grouping = OutputGrouping.OUTPUT_ONELINE;
    } else {
        grouping = OutputGrouping.OUTPUT_ARRAY;
    }
    this.outputGrouping = grouping;

    this.compressionFormat = context.getProperty(COMPRESSION_FORMAT).getValue();
    this.compressionLevel = context.getProperty(COMPRESSION_LEVEL).asInteger();
}
 
Example #22
Source File: TestStandardProcessScheduler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnEnabled
public void enable(final ConfigurationContext context) {
    try {
        Thread.sleep(random.nextInt(20));
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
 
Example #23
Source File: AlertHandler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
    super.onEnabled(context);
    defaultLogLevel = context.getProperty(DEFAULT_LOG_LEVEL).getValue().toUpperCase();
    defaultCategory = context.getProperty(DEFAULT_CATEGORY).getValue();
    defaultMessage = context.getProperty(DEFAULT_MESSAGE).getValue();
    includeFacts = context.getProperty(INCLUDE_FACTS).asBoolean();
}
 
Example #24
Source File: Syslog5424Reader.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    final String charsetName = context.getProperty(CHARSET).getValue();
    includeRaw = context.getProperty(ADD_RAW).asBoolean();
    parser = new StrictSyslog5424Parser(Charset.forName(charsetName), NilHandlingPolicy.NULL, NifiStructuredDataPolicy.MAP_OF_MAPS, new SimpleKeyProvider());
    recordSchema = createRecordSchema();
}
 
Example #25
Source File: AvroReader.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    final int cacheSize = context.getProperty(CACHE_SIZE).asInteger();
    compiledAvroSchemaCache = Caffeine.newBuilder()
            .maximumSize(cacheSize)
            .build(schemaText -> new Schema.Parser().parse(schemaText));
}
 
Example #26
Source File: SyslogReader.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) {
    final String charsetName = context.getProperty(CHARSET).getValue();
    parser = new SyslogParser(Charset.forName(charsetName));
    includeRaw = context.getProperty(ADD_RAW).asBoolean();
    recordSchema = createRecordSchema();
}
 
Example #27
Source File: LogHandler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
    super.onEnabled(context);
    logPrefix = context.getProperty(LOG_PREFIX).evaluateAttributeExpressions().getValue();
    logFacts = context.getProperty(LOG_FACTS).asBoolean();
    defaultLogLevel = context.getProperty(DEFAULT_LOG_LEVEL).getValue().toUpperCase();
    defaultLogMessage = context.getProperty(DEFAULT_LOG_MESSAGE).evaluateAttributeExpressions().getValue();
}
 
Example #28
Source File: DistributedCacheServer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnEnabled
public void startServer(final ConfigurationContext context) throws IOException {
    if (cacheServer == null) {
        cacheServer = createCacheServer(context);
        cacheServer.start();
    }
}
 
Example #29
Source File: SiteToSiteReportingRecordSink.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
    try {
        final ComponentLog logger = getLogger();
        siteToSiteClient = SiteToSiteUtils.getClient(context, logger, stateManager);

        writerFactory = context.getProperty(RECORD_WRITER_FACTORY).asControllerService(RecordSetWriterFactory.class);
    } catch(Exception e) {
        throw new InitializationException(e);
    }
}
 
Example #30
Source File: BaseScriptedLookupService.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}