MCPcopy Create free account
hub / github.com/GerritCodeReview/gerrit / start

Method start

java/com/google/gerrit/sshd/SshCommand.java:64–119  ·  view source on GitHub ↗
(ChannelSession channel, Environment env)

Source from the content-addressed store, hash-verified

62 protected PrintWriter stderr;
63
64 @Override
65 public void start(ChannelSession channel, Environment env) throws IOException {
66 String sessionId = HexFormat.fromInt(getSession().getSessionId());
67 startThread(
68 () -> {
69 try (PerThreadCache ignored = PerThreadCache.create();
70 DynamicOptions pluginOptions = new DynamicOptions(injector, dynamicBeans)) {
71 parseCommandLine(pluginOptions);
72 stdout = toPrintWriter(out);
73 stderr = toPrintWriter(err);
74 try (TraceContext traceContext = enableTracing();
75 PerformanceLogContext performanceLogContext =
76 new PerformanceLogContext(config, performanceLoggers)) {
77 traceContext.addTag("SSH_SESSION", sessionId);
78 RequestInfo requestInfo =
79 RequestInfo.builder(RequestInfo.RequestType.SSH, getName(), user, traceContext)
80 .build();
81 Throwable error = null;
82 try (RequestStateContext requestStateContext =
83 RequestStateContext.open()
84 .setPerformanceSummaryProvider(performanceLogContext)
85 .addRequestStateProvider(
86 deadlineCheckerFactory.create(requestInfo, deadline))) {
87 requestListeners.runEach(l -> l.onRequest(requestInfo));
88 SshCommand.this.run();
89 } catch (InvalidDeadlineException e) {
90 error = e;
91 stderr.println(e.getMessage());
92 } catch (RuntimeException e) {
93 error = e;
94 Optional<RequestCancelledException> requestCancelledException =
95 RequestCancelledException.getFromCausalChain(e);
96 if (!requestCancelledException.isPresent()) {
97 Throwables.throwIfUnchecked(e);
98 }
99 cancellationMetrics.countCancelledRequest(
100 requestInfo, requestCancelledException.get().getCancellationReason());
101 StringBuilder msg =
102 new StringBuilder(requestCancelledException.get().formatCancellationReason());
103 if (requestCancelledException.get().getCancellationMessage().isPresent()) {
104 msg.append(
105 String.format(
106 " (%s)", requestCancelledException.get().getCancellationMessage().get()));
107 }
108 stderr.println(msg.toString());
109 } finally {
110 sshMetrics.countRequest(requestInfo, error);
111 }
112 } finally {
113 stdout.flush();
114 stderr.flush();
115 }
116 }
117 },
118 AccessPath.SSH_COMMAND);
119 }
120
121 protected abstract void run() throws UnloggedFailure, Failure, Exception;

Callers

nothing calls this directly

Calls 15

fromIntMethod · 0.95
createMethod · 0.95
enableTracingMethod · 0.95
builderMethod · 0.95
openMethod · 0.95
getFromCausalChainMethod · 0.95
startThreadMethod · 0.80
toPrintWriterMethod · 0.80
printlnMethod · 0.80
isPresentMethod · 0.80

Tested by

no test coverage detected