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

[session & {:as keys-value-pairs}]

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

[session service & {:as keys-value-pairs}]

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

[session & {:as keys-value-pairs}]

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

[session facility instance-id values]

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

[m keys]

Initialise parameters based on the given keys, which are used to merge maps from m.

get-for

[session keys]
[session keys default]

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

[session keys]
[session keys default]

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

[session keys]
[session keys default]

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

[session node facility instance-id]

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

[session facility instance-id]
[session facility instance-id default]

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

[& keys]

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

[& keys]

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

[session & {:as keyvector-value-pairs}]

An action to set parameters

update-for

[session keys f & args]

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

[session keys f & args]

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

[session keys f & args]

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

[session facility instance-id f & args]

Update the settings for the specified host facility. The instance-id allows the specification of specific instance of the facility (the default is :default).