diff --git a/camino-messenger-bot.yaml.example b/camino-messenger-bot.yaml.example index af0d5e4e..6c037fbc 100644 --- a/camino-messenger-bot.yaml.example +++ b/camino-messenger-bot.yaml.example @@ -14,6 +14,8 @@ partner_plugin_ca_file: ca-cert.pem response_timeout: 3000 supported_request_types: - ActivitySearchRequest + - AccommodationProductInfoRequest + - AccommodationProductListRequest - AccommodationSearchRequest - GetNetworkFeeRequest - GetPartnerConfigurationRequest diff --git a/config/config.go b/config/config.go index 472eabd1..b0e85494 100644 --- a/config/config.go +++ b/config/config.go @@ -38,7 +38,7 @@ type PartnerPluginConfig struct { CACertFile string `mapstructure:"partner_plugin_ca_file"` } type ProcessorConfig struct { - Timeout int `mapstructure:"messenger_timeout"` // in milliseconds + Timeout int `mapstructure:"response_timeout"` // in milliseconds } type Config struct { AppConfig `mapstructure:",squash"` diff --git a/config/flag_keys.go b/config/flag_keys.go index 6ab42f27..2db71103 100644 --- a/config/flag_keys.go +++ b/config/flag_keys.go @@ -13,6 +13,6 @@ const ( PartnerPluginPortKey = "partner_plugin_port" PartnerPluginUnencryptedKey = "partner_plugin_unencrypted" PartnerPluginCAFileKey = "partner_plugin_ca_file" - MessengerTimeoutKey = "messenger_timeout" + MessengerTimeoutKey = "response_timeout" SupportedRequestTypesKey = "supported_request_types" ) diff --git a/examples/rpc/partner-plugin/server.go b/examples/rpc/partner-plugin/server.go index 6e7b1d49..da7526e5 100644 --- a/examples/rpc/partner-plugin/server.go +++ b/examples/rpc/partner-plugin/server.go @@ -29,6 +29,8 @@ import ( type partnerPlugin struct { activityv1alphagrpc.ActivitySearchServiceServer + accommodationv1alphagrpc.AccommodationProductInfoServiceServer + accommodationv1alphagrpc.AccommodationProductListServiceServer accommodationv1alphagrpc.AccommodationSearchServiceServer networkv1alphagrpc.GetNetworkFeeServiceServer partnerv1alphagrpc.GetPartnerConfigurationServiceServer @@ -52,7 +54,36 @@ func (p *partnerPlugin) ActivitySearch(ctx context.Context, request *activityv1a grpc.SendHeader(ctx, md.ToGrpcMD()) return &response, nil } +func (p *partnerPlugin) AccommodationProductInfo(ctx context.Context, request *accommodationv1alpha.AccommodationProductInfoRequest) (*accommodationv1alpha.AccommodationProductInfoResponse, error) { + md := metadata.Metadata{} + err := md.ExtractMetadata(ctx) + if err != nil { + log.Print("error extracting metadata") + } + md.Stamp(fmt.Sprintf("%s-%s", "ext-system", "response")) + log.Printf("Responding to request: %s", md.RequestID) + response := accommodationv1alpha.AccommodationProductInfoResponse{ + Properties: []*accommodationv1alpha.PropertyExtendedInfo{{PaymentType: "cash"}}, + } + grpc.SendHeader(ctx, md.ToGrpcMD()) + return &response, nil +} +func (p *partnerPlugin) AccommodationProductList(ctx context.Context, request *accommodationv1alpha.AccommodationProductListRequest) (*accommodationv1alpha.AccommodationProductListResponse, error) { + md := metadata.Metadata{} + err := md.ExtractMetadata(ctx) + if err != nil { + log.Print("error extracting metadata") + } + md.Stamp(fmt.Sprintf("%s-%s", "ext-system", "response")) + log.Printf("Responding to request: %s", md.RequestID) + + response := accommodationv1alpha.AccommodationProductListResponse{ + Properties: []*accommodationv1alpha.Property{{Name: "Hotel"}}, + } + grpc.SendHeader(ctx, md.ToGrpcMD()) + return &response, nil +} func (p *partnerPlugin) AccommodationSearch(ctx context.Context, request *accommodationv1alpha.AccommodationSearchRequest) (*accommodationv1alpha.AccommodationSearchResponse, error) { md := metadata.Metadata{} err := md.ExtractMetadata(ctx) @@ -140,6 +171,8 @@ func (p *partnerPlugin) TransportSearch(ctx context.Context, request *transportv func main() { grpcServer := grpc.NewServer() activityv1alphagrpc.RegisterActivitySearchServiceServer(grpcServer, &partnerPlugin{}) + accommodationv1alphagrpc.RegisterAccommodationProductInfoServiceServer(grpcServer, &partnerPlugin{}) + accommodationv1alphagrpc.RegisterAccommodationProductListServiceServer(grpcServer, &partnerPlugin{}) accommodationv1alphagrpc.RegisterAccommodationSearchServiceServer(grpcServer, &partnerPlugin{}) networkv1alphagrpc.RegisterGetNetworkFeeServiceServer(grpcServer, &partnerPlugin{}) partnerv1alphagrpc.RegisterGetPartnerConfigurationServiceServer(grpcServer, &partnerPlugin{}) diff --git a/internal/matrix/types.go b/internal/matrix/types.go index ad434fe4..3f851c91 100644 --- a/internal/matrix/types.go +++ b/internal/matrix/types.go @@ -29,6 +29,14 @@ func (m *CaminoMatrixMessage) UnmarshalContent(src []byte) error { return proto.Unmarshal(src, &m.Content.RequestContent.ActivitySearchRequest) case messaging.ActivitySearchResponse: return proto.Unmarshal(src, &m.Content.ResponseContent.ActivitySearchResponse) + case messaging.AccommodationProductInfoRequest: + return proto.Unmarshal(src, &m.Content.RequestContent.AccommodationProductInfoRequest) + case messaging.AccommodationProductInfoResponse: + return proto.Unmarshal(src, &m.Content.ResponseContent.AccommodationProductInfoResponse) + case messaging.AccommodationProductListRequest: + return proto.Unmarshal(src, &m.Content.RequestContent.AccommodationProductListRequest) + case messaging.AccommodationProductListResponse: + return proto.Unmarshal(src, &m.Content.ResponseContent.AccommodationProductListResponse) case messaging.AccommodationSearchRequest: return proto.Unmarshal(src, &m.Content.RequestContent.AccommodationSearchRequest) case messaging.AccommodationSearchResponse: diff --git a/internal/messaging/processor.go b/internal/messaging/processor.go index 80e4d22e..a9cfba0a 100644 --- a/internal/messaging/processor.go +++ b/internal/messaging/processor.go @@ -170,7 +170,7 @@ func (p *processor) Respond(msg Message) error { var header grpc_metadata.MD response, msgType, err := service.Call(ctx, &msg.Content.RequestContent, grpc.Header(&header)) if err != nil { - return err + return err //TODO handle error and return a response message } err = md.FromGrpcMD(header) diff --git a/internal/messaging/service.go b/internal/messaging/service.go index 74cab9a5..01063d4c 100644 --- a/internal/messaging/service.go +++ b/internal/messaging/service.go @@ -20,6 +20,8 @@ import ( var ( _ Service = (*activityService)(nil) + _ Service = (*accommodationProductInfoService)(nil) + _ Service = (*accommodationProductListService)(nil) _ Service = (*accommodationService)(nil) _ Service = (*networkService)(nil) _ Service = (*partnerService)(nil) @@ -35,6 +37,13 @@ type Service interface { type activityService struct { client *activityv1alphagrpc.ActivitySearchServiceClient } +type accommodationProductInfoService struct { + client *accommodationv1alphagrpc.AccommodationProductInfoServiceClient +} +type accommodationProductListService struct { + client *accommodationv1alphagrpc.AccommodationProductListServiceClient +} + type accommodationService struct { client *accommodationv1alphagrpc.AccommodationSearchServiceClient } @@ -49,6 +58,28 @@ type transportService struct { client *transportv1alphagrpc.TransportSearchServiceClient } +func (a accommodationProductInfoService) Call(ctx context.Context, request *RequestContent, opts ...grpc.CallOption) (ResponseContent, MessageType, error) { + if &request.AccommodationProductInfoRequest == nil { + return ResponseContent{}, "", ErrInvalidMessageType + } + response, err := (*a.client).AccommodationProductInfo(ctx, &request.AccommodationProductInfoRequest, opts...) + responseContent := ResponseContent{} + if err == nil { + responseContent.AccommodationProductInfoResponse = *response // otherwise nil pointer dereference + } + return responseContent, AccommodationProductInfoResponse, err +} +func (a accommodationProductListService) Call(ctx context.Context, request *RequestContent, opts ...grpc.CallOption) (ResponseContent, MessageType, error) { + if &request.AccommodationProductListRequest == nil { + return ResponseContent{}, "", ErrInvalidMessageType + } + response, err := (*a.client).AccommodationProductList(ctx, &request.AccommodationProductListRequest, opts...) + responseContent := ResponseContent{} + if err == nil { + responseContent.AccommodationProductListResponse = *response // otherwise nil pointer dereference + } + return responseContent, AccommodationProductListResponse, err +} func (s activityService) Call(ctx context.Context, request *RequestContent, opts ...grpc.CallOption) (ResponseContent, MessageType, error) { if &request.ActivitySearchRequest == nil { return ResponseContent{}, "", ErrInvalidMessageType diff --git a/internal/messaging/service_registry.go b/internal/messaging/service_registry.go index 04a28712..0da4cc6f 100644 --- a/internal/messaging/service_registry.go +++ b/internal/messaging/service_registry.go @@ -36,6 +36,12 @@ func (s *ServiceRegistry) RegisterServices(requestTypes config.SupportedRequestT case ActivitySearchRequest: c := activityv1alphagrpc.NewActivitySearchServiceClient(s.rpcClient.ClientConn) service = activityService{client: &c} + case AccommodationProductInfoRequest: + c := accommodationv1alphagrpc.NewAccommodationProductInfoServiceClient(s.rpcClient.ClientConn) + service = accommodationProductInfoService{client: &c} + case AccommodationProductListRequest: + c := accommodationv1alphagrpc.NewAccommodationProductListServiceClient(s.rpcClient.ClientConn) + service = accommodationProductListService{client: &c} case AccommodationSearchRequest: c := accommodationv1alphagrpc.NewAccommodationSearchServiceClient(s.rpcClient.ClientConn) service = accommodationService{client: &c} diff --git a/internal/messaging/types.go b/internal/messaging/types.go index ddca369d..2597822c 100644 --- a/internal/messaging/types.go +++ b/internal/messaging/types.go @@ -13,6 +13,8 @@ import ( type RequestContent struct { activityv1alpha.ActivitySearchRequest + accommodationv1alpha.AccommodationProductInfoRequest + accommodationv1alpha.AccommodationProductListRequest accommodationv1alpha.AccommodationSearchRequest networkv1alpha.GetNetworkFeeRequest partnerv1alpha.GetPartnerConfigurationRequest @@ -21,6 +23,8 @@ type RequestContent struct { } type ResponseContent struct { activityv1alpha.ActivitySearchResponse + accommodationv1alpha.AccommodationProductInfoResponse + accommodationv1alpha.AccommodationProductListResponse accommodationv1alpha.AccommodationSearchResponse networkv1alpha.GetNetworkFeeResponse partnerv1alpha.GetPartnerConfigurationResponse @@ -50,28 +54,36 @@ const ( // message types - ActivitySearchRequest MessageType = "ActivitySearchRequest" - ActivitySearchResponse MessageType = "ActivitySearchResponse" - AccommodationSearchRequest MessageType = "AccommodationSearchRequest" - AccommodationSearchResponse MessageType = "AccommodationSearchResponse" - GetNetworkFeeRequest MessageType = "GetNetworkFeeRequest" - GetNetworkFeeResponse MessageType = "GetNetworkFeeResponse" - GetPartnerConfigurationRequest MessageType = "GetPartnerConfigurationRequest" - GetPartnerConfigurationResponse MessageType = "GetPartnerConfigurationResponse" - PingRequest MessageType = "PingRequest" - PingResponse MessageType = "PingResponse" - TransportSearchRequest MessageType = "TransportSearchRequest" - TransportSearchResponse MessageType = "TransportSearchResponse" + ActivitySearchRequest MessageType = "ActivitySearchRequest" + ActivitySearchResponse MessageType = "ActivitySearchResponse" + AccommodationProductInfoRequest MessageType = "AccommodationProductInfoRequest" + AccommodationProductInfoResponse MessageType = "AccommodationProductInfoResponse" + AccommodationProductListRequest MessageType = "AccommodationProductListRequest" + AccommodationProductListResponse MessageType = "AccommodationProductListResponse" + AccommodationSearchRequest MessageType = "AccommodationSearchRequest" + AccommodationSearchResponse MessageType = "AccommodationSearchResponse" + GetNetworkFeeRequest MessageType = "GetNetworkFeeRequest" + GetNetworkFeeResponse MessageType = "GetNetworkFeeResponse" + GetPartnerConfigurationRequest MessageType = "GetPartnerConfigurationRequest" + GetPartnerConfigurationResponse MessageType = "GetPartnerConfigurationResponse" + PingRequest MessageType = "PingRequest" + PingResponse MessageType = "PingResponse" + TransportSearchRequest MessageType = "TransportSearchRequest" + TransportSearchResponse MessageType = "TransportSearchResponse" ) func (mt MessageType) Category() MessageCategory { switch mt { case ActivitySearchRequest, + AccommodationProductInfoRequest, + AccommodationProductListRequest, AccommodationSearchRequest, PingRequest, TransportSearchRequest: return Request case ActivitySearchResponse, + AccommodationProductInfoResponse, + AccommodationProductListResponse, AccommodationSearchResponse, GetNetworkFeeResponse, GetPartnerConfigurationResponse, @@ -90,6 +102,14 @@ func (m *Message) MarshalContent() ([]byte, error) { return proto.Marshal(&m.Content.ActivitySearchRequest) case ActivitySearchResponse: return proto.Marshal(&m.Content.ActivitySearchResponse) + case AccommodationProductInfoRequest: + return proto.Marshal(&m.Content.AccommodationProductInfoRequest) + case AccommodationProductInfoResponse: + return proto.Marshal(&m.Content.AccommodationProductInfoResponse) + case AccommodationProductListRequest: + return proto.Marshal(&m.Content.AccommodationProductListRequest) + case AccommodationProductListResponse: + return proto.Marshal(&m.Content.AccommodationProductListResponse) case AccommodationSearchRequest: return proto.Marshal(&m.Content.AccommodationSearchRequest) case AccommodationSearchResponse: diff --git a/internal/rpc/server/server.go b/internal/rpc/server/server.go index 2b46fcb8..75e4df42 100644 --- a/internal/rpc/server/server.go +++ b/internal/rpc/server/server.go @@ -32,12 +32,14 @@ import ( var ( _ Server = (*server)(nil) - _ accommodationv1alphagrpc.AccommodationSearchServiceServer = (*server)(nil) - _ activityv1alphagrpc.ActivitySearchServiceServer = (*server)(nil) - _ networkv1alphagrpc.GetNetworkFeeServiceServer = (*server)(nil) - _ partnerv1alphagrpc.GetPartnerConfigurationServiceServer = (*server)(nil) - _ pingv1alphagrpc.PingServiceServer = (*server)(nil) - _ transportv1alphagrpc.TransportSearchServiceServer = (*server)(nil) + _ accommodationv1alphagrpc.AccommodationProductInfoServiceServer = (*server)(nil) + _ accommodationv1alphagrpc.AccommodationProductListServiceServer = (*server)(nil) + _ accommodationv1alphagrpc.AccommodationSearchServiceServer = (*server)(nil) + _ activityv1alphagrpc.ActivitySearchServiceServer = (*server)(nil) + _ networkv1alphagrpc.GetNetworkFeeServiceServer = (*server)(nil) + _ partnerv1alphagrpc.GetPartnerConfigurationServiceServer = (*server)(nil) + _ pingv1alphagrpc.PingServiceServer = (*server)(nil) + _ transportv1alphagrpc.TransportSearchServiceServer = (*server)(nil) errMissingRecipient = errors.New("missing recipient") ) @@ -78,6 +80,8 @@ func NewServer(cfg *config.RPCServerConfig, logger *zap.SugaredLogger, processor func createGrpcServerAndRegisterServices(server *server, opts ...grpc.ServerOption) *grpc.Server { grpcServer := grpc.NewServer(opts...) activityv1alphagrpc.RegisterActivitySearchServiceServer(grpcServer, server) + accommodationv1alphagrpc.RegisterAccommodationProductInfoServiceServer(grpcServer, server) + accommodationv1alphagrpc.RegisterAccommodationProductListServiceServer(grpcServer, server) accommodationv1alphagrpc.RegisterAccommodationSearchServiceServer(grpcServer, server) networkv1alphagrpc.RegisterGetNetworkFeeServiceServer(grpcServer, server) partnerv1alphagrpc.RegisterGetPartnerConfigurationServiceServer(grpcServer, server) @@ -99,6 +103,16 @@ func (s *server) Stop() { s.grpcServer.Stop() } +func (s *server) AccommodationProductInfo(ctx context.Context, request *accommodationv1alpha.AccommodationProductInfoRequest) (*accommodationv1alpha.AccommodationProductInfoResponse, error) { + response, err := s.processExternalRequest(ctx, messaging.AccommodationProductInfoRequest, &messaging.RequestContent{AccommodationProductInfoRequest: *request}) + return &response.AccommodationProductInfoResponse, err +} + +func (s *server) AccommodationProductList(ctx context.Context, request *accommodationv1alpha.AccommodationProductListRequest) (*accommodationv1alpha.AccommodationProductListResponse, error) { + response, err := s.processExternalRequest(ctx, messaging.AccommodationProductListRequest, &messaging.RequestContent{AccommodationProductListRequest: *request}) + return &response.AccommodationProductListResponse, err +} + func (s *server) AccommodationSearch(ctx context.Context, request *accommodationv1alpha.AccommodationSearchRequest) (*accommodationv1alpha.AccommodationSearchResponse, error) { response, err := s.processExternalRequest(ctx, messaging.AccommodationSearchRequest, &messaging.RequestContent{AccommodationSearchRequest: *request}) return &response.AccommodationSearchResponse, err //TODO set specific errors according to https://grpc.github.io/grpc/core/md_doc_statuscodes.html ?