Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

feat: record environment id in service resource. #1099

Merged
merged 3 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions pkg/apis/environment/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ import (
"github.com/seal-io/seal/pkg/dao/model"
"github.com/seal-io/seal/pkg/dao/model/service"
"github.com/seal-io/seal/pkg/dao/model/servicerelationship"
"github.com/seal-io/seal/pkg/dao/model/serviceresource"
"github.com/seal-io/seal/pkg/dao/types"
"github.com/seal-io/seal/pkg/dao/types/object"
optypes "github.com/seal-io/seal/pkg/operator/types"
pkgresource "github.com/seal-io/seal/pkg/serviceresources"
)

var getServiceFields = service.WithoutFields(
service.FieldUpdateTime)

func (h Handler) RouteGetGraph(req RouteGetGraphRequest) (*RouteGetGraphResponse, error) {
// Fetch service entities.
entities, err := h.modelClient.Services().Query().
Where(service.EnvironmentID(req.ID)).
Order(model.Desc(service.FieldCreateTime)).
Select(getFields...).
Select(getServiceFields...).
// Must extract dependency.
WithDependencies(func(dq *model.ServiceRelationshipQuery) {
dq.Select(servicerelationship.FieldDependencyID).
Expand All @@ -29,12 +31,7 @@ func (h Handler) RouteGetGraph(req RouteGetGraphRequest) (*RouteGetGraphResponse
}).
// Must extract resource.
WithResources(func(rq *model.ServiceResourceQuery) {
dao.ServiceResourceShapeClassQuery(rq).
Where(
serviceresource.Shape(types.ServiceResourceShapeClass),
serviceresource.Mode(types.ServiceResourceModeManaged),
).
Order(model.Desc(serviceresource.FieldCreateTime))
dao.ServiceResourceShapeClassQuery(rq)
}).
Unique(false).
All(req.Context)
Expand All @@ -53,6 +50,7 @@ func (h Handler) RouteGetGraph(req RouteGetGraphRequest) (*RouteGetGraphResponse

for i := 0; i < len(entities); i++ {
entity := entities[i]

// Append Service to vertices.
vertices = append(vertices, GraphVertex{
GraphVertexID: GraphVertexID{
Expand All @@ -65,9 +63,13 @@ func (h Handler) RouteGetGraph(req RouteGetGraphRequest) (*RouteGetGraphResponse
CreateTime: entity.CreateTime,
UpdateTime: entity.UpdateTime,
Status: entity.Status.Summary,
Extensions: map[string]any{
"projectID": entity.ProjectID,
"environmentID": entity.EnvironmentID,
},
})

// Append the edge of Service to Service.
// Append the link of related Services to edges.
for j := 0; j < len(entity.Edges.Dependencies); j++ {
edges = append(edges, GraphEdge{
Type: types.EdgeTypeDependency,
Expand All @@ -82,15 +84,14 @@ func (h Handler) RouteGetGraph(req RouteGetGraphRequest) (*RouteGetGraphResponse
})
}

// Append ServiceResource to vertices,
// and append the link of related ServiceResources to edges.
pkgresource.SetKeys(req.Context, entity.Edges.Resources, operators)
vertices, edges = pkgresource.GetVerticesAndEdges(
entity.Edges.Resources,
vertices,
edges,
)
entity.Edges.Resources, vertices, edges)

for j := 0; j < len(entity.Edges.Resources); j++ {
// Append the edge of Service to ServiceResource.
// Append the link from Service to ServiceResource into edges.
edges = append(edges, GraphEdge{
Type: types.EdgeTypeComposition,
Start: GraphVertexID{
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/service/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ var (
service.FieldName,
}
getFields = service.WithoutFields(
service.FieldEnvironmentID,
service.FieldUpdateTime)
sortFields = []string{
service.FieldName,
Expand Down
30 changes: 4 additions & 26 deletions pkg/apis/service/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,31 +421,8 @@ func (h Handler) getServiceOutputs(ctx context.Context, id object.ID, onlySucces
}

func (h Handler) RouteGetGraph(req RouteGetGraphRequest) (*RouteGetGraphResponse, error) {
fields := []string{
serviceresource.FieldServiceID,
serviceresource.FieldDeployerType,
serviceresource.FieldType,
serviceresource.FieldID,
serviceresource.FieldName,
serviceresource.FieldMode,
serviceresource.FieldShape,
serviceresource.FieldClassID,
serviceresource.FieldCreateTime,
serviceresource.FieldUpdateTime,
serviceresource.FieldStatus,
}

// Fetch entities.
query := h.modelClient.ServiceResources().Query().
Select(fields...).
Order(model.Desc(serviceresource.FieldCreateTime)).
Where(
serviceresource.ServiceID(req.ID),
serviceresource.Mode(types.ServiceResourceModeManaged),
serviceresource.Shape(types.ServiceResourceShapeClass),
)

entities, err := dao.ServiceResourceShapeClassQuery(query, fields...).
entities, err := dao.ServiceResourceShapeClassQuery(h.modelClient.ServiceResources().Query()).
Where(serviceresource.ServiceID(req.ID)).
All(req.Context)
if err != nil {
return nil, err
Expand All @@ -472,7 +449,8 @@ func (h Handler) RouteGetGraph(req RouteGetGraphRequest) (*RouteGetGraphResponse
)

pkgresource.SetKeys(req.Context, entities, operators)
vertices, edges = pkgresource.GetVerticesAndEdges(entities, vertices, edges)
vertices, edges = pkgresource.GetVerticesAndEdges(
entities, vertices, edges)

return &RouteGetGraphResponse{
Vertices: vertices,
Expand Down
38 changes: 38 additions & 0 deletions pkg/dao/model/client.go

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

20 changes: 18 additions & 2 deletions pkg/dao/model/environment.go

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

30 changes: 30 additions & 0 deletions pkg/dao/model/environment/environment.go

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

29 changes: 29 additions & 0 deletions pkg/dao/model/environment/where.go

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

33 changes: 33 additions & 0 deletions pkg/dao/model/environment_create.go

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

Loading