Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
query-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GraphPolaris
Microservices
query-service
Commits
082d9e2b
Commit
082d9e2b
authored
7 months ago
by
Samed
Browse files
Options
Downloads
Patches
Plain Diff
Test commit
parent
8dc974b2
No related branches found
No related tags found
No related merge requests found
Pipeline
#138004
passed
7 months ago
Stage: tag-release
Stage: get-release-tag
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/query-service/main.go
+42
-0
42 additions, 0 deletions
cmd/query-service/main.go
with
42 additions
and
0 deletions
cmd/query-service/main.go
+
42
−
0
View file @
082d9e2b
...
@@ -6,12 +6,14 @@ This program has been developed by students from the bachelor Computer Science a
...
@@ -6,12 +6,14 @@ This program has been developed by students from the bachelor Computer Science a
package
main
package
main
import
(
import
(
"encoding/json"
"net/http"
"net/http"
"os"
"os"
"query-service/internal/usecases/consume"
"query-service/internal/usecases/consume"
"query-service/internal/usecases/produce"
"query-service/internal/usecases/produce"
"git.science.uu.nl/graphpolaris/go-common/microservice"
"git.science.uu.nl/graphpolaris/go-common/microservice"
"git.science.uu.nl/graphpolaris/go-common/structs/v1/models"
"git.science.uu.nl/graphpolaris/query-conversion"
"git.science.uu.nl/graphpolaris/query-conversion"
"git.science.uu.nl/graphpolaris/query-conversion/cypherv2"
"git.science.uu.nl/graphpolaris/query-conversion/cypherv2"
queryexecution
"git.science.uu.nl/graphpolaris/query-execution"
queryexecution
"git.science.uu.nl/graphpolaris/query-execution"
...
@@ -65,10 +67,50 @@ func main() {
...
@@ -65,10 +67,50 @@ func main() {
go
consumeService
.
Start
()
go
consumeService
.
Start
()
http
.
HandleFunc
(
"/execute-cypher-query"
,
handleExecuteCypherQuery
(
queryExecutor
))
// Expose /metrics endpoint for prometheus
// Expose /metrics endpoint for prometheus
log
.
Info
()
.
Int
(
"port"
,
8080
)
.
Msg
(
"starting prometheus metrics server"
)
log
.
Info
()
.
Int
(
"port"
,
8080
)
.
Msg
(
"starting prometheus metrics server"
)
http
.
Handle
(
"/metrics"
,
promhttp
.
Handler
())
http
.
Handle
(
"/metrics"
,
promhttp
.
Handler
())
http
.
ListenAndServe
(
":8080"
,
nil
)
http
.
ListenAndServe
(
":8080"
,
nil
)
select
{}
select
{}
}
}
func
handleExecuteCypherQuery
(
queryExecutor
queryexecution
.
Executor
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Info
()
.
Msg
(
"Received request to execute Cypher query"
)
if
r
.
Method
==
http
.
MethodPost
{
var
req
struct
{
Query
string
`json:"query"`
}
if
err
:=
json
.
NewDecoder
(
r
.
Body
)
.
Decode
(
&
req
);
err
!=
nil
{
log
.
Error
()
.
Err
(
err
)
.
Msg
(
"Failed to decode request payload"
)
http
.
Error
(
w
,
"Invalid request payload"
,
http
.
StatusBadRequest
)
return
}
log
.
Info
()
.
Str
(
"query"
,
req
.
Query
)
.
Msg
(
"Executing query"
)
result
,
err
:=
queryExecutor
.
ExecuteQuery
(
req
.
Query
,
&
models
.
DBConnectionModel
{
URL
:
"demo.neo4jlabs.com"
,
Protocol
:
"neo4j+s://"
,
Port
:
7687
,
Username
:
"movies"
,
Password
:
"fire$10"
,
//not sure what the password was
InternalDatabaseName
:
"movies"
,
Type
:
models
.
Neo4j
,
})
if
err
!=
nil
{
log
.
Error
()
.
Err
(
err
)
.
Msg
(
"Query execution failed"
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
Write
(
*
result
)
}
else
{
log
.
Error
()
.
Msg
(
"Invalid request method"
)
http
.
Error
(
w
,
"Invalid request method"
,
http
.
StatusMethodNotAllowed
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment