Skip to content
Snippets Groups Projects
Commit 2da89d3f authored by David Trattnig's avatar David Trattnig
Browse files

Added status and health endpoints.

parent 8ed3c3ce
No related branches found
No related tags found
No related merge requests found
......@@ -24,11 +24,13 @@ servers:
default: "8008"
version:
default: v1
- url: https://virtserver.swaggerhub.com/AURA-Engine/engine-api/1.0.0
description: SwaggerHub API Auto Mocking
tags:
- name: public
description: Operations available to the public
- name: internal
description: Secured, internal calls only
description: Secured calls only
paths:
/trackservice:
get:
......@@ -147,7 +149,7 @@ paths:
"400":
description: bad input parameter
x-openapi-router-controller: src.controllers.internal_controller
/status/active:
/engine/current:
get:
tags:
- internal
......@@ -165,6 +167,84 @@ paths:
"400":
description: bad input parameter
x-openapi-router-controller: src.controllers.internal_controller
/engine/{engineNumber}/health:
get:
tags:
- internal
summary: Get most recent health info
description: |
Retrieves the most recent health info of the requested engine
operationId: get_engine_health
parameters:
- name: engineNumber
in: path
description: Number of the engine
required: true
style: simple
explode: false
schema:
maximum: 2
minimum: 1
type: integer
responses:
"200":
description: report matching criteria
content:
application/json:
schema:
$ref: '#/components/schemas/HealthInfo'
"400":
description: bad input parameter
x-openapi-router-controller: src.controllers.internal_controller
post:
tags:
- internal
summary: Log health info
description: |
Logs another health entry for the given engine
operationId: log_engine_health
parameters:
- name: engineNumber
in: path
description: Number of the engine
required: true
style: simple
explode: false
schema:
maximum: 2
minimum: 1
type: integer
responses:
"200":
description: health info logged
"400":
description: bad input parameter
x-openapi-router-controller: src.controllers.internal_controller
/engine/{engineNumber}/activate:
put:
tags:
- internal
summary: Set active engine
description: |
Activates one engine and deactivates the other
operationId: activate_engine
parameters:
- name: engineNumber
in: path
description: Number of the engine
required: true
style: simple
explode: false
schema:
maximum: 2
minimum: 1
type: integer
responses:
"200":
description: status updated
"400":
description: bad input parameter
x-openapi-router-controller: src.controllers.internal_controller
components:
schemas:
PlayLogEntry:
......@@ -184,7 +264,7 @@ components:
example: Bricolage
track_title:
type: string
example: One Small Step
example: Chomp Samba
track_duration:
type: integer
example: 234
......@@ -225,7 +305,7 @@ components:
example: Feature
show_category:
type: string
example: Experimental
example: Progressive
show_topic:
type: string
example: Music
......@@ -234,7 +314,7 @@ components:
show_funding_category: Standard
show_id: 1
schedule_fallback_type: 0
track_title: One Small Step
track_title: Chomp Samba
show_name: Special Music Show
track_artist: Amon Tobin
show_topic: Music
......@@ -245,12 +325,13 @@ components:
schedule_repetition: false
schedule_end: 2020-08-29T09:12:33.001Z
track_duration: 234
show_category: Experimental
show_category: Progressive
schedule_id: 1
schedule_start: 2020-08-29T09:12:33.001Z
StatusEntry:
required:
- engine_host
- engine_number
- health_info
- is_active
- is_healthy
......@@ -261,6 +342,10 @@ components:
type: string
format: date-time
example: 2020-08-29T09:12:33.001Z
engine_number:
maximum: 2
minimum: 1
type: integer
engine_host:
type: string
example: engine1.local
......@@ -270,13 +355,13 @@ components:
is_active:
type: boolean
example: true
health_info:
type: string
example: '{}'
example:
is_healthy: true
is_active: true
health_info: '{}'
engine_number: 1
engine_host: engine1.local
log_time: 2020-08-29T09:12:33.001Z
HealthInfo:
type: string
example: '{}'
import connexion
import six
from src.models.health_info import HealthInfo # noqa: E501
from src.models.play_log_entry import PlayLogEntry # noqa: E501
from src.models.status_entry import StatusEntry # noqa: E501
from src import util
def activate_engine(engine_number): # noqa: E501
"""Set active engine
Activates one engine and deactivates the other # noqa: E501
:param engine_number: Number of the engine
:type engine_number: int
:rtype: None
"""
return 'do some magic!'
def get_active_engine(): # noqa: E501
"""Get active engine
......@@ -17,6 +31,19 @@ def get_active_engine(): # noqa: E501
return 'do some magic!'
def get_engine_health(engine_number): # noqa: E501
"""Get most recent health info
Retrieves the most recent health info of the requested engine # noqa: E501
:param engine_number: Number of the engine
:type engine_number: int
:rtype: HealthInfo
"""
return 'do some magic!'
def get_report(year_month): # noqa: E501
"""Report for one month
......@@ -28,3 +55,16 @@ def get_report(year_month): # noqa: E501
:rtype: List[PlayLogEntry]
"""
return 'do some magic!'
def log_engine_health(engine_number): # noqa: E501
"""Log health info
Logs another health entry for the given engine # noqa: E501
:param engine_number: Number of the engine
:type engine_number: int
:rtype: None
"""
return 'do some magic!'
......@@ -3,5 +3,6 @@
# flake8: noqa
from __future__ import absolute_import
# import models into model package
from src.models.health_info import HealthInfo
from src.models.play_log_entry import PlayLogEntry
from src.models.status_entry import StatusEntry
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from src.models.base_model_ import Model
from src import util
class HealthInfo(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self): # noqa: E501
"""HealthInfo - a model defined in Swagger
"""
self.swagger_types = {
}
self.attribute_map = {
}
@classmethod
def from_dict(cls, dikt):
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The HealthInfo of this HealthInfo. # noqa: E501
:rtype: HealthInfo
"""
return util.deserialize_model(dikt, cls)
......@@ -14,40 +14,40 @@ class StatusEntry(Model):
Do not edit the class manually.
"""
def __init__(self, log_time=None, engine_host=None, is_healthy=None, is_active=None, health_info=None): # noqa: E501
def __init__(self, log_time=None, engine_number=None, engine_host=None, is_healthy=None, is_active=None): # noqa: E501
"""StatusEntry - a model defined in Swagger
:param log_time: The log_time of this StatusEntry. # noqa: E501
:type log_time: datetime
:param engine_number: The engine_number of this StatusEntry. # noqa: E501
:type engine_number: int
:param engine_host: The engine_host of this StatusEntry. # noqa: E501
:type engine_host: str
:param is_healthy: The is_healthy of this StatusEntry. # noqa: E501
:type is_healthy: bool
:param is_active: The is_active of this StatusEntry. # noqa: E501
:type is_active: bool
:param health_info: The health_info of this StatusEntry. # noqa: E501
:type health_info: str
"""
self.swagger_types = {
'log_time': datetime,
'engine_number': int,
'engine_host': str,
'is_healthy': bool,
'is_active': bool,
'health_info': str
'is_active': bool
}
self.attribute_map = {
'log_time': 'log_time',
'engine_number': 'engine_number',
'engine_host': 'engine_host',
'is_healthy': 'is_healthy',
'is_active': 'is_active',
'health_info': 'health_info'
'is_active': 'is_active'
}
self._log_time = log_time
self._engine_number = engine_number
self._engine_host = engine_host
self._is_healthy = is_healthy
self._is_active = is_active
self._health_info = health_info
@classmethod
def from_dict(cls, dikt):
......@@ -83,6 +83,29 @@ class StatusEntry(Model):
self._log_time = log_time
@property
def engine_number(self):
"""Gets the engine_number of this StatusEntry.
:return: The engine_number of this StatusEntry.
:rtype: int
"""
return self._engine_number
@engine_number.setter
def engine_number(self, engine_number):
"""Sets the engine_number of this StatusEntry.
:param engine_number: The engine_number of this StatusEntry.
:type engine_number: int
"""
if engine_number is None:
raise ValueError("Invalid value for `engine_number`, must not be `None`") # noqa: E501
self._engine_number = engine_number
@property
def engine_host(self):
"""Gets the engine_host of this StatusEntry.
......@@ -151,26 +174,3 @@ class StatusEntry(Model):
raise ValueError("Invalid value for `is_active`, must not be `None`") # noqa: E501
self._is_active = is_active
@property
def health_info(self):
"""Gets the health_info of this StatusEntry.
:return: The health_info of this StatusEntry.
:rtype: str
"""
return self._health_info
@health_info.setter
def health_info(self, health_info):
"""Sets the health_info of this StatusEntry.
:param health_info: The health_info of this StatusEntry.
:type health_info: str
"""
if health_info is None:
raise ValueError("Invalid value for `health_info`, must not be `None`") # noqa: E501
self._health_info = health_info
......@@ -5,6 +5,7 @@ from __future__ import absolute_import
from flask import json
from six import BytesIO
from src.models.health_info import HealthInfo # noqa: E501
from src.models.play_log_entry import PlayLogEntry # noqa: E501
from src.models.status_entry import StatusEntry # noqa: E501
from src.test import BaseTestCase
......@@ -13,13 +14,35 @@ from src.test import BaseTestCase
class TestInternalController(BaseTestCase):
"""InternalController integration test stubs"""
def test_activate_engine(self):
"""Test case for activate_engine
Set active engine
"""
response = self.client.open(
'/engine/{engineNumber}/activate'.format(engine_number=2),
method='PUT')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_active_engine(self):
"""Test case for get_active_engine
Get active engine
"""
response = self.client.open(
'/status/active',
'/engine/current',
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_get_engine_health(self):
"""Test case for get_engine_health
Get most recent health info
"""
response = self.client.open(
'/engine/{engineNumber}/health'.format(engine_number=2),
method='GET')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
......@@ -35,6 +58,17 @@ class TestInternalController(BaseTestCase):
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_log_engine_health(self):
"""Test case for log_engine_health
Log health info
"""
response = self.client.open(
'/engine/{engineNumber}/health'.format(engine_number=2),
method='POST')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
if __name__ == '__main__':
import unittest
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment