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

refactor(api-server): instantiate plugins in api-server without install them #1456

Conversation

elenaizaguirre
Copy link
Contributor

@elenaizaguirre elenaizaguirre commented Oct 13, 2021

Added parameter action to PluginImport to determine if the plugin
should be installed.

Enabled feature to instantiate plugins from cactus-cmd-api-server
without install it.

Enabled feature to install packages from github

Added method create in class ConfigService to override old configuration.
Method newExampleConfigConvict accepts a boolean parameter to force
configuration override.

Closes #1210

Depends on #1527

Signed-off-by: Elena Izaguirre e.izaguirre.equiza@accenture.com

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2021

Codecov Report

Merging #1456 (9e84e6d) into main (9022064) will increase coverage by 0.05%.
The diff coverage is 84.00%.

❗ Current head 9e84e6d differs from pull request most recent head 12afee9. Consider uploading reports for the commit 12afee9 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1456      +/-   ##
==========================================
+ Coverage   69.80%   69.86%   +0.05%     
==========================================
  Files         336      336              
  Lines       12622    12637      +15     
  Branches     1512     1516       +4     
==========================================
+ Hits         8811     8829      +18     
+ Misses       2989     2985       -4     
- Partials      822      823       +1     
Impacted Files Coverage Δ
...erver/src/main/typescript/config/config-service.ts 76.08% <78.57%> (+0.80%) ⬆️
...s-cmd-api-server/src/main/typescript/api-server.ts 85.10% <84.84%> (+1.27%) ⬆️
...pescript/generated/openapi/typescript-axios/api.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9022064...12afee9. Read the comment docs.

@takeutak
Copy link
Contributor

takeutak commented Oct 15, 2021

@elenaizaguirre
Thanks for contributing! The contents of this PR itself is almost good for me.
But I have a small favor to request for you. In the previous meeting, we agree that new feature addtions should be managed by another branch from main.
https://wiki.hyperledger.org/display/cactus/2021-10-04+Meeting+Notes

In the case of this PR, I think that the contents is not substantially "new feature" but "refactoring of api-server" (not including new features).
So, if you change the title of this PR and the one of this commit from "feat: instantiate plugins in api-server ..." to "refactor(api-server): instantiate plugins in api-server ...", I can approve this PR.
Would you mind if you change the title of this PR and the one of this commit?
Note that the title of this commit can be changed using the command git rebase.

@elenaizaguirre elenaizaguirre force-pushed the api-server-optional-installation branch from 754113c to d06365f Compare October 15, 2021 11:44
@elenaizaguirre elenaizaguirre changed the title feat: instantiate plugins in api-server without install them refactor(api-server): instantiate plugins in api-server without install them Oct 15, 2021
@elenaizaguirre elenaizaguirre force-pushed the api-server-optional-installation branch from d06365f to 86f3511 Compare October 15, 2021 11:45
@elenaizaguirre
Copy link
Contributor Author

@elenaizaguirre Thanks for contributing! The contents of this PR itself is almost good for me. But I have a small favor to request for you. In the previous meeting, we agree that new feature addtions should be managed by another branch from main. https://wiki.hyperledger.org/display/cactus/2021-10-04+Meeting+Notes

In the case of this PR, I think that the contents is not substantially "new feature" but "refactoring of api-server" (not including new features). So, if you change the title of this PR and the one of this commit from "feat: instantiate plugins in api-server ..." to "refactor(api-server): instantiate plugins in api-server ...", I can approve this PR. Would you mind if you change the title of this PR and the one of this commit? Note that the title of this commit can be changed using the command git rebase.

@takeutak Done!

Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

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

@elenaizaguirre Left question above

@elenaizaguirre elenaizaguirre force-pushed the api-server-optional-installation branch from 9107cbb to d521a1a Compare October 21, 2021 07:43
@petermetz
Copy link
Contributor

I'm not sure if I understood this right. I have added an optional boolean parameter to newExampleConfigConvict to call either create or getOrCreate directly. I can set this value inside env but is not necessary having these methods separated, right? I think this way the configuration overriding is more flexible and can be set from an external call

@elenaizaguirre Yeah that works, sorry if I wasn't clear enough, I'm just making it up as I go. :-)

@petermetz
Copy link
Contributor

@elenaizaguirre GitHub is bugging out somehow I'm not able to respond to your comment thread directly, but I agree it's a good idea to use an enum.

image


@petermetz Thinking about #1210, what do you think if I change this property for another one that contains a literal indicating the action to be performed? The options of this literal could be:

Instantiate
Install
Remove
Modify (remove and install, includes upgrade and downgrade)

@elenaizaguirre elenaizaguirre force-pushed the api-server-optional-installation branch 2 times, most recently from bef4775 to acea582 Compare November 3, 2021 09:20
@elenaizaguirre elenaizaguirre marked this pull request as draft November 3, 2021 09:32
Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

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

@elenaizaguirre Responding to the comment I pasted below, GitHub is not letting me respond to comment thread (super annoying bug)

The response: I would say it's better to just crash so that we don't need additional if conditions and it's guaranteed that way that if we started then all the plugins are actually operational (at least to the point that we could instantiate them).
Otherwise people would always have to wonder if their endpoints are operational or not on account of that if condition.
It might be less convenient upfront (because if you have a faulty plugin you will have to adjust your configuration) but then it's more deterministic with less possible execution paths at runtime.


@petermetz
Not right now because inside the instantiatePlugin method, if plugin was undefined, an error would have been thrown when calling onPluginInit. As the code is now, this error would be caught in the second catch and would return undefined as well.
This generates doubts to me because I put the undefined value for the purpose of not to paralyze the execution of the server in case the plugin could not be installed but there is new code that throws an exception when is not possible to call onPluginInit (although right now this error is caught).
In case of installation failure, should we throw the error or just not install the plugin?

@elenaizaguirre elenaizaguirre force-pushed the api-server-optional-installation branch 2 times, most recently from 76272a3 to 12afee9 Compare November 5, 2021 12:00
…ll them

Added parameter action to PluginImport to determine if the plugin
should be installed.

Enabled feature to instantiate plugins from cactus-cmd-api-server
without install it.

Enabled feature to install packages from github

Added method create in class ConfigService to override old configuration.
Method newExampleConfigConvict accepts a boolean parameter to force
configuration override.

Closes hyperledger-cacti#1210

Signed-off-by: Elena Izaguirre <e.izaguirre.equiza@accenture.com>
@elenaizaguirre elenaizaguirre force-pushed the api-server-optional-installation branch from 12afee9 to d223d8b Compare November 23, 2021 11:45
@github-actions
Copy link

🎉 Great news! Looks like all the dependencies have been resolved:

💡 To add or remove a dependency please update this issue/PR description.

Brought to you by Dependent Issues (:robot: ). Happy coding!

@elenaizaguirre elenaizaguirre marked this pull request as ready for review November 23, 2021 14:42
Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

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

@petermetz
Done, I have created #1527 for that purpose, but I needed to add the dist/main folder from a real plugin (instead of a single js file) because when we instantiate a plugin, it should be able to call some plugin methods. Otherwise, server startup will fail

@elenaizaguirre Great! Thank you very much for the extra steps and also special thanks for making sure that the readmes are updated with the latest config parameter schema! LGTM

@petermetz petermetz merged commit 587052c into hyperledger-cacti:main Nov 23, 2021
@petermetz petermetz deleted the api-server-optional-installation branch November 23, 2021 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(cmd-api-server): add ability to install specific versions of plugins
4 participants