<s> """<STR_LIT>""" <EOL> import datetime <EOL> from zope . interface import implements <EOL> from twisted . python import log <EOL> from twisted . internet import defer <EOL> from opennsa . interface import INSIProvider , INSIRequester <EOL> from opennsa import error , nsa , state , database , constants as cnt <EOL> LOG_SYSTEM = '<STR_LIT>' <EOL> def shortLabel ( label ) : <EOL> if label is None : <EOL> return '<STR_LIT>' <EOL> if '<STR_LIT:}>' in label . type_ : <EOL> name = label . type_ . split ( '<STR_LIT:}>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> elif '<STR_LIT:#>' in label . type_ : <EOL> name = label . type_ . split ( '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> else : <EOL> name = label . type_ <EOL> return name + '<STR_LIT:=>' + label . labelValue ( ) <EOL> def _logErrorResponse ( err , connection_id , provider_nsa , action ) : <EOL> log . msg ( '<STR_LIT>' % ( connection_id , action , provider_nsa ) , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( connection_id , err . getErrorMessage ( ) ) , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> err . printTraceback ( ) <EOL> return err <EOL> def _createAggregateException ( connection_id , action , results , provider_urns , default_error = error . InternalServerError ) : <EOL> failures = [ conn for success , conn in results if not success ] <EOL> if len ( failures ) == <NUM_LIT:0> : <EOL> return error . InternalServerError ( '<STR_LIT>' ) <EOL> if len ( failures ) == <NUM_LIT:1> : <EOL> return failures [ <NUM_LIT:0> ] <EOL> else : <EOL> provider_failures = [ provider_urn + '<STR_LIT>' + f . getErrorMessage ( ) for provider_urn , ( success , f ) in zip ( provider_urns , results ) if not success ] <EOL> error_msg = '<STR_LIT>' % ( len ( failures ) , len ( results ) , action , '<STR_LIT>' . join ( provider_failures ) ) <EOL> return default_error ( error_msg ) <EOL> class Aggregator : <EOL> implements ( INSIProvider , INSIRequester ) <EOL> def __init__ ( self , network , nsa_ , network_topology , route_vectors , parent_requester , provider_registry , policies , plugin ) : <EOL> self . network = network <EOL> self . nsa_ = nsa_ <EOL> self . network_topology = network_topology <EOL> self . route_vectors = route_vectors <EOL> self . parent_requester = parent_requester <EOL> self . provider_registry = provider_registry <EOL> self . policies = policies <EOL> self . plugin = plugin <EOL> self . reservations = { } <EOL> self . notification_id = <NUM_LIT:0> <EOL> self . db_connections = { } <EOL> self . db_sub_connections = { } <EOL> self . query_requests = { } <EOL> self . query_calls = { } <EOL> def getNotificationId ( self ) : <EOL> nid = self . notification_id <EOL> self . notification_id += <NUM_LIT:1> <EOL> return nid <EOL> def getProvider ( self , nsi_agent_urn ) : <EOL> return self . provider_registry . getProvider ( nsi_agent_urn ) <EOL> def getConnection ( self , connection_id ) : <EOL> def gotResult ( connections ) : <EOL> if len ( connections ) == <NUM_LIT:0> : <EOL> return defer . fail ( error . ConnectionNonExistentError ( '<STR_LIT>' % connection_id ) ) <EOL> self . db_connections [ connection_id ] = connections [ <NUM_LIT:0> ] <EOL> return connections [ <NUM_LIT:0> ] <EOL> if connection_id in self . db_connections : <EOL> return defer . succeed ( self . db_connections [ connection_id ] ) <EOL> d = database . ServiceConnection . findBy ( connection_id = connection_id ) <EOL> d . addCallback ( gotResult ) <EOL> return d <EOL> def getConnectionByKey ( self , connection_key ) : <EOL> def gotResult ( connections ) : <EOL> if len ( connections ) == <NUM_LIT:0> : <EOL> return defer . fail ( error . ConnectionNonExistentError ( '<STR_LIT>' % connection_key ) ) <EOL> conn = connections [ <NUM_LIT:0> ] <EOL> return self . getConnection ( conn . connection_id ) <EOL> d = database . ServiceConnection . findBy ( id = connection_key ) <EOL> d . addCallback ( gotResult ) <EOL> return d <EOL> def getSubConnection ( self , provider_nsa , connection_id ) : <EOL> def gotResult ( connections ) : <EOL> if len ( connections ) == <NUM_LIT:0> : <EOL> return defer . fail ( error . ConnectionNonExistentError ( '<STR_LIT>' % ( connection_id , provider_nsa ) ) ) <EOL> self . db_sub_connections [ connection_id ] = connections [ <NUM_LIT:0> ] <EOL> return connections [ <NUM_LIT:0> ] <EOL> if connection_id in self . db_sub_connections : <EOL> return defer . succeed ( self . db_sub_connections [ connection_id ] ) <EOL> d = database . SubConnection . findBy ( provider_nsa = provider_nsa , connection_id = connection_id ) <EOL> d . addCallback ( gotResult ) <EOL> return d <EOL> def getSubConnectionsByConnectionKey ( self , service_connection_key ) : <EOL> def gotResult ( rows ) : <EOL> def gotSubConns ( results ) : <EOL> if all ( [ r [ <NUM_LIT:0> ] for r in results ] ) : <EOL> return [ r [ <NUM_LIT:1> ] for r in results ] <EOL> else : <EOL> return defer . fail ( '<STR_LIT>' % str ( results ) ) <EOL> defs = [ self . getSubConnection ( r [ '<STR_LIT>' ] , r [ '<STR_LIT>' ] ) for r in rows ] <EOL> return defer . DeferredList ( defs ) . addCallback ( gotSubConns ) <EOL> dbconfig = database . Registry . getConfig ( ) <EOL> d = dbconfig . select ( '<STR_LIT>' , where = [ '<STR_LIT>' , service_connection_key ] , select = '<STR_LIT>' ) <EOL> d . addCallback ( gotResult ) <EOL> return d <EOL> @ defer . inlineCallbacks <EOL> def reserve ( self , header , connection_id , global_reservation_id , description , criteria , request_info = None ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( header . requester_nsa , header . connection_trace ) , system = LOG_SYSTEM ) <EOL> if connection_id != None : <EOL> connection_exists = yield database . ServiceConnection . exists ( [ '<STR_LIT>' , connection_id ] ) <EOL> if connection_exists : <EOL> raise error . ConnectionExistsError ( '<STR_LIT>' % connection_id ) <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> yield self . plugin . connectionRequest ( header , connection_id , global_reservation_id , description , criteria ) <EOL> if cnt . REQUIRE_TRACE in self . policies : <EOL> if not header . connection_trace : <EOL> log . msg ( '<STR_LIT>' ) <EOL> raise error . SecurityError ( '<STR_LIT>' % self . nsa_ . urn ( ) ) <EOL> if cnt . REQUIRE_USER in self . policies : <EOL> user_attrs = [ sa for sa in header . security_attributes if sa . type_ == '<STR_LIT:user>' ] <EOL> if not user_attrs : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> raise error . SecurityError ( '<STR_LIT>' % self . nsa_ . urn ( ) ) <EOL> sd = criteria . service_def <EOL> source_stp = sd . source_stp <EOL> dest_stp = sd . dest_stp <EOL> if not ( source_stp . network == self . network or dest_stp . network == self . network ) : <EOL> raise error . ConnectionCreateError ( '<STR_LIT>' % <EOL> ( source_stp . network , dest_stp . network , self . network ) ) <EOL> if ( source_stp . label is None and dest_stp . label ) or ( source_stp . label and dest_stp . label is None ) : <EOL> raise error . ConnectionCreateError ( '<STR_LIT>' ) <EOL> if source_stp . network != self . network and self . route_vectors . vector ( source_stp . network ) is None : <EOL> raise error . ConnectionCreateError ( '<STR_LIT>' % source_stp . network ) <EOL> if dest_stp . network != self . network and self . route_vectors . vector ( dest_stp . network ) is None : <EOL> raise error . ConnectionCreateError ( '<STR_LIT>' % dest_stp . network ) <EOL> if source_stp . network == self . network : <EOL> self . network_topology . getPort ( source_stp . network + '<STR_LIT::>' + source_stp . port ) <EOL> if dest_stp . network == self . network : <EOL> self . network_topology . getPort ( dest_stp . network + '<STR_LIT::>' + dest_stp . port ) <EOL> connection_id = yield self . plugin . createConnectionId ( ) <EOL> conn = database . ServiceConnection ( connection_id = connection_id , revision = <NUM_LIT:0> , global_reservation_id = global_reservation_id , description = description , <EOL> requester_nsa = header . requester_nsa , requester_url = header . reply_to , reserve_time = datetime . datetime . utcnow ( ) , <EOL> reservation_state = state . RESERVE_START , provision_state = state . RELEASED , lifecycle_state = state . CREATED , <EOL> source_network = source_stp . network , source_port = source_stp . port , source_label = source_stp . label , <EOL> dest_network = dest_stp . network , dest_port = dest_stp . port , dest_label = dest_stp . label , <EOL> start_time = criteria . schedule . start_time , end_time = criteria . schedule . end_time , <EOL> symmetrical = sd . symmetric , directionality = sd . directionality , bandwidth = sd . capacity , <EOL> security_attributes = header . security_attributes , connection_trace = header . connection_trace ) <EOL> yield conn . save ( ) <EOL> yield state . reserveChecking ( conn ) <EOL> if conn . source_network == self . network and conn . dest_network == self . network : <EOL> if conn . source_port == conn . dest_port : <EOL> raise error . ServiceError ( '<STR_LIT>' ) <EOL> path_info = ( conn . connection_id , self . network , conn . source_port , shortLabel ( conn . source_label ) , conn . dest_port , shortLabel ( conn . dest_label ) ) <EOL> log . msg ( '<STR_LIT>' % path_info , system = LOG_SYSTEM ) <EOL> paths = [ [ nsa . Link ( nsa . STP ( self . network , conn . source_port , conn . source_label ) , <EOL> nsa . STP ( self . network , conn . dest_port , conn . dest_label ) ) ] ] <EOL> else : <EOL> log . msg ( '<STR_LIT>' % ( conn . connection_id , str ( source_stp ) , str ( dest_stp ) ) , system = LOG_SYSTEM ) <EOL> if source_stp . network == self . network : <EOL> local_stp = source_stp <EOL> remote_stp = dest_stp <EOL> else : <EOL> local_stp = dest_stp <EOL> remote_stp = source_stp <EOL> vector_port = self . route_vectors . vector ( remote_stp . network ) <EOL> if vector_port is None : <EOL> raise error . STPResolutionError ( '<STR_LIT>' % remote_stp . network ) <EOL> log . msg ( '<STR_LIT>' % ( remote_stp . network , vector_port ) , system = LOG_SYSTEM ) <EOL> demarc_ports = [ self . network_topology . getPort ( self . network + '<STR_LIT::>' + vector_port ) ] <EOL> ldp = demarc_ports [ <NUM_LIT:0> ] <EOL> local_demarc_port = ldp . id_ . rsplit ( '<STR_LIT::>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> remote_demarc_network , remote_demarc_port = ldp . remote_port . rsplit ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> local_link = nsa . Link ( local_stp , nsa . STP ( local_stp . network , local_demarc_port , ldp . label ( ) ) ) <EOL> remote_link = nsa . Link ( nsa . STP ( remote_demarc_network , remote_demarc_port , ldp . label ( ) ) , remote_stp ) <EOL> paths = [ [ local_link , remote_link ] ] <EOL> paths = yield self . plugin . prunePaths ( paths ) <EOL> selected_path = paths [ <NUM_LIT:0> ] <EOL> log_path = '<STR_LIT>' . join ( [ str ( p ) for p in selected_path ] ) <EOL> log . msg ( '<STR_LIT>' % log_path , system = LOG_SYSTEM ) <EOL> for link in selected_path : <EOL> if link . src_stp . network == self . network : <EOL> continue <EOL> p = self . provider_registry . getProviderByNetwork ( link . src_stp . network ) <EOL> if p is None : <EOL> raise error . ConnectionCreateError ( '<STR_LIT>' % link . src_stp . network ) <EOL> conn_trace = ( header . connection_trace or [ ] ) + [ self . nsa_ . urn ( ) + '<STR_LIT::>' + conn . connection_id ] <EOL> conn_info = [ ] <EOL> for idx , link in enumerate ( selected_path ) : <EOL> sub_connection_id = None <EOL> if link . src_stp . network == self . network : <EOL> provider_urn = self . nsa_ . urn ( ) <EOL> sub_connection_id = connection_id <EOL> else : <EOL> provider_urn = self . provider_registry . getProviderByNetwork ( link . src_stp . network ) <EOL> c_header = nsa . NSIHeader ( self . nsa_ . urn ( ) , provider_urn , security_attributes = header . security_attributes , connection_trace = conn_trace ) <EOL> sd = nsa . Point2PointService ( link . src_stp , link . dst_stp , conn . bandwidth , sd . directionality , sd . symmetric ) <EOL> self . reservations [ c_header . correlation_id ] = { <EOL> '<STR_LIT>' : provider_urn , <EOL> '<STR_LIT>' : conn . id , <EOL> '<STR_LIT>' : idx , <EOL> '<STR_LIT>' : link . src_stp . network , <EOL> '<STR_LIT>' : link . src_stp . port , <EOL> '<STR_LIT>' : link . dst_stp . network , <EOL> '<STR_LIT>' : link . dst_stp . port } <EOL> crt = nsa . Criteria ( criteria . revision , criteria . schedule , sd ) <EOL> provider = self . getProvider ( provider_urn ) <EOL> d = provider . reserve ( c_header , sub_connection_id , conn . global_reservation_id , conn . description , crt , request_info ) <EOL> d . addErrback ( _logErrorResponse , connection_id , provider_urn , '<STR_LIT>' ) <EOL> conn_info . append ( ( d , provider_urn ) ) <EOL> results = yield defer . DeferredList ( [ c [ <NUM_LIT:0> ] for c in conn_info ] , consumeErrors = True ) <EOL> successes = [ r [ <NUM_LIT:0> ] for r in results ] <EOL> if all ( successes ) : <EOL> log . msg ( '<STR_LIT>' % conn . connection_id , system = LOG_SYSTEM ) <EOL> defer . returnValue ( connection_id ) <EOL> else : <EOL> yield state . terminating ( conn ) <EOL> defs = [ ] <EOL> reserved_connections = [ ( sc_id , provider_urn ) for ( success , sc_id ) , ( _ , provider_urn ) in zip ( results , conn_info ) if success ] <EOL> for ( sc_id , provider_urn ) in reserved_connections : <EOL> provider = self . getProvider ( provider_urn ) <EOL> t_header = nsa . NSIHeader ( self . nsa_ . urn ( ) , provider_urn , security_attributes = header . security_attributes ) <EOL> d = provider . terminate ( t_header , sc_id ) <EOL> d . addCallbacks ( <EOL> lambda c : log . msg ( '<STR_LIT>' % ( sc_id , provider_urn ) , system = LOG_SYSTEM ) , <EOL> lambda f : log . msg ( '<STR_LIT>' % str ( f ) , system = LOG_SYSTEM ) <EOL> ) <EOL> defs . append ( d ) <EOL> dl = defer . DeferredList ( defs ) <EOL> yield dl <EOL> yield state . terminated ( conn ) <EOL> provider_urns = [ ci [ <NUM_LIT:1> ] for ci in conn_info ] <EOL> err = _createAggregateException ( connection_id , '<STR_LIT>' , results , provider_urns , error . ConnectionCreateError ) <EOL> raise err <EOL> @ defer . inlineCallbacks <EOL> def reserveCommit ( self , header , connection_id , request_info = None ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( header . requester_nsa , connection_id ) , system = LOG_SYSTEM ) <EOL> conn = yield self . getConnection ( connection_id ) <EOL> if conn . lifecycle_state == state . TERMINATED : <EOL> raise error . ConnectionGoneError ( '<STR_LIT>' % connection_id ) <EOL> yield state . reserveCommit ( conn ) <EOL> defs = [ ] <EOL> sub_connections = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> for sc in sub_connections : <EOL> provider = self . getProvider ( sc . provider_nsa ) <EOL> req_header = nsa . NSIHeader ( self . nsa_ . urn ( ) , sc . provider_nsa , security_attributes = header . security_attributes ) <EOL> d = provider . reserveCommit ( req_header , sc . connection_id , request_info ) <EOL> d . addErrback ( _logErrorResponse , connection_id , sc . provider_nsa , '<STR_LIT>' ) <EOL> defs . append ( d ) <EOL> results = yield defer . DeferredList ( defs , consumeErrors = True ) <EOL> successes = [ r [ <NUM_LIT:0> ] for r in results ] <EOL> if all ( successes ) : <EOL> log . msg ( '<STR_LIT>' % conn . connection_id , system = LOG_SYSTEM ) <EOL> defer . returnValue ( connection_id ) <EOL> else : <EOL> n_success = sum ( [ <NUM_LIT:1> for s in successes if s ] ) <EOL> log . msg ( '<STR_LIT>' % ( connection_id , n_success , len ( defs ) ) , system = LOG_SYSTEM ) <EOL> provider_urns = [ sc . provider_nsa for sc in sub_connections ] <EOL> raise _createAggregateException ( connection_id , '<STR_LIT>' , results , provider_urns , error . ConnectionError ) <EOL> @ defer . inlineCallbacks <EOL> def reserveAbort ( self , header , connection_id , request_info = None ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( header . requester_nsa , connection_id ) , system = LOG_SYSTEM ) <EOL> conn = yield self . getConnection ( connection_id ) <EOL> if conn . lifecycle_state == state . TERMINATED : <EOL> raise error . ConnectionGoneError ( '<STR_LIT>' % connection_id ) <EOL> yield state . reserveAbort ( conn ) <EOL> save_defs = [ ] <EOL> defs = [ ] <EOL> sub_connections = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> for sc in sub_connections : <EOL> save_defs . append ( state . reserveAbort ( sc ) ) <EOL> provider = self . getProvider ( sc . provider_nsa ) <EOL> header = nsa . NSIHeader ( self . nsa_ . urn ( ) , sc . provider_nsa , security_attributes = header . security_attributes ) <EOL> d = provider . reserveAbort ( header , sc . connection_id , request_info ) <EOL> d . addErrback ( _logErrorResponse , connection_id , sc . provider_nsa , '<STR_LIT>' ) <EOL> defs . append ( d ) <EOL> yield defer . DeferredList ( save_defs , consumeErrors = True ) <EOL> results = yield defer . DeferredList ( defs , consumeErrors = True ) <EOL> successes = [ r [ <NUM_LIT:0> ] for r in results ] <EOL> if all ( successes ) : <EOL> log . msg ( '<STR_LIT>' % conn . connection_id , system = LOG_SYSTEM ) <EOL> defer . returnValue ( connection_id ) <EOL> else : <EOL> n_success = sum ( [ <NUM_LIT:1> for s in successes if s ] ) <EOL> log . msg ( '<STR_LIT>' % ( conn . connection_id , len ( n_success ) , len ( defs ) ) , system = LOG_SYSTEM ) <EOL> provider_urns = [ sc . provider_nsa for sc in sub_connections ] <EOL> raise _createAggregateException ( connection_id , '<STR_LIT>' , results , provider_urns , error . ConnectionError ) <EOL> @ defer . inlineCallbacks <EOL> def provision ( self , header , connection_id , request_info = None ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( header . requester_nsa , connection_id ) , system = LOG_SYSTEM ) <EOL> conn = yield self . getConnection ( connection_id ) <EOL> if conn . lifecycle_state == state . TERMINATED : <EOL> raise error . ConnectionGoneError ( '<STR_LIT>' % connection_id ) <EOL> yield state . provisioning ( conn ) <EOL> save_defs = [ ] <EOL> defs = [ ] <EOL> sub_connections = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> for sc in sub_connections : <EOL> if sc . provision_state != state . PROVISIONING : <EOL> save_defs . append ( state . provisioning ( sc ) ) <EOL> if save_defs : <EOL> yield defer . DeferredList ( save_defs ) <EOL> for sc in sub_connections : <EOL> provider = self . getProvider ( sc . provider_nsa ) <EOL> header = nsa . NSIHeader ( self . nsa_ . urn ( ) , sc . provider_nsa , security_attributes = header . security_attributes ) <EOL> d = provider . provision ( header , sc . connection_id , request_info ) <EOL> d . addErrback ( _logErrorResponse , connection_id , sc . provider_nsa , '<STR_LIT>' ) <EOL> defs . append ( d ) <EOL> results = yield defer . DeferredList ( defs , consumeErrors = True ) <EOL> successes = [ r [ <NUM_LIT:0> ] for r in results ] <EOL> if all ( successes ) : <EOL> defer . returnValue ( connection_id ) <EOL> else : <EOL> n_success = sum ( [ <NUM_LIT:1> for s in successes if s ] ) <EOL> log . msg ( '<STR_LIT>' % ( connection_id , n_success , len ( defs ) ) , system = LOG_SYSTEM ) <EOL> provider_urns = [ sc . provider_nsa for sc in sub_connections ] <EOL> raise _createAggregateException ( connection_id , '<STR_LIT>' , results , provider_urns , error . ConnectionError ) <EOL> @ defer . inlineCallbacks <EOL> def release ( self , header , connection_id , request_info = None ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( header . requester_nsa , connection_id ) , system = LOG_SYSTEM ) <EOL> conn = yield self . getConnection ( connection_id ) <EOL> if conn . lifecycle_state == state . TERMINATED : <EOL> raise error . ConnectionGoneError ( '<STR_LIT>' % connection_id ) <EOL> yield state . releasing ( conn ) <EOL> save_defs = [ ] <EOL> defs = [ ] <EOL> sub_connections = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> for sc in sub_connections : <EOL> save_defs . append ( state . releasing ( sc ) ) <EOL> yield defer . DeferredList ( save_defs ) <EOL> for sc in sub_connections : <EOL> provider = self . getProvider ( sc . provider_nsa ) <EOL> header = nsa . NSIHeader ( self . nsa_ . urn ( ) , sc . provider_nsa , security_attributes = header . security_attributes ) <EOL> d = provider . release ( header , sc . connection_id , request_info ) <EOL> d . addErrback ( _logErrorResponse , connection_id , sc . provider_nsa , '<STR_LIT>' ) <EOL> defs . append ( d ) <EOL> yield defer . DeferredList ( save_defs , consumeErrors = True ) <EOL> results = yield defer . DeferredList ( defs , consumeErrors = True ) <EOL> successes = [ r [ <NUM_LIT:0> ] for r in results ] <EOL> if all ( successes ) : <EOL> defer . returnValue ( connection_id ) <EOL> else : <EOL> n_success = sum ( [ <NUM_LIT:1> for s in successes if s ] ) <EOL> log . msg ( '<STR_LIT>' % ( conn . connection_id , n_success , len ( defs ) ) , system = LOG_SYSTEM ) <EOL> provider_urns = [ sc . provider_nsa for sc in sub_connections ] <EOL> raise _createAggregateException ( connection_id , '<STR_LIT>' , results , provider_urns , error . ConnectionError ) <EOL> @ defer . inlineCallbacks <EOL> def terminate ( self , header , connection_id , request_info = None ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( header . requester_nsa , connection_id ) , system = LOG_SYSTEM ) <EOL> conn = yield self . getConnection ( connection_id ) <EOL> if conn . lifecycle_state == state . TERMINATED : <EOL> defer . returnValue ( connection_id ) <EOL> yield state . terminating ( conn ) <EOL> defs = [ ] <EOL> sub_connections = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> for sc in sub_connections : <EOL> provider = self . getProvider ( sc . provider_nsa ) <EOL> header = nsa . NSIHeader ( self . nsa_ . urn ( ) , sc . provider_nsa , security_attributes = header . security_attributes ) <EOL> d = provider . terminate ( header , sc . connection_id , request_info ) <EOL> d . addErrback ( _logErrorResponse , connection_id , sc . provider_nsa , '<STR_LIT>' ) <EOL> defs . append ( d ) <EOL> results = yield defer . DeferredList ( defs , consumeErrors = True ) <EOL> successes = [ r [ <NUM_LIT:0> ] for r in results ] <EOL> if all ( successes ) : <EOL> log . msg ( '<STR_LIT>' % ( conn . connection_id , len ( defs ) ) , system = LOG_SYSTEM ) <EOL> defer . returnValue ( connection_id ) <EOL> else : <EOL> n_success = sum ( [ <NUM_LIT:1> for s in successes if s ] ) <EOL> log . msg ( '<STR_LIT>' % ( conn . connection_id , n_success , len ( defs ) ) , system = LOG_SYSTEM ) <EOL> provider_urns = [ sc . provider_nsa for sc in sub_connections ] <EOL> raise _createAggregateException ( connection_id , '<STR_LIT>' , results , provider_urns , error . ConnectionError ) <EOL> @ defer . inlineCallbacks <EOL> def querySummary ( self , header , connection_ids = None , global_reservation_ids = None , request_info = None ) : <EOL> log . msg ( '<STR_LIT>' % ( header . requester_nsa , connection_ids , global_reservation_ids ) , system = LOG_SYSTEM ) <EOL> try : <EOL> if connection_ids : <EOL> conns = yield database . ServiceConnection . find ( where = [ '<STR_LIT>' , header . requester_nsa , tuple ( connection_ids ) ] ) <EOL> elif global_reservation_ids : <EOL> conns = yield database . ServiceConnection . find ( where = [ '<STR_LIT>' , header . requester_nsa , tuple ( global_reservation_ids ) ] ) <EOL> else : <EOL> conns = yield database . ServiceConnection . find ( where = [ '<STR_LIT>' , header . requester_nsa ] ) <EOL> reservations = [ ] <EOL> for c in conns : <EOL> source_stp = nsa . STP ( c . source_network , c . source_port , c . source_label ) <EOL> dest_stp = nsa . STP ( c . dest_network , c . dest_port , c . dest_label ) <EOL> schedule = nsa . Schedule ( c . start_time , c . end_time ) <EOL> sd = nsa . Point2PointService ( source_stp , dest_stp , c . bandwidth , cnt . BIDIRECTIONAL , False , None ) <EOL> criteria = nsa . QueryCriteria ( c . revision , schedule , sd ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( c . id ) <EOL> if len ( sub_conns ) == <NUM_LIT:0> : <EOL> data_plane_status = ( False , <NUM_LIT:0> , False ) <EOL> else : <EOL> aggr_active = all ( [ sc . data_plane_active for sc in sub_conns ] ) <EOL> aggr_version = max ( [ sc . data_plane_version for sc in sub_conns ] ) or <NUM_LIT:0> <EOL> aggr_consistent = all ( [ sc . data_plane_consistent for sc in sub_conns ] ) <EOL> data_plane_status = ( aggr_active , aggr_version , aggr_consistent ) <EOL> states = ( c . reservation_state , c . provision_state , c . lifecycle_state , data_plane_status ) <EOL> notification_id = self . getNotificationId ( ) <EOL> result_id = <NUM_LIT:0> <EOL> ci = nsa . ConnectionInfo ( c . connection_id , c . global_reservation_id , c . description , cnt . EVTS_AGOLE , [ criteria ] , <EOL> self . nsa_ . urn ( ) , c . requester_nsa , states , notification_id , result_id ) <EOL> reservations . append ( ci ) <EOL> self . parent_requester . querySummaryConfirmed ( header , reservations ) <EOL> except Exception as e : <EOL> log . msg ( '<STR_LIT>' % str ( e ) , system = LOG_SYSTEM ) <EOL> raise e <EOL> @ defer . inlineCallbacks <EOL> def queryRecursive ( self , header , connection_ids , global_reservation_ids , request_info = None ) : <EOL> log . msg ( '<STR_LIT>' % ( header . requester_nsa , connection_ids , global_reservation_ids ) , system = LOG_SYSTEM ) <EOL> if global_reservation_ids : <EOL> raise error . UnsupportedParameter ( "<STR_LIT>" ) <EOL> if not connection_ids : <EOL> raise error . MissingParameterError ( "<STR_LIT>" ) <EOL> if len ( connection_ids ) > <NUM_LIT:1> : <EOL> raise error . UnsupportedParameter ( "<STR_LIT>" ) <EOL> try : <EOL> conn = yield self . getConnection ( connection_ids [ <NUM_LIT:0> ] ) <EOL> sub_connections = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> cb_header = nsa . NSIHeader ( header . requester_nsa , self . nsa_ . urn ( ) , header . correlation_id , reply_to = header . reply_to , security_attributes = header . security_attributes ) <EOL> self . query_requests [ cb_header . correlation_id ] = ( cb_header , conn , len ( sub_connections ) ) <EOL> defs = [ ] <EOL> for sc in sub_connections : <EOL> provider = self . getProvider ( sc . provider_nsa ) <EOL> sch = nsa . NSIHeader ( self . nsa_ . urn ( ) , sc . provider_nsa , security_attributes = header . security_attributes ) <EOL> d = provider . queryRecursive ( sch , [ sc . connection_id ] , None , request_info ) <EOL> d . addErrback ( _logErrorResponse , '<STR_LIT>' , sc . provider_nsa , '<STR_LIT>' ) <EOL> defs . append ( d ) <EOL> self . query_calls [ sch . correlation_id ] = ( cb_header . correlation_id , None ) <EOL> results = yield defer . DeferredList ( defs , consumeErrors = True ) <EOL> successes = [ r [ <NUM_LIT:0> ] for r in results ] <EOL> if all ( successes ) : <EOL> defer . returnValue ( None ) <EOL> else : <EOL> n_success = sum ( [ <NUM_LIT:1> for s in successes if s ] ) <EOL> log . msg ( '<STR_LIT>' % ( n_success , len ( defs ) ) , system = LOG_SYSTEM ) <EOL> provider_urns = [ sc . provider_nsa for sc in sub_connections ] <EOL> raise _createAggregateException ( '<STR_LIT>' , '<STR_LIT>' , results , provider_urns , error . ConnectionError ) <EOL> except ValueError as e : <EOL> log . msg ( '<STR_LIT>' % str ( e ) , system = LOG_SYSTEM ) <EOL> raise e <EOL> @ defer . inlineCallbacks <EOL> def queryRecursiveConfirmed ( self , header , sub_result ) : <EOL> @ defer . inlineCallbacks <EOL> def createCQR ( conn , children = None ) : <EOL> c = conn <EOL> source_stp = nsa . STP ( c . source_network , c . source_port , c . source_label ) <EOL> dest_stp = nsa . STP ( c . dest_network , c . dest_port , c . dest_label ) <EOL> schedule = nsa . Schedule ( c . start_time , c . end_time ) <EOL> sd = nsa . Point2PointService ( source_stp , dest_stp , c . bandwidth , cnt . BIDIRECTIONAL , False , None ) <EOL> criteria = nsa . QueryCriteria ( c . revision , schedule , sd , children ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( c . id ) <EOL> if len ( sub_conns ) == <NUM_LIT:0> : <EOL> data_plane_status = ( False , <NUM_LIT:0> , False ) <EOL> else : <EOL> aggr_active = all ( [ sc . data_plane_active for sc in sub_conns ] ) <EOL> aggr_version = max ( [ sc . data_plane_version for sc in sub_conns ] ) or <NUM_LIT:0> <EOL> aggr_consistent = all ( [ sc . data_plane_consistent for sc in sub_conns ] ) <EOL> data_plane_status = ( aggr_active , aggr_version , aggr_consistent ) <EOL> states = ( c . reservation_state , c . provision_state , c . lifecycle_state , data_plane_status ) <EOL> notification_id = self . getNotificationId ( ) <EOL> result_id = notification_id <EOL> ci = nsa . ConnectionInfo ( c . connection_id , c . global_reservation_id , c . description , cnt . EVTS_AGOLE , [ criteria ] , <EOL> self . nsa_ . urn ( ) , c . requester_nsa , states , notification_id , result_id ) <EOL> defer . returnValue ( ci ) <EOL> log . msg ( '<STR_LIT>' % ( header . provider_nsa , ) , system = LOG_SYSTEM ) <EOL> if not header . correlation_id in self . query_calls : <EOL> log . msg ( '<STR_LIT>' % header . correlation_id , system = LOG_SYSTEM ) <EOL> return <EOL> cbh_correlation_id , res = self . query_calls [ header . correlation_id ] <EOL> if res : <EOL> log . msg ( '<STR_LIT>' % header . correlation_id , system = LOG_SYSTEM ) <EOL> return <EOL> self . query_calls [ header . correlation_id ] = cbh_correlation_id , sub_result <EOL> cb_header , conn , count = self . query_requests [ cbh_correlation_id ] <EOL> scr = [ res [ <NUM_LIT:0> ] for cbhci , res in self . query_calls . values ( ) if res and cbhci == cbh_correlation_id ] <EOL> if len ( scr ) == count : <EOL> self . query_requests . pop ( cbh_correlation_id ) <EOL> for k , v in self . query_calls . items ( ) : <EOL> cbhci , res = v <EOL> if cbhci == cbh_correlation_id : <EOL> self . query_calls . pop ( k ) <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> results = yield createCQR ( conn , scr ) <EOL> self . parent_requester . queryRecursiveConfirmed ( cb_header , [ results ] ) <EOL> else : <EOL> log . msg ( '<STR_LIT>' % ( count - len ( scr ) , count ) , system = LOG_SYSTEM ) <EOL> def queryNotification ( self , header , connection_id , start_notification , end_notification ) : <EOL> log . msg ( '<STR_LIT>' % ( header . requester_nsa , connection_id , start_notification , end_notification ) , system = LOG_SYSTEM ) <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def reserveConfirmed ( self , header , connection_id , global_reservation_id , description , criteria ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( header . provider_nsa , connection_id ) , system = LOG_SYSTEM ) <EOL> if not header . correlation_id in self . reservations : <EOL> msg = '<STR_LIT>' % ( header . correlation_id , connection_id , header . provider_nsa ) <EOL> log . msg ( msg , system = LOG_SYSTEM ) <EOL> raise error . ConnectionNonExistentError ( msg ) <EOL> org_provider_nsa = self . reservations [ header . correlation_id ] [ '<STR_LIT>' ] <EOL> if header . provider_nsa != org_provider_nsa : <EOL> log . msg ( '<STR_LIT>' % ( header . provider_nsa , org_provider_nsa ) , system = LOG_SYSTEM ) <EOL> raise error . SecurityError ( '<STR_LIT>' ) <EOL> resv_info = self . reservations . pop ( header . correlation_id ) <EOL> sd = criteria . service_def <EOL> if sd . source_stp . network != resv_info [ '<STR_LIT>' ] : <EOL> log . msg ( '<STR_LIT>' % ( resv_info [ '<STR_LIT>' ] , sd . source_stp . network ) , system = LOG_SYSTEM ) <EOL> if sd . source_stp . port != resv_info [ '<STR_LIT>' ] : <EOL> log . msg ( '<STR_LIT>' % ( resv_info [ '<STR_LIT>' ] , sd . source_stp . port ) , system = LOG_SYSTEM ) <EOL> if sd . dest_stp . network != resv_info [ '<STR_LIT>' ] : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> if sd . dest_stp . port != resv_info [ '<STR_LIT>' ] : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> if not sd . source_stp . label . singleValue ( ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> if not sd . dest_stp . label . singleValue ( ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> db_start_time = criteria . schedule . start_time . isoformat ( ) if criteria . schedule . start_time is not None else None <EOL> db_end_time = criteria . schedule . end_time . isoformat ( ) if criteria . schedule . end_time is not None else None <EOL> sc = database . SubConnection ( provider_nsa = org_provider_nsa , connection_id = connection_id , local_link = False , <EOL> revision = criteria . revision , service_connection_id = resv_info [ '<STR_LIT>' ] , order_id = resv_info [ '<STR_LIT>' ] , <EOL> global_reservation_id = global_reservation_id , description = description , <EOL> reservation_state = state . RESERVE_HELD , provision_state = state . RELEASED , lifecycle_state = state . CREATED , data_plane_active = False , <EOL> source_network = sd . source_stp . network , source_port = sd . source_stp . port , source_label = sd . source_stp . label , <EOL> dest_network = sd . dest_stp . network , dest_port = sd . dest_stp . port , dest_label = sd . dest_stp . label , <EOL> start_time = db_start_time , end_time = db_end_time , bandwidth = sd . capacity ) <EOL> yield sc . save ( ) <EOL> conn = yield self . getConnectionByKey ( sc . service_connection_id ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> if sc . order_id == <NUM_LIT:0> : <EOL> conn . source_label = sd . source_stp . label <EOL> if sc . order_id == len ( sub_conns ) - <NUM_LIT:1> : <EOL> conn . dest_label = sd . dest_stp . label <EOL> yield conn . save ( ) <EOL> outstanding_calls = [ v for v in self . reservations . values ( ) if v . get ( '<STR_LIT>' ) == resv_info [ '<STR_LIT>' ] ] <EOL> if len ( outstanding_calls ) > <NUM_LIT:0> : <EOL> log . msg ( '<STR_LIT>' % ( conn . connection_id , len ( outstanding_calls ) ) , system = LOG_SYSTEM ) <EOL> return <EOL> if all ( [ sc . reservation_state == state . RESERVE_HELD for sc in sub_conns ] ) and conn . reservation_state != state . RESERVE_HELD : <EOL> log . msg ( '<STR_LIT>' % ( conn . connection_id ) , system = LOG_SYSTEM ) <EOL> yield state . reserveHeld ( conn ) <EOL> header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) ) <EOL> source_stp = nsa . STP ( conn . source_network , conn . source_port , conn . source_label ) <EOL> dest_stp = nsa . STP ( conn . dest_network , conn . dest_port , conn . dest_label ) <EOL> schedule = nsa . Schedule ( conn . start_time , conn . end_time ) <EOL> sd = nsa . Point2PointService ( source_stp , dest_stp , conn . bandwidth , cnt . BIDIRECTIONAL , False , None ) <EOL> conn_criteria = nsa . Criteria ( conn . revision , schedule , sd ) <EOL> self . parent_requester . reserveConfirmed ( header , conn . connection_id , conn . global_reservation_id , conn . description , conn_criteria ) <EOL> else : <EOL> log . msg ( '<STR_LIT>' % ( conn . connection_id ) , system = LOG_SYSTEM ) <EOL> @ defer . inlineCallbacks <EOL> def reserveFailed ( self , header , connection_id , connection_states , err ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( header . provider_nsa , connection_id , err ) , system = LOG_SYSTEM ) <EOL> if not header . correlation_id in self . reservations : <EOL> msg = '<STR_LIT>' % ( header . correlation_id , connection_id , header . provider_nsa ) <EOL> log . msg ( msg , system = LOG_SYSTEM ) <EOL> raise error . ConnectionNonExistentError ( msg ) <EOL> org_provider_nsa = self . reservations [ header . correlation_id ] [ '<STR_LIT>' ] <EOL> if header . provider_nsa != org_provider_nsa : <EOL> log . msg ( '<STR_LIT>' % ( header . provider_nsa , org_provider_nsa ) , system = LOG_SYSTEM ) <EOL> raise error . SecurityError ( '<STR_LIT>' ) <EOL> resv_info = self . reservations . pop ( header . correlation_id ) <EOL> service_connection_key = resv_info [ '<STR_LIT>' ] <EOL> conn = yield self . getConnectionByKey ( service_connection_key ) <EOL> if conn . reservation_state != state . RESERVE_FAILED : <EOL> yield state . reserveFailed ( conn ) <EOL> header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) ) <EOL> self . parent_requester . reserveFailed ( header , conn . connection_id , connection_states , err ) <EOL> @ defer . inlineCallbacks <EOL> def reserveCommitConfirmed ( self , header , connection_id ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( connection_id , header . provider_nsa ) , system = LOG_SYSTEM ) <EOL> sub_connection = yield self . getSubConnection ( header . provider_nsa , connection_id ) <EOL> sub_connection . reservation_state = state . RESERVE_START <EOL> yield sub_connection . save ( ) <EOL> conn = yield self . getConnectionByKey ( sub_connection . service_connection_id ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> if all ( [ sc . reservation_state == state . RESERVE_START for sc in sub_conns ] ) and conn . reservation_state != state . RESERVE_START : <EOL> yield state . reserved ( conn ) <EOL> header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) ) <EOL> self . parent_requester . reserveCommitConfirmed ( header , conn . connection_id ) <EOL> self . plugin . connectionCreated ( conn ) <EOL> @ defer . inlineCallbacks <EOL> def reserveAbortConfirmed ( self , header , connection_id ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( connection_id , header . provider_nsa ) , system = LOG_SYSTEM ) <EOL> sub_connection = yield self . getSubConnection ( header . provider_nsa , connection_id ) <EOL> sub_connection . reservation_state = state . RESERVE_START <EOL> yield sub_connection . save ( ) <EOL> conn = yield self . getConnectionByKey ( sub_connection . service_connection_id ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> if all ( [ sc . reservation_state == state . RESERVE_START for sc in sub_conns ] ) and conn . reservation_state != state . RESERVE_START : <EOL> yield state . reserved ( conn ) <EOL> header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) ) <EOL> self . parent_requester . reserveAbortConfirmed ( header , conn . connection_id ) <EOL> @ defer . inlineCallbacks <EOL> def provisionConfirmed ( self , header , connection_id ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( connection_id , header . provider_nsa ) , system = LOG_SYSTEM ) <EOL> sub_connection = yield self . getSubConnection ( header . provider_nsa , connection_id ) <EOL> yield state . provisioned ( sub_connection ) <EOL> conn = yield self . getConnectionByKey ( sub_connection . service_connection_id ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> if all ( [ sc . provision_state == state . PROVISIONED for sc in sub_conns ] ) and conn . provision_state != state . PROVISIONED : <EOL> yield state . provisioned ( conn ) <EOL> req_header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) ) <EOL> self . parent_requester . provisionConfirmed ( req_header , conn . connection_id ) <EOL> @ defer . inlineCallbacks <EOL> def releaseConfirmed ( self , header , connection_id ) : <EOL> log . msg ( '<STR_LIT>' , system = LOG_SYSTEM ) <EOL> log . msg ( '<STR_LIT>' % ( connection_id , header . provider_nsa ) , system = LOG_SYSTEM ) <EOL> sub_connection = yield self . getSubConnection ( header . provider_nsa , connection_id ) <EOL> yield state . released ( sub_connection ) <EOL> conn = yield self . getConnectionByKey ( sub_connection . service_connection_id ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> if all ( [ sc . provision_state == state . RELEASED for sc in sub_conns ] ) and conn . provision_state != state . RELEASED : <EOL> yield state . released ( conn ) <EOL> req_header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) ) <EOL> self . parent_requester . releaseConfirmed ( req_header , conn . connection_id ) <EOL> @ defer . inlineCallbacks <EOL> def terminateConfirmed ( self , header , connection_id ) : <EOL> sub_connection = yield self . getSubConnection ( header . provider_nsa , connection_id ) <EOL> sub_connection . lifecycle_state = state . TERMINATED <EOL> yield sub_connection . save ( ) <EOL> conn = yield self . getConnectionByKey ( sub_connection . service_connection_id ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> if all ( [ sc . lifecycle_state == state . TERMINATED for sc in sub_conns ] ) and conn . lifecycle_state != state . TERMINATED : <EOL> yield state . terminated ( conn ) <EOL> header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) ) <EOL> self . parent_requester . terminateConfirmed ( header , conn . connection_id ) <EOL> self . plugin . connectionTerminated ( conn ) <EOL> def doTimeout ( self , conn , timeout_value , org_connection_id , org_nsa ) : <EOL> header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) , reply_to = conn . requester_url ) <EOL> now = datetime . datetime . utcnow ( ) <EOL> self . parent_requester . reserveTimeout ( header , conn . connection_id , <NUM_LIT:0> , now , timeout_value , org_connection_id , org_nsa ) <EOL> def doErrorEvent ( self , conn , notification_id , event , info , service_ex = None ) : <EOL> header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) , reply_to = conn . requester_url ) <EOL> now = datetime . datetime . utcnow ( ) <EOL> self . parent_requester . errorEvent ( header , conn . connection_id , notification_id , now , event , info , service_ex ) <EOL> @ defer . inlineCallbacks <EOL> def reserveTimeout ( self , header , connection_id , notification_id , timestamp , timeout_value , org_connection_id , org_nsa ) : <EOL> log . msg ( "<STR_LIT>" % ( header . provider_nsa , connection_id ) , system = LOG_SYSTEM ) <EOL> sub_conn = yield self . getSubConnection ( header . provider_nsa , connection_id ) <EOL> yield state . reserveTimeout ( sub_conn ) <EOL> conn = yield self . getConnectionByKey ( sub_conn . service_connection_id ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> if conn . reservation_state == state . RESERVE_FAILED : <EOL> log . msg ( "<STR_LIT>" % conn . connection_id , system = LOG_SYSTEM ) <EOL> elif sum ( [ <NUM_LIT:1> if sc . reservation_state == state . RESERVE_TIMEOUT else <NUM_LIT:0> for sc in sub_conns ] ) == <NUM_LIT:1> : <EOL> log . msg ( "<STR_LIT>" % conn . connection_id , system = LOG_SYSTEM ) <EOL> header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) , reply_to = conn . requester_url ) <EOL> self . parent_requester . reserveTimeout ( header , conn . connection_id , notification_id , timestamp , timeout_value , org_connection_id , org_nsa ) <EOL> else : <EOL> log . msg ( "<STR_LIT>" % conn . connection_id , system = LOG_SYSTEM ) <EOL> @ defer . inlineCallbacks <EOL> def dataPlaneStateChange ( self , header , connection_id , notification_id , timestamp , dps ) : <EOL> active , version , consistent = dps <EOL> log . msg ( "<STR_LIT>" % ( connection_id , active , version , consistent ) , system = LOG_SYSTEM ) <EOL> sub_conn = yield self . getSubConnection ( header . provider_nsa , connection_id ) <EOL> sub_conn . data_plane_active = active <EOL> sub_conn . data_plane_version = version <EOL> sub_conn . data_plane_consistent = consistent <EOL> yield sub_conn . save ( ) <EOL> conn = yield self . getConnectionByKey ( sub_conn . service_connection_id ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> actives = [ sc . data_plane_active for sc in sub_conns ] <EOL> aggr_active = all ( actives ) <EOL> aggr_version = max ( [ sc . data_plane_version for sc in sub_conns ] ) <EOL> aggr_consistent = all ( [ sc . data_plane_consistent for sc in sub_conns ] ) and all ( [ a == actives [ <NUM_LIT:0> ] for a in actives ] ) <EOL> header = nsa . NSIHeader ( conn . requester_nsa , self . nsa_ . urn ( ) , reply_to = conn . requester_url ) <EOL> now = datetime . datetime . utcnow ( ) <EOL> data_plane_status = ( aggr_active , aggr_version , aggr_consistent ) <EOL> log . msg ( "<STR_LIT>" % ( conn . connection_id , aggr_active , aggr_version , aggr_consistent ) , system = LOG_SYSTEM ) <EOL> self . parent_requester . dataPlaneStateChange ( header , conn . connection_id , <NUM_LIT:0> , now , data_plane_status ) <EOL> def error ( self , header , nsa_id , connection_id , service_type , error_id , text , variables , child_ex ) : <EOL> log . msg ( "<STR_LIT>" % ( connection_id , nsa_id , text , str ( variables ) ) , system = LOG_SYSTEM ) <EOL> if header . provider_nsa != nsa_id : <EOL> log . msg ( "<STR_LIT>" % ( header . provider_nsa , nsa_id ) , system = LOG_SYSTEM ) <EOL> return <EOL> self . parent_requester . error ( header , nsa_id , connection_id , service_type , error_id , text , variables , None ) <EOL> @ defer . inlineCallbacks <EOL> def errorEvent ( self , header , connection_id , notification_id , timestamp , event , info , service_ex ) : <EOL> sub_conn = yield self . getSubConnection ( header . provider_nsa , connection_id ) <EOL> conn = yield self . getConnectionByKey ( sub_conn . service_connection_id ) <EOL> sub_conns = yield self . getSubConnectionsByConnectionKey ( conn . id ) <EOL> if len ( sub_conns ) == <NUM_LIT:1> : <EOL> log . msg ( "<STR_LIT>" % conn . connection_id , system = LOG_SYSTEM ) <EOL> self . doErrorEvent ( conn , notification_id , event , info , service_ex ) <EOL> else : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def querySummaryConfirmed ( self , header , summary_results ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def queryNotificationFailed ( self , header , service_exception ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) </s>
