Search in sources :

Example 71 with PropertyDescriptor

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

the class MockProcessContext method getProperties.

@Override
public Map<PropertyDescriptor, String> getProperties() {
    final List<PropertyDescriptor> supported = component.getPropertyDescriptors();
    if (supported == null || supported.isEmpty()) {
        return Collections.unmodifiableMap(properties);
    } else {
        final Map<PropertyDescriptor, String> props = new LinkedHashMap<>();
        for (final PropertyDescriptor descriptor : supported) {
            props.put(descriptor, null);
        }
        props.putAll(properties);
        return props;
    }
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) LinkedHashMap(java.util.LinkedHashMap)

Example 72 with PropertyDescriptor

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

the class MockProcessContext method getProperty.

@Override
public PropertyValue getProperty(final String propertyName) {
    final PropertyDescriptor descriptor = component.getPropertyDescriptor(propertyName);
    if (descriptor == null) {
        return null;
    }
    final String setPropertyValue = properties.get(descriptor);
    final String propValue = (setPropertyValue == null) ? descriptor.getDefaultValue() : setPropertyValue;
    return new MockPropertyValue(propValue, this, variableRegistry, (enableExpressionValidation && allowExpressionValidation) ? descriptor : null);
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor)

Example 73 with PropertyDescriptor

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

the class MockProcessContext method removeProperty.

public boolean removeProperty(final String property) {
    Objects.requireNonNull(property);
    final PropertyDescriptor fullyPopulatedDescriptor = component.getPropertyDescriptor(property);
    String value = null;
    if ((value = properties.remove(fullyPopulatedDescriptor)) != null) {
        if (!value.equals(fullyPopulatedDescriptor.getDefaultValue())) {
            component.onPropertyModified(fullyPopulatedDescriptor, value, null);
        }
        return true;
    }
    return false;
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor)

Example 74 with PropertyDescriptor

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

the class NotificationServiceManager method buildNotificationContext.

private NotificationContext buildNotificationContext(final ConfiguredNotificationService config) {
    return new NotificationContext() {

        @Override
        public PropertyValue getProperty(final PropertyDescriptor descriptor) {
            final PropertyDescriptor fullPropDescriptor = config.getService().getPropertyDescriptor(descriptor.getName());
            if (fullPropDescriptor == null) {
                return null;
            }
            String configuredValue = config.getProperties().get(fullPropDescriptor.getName());
            if (configuredValue == null) {
                configuredValue = fullPropDescriptor.getDefaultValue();
            }
            return new StandardPropertyValue(configuredValue, null, variableRegistry);
        }

        @Override
        public Map<PropertyDescriptor, String> getProperties() {
            final Map<PropertyDescriptor, String> props = new HashMap<>();
            final Map<String, String> configuredProps = config.getProperties();
            final NotificationService service = config.getService();
            final List<PropertyDescriptor> configuredPropertyDescriptors = new ArrayList<>(service.getPropertyDescriptors());
            // This is needed to capture all dynamic properties
            configuredProps.forEach((key, value) -> {
                PropertyDescriptor propertyDescriptor = config.service.getPropertyDescriptor(key);
                props.put(config.service.getPropertyDescriptor(key), value);
                configuredPropertyDescriptors.remove(propertyDescriptor);
            });
            for (final PropertyDescriptor descriptor : configuredPropertyDescriptors) {
                props.put(descriptor, descriptor.getDefaultValue());
            }
            return props;
        }
    };
}
Also used : NotificationContext(org.apache.nifi.bootstrap.notification.NotificationContext) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) ArrayList(java.util.ArrayList) NotificationService(org.apache.nifi.bootstrap.notification.NotificationService)

Example 75 with PropertyDescriptor

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

the class HiveConnectionPoolTest method testExpressionLanguageSupport.

@Test
public void testExpressionLanguageSupport() throws Exception {
    final String URL = "jdbc:hive2://localhost:10000/default";
    final String USER = "user";
    final String PASS = "pass";
    final int MAX_CONN = 7;
    // 10000 milliseconds
    final String MAX_WAIT = "10 sec";
    final String CONF = "/path/to/hive-site.xml";
    hiveConnectionPool = new HiveConnectionPool();
    Map<PropertyDescriptor, String> props = new HashMap<PropertyDescriptor, String>() {

        {
            put(HiveConnectionPool.DATABASE_URL, "${url}");
            put(HiveConnectionPool.DB_USER, "${username}");
            put(HiveConnectionPool.DB_PASSWORD, "${password}");
            put(HiveConnectionPool.MAX_TOTAL_CONNECTIONS, "${maxconn}");
            put(HiveConnectionPool.MAX_WAIT_TIME, "${maxwait}");
            put(HiveConnectionPool.HIVE_CONFIGURATION_RESOURCES, "${hiveconf}");
        }
    };
    MockVariableRegistry registry = new MockVariableRegistry();
    registry.setVariable(new VariableDescriptor("url"), URL);
    registry.setVariable(new VariableDescriptor("username"), USER);
    registry.setVariable(new VariableDescriptor("password"), PASS);
    registry.setVariable(new VariableDescriptor("maxconn"), Integer.toString(MAX_CONN));
    registry.setVariable(new VariableDescriptor("maxwait"), MAX_WAIT);
    registry.setVariable(new VariableDescriptor("hiveconf"), CONF);
    MockConfigurationContext context = new MockConfigurationContext(props, null, registry);
    hiveConnectionPool.onConfigured(context);
    Field dataSourceField = HiveConnectionPool.class.getDeclaredField("dataSource");
    dataSourceField.setAccessible(true);
    basicDataSource = (BasicDataSource) dataSourceField.get(hiveConnectionPool);
    assertEquals(URL, basicDataSource.getUrl());
    assertEquals(USER, basicDataSource.getUsername());
    assertEquals(PASS, basicDataSource.getPassword());
    assertEquals(MAX_CONN, basicDataSource.getMaxActive());
    assertEquals(10000L, basicDataSource.getMaxWait());
    assertEquals(URL, hiveConnectionPool.getConnectionURL());
}
Also used : Field(java.lang.reflect.Field) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) MockConfigurationContext(org.apache.nifi.util.MockConfigurationContext) HashMap(java.util.HashMap) MockVariableRegistry(org.apache.nifi.util.MockVariableRegistry) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) Test(org.junit.Test)

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