~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/QrStatCommand.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
 *  The Contents of this file are made available subject to the terms of
 
4
 *  the Sun Industry Standards Source License Version 1.2
 
5
 *
 
6
 *  Sun Microsystems Inc., March, 2001
 
7
 *
 
8
 *
 
9
 *  Sun Industry Standards Source License Version 1.2
 
10
 *  =================================================
 
11
 *  The contents of this file are subject to the Sun Industry Standards
 
12
 *  Source License Version 1.2 (the "License"); You may not use this file
 
13
 *  except in compliance with the License. You may obtain a copy of the
 
14
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
15
 *
 
16
 *  Software provided under this License is provided on an "AS IS" basis,
 
17
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
18
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
19
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
20
 *  See the License for the specific provisions governing your rights and
 
21
 *  obligations concerning the Software.
 
22
 *
 
23
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
24
 *
 
25
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
26
 *
 
27
 *   All Rights Reserved.
 
28
 *
 
29
 ************************************************************************/
 
30
/*___INFO__MARK_END__*/
 
31
package com.sun.grid.jgdi.util.shell;
 
32
 
 
33
import com.sun.grid.jgdi.JGDIException;
 
34
import com.sun.grid.jgdi.JGDIFactory;
 
35
import com.sun.grid.jgdi.configuration.AdvanceReservation;
 
36
import com.sun.grid.jgdi.configuration.AdvanceReservationImpl;
 
37
import com.sun.grid.jgdi.configuration.xml.XMLUtil;
 
38
import java.util.ArrayList;
 
39
import java.util.List;
 
40
 
 
41
import static com.sun.grid.jgdi.util.JGDIShell.getResourceString;
 
42
import static com.sun.grid.jgdi.util.shell.Util.*;
 
43
 
 
44
@CommandAnnotation("qrstat")
 
45
public class QrStatCommand extends AnnotatedCommand {
 
46
    List<String> userList = null;
 
47
    List<Integer> arList = null;
 
48
    
 
49
    boolean xml=false;
 
50
    boolean explain=false;
 
51
    
 
52
    public void run(String[] args) throws Exception {
 
53
        clear();
 
54
        
 
55
        //parse the option
 
56
        parseAndInvokeOptions(args);
 
57
        
 
58
        boolean arlist = !arList.isEmpty();
 
59
        //Let's take ar_list and look for candidates to delete
 
60
        @SuppressWarnings(value = "unchecked")
 
61
        List<AdvanceReservation> ars = (List<AdvanceReservation>) jgdi.getAdvanceReservationList();
 
62
        //Filter out just the ars in the arList
 
63
        if (ars.size() > 0) {
 
64
            if (arList.isEmpty()) {
 
65
                out.println("ar-id   name       owner        state start at             end at               duration");
 
66
                out.println("----------------------------------------------------------------------------------------");
 
67
            }
 
68
            for (AdvanceReservation ar : ars) {
 
69
                if (!arlist) {
 
70
                    if (userList.isEmpty() || userList.contains(ar.getOwner())) {
 
71
                        if (xml) {
 
72
                            XMLUtil.write(ar, out);
 
73
                        } else {
 
74
                            out.printf("%1$7d %2$-10.10s %3$-12.12s %4$-5.5s %5$-20.20s %6$-20.20s %7$s\n", ar.getId(), ar.getName() == null ? "" : ar.getName(), ar.getOwner(), ar.getStateAsString(), getDateAndTimeAsString(ar.getStartTime()), getDateAndTimeAsString(ar.getEndTime()), getTimeAsString(ar.getDuration()));
 
75
                        }
 
76
                    }
 
77
                } else {
 
78
                    if (arList.remove((Object) ar.getId()) && (userList.isEmpty() || userList.contains(ar.getOwner()))) {
 
79
                        AdvanceReservationImpl ari = (AdvanceReservationImpl) ar;
 
80
                        if (xml) {
 
81
                            XMLUtil.write(ari, out);
 
82
                        } else {
 
83
                            out.println(ari.dump());
 
84
                        }
 
85
                    }
 
86
                }
 
87
            }
 
88
        }
 
89
        
 
90
        if (!arList.isEmpty()) {
 
91
            out.println("Following advance reservations do not exist:");
 
92
            out.println(arList);
 
93
        }
 
94
    }
 
95
    
 
96
    //[-ar ar_id_list]                         show advance reservation information
 
97
    @OptionAnnotation(value="-ar",extra=OptionAnnotation.MAX_ARG_VALUE)
 
98
    public void setAdvanceReservationList(final OptionInfo oi) throws JGDIException {
 
99
        try {
 
100
            arList.add(Integer.parseInt(oi.getFirstArg()));
 
101
        } catch (NumberFormatException ex) {
 
102
            throw new IllegalArgumentException("error: ERROR! invalid id, must be an unsigned integer");
 
103
        }
 
104
    }
 
105
    //[-help]                                  print this help
 
106
    @OptionAnnotation(value="-help",min=0)
 
107
    public void printUsage(final OptionInfo oi) throws JGDIException {
 
108
        out.println(getUsage());
 
109
        // To avoid the continue of the command
 
110
        throw new AbortException();
 
111
    }
 
112
    //[-u user_list]                           all advance reservations of users specified in list
 
113
    @OptionAnnotation(value="-u",extra=OptionAnnotation.MAX_ARG_VALUE)
 
114
    public void setUserList(final OptionInfo oi) throws JGDIException {
 
115
        userList.add(oi.getFirstArg());
 
116
    }
 
117
    
 
118
    //[-xml]                                   display the information in XML-Format
 
119
    @OptionAnnotation(value="-xml",min=0)
 
120
    public void setXml(final OptionInfo oi) throws JGDIException {
 
121
        xml=true;
 
122
    }
 
123
    //[-explain]                               show reason for error state
 
124
    @OptionAnnotation(value="-explain",min=0)
 
125
    public void setExplain(final OptionInfo oi) throws JGDIException {
 
126
        explain=true;
 
127
        throw new UnsupportedOperationException("Option -explain is not implemented");
 
128
    }
 
129
    
 
130
    private void clear() {
 
131
        userList = new ArrayList<String>();
 
132
        arList = new ArrayList<Integer>();
 
133
    }
 
134
}