def register(self, hostpart): if hostpart == "default": hostpart = self.default_address host = hostpart + self.app_id jobj = { k: [ tp.name if isinstance(tp, TriggerProcedure) else tp.__rtypes_metadata__.name for tp in v ] for k, v in self.host_to_typemap[host].iteritems() } jsonobj = json.dumps({ "sim_typemap": jobj, "wire_format": self.wire_format, "app_id": self.app_id, "wait_for_server": self.wait_for_server }) try: self.host_to_connection[host] = Session() if platform.system() == "Java": ignoreJavaSSL() self.logger.info("Using custom HTTPAdapter for Jython") self.host_to_connection[host].mount(host, MyJavaHTTPAdapter()) self.host_to_connection[host].verify = False self.logger.info("Registering with %s", host) resp = requests.put( host, data=jsonobj, headers={"content-type": "application/octet-stream"}) except HTTPError: self.__handle_request_errors(resp) return False except ConnectionError: self.logger.exception("Cannot connect to host.") return False
def __register_app(self, app): self.logger = self.__setup_logger("spacetime@" + self.__appname) self.__host_typemap = {} for address, tpmap in self.__app.__declaration_map__.items(): if address == "default": address = self.__address fulladdress = address + self.__appname if fulladdress not in self.__host_typemap: self.__host_typemap[fulladdress] = tpmap else: for declaration in tpmap: self.__host_typemap[fulladdress].setdefault( declaration, set()).update(set(tpmap[declaration])) self.__default_wire_format = ( self.__app.__special_wire_format__["default"] if "default" in self.__app.__special_wire_format__ else self.__default_wire_format) for host in self.__host_typemap: self.__host_wire_format[host] = ( self.__app.__special_wire_format__[host] if host in self.__app.__special_wire_format__ else self.__default_wire_format) all_types = set() for host in self.__host_typemap: wire_format = self.__host_wire_format[host] jobj = { k: [ tp.name if isinstance(tp, TriggerProcedure) else tp.__rtypes_metadata__.name for tp in v ] for k, v in self.__host_typemap[host].iteritems() } producing, getting, gettingsetting, deleting, setting, tracking, triggers = ( self.__host_typemap[host].setdefault(Modes.Producing, set()), self.__host_typemap[host].setdefault(Modes.Getter, set()), self.__host_typemap[host].setdefault(Modes.GetterSetter, set()), self.__host_typemap[host].setdefault(Modes.Deleter, set()), self.__host_typemap[host].setdefault(Modes.Setter, set()), self.__host_typemap[host].setdefault(Modes.Tracker, set()), self.__host_typemap[host].setdefault(Modes.Triggers, set())) self.__typemap.setdefault(Modes.Producing, set()).update(producing) self.__typemap.setdefault(Modes.Getter, set()).update(getting) self.__typemap.setdefault(Modes.GetterSetter, set()).update(gettingsetting) self.__typemap.setdefault(Modes.Deleter, set()).update(deleting) self.__typemap.setdefault(Modes.Setter, set()).update(setting) self.__typemap.setdefault(Modes.Tracker, set()).update(tracking) all_types_host = tracking.union(producing).union(getting).union( gettingsetting).union(deleting).union(setting) all_types.update(all_types_host) self.__observed_types.update(all_types_host) self.__observed_types_new.update( self.__host_typemap[host][Modes.Tracker].union( self.__host_typemap[host][Modes.Getter]).union( self.__host_typemap[host][Modes.GetterSetter])) self.__observed_types_mod.update( self.__host_typemap[host][Modes.Getter].union( self.__host_typemap[host][Modes.GetterSetter])) jsonobj = cbor.dumps({ "sim_typemap": jobj, "wire_format": wire_format, "app_id": self.__app.app_id }) try: self.__sessions[host] = Session() if platform.system() == 'Java': ignoreJavaSSL() self.logger.info("Using custom HTTPAdapter for Jython") self.__sessions[host].mount(host, MyJavaHTTPAdapter()) self.__sessions[host].verify = False resp = requests.put( host, data=jsonobj, headers={'content-type': "application/octet-stream"}) except HTTPError as exc: self.__handle_request_errors(resp, exc) return False except ConnectionError: self.logger.exception("Cannot connect to host.") self.__disconnected = True return False self.__name2type = dict([(tp.__rtypes_metadata__.name, tp) for tp in all_types]) self.object_store.add_types(all_types) for host in self.__host_typemap: self.__host_to_push_groupkey[host] = set([ self.object_store.get_group_key(tp) for tp in self.__host_typemap[host][Modes.GetterSetter].union( self.__host_typemap[host][Modes.Setter]).union( self.__host_typemap[host][Modes.Producing]).union( self.__host_typemap[host][Modes.Deleter]) ]) return True