MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / Delete

Method Delete

service/admin/node.go:220–256  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

218}
219
220func (s *SingleNodeService) Delete(c *gin.Context) error {
221 dep := dependency.FromContext(c)
222 nodeClient := dep.NodeClient()
223
224 ctx := context.WithValue(c, inventory.LoadNodeStoragePolicy{}, true)
225 existing, err := nodeClient.GetNodeById(ctx, s.ID)
226 if err != nil {
227 return serializer.NewError(serializer.CodeDBError, "Failed to get node", err)
228 }
229
230 if existing.Type == node.TypeMaster {
231 return serializer.NewError(serializer.CodeInvalidActionOnSystemNode, "", nil)
232 }
233
234 if len(existing.Edges.StoragePolicy) > 0 {
235 return serializer.NewError(
236 serializer.CodeNodeUsedByStoragePolicy,
237 strings.Join(lo.Map(existing.Edges.StoragePolicy, func(i *ent.StoragePolicy, _ int) string {
238 return i.Name
239 }), ", "),
240 nil,
241 )
242 }
243
244 // insert dummpy disabled node in nodepool to evict it
245 disabledNode := &ent.Node{
246 ID: s.ID,
247 Type: node.TypeSlave,
248 Status: node.StatusSuspended,
249 }
250 np, err := dep.NodePool(c)
251 if err != nil {
252 return serializer.NewError(serializer.CodeInternalSetting, "Failed to get node pool", err)
253 }
254 np.Upsert(c, disabledNode)
255 return nodeClient.Delete(c, s.ID)
256}

Callers

nothing calls this directly

Calls 8

FromContextFunction · 0.92
NewErrorFunction · 0.92
JoinMethod · 0.80
NodeClientMethod · 0.65
GetNodeByIdMethod · 0.65
NodePoolMethod · 0.65
UpsertMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected