예제 #1
0
    async def get(self, path=''):
        path = path or ''
        path = url_unescape(path)

        self.log.debug(f"Parsing file: {path}")

        try:
            root_dir = self.settings['server_root_dir']
            absolute_path = get_absolute_path(get_expanded_path(root_dir),
                                              path)

            properties = self.content_parser.parse(absolute_path)

            # TODO: Validation of model
            self.finish(json.dumps(properties))
        except FileNotFoundError as fnfe:
            raise web.HTTPError(404, str(fnfe)) from fnfe
        except IsADirectoryError as iade:
            raise web.HTTPError(400, str(iade)) from iade
        except Exception as e:
            # Parser could not parse the given file, but this does not necessarily indicate an error with the file.
            # Log the issue and return an empty model so that other user processes are not disrupted.
            self.log.debug(f"Could not parse '{path}': {str(e)}")
            empty_properties = {"env_vars": {}, "inputs": [], "outputs": []}
            self.finish(json.dumps(empty_properties))
예제 #2
0
    def _get_remaining_component_params(self, node: Dict):
        """
        Builds a dictionary of the parameters for a given node that do not have a corresponding
        property in the Operation object. These parameters will be used by the appropriate processor when
        loading and running a component that is not one of the standard notebook or script operations.
        """
        component_params = {}
        if node.get('op') not in ["execute-notebook-node", "execute-python-node", "execute-r-node"]:
            for key, value in node['app_data'].items():
                # Do not include any null values
                if not value or value == "None":
                    continue
                # Do not include any of the standard set of parameters
                if key in ["filename", "runtime_image", "cpu", "gpu", "memory", "dependencies", "env_vars", "outputs",
                           "include_subdirectories", "ui_data", "component_source", "component_source_type",
                           "elyra_airflow_class_name"]:
                    continue
                # For Airflow inputs, remove class name information from key
                class_name = PipelineParser._get_app_data_field(node, 'elyra_airflow_class_name')
                if class_name and not key.startswith(class_name.lower().replace(' ', '_')):
                    # Skip if the class name does not match that selected
                    continue
                elif class_name and key.startswith(class_name.lower()):
                    key = key.replace(class_name.lower() + "_", "")
                    # TODO Add try/except clause here to catch user-entered incorrect values and
                    # display error
                    if "elyra_dict_" in key:
                        key = key.replace("elyra_dict_", "")
                        value = ast.literal_eval(value)
                    elif "elyra_int_" in key:
                        key = key.replace("elyra_int_", "")
                        value = int(value)
                    # If not dictionary or list object, convert string to include surrounding quotes
                    # so that jinja template can render values properly. Integers and booleans will
                    # not appear as string instances
                    elif isinstance(value, str):
                        value = json.dumps(value)
                # For KFP path inputs and outputs, grab the content in order to pass to contructor
                if key.startswith("elyra_path_"):
                    key = key.replace("elyra_path_", "")
                    filename = get_absolute_path(get_expanded_path(self.root_dir), value)
                    # TODO: Add error checking for FNF scenarios (at minimum)
                    try:
                        with open(filename) as f:
                            value = f.read()
                    except Exception:
                        # If file can't be found locally, assume a remote file location was entered.
                        # This may cause the pipeline run to fail; the user must debug in this case.
                        pass

                component_params[key] = value

        return component_params