def fixture_deepen_negation_service(events_service, processor_watcher, processor_timeout): port = str(find_free_port()) address = '127.0.0.1:' + port p = Popen( ['python', '-m', 'biomedicus.negation.deepen', '-p', port, '--events', events_service], stdin=PIPE, stdout=PIPE, stderr=STDOUT) yield from processor_watcher(address, p, processor_timeout)
def fixture_concepts_service(events_service, processor_watcher, processor_timeout): port = str(find_free_port()) address = '127.0.0.1:' + port biomedicus_jar = biomedicus.biomedicus_jar() p = Popen(['java', '-cp', biomedicus_jar, 'edu.umn.biomedicus.concepts.DictionaryConceptDetector', '-p', port, '--events', events_service], stdin=PIPE, stdout=PIPE, stderr=PIPE) yield from processor_watcher(address, p, timeout=processor_timeout)
def fixture_java_hello_processor(python_events, processor_watcher): mtap_jar = os.environ['MTAP_JAR'] port = str(find_free_port()) p = Popen(['java', '-cp', mtap_jar, 'edu.umn.nlpie.mtap.examples.HelloWorldExample', '-p', port, '--events', python_events], stdin=PIPE, stdout=PIPE, stderr=STDOUT) address = "127.0.0.1:" + port yield from processor_watcher(address=address, process=p)
def fixture_modification_detector_service(events_service, processor_watcher, processor_timeout): port = str(find_free_port()) address = '127.0.0.1:' + port biomedicus_jar = biomedicus.biomedicus_jar() p = Popen(['java', '-cp', biomedicus_jar, 'edu.umn.biomedicus.modification.ModificationDetector', '-p', port, '--events', events_service], stdin=PIPE, stdout=PIPE, stderr=STDOUT) yield from processor_watcher(address, p, timeout=processor_timeout)
def fixture_java_references_processor(python_events, processor_watcher): mtap_jar = os.environ['MTAP_JAR'] mtap_jar = mtap_jar + ':' + str(Path(__file__).parents[1] / 'slf4j-simple-1.7.30.jar') env = dict(os.environ) port = str(find_free_port()) p = Popen(['java', '-cp', mtap_jar, 'edu.umn.nlpie.mtap.examples.ReferenceLabelsExampleProcessor', '-p', port, '-e', python_events], stdin=PIPE, stdout=PIPE, stderr=STDOUT, env=env) yield from processor_watcher(address="127.0.0.1:" + port, process=p)
def fixture_normalization_processor(events_service, processor_watcher, processor_timeout): port = str(find_free_port()) address = '127.0.0.1:' + port biomedicus_jar = biomedicus.biomedicus_jar() p = Popen(['java', '-cp', biomedicus_jar, 'edu.umn.biomedicus.normalization.NormalizationProcessor', '-p', port, '--events', events_service], start_new_session=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) yield from processor_watcher(address, p, timeout=processor_timeout)
def fixture_pos_tags_service(events_service, processor_watcher, processor_timeout): port = str(find_free_port()) address = '127.0.0.1:' + port biomedicus_jar = biomedicus.biomedicus_jar() p = Popen(['java', '-cp', biomedicus_jar, 'edu.umn.biomedicus.tagging.tnt.TntPosTaggerProcessor', '-p', port, '--events', events_service], start_new_session=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT) yield from processor_watcher(address, p, timeout=processor_timeout)
def fixture_python_processor(python_events, processor_watcher): port = str(find_free_port()) p = Popen([ 'python', '-m', 'mtap.examples.example_processor', '-p', port, '--events', python_events ], stdin=PIPE, stdout=PIPE, stderr=STDOUT) yield from processor_watcher(address="127.0.0.1:" + port, process=p)
def fixture_hello_processor(python_events, processor_watcher): port = find_free_port() p = Popen([ 'python', '-m', 'mtap.examples.tutorial.hello', '-p', str(port), '--events', python_events ], stdin=PIPE, stdout=PIPE, stderr=STDOUT) address = "127.0.0.1:" + str(port) yield from processor_watcher(address=address, process=p)
def fixture_sentences_service(events_service, processor_watcher, processor_timeout): port = str(find_free_port()) address = '127.0.0.1:' + port p = subprocess.Popen([ 'python', '-m', 'biomedicus.sentences.bi_lstm', 'processor', '-p', port, '--events', events_service ], start_new_session=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) yield from processor_watcher(address, p, timeout=processor_timeout)
def fixture_dependencies_service(events_service, processor_watcher, processor_timeout): try: existing_address = os.environ['DEPENDENCIES_ADDRESS'] yield existing_address return except KeyError: pass port = str(find_free_port()) address = '127.0.0.1:' + port p = Popen(['python', '-m', 'biomedicus.dependencies.stanza_selective_parser', '-p', port, '--events', events_service], start_new_session=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT) yield from processor_watcher(address, p, timeout=processor_timeout)
def fixture_python_references_processor(python_events, processor_watcher): env = dict(os.environ) port = str(find_free_port()) p = Popen(['python', '-m', 'mtap.examples.example_references_processor', '-p', port, '--events', python_events, '--log-level', 'DEBUG'], stdin=PIPE, stdout=PIPE, stderr=STDOUT, env=env) yield from processor_watcher(address="127.0.0.1:" + port, process=p)
def fixture_python_events(): port = find_free_port() with subprocess_events_server(port=port) as address: yield address
def fixture_api_gateway(python_events, python_processor, java_processor): port = find_free_port() config = { 'discovery': 'consul', 'grpc': { 'enable_proxy': False }, 'max_send_message_length': 104857600, 'max_receive_message_length': 104857600, 'consul': { 'host': 'localhost', 'port': 8500, 'scheme': 'http', # Python uses {python_naming_scheme}:address[:port][,address[:port],...] as grpc targets 'python_naming_scheme': 'ipv4' }, 'gateway': { 'port': port, 'refresh_interval': 10, 'events': python_events, 'processors': [{ 'Identifier': 'mtap-example-processor-python', 'Endpoint': python_processor }, { 'Identifier': 'mtap-example-processor-java', 'Endpoint': java_processor }] } } with tempfile.NamedTemporaryFile('w', suffix='.yml') as conf_file: yaml.dump(config, conf_file, Dumper=Dumper) conf_file.flush() p = Popen([ 'mtap-gateway', '-logtostderr', '-v=3', '-mtap-config=' + conf_file.name ], stdin=PIPE, stdout=PIPE, stderr=STDOUT) session = requests.Session() session.trust_env = False gateway = '127.0.0.1:{}'.format(port) try: if p.returncode is not None: raise ValueError("Failed to launch go gateway") for i in range(6): if i == 5: raise ValueError("Failed to connect to go gateway") try: time.sleep(3) resp = session.get( "http://{}/v1/processors".format(gateway), timeout=1) if resp.status_code == 200 and len( resp.json()['Processors']) == 2: break except RequestException: pass yield gateway finally: session.close() p.send_signal(signal.SIGINT) try: stdout, _ = p.communicate(timeout=1) print("api gateway exited with code: ", p.returncode) print(stdout.decode('utf-8')) except TimeoutExpired: print("timed out waiting for api gateway to terminate")