Beispiel #1
0
def load_config():
    """Parses the command line arguments and loads config files.
    """
    base_config_file = utils.determine_config_file(fname_base="base_sender")
    arguments = argument_parsing()

    if arguments.config_file is None:
        arguments.config_file = utils.determine_config_file(
            fname_base="datamanager").as_posix()
    else:
        arguments.config_file = Path(arguments.config_file).as_posix()

    # check if config_file exist
    utils.check_existence(base_config_file)
    utils.check_existence(arguments.config_file)

    # ------------------------------------------------------------------------
    # Get arguments from config file and command line
    # ------------------------------------------------------------------------

    config = utils.load_config(base_config_file)
    config_detailed = utils.load_config(arguments.config_file)

    # if config and yaml is mixed mapping has to take place before merging them
    config_type = "sender"
    config = utils.map_conf_format(config, config_type)
    config_detailed = utils.map_conf_format(config_detailed, config_type)
    arguments_dict = utils.map_conf_format(arguments,
                                           config_type,
                                           is_namespace=True)

    utils.update_dict(config_detailed, config)
    utils.update_dict(arguments_dict, config)

    return config
Beispiel #2
0
def main():
    """Parses the settings from the configure file and displays them.
    """

    args = get_arguments()

    config_file = args.config_file
    params = utils.load_config(config_file)
    # in case the config file was in the old config format
    # (for backwards compatibility to 4.0.x)
    config = utils.map_conf_format(params, "sender")

    config_ed = config["eventdetector"][config["eventdetector"]["type"]]

    print("Configured settings:")
    print("Monitored directory: {}".format(config_ed["monitored_dir"]))
    print("Watched subdirectories are: {}".format(config_ed["fix_subdirs"]))

    msg = "Data is written to: {}"
    if config["datafetcher"]["store_data"]:
        print(msg.format(config["datafetcher"]["local_target"]))
    else:
        print(msg.format("Data is not stored locally"))

    msg = "Data is sent to: {}"
    if config["datafetcher"]["use_data_stream"]:
        print(msg.format(config["datafetcher"]["data_stream_targets"]))
    else:
        print(msg.format("Data is not sent as priority stream anywhere"))

    print("Remove data from the detector: {}".format(
        config["datafetcher"]["remove_data"]))
    print("Whitelist: {}".format(config["general"]["whitelist"]))
Beispiel #3
0
 def _create_asapo_config(self):
     config = self.config.copy()
     try:
         user_config = utils.load_config(self.user_config_path)
         config.update(user_config)
     except OSError as err:
         logger.warning("Could not get user config: {}".format(err))
         logger.warning("Default config is used")
     return config
Beispiel #4
0
def argument_parsing():
    """Parsing of command line arguments.
    """
    parser = argparse.ArgumentParser()

    parser.add_argument("--config_file",
                        type=str,
                        help="Location of the configuration file")
    parser.add_argument("--beamline",
                        type=str,
                        help="Beamline for which the HiDRA Server "
                        "(detector mode) should be started",
                        default="p00")
    parser.add_argument("--verbose",
                        help="More verbose output",
                        action="store_true")
    parser.add_argument("--onscreen",
                        type=str,
                        help="Display logging on screen "
                        "(options are CRITICAL, ERROR, WARNING, "
                        "INFO, DEBUG)",
                        default=False)

    arguments = parser.parse_args()

    config_file = arguments.config_file
    if config_file is None:
        config_file = utils.determine_config_file(
            fname_base="control_server.yaml")

    # convert to dict and map to config section
    arguments = {"controlserver": vars(arguments)}

    # ------------------------------------------------------------------------
    # Get arguments from config file and command line
    # ------------------------------------------------------------------------
    utils.check_existence(config_file)

    config = utils.load_config(config_file)
    utils.update_dict(arguments, config)

    # the configuration is now of the form:
    # {
    #   "controlserver": {...}
    #   "hidraconfig_static" : {...}
    #   "hidraconfig_variable" : {...}
    # }

    # TODO check config for required params

    return config
Beispiel #5
0
def main():
    """Connect to the receiver and show status.
    """

    parser = get_arguments()
    args = parser.parse_args()

    host = args.host

    default_config_file = "/opt/hidra/conf/datamanager.yaml"
    config_file = args.config_file or default_config_file

    if host is not None and config_file is not None:
        parser.error("Either use --host or --config_file but not both.")

    if host is None:
        params = utils.load_config(config_file)
        # in case the config file was in the old config format
        # (for backwards compatibility to 4.0.x)
        config = utils.map_conf_format(params, "sender")

        data_stream_targets = params["datafetcher"]["data_stream_targets"]
        hosts = [target[0] for target in data_stream_targets]

        # TODO make generic
        host = hosts[0]

    control = ReceiverControl(host)

    print("Checking for service hidra receiver on", host, ": ", end="")
    try:
        status = control.get_status()
        if status == ["OK"]:
            print(CGREEN + "running." + CEND)
        else:
            print(CYELLOW +
                  "running but in error state:"
                  + CEND)
            print(status)

    except CommunicationFailed as excp:
        print(CRED + "not reachable." + CEND)
        print(traceback.format_exception_only(type(excp), excp)[0], end="")

    except Exception:
        print(CRED +
              "not reachable. Unknown Error.\n"
              + CEND)
        print(traceback.format_exc())

        sys.exit(1)
Beispiel #6
0
    def _read_config(self):

        config_file = self.get_config_file_name()
        self.log.info("Reading config files: %s", config_file)

        try:
            self.active_config = utils.load_config(config_file, log=self.log)
        except IOError:
            self.log.debug("Configuration file not readable: %s", config_file)
        except Exception:
            self.log.debug("cfile=%s", config_file)
            self.log.error("Error when trying to load config file",
                           exc_info=True)
            raise

        self.print_config(self.active_config, description="active_config=")
Beispiel #7
0
def _merge_with_config(args, parser):
    """
    Takes the command line arguments and overwrites the parameter of the config
    file with it.
    """
    # convert to dict and map to config section
    args_dict = vars(args)

    # hidra config
    eventdetector = {
        "http_events": {
            "det_ip": args_dict["det"],
        }
    }
    if args_dict["detapi"] is not None:
        eventdetector["http_events"]["det_api_version"] = args_dict["detapi"]

    arguments = {"hidra": {"eventdetector": eventdetector}}

    del args_dict["det"]
    del args_dict["detapi"]

    if args_dict["beamline"] is None:
        del args_dict["beamline"]

    # general config
    arguments["general"] = args_dict

    # ------------------------------------------------------------------------
    # Get arguments from config file and command line
    # ------------------------------------------------------------------------
    config_file = _identify_config_file(arguments)
    config = utils.load_config(config_file)
    utils.update_dict(arguments, config)

    # check for beamline
    try:
        if config["general"]["beamline"] not in ALLOWED_BEAMLINES:
            raise parser.error(
                "argument --beamline: invalid choice: '{}' (choose from {})"
                .format(config["general"]["beamline"],
                        str(ALLOWED_BEAMLINES)[1:-1])
            )
    except KeyError:
        raise parser.error("the following arguments are required: --beamline")

    return config
Beispiel #8
0
def argument_parsing():
    """Parses and checks the command line arguments used.
    """

    base_config_file = utils.determine_config_file(fname_base="base_receiver")

    # ------------------------------------------------------------------------
    # Get command line arguments
    # ------------------------------------------------------------------------

    parser = argparse.ArgumentParser()

    parser.add_argument("--config_file",
                        type=str,
                        help="Location of the configuration file")

    parser.add_argument("--log_path",
                        type=str,
                        help="Path where logfile will be created")
    parser.add_argument("--log_name",
                        type=str,
                        help="Filename used for logging")
    parser.add_argument("--log_size",
                        type=int,
                        help="File size before rollover in B (linux only)")
    parser.add_argument("--verbose",
                        help="More verbose output",
                        action="store_true")
    parser.add_argument("--onscreen",
                        type=str,
                        help="Display logging on screen "
                        "(options are CRITICAL, ERROR, WARNING, "
                        "INFO, DEBUG)",
                        default=False)

    parser.add_argument("--procname",
                        type=str,
                        help="Name with which the service should be running")

    parser.add_argument("--whitelist",
                        type=str,
                        help="List of hosts allowed to connect")
    parser.add_argument("--target_dir",
                        type=str,
                        help="Where incoming data will be stored to")
    parser.add_argument("--dirs_not_to_create",
                        type=str,
                        help="Subdirectories which should not be created when "
                        "data is stored")
    parser.add_argument("--data_stream_ip",
                        type=str,
                        help="Ip of dataStream-socket to pull new files from")
    parser.add_argument("--data_stream_port",
                        type=str,
                        help="Port number of dataStream-socket to pull new "
                        "files from")

    arguments = parser.parse_args()
    arguments.config_file = (
        arguments.config_file
        or utils.determine_config_file(fname_base="datareceiver"))

    # check if config_file exist
    utils.check_existence(arguments.config_file)

    # ------------------------------------------------------------------------
    # Get arguments from config file
    # ------------------------------------------------------------------------

    config = utils.load_config(base_config_file)
    config_detailed = utils.load_config(arguments.config_file)

    # if config and yaml is mixed mapping has to take place before merging them
    config_type = "receiver"
    config = utils.map_conf_format(config, config_type)
    config_detailed = utils.map_conf_format(config_detailed, config_type)
    arguments_dict = utils.map_conf_format(arguments,
                                           config_type,
                                           is_namespace=True)

    utils.update_dict(config_detailed, config)

    utils.update_dict(arguments_dict, config)

    # ------------------------------------------------------------------------
    # Check given arguments
    # ------------------------------------------------------------------------

    required_params = {
        "general": [
            "log_path", "log_name", "procname", "procname", "ldapuri",
            "dirs_not_to_create", "whitelist"
        ],
        "datareceiver": [
            "target_dir",
            "data_stream_ip",
            "data_stream_port",
        ]
    }

    # Check format of config
    check_passed, _ = utils.check_config(required_params, config, logging)
    if not check_passed:
        logging.error("Configuration check failed")
        raise utils.WrongConfiguration

    # check target directory for existence
    utils.check_existence(config["datareceiver"]["target_dir"])

    # check if logfile is writable
    config["general"]["log_file"] = os.path.join(config["general"]["log_path"],
                                                 config["general"]["log_name"])

    return config