Esempio n. 1
0
    def _create_and_start_pipeline(self, instance_id, pipeline_config,
                                   read_only_pipeline):
        stream_port = self._get_next_available_port(instance_id)

        camera_name = pipeline_config.get_camera_name()

        if not self.cam_server_client.is_camera_online(camera_name):
            raise ValueError(
                "Camera %s is not online. Cannot start pipeline." %
                camera_name)

        _logger.info(
            "Creating pipeline on port '%s' for camera '%s'. instance_id=%s",
            stream_port, camera_name, instance_id)

        self.add_instance(
            instance_id,
            PipelineInstance(instance_id=instance_id,
                             process_function=get_pipeline_function(
                                 pipeline_config.get_pipeline_type()),
                             pipeline_config=pipeline_config,
                             output_stream_port=stream_port,
                             cam_client=self.cam_server_client,
                             background_manager=self.background_manager,
                             hostname=self.hostname,
                             read_only_config=read_only_pipeline))

        self.start_instance(instance_id)
Esempio n. 2
0
    def _create_and_start_pipeline(self, instance_id, pipeline_config, read_only_pipeline):
        if pipeline_config.get_pipeline_type() in (config.PIPELINE_TYPE_STREAM, config.PIPELINE_TYPE_CUSTOM):
            camera_name = None
        else:
            camera_name = pipeline_config.get_camera_name()
            if not self.cam_server_client.is_camera_online(camera_name):
                raise ValueError("Camera %s is not online. Cannot start pipeline." % camera_name)

        if pipeline_config.get_configuration().get("port"):
            stream_port =  int(pipeline_config.get_configuration().get("port"))
            _logger.info("Creating pipeline on fixed port '%s' for camera '%s'. instance_id=%s" %
                     (stream_port, camera_name, instance_id))
        else:
            stream_port = self.get_next_available_port(instance_id)
            _logger.info("Creating pipeline on port '%s' for camera '%s'. instance_id=%s" %
                     (stream_port, camera_name, instance_id))


        self.add_instance(instance_id, PipelineInstance(
            instance_id=instance_id,
            process_function=get_pipeline_function(pipeline_config.get_pipeline_type()),
            pipeline_config=pipeline_config,
            stream_port=stream_port,
            cam_client=self.cam_server_client,
            background_manager=self.background_manager,
            user_scripts_manager=self.user_scripts_manager,
            hostname=self.hostname,
            read_only_config=read_only_pipeline
        ))

        self.start_instance(instance_id)
    def _create_and_start_pipeline(self, instance_id, pipeline_config,
                                   read_only_pipeline):
        if pipeline_config.get_pipeline_type() in (
                config.PIPELINE_TYPE_PROCESSING, config.PIPELINE_TYPE_STORE):
            camera_name = pipeline_config.get_camera_name()
            if not self.cam_server_client.is_camera_online(camera_name):
                raise ValueError(
                    "Camera %s is not online. Cannot start pipeline." %
                    camera_name)
        else:
            camera_name = None

        if pipeline_config.get_configuration().get("port"):
            stream_port = int(pipeline_config.get_configuration().get("port"))
            _logger.info(
                "Creating pipeline on fixed port '%s' for camera '%s'. instance_id=%s"
                % (stream_port, camera_name, instance_id))
        else:
            stream_port = self.get_next_available_port(instance_id)
            _logger.info(
                "Creating pipeline on port '%s' for camera '%s'. instance_id=%s"
                % (stream_port, camera_name, instance_id))

        pipeline_type = pipeline_config.get_pipeline_type()
        if pipeline_type == config.PIPELINE_TYPE_SCRIPT:
            pipeline_script = pipeline_config.get_configuration().get(
                "pipeline_script")
            if self.user_scripts_manager and self.user_scripts_manager.exists(
                    pipeline_script):
                mod = load_source(
                    'mod', self.user_scripts_manager.get_path(pipeline_script))
                process_function = mod.run
            else:
                raise ValueError("Invalid pipeline script: %s" %
                                 pipeline_script)
        else:
            process_function = get_pipeline_function(pipeline_type)

        self.add_instance(
            instance_id,
            PipelineInstance(instance_id=instance_id,
                             process_function=process_function,
                             pipeline_config=pipeline_config,
                             stream_port=stream_port,
                             cam_client=self.cam_server_client,
                             background_manager=self.background_manager,
                             user_scripts_manager=self.user_scripts_manager,
                             hostname=self.hostname,
                             read_only_config=read_only_pipeline))

        self.start_instance(instance_id)
Esempio n. 4
0
    def validate_pipeline_config(configuration):
        """
        Verify if the pipeline config has all the mandatory attributes.
        :param configuration: Config to validate.
        :return:
        """

        if not configuration:
            raise ValueError("Config object cannot be empty.\nConfig: %s" %
                             configuration)

        if "camera_name" not in configuration:
            raise ValueError("Camera name not specified in configuration.")

        def verify_attributes(section_name, section, mandatory_attributes):
            missing_attributes = [
                attr for attr in mandatory_attributes if attr not in section
            ]

            if missing_attributes:
                raise ValueError(
                    "The following mandatory attributes were not found in the %s: %s"
                    % (section_name, missing_attributes))

        # Verify root attributes.
        verify_attributes("configuration", configuration,
                          PipelineConfig.DEFAULT_CONFIGURATION.keys())

        image_good_region = configuration["image_good_region"]
        if image_good_region:
            verify_attributes("image_good_region", image_good_region,
                              PipelineConfig.DEFAULT_IMAGE_GOOD_REGION)

        image_slices = configuration["image_slices"]
        if image_slices:
            verify_attributes("image_slices", image_slices,
                              PipelineConfig.DEFAULT_IMAGE_SLICES)

            if not isinstance(image_slices["number_of_slices"], int):
                raise ValueError("number_of_slices must be an integer.")

            if image_slices["orientation"] not in ("vertical", "horizontal"):
                raise ValueError(
                    "Invalid slice orientation '%s'. Slices orientation can be 'vertical' or 'horizontal'."
                    % image_slices["orientation"])

        # Verify if the pipeline exists.
        get_pipeline_function(configuration["pipeline_type"])

        if configuration["pipeline_type"] == "store":

            if "stream_port" not in configuration:
                raise ValueError(
                    "Pipelines with pipeline_type='store' need 'stream_port' specified. "
                    "Config: %s" % configuration)

            stream_port = configuration["stream_port"]
            if not isinstance(stream_port, int):
                raise ValueError(
                    "Property 'stream_port' must be an integer. Config: %s" %
                    configuration)

            if config.PIPELINE_STREAM_PORT_RANGE[
                    0] <= stream_port <= config.PIPELINE_STREAM_PORT_RANGE[1]:
                raise ValueError(
                    "Property 'stream_port' must be outside of the PIPELINE_STREAM_PORT_RANGE."
                    "Stream port range: %s Config: %s" %
                    (config.PIPELINE_STREAM_PORT_RANGE, configuration))
    def validate_pipeline_config(configuration):
        """
        Verify if the pipeline config has all the mandatory attributes.
        :param configuration: Config to validate.
        :return:
        """

        if not configuration:
            raise ValueError("Config object cannot be empty.\nConfig: %s" %
                             configuration)

        def verify_attributes(section_name, section, mandatory_attributes):
            missing_attributes = [
                attr for attr in mandatory_attributes if attr not in section
            ]

            if missing_attributes:
                raise ValueError(
                    "The following mandatory attributes were not found in the %s: %s"
                    % (section_name, missing_attributes))

        verify_attributes("configuration", configuration,
                          PipelineConfig.MANDATORY_ATTRIBUTES)

        if (configuration["pipeline_type"] == config.PIPELINE_TYPE_PROCESSING
            ) or (configuration["pipeline_type"]
                  == config.PIPELINE_TYPE_STORE):
            if "camera_name" not in configuration:
                raise ValueError("Camera name not specified in configuration.")

        if configuration["pipeline_type"] == config.PIPELINE_TYPE_PROCESSING:

            # Verify root attributes.
            verify_attributes("configuration", configuration,
                              PipelineConfig.DEFAULT_CONFIGURATION.keys())

            image_good_region = configuration["image_good_region"]
            if image_good_region:
                verify_attributes("image_good_region", image_good_region,
                                  PipelineConfig.DEFAULT_IMAGE_GOOD_REGION)

            image_slices = configuration["image_slices"]
            if image_slices:
                verify_attributes("image_slices", image_slices,
                                  PipelineConfig.DEFAULT_IMAGE_SLICES)

                if not isinstance(image_slices["number_of_slices"], int):
                    raise ValueError("number_of_slices must be an integer.")

                if image_slices["orientation"] not in ("vertical",
                                                       "horizontal"):
                    raise ValueError(
                        "Invalid slice orientation '%s'. Slices orientation can be 'vertical' or 'horizontal'."
                        % image_slices["orientation"])

        # Verify if the pipeline exists.
        get_pipeline_function(configuration["pipeline_type"])

        if configuration.get("mode") == "FILE":
            if not configuration.get("file"):
                raise ValueError("File name not defined")