def validate_input_files(self, files): """Validates the given file parameters to make sure they are valid with respect to the job interface. :param files: List of file inputs :type files: [:class:`job.seed.types.SeedInputFiles`] :returns: A list of warnings discovered during validation. :rtype: list[:class:`job.configuration.data.job_data.ValidationWarning`] :raises :class:`job.configuration.data.exceptions.InvalidConnection`: If there is a configuration problem. """ warnings = [] for file in files: if file.name not in self.files: if file.required: raise InvalidRecipeConnection('Data input %s is required and was not provided' % file.name) continue conn_file = self.files[file.name] conn_multiple = conn_file[0] conn_media_types = conn_file[1] conn_optional = conn_file[2] if conn_optional: if file.required: raise InvalidRecipeConnection('Data input %s is required and data from connection is optional' % file.name) if not file.multiple and conn_multiple: raise InvalidRecipeConnection('Data input %s only accepts a single file' % file.name) for conn_media_type in conn_media_types: if not file.is_media_type_allowed(conn_media_type): warn = ValidationWarning('media_type', 'Invalid media type for data input: %s -> %s' % (file.name, conn_media_type)) warnings.append(warn) return warnings
def validate_connection(self, recipe_conn): """Validates the given recipe connection to ensure that the connection will provide sufficient data to run a recipe with this definition :param recipe_conn: The recipe definition :type recipe_conn: :class:`recipe.configuration.data.recipe_connection.RecipeConnection` :returns: A list of warnings discovered during validation :rtype: list[:class:`recipe.configuration.data.recipe_data.ValidationWarning`] :raises :class:`recipe.configuration.data.exceptions.InvalidRecipeConnection`: If there is a configuration problem """ warnings = [] warnings.extend(recipe_conn.validate_input_files(self._input_file_validation_dict)) warnings.extend(recipe_conn.validate_properties(self._property_validation_dict)) # Check all recipe jobs for any file outputs file_outputs = False for job_type in self.get_job_types(): if job_type.get_job_interface().get_file_output_names(): file_outputs = True break # Make sure connection has a workspace if the recipe has any output files if file_outputs and not recipe_conn.has_workspace(): raise InvalidRecipeConnection('No workspace provided for output files') return warnings
def validate_input_files(self, files): """Validates the given file parameters to make sure they are valid with respect to the recipe definition. :param files: Dict of file parameter names mapped to a tuple with three items: whether the parameter is required (True), if the parameter is for multiple files (True), and the description of the expected file meta-data :type files: dict of str -> tuple(bool, bool, :class:`job.configuration.interface.scale_file.ScaleFileDescription`) :returns: A list of warnings discovered during validation. :rtype: list[:class:`recipe.configuration.data.recipe_data.ValidationWarning`] :raises :class:`recipe.configuration.data.exceptions.InvalidRecipeConnection`: If there is a configuration problem """ warnings = [] for name in files: required = files[name][0] multiple = files[name][1] file_desc = files[name][2] if name not in self.files: if required: raise InvalidRecipeConnection( 'Data input %s is required and was not provided' % name) continue conn_file = self.files[name] conn_multiple = conn_file[0] conn_media_types = conn_file[1] conn_optional = conn_file[2] if conn_optional and required: raise InvalidRecipeConnection( 'Data input %s is required and data from connection is optional' % name) if not multiple and conn_multiple: raise InvalidRecipeConnection( 'Data input %s only accepts a single file' % name) for conn_media_type in conn_media_types: if not file_desc.is_media_type_allowed(conn_media_type): warn = ValidationWarning( 'media_type', 'Invalid media type for data input: %s -> %s' % (name, conn_media_type)) warnings.append(warn) return warnings
def validate_properties(self, property_names): """Validates the given property names to make sure all properties exist if they are required. :param property_names: Dict of property names mapped to a bool indicating if they are required :type property_names: dict of str -> bool :returns: A list of warnings discovered during validation. :rtype: list[:class:`job.configuration.data.job_data.ValidationWarning`] :raises :class:`job.configuration.data.exceptions.InvalidConnection`: If there is a configuration problem. """ warnings = [] for name in property_names: if name not in self.properties and property_names[name]: raise InvalidRecipeConnection('Property %s is required and was not provided' % name) return warnings
def validate_trigger_for_recipe(self, recipe_definition): raise InvalidRecipeConnection('Error!')