Search in sources :

Example 46 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class TestStandardPropertyValue method testMissingEndBraceEvaluatesToStringLiteral.

@Test
public void testMissingEndBraceEvaluatesToStringLiteral() {
    final PropertyValue value = new StandardPropertyValue("Hello, ${audience!", lookup);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("audience", "World");
    assertEquals("Hello, ${audience!", value.evaluateAttributeExpressions(createFlowFile(attributes)).getValue());
}
Also used : HashMap(java.util.HashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) Test(org.junit.Test)

Example 47 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class TestStandardPropertyValue method testSubstituteAttributesWithMultipleMatchingArgs.

@Test
public void testSubstituteAttributesWithMultipleMatchingArgs() {
    final PropertyValue value = new StandardPropertyValue("Hello, ${audience}${comma}${question}!", lookup);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("audience", "World");
    attributes.put("comma", ",");
    attributes.put("question", " how are you?");
    assertEquals("Hello, World, how are you?!", value.evaluateAttributeExpressions(createFlowFile(attributes)).getValue());
}
Also used : HashMap(java.util.HashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) Test(org.junit.Test)

Example 48 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class CaptureChangeMySQL method setup.

public void setup(ProcessContext context) {
    final ComponentLog logger = getLogger();
    final StateManager stateManager = context.getStateManager();
    final StateMap stateMap;
    try {
        stateMap = stateManager.getState(Scope.CLUSTER);
    } catch (final IOException ioe) {
        logger.error("Failed to retrieve observed maximum values from the State Manager. Will not attempt " + "connection until this is accomplished.", ioe);
        context.yield();
        return;
    }
    PropertyValue dbNameValue = context.getProperty(DATABASE_NAME_PATTERN);
    databaseNamePattern = dbNameValue.isSet() ? Pattern.compile(dbNameValue.getValue()) : null;
    PropertyValue tableNameValue = context.getProperty(TABLE_NAME_PATTERN);
    tableNamePattern = tableNameValue.isSet() ? Pattern.compile(tableNameValue.getValue()) : null;
    stateUpdateInterval = context.getProperty(STATE_UPDATE_INTERVAL).evaluateAttributeExpressions().asTimePeriod(TimeUnit.MILLISECONDS);
    boolean getAllRecords = context.getProperty(RETRIEVE_ALL_RECORDS).asBoolean();
    includeBeginCommit = context.getProperty(INCLUDE_BEGIN_COMMIT).asBoolean();
    includeDDLEvents = context.getProperty(INCLUDE_DDL_EVENTS).asBoolean();
    // Set current binlog filename to whatever is in State, falling back to the Retrieve All Records then Initial Binlog Filename if no State variable is present
    currentBinlogFile = stateMap.get(BinlogEventInfo.BINLOG_FILENAME_KEY);
    if (currentBinlogFile == null) {
        if (!getAllRecords) {
            if (context.getProperty(INIT_BINLOG_FILENAME).isSet()) {
                currentBinlogFile = context.getProperty(INIT_BINLOG_FILENAME).evaluateAttributeExpressions().getValue();
            }
        } else {
            // If we're starting from the beginning of all binlogs, the binlog filename must be the empty string (not null)
            currentBinlogFile = "";
        }
    }
    // Set current binlog position to whatever is in State, falling back to the Retrieve All Records then Initial Binlog Filename if no State variable is present
    String binlogPosition = stateMap.get(BinlogEventInfo.BINLOG_POSITION_KEY);
    if (binlogPosition != null) {
        currentBinlogPosition = Long.valueOf(binlogPosition);
    } else if (!getAllRecords) {
        if (context.getProperty(INIT_BINLOG_POSITION).isSet()) {
            currentBinlogPosition = context.getProperty(INIT_BINLOG_POSITION).evaluateAttributeExpressions().asLong();
        } else {
            currentBinlogPosition = DO_NOT_SET;
        }
    } else {
        currentBinlogPosition = -1;
    }
    // Get current sequence ID from state
    String seqIdString = stateMap.get(EventWriter.SEQUENCE_ID_KEY);
    if (StringUtils.isEmpty(seqIdString)) {
        // Use Initial Sequence ID property if none is found in state
        PropertyValue seqIdProp = context.getProperty(INIT_SEQUENCE_ID);
        if (seqIdProp.isSet()) {
            currentSequenceId.set(seqIdProp.evaluateAttributeExpressions().asInteger());
        }
    } else {
        currentSequenceId.set(Integer.parseInt(seqIdString));
    }
    // Get reference to Distributed Cache if one exists. If it does not, no enrichment (resolution of column names, e.g.) will be performed
    boolean createEnrichmentConnection = false;
    if (context.getProperty(DIST_CACHE_CLIENT).isSet()) {
        cacheClient = context.getProperty(DIST_CACHE_CLIENT).asControllerService(DistributedMapCacheClient.class);
        createEnrichmentConnection = true;
    } else {
        logger.warn("No Distributed Map Cache Client is specified, so no event enrichment (resolution of column names, e.g.) will be performed.");
        cacheClient = null;
    }
    // Save off MySQL cluster and JDBC driver information, will be used to connect for event enrichment as well as for the binlog connector
    try {
        List<InetSocketAddress> hosts = getHosts(context.getProperty(HOSTS).evaluateAttributeExpressions().getValue());
        String username = context.getProperty(USERNAME).evaluateAttributeExpressions().getValue();
        String password = context.getProperty(PASSWORD).evaluateAttributeExpressions().getValue();
        // BinaryLogClient expects a non-null password, so set it to the empty string if it is not provided
        if (password == null) {
            password = "";
        }
        long connectTimeout = context.getProperty(CONNECT_TIMEOUT).evaluateAttributeExpressions().asTimePeriod(TimeUnit.MILLISECONDS);
        String driverLocation = context.getProperty(DRIVER_LOCATION).evaluateAttributeExpressions().getValue();
        String driverName = context.getProperty(DRIVER_NAME).evaluateAttributeExpressions().getValue();
        Long serverId = context.getProperty(SERVER_ID).evaluateAttributeExpressions().asLong();
        connect(hosts, username, password, serverId, createEnrichmentConnection, driverLocation, driverName, connectTimeout);
    } catch (IOException | IllegalStateException e) {
        context.yield();
        binlogClient = null;
        throw new ProcessException(e.getMessage(), e);
    }
}
Also used : DistributedMapCacheClient(org.apache.nifi.distributed.cache.client.DistributedMapCacheClient) InetSocketAddress(java.net.InetSocketAddress) StateMap(org.apache.nifi.components.state.StateMap) PropertyValue(org.apache.nifi.components.PropertyValue) IOException(java.io.IOException) ComponentLog(org.apache.nifi.logging.ComponentLog) ProcessException(org.apache.nifi.processor.exception.ProcessException) StateManager(org.apache.nifi.components.state.StateManager) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 49 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class SchemaAccessUtils method getSchemaAccessStrategy.

public static SchemaAccessStrategy getSchemaAccessStrategy(final String allowableValue, final SchemaRegistry schemaRegistry, final PropertyContext context) {
    if (allowableValue.equalsIgnoreCase(SCHEMA_NAME_PROPERTY.getValue())) {
        final PropertyValue schemaName = context.getProperty(SCHEMA_NAME);
        final PropertyValue schemaBranchName = context.getProperty(SCHEMA_BRANCH_NAME);
        final PropertyValue schemaVersion = context.getProperty(SCHEMA_VERSION);
        return new SchemaNamePropertyStrategy(schemaRegistry, schemaName, schemaBranchName, schemaVersion);
    } else if (allowableValue.equalsIgnoreCase(INHERIT_RECORD_SCHEMA.getValue())) {
        return new InheritSchemaFromRecord();
    } else if (allowableValue.equalsIgnoreCase(SCHEMA_TEXT_PROPERTY.getValue())) {
        return new AvroSchemaTextStrategy(context.getProperty(SCHEMA_TEXT));
    } else if (allowableValue.equalsIgnoreCase(HWX_CONTENT_ENCODED_SCHEMA.getValue())) {
        return new HortonworksEncodedSchemaReferenceStrategy(schemaRegistry);
    } else if (allowableValue.equalsIgnoreCase(HWX_SCHEMA_REF_ATTRIBUTES.getValue())) {
        return new HortonworksAttributeSchemaReferenceStrategy(schemaRegistry);
    } else if (allowableValue.equalsIgnoreCase(CONFLUENT_ENCODED_SCHEMA.getValue())) {
        return new ConfluentSchemaRegistryStrategy(schemaRegistry);
    }
    return null;
}
Also used : PropertyValue(org.apache.nifi.components.PropertyValue)

Example 50 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class AbstractPutHDFSRecord method preProcessConfiguration.

@Override
protected void preProcessConfiguration(Configuration config, ProcessContext context) {
    // Set umask once, to avoid thread safety issues doing it in onTrigger
    final PropertyValue umaskProp = context.getProperty(UMASK);
    final short dfsUmask;
    if (umaskProp.isSet()) {
        dfsUmask = Short.parseShort(umaskProp.getValue(), 8);
    } else {
        dfsUmask = FsPermission.DEFAULT_UMASK;
    }
    FsPermission.setUMask(config, new FsPermission(dfsUmask));
}
Also used : PropertyValue(org.apache.nifi.components.PropertyValue) FsPermission(org.apache.hadoop.fs.permission.FsPermission)

Aggregations

PropertyValue (org.apache.nifi.components.PropertyValue)73 HashMap (java.util.HashMap)29 Test (org.junit.Test)22 StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)21 ComponentLog (org.apache.nifi.logging.ComponentLog)18 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)16 IOException (java.io.IOException)15 Map (java.util.Map)13 FlowFile (org.apache.nifi.flowfile.FlowFile)11 ProcessException (org.apache.nifi.processor.exception.ProcessException)11 MockPropertyValue (org.apache.nifi.util.MockPropertyValue)11 ArrayList (java.util.ArrayList)9 SSLContext (javax.net.ssl.SSLContext)7 Relationship (org.apache.nifi.processor.Relationship)7 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)6 File (java.io.File)5 DynamicRelationship (org.apache.nifi.annotation.behavior.DynamicRelationship)5 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)5 SchemaIdentifier (org.apache.nifi.serialization.record.SchemaIdentifier)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5