mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 18:58:02 +08:00
Merge pull request #862 from GLYASAI/startup-sequence
bug fix: circular dependency
This commit is contained in:
commit
45b6db9819
@ -312,18 +312,19 @@ func (s *ServiceDependency) buildLinkListByHead(l *list.List) []*list.List {
|
||||
if !ok {
|
||||
copy := list.New()
|
||||
copy.PushBackList(l)
|
||||
return []*list.List{l}
|
||||
return []*list.List{copy}
|
||||
}
|
||||
|
||||
var result []*list.List
|
||||
for _, depsid := range depsids {
|
||||
// child node is already in the linked list
|
||||
if alreadyInLinkedList(l, depsid) {
|
||||
if alreadyInLinkedList(l, depsid) || s.childInLinkedList(l, depsid) {
|
||||
copy := list.New()
|
||||
copy.PushBackList(l)
|
||||
result = append(result, copy)
|
||||
continue
|
||||
}
|
||||
|
||||
newl := list.New()
|
||||
newl.PushBackList(l)
|
||||
newl.PushBack(depsid)
|
||||
@ -341,6 +342,21 @@ func (s *ServiceDependency) buildLinkListByHead(l *list.List) []*list.List {
|
||||
return result
|
||||
}
|
||||
|
||||
func (s *ServiceDependency) childInLinkedList(l *list.List, sid string) bool {
|
||||
depsids, ok := s.sid2depsids[sid]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, depsid := range depsids {
|
||||
if alreadyInLinkedList(l, depsid) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func alreadyInLinkedList(l *list.List, depsid string) bool {
|
||||
pre := l.Back()
|
||||
for pre != nil {
|
||||
|
@ -167,6 +167,32 @@ func TestBuildLinkListByHead(t *testing.T) {
|
||||
return []*list.List{l}
|
||||
}(),
|
||||
},
|
||||
{
|
||||
name: "spring cloud pig",
|
||||
l: func() *list.List {
|
||||
l := list.New()
|
||||
l.PushBack("banana")
|
||||
return l
|
||||
}(),
|
||||
sid2depsids: map[string][]string{
|
||||
"apple": []string{"banana"},
|
||||
"banana": []string{"apple", "cat", "dog"},
|
||||
},
|
||||
want: func() []*list.List {
|
||||
l1 := list.New()
|
||||
l1.PushBack("banana")
|
||||
|
||||
l2 := list.New()
|
||||
l2.PushBack("banana")
|
||||
l2.PushBack("cat")
|
||||
|
||||
l3 := list.New()
|
||||
l3.PushBack("banana")
|
||||
l3.PushBack("dog")
|
||||
|
||||
return []*list.List{l1, l2, l3}
|
||||
}(),
|
||||
},
|
||||
}
|
||||
|
||||
for idx := range tests {
|
||||
|
@ -22,7 +22,7 @@ func CheckTenantResource(tenant *dbmodel.Tenants, needMemory int) error {
|
||||
}
|
||||
clusterInfo, err := GetTenantManager().GetAllocatableResources()
|
||||
if err != nil {
|
||||
logrus.Errorf("get cluster resources failure for check tenant resource.", err.Error())
|
||||
logrus.Errorf("get cluster resources failure for check tenant resource: %v", err.Error())
|
||||
}
|
||||
if clusterInfo != nil {
|
||||
clusterAvailMemory := clusterInfo.AllMemory - clusterInfo.RequestMemory
|
||||
|
Loading…
Reference in New Issue
Block a user