1
/*___INFO__MARK_BEGIN__*/ /*************************************************************************
3
* The Contents of this file are made available subject to the terms of
4
* the Sun Industry Standards Source License Version 1.2
6
* Sun Microsystems Inc., March, 2001
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
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.
23
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
25
* Copyright: 2001 by Sun Microsystems, Inc.
27
* All Rights Reserved.
29
************************************************************************/
30
/*___INFO__MARK_END__*/
31
package com.sun.grid.jgdi.util.shell;
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;
41
import static com.sun.grid.jgdi.util.JGDIShell.getResourceString;
42
import static com.sun.grid.jgdi.util.shell.Util.*;
44
@CommandAnnotation("qrstat")
45
public class QrStatCommand extends AnnotatedCommand {
46
List<String> userList = null;
47
List<Integer> arList = null;
50
boolean explain=false;
52
public void run(String[] args) throws Exception {
56
parseAndInvokeOptions(args);
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
64
if (arList.isEmpty()) {
65
out.println("ar-id name owner state start at end at duration");
66
out.println("----------------------------------------------------------------------------------------");
68
for (AdvanceReservation ar : ars) {
70
if (userList.isEmpty() || userList.contains(ar.getOwner())) {
72
XMLUtil.write(ar, out);
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()));
78
if (arList.remove((Object) ar.getId()) && (userList.isEmpty() || userList.contains(ar.getOwner()))) {
79
AdvanceReservationImpl ari = (AdvanceReservationImpl) ar;
81
XMLUtil.write(ari, out);
83
out.println(ari.dump());
90
if (!arList.isEmpty()) {
91
out.println("Following advance reservations do not exist:");
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 {
100
arList.add(Integer.parseInt(oi.getFirstArg()));
101
} catch (NumberFormatException ex) {
102
throw new IllegalArgumentException("error: ERROR! invalid id, must be an unsigned integer");
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();
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());
118
//[-xml] display the information in XML-Format
119
@OptionAnnotation(value="-xml",min=0)
120
public void setXml(final OptionInfo oi) throws JGDIException {
123
//[-explain] show reason for error state
124
@OptionAnnotation(value="-explain",min=0)
125
public void setExplain(final OptionInfo oi) throws JGDIException {
127
throw new UnsupportedOperationException("Option -explain is not implemented");
130
private void clear() {
131
userList = new ArrayList<String>();
132
arList = new ArrayList<Integer>();