Search in sources :

Example 1 with HTCSolver

use of cbit.vcell.solvers.HTCSolver in project vcell by virtualcell.

the class SolverPreprocessor method main.

public static void main(java.lang.String[] args) {
    if (args.length < 2) {
        System.out.print(SolverPreprocessor.class.getName() + " ");
        System.out.println(Arrays.toString(args));
        System.out.println("Missing arguments: " + SolverPreprocessor.class.getName() + " [simulationTaskFile] [userdir] <parallel dir> ");
        System.exit(1);
    }
    File parallelDirectory = null;
    if (args.length >= 3) {
        parallelDirectory = new File(args[2]);
        if (!parallelDirectory.exists()) {
            parallelDirectory.mkdirs();
        }
        if (!parallelDirectory.isDirectory() || !parallelDirectory.canWrite()) {
            throw new IllegalArgumentException(parallelDirectory.getAbsolutePath() + " is not a writeable directory");
        }
    }
    Logging.init();
    try {
        PropertyLoader.loadProperties();
        // 
        File simulationFile = new File(args[0]);
        final SimulationTask simTask = XmlHelper.XMLToSimTask(FileUtils.readFileToString(simulationFile));
        if (parallelDirectory != null) {
            // simulation task needs to be written to the "parallel directory" (a temporary directory) here (it is local to the cluster).
            FileUtils.copyFile(simulationFile, new File(parallelDirectory, simulationFile.getName()));
        }
        File userDirectory = new File(args[1]);
        final String hostName = null;
        VCMongoMessage.serviceStartup(ServiceName.solverPreprocessor, Integer.valueOf(simTask.getSimKey().toString()), args);
        // 
        // JMX registration
        // 
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
        final HTCSolver htcSolver = new HTCSolver(simTask, userDirectory, parallelDirectory) {

            public void startSolver() {
                try {
                    super.initialize();
                } catch (Exception e) {
                    e.printStackTrace();
                    SimulationMessage simMessage = SimulationMessage.jobFailed(e.getMessage());
                    try {
                        sendFailureAndExit(this, simTask, hostName, simMessage);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            }

            public void stopSolver() {
            }

            public double getCurrentTime() {
                return 0;
            }

            public double getProgress() {
                return 0;
            }
        };
        SolverListener solverListener = new SolverListener() {

            public void solverStopped(SolverEvent event) {
                VCMongoMessage.sendSolverEvent(event);
                try {
                    sendFailureAndExit(htcSolver, simTask, hostName, event.getSimulationMessage());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            public void solverStarting(SolverEvent event) {
                VCMongoMessage.sendSolverEvent(event);
            }

            public void solverProgress(SolverEvent event) {
                VCMongoMessage.sendSolverEvent(event);
            }

            public void solverPrinted(SolverEvent event) {
                VCMongoMessage.sendSolverEvent(event);
            }

            public void solverFinished(SolverEvent event) {
                VCMongoMessage.sendSolverEvent(event);
            }

            public void solverAborted(SolverEvent event) {
                VCMongoMessage.sendSolverEvent(event);
                try {
                    sendFailureAndExit(htcSolver, simTask, hostName, event.getSimulationMessage());
                } catch (VCMessagingException e) {
                    e.printStackTrace();
                }
            }
        };
        htcSolver.addSolverListener(solverListener);
        htcSolver.startSolver();
        VCMongoMessage.sendInfo("preprocessor done");
        exitWithCode(0);
    } catch (Throwable e) {
        lg.error(e.getMessage(), e);
        exitWithCode(-1);
    }
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) VCMessagingException(cbit.vcell.message.VCMessagingException) FileNotFoundException(java.io.FileNotFoundException) ObjectName(javax.management.ObjectName) SolverEvent(cbit.vcell.solver.server.SolverEvent) VCellServiceMXBeanImpl(cbit.vcell.message.server.jmx.VCellServiceMXBeanImpl) SimulationMessage(cbit.vcell.solver.server.SimulationMessage) SolverListener(cbit.vcell.solver.server.SolverListener) VCMessagingException(cbit.vcell.message.VCMessagingException) File(java.io.File) HTCSolver(cbit.vcell.solvers.HTCSolver) MBeanServer(javax.management.MBeanServer)

Aggregations

VCMessagingException (cbit.vcell.message.VCMessagingException)1 VCellServiceMXBeanImpl (cbit.vcell.message.server.jmx.VCellServiceMXBeanImpl)1 SimulationTask (cbit.vcell.messaging.server.SimulationTask)1 SimulationMessage (cbit.vcell.solver.server.SimulationMessage)1 SolverEvent (cbit.vcell.solver.server.SolverEvent)1 SolverListener (cbit.vcell.solver.server.SolverListener)1 HTCSolver (cbit.vcell.solvers.HTCSolver)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1