in pkg/scheduler/objects/allocation.go [87:153]
func NewAllocationFromSI(alloc *si.Allocation) *Allocation {
if alloc == nil {
return nil
}
// this is a safety check placeholder and task group name must be set as a combo
// order is important as task group can be set without placeholder but not the other way around
if alloc.Placeholder && alloc.TaskGroupName == "" {
log.Log(log.SchedAllocation).Debug("Allocation cannot be a placeholder without a TaskGroupName",
zap.Stringer("SI alloc", alloc))
return nil
}
var createTime time.Time
siCreationTime, err := strconv.ParseInt(alloc.AllocationTags[siCommon.CreationTime], 10, 64)
if err != nil {
log.Log(log.SchedAllocation).Debug("CreationTime is not set on the Allocation object or invalid",
zap.String("creationTime", alloc.AllocationTags[siCommon.CreationTime]))
createTime = time.Now()
} else {
createTime = time.Unix(siCreationTime, 0)
}
foreign := false
preemptable := true
if foreignType, ok := alloc.AllocationTags[siCommon.Foreign]; ok {
foreign = true
switch foreignType {
case siCommon.AllocTypeStatic:
preemptable = false
case siCommon.AllocTypeDefault:
default:
log.Log(log.SchedAllocation).Warn("Foreign tag has illegal value, using default",
zap.String("value", foreignType))
}
}
var allocated bool
var nodeID string
var bindTime time.Time
if alloc.NodeID != "" {
allocated = true
nodeID = alloc.NodeID
bindTime = time.Now()
}
return &Allocation{
allocationKey: alloc.AllocationKey,
applicationID: alloc.ApplicationID,
allocatedResource: resources.NewResourceFromProto(alloc.ResourcePerAlloc),
tags: CloneAllocationTags(alloc.AllocationTags),
createTime: createTime,
priority: alloc.Priority,
placeholder: alloc.Placeholder,
taskGroupName: alloc.TaskGroupName,
requiredNode: common.GetRequiredNodeFromTag(alloc.AllocationTags),
allowPreemptSelf: alloc.PreemptionPolicy.GetAllowPreemptSelf(),
allowPreemptOther: alloc.PreemptionPolicy.GetAllowPreemptOther(),
originator: alloc.Originator,
allocLog: make(map[string]*AllocationLogEntry),
askEvents: schedEvt.NewAskEvents(events.GetEventSystem()),
allocated: allocated,
nodeID: nodeID,
bindTime: bindTime,
foreign: foreign,
preemptable: preemptable,
}
}