configuration de la socket AF_UNIX en tant que client pour la communication avec le process KineIntercom

This commit is contained in:
Vincent BENOIT
2022-10-28 16:28:08 +02:00
parent aea9abbc8b
commit 37ae9d99b0
5 changed files with 55 additions and 3 deletions
+2 -2
View File
@@ -5,6 +5,6 @@
from src import app from src import app
print("Launch Flask KineInterCOM Configurateur Backend ...") print("Launch Flask KineInterCOM Configurateur Backend ...")
application = app.create_app() ret, application = app.create_app()
if application: if application and ret:
application.run(host="0.0.0.0", port=6000, use_reloader=False) application.run(host="0.0.0.0", port=6000, use_reloader=False)
+20 -1
View File
@@ -23,6 +23,7 @@ from src.account import account
from src.params import params from src.params import params
from src.schedule import schedule from src.schedule import schedule
from src.log import log as logs from src.log import log as logs
from src.manager import sock
from src.infos import info from src.infos import info
######################################################### #########################################################
@@ -37,6 +38,7 @@ def create_app(config=None, app_name=None):
:param app_name: :param app_name:
application name application name
''' '''
ret = True
if app_name is None: if app_name is None:
app_name = DefaultConfig.PROJECT app_name = DefaultConfig.PROJECT
@@ -51,8 +53,9 @@ def create_app(config=None, app_name=None):
configure_log(app) configure_log(app)
configure_blueprints(app) configure_blueprints(app)
ret = configure_connexion(app)
return app return ret, app
def configure_app(app=None, config=None): def configure_app(app=None, config=None):
''' configure the application with configuration file and/or object ''' configure the application with configuration file and/or object
@@ -136,3 +139,19 @@ def configure_blueprints(app=None):
''' '''
for bp in [auth, logs, account, params, schedule, info]: for bp in [auth, logs, account, params, schedule, info]:
app.register_blueprint(bp) app.register_blueprint(bp)
def configure_connexion(app=None):
''' Confgure AF_UNIX connexion with KineIntercom
process
'''
ret = False
try:
sock.connect(app.config['UNIX_ADDR'])
ret = True
except TimeoutError as e:
app.logger.error("Erreur de connexion avec le processus KineIntercom")
ret = False
except ConnectionRefusedError as e:
app.logger.error("Connexion refusée avec le processus KineIntercom")
ret = False
return ret
+1
View File
@@ -42,6 +42,7 @@ class BaseConfig(object):
MAX_CONTENT_LENGTH = 200 * 1024 * 1024 # 100 megabytes MAX_CONTENT_LENGTH = 200 * 1024 * 1024 # 100 megabytes
DB_PATH = os.path.join(os.getcwd(), 'db.json') DB_PATH = os.path.join(os.getcwd(), 'db.json')
UNIX_ADDR = "/tmp/uds_socket"
class DefaultConfig(BaseConfig): class DefaultConfig(BaseConfig):
DEBUG = True DEBUG = True
+21
View File
@@ -0,0 +1,21 @@
# -*- encoding: utf-8 -*-
# @author : vincent.benoit@scle.fr
# @brief : Client UNIX Socket Manager
#########################################################
# Importation de modules externes #
import sys, re, os
import socket
#########################################################
# Corps principal du programme #
#########################################################
# Decorators #
#########################################################
# Instantiation #
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+11
View File
@@ -24,6 +24,8 @@ import shutil
import hashlib import hashlib
from werkzeug.exceptions import HTTPException from werkzeug.exceptions import HTTPException
from src.manager import sock
######################################################### #########################################################
# Class et Methods # # Class et Methods #
@@ -133,6 +135,15 @@ def update_params():
with open(current_app.config['DB_PATH'], 'w') as f: with open(current_app.config['DB_PATH'], 'w') as f:
json.dump(data, f) json.dump(data, f)
try:
# send order to KineIntercom process
sock.send(b"RELOAD_DB\n")
except:
current_app.logger.error("Erreur d'envoi de l'ordre au processus KineIntercom")
abort(status.HTTP_406_NOT_ACCEPTABLE, description="Erreur d'envoi de l'ordre au processus")
content = {'message':'maj parameters successful!'} content = {'message':'maj parameters successful!'}
return content, status.HTTP_200_OK return content, status.HTTP_200_OK