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

Package library microservice #195

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d6b162a
added -config cl-utility and libms command
lindot11 Oct 3, 2023
bf875b4
really added -config cl-utility
lindot11 Oct 3, 2023
55015e6
Merge remote-tracking branch 'upstream/feature/distributed-demo' into…
lindot11 Oct 3, 2023
23bff03
small undo
lindot11 Oct 3, 2023
1253e6f
small typo fix
lindot11 Oct 3, 2023
72fd82f
removed console.error because of no-console rule
lindot11 Oct 3, 2023
ef44c70
named package libms for npm registry
lindot11 Oct 3, 2023
c848b01
version no updated after private publish
lindot11 Oct 3, 2023
ee72112
specified imported members functions used
lindot11 Oct 3, 2023
241f5ec
Merge branch 'feature/distributed-demo' into publish-package-libms
lindot11 Oct 9, 2023
fd6d238
removed package lock.json
lindot11 Oct 9, 2023
6d83226
nest-commander and libms command implemented
lindot11 Oct 12, 2023
d2bbaf6
solved peer dependencies
lindot11 Oct 12, 2023
613341c
v0.4.0
lindot11 Oct 12, 2023
6f760eb
Merge branch 'INTO-CPS-Association:feature/distributed-demo' into pub…
lindot11 Oct 12, 2023
94ffa17
restore yarn.lock to test linting checks
lindot11 Oct 12, 2023
5c798fe
applied fix to lint check errors
lindot11 Oct 12, 2023
b85cd0e
undo the this to test lint checks
lindot11 Oct 12, 2023
e6cee12
trying again using this to fix lint checks
lindot11 Oct 12, 2023
d1f1ad7
Added support for running libms as a cli with custom commands
MadsKelberg Oct 15, 2023
51d7ffa
Removed some unused dependencies and devDependencies
MadsKelberg Oct 15, 2023
30bee8a
Removed yarn.lock files
MadsKelberg Oct 17, 2023
3578440
Updated package.json
MadsKelberg Oct 17, 2023
8fcb853
Changed the CLI so it will output -h default & fixed a bug with dotenv
MadsKelberg Oct 17, 2023
eea1fcc
Fixed lint error
MadsKelberg Oct 17, 2023
07fc232
Added yarn.lock file & made some changes to the CLI commands
MadsKelberg Oct 17, 2023
b94ce47
The start.sh script can now forward the provided arguments & updated …
MadsKelberg Oct 17, 2023
f990a64
added -config cl-utility and libms command
lindot11 Oct 3, 2023
acfaf52
really added -config cl-utility
lindot11 Oct 3, 2023
6ec79a7
small undo
lindot11 Oct 3, 2023
0120b18
small typo fix
lindot11 Oct 3, 2023
3719d89
removed console.error because of no-console rule
lindot11 Oct 3, 2023
19a37fd
named package libms for npm registry
lindot11 Oct 3, 2023
f02f860
version no updated after private publish
lindot11 Oct 3, 2023
f658289
specified imported members functions used
lindot11 Oct 3, 2023
933c92b
removed package lock.json
lindot11 Oct 9, 2023
b791b48
nest-commander and libms command implemented
lindot11 Oct 12, 2023
0f6100b
solved peer dependencies
lindot11 Oct 12, 2023
f58c389
v0.4.0
lindot11 Oct 12, 2023
c7b3751
restore yarn.lock to test linting checks
lindot11 Oct 12, 2023
5d4f452
applied fix to lint check errors
lindot11 Oct 12, 2023
44f2d9a
undo the this to test lint checks
lindot11 Oct 12, 2023
c10bb24
trying again using this to fix lint checks
lindot11 Oct 12, 2023
6b2e803
Added support for running libms as a cli with custom commands
MadsKelberg Oct 15, 2023
4b23d7e
Removed some unused dependencies and devDependencies
MadsKelberg Oct 15, 2023
55fdb57
Removed yarn.lock files
MadsKelberg Oct 17, 2023
7676278
Updated package.json
MadsKelberg Oct 17, 2023
ef23367
Changed the CLI so it will output -h default & fixed a bug with dotenv
MadsKelberg Oct 17, 2023
0b5fa6c
Fixed lint error
MadsKelberg Oct 17, 2023
8c932fe
Added yarn.lock file & made some changes to the CLI commands
MadsKelberg Oct 17, 2023
eb210d9
The start.sh script can now forward the provided arguments & updated …
MadsKelberg Oct 17, 2023
59c7dc0
Minor improvements to filenames and documentation
prasadtalasila Oct 18, 2023
03d4f17
Updates npm packaging instructions
prasadtalasila Oct 19, 2023
0800463
Adds docs for publishing npm packages and updates libms tests
prasadtalasila Oct 20, 2023
60cdbb0
Merge branch 'feature/distributed-demo' into publish-package-libms
lindot11 Oct 21, 2023
4b33fc6
Merge remote-tracking branch 'otherfork/pr-169'
lindot11 Oct 21, 2023
22191c0
v0.2.1
lindot11 Oct 21, 2023
0ddf434
v0.2.2
lindot11 Oct 21, 2023
721a457
Fixed issue with global install and graphql
MadsKelberg Oct 21, 2023
5476baa
Merge remote-tracking branch 'origin/publish-package-libms' into publ…
lindot11 Oct 21, 2023
5e7b2b5
Minor changes to fix tests
prasadtalasila Oct 21, 2023
7175fac
fix markdownlint issues
prasadtalasila Oct 21, 2023
c1911b4
fix markdownlint issues
prasadtalasila Oct 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/admin/client/CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@ Given that multiple services are running at different routes,
a reverse proxy is needed to map the background services to external routes.
You can use Apache, NGINX, Traefik or any other software to work
as reverse proxy.

The website screenshots and usage information is available in
[user page](../../user/website/index.md).
221 changes: 2 additions & 219 deletions docs/admin/servers/lib/LIB-MS.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,222 +110,5 @@ Users can access the library microservice at URL: `http://localhost:<PORT>/lib`.

The URL endpoint for this microservice is located at: `localhost:PORT/lib`

## GraphQL API Calls

The lib microservice supports two GraphQL queries.

### Directory Listing

#### Query: List of Files

To retrieve a list of files in a directory, use the following GraphQL query.
Replace `path` with the desired directory path.

```graphql
query {
listDirectory(path: "user1") {
repository {
tree {
blobs {
edges {
node {
name
type
}
}
}
trees {
edges {
node {
name
type
}
}
}
}
}
}
}
```

#### Response: List of Files

This query returns the list of files and subdirectories in the specified directory.
The response will include the name and type of each item.

```graphql
{
"data": {
"listDirectory": {
"repository": {
"tree": {
"blobs": {
"edges": []
},
"trees": {
"edges": [
{
"node": {
"name": "common",
"type": "tree"
}
},
{
"node": {
"name": "data",
"type": "tree"
}
},
{
"node": {
"name": "digital twins",
"type": "tree"
}
},
{
"node": {
"name": "functions",
"type": "tree"
}
},
{
"node": {
"name": "models",
"type": "tree"
}
},
{
"node": {
"name": "tools",
"type": "tree"
}
}
]
}
}
}
}
}
}
```

### Fetching a File

#### Query: Get File Contents

This query receives directory path and send the file contents to user in response.

To check this query, create a file `files/user2/data/welcome.txt`
with content of `hello world`.

```graphql
query {
readFile(path: "user2/data/sample.txt") {
repository {
blobs {
nodes {
name
rawBlob
rawTextBlob
}
}
}
}
}
```

#### Response: Get File Contents

This query returns the name, raw binary blob, and raw text blob of
the specified file. The `rawBlob` field contains the file contents
in binary format, while the `rawTextBlob` field contains the file contents
as plain text.

```graphql
{
"data": {
"readFile": {
"repository": {
"blobs": {
"nodes": [
{
"name": "sample.txt",
"rawBlob": "hello world",
"rawTextBlob": "hello world"
}
]
}
}
}
}
}
```

## HTTP API Calls

The lib microservice also supports making API calls using HTTP POST requests.
Simply send a POST request to the URL endpoint with the GraphQL query in
the request body. Make sure to set the Content-Type header to
"application/json".

The easiest way to perform HTTP requests is to use
[HTTPie](https://github.com/httpie/desktop/releases) desktop application.
You can download the Ubuntu AppImage and run it. Select the following options:

```txt
Method: POST
URL: localhost:4001
Body: <<copy the json code from example>>
Content Type: text/json
```

Here are examples of the HTTP requests and responses for the HTTP API calls.

### Directory listing

```http
POST /lib HTTP/1.1
Host: localhost:4001
Content-Type: application/json
Content-Length: 388
{"query":"query {\n listDirectory(path: \"user1\") {\n repository {\n tree {\n blobs {\n edges {\n node {\n name\n type\n }\n }\n }\n trees {\n edges {\n node {\n name\n type\n }\n }\n }\n }\n }\n }\n}"}
```

This HTTP POST request will generate the following HTTP response message.

```http
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: close
Content-Length: 306
Content-Type: application/json; charset=utf-8
Date: Tue, 26 Sep 2023 20:26:49 GMT
X-Powered-By: Express
{"data":{"listDirectory":{"repository":{"tree":{"blobs":{"edges":[]},"trees":{"edges":[{"node":{"name":"data","type":"tree"}},{"node":{"name":"digital twins","type":"tree"}},{"node":{"name":"functions","type":"tree"}},{"node":{"name":"models","type":"tree"}},{"node":{"name":"tools","type":"tree"}}]}}}}}}
```

### Fetch a file

This query receives directory path and send the file contents to user in response.

To check this query, create a file `files/user2/data/welcome.txt`
with content of `hello world`.

```http
POST /lib HTTP/1.1
Host: localhost:4001
Content-Type: application/json
Content-Length: 217
{"query":"query {\n readFile(path: \"user2/data/welcome.txt\") {\n repository {\n blobs {\n nodes {\n name\n rawBlob\n rawTextBlob\n }\n }\n }\n }\n}"}
```

```http
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: close
Content-Length: 134
Content-Type: application/json; charset=utf-8
Date: Wed, 27 Sep 2023 09:17:18 GMT
X-Powered-By: Express
{"data":{"readFile":{"repository":{"blobs":{"nodes":[{"name":"welcome.txt","rawBlob":"hello world","rawTextBlob":"hello world"}]}}}}}
```
The service API documentation is available on
[user page](../../../user/servers/lib/LIB-MS.md).
69 changes: 69 additions & 0 deletions docs/developer/npm-packages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Publish NPM packages

The DTaaS software is developed as a monorepo with multiple npm packages.
Since publishing to [npmjs](https://www.npmjs.com/) is
irrevocable and public, developers are encouraged to setup their own private
npm registry for local development.

A private npm registry will help with local publish and unpublish steps.

## Setup private npm registry

We recommend using [verdaccio](https://verdaccio.org) for this task.
The following commands help you create a working private npm registry
for development.

```bash
docker run -d --name verdaccio -p 4873:4873 verdaccio/verdaccio
npm adduser --registry http://localhost:4873 #create a user on the verdaccio registry
npm set registry http://localhost:4873/
yarn config set registry "http://localhost:4873"
yarn login --registry "http://localhost:4873" #login with the credentials for yarn utility
npm login #login with the credentials for npm utility
```

You can open `http://localhost:4873` in your browser, login with
the user credentials to see the packages published.

### Publish to private npm registry

To publish a package to your local registry, do:

```bash
yarn install
yarn build #the dist/ directory is needed for publishing step
yarn publish --no-git-tag-version #increments version in package.json, publishes to registry
yarn publish #increments version in package.json, publishes to registry and adds a git tag
```

The package version in package.json gets updated as well. You can
open `http://localhost:4873` in your browser, login with the user credentials
to see the packages published. Please see
[verdaccio docs](https://verdaccio.org/docs/installation/#basic-usage)
for more information.

If there is a need to unpublish a package, ex: `@dtaas/[email protected]`, do:

```bash
npm unpublish --registry http://localhost:4873/ @dtaas/[email protected]
```

To install / uninstall this utility for all users, do:

```bash
sudo npm install --registry http://localhost:4873 -g @dtaas/runner
sudo npm list -g # should list @dtaas/runner in the packages
sudo npm remove --global @dtaas/runner
```

## :rocket: Use the packages

The packages available in private npm registry can be used like
the regular npm packages installed from [npmjs](https://www.npmjs.com/).

For example, to use `@dtaas/[email protected]` package, do:

```bash
sudo npm install --registry http://localhost:4873 -g @dtaas/runner
runner # launch the digital twin runner
```
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions mkdocs-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ nav:
- Client: developer/client/client.md
- Library Microservice: developer/servers/lib/lib-ms.md
- Testing: developer/testing/intro.md
- Publish NPM Packages: developer/npm-packages.md
- Bugs: bugs.md
- Thanks: thanks.md
- License: LICENSE.md
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ nav:
- Client: developer/client/client.md
- Library Microservice: developer/servers/lib/lib-ms.md
- Testing: developer/testing/intro.md
- Publish NPM Packages: developer/npm-packages.md
- Bugs: bugs.md
- Thanks: thanks.md
- License: LICENSE.md
Expand Down
44 changes: 8 additions & 36 deletions servers/execution/runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,16 @@ yarn start # start the application
yarn clean # deletes directories "build", "coverage", and "dist"
```

## :package: :ship: Publish Package
## :package: :ship: NPM package

### Setup private npm registry
Use the instructions in
[publish npm package](../../../docs/developer/npm-packages.md) for help
with publishing **runner npm package**.

This package need to be published to an npm registry. There after, the package
can be installed as a system command. Since publishing to npmjs.org is
irrevocable and public, developers are encouraged to setup their own private
npm registry for local development. We recommend using
[verdaccio](https://verdaccio.org) for this task. The following commands
help you create a working private npm registry for development.
Application of the advice given on that page for **runner** will require
running the following commands.

```bash
docker run -d --name verdaccio -p 4873:4873 verdaccio/verdaccio
npm adduser --registry http://localhost:4873 #create a user on the verdaccio registry
npm set registry http://localhost:4873/
yarn config set registry "http://localhost:4873"
```

You can open `http://localhost:4873` in your browser, login with
the user credentials to see the packages published.

### Publish to private registry

To publish a package to your local registry, do:
### Publish

```bash
yarn install
Expand All @@ -64,26 +50,12 @@ yarn publish --no-git-tag-version #increments version in package.json, publishes
yarn publish #increments version in package.json, publishes to registry and adds a git tag
```

The package version in package.json gets updated as well. You can
open `http://localhost:4873` in your browser, login with the user credentials
to see the packages published. Please see
[verdaccio docs](https://verdaccio.org/docs/installation/#basic-usage)
for more information.

If there is a need to unpublish a package, ex: `@dtaas/[email protected]`, do:
### Unpublish

```bash
npm unpublish --registry http://localhost:4873/ @dtaas/[email protected]
```

To install / uninstall this utility for all users, do:

```bash
sudo npm install --registry http://localhost:4873 -g @dtaas/runner
sudo npm list -g # should list @dtaas/runner in the packages
sudo npm remove --global @dtaas/runner
```

## :rocket: Access the service

```bash
Expand Down
Loading