Ejemplo n.º 1
0
    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 test_stop_instance(self):
        PipelineManager.pipeline_instances = {
            1:
            type(
                'GstreamerPipeline', (object, ), {
                    "stop": 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.stop_instance(1)

        self.assertEqual(result, expected_result)
Ejemplo n.º 3
0
def pipelines_name_version_instance_id_delete(name, version,
                                              instance_id):  # noqa: E501
    """pipelines_name_version_instance_id_delete

    Stop and remove an instance of the customized pipeline # noqa: E501

    :param name: 
    :type name: str
    :param version: 
    :type version: int
    :param instance_id: 
    :type instance_id: int

    :rtype: None
    """
    try:
        logger.debug("DELETE on /pipelines/{name}/{version}/{id}".format(
            name=name, version=version, id=instance_id))
        result = PipelineManager.stop_instance(name, version, instance_id)
        if result:
            return result
        return (bad_request_response, HTTPStatus.BAD_REQUEST)
    except Exception as e:
        logger.error('pipelines_name_version_instance_id_delete ' + e)
        return ('Unexpected error', HTTPStatus.INTERNAL_SERVER_ERROR)
Ejemplo n.º 4
0
    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_delete(name, version,
                                              instance_id):  # noqa: E501
    """pipelines_name_version_instance_id_delete

    Stop and remove an instance of the customized pipeline # noqa: E501

    :param name: 
    :type name: str
    :param version: 
    :type version: int
    :param instance_id: 
    :type instance_id: int

    :rtype: None
    """

    logger.debug("DELETE on /pipelines/{name}/{version}/{id}".format(
        name=name, version=version, id=instance_id))
    return PipelineManager.stop_instance(instance_id)
Ejemplo n.º 6
0
    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)