org.apache.nifi.registry.VariableRegistry Java Examples

The following examples show how to use org.apache.nifi.registry.VariableRegistry. 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: StatelessControllerServiceLookup.java    From nifi with Apache License 2.0 6 votes vote down vote up
public ValidationResult setControllerServiceProperty(final ControllerService service, final PropertyDescriptor property, final StatelessProcessContext context,
                                                     final VariableRegistry registry, final String value) {
    final StatelessStateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier());
    if (serviceStateManager == null) {
        throw new IllegalStateException("Controller service " + service + " has not been added to this TestRunner via the #addControllerService method");
    }

    final ValidationContext validationContext = new StatelessValidationContext(context, this, serviceStateManager, registry, parameterContext);
    final ValidationResult validationResult = property.validate(value, validationContext);

    final StatelessControllerServiceConfiguration configuration = getControllerServiceConfigToUpdate(service);
    final PropertyConfiguration oldValue = configuration.getProperties().get(property);
    final PropertyConfiguration propertyConfiguration = createPropertyConfiguration(value, property.isExpressionLanguageSupported());
    configuration.setProperty(property, propertyConfiguration);

    if (oldValue == null && value != null) {
        service.onPropertyModified(property, null, value);
    } else if ((value == null && oldValue.getRawValue() != null) || (value != null && !value.equals(oldValue.getRawValue()))) {
        service.onPropertyModified(property, oldValue.getRawValue(), value);
    }

    return validationResult;
}
 
Example #2
Source File: FlowController.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public static FlowController createStandaloneInstance(
        final FlowFileEventRepository flowFileEventRepo,
        final NiFiProperties properties,
        final Authorizer authorizer,
        final AuditService auditService,
        final StringEncryptor encryptor,
        final BulletinRepository bulletinRepo,
        final VariableRegistry variableRegistry) {

    return new FlowController(
            flowFileEventRepo,
            properties,
            authorizer,
            auditService,
            encryptor,
            /* configuredForClustering */ false,
            /* NodeProtocolSender */ null,
            bulletinRepo,
            /* cluster coordinator */ null,
            /* heartbeat monitor */ null,
            /* leader election manager */ null,
            /* variable registry */ variableRegistry);
}
 
Example #3
Source File: StandardReportingContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
public StandardReportingContext(final FlowController flowController, final BulletinRepository bulletinRepository,
                                final Map<PropertyDescriptor, String> properties, final ReportingTask reportingTask,
                                final VariableRegistry variableRegistry, final ParameterLookup parameterLookup) {
    this.flowController = flowController;
    this.eventAccess = flowController.getEventAccess();
    this.bulletinRepository = bulletinRepository;
    this.properties = Collections.unmodifiableMap(properties);
    this.serviceProvider = flowController.getControllerServiceProvider();
    this.reportingTask = reportingTask;
    this.variableRegistry = variableRegistry;
    this.parameterLookup = parameterLookup;
    this.analyticsEnabled = flowController.getStatusAnalyticsEngine() != null;
    preparedQueries = new HashMap<>();

    for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) {
        final PropertyDescriptor desc = entry.getKey();
        String value = entry.getValue();
        if (value == null) {
            value = desc.getDefaultValue();
        }

        final PreparedQuery pq = Query.prepare(value);
        preparedQueries.put(desc, pq);
    }
}
 
Example #4
Source File: MockProcessContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
public MockProcessContext(final ControllerService component,
                          final String componentName,
                          final MockProcessContext context,
                          final StateManager stateManager,
                          final VariableRegistry variableRegistry) {
    this(component, componentName, stateManager, variableRegistry);

    try {
        annotationData = context.getControllerServiceAnnotationData(component);
        final Map<PropertyDescriptor, String> props = context.getControllerServiceProperties(component);
        properties.putAll(props);

        super.addControllerServices(context);
    } catch (IllegalArgumentException e) {
        // do nothing...the service is being loaded
    }
}
 
Example #5
Source File: ValueLookup.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a ValueLookup where values are looked up first based any
 * provided additional maps, then flowfile properties, then flowfile
 * attributes, then based on the provided variable registry. The lookup is
 * immutable and operations which attempt to alter state will throw
 * UnsupportedOperationException
 *
 * @param registry the variable registry to lookup from; may be null
 * @param flowFile the flowFile to pull attributes from; may be null
 * @param additionalMaps the maps to pull values from; may be null or empty
 */
@SuppressWarnings("unchecked")
ValueLookup(final VariableRegistry registry, final FlowFile flowFile, final Map<String, String>... additionalMaps) {
    for (final Map<String, String> map : additionalMaps) {
        if (map != null && !map.isEmpty()) {
            maps.add(map);
        }
    }

    if (flowFile != null) {
        maps.add(ValueLookup.extractFlowFileProperties(flowFile));
        maps.add(flowFile.getAttributes());
    }

    this.registry = registry == null ? VariableRegistry.EMPTY_REGISTRY : registry;
}
 
Example #6
Source File: StatelessControllerServiceLookup.java    From nifi with Apache License 2.0 6 votes vote down vote up
public void enableControllerServices(final VariableRegistry variableRegistry) {
    for (final StatelessControllerServiceConfiguration config : controllerServiceMap.values()) {
        final ControllerService service = config.getService();
        final Collection<ValidationResult> validationResults = validate(service, config, variableRegistry);
        if (!validationResults.isEmpty()) {
            throw new RuntimeException("Failed to enable Controller Service {id=" + service.getIdentifier() + ", name=" + config.getName() + ", type=" + service.getClass() + "} because " +
                    "validation failed: " + validationResults);
        }

        try {
            enableControllerService(service, variableRegistry);
        } catch (IllegalAccessException| InvocationTargetException e) {
            throw new RuntimeException("Failed to enable Controller Service {id=" + service.getIdentifier() + ", name=" + config.getName() + ", type=" + service.getClass() + "}", e);
        }
    }
}
 
Example #7
Source File: ComponentFactory.java    From nifi with Apache License 2.0 6 votes vote down vote up
private Set<URL> getAdditionalClasspathResources(final List<PropertyDescriptor> propertyDescriptors, final String componentId, final Map<String, String> properties,
                                                 final ParameterLookup parameterLookup, final VariableRegistry variableRegistry, final ComponentLog logger) {
    final Set<String> modulePaths = new LinkedHashSet<>();
    for (final PropertyDescriptor descriptor : propertyDescriptors) {
        if (descriptor.isDynamicClasspathModifier()) {
            final String value = properties.get(descriptor.getName());
            if (!StringUtils.isEmpty(value)) {
                final StandardPropertyValue propertyValue = new StandardPropertyValue(value, null, parameterLookup, variableRegistry);
                modulePaths.add(propertyValue.evaluateAttributeExpressions().getValue());
            }
        }
    }

    final Set<URL> additionalUrls = new LinkedHashSet<>();
    try {
        final URL[] urls = ClassLoaderUtils.getURLsForClasspath(modulePaths, null, true);
        if (urls != null) {
            additionalUrls.addAll(Arrays.asList(urls));
        }
    } catch (MalformedURLException mfe) {
        logger.error("Error processing classpath resources for " + componentId + ": " + mfe.getMessage(), mfe);
    }

    return additionalUrls;
}
 
Example #8
Source File: StandardStateManagerProvider.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static synchronized StateManagerProvider create(final NiFiProperties properties, final VariableRegistry variableRegistry, final ExtensionManager extensionManager,
                                                       final ParameterLookup parameterLookup) throws ConfigParseException, IOException {
    if (provider != null) {
        return provider;
    }

    final StateProvider localProvider = createLocalStateProvider(properties,variableRegistry, extensionManager, parameterLookup);

    final StateProvider clusterProvider;
    if (properties.isNode()) {
        clusterProvider = createClusteredStateProvider(properties,variableRegistry, extensionManager, parameterLookup);
    } else {
        clusterProvider = null;
    }

    provider = new StandardStateManagerProvider(localProvider, clusterProvider);
    return provider;
}
 
Example #9
Source File: TestStandardProcessScheduler.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 10000)
public void testProcessorThrowsExceptionOnScheduledRetry() throws InterruptedException {
    final FailOnScheduledProcessor proc = new FailOnScheduledProcessor();
    proc.setDesiredFailureCount(3);

    proc.initialize(new StandardProcessorInitializationContext(UUID.randomUUID().toString(), null, null, null, KerberosConfig.NOT_CONFIGURED));
    final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);
    final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(proc, systemBundle.getBundleDetails().getCoordinate(), null);

    final ProcessorNode procNode = new StandardProcessorNode(loggableComponent, UUID.randomUUID().toString(),
        new StandardValidationContextFactory(serviceProvider, variableRegistry),
        scheduler, serviceProvider, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent, extensionManager, new SynchronousValidationTrigger());

    procNode.performValidation();
    rootGroup.addProcessor(procNode);

    scheduler.startProcessor(procNode, true);
    while (!proc.isSucceess()) {
        Thread.sleep(5L);
    }

    assertEquals(3, proc.getOnScheduledInvocationCount());
}
 
Example #10
Source File: TimerDrivenSchedulingAgent.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public TimerDrivenSchedulingAgent(
        final FlowController flowController,
        final FlowEngine flowEngine,
        final ProcessContextFactory contextFactory,
        final StringEncryptor encryptor,
        final VariableRegistry variableRegistry,
        final NiFiProperties nifiProperties) {
    super(flowEngine);
    this.flowController = flowController;
    this.contextFactory = contextFactory;
    this.encryptor = encryptor;
    this.variableRegistry = variableRegistry;

    final String boredYieldDuration = nifiProperties.getBoredYieldDuration();
    try {
        noWorkYieldNanos = FormatUtils.getTimeDuration(boredYieldDuration, TimeUnit.NANOSECONDS);
    } catch (final IllegalArgumentException e) {
        throw new RuntimeException("Failed to create SchedulingAgent because the " + NiFiProperties.BORED_YIELD_DURATION + " property is set to an invalid time duration: " + boredYieldDuration);
    }
}
 
Example #11
Source File: StandardValidationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
public StandardValidationContext(
        final ControllerServiceProvider controllerServiceProvider,
        final Map<PropertyDescriptor, PropertyConfiguration> properties,
        final String annotationData,
        final String groupId,
        final String componentId,
        final VariableRegistry variableRegistry,
        final ParameterContext parameterContext) {
    this.controllerServiceProvider = controllerServiceProvider;
    this.properties = new HashMap<>(properties);
    this.annotationData = annotationData;
    this.variableRegistry = variableRegistry;
    this.groupId = groupId;
    this.componentId = componentId;
    this.parameterContext = parameterContext;

    preparedQueries = new HashMap<>(properties.size());
    for (final Map.Entry<PropertyDescriptor, PropertyConfiguration> entry : properties.entrySet()) {
        final PropertyDescriptor desc = entry.getKey();
        final PropertyConfiguration configuration = entry.getValue();

        String value = (configuration == null) ? null : configuration.getEffectiveValue(parameterContext);
        if (value == null) {
            value = desc.getDefaultValue();
        }

        final PreparedQuery pq = Query.prepare(value);
        preparedQueries.put(desc, pq);
    }

    expressionLanguageSupported = new HashMap<>(properties.size());
    for (final PropertyDescriptor descriptor : properties.keySet()) {
        expressionLanguageSupported.put(descriptor.getName(), descriptor.isExpressionLanguageSupported());
    }
}
 
Example #12
Source File: NotificationServiceManager.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
NotificationServiceManager(final VariableRegistry variableRegistry){
    this.variableRegistry = variableRegistry;
    notificationExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
        @Override
        public Thread newThread(final Runnable r) {
            final Thread t = Executors.defaultThreadFactory().newThread(r);
            t.setName("Notification Service Dispatcher");
            t.setDaemon(true);
            return t;
        }
    });
}
 
Example #13
Source File: StandardProcessorNode.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public StandardProcessorNode(final Processor processor, final String uuid,
                             final ValidationContextFactory validationContextFactory, final ProcessScheduler scheduler,
                             final ControllerServiceProvider controllerServiceProvider, final NiFiProperties nifiProperties,
                             final VariableRegistry variableRegistry, final ComponentLog logger) {

    this(processor, uuid, validationContextFactory, scheduler, controllerServiceProvider,
        processor.getClass().getSimpleName(), processor.getClass().getCanonicalName(), nifiProperties, variableRegistry, logger);
}
 
Example #14
Source File: StandardFlowManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
public void removeRootControllerService(final ControllerServiceNode service) {
    final ControllerServiceNode existing = rootControllerServices.get(requireNonNull(service).getIdentifier());
    if (existing == null) {
        throw new IllegalStateException(service + " is not a member of this Process Group");
    }

    service.verifyCanDelete();

    final ExtensionManager extensionManager = flowController.getExtensionManager();
    final VariableRegistry variableRegistry = flowController.getVariableRegistry();

    try (final NarCloseable x = NarCloseable.withComponentNarLoader(extensionManager, service.getControllerServiceImplementation().getClass(), service.getIdentifier())) {
        final ConfigurationContext configurationContext = new StandardConfigurationContext(service, flowController.getControllerServiceProvider(), null, variableRegistry);
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, service.getControllerServiceImplementation(), configurationContext);
    }

    for (final Map.Entry<PropertyDescriptor, String> entry : service.getEffectivePropertyValues().entrySet()) {
        final PropertyDescriptor descriptor = entry.getKey();
        if (descriptor.getControllerServiceDefinition() != null) {
            final String value = entry.getValue() == null ? descriptor.getDefaultValue() : entry.getValue();
            if (value != null) {
                final ControllerServiceNode referencedNode = getRootControllerService(value);
                if (referencedNode != null) {
                    referencedNode.removeReference(service, descriptor);
                }
            }
        }
    }

    rootControllerServices.remove(service.getIdentifier());
    flowController.getStateManagerProvider().onComponentRemoved(service.getIdentifier());

    extensionManager.removeInstanceClassLoader(service.getIdentifier());

    logger.info("{} removed from Flow Controller", service);
}
 
Example #15
Source File: TestStandardProcessScheduler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 10000)
public void testProcessorTimeOutNoResponseToInterrupt() throws InterruptedException {
    final FailOnScheduledProcessor proc = new FailOnScheduledProcessor();
    proc.setDesiredFailureCount(0);
    proc.setOnScheduledSleepDuration(20, TimeUnit.MINUTES, false, 1);

    proc.initialize(new StandardProcessorInitializationContext(UUID.randomUUID().toString(), null, null, null, KerberosConfig.NOT_CONFIGURED));
    final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);
    final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(proc, systemBundle.getBundleDetails().getCoordinate(), null);

    final ProcessorNode procNode = new StandardProcessorNode(loggableComponent, UUID.randomUUID().toString(),
        new StandardValidationContextFactory(serviceProvider, variableRegistry),
        scheduler, serviceProvider, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent, extensionManager, new SynchronousValidationTrigger());

    rootGroup.addProcessor(procNode);

    procNode.performValidation();
    scheduler.startProcessor(procNode, true);

    while(proc.getOnScheduledInvocationCount() < 1){
        Thread.sleep(100L);
    }
    assertEquals(1, proc.getOnScheduledInvocationCount());
    Thread.sleep(100L);
    assertEquals(1, proc.getOnScheduledInvocationCount());

    // Allow test to complete.
    proc.setAllowSleepInterrupt(true);
}
 
Example #16
Source File: AbstractReportingTaskNode.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public AbstractReportingTaskNode(final ReportingTask reportingTask, final String id,
                                 final ControllerServiceProvider controllerServiceProvider, final ProcessScheduler processScheduler,
                                 final ValidationContextFactory validationContextFactory, final VariableRegistry variableRegistry,
                                 final ComponentLog logger) {

    this(reportingTask, id, controllerServiceProvider, processScheduler, validationContextFactory,
        reportingTask.getClass().getSimpleName(), reportingTask.getClass().getCanonicalName(),variableRegistry, logger);
}
 
Example #17
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public StandardProcessGroup(final String id, final ControllerServiceProvider serviceProvider, final StandardProcessScheduler scheduler,
        final NiFiProperties nifiProps, final StringEncryptor encryptor, final FlowController flowController,
        final VariableRegistry variableRegistry) {
    this.id = id;
    this.controllerServiceProvider = serviceProvider;
    this.parent = new AtomicReference<>();
    this.scheduler = scheduler;
    this.comments = new AtomicReference<>("");
    this.encryptor = encryptor;
    this.flowController = flowController;
    this.variableRegistry = variableRegistry;

    name = new AtomicReference<>();
    position = new AtomicReference<>(new Position(0D, 0D));
}
 
Example #18
Source File: TestStandardProcessScheduler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testDisableControllerServiceWithProcessorTryingToStartUsingIt() throws InterruptedException, ExecutionException {
    final String uuid = UUID.randomUUID().toString();
    final Processor proc = new ServiceReferencingProcessor();
    proc.initialize(new StandardProcessorInitializationContext(uuid, null, null, null, KerberosConfig.NOT_CONFIGURED));

    final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);

    final ControllerServiceNode service = flowManager.createControllerService(NoStartServiceImpl.class.getName(), "service",
            systemBundle.getBundleDetails().getCoordinate(), null, true, true);

    rootGroup.addControllerService(service);

    final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(proc, systemBundle.getBundleDetails().getCoordinate(), null);
    final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(serviceProvider, variableRegistry);
    final ProcessorNode procNode = new StandardProcessorNode(loggableComponent, uuid, validationContextFactory, scheduler,
        serviceProvider, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent, extensionManager, new SynchronousValidationTrigger());

    rootGroup.addProcessor(procNode);

    Map<String, String> procProps = new HashMap<>();
    procProps.put(ServiceReferencingProcessor.SERVICE_DESC.getName(), service.getIdentifier());
    procNode.setProperties(procProps);

    service.performValidation();
    scheduler.enableControllerService(service);

    procNode.performValidation();
    scheduler.startProcessor(procNode, true);

    Thread.sleep(25L);

    scheduler.stopProcessor(procNode);
    assertTrue(service.isActive());
    assertSame(service.getState(), ControllerServiceState.ENABLING);
    scheduler.disableControllerService(service).get();
    assertFalse(service.isActive());
    assertSame(service.getState(), ControllerServiceState.DISABLED);
}
 
Example #19
Source File: StatelessProcessContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
public StatelessProcessContext(final ConfigurableComponent component, final StatelessControllerServiceLookup lookup, final String componentName,
                               final SLF4JComponentLog logger, final StateManager stateManager, final VariableRegistry variableRegistry, final ParameterContext parameterContext) {
    this.component = Objects.requireNonNull(component);
    this.componentName = componentName == null ? "" : componentName;
    this.inputRequirement = component.getClass().getAnnotation(InputRequirement.class);
    this.lookup = lookup;
    this.stateManager = stateManager;
    this.variableRegistry = variableRegistry;
    this.identifier = component.getIdentifier();
    this.logger = logger;
    this.parameterContext = parameterContext;
}
 
Example #20
Source File: StandardControllerServiceNode.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public StandardControllerServiceNode(final ControllerService proxiedControllerService, final ControllerService implementation, final String id,
                                     final ValidationContextFactory validationContextFactory, final ControllerServiceProvider serviceProvider,
                                     final VariableRegistry variableRegistry, final ComponentLog logger) {

    this(proxiedControllerService, implementation, id, validationContextFactory, serviceProvider,
        implementation.getClass().getSimpleName(), implementation.getClass().getCanonicalName(), variableRegistry, logger);
}
 
Example #21
Source File: StandardConfigurationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
public StandardConfigurationContext(final ComponentNode component, final ControllerServiceLookup serviceLookup, final String schedulingPeriod,
                                    final VariableRegistry variableRegistry) {
    this.component = component;
    this.serviceLookup = serviceLookup;
    this.schedulingPeriod = schedulingPeriod;
    this.variableRegistry = variableRegistry;

    if (schedulingPeriod == null) {
        schedulingNanos = null;
    } else {
        if (FormatUtils.TIME_DURATION_PATTERN.matcher(schedulingPeriod).matches()) {
            schedulingNanos = FormatUtils.getTimeDuration(schedulingPeriod, TimeUnit.NANOSECONDS);
        } else {
            schedulingNanos = null;
        }
    }

    preparedQueries = new HashMap<>();
    for (final Map.Entry<PropertyDescriptor, String> entry : component.getEffectivePropertyValues().entrySet()) {
        final PropertyDescriptor desc = entry.getKey();
        String value = entry.getValue();
        if (value == null) {
            value = desc.getDefaultValue();
        }

        final PreparedQuery pq = Query.prepare(value);
        preparedQueries.put(desc, pq);
    }
}
 
Example #22
Source File: FlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static FlowController createStandaloneInstance(
        final FlowFileEventRepository flowFileEventRepo,
        final NiFiProperties properties,
        final Authorizer authorizer,
        final AuditService auditService,
        final StringEncryptor encryptor,
        final BulletinRepository bulletinRepo,
        final VariableRegistry variableRegistry,
        final FlowRegistryClient flowRegistryClient,
        final ExtensionManager extensionManager) {

    return new FlowController(
            flowFileEventRepo,
            properties,
            authorizer,
            auditService,
            encryptor,
            /* configuredForClustering */ false,
            /* NodeProtocolSender */ null,
            bulletinRepo,
            /* cluster coordinator */ null,
            /* heartbeat monitor */ null,
            /* leader election manager */ null,
            /* variable registry */ variableRegistry,
            flowRegistryClient,
            extensionManager);
}
 
Example #23
Source File: TestStandardControllerServiceProvider.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private ProcessorNode createProcessor(final StandardProcessScheduler scheduler, final ControllerServiceProvider serviceProvider) {
    final ProcessorNode procNode = new StandardProcessorNode(new DummyProcessor(), UUID.randomUUID().toString(),
            new StandardValidationContextFactory(serviceProvider, null), scheduler, serviceProvider,
            NiFiProperties.createBasicNiFiProperties(null, null),
            VariableRegistry.EMPTY_REGISTRY, Mockito.mock(ComponentLog.class));

    final ProcessGroup group = new StandardProcessGroup(UUID.randomUUID().toString(), serviceProvider, scheduler, null, null, null, variableRegistry);
    group.addProcessor(procNode);
    procNode.setProcessGroup(group);

    return procNode;
}
 
Example #24
Source File: TestFileBasedVariableRegistry.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateCustomVariableRegistry() {
    final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties");
    final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties");
    Path[] paths = {fooPath, testPath};
    final String vendorUrl = System.getProperty("java.vendor.url");
    VariableRegistry variableRegistry = new FileBasedVariableRegistry(paths);
    final Map<VariableDescriptor, String> variables = variableRegistry.getVariableMap();
    assertTrue(variables.containsKey(new VariableDescriptor("fake.property.3")));
    assertEquals(vendorUrl, variableRegistry.getVariableValue("java.vendor.url"));
    assertEquals("test me out 3, test me out 4", variableRegistry.getVariableValue("fake.property.3"));
}
 
Example #25
Source File: FileBasedVariableRegistry.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
public FileBasedVariableRegistry(final Path[] propertiesPaths) {
    final Map<VariableDescriptor, String> newMap = new HashMap<>(VariableRegistry.ENVIRONMENT_SYSTEM_REGISTRY.getVariableMap());
    final int systemEnvPropCount = newMap.size();
    int totalPropertiesLoaded = systemEnvPropCount;
    LOG.info("Loaded {} properties from system properties and environment variables",systemEnvPropCount);
    try {
        for (final Path path : propertiesPaths) {
            if (Files.exists(path)) {
                final AtomicInteger propsLoaded = new AtomicInteger(0);
                try (final InputStream inStream = new BufferedInputStream(new FileInputStream(path.toFile()))) {
                    Properties properties = new Properties();
                    properties.load(inStream);
                    properties.entrySet().stream().forEach((entry) -> {
                        final VariableDescriptor desc = new VariableDescriptor.Builder(entry.getKey().toString())
                                .description(path.toString())
                                .sensitive(false)
                                .build();
                        newMap.put(desc, entry.getValue().toString());
                        propsLoaded.incrementAndGet();
                    });
                }
                totalPropertiesLoaded += propsLoaded.get();
                if(propsLoaded.get() > 0){
                    LOG.info("Loaded {} properties from '{}'", propsLoaded.get(), path);
                }else{
                    LOG.warn("No properties loaded from '{}'", path);
                }
            } else {
                LOG.warn("Skipping property file {} as it does not appear to exist", path);
            }
        }
    } catch (final IOException ioe) {
        LOG.error("Unable to complete variable registry loading from files due to ", ioe);
    }
    LOG.info("Loaded a total of {} properties.  Including precedence overrides effective accessible registry key size is {}", totalPropertiesLoaded, newMap.size());
    map = newMap;
}
 
Example #26
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 #27
Source File: StandardFlowSerializerTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    final FlowFileEventRepository flowFileEventRepo = Mockito.mock(FlowFileEventRepository.class);
    final AuditService auditService = Mockito.mock(AuditService.class);
    final Map<String, String> otherProps = new HashMap<>();
    otherProps.put(NiFiProperties.PROVENANCE_REPO_IMPLEMENTATION_CLASS, MockProvenanceRepository.class.getName());
    otherProps.put("nifi.remote.input.socket.port", "");
    otherProps.put("nifi.remote.input.secure", "");
    final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(propsFile, otherProps);
    final String algorithm = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_ALGORITHM);
    final String provider = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_PROVIDER);
    final String password = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_KEY);
    final StringEncryptor encryptor = StringEncryptor.createEncryptor(algorithm, provider, password);

    // use the system bundle
    systemBundle = SystemBundle.create(nifiProperties);
    extensionManager = new StandardExtensionDiscoveringManager();
    extensionManager.discoverExtensions(systemBundle, Collections.emptySet());

    final AbstractPolicyBasedAuthorizer authorizer = new MockPolicyBasedAuthorizer();
    final VariableRegistry variableRegistry = new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths());

    final BulletinRepository bulletinRepo = Mockito.mock(BulletinRepository.class);
    controller = FlowController.createStandaloneInstance(flowFileEventRepo, nifiProperties, authorizer,
        auditService, encryptor, bulletinRepo, variableRegistry, Mockito.mock(FlowRegistryClient.class), extensionManager);

    serializer = new StandardFlowSerializer(encryptor);
}
 
Example #28
Source File: MockConfigurationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
public MockConfigurationContext(final ControllerService service,
        final Map<PropertyDescriptor, String> properties,
        final ControllerServiceLookup serviceLookup,
        final VariableRegistry variableRegistry) {
    this.service = service;
    this.properties = properties;
    this.serviceLookup = serviceLookup;
    this.variableRegistry = variableRegistry;
}
 
Example #29
Source File: NotificationServiceManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
NotificationServiceManager(final VariableRegistry variableRegistry){
    this.variableRegistry = variableRegistry;
    notificationExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
        @Override
        public Thread newThread(final Runnable r) {
            final Thread t = Executors.defaultThreadFactory().newThread(r);
            t.setName("Notification Service Dispatcher");
            t.setDaemon(true);
            return t;
        }
    });
}
 
Example #30
Source File: NotificationValidationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
public NotificationValidationContext(final NotificationContext processContext, VariableRegistry variableRegistry) {
    this.context = processContext;

    final Map<PropertyDescriptor, String> properties = processContext.getProperties();
    expressionLanguageSupported = new HashMap<>(properties.size());
    for (final PropertyDescriptor descriptor : properties.keySet()) {
        expressionLanguageSupported.put(descriptor.getName(), descriptor.isExpressionLanguageSupported());
    }
    this.variableRegistry = variableRegistry;
}