Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

Commit

Permalink
feature/valueentity state model (#57)
Browse files Browse the repository at this point in the history
[value entity] implemented. TCK passed.
  • Loading branch information
marcellanz authored Dec 6, 2020
1 parent 42eaf48 commit 25bd0ff
Show file tree
Hide file tree
Showing 52 changed files with 4,216 additions and 44 deletions.
59 changes: 53 additions & 6 deletions build/compile-pb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ protoc --go-grpc_out=paths=source_relative:cloudstate/entity --proto_path=protob
protoc --go_out=paths=source_relative:cloudstate/entity --proto_path=protobuf/protocol/ --proto_path=protobuf/protocol/cloudstate event_sourced.proto
protoc --go-grpc_out=paths=source_relative:cloudstate/entity --proto_path=protobuf/protocol/ --proto_path=protobuf/protocol/cloudstate action.proto
protoc --go_out=paths=source_relative:cloudstate/entity --proto_path=protobuf/protocol/ --proto_path=protobuf/protocol/cloudstate action.proto
protoc --go-grpc_out=paths=source_relative:cloudstate/entity --proto_path=protobuf/protocol/ --proto_path=protobuf/protocol/cloudstate value_entity.proto
protoc --go_out=paths=source_relative:cloudstate/entity --proto_path=protobuf/protocol/ --proto_path=protobuf/protocol/cloudstate value_entity.proto

# TCK CRDT
protoc --go-grpc_out=paths=source_relative:./tck/crdt \
Expand Down Expand Up @@ -75,30 +77,49 @@ protoc --go_out=paths=source_relative:./tck/action \
--proto_path=protobuf/tck/cloudstate/tck/model \
--proto_path=protobuf/tck tck_action.proto

# TCK Value Entity
protoc --go-grpc_out=paths=source_relative:./tck/value \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=protobuf/tck/cloudstate/tck/model \
--proto_path=protobuf/tck tck_valueentity.proto
protoc --go_out=paths=source_relative:./tck/value \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=protobuf/tck/cloudstate/tck/model \
--proto_path=protobuf/tck tck_valueentity.proto

# CRDT shopping cart example
protoc --go-grpc_out=paths=source_relative:./example/crdt_shoppingcart/shoppingcart --proto_path=protobuf/protocol \
protoc --go-grpc_out=paths=source_relative:./example/crdt_shoppingcart/shoppingcart \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/crdt_shoppingcart/shoppingcart shoppingcart.proto hotitems.proto
protoc --go_out=paths=source_relative:./example/crdt_shoppingcart/shoppingcart --proto_path=protobuf/protocol \
protoc --go_out=paths=source_relative:./example/crdt_shoppingcart/shoppingcart \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/crdt_shoppingcart/shoppingcart shoppingcart.proto hotitems.proto

protoc --go-grpc_out=paths=source_relative:./example/crdt_shoppingcart/domain --proto_path=protobuf/protocol \
protoc --go-grpc_out=paths=source_relative:./example/crdt_shoppingcart/domain \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/crdt_shoppingcart/domain domain.proto
protoc --go_out=paths=source_relative:./example/crdt_shoppingcart/domain --proto_path=protobuf/protocol \
protoc --go_out=paths=source_relative:./example/crdt_shoppingcart/domain \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/crdt_shoppingcart/domain domain.proto

# shopping cart example
# Event Sourced shopping cart example
protoc --go-grpc_out=paths=source_relative:./example/shoppingcart/ \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
Expand All @@ -124,6 +145,32 @@ protoc --go_out=paths=source_relative:./example/shoppingcart/persistence \
--proto_path=protobuf/proxy \
--proto_path=example/shoppingcart/persistence domain.proto

# Value Entity shopping cart example
protoc --go-grpc_out=paths=source_relative:./example/valueentity/ \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/valueentity value_shoppingcart.proto
protoc --go_out=paths=source_relative:./example/valueentity/ \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/valueentity value_shoppingcart.proto
protoc --go-grpc_out=paths=source_relative:./example/valueentity/persistence \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/valueentity/persistence value_domain.proto
protoc --go_out=paths=source_relative:./example/valueentity/persistence \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/valueentity/persistence value_domain.proto

# chat example
protoc --go-grpc_out=paths=source_relative:./example/chat/presence/ \
--proto_path=protobuf/protocol \
Expand Down
15 changes: 15 additions & 0 deletions cloudstate/cloudstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cloudstateio/go-support/cloudstate/entity"
"github.com/cloudstateio/go-support/cloudstate/eventsourced"
"github.com/cloudstateio/go-support/cloudstate/protocol"
"github.com/cloudstateio/go-support/cloudstate/value"
"google.golang.org/grpc"
)

Expand All @@ -38,6 +39,7 @@ type CloudState struct {
eventSourcedServer *eventsourced.Server
crdtServer *crdt.Server
actionServer *action.Server
valueServer *value.Server
}

// New returns a new CloudState instance.
Expand All @@ -48,10 +50,12 @@ func New(c protocol.Config) (*CloudState, error) {
eventSourcedServer: eventsourced.NewServer(),
crdtServer: crdt.NewServer(),
actionServer: action.NewServer(),
valueServer: value.NewServer(),
}
protocol.RegisterEntityDiscoveryServer(cs.grpcServer, cs.entityDiscoveryServer)
entity.RegisterEventSourcedServer(cs.grpcServer, cs.eventSourcedServer)
entity.RegisterCrdtServer(cs.grpcServer, cs.crdtServer)
entity.RegisterValueEntityServer(cs.grpcServer, cs.valueServer)
entity.RegisterActionProtocolServer(cs.grpcServer, cs.actionServer)
return cs, nil
}
Expand Down Expand Up @@ -89,6 +93,17 @@ func (cs *CloudState) RegisterAction(entity *action.Entity, config protocol.Desc
return nil
}

// RegisterValueEntity registers a Value entity.
func (cs *CloudState) RegisterValueEntity(entity *value.Entity, config protocol.DescriptorConfig) error {
if err := cs.valueServer.Register(entity); err != nil {
return err
}
if err := cs.entityDiscoveryServer.RegisterValueEntity(entity, config); err != nil {
return err
}
return nil
}

// Run runs the CloudState instance on the interface and port defined by
// the HOST and PORT environment variable.
func (cs *CloudState) Run() error {
Expand Down
15 changes: 15 additions & 0 deletions cloudstate/discovery/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cloudstateio/go-support/cloudstate/crdt"
"github.com/cloudstateio/go-support/cloudstate/eventsourced"
"github.com/cloudstateio/go-support/cloudstate/protocol"
"github.com/cloudstateio/go-support/cloudstate/value"
"github.com/golang/protobuf/descriptor"
"github.com/golang/protobuf/proto"
filedescr "github.com/golang/protobuf/protoc-gen-go/descriptor"
Expand Down Expand Up @@ -160,6 +161,20 @@ func (s *EntityDiscoveryServer) RegisterActionEntity(entity *action.Entity, conf
return s.updateSpec()
}

func (s *EntityDiscoveryServer) RegisterValueEntity(entity *value.Entity, config protocol.DescriptorConfig) error {
s.mu.Lock()
defer s.mu.Unlock()
if err := s.resolveFileDescriptors(config); err != nil {
return fmt.Errorf("failed to resolveFileDescriptor for DescriptorConfig: %+v: %w", config, err)
}
s.entitySpec.Entities = append(s.entitySpec.Entities, &protocol.Entity{
EntityType: protocol.Value,
ServiceName: entity.ServiceName.String(),
PersistenceId: entity.PersistenceID,
})
return s.updateSpec()
}

func (s *EntityDiscoveryServer) hasRegistered(filename string) bool {
for _, f := range s.fileDescriptorSet.File {
if f.GetName() == filename {
Expand Down
7 changes: 6 additions & 1 deletion cloudstate/entity/action.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cloudstate/entity/action_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion cloudstate/entity/crdt.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cloudstate/entity/crdt_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion cloudstate/entity/event_sourced.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cloudstate/entity/event_sourced_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 25bd0ff

Please sign in to comment.