1 | #Licensed to the Apache Software Foundation (ASF) under one |
---|
2 | #or more contributor license agreements. See the NOTICE file |
---|
3 | #distributed with this work for additional information |
---|
4 | #regarding copyright ownership. The ASF licenses this file |
---|
5 | #to you under the Apache License, Version 2.0 (the |
---|
6 | #"License"); you may not use this file except in compliance |
---|
7 | #with the License. You may obtain a copy of the License at |
---|
8 | |
---|
9 | # http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | |
---|
11 | #Unless required by applicable law or agreed to in writing, software |
---|
12 | #distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | #See the License for the specific language governing permissions and |
---|
15 | #limitations under the License. |
---|
16 | """defines nodepool and nodeset as abstract interface for batch system""" |
---|
17 | # -*- python -*- |
---|
18 | |
---|
19 | from hodlib.GridServices.service import * |
---|
20 | |
---|
21 | class NodeSet: |
---|
22 | """a set of nodes as one allocation unit""" |
---|
23 | |
---|
24 | PENDING, COMMITTED, COMPLETE = range(3) |
---|
25 | |
---|
26 | def __init__(self, id, numNodes, preferredList, isPreemptee): |
---|
27 | self.id = id |
---|
28 | self.numNodes = numNodes |
---|
29 | self.isPreemptee = isPreemptee |
---|
30 | self.preferredList = preferredList |
---|
31 | self.cmdDescSet = [] |
---|
32 | |
---|
33 | def getId(self): |
---|
34 | """returns a unique id of the nodeset""" |
---|
35 | return self.id |
---|
36 | |
---|
37 | def registerCommand(self, cmdDesc): |
---|
38 | """register a command to the nodeset""" |
---|
39 | self.cmdDescSet.append(cmdDesc) |
---|
40 | |
---|
41 | def getAddrList(self): |
---|
42 | """get list of node host names |
---|
43 | May return empty list if node set is not allocated yet""" |
---|
44 | raise NotImplementedError |
---|
45 | |
---|
46 | def _getNumNodes(self): |
---|
47 | return self.numNodes |
---|
48 | |
---|
49 | def _isPreemptee(self): |
---|
50 | return self.isPreemptee |
---|
51 | |
---|
52 | def _getPreferredList(self): |
---|
53 | return self.preferredList |
---|
54 | |
---|
55 | def _getCmdSet(self): |
---|
56 | return self.cmdDescSet |
---|
57 | |
---|
58 | class NodePool: |
---|
59 | """maintains a collection of node sets as they get allocated. |
---|
60 | Also the base class for all kinds of nodepools. """ |
---|
61 | |
---|
62 | def __init__(self, nodePoolDesc, cfg, log): |
---|
63 | self.nodePoolDesc = nodePoolDesc |
---|
64 | self.nodeSetDict = {} |
---|
65 | self._cfg = cfg |
---|
66 | self.nextNodeSetId = 0 |
---|
67 | self._log = log |
---|
68 | |
---|
69 | |
---|
70 | def newNodeSet(self, numNodes, preferred=[], isPreemptee=True, id=None): |
---|
71 | """create a nodeset possibly with asked properties""" |
---|
72 | raise NotImplementedError |
---|
73 | |
---|
74 | def submitNodeSet(self, nodeSet, walltime = None, qosLevel = None, |
---|
75 | account = None, resourcelist = None): |
---|
76 | """submit the nodeset request to nodepool |
---|
77 | return False if error happened""" |
---|
78 | raise NotImplementedError |
---|
79 | |
---|
80 | def pollNodeSet(self, nodeSet): |
---|
81 | """return status of node set""" |
---|
82 | raise NotImplementedError |
---|
83 | |
---|
84 | def getWorkers(self): |
---|
85 | """return the hosts that comprise this nodepool""" |
---|
86 | raise NotImplementedError |
---|
87 | |
---|
88 | def runWorkers(self, nodeSet = None, args = []): |
---|
89 | """Run node set workers.""" |
---|
90 | |
---|
91 | raise NotImplementedError |
---|
92 | |
---|
93 | def freeNodeSet(self, nodeset): |
---|
94 | """free a node set""" |
---|
95 | raise NotImplementedError |
---|
96 | |
---|
97 | def finalize(self): |
---|
98 | """cleans up all nodesets""" |
---|
99 | raise NotImplementedError |
---|
100 | |
---|
101 | def getServiceId(self): |
---|
102 | raise NotImplementedError |
---|
103 | |
---|
104 | def getJobInfo(self, jobId=None): |
---|
105 | raise NotImplementedError |
---|
106 | |
---|
107 | def deleteJob(self, jobId): |
---|
108 | """Delete a job, given it's id""" |
---|
109 | raise NotImplementedError |
---|
110 | |
---|
111 | def isJobFeasible(self): |
---|
112 | """Check if job can run by looking at any user/job limits""" |
---|
113 | raise NotImplementedError |
---|
114 | |
---|
115 | def updateWorkerInfo(self, workerInfoMap, jobId): |
---|
116 | """Update information about the workers started by this NodePool.""" |
---|
117 | raise NotImplementedError |
---|
118 | |
---|
119 | def getAccountString(self): |
---|
120 | """Return the account string for this job""" |
---|
121 | raise NotImplementedError |
---|
122 | |
---|
123 | def getNextNodeSetId(self): |
---|
124 | id = self.nextNodeSetId |
---|
125 | self.nextNodeSetId += 1 |
---|
126 | |
---|
127 | return id |
---|
128 | |
---|