Search in sources :

Example 41 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class ZooKeeperStateServer method create.

public static ZooKeeperStateServer create(final NiFiProperties properties) throws IOException, ConfigException {
    final File propsFile = properties.getEmbeddedZooKeeperPropertiesFile();
    if (propsFile == null) {
        return null;
    }
    if (!propsFile.exists() || !propsFile.canRead()) {
        throw new IOException("Cannot create Embedded ZooKeeper Server because the Properties File " + propsFile.getAbsolutePath() + " referenced in nifi.properties does not exist or cannot be read");
    }
    final Properties zkProperties = new Properties();
    try (final InputStream fis = new FileInputStream(propsFile);
        final InputStream bis = new BufferedInputStream(fis)) {
        zkProperties.load(bis);
    }
    return new ZooKeeperStateServer(zkProperties);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 42 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class FileAccessPolicyProviderTest method getNiFiProperties.

private NiFiProperties getNiFiProperties(final Properties properties) {
    final NiFiProperties nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getPropertyKeys()).thenReturn(properties.stringPropertyNames());
    when(nifiProperties.getProperty(anyString())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocationOnMock) throws Throwable {
            return properties.getProperty((String) invocationOnMock.getArguments()[0]);
        }
    });
    return nifiProperties;
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString)

Example 43 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class FileAuthorizerTest method getNiFiProperties.

private NiFiProperties getNiFiProperties(final Properties properties) {
    final NiFiProperties nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getPropertyKeys()).thenReturn(properties.stringPropertyNames());
    when(nifiProperties.getProperty(anyString())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocationOnMock) throws Throwable {
            return properties.getProperty((String) invocationOnMock.getArguments()[0]);
        }
    });
    return nifiProperties;
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString)

Example 44 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class DocGeneratorTest method testProcessorLoadsNarResources.

@Test
public void testProcessorLoadsNarResources() throws IOException, ClassNotFoundException {
    TemporaryFolder temporaryFolder = new TemporaryFolder();
    temporaryFolder.create();
    NiFiProperties properties = loadSpecifiedProperties("/conf/nifi.properties", NiFiProperties.COMPONENT_DOCS_DIRECTORY, temporaryFolder.getRoot().getAbsolutePath());
    final Bundle systemBundle = SystemBundle.create(properties);
    final ExtensionMapping mapping = NarUnpacker.unpackNars(properties, systemBundle);
    NarClassLoaders.getInstance().init(properties.getFrameworkWorkingDirectory(), properties.getExtensionsWorkingDirectory());
    ExtensionManager.discoverExtensions(systemBundle, NarClassLoaders.getInstance().getBundles());
    DocGenerator.generate(properties, mapping);
    final String extensionClassName = "org.apache.nifi.processors.WriteResourceToStream";
    final BundleCoordinate coordinate = mapping.getProcessorNames().get(extensionClassName).stream().findFirst().get();
    final String path = coordinate.getGroup() + "/" + coordinate.getId() + "/" + coordinate.getVersion() + "/" + extensionClassName;
    File processorDirectory = new File(temporaryFolder.getRoot(), path);
    File indexHtml = new File(processorDirectory, "index.html");
    Assert.assertTrue(indexHtml + " should have been generated", indexHtml.exists());
    String generatedHtml = FileUtils.readFileToString(indexHtml);
    Assert.assertNotNull(generatedHtml);
    Assert.assertTrue(generatedHtml.contains("This example processor loads a resource from the nar and writes it to the FlowFile content"));
    Assert.assertTrue(generatedHtml.contains("files that were successfully processed"));
    Assert.assertTrue(generatedHtml.contains("files that were not successfully processed"));
    Assert.assertTrue(generatedHtml.contains("resources"));
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) ExtensionMapping(org.apache.nifi.nar.ExtensionMapping) Bundle(org.apache.nifi.bundle.Bundle) SystemBundle(org.apache.nifi.nar.SystemBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) File(java.io.File) Test(org.junit.Test)

Example 45 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class DocGeneratorTest method loadSpecifiedProperties.

private NiFiProperties loadSpecifiedProperties(final String propertiesFile, final String key, final String value) {
    String file = DocGeneratorTest.class.getResource(propertiesFile).getFile();
    System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, file);
    final Properties props = new Properties();
    InputStream inStream = null;
    try {
        inStream = new BufferedInputStream(new FileInputStream(file));
        props.load(inStream);
    } catch (final Exception ex) {
        throw new RuntimeException("Cannot load properties file due to " + ex.getLocalizedMessage(), ex);
    } finally {
        if (null != inStream) {
            try {
                inStream.close();
            } catch (final Exception ex) {
            /**
             * do nothing *
             */
            }
        }
    }
    if (key != null && value != null) {
        props.setProperty(key, value);
    }
    return new NiFiProperties() {

        @Override
        public String getProperty(String key) {
            return props.getProperty(key);
        }

        @Override
        public Set<String> getPropertyKeys() {
            return props.stringPropertyNames();
        }
    };
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Aggregations

NiFiProperties (org.apache.nifi.util.NiFiProperties)98 Test (org.junit.Test)63 HashMap (java.util.HashMap)28 Properties (java.util.Properties)24 File (java.io.File)16 Bundle (org.apache.nifi.bundle.Bundle)13 Matchers.anyString (org.mockito.Matchers.anyString)13 IOException (java.io.IOException)10 HashSet (java.util.HashSet)10 Map (java.util.Map)8 X509Certificate (java.security.cert.X509Certificate)7 Mockito.anyString (org.mockito.Mockito.anyString)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 SystemBundle (org.apache.nifi.nar.SystemBundle)6 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IdentityMapping (org.apache.nifi.authorization.util.IdentityMapping)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4