mirror of https://github.com/apache/nifi.git
fixing formatting issues for NIFI-433
This commit is contained in:
parent
054f044fc5
commit
ba4a8937f8
|
@ -233,21 +233,27 @@ public class NiFiProperties extends Properties {
|
|||
* obtained.
|
||||
*
|
||||
* @return the NiFiProperties object to use
|
||||
* @throws RuntimeException if unable to load properties file
|
||||
* @throws RuntimeException
|
||||
* if unable to load properties file
|
||||
*/
|
||||
public static synchronized NiFiProperties getInstance() {
|
||||
if (null == instance) {
|
||||
final NiFiProperties suspectInstance = new NiFiProperties();
|
||||
final String nfPropertiesFilePath = System.getProperty(NiFiProperties.PROPERTIES_FILE_PATH);
|
||||
final String nfPropertiesFilePath = System
|
||||
.getProperty(NiFiProperties.PROPERTIES_FILE_PATH);
|
||||
if (null == nfPropertiesFilePath || nfPropertiesFilePath.trim().length() == 0) {
|
||||
throw new RuntimeException("Requires a system property called \'" + NiFiProperties.PROPERTIES_FILE_PATH + "\' and this is not set or has no value");
|
||||
throw new RuntimeException("Requires a system property called \'"
|
||||
+ NiFiProperties.PROPERTIES_FILE_PATH
|
||||
+ "\' and this is not set or has no value");
|
||||
}
|
||||
final File propertiesFile = new File(nfPropertiesFilePath);
|
||||
if (!propertiesFile.exists()) {
|
||||
throw new RuntimeException("Properties file doesn't exist \'" + propertiesFile.getAbsolutePath() + "\'");
|
||||
throw new RuntimeException("Properties file doesn't exist \'"
|
||||
+ propertiesFile.getAbsolutePath() + "\'");
|
||||
}
|
||||
if (!propertiesFile.canRead()) {
|
||||
throw new RuntimeException("Properties file exists but cannot be read \'" + propertiesFile.getAbsolutePath() + "\'");
|
||||
throw new RuntimeException("Properties file exists but cannot be read \'"
|
||||
+ propertiesFile.getAbsolutePath() + "\'");
|
||||
}
|
||||
InputStream inStream = null;
|
||||
try {
|
||||
|
@ -255,7 +261,8 @@ public class NiFiProperties extends Properties {
|
|||
suspectInstance.load(inStream);
|
||||
} catch (final Exception ex) {
|
||||
LOG.error("Cannot load properties file due to " + ex.getLocalizedMessage());
|
||||
throw new RuntimeException("Cannot load properties file due to " + ex.getLocalizedMessage(), ex);
|
||||
throw new RuntimeException("Cannot load properties file due to "
|
||||
+ ex.getLocalizedMessage(), ex);
|
||||
} finally {
|
||||
if (null != inStream) {
|
||||
try {
|
||||
|
@ -409,7 +416,8 @@ public class NiFiProperties extends Properties {
|
|||
* @return Whether to auto start the processors or not
|
||||
*/
|
||||
public boolean getAutoResumeState() {
|
||||
final String rawAutoResumeState = getProperty(AUTO_RESUME_STATE, DEFAULT_AUTO_RESUME_STATE.toString());
|
||||
final String rawAutoResumeState = getProperty(AUTO_RESUME_STATE,
|
||||
DEFAULT_AUTO_RESUME_STATE.toString());
|
||||
return Boolean.parseBoolean(rawAutoResumeState);
|
||||
}
|
||||
|
||||
|
@ -420,7 +428,8 @@ public class NiFiProperties extends Properties {
|
|||
* @return the number of partitions
|
||||
*/
|
||||
public int getFlowFileRepositoryPartitions() {
|
||||
final String rawProperty = getProperty(FLOWFILE_REPOSITORY_PARTITIONS, DEFAULT_FLOWFILE_REPO_PARTITIONS);
|
||||
final String rawProperty = getProperty(FLOWFILE_REPOSITORY_PARTITIONS,
|
||||
DEFAULT_FLOWFILE_REPO_PARTITIONS);
|
||||
return Integer.parseInt(rawProperty);
|
||||
}
|
||||
|
||||
|
@ -431,7 +440,8 @@ public class NiFiProperties extends Properties {
|
|||
* @return the number of milliseconds between checkpoint events
|
||||
*/
|
||||
public String getFlowFileRepositoryCheckpointInterval() {
|
||||
return getProperty(FLOWFILE_REPOSITORY_CHECKPOINT_INTERVAL, DEFAULT_FLOWFILE_CHECKPOINT_INTERVAL);
|
||||
return getProperty(FLOWFILE_REPOSITORY_CHECKPOINT_INTERVAL,
|
||||
DEFAULT_FLOWFILE_CHECKPOINT_INTERVAL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -473,7 +483,8 @@ public class NiFiProperties extends Properties {
|
|||
}
|
||||
|
||||
public String getUserCredentialCacheDuration() {
|
||||
return getProperty(SECURITY_USER_CREDENTIAL_CACHE_DURATION, DEFAULT_USER_CREDENTIAL_CACHE_DURATION);
|
||||
return getProperty(SECURITY_USER_CREDENTIAL_CACHE_DURATION,
|
||||
DEFAULT_USER_CREDENTIAL_CACHE_DURATION);
|
||||
}
|
||||
|
||||
public boolean getSupportNewAccountRequests() {
|
||||
|
@ -535,7 +546,8 @@ public class NiFiProperties extends Properties {
|
|||
// go through each property
|
||||
for (String propertyName : stringPropertyNames()) {
|
||||
// determine if the property is a nar library path
|
||||
if (StringUtils.startsWith(propertyName, NAR_LIBRARY_DIRECTORY_PREFIX) || NAR_LIBRARY_DIRECTORY.equals(propertyName)) {
|
||||
if (StringUtils.startsWith(propertyName, NAR_LIBRARY_DIRECTORY_PREFIX)
|
||||
|| NAR_LIBRARY_DIRECTORY.equals(propertyName)) {
|
||||
// attempt to resolve the path specified
|
||||
String narLib = getProperty(propertyName);
|
||||
if (!StringUtils.isBlank(narLib)) {
|
||||
|
@ -548,7 +560,6 @@ public class NiFiProperties extends Properties {
|
|||
narLibraryPaths.add(Paths.get(DEFAULT_NAR_LIBRARY_DIR));
|
||||
}
|
||||
|
||||
|
||||
return narLibraryPaths;
|
||||
}
|
||||
|
||||
|
@ -582,7 +593,8 @@ public class NiFiProperties extends Properties {
|
|||
|
||||
// getters for cluster protocol properties //
|
||||
public String getClusterProtocolHeartbeatInterval() {
|
||||
return getProperty(CLUSTER_PROTOCOL_HEARTBEAT_INTERVAL, DEFAULT_CLUSTER_PROTOCOL_HEARTBEAT_INTERVAL);
|
||||
return getProperty(CLUSTER_PROTOCOL_HEARTBEAT_INTERVAL,
|
||||
DEFAULT_CLUSTER_PROTOCOL_HEARTBEAT_INTERVAL);
|
||||
}
|
||||
|
||||
public String getNodeHeartbeatInterval() {
|
||||
|
@ -594,7 +606,8 @@ public class NiFiProperties extends Properties {
|
|||
}
|
||||
|
||||
public String getClusterProtocolConnectionHandshakeTimeout() {
|
||||
return getProperty(CLUSTER_PROTOCOL_CONNECTION_HANDSHAKE_TIMEOUT, DEFAULT_CLUSTER_PROTOCOL_CONNECTION_HANDSHAKE_TIMEOUT);
|
||||
return getProperty(CLUSTER_PROTOCOL_CONNECTION_HANDSHAKE_TIMEOUT,
|
||||
DEFAULT_CLUSTER_PROTOCOL_CONNECTION_HANDSHAKE_TIMEOUT);
|
||||
}
|
||||
|
||||
public boolean getClusterProtocolUseMulticast() {
|
||||
|
@ -616,7 +629,8 @@ public class NiFiProperties extends Properties {
|
|||
}
|
||||
|
||||
public File getPersistentStateDirectory() {
|
||||
final String dirName = getProperty(PERSISTENT_STATE_DIRECTORY, DEFAULT_PERSISTENT_STATE_DIRECTORY);
|
||||
final String dirName = getProperty(PERSISTENT_STATE_DIRECTORY,
|
||||
DEFAULT_PERSISTENT_STATE_DIRECTORY);
|
||||
final File file = new File(dirName);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
|
@ -626,14 +640,16 @@ public class NiFiProperties extends Properties {
|
|||
|
||||
public int getClusterProtocolMulticastServiceLocatorAttempts() {
|
||||
try {
|
||||
return Integer.parseInt(getProperty(CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS));
|
||||
return Integer
|
||||
.parseInt(getProperty(CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS));
|
||||
} catch (NumberFormatException nfe) {
|
||||
return DEFAULT_CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS;
|
||||
}
|
||||
}
|
||||
|
||||
public String getClusterProtocolMulticastServiceLocatorAttemptsDelay() {
|
||||
return getProperty(CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS_DELAY, DEFAULT_CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS_DELAY);
|
||||
return getProperty(CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS_DELAY,
|
||||
DEFAULT_CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS_DELAY);
|
||||
}
|
||||
|
||||
// getters for cluster node properties //
|
||||
|
@ -676,7 +692,8 @@ public class NiFiProperties extends Properties {
|
|||
if (StringUtils.isBlank(socketAddress)) {
|
||||
socketAddress = "localhost";
|
||||
}
|
||||
int socketPort = Integer.parseInt(getProperty(CLUSTER_NODE_UNICAST_MANAGER_PROTOCOL_PORT));
|
||||
int socketPort = Integer
|
||||
.parseInt(getProperty(CLUSTER_NODE_UNICAST_MANAGER_PROTOCOL_PORT));
|
||||
return InetSocketAddress.createUnresolved(socketAddress, socketPort);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Invalid unicast manager address/port due to: " + ex, ex);
|
||||
|
@ -727,11 +744,13 @@ public class NiFiProperties extends Properties {
|
|||
}
|
||||
|
||||
public String getClusterManagerNodeApiConnectionTimeout() {
|
||||
return getProperty(CLUSTER_MANAGER_NODE_API_CONNECTION_TIMEOUT, DEFAULT_CLUSTER_MANAGER_NODE_API_CONNECTION_TIMEOUT);
|
||||
return getProperty(CLUSTER_MANAGER_NODE_API_CONNECTION_TIMEOUT,
|
||||
DEFAULT_CLUSTER_MANAGER_NODE_API_CONNECTION_TIMEOUT);
|
||||
}
|
||||
|
||||
public String getClusterManagerNodeApiReadTimeout() {
|
||||
return getProperty(CLUSTER_MANAGER_NODE_API_READ_TIMEOUT, DEFAULT_CLUSTER_MANAGER_NODE_API_READ_TIMEOUT);
|
||||
return getProperty(CLUSTER_MANAGER_NODE_API_READ_TIMEOUT,
|
||||
DEFAULT_CLUSTER_MANAGER_NODE_API_READ_TIMEOUT);
|
||||
}
|
||||
|
||||
public int getClusterManagerNodeApiRequestThreads() {
|
||||
|
@ -743,7 +762,8 @@ public class NiFiProperties extends Properties {
|
|||
}
|
||||
|
||||
public String getClusterManagerFlowRetrievalDelay() {
|
||||
return getProperty(CLUSTER_MANAGER_FLOW_RETRIEVAL_DELAY, DEFAULT_CLUSTER_MANAGER_FLOW_RETRIEVAL_DELAY);
|
||||
return getProperty(CLUSTER_MANAGER_FLOW_RETRIEVAL_DELAY,
|
||||
DEFAULT_CLUSTER_MANAGER_FLOW_RETRIEVAL_DELAY);
|
||||
}
|
||||
|
||||
public int getClusterManagerProtocolThreads() {
|
||||
|
@ -755,7 +775,8 @@ public class NiFiProperties extends Properties {
|
|||
}
|
||||
|
||||
public String getClusterManagerSafeModeDuration() {
|
||||
return getProperty(CLUSTER_MANAGER_SAFEMODE_DURATION, DEFAULT_CLUSTER_MANAGER_SAFEMODE_DURATION);
|
||||
return getProperty(CLUSTER_MANAGER_SAFEMODE_DURATION,
|
||||
DEFAULT_CLUSTER_MANAGER_SAFEMODE_DURATION);
|
||||
}
|
||||
|
||||
public String getClusterProtocolManagerToNodeApiScheme() {
|
||||
|
@ -803,7 +824,8 @@ public class NiFiProperties extends Properties {
|
|||
* configured. No directories will be created as a result of this operation.
|
||||
*
|
||||
* @return database repository path
|
||||
* @throws InvalidPathException If the configured path is invalid
|
||||
* @throws InvalidPathException
|
||||
* If the configured path is invalid
|
||||
*/
|
||||
public Path getDatabaseRepositoryPath() {
|
||||
return Paths.get(getProperty(REPOSITORY_DATABASE_DIRECTORY));
|
||||
|
@ -814,7 +836,8 @@ public class NiFiProperties extends Properties {
|
|||
* configured. No directories will be created as a result of this operation.
|
||||
*
|
||||
* @return database repository path
|
||||
* @throws InvalidPathException If the configured path is invalid
|
||||
* @throws InvalidPathException
|
||||
* If the configured path is invalid
|
||||
*/
|
||||
public Path getFlowFileRepositoryPath() {
|
||||
return Paths.get(getProperty(FLOWFILE_REPOSITORY_DIRECTORY));
|
||||
|
@ -827,7 +850,8 @@ public class NiFiProperties extends Properties {
|
|||
* operation.
|
||||
*
|
||||
* @return file repositories paths
|
||||
* @throws InvalidPathException If any of the configured paths are invalid
|
||||
* @throws InvalidPathException
|
||||
* If any of the configured paths are invalid
|
||||
*/
|
||||
public Map<String, Path> getContentRepositoryPaths() {
|
||||
final Map<String, Path> contentRepositoryPaths = new HashMap<>();
|
||||
|
@ -837,7 +861,8 @@ public class NiFiProperties extends Properties {
|
|||
// determine if the property is a file repository path
|
||||
if (StringUtils.startsWith(propertyName, REPOSITORY_CONTENT_PREFIX)) {
|
||||
// get the repository key
|
||||
final String key = StringUtils.substringAfter(propertyName, REPOSITORY_CONTENT_PREFIX);
|
||||
final String key = StringUtils.substringAfter(propertyName,
|
||||
REPOSITORY_CONTENT_PREFIX);
|
||||
|
||||
// attempt to resolve the path specified
|
||||
contentRepositoryPaths.put(key, Paths.get(getProperty(propertyName)));
|
||||
|
@ -862,7 +887,8 @@ public class NiFiProperties extends Properties {
|
|||
// determine if the property is a file repository path
|
||||
if (StringUtils.startsWith(propertyName, PROVENANCE_REPO_DIRECTORY_PREFIX)) {
|
||||
// get the repository key
|
||||
final String key = StringUtils.substringAfter(propertyName, PROVENANCE_REPO_DIRECTORY_PREFIX);
|
||||
final String key = StringUtils.substringAfter(propertyName,
|
||||
PROVENANCE_REPO_DIRECTORY_PREFIX);
|
||||
|
||||
// attempt to resolve the path specified
|
||||
provenanceRepositoryPaths.put(key, Paths.get(getProperty(propertyName)));
|
||||
|
|
|
@ -22,8 +22,10 @@ public class NiFiPropertiesTest {
|
|||
|
||||
List<Path> directories = properties.getNarLibraryDirectories();
|
||||
|
||||
assertEquals(new File("./target/resources/NiFiProperties/lib/").getPath(), directories.get(0).toString());
|
||||
assertEquals(new File("./target/resources/NiFiProperties/lib2/").getPath(), directories.get(1).toString());
|
||||
assertEquals(new File("./target/resources/NiFiProperties/lib/").getPath(),
|
||||
directories.get(0).toString());
|
||||
assertEquals(new File("./target/resources/NiFiProperties/lib2/").getPath(), directories
|
||||
.get(1).toString());
|
||||
|
||||
}
|
||||
|
||||
|
@ -36,7 +38,8 @@ public class NiFiPropertiesTest {
|
|||
|
||||
assertEquals(1, directories.size());
|
||||
|
||||
assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.get(0).toString());
|
||||
assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.get(0)
|
||||
.toString());
|
||||
|
||||
}
|
||||
|
||||
|
@ -49,7 +52,8 @@ public class NiFiPropertiesTest {
|
|||
|
||||
assertEquals(1, directories.size());
|
||||
|
||||
assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.get(0).toString());
|
||||
assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.get(0)
|
||||
.toString());
|
||||
|
||||
}
|
||||
|
||||
|
@ -71,7 +75,8 @@ public class NiFiPropertiesTest {
|
|||
inStream = new BufferedInputStream(new FileInputStream(file));
|
||||
properties.load(inStream);
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException("Cannot load properties file due to " + ex.getLocalizedMessage(), ex);
|
||||
throw new RuntimeException("Cannot load properties file due to "
|
||||
+ ex.getLocalizedMessage(), ex);
|
||||
} finally {
|
||||
if (null != inStream) {
|
||||
try {
|
||||
|
|
|
@ -88,7 +88,6 @@ public final class NarUnpacker {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (!narFiles.isEmpty()) {
|
||||
for (File narFile : narFiles) {
|
||||
logger.debug("Expanding NAR file: " + narFile.getAbsolutePath());
|
||||
|
@ -104,7 +103,8 @@ public final class NarUnpacker {
|
|||
// determine if this is the framework
|
||||
if (NarClassLoaders.FRAMEWORK_NAR_ID.equals(narId)) {
|
||||
if (unpackedFramework != null) {
|
||||
throw new IllegalStateException("Multiple framework NARs discovered. Only one framework is permitted.");
|
||||
throw new IllegalStateException(
|
||||
"Multiple framework NARs discovered. Only one framework is permitted.");
|
||||
}
|
||||
|
||||
unpackedFramework = unpackNar(narFile, frameworkWorkingDir);
|
||||
|
@ -121,7 +121,8 @@ public final class NarUnpacker {
|
|||
throw new IllegalStateException("Framework NAR cannot be read.");
|
||||
}
|
||||
|
||||
// Determine if any nars no longer exist and delete their working directories. This happens
|
||||
// Determine if any nars no longer exist and delete their
|
||||
// working directories. This happens
|
||||
// if a new version of a nar is dropped into the lib dir.
|
||||
// ensure no old framework are present
|
||||
final File[] frameworkWorkingDirContents = frameworkWorkingDir.listFiles();
|
||||
|
@ -144,7 +145,8 @@ public final class NarUnpacker {
|
|||
}
|
||||
}
|
||||
|
||||
// attempt to delete any docs files that exist so that any components that have been removed
|
||||
// attempt to delete any docs files that exist so that any
|
||||
// components that have been removed
|
||||
// will no longer have entries in the docs folder
|
||||
final File[] docsFiles = docsWorkingDir.listFiles();
|
||||
if (docsFiles != null) {
|
||||
|
@ -157,7 +159,8 @@ public final class NarUnpacker {
|
|||
mapExtensions(extensionsWorkingDir, docsWorkingDir, extensionMapping);
|
||||
return extensionMapping;
|
||||
} catch (IOException e) {
|
||||
logger.warn("Unable to load NAR library bundles due to " + e + " Will proceed without loading any further Nar bundles");
|
||||
logger.warn("Unable to load NAR library bundles due to " + e
|
||||
+ " Will proceed without loading any further Nar bundles");
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.warn("", e);
|
||||
}
|
||||
|
@ -166,7 +169,8 @@ public final class NarUnpacker {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static void mapExtensions(final File workingDirectory, final File docsDirectory, final ExtensionMapping mapping) throws IOException {
|
||||
private static void mapExtensions(final File workingDirectory, final File docsDirectory,
|
||||
final ExtensionMapping mapping) throws IOException {
|
||||
final File[] directoryContents = workingDirectory.listFiles();
|
||||
if (directoryContents != null) {
|
||||
for (final File file : directoryContents) {
|
||||
|
@ -182,19 +186,24 @@ public final class NarUnpacker {
|
|||
/**
|
||||
* Unpacks the specified nar into the specified base working directory.
|
||||
*
|
||||
* @param nar the nar to unpack
|
||||
* @param baseWorkingDirectory the directory to unpack to
|
||||
* @param nar
|
||||
* the nar to unpack
|
||||
* @param baseWorkingDirectory
|
||||
* the directory to unpack to
|
||||
* @return the directory to the unpacked NAR
|
||||
* @throws IOException if unable to explode nar
|
||||
* @throws IOException
|
||||
* if unable to explode nar
|
||||
*/
|
||||
private static File unpackNar(final File nar, final File baseWorkingDirectory) throws IOException {
|
||||
private static File unpackNar(final File nar, final File baseWorkingDirectory)
|
||||
throws IOException {
|
||||
final File narWorkingDirectory = new File(baseWorkingDirectory, nar.getName() + "-unpacked");
|
||||
|
||||
// if the working directory doesn't exist, unpack the nar
|
||||
if (!narWorkingDirectory.exists()) {
|
||||
unpack(nar, narWorkingDirectory, calculateMd5sum(nar));
|
||||
} else {
|
||||
// the working directory does exist. Run MD5 sum against the nar file and check if the nar has changed since it was deployed.
|
||||
// the working directory does exist. Run MD5 sum against the nar
|
||||
// file and check if the nar has changed since it was deployed.
|
||||
final byte[] narMd5 = calculateMd5sum(nar);
|
||||
final File workingHashFile = new File(narWorkingDirectory, HASH_FILENAME);
|
||||
if (!workingHashFile.exists()) {
|
||||
|
@ -203,7 +212,8 @@ public final class NarUnpacker {
|
|||
} else {
|
||||
final byte[] hashFileContents = Files.readAllBytes(workingHashFile.toPath());
|
||||
if (!Arrays.equals(hashFileContents, narMd5)) {
|
||||
logger.info("Contents of nar {} have changed. Reloading.", new Object[]{nar.getAbsolutePath()});
|
||||
logger.info("Contents of nar {} have changed. Reloading.",
|
||||
new Object[] { nar.getAbsolutePath() });
|
||||
FileUtils.deleteFile(narWorkingDirectory, true);
|
||||
unpack(nar, narWorkingDirectory, narMd5);
|
||||
}
|
||||
|
@ -217,11 +227,13 @@ public final class NarUnpacker {
|
|||
* Unpacks the NAR to the specified directory. Creates a checksum file that
|
||||
* used to determine if future expansion is necessary.
|
||||
*
|
||||
* @param workingDirectory the root directory to which the NAR should be
|
||||
* unpacked.
|
||||
* @throws IOException if the NAR could not be unpacked.
|
||||
* @param workingDirectory
|
||||
* the root directory to which the NAR should be unpacked.
|
||||
* @throws IOException
|
||||
* if the NAR could not be unpacked.
|
||||
*/
|
||||
private static void unpack(final File nar, final File workingDirectory, final byte[] hash) throws IOException {
|
||||
private static void unpack(final File nar, final File workingDirectory, final byte[] hash)
|
||||
throws IOException {
|
||||
|
||||
try (JarFile jarFile = new JarFile(nar)) {
|
||||
Enumeration<JarEntry> jarEntries = jarFile.entries();
|
||||
|
@ -243,7 +255,8 @@ public final class NarUnpacker {
|
|||
}
|
||||
}
|
||||
|
||||
private static void unpackDocumentation(final File jar, final File docsDirectory, final ExtensionMapping extensionMapping) throws IOException {
|
||||
private static void unpackDocumentation(final File jar, final File docsDirectory,
|
||||
final ExtensionMapping extensionMapping) throws IOException {
|
||||
// determine the components that may have documentation
|
||||
determineDocumentedNiFiComponents(jar, extensionMapping);
|
||||
|
||||
|
@ -253,7 +266,8 @@ public final class NarUnpacker {
|
|||
final String entryName = "docs/" + componentName;
|
||||
|
||||
// go through each entry in this jar
|
||||
for (final Enumeration<JarEntry> jarEnumeration = jarFile.entries(); jarEnumeration.hasMoreElements();) {
|
||||
for (final Enumeration<JarEntry> jarEnumeration = jarFile.entries(); jarEnumeration
|
||||
.hasMoreElements();) {
|
||||
final JarEntry jarEntry = jarEnumeration.nextElement();
|
||||
|
||||
// if this entry is documentation for this component
|
||||
|
@ -265,8 +279,10 @@ public final class NarUnpacker {
|
|||
final File componentDocsDirectory = new File(docsDirectory, name);
|
||||
|
||||
// ensure the documentation directory can be created
|
||||
if (!componentDocsDirectory.exists() && !componentDocsDirectory.mkdirs()) {
|
||||
logger.warn("Unable to create docs directory " + componentDocsDirectory.getAbsolutePath());
|
||||
if (!componentDocsDirectory.exists()
|
||||
&& !componentDocsDirectory.mkdirs()) {
|
||||
logger.warn("Unable to create docs directory "
|
||||
+ componentDocsDirectory.getAbsolutePath());
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -281,19 +297,27 @@ public final class NarUnpacker {
|
|||
}
|
||||
}
|
||||
|
||||
private static void determineDocumentedNiFiComponents(final File jar, final ExtensionMapping extensionMapping) throws IOException {
|
||||
private static void determineDocumentedNiFiComponents(final File jar,
|
||||
final ExtensionMapping extensionMapping) throws IOException {
|
||||
try (final JarFile jarFile = new JarFile(jar)) {
|
||||
final JarEntry processorEntry = jarFile.getJarEntry("META-INF/services/org.apache.nifi.processor.Processor");
|
||||
final JarEntry reportingTaskEntry = jarFile.getJarEntry("META-INF/services/org.apache.nifi.reporting.ReportingTask");
|
||||
final JarEntry controllerServiceEntry = jarFile.getJarEntry("META-INF/services/org.apache.nifi.controller.ControllerService");
|
||||
final JarEntry processorEntry = jarFile
|
||||
.getJarEntry("META-INF/services/org.apache.nifi.processor.Processor");
|
||||
final JarEntry reportingTaskEntry = jarFile
|
||||
.getJarEntry("META-INF/services/org.apache.nifi.reporting.ReportingTask");
|
||||
final JarEntry controllerServiceEntry = jarFile
|
||||
.getJarEntry("META-INF/services/org.apache.nifi.controller.ControllerService");
|
||||
|
||||
extensionMapping.addAllProcessors(determineDocumentedNiFiComponents(jarFile, processorEntry));
|
||||
extensionMapping.addAllReportingTasks(determineDocumentedNiFiComponents(jarFile, reportingTaskEntry));
|
||||
extensionMapping.addAllControllerServices(determineDocumentedNiFiComponents(jarFile, controllerServiceEntry));
|
||||
extensionMapping.addAllProcessors(determineDocumentedNiFiComponents(jarFile,
|
||||
processorEntry));
|
||||
extensionMapping.addAllReportingTasks(determineDocumentedNiFiComponents(jarFile,
|
||||
reportingTaskEntry));
|
||||
extensionMapping.addAllControllerServices(determineDocumentedNiFiComponents(jarFile,
|
||||
controllerServiceEntry));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> determineDocumentedNiFiComponents(final JarFile jarFile, final JarEntry jarEntry) throws IOException {
|
||||
private static List<String> determineDocumentedNiFiComponents(final JarFile jarFile,
|
||||
final JarEntry jarEntry) throws IOException {
|
||||
final List<String> componentNames = new ArrayList<>();
|
||||
|
||||
if (jarEntry == null) {
|
||||
|
@ -301,13 +325,15 @@ public final class NarUnpacker {
|
|||
}
|
||||
|
||||
try (final InputStream entryInputStream = jarFile.getInputStream(jarEntry);
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(entryInputStream))) {
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
entryInputStream))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
final String trimmedLine = line.trim();
|
||||
if (!trimmedLine.isEmpty() && !trimmedLine.startsWith("#")) {
|
||||
final int indexOfPound = trimmedLine.indexOf("#");
|
||||
final String effectiveLine = (indexOfPound > 0) ? trimmedLine.substring(0, indexOfPound) : trimmedLine;
|
||||
final String effectiveLine = (indexOfPound > 0) ? trimmedLine.substring(0,
|
||||
indexOfPound) : trimmedLine;
|
||||
componentNames.add(effectiveLine);
|
||||
}
|
||||
}
|
||||
|
@ -320,12 +346,16 @@ public final class NarUnpacker {
|
|||
* Creates the specified file, whose contents will come from the
|
||||
* <tt>InputStream</tt>.
|
||||
*
|
||||
* @param inputStream the contents of the file to create.
|
||||
* @param file the file to create.
|
||||
* @throws IOException if the file could not be created.
|
||||
* @param inputStream
|
||||
* the contents of the file to create.
|
||||
* @param file
|
||||
* the file to create.
|
||||
* @throws IOException
|
||||
* if the file could not be created.
|
||||
*/
|
||||
private static void makeFile(final InputStream inputStream, final File file) throws IOException {
|
||||
try (final InputStream in = inputStream; final FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (final InputStream in = inputStream;
|
||||
final FileOutputStream fos = new FileOutputStream(file)) {
|
||||
byte[] bytes = new byte[65536];
|
||||
int numRead;
|
||||
while ((numRead = in.read(bytes)) != -1) {
|
||||
|
@ -337,9 +367,11 @@ public final class NarUnpacker {
|
|||
/**
|
||||
* Calculates an md5 sum of the specified file.
|
||||
*
|
||||
* @param file to calculate the md5sum of
|
||||
* @param file
|
||||
* to calculate the md5sum of
|
||||
* @return the md5sum bytes
|
||||
* @throws IOException if cannot read file
|
||||
* @throws IOException
|
||||
* if cannot read file
|
||||
*/
|
||||
private static byte[] calculateMd5sum(final File file) throws IOException {
|
||||
try (final FileInputStream inputStream = new FileInputStream(file)) {
|
||||
|
|
|
@ -32,7 +32,8 @@ public class NarUnpackerTest {
|
|||
Files.walkFileTree(sourcePath, new SimpleFileVisitor<Path>() {
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
|
||||
throws IOException {
|
||||
|
||||
Path relativeSource = sourcePath.relativize(dir);
|
||||
Path target = targetPath.resolve(relativeSource);
|
||||
|
@ -44,7 +45,8 @@ public class NarUnpackerTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
|
||||
throws IOException {
|
||||
|
||||
Path relativeSource = sourcePath.relativize(file);
|
||||
Path target = targetPath.resolve(relativeSource);
|
||||
|
@ -61,15 +63,19 @@ public class NarUnpackerTest {
|
|||
|
||||
NiFiProperties properties = loadSpecifiedProperties("/NarUnpacker/conf/nifi.properties");
|
||||
|
||||
assertEquals("./target/NarUnpacker/lib/", properties.getProperty("nifi.nar.library.directory"));
|
||||
assertEquals("./target/NarUnpacker/lib2/", properties.getProperty("nifi.nar.library.directory.alt"));
|
||||
assertEquals("./target/NarUnpacker/lib/",
|
||||
properties.getProperty("nifi.nar.library.directory"));
|
||||
assertEquals("./target/NarUnpacker/lib2/",
|
||||
properties.getProperty("nifi.nar.library.directory.alt"));
|
||||
|
||||
final ExtensionMapping extensionMapping = NarUnpacker.unpackNars(properties);
|
||||
|
||||
assertEquals(2, extensionMapping.getAllExtensionNames().size());
|
||||
|
||||
assertTrue(extensionMapping.getAllExtensionNames().contains("org.apache.nifi.processors.dummy.one"));
|
||||
assertTrue(extensionMapping.getAllExtensionNames().contains("org.apache.nifi.processors.dummy.two"));
|
||||
assertTrue(extensionMapping.getAllExtensionNames().contains(
|
||||
"org.apache.nifi.processors.dummy.one"));
|
||||
assertTrue(extensionMapping.getAllExtensionNames().contains(
|
||||
"org.apache.nifi.processors.dummy.two"));
|
||||
|
||||
final File extensionsWorkingDir = properties.getExtensionsWorkingDirectory();
|
||||
File[] extensionFiles = extensionsWorkingDir.listFiles();
|
||||
|
@ -94,7 +100,8 @@ public class NarUnpackerTest {
|
|||
final ExtensionMapping extensionMapping = NarUnpacker.unpackNars(properties);
|
||||
|
||||
assertEquals(1, extensionMapping.getAllExtensionNames().size());
|
||||
assertTrue(extensionMapping.getAllExtensionNames().contains("org.apache.nifi.processors.dummy.one"));
|
||||
assertTrue(extensionMapping.getAllExtensionNames().contains(
|
||||
"org.apache.nifi.processors.dummy.one"));
|
||||
|
||||
final File extensionsWorkingDir = properties.getExtensionsWorkingDirectory();
|
||||
File[] extensionFiles = extensionsWorkingDir.listFiles();
|
||||
|
@ -115,7 +122,8 @@ public class NarUnpackerTest {
|
|||
|
||||
final ExtensionMapping extensionMapping = NarUnpacker.unpackNars(properties);
|
||||
|
||||
assertTrue(extensionMapping.getAllExtensionNames().contains("org.apache.nifi.processors.dummy.one"));
|
||||
assertTrue(extensionMapping.getAllExtensionNames().contains(
|
||||
"org.apache.nifi.processors.dummy.one"));
|
||||
|
||||
assertEquals(1, extensionMapping.getAllExtensionNames().size());
|
||||
|
||||
|
@ -141,7 +149,6 @@ public class NarUnpackerTest {
|
|||
assertNull(extensionMapping);
|
||||
}
|
||||
|
||||
|
||||
private NiFiProperties loadSpecifiedProperties(String propertiesFile) {
|
||||
String file = NarUnpackerTest.class.getResource(propertiesFile).getFile();
|
||||
|
||||
|
@ -159,7 +166,8 @@ public class NarUnpackerTest {
|
|||
inStream = new BufferedInputStream(new FileInputStream(file));
|
||||
properties.load(inStream);
|
||||
} catch (final Exception ex) {
|
||||
throw new RuntimeException("Cannot load properties file due to " + ex.getLocalizedMessage(), ex);
|
||||
throw new RuntimeException("Cannot load properties file due to "
|
||||
+ ex.getLocalizedMessage(), ex);
|
||||
} finally {
|
||||
if (null != inStream) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue