From e1fad405885753aaa5c45f648f262083d099f4c9 Mon Sep 17 00:00:00 2001 From: tpetr Date: Wed, 25 Nov 2015 13:58:11 -0500 Subject: [PATCH] tweaks to make grepping a file easier --- .../hubspot/mesos/json/MesosFileChunkObject.java | 15 ++++++++++++--- .../singularity/resources/SandboxResource.java | 5 +++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/SingularityBase/src/main/java/com/hubspot/mesos/json/MesosFileChunkObject.java b/SingularityBase/src/main/java/com/hubspot/mesos/json/MesosFileChunkObject.java index 93cec032c8..53cc91317c 100644 --- a/SingularityBase/src/main/java/com/hubspot/mesos/json/MesosFileChunkObject.java +++ b/SingularityBase/src/main/java/com/hubspot/mesos/json/MesosFileChunkObject.java @@ -4,15 +4,18 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Optional; public class MesosFileChunkObject { private final String data; private final long offset; + private final Optional nextOffset; @JsonCreator - public MesosFileChunkObject(@JsonProperty("data") String data, @JsonProperty("offset") long offset) { + public MesosFileChunkObject(@JsonProperty("data") String data, @JsonProperty("offset") long offset, @JsonProperty("nextOffset") Optional nextOffset) { this.data = data; this.offset = offset; + this.nextOffset = nextOffset; } public String getData() { @@ -23,11 +26,16 @@ public long getOffset() { return offset; } + public Optional getNextOffset() { + return nextOffset; + } + @Override public String toString() { return "MesosFileChunkObject[" + "data='" + data + '\'' + ", offset=" + offset + + ", nextOffset=" + nextOffset + ']'; } @@ -41,11 +49,12 @@ public boolean equals(Object o) { } MesosFileChunkObject that = (MesosFileChunkObject) o; return Objects.equals(offset, that.offset) && - Objects.equals(data, that.data); + Objects.equals(data, that.data) && + Objects.equals(nextOffset, that.nextOffset); } @Override public int hashCode() { - return Objects.hash(data, offset); + return Objects.hash(data, offset, nextOffset); } } diff --git a/SingularityService/src/main/java/com/hubspot/singularity/resources/SandboxResource.java b/SingularityService/src/main/java/com/hubspot/singularity/resources/SandboxResource.java index 4728f3875e..5605e2e49c 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/resources/SandboxResource.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/resources/SandboxResource.java @@ -19,6 +19,7 @@ import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Splitter; +import com.google.common.base.Strings; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.inject.Inject; @@ -139,7 +140,7 @@ public MesosFileChunkObject read(@ApiParam("The task ID of the sandbox to read f checkNotFound(maybeChunk.isPresent(), "File %s does not exist for task ID %s", fullPath, taskId); - if (grep.isPresent()) { + if (grep.isPresent() && !Strings.isNullOrEmpty(grep.get())) { final Pattern grepPattern = Pattern.compile(grep.get()); final StringBuilder strBuilder = new StringBuilder(maybeChunk.get().getData().length()); @@ -150,7 +151,7 @@ public MesosFileChunkObject read(@ApiParam("The task ID of the sandbox to read f } } - return new MesosFileChunkObject(strBuilder.toString(), maybeChunk.get().getOffset()); + return new MesosFileChunkObject(strBuilder.toString(), maybeChunk.get().getOffset(), Optional.of(maybeChunk.get().getOffset() + maybeChunk.get().getData().length())); } return maybeChunk.get();