コード例 #1
0
  /**
   * Retrieve the status of a execution.
   *
   * @param tid The tid of the execution
   * @return A structure containing the status and information related to the status
   */
  @RequestMapping(method = RequestMethod.GET, value = "/programs/{tid}/status")
  public GetProgramStatusResponse getProgramStatus(@PathVariable Long tid) {

    Program p = programsRepository.findOne(tid);

    GetProgramStatusResponse response = new GetProgramStatusResponse();
    response.status = p.getStatus();
    response.compilationOutput = p.getCompilationOutput();

    return response;
  }
コード例 #2
0
  /**
   * Create a execution.
   *
   * <p>If the execution needs to be compiled, the compilation will be launched asynchronously by
   * this webservice.
   *
   * @param body The body of the request should contain the source code to compile
   * @return A unique ID representing the execution in the system. The id will be used for all
   *     further interactions with the API
   */
  @RequestMapping(method = RequestMethod.POST, value = "/programs")
  public PostProgramResponse postProgram(@RequestBody String body) {

    Program p = new Program();
    PostProgramResponse response = new PostProgramResponse();

    try {
      p.setStatus(ProgramStatus.NEW);
      p.setSourceCode(body);
      programsRepository.save(p);
    } catch (DataAccessException e) {
      response.status = RequestStatus.KO;
      response.programId = null;
      return response;
    }

    compilationService.compile(p);

    response.status = RequestStatus.OK;
    response.programId = p.getTid();

    return response;
  }
コード例 #3
0
  /**
   * Execute a execution.
   *
   * @param tid The tid of the execution
   * @return the ID of the execution launched
   */
  @RequestMapping(method = RequestMethod.POST, value = "/programs/{tid}/executions")
  public PostProgramExecutionResponse postProgramExecution(@PathVariable Long tid) {

    Program p = programsRepository.findOne(tid);

    PostProgramExecutionResponse response = new PostProgramExecutionResponse();

    if (p.getStatus() == ProgramStatus.COMPILED) {

      Execution e = new Execution();
      e.setProgram(p);
      e.setStatus(ExecutionStatus.NEW);
      executionsRepository.save(e);

      executionService.execute(e);

      response.executionId = e.getTid();
      response.status = RequestStatus.OK;
    } else {
      response.status = RequestStatus.KO;
    }

    return response;
  }