Skip to content

Commit

Permalink
Update mmsys-test-encode example
Browse files Browse the repository at this point in the history
  • Loading branch information
mtneug committed Feb 1, 2024
1 parent 292f89f commit c5ad770
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 83 deletions.
181 changes: 129 additions & 52 deletions config/samples/k8s/mmsys-test-encode/README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,134 @@
# Example for mmsys-test-encode operation

This example shows task execution of the `mmsys-test-encode` function demonstrating MPEG NBMP task recovery using event sourcing.
This example shows task execution of the `mmsys-test-encode` function demonstrating MPEG NBMP task error recovery using event sourcing. The NBMP tasks are created directly without going through the NBMP Workflow API and the full workflow manager. However, the nagare media engine `workflow-manager-helper` is deployed as a sidecar container next to the task container. The `workflow-manager-helper` will read the mounted secret and configure the task using the NBMP Task API. It then monitors the execution status.

The `mmsys-test-encode` function can be configured with the following options:

| Config | Description |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------- |
| `mmsys-test-encode.engine.nagare.media/test` | Execution test/mode to use (s. below). (required) |
| `mmsys-test-encode.engine.nagare.media/chunk-seconds` | Duration of a chunk for split-merge execution modes. (required) |
| `mmsys-test-encode.engine.nagare.media/max-number-of-simulated-crashes` | Number crashes, i.e. hard terminations, to simulate (defaults to 2) |
| `mmsys-test-encode.engine.nagare.media/simulated-crash-wait-duration` | Time to wait until simulated crash is triggered. (defaults to 120s) |

The following execution tests/modes exist:

| Test | Description |
| ---------------------------- | --------------------------------------------------------------------- |
| baseline-simple | Simple encode of the whole file. |
| baseline-split-merge | Simple split-and-merge encode. The chunks are processes sequentially. |
| test-no-recovery-simple | Encode of the whole file with simulated crashes without recovery. |
| test-no-recovery-split-merge | Split-and-merge encode with simulated crashes without recovery. |
| test-recovery-split-merge | Split-and-merge encode with simulated crashed with recovery. |

## Host environment

The following sections assume that certain software is installed on the host environment:

* Docker
* `sh` (UNIX shell)
* `bash`
* `make`
* `kind`
* `kubectl`
* `helm`

Alternatively, the commands can be executed in a Docker container that serves as the test environment. Use the following commands to initialize a new container and install the necessary tools. Then follow the guide normally but execute the commands within the container environment.

```sh
# create kind network; ignore if it already exist
$ docker network create \
--driver bridge \
--ipv6 --subnet fc00:f853:ccd:e793::/64 \
--opt com.docker.network.bridge.enable_ip_masquerade=true \
--opt com.docker.network.driver.mtu=65535 \
kind

$ docker run --rm -it --privileged \
--name nagare-media-engine-test-env \
--network kind \
-v "/var/run/docker.sock:/var/run/docker.sock" \
-v "$PWD:/src" \
-w /src \
docker.io/library/alpine:edge

# within the container:

# install necessary tools
docker$ echo "https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
docker$ apk add \
bash \
docker-cli \
helm \
kind \
kubectl \
make

# continue with the guide
docker$ ...

# exit (with automatic cleanup)
docker$ exit
```

## Create Kubernetes Cluster

```sh
$ make kind-up
$ kubectl create namespace mmsys-test-encode
```

## Upload Test Media to In-Cluster S3

```sh
$ kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-upload-media.yaml
# wait until job is complete
$ kubectl logs -f -n mmsys-test-encode jobs/upload-media
```

## Create Tasks (`Secret` + `Job`)

In every test case, the output encoding can be accessed at <http://s3.local.gd/nagare-media-engine-tests/outputs/sintel.mp4> (`s3.local.gd` resolves to 127.0.0.1 assuming the local DNS resolver allows that; the Kubernetes cluster has an Ingress that routes `s3.local.gd` requests to the in-cluster S3).

```sh
# baseline-simple
$ kubectl -n mmsys-test-encode create secret generic workflow-manager-helper-data-mmsys-test-encode-baseline-simple \
--from-file=data.yaml=config/samples/nagare-media/workflow-manager-helper-data_mmsys-test-encode-baseline-simple.yaml

$ kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-task-mmsys-test-encode-baseline-simple.yaml
$ kubectl logs -f -n mmsys-test-encode jobs/task-mmsys-test-encode-baseline-simple -c function

# baseline-split-merge
$ kubectl -n mmsys-test-encode create secret generic workflow-manager-helper-data-mmsys-test-encode-baseline-split-merge \
--from-file=data.yaml=config/samples/nagare-media/workflow-manager-helper-data_mmsys-test-encode-baseline-split-merge.yaml

$ kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-task-mmsys-test-encode-baseline-split-merge.yaml
$ kubectl logs -f -n mmsys-test-encode jobs/task-mmsys-test-encode-baseline-split-merge -c function

# test-no-recovery-simple
$ kubectl -n mmsys-test-encode create secret generic workflow-manager-helper-data-mmsys-test-encode-test-no-recovery-simple \
--from-file=data.yaml=config/samples/nagare-media/workflow-manager-helper-data_mmsys-test-encode-test-no-recovery-simple.yaml

$ kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-task-mmsys-test-encode-test-no-recovery-simple.yaml
$ kubectl logs -f -n mmsys-test-encode jobs/task-mmsys-test-encode-test-no-recovery-simple -c function

# test-no-recovery-split-merge
$ kubectl -n mmsys-test-encode create secret generic workflow-manager-helper-data-mmsys-test-encode-test-no-recovery-split-merge \
--from-file=data.yaml=config/samples/nagare-media/workflow-manager-helper-data_mmsys-test-encode-test-no-recovery-split-merge.yaml

$ kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-task-mmsys-test-encode-test-no-recovery-split-merge.yaml
$ kubectl logs -f -n mmsys-test-encode jobs/task-mmsys-test-encode-test-no-recovery-split-merge -c function

# test-recovery-split-merge
$ kubectl -n mmsys-test-encode create secret generic workflow-manager-helper-data-mmsys-test-encode-test-recovery-split-merge \
--from-file=data.yaml=config/samples/nagare-media/workflow-manager-helper-data_mmsys-test-encode-test-recovery-split-merge.yaml

$ kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-task-mmsys-test-encode-test-recovery-split-merge.yaml
$ kubectl logs -f -n mmsys-test-encode jobs/task-mmsys-test-encode-test-recovery-split-merge -c function
```

## Delete Kubernetes Cluster

```sh
# create cluster
make kind-up
kubectl create namespace mmsys-test-encode

# upload media to S3
kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-upload-media.yaml
kubectl -n mmsys-test-encode wait --timeout=-1s --for=condition=complete job/upload-media
kubectl -n mmsys-test-encode delete job upload-media

# create secrets
kubectl -n mmsys-test-encode create secret generic workflow-manager-helper-data-mmsys-test-encode-baseline-simple "--from-literal=data.yaml=$(
cat config/samples/nagare-media/workflow-manager-helper-data_mmsys-test-encode-baseline-simple.yaml \
| sed 's/localhost:9000/minio.s3.svc.cluster.local:9000/g' \
| sed 's/localhost:4222/nats.nats.svc.cluster.local:4222/g'
)"
kubectl -n mmsys-test-encode create secret generic workflow-manager-helper-data-mmsys-test-encode-baseline-split-merge "--from-literal=data.yaml=$(
cat config/samples/nagare-media/workflow-manager-helper-data_mmsys-test-encode-baseline-split-merge.yaml \
| sed 's/localhost:9000/minio.s3.svc.cluster.local:9000/g' \
| sed 's/localhost:4222/nats.nats.svc.cluster.local:4222/g'
)"
kubectl -n mmsys-test-encode create secret generic workflow-manager-helper-data-mmsys-test-encode-test-no-recovery-simple "--from-literal=data.yaml=$(
cat config/samples/nagare-media/workflow-manager-helper-data_mmsys-test-encode-test-no-recovery-simple.yaml \
| sed 's/localhost:9000/minio.s3.svc.cluster.local:9000/g' \
| sed 's/localhost:4222/nats.nats.svc.cluster.local:4222/g'
)"
kubectl -n mmsys-test-encode create secret generic workflow-manager-helper-data-mmsys-test-encode-test-no-recovery-split-merge "--from-literal=data.yaml=$(
cat config/samples/nagare-media/workflow-manager-helper-data_mmsys-test-encode-test-no-recovery-split-merge.yaml \
| sed 's/localhost:9000/minio.s3.svc.cluster.local:9000/g' \
| sed 's/localhost:4222/nats.nats.svc.cluster.local:4222/g'
)"
kubectl -n mmsys-test-encode create secret generic workflow-manager-helper-data-mmsys-test-encode-test-recovery-split-merge "--from-literal=data.yaml=$(
cat config/samples/nagare-media/workflow-manager-helper-data_mmsys-test-encode-test-recovery-split-merge.yaml \
| sed 's/localhost:9000/minio.s3.svc.cluster.local:9000/g' \
| sed 's/localhost:4222/nats.nats.svc.cluster.local:4222/g'
)"

# create jobs
kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-task-mmsys-test-encode-baseline-simple.yaml
kubectl -n mmsys-test-encode wait --timeout=-1s --for=condition=complete job/task-mmsys-test-encode-baseline-simple

kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-task-mmsys-test-encode-baseline-split-merge.yaml
kubectl -n mmsys-test-encode wait --timeout=-1s --for=condition=complete job/task-mmsys-test-encode-baseline-split-merge

kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-task-mmsys-test-encode-test-no-recovery-simple.yaml
kubectl -n mmsys-test-encode wait --timeout=-1s --for=condition=complete job/task-mmsys-test-encode-test-no-recovery-simple

kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-task-mmsys-test-encode-test-no-recovery-split-merge.yaml
kubectl -n mmsys-test-encode wait --timeout=-1s --for=condition=complete job/task-mmsys-test-encode-test-no-recovery-split-merge

kubectl -n mmsys-test-encode apply -f config/samples/k8s/mmsys-test-encode/job-task-mmsys-test-encode-test-recovery-split-merge.yaml
kubectl -n mmsys-test-encode wait --timeout=-1s --for=condition=complete job/task-mmsys-test-encode-test-recovery-split-merge
$ make kind-down
```
4 changes: 2 additions & 2 deletions config/samples/k8s/mmsys-test-encode/job-upload-media.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ spec:
MLYEAE6AES7IUSL4APYL \
snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H \
--api S3v4
curl -sSL -o /tmp/sintel.mov https://public.educast.cloud/media/master/sintel.mov
mc cp /tmp/sintel.mov s3/nagare-media-engine-tests/inputs/sintel.mov
curl -sSL -o /tmp/sintel.mp4 https://shio-eu-c-public.s3.eu-central-003.backblazeb2.com/media/master/sintel-video-only.mp4
mc cp /tmp/sintel.mp4 s3/nagare-media-engine-tests/inputs/sintel.mp4
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ task:
direction: pull
portBindings:
- id: input
url: http://localhost:9000/nagare-media-engine-tests/inputs/sintel.mov
url: http://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/inputs/sintel.mp4
metadata:
streams:
- duration: 14m48s
Expand All @@ -30,12 +30,12 @@ task:
direction: push
portBindings:
- id: output
url: s3://localhost:9000/nagare-media-engine-tests/outputs/sintel.mp4?INSECURE=true&AWS_ACCESS_KEY_ID=MLYEAE6AES7IUSL4APYL&AWS_SECRET_ACCESS_KEY=snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H
# -> http://localhost:9000/nagare-media-engine-tests/outputs/sintel.mp4
url: s3://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/outputs/sintel.mp4?INSECURE=true&AWS_ACCESS_KEY_ID=MLYEAE6AES7IUSL4APYL&AWS_SECRET_ACCESS_KEY=snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H
# -> http://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/outputs/sintel.mp4
config:
mmsys-test-encode.engine.nagare.media/test: baseline-simple
mmsys-test-encode.engine.nagare.media/chunk-seconds: "120"
mmsys-test-encode.engine.nagare.media/chunk-seconds: "60"

system:
nats:
url: nats://localhost:4222
url: nats://nats.nats.svc.cluster.local:4222
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ task:
direction: pull
portBindings:
- id: input
url: http://localhost:9000/nagare-media-engine-tests/inputs/sintel.mov
url: http://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/inputs/sintel.mp4
metadata:
streams:
- duration: 14m48s
Expand All @@ -30,12 +30,12 @@ task:
direction: push
portBindings:
- id: output
url: s3://localhost:9000/nagare-media-engine-tests/outputs/sintel.mp4?INSECURE=true&AWS_ACCESS_KEY_ID=MLYEAE6AES7IUSL4APYL&AWS_SECRET_ACCESS_KEY=snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H
# -> http://localhost:9000/nagare-media-engine-tests/outputs/sintel.mp4
url: s3://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/outputs/sintel.mp4?INSECURE=true&AWS_ACCESS_KEY_ID=MLYEAE6AES7IUSL4APYL&AWS_SECRET_ACCESS_KEY=snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H
# -> http://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/outputs/sintel.mp4
config:
mmsys-test-encode.engine.nagare.media/test: baseline-split-merge
mmsys-test-encode.engine.nagare.media/chunk-seconds: "120"
mmsys-test-encode.engine.nagare.media/chunk-seconds: "60"

system:
nats:
url: nats://localhost:4222
url: nats://nats.nats.svc.cluster.local:4222
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ task:
direction: pull
portBindings:
- id: input
url: http://localhost:9000/nagare-media-engine-tests/inputs/sintel.mov
url: http://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/inputs/sintel.mp4
metadata:
streams:
- duration: 14m48s
Expand All @@ -38,14 +38,14 @@ task:
direction: push
portBindings:
- id: output
url: s3://localhost:9000/nagare-media-engine-tests/outputs/sintel.mp4?INSECURE=true&AWS_ACCESS_KEY_ID=MLYEAE6AES7IUSL4APYL&AWS_SECRET_ACCESS_KEY=snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H
# -> http://localhost:9000/nagare-media-engine-tests/outputs/sintel.mp4
url: s3://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/outputs/sintel.mp4?INSECURE=true&AWS_ACCESS_KEY_ID=MLYEAE6AES7IUSL4APYL&AWS_SECRET_ACCESS_KEY=snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H
# -> http://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/outputs/sintel.mp4
config:
mmsys-test-encode.engine.nagare.media/test: test-no-recovery-simple
mmsys-test-encode.engine.nagare.media/chunk-seconds: "120"
mmsys-test-encode.engine.nagare.media/chunk-seconds: "60"
mmsys-test-encode.engine.nagare.media/max-number-of-simulated-crashes: "2"
mmsys-test-encode.engine.nagare.media/simulated-crash-wait-duration: 360s
mmsys-test-encode.engine.nagare.media/simulated-crash-wait-duration: 180s

system:
nats:
url: nats://localhost:4222
url: nats://nats.nats.svc.cluster.local:4222
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ task:
direction: pull
portBindings:
- id: input
url: http://localhost:9000/nagare-media-engine-tests/inputs/sintel.mov
url: http://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/inputs/sintel.mp4
metadata:
streams:
- duration: 14m48s
Expand All @@ -38,14 +38,14 @@ task:
direction: push
portBindings:
- id: output
url: s3://localhost:9000/nagare-media-engine-tests/outputs/sintel.mp4?INSECURE=true&AWS_ACCESS_KEY_ID=MLYEAE6AES7IUSL4APYL&AWS_SECRET_ACCESS_KEY=snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H
# -> http://localhost:9000/nagare-media-engine-tests/outputs/sintel.mp4
url: s3://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/outputs/sintel.mp4?INSECURE=true&AWS_ACCESS_KEY_ID=MLYEAE6AES7IUSL4APYL&AWS_SECRET_ACCESS_KEY=snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H
# -> http://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/outputs/sintel.mp4
config:
mmsys-test-encode.engine.nagare.media/test: test-no-recovery-split-merge
mmsys-test-encode.engine.nagare.media/chunk-seconds: "120"
mmsys-test-encode.engine.nagare.media/chunk-seconds: "60"
mmsys-test-encode.engine.nagare.media/max-number-of-simulated-crashes: "2"
mmsys-test-encode.engine.nagare.media/simulated-crash-wait-duration: 360s
mmsys-test-encode.engine.nagare.media/simulated-crash-wait-duration: 180s

system:
nats:
url: nats://localhost:4222
url: nats://nats.nats.svc.cluster.local:4222
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ task:
direction: pull
portBindings:
- id: input
url: http://localhost:9000/nagare-media-engine-tests/inputs/sintel.mov
url: http://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/inputs/sintel.mp4
metadata:
streams:
- duration: 14m48s
Expand All @@ -38,14 +38,14 @@ task:
direction: push
portBindings:
- id: output
url: s3://localhost:9000/nagare-media-engine-tests/outputs/sintel.mp4?INSECURE=true&AWS_ACCESS_KEY_ID=MLYEAE6AES7IUSL4APYL&AWS_SECRET_ACCESS_KEY=snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H
# -> http://localhost:9000/nagare-media-engine-tests/outputs/sintel.mp4
url: s3://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/outputs/sintel.mp4?INSECURE=true&AWS_ACCESS_KEY_ID=MLYEAE6AES7IUSL4APYL&AWS_SECRET_ACCESS_KEY=snTrPIV2NDBoQOjpL10Nk6KY6EyWlePkF1NLMX3H
# -> http://minio.s3.svc.cluster.local:9000/nagare-media-engine-tests/outputs/sintel.mp4
config:
mmsys-test-encode.engine.nagare.media/test: test-recovery-split-merge
mmsys-test-encode.engine.nagare.media/chunk-seconds: "120"
mmsys-test-encode.engine.nagare.media/chunk-seconds: "60"
mmsys-test-encode.engine.nagare.media/max-number-of-simulated-crashes: "2"
mmsys-test-encode.engine.nagare.media/simulated-crash-wait-duration: 360s
mmsys-test-encode.engine.nagare.media/simulated-crash-wait-duration: 180s

system:
nats:
url: nats://localhost:4222
url: nats://nats.nats.svc.cluster.local:4222
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ task:

system:
nats:
url: nats://localhost:4222
url: nats://nats.nats.svc.cluster.local:4222
8 changes: 8 additions & 0 deletions scripts/tasks/kind-up
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ kind create cluster \
--config "hack/kind/config-${EDGE_CLUSTER_NAME}.yaml" \
--wait 300s

# check if we are within a container, i.e. if we can reach the control plane directly
if nslookup "${MANAGEMENT_CLUSTER_NAME}-control-plane" > /dev/null; then
kind export kubeconfig --name ${MANAGEMENT_CLUSTER_NAME} --internal
fi
if nslookup "${EDGE_CLUSTER_NAME}-control-plane" > /dev/null; then
kind export kubeconfig --name ${EDGE_CLUSTER_NAME} --internal
fi

# create kubeconfig secret in management cluster to get access to edge cluster
kubectl config use "kind-${MANAGEMENT_CLUSTER_NAME}"
kubectl create secret generic edge-cluster-kubeconfig "--from-literal=kubeconfig=$(
Expand Down

0 comments on commit c5ad770

Please sign in to comment.