Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit 6eb5bcf

Browse files
authored
Merge pull request #36 from humpback/develop-0.0.1
add failed status to service
2 parents f9cd766 + 5317458 commit 6eb5bcf

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

backend/scheduler/serviceManager.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func (sm *ServiceManager) Reconcile() {
7979
sm.ServiceInfo = svc
8080
sm.PrepareMeta()
8181
sm.CheckNodeStatus()
82+
83+
// Failed的情况下,如果service或者node有变动,尝试重新调度
84+
if sm.ServiceInfo.Status == types.ServiceStatusFailed {
85+
sm.ServiceInfo.Status = types.ServiceStatusNotReady
86+
}
8287
}
8388

8489
if sm.ServiceInfo.Status == types.ServiceStatusRunning &&
@@ -104,6 +109,12 @@ func (sm *ServiceManager) Reconcile() {
104109
return
105110
}
106111

112+
// 服务处于failed状态,就不需要再做任何操作
113+
if sm.ServiceInfo.Status == types.MemoCreateContainerFailed {
114+
slog.Info("[Service Manager] Service is failed......", "ServiceId", sm.ServiceInfo.ServiceId)
115+
return
116+
}
117+
107118
// 所有容器都是正常的,就不需要再做任何操作
108119
if sm.ServiceInfo.Status == types.ServiceStatusRunning && sm.IsContainerAllReady() {
109120
slog.Info("[Service Manager] Service is running ok......", "ServiceId", sm.ServiceInfo.ServiceId)
@@ -119,6 +130,14 @@ func (sm *ServiceManager) Reconcile() {
119130
return
120131
}
121132

133+
// 如果有容器失败,就不再继续
134+
if sm.ServiceInfo.Deployment.Type != types.DeployTypeSchedule && sm.HasFailedContainer() {
135+
slog.Info("[Service Manager] container failed, stop dispatch......", "ServiceId", sm.ServiceInfo.ServiceId)
136+
sm.ServiceInfo.Status = types.ServiceStatusFailed
137+
db.ServiceUpdate(sm.ServiceInfo)
138+
return
139+
}
140+
122141
// 先选一个容器做删除
123142
if c, ok := sm.TryToDeleteOne(); ok {
124143
nodeId := c.NodeId
@@ -291,6 +310,16 @@ func (sm *ServiceManager) HasPendingContainer() bool {
291310
return false
292311
}
293312

313+
func (sm *ServiceManager) HasFailedContainer() bool {
314+
for _, c := range sm.ServiceInfo.Containers {
315+
version := parseVersionByContainerId(c.ContainerName)
316+
if isContainerFailed(c.State) && version == sm.ServiceInfo.Version {
317+
return true
318+
}
319+
}
320+
return false
321+
}
322+
294323
func (sm *ServiceManager) TryToDeleteOne() (*types.ContainerStatus, bool) {
295324

296325
nodeDeployed := make(map[string]bool)
@@ -305,7 +334,7 @@ func (sm *ServiceManager) TryToDeleteOne() (*types.ContainerStatus, bool) {
305334
return c, true
306335
}
307336
}
308-
if isContainerFailed(c.State) || isContainerRemoved(c.State) {
337+
if isContainerWarning(c.State) || isContainerRemoved(c.State) {
309338
return c, true
310339
}
311340

@@ -340,6 +369,7 @@ func (sm *ServiceManager) StartNextContainer() {
340369
if len(nodes) == 0 {
341370
slog.Error("[Service Manager] Start Service error: No available nodes", "ServiceId", sm.ServiceInfo.ServiceId)
342371
sm.ServiceInfo.Memo = types.MemoNoAvailableNode
372+
sm.ServiceInfo.Status = types.ServiceStatusFailed
343373
return
344374
}
345375

@@ -348,6 +378,7 @@ func (sm *ServiceManager) StartNextContainer() {
348378
if nodeId == "" {
349379
slog.Error("[Service Manager] Start Service error: No available nodes", "ServiceId", sm.ServiceInfo.ServiceId)
350380
sm.ServiceInfo.Memo = types.MemoNoAvailableNode
381+
sm.ServiceInfo.Status = types.ServiceStatusFailed
351382
return
352383
}
353384

@@ -441,6 +472,7 @@ func (sm *ServiceManager) UpdateContainerWhenChanged(cs types.ContainerStatus) {
441472
ct.Env = cs.Env
442473
ct.Mounts = cs.Mounts
443474
ct.Ports = cs.Ports
475+
ct.ErrorMsg = cs.ErrorMsg
444476
if ct.State == types.ContainerStatusRunning {
445477
ct.ErrorMsg = ""
446478
}

backend/scheduler/util.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ func isContainerStarting(status string) bool {
4646
status == types.ContainerStatusStarting
4747
}
4848

49+
func isContainerWarning(status string) bool {
50+
return status == types.ContainerStatusWarning
51+
}
52+
4953
func isContainerFailed(status string) bool {
50-
return status == types.ContainerStatusFailed ||
51-
status == types.ContainerStatusWarning
54+
return status == types.ContainerStatusFailed
5255
}
5356

5457
func isPlacementMatched(node *types.Node, p *types.PlacementInfo) bool {

0 commit comments

Comments
 (0)