YARN-11419. Remove redundant exception capture in NMClientAsyncImpl and improve readability in ContainerShellWebSocket, etc (#5309)

Co-authored-by: smallzhongfeng <982458633@qq.com>
Reviewed-by: Shilun Fan <slfan1989@apache.org>
Signed-off-by: Shilun Fan <slfan1989@apache.org>
This commit is contained in:
jokercurry 2023-02-04 10:29:19 +08:00 committed by GitHub
parent bce388fd3f
commit dad73b76c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 27 deletions

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.yarn.client.api;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
@ -62,7 +62,7 @@ public class ContainerShellWebSocket {
session.getRemote().flush(); session.getRemote().flush();
sttySet = true; sttySet = true;
} }
terminal.output().write(message.getBytes(Charset.forName("UTF-8"))); terminal.output().write(message.getBytes(StandardCharsets.UTF_8));
terminal.output().flush(); terminal.output().flush();
} }

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.yarn.client.api.async.impl; package org.apache.hadoop.yarn.client.api.async.impl;
import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
@ -51,7 +50,6 @@ import org.apache.hadoop.yarn.client.api.impl.NMClientImpl;
import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.event.AbstractEvent; import org.apache.hadoop.yarn.event.AbstractEvent;
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.ipc.RPCUtil; import org.apache.hadoop.yarn.ipc.RPCUtil;
import org.apache.hadoop.yarn.state.InvalidStateTransitionException; import org.apache.hadoop.yarn.state.InvalidStateTransitionException;
import org.apache.hadoop.yarn.state.MultipleArcTransition; import org.apache.hadoop.yarn.state.MultipleArcTransition;
@ -636,12 +634,8 @@ public class NMClientAsyncImpl extends NMClientAsync {
+ "Container " + containerId, thr); + "Container " + containerId, thr);
} }
return ContainerState.RUNNING; return ContainerState.RUNNING;
} catch (YarnException e) { } catch (Throwable e) {
return onExceptionRaised(container, event, e); return onExceptionRaised(container, event, e);
} catch (IOException e) {
return onExceptionRaised(container, event, e);
} catch (Throwable t) {
return onExceptionRaised(container, event, t);
} }
} }
@ -854,12 +848,8 @@ public class NMClientAsyncImpl extends NMClientAsync {
+ "Container " + event.getContainerId(), thr); + "Container " + event.getContainerId(), thr);
} }
return ContainerState.DONE; return ContainerState.DONE;
} catch (YarnException e) { } catch (Throwable e) {
return onExceptionRaised(container, event, e); return onExceptionRaised(container, event, e);
} catch (IOException e) {
return onExceptionRaised(container, event, e);
} catch (Throwable t) {
return onExceptionRaised(container, event, t);
} }
} }
@ -966,12 +956,8 @@ public class NMClientAsyncImpl extends NMClientAsync {
"Unchecked exception is thrown from onContainerStatusReceived" + "Unchecked exception is thrown from onContainerStatusReceived" +
" for Container " + event.getContainerId(), thr); " for Container " + event.getContainerId(), thr);
} }
} catch (YarnException e) { } catch (Throwable e) {
onExceptionRaised(containerId, e); onExceptionRaised(containerId, e);
} catch (IOException e) {
onExceptionRaised(containerId, e);
} catch (Throwable t) {
onExceptionRaised(containerId, t);
} }
} else { } else {
StatefulContainer container = containers.get(containerId); StatefulContainer container = containers.get(containerId);

View File

@ -158,14 +158,8 @@ public class SharedCacheClientImpl extends SharedCacheClient {
public String getFileChecksum(Path sourceFile) public String getFileChecksum(Path sourceFile)
throws IOException { throws IOException {
FileSystem fs = sourceFile.getFileSystem(this.conf); FileSystem fs = sourceFile.getFileSystem(this.conf);
FSDataInputStream in = null; try (FSDataInputStream in = fs.open(sourceFile)) {
try {
in = fs.open(sourceFile);
return this.checksum.computeChecksum(in); return this.checksum.computeChecksum(in);
} finally {
if (in != null) {
in.close();
}
} }
} }
} }

View File

@ -145,7 +145,7 @@ public abstract class YarnClientUtils {
// Now we only support one property, which is exclusive, so check if // Now we only support one property, which is exclusive, so check if
// key = exclusive and value = {true/false} // key = exclusive and value = {true/false}
if (key.equals("exclusive") if ("exclusive".equals(key)
&& ImmutableSet.of("true", "false").contains(value)) { && ImmutableSet.of("true", "false").contains(value)) {
exclusive = Boolean.parseBoolean(value); exclusive = Boolean.parseBoolean(value);
} else { } else {