c0fbb0b6571afc279dcdb57289de72b69223952e
[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.*;\r
20 \r
21 public enum _Queue {\r
22 \r
23         /*\r
24          * devel.q          4Gb or 16Gb          8 hour  I\r
25            64bit-pri.q  4Gb or 16Gb     24 hours        B\r
26        64bit.q          4Gb or 16Gb     None    B\r
27        bigint.q         32Gb            8 h     I\r
28        bigmem.q         32Gb            None    B \r
29          */\r
30 \r
31         /**\r
32          * Order of the constraint reflect the priority of the queue\r
33          */\r
34         DEVEL(FIRST_MEMORY_LIMIT, SHORT_TIME_LIMIT,"devel.q"), \r
35         PRIBIT64(FIRST_MEMORY_LIMIT,LONG_TIME_LIMIT,"64bit-pri.q"), \r
36         BIT64(FIRST_MEMORY_LIMIT,0,"64bit.q"), \r
37         BIGINT(MAX_MEMORY_LIMIT,SHORT_TIME_LIMIT,"bigint.q"), \r
38         BIGMEM(MAX_MEMORY_LIMIT,0,"bigmem.q");\r
39         \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          * @return max runtime in hours\r
59          */\r
60         public int getTimeLimit() { \r
61                 return this.maxRuntime;\r
62         }\r
63         \r
64         /**\r
65          * \r
66          * @return true if the queue has time limit, false overwise \r
67          */\r
68         public boolean hasTimeLimit()  { \r
69                 return this.maxRuntime != 0; \r
70         }\r
71         /**\r
72          * return max memory limit in Mb\r
73          * @return\r
74          */\r
75         public int getMemoryLimit() { \r
76                 return this.maxMemory;\r
77         }\r
78         \r
79         public static _Queue getQueueByMemoryRequirements(int maxMemory) { \r
80                 if(maxMemory>FIRST_MEMORY_LIMIT) {\r
81                         return BIGMEM;\r
82                 } else if(maxMemory<MAX_MEMORY_LIMIT)\r
83                         return BIT64; \r
84                 else { \r
85                         throw new UnsupportedOperationException("Cluster does not support tasks requiring more than 30000M of memory");\r
86                 }\r
87         }\r
88 \r
89         public static _Queue getQueue(int maxMemory, int timeLimitInHours) { \r
90                 if(timeLimitInHours==0) { \r
91                         return getQueueByMemoryRequirements(maxMemory);\r
92                 } else { \r
93                         if(timeLimitInHours<=SHORT_TIME_LIMIT) { \r
94                                 if(maxMemory<=FIRST_MEMORY_LIMIT) { \r
95                                         return DEVEL;\r
96                                 }else if(maxMemory<=MAX_MEMORY_LIMIT){ \r
97                                         return BIGINT;\r
98                                 } else { \r
99                                         throw new UnsupportedOperationException("Cluster does not support tasks requiring more than 30000M of memory");\r
100                                 }\r
101                         } else { \r
102                                 // timeLimit > 8\r
103                                 if(timeLimitInHours <= LONG_TIME_LIMIT && maxMemory <=FIRST_MEMORY_LIMIT) { \r
104                                         return PRIBIT64; \r
105                                 } else if( maxMemory<= MAX_MEMORY_LIMIT){ \r
106                                         return BIGMEM;\r
107                                 } else { \r
108                                         throw new UnsupportedOperationException("Cluster does not support tasks requiring more than 30000M of memory");\r
109                                 }\r
110                         }\r
111                 }\r
112         }\r
113         \r
114         public _Queue getQueue(String queueName) { \r
115                 switch(this) { \r
116                 case DEVEL: \r
117                         if ( queueName.equals(DEVEL.toString())) {  \r
118                                 return DEVEL;\r
119                         }\r
120                         break;\r
121                 case PRIBIT64: \r
122                         if ( queueName.equals(PRIBIT64.toString())) {  \r
123                                 return PRIBIT64;\r
124                         }\r
125                         break;\r
126                 case BIT64: \r
127                         if ( queueName.equals(BIT64.toString())) {  \r
128                                 return BIT64;\r
129                         }\r
130                         break;\r
131                 case BIGMEM: \r
132                         if ( queueName.equals(BIGMEM.toString())) {  \r
133                                 return BIGMEM;\r
134                         }\r
135                         break;\r
136                 case BIGINT: \r
137                         if ( queueName.equals(BIGINT.toString())) {  \r
138                                 return BIGINT;\r
139                         }\r
140                         break; \r
141                 }\r
142                 // such queue appears to be not defined in the system!\r
143                 return null; \r
144         }\r
145 \r
146 }\r