forked from apache/yunikorn-k8shim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[YUNIKORN-153] Move SI functions to si_helper (apache#118)
Scheduler interface functions are currently part of the resource code. The resources and SI are not related and should not be mixed in the source code. This is not a change in functionality. Fixes: apache#118
- Loading branch information
1 parent
b8a4a01
commit 617e9e5
Showing
4 changed files
with
192 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
"github.com/apache/incubator-yunikorn-k8shim/pkg/conf" | ||
"github.com/apache/incubator-yunikorn-scheduler-interface/lib/go/si" | ||
) | ||
|
||
func CreateUpdateRequestForTask(appID, taskID string, resource *si.Resource) si.UpdateRequest { | ||
ask := si.AllocationAsk{ | ||
AllocationKey: taskID, | ||
ResourceAsk: resource, | ||
ApplicationID: appID, | ||
MaxAllocations: 1, | ||
} | ||
|
||
result := si.UpdateRequest{ | ||
Asks: []*si.AllocationAsk{&ask}, | ||
NewSchedulableNodes: nil, | ||
UpdatedNodes: nil, | ||
UtilizationReports: nil, | ||
RmID: conf.GetSchedulerConf().ClusterID, | ||
} | ||
|
||
return result | ||
} | ||
|
||
func CreateReleaseAskRequestForTask(appID, taskId, partition string) si.UpdateRequest { | ||
toReleases := make([]*si.AllocationAskReleaseRequest, 0) | ||
toReleases = append(toReleases, &si.AllocationAskReleaseRequest{ | ||
ApplicationID: appID, | ||
Allocationkey: taskId, | ||
PartitionName: partition, | ||
Message: "task request is canceled", | ||
}) | ||
|
||
releaseRequest := si.AllocationReleasesRequest{ | ||
AllocationAsksToRelease: toReleases, | ||
} | ||
|
||
result := si.UpdateRequest{ | ||
Releases: &releaseRequest, | ||
RmID: conf.GetSchedulerConf().ClusterID, | ||
} | ||
|
||
return result | ||
} | ||
|
||
func CreateReleaseAllocationRequestForTask(appID, allocUUID, partition string) si.UpdateRequest { | ||
toReleases := make([]*si.AllocationReleaseRequest, 0) | ||
toReleases = append(toReleases, &si.AllocationReleaseRequest{ | ||
ApplicationID: appID, | ||
UUID: allocUUID, | ||
PartitionName: partition, | ||
Message: "task completed", | ||
}) | ||
|
||
releaseRequest := si.AllocationReleasesRequest{ | ||
AllocationsToRelease: toReleases, | ||
} | ||
|
||
result := si.UpdateRequest{ | ||
Releases: &releaseRequest, | ||
RmID: conf.GetSchedulerConf().ClusterID, | ||
} | ||
|
||
return result | ||
} | ||
|
||
func CreateUpdateRequestForNewNode(node Node) si.UpdateRequest { | ||
// Use node's name as the NodeID, this is because when bind pod to node, | ||
// name of node is required but uid is optional. | ||
nodeInfo := &si.NewNodeInfo{ | ||
NodeID: node.name, | ||
SchedulableResource: node.capacity, | ||
// TODO is this required? | ||
Attributes: map[string]string{ | ||
DefaultNodeAttributeHostNameKey: node.name, | ||
DefaultNodeAttributeRackNameKey: DefaultRackName, | ||
}, | ||
} | ||
|
||
nodes := make([]*si.NewNodeInfo, 1) | ||
nodes[0] = nodeInfo | ||
request := si.UpdateRequest{ | ||
NewSchedulableNodes: nodes, | ||
RmID: conf.GetSchedulerConf().ClusterID, | ||
} | ||
return request | ||
} | ||
|
||
func CreateUpdateRequestForUpdatedNode(node Node) si.UpdateRequest { | ||
// Currently only includes resource in the update request | ||
nodeInfo := &si.UpdateNodeInfo{ | ||
NodeID: node.name, | ||
Attributes: make(map[string]string), | ||
SchedulableResource: node.capacity, | ||
OccupiedResource: node.occupied, | ||
Action: si.UpdateNodeInfo_UPDATE, | ||
} | ||
|
||
nodes := make([]*si.UpdateNodeInfo, 1) | ||
nodes[0] = nodeInfo | ||
request := si.UpdateRequest{ | ||
UpdatedNodes: nodes, | ||
RmID: conf.GetSchedulerConf().ClusterID, | ||
} | ||
return request | ||
} | ||
|
||
func CreateUpdateRequestForDeleteNode(node Node) si.UpdateRequest { | ||
deletedNodes := make([]*si.UpdateNodeInfo, 1) | ||
nodeInfo := &si.UpdateNodeInfo{ | ||
NodeID: node.name, | ||
SchedulableResource: node.capacity, | ||
OccupiedResource: node.occupied, | ||
Attributes: make(map[string]string), | ||
Action: si.UpdateNodeInfo_DECOMISSION, | ||
} | ||
|
||
deletedNodes[0] = nodeInfo | ||
request := si.UpdateRequest{ | ||
UpdatedNodes: deletedNodes, | ||
RmID: conf.GetSchedulerConf().ClusterID, | ||
} | ||
return request | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
) | ||
|
||
func TestCreateReleaseAllocationRequest(t *testing.T) { | ||
request := CreateReleaseAllocationRequestForTask("app01", "alloc01", "default") | ||
assert.Assert(t, request.Releases != nil) | ||
assert.Assert(t, request.Releases.AllocationsToRelease != nil) | ||
assert.Assert(t, request.Releases.AllocationAsksToRelease == nil) | ||
assert.Equal(t, len(request.Releases.AllocationsToRelease), 1) | ||
assert.Equal(t, len(request.Releases.AllocationAsksToRelease), 0) | ||
assert.Equal(t, request.Releases.AllocationsToRelease[0].ApplicationID, "app01") | ||
assert.Equal(t, request.Releases.AllocationsToRelease[0].UUID, "alloc01") | ||
assert.Equal(t, request.Releases.AllocationsToRelease[0].PartitionName, "default") | ||
} | ||
|
||
func TestCreateReleaseAskRequestForTask(t *testing.T) { | ||
request := CreateReleaseAskRequestForTask("app01", "task01", "default") | ||
assert.Assert(t, request.Releases != nil) | ||
assert.Assert(t, request.Releases.AllocationsToRelease == nil) | ||
assert.Assert(t, request.Releases.AllocationAsksToRelease != nil) | ||
assert.Equal(t, len(request.Releases.AllocationsToRelease), 0) | ||
assert.Equal(t, len(request.Releases.AllocationAsksToRelease), 1) | ||
assert.Equal(t, request.Releases.AllocationAsksToRelease[0].ApplicationID, "app01") | ||
assert.Equal(t, request.Releases.AllocationAsksToRelease[0].Allocationkey, "task01") | ||
assert.Equal(t, request.Releases.AllocationAsksToRelease[0].PartitionName, "default") | ||
} |