Skip to content

Commit

Permalink
Merge pull request #84 from moleculer-go/develop
Browse files Browse the repository at this point in the history
Add version to action names on remote services.
  • Loading branch information
pentateu authored Mar 11, 2020
2 parents 614fca2 + 18a249e commit e221ad0
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ steps:
- export NATS_HOST="nats-streaming"
- export AMQP_HOST="guest:guest@rabbitmq"
- go build
- go run github.com/onsi/ginkgo/ginkgo -r --keepGoing --cover --trace
- go run github.com/onsi/ginkgo/ginkgo -r --keepGoing --cover --trace -skipPackage=amqp
# - curl -sL https://deb.nodesource.com/setup_12.x | bash -
# - apt-get update
# - apt-get install -y nodejs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(string) (len=6) "events": (map[string]map[string]interface {}) {
},
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=7) "compute": (map[string]interface {}) (len=3) {
(string) (len=11) "cpu.compute": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=11) "cpu.compute",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand Down Expand Up @@ -37,7 +37,7 @@
}
},
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=5) "print": (map[string]interface {}) (len=3) {
(string) (len=13) "printer.print": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "printer.print",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
},
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=5) "print": (map[string]interface {}) (len=3) {
(string) (len=13) "printer.print": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "printer.print",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
},
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=4) "scan": (map[string]interface {}) (len=3) {
(string) (len=12) "scanner.scan": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "scanner.scan",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@
},
(string) (len=6) "nodeID": (string) (len=18) "node_printerBroker",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=6) {
(string) (len=4) "list": (map[string]interface {}) (len=3) {
(string) (len=10) "$node.list": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=10) "$node.list",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=4) "list"
},
(string) (len=6) "events": (map[string]interface {}) (len=3) {
(string) (len=12) "$node.events": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "$node.events",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=6) "events"
},
(string) (len=6) "health": (map[string]interface {}) (len=3) {
(string) (len=12) "$node.health": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "$node.health",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=6) "health"
},
(string) (len=7) "actions": (map[string]interface {}) (len=3) {
(string) (len=13) "$node.actions": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "$node.actions",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=7) "actions"
},
(string) (len=7) "options": (map[string]interface {}) (len=3) {
(string) (len=13) "$node.options": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "$node.options",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=7) "options"
},
(string) (len=8) "services": (map[string]interface {}) (len=3) {
(string) (len=14) "$node.services": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=14) "$node.services",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand All @@ -74,7 +74,7 @@
},
(string) (len=6) "nodeID": (string) (len=18) "node_printerBroker",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=5) "print": (map[string]interface {}) (len=3) {
(string) (len=13) "printer.print": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "printer.print",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(map[string]interface {}) (len=7) {
(string) (len=4) "name": (string) (len=3) "cpu",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=7) "compute": (map[string]interface {}) (len=3) {
(string) (len=11) "cpu.compute": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=11) "cpu.compute",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand All @@ -23,37 +23,37 @@
(map[string]interface {}) (len=7) {
(string) (len=4) "name": (string) (len=5) "$node",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=6) {
(string) (len=4) "list": (map[string]interface {}) (len=3) {
(string) (len=10) "$node.list": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=10) "$node.list",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=4) "list"
},
(string) (len=6) "events": (map[string]interface {}) (len=3) {
(string) (len=12) "$node.events": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "$node.events",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=6) "events"
},
(string) (len=6) "health": (map[string]interface {}) (len=3) {
(string) (len=12) "$node.health": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "$node.health",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=6) "health"
},
(string) (len=7) "actions": (map[string]interface {}) (len=3) {
(string) (len=13) "$node.actions": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "$node.actions",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=7) "actions"
},
(string) (len=7) "options": (map[string]interface {}) (len=3) {
(string) (len=13) "$node.options": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "$node.options",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=7) "options"
},
(string) (len=8) "services": (map[string]interface {}) (len=3) {
(string) (len=14) "$node.services": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=14) "$node.services",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand All @@ -73,7 +73,7 @@
(map[string]interface {}) (len=7) {
(string) (len=4) "name": (string) (len=7) "printer",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=5) "print": (map[string]interface {}) (len=3) {
(string) (len=13) "printer.print": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "printer.print",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand All @@ -93,7 +93,7 @@
(map[string]interface {}) (len=7) {
(string) (len=4) "name": (string) (len=7) "scanner",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=4) "scan": (map[string]interface {}) (len=3) {
(string) (len=12) "scanner.scan": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "scanner.scan",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
(map[string]interface {}) (len=7) {
(string) (len=4) "name": (string) (len=5) "$node",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=6) {
(string) (len=4) "list": (map[string]interface {}) (len=3) {
(string) (len=10) "$node.list": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=10) "$node.list",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=4) "list"
},
(string) (len=6) "events": (map[string]interface {}) (len=3) {
(string) (len=12) "$node.events": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "$node.events",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=6) "events"
},
(string) (len=6) "health": (map[string]interface {}) (len=3) {
(string) (len=12) "$node.health": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "$node.health",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=6) "health"
},
(string) (len=7) "actions": (map[string]interface {}) (len=3) {
(string) (len=13) "$node.actions": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "$node.actions",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=7) "actions"
},
(string) (len=7) "options": (map[string]interface {}) (len=3) {
(string) (len=13) "$node.options": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "$node.options",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=7) "options"
},
(string) (len=8) "services": (map[string]interface {}) (len=3) {
(string) (len=14) "$node.services": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=14) "$node.services",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand All @@ -53,7 +53,7 @@
(map[string]interface {}) (len=7) {
(string) (len=4) "name": (string) (len=7) "printer",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=5) "print": (map[string]interface {}) (len=3) {
(string) (len=13) "printer.print": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "printer.print",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
(map[string]interface {}) (len=7) {
(string) (len=4) "name": (string) (len=5) "$node",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=6) {
(string) (len=4) "list": (map[string]interface {}) (len=3) {
(string) (len=10) "$node.list": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=10) "$node.list",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=4) "list"
},
(string) (len=6) "events": (map[string]interface {}) (len=3) {
(string) (len=12) "$node.events": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "$node.events",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=6) "events"
},
(string) (len=6) "health": (map[string]interface {}) (len=3) {
(string) (len=12) "$node.health": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "$node.health",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=6) "health"
},
(string) (len=7) "actions": (map[string]interface {}) (len=3) {
(string) (len=13) "$node.actions": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "$node.actions",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=7) "actions"
},
(string) (len=7) "options": (map[string]interface {}) (len=3) {
(string) (len=13) "$node.options": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "$node.options",
(string) (len=6) "params": (map[string]interface {}) {
},
(string) (len=7) "rawName": (string) (len=7) "options"
},
(string) (len=8) "services": (map[string]interface {}) (len=3) {
(string) (len=14) "$node.services": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=14) "$node.services",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand All @@ -53,7 +53,7 @@
(map[string]interface {}) (len=7) {
(string) (len=4) "name": (string) (len=7) "printer",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=5) "print": (map[string]interface {}) (len=3) {
(string) (len=13) "printer.print": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=13) "printer.print",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand All @@ -73,7 +73,7 @@
(map[string]interface {}) (len=7) {
(string) (len=4) "name": (string) (len=7) "scanner",
(string) (len=7) "actions": (map[string]map[string]interface {}) (len=1) {
(string) (len=4) "scan": (map[string]interface {}) (len=3) {
(string) (len=12) "scanner.scan": (map[string]interface {}) (len=3) {
(string) (len=4) "name": (string) (len=12) "scanner.scan",
(string) (len=6) "params": (map[string]interface {}) {
},
Expand Down
8 changes: 6 additions & 2 deletions registry/actionCatalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ func (actionCatalog *ActionCatalog) listByName() map[string][]ActionEntry {
}

// Add a new action to the catalog.
func (actionCatalog *ActionCatalog) Add(action service.Action, service *service.Service, local bool) {
entry := ActionEntry{service.NodeID(), &action, local, service, actionCatalog.logger}
func (actionCatalog *ActionCatalog) Add(action service.Action, serv *service.Service, local bool) {
entry := ActionEntry{serv.NodeID(), &action, local, serv, actionCatalog.logger}
name := action.FullName()
ver := serv.Version()
if ver != "" && !strings.HasPrefix(name, ver) {
name = service.JoinVersionToName(name, ver)
}
list, exists := actionCatalog.actions.Load(name)
if !exists {
list = []ActionEntry{entry}
Expand Down
2 changes: 1 addition & 1 deletion registry/serviceCatalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (serviceCatalog *ServiceCatalog) updateActions(serviceMap map[string]interf
}
}
for _, action := range current.Actions() {
name := action.Name()
name := action.FullName()
_, exists := actions[name]
if !exists {
deletedActions = append(deletedActions, action)
Expand Down
8 changes: 4 additions & 4 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func applyMixins(service moleculer.ServiceSchema) moleculer.ServiceSchema {
return service
}

func joinVersionToName(name string, version string) string {
func JoinVersionToName(name string, version string) string {
if version != "" {
return fmt.Sprintf("%s.%s", version, name)
}
Expand Down Expand Up @@ -372,7 +372,7 @@ func (service *Service) AsMap() map[string]interface{} {
actionInfo["name"] = serviceAction.fullname
actionInfo["rawName"] = serviceAction.name
actionInfo["params"] = paramsAsMap(&serviceAction.params)
actions[serviceAction.name] = actionInfo
actions[serviceAction.fullname] = actionInfo
}
}
serviceInfo["actions"] = actions
Expand Down Expand Up @@ -482,7 +482,7 @@ func populateFromMap(service *Service, serviceInfo map[string]interface{}) {
}
service.version = ParseVersion(serviceInfo["version"])
service.name = serviceInfo["name"].(string)
service.fullname = joinVersionToName(
service.fullname = JoinVersionToName(
service.name,
service.version)

Expand All @@ -506,7 +506,7 @@ func (service *Service) populateFromSchema() {
schema := service.schema
service.name = schema.Name
service.version = schema.Version
service.fullname = joinVersionToName(service.name, service.version)
service.fullname = JoinVersionToName(service.name, service.version)
service.dependencies = schema.Dependencies
service.settings = schema.Settings
if service.settings == nil {
Expand Down

0 comments on commit e221ad0

Please sign in to comment.