Exemplo 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();
    }
  }
Exemplo 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);
    }
  }
Exemplo n.º 3
0
 @Override
 protected void visitCancelled(ModuleBuild build) throws Exception {
   if (build.getTaskId().isPresent()) {
     String taskId = build.getTaskId().get();
     LOG.info("Killing singularity task {} for cancelled build {}", taskId, build.getId().get());
     Optional<SingularityTaskCleanupResult> result =
         singularityClient.killTask(taskId, Optional.of(killTaskRequest));
     if (result.isPresent()) {
       LOG.info("Cleanup result for task {}: {}", result.get());
     } else {
       LOG.info("No cleanup result for task {}", taskId);
     }
   }
 }