change InnerMethodName
This commit is contained in:
parent
6454f71672
commit
64fb289c40
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>maven-parent</artifactId>
|
<artifactId>maven-parent</artifactId>
|
||||||
<groupId>org.gcube.tools</groupId>
|
<groupId>org.gcube.tools</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.1.0</version>
|
||||||
<relativePath />
|
<relativePath />
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
|
|
|
@ -34,21 +34,21 @@ public class RequestAccounting extends RequestHandler {
|
||||||
|
|
||||||
String context = getContext(appContext);
|
String context = getContext(appContext);
|
||||||
|
|
||||||
if (InnerMethodName.instance.get() == null) {
|
if (InnerMethodName.get() == null) {
|
||||||
String calledMethod = e.request().getRequestURI().substring(e.request().getContextPath().length());
|
String calledMethod = e.request().getRequestURI().substring(e.request().getContextPath().length());
|
||||||
if (calledMethod.isEmpty())
|
if (calledMethod.isEmpty())
|
||||||
calledMethod = "/";
|
calledMethod = "/";
|
||||||
calledMethod = e.request().getMethod() + " " + calledMethod;
|
calledMethod = e.request().getMethod() + " " + calledMethod;
|
||||||
InnerMethodName.instance.set(calledMethod);
|
InnerMethodName.set(calledMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
String caller = SecretManagerProvider.instance.get() != null
|
String caller = SecretManagerProvider.get() != null
|
||||||
? SecretManagerProvider.instance.get().getOwner().getId()
|
? SecretManagerProvider.get().getOwner().getId()
|
||||||
: UNKNOWN;
|
: UNKNOWN;
|
||||||
startCallThreadLocal.set(System.currentTimeMillis());
|
startCallThreadLocal.set(System.currentTimeMillis());
|
||||||
|
|
||||||
log.info("REQUEST START ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} ", appContext.configuration().name(),
|
log.info("REQUEST START ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} ", appContext.configuration().name(),
|
||||||
appContext.configuration().group(), InnerMethodName.instance.get(), caller,
|
appContext.configuration().group(), InnerMethodName.get(), caller,
|
||||||
e.request().getRemoteHost(), context);
|
e.request().getRemoteHost(), context);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,8 @@ public class RequestAccounting extends RequestHandler {
|
||||||
|
|
||||||
String context = getContext(appContext);
|
String context = getContext(appContext);
|
||||||
|
|
||||||
String caller = SecretManagerProvider.instance.get() != null
|
String caller = SecretManagerProvider.get() != null
|
||||||
? SecretManagerProvider.instance.get().getOwner().getId()
|
? SecretManagerProvider.get().getOwner().getId()
|
||||||
: UNKNOWN;
|
: UNKNOWN;
|
||||||
String callerQualifier = UNKNOWN;
|
String callerQualifier = UNKNOWN;
|
||||||
// retieves caller Ip when there is a proxy
|
// retieves caller Ip when there is a proxy
|
||||||
|
@ -91,7 +91,7 @@ public class RequestAccounting extends RequestHandler {
|
||||||
|
|
||||||
log.info("REQUEST SERVED ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} {}(CODE {}) IN {} millis",
|
log.info("REQUEST SERVED ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} {}(CODE {}) IN {} millis",
|
||||||
appContext.configuration().name(), appContext.configuration().group(),
|
appContext.configuration().name(), appContext.configuration().group(),
|
||||||
InnerMethodName.instance.get(), caller, callerIp, context, success ? "SUCCEDED" : "FAILED",
|
InnerMethodName.get(), caller, callerIp, context, success ? "SUCCEDED" : "FAILED",
|
||||||
e.response().getStatus(), durationInMillis);
|
e.response().getStatus(), durationInMillis);
|
||||||
|
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
|
@ -99,7 +99,7 @@ public class RequestAccounting extends RequestHandler {
|
||||||
throw e1;
|
throw e1;
|
||||||
} finally {
|
} finally {
|
||||||
startCallThreadLocal.remove();
|
startCallThreadLocal.remove();
|
||||||
InnerMethodName.instance.reset();
|
InnerMethodName.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ public class RequestAccounting extends RequestHandler {
|
||||||
|
|
||||||
serviceUsageRecord.setHost(appContext.container().configuration().hostname() + ":"
|
serviceUsageRecord.setHost(appContext.container().configuration().hostname() + ":"
|
||||||
+ appContext.container().configuration().port());
|
+ appContext.container().configuration().port());
|
||||||
serviceUsageRecord.setCalledMethod(InnerMethodName.instance.get());
|
serviceUsageRecord.setCalledMethod(InnerMethodName.get());
|
||||||
serviceUsageRecord.setCallerHost(remoteHost);
|
serviceUsageRecord.setCallerHost(remoteHost);
|
||||||
serviceUsageRecord.setOperationResult(success ? OperationResult.SUCCESS : OperationResult.FAILED);
|
serviceUsageRecord.setOperationResult(success ? OperationResult.SUCCESS : OperationResult.FAILED);
|
||||||
serviceUsageRecord.setDuration(System.currentTimeMillis() - startCallThreadLocal.get());
|
serviceUsageRecord.setDuration(System.currentTimeMillis() - startCallThreadLocal.get());
|
||||||
|
@ -134,8 +134,8 @@ public class RequestAccounting extends RequestHandler {
|
||||||
private String getContext(ApplicationContext appContext) {
|
private String getContext(ApplicationContext appContext) {
|
||||||
String infrastructure = appContext.container().configuration().infrastructure();
|
String infrastructure = appContext.container().configuration().infrastructure();
|
||||||
String context = "/" + infrastructure;
|
String context = "/" + infrastructure;
|
||||||
if (SecretManagerProvider.instance.get() != null)
|
if (SecretManagerProvider.get() != null)
|
||||||
context = SecretManagerProvider.instance.get().getContext();
|
context = SecretManagerProvider.get().getContext();
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class RequestValidator extends RequestHandler {
|
||||||
|
|
||||||
appContext = call.context();
|
appContext = call.context();
|
||||||
|
|
||||||
SecretManagerProvider.instance.set(getSecret(call));
|
SecretManagerProvider.set(getSecret(call));
|
||||||
|
|
||||||
validateAgainstLifecycle(call);
|
validateAgainstLifecycle(call);
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class RequestValidator extends RequestHandler {
|
||||||
@Override
|
@Override
|
||||||
public void handleResponse(ResponseEvent e) {
|
public void handleResponse(ResponseEvent e) {
|
||||||
log.debug("resetting all the Thread local for this call.");
|
log.debug("resetting all the Thread local for this call.");
|
||||||
SecretManagerProvider.instance.reset();
|
SecretManagerProvider.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ public class RequestValidator extends RequestHandler {
|
||||||
|
|
||||||
private void validateScopeCall() {
|
private void validateScopeCall() {
|
||||||
|
|
||||||
String context = SecretManagerProvider.instance.get().getContext();
|
String context = SecretManagerProvider.get().getContext();
|
||||||
|
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
log.warn("rejecting unscoped call to {}",appContext.name());
|
log.warn("rejecting unscoped call to {}",appContext.name());
|
||||||
|
@ -106,7 +106,7 @@ public class RequestValidator extends RequestHandler {
|
||||||
|
|
||||||
private void rejectUnauthorizedCalls(RequestEvent call){
|
private void rejectUnauthorizedCalls(RequestEvent call){
|
||||||
|
|
||||||
Secret secret = SecretManagerProvider.instance.get();
|
Secret secret = SecretManagerProvider.get();
|
||||||
|
|
||||||
if (secret == null){
|
if (secret == null){
|
||||||
log.warn("rejecting call to {}, authorization required",appContext.name());
|
log.warn("rejecting call to {}, authorization required",appContext.name());
|
||||||
|
|
|
@ -5,8 +5,6 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class InnerMethodName {
|
public class InnerMethodName {
|
||||||
|
|
||||||
public static InnerMethodName instance = new InnerMethodName();
|
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(InnerMethodName.class);
|
private static Logger logger = LoggerFactory.getLogger(InnerMethodName.class);
|
||||||
|
|
||||||
// Thread local variable containing each thread's ID
|
// Thread local variable containing each thread's ID
|
||||||
|
@ -14,26 +12,26 @@ public class InnerMethodName {
|
||||||
new InheritableThreadLocal<String>() {
|
new InheritableThreadLocal<String>() {
|
||||||
|
|
||||||
@Override protected String initialValue() {
|
@Override protected String initialValue() {
|
||||||
return "UNKNOWN";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private InnerMethodName(){}
|
private InnerMethodName(){}
|
||||||
|
|
||||||
public String get(){
|
public static String get(){
|
||||||
String calledMethod = threadMethod.get();
|
String calledMethod = threadMethod.get();
|
||||||
logger.trace("getting InnerMethodName as "+calledMethod+" in thread "+Thread.currentThread().getId() );
|
logger.trace("getting InnerMethodName as "+calledMethod+" in thread "+Thread.currentThread().getId() );
|
||||||
return calledMethod;
|
return calledMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String calledMethod){
|
public static void set(String calledMethod){
|
||||||
if (calledMethod==null) return;
|
if (calledMethod==null) return;
|
||||||
threadMethod.set(calledMethod);
|
threadMethod.set(calledMethod);
|
||||||
logger.trace("setting InnerMethodName as "+calledMethod+" in thread "+Thread.currentThread().getId() );
|
logger.trace("setting InnerMethodName as "+calledMethod+" in thread "+Thread.currentThread().getId() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset(){
|
public static void reset(){
|
||||||
threadMethod.remove();
|
threadMethod.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue