pbacsko commented on code in PR #975:
URL: https://github.com/apache/yunikorn-core/pull/975#discussion_r1778415846


##########
pkg/scheduler/partition.go:
##########
@@ -1286,12 +1291,54 @@ func (pc *PartitionContext) UpdateAllocation(alloc 
*objects.Allocation) (request
        return false, false, nil
 }
 
+func (pc *PartitionContext) handleForeignAllocation(allocationKey, 
applicationID, nodeID string, node *objects.Node, alloc *objects.Allocation) 
(requestCreated bool, allocCreated bool, err error) {
+       allocated := alloc.IsAllocated()
+       if !allocated {
+               return false, false, fmt.Errorf("trying to add a foreign 
request (non-allocation) %s", allocationKey)
+       }
+       if alloc.GetNodeID() == common.Empty {
+               return false, false, fmt.Errorf("node ID is empty for 
allocation %s", allocationKey)
+       }
+       if node == nil {
+               return false, false, fmt.Errorf("failed to find node %s for 
allocation %s", nodeID, allocationKey)
+       }
+
+       existingNodeID := pc.getOrSetNodeIDForAlloc(allocationKey, nodeID)
+       if existingNodeID == common.Empty {
+               log.Log(log.SchedPartition).Info("handling new foreign 
allocation",
+                       zap.String("partitionName", pc.Name),
+                       zap.String("nodeID", nodeID),
+                       zap.String("allocationKey", allocationKey))
+               node.AddAllocation(alloc)
+               return false, true, nil
+       }
+
+       log.Log(log.SchedPartition).Info("handling foreign allocation update",
+               zap.String("partitionName", pc.Name),
+               zap.String("appID", applicationID),
+               zap.String("allocationKey", allocationKey))
+       // this is a placeholder for eventual resource updates; nothing to do 
yet
+       return false, false, nil
+}
+
 func (pc *PartitionContext) convertUGI(ugi *si.UserGroupInformation, forced 
bool) (security.UserGroup, error) {
        pc.RLock()
        defer pc.RUnlock()
        return pc.userGroupCache.ConvertUGI(ugi, forced)
 }
 
+// getOrSetNodeIDForAlloc returns the nodeID for a given foreign allocation, 
or sets is if it's unset
+func (pc *PartitionContext) getOrSetNodeIDForAlloc(allocKey, nodeID string) 
string {
+       pc.Lock()
+       defer pc.Unlock()
+       id := pc.foreignAllocs[allocKey]
+       if id != common.Empty {
+               return id
+       }

Review Comment:
   Notes: lines 1316-1321, 1336 will be covered as part of YUNIKORN-1765.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to