This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang 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 1d81396 [SCB-2094] Implement mongo datasource interface (#737)
1d81396 is described below
commit 1d81396228505c1e3b4c0215dc2140cc7ee93e61
Author: xzccfzy <[email protected]>
AuthorDate: Tue Nov 10 15:01:37 2020 +0800
[SCB-2094] Implement mongo datasource interface (#737)
---
datasource/mongo/account.go | 59 +++++++++++++++
datasource/mongo/dep.go | 39 ++++++++++
datasource/mongo/engine.go | 44 +++++++++++
datasource/mongo/mongo.go | 53 +++++++++++++
datasource/mongo/ms.go | 181 ++++++++++++++++++++++++++++++++++++++++++++
datasource/mongo/system.go | 27 +++++++
6 files changed, 403 insertions(+)
diff --git a/datasource/mongo/account.go b/datasource/mongo/account.go
new file mode 100644
index 0000000..e2ab1d9
--- /dev/null
+++ b/datasource/mongo/account.go
@@ -0,0 +1,59 @@
+/*
+ * 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 mongo
+
+import (
+ "context"
+ "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+)
+
+func (ds *DataSource) AccountExist(ctx context.Context, key string) (bool,
error) {
+ return false, nil
+}
+
+func (ds *DataSource) GetAccount(ctx context.Context, key string)
(*rbacframe.Account, error) {
+ return &rbacframe.Account{}, nil
+}
+
+func (ds *DataSource) ListAccount(ctx context.Context, key string)
([]*rbacframe.Account, int64, error) {
+ return nil, 0, nil
+}
+
+func (ds *DataSource) DeleteAccount(ctx context.Context, key string) (bool,
error) {
+ return false, nil
+}
+
+func (ds *DataSource) UpdateAccount(ctx context.Context, key string, account
*rbacframe.Account) error {
+ return nil
+}
+
+func (ds *DataSource) AddDomain(ctx context.Context, domain string) (bool,
error) {
+ return false, nil
+}
+
+func (ds *DataSource) DomainExist(ctx context.Context, domain string) (bool,
error) {
+ return false, nil
+}
+
+func (ds *DataSource) AddProject(ctx context.Context, domain, project string)
(bool, error) {
+ return false, nil
+}
+
+func (ds *DataSource) ProjectExist(ctx context.Context, domain, project
string) (bool, error) {
+ return false, nil
+}
diff --git a/datasource/mongo/dep.go b/datasource/mongo/dep.go
new file mode 100644
index 0000000..0d58bd3
--- /dev/null
+++ b/datasource/mongo/dep.go
@@ -0,0 +1,39 @@
+/*
+ * 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 mongo
+
+import (
+ "context"
+ pb "github.com/apache/servicecomb-service-center/pkg/registry"
+)
+
+func (ds *DataSource) SearchProviderDependency(ctx context.Context, request
*pb.GetDependenciesRequest) (*pb.GetProDependenciesResponse, error) {
+ return &pb.GetProDependenciesResponse{}, nil
+}
+
+func (ds *DataSource) SearchConsumerDependency(ctx context.Context, request
*pb.GetDependenciesRequest) (*pb.GetConDependenciesResponse, error) {
+ return &pb.GetConDependenciesResponse{}, nil
+}
+
+func (ds *DataSource) AddOrUpdateDependencies(ctx context.Context,
dependencyInfos []*pb.ConsumerDependency, override bool) (*pb.Response, error) {
+ return pb.CreateResponse(pb.ResponseSuccess, ""), nil
+}
+
+func (ds *DataSource) DeleteDependency() {
+ panic("implement me")
+}
diff --git a/datasource/mongo/engine.go b/datasource/mongo/engine.go
new file mode 100644
index 0000000..3d35663
--- /dev/null
+++ b/datasource/mongo/engine.go
@@ -0,0 +1,44 @@
+/*
+ * 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 mongo
+
+import (
+ "context"
+ "github.com/apache/servicecomb-service-center/pkg/cluster"
+ "time"
+)
+
+func (ds *DataSource) SelfRegister(ctx context.Context) error {
+ return nil
+}
+func (ds *DataSource) SelfUnregister(ctx context.Context) error {
+ return nil
+}
+
+// OPS
+func (ds *DataSource) ClearNoInstanceServices(ctx context.Context, ttl
time.Duration) error {
+ return nil
+}
+
+func (ds *DataSource) UpgradeVersion(ctx context.Context) error {
+ return nil
+}
+
+func (ds *DataSource) GetClusters(ctx context.Context) (cluster.Clusters,
error) {
+ return nil, nil
+}
diff --git a/datasource/mongo/mongo.go b/datasource/mongo/mongo.go
new file mode 100644
index 0000000..a6c9d15
--- /dev/null
+++ b/datasource/mongo/mongo.go
@@ -0,0 +1,53 @@
+/*
+ * 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 mongo
+
+import (
+ "github.com/apache/servicecomb-service-center/datasource"
+ "github.com/apache/servicecomb-service-center/pkg/log"
+)
+
+func init() {
+ datasource.Install("mongo", NewDataSource)
+}
+
+type DataSource struct {
+ // SchemaEditable determines whether schema modification is allowed for
+ SchemaEditable bool
+ // TTL options
+ ttlFromEnv int64
+}
+
+func NewDataSource(opts datasource.Options) (datasource.DataSource, error) {
+ // TODO: construct a reasonable DataSource instance
+ log.Warnf("dependency data source enable etcd mode")
+
+ inst := &DataSource{
+ SchemaEditable: opts.SchemaEditable,
+ ttlFromEnv: opts.TTL,
+ }
+ // TODO: deal with exception
+ if err := inst.initialize(); err != nil {
+ return nil, err
+ }
+ return inst, nil
+}
+
+func (ds *DataSource) initialize() error {
+ return nil
+}
diff --git a/datasource/mongo/ms.go b/datasource/mongo/ms.go
new file mode 100644
index 0000000..88878d6
--- /dev/null
+++ b/datasource/mongo/ms.go
@@ -0,0 +1,181 @@
+/*
+ * 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 request 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 request 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 mongo
+
+import (
+ "context"
+ pb "github.com/apache/servicecomb-service-center/pkg/registry"
+)
+
+func (ds *DataSource) RegisterService(ctx context.Context, request
*pb.CreateServiceRequest) (
+ *pb.CreateServiceResponse, error) {
+ return &pb.CreateServiceResponse{}, nil
+}
+
+func (ds *DataSource) GetServices(ctx context.Context, request
*pb.GetServicesRequest) (*pb.GetServicesResponse, error) {
+ return &pb.GetServicesResponse{}, nil
+}
+
+func (ds *DataSource) GetService(ctx context.Context, request
*pb.GetServiceRequest) (*pb.GetServiceResponse, error) {
+ return &pb.GetServiceResponse{}, nil
+}
+
+func (ds *DataSource) GetServiceDetail(ctx context.Context, request
*pb.GetServiceRequest) (*pb.GetServiceDetailResponse, error) {
+ return &pb.GetServiceDetailResponse{}, nil
+}
+
+func (ds *DataSource) GetServicesInfo(ctx context.Context, request
*pb.GetServicesInfoRequest) (*pb.GetServicesInfoResponse, error) {
+ return &pb.GetServicesInfoResponse{}, nil
+}
+
+func (ds *DataSource) GetApplications(ctx context.Context, request
*pb.GetAppsRequest) (*pb.GetAppsResponse, error) {
+ return &pb.GetAppsResponse{}, nil
+}
+
+func (ds *DataSource) ExistServiceByID(ctx context.Context, request
*pb.GetExistenceByIDRequest) (*pb.GetExistenceByIDResponse, error) {
+ return &pb.GetExistenceByIDResponse{}, nil
+}
+
+func (ds *DataSource) ExistService(ctx context.Context, request
*pb.GetExistenceRequest) (*pb.GetExistenceResponse, error) {
+ return &pb.GetExistenceResponse{}, nil
+}
+
+func (ds *DataSource) UpdateService(ctx context.Context, request
*pb.UpdateServicePropsRequest) (*pb.UpdateServicePropsResponse, error) {
+ return &pb.UpdateServicePropsResponse{}, nil
+}
+
+func (ds *DataSource) UnregisterService(ctx context.Context, request
*pb.DeleteServiceRequest) (*pb.DeleteServiceResponse, error) {
+ return &pb.DeleteServiceResponse{}, nil
+}
+
+func (ds *DataSource) GetDeleteServiceFunc(ctx context.Context, serviceID
string, force bool, serviceRespChan chan<- *pb.DelServicesRspInfo)
func(context.Context) {
+ return func(_ context.Context) {
+
+ }
+}
+
+// Instance management
+func (ds *DataSource) RegisterInstance(ctx context.Context, request
*pb.RegisterInstanceRequest) (*pb.RegisterInstanceResponse, error) {
+ return &pb.RegisterInstanceResponse{}, nil
+}
+
+// GetInstances returns instances under the current domain
+func (ds *DataSource) GetInstance(ctx context.Context, request
*pb.GetOneInstanceRequest) (*pb.GetOneInstanceResponse, error) {
+ return &pb.GetOneInstanceResponse{}, nil
+}
+
+func (ds *DataSource) GetInstances(ctx context.Context, request
*pb.GetInstancesRequest) (*pb.GetInstancesResponse, error) {
+ return &pb.GetInstancesResponse{}, nil
+}
+
+// GetProviderInstances returns instances under the specified domain
+func (ds *DataSource) GetProviderInstances(ctx context.Context, request
*pb.HeartbeatSetElement) (instances []*pb.MicroServiceInstance, rev string, err
error) {
+ return nil, "", nil
+}
+
+func (ds *DataSource) BatchGetProviderInstances(ctx context.Context, request
*pb.BatchGetInstancesRequest) (instances []*pb.MicroServiceInstance, rev
string, err error) {
+ return nil, "", nil
+}
+
+// FindInstances returns instances under the specified domain
+func (ds *DataSource) FindInstances(ctx context.Context, request
*pb.FindInstancesRequest) (*pb.FindInstancesResponse, error) {
+ return &pb.FindInstancesResponse{}, nil
+}
+
+func (ds *DataSource) UpdateInstanceStatus(ctx context.Context, request
*pb.UpdateInstanceStatusRequest) (*pb.UpdateInstanceStatusResponse, error) {
+ return &pb.UpdateInstanceStatusResponse{}, nil
+}
+
+func (ds *DataSource) UpdateInstanceProperties(ctx context.Context, request
*pb.UpdateInstancePropsRequest) (*pb.UpdateInstancePropsResponse, error) {
+ return &pb.UpdateInstancePropsResponse{}, nil
+}
+
+func (ds *DataSource) UnregisterInstance(ctx context.Context, request
*pb.UnregisterInstanceRequest) (*pb.UnregisterInstanceResponse, error) {
+ return &pb.UnregisterInstanceResponse{}, nil
+}
+
+func (ds *DataSource) Heartbeat(ctx context.Context, request
*pb.HeartbeatRequest) (*pb.HeartbeatResponse, error) {
+ return &pb.HeartbeatResponse{}, nil
+}
+
+func (ds *DataSource) HeartbeatSet(ctx context.Context, request
*pb.HeartbeatSetRequest) (*pb.HeartbeatSetResponse, error) {
+ return &pb.HeartbeatSetResponse{}, nil
+}
+
+func (ds *DataSource) BatchFind(ctx context.Context, request
*pb.BatchFindInstancesRequest) (*pb.BatchFindInstancesResponse, error) {
+ return &pb.BatchFindInstancesResponse{}, nil
+}
+
+// Schema management
+func (ds *DataSource) ModifySchemas(ctx context.Context, request
*pb.ModifySchemasRequest) (*pb.ModifySchemasResponse, error) {
+ return &pb.ModifySchemasResponse{}, nil
+}
+
+func (ds *DataSource) ModifySchema(ctx context.Context, request
*pb.ModifySchemaRequest) (*pb.ModifySchemaResponse, error) {
+ return &pb.ModifySchemaResponse{}, nil
+}
+
+func (ds *DataSource) ExistSchema(ctx context.Context, request
*pb.GetExistenceRequest) (*pb.GetExistenceResponse, error) {
+ return &pb.GetExistenceResponse{}, nil
+}
+
+func (ds *DataSource) GetSchema(ctx context.Context, request
*pb.GetSchemaRequest) (*pb.GetSchemaResponse, error) {
+ return &pb.GetSchemaResponse{}, nil
+}
+
+func (ds *DataSource) GetAllSchemas(ctx context.Context, request
*pb.GetAllSchemaRequest) (*pb.GetAllSchemaResponse, error) {
+ return &pb.GetAllSchemaResponse{}, nil
+}
+
+func (ds *DataSource) DeleteSchema(ctx context.Context, request
*pb.DeleteSchemaRequest) (*pb.DeleteSchemaResponse, error) {
+ return &pb.DeleteSchemaResponse{}, nil
+}
+
+// Tag management
+func (ds *DataSource) AddTags(ctx context.Context, request
*pb.AddServiceTagsRequest) (*pb.AddServiceTagsResponse, error) {
+ return &pb.AddServiceTagsResponse{}, nil
+}
+
+func (ds *DataSource) GetTags(ctx context.Context, request
*pb.GetServiceTagsRequest) (*pb.GetServiceTagsResponse, error) {
+ return &pb.GetServiceTagsResponse{}, nil
+}
+
+func (ds *DataSource) UpdateTag(ctx context.Context, request
*pb.UpdateServiceTagRequest) (*pb.UpdateServiceTagResponse, error) {
+ return &pb.UpdateServiceTagResponse{}, nil
+}
+
+func (ds *DataSource) DeleteTags(ctx context.Context, request
*pb.DeleteServiceTagsRequest) (*pb.DeleteServiceTagsResponse, error) {
+ return &pb.DeleteServiceTagsResponse{}, nil
+}
+
+// White/black list management
+func (ds *DataSource) AddRule(ctx context.Context, request
*pb.AddServiceRulesRequest) (*pb.AddServiceRulesResponse, error) {
+ return &pb.AddServiceRulesResponse{}, nil
+}
+
+func (ds *DataSource) GetRule(ctx context.Context, request
*pb.GetServiceRulesRequest) (*pb.GetServiceRulesResponse, error) {
+ return &pb.GetServiceRulesResponse{}, nil
+}
+
+func (ds *DataSource) UpdateRule(ctx context.Context, request
*pb.UpdateServiceRuleRequest) (*pb.UpdateServiceRuleResponse, error) {
+ return &pb.UpdateServiceRuleResponse{}, nil
+}
+
+func (ds *DataSource) DeleteRule(ctx context.Context, request
*pb.DeleteServiceRulesRequest) (*pb.DeleteServiceRulesResponse, error) {
+ return &pb.DeleteServiceRulesResponse{}, nil
+}
diff --git a/datasource/mongo/system.go b/datasource/mongo/system.go
new file mode 100644
index 0000000..8ef2add
--- /dev/null
+++ b/datasource/mongo/system.go
@@ -0,0 +1,27 @@
+/*
+ * 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 mongo
+
+import (
+ "context"
+ "github.com/apache/servicecomb-service-center/pkg/dump"
+)
+
+func (ds *DataSource) DumpCache(ctx context.Context, cache *dump.Cache) {
+
+}