def TeardownSession(self, request, context): response = remote_pb2.TeardownSessionResponse() self.logger.debug('Tearing down session "%s"', request.session_id) with ResponseContext(response, request): with self.lock: self._teardown_session_implementation(request, response) return response
def Stop(self, request, context): response = remote_pb2.StopResponse() with ResponseContext(response, request): self.logger.info('Stopping session.') self.sessions_by_id[request.session_id] = Session() response.status = remote_pb2.StopResponse.STATUS_OK return response
def EstablishSession(self, request, context): response = remote_pb2.EstablishSessionResponse() self.logger.debug('Establishing session with %i leases and %i inputs', len(request.leases), len(request.inputs)) with ResponseContext(response, request): with self.lock: self._establish_session_implementation(request, response) return response
def Tick(self, request, context): response = remote_pb2.TickResponse() self.logger.debug( 'Ticked with session ID "%s" %i leases and %i inputs', request.session_id, len(request.leases), len(request.inputs)) with ResponseContext(response, request): with self.lock: self._tick_implementation(request, response) return response
def Stop(self, request, context): # Called when the client has decided it doesn't need to continue checking on this # service. For example, if this service is running as part of a Mission, some other part # of the Mission may have been activated. response = remote_pb2.StopResponse() self.logger.debug('Stopping session "%s"', request.session_id) with ResponseContext(response, request): with self.lock: self._stop_implementation(request, response) return response
def TeardownSession(self, request, context): response = remote_pb2.TeardownSessionResponse() with ResponseContext(response, request): self.logger.info('Tearing down session.') if request.session_id in self.sessions_by_id: del self.sessions_by_id[request.session_id] response.status = remote_pb2.TeardownSessionResponse.STATUS_OK else: response.status = remote_pb2.TeardownSessionResponse.STATUS_INVALID_SESSION_ID return response
def AcquirePluginData(self, request, context): """Trigger a data acquisition and store results in the data acquisition store service. Args: request (data_acquisition_pb2.AcquirePluginDataRequest): The data acquisition request. context (GRPC ClientContext): tracks internal grpc statuses and information. Returns: An AcquirePluginDataResponse containing a request_id to use with GetStatus. """ response = data_acquisition_pb2.AcquirePluginDataResponse() with ResponseContext(response, request, self.data_buffer_client): self._start_plugin_acquire(request, response) return response
def EstablishSession(self, request, context): response = remote_pb2.EstablishSessionResponse() with ResponseContext(response, request): response.status = remote_pb2.EstablishSessionResponse.STATUS_OK session_id = self._get_unique_random_session_id() self.sessions_by_id[session_id] = Session() self._used_session_ids.append(session_id) response.session_id = session_id if self.options.time_period: self.start_time = ( datetime.datetime.utcnow() - datetime.timedelta(minutes=self.options.time_period) ).strftime("%Y-%m-%dT%H:%M:%SZ") return response
def GetServiceInfo(self, request, context): """Get a list of data acquisition capabilities. Args: request (data_acquisition_pb2.GetServiceInfoRequest): The get service info request. context (GRPC ClientContext): tracks internal grpc statuses and information. Returns: An GetServiceInfoResponse containing the list of data acquisition capabilities for the plugin. """ response = data_acquisition_pb2.GetServiceInfoResponse() with ResponseContext(response, request, self.data_buffer_client): response.capabilities.data_sources.extend(self.capabilities) populate_response_header(response, request) return response
def Tick(self, request, context): """Logs text, then provides a valid response.""" response = remote_pb2.TickResponse() # This utility context manager will fill out some fields in the message headers. with ResponseContext(response, request): # Default to saying hello to "world". name = 'World' # See if a different name was provided to us in the request's inputs. # This "user-string" input is provided by the Autowalk missions. # To provide other inputs, see the RemoteGrpc message. for keyvalue in request.inputs: if keyvalue.key == 'user-string': name = util.get_value_from_constant_value_message( keyvalue.value.constant) self.logger.info('Hello %s!', name) response.status = remote_pb2.TickResponse.STATUS_SUCCESS return response
def GetState(self, request, context): """Mock out GetState to produce specific state.""" response = mission_pb2.GetStateResponse() with ResponseContext(response, request): q = response.state.questions.add() q.id = self.question_id q.source = self.source q.text = 'Answer me these questions three' i = 0 for t in ('What is your name', 'What is your quest', 'What is the air-speed velocity of an unladen swallow'): o = q.options.add() o.text = 'What is your name' o.answer_code = i i += 1 self.active_questions[q.id] = q self.question_id += 1 return response
def GetStatus(self, request, context): """Query the status of a data acquisition by ID. Args: request (data_acquisition_pb2.GetStatusRequest): The get status request. context (GRPC ClientContext): tracks internal grpc statuses and information. Returns: An GetStatusResponse containing the details of the data acquisition. """ response = data_acquisition_pb2.GetStatusResponse() with ResponseContext(response, request, self.data_buffer_client): try: # Note: this needs to be a copy from and not '=' such that the response that is logged # in the request context gets updated. response.CopyFrom( self.request_manager.get_status_proto(request.request_id)) except KeyError: response.status = response.STATUS_REQUEST_ID_DOES_NOT_EXIST populate_response_header(response, request) return response
def CancelAcquisition(self, request, context): """Cancel a data acquisition by ID. Args: request (data_acquisition_pb2.CancelAcquisitionRequest): The cancel acquisition request. context (GRPC ClientContext): tracks internal grpc statuses and information. Returns: An CancelAcquisitionResponse containing the status of the cancel operation. """ response = data_acquisition_pb2.CancelAcquisitionResponse() with ResponseContext(response, request, self.data_buffer_client): try: self.request_manager.mark_request_cancelled(request.request_id) self.logger.info('Cancelling request %d', request.request_id) except KeyError: response.status = response.STATUS_REQUEST_ID_DOES_NOT_EXIST else: response.status = response.STATUS_OK populate_response_header(response, request) return response
def RestartMission(self, request, context): response = mission_pb2.RestartMissionResponse() with ResponseContext(response, request): response.status = self.restart_mission_response_status return response
def PlayMission(self, request, context): response = mission_pb2.PlayMissionResponse() with ResponseContext(response, request): response.status = self.play_mission_response_status return response
def AnswerQuestion(self, request, context): """Mimic AnswerQuestion in actual servicer.""" response = mission_pb2.AnswerQuestionResponse() with ResponseContext(response, request): self._answer_question_impl(request, response) return response
def LoadMission(self, request, context): response = mission_pb2.LoadMissionResponse() with ResponseContext(response, request): response.status = self.load_mission_response_status return response
def TeardownSession(self, request, context): response = remote_pb2.TeardownSessionResponse() with ResponseContext(response, request): self.logger.info('TeardownSession unimplemented!') response.status = remote_pb2.TeardownSessionResponse.STATUS_OK return response
def Stop(self, request, context): response = remote_pb2.StopResponse() with ResponseContext(response, request): self.logger.info('Stop unimplemented!') response.status = remote_pb2.StopResponse.STATUS_OK return response