Esempio n. 1
0
    def _populate_default_values(self, do_validate=False):
        """Populates any missing JSON fields that have default values
        """

        if 'parameters' not in self._definition:
            self._definition['parameters'] = InterfaceV6().get_dict()
        elif type(self._definition['parameters']) is not dict:
            raise InvalidDataSetDefinition('INVALID_DATASET_DEFINITION', '"parameters" is not a dictionary')
        else:
            self._definition['parameters'] = InterfaceV6(interface=self._definition['parameters'], do_validate=do_validate).get_dict()
        rest_utils.strip_schema_version(self._definition['parameters'])

        if 'global_parameters' not in self._definition:
            self._definition['global_parameters'] = InterfaceV6().get_dict()
        elif type(self._definition['global_parameters']) is not dict:
            raise InvalidDataSetDefinition('INVALID_DATASET_DEFINITION', '"global_parameters" is not a dictionary')
        else:
            self._definition['global_parameters'] = InterfaceV6(interface=self._definition['global_parameters'], do_validate=do_validate).get_dict()
        rest_utils.strip_schema_version(self._definition['global_parameters'])

        if 'global_data' not in self._definition:
            self._definition['global_data'] = DataV6().get_dict()
        elif type(self._definition['global_data']) is not dict:
            raise InvalidDataSetDefinition('INVALID_DATASET_DEFINITION', '"global_data" is not a dictionary')
        else:
            self._definition['global_data'] = DataV6(data=self._definition['global_data'], do_validate=do_validate).get_dict()
        rest_utils.strip_schema_version(self._definition['global_data'])
Esempio n. 2
0
    def __init__(self, definition=None):
        """Constructor

        :param definition: Parameters of the definition
        :type defintion: dict
        """

        if not definition:
            definition = {}
        self._definition = definition
        self.param_names = set()
        self.parameters = {}
        if 'parameters' in self._definition:
            self.parameters = InterfaceV6(
                interface=definition['parameters']).get_interface()
            self.param_names = set(self.parameters.parameters.keys())

        self.global_parameters = {}
        if 'global_parameters' in self._definition:
            self.global_parameters = InterfaceV6(
                definition['global_parameters']).get_interface()
            keys = self.global_parameters.parameters.keys()
            dupes = self.param_names.intersection(keys)
            if dupes:
                raise InvalidDataSetDefinition(
                    'DUPLICATE_PARAMETER',
                    'Invalid dataset definition: Names must be unique. %s defined more than once'
                    % dupes)
            self.param_names.update(keys)

        self.global_data = {}
        if 'global_data' in self._definition:
            self.global_data = DataV6(definition['global_data']).get_data()
Esempio n. 3
0
    def get_definition(self):
        """Returns the recipe definition represented by this JSON

        :returns: The recipe definition
        :rtype: :class:`recipe.definition.definition.RecipeDefinition`:
        """

        interface_json = InterfaceV6(self._definition['input'],
                                     do_validate=False)
        interface = interface_json.get_interface()
        definition = RecipeDefinition(interface)

        # Add all nodes to definition first
        for node_name, node_dict in self._definition['nodes'].items():
            node_type_dict = node_dict['node_type']
            if node_type_dict['node_type'] == 'condition':
                cond_interface_json = InterfaceV6(node_type_dict['interface'],
                                                  do_validate=False)
                data_filter_json = DataFilterV6(node_type_dict['data_filter'],
                                                do_validate=False)
                definition.add_condition_node(
                    node_name, cond_interface_json.get_interface(),
                    data_filter_json.get_filter())
            elif node_type_dict['node_type'] == 'job':
                definition.add_job_node(node_name,
                                        node_type_dict['job_type_name'],
                                        node_type_dict['job_type_version'],
                                        node_type_dict['job_type_revision'])
            elif node_type_dict['node_type'] == 'recipe':
                definition.add_recipe_node(
                    node_name, node_type_dict['recipe_type_name'],
                    node_type_dict['recipe_type_revision'])

        # Now add dependencies and connections
        for node_name, node_dict in self._definition['nodes'].items():
            for dependency_dict in node_dict['dependencies']:
                acceptance = dependency_dict['acceptance'] if (
                    'acceptance' in dependency_dict) else True
                definition.add_dependency(dependency_dict['name'], node_name,
                                          acceptance)
            for conn_name, conn_dict in node_dict['input'].items():
                if conn_dict['type'] == 'recipe':
                    definition.add_recipe_input_connection(
                        node_name, conn_name, conn_dict['input'])
                elif conn_dict['type'] == 'dependency':
                    definition.add_dependency_input_connection(
                        node_name, conn_name, conn_dict['node'],
                        conn_dict['output'])

        return definition
Esempio n. 4
0
    def get_input_interface(self):
        """Returns the input interface for this manifest

        :returns: The input interface for this manifest
        :rtype: :class:`data.interface.interface.Interface`
        """

        input_dict = self.get_inputs()
        for file_dict in input_dict['files']:
            if 'partial' in file_dict:
                del file_dict['partial']
        return InterfaceV6(interface=input_dict, do_validate=False).get_interface()
Esempio n. 5
0
    def _populate_default_values(self):
        """Populates any missing required values with defaults
        """

        if 'input' not in self._definition:
            self._definition['input'] = {}
        if 'nodes' not in self._definition:
            self._definition['nodes'] = {}

        # Populate defaults for input interface
        interface_json = InterfaceV6(self._definition['input'],
                                     do_validate=False)
        self._definition['input'] = strip_schema_version(
            interface_json.get_dict())
Esempio n. 6
0
    def get_input_interface(self):
        """Returns the input interface for this manifest

        :returns: The input interface for this manifest
        :rtype: :class:`data.interface.interface.Interface`
        """

        input_dict = copy.deepcopy(self.get_inputs())
        if 'files' in input_dict:
            for file_dict in input_dict['files']:
                if 'partial' in file_dict:
                    del file_dict['partial']
                if 'mediaTypes' in file_dict:
                    file_dict['media_types'] = file_dict['mediaTypes']
                    del file_dict['mediaTypes']
        return InterfaceV6(interface=input_dict,
                           do_validate=False).get_interface()
Esempio n. 7
0
    def add_global_parameter(self, parameter):
        """Adds a new global parameter to the dataset definition

        :param parameter: The parameter to add
        :type parameter: :class:`data.interface.parameter.Parameter`
        """
        if parameter.name in self.param_names:
            raise InvalidDataSetDefinition(
                'DUPLICATE_PARAMETER',
                'Invalid dataset definition: %s cannot be defined more than once'
                % parameter.name)
        else:
            self.param_names.add(parameter.name)
            if self.global_parameters:
                self.global_parameters.add_parameter(parameter)
            else:
                self.global_parameters = InterfaceV6().get_interface()
                self.global_parameters.add_parameter(parameter)
Esempio n. 8
0
    def get_output_interface(self):
        """Returns the output interface for this manifest

        :returns: The output interface for this manifest
        :rtype: :class:`data.interface.interface.Interface`
        """

        output_dict = copy.deepcopy(self.get_outputs())
        if 'files' in output_dict:
            for file_dict in output_dict['files']:
                if 'pattern' in file_dict:
                    del file_dict['pattern']
                if 'mediaType' in file_dict:
                    file_dict['media_types'] = [file_dict['mediaType']]
                    del file_dict['mediaType']
        if 'json' in output_dict:
            for json_dict in output_dict['json']:
                if 'key' in json_dict:
                    del json_dict['key']
        return InterfaceV6(interface=output_dict,
                           do_validate=False).get_interface()