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

fixes #23369 - load vmware datastores async #6103

Conversation

timogoebel
Copy link
Member

@timogoebel timogoebel commented Oct 3, 2018

This commit introduces async loading of vSphere Datastores and Storage Pods.

This speeds up the time before the form is required and is a prerequisite for #3559, a feature requested in 2013 that we still haven't delivered.

foreman-vsphere-load-datastores-async-3

@ohadlevy: Do you mind reviewing this as this is react code?

@timogoebel timogoebel added the UI label Oct 3, 2018
@theforeman-bot
Copy link
Member

Issues: #23369

Copy link
Member

@amirfefer amirfefer left a comment

Choose a reason for hiding this comment

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

Thanks @timogoebel 👍
I left few inline comments about the javascript part :)

const { allowClear } = this.props;

if ($.fn.select2) {
$(this.refs.select)
Copy link
Member

Choose a reason for hiding this comment

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

react 16.3 uses createRef API instead
Would you mind to use it?
https://reactjs.org/docs/refs-and-the-dom.html

.set('datastoresError', undefined)
.set('storagePods', {})
.set('storagePodsLoading', true)
.set('storagePodsError', undefined)
Copy link
Member

@amirfefer amirfefer Oct 3, 2018

Choose a reason for hiding this comment

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

instead of a lot of nested .set you can use merge

});
};

export const fetchDatastores = url => (dispatch) => {
Copy link
Member

@amirfefer amirfefer Oct 3, 2018

Choose a reason for hiding this comment

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

should it be exported while it's used only in this file?

Copy link
Member

Choose a reason for hiding this comment

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

on the other hand, i tend to prefer to call this action from the component's componentDidMount

});
};

export const fetchStoragePods = url => (dispatch) => {
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -17,6 +17,12 @@ const Controller = ({
controllerVolumes,
removeController,
config,
datastores,
Copy link
Member

Choose a reason for hiding this comment

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

Could you add Proptype? It would be much easier to understand the component's props with it

@timogoebel
Copy link
Member Author

@amirfefer: Thanks for the review, will take a look at your invaluable comments (and probably learn a lot!). 👍

@timogoebel timogoebel force-pushed the 23369-vmware-datastores-async-react-2 branch from caeac4d to a24ce0f Compare October 3, 2018 13:38
@timogoebel
Copy link
Member Author

@amirfefer: I hope I addressed most of your comments. Unfortunately, I did not get createRef working. I guess there is enough refactoring in this PR already, we can always change that later.

@ares
Copy link
Member

ares commented Oct 3, 2018

I've tested the functionality and works great with and without cache enabled. I defer to @amirfefer for the createRef pattern, but 👍 form me for manual testing. I haven't really read the code. Test failures are unrelated.

return state
.set('datastoresError', undefined)
.set('datastores', {})
.set('datastoresLoading', true);
Copy link
Member

Choose a reason for hiding this comment

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

please use merge instead of multiple sets, its suppose to be faster :)

Copy link
Member

@ohadlevy ohadlevy left a comment

Choose a reason for hiding this comment

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

could you please also have a look at the storybook? I think it needs an update after these changes.

nice additions, thanks!

@timogoebel
Copy link
Member Author

@ohadlevy: Sure, but after 20 minutes trying to get the storybook server running I gave up. Does it work for you?

$ npm run storybook

> TheForemanDevDeps@1.20.0 storybook /Users/f0218175/foremandev/foreman
> start-storybook -p 6006

@storybook/react v3.2.13

=> Loading custom .babelrc
=> Loading custom addons config.
=> Loading custom webpack config (full-control mode).
/Users/f0218175/foremandev/foreman/.storybook/webpack.config.js:7
  defaultConfig.module.rules = [
                ^

TypeError: Cannot read property 'module' of undefined
    at module.exports (/Users/f0218175/foremandev/foreman/.storybook/webpack.config.js:7:17)
    at exports.default (/Users/f0218175/foremandev/foreman/node_modules/@storybook/react/dist/server/config.js:62:12)
    at exports.default (/Users/f0218175/foremandev/foreman/node_modules/@storybook/react/dist/server/middleware.js:19:37)
    at Object.<anonymous> (/Users/f0218175/foremandev/foreman/node_modules/@storybook/react/dist/server/index.js:153:34)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)

@ohadlevy
Copy link
Member

ohadlevy commented Oct 4, 2018

@timogoebel it seems to work for me:

Switched to a new branch '6103'
➜  foreman git:(6103) npm run storybook                                                                                                                     git:(6103|) 

> TheForemanDevDeps@1.20.0 storybook /home/ohad/git/foreman
> start-storybook -p 6006

info @storybook/react v3.4.8
info 
info => Loading custom .babelrc
info => Loading custom addons config.
info => Loading custom webpack config (full-control mode).
 66% building modules 623/657 modules 34 active ...oreman/node_modules/lodash/isArray.jsDEPRECATION WARNING on line 1, column 8 of stdin:
Including .css files with @import is non-standard behaviour which will be removed in future versions of LibSass.
Use a custom importer to maintain this behaviour. Check your implementations documentation on how to create a custom importer.

webpack built d4fc339334bb701f4e07 in 13336ms                                             
info Storybook started on => http://localhost:6006/

@ares
Copy link
Member

ares commented Oct 4, 2018

I have the similar issue without this PR, the npm command starts the server but navigating to storybook, I see Cannot read property 'defaults' of undefined
story

Copy link
Member

@amirfefer amirfefer left a comment

Choose a reason for hiding this comment

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

Thanks @timogoebel 👍
just few minor issues with PropType

config: PropTypes.object,
controllers: PropTypes.array,
data: PropTypes.object,
datastores: PropTypes.object,
Copy link
Member

@amirfefer amirfefer Oct 4, 2018

Choose a reason for hiding this comment

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

PropTypes.object is not informative
Proptype.shape is much better for arrays and objects.
Plus, if a prop is required, add isRequired to it
i.e:

PropTypes.shape({
    color: PropTypes.string,
    fontSize: PropTypes.number
  }).isRequired, // if a prop is required, add `.isRequired`, else just add a default value

const mapDispatchToProps = (state) => {
const { controllers, config, volumes = [] } = state.hosts.storage.vmware;
const {
controllers, config, volumes = [], datastores, datastoresLoading, datastoresError,
Copy link
Member

@amirfefer amirfefer Oct 4, 2018

Choose a reason for hiding this comment

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

you can use default values with Proptype:

StorageContainer.defaultProps = {
  volumes: []
};

@ohadlevy
Copy link
Member

ohadlevy commented Oct 8, 2018

what is the status of this PR? (if its ready for today's cut of date?)

@timogoebel
Copy link
Member Author

@ohadlevy: I won't be able to look at this today. Let's to it in the 1.21 cycle.

@timogoebel
Copy link
Member Author

@amirfefer, @ohadlevy, @ares: Improved the prop types and fixed up storybook. Can you please re-review?

@amirfefer
Copy link
Member

LGFM 👍

@timogoebel timogoebel force-pushed the 23369-vmware-datastores-async-react-2 branch 2 times, most recently from c554d37 to ad0e808 Compare November 5, 2018 14:43
@timogoebel
Copy link
Member Author

This is my final attempt to get this in, I rebased the code and added support for statistics of the datastore and storage pods.

ohadlevy
ohadlevy previously approved these changes Nov 5, 2018
Copy link
Member

@ohadlevy ohadlevy left a comment

Choose a reason for hiding this comment

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

LGTM, I don't have a working VMWare env to test.

@lizagilman
Copy link
Member

lizagilman commented Nov 5, 2018

@timogoebel or anyone interested, regarding storybook issue (if you still have it), this workaround works for me - https://gist.github.com/lizagilman/d3a94114fc3fd3214138ec120fca4a5c

@timogoebel
Copy link
Member Author

@lizagilman: Thanks. I chose the "reboot" approach. That was quite popular in ancient times.
rm -rf node_module && npm install.

@timogoebel
Copy link
Member Author

@chris1984: Can you do me a favor and test and ack this? Thanks a bunch.

@amirfefer
Copy link
Member

amirfefer commented Nov 5, 2018

I've test it with vmware env and it works for me:
vmware

Looks like a snapshot needs an update

amirfefer
amirfefer previously approved these changes Nov 5, 2018
chris1984
chris1984 previously approved these changes Nov 5, 2018
Copy link
Member

@chris1984 chris1984 left a comment

Choose a reason for hiding this comment

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

ACK, looks good Thanks @timogoebel

@chris1984
Copy link
Member

[test foreman]

@ares
Copy link
Member

ares commented Nov 6, 2018

It seems like test failures are related, mind to take a look?

@timogoebel timogoebel force-pushed the 23369-vmware-datastores-async-react-2 branch from ad0e808 to 6fa1416 Compare November 7, 2018 08:43
@timogoebel
Copy link
Member Author

Fixed the tests.

@timogoebel
Copy link
Member Author

Tests passed.

@@ -83,6 +83,7 @@
"jstz": "~1.0.7",
"lodash": "^4.17.10",
"multiselect": "~0.9.12",
"number_helpers": "^0.1.1",
Copy link
Member

@ohadlevy ohadlevy Nov 7, 2018

Choose a reason for hiding this comment

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

I tried packaging this, but it fails, I assume before merge we would need a packaging ACK.

EDIT: for completion, the error is

./add_npm_package.sh number_helpers 0.1.1
Found 0 dependencies - using single strategy
Making directory...FINISHED
Creating specs and downloading sources...---- npm2rpm ----
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
 - Starting npm module download: https://registry.npmjs.org/number_helpers/-/number_helpers-0.1.1.tgz
 - Unpacking in /tmp/npm2rpm-15831E09pZQE4YSYD ...
 - Finished extracting for number_helpers
 - Reading package.json for number_helpers
Warning: No README data
Warning: No license field.
 - Finished reading package.json for number_helpers
fs.js:133
  throw new ERR_INVALID_CALLBACK();
  ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
    at maybeCallback (fs.js:133:9)
    at Object.writeFile (fs.js:1139:14)
    at writeSpecFile (/home/ohad/git/foreman-packaging/node_modules/npm2rpm/bin/npm2rpm.js:87:6)
    at Extract.tar_extract.stream.on (/home/ohad/git/foreman-packaging/node_modules/npm2rpm/bin/npm2rpm.js:78:5)
    at Extract.emit (events.js:187:15)
    at DirWriter.<anonymous> (/home/ohad/git/foreman-packaging/node_modules/tar/lib/extract.js:81:8)
    at DirWriter.emit (events.js:187:15)
    at end (/home/ohad/git/foreman-packaging/node_modules/fstream/lib/writer.js:324:14)
    at /home/ohad/git/foreman-packaging/node_modules/fstream/lib/writer.js:314:34
    at endUtimes (/home/ohad/git/foreman-packaging/node_modules/fstream/lib/writer.js:238:46)

Copy link
Member

Choose a reason for hiding this comment

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

I think that was a warning for a while already but likely that there's an update which makes it strict. I'll have a look.

Copy link
Member

Choose a reason for hiding this comment

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

also TODO: add this package to webpack vendor file (can be done in a follow up pr).

Copy link
Member

Choose a reason for hiding this comment

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

theforeman/foreman-packaging#3174. Luckily in theforeman/npm2rpm#48 I already fixed that issue.

Copy link
Member

Choose a reason for hiding this comment

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

@ekohl great, once you are ready please ack this PR.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Packaging ACK, haven't looked at the code :)

@ohadlevy ohadlevy merged commit b4d7f9c into theforeman:develop Nov 7, 2018
@ohadlevy
Copy link
Member

ohadlevy commented Nov 7, 2018

thanks @timogoebel!

@timogoebel
Copy link
Member Author

Thanks, @ohadlevy + @amirfefer + @ares + @ekohl + @chris1984!

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.

10 participants