MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / SetCluster

Method SetCluster

service/plugin-cluster/iml.go:159–209  ·  view source on GitHub ↗
(ctx context.Context, clusterId string, name string, status plugin_model.Status, config plugin_model.ConfigType)

Source from the content-addressed store, hash-verified

157}
158
159func (i *imlPluginService) SetCluster(ctx context.Context, clusterId string, name string, status plugin_model.Status, config plugin_model.ConfigType) error {
160 operator := utils.UserId(ctx)
161
162 return i.defineStore.Transaction(ctx, func(txCtx context.Context) error {
163
164 define, err := i.defineStore.First(ctx, map[string]interface{}{
165 "name": name,
166 })
167 if err != nil {
168 if errors.Is(err, gorm.ErrRecordNotFound) {
169 return fmt.Errorf("plugin not exits:%s", name)
170 }
171 return err
172 }
173 if define.Kind != plugin_model.OpenKind {
174 return fmt.Errorf("plugin not support config: %s[%s] width %s", define.Cname, name, define.Cname)
175 }
176 conf, err := i.pluginPartitionStore.First(ctx, map[string]interface{}{
177 "partition": clusterId,
178 "name": name,
179 })
180 if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
181 return err
182 }
183 if conf == nil {
184 conf = &plugin.Partition{
185 Id: 0,
186 Partition: clusterId,
187 Plugin: define.Name,
188 Config: config,
189 Status: status,
190 CreateTime: time.Now(),
191 UpdateTime: time.Now(),
192 Operator: operator,
193 }
194 return i.pluginPartitionStore.Insert(ctx, conf)
195 } else {
196 conf.Config = config
197 conf.Status = status
198 conf.Operator = operator
199 conf.UpdateTime = time.Now()
200 _, err := i.pluginPartitionStore.Update(ctx, conf)
201 if err != nil {
202 return err
203 }
204 return nil
205 }
206
207 })
208
209}
210
211func (i *imlPluginService) ListCluster(ctx context.Context, clusterId string, kind ...plugin_model.Kind) ([]*ConfigPartition, error) {
212

Callers

nothing calls this directly

Calls 1

UpdateMethod · 0.65

Tested by

no test coverage detected