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

Commit 118c289

Browse files
authored
Merge pull request #38 from humpback/develop-0.0.1
Develop 0.0.1
2 parents 5607028 + bbd2588 commit 118c289

File tree

45 files changed

+174
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+174
-162
lines changed

backend/api/handle/models/service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ func (s *ServiceUpdateReqInfo) checkDeployment() error {
403403
} else {
404404
info.Schedule.Timeout = ""
405405
}
406+
if len(info.Schedule.Rules) > 0 {
407+
info.ManualExec = false
408+
}
406409
s.DeploymentInfo = info
407410
return nil
408411
}

backend/internal/controller/controller.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ import (
1111
"humpback/types"
1212
)
1313

14-
type ControllerInter interface {
15-
}
16-
17-
var Controller ControllerInter = &controller{}
18-
19-
type controller struct{}
20-
2114
func Start(stopCh <-chan struct{}) {
2215
go SessionGCInterval(stopCh)
2316
}

backend/internal/node/agentHelper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func StartNewContainer(nodeId, containerName string, svc *types.Service) error {
5050
ServiceName: svc.ServiceName,
5151
ServiceId: svc.ServiceId,
5252
GroupId: svc.GroupId,
53+
ManualExec: svc.Deployment.ManualExec,
5354
ServiceMetaDocker: svc.Meta,
5455
ScheduleInfo: svc.Deployment.Schedule,
5556
}

backend/internal/node/nodeCache.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,14 @@ func GetNodeInfo(nodeId string) *types.Node {
5757

5858
return n
5959
}
60+
61+
func ClearNodeCache(nodeInfo types.NodeSimpleInfo) {
62+
63+
n, err := db.GetDataById[types.Node](db.BucketNodes, nodeInfo.NodeId)
64+
if err == nil && n != nil {
65+
nodeCache.Remove(n.NodeId)
66+
ip := n.IpAddress
67+
cache.Remove(ip)
68+
}
69+
70+
}

backend/scheduler/serviceController.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func (sc *ServiceController) HandleNodeChanged() {
8484

8585
// 机器上下线时需要通知该机器所属的Group,去检查Group中所有service的状态
8686
func (sc *ServiceController) HandleNodeStatusChanged(nodeInfo types.NodeSimpleInfo) {
87+
88+
node.ClearNodeCache(nodeInfo)
89+
8790
groups, _ := db.GroupsGetByNodeId(nodeInfo.NodeId)
8891
for _, g := range groups {
8992
for _, serviceManager := range sc.ServiceCtrls {
@@ -129,7 +132,7 @@ func getServiceIdByContainerId(containerName string) (string, string) {
129132
serviceId := ""
130133
version := ""
131134
splits := strings.Split(containerName, "-")
132-
if len(splits) == 4 && strings.EqualFold(splits[0], "humpback") {
135+
if len(splits) == 4 && strings.EqualFold(splits[0], InstanceNamePrefix) {
133136
serviceId = splits[1]
134137
version = splits[2]
135138
}

backend/scheduler/serviceManager.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,16 @@ func (sm *ServiceManager) Reconcile() {
125125
if sm.ServiceInfo.Status == types.ServiceStatusNotReady {
126126

127127
// 如果有容器正在启动,就不再继续
128-
if sm.ServiceInfo.Deployment.Type != types.DeployTypeSchedule && sm.HasPendingContainer() {
128+
if !sm.IsRunningWithSchedule() && sm.HasPendingContainer() {
129129
slog.Info("[Service Manager] Wait pending container......", "ServiceId", sm.ServiceInfo.ServiceId)
130130
return
131131
}
132132

133133
// 如果有容器失败,就不再继续
134-
if sm.ServiceInfo.Deployment.Type != types.DeployTypeSchedule && sm.HasFailedContainer() {
134+
if !sm.IsRunningWithSchedule() && sm.HasFailedContainer() {
135135
slog.Info("[Service Manager] container failed, stop dispatch......", "ServiceId", sm.ServiceInfo.ServiceId)
136136
sm.ServiceInfo.Status = types.ServiceStatusFailed
137+
sm.ServiceInfo.Memo = types.MemoCreateContainerFailed
137138
db.ServiceUpdate(sm.ServiceInfo)
138139
return
139140
}
@@ -269,12 +270,11 @@ func (sm *ServiceManager) IsContainerAllReady() bool {
269270
version := parseVersionByContainerId(c.ContainerName)
270271
if version == sm.ServiceInfo.Version {
271272
if isContainerExited(c.State) &&
272-
(sm.ServiceInfo.Deployment.Type == types.DeployTypeSchedule ||
273-
strings.EqualFold(sm.ServiceInfo.Action, types.ServiceActionStop)) {
273+
(sm.IsRunningWithSchedule() || strings.EqualFold(sm.ServiceInfo.Action, types.ServiceActionStop)) {
274274
continue
275275
}
276276

277-
if isContainerStarting(c.State) && sm.ServiceInfo.Deployment.Type == types.DeployTypeSchedule {
277+
if isContainerStarting(c.State) && sm.IsRunningWithSchedule() {
278278
continue
279279
}
280280

@@ -320,6 +320,10 @@ func (sm *ServiceManager) HasFailedContainer() bool {
320320
return false
321321
}
322322

323+
func (sm *ServiceManager) IsRunningWithSchedule() bool {
324+
return sm.ServiceInfo.Deployment.Type == types.DeployTypeSchedule || sm.ServiceInfo.Deployment.ManualExec
325+
}
326+
323327
func (sm *ServiceManager) TryToDeleteOne() (*types.ContainerStatus, bool) {
324328

325329
nodeDeployed := make(map[string]bool)
@@ -329,10 +333,8 @@ func (sm *ServiceManager) TryToDeleteOne() (*types.ContainerStatus, bool) {
329333
if version != sm.ServiceInfo.Version {
330334
return c, true
331335
}
332-
if isContainerExited(c.State) {
333-
if sm.ServiceInfo.Deployment.Type == types.DeployTypeBackground {
334-
return c, true
335-
}
336+
if isContainerExited(c.State) && !sm.IsRunningWithSchedule() {
337+
return c, true
336338
}
337339
if isContainerWarning(c.State) || isContainerRemoved(c.State) {
338340
return c, true

backend/scheduler/test/heartbeat.http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Accept: application/json
3939
"containers": [
4040
{
4141
"containerId": "asecfesac3cabd67af7d1ded36c464d6f326c04e80a4bb99a061faca1347f4b2",
42-
"containerName": "humpback-kOC3jh7F-PCvTc-n5PLi",
42+
"containerName": "Humpback-kOC3jh7F-PCvTc-n5PLi",
4343
"state": "Running",
4444
"status": "Up 2 hours",
4545
"network": "bridge",

backend/scheduler/util.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import (
88
"humpback/types"
99
)
1010

11+
const (
12+
InstanceNamePrefix = "Humpback"
13+
)
14+
1115
func parseVersionByContainerId(containerId string) string {
1216
parts := strings.Split(containerId, "-")
1317
if len(parts) < 4 {
@@ -25,7 +29,7 @@ func ParseServiceIdByContainerId(containerId string) string {
2529
}
2630

2731
func GenerateContainerName(serviceId, version string) string {
28-
return "humpback-" + serviceId + "-" + version + "-" + utils.NewVersionId()
32+
return InstanceNamePrefix + "-" + serviceId + "-" + version + "-" + utils.NewVersionId()
2933
}
3034

3135
func isContainerRunning(status string) bool {

backend/types/service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type AgentTask struct {
5656
ServiceName string `json:"serviceName"`
5757
ServiceId string `json:"serviceId"`
5858
GroupId string `json:"groupId"`
59+
ManualExec bool `json:"manualExec"`
5960
*ServiceMetaDocker
6061
*ScheduleInfo
6162
}
@@ -99,6 +100,7 @@ type Deployment struct {
99100
Replicas int `json:"replicas"`
100101
Placements []*PlacementInfo `json:"placements"`
101102
Schedule *ScheduleInfo `json:"schedule"`
103+
ManualExec bool `json:"manualExec"`
102104
}
103105

104106
type DeployMode string

front/projects/web/auto-imports.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ declare global {
1717
const GetUserRole: typeof import('./src/utils/common')['GetUserRole']
1818
const IconMdiAccount: typeof import('~icons/mdi/account')['default']
1919
const IconMdiAlphaCBoxOutline: typeof import('~icons/mdi/alpha-c-box-outline')['default']
20-
const IconMdiCheckboxMultipleBlankOutline: typeof import('~icons/mdi/checkbox-multiple-blank-outline')['default']
2120
const IconMdiCogOutline: typeof import('~icons/mdi/cog-outline')['default']
2221
const IconMdiCompany: typeof import('~icons/mdi/company')['default']
2322
const IconMdiLogoutVariant: typeof import('~icons/mdi/logout-variant')['default']
24-
const IconMdiPauseBoxOutline: typeof import('~icons/mdi/pause-box-outline')['default']
2523
const IconMdiPlay: typeof import('~icons/mdi/play')['default']
2624
const IconMdiRestart: typeof import('~icons/mdi/restart')['default']
2725
const IconMdiSquare: typeof import('~icons/mdi/square')['default']

0 commit comments

Comments
 (0)