def create_member_objects(self, regh, keyspec, msg, user_data): """This function implements the data member APIs to create, update and read objects """ logger.info("Creating member data objects !!!") id = 1 for id in range(1, 10): emp = RwDtsToyTaskletYang.Employee() emp.name = 'jdoe' + str(id) emp.age = 30 + id emp.phone = '978-863-00' + str(id) emp.ssn = '123-45-000' + str(id) path = '/rw-dts-toy-tasklet:employee[rw-dts-toy-tasklet:name=\'jdoe' + str(id) + '\']' status, ks = self.apih.keyspec_from_xpath(path) logger.debug("keyspec_from_xpath returned %s for path %s", status, ks) status = self.mbdreg.create_element_keyspec(ks, emp.to_pbcm()) logger.debug("create_element_keyspec returned %s for path %s", status, ks) #Update an element path = '/rw-dts-toy-tasklet:employee[rw-dts-toy-tasklet:name=\'jdoe9\']' status, ks = self.apih.keyspec_from_xpath(path) logger.debug("keyspec_from_xpath returned %s for path %s", status, ks) emp = RwDtsToyTaskletYang.Employee() emp.name = 'jdoe9' + str(id) emp.age = 41 emp.phone = '978-863-099' emp.ssn = '123-45-0099' status = self.mbdreg.update_element_keyspec(ks, emp.to_pbcm(), RwDts.XactFlag.REPLACE) logger.info("Updated the object with key = %s status = %s", path, status) # Now read it back status, out_ks, pbcm = self.mbdreg.get_element_keyspec(ks) logger.info("Get returned status=%s, pbcm=%s out_ks = %s", status, pbcm, out_ks) employee = RwDtsToyTaskletYang.Employee.from_pbcm(pbcm) logger.info("Read record is %s", employee) # Now read with xpath status, pbcm,out_ks = self.mbdreg.get_element_xpath('C,/rw-dts-toy-tasklet:employee[rw-dts-toy-tasklet:name=\'jdoe8\']') logger.info("Get returned using xpath status=%s pbcm=%s out_ks = %s", status, pbcm, out_ks) employee = RwDtsToyTaskletYang.Employee.from_pbcm(pbcm) logger.info("Read record using xpath is %s", employee) # Get a cursor and walk the list cursor = self.mbdreg.get_current_cursor() msg, ks = self.mbdreg.get_next_element(cursor) while msg is not None: employee = RwDtsToyTaskletYang.Employee.from_pbcm(msg) logger.info("Read record using get next api %s", employee) msg, ks = self.mbdreg.get_next_element(cursor)
def main(self): self.log.debug('tasklet main function running') xpath = '/rw-dts-toy-tasklet:a-container' ret = toyyang.AContainer() ret.a_string = 'pub' events = [asyncio.Event(loop=self.loop) for _ in range(2)] @asyncio.coroutine def on_ready(*args): yield from asyncio.sleep(1, loop=self.loop) events[0].set() @asyncio.coroutine def on_prepare(xact_info, *args): xact_info.respond_xpath(rwdts.XactRspCode.ACK, xpath, ret) handler = rift.tasklets.DTS.RegistrationHandler(on_ready=on_ready, on_prepare=on_prepare) self.reg = yield from self._dts.register(xpath, flags=rwdts.Flag.PUBLISHER, handler=handler) yield from events[1].wait() # Normally this wouldn't be done, but all the printing of ticks is annoying self.log.debug('tasklet main finished')
def dts_cfg_prepare_cb(self, apih, xact, xactinfo, keyspec, msg, user_data): logger.info("**** DTS cfg prepare is called *****") logger.debug("apih is %s", apih) logger.debug("keyspec is %s", keyspec) logger.debug("msg is %s", msg) logger.debug("xactinfo is %s", xactinfo) logger.debug("userdata is %s", user_data) #Create a company object and return o/p company = RwDtsToyTaskletYang.Company() company.name = 'riftio' company.profile.industry='technology' company.profile.revenue = '$100,000,000,000' # Convert the gerneric type to a type that we understand if msg is not None : company = RwDtsToyTaskletYang.Company.from_pbcm(msg) if keyspec is not None : schema = RwDtsToyTaskletYang.Company.schema() pathentry = schema.keyspec_to_entry(keyspec) logger.debug(pathentry) if pathentry is not None: logger.debug("Received keyspec with path key %s", pathentry.key00.name) else: logger.debug("Oh-Oh ---- Could not find path entry") logger.debug("member_register_xpath(cfgpath) returned") return (RwDts.MemberRspCode.ACTION_OK);
def __init__(self, test): logger.debug("Subscriber INIT") self.test = test self.default_regh = None self.ti = test.rwmain.new_tasklet_info("SUBSCRIBER", Subscriber.ready_count) self.apih = RwDts.Api.new(self.ti, RwDtsToyTaskletYang.get_schema(), self.dts_state_change_cb, self)
def start(self): self.log.setLevel(logging.DEBUG) super(DtsPubTestTasklet, self).start() self.schema = toyyang.get_schema() self._dts = rift.tasklets.DTS( self.tasklet_info, self.schema, self.loop, self.on_dts_state_change)
def __init__(self, test): logger.debug("Publisher INIT") self.test = test self.default_regh = None self.ti = test.rwmain.new_tasklet_info("PUBLISHER", 0) self.apih = RwDts.Api.new(self.ti, RwDtsToyTaskletYang.get_schema(), self.dts_state_change_cb, self) # Rift-8338 self.stats = RwDtsToyTaskletYang.StatsData.new() self.stats.payload = "x" * (1024 * 1024 * 8 * 10) self.stats_pbcm = self.stats.to_pbcm()
def __init__(self, test): logger.debug("Publisher INIT") self.test = test self.default_regh = None self.ti = test.rwmain.new_tasklet_info("PUBLISHER", 0) self.apih = RwDts.Api.new(self.ti, RwDtsToyTaskletYang.get_schema(), self.dts_state_change_cb, self) #Rift-8338 self.stats = RwDtsToyTaskletYang.StatsData.new() self.stats.payload = "x" * (1024 * 1024 * 8 * 10) self.stats_pbcm = self.stats.to_pbcm()
def do_instance_start(self, component_handle, instance_handle): """This function is called to start the tasklet operations. Typically DTS initialization is done in this function. In this example a periodic timer is added to the tasklet scheduler. """ logger.debug("RwdtstaskletPython: do_instance_start function called") # Create an instance of DTS API - This object is needed by all DTS # member and query APIs directly or indirectly. # DTS invokes the callback to notify the tasklet that the DTS API instance is ready # for use. foo = Callback() #sub = SubscribeInsideXactExample(self) self.dts_api = RwDts.Api.new(self.taskletinfo, # tasklet object RwDtsToyTaskletYang.get_schema(), # Schema object foo.rwdts_tasklet_state_change_cb, # The callback for DTS state change #sub.rwdts_tasklet_state_change_cb, self) # user data in the callback - in this case self
def dts_prepare_cb(self, xact_info, action, keyspec, msg, user_data): logger.info("**** DTS prepare is called (are regh, self, keyspec, msg, user_data all different or all self?) *****") logger.debug("xact_info is %s", xact_info) logger.debug("action is %s", action) logger.debug("keyspec is %s", keyspec) logger.debug("msg is %s", msg) logger.debug("user_data is %s", user_data) if keyspec is not None : schema = RwDtsToyTaskletYang.Company.schema() pathentry = schema.keyspec_to_entry(keyspec) logger.debug("Received path entry") logger.debug(pathentry) logger.debug(dir(pathentry)) # Convert the gerneric type to a type that we understand xpath = 'C,/rw-dts-toy-tasklet:company[rw-dts-toy-tasklet:name=\'riftio\']' if action == RwDts.QueryAction.READ: xact_info.send_error_xpath(RwTypes.RwStatus.FAILURE, xpath, "PYTHON TASKLET THROWING ERRORERRORERROR dts_prepare_cb") #Create a company object and return o/p company = RwDtsToyTaskletYang.Company() company.name = 'riftio' company.profile.industry='technology' company.profile.revenue = '$100,000,000,000' check_list.append("dts_prepare_cb read " + company.name) xact_info.respond_xpath(RwDts.XactRspCode.ACK, xpath, company.to_pbcm()) else: if msg is not None : company = RwDtsToyTaskletYang.Company.from_pbcm(msg) # We ret async. How does this end? Oh, it's ack above... logger.info("**** DTS dts_prepare_cb done, ret ASYNC *****") return (RwDts.MemberRspCode.ACTION_ASYNC)
def start(self): self.log.setLevel(logging.DEBUG) super(DtsPubTestTasklet, self).start() self.schema = toyyang.get_schema() self._dts = rift.tasklets.DTS(self.tasklet_info, self.schema, self.loop, self.on_dts_state_change)