Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
maestro-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
maestro
maestro-core
Commits
fdbf412b
Commit
fdbf412b
authored
4 years ago
by
Ali Mohammed
Browse files
Options
Downloads
Patches
Plain Diff
Add env. variable MSTRO_SCHEMA_LIST to list user defined schemas and adding a unit test for it
parent
c5527229
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/maestro/env.h
+5
-0
5 additions, 0 deletions
include/maestro/env.h
maestro/core.c
+69
-20
69 additions, 20 deletions
maestro/core.c
tests/check_declaration_seal.c
+33
-0
33 additions, 0 deletions
tests/check_declaration_seal.c
tests/test_attributes.yaml
+16
-0
16 additions, 0 deletions
tests/test_attributes.yaml
with
123 additions
and
20 deletions
include/maestro/env.h
+
5
−
0
View file @
fdbf412b
...
...
@@ -96,6 +96,11 @@
*/
#define MSTRO_ENV_LOG_COLOR "MSTRO_LOG_COLOR"
/**@brief lists the set of Schemata (in order from left to right) that should be loaded after the maestro-core schema is loaded.
* If set,mstro_init will merge these onto the built-ins. Default: core + ecmwf
*/
#define MSTRO_ENV_SCHEMA_LIST "MSTRO_SCHEMA_LIST"
/**@brief enable coloring of error log messages
*
* If set, enable coloring of error and warning messages. May not be a good idea if logging to syslog (see @ref MSTRO_LOG_DST).
...
...
This diff is collapsed.
Click to expand it.
maestro/core.c
+
69
−
20
View file @
fdbf412b
...
...
@@ -145,6 +145,72 @@ BAILOUT:
/** minimum mlock() limit */
#define MSTRO_MIN_MEMLOCK (4*sizeof(g_component_descriptor))
mstro_status
mstro_core_init__setup_schemata
(
void
)
{
mstro_status
status
=
MSTRO_OK
;
char
*
env_schema_list
=
getenv
(
MSTRO_ENV_SCHEMA_LIST
);
char
*
token
;
// parse and merge the builtin schemas first
DEBUG
(
"Parsing Maestro core schema
\n
"
);
status
=
mstro_schema_parse
(
MSTRO_SCHEMA_BUILTIN_YAML_CORE
,
MSTRO_SCHEMA_BUILTIN_YAML_CORE_LEN
,
&
g_mstro_core_schema_instance
);
if
(
status
!=
MSTRO_OK
)
{
ERR
(
"Failed to parse built-in core schema
\n
"
);
return
status
;
}
DEBUG
(
"Parsing ECMWF schema
\n
"
);
mstro_schema
ecmwf
;
status
=
mstro_schema_parse
(
MSTRO_SCHEMA_BUILTIN_YAML_ECMWF
,
MSTRO_SCHEMA_BUILTIN_YAML_ECMWF_LEN
,
&
ecmwf
);
if
(
status
!=
MSTRO_OK
)
{
ERR
(
"Failed to parse built-in ecmwf schema
\n
"
);
return
status
;
}
status
=
mstro_schema_merge
(
g_mstro_core_schema_instance
,
ecmwf
);
if
(
status
!=
MSTRO_OK
)
{
ERR
(
"Failed to merge core and ECMWF schema
\n
"
);
return
status
;
}
// start reading user-defined schemas and merge them.
/* get the first token */
token
=
strtok
(
env_schema_list
,
":"
);
/* walk through other tokens */
while
(
token
!=
NULL
)
{
// parse a schema from the user
mstro_schema
user_schema
;
DEBUG
(
"Parsing user-defined schema
\n
"
);
status
=
mstro_schema_parse_from_file
(
token
,
&
user_schema
);
if
(
status
!=
MSTRO_OK
)
{
ERR
(
"Failed to parse user_schema from file: %s
\n
"
,
token
);
return
status
;
}
// merge the schema
status
=
mstro_schema_merge
(
g_mstro_core_schema_instance
,
user_schema
);
if
(
status
!=
MSTRO_OK
)
{
ERR
(
"Failed to merge core and user schema from file %s
\n
"
,
token
);
return
status
;
}
// read the next path
token
=
strtok
(
NULL
,
":"
);
}
return
status
;
}
mstro_status
mstro_core_init
(
const
char
*
workflow_name
,
const
char
*
component_name
,
...
...
@@ -197,26 +263,9 @@ mstro_core_init(const char *workflow_name,
g_component_descriptor
.
component_name
[
MSTRO_WORKFLOW_NAME_MAX
-
1
]
=
'\0'
;
strcpy
(
g_component_descriptor
.
version
,
mstro_version
());
status
=
mstro_schema_parse
(
MSTRO_SCHEMA_BUILTIN_YAML_CORE
,
MSTRO_SCHEMA_BUILTIN_YAML_CORE_LEN
,
&
g_mstro_core_schema_instance
);
if
(
status
!=
MSTRO_OK
)
{
ERR
(
"Failed to parse built-in core schema
\n
"
);
goto
BAILOUT
;
}
/* FIXME: this should not be here */
DEBUG
(
"Including ECMWF schema
\n
"
);
mstro_schema
ecmwf
;
status
=
mstro_schema_parse
(
MSTRO_SCHEMA_BUILTIN_YAML_ECMWF
,
MSTRO_SCHEMA_BUILTIN_YAML_ECMWF_LEN
,
&
ecmwf
);
if
(
status
!=
MSTRO_OK
)
{
ERR
(
"Failed to parse built-in ecmwf schema
\n
"
);
goto
BAILOUT
;
}
status
=
mstro_schema_merge
(
g_mstro_core_schema_instance
,
ecmwf
);
status
=
mstro_core_init__setup_schemata
();
if
(
status
!=
MSTRO_OK
)
{
ERR
(
"Failed to merge core and ECMWF schema
\n
"
);
goto
BAILOUT
;
}
...
...
This diff is collapsed.
Click to expand it.
tests/check_declaration_seal.c
+
33
−
0
View file @
fdbf412b
...
...
@@ -133,3 +133,36 @@ CHEAT_TEST(cdo_declaration_seal_works,
)
/* put a path to user-defined schema*/
CHEAT_TEST
(
user_defined_schemas_works
,
putenv
(
"MSTRO_SCHEMA_LIST=test_attributes.yaml"
);
cheat_assert
(
MSTRO_OK
==
mstro_init
(
"Tests"
,
"DECLARE"
,
0
));
mstro_cdo
cdo
;
cheat_assert
(
MSTRO_OK
==
mstro_cdo_declare
(
"test cdo"
,
MSTRO_ATTR_DEFAULT
,
&
cdo
));
cheat_assert
(
MSTRO_OK
==
mstro_cdo_attribute_set
(
cdo
,
".maestro.test.t_1"
,
"test value"
));
cheat_assert
(
MSTRO_OK
==
mstro_cdo_declaration_seal
(
cdo
));
cheat_assert
(
MSTRO_OK
==
mstro_cdo_offer
(
cdo
));
cheat_assert
(
MSTRO_OK
==
mstro_cdo_withdraw
(
cdo
));
cheat_assert
(
MSTRO_OK
==
mstro_cdo_dispose
(
cdo
));
cheat_assert
(
MSTRO_OK
==
mstro_finalize
());
)
/* put a path to user-defined schema with wrong path and wrong separators*/
CHEAT_TEST
(
user_defined_schemas_doesnot_exist
,
putenv
(
"MSTRO_SCHEMA_LIST=bechmark_attributes.yaml"
);
cheat_assert
(
MSTRO_OK
!=
mstro_init
(
"Tests"
,
"DECLARE"
,
0
));
cheat_assert
(
MSTRO_FAIL
==
mstro_finalize
());
)
This diff is collapsed.
Click to expand it.
tests/test_attributes.yaml
0 → 100644
+
16
−
0
View file @
fdbf412b
# A user-defined schema. The minimum is name and version
schema-name
:
Test Attributes
schema-version
:
0
schema-namespace
:
"
.maestro.test."
# attributes section is optional; if given it needs to have a sequence value
maestro-attributes
:
# Top-level attributes
-
key
:
"
t_1"
type
:
str()
required
:
False
default
:
"
"
documentation
:
Value length is the attribute size
This diff is collapsed.
Click to expand it.
Ali Mohammed
@mohammed1
mentioned in commit
0c477b34
·
4 years ago
mentioned in commit
0c477b34
mentioned in commit 0c477b34900ad49ad6572cd306c0e770b8fb49e0
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment