use of com.google.gerrit.server.git.TracingHook in project gerrit by GerritCodeReview.
the class Upload method runImpl.
@Override
protected void runImpl() throws IOException, Failure {
PermissionBackend.ForProject perm = permissionBackend.user(user).project(projectState.getNameKey());
try {
perm.check(ProjectPermission.RUN_UPLOAD_PACK);
} catch (AuthException e) {
throw new Failure(1, "fatal: upload-pack not permitted on this server", e);
} catch (PermissionBackendException e) {
throw new Failure(1, "fatal: unable to check permissions ", e);
}
Repository permissionAwareRepo = PermissionAwareRepositoryManager.wrap(repo, perm);
UploadPack up = new UploadPack(permissionAwareRepo);
up.setPackConfig(config.getPackConfig());
up.setTimeout(config.getTimeout());
up.setPostUploadHook(PostUploadHookChain.newChain(Lists.newArrayList(postUploadHooks)));
if (projectState.isAllUsers()) {
up.setAdvertiseRefsHook(usersSelfAdvertiseRefsHook);
}
if (extraParameters != null) {
up.setExtraParameters(ImmutableList.copyOf(extraParameters));
}
List<PreUploadHook> allPreUploadHooks = Lists.newArrayList(preUploadHooks);
allPreUploadHooks.add(uploadValidatorsFactory.create(project, permissionAwareRepo, session.getRemoteAddressAsString()));
up.setPreUploadHook(PreUploadHookChain.newChain(allPreUploadHooks));
for (UploadPackInitializer initializer : uploadPackInitializers) {
initializer.init(projectState.getNameKey(), up);
}
try (TraceContext traceContext = TraceContext.open();
TracingHook tracingHook = new TracingHook()) {
RequestInfo requestInfo = RequestInfo.builder(RequestInfo.RequestType.GIT_UPLOAD, user, traceContext).project(projectState.getNameKey()).build();
requestListeners.runEach(l -> l.onRequest(requestInfo));
up.setProtocolV2Hook(tracingHook);
up.upload(in, out, err);
session.setPeerAgent(up.getPeerUserAgent());
stats = up.getStatistics();
} catch (UploadValidationException e) {
// internal server error to the client.
if (!e.isOutput()) {
up.sendMessage(e.getMessage());
}
}
}
Aggregations