Esempio n. 1
0
  @GET
  @Path("/{taskId}/read")
  public MesosFileChunkObject read(
      @PathParam("taskId") String taskId,
      @QueryParam("path") String qPath,
      @QueryParam("offset") Optional<Long> offset,
      @QueryParam("length") Optional<Long> length) {
    final String path = getDefaultPath(taskId, qPath);
    final SingularityTaskHistory history = checkHistory(taskId);

    final String slaveHostname = history.getTask().getOffer().getHostname();
    final String fullPath = new File(history.getDirectory().get(), path).toString();

    try {
      final Optional<MesosFileChunkObject> maybeChunk =
          sandboxManager.read(slaveHostname, fullPath, offset, length);

      if (!maybeChunk.isPresent()) {
        throw WebExceptions.notFound("File %s does not exist for task ID %s", fullPath, taskId);
      }

      return maybeChunk.get();
    } catch (SlaveNotFoundException snfe) {
      throw WebExceptions.notFound(
          "Slave @ %s was not found, it is probably offline", slaveHostname);
    }
  }
Esempio n. 2
0
  @GET
  @Path("/{taskId}/browse")
  public Collection<MesosFileObject> browse(
      @PathParam("taskId") String taskId, @QueryParam("path") String qPath) {
    final String path = getDefaultPath(taskId, qPath);
    final SingularityTaskHistory history = checkHistory(taskId);

    final String slaveHostname = history.getTask().getOffer().getHostname();
    final String fullPath = new File(history.getDirectory().get(), path).toString();

    try {
      return sandboxManager.browse(slaveHostname, fullPath);
    } catch (SlaveNotFoundException snfe) {
      throw WebExceptions.notFound(
          "Slave @ %s was not found, it is probably offline", slaveHostname);
    }
  }
Esempio n. 3
0
  @GET
  @Path("/{taskId}/download")
  public Response download(@PathParam("taskId") String taskId, @QueryParam("path") String path) {
    final SingularityTaskHistory history = checkHistory(taskId);

    final String slaveHostname = history.getTask().getOffer().getHostname();
    final String fullPath = new File(history.getDirectory().get(), path).toString();

    try {
      final URI downloadUri =
          new URI(
              "http",
              null,
              slaveHostname,
              5051,
              "/files/download.json",
              String.format("path=%s", fullPath),
              null);

      return Response.temporaryRedirect(downloadUri).build();
    } catch (URISyntaxException e) {
      throw Throwables.propagate(e);
    }
  }