You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2021/12/08 13:41:10 UTC

[servicecomb-service-center] branch master updated: [feat] add eventbase (#1175)

This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e3e608  [feat] add eventbase (#1175)
6e3e608 is described below

commit 6e3e60889dc8b541f4f91b70934df834d5b7ab93
Author: robotljw <79...@qq.com>
AuthorDate: Wed Dec 8 21:41:02 2021 +0800

    [feat] add eventbase (#1175)
    
    1.add datasource in eventbase
---
 eventbase/datasource/datasource.go   | 24 +++++++++++
 eventbase/datasource/manager.go      | 84 ++++++++++++++++++++++++++++++++++++
 eventbase/datasource/options.go      | 68 +++++++++++++++++++++++++++++
 eventbase/datasource/task.go         | 33 ++++++++++++++
 eventbase/datasource/tombstone.go    | 35 +++++++++++++++
 eventbase/go.mod                     |  8 ++++
 eventbase/go.sum                     | 18 ++++++++
 eventbase/model/tombstone_request.go | 26 +++++++++++
 go.mod                               |  2 +-
 go.sum                               |  4 +-
 10 files changed, 299 insertions(+), 3 deletions(-)

diff --git a/eventbase/datasource/datasource.go b/eventbase/datasource/datasource.go
new file mode 100644
index 0000000..3f90469
--- /dev/null
+++ b/eventbase/datasource/datasource.go
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package datasource
+
+// DataSource is the DAO layer
+type DataSource interface {
+	TaskDao() TaskDao
+	TombstoneDao() TombstoneDao
+}
diff --git a/eventbase/datasource/manager.go b/eventbase/datasource/manager.go
new file mode 100644
index 0000000..215d322
--- /dev/null
+++ b/eventbase/datasource/manager.go
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package datasource
+
+import (
+	"fmt"
+	"time"
+
+	"github.com/go-chassis/cari/db"
+	"github.com/go-chassis/openlog"
+)
+
+const (
+	DefaultTimeout = 60 * time.Second
+	DefaultDBKind  = "embedded_etcd"
+)
+
+var (
+	dataSourceInst DataSource
+	plugins        = make(map[string]dataSourceEngine)
+)
+
+type dataSourceEngine func(c *db.Config) (DataSource, error)
+
+func GetDataSource() DataSource {
+	return dataSourceInst
+}
+
+func RegisterPlugin(name string, engineFunc dataSourceEngine) {
+	plugins[name] = engineFunc
+}
+
+func Init(c db.Config) error {
+	var err error
+	if c.Kind == "" {
+		c.Kind = DefaultDBKind
+	}
+	f, ok := plugins[c.Kind]
+	if !ok {
+		return fmt.Errorf("do not support %s", c.Kind)
+	}
+	if c.Timeout == 0 {
+		c.Timeout = DefaultTimeout
+	}
+	dbc := &db.Config{
+		URI:         c.URI,
+		PoolSize:    c.PoolSize,
+		SSLEnabled:  c.SSLEnabled,
+		RootCA:      c.RootCA,
+		CertFile:    c.CertFile,
+		CertPwdFile: c.CertPwdFile,
+		KeyFile:     c.KeyFile,
+		Timeout:     c.Timeout,
+	}
+
+	if dataSourceInst, err = f(dbc); err != nil {
+		return err
+	}
+	openlog.Info(fmt.Sprintf("use %s as storage", c.Kind))
+	return nil
+}
+
+func GetTaskDao() TaskDao {
+	return dataSourceInst.TaskDao()
+}
+
+func GetTombstoneDao() TombstoneDao {
+	return dataSourceInst.TombstoneDao()
+}
diff --git a/eventbase/datasource/options.go b/eventbase/datasource/options.go
new file mode 100644
index 0000000..236b166
--- /dev/null
+++ b/eventbase/datasource/options.go
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package datasource
+
+type TaskFindOptions struct {
+	Action   string
+	Status   string
+	DataType string
+}
+
+type TombstoneFindOptions struct {
+	ResourceType    string
+	BeforeTimestamp int64
+}
+
+type TaskFindOption func(options *TaskFindOptions)
+
+type TombstoneFindOption func(options *TombstoneFindOptions)
+
+// WithAction find task with action
+func WithAction(action string) TaskFindOption {
+	return func(options *TaskFindOptions) {
+		options.Action = action
+	}
+}
+
+// WithStatus find task with status
+func WithStatus(status string) TaskFindOption {
+	return func(options *TaskFindOptions) {
+		options.Status = status
+	}
+}
+
+// WithDataType find task with dataType
+func WithDataType(dataType string) TaskFindOption {
+	return func(options *TaskFindOptions) {
+		options.DataType = dataType
+	}
+}
+
+// WithResourceType find tombstone with resource type
+func WithResourceType(resourceType string) TombstoneFindOption {
+	return func(options *TombstoneFindOptions) {
+		options.ResourceType = resourceType
+	}
+}
+
+// WithBeforeTimestamp find tombstone with beforeTimestamp
+func WithBeforeTimestamp(timestamp int64) TombstoneFindOption {
+	return func(options *TombstoneFindOptions) {
+		options.BeforeTimestamp = timestamp
+	}
+}
diff --git a/eventbase/datasource/task.go b/eventbase/datasource/task.go
new file mode 100644
index 0000000..f299109
--- /dev/null
+++ b/eventbase/datasource/task.go
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package datasource
+
+import (
+	"context"
+
+	"github.com/go-chassis/cari/sync"
+)
+
+// TaskDao provide api of Task entity
+type TaskDao interface {
+	// Create func is used for ut
+	Create(ctx context.Context, task *sync.Task) (*sync.Task, error)
+	Update(ctx context.Context, task *sync.Task) error
+	Delete(ctx context.Context, tasks ...*sync.Task) error
+	List(ctx context.Context, domain string, project string, options ...TaskFindOption) ([]*sync.Task, error)
+}
diff --git a/eventbase/datasource/tombstone.go b/eventbase/datasource/tombstone.go
new file mode 100644
index 0000000..f57effb
--- /dev/null
+++ b/eventbase/datasource/tombstone.go
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package datasource
+
+import (
+	"context"
+
+	"github.com/go-chassis/cari/sync"
+
+	"servicecomb-service-center/eventbase/model"
+)
+
+// TombstoneDao provide api of Tombstone entity
+type TombstoneDao interface {
+	Get(ctx context.Context, req *model.GetTombstoneRequest) (*sync.Tombstone, error)
+	// Create func is used for ut
+	Create(ctx context.Context, tombstone *sync.Tombstone) (*sync.Tombstone, error)
+	Delete(ctx context.Context, tombstone ...*sync.Tombstone) error
+	List(ctx context.Context, domain string, project string, options ...TombstoneFindOptions) ([]*sync.Tombstone, error)
+}
diff --git a/eventbase/go.mod b/eventbase/go.mod
new file mode 100644
index 0000000..8c0e230
--- /dev/null
+++ b/eventbase/go.mod
@@ -0,0 +1,8 @@
+module servicecomb-service-center/eventbase
+
+require (
+	github.com/go-chassis/cari v0.5.1-0.20211208092532-78a52aa9d52e
+	github.com/go-chassis/openlog v1.1.3
+)
+
+go 1.17
diff --git a/eventbase/go.sum b/eventbase/go.sum
new file mode 100644
index 0000000..cf859ad
--- /dev/null
+++ b/eventbase/go.sum
@@ -0,0 +1,18 @@
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
+github.com/go-chassis/cari v0.5.1-0.20211208092532-78a52aa9d52e h1:6z88U255Sm/Ds10uT7ZqYomKLanDzTWxseDBITONFhk=
+github.com/go-chassis/cari v0.5.1-0.20211208092532-78a52aa9d52e/go.mod h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
+github.com/go-chassis/openlog v1.1.3 h1:XqIOvZ8YPJ9o9lLtLBskQNNWolK5kC6a4Sv7r4s9sZ4=
+github.com/go-chassis/openlog v1.1.3/go.mod h1:+eYCADVxWyJkwsFMUBrMxyQlNqW+UUsCxvR2LrYZUaA=
+github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
+github.com/karlseguin/ccache/v2 v2.0.8/go.mod h1:2BDThcfQMf/c0jnZowt16eW405XIqZPavt+HoYEtcxQ=
+github.com/karlseguin/expect v1.0.2-0.20190806010014-778a5f0c6003/go.mod h1:zNBxMY8P21owkeogJELCLeHIt+voOSduHYTFUbwRAV8=
+github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
+github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0/go.mod h1:IXCdmsXIht47RaVFLEdVnh1t+pgYtTAhQGj73kz+2DM=
+golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/eventbase/model/tombstone_request.go b/eventbase/model/tombstone_request.go
new file mode 100644
index 0000000..1e77f62
--- /dev/null
+++ b/eventbase/model/tombstone_request.go
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package model
+
+// GetTombstoneRequest contains tombstone get request params
+type GetTombstoneRequest struct {
+	Project      string `json:"project,omitempty" yaml:"project,omitempty"`
+	Domain       string `json:"domain,omitempty" yaml:"domain,omitempty"`
+	ResourceType string `json:"resource_type,omitempty" yaml:"resource_type,omitempty"`
+	ResourceID   string `json:"resource_id,omitempty" yaml:"resource_id,omitempty"`
+}
diff --git a/go.mod b/go.mod
index 28cb4f7..94afd9b 100644
--- a/go.mod
+++ b/go.mod
@@ -13,7 +13,7 @@ require (
 	github.com/deckarep/golang-set v1.7.1
 	github.com/elithrar/simple-scrypt v1.3.0
 	github.com/ghodss/yaml v1.0.0
-	github.com/go-chassis/cari v0.5.1-0.20211124031617-99bda218b0cf
+	github.com/go-chassis/cari v0.5.1-0.20211208092532-78a52aa9d52e
 	github.com/go-chassis/foundation v0.3.1-0.20210811025651-7f4d2b2b906c
 	github.com/go-chassis/go-archaius v1.5.1
 	github.com/go-chassis/go-chassis-extension/protocol/grpc v0.0.0-20210902082902-eb5df922afcd
diff --git a/go.sum b/go.sum
index c49fa85..836ac22 100644
--- a/go.sum
+++ b/go.sum
@@ -179,8 +179,8 @@ github.com/go-chassis/cari v0.0.0-20201210041921-7b6fbef2df11/go.mod h1:MgtsEI0A
 github.com/go-chassis/cari v0.4.0/go.mod h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
 github.com/go-chassis/cari v0.5.0/go.mod h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
 github.com/go-chassis/cari v0.5.1-0.20210823023004-74041d1363c4/go.mod h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
-github.com/go-chassis/cari v0.5.1-0.20211124031617-99bda218b0cf h1:870QYgkSLFhpqGA8YuCRPazgdAKP4oqs5vs09A6d/gE=
-github.com/go-chassis/cari v0.5.1-0.20211124031617-99bda218b0cf/go.mod h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
+github.com/go-chassis/cari v0.5.1-0.20211208092532-78a52aa9d52e h1:6z88U255Sm/Ds10uT7ZqYomKLanDzTWxseDBITONFhk=
+github.com/go-chassis/cari v0.5.1-0.20211208092532-78a52aa9d52e/go.mod h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
 github.com/go-chassis/foundation v0.2.2-0.20201210043510-9f6d3de40234/go.mod h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=
 github.com/go-chassis/foundation v0.2.2/go.mod h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=
 github.com/go-chassis/foundation v0.3.0/go.mod h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=