Skip to content
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

Create a pool and attach machines to it #985

Merged
merged 2 commits into from
Apr 17, 2020

Conversation

huwshimi
Copy link
Contributor

@huwshimi huwshimi commented Apr 16, 2020

Done

  • Set up the websocket channel to receive additional messages.
  • Handle creating a pool and attaching machines to it.

Note: Errors and saving state will be handled by #984 and #881.

QA

  • Visit the machine list. Select machines and choose "Set resource pool..." from the take action menu.
  • Change the radiobutton to "Create pool".
  • Enter a new pool name and submit the form.
  • Your selected machines should be attached to the new pool.

Fixes

Fixes: #928.

Copy link
Contributor

@Caleb-Ellis Caleb-Ellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code and QA + 1 from me, but I think the websocket and saga code is a little over my head so I'll let @squidsoup add the approval if he's happy with it.

* @param {Array} machines - A list of machine ids.
* @returns {Array} The list of action creator functions.
*/
export const generateActionCreators = (machines) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will every one of these chained websocket sagas need its own function generator like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, something like that. It depends on the action that needs to be performed. The generator is outside. This is only external to the saga to make the saga testable.

.provide([[call(getNextActions, 99), [actionCreator]]])
.call(actionCreator, response.result)
.put(action)
.run();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah! I forgot how confusing these saga tests are.

@huwshimi huwshimi force-pushed the create-and-set-pool branch from 95f2ea1 to f3c98e8 Compare April 16, 2020 23:21
Copy link
Contributor

@squidsoup squidsoup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small comments for your consideration, but I think overall this seems workable. Thanks for figuring this out @huwshimi. Have you given any thought as to how error handling will work? If our action requires two 'commits' across the websocket, what happens if the first fails? (e.g. if creating a new resource pool fails, before associating machines).

* @param {Array} machines - A list of machine ids.
* @returns {Array} The list of action creator functions.
*/
export const generateActionCreators = (machines) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this function seems a bit odd, generateActionCreators sounds generic, but this function is specific to generating actionCreators for machineActions.setPool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yep done.

*
* @param {Object} response - A websocket response.
*/
export function* handleNextActions({ request_id, result }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think typically you would only destructure an object as a function param if you were setting a default value, otherwise it is probably clearer to destructure the object in the function body so the jsdoc matches the function signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -292,7 +340,7 @@ export function* sendMessage(socketClient, action) {
/**
* Connect to the WebSocket and watch for message.
*/
export function* setupWebSocket() {
export function* setupWebSocket(messageHandlers = []) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a jsdoc @param

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@huwshimi
Copy link
Contributor Author

@squidsoup my plan is that the form will receive the error from the redux store for the pool model, I've created an issue for that here: #984. I need to do #881 first so that the form stays open so it can display the errors.

@huwshimi huwshimi force-pushed the create-and-set-pool branch from 3d4d50c to dd717c2 Compare April 17, 2020 00:38
@huwshimi huwshimi merged commit 7cccbc9 into canonical:master Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle actions that rely on websocket response data
3 participants