<s> from __future__ import print_function , unicode_literals <EOL> import re <EOL> from weblab . core . coordinator . resource import Resource <EOL> from weblab . data . experiments import ExperimentInstanceId <EOL> import weblab . core . exc as coreExc <EOL> COORDINATOR_LABORATORY_SERVERS = "<STR_LIT>" <EOL> COORDINATOR_EXTERNAL_SERVERS = "<STR_LIT>" <EOL> class CoordinationConfigurationParser ( object ) : <EOL> EXPERIMENT_INSTANCE_REGEX = r"<STR_LIT>" <EOL> RESOURCE_INSTANCE_REGEX = r"<STR_LIT>" <EOL> def __init__ ( self , cfg_manager ) : <EOL> self . _cfg_manager = cfg_manager <EOL> def parse_external_servers ( self ) : <EOL> external_servers = self . _cfg_manager . get_value ( COORDINATOR_EXTERNAL_SERVERS , { } ) <EOL> for external_server in external_servers : <EOL> external_servers [ external_server ] = set ( external_servers [ external_server ] ) <EOL> return external_servers <EOL> def parse_resources_for_experiment_ids ( self ) : <EOL> raw_configuration = self . parse_configuration ( ) <EOL> configuration = self . parse_external_servers ( ) <EOL> for laboratory in raw_configuration : <EOL> laboratory_config = raw_configuration [ laboratory ] <EOL> for experiment_instance_id in laboratory_config : <EOL> resource_type_name = laboratory_config [ experiment_instance_id ] . resource_type <EOL> experiment_id_str = experiment_instance_id . to_experiment_id ( ) . to_weblab_str ( ) <EOL> if not experiment_id_str in configuration : <EOL> configuration [ experiment_id_str ] = set ( ) <EOL> configuration [ experiment_id_str ] . add ( resource_type_name ) <EOL> return configuration <EOL> def parse_configuration ( self ) : <EOL> configuration = { } <EOL> laboratory_servers = self . _cfg_manager . get_value ( COORDINATOR_LABORATORY_SERVERS ) <EOL> for laboratory_server_coord_address_str in laboratory_servers : <EOL> experiment_instances = laboratory_servers [ laboratory_server_coord_address_str ] <EOL> laboratory_configuration = { } <EOL> configuration [ laboratory_server_coord_address_str ] = laboratory_configuration <EOL> for experiment_instance in experiment_instances : <EOL> resource_instance = experiment_instances [ experiment_instance ] <EOL> mo_experiment_instance = re . match ( self . EXPERIMENT_INSTANCE_REGEX , experiment_instance ) <EOL> if mo_experiment_instance is None : <EOL> raise coreExc . CoordinationConfigurationParsingError ( "<STR_LIT>" % ( experiment_instance , self . EXPERIMENT_INSTANCE_REGEX ) ) <EOL> mo_resource_instance = re . match ( self . RESOURCE_INSTANCE_REGEX , resource_instance ) <EOL> if mo_resource_instance is None : <EOL> raise coreExc . CoordinationConfigurationParsingError ( "<STR_LIT>" % ( resource_instance , self . RESOURCE_INSTANCE_REGEX ) ) <EOL> ( <EOL> inst_name , <EOL> exp_name , <EOL> exp_cat_name <EOL> ) = mo_experiment_instance . groups ( ) <EOL> experiment_instance_id = ExperimentInstanceId ( inst_name , exp_name , exp_cat_name ) <EOL> ( <EOL> resource_instance , <EOL> resource_type <EOL> ) = mo_resource_instance . groups ( ) <EOL> resource = Resource ( resource_type , resource_instance ) <EOL> laboratory_configuration [ experiment_instance_id ] = resource <EOL> return configuration </s>
