diff options
author | Michael Hwang <mhwang@research.att.com> | 2017-09-14 13:06:21 -0400 |
---|---|---|
committer | Michael Hwang <mhwang@research.att.com> | 2017-09-14 14:50:51 -0400 |
commit | 0d4c19a9389a933cf5b5e83173f97f8cd72b7f5e (patch) | |
tree | c160ab6cdaf600f8025d75e91898d133ebc000f8 /dcae-cli/dcae_cli/commands/component/commands.py | |
parent | 3b22c6518e8dbb4a4ddf7aa615a8dccdc2d280b7 (diff) |
Merge in changes there were made since seeding
* Fix DR config keys issue
* Add data format generate command
* Improve error messaging
* Add in support for inputs otherwise known as "sourced at deployment"
Change-Id: I9d97c30aeba587315d7fd1a18c38f71d8199d42b
Issue-Id: DCAEGEN2-91
Signed-off-by: Michael Hwang <mhwang@research.att.com>
Diffstat (limited to 'dcae-cli/dcae_cli/commands/component/commands.py')
-rw-r--r-- | dcae-cli/dcae_cli/commands/component/commands.py | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/dcae-cli/dcae_cli/commands/component/commands.py b/dcae-cli/dcae_cli/commands/component/commands.py index 9c7a56d..4326636 100644 --- a/dcae-cli/dcae_cli/commands/component/commands.py +++ b/dcae-cli/dcae_cli/commands/component/commands.py @@ -29,7 +29,7 @@ import click from discovery_client import resolve_name -from dcae_cli.util import profiles, load_json, dmaap +from dcae_cli.util import profiles, load_json, dmaap, inputs from dcae_cli.util.run import run_component, dev_component from dcae_cli.util import discovery as dis from dcae_cli.util.discovery import DiscoveryNoDownstreamComponentError @@ -165,6 +165,28 @@ def _parse_dmaap_file(dmaap_file): message = "Problems with parsing the dmaap file. Check to make sure that it is a valid json and is in the expected structure." raise DcaeException(message) +_help_inputs_file = """ +Path to a file that contains a json that contains values to be used to bind to configuration parameters that have been marked as "sourced_at_deployment". The structure of the json is expected to be: + + { + <parameter1 name>: value, + <parameter2 name>: value + } + +The "parameter name" is the value of the "name" property for the given configuration parameter. +""" + +def _parse_inputs_file(inputs_file): + try: + with open(inputs_file, 'r+') as f: + inputs_map = json.load(f) + # TODO: Validation of schema in the future? Skipping this because + # dti_payload is not being intended to be used. + return inputs_map + except Exception as e: + message = "Problems with parsing the inputs file. Check to make sure that it is a valid json and is in the expected structure." + raise DcaeException(message) + @component.command() @click.option('--external-ip', '-ip', default=None, help='The external IP address of the Docker host. Only used for Docker components.') @@ -173,21 +195,29 @@ def _parse_dmaap_file(dmaap_file): @click.option('--force', is_flag=True, help='Force component to run without valid downstream dependencies') @click.option('--dmaap-file', type=click.Path(resolve_path=True, exists=True, dir_okay=False), help=_help_dmaap_file) +@click.option('--inputs-file', type=click.Path(resolve_path=True, exists=True, dir_okay=False), + help=_help_inputs_file) @click.argument('component') @click.pass_obj -def run(obj, external_ip, additional_user, attached, force, dmaap_file, component): +def run(obj, external_ip, additional_user, attached, force, dmaap_file, component, + inputs_file): '''Runs the latest version of COMPONENT. You may optionally specify version via COMPONENT:VERSION''' cname, cver = parse_input(component) user, catalog = obj['config']['user'], obj['catalog'] dmaap_map = _parse_dmaap_file(dmaap_file) if dmaap_file else {} + inputs_map = _parse_inputs_file(inputs_file) if inputs_file else {} try: run_component(user, cname, cver, catalog, additional_user, attached, force, - dmaap_map, external_ip) + dmaap_map, inputs_map, external_ip) except DiscoveryNoDownstreamComponentError as e: message = "Either run a compatible downstream component first or run with the --force flag to ignore this error" raise DcaeException(message) + except inputs.InputsValidationError as e: + click.echo("There is a problem. {0}".format(e)) + message = "Component requires inputs. Please look at the use of --inputs-file and make sure the format is correct" + raise DcaeException(message) @component.command() @click.argument('component') @@ -205,20 +235,28 @@ def undeploy(obj, component): @click.option('--force', is_flag=True, help='Force component to run without valid downstream dependencies') @click.option('--dmaap-file', type=click.Path(resolve_path=True, exists=True, dir_okay=False), help=_help_dmaap_file) +@click.option('--inputs-file', type=click.Path(resolve_path=True, exists=True, dir_okay=False), + help=_help_inputs_file) @click.pass_obj -def dev(obj, specification, additional_user, force, dmaap_file): +def dev(obj, specification, additional_user, force, dmaap_file, inputs_file): '''Set up component in development for discovery, use for local development''' user, catalog = obj['config']['user'], obj['catalog'] dmaap_map = _parse_dmaap_file(dmaap_file) if dmaap_file else {} + inputs_map = _parse_inputs_file(inputs_file) if inputs_file else {} with open(specification, 'r+') as f: spec = json.loads(f.read()) try: - dev_component(user, catalog, spec, additional_user, force, dmaap_map) + dev_component(user, catalog, spec, additional_user, force, dmaap_map, + inputs_map) except DiscoveryNoDownstreamComponentError as e: message = "Either run a compatible downstream component first or run with the --force flag to ignore this error" raise DcaeException(message) + except inputs.InputsValidationError as e: + click.echo("There is a problem. {0}".format(e)) + message = "Component requires inputs. Please look at the use of --inputs-file and make sure the format is correct" + raise DcaeException(message) @component.command() |