-
Notifications
You must be signed in to change notification settings - Fork 39
/
resource_component.go
164 lines (157 loc) · 4.65 KB
/
resource_component.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/seal-io/walrus/pkg/dao/entx"
"github.com/seal-io/walrus/pkg/dao/schema/intercept"
"github.com/seal-io/walrus/pkg/dao/schema/mixin"
"github.com/seal-io/walrus/pkg/dao/types"
"github.com/seal-io/walrus/pkg/dao/types/object"
)
type ResourceComponent struct {
ent.Schema
}
func (ResourceComponent) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.ID(),
mixin.Time(),
mixin.Status(),
}
}
func (ResourceComponent) Fields() []ent.Field {
return []ent.Field{
object.IDField("project_id").
Comment("ID of the project to belong.").
NotEmpty().
Immutable(),
object.IDField("environment_id").
Comment("ID of the environment to which the component belongs.").
NotEmpty().
Immutable(),
object.IDField("resource_id").
Comment("ID of the resource to which the component belongs.").
NotEmpty().
Immutable(),
object.IDField("connector_id").
Comment("ID of the connector to which the component deploys.").
NotEmpty().
Immutable(),
object.IDField("composition_id").
Comment("ID of the parent component.").
Optional().
Immutable(),
object.IDField("class_id").
Comment("ID of the parent class of the component realization.").
Optional().
Immutable(),
field.String("mode").
Comment("Mode that manages the generated component, " +
"it is the management way of the deployer to the component, " +
"which provides by deployer.").
NotEmpty().
Immutable(),
field.String("type").
Comment("Type of the generated component, " +
"it is the type of the resource which the deployer observes, " +
"which provides by deployer.").
NotEmpty().
Immutable().
StructTag(`json:"type,omitempty,cli-table-column"`),
field.String("name").
Comment("Name of the generated component, " +
"it is the real identifier of the component, " +
"which provides by deployer.").
NotEmpty().
Immutable(),
field.String("deployer_type").
Comment("Type of deployer.").
NotEmpty().
Immutable(),
field.String("shape").
Comment("Shape of the component, it can be class or instance shape.").
NotEmpty().
Immutable(),
field.JSON("keys", &types.ResourceComponentOperationKeys{}).
Comment("Keys of the component.").
Optional().
Annotations(
entx.SkipInput(),
entx.SkipStoringField()),
field.String("index_key").
Comment("Index key to identify the component instance.").
Optional().
Immutable().
Annotations(
entx.SkipInput(),
),
}
}
func (ResourceComponent) Edges() []ent.Edge {
return []ent.Edge{
// Project 1-* ResourceComponents.
edge.From("project", Project.Type).
Ref("resource_components").
Field("project_id").
Comment("Project to which the component belongs.").
Unique().
Required().
Immutable().
Annotations(
entx.ValidateContext(intercept.WithProjectInterceptor)),
// Environment 1-* ResourceComponents.
edge.From("environment", Environment.Type).
Ref("resource_components").
Field("environment_id").
Comment("Environment to which the component deploys.").
Unique().
Required().
Immutable(),
// Resource 1-* ResourceComponents.
edge.From("resource", Resource.Type).
Ref("components").
Field("resource_id").
Comment("Resource to which the component belongs.").
Unique().
Required().
Immutable(),
// Connector 1-* ResourceComponents.
edge.From("connector", Connector.Type).
Ref("resource_components").
Field("connector_id").
Comment("Connector to which the component deploys.").
Unique().
Required().
Immutable().
Annotations(
entx.SkipInput()),
// ResourceComponent (!discovered) 1-* ResourceComponents (discovered).
edge.To("components", ResourceComponent.Type).
Comment("Components that makes up the resource component.").
From("composition").
Field("composition_id").
Unique().
Immutable().
Annotations(
entsql.OnDelete(entsql.Cascade)),
// ResourceComponent (class) 1-* ResourceComponents (instance).
edge.To("instances", ResourceComponent.Type).
Comment("Instances that realizes the resource component.").
From("class").
Field("class_id").
Unique().
Immutable().
Annotations(
entsql.OnDelete(entsql.Cascade)),
// ResourceComponent 1-* ResourceComponents (dependency).
edge.To("dependencies", ResourceComponent.Type).
Comment("Dependencies that requires for the resource component.").
Through("resource_component_relationships", ResourceComponentRelationship.Type),
}
}
func (ResourceComponent) Interceptors() []ent.Interceptor {
return []ent.Interceptor{
intercept.ByProject("project_id"),
}
}