Ejemplo n.º 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\""
            )
Ejemplo n.º 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\"")
Ejemplo n.º 3
0
def get_client_version() -> Optional[str]:
    try:
        import pkg_resources
        ver: Optional[str] = None
        module = sys._getframe(1).f_globals.get("__name__")
        for dist in pkg_resources.working_set:
            scripts = dist.get_entry_map().get("console_scripts") or {}
            for _, entry_point in iteritems(scripts):
                if entry_point.module_name == module:
                    ver = dist.version
        return ver
    except Exception as e:
        banner("Could not find client version", "fatal")
        return None
Ejemplo n.º 4
0
    def initialize(self) -> str:
        if not path.exists(self.home):
            banner(f"Creating MASON_HOME at {self.home}", "fatal")
            os.mkdir(self.home)
        if not path.exists(self.operator_home):
            banner(f"Creating OPERATOR_HOME at {self.operator_home}", "fatal")
            os.mkdir(self.operator_home)
            Path(self.operator_home + "__init__.py").touch()
        if not path.exists(self.workflow_home):
            banner(f"Creating WORKFLOW_HOME at {self.workflow_home}", "fatal")
            os.mkdir(self.workflow_home)
            Path(self.workflow_home + "__init__.py").touch()
        if not path.exists(self.config_home):
            banner(f"Creating CONFIG_HOME at {self.config_home}", "fatal")
            os.mkdir(self.config_home)

        return "Succesfully initialized"