MCPcopy
hub / github.com/baetyl/baetyl / reportAndApply

Method reportAndApply

engine/engine.go:265–333  ·  view source on GitHub ↗
(isSys, delete bool, desire specv1.Desire)

Source from the content-addressed store, hash-verified

263}
264
265func (e *engineImpl) reportAndApply(isSys, delete bool, desire specv1.Desire) error {
266 var ns string
267 if isSys {
268 ns = context.EdgeSystemNamespace()
269 } else {
270 ns = context.EdgeNamespace()
271 }
272 r := e.Collect(ns, isSys, desire)
273 e.log.Debug("collect stats of node and apps", log.Any("report", r))
274
275 rapps := r.AppInfos(isSys)
276 delta, err := e.nod.Report(r, false)
277 if err != nil {
278 return errors.Trace(err)
279 }
280 // if apps are updated, to apply new apps
281 if delta == nil {
282 return nil
283 }
284 // in the case of cloud data synchronization, return from here
285 dapps := specv1.Desire(delta).AppInfos(isSys)
286 if dapps == nil {
287 return nil
288 }
289
290 e.log.Debug("before filter", log.Any("dapps", dapps), log.Any("rapps", rapps))
291 switch os.Getenv(context.KeySvcName) {
292 case specv1.BaetylCore:
293 dapps = filterAppNotLike(dapps, []string{specv1.BaetylCore})
294 rapps = filterAppNotLike(rapps, []string{specv1.BaetylCore})
295 case specv1.BaetylInit:
296 dapps = filterAppLike(dapps, []string{specv1.BaetylCore})
297 rapps = filterAppLike(rapps, []string{specv1.BaetylCore})
298 }
299 e.log.Debug("after filter", log.Any("dapps", dapps), log.Any("rapps", rapps))
300
301 del, update := getDeleteAndUpdate(dapps, rapps)
302 e.log.Debug("delete and update list", log.Any("delete", del), log.Any("update", update))
303
304 stats := map[string]specv1.AppStats{}
305 for _, s := range r.AppStats(isSys) {
306 stats[s.Name] = s
307 }
308 appData, err := e.syn.SyncApps(dapps)
309 if err != nil {
310 return errors.Trace(err)
311 }
312 // will remove invalid app info in update
313 // multiple apps change to multiple containers , remove checkService
314 // checkService(dapps, appData, stats, update)
315 checkMultiAppPort(dapps, appData, stats, update)
316 if err = e.reportAppStatsIfNeed(isSys, r, stats); err != nil {
317 return errors.Trace(err)
318 }
319 if delete {
320 for n := range del {
321 if err := e.ami.DeleteApp(ns, n); err != nil {
322 e.log.Error("failed to delete applications", log.Any("system", isSys), log.Error(err))

Callers 2

reportAndDesireAsyncMethod · 0.95
TestReportAndApplyFunction · 0.95

Calls 12

CollectMethod · 0.95
reportAppStatsIfNeedMethod · 0.95
applyAppsMethod · 0.95
filterAppNotLikeFunction · 0.85
filterAppLikeFunction · 0.85
getDeleteAndUpdateFunction · 0.85
checkMultiAppPortFunction · 0.85
DebugMethod · 0.65
ReportMethod · 0.65
DesireMethod · 0.65
SyncAppsMethod · 0.65
DeleteAppMethod · 0.65

Tested by 1

TestReportAndApplyFunction · 0.76