org.apache.nifi.controller.repository.FlowFileEventRepository Java Examples

The following examples show how to use org.apache.nifi.controller.repository.FlowFileEventRepository. 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: StandardFlowServiceTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    properties = NiFiProperties.createBasicNiFiProperties(null);



    variableRegistry = new FileBasedVariableRegistry(properties.getVariableRegistryPropertiesPaths());
    mockFlowFileEventRepository = mock(FlowFileEventRepository.class);
    authorizer = mock(Authorizer.class);
    mockAuditService = mock(AuditService.class);
    revisionManager = mock(RevisionManager.class);
    extensionManager = mock(ExtensionDiscoveringManager.class);
    flowController = FlowController.createStandaloneInstance(mockFlowFileEventRepository, properties, authorizer, mockAuditService, mockEncryptor,
                                    new VolatileBulletinRepository(), variableRegistry, mock(FlowRegistryClient.class), extensionManager);
    flowService = StandardFlowService.createStandaloneInstance(flowController, properties, mockEncryptor, revisionManager, authorizer);
}
 
Example #2
Source File: TestConnectableTask.java    From nifi with 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 #3
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 #4
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private FlowController buildFlowControllerForTest(final String propKey, final String propValue) throws Exception {
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(NiFiProperties.ADMINISTRATIVE_YIELD_DURATION, "1 sec");
    addProps.put(NiFiProperties.STATE_MANAGEMENT_CONFIG_FILE, "target/test-classes/state-management.xml");
    addProps.put(NiFiProperties.STATE_MANAGEMENT_LOCAL_PROVIDER_ID, "local-provider");
    addProps.put(NiFiProperties.PROVENANCE_REPO_IMPLEMENTATION_CLASS, MockProvenanceRepository.class.getName());
    addProps.put("nifi.remote.input.socket.port", "");
    addProps.put("nifi.remote.input.secure", "");
    if (propKey != null && propValue != null) {
        addProps.put(propKey, propValue);
    }
    final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);
    return FlowController.createStandaloneInstance(mock(FlowFileEventRepository.class), nifiProperties,
            mock(Authorizer.class), mock(AuditService.class), null, new VolatileBulletinRepository(),
            new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths()));
}
 
Example #5
Source File: FlowControllerFactoryBean.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObject() throws Exception {
    if (flowController == null) {
        final FlowFileEventRepository flowFileEventRepository = applicationContext.getBean("flowFileEventRepository", FlowFileEventRepository.class);

        if (properties.isNode()) {
            final NodeProtocolSender nodeProtocolSender = applicationContext.getBean("nodeProtocolSender", NodeProtocolSender.class);
            final HeartbeatMonitor heartbeatMonitor = applicationContext.getBean("heartbeatMonitor", HeartbeatMonitor.class);
            flowController = FlowController.createClusteredInstance(
                flowFileEventRepository,
                properties,
                authorizer,
                auditService,
                encryptor,
                nodeProtocolSender,
                bulletinRepository,
                clusterCoordinator,
                heartbeatMonitor,
                leaderElectionManager,
                variableRegistry);
        } else {
            flowController = FlowController.createStandaloneInstance(
                flowFileEventRepository,
                properties,
                authorizer,
                auditService,
                encryptor,
                bulletinRepository, variableRegistry);
        }

    }

    return flowController;
}
 
Example #6
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
private FlowManagerAndSystemBundle buildFlowControllerForTest(final String propKey, final String propValue) throws Exception {
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(NiFiProperties.ADMINISTRATIVE_YIELD_DURATION, "1 sec");
    addProps.put(NiFiProperties.STATE_MANAGEMENT_CONFIG_FILE, "target/test-classes/state-management.xml");
    addProps.put(NiFiProperties.STATE_MANAGEMENT_LOCAL_PROVIDER_ID, "local-provider");
    addProps.put(NiFiProperties.PROVENANCE_REPO_IMPLEMENTATION_CLASS, MockProvenanceRepository.class.getName());
    addProps.put("nifi.remote.input.socket.port", "");
    addProps.put("nifi.remote.input.secure", "");
    if (propKey != null && propValue != null) {
        addProps.put(propKey, propValue);
    }
    final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(propsFile, addProps);

    final Bundle systemBundle = SystemBundle.create(nifiProperties);
    final ExtensionDiscoveringManager extensionManager = new StandardExtensionDiscoveringManager();
    extensionManager.discoverExtensions(systemBundle, Collections.emptySet());

    final FlowController flowController = FlowController.createStandaloneInstance(mock(FlowFileEventRepository.class), nifiProperties,
        mock(Authorizer.class), mock(AuditService.class), null, new VolatileBulletinRepository(),
        new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths()),
        mock(FlowRegistryClient.class), extensionManager);

    final FlowManager flowManager = flowController.getFlowManager();
    this.processScheduler = flowController.getProcessScheduler();

    return new FlowManagerAndSystemBundle(flowManager, systemBundle);
}
 
Example #7
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 #8
Source File: FlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static FlowController createClusteredInstance(
        final FlowFileEventRepository flowFileEventRepo,
        final NiFiProperties properties,
        final Authorizer authorizer,
        final AuditService auditService,
        final StringEncryptor encryptor,
        final NodeProtocolSender protocolSender,
        final BulletinRepository bulletinRepo,
        final ClusterCoordinator clusterCoordinator,
        final HeartbeatMonitor heartbeatMonitor,
        final LeaderElectionManager leaderElectionManager,
        final VariableRegistry variableRegistry,
        final FlowRegistryClient flowRegistryClient,
        final ExtensionManager extensionManager) {

    final FlowController flowController = new FlowController(
            flowFileEventRepo,
            properties,
            authorizer,
            auditService,
            encryptor,
            /* configuredForClustering */ true,
            protocolSender,
            bulletinRepo,
            clusterCoordinator,
            heartbeatMonitor,
            leaderElectionManager,
            variableRegistry,
            flowRegistryClient,
            extensionManager);

    return flowController;
}
 
Example #9
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 #10
Source File: StandardFlowManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
public StandardFlowManager(final NiFiProperties nifiProperties, final SSLContext sslContext, final FlowController flowController,
                           final FlowFileEventRepository flowFileEventRepository, final ParameterContextManager parameterContextManager) {
    this.nifiProperties = nifiProperties;
    this.flowController = flowController;
    this.bulletinRepository = flowController.getBulletinRepository();
    this.processScheduler = flowController.getProcessScheduler();
    this.authorizer = flowController.getAuthorizer();
    this.sslContext = sslContext;
    this.flowFileEventRepository = flowFileEventRepository;
    this.parameterContextManager = parameterContextManager;

    this.isSiteToSiteSecure = Boolean.TRUE.equals(nifiProperties.isSiteToSiteSecure());
}
 
Example #11
Source File: RepositoryContextFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
public RepositoryContextFactory(final ContentRepository contentRepository, final FlowFileRepository flowFileRepository,
        final FlowFileEventRepository flowFileEventRepository, final CounterRepository counterRepository,
        final ProvenanceRepository provenanceRepository) {

    this.contentRepo = contentRepository;
    this.flowFileRepo = flowFileRepository;
    this.flowFileEventRepo = flowFileEventRepository;
    this.counterRepo = counterRepository;
    this.provenanceRepo = provenanceRepository;
}
 
Example #12
Source File: FlowControllerFactoryBean.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Object getObject() throws Exception {
    if (flowController == null) {
        final FlowFileEventRepository flowFileEventRepository = applicationContext.getBean("flowFileEventRepository", FlowFileEventRepository.class);

        if (properties.isNode()) {
            final NodeProtocolSender nodeProtocolSender = applicationContext.getBean("nodeProtocolSender", NodeProtocolSender.class);
            final HeartbeatMonitor heartbeatMonitor = applicationContext.getBean("heartbeatMonitor", HeartbeatMonitor.class);
            flowController = FlowController.createClusteredInstance(
                flowFileEventRepository,
                properties,
                authorizer,
                auditService,
                encryptor,
                nodeProtocolSender,
                bulletinRepository,
                clusterCoordinator,
                heartbeatMonitor,
                leaderElectionManager,
                variableRegistry,
                flowRegistryClient,
                extensionManager);
        } else {
            flowController = FlowController.createStandaloneInstance(
                flowFileEventRepository,
                properties,
                authorizer,
                auditService,
                encryptor,
                bulletinRepository,
                variableRegistry,
                flowRegistryClient,
                extensionManager);
        }

    }

    return flowController;
}
 
Example #13
Source File: StandardFlowServiceTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    properties = NiFiProperties.createBasicNiFiProperties(null, null);
    variableRegistry = new FileBasedVariableRegistry(properties.getVariableRegistryPropertiesPaths());
    mockFlowFileEventRepository = mock(FlowFileEventRepository.class);
    authorizer = mock(Authorizer.class);
    mockAuditService = mock(AuditService.class);
    revisionManager = mock(RevisionManager.class);
    flowController = FlowController.createStandaloneInstance(mockFlowFileEventRepository, properties, authorizer, mockAuditService, mockEncryptor,
                                    new VolatileBulletinRepository(), variableRegistry);
    flowService = StandardFlowService.createStandaloneInstance(flowController, properties, mockEncryptor, revisionManager, authorizer);
}
 
Example #14
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public static FlowController createClusteredInstance(
        final FlowFileEventRepository flowFileEventRepo,
        final NiFiProperties properties,
        final Authorizer authorizer,
        final AuditService auditService,
        final StringEncryptor encryptor,
        final NodeProtocolSender protocolSender,
        final BulletinRepository bulletinRepo,
        final ClusterCoordinator clusterCoordinator,
        final HeartbeatMonitor heartbeatMonitor,
        final LeaderElectionManager leaderElectionManager,
        final VariableRegistry variableRegistry) {

    final FlowController flowController = new FlowController(
            flowFileEventRepo,
            properties,
            authorizer,
            auditService,
            encryptor,
            /* configuredForClustering */ true,
            protocolSender,
            bulletinRepo,
            clusterCoordinator,
            heartbeatMonitor,
            leaderElectionManager,
            variableRegistry);

    return flowController;
}
 
Example #15
Source File: ProcessContextFactory.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public ProcessContextFactory(final ContentRepository contentRepository, final FlowFileRepository flowFileRepository,
        final FlowFileEventRepository flowFileEventRepository, final CounterRepository counterRepository,
        final ProvenanceEventRepository provenanceRepository) {

    this.contentRepo = contentRepository;
    this.flowFileRepo = flowFileRepository;
    this.flowFileEventRepo = flowFileEventRepository;
    this.counterRepo = counterRepository;
    this.provenanceRepo = provenanceRepository;
}
 
Example #16
Source File: MonitorMemoryTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private FlowController buildFlowControllerForTest(final Map<String, String> addProps) throws Exception {
    addProps.put(NiFiProperties.PROVENANCE_REPO_IMPLEMENTATION_CLASS, MockProvenanceRepository.class.getName());
    addProps.put("nifi.remote.input.socket.port", "");
    addProps.put("nifi.remote.input.secure", "");
    final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);

    return FlowController.createStandaloneInstance(
            mock(FlowFileEventRepository.class),
            nifiProperties,
            mock(Authorizer.class),
            mock(AuditService.class),
            null,
            null,
            null);
}
 
Example #17
Source File: StandardEventAccess.java    From nifi with Apache License 2.0 4 votes vote down vote up
public StandardEventAccess(final FlowController flowController, final FlowFileEventRepository flowFileEventRepository) {
    this.flowController = flowController;
    this.flowFileEventRepository = flowFileEventRepository;
    this.statusAnalyticsEngine = flowController.getStatusAnalyticsEngine();
}
 
Example #18
Source File: MiNiFiServer.java    From nifi-minifi with Apache License 2.0 4 votes vote down vote up
public void start() {
    try {
        logger.info("Loading Flow...");

        FlowFileEventRepository flowFileEventRepository = new RingBufferEventRepository(5);
        AuditService auditService = new StandardAuditService();
        Authorizer authorizer = new Authorizer() {
            @Override
            public AuthorizationResult authorize(AuthorizationRequest request) throws AuthorizationAccessException {
                return AuthorizationResult.approved();
            }

            @Override
            public void initialize(AuthorizerInitializationContext initializationContext) throws AuthorizerCreationException {
                // do nothing
            }

            @Override
            public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException {
                // do nothing
            }

            @Override
            public void preDestruction() throws AuthorizerDestructionException {
                // do nothing
            }
        };

        final String sensitivePropAlgorithmVal = props.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_ALGORITHM);
        final String sensitivePropProviderVal = props.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_PROVIDER);
        final String sensitivePropValueNifiPropVar = props.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_KEY, DEFAULT_SENSITIVE_PROPS_KEY);

        StringEncryptor encryptor = StringEncryptor.createEncryptor(sensitivePropAlgorithmVal, sensitivePropProviderVal, sensitivePropValueNifiPropVar);
        VariableRegistry variableRegistry = new FileBasedVariableRegistry(props.getVariableRegistryPropertiesPaths());
        BulletinRepository bulletinRepository = new VolatileBulletinRepository();

        FlowController flowController = FlowController.createStandaloneInstance(
                flowFileEventRepository,
                props,
                authorizer,
                auditService,
                encryptor,
                bulletinRepository,
                variableRegistry,
                new StandardFlowRegistryClient()
                );

        flowService = StandardFlowService.createStandaloneInstance(
                flowController,
                props,
                encryptor,
                null, // revision manager
                authorizer);

        // start and load the flow
        flowService.start();
        flowService.load(null);
        flowController.onFlowInitialized(true);
        flowController.getGroup(flowController.getRootGroupId()).startProcessing();

        this.flowController = flowController;

        logger.info("Flow loaded successfully.");
    } catch (Exception e) {
        // ensure the flow service is terminated
        if (flowService != null && flowService.isRunning()) {
            flowService.stop(false);
        }
        startUpFailure(new Exception("Unable to load flow due to: " + e, e));
    }
}
 
Example #19
Source File: TestFlowController.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, TestFlowController.class.getResource("/nifi.properties").getFile());

    flowFileEventRepo = Mockito.mock(FlowFileEventRepository.class);
    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", "");
    nifiProperties = NiFiProperties.createBasicNiFiProperties(null, otherProps);
    encryptor = StringEncryptor.createEncryptor(nifiProperties);

    User user1 = new User.Builder().identifier("user-id-1").identity("user-1").build();
    User user2 = new User.Builder().identifier("user-id-2").identity("user-2").build();

    Group group1 = new Group.Builder().identifier("group-id-1").name("group-1").addUser(user1.getIdentifier()).build();
    Group group2 = new Group.Builder().identifier("group-id-2").name("group-2").build();

    AccessPolicy policy1 = new AccessPolicy.Builder()
            .identifier("policy-id-1")
            .resource("resource1")
            .action(RequestAction.READ)
            .addUser(user1.getIdentifier())
            .addUser(user2.getIdentifier())
            .build();

    AccessPolicy policy2 = new AccessPolicy.Builder()
            .identifier("policy-id-2")
            .resource("resource2")
            .action(RequestAction.READ)
            .addGroup(group1.getIdentifier())
            .addGroup(group2.getIdentifier())
            .addUser(user1.getIdentifier())
            .addUser(user2.getIdentifier())
            .build();

    Set<Group> groups1 = new LinkedHashSet<>();
    groups1.add(group1);
    groups1.add(group2);

    Set<User> users1 = new LinkedHashSet<>();
    users1.add(user1);
    users1.add(user2);

    Set<AccessPolicy> policies1 = new LinkedHashSet<>();
    policies1.add(policy1);
    policies1.add(policy2);

    authorizer = new MockPolicyBasedAuthorizer(groups1, users1, policies1);
    variableRegistry = new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths());

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

    standardFlowSynchronizer = new StandardFlowSynchronizer(StringEncryptor.createEncryptor(nifiProperties), nifiProperties);
}
 
Example #20
Source File: FrameworkIntegrationTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected final void initialize(final NiFiProperties nifiProperties) throws IOException {
    this.nifiProperties = nifiProperties;

    final FlowFileEventRepository flowFileEventRepository = new RingBufferEventRepository(5);

    final BulletinRepository bulletinRepo = new VolatileBulletinRepository();
    flowEngine = new FlowEngine(4, "unit test flow engine");
    extensionManager = new DirectInjectionExtensionManager();

    extensionManager.injectExtensionType(FlowFileRepository.class, WriteAheadFlowFileRepository.class);
    extensionManager.injectExtensionType(ContentRepository.class, FileSystemRepository.class);
    extensionManager.injectExtensionType(ProvenanceRepository.class, WriteAheadProvenanceRepository.class);
    extensionManager.injectExtensionType(StateProvider.class, WriteAheadLocalStateProvider.class);
    extensionManager.injectExtensionType(ComponentStatusRepository.class, VolatileComponentStatusRepository.class);
    extensionManager.injectExtensionType(FlowFileSwapManager.class, FileSystemSwapManager.class);

    extensionManager.injectExtensionType(Processor.class, BiConsumerProcessor.class);
    extensionManager.injectExtensionType(Processor.class, GenerateProcessor.class);
    extensionManager.injectExtensionType(Processor.class, TerminateOnce.class);
    extensionManager.injectExtensionType(Processor.class, TerminateAll.class);
    extensionManager.injectExtensionType(Processor.class, NopProcessor.class);
    extensionManager.injectExtensionType(Processor.class, UsernamePasswordProcessor.class);

    injectExtensionTypes(extensionManager);
    systemBundle = SystemBundle.create(nifiProperties);
    extensionManager.discoverExtensions(systemBundle, Collections.emptySet());

    final StringEncryptor encryptor = StringEncryptor.createEncryptor("PBEWITHMD5AND256BITAES-CBC-OPENSSL", "BC", "unit-test");
    final Authorizer authorizer = new AlwaysAuthorizedAuthorizer();
    final AuditService auditService = new NopAuditService();

    if (isClusteredTest()) {
        final File zookeeperDir = new File("target/state/zookeeper");
        final File version2Dir =  new File(zookeeperDir, "version-2");

        if (!version2Dir.exists()) {
            assertTrue(version2Dir.mkdirs());
        }

        final File[] children = version2Dir.listFiles();
        if (children != null) {
            for (final File file : children) {
                FileUtils.deleteFile(file, true);
            }
        }

        clusterCoordinator = Mockito.mock(ClusterCoordinator.class);
        final HeartbeatMonitor heartbeatMonitor = Mockito.mock(HeartbeatMonitor.class);
        final NodeProtocolSender protocolSender = Mockito.mock(NodeProtocolSender.class);
        final LeaderElectionManager leaderElectionManager = new CuratorLeaderElectionManager(2, nifiProperties);

        final NodeIdentifier localNodeId = new NodeIdentifier(UUID.randomUUID().toString(), "localhost", 8111, "localhost", 8081,
            "localhost", 8082, "localhost", 8083, 8084, false, Collections.emptySet());
        final NodeIdentifier node2Id = new NodeIdentifier(UUID.randomUUID().toString(), "localhost", 8222, "localhost", 8081,
            "localhost", 8082, "localhost", 8083, 8084, false, Collections.emptySet());

        final Set<NodeIdentifier> nodeIdentifiers = new HashSet<>();
        nodeIdentifiers.add(localNodeId);
        nodeIdentifiers.add(node2Id);
        Mockito.when(clusterCoordinator.getNodeIdentifiers()).thenReturn(nodeIdentifiers);
        Mockito.when(clusterCoordinator.getLocalNodeIdentifier()).thenReturn(localNodeId);

        flowController = FlowController.createClusteredInstance(flowFileEventRepository, nifiProperties, authorizer, auditService, encryptor, protocolSender, bulletinRepo, clusterCoordinator,
            heartbeatMonitor, leaderElectionManager, VariableRegistry.ENVIRONMENT_SYSTEM_REGISTRY, flowRegistryClient, extensionManager);

        flowController.setClustered(true, UUID.randomUUID().toString());
        flowController.setNodeId(localNodeId);

        flowController.setConnectionStatus(new NodeConnectionStatus(localNodeId, NodeConnectionState.CONNECTED));
    } else {
        flowController = FlowController.createStandaloneInstance(flowFileEventRepository, nifiProperties, authorizer, auditService, encryptor, bulletinRepo,
            VariableRegistry.ENVIRONMENT_SYSTEM_REGISTRY, flowRegistryClient, extensionManager);
    }

    processScheduler = new StandardProcessScheduler(flowEngine, flowController, encryptor, flowController.getStateManagerProvider(), nifiProperties);

    final RepositoryContextFactory repositoryContextFactory = flowController.getRepositoryContextFactory();
    final SchedulingAgent timerDrivenSchedulingAgent = new TimerDrivenSchedulingAgent(flowController, flowEngine, repositoryContextFactory, encryptor, nifiProperties);
    processScheduler.setSchedulingAgent(SchedulingStrategy.TIMER_DRIVEN, timerDrivenSchedulingAgent);

    flowFileSwapManager = flowController.createSwapManager();
    resourceClaimManager = flowController.getResourceClaimManager();
}
 
Example #21
Source File: FrameworkIntegrationTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected FlowFileEvent getStatusReport(final ProcessorNode processor) {
    final FlowFileEventRepository repository = getRepositoryContext().getFlowFileEventRepository();
    RepositoryStatusReport statusReport = repository.reportTransferEvents(0L);
    return statusReport.getReportEntry(processor.getIdentifier());
}
 
Example #22
Source File: TestStandardReportingContext.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    flowFileEventRepo = Mockito.mock(FlowFileEventRepository.class);
    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", "");
    nifiProperties = NiFiProperties.createBasicNiFiProperties(propsFile, otherProps);
    final String algorithm = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_ALGORITHM);
    final String provider = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_PROVIDER);
    String password = nifiProperties.getProperty(NiFiProperties.SENSITIVE_PROPS_KEY);
    if (StringUtils.isBlank(password)) {
        password = DEFAULT_SENSITIVE_PROPS_KEY;
    }
    encryptor = StringEncryptor.createEncryptor(algorithm, provider, password);

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

    User user1 = new User.Builder().identifier("user-id-1").identity("user-1").build();
    User user2 = new User.Builder().identifier("user-id-2").identity("user-2").build();

    Group group1 = new Group.Builder().identifier("group-id-1").name("group-1").addUser(user1.getIdentifier()).build();
    Group group2 = new Group.Builder().identifier("group-id-2").name("group-2").build();

    AccessPolicy policy1 = new AccessPolicy.Builder()
            .identifier("policy-id-1")
            .resource("resource1")
            .action(RequestAction.READ)
            .addUser(user1.getIdentifier())
            .addUser(user2.getIdentifier())
            .build();

    AccessPolicy policy2 = new AccessPolicy.Builder()
            .identifier("policy-id-2")
            .resource("resource2")
            .action(RequestAction.READ)
            .addGroup(group1.getIdentifier())
            .addGroup(group2.getIdentifier())
            .addUser(user1.getIdentifier())
            .addUser(user2.getIdentifier())
            .build();

    Set<Group> groups1 = new LinkedHashSet<>();
    groups1.add(group1);
    groups1.add(group2);

    Set<User> users1 = new LinkedHashSet<>();
    users1.add(user1);
    users1.add(user2);

    Set<AccessPolicy> policies1 = new LinkedHashSet<>();
    policies1.add(policy1);
    policies1.add(policy2);

    authorizer = new MockPolicyBasedAuthorizer(groups1, users1, policies1);
    variableRegistry = new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths());
    flowRegistry = Mockito.mock(FlowRegistryClient.class);

    bulletinRepo = Mockito.mock(BulletinRepository.class);
    controller = FlowController.createStandaloneInstance(flowFileEventRepo, nifiProperties, authorizer, auditService, encryptor,
            bulletinRepo, variableRegistry, flowRegistry, extensionManager);
}
 
Example #23
Source File: TestStandardProcessorNode.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testNativeLibLoadedFromDynamicallyModifiesClasspathProperty() throws Exception {
    // GIVEN
    assumeTrue("Test only runs on Mac OS", new OSUtil(){}.isOsMac());

    // Init NiFi
    NarClassLoader narClassLoader = mock(NarClassLoader.class);
    when(narClassLoader.getURLs()).thenReturn(new URL[0]);

    Bundle narBundle = SystemBundle.create(niFiProperties, narClassLoader);

    HashMap<String, String> additionalProperties = new HashMap<>();
    additionalProperties.put(NiFiProperties.ADMINISTRATIVE_YIELD_DURATION, "1 sec");
    additionalProperties.put(NiFiProperties.STATE_MANAGEMENT_CONFIG_FILE, "target/test-classes/state-management.xml");
    additionalProperties.put(NiFiProperties.STATE_MANAGEMENT_LOCAL_PROVIDER_ID, "local-provider");
    additionalProperties.put(NiFiProperties.PROVENANCE_REPO_IMPLEMENTATION_CLASS, MockProvenanceRepository.class.getName());
    additionalProperties.put("nifi.remote.input.socket.port", "");
    additionalProperties.put("nifi.remote.input.secure", "");

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

    final FlowController flowController = FlowController.createStandaloneInstance(mock(FlowFileEventRepository.class), nifiProperties,
            mock(Authorizer.class), mock(AuditService.class), null, new VolatileBulletinRepository(),
            new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths()),
            mock(FlowRegistryClient.class), extensionManager);

    // Init processor
    final PropertyDescriptor classpathProp = new PropertyDescriptor.Builder().name("Classpath Resources")
            .dynamicallyModifiesClasspath(true).addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();

    final ModifiesClasspathProcessor processor = new ModifiesClasspathProcessor(Arrays.asList(classpathProp));
    final String uuid = UUID.randomUUID().toString();

    final ValidationContextFactory validationContextFactory = createValidationContextFactory();
    final ProcessScheduler processScheduler = mock(ProcessScheduler.class);
    final TerminationAwareLogger componentLog = mock(TerminationAwareLogger.class);

    final ReloadComponent reloadComponent = new StandardReloadComponent(flowController);
    ProcessorInitializationContext initContext = new StandardProcessorInitializationContext(uuid, componentLog, null, null, KerberosConfig.NOT_CONFIGURED);
    ((Processor) processor).initialize(initContext);

    final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(processor, narBundle.getBundleDetails().getCoordinate(), componentLog);
    final StandardProcessorNode procNode = new StandardProcessorNode(loggableComponent, uuid, validationContextFactory, processScheduler,
            null, new StandardComponentVariableRegistry(variableRegistry), reloadComponent, extensionManager, new SynchronousValidationTrigger());

    final Map<String, String> properties = new HashMap<>();
    properties.put(classpathProp.getName(), "src/test/resources/native");
    procNode.setProperties(properties);

    try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(extensionManager, procNode.getProcessor().getClass(), procNode.getIdentifier())){
        // Should pass validation
        assertTrue(procNode.computeValidationErrors(procNode.getValidationContext()).isEmpty());

        // WHEN
        String actualLibraryLocation = currentInstanceClassLoaderHolder.get().findLibrary("testjni");

        // THEN
        assertThat(actualLibraryLocation, containsString(currentInstanceClassLoaderHolder.get().getIdentifier()));
    } finally {
        extensionManager.removeInstanceClassLoader(procNode.getIdentifier());
    }
}
 
Example #24
Source File: TestFlowController.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {

    flowFileEventRepo = Mockito.mock(FlowFileEventRepository.class);
    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 String propsFile = "src/test/resources/flowcontrollertest.nifi.properties";
    nifiProperties = NiFiProperties.createBasicNiFiProperties(propsFile, otherProps);
    encryptor = createEncryptorFromProperties(nifiProperties);

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

    User user1 = new User.Builder().identifier("user-id-1").identity("user-1").build();
    User user2 = new User.Builder().identifier("user-id-2").identity("user-2").build();

    Group group1 = new Group.Builder().identifier("group-id-1").name("group-1").addUser(user1.getIdentifier()).build();
    Group group2 = new Group.Builder().identifier("group-id-2").name("group-2").build();

    AccessPolicy policy1 = new AccessPolicy.Builder()
            .identifier("policy-id-1")
            .resource("resource1")
            .action(RequestAction.READ)
            .addUser(user1.getIdentifier())
            .addUser(user2.getIdentifier())
            .build();

    AccessPolicy policy2 = new AccessPolicy.Builder()
            .identifier("policy-id-2")
            .resource("resource2")
            .action(RequestAction.READ)
            .addGroup(group1.getIdentifier())
            .addGroup(group2.getIdentifier())
            .addUser(user1.getIdentifier())
            .addUser(user2.getIdentifier())
            .build();

    Set<Group> groups1 = new LinkedHashSet<>();
    groups1.add(group1);
    groups1.add(group2);

    Set<User> users1 = new LinkedHashSet<>();
    users1.add(user1);
    users1.add(user2);

    Set<AccessPolicy> policies1 = new LinkedHashSet<>();
    policies1.add(policy1);
    policies1.add(policy2);

    authorizer = new MockPolicyBasedAuthorizer(groups1, users1, policies1);
    variableRegistry = new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths());

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