Search in sources :

Example 1 with BundleDetails

use of org.apache.nifi.bundle.BundleDetails in project nifi by apache.

the class SystemBundle method create.

/**
 * Returns a bundle representing the system class loader.
 *
 * @param niFiProperties a NiFiProperties instance which will be used to obtain the default NAR library path,
 *                       which will become the working directory of the returned bundle
 * @return a bundle for the system class loader
 */
public static Bundle create(final NiFiProperties niFiProperties) {
    final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
    final String narLibraryDirectory = niFiProperties.getProperty(NiFiProperties.NAR_LIBRARY_DIRECTORY);
    if (StringUtils.isBlank(narLibraryDirectory)) {
        throw new IllegalStateException("Unable to create system bundle because " + NiFiProperties.NAR_LIBRARY_DIRECTORY + " was null or empty");
    }
    final BundleDetails systemBundleDetails = new BundleDetails.Builder().workingDir(new File(narLibraryDirectory)).coordinate(SYSTEM_BUNDLE_COORDINATE).build();
    return new Bundle(systemBundleDetails, systemClassLoader);
}
Also used : BundleDetails(org.apache.nifi.bundle.BundleDetails) Bundle(org.apache.nifi.bundle.Bundle) File(java.io.File)

Example 2 with BundleDetails

use of org.apache.nifi.bundle.BundleDetails in project nifi by apache.

the class NarBundleUtilTest method testManifestWithVersioningAndBuildInfo.

@Test
public void testManifestWithVersioningAndBuildInfo() throws IOException {
    final File narDir = new File("src/test/resources/nars/nar-with-versioning");
    final BundleDetails narDetails = NarBundleUtil.fromNarDirectory(narDir);
    assertEquals(narDir.getPath(), narDetails.getWorkingDirectory().getPath());
    assertEquals("org.apache.nifi", narDetails.getCoordinate().getGroup());
    assertEquals("nifi-hadoop-nar", narDetails.getCoordinate().getId());
    assertEquals("1.2.0", narDetails.getCoordinate().getVersion());
    assertEquals("org.apache.nifi.hadoop", narDetails.getDependencyCoordinate().getGroup());
    assertEquals("nifi-hadoop-libraries-nar", narDetails.getDependencyCoordinate().getId());
    assertEquals("1.2.1", narDetails.getDependencyCoordinate().getVersion());
    assertEquals("NIFI-3380", narDetails.getBuildBranch());
    assertEquals("1.8.0_74", narDetails.getBuildJdk());
    assertEquals("a032175", narDetails.getBuildRevision());
    assertEquals("HEAD", narDetails.getBuildTag());
    assertEquals("2017-01-23T10:36:27Z", narDetails.getBuildTimestamp());
    assertEquals("bbende", narDetails.getBuiltBy());
}
Also used : BundleDetails(org.apache.nifi.bundle.BundleDetails) File(java.io.File) Test(org.junit.Test)

Example 3 with BundleDetails

use of org.apache.nifi.bundle.BundleDetails in project nifi by apache.

the class JettyServer method findWars.

private Map<File, Bundle> findWars(final Set<Bundle> bundles) {
    final Map<File, Bundle> wars = new HashMap<>();
    // consider each nar working directory
    bundles.forEach(bundle -> {
        final BundleDetails details = bundle.getBundleDetails();
        final File narDependencies = new File(details.getWorkingDirectory(), "META-INF/bundled-dependencies");
        if (narDependencies.isDirectory()) {
            // list the wars from this nar
            final File[] narDependencyDirs = narDependencies.listFiles(WAR_FILTER);
            if (narDependencyDirs == null) {
                throw new IllegalStateException(String.format("Unable to access working directory for NAR dependencies in: %s", narDependencies.getAbsolutePath()));
            }
            // add each war
            for (final File war : narDependencyDirs) {
                wars.put(war, bundle);
            }
        }
    });
    return wars;
}
Also used : BundleDetails(org.apache.nifi.bundle.BundleDetails) HashMap(java.util.HashMap) Bundle(org.apache.nifi.bundle.Bundle) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 4 with BundleDetails

use of org.apache.nifi.bundle.BundleDetails in project nifi-minifi by apache.

the class SystemBundle method create.

/**
 * Returns a bundle representing the system class loader.
 *
 * @param niFiProperties a NiFiProperties instance which will be used to obtain the default NAR library path,
 *                       which will become the working directory of the returned bundle
 * @return a bundle for the system class loader
 */
public static Bundle create(final NiFiProperties niFiProperties) {
    final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
    final String narLibraryDirectory = niFiProperties.getProperty(NiFiProperties.NAR_LIBRARY_DIRECTORY);
    if (StringUtils.isBlank(narLibraryDirectory)) {
        throw new IllegalStateException("Unable to create system bundle because " + NiFiProperties.NAR_LIBRARY_DIRECTORY + " was null or empty");
    }
    final BundleDetails systemBundleDetails = new BundleDetails.Builder().workingDir(new File(narLibraryDirectory)).coordinate(SYSTEM_BUNDLE_COORDINATE).build();
    return new Bundle(systemBundleDetails, systemClassLoader);
}
Also used : BundleDetails(org.apache.nifi.bundle.BundleDetails) Bundle(org.apache.nifi.bundle.Bundle) File(java.io.File)

Example 5 with BundleDetails

use of org.apache.nifi.bundle.BundleDetails in project nifi-minifi by apache.

the class NarBundleUtil method fromNarDirectory.

/**
 * Creates a BundleDetails from the given NAR working directory.
 *
 * @param narDirectory the directory of an exploded NAR which contains a META-INF/MANIFEST.MF
 *
 * @return the BundleDetails constructed from the information in META-INF/MANIFEST.MF
 */
public static BundleDetails fromNarDirectory(final File narDirectory) throws IOException, IllegalStateException {
    if (narDirectory == null) {
        throw new IllegalArgumentException("NAR Directory cannot be null");
    }
    final File manifestFile = new File(narDirectory, "META-INF/MANIFEST.MF");
    try (final FileInputStream fis = new FileInputStream(manifestFile)) {
        final Manifest manifest = new Manifest(fis);
        final Attributes attributes = manifest.getMainAttributes();
        final BundleDetails.Builder builder = new BundleDetails.Builder();
        builder.workingDir(narDirectory);
        final String group = attributes.getValue(NarManifestEntry.NAR_GROUP.getManifestName());
        final String id = attributes.getValue(NarManifestEntry.NAR_ID.getManifestName());
        final String version = attributes.getValue(NarManifestEntry.NAR_VERSION.getManifestName());
        builder.coordinate(new BundleCoordinate(group, id, version));
        final String dependencyGroup = attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_GROUP.getManifestName());
        final String dependencyId = attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_ID.getManifestName());
        final String dependencyVersion = attributes.getValue(NarManifestEntry.NAR_DEPENDENCY_VERSION.getManifestName());
        if (!StringUtils.isBlank(dependencyId)) {
            builder.dependencyCoordinate(new BundleCoordinate(dependencyGroup, dependencyId, dependencyVersion));
        }
        builder.buildBranch(attributes.getValue(NarManifestEntry.BUILD_BRANCH.getManifestName()));
        builder.buildTag(attributes.getValue(NarManifestEntry.BUILD_TAG.getManifestName()));
        builder.buildRevision(attributes.getValue(NarManifestEntry.BUILD_REVISION.getManifestName()));
        builder.buildTimestamp(attributes.getValue(NarManifestEntry.BUILD_TIMESTAMP.getManifestName()));
        builder.buildJdk(attributes.getValue(NarManifestEntry.BUILD_JDK.getManifestName()));
        builder.builtBy(attributes.getValue(NarManifestEntry.BUILT_BY.getManifestName()));
        return builder.build();
    }
}
Also used : BundleDetails(org.apache.nifi.bundle.BundleDetails) Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) File(java.io.File) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) FileInputStream(java.io.FileInputStream)

Aggregations

BundleDetails (org.apache.nifi.bundle.BundleDetails)13 File (java.io.File)10 Bundle (org.apache.nifi.bundle.Bundle)8 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)5 HashMap (java.util.HashMap)4 Set (java.util.Set)3 Test (org.junit.Test)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 Attributes (java.util.jar.Attributes)2 Manifest (java.util.jar.Manifest)2 NiFiProperties (org.apache.nifi.util.NiFiProperties)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2