Search in sources :

Example 26 with PropertyDescriptor

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

the class TestCredentialsProviderFactory method testFileCredentials.

@Test
public void testFileCredentials() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class);
    runner.setProperty(CredentialPropertyDescriptors.CREDENTIALS_FILE, "src/test/resources/mock-aws-credentials.properties");
    runner.assertValid();
    Map<PropertyDescriptor, String> properties = runner.getProcessContext().getProperties();
    final CredentialsProviderFactory factory = new CredentialsProviderFactory();
    final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties);
    Assert.assertNotNull(credentialsProvider);
    assertEquals("credentials provider should be equal", PropertiesFileCredentialsProvider.class, credentialsProvider.getClass());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) TestRunner(org.apache.nifi.util.TestRunner) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 27 with PropertyDescriptor

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

the class TestCredentialsProviderFactory method testNamedProfileCredentials.

@Test
public void testNamedProfileCredentials() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class);
    runner.setProperty(CredentialPropertyDescriptors.USE_DEFAULT_CREDENTIALS, "false");
    runner.setProperty(CredentialPropertyDescriptors.PROFILE_NAME, "BogusProfile");
    runner.assertValid();
    Map<PropertyDescriptor, String> properties = runner.getProcessContext().getProperties();
    final CredentialsProviderFactory factory = new CredentialsProviderFactory();
    final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties);
    Assert.assertNotNull(credentialsProvider);
    assertEquals("credentials provider should be equal", ProfileCredentialsProvider.class, credentialsProvider.getClass());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) TestRunner(org.apache.nifi.util.TestRunner) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 28 with PropertyDescriptor

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

the class TestCredentialsProviderFactory method testExplicitDefaultCredentials.

@Test
public void testExplicitDefaultCredentials() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class);
    runner.setProperty(CredentialPropertyDescriptors.USE_DEFAULT_CREDENTIALS, "true");
    runner.assertValid();
    Map<PropertyDescriptor, String> properties = runner.getProcessContext().getProperties();
    final CredentialsProviderFactory factory = new CredentialsProviderFactory();
    final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties);
    Assert.assertNotNull(credentialsProvider);
    assertEquals("credentials provider should be equal", DefaultAWSCredentialsProviderChain.class, credentialsProvider.getClass());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) TestRunner(org.apache.nifi.util.TestRunner) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 29 with PropertyDescriptor

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

the class PutEmail method getMailPropertiesFromFlowFile.

/**
 * Uses the mapping of javax.mail properties to NiFi PropertyDescriptors to build the required Properties object to be used for sending this email
 *
 * @param context context
 * @param flowFile flowFile
 * @return mail properties
 */
private Properties getMailPropertiesFromFlowFile(final ProcessContext context, final FlowFile flowFile) {
    final Properties properties = new Properties();
    final ComponentLog logger = this.getLogger();
    for (Entry<String, PropertyDescriptor> entry : propertyToContext.entrySet()) {
        // Evaluate the property descriptor against the flow file
        String flowFileValue = context.getProperty(entry.getValue()).evaluateAttributeExpressions(flowFile).getValue();
        String property = entry.getKey();
        logger.debug("Evaluated Mail Property: {} with Value: {}", new Object[] { property, flowFileValue });
        // Nullable values are not allowed, so filter out
        if (null != flowFileValue) {
            properties.setProperty(property, flowFileValue);
        }
    }
    return properties;
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) Properties(java.util.Properties) ComponentLog(org.apache.nifi.logging.ComponentLog)

Example 30 with PropertyDescriptor

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

the class RouteText method onScheduled.

/**
 * When this processor is scheduled, update the dynamic properties into the map
 * for quick access during each onTrigger call
 *
 * @param context ProcessContext used to retrieve dynamic properties
 */
@OnScheduled
public void onScheduled(final ProcessContext context) {
    final String regex = context.getProperty(GROUPING_REGEX).getValue();
    if (regex != null) {
        groupingRegex = Pattern.compile(regex);
    }
    final Map<Relationship, PropertyValue> newPropertyMap = new HashMap<>();
    for (final PropertyDescriptor descriptor : context.getProperties().keySet()) {
        if (!descriptor.isDynamic()) {
            continue;
        }
        getLogger().debug("Adding new dynamic property: {}", new Object[] { descriptor });
        newPropertyMap.put(new Relationship.Builder().name(descriptor.getName()).build(), context.getProperty(descriptor));
    }
    this.propertyMap = newPropertyMap;
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) Relationship(org.apache.nifi.processor.Relationship) DynamicRelationship(org.apache.nifi.annotation.behavior.DynamicRelationship) PropertyValue(org.apache.nifi.components.PropertyValue) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Aggregations

PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)206 HashMap (java.util.HashMap)97 Test (org.junit.Test)67 Map (java.util.Map)57 ArrayList (java.util.ArrayList)49 HashSet (java.util.HashSet)24 IOException (java.io.IOException)23 Relationship (org.apache.nifi.processor.Relationship)22 ComponentLog (org.apache.nifi.logging.ComponentLog)21 LinkedHashMap (java.util.LinkedHashMap)20 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)19 TestRunner (org.apache.nifi.util.TestRunner)19 ValidationResult (org.apache.nifi.components.ValidationResult)17 ProcessException (org.apache.nifi.processor.exception.ProcessException)17 FlowFile (org.apache.nifi.flowfile.FlowFile)16 LinkedHashSet (java.util.LinkedHashSet)15 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)14 PropertyValue (org.apache.nifi.components.PropertyValue)14 URL (java.net.URL)13 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)13