From dfcb66839a5fbd5b1a9fc00e085a6ab2449ca8cc Mon Sep 17 00:00:00 2001 From: Evgeny Safronov Date: Wed, 7 Nov 2018 17:07:25 +0300 Subject: [PATCH] feat: return order IDs after price prediction (#1682) --- optimus/engine.go | 2 -- optimus/optimus.go | 3 ++- optimus/predictor_service.go | 10 +++++++- optimus/worker.go | 11 +++++++++ proto/optimus.pb.go | 44 ++++++++++++++++++++++-------------- proto/optimus.proto | 2 ++ 6 files changed, 51 insertions(+), 21 deletions(-) diff --git a/optimus/engine.go b/optimus/engine.go index 332049c61..473bbcded 100644 --- a/optimus/engine.go +++ b/optimus/engine.go @@ -354,8 +354,6 @@ func (m *workerEngine) execute(ctx context.Context) error { // Extract the order ID for whose the selling plan is created. orderID := plan.GetOrderID() - // Then we need to clean this, because otherwise worker rejects such request. - plan.OrderID = nil plan.Identity = m.cfg.Identity plan.Tag = m.tagger.Tag() diff --git a/optimus/optimus.go b/optimus/optimus.go index 80479aca2..10c191817 100644 --- a/optimus/optimus.go +++ b/optimus/optimus.go @@ -91,7 +91,8 @@ func (m *Optimus) Run(ctx context.Context) error { } // TODO: Well, 10 parameters seems to be WAT. - control, err := newWorkerEngine(cfg, ethAddr, masterAddr, blacklist, worker, market.Market(), marketCache, benchmarkMapping, newTagger(m.version), m.log) + workerClient := &workerManagementClientAPI{worker} + control, err := newWorkerEngine(cfg, ethAddr, masterAddr, blacklist, workerClient, market.Market(), marketCache, benchmarkMapping, newTagger(m.version), m.log) if err != nil { return err } diff --git a/optimus/predictor_service.go b/optimus/predictor_service.go index 639298ce3..7bf09172b 100644 --- a/optimus/predictor_service.go +++ b/optimus/predictor_service.go @@ -71,5 +71,13 @@ func (m *PredictorService) PredictSupplier(ctx context.Context, request *sonm.Pr return nil, err } - return &sonm.PredictSupplierReply{Price: sonm.SumPrice(worker.Result)}, nil + orderIDs := make([]*sonm.BigInt, 0, len(worker.Result)) + for _, plan := range worker.Result { + orderIDs = append(orderIDs, plan.GetOrderID()) + } + + return &sonm.PredictSupplierReply{ + Price: sonm.SumPrice(worker.Result), + OrderIDs: orderIDs, + }, nil } diff --git a/optimus/worker.go b/optimus/worker.go index c1a2c8167..e34fccfd7 100644 --- a/optimus/worker.go +++ b/optimus/worker.go @@ -68,6 +68,17 @@ type WorkerManagementClientAPI interface { NextMaintenance(ctx context.Context, request *sonm.Empty, opts ...grpc.CallOption) (*sonm.Timestamp, error) } +type workerManagementClientAPI struct { + WorkerManagementClientAPI +} + +func (m *workerManagementClientAPI) CreateAskPlan(ctx context.Context, request *sonm.AskPlan, opts ...grpc.CallOption) (*sonm.ID, error) { + // We need to clean this, because otherwise worker rejects such request. + request.OrderID = nil + + return m.WorkerManagementClientAPI.CreateAskPlan(ctx, request, opts...) +} + // WorkerManagementClientExt extends default "WorkerManagementClient" with an // ability to remove multiple ask-plans. type WorkerManagementClientExt interface { diff --git a/proto/optimus.pb.go b/proto/optimus.pb.go index ef23fbcb3..b378ddbf2 100644 --- a/proto/optimus.pb.go +++ b/proto/optimus.pb.go @@ -34,7 +34,8 @@ func (m *PredictSupplierRequest) GetDevices() *DevicesReply { } type PredictSupplierReply struct { - Price *Price `protobuf:"bytes,1,opt,name=price" json:"price,omitempty"` + Price *Price `protobuf:"bytes,1,opt,name=price" json:"price,omitempty"` + OrderIDs []*BigInt `protobuf:"bytes,2,rep,name=orderIDs" json:"orderIDs,omitempty"` } func (m *PredictSupplierReply) Reset() { *m = PredictSupplierReply{} } @@ -49,6 +50,13 @@ func (m *PredictSupplierReply) GetPrice() *Price { return nil } +func (m *PredictSupplierReply) GetOrderIDs() []*BigInt { + if m != nil { + return m.OrderIDs + } + return nil +} + func init() { proto.RegisterType((*PredictSupplierRequest)(nil), "sonm.PredictSupplierRequest") proto.RegisterType((*PredictSupplierReply)(nil), "sonm.PredictSupplierReply") @@ -162,20 +170,22 @@ var _OrderPredictor_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("optimus.proto", fileDescriptor10) } var fileDescriptor10 = []byte{ - // 229 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0x3d, 0x4b, 0x04, 0x31, - 0x10, 0x86, 0x6f, 0xc1, 0x0f, 0xc8, 0xa9, 0x87, 0x41, 0x44, 0x82, 0x85, 0x6e, 0x65, 0x21, 0x5b, - 0x9c, 0x95, 0xad, 0x88, 0x9d, 0x78, 0xc4, 0x5f, 0xb0, 0x26, 0x53, 0x0c, 0x97, 0xdd, 0x8c, 0x93, - 0x44, 0xd9, 0x1f, 0xe1, 0x7f, 0x96, 0x98, 0x2c, 0x88, 0x1f, 0x55, 0x98, 0x67, 0x5e, 0x9e, 0x97, - 0x8c, 0x38, 0xf4, 0x14, 0x71, 0x48, 0xa1, 0x23, 0xf6, 0xd1, 0xcb, 0x9d, 0xe0, 0xc7, 0x41, 0xad, - 0x70, 0xcc, 0xef, 0x88, 0x7d, 0xc1, 0xea, 0x78, 0xe8, 0x79, 0x0b, 0x91, 0x5c, 0x6f, 0xa0, 0xa2, - 0x83, 0x77, 0xcf, 0x5b, 0xe0, 0x32, 0xb5, 0x0f, 0xe2, 0x74, 0xc3, 0x60, 0xd1, 0xc4, 0xe7, 0x44, - 0xe4, 0x10, 0x58, 0xc3, 0x6b, 0x82, 0x10, 0xe5, 0xb5, 0xd8, 0xb7, 0xf0, 0x86, 0x06, 0xc2, 0x59, - 0x73, 0xd1, 0x5c, 0x2d, 0xd7, 0xb2, 0xcb, 0xee, 0xee, 0xbe, 0x40, 0x0d, 0xe4, 0x26, 0x3d, 0x47, - 0xda, 0x5b, 0x71, 0xf2, 0xcb, 0x43, 0x6e, 0x92, 0x97, 0x62, 0x97, 0x18, 0x0d, 0x54, 0xc7, 0xb2, - 0x38, 0x36, 0x19, 0xe9, 0xb2, 0x59, 0x7f, 0x34, 0xe2, 0xe8, 0x89, 0x2d, 0x70, 0x15, 0x78, 0xce, - 0xdd, 0x75, 0x90, 0xb5, 0xf5, 0x0e, 0xad, 0x86, 0xe0, 0x13, 0x1b, 0x08, 0xea, 0xbb, 0xa5, 0x5d, - 0xc8, 0x47, 0xb1, 0xfa, 0xd1, 0x2d, 0xcf, 0xe7, 0xc4, 0x5f, 0x5f, 0x53, 0xea, 0x9f, 0x2d, 0xb9, - 0xa9, 0x5d, 0xbc, 0xec, 0x7d, 0x5d, 0xe6, 0xe6, 0x33, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x8c, 0xc0, - 0x1b, 0x62, 0x01, 0x00, 0x00, + // 262 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xdd, 0x4a, 0xfc, 0x30, + 0x10, 0xc5, 0xb7, 0xff, 0xbf, 0x5f, 0xa4, 0xd5, 0xc5, 0x20, 0xb2, 0x14, 0x2f, 0xd6, 0x5e, 0xf5, + 0x42, 0x7a, 0x51, 0xdf, 0x40, 0x16, 0x61, 0x2f, 0xc4, 0x25, 0x3e, 0x41, 0x37, 0x1d, 0x96, 0x61, + 0xdb, 0x24, 0x4e, 0x52, 0xa5, 0x0f, 0xe1, 0x3b, 0x4b, 0x4c, 0x2a, 0xe2, 0xc7, 0xe5, 0xf9, 0x9d, + 0x33, 0x67, 0x86, 0x61, 0xa7, 0xda, 0x38, 0xec, 0x07, 0x5b, 0x19, 0xd2, 0x4e, 0xf3, 0x03, 0xab, + 0x55, 0x9f, 0x67, 0x5b, 0xdc, 0xa1, 0x72, 0x81, 0xe5, 0x73, 0x54, 0x9e, 0x2a, 0x6c, 0x22, 0x38, + 0xef, 0x1b, 0xda, 0x83, 0x33, 0x5d, 0x23, 0x21, 0xa2, 0xec, 0x55, 0xd3, 0x1e, 0x28, 0xa8, 0xe2, + 0x9e, 0x5d, 0x6e, 0x08, 0x5a, 0x94, 0xee, 0x69, 0x30, 0xa6, 0x43, 0x20, 0x01, 0xcf, 0x03, 0x58, + 0xc7, 0x6f, 0xd8, 0x71, 0x0b, 0x2f, 0x28, 0xc1, 0x2e, 0x92, 0x65, 0x52, 0xa6, 0x35, 0xaf, 0x7c, + 0x77, 0xb5, 0x0a, 0x50, 0x80, 0xe9, 0x46, 0x31, 0x45, 0x0a, 0xc9, 0x2e, 0x7e, 0xf4, 0x98, 0x6e, + 0xe4, 0xd7, 0xec, 0xd0, 0x10, 0x4a, 0x88, 0x1d, 0x69, 0xe8, 0xd8, 0x78, 0x24, 0x82, 0xc3, 0x4b, + 0x76, 0xa2, 0xa9, 0x05, 0x5a, 0xaf, 0xec, 0xe2, 0xdf, 0xf2, 0x7f, 0x99, 0xd6, 0x59, 0x48, 0xdd, + 0xe1, 0x6e, 0xad, 0x9c, 0xf8, 0x74, 0xeb, 0xb7, 0x84, 0x9d, 0x3d, 0x7a, 0x11, 0x57, 0x69, 0xf2, + 0x57, 0x46, 0xc1, 0xf9, 0x34, 0xd5, 0x0a, 0xb0, 0x7a, 0x20, 0x09, 0x36, 0xff, 0xba, 0xaf, 0x98, + 0xf1, 0x07, 0x36, 0xff, 0x76, 0x25, 0xbf, 0x9a, 0x12, 0xbf, 0x3d, 0x21, 0xcf, 0xff, 0x70, 0x4d, + 0x37, 0x16, 0xb3, 0xed, 0xd1, 0xc7, 0x0f, 0x6f, 0xdf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xfc, 0xf4, + 0x18, 0x0d, 0x9a, 0x01, 0x00, 0x00, } diff --git a/proto/optimus.proto b/proto/optimus.proto index fb53180b1..db0655477 100644 --- a/proto/optimus.proto +++ b/proto/optimus.proto @@ -1,5 +1,6 @@ syntax = "proto3"; +import "bigint.proto"; import "insonmnia.proto"; import "marketplace.proto"; import "worker.proto"; @@ -17,4 +18,5 @@ message PredictSupplierRequest { message PredictSupplierReply { Price price = 1; + repeated BigInt orderIDs = 2; }