コード例 #1
0
 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
コード例 #2
0
 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
コード例 #3
0
 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
コード例 #4
0
 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
コード例 #5
0
 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
コード例 #6
0
 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
コード例 #7
0
    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
コード例 #8
0
 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
コード例 #9
0
    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
コード例 #10
0
    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
コード例 #11
0
ファイル: test_client.py プロジェクト: xwixcn/spot-sdk
    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
コード例 #12
0
    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
コード例 #13
0
    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
コード例 #14
0
ファイル: test_client.py プロジェクト: xwixcn/spot-sdk
 def RestartMission(self, request, context):
     response = mission_pb2.RestartMissionResponse()
     with ResponseContext(response, request):
         response.status = self.restart_mission_response_status
     return response
コード例 #15
0
ファイル: test_client.py プロジェクト: xwixcn/spot-sdk
 def PlayMission(self, request, context):
     response = mission_pb2.PlayMissionResponse()
     with ResponseContext(response, request):
         response.status = self.play_mission_response_status
     return response
コード例 #16
0
ファイル: test_client.py プロジェクト: xwixcn/spot-sdk
 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
コード例 #17
0
ファイル: test_client.py プロジェクト: xwixcn/spot-sdk
 def LoadMission(self, request, context):
     response = mission_pb2.LoadMissionResponse()
     with ResponseContext(response, request):
         response.status = self.load_mission_response_status
     return response
コード例 #18
0
 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
コード例 #19
0
 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