Skip to content

Commit 11bc032

Browse files
Lakshmandhschall
authored andcommitted
Added files for video-analytics-standalone benchmark.
Signed-off-by: L Lakshmanan <[email protected]>
1 parent 2bd3780 commit 11bc032

File tree

16 files changed

+1695
-4
lines changed

16 files changed

+1695
-4
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ benchmarks/video-processing/videos/video1.mp4 filter=lfs diff=lfs merge=lfs -tex
2323
benchmarks/video-processing/videos/video2.mp4 filter=lfs diff=lfs merge=lfs -text
2424
benchmarks/video-processing/videos/video3.mp4 filter=lfs diff=lfs merge=lfs -text
2525
benchmarks/video-processing/videos/video4.mp4 filter=lfs diff=lfs merge=lfs -text
26+
benchmarks/video-analytics-standalone/videos/default.mp4 filter=lfs diff=lfs merge=lfs -text
27+
benchmarks/video-analytics-standalone/videos/video1.mp4 filter=lfs diff=lfs merge=lfs -text
28+
benchmarks/video-analytics-standalone/videos/video2.mp4 filter=lfs diff=lfs merge=lfs -text

.github/workflows/e2e-video-analytics-standalone.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ env:
2424
GOOS: linux
2525
GO111MODULE: on
2626
PORT: 50051
27-
PLATFORMS: linux/amd64,linux/arm64
27+
PLATFORMS: linux/amd64
2828

2929
jobs:
3030
build-and-push:
@@ -183,10 +183,11 @@ jobs:
183183
if: ${{ always() }}
184184
run: |
185185
set -x
186-
container_list=$(kubectl get pods -n default -o jsonpath="{.items[*].spec.containers[*].name}")
187-
for container_name in $container_list
186+
187+
pod_list=$(kubectl get pods -n default -o jsonpath="{.items[*].name}")
188+
for pod in $pod_list
188189
do
189-
kubectl logs -n default -c $container_name -l serving.knative.dev/service=${{ matrix.service }}
190+
kubectl logs $pod
190191
done
191192
192193
- name: Print logs from database
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# MIT License
2+
3+
# Copyright (c) 2024 EASE lab
4+
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
ROOT = ../../
24+
25+
all-image: init-database video-analytics-standalone-python
26+
27+
video-analytics-standalone-python: docker/Dockerfile python/server.py python/imagenet_labels.txt python/requirements.txt videos/default.mp4
28+
DOCKER_BUILDKIT=1 docker build \
29+
--tag vhiveease/video-analytics-standalone-python:latest \
30+
--target videoAnalyticsStandalonePython \
31+
-f docker/Dockerfile \
32+
$(ROOT) --load
33+
34+
init-database: docker/Dockerfile init/init-database.go videos/default.mp4
35+
DOCKER_BUILDKIT=1 docker build \
36+
--tag vhiveease/video-analytics-standalone-init-database:latest \
37+
--target databaseInit \
38+
-f docker/Dockerfile \
39+
$(ROOT) --load
40+
41+
## Push images
42+
push:
43+
docker push docker.io/vhiveease/video-analytics-standalone-python:latest
44+
docker push docker.io/vhiveease/video-analytics-standalone-init-database:latest
45+
46+
## Pull images from docker hub
47+
pull:
48+
docker pull docker.io/vhiveease/video-analytics-standalone-python:latest
49+
docker pull docker.io/vhiveease/video-analytics-standalone-init-database:latest
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# MIT License
2+
3+
# Copyright (c) 2024 EASE lab
4+
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
#---------- Init-Database -----------#
24+
# First stage (Builder):
25+
FROM vhiveease/golang-builder:latest AS databaseInitBuilder
26+
WORKDIR /app/app/
27+
RUN apt-get install git ca-certificates
28+
29+
COPY ./benchmarks/video-analytics-standalone/init/go.mod ./
30+
COPY ./benchmarks/video-analytics-standalone/init/go.sum ./
31+
COPY ./benchmarks/video-analytics-standalone/init/init-database.go ./
32+
33+
RUN go mod tidy
34+
RUN CGO_ENABLED=0 GOOS=linux go build -v -o ./init-database init-database.go
35+
36+
# Second stage (Runner):
37+
FROM scratch as databaseInit
38+
WORKDIR /app/
39+
COPY --from=databaseInitBuilder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
40+
COPY --from=databaseInitBuilder /app/app/init-database .
41+
COPY ./benchmarks/video-analytics-standalone/videos/ ./videos
42+
43+
ENTRYPOINT [ "/app/init-database" ]
44+
45+
46+
#---------- PYTHON -----------#
47+
# First stage (Builder):
48+
# Install gRPC and all other dependencies
49+
FROM vhiveease/python-slim:latest as videoAnalyticsStandalonePythonBuilder
50+
WORKDIR /py
51+
COPY ./benchmarks/video-analytics-standalone/python/requirements.txt ./requirements.txt
52+
RUN pip3 install --no-cache-dir --user -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
53+
COPY ./utils/tracing/python/tracing.py ./
54+
COPY ./benchmarks/video-analytics-standalone/python/server.py ./
55+
COPY ./benchmarks/video-analytics-standalone/python/imagenet_labels.txt ./
56+
ADD https://raw.githubusercontent.com/vhive-serverless/vSwarm-proto/main/proto/video_analytics_standalone/video_analytics_standalone_pb2_grpc.py ./
57+
ADD https://raw.githubusercontent.com/vhive-serverless/vSwarm-proto/main/proto/video_analytics_standalone/video_analytics_standalone_pb2.py ./proto/video_analytics_standalone/
58+
59+
# Second stage (Runner):
60+
FROM vhiveease/python-slim:latest as videoAnalyticsStandalonePython
61+
COPY --from=videoAnalyticsStandalonePythonBuilder /root/.local /root/.local
62+
COPY --from=videoAnalyticsStandalonePythonBuilder /py /app
63+
WORKDIR /app
64+
# ENV PATH=/root/.local/bin:$PATH
65+
ENTRYPOINT [ "python3", "/app/server.py" ]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Permission is hereby granted, free of charge, to any person obtaining a copy
2+
// of this software and associated documentation files (the "Software"), to deal
3+
// in the Software without restriction, including without limitation the rights
4+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5+
// copies of the Software, and to permit persons to whom the Software is
6+
// furnished to do so, subject to the following conditions:
7+
8+
// The above copyright notice and this permission notice shall be included in all
9+
// copies or substantial portions of the Software.
10+
11+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17+
// SOFTWARE.
18+
19+
module initdatabase
20+
21+
go 1.21
22+
23+
replace github.com/vhive-serverless/vSwarm/utils/tracing/go => ../../../utils/tracing/go
24+
25+
require (
26+
github.com/sirupsen/logrus v1.9.3
27+
go.mongodb.org/mongo-driver v1.14.0
28+
)
29+
30+
require (
31+
github.com/golang/snappy v0.0.1 // indirect
32+
github.com/klauspost/compress v1.13.6 // indirect
33+
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
34+
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
35+
github.com/xdg-go/scram v1.1.2 // indirect
36+
github.com/xdg-go/stringprep v1.0.4 // indirect
37+
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
38+
golang.org/x/crypto v0.17.0 // indirect
39+
golang.org/x/sync v0.1.0 // indirect
40+
golang.org/x/sys v0.15.0 // indirect
41+
golang.org/x/text v0.14.0 // indirect
42+
)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
5+
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
6+
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
7+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
8+
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
9+
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
10+
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
11+
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
12+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
13+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
14+
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
15+
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
16+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
17+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
18+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
19+
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
20+
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
21+
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
22+
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
23+
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
24+
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
25+
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
26+
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
27+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
28+
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
29+
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
30+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
31+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
32+
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
33+
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
34+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
35+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
36+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
37+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
38+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
39+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
40+
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
41+
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
42+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
43+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
44+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
45+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
46+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
47+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
48+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
49+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
50+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
51+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
52+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
53+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
54+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
55+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
56+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
57+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
58+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
59+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
60+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
61+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
62+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
63+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
64+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
65+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
66+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// MIT License
2+
3+
// Copyright (c) 2024 EASE lab
4+
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
package main
24+
25+
import (
26+
"context"
27+
"flag"
28+
"strings"
29+
30+
"path/filepath"
31+
32+
log "github.com/sirupsen/logrus"
33+
34+
"os"
35+
36+
"go.mongodb.org/mongo-driver/mongo"
37+
"go.mongodb.org/mongo-driver/mongo/gridfs"
38+
"go.mongodb.org/mongo-driver/mongo/options"
39+
)
40+
41+
var (
42+
database_address = flag.String("db_addr", "mongodb://video-analytics-standalone-database:27017", "Address of the data-base server")
43+
)
44+
45+
func main() {
46+
flag.Parse()
47+
48+
// Connect to MongoDB
49+
client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(*database_address))
50+
if err != nil {
51+
log.Fatalf("Error connecting to MongoDB: %v", err)
52+
}
53+
defer func() {
54+
if err = client.Disconnect(context.Background()); err != nil {
55+
log.Fatalf("Disconnect error: %v", err)
56+
}
57+
}()
58+
59+
dbName := "video_db"
60+
61+
bucket, err := gridfs.NewBucket(
62+
client.Database(dbName),
63+
)
64+
if err != nil {
65+
log.Fatalf("Error using GridFS: %v", err)
66+
}
67+
68+
dirPath := "./videos"
69+
files, err := os.ReadDir(dirPath)
70+
if err != nil {
71+
log.Fatalf("Error finding files: %v", err)
72+
}
73+
74+
for _, file := range files {
75+
76+
if isVideoFile(file.Name()) {
77+
78+
videoPath := filepath.Join(dirPath, file.Name())
79+
videoFile, err := os.ReadFile(videoPath)
80+
if err != nil {
81+
log.Warnf("Error reading file: %v", err)
82+
continue
83+
}
84+
85+
uploadStream, err := bucket.OpenUploadStream(file.Name())
86+
defer func() {
87+
if err = uploadStream.Close(); err != nil {
88+
log.Fatalf("Disconnect error: %v", err)
89+
}
90+
}()
91+
if err != nil {
92+
log.Warnf("Error creating GridFS upload stream for file %q: %v", videoPath, err)
93+
continue
94+
}
95+
96+
_, err = uploadStream.Write(videoFile)
97+
if err != nil {
98+
log.Warnf("Error uploading file %q to GridFS: %v", videoPath, err)
99+
continue
100+
}
101+
log.Print("Inserted video:", file.Name())
102+
}
103+
}
104+
105+
}
106+
107+
func isVideoFile(fileName string) bool {
108+
videoExtensions := []string{".mp4"}
109+
for _, ext := range videoExtensions {
110+
if strings.HasSuffix(strings.ToLower(fileName), ext) {
111+
return true
112+
}
113+
}
114+
return false
115+
}

0 commit comments

Comments
 (0)