pallet.parameter documentation
Provides functions for working with parameters.
Parameters are data maps that allow propogation of information between the functions of a crate, and between crates. There are two conventions for using parameters in crates that are directly supported here.
Host specific parameters are specified under
[:parameters :host (keyword target-id)]
These functions are get-for-target, assoc-for-target, and
update-for-target.
Service specific paramters, used across hosts, are specified under
[:parameters :service (keyword service-name)]
These functions are get-for-service, assoc-for-service, and
update-for-service.
The get-for functions have slightly different semantics compared with
clojure.core/get, in that they throw an exception if the key is undefined
and no default value is specified.
Delayed evaluation of parameters specified as arguments to action functions
are also implemented here. lookup and lookup-for-target.
assoc-for
Set the :parameters values at the paths specified.
(assoc-for {} [:a :b] 1 [:a :d] 2) => {:parameters {:a {:b 1} {:d 2}}}
assoc-for-service
Set the service parameter values at the paths specified.
(assoc-for-service {} :proxy [:a :b] 1 [:a :d] 2) => {:parameters {:srvice {:proxy {:a {:b 1} {:d 2}}}}}
assoc-for-target
Set the host parameter values at the paths specified.
(assoc-for-target {:target-id :id1} [:a :b] 1 [:a :d] 2) => {:parameters {:host {:id1 {:a {:b 1} {:d 2}}}}}
assoc-target-settings
Set the settings for the specified host facility. The instance-id allows the specification of specific instance of the facility (the default is :default).
from-map
Initialise parameters based on the given keys, which are used to merge maps from m.
get-for
Retrieve the parameter at the path specified by keys. When no default value is specified, then raise a :parameter-not-found if no parameter is set.
(get-for {:p {:a {:b 1} {:d 2}}} [:p :a :d])
=> 2
get-for-service
Retrieve the service parameter for the service and path specified by keys. When no default value is specified, then raise a :parameter-not-found if no parameter is set.
(get-for-service
{:parameters {:service {:proxy {:a {:b 1} {:d 2}}}}} [:proxy :a :b])
=> 1
get-for-target
Retrieve the host parameter for the current target at the path specified by keys. When no default value is specified, then raise a :parameter-not-found if no parameter is set.
(get-for-target
{:parameters {:host {:id1 {:a {:b 1} {:d 2}}}}
:target-id :id1} [:a :b])
=> 1
get-node-settings
Retrieve the settings for the specified node facility. The instance-id allows
the specification of specific instance of the facility. If passed a nil
instance-id, then :default is used
get-target-settings
Retrieve the settings for the specified host facility. The instance-id allows
the specification of specific instance of the facility. If passed a nil
instance-id, then :default is used
lookup
Lookup a parameter in a delayed manner. Use a call to this function as the argument of a action. This function produces an object, which causes parameter lookup when it's toString method is called.
See also pallet.argument.
lookup-for-target
Lookup a parameter for the target in a delayed manner. Use a call to this function as the argument of a action. This function produces an object, which causes parameter lookup when it's toString method is called.
See also pallet.argument.
parameters
An action to set parameters
update-for
Update parameters at the path given by keys. The value is set to the value return by calling f with the current value and the given args.
(update-for {:parameters {:a {:b 1}}} [:a :b] + 2)
=> {:parameters {:a {:b 3}}}
update-for-service
Update serivce parameters for the pecified service at the path given by keys. The value is set to the value return by calling f with the current value and the given args.
(update-for-service
{:parameters {:service {:proxy {:a {:b 1}}}}}
[:proxy :a :b] + 2)
=> {:parameters {:service {:proxy {:a {:b 3}}}}}
update-for-target
Update host parameters for the current target at the path given by keys. The value is set to the value return by calling f with the current value and the given args.
(update-for-target
{:parameters {:host {:id1 {:a {:b 1}}}}
:target-id :id1}
[:a :b] + 2)
=> {:parameters {:host {:id1 {:a {:b 3}}}}}
update-target-settings
Update the settings for the specified host facility. The instance-id allows the specification of specific instance of the facility (the default is :default).