From 575d8888a5f3bd2222b65eba141370084777f988 Mon Sep 17 00:00:00 2001 From: Todd Lisonbee Date: Wed, 10 May 2017 16:34:49 -0700 Subject: [PATCH] Fixing issue where traceId was missing in the logs https://github.com/Nike-Inc/cerberus-management-service/issues/35 --- .../endpoints/admin/GetSDBMetadata.java | 20 ++++++++++++---- .../endpoints/admin/PutSDBMetadata.java | 24 ++++++++++++------- .../AuthenticateIamPrincipal.java | 20 ++++++++++------ .../authentication/AuthenticateIamRole.java | 20 ++++++++++------ .../authentication/AuthenticateUser.java | 18 +++++++------- .../endpoints/authentication/MfaCheck.java | 6 ++++- .../authentication/RefreshUserToken.java | 7 +++--- .../endpoints/authentication/RevokeToken.java | 6 ++++- .../endpoints/category/CreateCategory.java | 12 +++++----- .../endpoints/category/DeleteCategory.java | 8 +++---- .../endpoints/category/GetAllCategories.java | 11 +++++---- .../endpoints/category/GetCategory.java | 15 ++++++------ .../cerberus/endpoints/role/GetAllRoles.java | 5 +++- .../nike/cerberus/endpoints/role/GetRole.java | 9 +++++-- .../endpoints/sdb/CreateSafeDepositBoxV1.java | 6 ++++- .../endpoints/sdb/CreateSafeDepositBoxV2.java | 10 +++++--- .../endpoints/sdb/DeleteSafeDepositBox.java | 7 ++++-- .../endpoints/sdb/GetSafeDepositBoxV1.java | 6 ++++- .../endpoints/sdb/GetSafeDepositBoxV2.java | 6 ++++- .../endpoints/sdb/GetSafeDepositBoxes.java | 7 ++++-- .../endpoints/sdb/UpdateSafeDepositBoxV1.java | 10 ++++++-- .../endpoints/sdb/UpdateSafeDepositBoxV2.java | 10 ++++++-- 22 files changed, 163 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/nike/cerberus/endpoints/admin/GetSDBMetadata.java b/src/main/java/com/nike/cerberus/endpoints/admin/GetSDBMetadata.java index 072ebff4a..f6b83af36 100644 --- a/src/main/java/com/nike/cerberus/endpoints/admin/GetSDBMetadata.java +++ b/src/main/java/com/nike/cerberus/endpoints/admin/GetSDBMetadata.java @@ -25,6 +25,8 @@ import com.nike.cerberus.service.MetadataService; import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; +import com.nike.riposte.server.http.impl.FullResponseInfo; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -57,15 +59,20 @@ public CompletableFuture> doExecute(final Reques final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx, final SecurityContext securityContext) { - return CompletableFuture.supplyAsync( - () -> ResponseInfo.newBuilder(metadataService.getSDBMetadata(getLimit(request), getOffset(request))) - .build(), longRunningTaskExecutor + AsyncNettyHelper.supplierWithTracingAndMdc(() -> getMetadata(request), ctx), + longRunningTaskExecutor ); } + private FullResponseInfo getMetadata(RequestInfo request) { + return ResponseInfo.newBuilder(metadataService.getSDBMetadata(getLimit(request), getOffset(request))) + .build(); + } + /** * Parses and validates limit query param + * * @param request The request * @return default or parsed vaule */ @@ -83,10 +90,11 @@ protected int getLimit(RequestInfo request) { /** * validates that the limit query is a valid number >= 1 + * * @param limitQueryValue */ protected void validateLimitQuery(String limitQueryValue) { - if (! StringUtils.isNumeric(limitQueryValue) || Integer.parseInt(limitQueryValue) < 1) { + if (!StringUtils.isNumeric(limitQueryValue) || Integer.parseInt(limitQueryValue) < 1) { throw ApiException.newBuilder() .withApiErrors(new ApiErrorBase( DefaultApiError.INVALID_QUERY_PARAMS.getName(), @@ -99,6 +107,7 @@ protected void validateLimitQuery(String limitQueryValue) { /** * Parses and validates offset query param + * * @param request The request * @return default or parsed vaule */ @@ -116,10 +125,11 @@ protected int getOffset(RequestInfo request) { /** * Validates that the offset value is a number that is >= 0 + * * @param offsetQueryValue */ protected void validateOffsetQuery(String offsetQueryValue) { - if (! StringUtils.isNumeric(offsetQueryValue)) { + if (!StringUtils.isNumeric(offsetQueryValue)) { throw ApiException.newBuilder() .withApiErrors(new ApiErrorBase( DefaultApiError.INVALID_QUERY_PARAMS.getName(), diff --git a/src/main/java/com/nike/cerberus/endpoints/admin/PutSDBMetadata.java b/src/main/java/com/nike/cerberus/endpoints/admin/PutSDBMetadata.java index 479583640..87142048f 100644 --- a/src/main/java/com/nike/cerberus/endpoints/admin/PutSDBMetadata.java +++ b/src/main/java/com/nike/cerberus/endpoints/admin/PutSDBMetadata.java @@ -23,6 +23,7 @@ import com.nike.cerberus.service.MetadataService; import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -54,19 +55,24 @@ public CompletableFuture> doExecute(RequestInfo ChannelHandlerContext ctx, SecurityContext securityContext) { - return CompletableFuture.supplyAsync(() -> { - VaultAuthPrincipal vaultAuthPrincipal = (VaultAuthPrincipal) securityContext.getUserPrincipal(); + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> restoreSdbMetadata(request, securityContext), ctx), + longRunningTaskExecutor + ); + } + + private ResponseInfo restoreSdbMetadata(RequestInfo request, SecurityContext securityContext) { + VaultAuthPrincipal vaultAuthPrincipal = (VaultAuthPrincipal) securityContext.getUserPrincipal(); - String principal = vaultAuthPrincipal.getName(); + String principal = vaultAuthPrincipal.getName(); - log.info("Metadata Restore Event: the principal {} is attempting to restore sdb name: '{}'", principal, request.getContent().getName()); + log.info("Metadata Restore Event: the principal {} is attempting to restore sdb name: '{}'", principal, request.getContent().getName()); - metadataService.restoreMetadata(request.getContent(), principal); + metadataService.restoreMetadata(request.getContent(), principal); - return ResponseInfo.newBuilder() - .withHttpStatusCode(HttpResponseStatus.NO_CONTENT.code()) - .build(); - }, longRunningTaskExecutor); + return ResponseInfo.newBuilder() + .withHttpStatusCode(HttpResponseStatus.NO_CONTENT.code()) + .build(); } @Override diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamPrincipal.java b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamPrincipal.java index 3f3965848..fdd2320ec 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamPrincipal.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamPrincipal.java @@ -17,12 +17,13 @@ package com.nike.cerberus.endpoints.authentication; -import com.nike.cerberus.domain.IamRoleAuthResponse; import com.nike.cerberus.domain.IamPrincipalCredentials; +import com.nike.cerberus.domain.IamRoleAuthResponse; import com.nike.cerberus.service.AuthenticationService; import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -52,13 +53,18 @@ public AuthenticateIamPrincipal(final AuthenticationService authenticationServic public CompletableFuture> execute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> { - IamPrincipalCredentials credentials = request.getContent(); - log.info("IAM Auth Event: the IAM principal {} in attempting to authenticate in region {}", - credentials.getIamPrincipalArn(), credentials.getRegion()); + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> authenticate(request), ctx), + longRunningTaskExecutor + ); + } + + private ResponseInfo authenticate(RequestInfo request) { + IamPrincipalCredentials credentials = request.getContent(); + log.info("IAM Auth Event: the IAM principal {} in attempting to authenticate in region {}", + credentials.getIamPrincipalArn(), credentials.getRegion()); - return ResponseInfo.newBuilder(authenticationService.authenticate(request.getContent())).build(); - }, longRunningTaskExecutor); + return ResponseInfo.newBuilder(authenticationService.authenticate(request.getContent())).build(); } @Override diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRole.java b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRole.java index 99aa83b3b..e7dfaa035 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRole.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRole.java @@ -23,6 +23,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -53,15 +54,20 @@ public AuthenticateIamRole(final AuthenticationService authenticationService) { public CompletableFuture> execute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> { - IamRoleCredentials credentials = request.getContent(); - log.info("IAM Auth Event: the IAM principal {} in attempting to authenticate in region {}", - String.format(AwsIamRoleArnParser.AWS_IAM_ROLE_ARN_TEMPLATE, - credentials.getAccountId(), credentials.getRoleName()), credentials.getRegion()); + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> authenticate(request), ctx), + longRunningTaskExecutor + ); - return ResponseInfo.newBuilder(authenticationService.authenticate(request.getContent())).build(); - }, longRunningTaskExecutor); + } + + private ResponseInfo authenticate(RequestInfo request) { + IamRoleCredentials credentials = request.getContent(); + log.info("IAM Auth Event: the IAM principal {} in attempting to authenticate in region {}", + String.format(AwsIamRoleArnParser.AWS_IAM_ROLE_ARN_TEMPLATE, + credentials.getAccountId(), credentials.getRoleName()), credentials.getRegion()); + return ResponseInfo.newBuilder(authenticationService.authenticate(request.getContent())).build(); } @Override diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateUser.java b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateUser.java index d456ab72f..299e4ba18 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateUser.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateUser.java @@ -24,6 +24,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -57,18 +58,19 @@ public CompletableFuture> execute(final RequestInfo { - final UserCredentials credentials = - extractCredentials(request.getHeaders().get(HttpHeaders.AUTHORIZATION)); - - log.info("User Auth Event: the principal: {} is attempting to authenticate", credentials.getUsername()); - - return ResponseInfo.newBuilder(authenticationService.authenticate(credentials)).build(); - }, + AsyncNettyHelper.supplierWithTracingAndMdc(() -> authenticate(request), ctx), longRunningTaskExecutor ); } + private ResponseInfo authenticate(RequestInfo request) { + final UserCredentials credentials = extractCredentials(request.getHeaders().get(HttpHeaders.AUTHORIZATION)); + + log.info("User Auth Event: the principal: {} is attempting to authenticate", credentials.getUsername()); + + return ResponseInfo.newBuilder(authenticationService.authenticate(credentials)).build(); + } + @Override public Matcher requestMatcher() { return Matcher.match("/v2/auth/user", HttpMethod.GET); diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/MfaCheck.java b/src/main/java/com/nike/cerberus/endpoints/authentication/MfaCheck.java index 27dfcade3..b9d82ac1b 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/MfaCheck.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/MfaCheck.java @@ -22,6 +22,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -47,7 +48,10 @@ public CompletableFuture> execute(final RequestInfo ResponseInfo.newBuilder(authenticationService.mfaCheck(request.getContent())).build(), + AsyncNettyHelper.supplierWithTracingAndMdc( + () -> ResponseInfo.newBuilder(authenticationService.mfaCheck(request.getContent())).build(), + ctx + ), longRunningTaskExecutor ); } diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/RefreshUserToken.java b/src/main/java/com/nike/cerberus/endpoints/authentication/RefreshUserToken.java index e3411c67a..87b32f574 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/RefreshUserToken.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/RefreshUserToken.java @@ -25,6 +25,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -53,10 +54,10 @@ public RefreshUserToken(final AuthenticationService authenticationService) { @Override public CompletableFuture> execute(final RequestInfo request, - final Executor longRunningTaskExecutor, - final ChannelHandlerContext ctx) { + final Executor longRunningTaskExecutor, + final ChannelHandlerContext ctx) { return CompletableFuture.supplyAsync( - () -> getRefreshedUserToken(request), + AsyncNettyHelper.supplierWithTracingAndMdc(() -> getRefreshedUserToken(request), ctx), longRunningTaskExecutor ); } diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/RevokeToken.java b/src/main/java/com/nike/cerberus/endpoints/authentication/RevokeToken.java index ccef04de2..84d0f5320 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/RevokeToken.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/RevokeToken.java @@ -24,6 +24,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -55,7 +56,10 @@ public RevokeToken(final AuthenticationService authenticationService) { public CompletableFuture> execute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> revokeToken(request), longRunningTaskExecutor); + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> revokeToken(request), ctx), + longRunningTaskExecutor + ); } public ResponseInfo revokeToken(RequestInfo request) { diff --git a/src/main/java/com/nike/cerberus/endpoints/category/CreateCategory.java b/src/main/java/com/nike/cerberus/endpoints/category/CreateCategory.java index 1c0cfc887..fc8bca4b7 100644 --- a/src/main/java/com/nike/cerberus/endpoints/category/CreateCategory.java +++ b/src/main/java/com/nike/cerberus/endpoints/category/CreateCategory.java @@ -23,6 +23,7 @@ import com.nike.cerberus.service.CategoryService; import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; @@ -53,11 +54,10 @@ public CreateCategory(final CategoryService categoryService) { public CompletableFuture> doExecute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx, - final SecurityContext securityContext - ) { + final SecurityContext securityContext) { return CompletableFuture.supplyAsync( - () -> createCategory(request.getContent(), securityContext, CATEGORY_PATH), - longRunningTaskExecutor + AsyncNettyHelper.supplierWithTracingAndMdc(() -> createCategory(request.getContent(), securityContext, CATEGORY_PATH), ctx), + longRunningTaskExecutor ); } @@ -71,8 +71,8 @@ public ResponseInfo createCategory(final Category category, final String id = categoryService.createCategory(category, securityContext.getUserPrincipal().getName()); final String location = basePathNoId + "/" + id; return ResponseInfo.newBuilder().withHeaders(new DefaultHttpHeaders().set(LOCATION, location)) - .withHttpStatusCode(201) - .build(); + .withHttpStatusCode(201) + .build(); } @Override diff --git a/src/main/java/com/nike/cerberus/endpoints/category/DeleteCategory.java b/src/main/java/com/nike/cerberus/endpoints/category/DeleteCategory.java index d9e885278..6fe9d4081 100644 --- a/src/main/java/com/nike/cerberus/endpoints/category/DeleteCategory.java +++ b/src/main/java/com/nike/cerberus/endpoints/category/DeleteCategory.java @@ -20,6 +20,7 @@ import com.nike.cerberus.service.CategoryService; import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -48,11 +49,10 @@ public DeleteCategory(final CategoryService categoryService) { public CompletableFuture> doExecute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx, - final SecurityContext securityContext - ) { + final SecurityContext securityContext) { return CompletableFuture.supplyAsync( - () -> deleteCategory(request.getPathParam(PATH_PARAM_ID)), - longRunningTaskExecutor + AsyncNettyHelper.supplierWithTracingAndMdc(() -> deleteCategory(request.getPathParam(PATH_PARAM_ID)), ctx), + longRunningTaskExecutor ); } diff --git a/src/main/java/com/nike/cerberus/endpoints/category/GetAllCategories.java b/src/main/java/com/nike/cerberus/endpoints/category/GetAllCategories.java index 67ca1da49..3b048d12d 100644 --- a/src/main/java/com/nike/cerberus/endpoints/category/GetAllCategories.java +++ b/src/main/java/com/nike/cerberus/endpoints/category/GetAllCategories.java @@ -21,6 +21,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -43,12 +44,12 @@ public GetAllCategories(final CategoryService categoryService) { } @Override - public CompletableFuture>> execute( - RequestInfo request, Executor longRunningTaskExecutor, ChannelHandlerContext ctx - ) { + public CompletableFuture>> execute(RequestInfo request, + Executor longRunningTaskExecutor, + ChannelHandlerContext ctx) { return CompletableFuture.supplyAsync( - this::getAllCategories, - longRunningTaskExecutor + AsyncNettyHelper.supplierWithTracingAndMdc(this::getAllCategories, ctx), + longRunningTaskExecutor ); } diff --git a/src/main/java/com/nike/cerberus/endpoints/category/GetCategory.java b/src/main/java/com/nike/cerberus/endpoints/category/GetCategory.java index e8010500d..9bb6a1eb4 100644 --- a/src/main/java/com/nike/cerberus/endpoints/category/GetCategory.java +++ b/src/main/java/com/nike/cerberus/endpoints/category/GetCategory.java @@ -21,6 +21,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -46,14 +47,14 @@ public GetCategory(final CategoryService categoryService) { } @Override - public CompletableFuture> execute( - RequestInfo request, Executor longRunningTaskExecutor, ChannelHandlerContext ctx - ) { + public CompletableFuture> execute(RequestInfo request, + Executor longRunningTaskExecutor, + ChannelHandlerContext ctx) { return CompletableFuture.supplyAsync( - () -> { - String id = request.getPathParam(PATH_PARAM_ID); - return getCategory(id); - }, + AsyncNettyHelper.supplierWithTracingAndMdc(() -> { + String id = request.getPathParam(PATH_PARAM_ID); + return getCategory(id); + }, ctx), longRunningTaskExecutor ); } diff --git a/src/main/java/com/nike/cerberus/endpoints/role/GetAllRoles.java b/src/main/java/com/nike/cerberus/endpoints/role/GetAllRoles.java index 212f54379..d458d09fe 100644 --- a/src/main/java/com/nike/cerberus/endpoints/role/GetAllRoles.java +++ b/src/main/java/com/nike/cerberus/endpoints/role/GetAllRoles.java @@ -21,6 +21,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -47,7 +48,9 @@ public CompletableFuture>> execute(final RequestInfo ResponseInfo.newBuilder(roleService.getAllRoles()).build(), longRunningTaskExecutor); + AsyncNettyHelper.supplierWithTracingAndMdc(() -> ResponseInfo.newBuilder(roleService.getAllRoles()).build(), ctx), + longRunningTaskExecutor + ); } @Override diff --git a/src/main/java/com/nike/cerberus/endpoints/role/GetRole.java b/src/main/java/com/nike/cerberus/endpoints/role/GetRole.java index 0f488d9c9..dac81b468 100644 --- a/src/main/java/com/nike/cerberus/endpoints/role/GetRole.java +++ b/src/main/java/com/nike/cerberus/endpoints/role/GetRole.java @@ -22,6 +22,7 @@ import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; import com.nike.riposte.server.http.impl.FullResponseInfo; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -47,9 +48,13 @@ public GetRole(RoleService roleService) { } @Override - public CompletableFuture> execute(RequestInfo request, Executor longRunningTaskExecutor, ChannelHandlerContext ctx) { + public CompletableFuture> execute(RequestInfo request, + Executor longRunningTaskExecutor, + ChannelHandlerContext ctx) { return CompletableFuture.supplyAsync( - () -> getRole(request.getPathParam(PATH_PARAM_ID)), longRunningTaskExecutor); + AsyncNettyHelper.supplierWithTracingAndMdc(() -> getRole(request.getPathParam(PATH_PARAM_ID)), ctx), + longRunningTaskExecutor + ); } public FullResponseInfo getRole(final String id) { diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBoxV1.java b/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBoxV1.java index 6971ae21d..462f1aaed 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBoxV1.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBoxV1.java @@ -26,6 +26,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; @@ -66,7 +67,10 @@ public CreateSafeDepositBoxV1(final SafeDepositBoxService safeDepositBoxService) public CompletableFuture>> execute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> createSafeDepositBox(request, BASE_PATH), longRunningTaskExecutor); + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> createSafeDepositBox(request, BASE_PATH), ctx), + longRunningTaskExecutor + ); } private ResponseInfo> createSafeDepositBox(final RequestInfo request, diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBoxV2.java b/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBoxV2.java index fc9f40351..d4a719eb9 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBoxV2.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBoxV2.java @@ -28,6 +28,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; @@ -61,9 +62,12 @@ public CreateSafeDepositBoxV2(final SafeDepositBoxService safeDepositBoxService) @Override public CompletableFuture> execute(final RequestInfo request, - final Executor longRunningTaskExecutor, - final ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> createSafeDepositBox(request, BASE_PATH), longRunningTaskExecutor); + final Executor longRunningTaskExecutor, + final ChannelHandlerContext ctx) { + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> createSafeDepositBox(request, BASE_PATH), ctx), + longRunningTaskExecutor + ); } private ResponseInfo createSafeDepositBox(final RequestInfo request, diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/DeleteSafeDepositBox.java b/src/main/java/com/nike/cerberus/endpoints/sdb/DeleteSafeDepositBox.java index a74bceee6..0eef88f87 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/DeleteSafeDepositBox.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/DeleteSafeDepositBox.java @@ -25,6 +25,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import com.nike.riposte.util.MultiMatcher; import io.netty.channel.ChannelHandlerContext; @@ -43,7 +44,6 @@ /** * Endpoint for deleting a safe deposit box. */ -@Deprecated public class DeleteSafeDepositBox extends StandardEndpoint { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -59,7 +59,10 @@ public DeleteSafeDepositBox(final SafeDepositBoxService safeDepositBoxService) { @Override public CompletableFuture> execute(RequestInfo request, Executor longRunningTaskExecutor, ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> deleteSafeDepositBox(request), longRunningTaskExecutor); + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> deleteSafeDepositBox(request), ctx), + longRunningTaskExecutor + ); } private ResponseInfo deleteSafeDepositBox(final RequestInfo request) { diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxV1.java b/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxV1.java index edd0b7163..2295468b7 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxV1.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxV1.java @@ -26,6 +26,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -58,7 +59,10 @@ public GetSafeDepositBoxV1(final SafeDepositBoxService safeDepositBoxService) { public CompletableFuture> execute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> getSafeDepositBox(request), longRunningTaskExecutor); + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> getSafeDepositBox(request), ctx), + longRunningTaskExecutor + ); } public ResponseInfo getSafeDepositBox(final RequestInfo request) { diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxV2.java b/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxV2.java index 5b4fd8b39..d86a08810 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxV2.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxV2.java @@ -28,6 +28,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; @@ -59,7 +60,10 @@ public GetSafeDepositBoxV2(final SafeDepositBoxService safeDepositBoxService) { public CompletableFuture> execute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> getSafeDepositBox(request), longRunningTaskExecutor); + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> getSafeDepositBox(request), ctx), + longRunningTaskExecutor + ); } public ResponseInfo getSafeDepositBox(final RequestInfo request) { diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxes.java b/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxes.java index d036d3d0a..b8ef841c9 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxes.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxes.java @@ -26,6 +26,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import com.nike.riposte.util.MultiMatcher; import io.netty.channel.ChannelHandlerContext; @@ -44,7 +45,6 @@ * Extracts the user groups from the security context for the request and returns any safe deposit boxes * associated with that list of user groups. */ -@Deprecated public class GetSafeDepositBoxes extends StandardEndpoint> { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -60,7 +60,10 @@ public GetSafeDepositBoxes(final SafeDepositBoxService safeDepositBoxService) { public CompletableFuture>> execute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> getSafeDepositBoxes(request), longRunningTaskExecutor); + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> getSafeDepositBoxes(request), ctx), + longRunningTaskExecutor + ); } public ResponseInfo> getSafeDepositBoxes(final RequestInfo request) { diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBoxV1.java b/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBoxV1.java index 423167a85..57ff3da47 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBoxV1.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBoxV1.java @@ -26,6 +26,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; @@ -58,8 +59,13 @@ public UpdateSafeDepositBoxV1(final SafeDepositBoxService safeDepositBoxService) } @Override - public CompletableFuture> execute(RequestInfo request, Executor longRunningTaskExecutor, ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> updateSafeDepositBox(request), longRunningTaskExecutor); + public CompletableFuture> execute(RequestInfo request, + Executor longRunningTaskExecutor, + ChannelHandlerContext ctx) { + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> updateSafeDepositBox(request), ctx), + longRunningTaskExecutor + ); } private ResponseInfo updateSafeDepositBox(final RequestInfo request) { diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBoxV2.java b/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBoxV2.java index 2ba0aafed..a3ef86499 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBoxV2.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBoxV2.java @@ -27,6 +27,7 @@ import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; +import com.nike.riposte.util.AsyncNettyHelper; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; @@ -54,8 +55,13 @@ public UpdateSafeDepositBoxV2(final SafeDepositBoxService safeDepositBoxService) } @Override - public CompletableFuture> execute(RequestInfo request, Executor longRunningTaskExecutor, ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> updateSafeDepositBox(request), longRunningTaskExecutor); + public CompletableFuture> execute(RequestInfo request, + Executor longRunningTaskExecutor, + ChannelHandlerContext ctx) { + return CompletableFuture.supplyAsync( + AsyncNettyHelper.supplierWithTracingAndMdc(() -> updateSafeDepositBox(request), ctx), + longRunningTaskExecutor + ); } private ResponseInfo updateSafeDepositBox(final RequestInfo request) {