Exemple #1
0
def run_test(env: MasonEnvironment, namespace: str, command: str,
             configs: List[str], workflow: bool, callable):
    op: Union[Operator, Workflow, MalformedResource]
    res = base.Resources(env)

    if workflow:
        op = res.get_workflow(namespace, command)
    else:
        op = res.get_operator(namespace, command)

    if not isinstance(op, MalformedResource) and (op != None):
        for config in configs:
            conf = res.get_config(config)
            # invalid = res.get_bad()
            # for inv in invalid:
            #     print(f"Invalid Config: {inv.get_message()}")
            # conf = get_config(env, config)
            if isinstance(conf, Config):
                callable(env, conf, op)
            else:
                raise Exception(
                    f"No matching valid configuration found for {namespace}:{command}."
                )
    else:
        raise Exception(f"No operator found: {namespace}:{command}")
Exemple #2
0
 def validate_workflow(
         self, env: MasonEnvironment, command: str, config_id: str,
         params: dict) -> Union[ValidWorkflow, InvalidWorkflow]:
     logger.set_level("fatal")
     res = base.Resources(env)
     wf = res.get_workflow("testing_namespace", command)
     config = res.get_config(config_id)
     if wf and config and isinstance(wf, Workflow) and isinstance(
             config, Config):
         parameters = WorkflowParameters(parameter_dict=params)
         validated = wf.validate(env, config, parameters)
         return validated
     else:
         raise Exception("Invalid workflow or config")
Exemple #3
0
def get(resource_type: Optional[str],
        namespace: Optional[str] = None,
        command: Optional[str] = None,
        log_level: Optional[str] = "info",
        env: Optional[MasonEnvironment] = None,
        printer: Printer = ApiPrinter()):
    environment: MasonEnvironment = env or MasonEnvironment().initialize()
    logger.set_level(log_level)
    resource_type = resource_type or "all"
    res = base.Resources(environment)

    all = res.get_resources(resource_type, namespace, command)
    response = printer.print_resources(all,
                                       resource_type,
                                       namespace,
                                       command,
                                       environment=environment)

    return response.with_status()
Exemple #4
0
def run(resource_type: str,
        namespace: str,
        command: str,
        parameter_string: Optional[str] = None,
        param_file: Optional[str] = None,
        config_id: Optional[str] = None,
        log_level: Optional[str] = None,
        env: Optional[MasonEnvironment] = None,
        dry_run: bool = False,
        parameters: Optional[dict] = None,
        printer=ApiPrinter()):
    response = Response()
    environment: MasonEnvironment = env or MasonEnvironment().initialize()
    logger.set_level(log_level)
    res = base.Resources(environment)

    resource: Union[Resource, MalformedResource] = res.get_resource(
        resource_type, namespace, command)
    config: Union[Config, MalformedResource] = res.get_best_config(config_id)
    params: Union[Parameters, MalformedResource] = res.get_parameters(
        resource_type, parameter_string, param_file, parameters)

    if isinstance(resource, Resource) and isinstance(
            config, Config) and isinstance(params, Parameters):
        if dry_run:
            response = validate_resource(resource, config, params,
                                         environment).dry_run(
                                             environment,
                                             response).to_response(response)
        else:
            response = validate_resource(resource, config, params,
                                         environment).run(
                                             environment,
                                             response).to_response(response)
    else:
        if isinstance(resource, MalformedResource):
            response.add_error(f"Malformed Resource: {resource.get_message()}")
        elif isinstance(config, MalformedResource):
            response.add_error(f"Bad Config: {config.get_message()}")
        elif isinstance(params, MalformedResource):
            response.add_error(f"Bad Parameters: {params.get_message()}")

    return printer.print_response(response)
Exemple #5
0
 def test_all(self):
     env = get_env("/test/support/", "/test/support/validations/")
     res = base.Resources(env)
     config = res.get_config('3')
     assert (isinstance(config, Config))
     execution_clients = list(
         map(lambda e: e.client.name(), config.execution_clients))
     scheduler_clients = list(
         map(lambda e: e.client.name(), config.scheduler_clients))
     storage_clients = list(
         map(lambda e: e.client.name(), config.storage_clients))
     metastore_clients = list(
         map(lambda e: e.client.name(), config.metastore_clients))
     assert (execution_clients == ["test2"])
     assert (storage_clients == ["test"])
     assert (scheduler_clients == ["test2"])
     assert (metastore_clients == ["test"])
     assert (config.metastore().client.name() == "test")
     assert (config.storage().client.name() == "test")
     assert (config.scheduler().client.name() == "test2")
     assert (config.execution().client.name() == "test2")