Search in sources :

Example 1 with StringEncryptor

use of org.apache.nifi.encrypt.StringEncryptor in project nifi by apache.

the class TestFlowController method testSynchronizeFlowWhenExistingMissingComponentsAreDifferent.

@Test
public void testSynchronizeFlowWhenExistingMissingComponentsAreDifferent() throws IOException {
    final StringEncryptor stringEncryptor = StringEncryptor.createEncryptor(nifiProperties);
    final FlowSynchronizer standardFlowSynchronizer = new StandardFlowSynchronizer(stringEncryptor, nifiProperties);
    final ProcessorNode mockProcessorNode = mock(ProcessorNode.class);
    when(mockProcessorNode.getIdentifier()).thenReturn("1");
    when(mockProcessorNode.isExtensionMissing()).thenReturn(true);
    final ControllerServiceNode mockControllerServiceNode = mock(ControllerServiceNode.class);
    when(mockControllerServiceNode.getIdentifier()).thenReturn("2");
    when(mockControllerServiceNode.isExtensionMissing()).thenReturn(true);
    final ReportingTaskNode mockReportingTaskNode = mock(ReportingTaskNode.class);
    when(mockReportingTaskNode.getIdentifier()).thenReturn("3");
    when(mockReportingTaskNode.isExtensionMissing()).thenReturn(true);
    final ProcessGroup mockRootGroup = mock(ProcessGroup.class);
    when(mockRootGroup.findAllProcessors()).thenReturn(Collections.singletonList(mockProcessorNode));
    final SnippetManager mockSnippetManager = mock(SnippetManager.class);
    when(mockSnippetManager.export()).thenReturn(new byte[0]);
    final FlowController mockFlowController = mock(FlowController.class);
    when(mockFlowController.getRootGroup()).thenReturn(mockRootGroup);
    when(mockFlowController.getAllControllerServices()).thenReturn(new HashSet<>(Arrays.asList(mockControllerServiceNode)));
    when(mockFlowController.getAllReportingTasks()).thenReturn(new HashSet<>(Arrays.asList(mockReportingTaskNode)));
    when(mockFlowController.getAuthorizer()).thenReturn(authorizer);
    when(mockFlowController.getSnippetManager()).thenReturn(mockSnippetManager);
    final DataFlow proposedDataFlow = Mockito.mock(DataFlow.class);
    when(proposedDataFlow.getMissingComponents()).thenReturn(new HashSet<>());
    try {
        standardFlowSynchronizer.sync(mockFlowController, proposedDataFlow, stringEncryptor);
        Assert.fail("Should have thrown exception");
    } catch (UninheritableFlowException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("Current flow has missing components that are not considered missing in the proposed flow (1,2,3)"));
    }
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) FlowSynchronizer(org.apache.nifi.controller.serialization.FlowSynchronizer) ProcessGroup(org.apache.nifi.groups.ProcessGroup) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) DataFlow(org.apache.nifi.cluster.protocol.DataFlow) Test(org.junit.Test)

Example 2 with StringEncryptor

use of org.apache.nifi.encrypt.StringEncryptor in project nifi by apache.

the class PopularVoteFlowElectionFactoryBean method getObject.

@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);
}
Also used : FingerprintFactory(org.apache.nifi.fingerprint.FingerprintFactory) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor)

Example 3 with StringEncryptor

use of org.apache.nifi.encrypt.StringEncryptor in project nifi by apache.

the class StandardFlowSerializerTest method setUp.

@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 StringEncryptor encryptor = StringEncryptor.createEncryptor(nifiProperties);
    // use the system bundle
    systemBundle = SystemBundle.create(nifiProperties);
    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));
    serializer = new StandardFlowSerializer(encryptor);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) BulletinRepository(org.apache.nifi.reporting.BulletinRepository) HashMap(java.util.HashMap) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry) VariableRegistry(org.apache.nifi.registry.VariableRegistry) AbstractPolicyBasedAuthorizer(org.apache.nifi.authorization.AbstractPolicyBasedAuthorizer) FlowFileEventRepository(org.apache.nifi.controller.repository.FlowFileEventRepository) MockProvenanceRepository(org.apache.nifi.provenance.MockProvenanceRepository) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) MockPolicyBasedAuthorizer(org.apache.nifi.authorization.MockPolicyBasedAuthorizer) AuditService(org.apache.nifi.admin.service.AuditService) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry) Before(org.junit.Before)

Example 4 with StringEncryptor

use of org.apache.nifi.encrypt.StringEncryptor in project nifi by apache.

the class TestConnectableTask method testIsWorkToDo.

@Test
public void testIsWorkToDo() {
    final ProcessorNode procNode = Mockito.mock(ProcessorNode.class);
    Mockito.when(procNode.hasIncomingConnection()).thenReturn(false);
    final Processor processor = Mockito.mock(Processor.class);
    Mockito.when(procNode.getIdentifier()).thenReturn("123");
    Mockito.when(procNode.getRunnableComponent()).thenReturn(processor);
    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);
    ConnectableTask task = new ConnectableTask(Mockito.mock(SchedulingAgent.class), procNode, flowController, contextFactory, scheduleState, encryptor);
    // There is work to do because there are no incoming connections.
    assertFalse(task.invoke().isYield());
    // Test with only a single connection that is self-looping and empty
    final Connection selfLoopingConnection = Mockito.mock(Connection.class);
    when(selfLoopingConnection.getSource()).thenReturn(procNode);
    when(selfLoopingConnection.getDestination()).thenReturn(procNode);
    when(procNode.hasIncomingConnection()).thenReturn(true);
    when(procNode.getIncomingConnections()).thenReturn(Collections.singletonList(selfLoopingConnection));
    assertFalse(task.invoke().isYield());
    // Test with only a single connection that is self-looping and empty
    final FlowFileQueue flowFileQueue = Mockito.mock(FlowFileQueue.class);
    when(flowFileQueue.isActiveQueueEmpty()).thenReturn(true);
    final FlowFileQueue nonEmptyQueue = Mockito.mock(FlowFileQueue.class);
    when(nonEmptyQueue.isActiveQueueEmpty()).thenReturn(false);
    when(selfLoopingConnection.getFlowFileQueue()).thenReturn(nonEmptyQueue);
    assertFalse(task.invoke().isYield());
    // Test with only a non-looping Connection that has no FlowFiles
    final Connection emptyConnection = Mockito.mock(Connection.class);
    when(emptyConnection.getSource()).thenReturn(Mockito.mock(ProcessorNode.class));
    when(emptyConnection.getDestination()).thenReturn(procNode);
    when(emptyConnection.getFlowFileQueue()).thenReturn(flowFileQueue);
    when(procNode.getIncomingConnections()).thenReturn(Collections.singletonList(emptyConnection));
    // Create a new ConnectableTask because we want to have a different value for the 'hasNonLoopConnection' value, which is calculated in the task's constructor.
    task = new ConnectableTask(Mockito.mock(SchedulingAgent.class), procNode, flowController, contextFactory, scheduleState, encryptor);
    assertTrue(task.invoke().isYield());
    // test when the queue has data
    final Connection nonEmptyConnection = Mockito.mock(Connection.class);
    when(nonEmptyConnection.getSource()).thenReturn(Mockito.mock(ProcessorNode.class));
    when(nonEmptyConnection.getDestination()).thenReturn(procNode);
    when(nonEmptyConnection.getFlowFileQueue()).thenReturn(nonEmptyQueue);
    when(procNode.getIncomingConnections()).thenReturn(Collections.singletonList(nonEmptyConnection));
    assertFalse(task.invoke().isYield());
}
Also used : RepositoryContext(org.apache.nifi.controller.repository.RepositoryContext) Processor(org.apache.nifi.processor.Processor) Connection(org.apache.nifi.connectable.Connection) LifecycleState(org.apache.nifi.controller.scheduling.LifecycleState) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) AtomicLong(java.util.concurrent.atomic.AtomicLong) ProcessorNode(org.apache.nifi.controller.ProcessorNode) FlowFileEventRepository(org.apache.nifi.controller.repository.FlowFileEventRepository) RepositoryContextFactory(org.apache.nifi.controller.scheduling.RepositoryContextFactory) Connectable(org.apache.nifi.connectable.Connectable) FlowController(org.apache.nifi.controller.FlowController) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) SchedulingAgent(org.apache.nifi.controller.scheduling.SchedulingAgent) StateManagerProvider(org.apache.nifi.components.state.StateManagerProvider) Test(org.junit.Test)

Example 5 with StringEncryptor

use of org.apache.nifi.encrypt.StringEncryptor in project nifi by apache.

the class FingerprintFactoryTest method setup.

@Before
public void setup() {
    encryptor = new StringEncryptor("PBEWITHMD5AND256BITAES-CBC-OPENSSL", "BC", "nififtw!");
    fingerprinter = new FingerprintFactory(encryptor);
}
Also used : StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) Before(org.junit.Before)

Aggregations

StringEncryptor (org.apache.nifi.encrypt.StringEncryptor)7 FlowFileEventRepository (org.apache.nifi.controller.repository.FlowFileEventRepository)3 HashMap (java.util.HashMap)2 AuditService (org.apache.nifi.admin.service.AuditService)2 Authorizer (org.apache.nifi.authorization.Authorizer)2 Connectable (org.apache.nifi.connectable.Connectable)2 Connection (org.apache.nifi.connectable.Connection)2 FlowController (org.apache.nifi.controller.FlowController)2 VariableRegistry (org.apache.nifi.registry.VariableRegistry)2 BulletinRepository (org.apache.nifi.reporting.BulletinRepository)2 NiFiProperties (org.apache.nifi.util.NiFiProperties)2 Before (org.junit.Before)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1