From f4926568d90fa149d015e3925fc890127a18f50e Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Fri, 15 Oct 2021 08:05:06 +0200 Subject: [PATCH] TMSS-1093: logging, and added cmdline options to do/don't populate schemas/connectors/permissions --- SAS/TMSS/backend/src/tmss/tmssapp/populate.py | 4 ++- SAS/TMSS/client/lib/populate.py | 29 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py index bc42975e451..671fba35fcf 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py @@ -503,7 +503,9 @@ def populate_connectors(): # wrapper func to silently skip duplicates for task_template in TaskTemplate.objects.filter(name=task_template_name).all(): try: - TaskConnectorType.objects.create(task_template=task_template, **kwargs) + connector = TaskConnectorType.objects.create(task_template=task_template, **kwargs) + logger.info('created task_type_connector id: %s role: %s datatype: %s dataformat: %s iotype: %s task_template=\'%s-v%s\'', + connector.id, connector.role.value, connector.datatype.value, connector.dataformat.value, connector.iotype.value, connector.task_template.name, connector.task_template.version) except IntegrityError: # skipping duplicate pass diff --git a/SAS/TMSS/client/lib/populate.py b/SAS/TMSS/client/lib/populate.py index c0648f5bbde..0ccf9a63eeb 100644 --- a/SAS/TMSS/client/lib/populate.py +++ b/SAS/TMSS/client/lib/populate.py @@ -12,9 +12,15 @@ def populate_main(): # Check the invocation arguments parser = OptionParser('%prog [options]', description='upload the templates to TMSS') - parser.add_option('-d', '--dir', dest='schema_dir', type='string', + + group = OptionGroup(parser, 'Populate options') + parser.add_option_group(group) + group.add_option('-s', '--schemas', action="store_true", dest="schemas", default=False, help='upload the templates and schemas in the given <schemas_dir> to TMSS, default: %default') + group.add_option('-d', '--schemas_dir', dest='schemas_dir', type='string', default=os.path.expandvars('$LOFARROOT/share/tmss/schemas'), help='''directory path containing the schemas, default: '%default')''') + group.add_option('-c', '--connectors', action="store_true", dest="connectors", default=False, help='create the default task_connector_types for all known task_templates in TMSS, default: %default') + group.add_option('-p', '--permissions', action="store_true", dest="permissions", default=False, help='create the default permissions for TMSS, default: %default') group = OptionGroup(parser, 'Django options') parser.add_option_group(group) @@ -23,15 +29,22 @@ def populate_main(): (options, args) = parser.parse_args() - # when called from the commandline, don't use parallel uploading to make the log lines sequential/readable - populate_schemas(options.schema_dir, options.rest_credentials, parallel=False) + if options.schemas: + # when called from the commandline (like in this case), don't use parallel uploading to make the log lines sequential/readable + populate_schemas(options.schemas_dir, options.rest_credentials, parallel=False) + + if options.connectors or options.permissions: + # now that the schema's were uploaded, let's populate the dependent task connectors, and the permissions + from lofar.sas.tmss.tmss import setup_and_check_tmss_django_database_connection_and_exit_on_error + setup_and_check_tmss_django_database_connection_and_exit_on_error(options.dbcredentials) - # now that the schema's were uploaded, let's populate the dependend task connectors, and the permissions - from lofar.sas.tmss.tmss import setup_and_check_tmss_django_database_connection_and_exit_on_error - setup_and_check_tmss_django_database_connection_and_exit_on_error(options.dbcredentials) + if options.connectors: + from lofar.sas.tmss.tmss.tmssapp.populate import populate_connectors + populate_connectors() - from lofar.sas.tmss.tmss.tmssapp.populate import populate_connectors - populate_connectors() + if options.permissions: + from lofar.sas.tmss.tmss.tmssapp.populate import populate_permissions + populate_permissions() def populate_schemas(schema_dir: str=None, dbcreds_name: str=None, parallel: bool=True): -- GitLab