YARN-9837. Fixed reading YARN Service JSON spec file larger than 128k.

Contributed by Tarun Parimi
This commit is contained in:
Eric Yang 2019-09-17 13:13:35 -04:00
parent cab81f7f5f
commit dae22c962d
1 changed files with 2 additions and 12 deletions

View File

@ -20,7 +20,6 @@ package org.apache.hadoop.yarn.service.utils;
import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
@ -34,7 +33,6 @@ import org.codehaus.jackson.map.SerializationConfig;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.EOFException;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -177,17 +175,9 @@ public class JsonSerDeser<T> {
* @throws JsonParseException parse problems * @throws JsonParseException parse problems
* @throws JsonMappingException O/J mapping problems * @throws JsonMappingException O/J mapping problems
*/ */
public T load(FileSystem fs, Path path) public T load(FileSystem fs, Path path) throws IOException {
throws IOException, JsonParseException, JsonMappingException {
FileStatus status = fs.getFileStatus(path);
long len = status.getLen();
byte[] b = new byte[(int) len];
FSDataInputStream dataInputStream = fs.open(path); FSDataInputStream dataInputStream = fs.open(path);
int count = dataInputStream.read(b); return fromStream(dataInputStream);
if (count != len) {
throw new EOFException("Read of " + path +" finished prematurely");
}
return fromBytes(b);
} }