Java Code Examples for org.apache.nifi.encrypt.StringEncryptor

The following examples show how to use org.apache.nifi.encrypt.StringEncryptor. These examples are extracted from open source projects. 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
@Override
public PopularVoteFlowElection getObject() throws Exception {
    final String maxWaitTime = properties.getFlowElectionMaxWaitTime();
    long maxWaitMillis;
    try {
        maxWaitMillis = FormatUtils.getTimeDuration(maxWaitTime, TimeUnit.MILLISECONDS);
    } catch (final Exception e) {
        logger.warn("Failed to parse value of property '{}' as a valid time period. Value was '{}'. Ignoring this value and using the default value of '{}'",
            NiFiProperties.FLOW_ELECTION_MAX_WAIT_TIME, maxWaitTime, NiFiProperties.DEFAULT_FLOW_ELECTION_MAX_WAIT_TIME);
        maxWaitMillis = FormatUtils.getTimeDuration(NiFiProperties.DEFAULT_FLOW_ELECTION_MAX_WAIT_TIME, TimeUnit.MILLISECONDS);
    }

    final Integer maxNodes = properties.getFlowElectionMaxCandidates();

    final StringEncryptor encryptor = StringEncryptor.createEncryptor(properties);
    final FingerprintFactory fingerprintFactory = new FingerprintFactory(encryptor);
    return new PopularVoteFlowElection(maxWaitMillis, TimeUnit.MILLISECONDS, maxNodes, fingerprintFactory);
}
 
Example 2
Source Project: localization_nifi   Source File: Cluster.java    License: Apache License 2.0 6 votes vote down vote up
public Node createNode() {
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(NiFiProperties.ZOOKEEPER_CONNECT_STRING, getZooKeeperConnectString());
    addProps.put(NiFiProperties.CLUSTER_IS_NODE, "true");

    final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties("src/test/resources/conf/nifi.properties", addProps);

    final FingerprintFactory fingerprintFactory = new FingerprintFactory(StringEncryptor.createEncryptor(nifiProperties));
    final FlowElection flowElection = new PopularVoteFlowElection(flowElectionTimeoutMillis, TimeUnit.MILLISECONDS, flowElectionMaxNodes, fingerprintFactory);

    final Node node = new Node(nifiProperties, flowElection);
    node.start();
    nodes.add(node);

    return node;
}
 
Example 3
public StandardXMLFlowConfigurationDAO(final Path flowXml, final StringEncryptor encryptor, final NiFiProperties nifiProperties) throws IOException {
    this.nifiProperties = nifiProperties;
    final File flowXmlFile = flowXml.toFile();
    if (!flowXmlFile.exists()) {
        // createDirectories would throw an exception if the directory exists but is a symbolic link
        if (Files.notExists(flowXml.getParent())) {
            Files.createDirectories(flowXml.getParent());
        }
        Files.createFile(flowXml);
        //TODO: find a better solution. With Windows 7 and Java 7, Files.isWritable(source.getParent()) returns false, even when it should be true.
    } else if (!flowXmlFile.canRead() || !flowXmlFile.canWrite()) {
        throw new IOException(flowXml + " exists but you have insufficient read/write privileges");
    }

    this.flowXmlPath = flowXml;
    this.encryptor = encryptor;

    this.archiveManager = new FlowConfigurationArchiveManager(flowXmlPath, nifiProperties);
}
 
Example 4
Source Project: localization_nifi   Source File: FlowFromDOMFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static ControllerServiceDTO getControllerService(final Element element, final StringEncryptor encryptor) {
    final ControllerServiceDTO dto = new ControllerServiceDTO();

    dto.setId(getString(element, "id"));
    dto.setName(getString(element, "name"));
    dto.setComments(getString(element, "comment"));
    dto.setType(getString(element, "class"));

    final boolean enabled = getBoolean(element, "enabled");
    dto.setState(enabled ? ControllerServiceState.ENABLED.name() : ControllerServiceState.DISABLED.name());

    dto.setProperties(getProperties(element, encryptor));
    dto.setAnnotationData(getString(element, "annotationData"));

    return dto;
}
 
Example 5
Source Project: localization_nifi   Source File: FlowFromDOMFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static ReportingTaskDTO getReportingTask(final Element element, final StringEncryptor encryptor) {
    final ReportingTaskDTO dto = new ReportingTaskDTO();

    dto.setId(getString(element, "id"));
    dto.setName(getString(element, "name"));
    dto.setComments(getString(element, "comment"));
    dto.setType(getString(element, "class"));
    dto.setSchedulingPeriod(getString(element, "schedulingPeriod"));
    dto.setState(getString(element, "scheduledState"));
    dto.setSchedulingStrategy(getString(element, "schedulingStrategy"));

    dto.setProperties(getProperties(element, encryptor));
    dto.setAnnotationData(getString(element, "annotationData"));

    return dto;
}
 
Example 6
Source Project: localization_nifi   Source File: FlowFromDOMFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static RemoteProcessGroupDTO getRemoteProcessGroup(final Element element, final StringEncryptor encryptor) {
    final RemoteProcessGroupDTO dto = new RemoteProcessGroupDTO();
    dto.setId(getString(element, "id"));
    dto.setName(getString(element, "name"));
    dto.setTargetUri(getString(element, "url"));
    dto.setTargetUris(getString(element, "urls"));
    dto.setTransmitting(getBoolean(element, "transmitting"));
    dto.setPosition(getPosition(DomUtils.getChild(element, "position")));
    dto.setCommunicationsTimeout(getString(element, "timeout"));
    dto.setComments(getString(element, "comment"));
    dto.setYieldDuration(getString(element, "yieldPeriod"));
    dto.setTransportProtocol(getString(element, "transportProtocol"));
    dto.setProxyHost(getString(element, "proxyHost"));
    dto.setProxyPort(getOptionalInt(element, "proxyPort"));
    dto.setProxyUser(getString(element, "proxyUser"));
    dto.setLocalNetworkInterface(getString(element, "networkInterface"));

    final String rawPassword = getString(element, "proxyPassword");
    final String proxyPassword = encryptor == null ? rawPassword : decrypt(rawPassword, encryptor);
    dto.setProxyPassword(proxyPassword);

    return dto;
}
 
Example 7
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 8
public StandardProcessScheduler(
        final ControllerServiceProvider controllerServiceProvider,
        final StringEncryptor encryptor,
        final StateManagerProvider stateManagerProvider,
        final VariableRegistry variableRegistry,
        final NiFiProperties nifiProperties
) {
    this.controllerServiceProvider = controllerServiceProvider;
    this.encryptor = encryptor;
    this.stateManagerProvider = stateManagerProvider;
    this.variableRegistry = variableRegistry;

    administrativeYieldDuration = nifiProperties.getAdministrativeYieldDuration();
    administrativeYieldMillis = FormatUtils.getTimeDuration(administrativeYieldDuration, TimeUnit.MILLISECONDS);

    frameworkTaskExecutor = new FlowEngine(4, "Framework Task Thread");
}
 
Example 9
public EventDrivenSchedulingAgent(final FlowEngine flowEngine, final ControllerServiceProvider serviceProvider, final StateManagerProvider stateManagerProvider,
                                  final EventDrivenWorkerQueue workerQueue, final ProcessContextFactory contextFactory, final int maxThreadCount, final StringEncryptor encryptor,
                                  final VariableRegistry variableRegistry) {
    super(flowEngine);
    this.serviceProvider = serviceProvider;
    this.stateManagerProvider = stateManagerProvider;
    this.workerQueue = workerQueue;
    this.contextFactory = contextFactory;
    this.maxThreadCount = new AtomicInteger(maxThreadCount);
    this.encryptor = encryptor;
    this.variableRegistry = variableRegistry;

    for (int i = 0; i < maxThreadCount; i++) {
        final Runnable eventDrivenTask = new EventDrivenTask(workerQueue);
        flowEngine.scheduleWithFixedDelay(eventDrivenTask, 0L, 1L, TimeUnit.NANOSECONDS);
    }
}
 
Example 10
Source Project: localization_nifi   Source File: ControllerServiceLoader.java    License: Apache License 2.0 6 votes vote down vote up
public static Map<ControllerServiceNode, Element> loadControllerServices(final List<Element> serviceElements, final FlowController controller,
                                                                         final ProcessGroup parentGroup, final StringEncryptor encryptor) {

    final Map<ControllerServiceNode, Element> nodeMap = new HashMap<>();
    for (final Element serviceElement : serviceElements) {
        final ControllerServiceNode serviceNode = createControllerService(controller, serviceElement, encryptor);
        if (parentGroup == null) {
            controller.addRootControllerService(serviceNode);
        } else {
            parentGroup.addControllerService(serviceNode);
        }

        // We need to clone the node because it will be used in a separate thread below, and
        // Element is not thread-safe.
        nodeMap.put(serviceNode, (Element) serviceElement.cloneNode(true));
    }
    for (final Map.Entry<ControllerServiceNode, Element> entry : nodeMap.entrySet()) {
        configureControllerService(entry.getKey(), entry.getValue(), encryptor);
    }

    return nodeMap;
}
 
Example 11
Source Project: localization_nifi   Source File: ControllerServiceLoader.java    License: Apache License 2.0 6 votes vote down vote up
public static void enableControllerServices(final Map<ControllerServiceNode, Element> nodeMap, final FlowController controller,
                                            final StringEncryptor encryptor, final boolean autoResumeState) {
    // Start services
    if (autoResumeState) {
        final Set<ControllerServiceNode> nodesToEnable = new HashSet<>();

        for (final ControllerServiceNode node : nodeMap.keySet()) {
            final Element controllerServiceElement = nodeMap.get(node);

            final ControllerServiceDTO dto;
            synchronized (controllerServiceElement.getOwnerDocument()) {
                dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor);
            }

            final ControllerServiceState state = ControllerServiceState.valueOf(dto.getState());
            if (state == ControllerServiceState.ENABLED) {
                nodesToEnable.add(node);
            }
        }

        enableControllerServices(nodesToEnable, controller, autoResumeState);
    }
}
 
Example 12
Source Project: localization_nifi   Source File: FlowController.java    License: 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 13
Source Project: localization_nifi   Source File: StandardProcessContext.java    License: Apache License 2.0 6 votes vote down vote up
public StandardProcessContext(final ProcessorNode processorNode, final ControllerServiceProvider controllerServiceProvider, final StringEncryptor encryptor, final StateManager stateManager,
                              final VariableRegistry variableRegistry) {
    this.procNode = processorNode;
    this.controllerServiceProvider = controllerServiceProvider;
    this.encryptor = encryptor;
    this.stateManager = stateManager;
    this.variableRegistry = variableRegistry;

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

        if (value != null) {
            final PreparedQuery pq = Query.prepare(value);
            preparedQueries.put(desc, pq);
        }
    }
}
 
Example 14
Source Project: nifi   Source File: Cluster.java    License: Apache License 2.0 6 votes vote down vote up
public Node createNode() {
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(NiFiProperties.ZOOKEEPER_CONNECT_STRING, getZooKeeperConnectString());
    addProps.put(NiFiProperties.CLUSTER_IS_NODE, "true");

    final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties("src/test/resources/conf/nifi.properties", addProps);

    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);
    final ExtensionDiscoveringManager extensionManager = new StandardExtensionDiscoveringManager();
    final FingerprintFactory fingerprintFactory = new FingerprintFactory(encryptor, extensionManager);
    final FlowElection flowElection = new PopularVoteFlowElection(flowElectionTimeoutMillis, TimeUnit.MILLISECONDS, flowElectionMaxNodes, fingerprintFactory);

    final Node node = new Node(nifiProperties, extensionManager, flowElection);
    node.start();
    nodes.add(node);

    return node;
}
 
Example 15
Source Project: nifi   Source File: TestConnectableTask.java    License: Apache License 2.0 6 votes vote down vote up
private ConnectableTask createTask(final Connectable connectable) {
    final FlowController flowController = Mockito.mock(FlowController.class);
    Mockito.when(flowController.getStateManagerProvider()).thenReturn(Mockito.mock(StateManagerProvider.class));

    final RepositoryContext repoContext = Mockito.mock(RepositoryContext.class);
    Mockito.when(repoContext.getFlowFileEventRepository()).thenReturn(Mockito.mock(FlowFileEventRepository.class));

    final RepositoryContextFactory contextFactory = Mockito.mock(RepositoryContextFactory.class);
    Mockito.when(contextFactory.newProcessContext(Mockito.any(Connectable.class), Mockito.any(AtomicLong.class))).thenReturn(repoContext);

    final LifecycleState scheduleState = new LifecycleState();
    final StringEncryptor encryptor = Mockito.mock(StringEncryptor.class);

    return new ConnectableTask(Mockito.mock(SchedulingAgent.class), connectable,
            flowController, contextFactory, scheduleState, encryptor);
}
 
Example 16
Source Project: nifi   Source File: FlowFromDOMFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static ReportingTaskDTO getReportingTask(final Element element, final StringEncryptor encryptor, final FlowEncodingVersion flowEncodingVersion) {
    final ReportingTaskDTO dto = new ReportingTaskDTO();

    dto.setId(getString(element, "id"));
    dto.setName(getString(element, "name"));
    dto.setComments(getString(element, "comment"));
    dto.setType(getString(element, "class"));
    dto.setBundle(getBundle(DomUtils.getChild(element, "bundle")));
    dto.setSchedulingPeriod(getString(element, "schedulingPeriod"));
    dto.setState(getString(element, "scheduledState"));
    dto.setSchedulingStrategy(getString(element, "schedulingStrategy"));

    dto.setProperties(getProperties(element, encryptor, flowEncodingVersion));
    dto.setAnnotationData(getString(element, "annotationData"));

    return dto;
}
 
Example 17
Source Project: nifi   Source File: FlowFromDOMFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static RemoteProcessGroupDTO getRemoteProcessGroup(final Element element, final StringEncryptor encryptor) {
    final RemoteProcessGroupDTO dto = new RemoteProcessGroupDTO();
    dto.setId(getString(element, "id"));
    dto.setVersionedComponentId(getString(element, "versionedComponentId"));
    dto.setName(getString(element, "name"));
    dto.setTargetUri(getString(element, "url"));
    dto.setTargetUris(getString(element, "urls"));
    dto.setTransmitting(getBoolean(element, "transmitting"));
    dto.setPosition(getPosition(DomUtils.getChild(element, "position")));
    dto.setCommunicationsTimeout(getString(element, "timeout"));
    dto.setComments(getString(element, "comment"));
    dto.setYieldDuration(getString(element, "yieldPeriod"));
    dto.setTransportProtocol(getString(element, "transportProtocol"));
    dto.setProxyHost(getString(element, "proxyHost"));
    dto.setProxyPort(getOptionalInt(element, "proxyPort"));
    dto.setProxyUser(getString(element, "proxyUser"));
    dto.setLocalNetworkInterface(getString(element, "networkInterface"));

    final String rawPassword = getString(element, "proxyPassword");
    final String proxyPassword = encryptor == null ? rawPassword : decrypt(rawPassword, encryptor);
    dto.setProxyPassword(proxyPassword);

    return dto;
}
 
Example 18
Source Project: nifi   Source File: FlowFromDOMFactory.java    License: Apache License 2.0 6 votes vote down vote up
private static LinkedHashMap<String, String> getProperties(final Element element, final StringEncryptor encryptor, final FlowEncodingVersion flowEncodingVersion) {
    final LinkedHashMap<String, String> properties = new LinkedHashMap<>();
    final List<Element> propertyNodeList = getChildrenByTagName(element, "property");

    final ParameterParser parameterParser = new ExpressionLanguageAwareParameterParser();

    for (final Element propertyElement : propertyNodeList) {
        final String name = getString(propertyElement, "name");

        final String rawPropertyValue = getString(propertyElement, "value");
        final String value = encryptor == null ? rawPropertyValue : decrypt(rawPropertyValue, encryptor);

        if (flowEncodingVersion == null || (flowEncodingVersion.getMajorVersion() <= 1 && flowEncodingVersion.getMinorVersion() < 4)) {
            // Version 1.4 introduced the #{paramName} syntax for referencing parameters. If the version is less than 1.4, we must escpae any
            // #{...} reference that we find.
            final ParameterTokenList parameterTokenList = parameterParser.parseTokens(value);
            final String escaped = parameterTokenList.escape();
            properties.put(name, escaped);
        } else {
            properties.put(name, value);
        }
    }

    return properties;
}
 
Example 19
Source Project: nifi   Source File: StandardFlowSerializer.java    License: Apache License 2.0 6 votes vote down vote up
public static void addReportingTask(final Element element, final ReportingTaskNode taskNode, final StringEncryptor encryptor) {
    final Element taskElement = element.getOwnerDocument().createElement("reportingTask");
    addTextElement(taskElement, "id", taskNode.getIdentifier());
    addTextElement(taskElement, "name", taskNode.getName());
    addTextElement(taskElement, "comment", taskNode.getComments());
    addTextElement(taskElement, "class", taskNode.getCanonicalClassName());

    addBundle(taskElement, taskNode.getBundleCoordinate());

    addTextElement(taskElement, "schedulingPeriod", taskNode.getSchedulingPeriod());
    addTextElement(taskElement, "scheduledState", taskNode.getScheduledState().name());
    addTextElement(taskElement, "schedulingStrategy", taskNode.getSchedulingStrategy().name());

    addConfiguration(taskElement, taskNode.getRawPropertyValues(), taskNode.getAnnotationData(), encryptor);

    element.appendChild(taskElement);
}
 
Example 20
Source Project: nifi   Source File: EventDrivenSchedulingAgent.java    License: Apache License 2.0 6 votes vote down vote up
public EventDrivenSchedulingAgent(final FlowEngine flowEngine, final ControllerServiceProvider serviceProvider, final StateManagerProvider stateManagerProvider,
                                  final EventDrivenWorkerQueue workerQueue, final RepositoryContextFactory contextFactory, final int maxThreadCount,
                                  final StringEncryptor encryptor, final ExtensionManager extensionManager) {
    super(flowEngine);
    this.serviceProvider = serviceProvider;
    this.stateManagerProvider = stateManagerProvider;
    this.workerQueue = workerQueue;
    this.contextFactory = contextFactory;
    this.maxThreadCount = new AtomicInteger(maxThreadCount);
    this.encryptor = encryptor;
    this.extensionManager = extensionManager;

    for (int i = 0; i < maxThreadCount; i++) {
        final Runnable eventDrivenTask = new EventDrivenTask(workerQueue, activeThreadCount);
        flowEngine.scheduleWithFixedDelay(eventDrivenTask, 0L, 1L, TimeUnit.NANOSECONDS);
    }
}
 
Example 21
Source Project: nifi   Source File: ConnectableTask.java    License: Apache License 2.0 6 votes vote down vote up
public ConnectableTask(final SchedulingAgent schedulingAgent, final Connectable connectable,
        final FlowController flowController, final RepositoryContextFactory contextFactory, final LifecycleState scheduleState,
        final StringEncryptor encryptor) {

    this.schedulingAgent = schedulingAgent;
    this.connectable = connectable;
    this.scheduleState = scheduleState;
    this.numRelationships = connectable.getRelationships().size();
    this.flowController = flowController;

    final StateManager stateManager = new TaskTerminationAwareStateManager(flowController.getStateManagerProvider().getStateManager(connectable.getIdentifier()), scheduleState::isTerminated);
    if (connectable instanceof ProcessorNode) {
        processContext = new StandardProcessContext((ProcessorNode) connectable, flowController.getControllerServiceProvider(), encryptor, stateManager, scheduleState::isTerminated);
    } else {
        processContext = new ConnectableProcessContext(connectable, encryptor, stateManager);
    }

    repositoryContext = contextFactory.newProcessContext(connectable, new AtomicLong(0L));
}
 
Example 22
Source Project: nifi   Source File: ControllerServiceLoader.java    License: Apache License 2.0 6 votes vote down vote up
public static Map<ControllerServiceNode, Element> loadControllerServices(final List<Element> serviceElements, final FlowController controller,
                                                                         final ProcessGroup parentGroup, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) {

    final Map<ControllerServiceNode, Element> nodeMap = new HashMap<>();
    for (final Element serviceElement : serviceElements) {
        final ControllerServiceNode serviceNode = createControllerService(controller, serviceElement, encryptor, encodingVersion);
        if (parentGroup == null) {
            controller.getFlowManager().addRootControllerService(serviceNode);
        } else {
            parentGroup.addControllerService(serviceNode);
        }

        // We need to clone the node because it will be used in a separate thread below, and
        // Element is not thread-safe.
        nodeMap.put(serviceNode, (Element) serviceElement.cloneNode(true));
    }
    for (final Map.Entry<ControllerServiceNode, Element> entry : nodeMap.entrySet()) {
        configureControllerService(entry.getKey(), entry.getValue(), encryptor, encodingVersion);
    }

    return nodeMap;
}
 
Example 23
Source Project: nifi   Source File: ControllerServiceLoader.java    License: Apache License 2.0 6 votes vote down vote up
private static ControllerServiceNode createControllerService(final FlowController flowController, final Element controllerServiceElement, final StringEncryptor encryptor,
                                                             final FlowEncodingVersion encodingVersion) {
    final ControllerServiceDTO dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor, encodingVersion);

    BundleCoordinate coordinate;
    try {
        coordinate = BundleUtils.getCompatibleBundle(flowController.getExtensionManager(), dto.getType(), dto.getBundle());
    } catch (final IllegalStateException e) {
        final BundleDTO bundleDTO = dto.getBundle();
        if (bundleDTO == null) {
            coordinate = BundleCoordinate.UNKNOWN_COORDINATE;
        } else {
            coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion());
        }
    }

    final ControllerServiceNode node = flowController.getFlowManager().createControllerService(dto.getType(), dto.getId(), coordinate, Collections.emptySet(), false, true);
    node.setName(dto.getName());
    node.setComments(dto.getComments());
    node.setVersionedComponentId(dto.getVersionedComponentId());
    return node;
}
 
Example 24
Source Project: nifi   Source File: StandardProcessContext.java    License: Apache License 2.0 6 votes vote down vote up
public StandardProcessContext(final ProcessorNode processorNode, final ControllerServiceProvider controllerServiceProvider, final StringEncryptor encryptor, final StateManager stateManager,
                              final TaskTermination taskTermination) {
    this.procNode = processorNode;
    this.controllerServiceProvider = controllerServiceProvider;
    this.encryptor = encryptor;
    this.stateManager = stateManager;
    this.taskTermination = taskTermination;

    properties = Collections.unmodifiableMap(processorNode.getEffectivePropertyValues());

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

        if (value != null) {
            final PreparedQuery pq = Query.prepare(value);
            preparedQueries.put(desc, pq);
        }
    }
}
 
Example 25
Source Project: localization_nifi   Source File: StandardProcessGroup.java    License: 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 26
Source Project: localization_nifi   Source File: FlowFromDOMFactory.java    License: Apache License 2.0 5 votes vote down vote up
private static LinkedHashMap<String, String> getProperties(final Element element, final StringEncryptor encryptor) {
    final LinkedHashMap<String, String> properties = new LinkedHashMap<>();
    final List<Element> propertyNodeList = getChildrenByTagName(element, "property");
    for (final Element propertyElement : propertyNodeList) {
        final String name = getString(propertyElement, "name");

        final String rawPropertyValue = getString(propertyElement, "value");
        final String value = encryptor == null ? rawPropertyValue : decrypt(rawPropertyValue, encryptor);
        properties.put(name, value);
    }
    return properties;
}
 
Example 27
Source Project: nifi   Source File: FingerprintFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
private <T> Element serializeElement(final StringEncryptor encryptor, final Class<T> componentClass, final T component,
                                     final String serializerMethodName, ScheduledStateLookup scheduledStateLookup) throws Exception {

    final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    final Document doc = docBuilder.newDocument();

    final FlowSerializer flowSerializer = new StandardFlowSerializer(encryptor);
    final Method serializeMethod = StandardFlowSerializer.class.getDeclaredMethod(serializerMethodName,
            Element.class, componentClass, ScheduledStateLookup.class);
    serializeMethod.setAccessible(true);
    final Element rootElement = doc.createElement("root");
    serializeMethod.invoke(flowSerializer, rootElement, component, scheduledStateLookup);
    return rootElement;
}
 
Example 28
Source Project: localization_nifi   Source File: StandardFlowSerializer.java    License: Apache License 2.0 5 votes vote down vote up
private static void addConfiguration(final Element element, final Map<PropertyDescriptor, String> properties, final String annotationData, final StringEncryptor encryptor) {
    final Document doc = element.getOwnerDocument();
    for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) {
        final PropertyDescriptor descriptor = entry.getKey();
        String value = entry.getValue();

        if (value != null && descriptor.isSensitive()) {
            value = ENC_PREFIX + encryptor.encrypt(value) + ENC_SUFFIX;
        }

        if (value == null) {
            value = descriptor.getDefaultValue();
        }

        final Element propElement = doc.createElement("property");
        addTextElement(propElement, "name", descriptor.getName());
        if (value != null) {
            addTextElement(propElement, "value", value);
        }

        element.appendChild(propElement);
    }

    if (annotationData != null) {
        addTextElement(element, "annotationData", annotationData);
    }
}
 
Example 29
Source Project: localization_nifi   Source File: QuartzSchedulingAgent.java    License: Apache License 2.0 5 votes vote down vote up
public QuartzSchedulingAgent(final FlowController flowController, final FlowEngine flowEngine, final ProcessContextFactory contextFactory, final StringEncryptor enryptor,
                             final VariableRegistry variableRegistry) {
    super(flowEngine);
    this.flowController = flowController;
    this.contextFactory = contextFactory;
    this.encryptor = enryptor;
    this.variableRegistry = variableRegistry;
}
 
Example 30
Source Project: localization_nifi   Source File: ControllerServiceLoader.java    License: Apache License 2.0 5 votes vote down vote up
private static ControllerServiceNode createControllerService(final ControllerServiceProvider provider, final Element controllerServiceElement, final StringEncryptor encryptor) {
    final ControllerServiceDTO dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor);

    final ControllerServiceNode node = provider.createControllerService(dto.getType(), dto.getId(), false);
    node.setName(dto.getName());
    node.setComments(dto.getComments());
    return node;
}