Run manual diagnostic attachments in the background
This commit is contained in:
1 parent
d845a5e4b6
commit
89ac4d5bcd
40 files changed
+1560
-58
No files matched your search
@@ -56,33 +56,13 @@ func (o *Orchestrator) DiagnosticAttach(ctx context.Context, items []DiagnosticI
|
||||
|
||||
func (o *Orchestrator) diagnosticAttachOne(ctx context.Context, it DiagnosticItem, note string) DiagnosticResult {
|
||||
addr := it.Address
|
||||
holds, err := o.DB.ListDiagnosticHolds(ctx)
|
||||
v, fip, reason, err := o.prepareDiagnosticAttach(ctx, it, "")
|
||||
if err != nil {
|
||||
return rejected(addr, "internal error: "+err.Error())
|
||||
}
|
||||
for _, h := range holds {
|
||||
if h.Address == addr {
|
||||
return rejected(addr, "address is already on diagnostic")
|
||||
}
|
||||
}
|
||||
if item, err := o.DB.GetIPByAddress(ctx, addr); err == nil && activeQueueStates[item.State] {
|
||||
return rejected(addr, "address is being checked ("+item.State+")")
|
||||
}
|
||||
fip, err := o.OS.GetFloatingIPByAddress(ctx, addr)
|
||||
if err != nil {
|
||||
if openstack.IsNotFound(err) {
|
||||
return rejected(addr, "floating ip not found in the project")
|
||||
}
|
||||
return rejected(addr, "cloud lookup failed: "+err.Error())
|
||||
}
|
||||
|
||||
v, reason := o.pickDiagnosticValidator(ctx, it.ValidatorID)
|
||||
if v == nil {
|
||||
if reason != "" {
|
||||
return rejected(addr, reason)
|
||||
}
|
||||
if fip.PortID != "" && fip.PortID != v.OSPortID {
|
||||
return rejected(addr, "floating ip is attached to another port")
|
||||
}
|
||||
if err := o.DB.ClaimDiagnostic(ctx, v.ValidatorID, addr, fip.ID, note); err != nil {
|
||||
return rejected(addr, "validator "+v.ValidatorID+" cannot be claimed: "+err.Error())
|
||||
}
|
||||
@@ -97,6 +77,36 @@ func (o *Orchestrator) diagnosticAttachOne(ctx context.Context, it DiagnosticIte
|
||||
return DiagnosticResult{Address: addr, Status: DiagAttached, ValidatorID: v.ValidatorID, FIPID: fip.ID}
|
||||
}
|
||||
|
||||
func (o *Orchestrator) prepareDiagnosticAttach(ctx context.Context, it DiagnosticItem, operationID string) (*db.Validator, *openstack.FloatingIP, string, error) {
|
||||
addr := it.Address
|
||||
held, err := o.DB.HasDiagnosticHold(ctx, addr)
|
||||
if err != nil {
|
||||
return nil, nil, "", err
|
||||
}
|
||||
if held {
|
||||
return nil, nil, "address is already on diagnostic", nil
|
||||
}
|
||||
if item, err := o.DB.GetIPByAddress(ctx, addr); err == nil && activeQueueStates[item.State] {
|
||||
return nil, nil, "address is being checked (" + item.State + ")", nil
|
||||
}
|
||||
fip, err := o.lookupDiagnosticFIP(ctx, operationID, addr)
|
||||
if err != nil {
|
||||
if openstack.IsNotFound(err) {
|
||||
return nil, nil, "floating ip not found in the project", nil
|
||||
}
|
||||
return nil, nil, "cloud lookup failed: " + err.Error(), nil
|
||||
}
|
||||
|
||||
v, reason := o.pickDiagnosticValidator(ctx, it.ValidatorID)
|
||||
if v == nil {
|
||||
return nil, nil, reason, nil
|
||||
}
|
||||
if fip.PortID != "" && fip.PortID != v.OSPortID {
|
||||
return nil, nil, "floating ip is attached to another port", nil
|
||||
}
|
||||
return v, fip, "", nil
|
||||
}
|
||||
|
||||
// pickDiagnosticValidator returns the requested validator if it is idle, or
|
||||
// the first idle one with a port when none is requested.
|
||||
func (o *Orchestrator) pickDiagnosticValidator(ctx context.Context, id string) (*db.Validator, string) {
|
||||
@@ -180,8 +190,12 @@ func (o *Orchestrator) DiagnosticList(ctx context.Context) ([]db.DiagnosticHold,
|
||||
}
|
||||
|
||||
func (o *Orchestrator) diagnosticEvent(ctx context.Context, typ, addr, validatorID, fipID, note string) {
|
||||
o.event(ctx, "control-api", validatorID, nil, typ, diagnosticPayload(addr, validatorID, fipID, note))
|
||||
}
|
||||
|
||||
func diagnosticPayload(addr, validatorID, fipID, note string) string {
|
||||
payload, _ := json.Marshal(map[string]string{
|
||||
"address": addr, "validator_id": validatorID, "fip_id": fipID, "note": note,
|
||||
})
|
||||
o.event(ctx, "control-api", validatorID, nil, typ, string(payload))
|
||||
return string(payload)
|
||||
}
|
||||
Reference in new issue
Block a user