Skip to content

Commit

Permalink
Adds API Specification for DT Runner and updates shell scripts
Browse files Browse the repository at this point in the history
  - Add OpenAPI specification for DT Runner
  - Updates git-hooks to check against runner as well
  - Adds more yarn test commands to runner
  • Loading branch information
prasadtalasila committed Sep 18, 2023
1 parent d31da4a commit 2fe0344
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 6 deletions.
14 changes: 13 additions & 1 deletion .git-hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#!/usr/bin/env sh

TOP_DIR="$(pwd)"
export TOP_DIR

if git diff --cached --name-only | grep "^client/" >/dev/null; then
cd client || exit
yarn install
yarn format && yarn syntax
else
printf "No changes in the client directory. Skipping pre-commit hook."
printf "No changes in the client directory. Skipping pre-commit hook.\n\n"
fi

cd "$TOP_DIR" || exit
if git diff --cached --name-only | grep "^servers/execution/runner/" >/dev/null; then
cd "servers/execution/runner" || exit
yarn install
yarn format && yarn syntax
else
printf "No changes in the servers/execution/runner directory. Skipping pre-commit hook.\n\n"
fi
13 changes: 12 additions & 1 deletion .git-hooks/pre-push
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#!/usr/bin/env sh

BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
TOP_DIR="$(pwd)"
export TOP_DIR

if git diff --name-only origin/"$BRANCH_NAME"...HEAD | grep "^client/" >/dev/null; then
cd client || exit
yarn install
yarn jest . --coverage=false
else
echo "No changes in the client directory. Skipping pre-push hook."
printf "No changes in the client directory. Skipping pre-push hook.\n\n"
fi

cd "$TOP_DIR" || exit
if git diff --name-only origin/"$BRANCH_NAME"...HEAD | grep "^servers/execution/runner/" >/dev/null; then
cd "servers/execution/runner" || exit
yarn install
yarn test:nocov
else
printf "No changes in the servers/execution/runner/ directory. Skipping pre-push hook.\n\n"
fi
3 changes: 2 additions & 1 deletion servers/execution/runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"start": "script/start.bash",
"syntax": "script/syntax.bash",
"test": "script/test.bash",
"test:watchAll": "script/test.bash --watchAll"
"test:nocov": "script/test.bash nocoverage",
"test:watchAll": "script/test.bash watchAll"
},
"bin": {
"runner": "./dist/src/runner.js"
Expand Down
110 changes: 110 additions & 0 deletions servers/execution/runner/runner-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
openapi: '3.0.2'
info:
title: Digital Twin Runner API
version: '0.0.1'
contact:
name: Prasad Talasila
url: https://github.com/INTO-CPS-Association/DTaaS
license:
name: The INTO-CPS Association
url: https://into-cps.org
description: |
The Digital Twin (DT) Runner is a component of Digital Twin as a Service (DTaaS) software. The DT Runner component is responsible for managing the execution of one digital twin.
This document describes the API for the DT Runner.
servers:
- url: https://api.server.test/v0.0.1
paths:
/controller/status:
get:
description: 'Check the status of the Digital Twin Runner. This is a heartbeat check.'
responses:
'200':
description: Aliv-e
'404':
description: 'Service is unavailable'

/controller/logs:
get:
description: 'Fetch the logs of Digital Twin Runner.'
responses:
'200':
description: OK
content:
text/plain:
schema:
type: string
example: |
'[20:20:10] Request received'
'404':
description: 'Service is unavailable'

/controller/terminate:
get:
description: 'Stop the Digital Twin managed by Digital Twin Runner and exit.'
responses:
'200':
description: Shutting down
'404':
description: 'Service is unavailable'

/dt/lifecycle/phase/list:
get:
description: |
'Fetch the list of lifecycle phases supported by the digital twin. These lifecycles are given as configuration information to the Digital Twin Runner.'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Phases"

/dt/lifecycle/phase/{phaseName}:
post:
description: |
'Change to the lifecycle phase indicated in the request URL'
parameters:
- in: path
name: phaseName
schema:
type: string
required: true
description: Phase name of digital twin
responses:
'200':
description: OK

/dt/lifecycle/phase/history:
get:
description: |
'Get the history of phase change requests made to the digital twin.'
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
type: string
example: ["execute", "evolve"]

components:
schemas:
Phase:
type: object
properties:
phaseName:
type: string
example: execute
description:
type: string
example: "execute the digital twin"
Phases:
type: array
items:
$ref: "#/components/schemas/Phase"
example: |
[{phaseName: configure, description: "set configuration of digital twin"}, {phaseName: execute, description: "execute the digital twin"}]
16 changes: 14 additions & 2 deletions servers/execution/runner/script/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@

printf "testing in progress"
new_path="$(yarn bin):$PATH"
export PATH="$new_path"
PATH="$new_path"
export PATH

if [ "$1" == "nocoverage" ]; then
COV_FLAG="false"
WATCH_FLAG=""
elif [ "$1" == "watchAll" ]; then
COV_FLAG="true"
WATCH_FLAG="--watchAll"
else
COV_FLAG="true"
WATCH_FLAG=""
fi

npx cross-env NODE_OPTIONS=--experimental-vm-modules \
NODE_NO_WARNINGS=1 \
jest --coverage "$1"
jest --coverage="${COV_FLAG}" "$WATCH_FLAG"
2 changes: 1 addition & 1 deletion servers/lib/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ build/
dist/
node_modules/
script/
src/types.ts
src/types.ts

0 comments on commit 2fe0344

Please sign in to comment.