davsclaus commented on code in PR #281:
URL: https://github.com/apache/camel-examples/pull/281#discussion_r4165244302


##########
semantic-agent-routing/start.sh:
##########
@@ -0,0 +1,101 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+if (( $# > 1 )); then
+    echo "Usage: $0 [environment-file]" >&2
+    exit 1
+fi
+
+example_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
+env_file=${1:-./camel-agent-routing.env}
+if [[ -f "$env_file" ]]; then
+    set -a
+    # Load the private file without passing credentials on the command line.
+    source "$env_file"
+    set +a
+elif (( $# == 1 )); then
+    echo "Environment file not found: $env_file" >&2
+    exit 1
+fi
+: "${OPENAI_API_KEY:?Set OPENAI_API_KEY in the environment or shared 
environment file}"
+command -v camel >/dev/null || { echo 'Install Camel JBang first.' >&2; exit 
1; }
+
+for port in 8080 8081 8082 8083 8084; do
+    if (: >"/dev/tcp/127.0.0.1/$port") 2>/dev/null; then
+        echo "Port $port is already in use. Stop the existing application 
first." >&2
+        exit 1
+    fi
+done
+
+log_dir="$example_dir/target/run-logs"
+mkdir -p "$log_dir"
+cd "$example_dir/src/main/resources"
+pids=()
+roles=()
+# Give each Camel command its own process group, including JBang's child JVMs.
+set -m
+cleanup() {
+    trap - EXIT INT TERM
+    echo 'Stopping the Camel applications started by this script...'
+    for pid in "${pids[@]}"; do
+        kill -TERM -- "-$pid" 2>/dev/null || true
+    done
+    wait || true
+}
+trap cleanup EXIT
+trap 'exit 130' INT
+trap 'exit 143' TERM
+
+start() {
+    local role=$1 port=$2 pid deadline
+    shift 2
+    echo "Starting $role on port $port (log: $log_dir/$role.log)"
+    camel run "routes/$role.yaml" --property="role=$role" 
--property="port=$port" \
+        --camel-version=4.23.0-SNAPSHOT \
+        --repos=https://repository.apache.org/content/groups/snapshots/ \

Review Comment:
   This pins the released example to `4.23.0-SNAPSHOT` and the snapshot 
repository. Once 4.23.0 ships, these snapshots go away. Could the two flags be 
dropped (README: Camel 4.23 or later required), or the version be taken from 
`${camel.version}`?



##########
semantic-agent-routing/start.ps1:
##########
@@ -0,0 +1,113 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#Requires -Version 5.1
+param([string]$EnvFile = "./camel-agent-routing.env")
+
+$ErrorActionPreference = 'Stop'
+if ($env:OS -ne 'Windows_NT') {
+    throw 'Use start.sh on Linux or macOS.'
+}
+
+if (Test-Path -LiteralPath $EnvFile -PathType Leaf) {
+    foreach ($line in Get-Content -LiteralPath $EnvFile) {
+        if ($line -match '^\s*(#|$)') { continue }
+        if ($line -notmatch 
'^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$') {
+            throw 'Use KEY=value entries and whole-line comments in the 
environment file.'
+        }
+        $name, $value = $Matches[1], $Matches[2].Trim()
+        if ($value -match "^'(.*)'$") {
+            $value = $Matches[1]
+        } else {
+            if ($value -match '^"(.*)"$') { $value = $Matches[1] }
+            # Expand references such as DECISION_API_KEY=${JEV_API_KEY}, 
without evaluating code.
+            $value = [regex]::Replace($value, 
'\$\{([A-Za-z_][A-Za-z0-9_]*)\}', {
+                param($reference)
+                $replacement = 
[Environment]::GetEnvironmentVariable($reference.Groups[1].Value)
+                if ($null -eq $replacement) { throw 'An environment-file 
reference is not defined.' }
+                return $replacement
+            })
+        }
+        [Environment]::SetEnvironmentVariable($name, $value, 'Process')
+    }
+} elseif ($PSBoundParameters.ContainsKey('EnvFile')) {
+    throw "Environment file not found: $EnvFile"
+}
+if (-not $env:OPENAI_API_KEY) {
+    throw 'Set OPENAI_API_KEY in the environment or shared environment file.'
+}
+$camel = (Get-Command camel.cmd -CommandType Application -ErrorAction 
Stop).Source
+
+foreach ($port in 8080..8084) {
+    $client = New-Object System.Net.Sockets.TcpClient
+    try {
+        try { $client.Connect('127.0.0.1', $port) } catch 
[System.Net.Sockets.SocketException] { }
+        if ($client.Connected) { throw "Port $port is already in use. Stop the 
existing application first." }
+    } finally { $client.Dispose() }
+}
+
+$logDir = Join-Path $PSScriptRoot 'target/run-logs'
+$resources = Join-Path $PSScriptRoot 'src/main/resources'
+New-Item -ItemType Directory -Force -Path $logDir | Out-Null
+$applications = New-Object System.Collections.ArrayList
+
+function Start-Integration([string]$Role, [int]$Port, [string]$Extra = '') {
+    $log = Join-Path $logDir "$Role.log"
+    $errorLog = Join-Path $logDir "$Role.err.log"
+    Write-Host "Starting $Role on port $Port (logs: $log and $errorLog)"
+    # cmd.exe runs the Camel JBang launcher; /s /c requires the outer pair of 
quotes.
+    $command = '/d /s /c ""{0}" run routes/{1}.yaml --property=role={1} 
--property=port={2} --camel-version=4.23.0-SNAPSHOT 
--repos=https://repository.apache.org/content/groups/snapshots/ {3}"' -f 
$camel, $Role, $Port, $Extra

Review Comment:
   The same snapshot pin as in `start.sh`: `--camel-version=4.23.0-SNAPSHOT 
--repos=…/snapshots/` will break after the 4.23.0 release.



##########
semantic-agent-routing/.gitignore:
##########
@@ -0,0 +1,3 @@
+.venv/
+__pycache__/
+*.env

Review Comment:
   The example has no Python, so only the env file needs ignoring:
   
   ```suggestion
   *.env
   ```



-- 
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]

Reply via email to