Search in sources :

Example 1 with CouldNotCreateProcessException

use of de.ipbhalle.exception.CouldNotCreateProcessException in project MetFragRelaunched by ipb-halle.

the class MetFragRestController method process.

/**
 * runs a metfrag query
 *
 * @param args
 * @return
 * @throws CouldNotWriteStatusException
 * @throws CouldNotCreateProcessException
 */
@RequestMapping(method = RequestMethod.POST, value = "", produces = { MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
public ResponseEntity<Resource<ProcessAssembler>> process(@RequestBody ProcessArguments args) throws CouldNotWriteStatusException, CouldNotCreateProcessException {
    File resFolder;
    String processid;
    try {
        resFolder = Files.createTempDirectory("java.io.tmpdir").toFile();
        processid = resFolder.getName();
        try {
            MetFragGlobalSettings settings = args.getSettingsObject(resFolder);
            // check settings
            SettingsChecker settingsChecker = new SettingsChecker();
            if (!settingsChecker.check(settings))
                throw new CouldNotCreateProcessException("Error: Corrupt parameters");
            logger.info("Storing in " + settings.get(VariableNames.STORE_RESULTS_PATH_NAME));
            CombinedMetFragProcess mp = new CombinedMetFragProcess(settings);
            this.writeStatus("RUNNING", processid);
            this.writeHost(processid);
            new Thread(() -> {
                System.out.println("staring run");
                try {
                    MetFragRestService.startMetFrag(mp, settings, resFolder.getAbsolutePath());
                } catch (IOException e) {
                    e.printStackTrace();
                    return;
                }
            }, "MyThread-" + processid).start();
        } catch (ParameterNotKnownException e) {
            e.printStackTrace();
            this.writeStatus("ERROR", processid);
            throw new CouldNotCreateProcessException("Error: Parameter not known");
        } catch (IOException e) {
            e.printStackTrace();
            throw new CouldNotCreateProcessException("Error: Could not write status");
        } catch (Exception e) {
            e.printStackTrace();
            this.writeStatus("ERROR", processid);
            throw new CouldNotCreateProcessException("Error: Unknown error");
        }
    } catch (IOException e) {
        throw new CouldNotWriteStatusException(e.getMessage());
    }
    Resource<ProcessAssembler> resource = new ProcessAssembler("process", processid).toResource();
    resource.add(linkTo(MetFragRestController.class).slash("process").withSelfRel());
    resource.add(linkTo(MetFragRestController.class).slash("status").slash(processid).withRel("status"));
    resource.add(linkTo(MetFragRestController.class).slash("host").slash(processid).withRel("host"));
    resource.add(linkTo(MetFragRestController.class).slash("result").slash(processid).withRel("result"));
    resource.add(linkTo(MetFragRestController.class).slash("resultzip").slash(processid).withRel("resultzip"));
    return new ResponseEntity<Resource<ProcessAssembler>>(resource, HttpStatus.CREATED);
}
Also used : CouldNotCreateProcessException(de.ipbhalle.exception.CouldNotCreateProcessException) MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) CouldNotWriteStatusException(de.ipbhalle.exception.CouldNotWriteStatusException) IOException(java.io.IOException) ParameterNotKnownException(de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException) CouldNotReadStatusException(de.ipbhalle.exception.CouldNotReadStatusException) CouldNotFetchResultsException(de.ipbhalle.exception.CouldNotFetchResultsException) ParameterNotKnownException(de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException) CouldNotCreateProcessException(de.ipbhalle.exception.CouldNotCreateProcessException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CouldNotRemoveProcessException(de.ipbhalle.exception.CouldNotRemoveProcessException) ExecutionException(java.util.concurrent.ExecutionException) CouldNotReadHostException(de.ipbhalle.exception.CouldNotReadHostException) CouldNotWriteStatusException(de.ipbhalle.exception.CouldNotWriteStatusException) ResponseEntity(org.springframework.http.ResponseEntity) SettingsChecker(de.ipbhalle.metfraglib.parameter.SettingsChecker) File(java.io.File) ProcessAssembler(de.ipbhalle.model.ProcessAssembler) CombinedMetFragProcess(de.ipbhalle.metfraglib.process.CombinedMetFragProcess) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

CouldNotCreateProcessException (de.ipbhalle.exception.CouldNotCreateProcessException)1 CouldNotFetchResultsException (de.ipbhalle.exception.CouldNotFetchResultsException)1 CouldNotReadHostException (de.ipbhalle.exception.CouldNotReadHostException)1 CouldNotReadStatusException (de.ipbhalle.exception.CouldNotReadStatusException)1 CouldNotRemoveProcessException (de.ipbhalle.exception.CouldNotRemoveProcessException)1 CouldNotWriteStatusException (de.ipbhalle.exception.CouldNotWriteStatusException)1 ParameterNotKnownException (de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException)1 SettingsChecker (de.ipbhalle.metfraglib.parameter.SettingsChecker)1 CombinedMetFragProcess (de.ipbhalle.metfraglib.process.CombinedMetFragProcess)1 MetFragGlobalSettings (de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)1 ProcessAssembler (de.ipbhalle.model.ProcessAssembler)1 File (java.io.File)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1