Javadoc fixes
[jabaws.git] / engine / compbio / engine / cluster / dundee / _Queue.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 package compbio.engine.cluster.dundee;\r
19 import static compbio.engine.cluster.dundee._QueueConstraints.FIRST_MEMORY_LIMIT;\r
20 import static compbio.engine.cluster.dundee._QueueConstraints.LONG_TIME_LIMIT;\r
21 import static compbio.engine.cluster.dundee._QueueConstraints.MAX_MEMORY_LIMIT;\r
22 import static compbio.engine.cluster.dundee._QueueConstraints.SHORT_TIME_LIMIT;\r
23 \r
24 @Deprecated\r
25 public enum _Queue {\r
26 \r
27         /*\r
28          * devel.q 4Gb or 16Gb 8 hour I 64bit-pri.q 4Gb or 16Gb 24 hours B 64bit.q\r
29          * 4Gb or 16Gb None B bigint.q 32Gb 8 h I bigmem.q 32Gb None B\r
30          */\r
31 \r
32         /**\r
33          * Order of the constraint reflect the priority of the queue\r
34          */\r
35         DEVEL(FIRST_MEMORY_LIMIT, SHORT_TIME_LIMIT, "devel.q"), PRIBIT64(\r
36                         FIRST_MEMORY_LIMIT, LONG_TIME_LIMIT, "64bit-pri.q"), BIT64(\r
37                         FIRST_MEMORY_LIMIT, 0, "64bit.q"), BIGINT(MAX_MEMORY_LIMIT,\r
38                         SHORT_TIME_LIMIT, "bigint.q"), BIGMEM(MAX_MEMORY_LIMIT, 0,\r
39                         "bigmem.q");\r
40 \r
41         int maxMemory;\r
42         int maxRuntime;\r
43         String qname;\r
44         private _Queue(int maxMemory, int maxRuntime, String qname) {\r
45                 this.maxMemory = maxMemory;\r
46                 this.maxRuntime = maxRuntime;\r
47                 this.qname = qname;\r
48         }\r
49 \r
50         // -q 64bit.q -l qname=64bit.q -l h_vmem=8000M -l ram=8000M\r
51         @Override\r
52         public String toString() {\r
53                 return qname;\r
54         }\r
55 \r
56         /**\r
57          * 0 - unlimited\r
58          * \r
59          * @return max runtime in hours\r
60          */\r
61         public int getTimeLimit() {\r
62                 return this.maxRuntime;\r
63         }\r
64 \r
65         /**\r
66          * \r
67          * @return true if the queue has time limit, false overwise\r
68          */\r
69         public boolean hasTimeLimit() {\r
70                 return this.maxRuntime != 0;\r
71         }\r
72         /**\r
73          * return max memory limit in Mb\r
74          * \r
75          * @return\r
76          */\r
77         public int getMemoryLimit() {\r
78                 return this.maxMemory;\r
79         }\r
80 \r
81         public static _Queue getQueueByMemoryRequirements(int maxMemory) {\r
82                 if (maxMemory > FIRST_MEMORY_LIMIT) {\r
83                         return BIGMEM;\r
84                 } else if (maxMemory < MAX_MEMORY_LIMIT)\r
85                         return BIT64;\r
86                 else {\r
87                         throw new UnsupportedOperationException(\r
88                                         "Cluster does not support tasks requiring more than 30000M of memory");\r
89                 }\r
90         }\r
91 \r
92         public static _Queue getQueue(int maxMemory, int timeLimitInHours) {\r
93                 if (timeLimitInHours == 0) {\r
94                         return getQueueByMemoryRequirements(maxMemory);\r
95                 } else {\r
96                         if (timeLimitInHours <= SHORT_TIME_LIMIT) {\r
97                                 if (maxMemory <= FIRST_MEMORY_LIMIT) {\r
98                                         return DEVEL;\r
99                                 } else if (maxMemory <= MAX_MEMORY_LIMIT) {\r
100                                         return BIGINT;\r
101                                 } else {\r
102                                         throw new UnsupportedOperationException(\r
103                                                         "Cluster does not support tasks requiring more than 30000M of memory");\r
104                                 }\r
105                         } else {\r
106                                 // timeLimit > 8\r
107                                 if (timeLimitInHours <= LONG_TIME_LIMIT\r
108                                                 && maxMemory <= FIRST_MEMORY_LIMIT) {\r
109                                         return PRIBIT64;\r
110                                 } else if (maxMemory <= MAX_MEMORY_LIMIT) {\r
111                                         return BIGMEM;\r
112                                 } else {\r
113                                         throw new UnsupportedOperationException(\r
114                                                         "Cluster does not support tasks requiring more than 30000M of memory");\r
115                                 }\r
116                         }\r
117                 }\r
118         }\r
119 \r
120         public _Queue getQueue(String queueName) {\r
121                 switch (this) {\r
122                         case DEVEL :\r
123                                 if (queueName.equals(DEVEL.toString())) {\r
124                                         return DEVEL;\r
125                                 }\r
126                                 break;\r
127                         case PRIBIT64 :\r
128                                 if (queueName.equals(PRIBIT64.toString())) {\r
129                                         return PRIBIT64;\r
130                                 }\r
131                                 break;\r
132                         case BIT64 :\r
133                                 if (queueName.equals(BIT64.toString())) {\r
134                                         return BIT64;\r
135                                 }\r
136                                 break;\r
137                         case BIGMEM :\r
138                                 if (queueName.equals(BIGMEM.toString())) {\r
139                                         return BIGMEM;\r
140                                 }\r
141                                 break;\r
142                         case BIGINT :\r
143                                 if (queueName.equals(BIGINT.toString())) {\r
144                                         return BIGINT;\r
145                                 }\r
146                                 break;\r
147                 }\r
148                 // such queue appears to be not defined in the system!\r
149                 return null;\r
150         }\r
151 \r
152 }\r