How to setup this complex configuration project with Pkl? #1255
-
|
Hello and thanks eveeryone for giving this one a read. I'm in charge of defining a configuration framework for a complex project, in which multiple heterogeneous nodes co-exist and each one has its own set of configuration files in different formats (JSON, Yaml, etc). These configurations often share multiple parameters, and have unique sets of parameters as well. It is important to keep coherence between the shared parameters. Moreover, there are constraints across parameters, even among different nodes. I tought of using Pkl for its capabilities of rendering multiple formats and handling constraints. However, I am struggling to set up the architecture of this project, probably for my inexperience with Pkl. I tought of three layers: 1. First layer (libraries) module obc
import "obc_network.pkl" // contains obc.network class definitions
import "obc_algorithms.pkl" // contains obc.algorithms class definitions
obcNetwork : OBCNetwork
obcAlgorithms : OBCAlgorithms
output {
files {
[network.json] {
...
}
[algorithms.json] {
...
}
Apart from this, I also include general domain libraries, such as definition of network-related classes ( 2. Second layer (templates) import ".../lib/network/network.pkl" as Network // Network definitions
import "../lib/obc/obc.pkl" // OBC specific definitions
/* ... */
hidden subsystemEndpoint : Network.Host
fixed subsystemHostname : String = subsystemEndpoint.hostname
fixed subsystemPort : Int(this>0) = subsystemEndpoint.portThe idea is that, when amending this template, configuration usres only need to setup the 3. Thirst layer (user-defined configuration) amends ".../templates/obc/obc.pkl"
import ".../impl/network/endpoints.pkl" as Endpoints
subsystemEndpoint = Endpoints.subsystemFrom what I understood, the properties to be rendered in the output (i.e., Issues 1. Outputs I tried to inherit the output configuration in the template layer, i.e., /// templates/obc/obc.pkl
/*... */
output = import(".../lib/obc/obc.pkl).outputBut I get an error that tells me that the top-level properties have not been defined. It seems Pkl is trying to render directly the output of the top-level module. So, I tought of changing the /// templates/obc/obc.pkl
/* ... */
output = import(".../lib/obc/obc.pkl")._outputBut it seems that the type mismatch for the inner porperty are not trivially resolved, as I get a bunch of It seems the only way to avoid this is to have the template as an I am pretty confused as of now, and therefore I make a step back. Is this a XY problem? Is there a better project configuration to achieve what I'm looking for? In summary, I have the following requirements:
Is there a suggested architecture or language features I'm missing to obtain these? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Your overall design makes sense to me! This code seems incorrect, because output = import(".../lib/obc/obc.pkl").outputYou likely want to be extending By the way, I don't know if you need a second layer? You can just one one base layer, and then amend it: module obc
import "obc_network.pkl" // contains obc.network class definitions
import "obc_algorithms.pkl" // contains obc.algorithms class definitions
// define your input properties
subsystemEndpoint: Network.Host
// ...
// then define your derived "output" properties
fixed subsystemHostname : String = subsystemEndpoint.hostname
fixed subsystemPort : Int(this>0) = subsystemEndpoint.port
fixed obcNetwork: OBCNetwork = new {
endpoint = subsystemEndpoint
}
fixed obcAlgorithms: OBCAlgorithms = new {
endpoint = subsystemEndpoint
}
// ...
// the define the output of your module
output {
files {
["network.json"] = obcNetwork.output
["algorithms.json"] = obcAlgorithms.output
}
}
This looks like a simple bug in your code; you are assigning the output to be a |
Beta Was this translation helpful? Give feedback.
Your overall design makes sense to me!
This code seems incorrect, because
.../lib/obc/obc.pklis your base template, not where your data is defined:You likely want to be extending
obc.pklinstead.By the way, I don't know if you need a second layer? You can just one one base layer, and then amend it: