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,10 +192,10 @@ public class UnmanagedAMLauncher {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
tokenFile.deleteOnExit(); tokenFile.deleteOnExit();
DataOutputStream os = new DataOutputStream(new FileOutputStream(tokenFile, try (DataOutputStream os = new DataOutputStream(
true)); new FileOutputStream(tokenFile, true))) {
credentials.writeTokenStorageToStream(os); credentials.writeTokenStorageToStream(os);
os.close(); }
Map<String, String> env = System.getenv(); Map<String, String> env = System.getenv();
ArrayList<String> envAMList = new ArrayList<String>(); ArrayList<String> envAMList = new ArrayList<String>();

View File

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

View File

@ -805,7 +805,7 @@ public class TimelineClientImpl extends TimelineClient {
error.getErrorCode()); error.getErrorCode());
} }
} }
} else if (type.equals(DOMAIN_DATA_TYPE)) { } else if (type.equals(DOMAIN_DATA_TYPE) && domains != null) {
boolean hasError = false; boolean hasError = false;
for (TimelineDomain domain : domains.getDomains()) { for (TimelineDomain domain : domains.getDomains()) {
try { try {

View File

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

View File

@ -49,7 +49,9 @@ public class VisualizeStateMachine {
if (gname.endsWith("Impl")) { if (gname.endsWith("Impl")) {
gname = gname.substring(0, gname.length()-4); gname = gname.substring(0, gname.length()-4);
} }
ret.addSubGraph(factory.generateStateGraph(gname)); if (ret != null) {
ret.addSubGraph(factory.generateStateGraph(gname));
}
} }
return ret; return ret;
} }

View File

@ -803,7 +803,10 @@ public class ProcfsBasedProcessTree extends ResourceCalculatorProcessTree {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("MemInfo : " + key + " : Value : " + value); LOG.debug("MemInfo : " + key + " : Value : " + value);
} }
memoryMappingInfo.setMemInfo(key, value);
if (memoryMappingInfo != null) {
memoryMappingInfo.setMemInfo(key, value);
}
} }
} catch (Throwable t) { } catch (Throwable t) {
LOG LOG

View File

@ -603,7 +603,7 @@ public class ApplicationImpl implements Application {
} catch (InvalidStateTransitionException e) { } catch (InvalidStateTransitionException e) {
LOG.warn("Can't handle this event at current state", 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 " LOG.info("Application " + applicationID + " transitioned from "
+ oldState + " to " + newState); + oldState + " to " + newState);
} }

View File

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

View File

@ -626,15 +626,16 @@ import java.util.regex.Pattern;
try { try {
File tcCmds = File.createTempFile(TMP_FILE_PREFIX, TMP_FILE_SUFFIX, new File tcCmds = File.createTempFile(TMP_FILE_PREFIX, TMP_FILE_SUFFIX, new
File(tmpDirPath)); File(tmpDirPath));
Writer writer = new OutputStreamWriter(new FileOutputStream(tcCmds),
"UTF-8");
PrintWriter printWriter = new PrintWriter(writer);
for (String command : commands) { try (
printWriter.println(command); 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()); operation.appendArgs(tcCmds.getAbsolutePath());
return operation; return operation;

View File

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

View File

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