In this part of the tutorial, you will see how to pass arbitrary configuration parameters to your component. By this time, you probably noticed that your component has a configuration field:
Let’s assume you want to make the sample component
add a given sound to each row a given number of times. For that you’ll need two parameters:
To implement the above, you can change the sample component to:
At the beginning, the KBC Docker library is imported and
initialized by reading the
data directory (
docker.Config('/data/')). Its method
get_parameters will provide the
configuration parameters as a dictionary. The library is currently available for the R language and
Python. It does no magic or rocket science, so you can
read the config file directly if you wish.
Commit and push the code in your repository and tag it with a normal version tag. This will trigger a build on Travis CI and automatically deploy the new version into KBC. Keep in mind that after the deployment, it may take up to 5 minutes for the update to propagate to all KBC instances.
To verify that the parameters work, simply edit the component configuration in KBC and paste in, for example:
Run the component and examine the job results. In the
odd result table, you should see that
Moo was added twice to every value.
Entering configuration parameters using JSON data is quite low-level. Therefore you should provide a UI for the end user. The easiest option is to take advantage of the JSON editor based on the configuration schema. For the above configuration, the following schema can be created:
In the schema the two properties
repeat are declared along with the specification
of their form input fields.
You can test the above schema online and verify that the
form generated from it produces the desired JSON structure. Once satisfied with the result,
simply paste the schema into the Configuration schema in your component properties in the
Once the change propagates to your KBC instance, you should see the form in the UI:
The end user can now configure your component without writing the JSON with parameters. For a very complex UI, the JSON schema editor is not really suitable; contact us about available options.
Your component can now successfully read configuration parameters provided by the end user. You can read more about all the features of the configuration file. Keep in mind that the code presented above is simplified as it does not use any validation of end user parameters. The next part of the tutorial will show you how to configure processors.