1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
32
package com.sun.grid.jgdi.util.shell;
34
import com.sun.grid.jgdi.JGDIException;
35
import com.sun.grid.jgdi.JGDIFactory;
36
import com.sun.grid.jgdi.configuration.Job;
37
import com.sun.grid.jgdi.configuration.JobImpl;
38
import com.sun.grid.jgdi.monitoring.ClusterQueueSummary;
39
import com.sun.grid.jgdi.monitoring.ClusterQueueSummaryOptions;
40
import com.sun.grid.jgdi.monitoring.QueueInstanceSummaryOptions;
41
import com.sun.grid.jgdi.monitoring.QueueInstanceSummaryPrinter;
42
import com.sun.grid.jgdi.monitoring.QueueInstanceSummaryResult;
43
import java.util.List;
45
import static com.sun.grid.jgdi.util.JGDIShell.getResourceString;
49
@CommandAnnotation("qstat")
50
public class QStatCommand extends AnnotatedCommand {
51
ClusterQueueSummaryOptions cqOptions = null;
52
QueueInstanceSummaryOptions qiOptions = null;
54
boolean showXml = false;
56
public void run(String[] args) throws Exception {
57
cqOptions = new ClusterQueueSummaryOptions();
58
qiOptions = new QueueInstanceSummaryOptions();
62
//Lookahead if we have -g c
63
OptionInfo oi = getOptionInfo("-g");
64
//If so print the cluster queues only
65
if (oi != null && oi.getArgsAsString().indexOf("c") >= 0) {
67
if (cqOptions == null) {
70
@SuppressWarnings("unchecked")
71
List<ClusterQueueSummary> res = jgdi.getClusterQueueSummary(cqOptions);
72
if (res.size() == 0) {
75
out.printf("%s%s%n","CLUSTER QUEUE CQLOAD USED RES AVAIL TOTAL aoACDS cdsuE",cqOptions.showAdditionalAttributes() ? " s A S C u a d D c o E" : "");
76
out.printf("%s%s%n","--------------------------------------------------------------------------------",cqOptions.showAdditionalAttributes() ? "------------------------------------------------------------------" : "");
77
for (ClusterQueueSummary elem : res) {
78
out.printf("%-30.30s ",elem.getName());
79
if (elem.isLoadSet()) {
80
out.printf("%7.2f ", elem.getLoad());
82
out.printf("%7s ", "-NA-");
84
out.printf("%6d %6d %6d %6d %6d %6d ", elem.getUsedSlots(), elem.getReservedSlots(), elem.getAvailableSlots(), elem.getTotalSlots(), elem.getTempDisabled(), elem.getManualIntervention());
85
if (cqOptions.showAdditionalAttributes()) {
86
out.printf("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d ", elem.getSuspendManual(), elem.getSuspendThreshold(),
87
elem.getSuspendOnSubordinate(), elem.getSuspendByCalendar(), elem.getUnknown(), elem.getLoadAlarm(), elem.getDisabledManual(),
88
elem.getDisabledByCalendar(), elem.getAmbiguous(), elem.getOrphaned(), elem.getError());
92
//No, we just print normal queue instances
94
//fill the option object
96
if (qiOptions == null) {
99
QueueInstanceSummaryResult res = jgdi.getQueueInstanceSummary(qiOptions);
100
QueueInstanceSummaryPrinter.print(out, res, qiOptions);
104
//[-ext] view additional attributes
105
@OptionAnnotation(value = "-ext", min = 0)
106
public void showExtendedAttributes(final OptionInfo oi) throws JGDIException {
107
qiOptions.setShowAdditionalAttributes(true);
108
cqOptions.setShowAdditionalAttributes(true);
111
//[-explain a|c|A|E] show reason for a(larm),c(onfiguration ambiguous),suspend A(larm), E(rror) state
112
@OptionAnnotation(value = "-explain")
113
public void explainState(final OptionInfo oi) throws JGDIException {
114
qiOptions.setShowFullOutput(true);
115
String str = oi.getFirstArg();
116
if (str.length() != 1) {
117
throw new IllegalArgumentException("Invalid explain specifier in -explain "+str);
119
qiOptions.setExplain(str.charAt(0));
123
@OptionAnnotation(value = "-f", min = 0)
124
public void showFullOutput(final OptionInfo oi) throws JGDIException {
125
qiOptions.setShowFullOutput(true);
126
qiOptions.setShowEmptyQueues(true);
129
//[-F [resource_attributes]] full output and show(selected) resources of queue(s)
130
@OptionAnnotation(value = "-F", min =0, extra=OptionAnnotation.MAX_ARG_VALUE)
131
public void setResourceAttributes(final OptionInfo oi) throws JGDIException {
132
qiOptions.setShowFullOutput(true);
133
qiOptions.updateResourceAttributeFilter(oi.getArgsAsString());
137
//[-g {c|d|t}] display cluster queue summary|all job-array tasks (do not group)|all parallel job tasks (do not group)
138
@OptionAnnotation(value = "-g", extra=OptionAnnotation.MAX_ARG_VALUE)
139
public void setGroupOptions(final OptionInfo oi) throws JGDIException {
140
StringBuilder sb = new StringBuilder(oi.getFirstArg());
141
for (int i = 0; i < sb.length(); i++) {
142
switch (sb.charAt(i)) {
144
qiOptions.setShowArrayJobs(true);
147
qiOptions.setShowPEJobs(true);
152
throw new IllegalArgumentException("Invalid character '" + sb.charAt(i) + "' in -g " + sb.toString());
157
//[-help] print this help
158
@OptionAnnotation(value = "-help", min = 0)
159
public void printUsage(final OptionInfo oi) throws JGDIException {
160
out.println(getUsage());
161
// To avoid the continue of the command
162
throw new AbortException();
165
//[-j job_identifier_list ] show scheduler job information
166
@OptionAnnotation(value = "-j", extra=OptionAnnotation.MAX_ARG_VALUE)
167
public void setShowSchedulerJobInfo(final OptionInfo oi) throws JGDIException {
168
//TODO LP: Improve input values and printing
169
String job = oi.getFirstArg();
170
Job jb = jgdi.getJob(Integer.parseInt(job));
171
/*pw.printf("%29.29s %-s%n", "job_number:", jb.getJobNumber());
172
pw.printf("%29.29s %-s%n", "exec_file:", jb.getExecFile());*/
173
out.print(((JobImpl)jb).dump());
174
throw new AbortException();
177
//[-l resource_list] request the given resources
178
@OptionAnnotation(value = "-l", extra=OptionAnnotation.MAX_ARG_VALUE)
179
public void setResourceList(final OptionInfo oi) throws JGDIException {
180
qiOptions.updateResourceFilter(oi.getArgsAsString());
184
//[-ne] hide empty queues
185
@OptionAnnotation(value = "-ne", min=0)
186
public void hideEmptyQueues(final OptionInfo oi) throws JGDIException {
187
qiOptions.setShowEmptyQueues(false);
190
//[-pe pe_list] select only queues with one of these parallel environments
191
@OptionAnnotation(value = "-pe", extra=OptionAnnotation.MAX_ARG_VALUE)
192
public void setParallelEnvironmentList(final OptionInfo oi) throws JGDIException {
193
qiOptions.updatePeFilter(oi.getArgsAsString());
197
//[-q wc_queue_list] print information on given queue
198
@OptionAnnotation(value = "-q", extra=OptionAnnotation.MAX_ARG_VALUE)
199
public void setQueueList(final OptionInfo oi) throws JGDIException {
200
qiOptions.updateQueueFilter(oi.getArgsAsString());
204
//[-qs {a|c|d|o|s|u|A|C|D|E|S}] selects queues, which are in the given state(s)
205
@OptionAnnotation(value = "-qs" , extra = OptionAnnotation.MAX_ARG_VALUE)
206
public void selectQueuesInState(final OptionInfo oi) throws JGDIException {
207
qiOptions.updateQueueStateFilter(oi.getArgsAsString());
211
//[-r] show requested resources of job(s)
212
@OptionAnnotation(value = "-r", min=0)
213
public void showRequestedResources(final OptionInfo oi) throws JGDIException {
214
qiOptions.setShowRequestedResourcesForJobs(true);
217
/*[-s {p|r|s|z|hu|ho|hs|hj|ha|h|a}] show pending, running, suspended, zombie jobs,jobs with a user/operator/system hold,
218
jobs with a start time in future or any combination only.
219
h is an abbreviation for huhohshjha
220
a is an abbreviation for prsh*/
221
@OptionAnnotation(value = "-s", extra = OptionAnnotation.MAX_ARG_VALUE)
222
public void showJobsInState(final OptionInfo oi) throws JGDIException {
223
throw new UnsupportedOperationException("NOT IMPLEMENTED"); //TODO LP: Implement
224
//jobStateFilter = JobStateFilter.parse(oi.getArgsAsString());
228
//[-t] show task information (implicitly -g t)
229
@OptionAnnotation(value = "-t", min=0)
230
public void showTaskInformation(final OptionInfo oi) throws JGDIException {
231
qiOptions.setShowExtendedSubTaskInfo(true);
232
qiOptions.setShowPEJobs(true);
235
//[-u user_list] view only jobs of this user
236
@OptionAnnotation(value = "-u", extra=OptionAnnotation.MAX_ARG_VALUE)
237
public void showJobsForUsersInUserList(final OptionInfo oi) throws JGDIException {
238
qiOptions.updateJobUserFilter(oi.getArgsAsString());
242
//[-U user_list] select only queues where these users have access
243
@OptionAnnotation(value = "-U", extra=OptionAnnotation.MAX_ARG_VALUE)
244
public void showQueuesAccessibleToUserList(final OptionInfo oi) throws JGDIException {
245
qiOptions.updateQueueUserFilter(oi.getArgsAsString());
249
//[-urg] display job urgency information
250
@OptionAnnotation(value = "-urg", min=0)
251
public void showJobUrgency(final OptionInfo oi) throws JGDIException {
252
qiOptions.setShowJobUrgency(true);
255
//[-pri] display job priority information
256
@OptionAnnotation(value = "-pri", min=0)
257
public void showJobPriority(final OptionInfo oi) throws JGDIException {
258
qiOptions.setShowJobPriorities(true);
261
//[-xml] display the information in XML-Format
262
@OptionAnnotation(value="-xml",min=0)
263
public void setXml(final OptionInfo oi) throws JGDIException {