mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 13:01:32 +00:00
Strip controller from TFW
This commit is contained in:
parent
fda242d263
commit
abcf490019
@ -43,12 +43,10 @@ ENV TFW_PUBLIC_PORT=8888 \
|
|||||||
TFW_LOGIN_APP_PORT=6666 \
|
TFW_LOGIN_APP_PORT=6666 \
|
||||||
TFW_TERMINADO_PORT=7878 \
|
TFW_TERMINADO_PORT=7878 \
|
||||||
TFW_SUPERVISOR_HTTP_PORT=9001 \
|
TFW_SUPERVISOR_HTTP_PORT=9001 \
|
||||||
TFW_CONTROLLER_PORT=7777 \
|
|
||||||
TFW_CRP_LISTENER_PORT=5555 \
|
|
||||||
TFW_PUBLISHER_PORT=7654 \
|
TFW_PUBLISHER_PORT=7654 \
|
||||||
TFW_RECEIVER_PORT=8765
|
TFW_RECEIVER_PORT=8765
|
||||||
|
|
||||||
EXPOSE ${TFW_PUBLIC_PORT} ${TFW_CRP_LISTENER_PORT}
|
EXPOSE ${TFW_PUBLIC_PORT}
|
||||||
|
|
||||||
ENV PYTHONPATH="/usr/local/lib/" \
|
ENV PYTHONPATH="/usr/local/lib/" \
|
||||||
TFW_SUPERVISOR_HTTP_URI="http://localhost:${TFW_SUPERVISOR_HTTP_PORT}" \
|
TFW_SUPERVISOR_HTTP_URI="http://localhost:${TFW_SUPERVISOR_HTTP_PORT}" \
|
||||||
@ -58,7 +56,6 @@ ENV PYTHONPATH="/usr/local/lib/" \
|
|||||||
TFW_NGINX_DEFAULT="/etc/nginx/sites-enabled/default" \
|
TFW_NGINX_DEFAULT="/etc/nginx/sites-enabled/default" \
|
||||||
TFW_NGINX_COMPONENTS="/etc/nginx/components" \
|
TFW_NGINX_COMPONENTS="/etc/nginx/components" \
|
||||||
TFW_LIB_DIR="/usr/local/lib/" \
|
TFW_LIB_DIR="/usr/local/lib/" \
|
||||||
TFW_CONTROLLER_DIR="/srv/controller" \
|
|
||||||
TFW_TERMINADO_DIR="/tmp/terminado_server" \
|
TFW_TERMINADO_DIR="/tmp/terminado_server" \
|
||||||
TFW_FRONTEND_DIR="/srv/frontend" \
|
TFW_FRONTEND_DIR="/srv/frontend" \
|
||||||
TFW_HISTFILE="/home/${AVATAO_USER}/.bash_history" \
|
TFW_HISTFILE="/home/${AVATAO_USER}/.bash_history" \
|
||||||
@ -84,7 +81,6 @@ RUN chown -R ${AVATAO_USER} /var/log/nginx /var/lib/nginx
|
|||||||
COPY supervisor/supervisord.conf ${TFW_SUPERVISORD_CONF}
|
COPY supervisor/supervisord.conf ${TFW_SUPERVISORD_CONF}
|
||||||
COPY supervisor/components/ ${TFW_SUPERVISORD_COMPONENTS}
|
COPY supervisor/components/ ${TFW_SUPERVISORD_COMPONENTS}
|
||||||
COPY lib ${TFW_LIB_DIR}
|
COPY lib ${TFW_LIB_DIR}
|
||||||
COPY src/controller ${TFW_CONTROLLER_DIR}
|
|
||||||
RUN mv /data/dist ${TFW_FRONTEND_DIR} && rm -rf /data
|
RUN mv /data/dist ${TFW_FRONTEND_DIR} && rm -rf /data
|
||||||
|
|
||||||
### TFW internals ^ ### DEMO v ###############################################################
|
### TFW internals ^ ### DEMO v ###############################################################
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
from tfw.networking.serialization import deserialize_all
|
|
||||||
from tfw.networking.solvable_connector import SolvableConnector
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncSolvableConnector(SolvableConnector):
|
|
||||||
def __init__(self, async_zmq_context=None):
|
|
||||||
if async_zmq_context is None:
|
|
||||||
from zmq.eventloop.future import Context
|
|
||||||
async_zmq_context = Context.instance()
|
|
||||||
super(AsyncSolvableConnector, self).__init__(async_zmq_context)
|
|
||||||
|
|
||||||
async def recv(self):
|
|
||||||
response = await self._zmq_req_socket.recv_multipart()
|
|
||||||
return deserialize_all(*response)
|
|
@ -1,7 +1,6 @@
|
|||||||
from tornado.web import Application
|
from tornado.web import Application
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from tfw.networking.server.controller_responder import ControllerResponder
|
|
||||||
from tfw.networking.server.zmq_websocket_handler import ZMQWebSocketProxy
|
from tfw.networking.server.zmq_websocket_handler import ZMQWebSocketProxy
|
||||||
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
||||||
from tfw.message_sender import MessageSender
|
from tfw.message_sender import MessageSender
|
||||||
@ -20,7 +19,7 @@ class TFWServer:
|
|||||||
[(r'/ws', ZMQWebSocketProxy, {'make_response': self.make_response,
|
[(r'/ws', ZMQWebSocketProxy, {'make_response': self.make_response,
|
||||||
'proxy_filter': self.proxy_filter})]
|
'proxy_filter': self.proxy_filter})]
|
||||||
)
|
)
|
||||||
self.controller_responder = ControllerResponder(self.fsm)
|
#self.controller_responder = ControllerResponder(self.fsm) TODO: add this once controller stuff is resolved
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fsm(self):
|
def fsm(self):
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
import zmq
|
|
||||||
|
|
||||||
from tfw.config import tfwenv
|
|
||||||
from tfw.networking.zmq_connector_base import ZMQConnectorBase
|
|
||||||
from tfw.networking.serialization import serialize_all, deserialize_all
|
|
||||||
|
|
||||||
|
|
||||||
class SolvableConnector(ZMQConnectorBase):
|
|
||||||
def __init__(self, zmq_context=None):
|
|
||||||
super(SolvableConnector, self).__init__(zmq_context)
|
|
||||||
self._zmq_req_socket = self._zmq_context.socket(zmq.REQ)
|
|
||||||
self._zmq_req_socket.bind('tcp://*:{}'.format(tfwenv.CONTROLLER_PORT))
|
|
||||||
|
|
||||||
def send(self, key, message):
|
|
||||||
self._zmq_req_socket.send_multipart(serialize_all(key, message))
|
|
||||||
|
|
||||||
def recv(self):
|
|
||||||
return deserialize_all(*self._zmq_req_socket.recv_multipart())
|
|
@ -1,38 +0,0 @@
|
|||||||
import secrets
|
|
||||||
from tornado.ioloop import IOLoop
|
|
||||||
from tornado.web import Application
|
|
||||||
|
|
||||||
from tao.config import taoenv
|
|
||||||
from tfw.config import tfwenv
|
|
||||||
from handlers import SolutionCheckHandler, TestHandler
|
|
||||||
from tfw.networking.async_solvable_connector import AsyncSolvableConnector
|
|
||||||
|
|
||||||
from tfw.config.logs import logging
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
async def setup_token(solvable_connector, token):
|
|
||||||
solvable_connector.send('token', token)
|
|
||||||
key, data = await solvable_connector.recv()
|
|
||||||
if secrets.compare_digest(token, key):
|
|
||||||
log.debug('Token setup is done.')
|
|
||||||
else:
|
|
||||||
log.error('Failed to setup token between controller and solvable.') # TODO: signaling to Avatao platform?
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
kwargs = {
|
|
||||||
'solvable_connector': AsyncSolvableConnector(),
|
|
||||||
'token': secrets.token_hex(32)
|
|
||||||
}
|
|
||||||
IOLoop.instance().add_callback(setup_token, **kwargs)
|
|
||||||
routes = [
|
|
||||||
(r'/{secret}/?'.format(secret=taoenv.SECRET), SolutionCheckHandler, kwargs),
|
|
||||||
(r'/{secret}/test/?'.format(secret=taoenv.SECRET), TestHandler, kwargs)
|
|
||||||
]
|
|
||||||
app = Application(
|
|
||||||
routes
|
|
||||||
)
|
|
||||||
app.listen(tfwenv.CRP_LISTENER_PORT)
|
|
||||||
log.debug('Controller listening on {}'.format(tfwenv.CRP_LISTENER_PORT))
|
|
||||||
IOLoop.instance().start()
|
|
@ -1,2 +0,0 @@
|
|||||||
from .solution_check_handler import SolutionCheckHandler
|
|
||||||
from .test_handler import TestHandler
|
|
@ -1,19 +0,0 @@
|
|||||||
import secrets
|
|
||||||
from tornado.web import RequestHandler, HTTPError
|
|
||||||
|
|
||||||
from tfw.config.logs import logging
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class SolutionCheckHandler(RequestHandler):
|
|
||||||
def initialize(self, solvable_connector, token):
|
|
||||||
self.solvable_connector = solvable_connector
|
|
||||||
self.token = token
|
|
||||||
|
|
||||||
async def get(self):
|
|
||||||
log.debug('Sending request to solvable')
|
|
||||||
self.solvable_connector.send('solution_check', {})
|
|
||||||
resp_token, resp_data = await self.solvable_connector.recv()
|
|
||||||
if not secrets.compare_digest(self.token, resp_token):
|
|
||||||
raise HTTPError(500, 'Solvable didn\'t provide initial token.')
|
|
||||||
log.debug('Received answer from solvable')
|
|
||||||
self.write(resp_data)
|
|
@ -1,15 +0,0 @@
|
|||||||
import secrets
|
|
||||||
from tornado.web import RequestHandler, HTTPError
|
|
||||||
|
|
||||||
|
|
||||||
class TestHandler(RequestHandler):
|
|
||||||
def initialize(self, solvable_connector, token):
|
|
||||||
self.solvable_connector = solvable_connector
|
|
||||||
self.token = token
|
|
||||||
|
|
||||||
async def get(self):
|
|
||||||
self.solvable_connector.send('test', {})
|
|
||||||
resp_token, resp_data = await self.solvable_connector.recv()
|
|
||||||
if not secrets.compare_digest(self.token, resp_token):
|
|
||||||
raise HTTPError(500, 'Solvable didn\'t provide initial token.')
|
|
||||||
self.write(resp_data)
|
|
@ -1,3 +0,0 @@
|
|||||||
[program:controller]
|
|
||||||
directory=%(ENV_TFW_CONTROLLER_DIR)s
|
|
||||||
command=env python app.py
|
|
Loading…
Reference in New Issue
Block a user