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

The following examples show how to use org.apache.nifi.components.PropertyDescriptor#isExpressionLanguageSupported() . 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: ForkRecord.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    final List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext));
    Validator validator = new RecordPathValidator();

    Map<PropertyDescriptor, String> processorProperties = validationContext.getProperties();
    for (final Map.Entry<PropertyDescriptor, String> entry : processorProperties.entrySet()) {
        PropertyDescriptor property = entry.getKey();
        if (property.isDynamic() && property.isExpressionLanguageSupported()) {
            String dynamicValue = validationContext.getProperty(property).getValue();
            if(!validationContext.isExpressionLanguagePresent(dynamicValue)) {
                results.add(validator.validate(property.getDisplayName(), dynamicValue, validationContext));
            }
        }
    }

    return results;
}
 
Example 2
Source File: MockProcessContext.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isExpressionLanguagePresent(final PropertyDescriptor property) {
    if (property == null || !property.isExpressionLanguageSupported()) {
        return false;
    }

    final List<Range> elRanges = Query.extractExpressionRanges(getProperty(property).getValue());
    return (elRanges != null && !elRanges.isEmpty());
}
 
Example 3
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 4
Source File: StatelessProcessContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isExpressionLanguagePresent(final PropertyDescriptor property) {
    if (property == null || !property.isExpressionLanguageSupported()) {
        return false;
    }

    final List<Query.Range> elRanges = Query.extractExpressionRanges(getProperty(property).getValue());
    return (elRanges != null && !elRanges.isEmpty());
}
 
Example 5
Source File: StatelessPropertyValue.java    From nifi with Apache License 2.0 5 votes vote down vote up
private StatelessPropertyValue(final String rawValue, final ControllerServiceLookup serviceLookup, final PropertyDescriptor propertyDescriptor, final boolean alreadyEvaluated,
                               final ParameterLookup parameterLookup, final VariableRegistry variableRegistry) {
    this.stdPropValue = new StandardPropertyValue(rawValue, serviceLookup, parameterLookup, variableRegistry);
    this.rawValue = rawValue;
    this.serviceLookup = (StatelessControllerServiceLookup) serviceLookup;
    this.expectExpressions = propertyDescriptor == null ? null : propertyDescriptor.isExpressionLanguageSupported();
    this.expressionLanguageScope = propertyDescriptor == null ? null : propertyDescriptor.getExpressionLanguageScope();
    this.propertyDescriptor = propertyDescriptor;
    this.expressionsEvaluated = alreadyEvaluated;
    this.variableRegistry = variableRegistry;
    this.parameterLookup = parameterLookup;
}
 
Example 6
Source File: MockProcessContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isExpressionLanguagePresent(final PropertyDescriptor property) {
    if (property == null || !property.isExpressionLanguageSupported()) {
        return false;
    }

    final List<Range> elRanges = Query.extractExpressionRanges(getProperty(property).getValue());
    return (elRanges != null && !elRanges.isEmpty());
}
 
Example 7
Source File: MockPropertyValue.java    From nifi with Apache License 2.0 5 votes vote down vote up
private MockPropertyValue(final String rawValue, final ControllerServiceLookup serviceLookup, final PropertyDescriptor propertyDescriptor, final boolean alreadyEvaluated,
        final VariableRegistry variableRegistry) {
    this.stdPropValue = new StandardPropertyValue(rawValue, serviceLookup, ParameterLookup.EMPTY, variableRegistry);
    this.rawValue = rawValue;
    this.serviceLookup = (MockControllerServiceLookup) serviceLookup;
    this.expectExpressions = propertyDescriptor == null ? null : propertyDescriptor.isExpressionLanguageSupported();
    this.expressionLanguageScope = propertyDescriptor == null ? null : propertyDescriptor.getExpressionLanguageScope();
    this.propertyDescriptor = propertyDescriptor;
    this.expressionsEvaluated = alreadyEvaluated;
    this.variableRegistry = variableRegistry;
}
 
Example 8
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 9
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 10
Source File: StandardProcessContext.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isExpressionLanguagePresent(final PropertyDescriptor property) {
    if (property == null || !property.isExpressionLanguageSupported()) {
        return false;
    }

    final List<Range> elRanges = Query.extractExpressionRanges(getProperty(property).getValue());
    return (elRanges != null && !elRanges.isEmpty());
}
 
Example 11
Source File: StandardSchedulingContext.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isExpressionLanguagePresent(PropertyDescriptor property) {
    if (property == null || !property.isExpressionLanguageSupported()) {
        return false;
    }

    final List<Range> elRanges = Query.extractExpressionRanges(getProperty(property).getValue());
    return (elRanges != null && !elRanges.isEmpty());
}
 
Example 12
Source File: BaseTransformer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
InvocationContextProperties(ProcessContext context, FlowFile flowFile) {
    List<PropertyDescriptor> propertyDescriptors = BaseTransformer.this.getSupportedPropertyDescriptors();
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        if (propertyDescriptor.isExpressionLanguageSupported()) {
            PropertyValue value = context.getProperty(propertyDescriptor)
                    .evaluateAttributeExpressions(flowFile);
            this.propertyInvocationValues.put(propertyDescriptor, value.getValue());
        }
    }
}
 
Example 13
Source File: BaseTransformer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void onScheduled(ProcessContext context) {
    List<PropertyDescriptor> propertyDescriptors = this.getSupportedPropertyDescriptors();
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        if (!propertyDescriptor.isExpressionLanguageSupported()){
            this.propertyInstanceValues.put(propertyDescriptor, context.getProperty(propertyDescriptor).getValue());
        }
    }
}
 
Example 14
Source File: MockPropertyValue.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private MockPropertyValue(final String rawValue, final ControllerServiceLookup serviceLookup, final PropertyDescriptor propertyDescriptor, final boolean alreadyEvaluated,
                          final VariableRegistry variableRegistry) {
    this.stdPropValue = new StandardPropertyValue(rawValue, serviceLookup, variableRegistry);

    this.rawValue = rawValue;
    this.serviceLookup = serviceLookup;
    this.expectExpressions = propertyDescriptor == null ? null : propertyDescriptor.isExpressionLanguageSupported();
    this.propertyDescriptor = propertyDescriptor;
    this.expressionsEvaluated = alreadyEvaluated;
    this.variableRegistry = variableRegistry;
}
 
Example 15
Source File: KafkaRecordSink_1_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);
    }
}
 
Example 16
Source File: HtmlDocumentationWriter.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the PropertyDescriptors out as a table.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer
 * @throws XMLStreamException thrown if there was a problem writing to the
 * XML Stream
 */
protected void writeProperties(final ConfigurableComponent configurableComponent,
        final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {

    final List<PropertyDescriptor> properties = configurableComponent.getPropertyDescriptors();
    writeSimpleElement(xmlStreamWriter, "h3", "Properties: ");

    if (properties.size() > 0) {
        final boolean containsExpressionLanguage = containsExpressionLanguage(configurableComponent);
        final boolean containsSensitiveProperties = containsSensitiveProperties(configurableComponent);
        xmlStreamWriter.writeStartElement("p");
        xmlStreamWriter.writeCharacters("In the list below, the names of required properties appear in ");
        writeSimpleElement(xmlStreamWriter, "strong", "bold");
        xmlStreamWriter.writeCharacters(". Any other properties (not in bold) are considered optional. " +
                "The table also indicates any default values");
        if (containsExpressionLanguage) {
            if (!containsSensitiveProperties) {
                xmlStreamWriter.writeCharacters(", and ");
            } else {
                xmlStreamWriter.writeCharacters(", ");
            }
            xmlStreamWriter.writeCharacters("whether a property supports the ");
            writeLink(xmlStreamWriter, "NiFi Expression Language", "../../html/expression-language-guide.html");
        }
        if (containsSensitiveProperties) {
            xmlStreamWriter.writeCharacters(", and whether a property is considered " + "\"sensitive\", meaning that its value will be encrypted. Before entering a "
                    + "value in a sensitive property, ensure that the ");

            writeSimpleElement(xmlStreamWriter, "strong", "nifi.properties");
            xmlStreamWriter.writeCharacters(" file has " + "an entry for the property ");
            writeSimpleElement(xmlStreamWriter, "strong", "nifi.sensitive.props.key");
        }
        xmlStreamWriter.writeCharacters(".");
        xmlStreamWriter.writeEndElement();

        xmlStreamWriter.writeStartElement("table");
        xmlStreamWriter.writeAttribute("id", "properties");

        // write the header row
        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "th", "Name");
        writeSimpleElement(xmlStreamWriter, "th", "Default Value");
        writeSimpleElement(xmlStreamWriter, "th", "Allowable Values");
        writeSimpleElement(xmlStreamWriter, "th", "Description");
        xmlStreamWriter.writeEndElement();

        // write the individual properties
        for (PropertyDescriptor property : properties) {
            xmlStreamWriter.writeStartElement("tr");
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "name");
            if (property.isRequired()) {
                writeSimpleElement(xmlStreamWriter, "strong", property.getDisplayName());
            } else {
                xmlStreamWriter.writeCharacters(property.getDisplayName());
            }

            xmlStreamWriter.writeEndElement();
            writeSimpleElement(xmlStreamWriter, "td", property.getDefaultValue(), false, "default-value");
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "allowable-values");
            writeValidValues(xmlStreamWriter, property);
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "description");
            if (property.getDescription() != null && property.getDescription().trim().length() > 0) {
                xmlStreamWriter.writeCharacters(property.getDescription());
            } else {
                xmlStreamWriter.writeCharacters("No Description Provided.");
            }

            if (property.isSensitive()) {
                xmlStreamWriter.writeEmptyElement("br");
                writeSimpleElement(xmlStreamWriter, "strong", "Sensitive Property: true");
            }

            if (property.isExpressionLanguageSupported()) {
                xmlStreamWriter.writeEmptyElement("br");
                writeSimpleElement(xmlStreamWriter, "strong", "Supports Expression Language: true");
            }
            xmlStreamWriter.writeEndElement();

            xmlStreamWriter.writeEndElement();
        }

        // TODO support dynamic properties...
        xmlStreamWriter.writeEndElement();

    } else {
        writeSimpleElement(xmlStreamWriter, "p", "This component has no required or optional properties.");
    }
}
 
Example 17
Source File: GenerateFlowFile.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
    final byte[] data;
    if (context.getProperty(UNIQUE_FLOWFILES).asBoolean()) {
        data = generateData(context);
    } else if(context.getProperty(CUSTOM_TEXT).isSet()) {
        final Charset charset = Charset.forName(context.getProperty(CHARSET).getValue());
        data = context.getProperty(CUSTOM_TEXT).evaluateAttributeExpressions().getValue().getBytes(charset);
    } else {
        data = this.data.get();
    }

    Map<PropertyDescriptor, String> processorProperties = context.getProperties();
    Map<String, String> generatedAttributes = new HashMap<String, String>();
    for (final Map.Entry<PropertyDescriptor, String> entry : processorProperties.entrySet()) {
        PropertyDescriptor property = entry.getKey();
        if (property.isDynamic() && property.isExpressionLanguageSupported()) {
            String dynamicValue = context.getProperty(property).evaluateAttributeExpressions().getValue();
            generatedAttributes.put(property.getName(), dynamicValue);
        }
    }

    if(context.getProperty(MIME_TYPE).isSet()) {
        generatedAttributes.put(CoreAttributes.MIME_TYPE.key(), context.getProperty(MIME_TYPE).getValue());
    }

    for (int i = 0; i < context.getProperty(BATCH_SIZE).asInteger(); i++) {
        FlowFile flowFile = session.create();
        if (data.length > 0) {
            flowFile = session.write(flowFile, new OutputStreamCallback() {
                @Override
                public void process(final OutputStream out) throws IOException {
                    out.write(data);
                }
            });
        }
        flowFile = session.putAllAttributes(flowFile, generatedAttributes);

        session.getProvenanceReporter().create(flowFile);
        session.transfer(flowFile, SUCCESS);
    }
}
 
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: 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);
    }
}