Skip to content

Commit

Permalink
Improve smart trailer script and instructions (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
inf17101 authored Jun 28, 2024
1 parent 36fb06c commit 2ef2f3e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
24 changes: 18 additions & 6 deletions eclipse-ankaios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,23 @@ The output looks similar to the following:
start_trailer_applications.sh
```

5. Use the `ank get workloads` command again to verify that the new smart trailer applications are running:
- `trailer_properties_provider`, providing the smart trailer's dummy weight property
- `smart_trailer_application`, the smart trailer application reading the smart trailer's dummy weight property
5. Connect the smart trailer to the vehicle starting the `trailer_connected_provider` workload by using the Ank CLI:
```shell
ank run workload trailer_connected_provider --runtime podman --config $'image: ghcr.io/eclipse-sdv-blueprints/software-orchestration/invehicle-stack/trailer-connected-provider:0.1.0\ncommandOptions: ["--network", "host", "--name", "trailer_connected_provider"]' --agent agent_A
```

6. Use the `ank get workloads` command again to verify that the new smart trailer applications are running:
```shell
...
smart_trailer_application agent_A podman Running(Ok)
trailer_connected_provider agent_A podman Running(Ok)
trailer_properties_provider agent_A podman Running(Ok)
```
- `trailer_connected_provider`, sending the signal that the trailer is connected
- `trailer_properties_provider`, providing the trailer's weight property
- `smart_trailer_application`, the trailer application reading the weight property

6. Verify the logs of the smart trailer app and the smart trailer provider using the trailer's weight property:
7. Verify the logs of the smart trailer app and the smart trailer provider using the trailer's weight property:

Logs of the `trailer_properties_provider`:
```shell
Expand All @@ -122,12 +134,12 @@ Logs of the `smart_trailer_application`:
podman logs -f smart_trailer_application
```

7. Verify the logs of the `local-cloud-sync` workload emitting the trailer weight to the cloud (currently to the mock cloud adapter):
8. Verify the logs of the `local-cloud-sync` workload emitting the trailer weight to the cloud (currently to the mock cloud adapter):
```shell
podman logs -f local-cloud-sync
```

8. Stop Ankaios and clean up all workloads by pressing `Ctrl+C` inside the terminal window of `run_blueprint.sh`.
9. Stop Ankaios and clean up all workloads by pressing `Ctrl+C` inside the terminal window of `run_blueprint.sh`.

## Workload development

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@

set -eu

DEBUG_LOG_ENABLED=0
# optarg with enabling debug log output
while getopts ":d" opt; do
case ${opt} in
d )
DEBUG_LOG_ENABLED=1
;;
\? )
echo "Usage: start_trailer_applications_ankaios.sh [-d]"
echo "Options:"
echo " -d Enable debug log output"
exit 1
;;
esac
done

# This script requires jq and grpcurl to be installed
# These are included in the ankaios devcontainer, but if you want to run it outside
# you could add the commands to install them here
Expand Down Expand Up @@ -41,11 +57,33 @@ BODY='{"id":"dtmi:sdv:Trailer:IsTrailerConnected;1"}'
PROTO_URL="https://github.com/eclipse-ibeji/ibeji/releases/download/0.1.1/invehicle_digital_twin.proto"
PROTO_PATH="${SCRIPT_DIR}"
PROTO="invehicle_digital_twin.proto"
curl -L "${PROTO_URL}" -o "${PROTO_PATH}/${PROTO}"
curl -sL "${PROTO_URL}" -o "${PROTO_PATH}/${PROTO}"

if [ $? -ne 0 ]; then
echo "Failed to download the invehicle-digital twin proto file."
exit 1
fi

EXPECTED_PROTOCOL="grpc"
EXPECTED_OPERATION="get"

trap 'cleanup_routine' EXIT SIGTERM SIGQUIT SIGKILL

cleanup_routine() {
rm "${PROTO_PATH}/${PROTO}"
}

log_info() {
echo -e "[$(date -u +"%Y-%m-%dT%H:%M:%SZ") INFO] $1"
}

log_debug() {
if [ $DEBUG_LOG_ENABLED = 1 ]; then
echo -e "[$(date -u +"%Y-%m-%dT%H:%M:%SZ") DEBUG] $1"
fi
}


# Call FindById in a loop until something is returned
while true; do
STATUS=0
Expand All @@ -54,12 +92,12 @@ while true; do
# Check if the output contains entityAccessInfo (the response from Ibeji when a provider is found)
if echo "$OUTPUT" | grep -iq "EntityAccessInfo"
then
echo "The FindById call was successful. Output:"
echo "$OUTPUT"
log_debug "The FindById call was successful. Output:\n$OUTPUT"
log_info "Trailer successfully connected to the vehicle!"
break
else
echo "Provider not found. Status Code '$STATUS' Error '$OUTPUT'"
echo "The trailer is not connected. Retrying..."
log_debug "Provider not found. Status Code '$STATUS' Error '$OUTPUT'\nThe trailer is not connected. Retrying..."
log_info "Waiting for the trailer to connect. Connect the trailer by starting the following workload with the Ank CLI:\nank run workload trailer_connected_provider --runtime podman --config $'image: ghcr.io/eclipse-sdv-blueprints/software-orchestration/invehicle-stack/trailer-connected-provider:0.1.0\\\ncommandOptions: ["--network", "host", "--name", "trailer_connected_provider"]' --agent agent_A\n"
sleep 5
fi
done
Expand All @@ -79,7 +117,7 @@ do
do
if [[ $(echo $OPERATION | tr '[:upper:]' '[:lower:]') == $EXPECTED_OPERATION ]]
then
echo "Trailer is connected! Starting workloads to manage it"
log_info "Starting trailer applications to manage the trailer!"

# Start up the other workloads using podman
CFG_PROVIDER=$'image: ghcr.io/eclipse-sdv-blueprints/software-orchestration/invehicle-stack/trailer-properties-provider:0.1.0\ncommandOptions: ["--network", "host", "--name", "trailer_properties_provider"]'
Expand All @@ -88,14 +126,12 @@ do
ank run workload trailer_properties_provider --runtime podman --config "$CFG_PROVIDER" --agent agent_A
ank run workload smart_trailer_application --runtime podman --config "$CFG_APP" --agent agent_A

echo "Called Ankaios to start the Trailer Properties Digital Twin Provider and Smart Trailer Application"
echo "Check Ankaios status with 'ank get workloads'"
rm "${PROTO_PATH}/${PROTO}"
log_debug "Called Ankaios to start the Trailer Properties Digital Twin Provider and Smart Trailer Application"
log_debug "Check Ankaios status with 'ank get workloads'"
exit 0
fi
done
fi
done
# We didn't find an endpoint which satisfied our conditions
rm "${PROTO_PATH}/${PROTO}"
exit 1

0 comments on commit 2ef2f3e

Please sign in to comment.