davsclaus opened a new pull request, #3196:
URL: https://github.com/apache/camel-kamelets/pull/3196
Part of #3170: `exec-sink` takes the arguments of the program, and can set
its working directory, stop it after a timeout, and fail the message on an
unexpected exit code. Until now only `executable` was mapped, so a command with
arguments had to be wrapped in a script.
### The options
| Option | Type | Exec parameter | What it does |
|---|---|---|---|
| `args` | string | `args=RAW({{?args}})` | The arguments, separated by
spaces. An argument with a space goes in double or single quotes, which are
removed. |
| `workingDir` | string | `workingDir=RAW({{?workingDir}})` | The directory
to run the program in. A directory that does not exist fails the message. |
| `commandTimeout` | integer | `timeout={{?commandTimeout}}` | Milliseconds
after which the program is stopped. |
| `exitValues` | string | `exitValues={{?exitValues}}` | The exit codes that
mean success, such as `0` or `0,1`; another exit code fails the message. Has a
`pattern`. |
- None of the options has a `default`. When one is not set, the optional
placeholder drops the parameter, so the endpoint URI is exactly today's
(checked with `camel get endpoint`, below).
- `args` and `workingDir` are wrapped in `RAW()`. Without it the value is
put into the endpoint URI as it is: an `&` in the arguments broke the endpoint
(`Unknown parameters=[{y=z ...}]`), and a `+` would have turned into a space.
- The option is `commandTimeout`, not `timeout`: `timeout` is an option of
the `kamelet:` endpoint itself (how long to wait for the Kamelet's consumer),
so `kamelet:exec-sink?timeout=1000` never reached the template. A first version
named `timeout` was silently ignored: `sleep 10` ran for 10 seconds with
`timeout: 1000`.
- The arguments are split by camel-exec, and the program is started
directly, not through a shell: `*`, `$HOME`, `|`, `>` and `;` reach the program
as they are.
The "Good to know" paragraph no longer says that arguments cannot be given,
and says what makes a message fail and what the timeout does. The partial page
has an example with all the options.
### Verification
Tested with Camel JBang 4.24.0-SNAPSHOT and `--local-kamelet-dir`, with a
script that prints its arguments one per line.
| Case | Result |
|---|---|
| `args: "one two three"` | 3 arguments: `one`, `two`, `three` |
| `args: --name "John Doe" 'single quoted' plain` | 4 arguments: `--name`,
`John Doe`, `single quoted`, `plain` |
| `args: --name="John Doe" a+b x&y=z 100% c=d #hash` | 6 arguments, as
written: `--name=John Doe`, `a+b`, `x&y=z`, `100%`, `c=d`, `#hash` |
| `args: "it's" (a) f(x) "" end` | `it's`, `(a)`, `f(x)`, an empty argument,
`end` |
| `args: * $HOME a\|b >out.txt ; ls` | 6 arguments passed as they are; no
shell expansion, no file written |
| `echo` with `args: hello world` | `hello world` |
| `ls` with `args: -1 <dir>` | the files of the directory |
| The partial page example (`args`, `workingDir`, `commandTimeout`,
`exitValues`) | 4 arguments: `--input`, `/data/orders.csv`, `--name`, `John
Doe`; exit 0 |
| Options unset, `cat` with a body and the script, Kamelet from `main` and
from this PR | Same endpoint URIs (`exec://cat`, `exec:///.../printargs.sh`),
same output: the body, and 0 arguments |
| `pwd` with `workingDir: /tmp` | `/private/tmp` |
| `pwd` with `workingDir` of a directory with a space and a `+` | that
directory, as written |
| `pwd` with `workingDir: /does/not/exist` | The message fails:
`/does/not/exist doesn't exist.` |
| `sh -c 'echo started; sleep 10; echo finished'` with `commandTimeout:
1000` | Stopped after 1 second; the message carries on with body `started` and
`CamelExecExitValue` 143 |
| The same with `exitValues: "0"` | Stopped after 1 second; the message
fails with exit value 143 |
| `sleep 1` with `commandTimeout: 5000` | Ends normally, exit 0 |
| `sh -c 'exit 3'` without `exitValues` | The message carries on,
`CamelExecExitValue` 3 |
| `sh -c 'exit 3'` with `exitValues: "0,3"` | The message carries on, exit 3
|
| `sh -c 'echo partial; exit 3'` with `exitValues: "0"` | The message fails:
`Process exited with an error: 3` |
`./mvnw clean verify -DskipTests` and then `./mvnw clean verify` passed.
_Claude Code on behalf of Claus Ibsen_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]