Skip to content

Commit

Permalink
Merge pull request #3 from 2Delight/release/MLINE-add-gateway-service…
Browse files Browse the repository at this point in the history
…-handlers

MLINE Add handlers for gateway/integrator
  • Loading branch information
2gury authored Dec 1, 2024
2 parents 3a52851 + 7732912 commit b398d8a
Show file tree
Hide file tree
Showing 50 changed files with 11,153 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ target/
# misc
.DS_Store
*.pem
/.idea
/vendor-proto

# debug
/web-app/npm-debug.log*
Expand All @@ -44,3 +46,4 @@ target/
# typescript
/web-app/*.tsbuildinfo
/web-app/next-env.d.ts

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,19 @@ For maintainers debug logging and tracing must be provided. For users, container
### Draft

![Architecture](diagrams/draft-architecture.drawio.svg)

## Integration

### gateway-api

httpPort: 8080
grpcPort: 8082
databaseConnectionString: "postgres://user:password@gateway-db:5432/specifications?sslmode=disable"

gateway-api ходит по grpc integrator-api

### integrator-api

httPort: 8082
grpcPort: 8083

4 changes: 4 additions & 0 deletions code/back/gateway/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.idea
/bin
/vendor-proto
.DS_Store
109 changes: 109 additions & 0 deletions code/back/gateway/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
CURDIR=$(shell pwd)
BINDIR=${CURDIR}/bin
GOVER=$(shell go version | perl -nle '/(go\d\S+)/; print $$1;')
SMARTIMPORTS=${BINDIR}/smartimports_${GOVER}
LINTVER=v1.61.0
LINTBIN=${BINDIR}/lint_${GOVER}_${LINTVER}
PACKAGE=banks-api/cmd/app

all: format build test lint

build: bindir
GOOS=linux GOARCH=amd64 go build -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn" -o ${BINDIR}/app ${PACKAGE}

test:
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn go test ./...

run:
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn go run ${PACKAGE}

lint: install-lint
${LINTBIN} run

precommit: format build test lint
echo "OK"

bindir:
mkdir -p ${BINDIR}

format: install-smartimports
${SMARTIMPORTS} -exclude internal/mocks

install-lint: bindir
test -f ${LINTBIN} || \
(GOBIN=${BINDIR} go install github.com/golangci/golangci-lint/cmd/golangci-lint@${LINTVER} && \
mv ${BINDIR}/golangci-lint ${LINTBIN})

install-smartimports: bindir
test -f ${SMARTIMPORTS} || \
(GOBIN=${BINDIR} go install github.com/pav5000/smartimports/cmd/smartimports@latest && \
mv ${BINDIR}/smartimports ${SMARTIMPORTS})

# Используем bin в текущей директории для установки плагинов protoc
LOCAL_BIN:=$(CURDIR)/bin
bin:
GOBIN=$(LOCAL_BIN) go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
GOBIN=$(LOCAL_BIN) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
GOBIN=$(LOCAL_BIN) go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
GOBIN=$(LOCAL_BIN) go install github.com/envoyproxy/protoc-gen-validate@latest

# Добавляем bin в текущей директории в PATH при запуске protoc
PROTOC = PATH="$$PATH:$(LOCAL_BIN)" protoc

# Устанавливаем proto описания google/googleapis
vendor-proto/google/api:
git clone -b master --single-branch -n --depth=1 --filter=tree:0 \
https://github.com/googleapis/googleapis vendor-proto/googleapis &&\
cd vendor-proto/googleapis &&\
git sparse-checkout set --no-cone google/api &&\
git checkout
mkdir -p vendor-proto/google
mv vendor-proto/googleapis/google/api vendor-proto/google
rm -rf vendor-proto/googleapis

# Устанавливаем proto описания google/protobuf
vendor-proto/google/protobuf:
git clone -b main --single-branch -n --depth=1 --filter=tree:0 \
https://github.com/protocolbuffers/protobuf vendor-proto/protobuf &&\
cd vendor-proto/protobuf &&\
git sparse-checkout set --no-cone src/google/protobuf &&\
git checkout
mkdir -p vendor-proto/google
mv vendor-proto/protobuf/src/google/protobuf vendor-proto/google
rm -rf vendor-proto/protobuf

generate: generate-gateway-api generate-integrator-api generate-validator-api

generate-gateway-api: bin vendor-proto/google/api vendor-proto/google/protobuf
mkdir -p pkg/gateway
$(PROTOC) -I api/gateway -I vendor-proto \
--go_out pkg/gateway --go_opt paths=source_relative \
--go-grpc_out pkg/gateway --go-grpc_opt paths=source_relative \
--grpc-gateway_out pkg/gateway --grpc-gateway_opt paths=source_relative \
--validate_out="lang=go,paths=source_relative:pkg/gateway" \
api/gateway/gateway.proto

generate-integrator-api: bin vendor-proto/google/api vendor-proto/google/protobuf
mkdir -p pkg/integrator
$(PROTOC) -I api/integrator -I vendor-proto \
--go_out pkg/integrator --go_opt paths=source_relative \
--go-grpc_out pkg/integrator --go-grpc_opt paths=source_relative \
--grpc-gateway_out pkg/integrator --grpc-gateway_opt paths=source_relative \
--validate_out="lang=go,paths=source_relative:pkg/integrator" \
api/integrator/integrator.proto

generate-validator-api: bin vendor-proto/google/api vendor-proto/google/protobuf
mkdir -p pkg/validator
$(PROTOC) -I api/validator -I vendor-proto \
--go_out pkg/validator --go_opt paths=source_relative \
--go-grpc_out pkg/validator --go-grpc_opt paths=source_relative \
--grpc-gateway_out pkg/validator --grpc-gateway_opt paths=source_relative \
--validate_out="lang=go,paths=source_relative:pkg/validator" \
api/validator/validator.proto

build-all:
GOOS=linux GOARCH=amd64 make build

run-all: build-all
sudo docker compose up --force-recreate --build
#docker-compose up --force-recreate --build
115 changes: 115 additions & 0 deletions code/back/gateway/api/gateway/gateway.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
syntax = 'proto3';

package gateway;

option go_package = "gateway-api/pkg/gateway";

import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";

service GatewayService {
rpc GetSpecification(GetSpecificationRequest) returns (Specification) {
option (google.api.http) = {
get: "/gateway/specifications/{id}"
};
}

rpc UpdateSpecification(UpdateSpecificationRequest) returns (UpdateSpecificationResponse) {
option (google.api.http) = {
put: "/gateway/specifications/{id}"
};
}

rpc GetStatus(GetStatusRequest) returns (Status) {
option (google.api.http) = {
get: "/gateway/specifications/{id}/status"
};
}

rpc UpdateStatus(UpdateStatusRequest) returns (StatusUpdateResponse) {
option (google.api.http) = {
post: "/gateway/specifications/{id}/status"
};
}

rpc ValidateSpecification(ValidateSpecificationRequest) returns (ValidationResult) {
option (google.api.http) = {
post: "/gateway/specifications/{id}/validate"
};
}
}

message Specification {
int64 id = 1;
string name = 2;
string content = 3; // YAML content
string git_path = 4;
string status = 5;
google.protobuf.Timestamp created_at = 6;
google.protobuf.Timestamp updated_at = 7;
}

message CommitPushResult {
string commit_hash = 1;
bool is_success = 2;
}

message MLDevResult {
bool is_success = 1;
repeated string artifacts = 2;
}

message Status {
int64 id = 1;
string name = 2; // "committed", "completed", etc.
}

message StatusUpdate {
string new_status = 1;
}

message StatusUpdateResponse {
bool is_success = 1;
}

message ValidationResult {
bool is_valid = 1;
repeated Error errors = 2;
repeated Hint hints = 3;
}

message Error {
string code = 1;
string message = 2;
}

message Hint {
string message = 1;
}

message GetSpecificationRequest {
int64 id = 1;
}

message UpdateSpecificationRequest {
int64 id = 1;
string specification_content = 2;
}

message UpdateSpecificationResponse {
bool is_success = 1;
}

message GetStatusRequest {
int64 id = 1;
}

message UpdateStatusRequest {
int64 id = 1;
StatusUpdate status_update = 2;
}

message ValidateSpecificationRequest {
int64 id = 1;
string specification_content = 2;
}
66 changes: 66 additions & 0 deletions code/back/gateway/api/integrator/integrator.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
syntax = "proto3";

package integrator;

option go_package = "gateway-api/pkg/integrator";

import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";

service WorkerService {
rpc SaveSpecification(SaveSpecificationRequest) returns (CommitPushResult) {
option (google.api.http) = {
post: "/worker/specifications/{id}/save"
};
}

rpc RunMLDev(RunMLDevRequest) returns (MLDevResult) {
option (google.api.http) = {
post: "/worker/specifications/{id}/run-mldev"
};
}

rpc GetSpecificationFromGit(GetSpecificationRequest) returns (Specification) {
option (google.api.http) = {
get: "/worker/specifications/{id}/get"
};
}
}

message Specification {
int64 id = 1;
string name = 2;
string content = 3; // YAML content
string git_path = 4;
string status = 5;
google.protobuf.Timestamp created_at = 6;
google.protobuf.Timestamp updated_at = 7;
}

message CommitPushResult {
string commit_hash = 1;
bool is_success = 2;
}

message MLDevResult {
bool is_success = 1;
repeated string artifacts = 2;
}

message GetSpecificationRequest {
int64 id = 1;
}

message SaveSpecificationRequest {
int64 id = 1;
Specification specification = 2;
}

message RunMLDevRequest {
int64 id = 1;
MLDevPath path = 2;
}

message MLDevPath {
string path = 1;
}
46 changes: 46 additions & 0 deletions code/back/gateway/api/validator/validator.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
syntax = "proto3";

package validator;

option go_package = "gateway-api/pkg/validator";

import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";

// ValidatorService предоставляет методы для валидации спецификаций.
service ValidatorService {
// Провалидировать спецификацию.
rpc ValidateSpecification(ValidateSpecificationRequest) returns (ValidationResult) {
option (google.api.http) = {
post: "/validator/specifications/validate"
};
}
}

// Запрос на валидацию спецификации.
message ValidateSpecificationRequest {
Specification specification = 1; // Спецификация для валидации.
}

// Результат валидации.
message ValidationResult {
bool is_valid = 1; // Является ли спецификация валидной.
repeated Error errors = 2; // Список ошибок.
repeated Hint hints = 3; // Список подсказок.
}

message Specification {
int64 id = 1; // Уникальный идентификатор спецификации.
string content = 3; // YAML-контент спецификации.
}

// Ошибка, найденная при валидации.
message Error {
string code = 1; // Код ошибки.
string message = 2; // Описание ошибки.
}

// Подсказка, найденная при валидации.
message Hint {
string message = 1; // Текст подсказки.
}
Loading

0 comments on commit b398d8a

Please sign in to comment.