Assignment group B.4 - Improve batch architecture

Reference documents

Dependencies

Assignment B.4.1 - use security manager for batch jobs

Read relevant parts of the [http://java.sun.com/docs/books/tutorial/security1.2/index.html Java security tutorial trail].

Set up our bitarchives to run with a security policy that grants AllPermission to code signed by the NetarchiveSuite, and only limited permissions to other code. The limited permissions should be just enough for third party class files to write results of batchjobs to the result files.

Update our build scripts to sign the jar files.

Update our deploy applications to start the bitarchives with a security policy.

Note: This may not be the correct or ideal solution, a better solution may present itself while reading the Java tutorial trail, which I have not done while writing this assignment.

Note: I am unsure if this will not still allow batch jobs to interfere with eachother.

Assignment B.4.2 - allow third-party batch jobs to be submitted

Basically, we need a batch job that takes a serialised class file, and loads it at the bitarchives and then runs it.

Such a class would look like this (but should of course be tested and documented properly, and have error handling):

public class ClassBatchJob extends FileBatchJob {
    private final byte[] fileBatchJobClass;
    private transient FileBatchJob job;

    public ClassBatchJob(byte [] fileBatchJobClass) {
        this.fileBatchJobClass = fileBatchJobClass;
    }

    public void initialize(OutputStream os) {
        Class c = new ClassLoader() { 
                          Class initialize() {
                              return defineClass(null, fileBatchJobClass,
                                                 0, fileBatchJobClass.length);
            }
        }.initialize();
        try {
            job = (FileBatchJob) c.newInstance();
        } catch (InstantiationException e) {
            throw new IOFailure("Unable to initialise class", e);
        } catch (IllegalAccessException e) {
            throw new IOFailure("Illegal access for class", e);
        }
        job.initialize(os);
    }

    public boolean processFile(File file, OutputStream os) {
        return job.processFile(file, os);
    }

    public void finish(OutputStream os) {
        job.finish(os);
    }
}

Once that job has been written, it is merely a question of making a webpage where you can upload a class file, and submit the job and print the results.

The webpage should be asynchronous, so a web timeout does not prevent you from seeing the result of the batch job.