Browse Source

fix comment

lijian 3 years ago
parent
commit
a95025c69d

+ 0 - 0
install_production.sh


+ 1 - 1
pkg/generator/key_gen_test.go

@@ -9,7 +9,7 @@ func TestKeyGen(t *testing.T) {
 	if err == nil {
 		t.Error("should return error when key length is invalid")
 	}
-	 testid := "lijian"
+	 testid := "1ps9djpivy0cdrkuofw86083000jfcet"
 	generator, err = NewKeyGenerator("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP")
 	if err != nil {
 		t.Fatal(err)

+ 4 - 4
pkg/protocol/message.go

@@ -60,13 +60,13 @@ func (a *Message) Decode(data []byte) error {
 
 // IMessageCallBack message call back
 type IMessageCallBack interface {
-	// on success do sth.
+	// OnSuccess on success do sth.
 	OnSuccess()
-	// on failure do sth.
+	// OnFailure on failure do sth.
 	OnFailure(err error)
-	// on process start do sth.
+	// OnProcessingStart on process start do sth.
 	OnProcessingStart(ruleNodeInfo *RuleNodeInfo)
-	// on process end do sth.
+	// OnProcessingEnd on process end do sth.
 	OnProcessingEnd(ruleNodeId string)
 }
 

+ 10 - 10
pkg/ruleEngine/actor_system.go

@@ -110,25 +110,25 @@ func (s *SystemContext) TellWithHighPriority(msg protocol.ActorMsg) {
 
 // System actor system interface
 type System interface {
-	// 创建分发器
+	// CreateDispatcher 创建分发器
 	CreateDispatcher(name string, dispatcher IDispatcher) error
-	// 销毁分发器
+	// DestroyDispatcher 销毁分发器
 	DestroyDispatcher(name string) error
-	// 获取一个actor ref
+	// GetActor 获取一个actor ref
 	GetActor(actorId string) Ref
-	// create root actor
+	// CreateRootActor create root actor
 	CreateRootActor(dispatcherName string, creator Creator) (Ref, error)
-	// create child actor by parent actor
+	// CreateChildActor create child actor by parent actor
 	CreateChildActor(dispatcherName string, creator Creator, parentId string) (Ref, error)
-	// tell actor a message
+	// Tell tell actor a message
 	Tell(actorId string, msg protocol.ActorMsg) error
-	// tell actor message with high priority
+	// TellWithHighPriority tell actor message with high priority
 	TellWithHighPriority(actorId string, msg protocol.ActorMsg) error
-	// stop actor by actor id
+	// StopActorById stop actor by actor id
 	StopActorById(actorId string) error
-	// stop actor by actor ref
+	// StopActorByRef stop actor by actor ref
 	StopActorByRef(ref Ref) error
-	// broadcast message to children
+	// BroadcastToChildren broadcast message to children
 	BroadcastToChildren(parentActorId string, msg protocol.ActorMsg) error
 }
 

+ 5 - 5
pkg/ruleEngine/rule_chain_service.go

@@ -1,15 +1,15 @@
 package ruleEngine
 
 type RuleChainService interface {
-	// 根据id查询规则链数据
+	// FindRuleChainById 根据id查询规则链数据
 	FindRuleChainById(tenantId, ruleChainId string) (*RuleChain, error)
-	// 根据id查询规则节点数据
+	// FindRuleNodeById 根据id查询规则节点数据
 	FindRuleNodeById(tenantId, ruleNodeId string) (*RuleNode, error)
-	// 查询规则链的节点列表
+	// GetRuleChainNodes 查询规则链的节点列表
 	GetRuleChainNodes(tenantId, ruleChainId string) ([]*RuleNode, error)
-	// 查询租户的全部规则链
+	// FindRuleChains 查询租户的全部规则链
 	FindRuleChains(tenantId string) ([]*RuleChain, error)
-	// 查询节点的连接关系列表
+	// GetRuleNodeRelations 查询节点的连接关系列表
 	GetRuleNodeRelations(tenantId, nodeId string) ([]*Relation, error)
 }
 

+ 2 - 2
pkg/ruleEngine/tenant_service.go

@@ -17,7 +17,7 @@ type TestTenantService struct {
 func (t *TestTenantService) FindTenants() ([]*Tenant, error) {
 	return []*Tenant{
 		{
-			Id:   "4jnh0r0hrl0c5a8mmecuoew200o32b8g",
+			Id:   "1ps9djpswi0cds7cofynkso300eql4iu",
 			Name: "测试租户",
 		},
 	}, nil
@@ -25,7 +25,7 @@ func (t *TestTenantService) FindTenants() ([]*Tenant, error) {
 
 func (t *TestTenantService) GetTenant(tId string) (*Tenant, error) {
 	return &Tenant{
-		Id:   "4jnh0r0hrl0c5a8mmecuoew200o32b8g",
+		Id:   "1ps9djpswi0cds7cofynkso300eql4iu",
 		Name: "测试租户",
 	}, nil
 }

+ 4 - 6
pkg/server/rpc_client.go

@@ -6,8 +6,6 @@ import (
 	"math/rand"
 	"net/rpc"
 	"time"
-
-	"github.com/opentracing/opentracing-go"
 )
 
 type RPCClient struct {
@@ -42,8 +40,8 @@ func rpcCallWithReconnect(client *rpc.Client, addr string, serverMethod string,
 }
 
 // RPC call with reconnect and retry.
-func (client *RPCClient) Call(span opentracing.Span, severName string, serverMethod string, args interface{}, reply interface{}) error {
-	defer span.Finish()
+func (client *RPCClient) Call(severName string, serverMethod string, args interface{}, reply interface{}) error {
+	// defer span.Finish()
 	addrs, err := serverInstance.svrmgr.GetServerHosts(severName, FlagRPCHost)
 	if err != nil {
 		return err
@@ -63,8 +61,8 @@ func (client *RPCClient) Call(span opentracing.Span, severName string, serverMet
 				continue
 			}
 		}
-		span.SetTag("server.method", serverMethod)
-		span.SetTag("server.addr", addr)
+		//span.SetTag("server.method", serverMethod)
+		//span.SetTag("server.addr", addr)
 		err = rpcCallWithReconnect(client.clients[mapkey], addr, serverMethod, args, reply)
 		if err != nil {
 			Log.WithField("method", serverMethod).Warnf("RpcCallWithReconnect error : %s", err)

+ 15 - 15
pkg/server/server.go

@@ -9,7 +9,6 @@ package server
 import (
 	"context"
 	"github.com/opentracing/opentracing-go"
-	"github.com/opentracing/opentracing-go/log"
 	// "github.com/vharitonsky/iniflags"
 	"flag"
 	"net/http"
@@ -188,20 +187,21 @@ func RPCCallByName(ctx context.Context, serverName string, serverMethod string,
 	if serverInstance == nil {
 		return errorf(errServerNotInit)
 	}
-	var span opentracing.Span
-
-	if ctx != nil {
-		sp := opentracing.SpanFromContext(ctx)
-		span = opentracing.StartSpan(serverName, opentracing.ChildOf(sp.Context()))
-
-	} else {
-		span = opentracing.StartSpan(serverName)
-	}
-	span.LogFields(
-		log.Object("args", args),
-	)
-	span.SetTag("server.name", serverName)
-	return serverInstance.rpccli.Call(span, serverName, serverMethod, args, reply)
+	//var span opentracing.Span
+	//
+	//if ctx != nil {
+	//	sp := opentracing.SpanFromContext(ctx)
+	//	if sp != nil {
+	//		span = opentracing.StartSpan(serverName, opentracing.ChildOf(sp.Context()))
+	//	}
+	//} else {
+	//	span = opentracing.StartSpan(serverName)
+	//}
+	//span.LogFields(
+	//	log.Object("args", args),
+	//)
+	//span.SetTag("server.name", serverName)
+	return serverInstance.rpccli.Call(serverName, serverMethod, args, reply)
 }
 
 // RPCCallByHost rpc call by host

+ 2 - 2
run.sh

@@ -5,13 +5,13 @@ sudo killall -9 httpaccess registry apiprovider devicemanager controller mqttacc
 # start services
 #$GOPATH/bin/httpaccess -etcd http://localhost:2379 -httphost internal:443 -loglevel debug -usehttps -keyfile $GOPATH/src/github.com/PandoCloud/pando-cloud/pkg/server/testdata/key.pem -cafile $GOPATH/src/github.com/PandoCloud/pando-cloud/pkg/server/testdata/cert.pem &
 $GOPATH/bin/httpaccess -etcd http://127.0.0.1:2379 -httphost internal:8088 -loglevel $LEVEL &
-$GOPATH/bin/registry -etcd http://127.0.0.1:2379 -rpchost internal:20034 -aeskey ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP -dbhost 39.98.250.155 -dbname gxt-iot-db -dbport 3306 -dbuser root -dbpass gEkYDPloQcp93t4WHr3X -loglevel $LEVEL &
+$GOPATH/bin/registry -etcd http://127.0.0.1:2379 -rpchost internal:20034 -aeskey ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP -dbhost 106.14.63.46 -dbname iot-hub -dbport 3306 -dbuser root -dbpass Lijian405! -loglevel $LEVEL &
 $GOPATH/bin/apiprovider -etcd http://127.0.0.1:2379 -loglevel $LEVEL  -httphost internal:8888 &
 $GOPATH/bin/devicemanager -etcd http://127.0.0.1:2379 -loglevel $LEVEL  -rpchost internal:20033 &
 $GOPATH/bin/controller -etcd http://127.0.0.1:2379 -loglevel $LEVEL  -rpchost internal:20032  &
 #$GOPATH/bin/mqttaccess -etcd http://localhost:2379 -loglevel debug  -rpchost localhost:20030 -tcphost internal:1883 -usetls -keyfile $GOPATH/src/github.com/PandoCloud/pando-cloud/pkg/server/testdata/key.pem -cafile $GOPATH/src/github.com/PandoCloud/pando-cloud/pkg/server/testdata/cert.pem &
 $GOPATH/bin/mqttaccess -etcd http://127.0.0.1:2379 -loglevel $LEVEL  -rpchost internal:20030 -tcphost internal:1883 &
-$GOPATH/bin/knowoapi -etcd http://127.0.0.1:2379 -loglevel $LEVEL  -httphost internal:8889 -dbhost 39.98.250.155 -dbname gxt-iot-db -dbport 3306 -dbuser root -dbpass gEkYDPloQcp93t4WHr3X -aeskey ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP &
+$GOPATH/bin/knowoapi -etcd http://127.0.0.1:2379 -loglevel $LEVEL  -httphost internal:8889 -dbhost 106.14.63.46 -dbname iot-hub -dbport 3306 -dbuser root -dbpass Lijian405! -aeskey ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP &
 $GOPATH/bin/fileaccess -etcd http://127.0.0.1:2379 -loglevel $LEVEL  -rpchost internal:20035 -httphost internal:9000 &
 $GOPATH/bin/coapaccess -etcd http://127.0.0.1:2379 -loglevel $LEVEL  -udphost internal:56883 &
 exit 0

+ 4 - 2
services/controller/controller.go

@@ -187,8 +187,8 @@ func (c *Controller) initActorSystem() (*ActorSystem, error) {
 	_ = system.CreateDispatcher(ruleEngine.RULE_DISPATCHER_NAME, ruleEngine.NewPoolDispatcher(0))
 
 	// init services
-	tenantService := &ruleEngine.TestTenantService{}
-	ruleChainService := &ruleEngine.TestRuleChainService{}
+	tenantService := &TenantService{}
+	ruleChainService := &RuleChainService{}
 	actorContext := ruleEngine.NewSystemContext(system, ruleEngine.SystemContextServiceConfig{
 		ClusterService:   c.cluster,
 		RuleChainService: ruleChainService,
@@ -202,6 +202,8 @@ func (c *Controller) initActorSystem() (*ActorSystem, error) {
 	}
 	actorContext.AppActor = appActor
 	server.Log.Debugln("actor system initialized")
+	time.Sleep(time.Second * 1)
+	appActor.Tell(&ruleEngine.AppInitMsg{})
 	c.actorContext = actorContext
 	return &ActorSystem{rootActor: appActor}, nil
 }

+ 96 - 2
services/controller/service.go

@@ -48,7 +48,7 @@ func (e *EventService) SaveAsync(data *models.Event) error {
 	})
 }
 
-// TODO:完成这里
+// TenantService 获取租户厂商
 type TenantService struct {
 }
 
@@ -56,7 +56,7 @@ func (t *TenantService) FindTenants() ([]*ruleEngine.Tenant, error) {
 	var arg int
 	var reply []*models.Vendor
 	var result []*ruleEngine.Tenant
-	err := server.RPCCallByName(context.Background(), rpcs.RegistryServerName, "Registry.GetVendors", &arg, &reply)
+ 	err := server.RPCCallByName(context.Background(), rpcs.RegistryServerName, "Registry.GetVendors", &arg, &reply)
 	if err != nil {
 		return nil, err
 	}
@@ -79,3 +79,97 @@ func (t *TenantService) GetTenant(tId string) (*ruleEngine.Tenant, error) {
 		Name: reply.VendorName,
 	}, nil
 }
+
+type RuleChainService struct{}
+
+func (a *RuleChainService) FindRuleChainById(tenantId, ruleChainId string) (*ruleEngine.RuleChain, error) {
+	var reply *models.RuleChain
+	err := server.RPCCallByName(context.TODO(), rpcs.RegistryServerName, "Registry.FindRuleChainById", &ruleChainId, &reply)
+	if err != nil {
+		return nil, err
+	}
+	return &ruleEngine.RuleChain{
+		TenantId:    reply.VendorID,
+		Name:        reply.Name,
+		FirstNodeId: reply.FirstRuleNodeID,
+		IsRoot:      reply.Root,
+		IsDebug:     reply.DebugModel,
+		Config:      reply.Configuration,
+		ChainId:     reply.RecordId,
+	}, nil
+}
+
+func (a *RuleChainService) FindRuleNodeById(tenantId, ruleNodeId string) (*ruleEngine.RuleNode, error) {
+	var reply *models.RuleNode
+	err := server.RPCCallByName(context.TODO(), rpcs.RegistryServerName, "Registry.FindRuleNodeById", &ruleNodeId, &reply)
+	if err != nil {
+		return nil, err
+	}
+	return &ruleEngine.RuleNode{
+		RuleChainId: reply.RuleChainID,
+		Type:        reply.Type,
+		Name:        reply.Name,
+		IsDebug:     reply.DebugModel,
+		Config:      reply.Configuration,
+		RuleNodeId:  reply.RecordId,
+	}, nil
+}
+
+func (a *RuleChainService) GetRuleChainNodes(tenantId, ruleChainId string) ([]*ruleEngine.RuleNode, error) {
+	var reply []*models.RuleNode
+	var result []*ruleEngine.RuleNode
+	err := server.RPCCallByName(context.TODO(), rpcs.RegistryServerName, "Registry.FindRuleChainNodes", &ruleChainId, &reply)
+	if err != nil {
+		return nil, err
+	}
+	for _, node := range reply {
+		result = append(result, &ruleEngine.RuleNode{
+			RuleChainId: node.RuleChainID,
+			Type:        node.Type,
+			Name:        node.Name,
+			IsDebug:     node.DebugModel,
+			Config:      node.Configuration,
+			RuleNodeId:  node.RecordId,
+		})
+	}
+	return result, nil
+}
+
+func (a *RuleChainService) FindRuleChains(tenantId string) ([]*ruleEngine.RuleChain, error) {
+	var reply []*models.RuleChain
+	var result []*ruleEngine.RuleChain
+	err := server.RPCCallByName(context.TODO(), rpcs.RegistryServerName, "Registry.FindRuleChains", &tenantId, &reply)
+	if err != nil {
+		return nil, err
+	}
+	for _, chain := range reply {
+		result = append(result, &ruleEngine.RuleChain{
+			TenantId:    chain.VendorID,
+			Name:        chain.Name,
+			FirstNodeId: chain.FirstRuleNodeID,
+			IsRoot:      chain.Root,
+			IsDebug:     chain.DebugModel,
+			Config:      chain.Configuration,
+			ChainId:     chain.RecordId,
+		})
+	}
+	return result, nil
+}
+
+func (a *RuleChainService) GetRuleNodeRelations(tenantId, nodeId string) ([]*ruleEngine.Relation, error) {
+	var reply []*models.Relation
+	var result []*ruleEngine.Relation
+	err := server.RPCCallByName(context.TODO(), rpcs.RegistryServerName, "Registry.GetRuleNodeRelations", &nodeId, &reply)
+	if err != nil {
+		return nil, err
+	}
+	for _, rel := range reply {
+		result = append(result, &ruleEngine.Relation{
+			From:              rel.FromID,
+			To:                rel.ToID,
+			Type:              rel.RelationType,
+			RelationTypeGroup: 0,
+		})
+	}
+	return result, nil
+}

+ 1 - 1
services/knowoapi/base_test.go

@@ -18,7 +18,7 @@ func getToken() string {
 	user := models.User{
 		UserKey:  "f7f2d7e5a8954ff4ef07ce7f77898c3f1dd389038842788346514183b5eff8b53e",
 		UserName: "lijian",
-		VendorID: 1,
+		VendorID: "1",
 	}
 	user.ID = 1
 	return tk.TokenMaker(&user)

+ 6 - 6
services/knowoapi/model/user.go

@@ -93,8 +93,8 @@ func (a *User) CheckUserName(name string) (bool, error) {
 	var count int
 	err := a.db.First(&user).
 		Where("user_name = ?", name).Count(&count).Error
-	if err != nil {
-		return false, err
+	if err != nil && err == gorm.ErrRecordNotFound  {
+		return false, nil
 	}
 	if count > 0 {
 		return true, nil
@@ -108,8 +108,8 @@ func (a *User) CheckPhone(name string) (bool, error) {
 	var count int
 	err := a.db.First(&user).
 		Where("user_name = ?", name).Count(&count).Error
-	if err != nil {
-		return false, err
+	if err != nil && err == gorm.ErrRecordNotFound  {
+		return false, nil
 	}
 	if count > 0 {
 		return true, nil
@@ -123,8 +123,8 @@ func (a *User) CheckEmail(name string) (bool, error) {
 	var count int
 	err := a.db.First(&user).
 		Where("user_name = ?", name).Count(&count).Error
-	if err != nil {
-		return false, err
+	if err != nil && err == gorm.ErrRecordNotFound  {
+		return false, nil
 	}
 	if count > 0 {
 		return true, nil

+ 7 - 7
services/knowoapi/services/user.go

@@ -11,19 +11,19 @@ import (
 
 // UserService 用户业务接口
 type UserService interface {
-	// 登陆
+	// Login 登陆
 	Login(*models.LoginRequest) (bool, *models.User, error)
-	// 注册
+	// Register 注册
 	Register(*models.Reqrequest) (*models.User, error)
-	// 修改密码,其中密码接收的是已经base64过的字符串
+	// ModifyPassword 修改密码,其中密码接收的是已经base64过的字符串
 	ModifyPassword(uint, string, string) (bool, error)
-	// check name exsits
+	// CheckUserName check name exsits
 	CheckUserName(string) (bool, error)
-	// check phone number exsits
+	// CheckPhone check phone number exsits
 	CheckPhone(string) (bool, error)
-	// check email exsits
+	// CheckEmail check email exsits
 	CheckEmail(string) (bool, error)
-	// get role info
+	// GetRole get role info
 	GetRole(int) (models.Role, error)
 }
 

+ 0 - 1
services/registry/registry.go

@@ -226,7 +226,6 @@ func (r *Registry) GetVendors(noarg int, reply *[]*models.Vendor) error {
 	if err != nil {
 		return err
 	}
-
 	return db.Find(reply).Error
 }
 

+ 47 - 0
services/registry/rule_chain.go

@@ -0,0 +1,47 @@
+package main
+
+import "sparrow/pkg/models"
+
+func (r *Registry) FindRuleChains(vendorId string, reply *[]*models.RuleChain) error {
+	db, err := getDB()
+	if err != nil {
+		return err
+	}
+	return db.Where("vendor_id = ?", vendorId).
+		Find(reply).Error
+}
+
+func (r *Registry) FindRuleChainById(ruleChainId string, reply *models.RuleChain) error {
+	db, err := getDB()
+	if err != nil {
+		return err
+	}
+	return db.Where("record_id = ?", ruleChainId).
+		First(reply).Error
+}
+
+func (r *Registry) FindRuleNodeById(nodeId string, reply *models.RuleNode) error {
+	db, err := getDB()
+	if err != nil {
+		return err
+	}
+	return db.Where("record_id = ?", nodeId).First(reply).Error
+}
+
+func (r *Registry) FindRuleChainNodes(ruleChainId string, reply *[]*models.RuleNode) error {
+	db, err := getDB()
+	if err != nil {
+		return err
+	}
+	return db.Where("rule_chain_id = ?", ruleChainId).
+		Find(reply).Error
+}
+
+func (r *Registry) GetRuleNodeRelations(nodeId string, reply*[]*models.Relation) error {
+	db, err := getDB()
+	if err != nil {
+		return err
+	}
+	return db.Where("from_id = ?", nodeId).Find(reply).Error
+}
+

+ 0 - 1
services/registry/vendor.go

@@ -1 +0,0 @@
-package main

+ 3 - 3
tools/pdcfg/build.sh

@@ -1,5 +1,5 @@
-export CGO_ENABLED=0
-export GOOS=linux
-export GOARCH=amd64
+#export CGO_ENABLED=0
+#export GOOS=linux
+#export GOARCH=amd64
 
 go build ./...

BIN
tools/pdcfg/pdcfg