List all pending deployments as array, with an action for each process

This commit is contained in:
Ingo Oppermann
2025-09-18 15:30:35 +02:00
parent 8c7ca4898a
commit a6e806fd31
6 changed files with 67 additions and 136 deletions

View File

@@ -1150,16 +1150,11 @@ func (c *cluster) Store() store.Store {
} }
type Deployments struct { type Deployments struct {
Process struct { Process []DeploymentsProcess
Delete []DeploymentsProcess
Update []DeploymentsProcess
Order []DeploymentsProcess
Add []DeploymentsProcess
Relocate []DeploymentsProcess
}
} }
type DeploymentsProcess struct { type DeploymentsProcess struct {
Action string
ID string ID string
Domain string Domain string
NodeID string NodeID string
@@ -1169,11 +1164,7 @@ type DeploymentsProcess struct {
} }
func (c *cluster) Deployments() (Deployments, error) { func (c *cluster) Deployments() (Deployments, error) {
processDelete := []DeploymentsProcess{} processes := []DeploymentsProcess{}
processUpdate := []DeploymentsProcess{}
processOrder := []DeploymentsProcess{}
processAdd := []DeploymentsProcess{}
processRelocate := []DeploymentsProcess{}
want := c.store.ProcessList() want := c.store.ProcessList()
have, err := c.manager.ClusterProcessList() have, err := c.manager.ClusterProcessList()
@@ -1195,7 +1186,8 @@ func (c *cluster) Deployments() (Deployments, error) {
pid := haveP.Config.ProcessID().String() pid := haveP.Config.ProcessID().String()
wantP, ok := wantMap[pid] wantP, ok := wantMap[pid]
if !ok { if !ok {
processDelete = append(processDelete, DeploymentsProcess{ processes = append(processes, DeploymentsProcess{
Action: "delete",
ID: haveP.Config.ID, ID: haveP.Config.ID,
Domain: haveP.Config.Domain, Domain: haveP.Config.Domain,
NodeID: haveP.NodeID, NodeID: haveP.NodeID,
@@ -1211,7 +1203,8 @@ func (c *cluster) Deployments() (Deployments, error) {
} }
hasMetadataChanges, _ := isMetadataUpdateRequired(wantP.Metadata, haveP.Metadata) hasMetadataChanges, _ := isMetadataUpdateRequired(wantP.Metadata, haveP.Metadata)
if hasConfigChanges || hasMetadataChanges { if hasConfigChanges || hasMetadataChanges {
processUpdate = append(processUpdate, DeploymentsProcess{ processes = append(processes, DeploymentsProcess{
Action: "update",
ID: wantP.Config.ID, ID: wantP.Config.ID,
Domain: wantP.Config.Domain, Domain: wantP.Config.Domain,
NodeID: haveP.NodeID, NodeID: haveP.NodeID,
@@ -1224,7 +1217,8 @@ func (c *cluster) Deployments() (Deployments, error) {
delete(wantMap, pid) delete(wantMap, pid)
if haveP.Order != wantP.Order { if haveP.Order != wantP.Order {
processOrder = append(processOrder, DeploymentsProcess{ processes = append(processes, DeploymentsProcess{
Action: "order",
ID: wantP.Config.ID, ID: wantP.Config.ID,
Domain: wantP.Config.Domain, Domain: wantP.Config.Domain,
NodeID: haveP.NodeID, NodeID: haveP.NodeID,
@@ -1237,7 +1231,8 @@ func (c *cluster) Deployments() (Deployments, error) {
// The wantMap now contains only those processes that need to be installed on a node. // The wantMap now contains only those processes that need to be installed on a node.
for _, wantP := range wantMap { for _, wantP := range wantMap {
processAdd = append(processAdd, DeploymentsProcess{ processes = append(processes, DeploymentsProcess{
Action: "add",
ID: wantP.Config.ID, ID: wantP.Config.ID,
Domain: wantP.Config.Domain, Domain: wantP.Config.Domain,
NodeID: "", NodeID: "",
@@ -1282,7 +1277,8 @@ func (c *cluster) Deployments() (Deployments, error) {
continue continue
} }
processRelocate = append(processRelocate, DeploymentsProcess{ processes = append(processes, DeploymentsProcess{
Action: "relocate",
ID: wantP.Config.ID, ID: wantP.Config.ID,
Domain: wantP.Config.Domain, Domain: wantP.Config.Domain,
NodeID: targetNodeid, NodeID: targetNodeid,
@@ -1291,13 +1287,9 @@ func (c *cluster) Deployments() (Deployments, error) {
}) })
} }
deployments := Deployments{} deployments := Deployments{
Process: processes,
deployments.Process.Delete = processDelete }
deployments.Process.Update = processUpdate
deployments.Process.Order = processOrder
deployments.Process.Add = processAdd
deployments.Process.Relocate = processRelocate
return deployments, nil return deployments, nil
} }

View File

@@ -5625,13 +5625,29 @@ const docTemplate = `{
"type": "object", "type": "object",
"properties": { "properties": {
"process": { "process": {
"$ref": "#/definitions/api.ClusterDeploymentsProcesses" "type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
} }
} }
}, },
"api.ClusterDeploymentsProcess": { "api.ClusterDeploymentsProcess": {
"type": "object", "type": "object",
"required": [
"action"
],
"properties": { "properties": {
"action": {
"type": "string",
"enum": [
"delete",
"update",
"add",
"order",
"relocate"
]
},
"domain": { "domain": {
"type": "string" "type": "string"
}, },
@@ -5652,41 +5668,6 @@ const docTemplate = `{
} }
} }
}, },
"api.ClusterDeploymentsProcesses": {
"type": "object",
"properties": {
"add": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
},
"delete": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
},
"order": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
},
"relocate": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
},
"update": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
}
}
},
"api.ClusterKVS": { "api.ClusterKVS": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {

View File

@@ -5618,13 +5618,29 @@
"type": "object", "type": "object",
"properties": { "properties": {
"process": { "process": {
"$ref": "#/definitions/api.ClusterDeploymentsProcesses" "type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
} }
} }
}, },
"api.ClusterDeploymentsProcess": { "api.ClusterDeploymentsProcess": {
"type": "object", "type": "object",
"required": [
"action"
],
"properties": { "properties": {
"action": {
"type": "string",
"enum": [
"delete",
"update",
"add",
"order",
"relocate"
]
},
"domain": { "domain": {
"type": "string" "type": "string"
}, },
@@ -5645,41 +5661,6 @@
} }
} }
}, },
"api.ClusterDeploymentsProcesses": {
"type": "object",
"properties": {
"add": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
},
"delete": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
},
"order": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
},
"relocate": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
},
"update": {
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
}
}
},
"api.ClusterKVS": { "api.ClusterKVS": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {

View File

@@ -207,10 +207,20 @@ definitions:
api.ClusterDeployments: api.ClusterDeployments:
properties: properties:
process: process:
$ref: '#/definitions/api.ClusterDeploymentsProcesses' items:
$ref: '#/definitions/api.ClusterDeploymentsProcess'
type: array
type: object type: object
api.ClusterDeploymentsProcess: api.ClusterDeploymentsProcess:
properties: properties:
action:
enum:
- delete
- update
- add
- order
- relocate
type: string
domain: domain:
type: string type: string
error: error:
@@ -223,29 +233,8 @@ definitions:
type: string type: string
updated_at: updated_at:
type: integer type: integer
type: object required:
api.ClusterDeploymentsProcesses: - action
properties:
add:
items:
$ref: '#/definitions/api.ClusterDeploymentsProcess'
type: array
delete:
items:
$ref: '#/definitions/api.ClusterDeploymentsProcess'
type: array
order:
items:
$ref: '#/definitions/api.ClusterDeploymentsProcess'
type: array
relocate:
items:
$ref: '#/definitions/api.ClusterDeploymentsProcess'
type: array
update:
items:
$ref: '#/definitions/api.ClusterDeploymentsProcess'
type: array
type: object type: object
api.ClusterKVS: api.ClusterKVS:
additionalProperties: additionalProperties:

View File

@@ -122,18 +122,11 @@ type ClusterStoreNode struct {
} }
type ClusterDeployments struct { type ClusterDeployments struct {
Process ClusterDeploymentsProcesses `json:"process"` Process []ClusterDeploymentsProcess `json:"process"`
}
type ClusterDeploymentsProcesses struct {
Delete []ClusterDeploymentsProcess `json:"delete"`
Update []ClusterDeploymentsProcess `json:"update"`
Order []ClusterDeploymentsProcess `json:"order"`
Add []ClusterDeploymentsProcess `json:"add"`
Relocate []ClusterDeploymentsProcess `json:"relocate"`
} }
type ClusterDeploymentsProcess struct { type ClusterDeploymentsProcess struct {
Action string `json:"action" validate:"required" enums:"delete,update,add,order,relocate" jsonschema:"enum=delete,enum=update,enum=add,enum=order,enum=relocate"`
ID string `json:"id"` ID string `json:"id"`
Domain string `json:"domain"` Domain string `json:"domain"`
NodeID string `json:"node_id"` NodeID string `json:"node_id"`

View File

@@ -309,6 +309,7 @@ func (h *ClusterHandler) Deployments(c echo.Context) error {
apiProcesses := []api.ClusterDeploymentsProcess{} apiProcesses := []api.ClusterDeploymentsProcess{}
for _, p := range processes { for _, p := range processes {
apiProcesses = append(apiProcesses, api.ClusterDeploymentsProcess{ apiProcesses = append(apiProcesses, api.ClusterDeploymentsProcess{
Action: p.Action,
ID: p.ID, ID: p.ID,
Domain: p.Domain, Domain: p.Domain,
NodeID: p.NodeID, NodeID: p.NodeID,
@@ -321,12 +322,6 @@ func (h *ClusterHandler) Deployments(c echo.Context) error {
} }
return c.JSON(http.StatusOK, api.ClusterDeployments{ return c.JSON(http.StatusOK, api.ClusterDeployments{
Process: api.ClusterDeploymentsProcesses{ Process: marshal(deployments.Process),
Delete: marshal(deployments.Process.Delete),
Update: marshal(deployments.Process.Update),
Order: marshal(deployments.Process.Order),
Add: marshal(deployments.Process.Add),
Relocate: marshal(deployments.Process.Relocate),
},
}) })
} }