unpackedFramework = unpackNar(narFile, frameworkWorkingDir); } else { final File unpackedExtension = unpackNar(narFile, extensionsWorkingDir); mapExtensions(unpackedNars, docsWorkingDir, extensionMapping); unpackBundleDocs(docsWorkingDir, extensionMapping, systemBundle.getBundleDetails().getCoordinate(), systemBundle.getBundleDetails().getWorkingDirectory());
unpack(nar, narWorkingDirectory, calculateMd5sum(nar)); } else { final byte[] narMd5 = calculateMd5sum(nar); final File workingHashFile = new File(narWorkingDirectory, HASH_FILENAME); if (!workingHashFile.exists()) { FileUtils.deleteFile(narWorkingDirectory, true); unpack(nar, narWorkingDirectory, narMd5); } else { final byte[] hashFileContents = Files.readAllBytes(workingHashFile.toPath()); logger.info("Contents of nar {} have changed. Reloading.", new Object[] { nar.getAbsolutePath() }); FileUtils.deleteFile(narWorkingDirectory, true); unpack(nar, narWorkingDirectory, narMd5);
private static void unpackDocumentation(final BundleCoordinate coordinate, final File jar, final File docsDirectory, final ExtensionMapping extensionMapping) throws IOException { final ExtensionMapping jarExtensionMapping = determineDocumentedNiFiComponents(coordinate, jar); makeFile(jarFile.getInputStream(jarEntry), componentDoc);
private File unpack(final File narFile) { try (final JarFile nar = new JarFile(narFile)) { final Manifest manifest = nar.getManifest(); final Attributes attributes = manifest.getMainAttributes(); final String groupId = attributes.getValue(NarManifestEntry.NAR_GROUP.getManifestName()); final String narId = attributes.getValue(NarManifestEntry.NAR_ID.getManifestName()); final String version = attributes.getValue(NarManifestEntry.NAR_VERSION.getManifestName()); if (NarClassLoaders.FRAMEWORK_NAR_ID.equals(narId)) { LOGGER.error("Found a framework NAR, will not load {}", new Object[]{narFile.getAbsolutePath()}); return null; } final BundleCoordinate coordinate = new BundleCoordinate(groupId, narId, version); final Bundle bundle = extensionManager.getBundle(coordinate); if (bundle != null) { LOGGER.warn("Found existing bundle with coordinate {}, will not load {}", new Object[]{coordinate, narFile.getAbsolutePath()}); return null; } final File unpackedExtension = NarUnpacker.unpackNar(narFile, extensionsWorkingDir); NarUnpacker.mapExtension(unpackedExtension, coordinate, docsWorkingDir, extensionMapping); return unpackedExtension; } catch (Exception e) { LOGGER.error("Error unpacking " + narFile.getAbsolutePath(), e); return null; } }
unpackedFramework = unpackNar(narFile, frameworkWorkingDir); } else { unpackedExtensions.add(unpackNar(narFile, extensionsWorkingDir)); mapExtensions(extensionsWorkingDir, docsWorkingDir, extensionMapping); return extensionMapping; } catch (IOException e) {
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) { if (file.isDirectory()) { mapExtensions(file, docsDirectory, mapping); } else if (file.getName().toLowerCase().endsWith(".jar")) { unpackDocumentation(file, docsDirectory, mapping); } } } }
private static ExtensionMapping determineDocumentedNiFiComponents(final BundleCoordinate coordinate, final File jar) throws IOException { final ExtensionMapping mapping = new ExtensionMapping(); 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"); if (processorEntry==null && reportingTaskEntry==null && controllerServiceEntry==null) { return mapping; } mapping.addAllProcessors(coordinate, determineDocumentedNiFiComponents(jarFile, processorEntry)); mapping.addAllReportingTasks(coordinate, determineDocumentedNiFiComponents(jarFile, reportingTaskEntry)); mapping.addAllControllerServices(coordinate, determineDocumentedNiFiComponents(jarFile, controllerServiceEntry)); return mapping; } }
/** * 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. */ 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(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); String name = jarEntry.getName(); if(name.contains("META-INF/bundled-dependencies")){ name = name.replace("META-INF/bundled-dependencies", "NAR-INF/bundled-dependencies"); } File f = new File(workingDirectory, name); if (jarEntry.isDirectory()) { FileUtils.ensureDirectoryExistAndCanReadAndWrite(f); } else { makeFile(jarFile.getInputStream(jarEntry), f); } } } final File hashFile = new File(workingDirectory, HASH_FILENAME); try (final FileOutputStream fos = new FileOutputStream(hashFile)) { fos.write(hash); } }
final ExtensionMapping extensionMapping = NarUnpacker.unpackNars(properties, systemBundle);
private static void unpackBundleDocs(final File docsDirectory, final ExtensionMapping mapping, final BundleCoordinate bundleCoordinate, final File bundledDirectory) throws IOException { final File[] directoryContents = bundledDirectory.listFiles(); if (directoryContents != null) { for (final File file : directoryContents) { if (file.getName().toLowerCase().endsWith(".jar")) { unpackDocumentation(bundleCoordinate, file, docsDirectory, mapping); } } } }
unpackedFramework = unpackNar(narFile, frameworkWorkingDir); } else { unpackedExtensions.add(unpackNar(narFile, extensionsWorkingDir)); mapExtensions(extensionsWorkingDir, docsWorkingDir, extensionMapping); return extensionMapping; } catch (IOException e) {
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) { if (file.isDirectory()) { mapExtensions(file, docsDirectory, mapping); } else if (file.getName().toLowerCase().endsWith(".jar")) { unpackDocumentation(file, docsDirectory, mapping); } } } }
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"); extensionMapping.addAllProcessors(determineDocumentedNiFiComponents(jarFile, processorEntry)); extensionMapping.addAllReportingTasks(determineDocumentedNiFiComponents(jarFile, reportingTaskEntry)); extensionMapping.addAllControllerServices(determineDocumentedNiFiComponents(jarFile, controllerServiceEntry)); } }
/** * 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. */ 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(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); String name = jarEntry.getName(); File f = new File(workingDirectory, name); if (jarEntry.isDirectory()) { FileUtils.ensureDirectoryExistAndCanAccess(f); } else { makeFile(jarFile.getInputStream(jarEntry), f); } } } final File hashFile = new File(workingDirectory, HASH_FILENAME); try (final FileOutputStream fos = new FileOutputStream(hashFile)) { fos.write(hash); } }
NarUnpacker.unpackNars(properties);
unpack(nar, narWorkingDirectory, calculateMd5sum(nar)); } else { final byte[] narMd5 = calculateMd5sum(nar); final File workingHashFile = new File(narWorkingDirectory, HASH_FILENAME); if (!workingHashFile.exists()) { FileUtils.deleteFile(narWorkingDirectory, true); unpack(nar, narWorkingDirectory, narMd5); } else { final byte[] hashFileContents = Files.readAllBytes(workingHashFile.toPath()); new Object[] { nar.getAbsolutePath() }); FileUtils.deleteFile(narWorkingDirectory, true); unpack(nar, narWorkingDirectory, narMd5);
private static void unpackDocumentation(final File jar, final File docsDirectory, final ExtensionMapping extensionMapping) throws IOException { determineDocumentedNiFiComponents(jar, extensionMapping); makeFile(jarFile.getInputStream(jarEntry), componentDoc);
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"); extensionMapping.addAllProcessors(determineDocumentedNiFiComponents(jarFile, processorEntry)); extensionMapping.addAllReportingTasks(determineDocumentedNiFiComponents(jarFile, reportingTaskEntry)); extensionMapping.addAllControllerServices(determineDocumentedNiFiComponents(jarFile, controllerServiceEntry)); } }
/** * 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. */ 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(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); String name = jarEntry.getName(); File f = new File(workingDirectory, name); if (jarEntry.isDirectory()) { FileUtils.ensureDirectoryExistAndCanAccess(f); } else { makeFile(jarFile.getInputStream(jarEntry), f); } } } final File hashFile = new File(workingDirectory, HASH_FILENAME); try (final FileOutputStream fos = new FileOutputStream(hashFile)) { fos.write(hash); } }
NarUnpacker.unpackNars(properties);