RodrigoDLopez commented on pull request #5353:
URL: https://github.com/apache/cloudstack/pull/5353#issuecomment-917172683
> @sureshanaparti, @RodrigoDLopez thanks for the suggestions, but, creating
a private method to log all commands will need to use the Command class as a
parameter, which is an abstract class and don't log any information using Gson.
To log information in this way, I will need to create a custom
serializer/deserializer, which would imply making many changes, in addition to
the risk of breaking something.
>
> If you have any suggestions to solve this problem, I'll really appreciate.
you can extract the code in a private method
```
private void logCommand(Command cmd) {
s_logger.debug(String.format(EXECUTING_RESOURCE_COMMAND,
cmd.getClass().getSimpleName(), _gson.toJson(cmd)));
}
```
and then reuse it where is appropriated
```
private GetVmVncTicketAnswer execute(GetVmVncTicketCommand cmd) {
logCommand(cmd);
[...]
}
private Answer execute(ValidateVcenterDetailsCommand cmd) {
logCommand(cmd);
[...]
}
private Answer execute(PrepareUnmanageVMInstanceCommand cmd) {
logCommand(cmd);
[...]
}
```
the command class is here just to type, who will actually be executed are
the classes that implement the parent class.
I ran some tests here. Apparently everything works correctly.
```
Executing resource command StartCommand:
[{"vm":{"mockitoInterceptor":{"handler":{"invocationListeners":[],"mockHandler":{}},"mockCreationSettings":{"typeToMock":{},"extraInterfaces":[],"defaultAnswer":{},"mockName":{"mockName":"virtualMachineTO","defaultName":true},"serializableMode":"NONE","invocationListeners":[],"stubbingLookupListeners":[],"verificationStartedListeners":[],"stubOnly":false,"stripAnnotations":false,"useConstructor":false,"lenient":false},"serializationSupport":{"instanceLocalCurrentlySerializingFlag":false,"mutex":{"sync":{"state":0}}}},"id":0,"cpus":0,"minRam":0,"maxRam":0,"enableHA":false,"limitCpuUse":false,"enableDynamicallyScaleVm":false,"enterHardwareSetup":false},"executeInSequence":true,"wait":0,"bypassHostMaintenance":false}].
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]