6f4125ffa9720f33deb6dd0c82f29023e9d0a915
[jabaws.git] / runner / compbio / runner / _NativeSpecHelper.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.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.runner;\r
19 \r
20 import java.net.UnknownServiceException;\r
21 \r
22 import compbio.engine.cluster.dundee._Queue;\r
23 \r
24 public class _NativeSpecHelper {\r
25 \r
26         int maxCalculationTime;\r
27         int requiredMemory;\r
28         String queue;\r
29 \r
30         public _NativeSpecHelper(int requiredMemory) {\r
31                 this(requiredMemory, 0);\r
32         }\r
33 \r
34         public _NativeSpecHelper(int requiredMemory, int maxCalculationTime) {\r
35                 this.requiredMemory = requiredMemory;\r
36                 this.maxCalculationTime = maxCalculationTime;\r
37         }\r
38 \r
39         public void setRequiredMemory(int memory) {\r
40                 this.requiredMemory = memory;\r
41         }\r
42 \r
43         int getRequiredMemory() {\r
44                 return requiredMemory;\r
45         }\r
46 \r
47         public void setQueue(String queue) {\r
48                 this.queue = queue;\r
49         }\r
50 \r
51         public String getQueue() {\r
52                 return queue;\r
53         }\r
54 \r
55         // -q 64bit.q -l qname=64bit.q -l h_vmem=8000M -l ram=8000M\r
56         public String getNativeSpec() throws UnknownServiceException {\r
57                 if (queue == null) {\r
58                         queue = getApproprieteQueue().toString();\r
59                 } else {\r
60                         // check whether chosen queue suits for memory and runtime settings\r
61                         _Queue knownQueue = _Queue.BIGINT.getQueue(queue);\r
62                         if (knownQueue == null) {\r
63                                 throw new UnknownServiceException("Queue " + queue\r
64                                                 + " is not regestered in the system! ");\r
65                         }\r
66                         if (this.requiredMemory <= knownQueue.getMemoryLimit()) {\r
67                                 throw new UnknownServiceException("Queue " + queue\r
68                                                 + " has a memory limit of "\r
69                                                 + knownQueue.getMemoryLimit()\r
70                                                 + "M - which is smaller than requested!");\r
71                         }\r
72                         if (knownQueue.hasTimeLimit()\r
73                                         && this.maxCalculationTime <= knownQueue.getTimeLimit()) {\r
74                                 throw new UnknownServiceException("Queue " + queue\r
75                                                 + " has a time limit of " + knownQueue.getTimeLimit()\r
76                                                 + "hours - which is smaller than requested!");\r
77                         }\r
78                 }\r
79                 return "-q " + queue.toString() + "-l qname=" + queue.toString()\r
80                                 + ", h_vmem=" + requiredMemory + "M,ram=" + requiredMemory\r
81                                 + "M";\r
82         }\r
83 \r
84         public _Queue getApproprieteQueue() {\r
85                 return _Queue.getQueue(requiredMemory, maxCalculationTime);\r
86         }\r
87 \r
88 }\r