def wrapper(backend_conf, modules_conf, ignore_stderr=False): nonlocal last_server_id server_id = last_server_id + 1 last_server_id = server_id port = unused_tcp_port_factory() event_server_address = f'tcp+sbs://127.0.0.1:{port}' conf = { 'type': 'event', 'log': { 'version': 1 }, 'monitor': { 'name': 'event server {server_id}', 'group': 'event servers', 'monitor_address': monitor_address, 'component_address': event_server_address }, 'backend_engine': { 'server_id': server_id, 'backend': backend_conf }, 'module_engine': { 'modules': modules_conf }, 'communication': { 'address': event_server_address } } conf_path = tmp_path / f'event_{server_id}.yaml' json.encode_file(conf, conf_path) return EventServerProcess(conf_path, port, ignore_stderr=ignore_stderr)
def run_event_server(tmp_path, event_conf): conf_path = tmp_path / f'event.yaml' json.encode_file(event_conf, conf_path) proc = Process( ['python', '-m', 'hat.event.server', '--conf', str(conf_path)]) return proc
def run_monitor_subprocess(conf, conf_folder_path): conf_path = conf_folder_path / 'monitor.yaml' json.encode_file(conf, conf_path) creationflags = (subprocess.CREATE_NEW_PROCESS_GROUP if sys.platform == 'win32' else 0) return psutil.Popen( ['python', '-m', 'hat.monitor.server.main', '--conf', str(conf_path), '--ui-path', ''], creationflags=creationflags)
def wrapper(gateway_conf, ignore_stderr=False): conf_path = tmp_path / 'gateway.yaml' json.encode_file(gateway_conf, conf_path) proc = Process( ['python', '-m', 'hat.gateway', '--conf', str(conf_path)], ignore_stderr=ignore_stderr) wait_until(proc.is_running) return proc
def monitor_process(tmp_path, monitor_conf, monitor_port): conf_path = tmp_path / 'monitor.yaml' json.encode_file(monitor_conf, conf_path) with Process([ 'python', '-m', 'hat.monitor.server', '--conf', str(conf_path), '--ui-path', str(tmp_path) ]) as p: wait_until(p.listens_on, monitor_port) yield p
def run_orchestrator_subprocess(conf, conf_folder_path): conf_path = conf_folder_path / "orchestrator.yaml" json.encode_file(conf, conf_path) creationflags = (subprocess.CREATE_NEW_PROCESS_GROUP if sys.platform == 'win32' else 0) return psutil.Popen( ['python', '-m', 'hat.orchestrator', '--conf', str(conf_path), '--ui-path', str(conf_folder_path)], creationflags=creationflags)
def monitor_process(tmp_path, monitor_conf, monitor_port): conf_path = tmp_path / 'monitor.yaml' json.encode_file(monitor_conf, conf_path) args = [ 'python', '-m', 'hat.monitor.server', '--conf', str(conf_path), '--ui-path', str(tmp_path) ] with Process(args) as p: p.wait_connection(monitor_port, 5) yield p
def calculate(json_schema_repo, params_path, method, result_path, output_path, output_type, output_panel_id): """Calculate result and generate outputs""" params_json_data = json.decode_file(params_path) opcut.json_validator.validate('opcut://params.yaml#', params_json_data) params = common.json_data_to_params(params_json_data) result = opcut.csp.calculate(params, method) result_json_data = common.result_to_json_data(result) json.encode_file(result_json_data, result_path) if output_path: output(json_schema_repo, output_path, result_path, output_type, output_panel_id)
def monitor_process(tmp_path, monitor_conf, monitor_port): conf_path = tmp_path / 'monitor.yaml' json.encode_file(monitor_conf, conf_path) with Process([ 'python', '-m', 'hat.monitor.server', '--conf', str(conf_path), '--json-schemas-path', str(json.default_schemas_json_path), '--sbs-schemas-path', str(sbs.default_schemas_sbs_path), '--ui-path', str(tmp_path) ]) as p: p.wait_connection(monitor_port, 1) yield p
def _create_package_json(name, desc, deps): version = _get_version() dst_dir = _get_dst_dir(name) package = {'name': name, 'version': version, 'description': desc, 'homepage': 'https://github.com/hat-open/hat-core', 'bugs': 'https://github.com/hat-open/hat-core/issues', 'license': 'MIT', 'main': 'index.js', 'repository': 'hat-open/hat-core', 'dependencies': deps} json.encode_file(package, dst_dir / 'package.json')
def generate(): repo = sbs.Repository(*src_paths) data = repo.to_json() for dst_path in dst_paths: json.encode_file(data, dst_path, indent=None)