Skip to content
Snippets Groups Projects
Commit 576f7ea1 authored by Behrisch, M. (Michael)'s avatar Behrisch, M. (Michael)
Browse files

Merge branch 'develop' into 'main'

Fixed keyvaluestore issue

See merge request !2
parents 6f2ae606 62299c83
No related branches found
No related tags found
1 merge request!2Fixed keyvaluestore issue
Pipeline #116577 failed
Showing
with 1299 additions and 0 deletions
.DS_Store
builds/
\ No newline at end of file
image: golang:1.16
stages:
- test
- docker
- deploy
lint:
stage: test
script:
- make lint
unit_tests:
stage: test
script:
- make dep
- make test
docker:
image: docker:stable
tags:
- docker
stage: docker
only:
- develop
- main
before_script:
# Make sure docker uses Buildkit
- export DOCKER_BUILDKIT=1
# Log full docker build progress
- export BUILDKIT_PROGRESS=plain
# Enable experimental features (buildx)
- export DOCKER_CLI_EXPERIMENTAL=enabled
# Install docker buildx
- mkdir -p $HOME/.docker/cli-plugins
- wget -O $HOME/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.4.2/buildx-v0.4.2.linux-amd64
- chmod a+x $HOME/.docker/cli-plugins/docker-buildx
# Log in to our private image registry
- docker login datastropheregistry.azurecr.io -u $REGISTRY_USERNAME -p $REGISTRY_PASSWORD
- docker buildx install
- docker buildx create --use
# Install openssh and curl
- apk add openssh-client curl
- mkdir ~/.ssh/
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
# Add our private ssh key
- ssh-add ~/.ssh/id_rsa
# Add UU gitlab to known hosts
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
# Build and push image for linux/amd64 as well as linux/arm64
# Check if $CI_COMMIT_BRANCH is available, as it is not if this is a merge pipeline run
- if [[ ! -z $CI_COMMIT_BRANCH+x ]]; then DOCKER_TAG=$CI_COMMIT_BRANCH; else DOCKER_TAG=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME; fi
- docker buildx build --platform linux/amd64,linux/arm64 -t datastropheregistry.azurecr.io/$CI_PROJECT_NAME:$DOCKER_TAG . --push --ssh default
deploy:
stage: deploy
only:
- develop
- main
script:
- apt-get install openssh-client curl -y >/dev/null
- mkdir ~/.ssh/
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-add ~/.ssh/id_rsa
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- ssh -fN -L 1234:science-vs260.science.uu.nl:22 sivan@up.science.uu.nl
# Copy kubernetes files over
- scp -r -o StrictHostKeyChecking=no -P 1234 -i ~/.ssh/id_rsa deployments/* root@localhost:/root/kubernetes/$CI_PROJECT_NAME
# Deploy all yml files
- ssh -p 1234 -i ~/.ssh/id_rsa root@localhost "kubectl apply -f kubernetes/$CI_PROJECT_NAME/"
# Set deployment image to the image we just made
- if [[ ! -z $CI_COMMIT_BRANCH+x ]]; then DOCKER_TAG=$CI_COMMIT_BRANCH; else DOCKER_TAG=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME; fi
# Restart the deployment if the image is not changed
- ssh -p 1234 -i ~/.ssh/id_rsa root@localhost "if kubectl set image deployment/$DEPLOYMENT_NAME $DEPLOYMENT_NAME=datastropheregistry.azurecr.io/$CI_PROJECT_NAME:$DOCKER_TAG | grep -q "image updated";
then
kubectl rollout restart deployment/$DEPLOYMENT_NAME;
fi"
dependencies: []
# docker buildx build --platform linux/amd64,linux/arm64 -t datastropheregistry.azurecr.io/schema-orchestrator:latest . --push --ssh default
# STAGE 1
FROM golang:1.16
ARG TARGETARCH
ARG TARGETOS
WORKDIR /app
# Use SSH instead of HTTPS
RUN echo "[url \"git@git.science.uu.nl:\"]\n\tinsteadOf = https://git.science.uu.nl/" >> /root/.gitconfig
# Turn off strict host key checking
RUN mkdir /root/.ssh && echo "StrictHostKeyChecking no " > /root/.ssh/config
# Copy go files into the image
COPY go.mod ./
COPY go.sum ./
COPY cmd/ ./cmd/
COPY internal/ ./internal/
# Gather dependencies
RUN --mount=type=ssh go mod download
# Compile for the target architecture and operating system
# Add SSH mount as this operation requires access to private repos
RUN GOARCH=${TARGETARCH} GOOS=${TARGETOS} CGO_ENABLED=0 go build -o ./main ./cmd/schema-orchestrator/
# STAGE 2
FROM busybox
WORKDIR /app
# Copy the built binary into this image
COPY --from=0 /app/main ./
# Run the binary
CMD ./main
\ No newline at end of file
LICENSE 0 → 100644
MIT License
Copyright (c) Utrecht University (Department of Information and Computing Sciences)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
Makefile 0 → 100644
.PHONY: all dep build test lint
lint: dep ## Lint the files
@golint -set_exit_status ./...
test: dep ## Run unittests
@go test -cover -coverprofile=coverage.txt -covermode count ./...
dep: login ## Get the dependencies
@go get -a -v ./...
@go get -u golang.org/x/lint/golint
@go get -u github.com/boumenot/gocover-cobertura
coverage: dep
@go test -v -coverpkg=./... -coverprofile=cover.out ./...
@go tool cover -func cover.out | grep total
@go tool cover -html=cover.out -o cover.html
windows:
$(eval export GOOS := windows)
@go build -o builds/main ./cmd/schema-orchestrator/
macos:
$(eval export GOOS := darwin)
@go build -o builds/main ./cmd/schema-orchestrator/
linux: login # Build for linux
$(eval export GOOS := linux)
CGO_ENABLED=0 go build -o builds/main ./cmd/schema-orchestrator/
run:
./builds/main
develop:
$(eval export RABBIT_USER := guest)
$(eval export RABBIT_PASSWORD := guest)
$(eval export RABBIT_HOST := localhost)
$(eval export RABBIT_PORT := 5672)
$(eval export JWT_SECRET := 15D262E1FB339FFBD062FFB81C1831B2757FA3F1C02B7432A3E586A447FB7870)
$(eval export LOG_MESSAGES := true)
@go run cmd/schema-orchestrator/main.go
docker: login
make linux
@docker build -t datastropheregistry.azurecr.io/schema-orchestrator:latest .
@docker push datastropheregistry.azurecr.io/schema-orchestrator\:latest
login:
echo -e "machine git.science.uu.nl\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
\ No newline at end of file
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
package main
import (
"fmt"
"log"
"os"
"schema-orchestrator/internal/drivers/rpcdriver"
"schema-orchestrator/internal/drivers/webdriver"
"schema-orchestrator/internal/usecases/produce"
"schema-orchestrator/internal/usecases/schema"
"git.science.uu.nl/graphpolaris/broker"
"git.science.uu.nl/graphpolaris/keyvaluestore"
"git.science.uu.nl/graphpolaris/objectstore"
)
/*
This is the main method, it executes the code for this service
*/
func main() {
// Create rpcDriver
rpcDriver := rpcdriver.New()
// Create broker driver
brokerDriver := broker.NewDriver()
// Create keyvaluestore to get the queue with which clients are connected (websockets)
clientUpdaterRedisService := keyvaluestore.NewDriver()
err := clientUpdaterRedisService.Connect(os.Getenv("UI_REDIS_ADDRESS"))
if err != nil {
log.Panicln(fmt.Sprintf("keyValueStore error: %s", err))
}
// Create keyvaluestore to keep track of schema status
schemaStatusRedisService := keyvaluestore.NewDriver()
err = schemaStatusRedisService.Connect(os.Getenv("SCHEMA_REDIS_ADDRESS"))
if err != nil {
log.Panicln(fmt.Sprintf("keyValueStore error: %s", err))
}
// Create object store driver
objectStore := objectstore.NewDriver()
err = objectStore.Connect()
if err != nil {
log.Panicln(fmt.Sprintf("objectStore error: %s", err))
}
// Create producer service
produceService := produce.NewService(brokerDriver, clientUpdaterRedisService, rpcDriver)
produceService.Start()
// Create a schema usecase
schemaService := schema.New(schemaStatusRedisService, objectStore, produceService)
// Create webdriver
webDriver := webdriver.CreateListener(schemaService)
webDriver.SetupHandlers()
webDriver.Start()
select {}
}
#This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
#© Copyright Utrecht University (Department of Information and Computing Sciences)
# Service that exposes this deployment
kind: Service
apiVersion: v1
metadata:
name: schema-orchestrator
spec:
selector:
app: schema-orchestrator
ports:
- port: 3000
targetPort: 3000
---
# schema orchestrator deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: schema-orchestrator
spec:
replicas: 1
selector:
matchLabels:
app: schema-orchestrator
template:
metadata:
labels:
app: schema-orchestrator
spec:
containers:
- name: schema-orchestrator
image: datastropheregistry.azurecr.io/schema-orchestrator:latest
ports:
- containerPort: 3000
env:
- name: RABBIT_HOST
value: rabbitmq
- name: RABBIT_PORT
value: "5672"
- name: RABBIT_USER
valueFrom:
secretKeyRef:
name: rabbitmq-default-user
key: username
- name: RABBIT_PASSWORD
valueFrom:
secretKeyRef:
name: rabbitmq-default-user
key: password
- name: UI_REDIS_ADDRESS
value: redis.redis.svc.cluster.local:6379
- name: SCHEMA_REDIS_ADDRESS
value: redis-schema:6379
- name: LOG_MESSAGES
value: "true"
- name: MINIO_ADDRESS
value: minio:9000
- name: MINIO_ACCESSKEYID
value: root
- name: MINIO_ACCESSKEY
value: DikkeDraak
- name: JWT_SECRET
valueFrom:
secretKeyRef:
name: jwt-secret
key: secret
resources:
requests:
memory: "100Mi"
cpu: "100m"
limits:
memory: "250Mi"
cpu: "500m"
imagePullSecrets:
- name: docker-regcred
---
# Deployment autoscaler
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: schema-orchestrator
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: schema-orchestrator
minReplicas: 1
maxReplicas: 3
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
module schema-orchestrator
go 1.16
require (
git.science.uu.nl/graphpolaris/broker v0.0.0-20210913145737-76d174f4367a
git.science.uu.nl/graphpolaris/keyvaluestore v0.0.0-20211015140849-feaa365e3730
git.science.uu.nl/graphpolaris/objectstore v0.0.0-20210913150113-977062fb8a3c
github.com/arangodb/go-driver v1.2.1
google.golang.org/grpc v1.41.0
google.golang.org/protobuf v1.25.0
)
go.sum 0 → 100644
This diff is collapsed.
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.14.0
// source: databaseType.proto
package databaseTypeService
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type DatabaseTypeResponse_DatabaseType int32
const (
DatabaseTypeResponse_ARANGODB DatabaseTypeResponse_DatabaseType = 0
DatabaseTypeResponse_NEO4J DatabaseTypeResponse_DatabaseType = 1
)
// Enum value maps for DatabaseTypeResponse_DatabaseType.
var (
DatabaseTypeResponse_DatabaseType_name = map[int32]string{
0: "ARANGODB",
1: "NEO4J",
}
DatabaseTypeResponse_DatabaseType_value = map[string]int32{
"ARANGODB": 0,
"NEO4J": 1,
}
)
func (x DatabaseTypeResponse_DatabaseType) Enum() *DatabaseTypeResponse_DatabaseType {
p := new(DatabaseTypeResponse_DatabaseType)
*p = x
return p
}
func (x DatabaseTypeResponse_DatabaseType) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (DatabaseTypeResponse_DatabaseType) Descriptor() protoreflect.EnumDescriptor {
return file_databaseType_proto_enumTypes[0].Descriptor()
}
func (DatabaseTypeResponse_DatabaseType) Type() protoreflect.EnumType {
return &file_databaseType_proto_enumTypes[0]
}
func (x DatabaseTypeResponse_DatabaseType) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use DatabaseTypeResponse_DatabaseType.Descriptor instead.
func (DatabaseTypeResponse_DatabaseType) EnumDescriptor() ([]byte, []int) {
return file_databaseType_proto_rawDescGZIP(), []int{1, 0}
}
type DatabaseTypeRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
ClientID string `protobuf:"bytes,1,opt,name=clientID,proto3" json:"clientID,omitempty"`
DatabaseName string `protobuf:"bytes,2,opt,name=databaseName,proto3" json:"databaseName,omitempty"`
}
func (x *DatabaseTypeRequest) Reset() {
*x = DatabaseTypeRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_databaseType_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DatabaseTypeRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DatabaseTypeRequest) ProtoMessage() {}
func (x *DatabaseTypeRequest) ProtoReflect() protoreflect.Message {
mi := &file_databaseType_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DatabaseTypeRequest.ProtoReflect.Descriptor instead.
func (*DatabaseTypeRequest) Descriptor() ([]byte, []int) {
return file_databaseType_proto_rawDescGZIP(), []int{0}
}
func (x *DatabaseTypeRequest) GetClientID() string {
if x != nil {
return x.ClientID
}
return ""
}
func (x *DatabaseTypeRequest) GetDatabaseName() string {
if x != nil {
return x.DatabaseName
}
return ""
}
type DatabaseTypeResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"`
DatabaseType DatabaseTypeResponse_DatabaseType `protobuf:"varint,2,opt,name=databaseType,proto3,enum=DatabaseTypeResponse_DatabaseType" json:"databaseType,omitempty"`
}
func (x *DatabaseTypeResponse) Reset() {
*x = DatabaseTypeResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_databaseType_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DatabaseTypeResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DatabaseTypeResponse) ProtoMessage() {}
func (x *DatabaseTypeResponse) ProtoReflect() protoreflect.Message {
mi := &file_databaseType_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DatabaseTypeResponse.ProtoReflect.Descriptor instead.
func (*DatabaseTypeResponse) Descriptor() ([]byte, []int) {
return file_databaseType_proto_rawDescGZIP(), []int{1}
}
func (x *DatabaseTypeResponse) GetError() string {
if x != nil {
return x.Error
}
return ""
}
func (x *DatabaseTypeResponse) GetDatabaseType() DatabaseTypeResponse_DatabaseType {
if x != nil {
return x.DatabaseType
}
return DatabaseTypeResponse_ARANGODB
}
var File_databaseType_proto protoreflect.FileDescriptor
var file_databaseType_proto_rawDesc = []byte{
0x0a, 0x12, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x54, 0x79, 0x70, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x22, 0x55, 0x0a, 0x13, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65,
0x54, 0x79, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x63,
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63,
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x12, 0x22, 0x0a, 0x0c, 0x64, 0x61, 0x74, 0x61, 0x62,
0x61, 0x73, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64,
0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x9d, 0x01, 0x0a, 0x14,
0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x46, 0x0a, 0x0c, 0x64, 0x61,
0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e,
0x32, 0x22, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65,
0x54, 0x79, 0x70, 0x65, 0x52, 0x0c, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x54, 0x79,
0x70, 0x65, 0x22, 0x27, 0x0a, 0x0c, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x54, 0x79,
0x70, 0x65, 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x52, 0x41, 0x4e, 0x47, 0x4f, 0x44, 0x42, 0x10, 0x00,
0x12, 0x09, 0x0a, 0x05, 0x4e, 0x45, 0x4f, 0x34, 0x4a, 0x10, 0x01, 0x32, 0x57, 0x0a, 0x13, 0x44,
0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x54, 0x79, 0x70, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x12, 0x40, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73,
0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65,
0x54, 0x79, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x44, 0x61,
0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x22, 0x00, 0x42, 0x47, 0x5a, 0x45, 0x75, 0x73, 0x65, 0x72, 0x2d, 0x6d, 0x61, 0x6e,
0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f,
0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x2f,
0x72, 0x70, 0x63, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x2f, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61,
0x73, 0x65, 0x54, 0x79, 0x70, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_databaseType_proto_rawDescOnce sync.Once
file_databaseType_proto_rawDescData = file_databaseType_proto_rawDesc
)
func file_databaseType_proto_rawDescGZIP() []byte {
file_databaseType_proto_rawDescOnce.Do(func() {
file_databaseType_proto_rawDescData = protoimpl.X.CompressGZIP(file_databaseType_proto_rawDescData)
})
return file_databaseType_proto_rawDescData
}
var file_databaseType_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_databaseType_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_databaseType_proto_goTypes = []interface{}{
(DatabaseTypeResponse_DatabaseType)(0), // 0: DatabaseTypeResponse.DatabaseType
(*DatabaseTypeRequest)(nil), // 1: DatabaseTypeRequest
(*DatabaseTypeResponse)(nil), // 2: DatabaseTypeResponse
}
var file_databaseType_proto_depIdxs = []int32{
0, // 0: DatabaseTypeResponse.databaseType:type_name -> DatabaseTypeResponse.DatabaseType
1, // 1: DatabaseTypeService.GetDatabaseType:input_type -> DatabaseTypeRequest
2, // 2: DatabaseTypeService.GetDatabaseType:output_type -> DatabaseTypeResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_databaseType_proto_init() }
func file_databaseType_proto_init() {
if File_databaseType_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_databaseType_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DatabaseTypeRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_databaseType_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DatabaseTypeResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_databaseType_proto_rawDesc,
NumEnums: 1,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_databaseType_proto_goTypes,
DependencyIndexes: file_databaseType_proto_depIdxs,
EnumInfos: file_databaseType_proto_enumTypes,
MessageInfos: file_databaseType_proto_msgTypes,
}.Build()
File_databaseType_proto = out.File
file_databaseType_proto_rawDesc = nil
file_databaseType_proto_goTypes = nil
file_databaseType_proto_depIdxs = nil
}
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
package databaseTypeService
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// DatabaseTypeServiceClient is the client API for DatabaseTypeService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type DatabaseTypeServiceClient interface {
GetDatabaseType(ctx context.Context, in *DatabaseTypeRequest, opts ...grpc.CallOption) (*DatabaseTypeResponse, error)
}
type databaseTypeServiceClient struct {
cc grpc.ClientConnInterface
}
func NewDatabaseTypeServiceClient(cc grpc.ClientConnInterface) DatabaseTypeServiceClient {
return &databaseTypeServiceClient{cc}
}
func (c *databaseTypeServiceClient) GetDatabaseType(ctx context.Context, in *DatabaseTypeRequest, opts ...grpc.CallOption) (*DatabaseTypeResponse, error) {
out := new(DatabaseTypeResponse)
err := c.cc.Invoke(ctx, "/DatabaseTypeService/GetDatabaseType", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// DatabaseTypeServiceServer is the server API for DatabaseTypeService service.
// All implementations must embed UnimplementedDatabaseTypeServiceServer
// for forward compatibility
type DatabaseTypeServiceServer interface {
GetDatabaseType(context.Context, *DatabaseTypeRequest) (*DatabaseTypeResponse, error)
mustEmbedUnimplementedDatabaseTypeServiceServer()
}
// UnimplementedDatabaseTypeServiceServer must be embedded to have forward compatible implementations.
type UnimplementedDatabaseTypeServiceServer struct {
}
func (UnimplementedDatabaseTypeServiceServer) GetDatabaseType(context.Context, *DatabaseTypeRequest) (*DatabaseTypeResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetDatabaseType not implemented")
}
func (UnimplementedDatabaseTypeServiceServer) mustEmbedUnimplementedDatabaseTypeServiceServer() {}
// UnsafeDatabaseTypeServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to DatabaseTypeServiceServer will
// result in compilation errors.
type UnsafeDatabaseTypeServiceServer interface {
mustEmbedUnimplementedDatabaseTypeServiceServer()
}
func RegisterDatabaseTypeServiceServer(s grpc.ServiceRegistrar, srv DatabaseTypeServiceServer) {
s.RegisterService(&DatabaseTypeService_ServiceDesc, srv)
}
func _DatabaseTypeService_GetDatabaseType_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DatabaseTypeRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DatabaseTypeServiceServer).GetDatabaseType(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/DatabaseTypeService/GetDatabaseType",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DatabaseTypeServiceServer).GetDatabaseType(ctx, req.(*DatabaseTypeRequest))
}
return interceptor(ctx, in, info, handler)
}
// DatabaseTypeService_ServiceDesc is the grpc.ServiceDesc for DatabaseTypeService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var DatabaseTypeService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "DatabaseTypeService",
HandlerType: (*DatabaseTypeServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetDatabaseType",
Handler: _DatabaseTypeService_GetDatabaseType_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "databaseType.proto",
}
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
package rpcdriver
import (
"context"
"errors"
"schema-orchestrator/internal/drivers/rpcdriver/databaseTypeService"
"google.golang.org/grpc"
)
/*
GetDatabaseType opens a gRPC connection to the user management service and retrieves the database info for the given client and database name
clientID: *string, the ID of the client
databaseName: *string, the name of the database
Return: (*string, error), returns the type of the database and a potential error
*/
func (driver *Driver) GetDatabaseType(clientID *string, databaseName *string) (*string, error) {
conn, err := grpc.Dial("user-management-service:9000", grpc.WithInsecure())
if err != nil {
return nil, err
}
defer conn.Close()
grpcClient := databaseTypeService.NewDatabaseTypeServiceClient(conn)
response, err := grpcClient.GetDatabaseType(context.Background(), &databaseTypeService.DatabaseTypeRequest{ClientID: *clientID, DatabaseName: *databaseName})
if err != nil {
return nil, err
}
var databaseType string
switch response.DatabaseType {
case databaseTypeService.DatabaseTypeResponse_ARANGODB:
databaseType = "arangodb"
case databaseTypeService.DatabaseTypeResponse_NEO4J:
databaseType = "neo4j"
default:
return nil, errors.New("Unknown database type returned")
}
return &databaseType, nil
}
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
package rpcdriver
/*
A Driver implements the rpc driver interface
*/
type Driver struct {
}
/*
New creates a new rpc driver
*/
func New() Interface {
return &Driver{}
}
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
package rpcdriver
/*
Interface specifies the methods a rpc driver should implement
*/
type Interface interface {
GetDatabaseType(clientID *string, databaseName *string) (*string, error)
}
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
package webdriver
import "net/http"
/*
setupResponse sets up response headers for CORS
w: *http.ResponseWriter, writes the responses for http
r: *http.Request, sends the requests for http
*/
func setupResponse(w *http.ResponseWriter, r *http.Request) {
(*w).Header().Set("Access-Control-Allow-Origin", "http://127.0.0.1:3000")
(*w).Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
(*w).Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
(*w).Header().Set("Access-Control-Allow-Credentials", "true")
}
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
package webdriver
/*
A ListenerInterface models what a web listener should do
*/
type ListenerInterface interface {
Start()
SetupHandlers()
}
package webdriver
import (
"encoding/json"
"io/ioutil"
"net/http"
)
/*
Handles incoming schema requests
authService: auth.UseCase, the usecase for the authentication service
produceService: produce.UseCase, the usecase for the producer service
Return: http.Handler, returns an http handler
*/
func (l *Listener) schemaRequestHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Setup CORS
setupResponse(&w, r)
// Publish a message into the query queue
body, err := ioutil.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
// Grab the databaseName and cached bool from the request
var temp map[string]interface{}
json.Unmarshal(body, &temp)
databaseName, ok := temp["databaseName"].(string)
if !ok {
w.WriteHeader(http.StatusBadRequest)
return
}
cached, ok := temp["cached"].(bool)
if !ok {
w.WriteHeader(http.StatusBadRequest)
return
}
// Pass request to schema usecase
err = l.schemaService.Retrieve(&body, r.Header["Sessionid"][0], r.Header["Userid"][0], databaseName, cached)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
})
}
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
package webdriver
import (
"log"
"net/http"
"schema-orchestrator/internal/usecases/schema"
)
/*
A Listener is a concrete implementation for a web listener
*/
type Listener struct {
schemaService schema.UseCase
}
/*
CreateListener creates a web listener
schemaService: schema.UseCase, the schema usecase
Return: *Listener, returns a web listener
*/
func CreateListener(schemaService schema.UseCase) *Listener {
return &Listener{
schemaService: schemaService,
}
}
/*
Start starts the web listener on port 3000
*/
func (l *Listener) Start() {
log.Println("Started listening on port :3000")
http.ListenAndServe(":3000", nil)
}
/*
SetupHandlers sets up the web handlers for this listener
*/
func (l *Listener) SetupHandlers() {
log.Println("Setting up handlers")
http.Handle("/", l.schemaRequestHandler())
}
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
package entity
import (
"context"
"github.com/arangodb/go-driver"
)
/*
Document with Empty struct to retrieve all data from the DB Document
*/
type Document map[string]interface{}
/*
NodeEdgeRetriever is a function that creates a node or edge set
*/
type NodeEdgeRetriever func(context.Context, driver.Cursor, string)
/*
JSONReturnFormat is the format in which the schema will be returned, so it can be easily converted to JSON
*/
type JSONReturnFormat struct {
Nodes []Node `json:"nodes"`
Edges []Edge `json:"edges"`
}
/*
Node is a JSON format for nodes
*/
type Node struct {
Name string `json:"name"`
Attributes []Attribute `json:"attributes"`
}
/*
Edge is a JSON format for edges
*/
type Edge struct {
Name string `json:"name"`
Collection string `json:"collection"`
From string `json:"from"`
To string `json:"to"`
Attributes []Attribute `json:"attributes"`
}
/*
Attribute is a JSON format for attributes, Type should onle be one of "string", "boolean", "int", "float"
*/
type Attribute struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
}
/*
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences)
*/
package produce
/*
UseCase is an interface describing the produce usecases
*/
type UseCase interface {
ProduceSchemaRetrievalRequest(request []byte, sessionID string, clientID string, databaseName string)
ProduceCachedSchema(schema *[]byte, sessionID *string)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment