From 52a939b3a1404436d8102a33639f86a9d64d7da8 Mon Sep 17 00:00:00 2001 From: MuZhou233 Date: Wed, 25 Sep 2024 11:11:34 +0800 Subject: [PATCH] feat: update proto to v0.4.23 --- app/sephirah/cmd/sephirah/wire_gen.go | 13 +++--- app/sephirah/internal/biz/bizangela/angela.go | 8 +++- app/sephirah/internal/biz/bizangela/notify.go | 11 +++++ app/sephirah/internal/biz/bizangela/porter.go | 23 ++++++++++ app/sephirah/internal/data/angela.go | 42 +++++++++++++++++++ .../data/internal/converter/generated.go | 6 +++ app/sephirah/internal/data/netzach.go | 11 +++++ .../internal/model/converter/generated.go | 13 ++++++ .../model/modelsupervisor/modelsupervisor.go | 11 ++--- .../service/librariansephirahservice.go | 4 +- app/sephirah/internal/service/porter.go | 27 ++++++++++++ app/sephirah/pkg/service/wire_gen.go | 2 +- go.mod | 2 +- go.sum | 4 +- 14 files changed, 160 insertions(+), 17 deletions(-) create mode 100644 app/sephirah/internal/biz/bizangela/porter.go create mode 100644 app/sephirah/internal/service/porter.go diff --git a/app/sephirah/cmd/sephirah/wire_gen.go b/app/sephirah/cmd/sephirah/wire_gen.go index fc0af4d..581468f 100644 --- a/app/sephirah/cmd/sephirah/wire_gen.go +++ b/app/sephirah/cmd/sephirah/wire_gen.go @@ -38,21 +38,22 @@ func wireApp(sephirahServer *conf.SephirahServer, database *conf.Database, s3 *c if err != nil { return nil, nil, err } - builtInObserver, err := libobserve.NewBuiltInObserver() + entClient, cleanup, err := data.NewSQLClient(database, settings) if err != nil { return nil, nil, err } - libmqMQ, cleanup, err := libmq.NewMQ(mq, database, cache, settings, builtInObserver) + dataData := data.NewData(entClient) + angelaRepo := data.NewAngelaRepo(dataData) + builtInObserver, err := libobserve.NewBuiltInObserver() if err != nil { + cleanup() return nil, nil, err } - entClient, cleanup2, err := data.NewSQLClient(database, settings) + libmqMQ, cleanup2, err := libmq.NewMQ(mq, database, cache, settings, builtInObserver) if err != nil { cleanup() return nil, nil, err } - dataData := data.NewData(entClient) - angelaRepo := data.NewAngelaRepo(dataData) librarianPorterServiceClient, err := client.NewPorterClient(consul, porter, settings) if err != nil { cleanup2() @@ -108,7 +109,7 @@ func wireApp(sephirahServer *conf.SephirahServer, database *conf.Database, s3 *c topic6 := bizangela.NewNotifyRouterTopic(angelaBase, map4, map5, topic5) topic7 := bizangela.NewFeedItemPostprocessTopic(angelaBase, topic6, topic) topic8 := bizangela.NewPullFeedTopic(angelaBase, topic7, topic) - angela, err := bizangela.NewAngela(libmqMQ, topic4, topic3, topic2, topic8, topic6, topic5, topic7, libmqTopic) + angela, err := bizangela.NewAngela(angelaBase, libmqMQ, topic4, topic3, topic2, topic8, topic6, topic5, topic7, libmqTopic) if err != nil { cleanup2() cleanup() diff --git a/app/sephirah/internal/biz/bizangela/angela.go b/app/sephirah/internal/biz/bizangela/angela.go index 92142ba..42a9f20 100644 --- a/app/sephirah/internal/biz/bizangela/angela.go +++ b/app/sephirah/internal/biz/bizangela/angela.go @@ -7,6 +7,7 @@ import ( "github.com/tuihub/librarian/app/sephirah/internal/client" "github.com/tuihub/librarian/app/sephirah/internal/model/modelangela" "github.com/tuihub/librarian/app/sephirah/internal/model/modelgebura" + "github.com/tuihub/librarian/app/sephirah/internal/model/modelsupervisor" "github.com/tuihub/librarian/app/sephirah/internal/model/modeltiphereth" "github.com/tuihub/librarian/app/sephirah/internal/model/modelyesod" "github.com/tuihub/librarian/app/sephirah/internal/supervisor" @@ -36,6 +37,7 @@ var ProviderSet = wire.NewSet( ) type Angela struct { + AngelaBase mq *libmq.MQ } type AngelaBase struct { @@ -58,6 +60,8 @@ type AngelaRepo interface { UpdateFeedPullStatus(context.Context, *modelyesod.FeedConfig) error GetFeedItem(context.Context, model.InternalID) (*modelfeed.Item, error) GetFeedActions(context.Context, model.InternalID) ([]*modelyesod.FeedActionSet, error) + GetNotifyTargetItems(context.Context, model.InternalID, model.Paging) (*modelsupervisor.FeatureRequest, []*modelfeed.Item, error) + AddFeedItemsToCollection(context.Context, model.InternalID, []model.InternalID) error } func NewAngelaBase( @@ -79,6 +83,7 @@ func NewAngelaBase( } func NewAngela( + base *AngelaBase, mq *libmq.MQ, pullAccountInfo *libmq.Topic[modeltiphereth.PullAccountInfo], pullAccountAppInfoRelation *libmq.Topic[modelangela.PullAccountAppInfoRelation], @@ -114,6 +119,7 @@ func NewAngela( return nil, err } return &Angela{ - mq: mq, + AngelaBase: *base, + mq: mq, }, nil } diff --git a/app/sephirah/internal/biz/bizangela/notify.go b/app/sephirah/internal/biz/bizangela/notify.go index 5513953..8527025 100644 --- a/app/sephirah/internal/biz/bizangela/notify.go +++ b/app/sephirah/internal/biz/bizangela/notify.go @@ -52,6 +52,13 @@ func NewNotifyRouterTopic( //nolint:gocognit // TODO if len(messages) == 0 { continue } + itemIDs := make([]model.InternalID, 0, len(messages)) + for _, item := range messages { + if item == nil { + continue + } + itemIDs = append(itemIDs, item.ID) + } for _, target := range flow.Targets { if target == nil { continue @@ -63,6 +70,10 @@ func NewNotifyRouterTopic( //nolint:gocognit // TODO if err != nil { return err } + err = a.repo.AddFeedItemsToCollection(ctx, flowID, itemIDs) + if err != nil { + return err + } } } return nil diff --git a/app/sephirah/internal/biz/bizangela/porter.go b/app/sephirah/internal/biz/bizangela/porter.go new file mode 100644 index 0000000..6187e44 --- /dev/null +++ b/app/sephirah/internal/biz/bizangela/porter.go @@ -0,0 +1,23 @@ +package bizangela + +import ( + "context" + + "github.com/tuihub/librarian/app/sephirah/internal/biz/bizutils" + "github.com/tuihub/librarian/app/sephirah/internal/model/modelsupervisor" + "github.com/tuihub/librarian/internal/lib/libauth" + "github.com/tuihub/librarian/internal/model" + "github.com/tuihub/librarian/internal/model/modelfeed" +) + +func (a *Angela) PorterGetNotifyTargetItems(ctx context.Context, id model.InternalID, paging model.Paging) (*modelsupervisor.FeatureRequest, []*modelfeed.Item, error) { + claims := libauth.FromContextAssertUserType(ctx, libauth.UserTypePorter) + if claims == nil { + return nil, nil, bizutils.NoPermissionError() + } + fr, items, err := a.repo.GetNotifyTargetItems(ctx, id, paging) + if err != nil { + return nil, nil, err + } + return fr, items, nil +} diff --git a/app/sephirah/internal/data/angela.go b/app/sephirah/internal/data/angela.go index 01985c6..3b1063b 100644 --- a/app/sephirah/internal/data/angela.go +++ b/app/sephirah/internal/data/angela.go @@ -14,7 +14,9 @@ import ( "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/feedactionset" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/feedconfig" "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/feeditem" + "github.com/tuihub/librarian/app/sephirah/internal/data/internal/ent/feeditemcollection" "github.com/tuihub/librarian/app/sephirah/internal/model/modelgebura" + "github.com/tuihub/librarian/app/sephirah/internal/model/modelsupervisor" "github.com/tuihub/librarian/app/sephirah/internal/model/modeltiphereth" "github.com/tuihub/librarian/app/sephirah/internal/model/modelyesod" "github.com/tuihub/librarian/internal/model" @@ -315,3 +317,43 @@ func (a *angelaRepo) GetFeedActions(ctx context.Context, id model.InternalID) ([ } return converter.ToBizFeedActionSetList(actions), nil } + +func (a *angelaRepo) GetNotifyTargetItems(ctx context.Context, id model.InternalID, paging model.Paging) (*modelsupervisor.FeatureRequest, []*modelfeed.Item, error) { + var fr *modelsupervisor.FeatureRequest + var it []*modelfeed.Item + err := a.data.WithTx(ctx, func(tx *ent.Tx) error { + target, err := tx.NotifyTarget.Get(ctx, id) + if err != nil { + return err + } + fr = target.Destination + ids, err := target.QueryNotifyFlow().IDs(ctx) + if err != nil { + return err + } + items, err := tx.FeedItem.Query().Where( + feeditem.HasFeedItemCollectionWith( + feeditemcollection.IDIn(ids...), + ), + ).Offset(paging.ToOffset()).Limit(paging.ToLimit()).All(ctx) + if err != nil { + return err + } + it = converter.ToBizFeedItemList(items) + return nil + }) + if err != nil { + return nil, nil, err + } + return fr, it, nil +} + +func (a *angelaRepo) AddFeedItemsToCollection( + ctx context.Context, + collectionID model.InternalID, + itemIDs []model.InternalID, +) error { + return a.data.db.FeedItemCollection.UpdateOneID(collectionID). + AddFeedItemIDs(itemIDs...). + Exec(ctx) +} diff --git a/app/sephirah/internal/data/internal/converter/generated.go b/app/sephirah/internal/data/internal/converter/generated.go index f151071..1c427b8 100644 --- a/app/sephirah/internal/data/internal/converter/generated.go +++ b/app/sephirah/internal/data/internal/converter/generated.go @@ -741,6 +741,12 @@ func pModelsupervisorFeatureFlagToPModelsupervisorFeatureFlag(source *modelsuper modelsupervisorFeatureFlag.Description = (*source).Description modelsupervisorFeatureFlag.ConfigJSONSchema = (*source).ConfigJSONSchema modelsupervisorFeatureFlag.RequireContext = (*source).RequireContext + if (*source).Extra != nil { + modelsupervisorFeatureFlag.Extra = make(map[string]string, len((*source).Extra)) + for key, value := range (*source).Extra { + modelsupervisorFeatureFlag.Extra[key] = value + } + } pModelsupervisorFeatureFlag = &modelsupervisorFeatureFlag } return pModelsupervisorFeatureFlag diff --git a/app/sephirah/internal/data/netzach.go b/app/sephirah/internal/data/netzach.go index 9266150..48cab91 100644 --- a/app/sephirah/internal/data/netzach.go +++ b/app/sephirah/internal/data/netzach.go @@ -138,6 +138,17 @@ func (n *netzachRepo) CreateNotifyFlow(ctx context.Context, userID model.Interna if err != nil { return err } + // For save flow items + err = tx.FeedItemCollection.Create(). + SetOwnerID(userID). + SetID(f.ID). + SetName(f.Name). + SetDescription(f.Description). + SetCategory(""). + Exec(ctx) + if err != nil { + return err + } return nil }) if err != nil { diff --git a/app/sephirah/internal/model/converter/generated.go b/app/sephirah/internal/model/converter/generated.go index d7e9c3c..d2ebe2c 100755 --- a/app/sephirah/internal/model/converter/generated.go +++ b/app/sephirah/internal/model/converter/generated.go @@ -198,6 +198,12 @@ func ToBizFeatureFlag(source *v1.FeatureFlag) *modelsupervisor.FeatureFlag { modelsupervisorFeatureFlag.Description = (*source).Description modelsupervisorFeatureFlag.ConfigJSONSchema = (*source).ConfigJsonSchema modelsupervisorFeatureFlag.RequireContext = (*source).RequireContext + if (*source).Extra != nil { + modelsupervisorFeatureFlag.Extra = make(map[string]string, len((*source).Extra)) + for key, value := range (*source).Extra { + modelsupervisorFeatureFlag.Extra[key] = value + } + } pModelsupervisorFeatureFlag = &modelsupervisorFeatureFlag } return pModelsupervisorFeatureFlag @@ -1045,6 +1051,12 @@ func ToPBFeatureFlag(source *modelsupervisor.FeatureFlag) *v1.FeatureFlag { v1FeatureFlag.Description = (*source).Description v1FeatureFlag.ConfigJsonSchema = (*source).ConfigJSONSchema v1FeatureFlag.RequireContext = (*source).RequireContext + if (*source).Extra != nil { + v1FeatureFlag.Extra = make(map[string]string, len((*source).Extra)) + for key, value := range (*source).Extra { + v1FeatureFlag.Extra[key] = value + } + } pV1FeatureFlag = &v1FeatureFlag } return pV1FeatureFlag @@ -1407,6 +1419,7 @@ func ToPBPorter(source *modelsupervisor.PorterInstanceController) *v11.Porter { v1Porter.BinarySummary = pModelsupervisorPorterBinarySummaryToPV1PorterBinarySummary((*source).PorterInstance.BinarySummary) v1Porter.GlobalName = (*source).PorterInstance.GlobalName v1Porter.Region = (*source).PorterInstance.Region + v1Porter.FeatureSummary = pModelsupervisorPorterFeatureSummaryToPV1FeatureSummary((*source).PorterInstance.FeatureSummary) v1Porter.Status = ToPBUserStatus((*source).PorterInstance.Status) v1Porter.ConnectionStatus = ToPBPorterConnectionStatus((*source).ConnectionStatus) pString := (*source).PorterInstance.ContextJSONSchema diff --git a/app/sephirah/internal/model/modelsupervisor/modelsupervisor.go b/app/sephirah/internal/model/modelsupervisor/modelsupervisor.go index 213693b..0182255 100644 --- a/app/sephirah/internal/model/modelsupervisor/modelsupervisor.go +++ b/app/sephirah/internal/model/modelsupervisor/modelsupervisor.go @@ -54,11 +54,12 @@ type PorterFeatureSummary struct { } type FeatureFlag struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - ConfigJSONSchema string `json:"config_json_schema"` - RequireContext bool `json:"require_context"` + ID string `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + ConfigJSONSchema string `json:"config_json_schema"` + RequireContext bool `json:"require_context"` + Extra map[string]string `json:"extra"` } func (f *FeatureFlag) Match(request *FeatureRequest) bool { diff --git a/app/sephirah/internal/service/librariansephirahservice.go b/app/sephirah/internal/service/librariansephirahservice.go index 7acddb0..00cc2dc 100644 --- a/app/sephirah/internal/service/librariansephirahservice.go +++ b/app/sephirah/internal/service/librariansephirahservice.go @@ -24,6 +24,7 @@ import ( type LibrarianSephirahServiceService struct { pb.UnimplementedLibrarianSephirahServiceServer + a *bizangela.Angela t *biztiphereth.Tiphereth g *bizgebura.Gebura b *bizbinah.Binah @@ -37,7 +38,7 @@ type LibrarianSephirahServiceService struct { } func NewLibrarianSephirahServiceService( - _ *bizangela.Angela, + a *bizangela.Angela, t *biztiphereth.Tiphereth, g *bizgebura.Gebura, b *bizbinah.Binah, @@ -58,6 +59,7 @@ func NewLibrarianSephirahServiceService( } res := &LibrarianSephirahServiceService{ UnimplementedLibrarianSephirahServiceServer: pb.UnimplementedLibrarianSephirahServiceServer{}, + a: a, t: t, g: g, b: b, diff --git a/app/sephirah/internal/service/porter.go b/app/sephirah/internal/service/porter.go new file mode 100644 index 0000000..a304590 --- /dev/null +++ b/app/sephirah/internal/service/porter.go @@ -0,0 +1,27 @@ +package service + +import ( + "context" + + "github.com/tuihub/librarian/app/sephirah/internal/model/converter" + "github.com/tuihub/librarian/internal/model" + pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1" +) + +func (s *LibrarianSephirahServiceService) PorterGetNotifyTargetItems( + ctx context.Context, + req *pb.PorterGetNotifyTargetItemsRequest, +) (*pb.PorterGetNotifyTargetItemsResponse, error) { + fr, items, err := s.a.PorterGetNotifyTargetItems(ctx, + converter.ToBizInternalID(req.GetId()), + model.ToBizPaging(req.GetPaging()), + ) + if err != nil { + return nil, err + } + return &pb.PorterGetNotifyTargetItemsResponse{ + Paging: nil, + Destination: converter.ToPBFeatureRequest(fr), + Items: converter.ToPBFeedItemList(items), + }, nil +} diff --git a/app/sephirah/pkg/service/wire_gen.go b/app/sephirah/pkg/service/wire_gen.go index 20d01aa..68b8978 100644 --- a/app/sephirah/pkg/service/wire_gen.go +++ b/app/sephirah/pkg/service/wire_gen.go @@ -77,7 +77,7 @@ func NewSephirahService(sephirahServer *conf.SephirahServer, database *conf.Data topic6 := bizangela.NewNotifyRouterTopic(angelaBase, map4, map5, topic5) topic7 := bizangela.NewFeedItemPostprocessTopic(angelaBase, topic6, topic) topic8 := bizangela.NewPullFeedTopic(angelaBase, topic7, topic) - angela, err := bizangela.NewAngela(mq, topic4, topic3, topic2, topic8, topic6, topic5, topic7, libmqTopic) + angela, err := bizangela.NewAngela(angelaBase, mq, topic4, topic3, topic2, topic8, topic6, topic5, topic7, libmqTopic) if err != nil { cleanup() return nil, nil, err diff --git a/go.mod b/go.mod index e3b62b6..097e61f 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/redis/go-redis/v9 v9.6.1 github.com/sony/sonyflake v1.2.0 github.com/stretchr/testify v1.9.0 - github.com/tuihub/protos v0.4.22 + github.com/tuihub/protos v0.4.23 github.com/zhihu/norm v0.1.11 go.opentelemetry.io/otel v1.29.0 go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.5.0 diff --git a/go.sum b/go.sum index a504093..ca9f85a 100644 --- a/go.sum +++ b/go.sum @@ -971,8 +971,8 @@ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+F github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tuihub/protos v0.4.22 h1:HtbZSsA8/t1vzWXYKGqRIU07mVEn8v3mrbsllNAON6c= -github.com/tuihub/protos v0.4.22/go.mod h1:lmf29LH3wf7Fb0in47Q/ar2qf2V7ogckV6dnlBrsZ1I= +github.com/tuihub/protos v0.4.23 h1:qKRxguvvVbDNBPItSB3dGYxpz+lsex2sZDXt2NyT8rE= +github.com/tuihub/protos v0.4.23/go.mod h1:lmf29LH3wf7Fb0in47Q/ar2qf2V7ogckV6dnlBrsZ1I= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/tylertreat/BoomFilters v0.0.0-20181028192813-611b3dbe80e8/go.mod h1:OYRfF6eb5wY9VRFkXJH8FFBi3plw2v+giaIu7P054pM= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=