Esempio n. 1
0
def check_config(config):
    """Check if the configuration has the required structure.

    Args:
        config (dict): The configuration dictionary.
    """

    log = utils.LoggingFunction("debug")

    # general section
    required_params = ["beamline", "ldapuri", "netgroup_template"]
    check_passed, _ = utils.check_config(
        required_params,
        config["general"],
        log
    )

    if not check_passed:
        raise utils.WrongConfiguration(
            "The general section of configuration has missing or wrong "
            "parameters."
        )

    # hidra section
    required_params_hidra = {
        "eventdetector": [
            {"http_events": ["history_size"]}
        ],
        "datafetcher": ["store_data", "remove_data"]
    }
    check_passed, _ = utils.check_config(
        required_params_hidra,
        config["hidra"],
        log
    )

    if not check_passed:
        raise utils.WrongConfiguration(
            "The hidra section of configuration has missing or wrong "
            "parameters."
        )

    potential_whitelist = (
        config["general"]["netgroup_template"]
        .format(bl=config["general"]["beamline"])
    )

    try:
        if "whitelist" not in config["hidra"]["general"]:
            config["hidra"]["general"]["whitelist"] = potential_whitelist
    except KeyError:
        config["hidra"]["general"] = {
            "whitelist": potential_whitelist
        }
Esempio n. 2
0
    def setup(self):
        """
        Sets static configuration parameters and sets up ring buffer.
        """

        self.session = requests.session()

        # Enable specification via IP and DNS name
        self.det_ip = socket.gethostbyaddr(self.config["det_ip"])[2][0]
        self.det_api_version = self.config["det_api_version"]

        try:
            self.file_writer_url = (self.config["filewriter_url"].format(
                det_ip=self.det_ip, det_api_version=self.det_api_version))
        except KeyError:
            if "det_api_version" not in self.config:
                raise utils.WrongConfiguration(
                    "Either filewriter_uri or det_api_version have to be "
                    "configured.")

            self.file_writer_url = (
                "http://{}/filewriter/api/{}/files/".format(
                    self.det_ip, self.det_api_version))

        self.log.debug("Getting files from: %s", self.file_writer_url)

        try:
            self.data_url = self.config["datat_url"].format(det_ip=self.det_ip)
        except KeyError:
            self.data_url = "http://{}/data".format(self.det_ip)

        # history to prevent double events
        self.files_downloaded = collections.deque(
            maxlen=self.config["history_size"])
Esempio n. 3
0
def check_config(config, required_parameter):
    failed = False
    for i in required_parameter:
        if i not in config:
            logger.error("Wrong configuration. Missing parameter: '%s'", i)
            failed = True

    if failed:
        raise utils.WrongConfiguration(
            "The configuration has missing or wrong parameters.")
Esempio n. 4
0
    def _check_config_complete(self, host_id):
        """
         Check if all required params are there.
        """

        # identify the configuration for this connection
        try:
            # This is a pointer
            current_config = self.client_dep_configs[host_id]
        except KeyError:
            self.log.debug("No current configuration found")
            raise utils.NotFoundError()

        config_complete, _ = utils.check_config(self.required_params,
                                                current_config, self.log)

        if not config_complete:
            self.log.debug(json.dumps(current_config, sort_keys=True,
                                      indent=4))
            raise utils.WrongConfiguration(
                "Not all required parameters are specified")