def test_get_instance_status(self): PipelineManager.pipeline_instances = { 1: type( 'GstreamerPipeline', (object, ), { "status": lambda self: { "id": 1, "state": "RUNNING", "avg_fps": 100000, "start_time": 1234, "elapsed_time": 1234 } })() } expected_result = { "id": 1, "state": "RUNNING", "avg_fps": 100000, "start_time": 1234, "elapsed_time": 1234 } result = PipelineManager.get_instance_status(1) self.assertEqual(result, expected_result)
def pipelines_name_version_instance_id_status_get(name, version, instance_id): # noqa: E501 """pipelines_name_version_instance_id_status_get Return instance status summary # noqa: E501 :param name: :type name: str :param version: :type version: int :param instance_id: :type instance_id: int :rtype: object """ try: logger.debug("GET on /pipelines/{name}/{version}/{id}/status".format( name=name, version=version, id=instance_id)) result = PipelineManager.get_instance_status(name, version, instance_id) if result: return result return ('Invalid pipeline, version or instance', HTTPStatus.BAD_REQUEST) except Exception as e: logger.error('pipelines_name_version_instance_id_status_get ' + e) return ('Unexpected error', HTTPStatus.INTERNAL_SERVER_ERROR)
def loop(self, reqs, pipeline, version="1"): print(reqs, flush=True) pid, msg = PipelineManager.create_instance(pipeline, version, reqs) if pid is None: print("Exception: " + str(msg), flush=True) return -1 fps = 0 while True: self._maincontext.iteration() pinfo = PipelineManager.get_instance_status(pipeline, version, pid) print(pinfo, flush=True) if pinfo is not None: state = pinfo["state"] if state == "COMPLETED": fps = pinfo["avg_fps"] print("Status analysis: Timing {0} {1} {2} {3} {4}".format( reqs["start_time"], pinfo["start_time"], pinfo["elapsed_time"], reqs["user"], reqs["source"]["uri"]), flush=True) break if state == "ABORTED" or state == "ERROR": return -1 PipelineManager.stop_instance(pipeline, version, pid) return fps
def loop(self, reqs, pipeline, version="1"): print(reqs, flush=True) pid, msg = PipelineManager.create_instance(pipeline, version, reqs) if pid is None: print("Exception: " + str(msg), flush=True) return -1 fps = 0 while True: self._maincontext.iteration() pinfo = PipelineManager.get_instance_status(pipeline, version, pid) print(pinfo, flush=True) if pinfo is not None: state = pinfo["state"] if state == "COMPLETED": break if state == "ABORTED" or state == "ERROR": return -1 fps = pinfo["avg_fps"] PipelineManager.stop_instance(pipeline, version, pid) return fps
def pipelines_name_version_instance_id_status_get(name, version, instance_id): # noqa: E501 """pipelines_name_version_instance_id_status_get Return instance status summary # noqa: E501 :param name: :type name: str :param version: :type version: int :param instance_id: :type instance_id: int :rtype: object """ logger.debug("GET on /pipelines/{name}/{version}/{id}/status".format( name=name, version=version, id=instance_id)) return PipelineManager.get_instance_status(instance_id)
def loop(self, sensor, location, uri, algorithm, algorithmName, resolution={ "width": 0, "height": 0 }, zonemap=[], topic="analytics"): pid, msg = PipelineManager.create_instance( self._pipeline, self._version, { "source": { "uri": uri, "type": "uri" }, "destination": { "type": "mqtt", "host": mqtthost, "clientid": algorithm, "topic": topic, }, "tags": { "sensor": sensor, "location": location, "algorithm": algorithm, "office": { "lat": office[0], "lon": office[1], }, }, "parameters": { "crowd_count": { # crowd-counting only "width": resolution["width"], "height": resolution["height"], "zonemap": zonemap }, "every-nth-frame": every_nth_frame, "recording_prefix": "/tmp/" + sensor, }, }) if pid is None: print("Exception: " + str(msg), flush=True) return while not self._stop: self._maincontext.iteration() pinfo = PipelineManager.get_instance_status( self._pipeline, self._version, pid) if pinfo is not None: print(pinfo, flush=True) state = pinfo["state"] if state == "COMPLETED" or state == "ABORTED" or state == "ERROR": print("pineline ended with " + str(state), flush=True) break if pinfo["avg_fps"] > 0 and state == "RUNNING": if "avg_pipeline_latency" not in pinfo: pinfo["avg_pipeline_latency"] = 0 self._db.update( algorithm, { "sensor": sensor, "performance": pinfo["avg_fps"], "latency": pinfo["avg_pipeline_latency"] * 1000, }) print("exiting va pipeline", flush=True) PipelineManager.stop_instance(self._pipeline, self._version, pid)