def test_connection_info(): prefix = Prefix(Subsystems.CSW, "MyComp") info = ConnectionInfo.make(prefix, ComponentType.Service, ConnectionType.HttpType) json = info.to_json() newInfo = ConnectionInfo.schema().loads(json) assert (newInfo == info)
def _registerWithLocationService(prefix: Prefix, port: int): log.debug("Registering with location service using port " + str(port)) locationService = LocationService() connection = ConnectionInfo.make(prefix, ComponentType.Service, ConnectionType.HttpType) atexit.register(locationService.unregister, connection) # locationService.unregister(connection) locationService.register( HttpRegistration(connection, port, "/post-endpoint"))
def __init__(self): """ Events are posted to Redis. This is internal class used to access Redis. """ prefix = Prefix(Subsystems.CSW, "EventServer") conn = ConnectionInfo.make(prefix, ComponentType.Service, ConnectionType.TcpType) loc = LocationService().find(conn) uri = urlparse(loc.uri) sentinel = Sentinel([(uri.hostname, uri.port)], socket_timeout=0.1) self.__redis = sentinel.master_for('eventServer', socket_timeout=0.1) self.__redis_pubsub = self.__redis.pubsub()
def test_location_service(): locationService = LocationService() # List all registered connections print("\nAll Locations:") for i in locationService.list(): print(" " + str(i)) # List the registered HCDs print("\nHCDs:") for i in locationService.list(ComponentType.HCD): print(" " + str(i)) # List the registered http connections print("\nConnections on 192.168.178.78") for i in locationService.list("192.168.178.78"): print(" " + str(i)) # List the registered http connections print("\nHTTP connections:") for i in locationService.list(ConnectionType.HttpType): print(" " + str(i)) # Register a connection connection = ConnectionInfo("csw.myComp", ComponentType.Service.value, ConnectionType.HttpType.value) reg = HttpRegistration(connection, 8080, path="myservice/test") regResult = locationService.register(reg) print("\nRegistration result: " + str(regResult)) # Find a connection location1 = locationService.find(connection) print("location1 = " + str(location1)) # Resolve a connection (waiting if needed) location2 = locationService.resolve(connection) print("location2 = " + str(location2)) # Unregister unregResult = locationService.unregister(connection) print("\nUnregister result: " + str(unregResult))
def test_location_service_models(self): testDir = pathlib.Path(__file__).parent.absolute() with open(f"{testDir}/location-models.json") as json_file: data = json.load(json_file) for p in data['ComponentType']: assert (ComponentType[p].name == p) for p in data['Connection']: connectionInfo = ConnectionInfo.from_dict(p) self.log.debug(f"Connection: {connectionInfo}") assert (connectionInfo.to_dict() == p) for p in data['Registration']: regType = p['_type'] if regType == "HttpRegistration": registration = HttpRegistration.from_dict(p) elif regType == "TcpRegistration": registration = TcpRegistration.from_dict(p) elif regType == "AkkaRegistration": registration = AkkaRegistration.from_dict(p) assert (registration.to_dict() == p) for p in data['ComponentId']: componentId = ComponentId.from_dict(p) self.log.debug(f"ComponentId: {componentId}") assert (componentId.to_dict() == p) for p in data['Prefix']: prefix = Prefix.from_str(p) assert (str(prefix) == p) for p in data['ConnectionType']: assert (ConnectionType(p).value == p) for p in data['Subsystem']: assert (Subsystems[p].name == p) for p in data['Location']: locType = p['_type'] if locType == "AkkaLocation": loc = AkkaLocation.from_dict(p) elif locType == "HttpLocation": loc = HttpLocation.from_dict(p) elif locType == "TcpLocation": loc = TcpLocation.from_dict(p) self.log.debug(f"Location: {loc}") assert (loc.to_dict() == p)
def test_location_service(): log = structlog.get_logger() locationService = LocationService() # List all registered connections log.debug("\nAll Locations:") allLocations = locationService.list() for i in allLocations: log.debug(" " + str(i)) # Check that the standard CSW services were found assert [ x for x in allLocations if x.connection.prefix == 'CSW.AAS' and x.connection.componentType == 'Service' ] assert [ x for x in allLocations if x.connection.prefix == 'CSW.AlarmServer' and x.connection.componentType == 'Service' ] assert [ x for x in allLocations if x.connection.prefix == 'CSW.DatabaseServer' and x.connection.componentType == 'Service' ] assert [ x for x in allLocations if x.connection.prefix == 'CSW.EventServer' and x.connection.componentType == 'Service' ] assert [ x for x in allLocations if x.connection.prefix == 'CSW.ConfigServer' and x.connection.componentType == 'Service' ] # List the registered HCDs log.debug("\nHCDs:") for i in locationService.list(ComponentType.HCD): log.debug(" " + str(i)) # List the registered http connections log.debug("\nConnections on 192.168.178.78") for i in locationService.list("192.168.178.78"): log.debug(" " + str(i)) # List the registered http connections log.debug("\nHTTP connections:") httpServices = locationService.list(ConnectionType.HttpType) for i in httpServices: log.debug(" " + str(i)) assert [ x for x in httpServices if x.connection.prefix == 'CSW.AAS' and x.connection.componentType == 'Service' ] assert not [ x for x in httpServices if x.connection.prefix == 'CSW.AlarmServer' and x.connection.componentType == 'Service' ] assert not [ x for x in httpServices if x.connection.prefix == 'CSW.DatabaseServer' and x.connection.componentType == 'Service' ] assert not [ x for x in httpServices if x.connection.prefix == 'CSW.EventServer' and x.connection.componentType == 'Service' ] assert [ x for x in httpServices if x.connection.prefix == 'CSW.ConfigServer' and x.connection.componentType == 'Service' ] # Register a connection prefix = Prefix(Subsystems.CSW, "myComp") connection = ConnectionInfo.make(prefix, ComponentType.Service, ConnectionType.HttpType) reg = HttpRegistration(connection, 8080, path="myservice/test") regResult = locationService.register(reg) log.debug("\nRegistration result: " + str(regResult)) assert regResult.componentType == ComponentType.Service.value assert regResult.prefix == 'CSW.myComp' assert regResult.connectionType == ConnectionType.HttpType.value # Find a connection location1 = locationService.find(connection) log.debug("location1 = " + str(location1)) assert location1.connection.componentType == ComponentType.Service.value assert location1.connection.prefix == 'CSW.myComp' assert location1.connection.connectionType == ConnectionType.HttpType.value # Resolve a connection (waiting if needed) location2 = locationService.resolve(connection) log.debug("location2 = " + str(location2)) assert location1 == location2 # Unregister unregResult = locationService.unregister(connection) log.debug("\nUnregister result: " + str(unregResult)) assert not locationService.find(connection)