Commit 609ca6a1 authored by Daniele Venzano's avatar Daniele Venzano
Browse files

Expose endpoints through the API and the command-line interface

parent 71c7491a
......@@ -175,7 +175,7 @@ class APIEndpoint:
log.debug('Cleanup task finished')
def execution_endpoints(self, uid, role, execution: zoe_lib.sql_manager.Execution):
def execution_endpoints(self, uid: str, role: str, execution: zoe_lib.sql_manager.Execution):
"""Return a list of the services and public endpoints available for a certain execution."""
services_info = []
endpoints = []
......
......@@ -19,7 +19,7 @@ from typing import List
import tornado.web
from zoe_api.rest_api.execution import ExecutionAPI, ExecutionCollectionAPI, ExecutionDeleteAPI
from zoe_api.rest_api.execution import ExecutionAPI, ExecutionCollectionAPI, ExecutionDeleteAPI, ExecutionEndpointsAPI
from zoe_api.rest_api.info import InfoAPI
from zoe_api.rest_api.service import ServiceAPI, ServiceLogsAPI
from zoe_api.rest_api.discovery import DiscoveryAPI
......@@ -41,6 +41,7 @@ def api_init(api_endpoint) -> List[tornado.web.URLSpec]:
tornado.web.url(API_PATH + r'/execution/([0-9]+)', ExecutionAPI, route_args),
tornado.web.url(API_PATH + r'/execution/delete/([0-9]+)', ExecutionDeleteAPI, route_args),
tornado.web.url(API_PATH + r'/execution/endpoints/([0-9]+)', ExecutionEndpointsAPI, route_args),
tornado.web.url(API_PATH + r'/execution', ExecutionCollectionAPI, route_args),
tornado.web.url(API_PATH + r'/service/([0-9]+)', ServiceAPI, route_args),
......
......@@ -130,3 +130,29 @@ class ExecutionCollectionAPI(RequestHandler):
def data_received(self, chunk):
"""Not implemented as we do not use stream uploads"""
pass
class ExecutionEndpointsAPI(RequestHandler):
"""The ExecutionEndpoints API endpoint."""
def initialize(self, **kwargs):
"""Initializes the request handler."""
self.api_endpoint = kwargs['api_endpoint'] # type: APIEndpoint
@catch_exceptions
def get(self, execution_id: int):
"""
Get a list of execution endpoints.
:param execution_id: the execution to be deleted
"""
uid, role = get_auth(self)
execution = self.api_endpoint.execution_by_id(uid, role, execution_id)
services_, endpoints = self.api_endpoint.execution_endpoints(uid, role, execution)
self.write({'endpoints': endpoints})
def data_received(self, chunk):
"""Not implemented as we do not use stream uploads"""
pass
......@@ -136,9 +136,11 @@ def exec_get_cmd(args):
print('Execution not found')
else:
print('Execution {} (ID: {})'.format(execution['name'], execution['id']))
print('Application name: {}'.format(execution['description']['name']))
print('Status: {}'.format(execution['status']))
if execution['status'] == 'error':
print('Last error: {}'.format(execution['error_message']))
print()
print('Time submit: {}'.format(datetime.datetime.fromtimestamp(execution['time_submit'])))
if execution['time_start'] is None:
......@@ -150,9 +152,17 @@ def exec_get_cmd(args):
print('Time end: {}'.format('not yet'))
else:
print('Time end: {}'.format(datetime.datetime.fromtimestamp(execution['time_end'])))
print()
app = execution['description']
print('Application name: {}'.format(app['name']))
endpoints = exec_api.endpoints(execution['id'])
if len(endpoints) > 0:
print('Exposed endpoints:')
else:
print('This ZApp does not expose any endpoint')
for ep in endpoints:
print(' - {}: {}'.format(ep[0], ep[1]))
print()
for c_id in execution['services']:
service = cont_api.get(c_id)
print('Service {} (ID: {})'.format(service['name'], service['id']))
......@@ -160,10 +170,6 @@ def exec_get_cmd(args):
print(' - docker status: {}'.format(service['docker_status']))
if service['error_message'] is not None:
print(' - error: {}'.format(service['error_message']))
if service['docker_status'] == 'started':
ip = service['ip_address']
for port in service['description']['ports']:
print(' - {}: {}://{}:{}{}'.format(port['name'], port['protocol'], ip, port['port_number'], port['path']))
def exec_kill_cmd(args):
......
......@@ -110,3 +110,16 @@ class ZoeExecutionsAPI(ZoeAPIBase):
raise ZoeAPIException(data['message'])
else:
return data['execution_id']
def endpoints(self, execution_id):
"""
Retrieve the public endpoints exposed by a running execution.
:param execution_id: the execution to inspect
:return:
"""
data, status_code = self._rest_get('/execution/endpoints/' + str(execution_id))
if status_code == 200:
return data['endpoints']
else:
return None
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment