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

Adds Digital Twin Runner utility #110

Conversation

prasadtalasila
Copy link
Contributor

@prasadtalasila prasadtalasila commented Sep 15, 2023

This PR adds new Digital Twin Runner component to the project. This component can be run as a microservice. It can also be installed as a system utility that can be run as a regular command.

Current Status:

✔️ Working Nestjs project with useful functionality
✔️ Can be published as an npm package
✔️ Runs HTTP service and services two routes: /phase and /lifecycle/phase
✔️ Includes sufficient functionality for Digital Twin Lifecycle management. But not all of this functionality is available via HTTP API.
✔️ Complete integration and end-to-end tests
✔️ OpenAPI compliant-spec for DT Runner API (this yet to be implemented)

❌ Does not use dependency injection of nestjs framework
❌ Can not receive the commands over HTTP API
✖️ No unit tests
✖️ No configuration

❔ What is a good way to save the logs?
❔ Where should the configuration be saved? Can it be placed at a default location which is Operating System platform independent?

prasadtalasila and others added 8 commits September 15, 2023 10:10
  - Adds Lifecycle manager to support DT lifecycle phases.
  - The past invocations of DT lifecycle operations are
    tracked via a queue. This will eventually help with
    replay of operations on DT.
  - The invocations of lifecycle operations are completely
    asynchronous. It is possible to run all the phases at the
    same time.
  - The runner code is ready to be published as npm package.
    The README contains instructions on setting up private
    npm repository for development purposes.
  - FIX: There are no tests
  - Adds skeleton invocation of ExecaCMDRunner from nestjs code
  - Formats code using prettier
  - Sets the correct ts-jest preset for tests
  - Removes the incorrect npm registry setting
    in yarn.lock file
  - Fixes eslint and jest configurations so that
    all yarn commands work correctly
  - Removes some of the lifeCycle code to make
    the basic code work
  - Adds lifecycleManager and its dependencies
  - Fixes the yarn publish step. Now the package
    can be published successfully
Copy link

@codeclimate codeclimate bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 7105 lines exceeds the maximum allowed for the inline comments feature.

@codecov-commenter
Copy link

codecov-commenter commented Sep 15, 2023

Codecov Report

Merging #110 (088669a) into feature/distributed-demo (a95ad9c) will increase coverage by 1.42%.
Report is 3 commits behind head on feature/distributed-demo.
The diff coverage is 93.02%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@                     Coverage Diff                      @@
##           feature/distributed-demo     #110      +/-   ##
============================================================
+ Coverage                     64.37%   65.80%   +1.42%     
============================================================
  Files                            38       35       -3     
  Lines                           494      424      -70     
  Branches                         28       27       -1     
============================================================
- Hits                            318      279      -39     
+ Misses                          160      129      -31     
  Partials                         16       16              
Files Coverage Δ
servers/execution/runner/src/app.controller.ts 100.00% <100.00%> (ø)
servers/execution/runner/src/queue.service.ts 100.00% <100.00%> (ø)
...s/execution/runner/src/lifecycleManager.service.ts 90.90% <90.90%> (ø)
servers/execution/runner/src/execaCMDRunner.ts 86.66% <86.66%> (ø)

... and 7 files with indirect coverage changes

Components Coverage Δ
Website 62.72% <ø> (ø)
Lib Microservice ∅ <ø> (∅)

@prasadtalasila
Copy link
Contributor Author

prasadtalasila commented Sep 16, 2023

@nichlaes quick questions:

  1. If we use npx, can the cross-env be removed from script/*.bash? NO
  2. Is there a way to launch dist/src/runner.js on Windows as a standalone executable? It is a Javascript program but needs the following Nodejs arguments to work.
    node -es-module-specifier-resolution=node --experimental-modules --experimental-specifier-resolution=node

Without cross-env, we get:

npx NODE_OPTIONS=--experimental-vm-modules \
  NODE_NO_WARNINGS=1 \
  jest --coverage
npm ERR! code EINVALIDTAGNAME
npm ERR! Invalid tag name "NODE_OPTIONS=--experimental-vm-modules" of package "NODE_OPTIONS=--experimental-vm-modules": Tags may not have any characters that encodeURIComponent encodes.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/prasad/.npm/_logs/2023-09-16T08_09_38_602Z-debug-0.log

  - Completes integration tests for the codebase
  - Makes the execaCMDRunner catch the invalid commands
  - Removes get-stream dependency from execaCMDRunner
  - Uploads codecoverage to codecov
  - Adds new yarn command to watch the tests
  - Adds emojis to README
Copy link

@codeclimate codeclimate bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 7253 lines exceeds the maximum allowed for the inline comments feature.

@prasadtalasila
Copy link
Contributor Author

The two codeclimate issues are contradicting the coding idioms suggested by supertest. These two codeclimate issues need to be ignored.

  - Add OpenAPI specification for DT Runner
  - Updates git-hooks to check against runner as well
  - Adds more yarn test commands to runner
Copy link

@codeclimate codeclimate bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 7401 lines exceeds the maximum allowed for the inline comments feature.

@nichlaes
Copy link
Collaborator

@nichlaes quick questions:
2. Is there a way to launch dist/src/runner.js on Windows as a standalone executable? It is a Javascript program but needs the following Nodejs arguments to work.
node -es-module-specifier-resolution=node --experimental-modules --experimental-specifier-resolution=node

@prasadtalasila
As I understand it, we need to either use cross-env or enforce the use of bash when we are on Windows, in order for the passed environments to work.

@prasadtalasila
Copy link
Contributor Author

We are currently restricted to Debian/Ubuntu. This is not a priority but the goal is to make cross-platform software.

Since the DT Runner is being developed from scratch now, I am exploring an easier way of adding cross-platform support.

More over, there is a definite requirement to execute DT Runner on Windows. The requirement will certainly come to us in a years' time.

@prasadtalasila
Copy link
Contributor Author

Would it be better to put powershell scripts in script/ directory? Or is there a better solution?

@nichlaes
Copy link
Collaborator

Hmm maybe a possibility would be to build it as a single executable file on both platforms?

I not sure I have an understanding of what we want to do exactly, but maybe we could talk about it in person at some point?

@nichlaes
Copy link
Collaborator

@prasadtalasila If we put bash -c before running the scripts in the package.json, we can remove the cross-env. The only requirement is that the windows machine has bash installed.

"scripts": {
     . . . 
    "start": "bash -c 'script/start.bash'",
    "test": "bash -c './script/test.bash'",
     . . . 

npx cross-env \
NODE_OPTIONS="$MOD_RES $EXP $EXP_RES" \
NODE_NO_WARNINGS=1 \
node dist/src/main.js
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should it run 'main' or 'runner'?

Copy link
Contributor Author

@prasadtalasila prasadtalasila Sep 19, 2023

Choose a reason for hiding this comment

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

It should run main.js.

The runner.ts was put in place to check the functionality of classes before tests were written. Also the
yarn publish uses dist/runner.js. That need to be changed to dist/main.js.

I will change this and check again.

@nichlaes
Copy link
Collaborator

Here are some of my comments on the PR:

It took me some time to grasp the whole 'phase' concept. Of course I'm still very new to the project, so maybe that is just how it is. You could consider if it would make sense to have it mention a bit further in the README or just an example.

Another comment, which properly out of scope / nice-to-have. As it is now, it would not be possible to see the logs before the processes has succeeded/failed. Therefore we can't give a continuously status back to the user. I could imagine, this would be nice for the user, if the 'phase' takes a longer amount of time.

Otherwise everything looks good. The code coverage is high, and the parts that are not covered are trivial.

@prasadtalasila
Copy link
Contributor Author

@prasadtalasila If we put bash -c before running the scripts in the package.json, we can remove the cross-env. The only requirement is that the windows machine has bash installed.

"scripts": {
     . . . 
    "start": "bash -c 'script/start.bash'",
    "test": "bash -c './script/test.bash'",
     . . . 

@nichlaes
Interesting. I will explore this possibility.

@prasadtalasila
Copy link
Contributor Author

prasadtalasila commented Sep 19, 2023

Hmm maybe a possibility would be to build it as a single executable file on both platforms?

I not sure I have an understanding of what we want to do exactly, but maybe we could talk about it in person at some point?

pkg or its equivalent software will do it. Certainly worth exploring. Thanks for the suggestion.

@prasadtalasila
Copy link
Contributor Author

Here are some of my comments on the PR:

It took me some time to grasp the whole 'phase' concept. Of course I'm still very new to the project, so maybe that is just how it is. You could consider if it would make sense to have it mention a bit further in the README or just an example.

This is a relevant comment. The concept is explained in https://into-cps-association.github.io/DTaaS/version0.2/user/digital-twins/lifecycle.html (documentation).

It must also be explained here as well. I will add more details in the README.

Another comment, which properly out of scope / nice-to-have. As it is now, it would not be possible to see the logs before the processes has succeeded/failed. Therefore we can't give a continuously status back to the user. I could imagine, this would be nice for the user, if the 'phase' takes a longer amount of time.

I need to change the stdout and stderr from string to streams.
Will come in future PRs.

Otherwise everything looks good. The code coverage is high, and the parts that are not covered are trivial.

Ok. Thanks for the review.

@prasadtalasila
Copy link
Contributor Author

@prasadtalasila If we put bash -c before running the scripts in the package.json, we can remove the cross-env. The only requirement is that the windows machine has bash installed.

"scripts": {
     . . . 
    "start": "bash -c 'script/start.bash'",
    "test": "bash -c './script/test.bash'",
     . . . 

The problem with bash -c is that it requires Windows Subsystem for Linux. This is not ideal. Can we use powershell scripts in Windows as equivalents for bash scripts? What are the downsides?

Copy link

@codeclimate codeclimate bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 7479 lines exceeds the maximum allowed for the inline comments feature.

@codeclimate
Copy link

codeclimate bot commented Sep 27, 2023

Code Climate has analyzed commit 088669a and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

View more on Code Climate.

@prasadtalasila prasadtalasila merged commit 6e6b9f5 into INTO-CPS-Association:feature/distributed-demo Sep 27, 2023
3 checks passed
@prasadtalasila prasadtalasila deleted the runner-nestjs branch September 27, 2023 14:10
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.

3 participants