Ravi Nori has uploaded a new change for review. Change subject: engine : Support logging of commands parameters ......................................................................
engine : Support logging of commands parameters When debug mode is enabled the command parameters excluding the ones in the VdcParametersBase are logged when the command is executed. Change-Id: Idfd9423e92f9f9c9a51eca24b20157cc32681018 Bug-Url: https://bugzilla.redhat.com/1095240 Signed-off-by: Ravi Nori <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ReflectionUtils.java 2 files changed, 50 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/80/27780/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java index f2cd1c4..7044428 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java @@ -1164,6 +1164,32 @@ return getParameters().getTransactionScopeOption(); } + private String getCommandParameters(T params) { + final String GET = "get"; + StringBuilder buf = new StringBuilder(""); + List<String> methodNames = ReflectionUtils.getMethodNames(params); + methodNames.removeAll(ReflectionUtils.getMethodNames(new VdcActionParametersBase())); + + for (String methodName : methodNames) { + if (!methodName.startsWith(GET)) { + continue; + } + Object retVal = ReflectionUtils.invokeMethodWithNoArgs(params, methodName); + if (retVal == null) { + continue; + } + if (buf.length() > 0) { + buf.append(", "); + } + buf.append(methodName.substring(GET.length())); + buf.append(" = "); + buf.append(retVal.toString()); + } + + return buf.toString(); + } + + /** * Log the running command , and log the affected entity id and type (if * there are any). @@ -1173,6 +1199,10 @@ StringBuilder logInfo = new StringBuilder("Running command: ") .append(getClass().getSimpleName()); + if (log.isDebugEnabled()) { + logInfo.append(getParameters() != null ? "(" + getCommandParameters(getParameters()) + ")" : StringUtils.EMPTY); + } + if (hasTaskHandlers()) { logInfo.append(" Task handler: ").append(getCurrentTaskHandler().getClass().getSimpleName()); } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ReflectionUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ReflectionUtils.java index 708ecae..6ac8001 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ReflectionUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ReflectionUtils.java @@ -1,7 +1,10 @@ package org.ovirt.engine.core.utils; import java.lang.reflect.Constructor; - +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; /** @@ -76,6 +79,22 @@ return true; } + public static List<String> getMethodNames(Object o) { + List<String> methodNames = new ArrayList<>(); + for (Method m : o.getClass().getMethods()) { + methodNames.add(m.getName()); + } + return methodNames; + } + + public static Object invokeMethodWithNoArgs(Object o, String name) { + try { + Method m = o.getClass().getMethod(name); + return m.invoke(o); + } catch (NoSuchMethodException|IllegalAccessException|InvocationTargetException e) { + return null; + } + } /** * @param className -- To view, visit http://gerrit.ovirt.org/27780 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idfd9423e92f9f9c9a51eca24b20157cc32681018 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Ravi Nori <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
