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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 *
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 *
 *  Sun Microsystems Inc., March, 2001
 *
 *
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *   Copyright: 2001 by Sun Microsystems, Inc.
 *
 *   All Rights Reserved.
 *
 ************************************************************************/
/*___INFO__MARK_END__*/
package com.sun.grid.jgdi.util.shell;

import com.sun.grid.jgdi.JGDIException;
import com.sun.grid.jgdi.JGDIFactory;
import com.sun.grid.jgdi.configuration.Job;
import com.sun.grid.jgdi.configuration.JobImpl;
import com.sun.grid.jgdi.monitoring.ClusterQueueSummary;
import com.sun.grid.jgdi.monitoring.ClusterQueueSummaryOptions;
import com.sun.grid.jgdi.monitoring.QueueInstanceSummaryOptions;
import com.sun.grid.jgdi.monitoring.QueueInstanceSummaryPrinter;
import com.sun.grid.jgdi.monitoring.QueueInstanceSummaryResult;
import java.util.List;

import static com.sun.grid.jgdi.util.JGDIShell.getResourceString;
/**
 *
 */
@CommandAnnotation("qstat")
public class QStatCommand extends AnnotatedCommand {
    ClusterQueueSummaryOptions cqOptions = null;
    QueueInstanceSummaryOptions qiOptions = null;
    
    boolean showXml = false;
    
    public void run(String[] args) throws Exception {
        cqOptions = new ClusterQueueSummaryOptions();
        qiOptions = new QueueInstanceSummaryOptions();
        
        parseOptions(args);
        
        //Lookahead if we have -g c
        OptionInfo oi = getOptionInfo("-g");
        //If so print the cluster queues only
        if (oi != null && oi.getArgsAsString().indexOf("c") >= 0) {
            invokeOptions();
            if (cqOptions == null) {
                return;
            }
            @SuppressWarnings("unchecked")
            List<ClusterQueueSummary> res = jgdi.getClusterQueueSummary(cqOptions);
            if (res.size() == 0) {
                return;
            }
            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" : "");
            out.printf("%s%s%n","--------------------------------------------------------------------------------",cqOptions.showAdditionalAttributes() ? "------------------------------------------------------------------" : "");
            for (ClusterQueueSummary elem : res) {
                out.printf("%-30.30s ",elem.getName());
                if (elem.isLoadSet()) {
                    out.printf("%7.2f ", elem.getLoad());
                } else {
                    out.printf("%7s ", "-NA-");
                }
                out.printf("%6d %6d %6d %6d %6d %6d ", elem.getUsedSlots(), elem.getReservedSlots(), elem.getAvailableSlots(), elem.getTotalSlots(), elem.getTempDisabled(), elem.getManualIntervention());
                if (cqOptions.showAdditionalAttributes()) {
                    out.printf("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d ", elem.getSuspendManual(), elem.getSuspendThreshold(),
                            elem.getSuspendOnSubordinate(), elem.getSuspendByCalendar(), elem.getUnknown(), elem.getLoadAlarm(), elem.getDisabledManual(),
                            elem.getDisabledByCalendar(), elem.getAmbiguous(), elem.getOrphaned(), elem.getError());
                }
                out.printf("%n");
            }
            //No, we just print normal queue instances
        } else {
            //fill the option object
            invokeOptions();
            if (qiOptions == null) {
                return;
            }
            QueueInstanceSummaryResult res = jgdi.getQueueInstanceSummary(qiOptions);
            QueueInstanceSummaryPrinter.print(out, res, qiOptions);
        }
    }
    
    //[-ext]                            view additional attributes
    @OptionAnnotation(value = "-ext", min = 0)
    public void showExtendedAttributes(final OptionInfo oi) throws JGDIException {
        qiOptions.setShowAdditionalAttributes(true);
        cqOptions.setShowAdditionalAttributes(true);
    }
    
    //[-explain a|c|A|E]                show reason for a(larm),c(onfiguration ambiguous),suspend A(larm), E(rror)   state
    @OptionAnnotation(value = "-explain")
    public void explainState(final OptionInfo oi) throws JGDIException {
        qiOptions.setShowFullOutput(true);
        String str = oi.getFirstArg();
        if (str.length() != 1) {
            throw new IllegalArgumentException("Invalid explain specifier in -explain "+str);
        }
        qiOptions.setExplain(str.charAt(0));
    }
    
    //[-f]                              full output
    @OptionAnnotation(value = "-f", min = 0)
    public void showFullOutput(final OptionInfo oi) throws JGDIException {
        qiOptions.setShowFullOutput(true);
        qiOptions.setShowEmptyQueues(true);
    }
    
    //[-F [resource_attributes]]        full output and show(selected) resources of queue(s)
    @OptionAnnotation(value = "-F", min =0, extra=OptionAnnotation.MAX_ARG_VALUE)
    public void setResourceAttributes(final OptionInfo oi) throws JGDIException {
        qiOptions.setShowFullOutput(true);
        qiOptions.updateResourceAttributeFilter(oi.getArgsAsString());
        oi.optionDone();
    }
    
    //[-g {c|d|t}]                      display cluster queue summary|all job-array tasks (do not group)|all parallel job tasks (do not group)
    @OptionAnnotation(value = "-g", extra=OptionAnnotation.MAX_ARG_VALUE)
    public void setGroupOptions(final OptionInfo oi) throws JGDIException {
        StringBuilder sb = new StringBuilder(oi.getFirstArg());
        for (int i = 0; i < sb.length(); i++) {
            switch (sb.charAt(i)) {
                case 'd':
                    qiOptions.setShowArrayJobs(true);
                    break;
                case 't':
                    qiOptions.setShowPEJobs(true);
                    break;
                case 'c':
                    break;
                default:
                    throw new IllegalArgumentException("Invalid character '" + sb.charAt(i) + "' in -g " + sb.toString());
            }
        }
    }
    
    //[-help]                                  print this help
    @OptionAnnotation(value = "-help", min = 0)
    public void printUsage(final OptionInfo oi) throws JGDIException {
        out.println(getUsage());
        // To avoid the continue of the command
        throw new AbortException();
    }
    
    //[-j job_identifier_list ]         show scheduler job information
    @OptionAnnotation(value = "-j", extra=OptionAnnotation.MAX_ARG_VALUE)
    public void setShowSchedulerJobInfo(final OptionInfo oi) throws JGDIException {
        //TODO LP: Improve input values and printing
        String job = oi.getFirstArg();
        Job jb = jgdi.getJob(Integer.parseInt(job));
      /*pw.printf("%29.29s %-s%n", "job_number:", jb.getJobNumber());
      pw.printf("%29.29s %-s%n", "exec_file:", jb.getExecFile());*/
        out.print(((JobImpl)jb).dump());
        throw new AbortException();
    }
    
    //[-l resource_list]                request the given resources
    @OptionAnnotation(value = "-l", extra=OptionAnnotation.MAX_ARG_VALUE)
    public void setResourceList(final OptionInfo oi) throws JGDIException {
        qiOptions.updateResourceFilter(oi.getArgsAsString());
        oi.optionDone();
    }
    
    //[-ne]                             hide empty queues
    @OptionAnnotation(value = "-ne", min=0)
    public void hideEmptyQueues(final OptionInfo oi) throws JGDIException {
        qiOptions.setShowEmptyQueues(false);
    }
    
    //[-pe pe_list]                     select only queues with one of these parallel environments
    @OptionAnnotation(value = "-pe", extra=OptionAnnotation.MAX_ARG_VALUE)
    public void setParallelEnvironmentList(final OptionInfo oi) throws JGDIException {
        qiOptions.updatePeFilter(oi.getArgsAsString());
        oi.optionDone();
    }
    
    //[-q wc_queue_list]                print information on given queue
    @OptionAnnotation(value = "-q", extra=OptionAnnotation.MAX_ARG_VALUE)
    public void setQueueList(final OptionInfo oi) throws JGDIException {
        qiOptions.updateQueueFilter(oi.getArgsAsString());
        oi.optionDone();
    }
    
    //[-qs {a|c|d|o|s|u|A|C|D|E|S}]     selects queues, which are in the given state(s)
    @OptionAnnotation(value = "-qs" , extra = OptionAnnotation.MAX_ARG_VALUE)
    public void selectQueuesInState(final OptionInfo oi) throws JGDIException {
        qiOptions.updateQueueStateFilter(oi.getArgsAsString());
        oi.optionDone();
    }
    
    //[-r]                              show requested resources of job(s)
    @OptionAnnotation(value = "-r", min=0)
    public void showRequestedResources(final OptionInfo oi) throws JGDIException {
        qiOptions.setShowRequestedResourcesForJobs(true);
    }
    
   /*[-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,
                                          jobs with a start time in future or any combination only.
                                          h is an abbreviation for huhohshjha
                                          a is an abbreviation for prsh*/
    @OptionAnnotation(value = "-s", extra = OptionAnnotation.MAX_ARG_VALUE)
    public void showJobsInState(final OptionInfo oi) throws JGDIException {
        throw new UnsupportedOperationException("NOT IMPLEMENTED");  //TODO LP: Implement
        //jobStateFilter = JobStateFilter.parse(oi.getArgsAsString());
        //oi.optionDone();
    }
    
    //[-t]                              show task information (implicitly -g t)
    @OptionAnnotation(value = "-t", min=0)
    public void showTaskInformation(final OptionInfo oi) throws JGDIException {
        qiOptions.setShowExtendedSubTaskInfo(true);
        qiOptions.setShowPEJobs(true);
    }
    
    //[-u user_list]                    view only jobs of this user
    @OptionAnnotation(value = "-u", extra=OptionAnnotation.MAX_ARG_VALUE)
    public void showJobsForUsersInUserList(final OptionInfo oi) throws JGDIException {
        qiOptions.updateJobUserFilter(oi.getArgsAsString());
        oi.optionDone();
    }
    
    //[-U user_list]                    select only queues where these users have access
    @OptionAnnotation(value = "-U", extra=OptionAnnotation.MAX_ARG_VALUE)
    public void showQueuesAccessibleToUserList(final OptionInfo oi) throws JGDIException {
        qiOptions.updateQueueUserFilter(oi.getArgsAsString());
        oi.optionDone();
    }
    
    //[-urg]                            display job urgency information
    @OptionAnnotation(value = "-urg", min=0)
    public void showJobUrgency(final OptionInfo oi) throws JGDIException {
        qiOptions.setShowJobUrgency(true);
    }
    
    //[-pri]                            display job priority information
    @OptionAnnotation(value = "-pri", min=0)
    public void showJobPriority(final OptionInfo oi) throws JGDIException {
        qiOptions.setShowJobPriorities(true);
    }
    
    //[-xml]                            display the information in XML-Format
    @OptionAnnotation(value="-xml",min=0)
    public void setXml(final OptionInfo oi) throws JGDIException {
        showXml=true;
    }
}