func toAutoScaleEvent(evt *event.Event) (autoScaleEvent, error) { var data evtCustomData err := evt.EndData(&data) if err != nil { return autoScaleEvent{}, err } autoScaleEvt := autoScaleEvent{ ID: evt.UniqueID, MetadataValue: evt.Target.Value, Nodes: data.Nodes, StartTime: evt.StartTime, EndTime: evt.EndTime, Successful: evt.Error == "", Error: evt.Error, Log: evt.Log, } if data.Result != nil { if data.Result.ToAdd > 0 { autoScaleEvt.Action = scaleActionAdd } else if len(data.Result.ToRemove) > 0 { autoScaleEvt.Action = scaleActionRemove } else if data.Result.ToRebalance { autoScaleEvt.Action = scaleActionRebalance } autoScaleEvt.Reason = data.Result.Reason } return autoScaleEvt, nil }
func toHealingEvt(evt *event.Event) (HealingEvent, error) { healingEvt := HealingEvent{ ID: evt.UniqueID, StartTime: evt.StartTime, EndTime: evt.EndTime, Action: fmt.Sprintf("%s-healing", evt.Target.Type), Successful: evt.Error == "", Error: evt.Error, } switch evt.Target.Type { case event.TargetTypeContainer: err := evt.StartData(&healingEvt.FailingContainer) if err != nil { return healingEvt, err } err = evt.EndData(&healingEvt.CreatedContainer) if err != nil { return healingEvt, err } case event.TargetTypeNode: var data healer.NodeHealerCustomData err := evt.StartData(&data) if err != nil { return healingEvt, err } if data.LastCheck != nil { healingEvt.Extra = data.LastCheck } healingEvt.Reason = data.Reason healingEvt.FailingNode = data.Node var createdNode provision.NodeSpec err = evt.EndData(&createdNode) if err != nil { return healingEvt, err } healingEvt.CreatedNode = createdNode } return healingEvt, nil }
func eventToDeployData(evt *event.Event, validImages set.Set, full bool) *DeployData { data := &DeployData{ ID: evt.UniqueID, App: evt.Target.Value, Timestamp: evt.StartTime, Duration: evt.EndTime.Sub(evt.StartTime), Error: evt.Error, User: evt.Owner.Name, } var startOpts DeployOptions err := evt.StartData(&startOpts) if err == nil { data.Commit = startOpts.Commit data.Origin = startOpts.GetOrigin() } if full { data.Log = evt.Log var otherData map[string]string err = evt.OtherData(&otherData) if err == nil { data.Diff = otherData["diff"] } } var endData map[string]string err = evt.EndData(&endData) if err == nil { data.Image = endData["image"] if validImages != nil { data.CanRollback = validImages.Includes(data.Image) if reImageVersion.MatchString(data.Image) { parts := reImageVersion.FindAllStringSubmatch(data.Image, -1) data.Image = parts[0][0] } } } return data }