Esempio n. 1
0
  @GET
  @Path("/{id}/log/size")
  public long getLogSize(@PathParam("id") long id) {
    Optional<ModuleBuild> build = get(id);
    if (!build.isPresent()) {
      throw new NotFoundException("No build found for ID " + id);
    }

    Optional<String> taskId = build.get().getBuild().getTaskId();
    if (!taskId.isPresent()) {
      throw new NotFoundException("No taskId found for build ID " + id);
    }

    String path = taskId.get() + "/service.log";
    Optional<Long> absent = Optional.absent();
    Optional<String> grep = Optional.absent();

    Optional<MesosFileChunkObject> chunk =
        singularityClient.readSandBoxFile(taskId.get(), path, grep, absent, absent);
    if (chunk.isPresent()) {
      return chunk.get().getOffset();
    } else {
      Collection<SingularityS3Log> s3Logs = singularityClient.getTaskLogs(taskId.get());
      if (s3Logs.isEmpty()) {
        throw new NotFoundException("No S3 log found for ID " + id);
      } else if (s3Logs.size() > 1) {
        throw new NotFoundException("Multiple S3 logs found for ID " + id);
      }

      SingularityS3Log s3Log = s3Logs.iterator().next();
      return s3Log.getSize();
    }
  }
Esempio n. 2
0
  @GET
  @Path("/{id}/log")
  public LogChunk getLog(
      @PathParam("id") long id,
      @QueryParam("offset") @DefaultValue("0") long offset,
      @QueryParam("length") @DefaultValue("90000") long length)
      throws Exception {
    Optional<ModuleBuild> build = get(id);
    if (!build.isPresent()) {
      throw new NotFoundException("No build found for ID " + id);
    }

    boolean completed = build.get().getBuild().getState().isComplete();
    Optional<String> taskId = build.get().getBuild().getTaskId();
    if (!taskId.isPresent()) {
      throw new NotFoundException("No taskId found for build ID " + id);
    }

    String path = taskId.get() + "/service.log";
    Optional<String> grep = Optional.absent();

    Optional<MesosFileChunkObject> chunk =
        singularityClient.readSandBoxFile(
            taskId.get(), path, grep, Optional.of(offset), Optional.of(length));
    if (chunk.isPresent()) {
      if (completed && chunk.get().getData().isEmpty()) {
        return new LogChunk(chunk.get().getData(), chunk.get().getOffset(), -1);
      } else {
        return new LogChunk(chunk.get().getData(), chunk.get().getOffset());
      }
    } else {
      Collection<SingularityS3Log> s3Logs = singularityClient.getTaskLogs(taskId.get());
      if (s3Logs.isEmpty()) {
        throw new NotFoundException("No S3 log found for ID " + id);
      } else if (s3Logs.size() > 1) {
        throw new NotFoundException("Multiple S3 logs found for ID " + id);
      }

      SingularityS3Log s3Log = s3Logs.iterator().next();
      if (offset >= s3Log.getSize()) {
        return new LogChunk("", s3Log.getSize(), -1);
      }

      return fetchS3Log(s3Log.getGetUrl(), offset, length);
    }
  }