-
Notifications
You must be signed in to change notification settings - Fork 1.4k
send unsupported answer only when applicable #2714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| import javax.xml.parsers.DocumentBuilderFactory; | ||
| import javax.xml.parsers.ParserConfigurationException; | ||
|
|
||
| import com.cloud.resource.RequestWrapper; | ||
| import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; | ||
| import org.apache.cloudstack.storage.to.VolumeObjectTO; | ||
| import org.apache.cloudstack.utils.hypervisor.HypervisorUtils; | ||
|
|
@@ -1432,13 +1433,21 @@ public boolean stop() { | |
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * This finds a command wrapper to handle the command and executes it. | ||
| * If no wrapper is found an {@see UnsupportedAnswer} is sent back. | ||
| * Any other exceptions are to be caught and wrapped in an generic {@see Answer}, marked as failed. | ||
| * | ||
| * @param cmd the instance of a {@see Command} to execute. | ||
| * @return the for the {@see Command} appropriate {@see Answer} or {@see UnsupportedAnswer} | ||
| */ | ||
| @Override | ||
| public Answer executeRequest(final Command cmd) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about a unit test cases? Then, you can have a test case that detects if we catch only
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that would require throwing everything else. I will add a subset to catch the most obvious cases
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes. If you want to check all possible cases. However, you can test with the most obvious ones such as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not really convinced that any of these make a lot of difference to one and another. How about the known and unknown case I just added?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It helps. I only think that you could go and test the method
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could also unittest RequestWrapper, yes.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problems ;) |
||
|
|
||
| final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance(); | ||
| try { | ||
| return wrapper.execute(cmd, this); | ||
| } catch (final Exception e) { | ||
| } catch (final RequestWrapper.CommandNotSupported cmde) { | ||
| return Answer.createUnsupportedCommandAnswer(cmd); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big 👍 . We really need more of these in our code base :)
Great job!