def cancel_download(retry): rvi_logger.info("SOTA Callback Server: Cancel download request: retry: %s.", retry) retry_obj = None update_obj = None try: retry_obj = sota.models.Retry.objects.filter(pk=retry)[0] update_obj = retry_obj.ret_update except: rvi_logger.error("SOTA Callback Server: Cancel downlaod request: Cannot access database object: %s", retry) return {u"status": 0} retry_obj.set_status(sota.models.Status.REJECTED) update_obj.set_status(sota.models.Status.REJECTED) sota_logger.info("SOTA Callback Server: Cancel download request: %s.", retry_obj) return {u"status": 0}
def cancel_download(retry): rvi_logger.info( 'SOTA Callback Server: Cancel download request: retry: %s.', retry) retry_obj = None update_obj = None try: retry_obj = sota.models.Retry.objects.filter(pk=retry)[0] update_obj = retry_obj.ret_update except: rvi_logger.error( 'SOTA Callback Server: Cancel downlaod request: Cannot access database object: %s', retry) return {u'status': 0} retry_obj.set_status(sota.models.Status.REJECTED) update_obj.set_status(sota.models.Status.REJECTED) sota_logger.info('SOTA Callback Server: Cancel download request: %s.', retry_obj) return {u'status': 0}
def download_complete(status, retry): rvi_logger.info("SOTA Callback Server: Download complete: retry: %s, status: %s.", retry, status) retry_obj = None update_obj = None try: retry_obj = sota.models.Retry.objects.filter(pk=retry)[0] update_obj = retry_obj.ret_update except: rvi_logger.error("SOTA Callback Server: Download complete: Cannot access database object: %s", retry) return {u"status": 0} if int(status) == 0: retry_obj.set_status(sota.models.Status.SUCCESS) update_obj.set_status(sota.models.Status.SUCCESS) else: retry_obj.set_status(sota.models.Status.FAILED) update_obj.set_status(sota.models.Status.FAILED) sota_logger.info("SOTA Callback Server: Download complete: retry: %s, status: %s.", retry_obj, status) return {u"status": 0}
def download_complete(status, retry): rvi_logger.info( 'SOTA Callback Server: Download complete: retry: %s, status: %s.', retry, status) retry_obj = None update_obj = None try: retry_obj = sota.models.Retry.objects.filter(pk=retry)[0] update_obj = retry_obj.ret_update except: rvi_logger.error( 'SOTA Callback Server: Download complete: Cannot access database object: %s', retry) return {u'status': 0} if int(status) == 0: retry_obj.set_status(sota.models.Status.SUCCESS) update_obj.set_status(sota.models.Status.SUCCESS) else: retry_obj.set_status(sota.models.Status.FAILED) update_obj.set_status(sota.models.Status.FAILED) sota_logger.info( 'SOTA Callback Server: Download complete: retry: %s, status: %s.', retry_obj, status) return {u'status': 0}
def run(self): while True: [package, destination, retry] = package_queue.get() rvi_logger.info( 'SOTA Transmission Server: Sending package %s to %s', package, destination) # accessing database objects retry_obj = None update_obj = None package_obj = None try: retry_obj = sota.models.Retry.objects.filter(pk=retry)[0] update_obj = retry_obj.ret_update package_obj = update_obj.upd_package except Exception as e: rvi_logger.error( 'SOTA Transmission Server: Cannot access database object: %s, Error: %s', retry, e) continue try: f = open(package_obj.pac_file.path) except Exception as e: sota_logger.error( 'SOTA Transmission Server: %s: Cannot open file: %s', retry_obj, package_obj.pac_file.path) retry_obj.set_status(sota.models.Status.FAILED) update_obj.set_status(sota.models.Status.FAILED) continue retry_obj.set_status(sota.models.Status.RUNNING) update_obj.set_status(sota.models.Status.RUNNING) f_stat = os.stat(package_obj.pac_file.path) self.transaction_id += 1 self.service_edge.message(calling_service=self.service_id, service_name=destination + "/start", transaction_id=str(self.transaction_id), timeout=int( retry_obj.get_timeout_epoch()), parameters=[{ u'package': package, u'chunk_size': self.chunk_size, u'total_size': f_stat.st_size }]) index = 0 while True: msg = f.read(self.chunk_size) if msg == "": break sota_logger.debug( 'SOTA Transmission Server: %s: Sending package: %s, chunk: %d, message size: %s', retry_obj, package, index, len(msg)) self.transaction_id += 1 self.service_edge.message( calling_service=self.service_id, service_name=destination + "/chunk", transaction_id=str(self.transaction_id), timeout=int(retry_obj.get_timeout_epoch()), parameters=[{ u'index': index }, { u'msg': base64.b64encode(msg) }]) time.sleep(0.05) index += 1 f.close() time.sleep(1.0) sota_logger.info( 'SOTA Transmission Server: %s: Finishing package: %s', retry_obj, package) self.transaction_id += 1 self.service_edge.message(calling_service=self.service_id, service_name=destination + "/finish", transaction_id=str(self.transaction_id), timeout=int( retry_obj.get_timeout_epoch()), parameters=[{ u'dummy': 0 }])
def run(self): while True: [package, destination, retry] = package_queue.get() rvi_logger.info("SOTA Transmission Server: Sending package %s to %s", package, destination) # accessing database objects retry_obj = None update_obj = None package_obj = None try: retry_obj = sota.models.Retry.objects.filter(pk=retry)[0] update_obj = retry_obj.ret_update package_obj = update_obj.upd_package except Exception as e: rvi_logger.error("SOTA Transmission Server: Cannot access database object: %s, Error: %s", retry, e) continue try: f = open(package_obj.pac_file.path) except Exception as e: sota_logger.error( "SOTA Transmission Server: %s: Cannot open file: %s", retry_obj, package_obj.pac_file.path ) retry_obj.set_status(sota.models.Status.FAILED) update_obj.set_status(sota.models.Status.FAILED) continue retry_obj.set_status(sota.models.Status.RUNNING) update_obj.set_status(sota.models.Status.RUNNING) f_stat = os.stat(package_obj.pac_file.path) self.transaction_id += 1 self.service_edge.message( calling_service=self.service_id, service_name=destination + "/start", transaction_id=str(self.transaction_id), timeout=int(retry_obj.get_timeout_epoch()), parameters=[{u"package": package, u"chunk_size": self.chunk_size, u"total_size": f_stat.st_size}], ) index = 0 while True: msg = f.read(self.chunk_size) if msg == "": break sota_logger.debug( "SOTA Transmission Server: %s: Sending package: %s, chunk: %d, message size: %s", retry_obj, package, index, len(msg), ) self.transaction_id += 1 self.service_edge.message( calling_service=self.service_id, service_name=destination + "/chunk", transaction_id=str(self.transaction_id), timeout=int(retry_obj.get_timeout_epoch()), parameters=[{u"index": index}, {u"msg": base64.b64encode(msg)}], ) time.sleep(0.05) index += 1 f.close() time.sleep(1.0) sota_logger.info("SOTA Transmission Server: %s: Finishing package: %s", retry_obj, package) self.transaction_id += 1 self.service_edge.message( calling_service=self.service_id, service_name=destination + "/finish", transaction_id=str(self.transaction_id), timeout=int(retry_obj.get_timeout_epoch()), parameters=[{u"dummy": 0}], )