Java Code Examples for org.apache.nifi.components.PropertyDescriptor#equals()

The following examples show how to use org.apache.nifi.components.PropertyDescriptor#equals() . 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: ControlRate.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    super.onPropertyModified(descriptor, oldValue, newValue);

    if (descriptor.equals(RATE_CONTROL_CRITERIA)
            || descriptor.equals(RATE_CONTROL_ATTRIBUTE_NAME)
            || descriptor.equals(GROUPING_ATTRIBUTE_NAME)
            || descriptor.equals(TIME_PERIOD)) {
        // if the criteria that is being used to determine limits/throttles is changed, we must clear our throttle map.
        throttleMap.clear();
    } else if (descriptor.equals(MAX_RATE)) {
        final long newRate;
        if (DataUnit.DATA_SIZE_PATTERN.matcher(newValue.toUpperCase()).matches()) {
            newRate = DataUnit.parseDataSize(newValue, DataUnit.B).longValue();
        } else {
            newRate = Long.parseLong(newValue);
        }

        for (final Throttle throttle : throttleMap.values()) {
            throttle.setMaxRate(newRate);
        }
    }
}
 
Example 2
Source File: DistributeLoad.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.equals(NUM_RELATIONSHIPS)) {
        final Set<Relationship> relationships = new HashSet<>();
        for (int i = 1; i <= Integer.parseInt(newValue); i++) {
            relationships.add(createRelationship(i));
        }
        this.relationshipsRef.set(Collections.unmodifiableSet(relationships));
    } else if (descriptor.equals(DISTRIBUTION_STRATEGY)) {
        switch (newValue.toLowerCase()) {
            case STRATEGY_ROUND_ROBIN:
                strategyRef.set(new RoundRobinStrategy());
                break;
            case STRATEGY_NEXT_AVAILABLE:
                strategyRef.set(new NextAvailableStrategy());
                break;
            case STRATEGY_LOAD_DISTRIBUTION_SERVICE:
                strategyRef.set(new LoadDistributionStrategy());
        }
        doSetProps.set(true);
        doCustomValidate.set(true);
    }
}
 
Example 3
Source File: DistributeLoad.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.equals(NUM_RELATIONSHIPS)) {
        final Set<Relationship> relationships = new HashSet<>();
        for (int i = 1; i <= Integer.parseInt(newValue); i++) {
            relationships.add(createRelationship(i));
        }
        this.relationshipsRef.set(Collections.unmodifiableSet(relationships));
    } else if (descriptor.equals(DISTRIBUTION_STRATEGY)) {
        switch (newValue.toLowerCase()) {
            case STRATEGY_ROUND_ROBIN:
                strategyRef.set(new RoundRobinStrategy());
                break;
            case STRATEGY_NEXT_AVAILABLE:
                strategyRef.set(new NextAvailableStrategy());
                break;
            case STRATEGY_LOAD_DISTRIBUTION_SERVICE:
                strategyRef.set(new LoadDistributionStrategy());
        }
        doSetProps.set(true);
        doCustomValidate.set(true);
    }
}
 
Example 4
Source File: RouteText.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.equals(IGNORE_CASE) && !newValue.equals(oldValue)) {
        patternsCache.clear();
    }

    if (descriptor.equals(ROUTE_STRATEGY)) {
        configuredRouteStrategy = newValue;
    } else {
        final Set<String> newDynamicPropertyNames = new HashSet<>(dynamicPropertyNames);
        if (newValue == null) {
            newDynamicPropertyNames.remove(descriptor.getName());
        } else if (oldValue == null && descriptor.isDynamic()) { // new property
            newDynamicPropertyNames.add(descriptor.getName());
        }

        this.dynamicPropertyNames = Collections.unmodifiableSet(newDynamicPropertyNames);
    }

    // formulate the new set of Relationships
    final Set<String> allDynamicProps = this.dynamicPropertyNames;
    final Set<Relationship> newRelationships = new HashSet<>();
    final String routeStrategy = configuredRouteStrategy;
    if (ROUTE_TO_MATCHING_PROPERTY_NAME.getValue().equals(routeStrategy)) {
        for (final String propName : allDynamicProps) {
            newRelationships.add(new Relationship.Builder().name(propName).build());
        }
    } else {
        newRelationships.add(REL_MATCH);
    }

    newRelationships.add(REL_ORIGINAL);
    newRelationships.add(REL_NO_MATCH);
    this.relationships.set(newRelationships);
}
 
Example 5
Source File: GetSplunk.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue) {
    if ( ((oldValue != null && !oldValue.equals(newValue)))
            && (descriptor.equals(QUERY)
            || descriptor.equals(TIME_FIELD_STRATEGY)
            || descriptor.equals(TIME_RANGE_STRATEGY)
            || descriptor.equals(EARLIEST_TIME)
            || descriptor.equals(LATEST_TIME)
            || descriptor.equals(HOSTNAME))
            ) {
        getLogger().debug("A property that require resetting state was modified - {} oldValue {} newValue {}",
                new Object[] {descriptor.getDisplayName(), oldValue, newValue});
        resetState = true;
    }
}
 
Example 6
Source File: KafkaProcessorUtils.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
static void buildCommonKafkaProperties(final ProcessContext context, final Class<?> kafkaConfigClass, final Map<String, Object> mapToPopulate) {
    for (PropertyDescriptor propertyDescriptor : context.getProperties().keySet()) {
        if (propertyDescriptor.equals(SSL_CONTEXT_SERVICE)) {
            // Translate SSLContext Service configuration into Kafka properties
            final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
            if (sslContextService != null && sslContextService.isKeyStoreConfigured()) {
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, sslContextService.getKeyStoreFile());
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, sslContextService.getKeyStorePassword());
                final String keyPass = sslContextService.getKeyPassword() == null ? sslContextService.getKeyStorePassword() : sslContextService.getKeyPassword();
                mapToPopulate.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, keyPass);
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, sslContextService.getKeyStoreType());
            }

            if (sslContextService != null && sslContextService.isTrustStoreConfigured()) {
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, sslContextService.getTrustStoreFile());
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, sslContextService.getTrustStorePassword());
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, sslContextService.getTrustStoreType());
            }
        }

        String propertyName = propertyDescriptor.getName();
        String propertyValue = propertyDescriptor.isExpressionLanguageSupported()
                ? context.getProperty(propertyDescriptor).evaluateAttributeExpressions().getValue()
                : context.getProperty(propertyDescriptor).getValue();

        if (propertyValue != null) {
            // If the property name ends in ".ms" then it is a time period. We want to accept either an integer as number of milliseconds
            // or the standard NiFi time period such as "5 secs"
            if (propertyName.endsWith(".ms") && !StringUtils.isNumeric(propertyValue.trim())) { // kafka standard time notation
                propertyValue = String.valueOf(FormatUtils.getTimeDuration(propertyValue.trim(), TimeUnit.MILLISECONDS));
            }

            if (isStaticStringFieldNamePresent(propertyName, kafkaConfigClass, CommonClientConfigs.class, SslConfigs.class, SaslConfigs.class)) {
                mapToPopulate.put(propertyName, propertyValue);
            }
        }
    }
}
 
Example 7
Source File: ListHDFS.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    super.onPropertyModified(descriptor, oldValue, newValue);
    if (isConfigurationRestored() && (descriptor.equals(DIRECTORY) || descriptor.equals(FILE_FILTER))) {
        this.resetState = true;
    }
}
 
Example 8
Source File: ExecuteStreamCommand.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.equals(PUT_OUTPUT_IN_ATTRIBUTE)) {
        if (newValue != null) {
            relationships.set(ATTRIBUTE_RELATIONSHIP_SET);
        } else {
            relationships.set(OUTPUT_STREAM_RELATIONSHIP_SET);
        }
    }
}
 
Example 9
Source File: UpdateAttribute.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    super.onPropertyModified(descriptor, oldValue, newValue);

    if (descriptor.equals(STORE_STATE)) {
        if (DO_NOT_STORE_STATE.equals(newValue)){
            stateful = false;
            relationships = statelessRelationshipSet;
        } else {
            stateful = true;
            relationships = statefulRelationshipSet;
        }
    }
}
 
Example 10
Source File: ReportingTaskAuditor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Locates the actual property descriptor for the given spec property descriptor.
 *
 * @param propertyDescriptors properties
 * @param specDescriptor example property
 * @return property
 */
private PropertyDescriptor locatePropertyDescriptor(Set<PropertyDescriptor> propertyDescriptors, PropertyDescriptor specDescriptor) {
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        if (propertyDescriptor.equals(specDescriptor)) {
            return propertyDescriptor;
        }
    }
    return specDescriptor;
}
 
Example 11
Source File: RouteOnAttribute.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.equals(ROUTE_STRATEGY)) {
        configuredRouteStrategy = newValue;
    } else {
        final Set<String> newDynamicPropertyNames = new HashSet<>(dynamicPropertyNames);
        if (newValue == null) {
            newDynamicPropertyNames.remove(descriptor.getName());
        } else if (oldValue == null) {    // new property
            newDynamicPropertyNames.add(descriptor.getName());
        }

        this.dynamicPropertyNames = Collections.unmodifiableSet(newDynamicPropertyNames);
    }

    // formulate the new set of Relationships
    final Set<String> allDynamicProps = this.dynamicPropertyNames;
    final Set<Relationship> newRelationships = new HashSet<>();
    final String routeStrategy = configuredRouteStrategy;
    if (ROUTE_PROPERTY_NAME.equals(routeStrategy)) {
        for (final String propName : allDynamicProps) {
            newRelationships.add(new Relationship.Builder().name(propName).build());
        }
    } else {
        newRelationships.add(REL_MATCH);
    }

    newRelationships.add(REL_NO_MATCH);
    this.relationships.set(newRelationships);
}
 
Example 12
Source File: KafkaProcessorUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
static void buildCommonKafkaProperties(final ProcessContext context, final Class<?> kafkaConfigClass, final Map<String, Object> mapToPopulate) {
    for (PropertyDescriptor propertyDescriptor : context.getProperties().keySet()) {
        if (propertyDescriptor.equals(SSL_CONTEXT_SERVICE)) {
            // Translate SSLContext Service configuration into Kafka properties
            final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
            if (sslContextService != null && sslContextService.isKeyStoreConfigured()) {
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, sslContextService.getKeyStoreFile());
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, sslContextService.getKeyStorePassword());
                final String keyPass = sslContextService.getKeyPassword() == null ? sslContextService.getKeyStorePassword() : sslContextService.getKeyPassword();
                mapToPopulate.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, keyPass);
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, sslContextService.getKeyStoreType());
            }

            if (sslContextService != null && sslContextService.isTrustStoreConfigured()) {
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, sslContextService.getTrustStoreFile());
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, sslContextService.getTrustStorePassword());
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, sslContextService.getTrustStoreType());
            }
        }

        String propertyName = propertyDescriptor.getName();
        String propertyValue = propertyDescriptor.isExpressionLanguageSupported()
                ? context.getProperty(propertyDescriptor).evaluateAttributeExpressions().getValue()
                : context.getProperty(propertyDescriptor).getValue();

        if (propertyValue != null) {
            // If the property name ends in ".ms" then it is a time period. We want to accept either an integer as number of milliseconds
            // or the standard NiFi time period such as "5 secs"
            if (propertyName.endsWith(".ms") && !StringUtils.isNumeric(propertyValue.trim())) { // kafka standard time notation
                propertyValue = String.valueOf(FormatUtils.getTimeDuration(propertyValue.trim(), TimeUnit.MILLISECONDS));
            }

            if (isStaticStringFieldNamePresent(propertyName, kafkaConfigClass, CommonClientConfigs.class, SslConfigs.class, SaslConfigs.class)) {
                mapToPopulate.put(propertyName, propertyValue);
            }
        }
    }
}
 
Example 13
Source File: UpdateAttribute.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    super.onPropertyModified(descriptor, oldValue, newValue);

    if (descriptor.equals(STORE_STATE)) {
        if (DO_NOT_STORE_STATE.equals(newValue)){
            stateful = false;
            relationships = statelessRelationshipSet;
        } else {
            stateful = true;
            relationships = statefulRelationshipSet;
        }
    }
}
 
Example 14
Source File: RouteText.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.equals(ROUTE_STRATEGY)) {
        configuredRouteStrategy = newValue;
    } else {
        final Set<String> newDynamicPropertyNames = new HashSet<>(dynamicPropertyNames);
        if (newValue == null) {
            newDynamicPropertyNames.remove(descriptor.getName());
        } else if (oldValue == null && descriptor.isDynamic()) { // new property
            newDynamicPropertyNames.add(descriptor.getName());
        }

        this.dynamicPropertyNames = Collections.unmodifiableSet(newDynamicPropertyNames);
    }

    // formulate the new set of Relationships
    final Set<String> allDynamicProps = this.dynamicPropertyNames;
    final Set<Relationship> newRelationships = new HashSet<>();
    final String routeStrategy = configuredRouteStrategy;
    if (ROUTE_TO_MATCHING_PROPERTY_NAME.equals(routeStrategy)) {
        for (final String propName : allDynamicProps) {
            newRelationships.add(new Relationship.Builder().name(propName).build());
        }
    } else {
        newRelationships.add(REL_MATCH);
    }

    newRelationships.add(REL_ORIGINAL);
    newRelationships.add(REL_NO_MATCH);
    this.relationships.set(newRelationships);
}
 
Example 15
Source File: RouteOnAttribute.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.equals(ROUTE_STRATEGY)) {
        configuredRouteStrategy = newValue;
    } else {
        final Set<String> newDynamicPropertyNames = new HashSet<>(dynamicPropertyNames);
        if (newValue == null) {
            newDynamicPropertyNames.remove(descriptor.getName());
        } else if (oldValue == null) {    // new property
            newDynamicPropertyNames.add(descriptor.getName());
        }

        this.dynamicPropertyNames = Collections.unmodifiableSet(newDynamicPropertyNames);
    }

    // formulate the new set of Relationships
    final Set<String> allDynamicProps = this.dynamicPropertyNames;
    final Set<Relationship> newRelationships = new HashSet<>();
    final String routeStrategy = configuredRouteStrategy;
    if (ROUTE_PROPERTY_NAME.equals(routeStrategy)) {
        for (final String propName : allDynamicProps) {
            newRelationships.add(new Relationship.Builder().name(propName).build());
        }
    } else {
        newRelationships.add(REL_MATCH);
    }

    newRelationships.add(REL_NO_MATCH);
    this.relationships.set(newRelationships);
}
 
Example 16
Source File: GetHBase.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.equals(TABLE_NAME)) {
        lastResult = null;
    }
}
 
Example 17
Source File: GetHBase.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.equals(TABLE_NAME)) {
        lastResult = null;
    }
}
 
Example 18
Source File: KafkaProcessorUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static void buildCommonKafkaProperties(final ProcessContext context, final Class<?> kafkaConfigClass, final Map<String, Object> mapToPopulate) {
    for (PropertyDescriptor propertyDescriptor : context.getProperties().keySet()) {
        if (propertyDescriptor.equals(SSL_CONTEXT_SERVICE)) {
            // Translate SSLContext Service configuration into Kafka properties
            final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
            if (sslContextService != null && sslContextService.isKeyStoreConfigured()) {
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, sslContextService.getKeyStoreFile());
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, sslContextService.getKeyStorePassword());
                final String keyPass = sslContextService.getKeyPassword() == null ? sslContextService.getKeyStorePassword() : sslContextService.getKeyPassword();
                mapToPopulate.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, keyPass);
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, sslContextService.getKeyStoreType());
            }

            if (sslContextService != null && sslContextService.isTrustStoreConfigured()) {
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, sslContextService.getTrustStoreFile());
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, sslContextService.getTrustStorePassword());
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, sslContextService.getTrustStoreType());
            }
        }

        String propertyName = propertyDescriptor.getName();
        String propertyValue = propertyDescriptor.isExpressionLanguageSupported()
                ? context.getProperty(propertyDescriptor).evaluateAttributeExpressions().getValue()
                : context.getProperty(propertyDescriptor).getValue();

        if (propertyValue != null && !propertyName.equals(USER_PRINCIPAL.getName()) && !propertyName.equals(USER_KEYTAB.getName())) {
            // If the property name ends in ".ms" then it is a time period. We want to accept either an integer as number of milliseconds
            // or the standard NiFi time period such as "5 secs"
            if (propertyName.endsWith(".ms") && !StringUtils.isNumeric(propertyValue.trim())) { // kafka standard time notation
                propertyValue = String.valueOf(FormatUtils.getTimeDuration(propertyValue.trim(), TimeUnit.MILLISECONDS));
            }

            if (isStaticStringFieldNamePresent(propertyName, kafkaConfigClass, CommonClientConfigs.class, SslConfigs.class, SaslConfigs.class)) {
                mapToPopulate.put(propertyName, propertyValue);
            }
        }
    }

    String securityProtocol = context.getProperty(SECURITY_PROTOCOL).getValue();
    if (SEC_SASL_PLAINTEXT.getValue().equals(securityProtocol) || SEC_SASL_SSL.getValue().equals(securityProtocol)) {
        setJaasConfig(mapToPopulate, context);
    }
}
 
Example 19
Source File: KafkaProcessorUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
static void buildCommonKafkaProperties(final ProcessContext context, final Class<?> kafkaConfigClass, final Map<String, Object> mapToPopulate) {
    for (PropertyDescriptor propertyDescriptor : context.getProperties().keySet()) {
        if (propertyDescriptor.equals(SSL_CONTEXT_SERVICE)) {
            // Translate SSLContext Service configuration into Kafka properties
            final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
            if (sslContextService != null && sslContextService.isKeyStoreConfigured()) {
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, sslContextService.getKeyStoreFile());
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, sslContextService.getKeyStorePassword());
                final String keyPass = sslContextService.getKeyPassword() == null ? sslContextService.getKeyStorePassword() : sslContextService.getKeyPassword();
                mapToPopulate.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, keyPass);
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, sslContextService.getKeyStoreType());
            }

            if (sslContextService != null && sslContextService.isTrustStoreConfigured()) {
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, sslContextService.getTrustStoreFile());
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, sslContextService.getTrustStorePassword());
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, sslContextService.getTrustStoreType());
            }
        }

        String propertyName = propertyDescriptor.getName();
        String propertyValue = propertyDescriptor.isExpressionLanguageSupported()
                ? context.getProperty(propertyDescriptor).evaluateAttributeExpressions().getValue()
                : context.getProperty(propertyDescriptor).getValue();

        if (propertyValue != null && !propertyName.equals(USER_PRINCIPAL.getName()) && !propertyName.equals(USER_KEYTAB.getName())) {
            // If the property name ends in ".ms" then it is a time period. We want to accept either an integer as number of milliseconds
            // or the standard NiFi time period such as "5 secs"
            if (propertyName.endsWith(".ms") && !StringUtils.isNumeric(propertyValue.trim())) { // kafka standard time notation
                propertyValue = String.valueOf(FormatUtils.getTimeDuration(propertyValue.trim(), TimeUnit.MILLISECONDS));
            }

            if (isStaticStringFieldNamePresent(propertyName, kafkaConfigClass, CommonClientConfigs.class, SslConfigs.class, SaslConfigs.class)) {
                mapToPopulate.put(propertyName, propertyValue);
            }
        }
    }

    String securityProtocol = context.getProperty(SECURITY_PROTOCOL).getValue();
    if (SEC_SASL_PLAINTEXT.getValue().equals(securityProtocol) || SEC_SASL_SSL.getValue().equals(securityProtocol)) {
        setJaasConfig(mapToPopulate, context);
    }
}
 
Example 20
Source File: KafkaRecordSink_2_0.java    From nifi with Apache License 2.0 4 votes vote down vote up
static void buildCommonKafkaProperties(final ConfigurationContext context, final Class<?> kafkaConfigClass, final Map<String, Object> mapToPopulate) {
    for (PropertyDescriptor propertyDescriptor : context.getProperties().keySet()) {
        if (propertyDescriptor.equals(KafkaProcessorUtils.SSL_CONTEXT_SERVICE)) {
            // Translate SSLContext Service configuration into Kafka properties
            final SSLContextService sslContextService = context.getProperty(KafkaProcessorUtils.SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
            if (sslContextService != null && sslContextService.isKeyStoreConfigured()) {
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, sslContextService.getKeyStoreFile());
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, sslContextService.getKeyStorePassword());
                final String keyPass = sslContextService.getKeyPassword() == null ? sslContextService.getKeyStorePassword() : sslContextService.getKeyPassword();
                mapToPopulate.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, keyPass);
                mapToPopulate.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, sslContextService.getKeyStoreType());
            }

            if (sslContextService != null && sslContextService.isTrustStoreConfigured()) {
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, sslContextService.getTrustStoreFile());
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, sslContextService.getTrustStorePassword());
                mapToPopulate.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, sslContextService.getTrustStoreType());
            }
        }

        String propertyName = propertyDescriptor.getName();
        String propertyValue = propertyDescriptor.isExpressionLanguageSupported()
                ? context.getProperty(propertyDescriptor).evaluateAttributeExpressions().getValue()
                : context.getProperty(propertyDescriptor).getValue();

        if (propertyValue != null) {
            // If the property name ends in ".ms" then it is a time period. We want to accept either an integer as number of milliseconds
            // or the standard NiFi time period such as "5 secs"
            if (propertyName.endsWith(".ms") && !StringUtils.isNumeric(propertyValue.trim())) { // kafka standard time notation
                propertyValue = String.valueOf(FormatUtils.getTimeDuration(propertyValue.trim(), TimeUnit.MILLISECONDS));
            }

            if (KafkaProcessorUtils.isStaticStringFieldNamePresent(propertyName, kafkaConfigClass, CommonClientConfigs.class, SslConfigs.class, SaslConfigs.class)) {
                mapToPopulate.put(propertyName, propertyValue);
            }
        }
    }

    String securityProtocol = context.getProperty(KafkaProcessorUtils.SECURITY_PROTOCOL).getValue();
    if (KafkaProcessorUtils.SEC_SASL_PLAINTEXT.getValue().equals(securityProtocol) || KafkaProcessorUtils.SEC_SASL_SSL.getValue().equals(securityProtocol)) {
        setJaasConfig(mapToPopulate, context);
    }
}