WIP2
This commit is contained in:
parent
a7934e37d7
commit
eccc5c4098
@ -1,4 +1,4 @@
|
||||
uri: applicationservices.dataset.updated
|
||||
uri: applicationservice.dataset.updated
|
||||
|
||||
description: |
|
||||
Initialise la table pour les services applicatifs.
|
||||
@ -7,8 +7,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: applicationservices-domain
|
||||
|
||||
parameters:
|
||||
release_path:
|
||||
type: String
|
@ -4,14 +4,10 @@ uri: config.configuration.server.deploy
|
||||
description: |
|
||||
Déployer la configuration d'un serveur.
|
||||
|
||||
sampleuse: ~
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: config-domain
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -4,14 +4,10 @@ uri: config.configuration.server.get
|
||||
description: |
|
||||
Récupère le contenu de la configuration.
|
||||
|
||||
sampleuse: ~
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: false
|
||||
|
||||
domain: config-domain
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -4,14 +4,10 @@ uri: config.configuration.server.updated
|
||||
description: |
|
||||
Une configuration de serveur a été mise à jour.
|
||||
|
||||
sampleuse: ~
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: config-domain
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -7,8 +7,6 @@ pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: server-domain
|
||||
|
||||
parameters:
|
||||
type: Server
|
||||
description: Description du serveur.
|
||||
|
@ -1,8 +1,6 @@
|
||||
---
|
||||
uri: server.deleted
|
||||
|
||||
sampleuse: ~
|
||||
|
||||
description: |
|
||||
Un serveur a été supprimé.
|
||||
|
||||
@ -10,8 +8,6 @@ pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: server-domain
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -4,15 +4,10 @@ uri: server.list
|
||||
description: |
|
||||
Liste les serveurs disponibles.
|
||||
|
||||
sampleuse: |
|
||||
zephir-client server.list
|
||||
|
||||
public: true
|
||||
|
||||
pattern: rpc
|
||||
|
||||
domain: server-domain
|
||||
|
||||
response:
|
||||
type: '[]Server'
|
||||
description: Retourne la liste des serveurs.
|
||||
|
@ -7,8 +7,6 @@ pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: servermodel-domain
|
||||
|
||||
parameters:
|
||||
type: Servermodel
|
||||
description: Informations sur les modèles de serveur créés.
|
||||
|
@ -7,8 +7,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: servermodel-domain
|
||||
|
||||
parameters:
|
||||
release_path:
|
||||
type: String
|
||||
|
@ -4,15 +4,10 @@ uri: servermodel.describe
|
||||
description: |
|
||||
Retourne les attributs détaillés d'un modèle de serveur.
|
||||
|
||||
sampleuse: |
|
||||
zephir-client servermodel.describe -s 1
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: servermodel-domain
|
||||
|
||||
parameters:
|
||||
servermodelid:
|
||||
type: Number
|
||||
|
@ -4,15 +4,10 @@ uri: servermodel.list
|
||||
description: |
|
||||
Retourne la liste des modèles de serveur disponibles.
|
||||
|
||||
sampleuse: |
|
||||
zephir-client servermodel.list
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: servermodel-domain
|
||||
|
||||
parameters:
|
||||
sourceid:
|
||||
type: Number
|
||||
|
@ -7,8 +7,6 @@ pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: servermodel-domain
|
||||
|
||||
parameters:
|
||||
type: 'Servermodel'
|
||||
description: Informations sur les modèles de serveur modifiés.
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
response:
|
||||
type: '[]Session'
|
||||
description: |
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
id:
|
||||
type: Number
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -7,8 +7,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
response:
|
||||
type: '[]Session'
|
||||
description: |
|
||||
|
@ -7,8 +7,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
id:
|
||||
type: Number
|
||||
|
@ -7,8 +7,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -7,8 +7,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: source-domain
|
||||
|
||||
parameters:
|
||||
source_name:
|
||||
type: String
|
||||
|
@ -8,8 +8,6 @@ pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: source-domain
|
||||
|
||||
response:
|
||||
type: '[]Release'
|
||||
description: Liste des versions disponibles.
|
||||
|
@ -4,14 +4,10 @@ uri: template.generate
|
||||
description: |
|
||||
Génère et récupère les templates générés.
|
||||
|
||||
sampleuse: ~
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: template-domain
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -19,7 +19,7 @@ properties:
|
||||
applicationservice_dependencies:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
type: number
|
||||
description: Liste des services applicatifs déclarés en dépendance de ce service applicatif.
|
||||
|
||||
required:
|
||||
|
@ -3,55 +3,28 @@ title: Servermodel
|
||||
type: object
|
||||
description: Description d'un modèle de serveur.
|
||||
properties:
|
||||
servermodelid:
|
||||
servermodel_id:
|
||||
type: number
|
||||
description: ID du modèle de serveur.
|
||||
ref: Servermodel.ServermodelId
|
||||
servermodelname:
|
||||
servermodel_name:
|
||||
type: string
|
||||
description: Nom du modèle de serveur.
|
||||
servermodeldescription:
|
||||
servermodel_description:
|
||||
type: string
|
||||
description: Description du modèle de serveur.
|
||||
servermodelparentsid:
|
||||
servermodel_parents_id:
|
||||
type: array
|
||||
items:
|
||||
type: number
|
||||
ref: Servermodel.ServermodelId
|
||||
description: ID du modèle de serveur parent.
|
||||
subreleaseid:
|
||||
release_id:
|
||||
type: number
|
||||
ref: Servermodel.SubreleaseId
|
||||
description: Version du modèle de serveur.
|
||||
subreleasename:
|
||||
type: string
|
||||
ref: SubRelease.SubReleaseName
|
||||
description: Nom de la sous-version.
|
||||
sourceid:
|
||||
type: number
|
||||
ref: ServermodelId.SourceId
|
||||
description: ID de la sous-version.
|
||||
services:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
description: Liste des services applicatifs déclarés pour ce modèle de serveur.
|
||||
schema:
|
||||
type: string
|
||||
description: Contenu du schema.
|
||||
probes:
|
||||
type: string
|
||||
description: Informations sur les sondes.
|
||||
creolefuncs:
|
||||
type: string
|
||||
description: Fonctions Creole.
|
||||
conffiles:
|
||||
type: string
|
||||
description: Fichiers creole au format tar encodé base64
|
||||
required:
|
||||
- servermodelid
|
||||
- servermodelname
|
||||
- servermodeldescription
|
||||
- servermodelsubreleaseid
|
||||
- sourceid
|
||||
- subreleasename
|
||||
- servermodel_id
|
||||
- servermodel_name
|
||||
- servermodel_description
|
||||
- release_id
|
||||
|
@ -19,16 +19,16 @@ CREATE TABLE Release (
|
||||
FOREIGN KEY (ReleaseSourceId) REFERENCES Source(SourceId)
|
||||
);
|
||||
|
||||
-- Création de la table ServerModel
|
||||
CREATE TABLE ServerModel (
|
||||
ServerModelId SERIAL PRIMARY KEY,
|
||||
ServerModelName VARCHAR(255) NOT NULL,
|
||||
ServerModelDescription VARCHAR(255) NOT NULL,
|
||||
ServerModelParentsId INTEGER [] DEFAULT '{}',
|
||||
ServerModelReleaseId INTEGER NOT NULL,
|
||||
ServerModelApplicationServiceId INTEGER NOT NULL,
|
||||
ServerModelUsers hstore,
|
||||
UNIQUE (ServerModelName, ServerModelReleaseId)
|
||||
-- Création de la table Servermodel
|
||||
CREATE TABLE Servermodel (
|
||||
ServermodelId SERIAL PRIMARY KEY,
|
||||
ServermodelName VARCHAR(255) NOT NULL,
|
||||
ServermodelDescription VARCHAR(255) NOT NULL,
|
||||
ServermodelParentsId INTEGER [] DEFAULT '{}',
|
||||
ServermodelReleaseId INTEGER NOT NULL,
|
||||
ServermodelApplicationServiceId INTEGER NOT NULL,
|
||||
ServermodelUsers hstore,
|
||||
UNIQUE (ServermodelName, ServermodelReleaseId)
|
||||
);
|
||||
|
||||
-- Création de la table ApplicationService
|
||||
@ -80,5 +80,5 @@ async def main():
|
||||
async with pool.acquire() as connection:
|
||||
async with connection.transaction():
|
||||
returns = await connection.execute(VERSION_INIT)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
|
@ -8,7 +8,7 @@ CONFIGURATION_DIR = 'configurations'
|
||||
TEMPLATE_DIR = 'templates'
|
||||
TMP_DIR = 'tmp'
|
||||
ROUGAIL_DTD_PATH = '../rougail/data/creole.dtd'
|
||||
POSTGRESQL_ADDRESS = 'localhost'
|
||||
POSTGRESQL_ADDRESS = '192.168.56.106'
|
||||
POSTGRESQL_PORT = 5432
|
||||
|
||||
def get_config():
|
||||
|
@ -97,7 +97,10 @@ class CallDispatcher:
|
||||
risotto_context.function = function_obj['function']
|
||||
if function_obj['risotto_context']:
|
||||
kw['risotto_context'] = risotto_context
|
||||
if function_obj['database']:
|
||||
# do not start a new database connection
|
||||
if function_obj['database'] and hasattr(old_risotto_context, 'connection'):
|
||||
risotto_context.connection = old_risotto_context.connection
|
||||
if function_obj['database'] and not hasattr(risotto_context, 'connection'):
|
||||
db_conf = get_config().get('database')
|
||||
pool = await asyncpg.create_pool(database=db_conf.get('dbname'), user=db_conf.get('user'))
|
||||
async with pool.acquire() as connection:
|
||||
|
@ -42,8 +42,6 @@ class MessageDefinition:
|
||||
__slots__ = ('version',
|
||||
'uri',
|
||||
'description',
|
||||
'sampleuse',
|
||||
'domain',
|
||||
'parameters',
|
||||
'public',
|
||||
'errors',
|
||||
@ -59,7 +57,6 @@ class MessageDefinition:
|
||||
self.errors = []
|
||||
self.related = []
|
||||
self.response = None
|
||||
self.sampleuse = None
|
||||
|
||||
# loads yaml information into object
|
||||
for key, value in raw_def.items():
|
||||
@ -428,7 +425,7 @@ def _get_option(name,
|
||||
'expected': ParamValue(optiondescription),
|
||||
'reverse_condition': ParamValue(True)}),
|
||||
calc_value_property_help))
|
||||
|
||||
|
||||
description = arg.description.strip().rstrip()
|
||||
kwargs = {'name': name,
|
||||
'doc': _get_description(description, name),
|
||||
@ -502,7 +499,7 @@ def _parse_responses(message_def,
|
||||
# FIXME
|
||||
'File': StrOption}.get(type_)
|
||||
if not option:
|
||||
raise Exception(f'unknown param type {obj.type}')
|
||||
raise Exception(f'unknown param type {obj.type} in responses of message {message_def.uri}')
|
||||
if hasattr(obj, 'default'):
|
||||
kwargs['default'] = obj.default
|
||||
else:
|
||||
|
1
src/risotto/services/applicationservice/__init__.py
Normal file
1
src/risotto/services/applicationservice/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .applicationservice import Risotto
|
@ -0,0 +1,70 @@
|
||||
from os import listdir
|
||||
from os.path import join
|
||||
from traceback import print_exc
|
||||
from yaml import load, SafeLoader
|
||||
from typing import Dict
|
||||
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...config import get_config
|
||||
from ...error import ExecutionError
|
||||
from ...context import Context
|
||||
from ...utils import _
|
||||
|
||||
class Risotto(Controller):
|
||||
async def _applicationservice_create(self,
|
||||
risotto_context: Context,
|
||||
applicationservice_name: str,
|
||||
applicationservice_description: str,
|
||||
release_id: int) -> Dict:
|
||||
applicationservice_update_query = """INSERT INTO ApplicationService(ApplicationServiceName, ApplicationServiceDescription, ApplicationServiceReleaseId) VALUES ($1,$2,$3)
|
||||
RETURNING ApplicationServiceId
|
||||
"""
|
||||
applicationservice_id = await risotto_context.connection.fetchval(applicationservice_update_query,
|
||||
applicationservice_name,
|
||||
applicationservice_description,
|
||||
release_id)
|
||||
return {'applicationservice_name': applicationservice_name,
|
||||
'applicationservice_description': applicationservice_description,
|
||||
'applicationservice_id': applicationservice_id}
|
||||
|
||||
@register('v1.applicationservice.create', None, database=True)
|
||||
async def applicationservice_create(self,
|
||||
risotto_context: Context,
|
||||
applicationservice_name: str,
|
||||
applicationservice_description: str,
|
||||
release_id: int) -> Dict:
|
||||
return await self._applicationservice_create(risotto_context,
|
||||
applicationservice_name,
|
||||
applicationservice_description,
|
||||
release_id)
|
||||
|
||||
@register('v1.applicationservice.dataset.updated', None, database=True)
|
||||
async def applicationservice_update(self,
|
||||
risotto_context,
|
||||
release_path: str,
|
||||
release_id: int) -> Dict:
|
||||
applicationservice_path = join(release_path, 'applicationservice')
|
||||
for service in listdir(applicationservice_path):
|
||||
try:
|
||||
applicationservice_description_path = join(applicationservice_path,
|
||||
service,
|
||||
'applicationservice.yml')
|
||||
with open(applicationservice_description_path, 'r') as applicationservice_yml:
|
||||
applicationservice_description = load(applicationservice_yml,
|
||||
Loader=SafeLoader)
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
print_exc()
|
||||
raise ExecutionError(_(f'Error while reading {applicationservice_description_path}: {err}'))
|
||||
try:
|
||||
await self._applicationservice_create(risotto_context,
|
||||
applicationservice_description['name'],
|
||||
applicationservice_description['description'],
|
||||
release_id)
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
print_exc()
|
||||
raise ExecutionError(_(f"Error while injecting application service {applicationservice_description['name']} in database: {err}"))
|
||||
return {'retcode': 0,
|
||||
'returns': _('Application Services successfully loaded')}
|
@ -1 +0,0 @@
|
||||
from .application_services import Risotto
|
@ -1,31 +0,0 @@
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
|
||||
class Risotto(Controller):
|
||||
@register('v1.applicationservice.create', None, database=True)
|
||||
async def applicationservice_create(self, risotto_context, applicationservice_name, applicationservice_description, release_id):
|
||||
applicationservice_update_query = """INSERT INTO ApplicationService(ApplicationServiceName, ApplicationServiceDescription, ApplicationServiceReleaseId) VALUES ($1,$2,$3)
|
||||
RETURNING ApplicationServiceId
|
||||
"""
|
||||
applicationservice_id = await risotto_context.connection.fetchval(applicationservice_update_query, applicationservice_description['name'], applicationservice_description['description'], release_id)
|
||||
return {'applicationservice_name': applicationservice_name, 'applicationservice_description': applicationservice_description, 'applicationservice_id': applicationservice_id}
|
||||
|
||||
@register('v1.applicationservice.dataset.updated', None, database=True)
|
||||
async def applicationservice_update(self, risotto_context, release_path, release_id):
|
||||
applicationservice_path = os.path.join(release_path, 'applicationservice')
|
||||
for service in os.listdir(applicationservice_path):
|
||||
try:
|
||||
applicationservice_description_path = os.path.join(applicationservice_path, service, 'applicationservice.yml')
|
||||
with open(applicationservice_description_path, 'r') as applicationservice_yml:
|
||||
applicationservice_description = yaml.load(applicationservice_yml, Loader=yaml.SafeLoader)
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
print_exc()
|
||||
raise ExecutionError(_(f'Error while reading {applicationservice_description_path}: {err}'))
|
||||
try:
|
||||
await self.applicationservice_create(risotto_context, applicationservice_description['name'], applicationservice_description['description'], release_id)
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
print_exc()
|
||||
raise ExecutionError(_(f"Error while injecting application service {applicationservice_description['name']} in database: {err}"))
|
||||
return {'retcode': 0, 'returns': _('Application Services successfully loaded')}
|
@ -18,14 +18,14 @@ from ...logger import log
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
servermodel = {}
|
||||
server = {}
|
||||
|
||||
def __init__(self) -> None:
|
||||
for dirname in [ROOT_CACHE_DIR, DATABASE_DIR]:
|
||||
if not isdir(dirname):
|
||||
raise RegistrationError(_(f'unable to find the cache dir "{dirname}"'))
|
||||
self.save_storage = Storage(engine='sqlite3', dir_database=DATABASE_DIR)
|
||||
self.servermodel = {}
|
||||
self.server = {}
|
||||
super().__init__()
|
||||
|
||||
async def on_join(self,
|
||||
@ -49,37 +49,37 @@ class Risotto(Controller):
|
||||
for servermodel in servermodels:
|
||||
try:
|
||||
await self.load_servermodel(risotto_context,
|
||||
servermodel['servermodelid'],
|
||||
servermodel['servermodelname'])
|
||||
servermodel['servermodel_id'],
|
||||
servermodel['servermodel_name'])
|
||||
except CallError as err:
|
||||
pass
|
||||
|
||||
# do link to this servermodel
|
||||
for servermodel in servermodels:
|
||||
if 'servermodelparentsid' in servermodel:
|
||||
for servermodelparentid in servermodel['servermodelparentsid']:
|
||||
if 'servermodel_parents_id' in servermodel:
|
||||
for servermodelparentid in servermodel['servermodel_parents_id']:
|
||||
self.servermodel_legacy(risotto_context,
|
||||
servermodel['servermodelname'],
|
||||
servermodel['servermodelid'],
|
||||
servermodel['servermodel_name'],
|
||||
servermodel['servermodel_id'],
|
||||
servermodelparentid)
|
||||
|
||||
def get_funcs_filename(self,
|
||||
servermodelid: int):
|
||||
return join(ROOT_CACHE_DIR, str(servermodelid)+".creolefuncs")
|
||||
servermodel_id: int):
|
||||
return join(ROOT_CACHE_DIR, str(servermodel_id)+".creolefuncs")
|
||||
|
||||
|
||||
|
||||
async def load_servermodel(self,
|
||||
risotto_context: Context,
|
||||
servermodelid: int,
|
||||
servermodelname: str) -> None:
|
||||
servermodel_id: int,
|
||||
servermodel_name: str) -> None:
|
||||
""" Loads a servermodel
|
||||
"""
|
||||
cache_file = join(ROOT_CACHE_DIR, str(servermodelid)+".xml")
|
||||
funcs_file = self.get_funcs_filename(servermodelid)
|
||||
cache_file = join(ROOT_CACHE_DIR, str(servermodel_id)+".xml")
|
||||
funcs_file = self.get_funcs_filename(servermodel_id)
|
||||
log.info_msg(risotto_context,
|
||||
None,
|
||||
f'Load servermodel {servermodelname} ({servermodelid})')
|
||||
f'Load servermodel {servermodel_name} ({servermodel_id})')
|
||||
|
||||
# use file in cache if found, otherwise retrieve it in servermodel context
|
||||
if isfile(cache_file):
|
||||
@ -87,7 +87,7 @@ class Risotto(Controller):
|
||||
else:
|
||||
servermodel = await self.call('v1.servermodel.describe',
|
||||
risotto_context,
|
||||
servermodelid=servermodelid,
|
||||
servermodel_id=servermodel_id,
|
||||
inheritance=False,
|
||||
resolvdepends=False,
|
||||
schema=True,
|
||||
@ -104,20 +104,20 @@ class Risotto(Controller):
|
||||
|
||||
# loads tiramisu config and store it
|
||||
xmlroot = parse(fileio).getroot()
|
||||
self.servermodel[servermodelid] = self.build_metaconfig(servermodelid,
|
||||
servermodelname,
|
||||
self.servermodel[servermodel_id] = self.build_metaconfig(servermodel_id,
|
||||
servermodel_name,
|
||||
xmlroot,
|
||||
funcs_file)
|
||||
|
||||
def build_metaconfig(self,
|
||||
servermodelid: int,
|
||||
servermodelname: str,
|
||||
servermodel_id: int,
|
||||
servermodel_name: str,
|
||||
xmlroot: str,
|
||||
funcs_file: str) -> MetaConfig:
|
||||
""" Build metaconfig for a servermodel
|
||||
"""
|
||||
# build tiramisu's session ID
|
||||
session_id = f'v_{servermodelid}'
|
||||
session_id = f'v_{servermodel_id}'
|
||||
optiondescription = rougail_load(xmlroot,
|
||||
ROUGAIL_DTD_PATH,
|
||||
funcs_file)
|
||||
@ -149,9 +149,9 @@ class Risotto(Controller):
|
||||
metaconfig.permissive.add('expert')
|
||||
|
||||
# set informtion and owner
|
||||
metaconfig.owner.set('v_{}'.format(servermodelname))
|
||||
metaconfig.information.set('servermodel_id', servermodelid)
|
||||
metaconfig.information.set('servermodel_name', servermodelname)
|
||||
metaconfig.owner.set('v_{}'.format(servermodel_name))
|
||||
metaconfig.information.set('servermodel_id', servermodel_id)
|
||||
metaconfig.information.set('servermodel_name', servermodel_name)
|
||||
|
||||
# return configuration
|
||||
return metaconfig
|
||||
@ -221,7 +221,7 @@ class Risotto(Controller):
|
||||
risotto_context: Context,
|
||||
server_id: int,
|
||||
servername: str,
|
||||
servermodelid: int) -> None:
|
||||
servermodel_id: int) -> None:
|
||||
""" Loads a server
|
||||
"""
|
||||
if server_id in self.server:
|
||||
@ -229,18 +229,18 @@ class Risotto(Controller):
|
||||
log.info_msg(risotto_context,
|
||||
None,
|
||||
f'Load server {servername} ({server_id})')
|
||||
if not servermodelid in self.servermodel:
|
||||
msg = f'unable to find servermodel with id {servermodelid}'
|
||||
if not servermodel_id in self.servermodel:
|
||||
msg = f'unable to find servermodel with id {servermodel_id}'
|
||||
log.error_msg(risotto_context,
|
||||
None,
|
||||
msg)
|
||||
raise CallError(msg)
|
||||
|
||||
|
||||
# check if server was already created
|
||||
session_id = f's_{server_id}'
|
||||
|
||||
# get the servermodel's metaconfig
|
||||
metaconfig = self.servermodel[servermodelid]
|
||||
metaconfig = self.servermodel[servermodel_id]
|
||||
|
||||
# create server configuration and server 'to deploy' configuration and store it
|
||||
self.server[server_id] = {'server': self.build_config(session_id,
|
||||
@ -251,7 +251,7 @@ class Risotto(Controller):
|
||||
server_id,
|
||||
servername,
|
||||
metaconfig),
|
||||
'funcs_file': self.get_funcs_filename(servermodelid)}
|
||||
'funcs_file': self.get_funcs_filename(servermodel_id)}
|
||||
|
||||
def build_config(self,
|
||||
session_id: str,
|
||||
@ -280,7 +280,7 @@ class Risotto(Controller):
|
||||
self.load_server(risotto_context,
|
||||
server_id,
|
||||
servername,
|
||||
servermodelid)
|
||||
servermodel_id)
|
||||
|
||||
@register('v1.server.deleted')
|
||||
async def server_deleted(self,
|
||||
@ -298,35 +298,35 @@ class Risotto(Controller):
|
||||
@register('v1.servermodel.created')
|
||||
async def servermodel_created(self,
|
||||
risotto_context: Context,
|
||||
servermodelid: int,
|
||||
servermodelname: str,
|
||||
servermodelparentsid: List[int]) -> None:
|
||||
servermodel_id: int,
|
||||
servermodel_name: str,
|
||||
servermodel_parents_id: List[int]) -> None:
|
||||
""" when servermodels are created, load it and do link
|
||||
"""
|
||||
await self.load_and_link_servermodel(risotto_context,
|
||||
servermodelid,
|
||||
servermodelname,
|
||||
servermodelparentsid)
|
||||
servermodel_id,
|
||||
servermodel_name,
|
||||
servermodel_parents_id)
|
||||
|
||||
|
||||
async def load_and_link_servermodel(self,
|
||||
risotto_context: Context,
|
||||
servermodelid: int,
|
||||
servermodelname: str,
|
||||
servermodelparentsid: List[int]) -> None:
|
||||
servermodel_id: int,
|
||||
servermodel_name: str,
|
||||
servermodel_parents_id: List[int]) -> None:
|
||||
await self.load_servermodel(risotto_context,
|
||||
servermodelid,
|
||||
servermodelname)
|
||||
if servermodelparentsid is not None:
|
||||
for servermodelparentid in servermodelparentsid:
|
||||
servermodel_id,
|
||||
servermodel_name)
|
||||
if servermodel_parents_id is not None:
|
||||
for servermodelparentid in servermodel_parents_id:
|
||||
self.servermodel_legacy(risotto_context,
|
||||
servermodelname,
|
||||
servermodelid,
|
||||
servermodel_name,
|
||||
servermodel_id,
|
||||
servermodelparentid)
|
||||
|
||||
def servermodel_delete(self,
|
||||
servermodelid: int) -> List[MetaConfig]:
|
||||
metaconfig = self.servermodel.pop(servermodelid)
|
||||
servermodel_id: int) -> List[MetaConfig]:
|
||||
metaconfig = self.servermodel.pop(servermodel_id)
|
||||
mixconfig = next(metaconfig.config.list())
|
||||
children = []
|
||||
for child in mixconfig.config.list():
|
||||
@ -345,42 +345,42 @@ class Risotto(Controller):
|
||||
@register('v1.servermodel.updated')
|
||||
async def servermodel_updated(self,
|
||||
risotto_context: Context,
|
||||
servermodelid: int,
|
||||
servermodelname: str,
|
||||
servermodelparentsid: List[int]) -> None:
|
||||
servermodel_id: int,
|
||||
servermodel_name: str,
|
||||
servermodel_parents_id: List[int]) -> None:
|
||||
log.info_msg(risotto_context,
|
||||
None,
|
||||
f'Reload servermodel {servermodelname} ({servermodelid})')
|
||||
f'Reload servermodel {servermodel_name} ({servermodel_id})')
|
||||
# unlink cache to force download new aggregated file
|
||||
cache_file = join(ROOT_CACHE_DIR, str(servermodelid)+".xml")
|
||||
cache_file = join(ROOT_CACHE_DIR, str(servermodel_id)+".xml")
|
||||
if isfile(cache_file):
|
||||
unlink(cache_file)
|
||||
|
||||
# store all informations
|
||||
if servermodelid in self.servermodel:
|
||||
old_values = self.servermodel[servermodelid].value.exportation()
|
||||
old_permissives = self.servermodel[servermodelid].permissive.exportation()
|
||||
old_properties = self.servermodel[servermodelid].property.exportation()
|
||||
children = self.servermodel_delete(servermodelid)
|
||||
if servermodel_id in self.servermodel:
|
||||
old_values = self.servermodel[servermodel_id].value.exportation()
|
||||
old_permissives = self.servermodel[servermodel_id].permissive.exportation()
|
||||
old_properties = self.servermodel[servermodel_id].property.exportation()
|
||||
children = self.servermodel_delete(servermodel_id)
|
||||
else:
|
||||
old_values = None
|
||||
|
||||
# create new one
|
||||
await self.load_and_link_servermodel(risotto_context,
|
||||
servermodelid,
|
||||
servermodelname,
|
||||
servermodelparentsid)
|
||||
servermodel_id,
|
||||
servermodel_name,
|
||||
servermodel_parents_id)
|
||||
|
||||
# migrates informations
|
||||
if old_values is not None:
|
||||
self.servermodel[servermodelid].value.importation(old_values)
|
||||
self.servermodel[servermodelid].permissive.importation(old_permissives)
|
||||
self.servermodel[servermodelid].property.importation(old_properties)
|
||||
self.servermodel[servermodel_id].value.importation(old_values)
|
||||
self.servermodel[servermodel_id].permissive.importation(old_permissives)
|
||||
self.servermodel[servermodel_id].property.importation(old_properties)
|
||||
for child in children:
|
||||
self.servermodel_legacy(risotto_context,
|
||||
child.information.get('servermodel_name'),
|
||||
child.information.get('servermodel_id'),
|
||||
servermodelid)
|
||||
servermodel_id)
|
||||
|
||||
@register('v1.config.configuration.server.get', None)
|
||||
async def get_configuration(self,
|
||||
|
@ -1,40 +1,70 @@
|
||||
from os import listdir
|
||||
from os.path import join
|
||||
from yaml import load, SafeLoader
|
||||
from traceback import print_exc
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...utils import _
|
||||
import os
|
||||
import yaml
|
||||
from traceback import print_exc
|
||||
from ...context import Context
|
||||
from ...config import get_config
|
||||
from ...error import ExecutionError
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
@register('v1.servermodel.dataset.updated', None, database=True)
|
||||
async def servermodel_update(self, risotto_context, release_path, release_id, applicationservice_įd):
|
||||
applicationservice_update = """INSERT INTO ApplicationService(ApplicationServiceName, ApplicationServiceDescription, ApplicationServiceReleaseId) VALUES ($1,$2,$3)
|
||||
RETURNING ApplicationServiceId
|
||||
async def servermodel_update(self,
|
||||
risotto_context: Context,
|
||||
release_path: str,
|
||||
release_id: int):
|
||||
servermodel_update = """INSERT INTO Servermodel(ServermodelName, ServermodelDescription, ServermodelParentsId, ServermodelReleaseId, ServermodelApplicationServiceId) VALUES ($1,$2,$3,$4,$5)
|
||||
RETURNING ServermodelId
|
||||
"""
|
||||
servermodel_path = os.path.join(release_path, 'servermodel')
|
||||
for servermodel in os.listdir(servermodel_path):
|
||||
servermodel_path = join(release_path, 'servermodel')
|
||||
for servermodel in listdir(servermodel_path):
|
||||
if not servermodel.endswith('.yml'):
|
||||
continue
|
||||
servermodel_description_path = join(servermodel_path, servermodel)
|
||||
try:
|
||||
with open(os.path.join(servermodel_path, servermodel), 'r') as applicationservice_yml:
|
||||
applicationservice_description = yaml.load(applicationservice_yml, Loader=yaml.SafeLoader)
|
||||
with open(servermodel_description_path, 'r') as servermodel_yml:
|
||||
servermodel_description = load(servermodel_yml,
|
||||
Loader=SafeLoader)
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
print_exc()
|
||||
raise ExecutionError(_(f'Error while reading {applicationservice_description_path}: {err}'))
|
||||
raise ExecutionError(_(f'Error while reading {servermodel_description_path}: {err}'))
|
||||
sm_name = servermodel_description['name']
|
||||
sm_description = servermodel_description['description']
|
||||
sm_parentsid = servermodel_description['parent']
|
||||
if sm_parentsid is None:
|
||||
sm_parentsid = []
|
||||
else:
|
||||
sm_parentsid = [sm_parentsid]
|
||||
as_name = f"local_{sm_name}"
|
||||
as_description = f'local application service for {sm_name}'
|
||||
applicationservice = await self.call('v1.applicationservice.create',
|
||||
risotto_context,
|
||||
applicationservice_name=as_name,
|
||||
applicationservice_description=as_description,
|
||||
release_id=release_id)
|
||||
try:
|
||||
await risotto_context.connection.fetch(applicationservice_update, applicationservice_description['name'], applicationservice_description['description'], release_id)
|
||||
await risotto_context.connection.fetch(servermodel_update,
|
||||
sm_name,
|
||||
sm_description,
|
||||
sm_parentsid,
|
||||
release_id,
|
||||
applicationservice['applicationservice_id'])
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
print_exc()
|
||||
raise ExecutionError(_(f"Error while injecting application service {applicationservice_description['name']} in database: {err}"))
|
||||
return {'retcode': 0, 'returns': _('Application Services successfully loaded')}
|
||||
raise ExecutionError(_(f"Error while injecting servermodel {servermodel_description['name']} in database: {err}"))
|
||||
return {'retcode': 0, 'returns': _('Servermodels successfully loaded')}
|
||||
|
||||
@register('v1.servermodel.list', None, database=True)
|
||||
async def servermodel_list(self, risotto_context, sourceid):
|
||||
async def servermodel_list(self,
|
||||
risotto_context: Context,
|
||||
sourceid: int):
|
||||
sql = '''
|
||||
SELECT * FROM ServerModel
|
||||
SELECT ServermodelId as servermodel_id, ServermodelName as servermodel_name, ServermodelDescription as servermodel_description, ServermodelParentsId as servermodel_parents_id, ServermodelReleaseId as release_id FROM Servermodel
|
||||
'''
|
||||
servermodels = await risotto_context.connection.fetch(sql)
|
||||
return [dict(r) for r in servermodels]
|
||||
|
Loading…
Reference in New Issue
Block a user