YARN-5257. Fix unreleased resources and null dereferences (yufeigu via rkanter)

This commit is contained in:
Robert Kanter 2016-12-27 14:14:08 -08:00
parent 1bbd023275
commit 9262797e86
11 changed files with 33 additions and 25 deletions

View File

@ -192,11 +192,11 @@ public void launchAM(ApplicationAttemptId attemptId)
throw new RuntimeException(ex);
}
tokenFile.deleteOnExit();
DataOutputStream os = new DataOutputStream(new FileOutputStream(tokenFile,
true));
credentials.writeTokenStorageToStream(os);
os.close();
try (DataOutputStream os = new DataOutputStream(
new FileOutputStream(tokenFile, true))) {
credentials.writeTokenStorageToStream(os);
}
Map<String, String> env = System.getenv();
ArrayList<String> envAMList = new ArrayList<String>();
boolean setClasspath = false;

View File

@ -774,13 +774,14 @@ long getRMStartTime() {
private JSONObject getJSONObject(URLConnection conn)
throws IOException, JSONException {
InputStream in = conn.getInputStream();
String encoding = conn.getContentEncoding();
encoding = encoding == null ? "UTF-8" : encoding;
String body = IOUtils.toString(in, encoding);
JSONObject obj = new JSONObject(body);
JSONObject clusterInfo = obj.getJSONObject("clusterInfo");
return clusterInfo;
try(InputStream in = conn.getInputStream()) {
String encoding = conn.getContentEncoding();
encoding = encoding == null ? "UTF-8" : encoding;
String body = IOUtils.toString(in, encoding);
JSONObject obj = new JSONObject(body);
JSONObject clusterInfo = obj.getJSONObject("clusterInfo");
return clusterInfo;
}
}
private URL getClusterUrl() throws Exception {

View File

@ -805,7 +805,7 @@ private static void putTimelineDataInJSONFile(String path, String type) {
error.getErrorCode());
}
}
} else if (type.equals(DOMAIN_DATA_TYPE)) {
} else if (type.equals(DOMAIN_DATA_TYPE) && domains != null) {
boolean hasError = false;
for (TimelineDomain domain : domains.getDomains()) {
try {

View File

@ -189,7 +189,7 @@ public String generateGraphViz() {
public void save(String filepath) throws IOException {
try (OutputStreamWriter fout = new OutputStreamWriter(
new FileOutputStream(filepath), Charset.forName("UTF-8"));) {
new FileOutputStream(filepath), Charset.forName("UTF-8"))) {
fout.write(generateGraphViz());
}
}

View File

@ -49,7 +49,9 @@ public static Graph getGraphFromClasses(String graphName, List<String> classes)
if (gname.endsWith("Impl")) {
gname = gname.substring(0, gname.length()-4);
}
ret.addSubGraph(factory.generateStateGraph(gname));
if (ret != null) {
ret.addSubGraph(factory.generateStateGraph(gname));
}
}
return ret;
}

View File

@ -803,7 +803,10 @@ private static void constructProcessSMAPInfo(ProcessTreeSmapMemInfo pInfo,
if (LOG.isDebugEnabled()) {
LOG.debug("MemInfo : " + key + " : Value : " + value);
}
memoryMappingInfo.setMemInfo(key, value);
if (memoryMappingInfo != null) {
memoryMappingInfo.setMemInfo(key, value);
}
}
} catch (Throwable t) {
LOG

View File

@ -603,7 +603,7 @@ public void handle(ApplicationEvent event) {
} catch (InvalidStateTransitionException e) {
LOG.warn("Can't handle this event at current state", e);
}
if (oldState != newState) {
if (newState != null && oldState != newState) {
LOG.info("Application " + applicationID + " transitioned from "
+ oldState + " to " + newState);
}

View File

@ -1680,7 +1680,7 @@ public void handle(ContainerEvent event) {
+ oldState + "], eventType: [" + event.getType() + "]," +
" container: [" + containerID + "]", e);
}
if (oldState != newState) {
if (newState != null && oldState != newState) {
LOG.info("Container " + containerID + " transitioned from "
+ oldState
+ " to " + newState);

View File

@ -626,15 +626,16 @@ public PrivilegedOperation commitBatchToTempFile()
try {
File tcCmds = File.createTempFile(TMP_FILE_PREFIX, TMP_FILE_SUFFIX, new
File(tmpDirPath));
Writer writer = new OutputStreamWriter(new FileOutputStream(tcCmds),
"UTF-8");
PrintWriter printWriter = new PrintWriter(writer);
for (String command : commands) {
printWriter.println(command);
try (
Writer writer = new OutputStreamWriter(new FileOutputStream(tcCmds),
"UTF-8");
PrintWriter printWriter = new PrintWriter(writer)) {
for (String command : commands) {
printWriter.println(command);
}
}
printWriter.close();
operation.appendArgs(tcCmds.getAbsolutePath());
return operation;

View File

@ -200,7 +200,7 @@ public void handle(ResourceEvent event) {
} catch (InvalidStateTransitionException e) {
LOG.warn("Can't handle this event at current state", e);
}
if (oldState != newState) {
if (newState != null && oldState != newState) {
if (LOG.isDebugEnabled()) {
LOG.debug("Resource " + resourcePath + (localPath != null ?
"(->" + localPath + ")": "") + " transitioned from " + oldState

View File

@ -1051,6 +1051,7 @@ LocalizerHeartbeatResponse processHeartbeat(
LOG.error(
"Got exception in parsing URL of LocalResource:"
+ rsrc.getResource(), e);
continue;
}
LocalizerResourceRequestEvent assoc = scheduled.get(req);
if (assoc == null) {