Example #1
0
    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)
Example #2
0
def make_session_run_result(summaries, hashes):
    return machine_manager_pb2.SessionRunResponse(
        result=machine_manager_pb2.SessionRunResult(summaries=summaries,
                                                    hashes=hashes))