~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jgdi/src/com/sun/grid/jgdi/util/shell/QStatCommand.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 *
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 *
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 *
 
9
 *
 
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
 
16
 *
 
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.
 
23
 *
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 *
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 *
 
28
 *   All Rights Reserved.
 
29
 *
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
package com.sun.grid.jgdi.util.shell;
 
33
 
 
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;
 
44
 
 
45
import static com.sun.grid.jgdi.util.JGDIShell.getResourceString;
 
46
/**
 
47
 *
 
48
 */
 
49
@CommandAnnotation("qstat")
 
50
public class QStatCommand extends AnnotatedCommand {
 
51
    ClusterQueueSummaryOptions cqOptions = null;
 
52
    QueueInstanceSummaryOptions qiOptions = null;
 
53
    
 
54
    boolean showXml = false;
 
55
    
 
56
    public void run(String[] args) throws Exception {
 
57
        cqOptions = new ClusterQueueSummaryOptions();
 
58
        qiOptions = new QueueInstanceSummaryOptions();
 
59
        
 
60
        parseOptions(args);
 
61
        
 
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) {
 
66
            invokeOptions();
 
67
            if (cqOptions == null) {
 
68
                return;
 
69
            }
 
70
            @SuppressWarnings("unchecked")
 
71
            List<ClusterQueueSummary> res = jgdi.getClusterQueueSummary(cqOptions);
 
72
            if (res.size() == 0) {
 
73
                return;
 
74
            }
 
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());
 
81
                } else {
 
82
                    out.printf("%7s ", "-NA-");
 
83
                }
 
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());
 
89
                }
 
90
                out.printf("%n");
 
91
            }
 
92
            //No, we just print normal queue instances
 
93
        } else {
 
94
            //fill the option object
 
95
            invokeOptions();
 
96
            if (qiOptions == null) {
 
97
                return;
 
98
            }
 
99
            QueueInstanceSummaryResult res = jgdi.getQueueInstanceSummary(qiOptions);
 
100
            QueueInstanceSummaryPrinter.print(out, res, qiOptions);
 
101
        }
 
102
    }
 
103
    
 
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);
 
109
    }
 
110
    
 
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);
 
118
        }
 
119
        qiOptions.setExplain(str.charAt(0));
 
120
    }
 
121
    
 
122
    //[-f]                              full output
 
123
    @OptionAnnotation(value = "-f", min = 0)
 
124
    public void showFullOutput(final OptionInfo oi) throws JGDIException {
 
125
        qiOptions.setShowFullOutput(true);
 
126
        qiOptions.setShowEmptyQueues(true);
 
127
    }
 
128
    
 
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());
 
134
        oi.optionDone();
 
135
    }
 
136
    
 
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)) {
 
143
                case 'd':
 
144
                    qiOptions.setShowArrayJobs(true);
 
145
                    break;
 
146
                case 't':
 
147
                    qiOptions.setShowPEJobs(true);
 
148
                    break;
 
149
                case 'c':
 
150
                    break;
 
151
                default:
 
152
                    throw new IllegalArgumentException("Invalid character '" + sb.charAt(i) + "' in -g " + sb.toString());
 
153
            }
 
154
        }
 
155
    }
 
156
    
 
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();
 
163
    }
 
164
    
 
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();
 
175
    }
 
176
    
 
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());
 
181
        oi.optionDone();
 
182
    }
 
183
    
 
184
    //[-ne]                             hide empty queues
 
185
    @OptionAnnotation(value = "-ne", min=0)
 
186
    public void hideEmptyQueues(final OptionInfo oi) throws JGDIException {
 
187
        qiOptions.setShowEmptyQueues(false);
 
188
    }
 
189
    
 
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());
 
194
        oi.optionDone();
 
195
    }
 
196
    
 
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());
 
201
        oi.optionDone();
 
202
    }
 
203
    
 
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());
 
208
        oi.optionDone();
 
209
    }
 
210
    
 
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);
 
215
    }
 
216
    
 
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());
 
225
        //oi.optionDone();
 
226
    }
 
227
    
 
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);
 
233
    }
 
234
    
 
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());
 
239
        oi.optionDone();
 
240
    }
 
241
    
 
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());
 
246
        oi.optionDone();
 
247
    }
 
248
    
 
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);
 
253
    }
 
254
    
 
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);
 
259
    }
 
260
    
 
261
    //[-xml]                            display the information in XML-Format
 
262
    @OptionAnnotation(value="-xml",min=0)
 
263
    public void setXml(final OptionInfo oi) throws JGDIException {
 
264
        showXml=true;
 
265
    }
 
266
}