Skip to content

Commit 786d755

Browse files
committed
Merge branch 'validate-schema' into 'master'
Validate schema See merge request acs/public/villas/controller!21
2 parents 3351413 + 14a020d commit 786d755

29 files changed

+421
-421
lines changed

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,18 @@ repos:
1818
rev: 3.8.4
1919
hooks:
2020
- id: flake8
21+
- repo: https://github.com/sirosen/check-jsonschema
22+
rev: 8a14ffa1d4c81a56057f55e1da308daeccc3bcd6
23+
hooks:
24+
- id: check-jsonschema
25+
name: "Check schemas"
26+
language: python
27+
files: ^villas/controller/schemas/.*\.yaml$
28+
types: [yaml]
29+
args: ["--schemafile", "https://json-schema.org/draft/2020-12/schema"]
30+
- id: check-jsonschema
31+
name: "Check OpenAPI doc"
32+
language: python
33+
files: ^doc/openapi.yaml$
34+
types: [yaml]
35+
args: ["--schemafile", "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json"]

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recursive-include villas/controller *

doc/openapi.yaml

Lines changed: 87 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ info:
44
title: VILLAScontroller API
55
description: 'A HTTP/REST API for controlling VILLAScontroller remotely for querying component status as well as issuing control actions.'
66
version: 0.0.1
7+
contact:
8+
name: "Steffen Vogel"
9+
email: "svogel2@eonerc.rwth-aachen.de"
710
license:
811
name: Apache-2.0
912
url: https://www.apache.org/licenses/LICENSE-2.0
13+
1014
servers:
1115
- url: https://villas.k8s.eonerc.rwth-aachen.de/api/v1
1216
description: Demo instance at RWTH Aachen
17+
1318
paths:
19+
1420
/:
1521
get:
1622
summary: 'Get status of VILLAScontroller daemon'
1723
operationId: getStatus
24+
tags:
25+
- status
1826
responses:
1927
'200':
2028
description: ''
@@ -66,9 +74,31 @@ paths:
6674
version: '#1 SMP Fri Sep 3 15:33:01 UTC 2021'
6775
machine: x86_64
6876

77+
/health:
78+
get:
79+
operationId: getHealth
80+
summary: Query health of daemon.
81+
tags:
82+
- status
83+
responses:
84+
'200':
85+
description: The daemon is healthy
86+
content:
87+
application/json:
88+
schema:
89+
type: object
90+
properties:
91+
status:
92+
type: string
93+
example:
94+
status: ok
95+
6996

7097
/component/{uuid}:
7198
get:
99+
summary: 'Get the current status of a component'
100+
operationId: getComponentStatus
101+
72102
parameters:
73103
- name: uuid
74104
in: path
@@ -77,10 +107,8 @@ paths:
77107
type: string
78108
format: uuid
79109

80-
operationId: getComponentStatus
81-
summary: 'Get the current status of a component'
82110
responses:
83-
200:
111+
'200':
84112
description: ''
85113
content:
86114
application/json:
@@ -186,139 +214,114 @@ paths:
186214
uuid: f4751894-205e-11eb-aefb-0741ff98abca
187215
schema:
188216
create:
189-
$schema: 'http://json-schema.org/draft-07/schema'
190-
$id: 'http://example.com/example.json'
217+
# $schema: 'http://json-schema.org/draft-07/schema'
191218
type: object
192219
default: {}
193220
required:
194-
- name
195-
- category
196-
- location
197-
- owner
198-
- realm
199-
- type
200-
- api_url
201-
- ws_url
221+
- name
222+
- category
223+
- location
224+
- owner
225+
- realm
226+
- type
227+
- api_url
228+
- ws_url
202229
properties:
203230
name:
204-
$id: '#/properties/name'
205231
type: string
206232
title: Component name
207233
default: New Component
208-
examples:
209-
- 'Generic Simulator #1'
234+
examples: 'Generic Simulator #1'
210235
owner:
211-
$id: '#/properties/owner'
212236
type: string
213237
title: Component owner
214-
default: ''
215238
examples:
216-
- rmr
217-
- svg
239+
- rmr
240+
- svg
218241
realm:
219-
$id: '#/properties/realm'
220242
type: string
221243
title: Component realm
222244
default: ''
223245
examples:
224-
- de.rwth-aachen.eonerc.acs
246+
- de.rwth-aachen.eonerc.acs
225247
category:
226-
$id: '#/properties/category'
227248
type: string
228249
title: Component category
229-
default: ''
230250
examples:
231-
- simulator
251+
- simulator
232252
location:
233-
$id: '#/properties/location'
234253
type: string
235254
title: Component location
236-
default: ''
237255
examples:
238-
- Richard's PC
256+
- Richard's PC
239257
type:
240-
$id: '#/properties/type'
241258
type: string
242-
title: The type schema
243-
default: ''
244-
examples:
245-
- generic
259+
default: generic
246260
uuid:
247-
$id: '#/properties/uuid'
248-
type: 'null'
249-
title: The uuid schema
250-
default: null
261+
type: 'string'
262+
format: uuid
251263
ws_url:
252-
$id: '#/properties/ws_url'
253264
type: string
254-
title: The ws_url schema
255-
default: ''
256265
examples:
257-
- 'https://villas.k8s.eonerc.rwth-aachen.de/ws/relay/generic_1'
266+
- 'https://villas.k8s.eonerc.rwth-aachen.de/ws/relay/generic_1'
258267
api_url:
259-
$id: '#/properties/api_url'
260268
type: string
261-
title: The api_url schema
262-
default: ''
263269
examples:
264-
- 'https://villas.k8s.eonerc.rwth-aachen.de/api/ic/generic_1'
270+
- 'https://villas.k8s.eonerc.rwth-aachen.de/api/ic/generic_1'
265271
shell:
266-
$id: '#/properties/shell'
267272
type: boolean
268-
title: The shell schema
269273
default: false
270274
examples:
271-
- true
275+
- true
272276
whitelist:
273-
$id: '#/properties/whitelist'
274277
type: array
275278
title: The whitelist schema
276279
default: []
277280
examples:
278-
- - /sbin/ping
279-
- ^echo
281+
- - /sbin/ping
282+
- ^echo
280283
additionalItems: true
281284
items:
282-
$id: '#/properties/whitelist/items'
283285
anyOf:
284-
- $id: '#/properties/whitelist/items/anyOf/0'
285-
type: string
286-
title: The first anyOf schema
287-
default: ''
288-
examples:
289-
- /sbin/ping
290-
- ^echo
291-
additionalProperties: true
292-
286+
- type: string
287+
examples:
288+
- /sbin/ping
289+
- ^echo
293290

294291
post:
295292
operationId: executeComponentAction
296293
summary: 'Send a control action to the component'
294+
requestBody:
295+
required: true
296+
content:
297+
application/json:
298+
schema:
299+
type: object
300+
properties:
301+
action:
302+
type: string
303+
enum:
304+
- start
305+
- stop
306+
- pause
307+
- resume
308+
- create
309+
- delete
310+
- shutdown
311+
- reset
312+
parameters:
313+
oneOf:
314+
- $ref: ../villas/controller/schemas/manager/generic/create.yaml
315+
- $ref: ../villas/controller/schemas/manager/kubernetes/create.yaml
316+
- $ref: ../villas/controller/schemas/simulator/dpsim/start.yaml
317+
- $ref: ../villas/controller/schemas/simulator/dummy/start.yaml
318+
297319
responses:
298-
200:
320+
'200':
299321
description: ''
300322
content:
301-
application/json:
302-
schema:
303-
type: object
304-
additionalProperties: true
323+
application/json: {}
305324

306-
example:
307-
runtime: 10.2
308325

309-
/health:
310-
get:
311-
operationId: getHealth
312-
summary: Query health of daemon.
313-
responses:
314-
'200':
315-
description: The daemon is healthy
316-
content:
317-
application/json:
318-
schema:
319-
type: object
320-
properties:
321-
status:
322-
type: string
323-
example:
324-
status: ok
326+
# example:
327+
# runtime: 10.2

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ xdg
88
dotmap
99
PyYAML
1010
tornado
11+
jsonschema>=4.1.0

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
'kubernetes',
3333
'xdg',
3434
'PyYAML',
35-
'tornado'
35+
'tornado',
36+
'jsonschema>=4.1.0'
3637
],
3738
data_files=[
3839
('/etc/villas/controller', glob('etc/*.{json,yaml}')),
@@ -43,5 +44,6 @@
4344
'villas-ctl=villas.controller.main:main',
4445
'villas-controller=villas.controller.main:main'
4546
],
46-
}
47+
},
48+
include_package_data=True
4749
)

villas/controller/commands/simulator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def _get_parameters(params, params_file):
1515

1616
try:
1717
if params is not None:
18-
parameters.update(yaml.loads(params,
19-
Loader=yaml.FullLoader))
18+
parameters.update(yaml.load(params,
19+
Loader=yaml.FullLoader))
2020
if params_file is not None:
2121
with open(params_file) as f:
2222
parameters.update(yaml.load(f, Loader=yaml.FullLoader))

0 commit comments

Comments
 (0)