import repository from arizona
[raven.git] / apps / gacks / gacksjob.py
1 class AsapResource:
2     def __init__(self, id="cpu", qty=0, string=None):
3         self.id = id
4         self.qty = qty
5         if string:
6             self.load_from_string(string)
7
8     def load_from_string(self, str):
9         parts = str.split("#")
10         if len(parts) >= 1:
11             self.id = parts[0]
12         if len(parts) >= 2:
13             self.qty = parts[1]
14
15     def as_string(self):
16         return str(self.id) + "#" + str(self.qty)
17
18 class AsapJob:
19     def __init__(self, dict = None, duration = 0, allocatorHRN = None, consumerHRN = None, resourceStr = None):
20         self.resources = []
21         self.jobId = -1
22         self.allocatorHRN = allocatorHRN
23         self.consumerHRN = consumerHRN
24         self.duration = duration
25
26         if dict:
27             self.jobId = dict.get("jobid", -1)
28             self.allocatorHRN = dict.get("allocatorHRN", None)
29             self.consumerHRN = dict.get("consumerHRN", None)
30             self.duration = dict.get("duration", 0)
31             resourceStr = dict.get("resources", None)
32
33         if resourceStr:
34             rstrings = resourceStr.split(",")
35             for rstring in rstrings:
36                 self.add(AsapResource(string=rstring))
37
38     def as_dict(self):
39         return {"jobid": self.jobId, "allocatorHRN": self.allocatorHRN, "consumerHRN": self.consumerHRN, "duration": self.duration, "resources": self.get_resources_string()}
40
41     def get_jobid(self):
42         return self.jobId;
43
44     def set_duration(self, x):
45         self.duration = x
46
47     def get_duration(self):
48         return self.duration
49
50     def set_allocator(self, hrn):
51         self.allocatorHRN = hrn
52
53     def get_allocator(self):
54         return self.allocatorHRN
55
56     def set_consumer(self, hrn):
57         self.consumerHRN = hrn
58
59     def get_consumer(self):
60         return self.consumerHRN
61
62     def add(self, resource):
63         self.resources.append(resource)
64
65     def get_resources(self):
66         return self.resources
67
68     def get_resources_string(self):
69         rstrings=[]
70         for resource in self.resources:
71             rstrings.append(resource.as_string())
72
73         return ",".join(rstrings)
74
75