def SessionRun(self, request, context): try: if self.ServerShuttingDown(context): return session_id = request.session_id final_cycles = request.final_cycles LOGGER.info("New session run requested for session_id {} with final cycles {}".format(session_id, final_cycles)) #Validate cycle values utils.validate_cycles(final_cycles) err_msg = "Result is not yet ready for SessionRun: " + session_id job = self.__get_job__(session_id, request, err_msg, self.session_registry_manager.run_session, session_id, final_cycles) return self.__set_job_cache__(request, job) #If the session result is not ready yet, return progress except NotReadyException as e: LOGGER.debug("Not ready yet, getting progress") session_context = self.session_registry_manager.registry[session_id] #Calculating cycles related progress last_cycle = request.final_cycles[-1] if session_context.halt_cycle != None: if last_cycle > session_context.halt_cycle: last_cycle = session_context.halt_cycle cycle_progress = 0 #Calcuting percentage progress with 2 decimal places, if machine already in a cycle #that alows it to run to the desired cycle if (session_context.cycle <= last_cycle): cycle_progress = int(int(session_context.cycle/last_cycle * 10000) / 100) #Build a status object to return session_run_progress = machine_manager_pb2.SessionRunProgress( progress=cycle_progress, application_progress=session_context.app_progress, updated_at=int(session_context.updated_at), cycle=session_context.cycle ) return machine_manager_pb2.SessionRunResponse(progress=session_run_progress) #No session with provided id, address issue, bad final cycles provided or problem during rollback except (SessionIdException, AddressException, utils.CycleException, RollbackException) as e: LOGGER.error(e) context.set_details("{}".format(e)) context.set_code(grpc.StatusCode.INVALID_ARGUMENT) #Generic error catch except Exception as e: LOGGER.error("An exception occurred: {}\nTraceback: {}".format(e, traceback.format_exc())) context.set_details('An exception with message "{}" was raised!'.format(e)) context.set_code(grpc.StatusCode.UNKNOWN)
def SessionStep(self, request, context): try: if self.ServerShuttingDown(context): return session_id = request.session_id initial_cycle = request.initial_cycle step_params = None #Setting step_params if provided if (request.WhichOneof("step_params_oneof") is not None): if (request.WhichOneof("step_params_oneof") == "step_params"): step_params = request.step_params LOGGER.info("Step parameters received on request") #Setting default step parameters if none were provided if (step_params == None): log_type = cartesi_machine_pb2.AccessLogType(proofs=True, annotations=False) step_params = cartesi_machine_pb2.StepRequest( log_type=log_type) LOGGER.info("Step parameters set to default") LOGGER.info( "New session step requested for session_id {} with initial cycle {}\nLog proofs: {}\nLog annotations: {}" .format(session_id, initial_cycle, step_params.log_type.proofs, step_params.log_type.annotations)) #Validate cycle value utils.validate_cycles([initial_cycle]) return self.session_registry_manager.step_session( session_id, initial_cycle, step_params) #No session with provided id, address issue, bad initial cycle provided or problem during rollback except (SessionIdException, AddressException, utils.CycleException, RollbackException) as e: LOGGER.error(e) context.set_details("{}".format(e)) context.set_code(grpc.StatusCode.INVALID_ARGUMENT) #Generic error catch except Exception as e: LOGGER.error("An exception occurred: {}\nTraceback: {}".format( e, traceback.format_exc())) context.set_details( 'An exception with message "{}" was raised!'.format(e)) context.set_code(grpc.StatusCode.UNKNOWN)
def SessionRun(self, request, context): try: if self.ServerShuttingDown(context): return #Return the fixed session run result summaries = [ cartesi_machine_pb2.RunResponse(), cartesi_machine_pb2.RunResponse() ] hashes = [ cartesi_machine_pb2.Hash(content=bytes.fromhex("00")), cartesi_machine_pb2.Hash(content=bytes.fromhex("00")) ] if DEFECTIVE: hashes = [ cartesi_machine_pb2.Hash(content=bytes.fromhex("00")), cartesi_machine_pb2.Hash(content=bytes.fromhex("01")) ] run_result = utils.make_session_run_result(summaries, hashes) return run_result session_id = request.session_id final_cycles = request.final_cycles LOGGER.info( "New session run requested for session_id {} with final cycles {}" .format(session_id, final_cycles)) #Validate cycle values utils.validate_cycles(final_cycles) #No session with provided id, address issue, bad final cycles provided or problem during rollback except (SessionIdException, AddressException, utils.CycleException, RollbackException) as e: LOGGER.error(e) context.set_details("{}".format(e)) context.set_code(grpc.StatusCode.INVALID_ARGUMENT) #Generic error catch except Exception as e: LOGGER.error("An exception occurred: {}\nTraceback: {}".format( e, traceback.format_exc())) context.set_details( 'An exception with message "{}" was raised!'.format(e)) context.set_code(grpc.StatusCode.UNKNOWN)