Skip to content

Commit

Permalink
add cloud core basic framework
Browse files Browse the repository at this point in the history
  • Loading branch information
veezhang committed Dec 9, 2021
1 parent cce0022 commit 02270c1
Show file tree
Hide file tree
Showing 105 changed files with 370,430 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ccore/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/vesoft-inc/nebula-http-gateway/ccore

go 1.16

require github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488
2 changes: 2 additions & 0 deletions ccore/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488 h1:A4KCT0mvTBkvb93gGN+efLPkrgTqmqMeaLDG51KVhMM=
github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488/go.mod h1:2tncLx5rmw69e5kMBv/yJneERbzrr1yr5fdlnTbu8lU=
18 changes: 18 additions & 0 deletions ccore/nebula/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package nebula

import (
"github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types"
)

type (
Version = types.Version
AuthResponse = types.AuthResponse
ExecutionResponse = types.ExecutionResponse
)

var (
V2_0_0 = types.V2_0_0
V2_5_0 = types.V2_5_0
V2_5_1 = types.V2_5_1
V2_6_0 = types.V2_6_0
)
67 changes: 67 additions & 0 deletions ccore/nebula/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package nebula

import "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types"

type (
Client interface {
Graph() GraphClient
Meta() MetaClient
StorageAdmin() StorageAdminClient
}

ConnectionInfo struct {
GraphEndpoints []string
MetaEndpoints []string
StorageAdminEndpoints []string
GraphAccount Account
}

Account struct {
Username string
Password string
}

defaultClient struct {
o Options
driver types.Driver
graph *driverGraph
meta *driverMeta
storageAdmin *driverStorageAdmin
}
)

func NewClient(info ConnectionInfo, opts ...Option) (Client, error) {
o := defaultOptions()
for _, opt := range opts {
opt(&o)
}
o.complete()
if err := o.validate(); err != nil {
return nil, err
}

driver, err := types.GetDriver(o.version)
if err != nil {
return nil, err
}

return &defaultClient{
o: o,
driver: driver,
graph: newDriverGraph(info.GraphEndpoints, info.GraphAccount.Username, info.GraphAccount.Password, &o.graph),
meta: newDriverMeta(info.MetaEndpoints, &o.meta),
storageAdmin: newDriverStorageAdmin(info.StorageAdminEndpoints, &o.storageAdmin),
}, nil
}

func (c *defaultClient) Graph() GraphClient {
return (*defaultGraphClient)(c)
}

func (c *defaultClient) Meta() MetaClient {
return (*defaultMetaClient)(c)
}

func (c *defaultClient) StorageAdmin() StorageAdminClient {
return (*defaultStorageAdminClient)(c)
}
56 changes: 56 additions & 0 deletions ccore/nebula/client_graph.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package nebula

import "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types"

type (
GraphClient interface {
Open() error
Execute(stmt []byte) (ExecutionResponse, error)
ExecuteJson(stmt []byte) ([]byte, error)
Close() error
}

defaultGraphClient defaultClient
)

func NewGraphClient(endpoints []string, username, password string, opts ...Option) (GraphClient, error) {
o := defaultOptions()
for _, opt := range opts {
opt(&o)
}
o.complete()
if err := o.validate(); err != nil {
return nil, err
}

driver, err := types.GetDriver(o.version)
if err != nil {
return nil, err
}

return &defaultGraphClient{
o: o,
driver: driver,
graph: newDriverGraph(endpoints, username, password, &o.graph),
}, nil
}

func (c *defaultGraphClient) Open() error {
return c.graph.open(c.driver)
}

func (c *defaultGraphClient) Execute(stmt []byte) (ExecutionResponse, error) {
return c.graph.Execute(c.graph.sessionId, stmt)
}

func (c *defaultGraphClient) ExecuteJson(stmt []byte) ([]byte, error) {
if err := c.graph.open(c.driver); err != nil {
return nil, err
}

return c.graph.ExecuteJson(c.graph.sessionId, stmt)
}

func (c *defaultGraphClient) Close() error {
return c.graph.open(c.driver)
}
42 changes: 42 additions & 0 deletions ccore/nebula/client_meta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package nebula

import "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types"

type (
MetaClient interface {
Open() error
Close() error
}

defaultMetaClient defaultClient
)

func NewMetaClient(endpoints []string, opts ...Option) (MetaClient, error) {
o := defaultOptions()
for _, opt := range opts {
opt(&o)
}
o.complete()
if err := o.validate(); err != nil {
return nil, err
}

driver, err := types.GetDriver(o.version)
if err != nil {
return nil, err
}

return &defaultMetaClient{
o: o,
driver: driver,
meta: newDriverMeta(endpoints, &o.meta),
}, nil
}

func (c *defaultMetaClient) Open() error {
return c.meta.open(c.driver)
}

func (c *defaultMetaClient) Close() error {
return c.meta.open(c.driver)
}
42 changes: 42 additions & 0 deletions ccore/nebula/client_storage_admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package nebula

import "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types"

type (
StorageAdminClient interface {
Open() error
Close() error
}

defaultStorageAdminClient defaultClient
)

func NewStorageAdminClient(endpoints []string, opts ...Option) (StorageAdminClient, error) {
o := defaultOptions()
for _, opt := range opts {
opt(&o)
}
o.complete()
if err := o.validate(); err != nil {
return nil, err
}

driver, err := types.GetDriver(o.version)
if err != nil {
return nil, err
}

return &defaultStorageAdminClient{
o: o,
driver: driver,
storageAdmin: newDriverStorageAdmin(endpoints, &o.storageAdmin),
}, nil
}

func (c *defaultStorageAdminClient) Open() error {
return c.storageAdmin.open(c.driver)
}

func (c *defaultStorageAdminClient) Close() error {
return c.storageAdmin.open(c.driver)
}
Loading

0 comments on commit 02270c1

Please sign in to comment.