-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust state logic and prune implementation #894
Open
giggsoff
wants to merge
4
commits into
lf-edge:master
Choose a base branch
from
itmo-eve:adjust-state-logic
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,16 +30,17 @@ | |
ExternalIP string | ||
InternalPort string | ||
ExternalPort string | ||
Metadata string | ||
MemoryUsed uint32 | ||
MemoryAvail uint32 | ||
CPUUsage int | ||
Macs []string | ||
Volumes map[string]uint32 | ||
|
||
prevCPUNS uint64 | ||
prevCPUNSTime time.Time | ||
deleted bool | ||
infoTime time.Time | ||
PrevCPUNS uint64 | ||
PrevCPUNSTime time.Time | ||
Deleted bool | ||
InfoTime time.Time | ||
} | ||
|
||
func appStateHeader() string { | ||
|
@@ -117,7 +118,7 @@ | |
} | ||
|
||
func (ctx *State) initApplications(ctrl controller.Cloud, dev *device.Ctx) error { | ||
ctx.applications = make(map[string]*AppInstState) | ||
ctx.Applications = make(map[string]*AppInstState) | ||
for _, el := range dev.GetApplicationInstances() { | ||
app, err := ctrl.GetApplicationInstanceConfig(el) | ||
if err != nil { | ||
|
@@ -144,35 +145,56 @@ | |
Volumes: volumes, | ||
UUID: app.Uuidandversion.Uuid, | ||
} | ||
ctx.applications[app.Uuidandversion.Uuid] = appStateObj | ||
ctx.Applications[app.Uuidandversion.Uuid] = appStateObj | ||
} | ||
return nil | ||
} | ||
|
||
func (ctx *State) applyOldStateApps(state *State) { | ||
for stateID, stateEL := range state.Applications { | ||
found := false | ||
for id := range ctx.Applications { | ||
if id != stateID { | ||
continue | ||
} | ||
ctx.Applications[id] = stateEL | ||
found = true | ||
} | ||
if !found { | ||
if stateEL.Deleted { | ||
continue | ||
} | ||
stateEL.AdamState = notInControllerConfig | ||
ctx.Applications[stateID] = stateEL | ||
} | ||
} | ||
} | ||
|
||
func (ctx *State) processApplicationsByMetric(msg *metrics.ZMetricMsg) { | ||
if appMetrics := msg.GetAm(); appMetrics != nil { | ||
for _, appMetric := range appMetrics { | ||
for _, el := range ctx.applications { | ||
for _, el := range ctx.Applications { | ||
if appMetric.AppID == el.UUID { | ||
el.MemoryAvail = appMetric.Memory.GetAvailMem() | ||
el.MemoryUsed = appMetric.Memory.GetUsedMem() | ||
// if not restarted | ||
if el.prevCPUNS < appMetric.Cpu.TotalNs { | ||
el.CPUUsage = int(float32(appMetric.Cpu.TotalNs-el.prevCPUNS) / float32(msg.GetAtTimeStamp().AsTime().Sub(el.prevCPUNSTime).Nanoseconds()) * 100.0) | ||
if el.PrevCPUNS < appMetric.Cpu.TotalNs { | ||
el.CPUUsage = int(float32(appMetric.Cpu.TotalNs-el.PrevCPUNS) / float32(msg.GetAtTimeStamp().AsTime().Sub(el.PrevCPUNSTime).Nanoseconds()) * 100.0) | ||
} | ||
el.prevCPUNS = appMetric.Cpu.TotalNs | ||
el.prevCPUNSTime = msg.GetAtTimeStamp().AsTime() | ||
el.PrevCPUNS = appMetric.Cpu.TotalNs | ||
el.PrevCPUNSTime = msg.GetAtTimeStamp().AsTime() | ||
break | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
//nolint:cyclop | ||
func (ctx *State) processApplicationsByInfo(im *info.ZInfoMsg) { | ||
switch im.GetZtype() { | ||
Check failure on line 195 in pkg/eve/applications.go GitHub Actions / yetus
|
||
case info.ZInfoTypes_ZiVolume: | ||
for _, app := range ctx.applications { | ||
for _, app := range ctx.Applications { | ||
if len(app.Volumes) == 0 { | ||
continue | ||
} | ||
|
@@ -188,16 +210,23 @@ | |
app.EVEState = fmt.Sprintf("%s (%d%%)", info.ZSwState_DOWNLOAD_STARTED.String(), int(percent)/len(app.Volumes)) | ||
} | ||
} | ||
case info.ZInfoTypes_ZiAppInstMetaData: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional thanks for AppInstMetaData |
||
for _, app := range ctx.Applications { | ||
if im.GetAmdinfo().Uuid == app.UUID { | ||
app.Metadata = string(im.GetAmdinfo().Data) | ||
break | ||
} | ||
} | ||
case info.ZInfoTypes_ZiApp: | ||
appStateObj, ok := ctx.applications[im.GetAinfo().AppID] | ||
appStateObj, ok := ctx.Applications[im.GetAinfo().AppID] | ||
if !ok { | ||
appStateObj = &AppInstState{ | ||
Name: im.GetAinfo().AppName, | ||
Image: "-", | ||
AdamState: notInControllerConfig, | ||
UUID: im.GetAinfo().AppID, | ||
} | ||
ctx.applications[im.GetAinfo().AppID] = appStateObj | ||
ctx.Applications[im.GetAinfo().AppID] = appStateObj | ||
} | ||
appStateObj.EVEState = im.GetAinfo().State.String() | ||
if len(im.GetAinfo().AppErr) > 0 { | ||
|
@@ -227,20 +256,20 @@ | |
//check appStateObj not defined in adam | ||
if appStateObj.AdamState != inControllerConfig { | ||
if im.GetAinfo().AppID == appStateObj.UUID { | ||
appStateObj.deleted = false //if in recent ZInfoTypes_ZiApp, then not deleted | ||
appStateObj.Deleted = false //if in recent ZInfoTypes_ZiApp, then not deleted | ||
} | ||
} | ||
if im.GetAinfo().State == info.ZSwState_INVALID { | ||
appStateObj.deleted = true | ||
appStateObj.Deleted = true | ||
} | ||
appStateObj.infoTime = im.AtTimeStamp.AsTime() | ||
appStateObj.InfoTime = im.AtTimeStamp.AsTime() | ||
case info.ZInfoTypes_ZiNetworkInstance: //try to find ips from NetworkInstances | ||
for _, el := range im.GetNiinfo().IpAssignments { | ||
// nothing to show if no IpAddress received | ||
if len(el.IpAddress) == 0 { | ||
continue | ||
} | ||
for _, appStateObj := range ctx.applications { | ||
for _, appStateObj := range ctx.Applications { | ||
for ind, mac := range appStateObj.Macs { | ||
if mac == el.MacAddress { | ||
appStateObj.InternalIP[ind] = el.IpAddress[0] | ||
|
@@ -250,18 +279,18 @@ | |
} | ||
case info.ZInfoTypes_ZiDevice: | ||
for _, el := range im.GetDinfo().AppInstances { | ||
if _, ok := ctx.applications[el.Uuid]; !ok { | ||
if _, ok := ctx.Applications[el.Uuid]; !ok { | ||
appStateObj := &AppInstState{ | ||
Name: el.Name, | ||
Image: "-", | ||
AdamState: notInControllerConfig, | ||
EVEState: "UNKNOWN", | ||
UUID: el.Uuid, | ||
} | ||
ctx.applications[el.Uuid] = appStateObj | ||
ctx.Applications[el.Uuid] = appStateObj | ||
} | ||
} | ||
for _, appStateObj := range ctx.applications { | ||
for _, appStateObj := range ctx.Applications { | ||
seen := false | ||
for _, el := range im.GetDinfo().AppInstances { | ||
if appStateObj.UUID == el.Uuid { | ||
|
@@ -289,12 +318,12 @@ | |
appStateObj.ExternalIP = "127.0.0.1" | ||
} | ||
//check appStateObj not defined in adam | ||
if appStateObj.AdamState != inControllerConfig && appStateObj.infoTime.Before(im.AtTimeStamp.AsTime()) { | ||
appStateObj.deleted = true | ||
if appStateObj.AdamState != inControllerConfig && appStateObj.InfoTime.Before(im.AtTimeStamp.AsTime()) { | ||
appStateObj.Deleted = true | ||
for _, el := range im.GetDinfo().AppInstances { | ||
//if in recent ZInfoTypes_ZiDevice with timestamp after ZInfoTypes_ZiApp, than not deleted | ||
//if in recent ZInfoTypes_ZiDevice with timestamp after ZInfoTypes_ZiApp, then not deleted | ||
if el.Uuid == appStateObj.UUID { | ||
appStateObj.deleted = false | ||
appStateObj.Deleted = false | ||
} | ||
} | ||
} | ||
|
@@ -308,8 +337,8 @@ | |
if _, err := fmt.Fprintln(w, appStateHeader()); err != nil { | ||
return err | ||
} | ||
appStatesSlice := make([]*AppInstState, 0, len(ctx.Applications())) | ||
appStatesSlice = append(appStatesSlice, ctx.Applications()...) | ||
appStatesSlice := make([]*AppInstState, 0, len(ctx.NotDeletedApplications())) | ||
appStatesSlice = append(appStatesSlice, ctx.NotDeletedApplications()...) | ||
sort.SliceStable(appStatesSlice, func(i, j int) bool { | ||
return appStatesSlice[i].Name < appStatesSlice[j].Name | ||
}) | ||
|
@@ -322,7 +351,7 @@ | |
} | ||
|
||
func (ctx *State) printPodListJSON() error { | ||
result, err := json.MarshalIndent(ctx.Applications(), "", " ") | ||
result, err := json.MarshalIndent(ctx.NotDeletedApplications(), "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to export Applications?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to store the state in file (using json functions), which requires to export fields