Search in sources :

Example 16 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class SSLContextServiceTest method testGoodTrustOnly.

@Test
public void testGoodTrustOnly() {
    try {
        TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
        SSLContextService service = new StandardSSLContextService();
        HashMap<String, String> properties = new HashMap<String, String>();
        properties.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
        properties.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
        properties.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
        runner.addControllerService("test-good2", service, properties);
        runner.enableControllerService(service);
        runner.setProperty("SSL Context Svc ID", "test-good2");
        runner.assertValid();
        Assert.assertNotNull(service);
        assertTrue(service instanceof StandardSSLContextService);
        service.createSSLContext(ClientAuth.NONE);
    } catch (InitializationException e) {
    }
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) InitializationException(org.apache.nifi.reporting.InitializationException) Test(org.junit.Test)

Example 17 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class TestListenTCP method testTLSClientAuthRequiredAndClientCertNotProvided.

@Test
public void testTLSClientAuthRequiredAndClientCertNotProvided() throws InitializationException, IOException, InterruptedException, UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    runner.setProperty(ListenTCP.CLIENT_AUTH, SSLContextService.ClientAuth.REQUIRED.name());
    configureProcessorSslContextService();
    final List<String> messages = new ArrayList<>();
    messages.add("This is message 1\n");
    messages.add("This is message 2\n");
    messages.add("This is message 3\n");
    messages.add("This is message 4\n");
    messages.add("This is message 5\n");
    // Make an SSLContext that only has the trust store, this should not work since the processor has client auth REQUIRED
    final SSLContext clientSslContext = SslContextFactory.createTrustSslContext("src/test/resources/localhost-ts.jks", "localtest".toCharArray(), "jks", "TLS");
    try {
        runTCP(messages, messages.size(), clientSslContext);
        Assert.fail("Should have thrown exception");
    } catch (Exception e) {
    }
}
Also used : ArrayList(java.util.ArrayList) SSLContext(javax.net.ssl.SSLContext) InitializationException(org.apache.nifi.reporting.InitializationException) KeyStoreException(java.security.KeyStoreException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Example 18 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class TestSplitRecord method testMultipleRecordsPerSplit.

@Test
public void testMultipleRecordsPerSplit() throws InitializationException {
    final MockRecordParser readerService = new MockRecordParser();
    final MockRecordWriter writerService = new MockRecordWriter("header", false);
    final TestRunner runner = TestRunners.newTestRunner(SplitRecord.class);
    runner.addControllerService("reader", readerService);
    runner.enableControllerService(readerService);
    runner.addControllerService("writer", writerService);
    runner.enableControllerService(writerService);
    runner.setProperty(SplitRecord.RECORD_READER, "reader");
    runner.setProperty(SplitRecord.RECORD_WRITER, "writer");
    runner.setProperty(SplitRecord.RECORDS_PER_SPLIT, "2");
    readerService.addSchemaField("name", RecordFieldType.STRING);
    readerService.addSchemaField("age", RecordFieldType.INT);
    readerService.addRecord("John Doe", 48);
    readerService.addRecord("Jane Doe", 47);
    readerService.addRecord("Jimmy Doe", 14);
    runner.enqueue("");
    runner.run();
    runner.assertTransferCount(SplitRecord.REL_SPLITS, 2);
    runner.assertTransferCount(SplitRecord.REL_ORIGINAL, 1);
    runner.assertTransferCount(SplitRecord.REL_FAILURE, 0);
    final List<MockFlowFile> out = runner.getFlowFilesForRelationship(SplitRecord.REL_SPLITS);
    assertEquals(1, out.stream().filter(mff -> mff.getAttribute("record.count").equals("1")).count());
    assertTrue(out.stream().allMatch(mff -> mff.getAttribute("mime.type").equals("text/plain")));
    assertEquals(1, out.stream().filter(mff -> mff.isContentEqual("header\nJohn Doe,48\nJane Doe,47\n")).count());
    assertEquals(1, out.stream().filter(mff -> mff.isContentEqual("header\nJimmy Doe,14\n")).count());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser) List(java.util.List) TestRunner(org.apache.nifi.util.TestRunner) InitializationException(org.apache.nifi.reporting.InitializationException) MockRecordWriter(org.apache.nifi.serialization.record.MockRecordWriter) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RecordFieldType(org.apache.nifi.serialization.record.RecordFieldType) TestRunners(org.apache.nifi.util.TestRunners) Assert.assertEquals(org.junit.Assert.assertEquals) MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) MockRecordWriter(org.apache.nifi.serialization.record.MockRecordWriter) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser) Test(org.junit.Test)

Example 19 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class TestPutHBaseRecord method generateTestData.

private void generateTestData(TestRunner runner) throws IOException {
    final MockRecordParser parser = new MockRecordParser();
    try {
        runner.addControllerService("parser", parser);
    } catch (InitializationException e) {
        throw new IOException(e);
    }
    runner.enableControllerService(parser);
    runner.setProperty(PutHBaseRecord.RECORD_READER_FACTORY, "parser");
    parser.addSchemaField("id", RecordFieldType.INT);
    parser.addSchemaField("name", RecordFieldType.STRING);
    parser.addSchemaField("code", RecordFieldType.LONG);
    for (int x = 0; x < KEYS.size(); x++) {
        parser.addRecord(KEYS.get(x), NAMES.get(x), CODES.get(x));
    }
}
Also used : IOException(java.io.IOException) InitializationException(org.apache.nifi.reporting.InitializationException) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser)

Example 20 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class ITListenGRPC method useSSLContextService.

private static void useSSLContextService(final TestRunner controller, final Map<String, String> sslProperties) {
    final SSLContextService service = new StandardSSLContextService();
    try {
        controller.addControllerService("ssl-service", service, sslProperties);
        controller.enableControllerService(service);
    } catch (InitializationException ex) {
        ex.printStackTrace();
        Assert.fail("Could not create SSL Context Service");
    }
    controller.setProperty(InvokeGRPC.PROP_SSL_CONTEXT_SERVICE, "ssl-service");
}
Also used : StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) InitializationException(org.apache.nifi.reporting.InitializationException)

Aggregations

InitializationException (org.apache.nifi.reporting.InitializationException)30 IOException (java.io.IOException)10 OnEnabled (org.apache.nifi.annotation.lifecycle.OnEnabled)7 MalformedURLException (java.net.MalformedURLException)6 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)5 SSLContextService (org.apache.nifi.ssl.SSLContextService)5 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)4 ProcessException (org.apache.nifi.processor.exception.ProcessException)4 StandardSSLContextService (org.apache.nifi.ssl.StandardSSLContextService)4 Test (org.junit.Test)4 ConnectException (java.net.ConnectException)3 KeyManagementException (java.security.KeyManagementException)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 UnrecoverableKeyException (java.security.UnrecoverableKeyException)3 CertificateException (java.security.cert.CertificateException)3 Driver (java.sql.Driver)3 ArrayList (java.util.ArrayList)3 MockRecordParser (org.apache.nifi.serialization.record.MockRecordParser)3