67 lines
2.6 KiB
Go
67 lines
2.6 KiB
Go
|
|
package backendupdate
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
|
||
|
|
"yms-daemon/internal/hostnginx"
|
||
|
|
"yms-daemon/internal/transaction"
|
||
|
|
)
|
||
|
|
|
||
|
|
func gatewaySwitchIntent(request persistedRequest, before hostnginx.Snapshot, after hostnginx.Snapshot) transaction.StepIntent {
|
||
|
|
return stepIntent("backend.gateway.switch", "switch host Nginx backend upstream", struct {
|
||
|
|
BeforePort int `json:"beforePort"`
|
||
|
|
BeforeHash string `json:"beforeHash"`
|
||
|
|
AfterPort int `json:"afterPort"`
|
||
|
|
AfterHash string `json:"afterHash"`
|
||
|
|
}{before.ActivePort, snapshotDigest(before), after.ActivePort, snapshotDigest(after)})
|
||
|
|
}
|
||
|
|
|
||
|
|
func activeLinkIntent(request persistedRequest, installedPath string) transaction.StepIntent {
|
||
|
|
return stepIntent("backend.native.active-link", "replace backend compatibility link", struct {
|
||
|
|
Path string `json:"path"`
|
||
|
|
Before pathState `json:"before"`
|
||
|
|
InstalledPath string `json:"installedPath"`
|
||
|
|
}{request.ActiveJARPath, request.ActiveJARBefore, installedPath})
|
||
|
|
}
|
||
|
|
|
||
|
|
func stopPreviousUnitIntent(request persistedRequest) transaction.StepIntent {
|
||
|
|
return stepIntent("backend.previous-unit.stop", "stop previous backend unit after drain", struct {
|
||
|
|
Unit string `json:"unit"`
|
||
|
|
}{request.PreviousUnit})
|
||
|
|
}
|
||
|
|
|
||
|
|
func activeLinkRestoreIntent(request persistedRequest) transaction.StepIntent {
|
||
|
|
return stepIntent("backend.native.active-link.restore", "restore backend compatibility path", struct {
|
||
|
|
Path string `json:"path"`
|
||
|
|
Before pathState `json:"before"`
|
||
|
|
}{request.ActiveJARPath, request.ActiveJARBefore})
|
||
|
|
}
|
||
|
|
|
||
|
|
func gatewayRestoreIntent(request persistedRequest) transaction.StepIntent {
|
||
|
|
return stepIntent("backend.gateway.restore", "restore host Nginx backend upstream", struct {
|
||
|
|
Port int `json:"port"`
|
||
|
|
}{request.PreviousGatewayPort})
|
||
|
|
}
|
||
|
|
|
||
|
|
func stopTargetUnitIntent(request persistedRequest) transaction.StepIntent {
|
||
|
|
return stepIntent("backend.target-unit.stop", "stop compensated backend target unit", struct {
|
||
|
|
Unit string `json:"unit"`
|
||
|
|
}{request.TargetUnit})
|
||
|
|
}
|
||
|
|
|
||
|
|
func restoreTargetSlotIntent(request persistedRequest, installedPath string) transaction.StepIntent {
|
||
|
|
return stepIntent("backend.target-slot.restore", "restore compensated backend target slot", struct {
|
||
|
|
Path string `json:"path"`
|
||
|
|
InstalledPath string `json:"installedPath"`
|
||
|
|
PreviousTarget string `json:"previousTarget"`
|
||
|
|
}{request.TargetSlotJAR, installedPath, request.PreviousSlotTarget})
|
||
|
|
}
|
||
|
|
|
||
|
|
func stepIntent(key string, name string, value any) transaction.StepIntent {
|
||
|
|
content, err := json.Marshal(value)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return transaction.StepIntent{Key: key, Name: name, Intent: content}
|
||
|
|
}
|