[SEBA-823] REST APIs initial implementation (legacy+new)
Change-Id: Ia8480b72540ff08d35003534d39aff984e31120c
diff --git a/Makefile b/Makefile
index 036735f..ee2b460 100644
--- a/Makefile
+++ b/Makefile
@@ -14,19 +14,44 @@
VERSION ?= $(shell cat ./VERSION)
DIFF ?= $(git diff --shortstat 2> /dev/null | tail -n1)
-GIT_STATUS ?= $(shell [[ $DIFF != "" ]] && echo "Dirty" || echo "Clean")
+GIT_STATUS ?= $(shell [ -z "$DIFF" ] && echo "Dirty" || echo "Clean")
## Docker related
DOCKER_TAG ?= ${VERSION}
DOCKER_REPOSITORY ?= ""
DOCKER_REGISTRY ?= ""
DOCKER_RUN_ARGS ?= ""
+DOCKER_PORTS ?= -p 50070:50070 -p 50060:50060 -p 50071:50071 -p 50072:50072 -p 50073:50073
+
+## protobuf related
+VOLTHA_PROTOS ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/opencord/voltha-protos)
+GOOGLEAPI ?= $(shell GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)
+TOOLS_DIR := tools
+TOOLS_BIN := $(TOOLS_DIR)/bin/
+
+export PATH=$(shell echo $$PATH):$(PWD)/$(TOOLS_BIN)
# Public targets
-
all: help
-protos: api/bbsim/bbsim.pb.go # @HELP Build proto files
+# go installed tools.go
+GO_TOOLS := github.com/golang/protobuf/protoc-gen-go \
+ github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
+ github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
+
+# tools
+GO_TOOLS_BIN := $(addprefix $(TOOLS_BIN), $(notdir $(GO_TOOLS)))
+GO_TOOLS_VENDOR := $(addprefix vendor/, $(GO_TOOLS))
+
+TEST_PACKAGES := github.com/opencord/bbsim/cmd/... \
+ github.com/opencord/bbsim/internal/...
+
+setup_tools: $(GO_TOOLS_BIN)
+
+$(GO_TOOLS_BIN): $(GO_TOOLS_VENDOR)
+ GO111MODULE=on GOBIN="$(PWD)/$(TOOLS_BIN)" go install -mod=vendor $(GO_TOOLS)
+
+protos: dep setup_tools api/bbsim/bbsim.pb.go api/bbsim/bbsim.pb.gw.go api/legacy/bbsim.pb.go api/legacy/bbsim.pb.gw.go # @HELP Build proto files
dep: # @HELP Download the dependencies to the vendor folder
GO111MODULE=on go mod vendor
@@ -39,7 +64,7 @@
docker run --rm -v $(shell pwd):/bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim-builder:${DOCKER_TAG} /bin/sh -c "cd /bbsim; make _build"
test: dep protos fmt # @HELP Execute unit tests
- GO111MODULE=on go test -v -mod vendor ./... -covermode count -coverprofile ./tests/results/go-test-coverage.out 2>&1 | tee ./tests/results/go-test-results.out
+ GO111MODULE=on go test -v -mod vendor $(TEST_PACKAGES) -covermode count -coverprofile ./tests/results/go-test-coverage.out 2>&1 | tee ./tests/results/go-test-results.out
go-junit-report < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml
gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml
@@ -53,15 +78,15 @@
docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG}
docker-run: # @HELP Runs the container locally (available options: DOCKER_RUN_ARGS="-pon 2 -onu 2" make docker-run)
- docker run -d -p 50070:50070 -p 50060:50060 --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
+ docker run -d ${DOCKER_PORTS} --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
docker-run-dev: # @HELP Runs the container locally (intended for development purposes, not in detached mode)
- docker run -p 50070:50070 -p 50060:50060 --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
+ docker run ${DOCKER_PORTS} --privileged --rm --name bbsim ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}bbsim:${DOCKER_TAG} /app/bbsim ${DOCKER_RUN_ARGS}
.PHONY: docs
-docs: # @HELP Generate docs and opens them in the browser
- pushd docs; make doc_venv; make html; popd
- open docs/build/html/index.html
+docs: swagger # @HELP Generate docs and opens them in the browser
+ cd docs; make doc_venv; make html; cd -
+ @echo -e "\nBBSim documentation generated in file://${PWD}/docs/build/html/index.html"
# Release related items
# Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH
@@ -79,7 +104,6 @@
export GOARCH=$(rel_arch) ;\
GO111MODULE=on go build -i -v -mod vendor \
-ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
- -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
-X main.gitStatus=${GIT_STATUS} \
-X main.version=${VERSION}" \
-o "$@" ./cmd/bbr
@@ -89,13 +113,13 @@
export GOARCH=$(rel_arch) ;\
GO111MODULE=on go build -i -v -mod vendor \
-ldflags "-w -X main.buildTime=$(shell date +”%Y/%m/%d-%H:%M:%S”) \
- -X main.commitHash=$(shell git log --pretty=format:%H -n 1) \
-X main.gitStatus=${GIT_STATUS} \
-X main.version=${VERSION}" \
-o "$@" ./cmd/bbsim
.PHONY: release $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS)
release: dep protos $(RELEASE_BBR_BINS) $(RELEASE_BBSIM_BINS) # @HELP Creates release ready bynaries for BBSimctl and BBR artifacts
+swagger: docs/swagger/bbsim/bbsim.swagger.json docs/swagger/leagacy/bbsim.swagger.json # @HELP Generate swagger documentation for BBSim API
help: # @HELP Print the command options
@echo
@@ -139,16 +163,37 @@
./cmd/bbsimctl
api/openolt/openolt.pb.go: api/openolt/openolt.proto
- @protoc -I . \
- -I${GOPATH}/src \
- -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
+ @protoc -I. \
+ -I${GOOGLEAPI}/third_party/googleapis \
--go_out=plugins=grpc:./ \
$<
-api/bbsim/bbsim.pb.go: api/bbsim/bbsim.proto
- @protoc -I . \
- -I${GOPATH}/src \
- -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
+api/bbsim/bbsim.pb.go api/bbsim/bbsim.pb.gw.go: api/bbsim/bbsim.proto api/bbsim/bbsim.yaml
+ @protoc -I. \
+ -I${GOOGLEAPI}/third_party/googleapis \
--go_out=plugins=grpc:./ \
+ --grpc-gateway_out=logtostderr=true,grpc_api_configuration=api/bbsim/bbsim.yaml,allow_delete_body=true:./ \
$<
+api/legacy/bbsim.pb.go api/legacy/bbsim.pb.gw.go: api/legacy/bbsim.proto
+ @protoc -I. \
+ -I${GOOGLEAPI}/third_party/googleapis/ \
+ -I${GOOGLEAPI}/ \
+ -I${VOLTHA_PROTOS}/protos/ \
+ --go_out=plugins=grpc:./ \
+ --grpc-gateway_out=logtostderr=true,allow_delete_body=true:./ \
+ $<
+
+docs/swagger/bbsim/bbsim.swagger.json: api/bbsim/bbsim.yaml
+ @protoc -I ./api \
+ -I${GOOGLEAPI}/ \
+ -I${VOLTHA_PROTOS}/protos/ \
+ --swagger_out=logtostderr=true,allow_delete_body=true,grpc_api_configuration=$<:docs/swagger/ \
+ api/bbsim/bbsim.proto
+
+docs/swagger/leagacy/bbsim.swagger.json: api/legacy/bbsim.proto
+ @protoc -I ./api \
+ -I${GOOGLEAPI}/ \
+ -I${VOLTHA_PROTOS}/protos/ \
+ --swagger_out=logtostderr=true,allow_delete_body=true:docs/swagger/ \
+ $<
\ No newline at end of file