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 {
Process struct {
Delete []DeploymentsProcess
Update []DeploymentsProcess
Order []DeploymentsProcess
Add []DeploymentsProcess
Relocate []DeploymentsProcess
}
Process []DeploymentsProcess
}
type DeploymentsProcess struct {
Action string
ID string
Domain string
NodeID string
@@ -1169,11 +1164,7 @@ type DeploymentsProcess struct {
}
func (c *cluster) Deployments() (Deployments, error) {
processDelete := []DeploymentsProcess{}
processUpdate := []DeploymentsProcess{}
processOrder := []DeploymentsProcess{}
processAdd := []DeploymentsProcess{}
processRelocate := []DeploymentsProcess{}
processes := []DeploymentsProcess{}
want := c.store.ProcessList()
have, err := c.manager.ClusterProcessList()
@@ -1195,7 +1186,8 @@ func (c *cluster) Deployments() (Deployments, error) {
pid := haveP.Config.ProcessID().String()
wantP, ok := wantMap[pid]
if !ok {
processDelete = append(processDelete, DeploymentsProcess{
processes = append(processes, DeploymentsProcess{
Action: "delete",
ID: haveP.Config.ID,
Domain: haveP.Config.Domain,
NodeID: haveP.NodeID,
@@ -1211,7 +1203,8 @@ func (c *cluster) Deployments() (Deployments, error) {
}
hasMetadataChanges, _ := isMetadataUpdateRequired(wantP.Metadata, haveP.Metadata)
if hasConfigChanges || hasMetadataChanges {
processUpdate = append(processUpdate, DeploymentsProcess{
processes = append(processes, DeploymentsProcess{
Action: "update",
ID: wantP.Config.ID,
Domain: wantP.Config.Domain,
NodeID: haveP.NodeID,
@@ -1224,7 +1217,8 @@ func (c *cluster) Deployments() (Deployments, error) {
delete(wantMap, pid)
if haveP.Order != wantP.Order {
processOrder = append(processOrder, DeploymentsProcess{
processes = append(processes, DeploymentsProcess{
Action: "order",
ID: wantP.Config.ID,
Domain: wantP.Config.Domain,
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.
for _, wantP := range wantMap {
processAdd = append(processAdd, DeploymentsProcess{
processes = append(processes, DeploymentsProcess{
Action: "add",
ID: wantP.Config.ID,
Domain: wantP.Config.Domain,
NodeID: "",
@@ -1282,7 +1277,8 @@ func (c *cluster) Deployments() (Deployments, error) {
continue
}
processRelocate = append(processRelocate, DeploymentsProcess{
processes = append(processes, DeploymentsProcess{
Action: "relocate",
ID: wantP.Config.ID,
Domain: wantP.Config.Domain,
NodeID: targetNodeid,
@@ -1291,13 +1287,9 @@ func (c *cluster) Deployments() (Deployments, error) {
})
}
deployments := Deployments{}
deployments.Process.Delete = processDelete
deployments.Process.Update = processUpdate
deployments.Process.Order = processOrder
deployments.Process.Add = processAdd
deployments.Process.Relocate = processRelocate
deployments := Deployments{
Process: processes,
}
return deployments, nil
}

View File

@@ -5625,13 +5625,29 @@ const docTemplate = `{
"type": "object",
"properties": {
"process": {
"$ref": "#/definitions/api.ClusterDeploymentsProcesses"
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
}
}
},
"api.ClusterDeploymentsProcess": {
"type": "object",
"required": [
"action"
],
"properties": {
"action": {
"type": "string",
"enum": [
"delete",
"update",
"add",
"order",
"relocate"
]
},
"domain": {
"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": {
"type": "object",
"additionalProperties": {

View File

@@ -5618,13 +5618,29 @@
"type": "object",
"properties": {
"process": {
"$ref": "#/definitions/api.ClusterDeploymentsProcesses"
"type": "array",
"items": {
"$ref": "#/definitions/api.ClusterDeploymentsProcess"
}
}
}
},
"api.ClusterDeploymentsProcess": {
"type": "object",
"required": [
"action"
],
"properties": {
"action": {
"type": "string",
"enum": [
"delete",
"update",
"add",
"order",
"relocate"
]
},
"domain": {
"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": {
"type": "object",
"additionalProperties": {

View File

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

View File

@@ -122,18 +122,11 @@ type ClusterStoreNode struct {
}
type ClusterDeployments struct {
Process ClusterDeploymentsProcesses `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"`
Process []ClusterDeploymentsProcess `json:"process"`
}
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"`
Domain string `json:"domain"`
NodeID string `json:"node_id"`

View File

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