Пример #1
0
    def print_workflows(self,
                        workflows: List[Workflow],
                        namespace: Optional[str] = None,
                        command: Optional[str] = None):
        workflows.sort(key=lambda o: o.namespace)
        if len(workflows) == 1:
            str_resp = json.dumps(workflows[0].to_dict(),
                                  indent=4,
                                  sort_keys=False)
            logger.info(highlight(str_resp, JsonLexer(), TerminalFormatter()))
        elif len(workflows) > 0:
            to_values = list(
                map(lambda wf: [wf.namespace, wf.command, wf.description],
                    workflows))
            namesp = f"Workflow "
            if namespace:
                namesp += f"{namespace}"

            banner(f"Available {namesp} Methods")
            logger.info()
            logger.info(
                tabulate(to_values,
                         headers=["namespace", "command", "description"]))
            logger.info()
        else:
            logger.error(
                "No workflows registered.  Register operators by running \"mason apply\""
            )
Пример #2
0
 def print_configs(self,
                   configs: List[Config],
                   environment: Optional[MasonEnvironment] = None):
     configs.sort(key=lambda o: o.id)
     current_config: Optional[str] = None
     if environment:
         current_config = environment.state_store.get_session_config()
     if len(configs) == 1:
         str_resp = json.dumps(configs[0].to_dict(current_config),
                               indent=4,
                               sort_keys=False)
         logger.info(highlight(str_resp, JsonLexer(), TerminalFormatter()))
     elif len(configs) > 0:
         to_values = list(
             map(lambda c: c.extended_info(current_config), configs))
         banner(f"Available Configs")
         logger.info()
         logger.info(
             tabulate(to_values,
                      headers=[
                          "id", "execution", "metastore", "storage",
                          "scheduler"
                      ]))
         logger.info()
         if current_config:
             logger.info("* Current Session Configuration")
     else:
         logger.error(
             "No configs.  Register configs by running \"mason apply\"")
Пример #3
0
    def print_resources(
            self,
            resources: List[Union[Operator, Workflow, Config,
                                  MalformedResource]],
            type: Optional[str] = None,
            namespace: Optional[str] = None,
            command: Optional[str] = None,
            environment: Optional[MasonEnvironment] = None) -> Response:
        if len(resources) == 0:
            logger.error(self.none_message(type, namespace, command))
        else:
            operators, workflows, configs, bad = sequence_4(
                resources, Operator, Workflow, Config, MalformedResource)
            type_name = type or "all"
            # TODO: dry up with resources
            if type in ["all", "operator", "operators"]:
                self.print_operators(operators, namespace, command)
            if type in ["all", "workflow", "workflows"]:
                self.print_workflows(workflows, namespace, command)
            if type in ["all", "config", "configs"]:
                self.print_configs(configs, environment)

        return Response()
Пример #4
0
    def run(self):
        try:
            # banner("Importing all registered_operator modules for API")
            env = MasonEnvironment()
            # operators.import_all(env)
            base_swagger = from_root("/api/base_swagger.yml")

            # banner(f"Regenerating api yaml based on registered_operators to {base_swagger}")
            # operators.update_yaml(env, base_swagger)

            app = connexion.App(__name__, specification_dir='api')

            # Read the swagger.yml file to configure the endpoints
            swagger = from_root("/api/base_swagger.yml")
            app.add_api(swagger)

            # Create a URL route in our application for "/"
            @app.route('/')
            def home():
                """
                This function just responds to the browser ULR
                localhost:5000/
                :return:        the rendered template 'home.html'
                """

                readme_file = open("../README.md", "r")
                md_template_string = markdown.markdown(
                    readme_file.read(), extensions=["fenced_code"])

                return md_template_string

            # If we're running in stand alone mode, run the application
            if __name__ == 'mason.server':
                app.run(host='0.0.0.0', port=5000, debug=True)

        except ModuleNotFoundError as e:
            logger.error(str(e))
Пример #5
0
def parse_yaml(file: str):
    try:
        with open(file, 'r') as stream:
            try:
                yaml_load: dict = yaml.safe_load(stream)
                if type(yaml_load).__name__ == "dict":
                    return yaml_load
                else:
                    logger.error(f"\nInvalid YAML {file}: {yaml_load}\n")
            except yaml.YAMLError as exc:
                logger.error(f"\nInvalid YAML {file}: {exc}\n")
    except FileNotFoundError as e:
        logger.error(f"Specified YAML does not exist: {e}")
Пример #6
0
def print_json(d: dict):
    formatted_json = to_json(d)
    # colorful_json = highlight(formatted_json, lexers.JsonLexer(), formatters.TerminalFormatter())
    colorful_json = formatted_json
    return logger.error(colorful_json)
Пример #7
0
 def add_error(self, error: str, log: bool = True):
     error = self.add_timestamp(error)
     if log:
         logger.error(error)
     self.errors.append(error)
Пример #8
0
 def print_invalid(self, invalid: List[InvalidObject]):
     for i in invalid:
         logger.error(i.message)