.. _userguide: """"""""""""""""""""""""""""" User Guide """"""""""""""""""""""""""""" ------------------------------------------------------------------ baltrad-exchange - a multipurpose exchange engine for radar data - ------------------------------------------------------------------ Introduction ================= The baltrad-exchange engine is a new modernized approach of allowing exchange of radar data. Currently, the only supported format is ODIM-H5 but the allowed formats is possible to extend in the future. There are several reasons for why this engine was created but to name a few key-points: - Add more flexible routing that can route on meta-information in a file - Possibility to distribute monitored files as well as received files - Smaller (and easier) installation footprint that doesn't require an external database - More flexible and easier configuration - Possibility to run several different instances on same server - Allow possibility to decorate a file before it is sent to a subscriber Besides the actual server & client software it is also possible to use several APIs from within the module. Note that the namespace is **bexchange** and not baltrad_exchange or any other variant. Overview ================= .. figure:: overview.png :alt: Basic overview of the server The exchange of any files can be divided into a number of different steps. **Input** First, there is the source file that should be distributed. This file should be injected into the system some how. Either waiting for input like when receiving a file or some sort of monitoring/triggering like polling or event handling. **Authentication** When a file is inserted into the system actively we must have some sort of authenticating that it is a valid origin. The baltrad-exchange is using public/private keys and signature handling to ensure that this is taken care of in a secure way. **Subscriptions** When the file has passed the authentication part it is time to decide what to do with the incomming file. - First, the origin (nodename / id) of the file is verified against the subscription to know that we are expecting something from that origin. - Next the metadata is extracted from the file and matched against the subscription filter to know if this subscription should handle the file - If both of above checks has passed. Then the incomming file is stored at zero or more storages before it is published to all publications that matches the file metadata - It is also possible to put the file on a processor queue if the above checks has passed if further processing should be done within the scope of the exchange mechanism **Publications** Since different parties want to have files distributed in various ways the publication has been divided into three different parts. The publisher, the connector and the sender. **Be aware that for each matching subscription all matching publications are run which means that one file can be published more than once.** - **publisher** is the overall spider taking care of threads, what connector to use and if the outgoing file should be modified in any way. Currently there are two publishers, the standard_publisher and the zmq publisher. The zmq publisher doesn't have a connection and/or sender since it's using the internal ZeroMQ framework for communication. - **connection** this is the approach to use when distributing the file. For example if the file should be sent with some sort of failover, duplication, ... - **sender** is the actual protocol to use when sending the file, like to another node, a dex-node or some sort of sftp, scp-protocol **Runners** If a file isn't injected into the system we need to be able to get the file into the system some other way and here is where the runners comes into action. A runner is a separate entity that uses the server backend to trigger and pass a file into the system like if it had passed the **Authentication** part. The runners can for example be event triggered variants like inotify. It can also be triggered variants that accepts some external trigger or scheduled variants. Authorization ======================== There are several different ways to ensure that the sender and receiver knows about each other and in this software we have used basic signature handling. That is, you as a sender signs a message using your private key and the receiver verifies the sent data using the senders public key. Hence, each installation of a node needs to have at least one private/public-key. The private key should be kept at a safe place with read-only permissions for the user that is running the system. Typically 600 or possibly 660 if the group should be trusted as well. Since we have to be backward compatible with earlier DEX-variants we have at this time added two different ways to handle private/public keys. The standard solution is to use the internal crypto handling which is just called **crypto** in the configuration. The other variant is named **keyczar** since DEX signatures is based on that implementation. To create the keypair it is just to type .. code-block:: shell-session %> baltrad-exchange-config create_keys --type=crypto --nodename=myserver Created: Private key: ./myserver.private Public key: ./myserver.public Public json: ./myserver_public.json As you see in the example, three files will be created. A private key in PEM-format which is to be kept safe and two different public keys. One in PEM format and the other in json format. The one in json format will typically be used when setting up the subscriptions. The json-file contains some meta information and the public PEM-key with newlines escaped to be compatible with json. !!!NOTE!!! It might be reasonable to also have configured a folder containing all the keys!!! Baltrad-DEX authorization (for backward compatibility) ======================================================= The DEX exchange mechanism needs to be replaced due to a couple of reasons. One is that the keyczar implementation no longer is supported and the other is that all exchange is based on WMO-numbers and since WMO are no longer issued to new radars we have decided to switch out this functionality. However, due to the fact that if you still need to pass files into the DEX tomcat server it has to be done using the DEX protocol that is using keyczar for signature handling and therefor it is possible to both create key-pairs and also send them to a remote node. Creating the dex-key -------------------- If you have installed a full baltrad-node and ran baltrad-config you already have a private/public key that can be used for keyczar signing which makes this step obsolete. However, if you dont, you create the key using: .. code-block:: sh > baltrad-exchange-config create_keys --type=keyczar --destination=/some/folder --nodename=my-local-nodename This command will create two folders, **my-local-nodename.pub** and **my-local-nodename.priv** under the folder /some/folder. These files have two different purposes. The pub key is used by a remote server for validating that the origin is correct. The private key is used to create a signature before sending the file to a remote server. Following this rule, the first thing that should be done if you want to publish files to a remote server using the dex-protocol is to send the public key to the remote DEX server. This is done by issuing the following command: .. code-block:: sh %> baltrad-exchange-config send_dexkey --pubkey=/some/folder/my-local-nodename.pub --url=https:// --nodename=my-local-nodename This will generate a request on the remote server that has to be approved by the remote administrator. Since there is no additional filter passed on in this request the remote administrator has to set this key to be an injector. After this has been done you will be able to verify the sending of files using: .. code-block:: sh %> baltrad-exchange-config send_dexfile --privkey=/some/folder/my-local-nodename.priv --url=https:// --nodename=my-local-nodename .. _ug_configuration: Configuration ======================== The basic configuration is just a property-file containing the most basic information which is specified when starting the server. In order for the system to start you won't need any json configuration but without them the system won't do anything. .. code-block:: cfg # This is the local address the WSGI server will be listening on baltrad.exchange.uri=https://localhost:8089 # How logging should be performed baltrad.exchange.log.type=logfile # The logfile to use if logfile logging is choosen. Is overridden by server options # baltrad.exchange.log.logfile=/var/log/baltrad/baltrad-exchange-server.log # The logfile to use if logfile logging is choosen. Can be overridden by server options. # baltrad.exchange.log.logfile=/var/log/baltrad/baltrad-exchange-server.log # The log id used baltrad.exchange.log.id=baltrad-exchange # The log level to use. All messages with priority >= log.level will be sent to the log output. # Available are: ERROR, WARNING, INFO, DEBUG baltrad.exchange.log.level=INFO # Number of threads, backlog and timeout baltrad.exchange.threads=20 baltrad.exchange.backlog=10 baltrad.exchange.timeout=10 # Restrict content size that is sent. 32MB (1024*1024*32). This should not be considered as the exact file size. It # can also be the content size of the complete message that can be some bytes larger than actual file. baltrad.exchange.max_content_length = 33554432 # Name of this server. Will be used when communicating with other nodes baltrad.exchange.node.name = example-server # Add keyczar to providers if wanted baltrad.exchange.auth.providers = noauth, crypto # Default crypto-variant baltrad.exchange.auth.crypto.root = /etc/baltrad/exchange/crypto-keys baltrad.exchange.auth.crypto.private.key = /etc/baltrad/exchange/crypto-keys/example-server.private # It is possible to add public keys to the authenticator by adding them according to the following syntax # baltrad.exchange.auth.crypto.keys. = . # Doing this will set the nodename to and associate this node name with the provided public key # # This is automatically handled for the crypto private key and will associate the public key with the # node name. #baltrad.exchange.auth.crypto.keys.example-server = /etc/baltrad/exchange/crypto-keys/example-server.public # If keyczar is in providers. Uncomment and create/import the keyczar private key # baltrad.exchange.auth.keyczar.keystore_root = /etc/baltrad/bltnode-keys # baltrad.exchange.auth.keyczar.private.key = /etc/baltrad/bltnode-keys/anders-nzxt.priv # Comma separated list of directories where json config files are located. baltrad.exchange.server.config.dirs = /etc/baltrad/exchange/config # Where the odim source file can be found in rave format. baltrad.exchange.server.odim_source = /etc/baltrad/rave/config/odim_source.xml # The database in where some basic data is stored when performing the source-lookup # this database doesn't need to be persisted on disk since it will be created upon started # from the above odim_source.xml file baltrad.exchange.server.source_db_uri = sqlite:///var/cache/baltrad/exchange/source.db # The database where we want to store all other information. This should preferrably # be persisted since it will contain statistics and other relevant information # pointing to a postgres database or similar but we can use sqlite as well. This # database will contain for example statistics and other data that should be persisted. baltrad.exchange.server.db_uri = sqlite:///var/lib/baltrad/exchange/baltrad-exchange.db # Note, these should only be readable by the baltrad user # and can be created using the following command. # openssl req -nodes -new -x509 -keyout server.key -out server.cert baltrad.exchange.server.certificate = /etc/baltrad/exchange/etc/server.cert baltrad.exchange.server.key = /etc/baltrad/exchange/etc/server.key # Statistics # It is possible to accumulate statistics from the operation. Most of this configuration is performed # per subscription / publisher / ... and all other cfg-entries that support this functionality # However, there are some general statistics that is configured from this section. # This data will be (unless otherwise configured) stored in the database pointed to by baltrad.exchange.server.db_uri # Keeps track of all incomming files. Will be stored with spid == server-incomming for each source/origin baltrad.exchange.server.statistics.incomming=false # Keeps track of all duplicate files. Note, this is from a general point of view. Will be stored with spid == server-duplicate for each source/origin baltrad.exchange.server.statistics.duplicates=false # Each incomming file will be stored as one separate entry so that it is possible to # calculate average process times and other relevant performance numbers. baltrad.exchange.server.statistics.add_individual_entry=false # Each incomming file will be associated with a total processing time to be able to check # if there are any performance issues. This will not result in a total, just individual entries. baltrad.exchange.server.statistics.file_handling_time=false # If you need to load different objects from paths that are not in the standard PYTHONPATH, # then this configuration entries can be used to add paths to the sys.path. # Sequenced from 1.. and when first number in sequence is missing no more atempts will be done. # baltrad.exchange.server.plugin.directory.1 = /etc/baltrad/exchange/plugins During startup all config.dirs will be traversed and all files ending with **.json** will be processed and possibly parsed. Each json-file should be defined like .. code-block:: json {"":{ } } Where the is one of the following types: - **subscription** - **storage** - **publication** - **runner** - **processor** Whenever a json file is read and the backend identifies one of the above keywords the object is created to support that configuration. Each of these keyword configurations will be explained later on. Templates ----------- To simplify the exchange and setup of the system, there is the possibility to use a template (or templates) to generate the subscription and publication that will be used to configure the exchange. The template contains the necessary parts which are used when the subscription and publication is generated. .. literalinclude:: exchange-template.json The first part is the publication part that contains the sender type and the type of publisher that should be used. Currently, only the rest_sender is supported as template and obviously only crypto which is the encryption method used by the rest-sender. The other section is the filter that will be used for matching files. This part will be put into both the publication and the subscription section. When the template has been created it is possible to use the baltrad-exchange-config program to generate both publication and subscription artifacts. The default location for the template is /etc/baltrad/exchange/etc/exchange-template.json. If you want to use several different templates you can instead specify the template file to use by specifying --template=