Search in sources :

Example 1 with ResourceTransformer

use of org.apache.storm.hack.resource.ResourceTransformer in project storm by apache.

the class StormShadeRequest method makeRequest.

public static ShadeRequest makeRequest() {
    ShadeRequest request = new ShadeRequest();
    request.setRelocators(Arrays.asList((Relocator) new SimpleRelocator("backtype.storm", "org.apache.storm"), (Relocator) new SimpleRelocator("storm.trident", "org.apache.storm.trident"), (Relocator) new SimpleRelocator("org.apache.thrift7", "org.apache.storm.thrift")));
    request.setResourceTransformers(Arrays.asList((ResourceTransformer) new ClojureTransformer()));
    return request;
}
Also used : SimpleRelocator(org.apache.storm.hack.relocation.SimpleRelocator) ResourceTransformer(org.apache.storm.hack.resource.ResourceTransformer) Relocator(org.apache.storm.hack.relocation.Relocator) SimpleRelocator(org.apache.storm.hack.relocation.SimpleRelocator) ClojureTransformer(org.apache.storm.hack.resource.ClojureTransformer)

Example 2 with ResourceTransformer

use of org.apache.storm.hack.resource.ResourceTransformer in project storm by apache.

the class DefaultShader method shadeJarStream.

public void shadeJarStream(ShadeRequest shadeRequest, InputStream in, final OutputStream fileOutputStream) throws IOException {
    Set<String> resources = new HashSet<>();
    List<ResourceTransformer> transformers = new ArrayList<>(shadeRequest.getResourceTransformers());
    LOG.debug("Transformers {}", transformers);
    RelocatorRemapper remapper = new RelocatorRemapper(shadeRequest.getRelocators());
    LOG.debug("Remapper {}", remapper);
    JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(fileOutputStream));
    JarInputStream jarFile = new JarInputStream(in);
    for (JarEntry entry = jarFile.getNextJarEntry(); entry != null; entry = jarFile.getNextJarEntry()) {
        String name = entry.getName();
        LOG.debug("Processing " + name);
        remapper.setClassName(name);
        if ("META-INF/INDEX.LIST".equals(name)) {
            LOG.debug("Skipping INDEX.LIST...");
            // later
            continue;
        }
        if (!entry.isDirectory()) {
            InputStream is = jarFile;
            String mappedName = remapper.map(name);
            LOG.debug(name + " -> " + mappedName);
            int idx = mappedName.lastIndexOf('/');
            if (idx != -1) {
                // make sure dirs are created
                String dir = mappedName.substring(0, idx);
                if (!resources.contains(dir)) {
                    addDirectory(resources, jos, dir);
                }
            }
            if (name.endsWith(".class")) {
                addRemappedClass(remapper, jos, name, is);
            } else if (name.endsWith(".java")) {
                // Avoid duplicates
                if (resources.contains(mappedName)) {
                    continue;
                }
                addJavaSource(resources, jos, mappedName, is, shadeRequest.getRelocators());
            } else {
                if (!resourceTransformed(transformers, mappedName, is, shadeRequest.getRelocators())) {
                    // Avoid duplicates that aren't accounted for by the resource transformers
                    if (resources.contains(mappedName)) {
                        continue;
                    }
                    addResource(resources, jos, mappedName, is);
                }
            }
        }
    }
    jarFile.close();
    for (ResourceTransformer transformer : transformers) {
        if (transformer.hasTransformedResource()) {
            transformer.modifyOutputStream(jos);
        }
    }
    jos.close();
}
Also used : JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) ResourceTransformer(org.apache.storm.hack.resource.ResourceTransformer) HashSet(java.util.HashSet)

Example 3 with ResourceTransformer

use of org.apache.storm.hack.resource.ResourceTransformer in project storm by apache.

the class DefaultShader method resourceTransformed.

private boolean resourceTransformed(List<ResourceTransformer> resourceTransformers, String name, InputStream is, List<Relocator> relocators) throws IOException {
    boolean resourceTransformed = false;
    for (ResourceTransformer transformer : resourceTransformers) {
        if (transformer.canTransformResource(name)) {
            LOG.debug("Transforming " + name + " using " + transformer.getClass().getName());
            transformer.processResource(name, is, relocators);
            resourceTransformed = true;
            break;
        }
    }
    return resourceTransformed;
}
Also used : ResourceTransformer(org.apache.storm.hack.resource.ResourceTransformer)

Aggregations

ResourceTransformer (org.apache.storm.hack.resource.ResourceTransformer)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JarEntry (java.util.jar.JarEntry)1 JarInputStream (java.util.jar.JarInputStream)1 JarOutputStream (java.util.jar.JarOutputStream)1 Relocator (org.apache.storm.hack.relocation.Relocator)1 SimpleRelocator (org.apache.storm.hack.relocation.SimpleRelocator)1 ClojureTransformer (org.apache.storm.hack.resource.ClojureTransformer)1