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

« back to all changes in this revision

Viewing changes to source/libs/jgdi/templates/java_qconf_cmd.jsp

  • 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
/**
 
33
 *  Generated from java_jmx_jgdi.jsp
 
34
 *  !!! DO NOT EDIT THIS FILE !!!
 
35
 */
 
36
 
 
37
 
 
38
<%
 
39
    /*
 
40
    * Helper class to initialize option Map.
 
41
    */
 
42
   class MapInit {
 
43
      java.util.Map<String, String> nameToOpt = new java.util.HashMap<String, String>();
 
44
 
 
45
      //TODO LP: Is already defined in OptionAnnotation, however annotation not seen in this context
 
46
      static final int MAX_ARG_VALUE = Integer.MAX_VALUE / 8;
 
47
      
 
48
      public MapInit() {
 
49
         nameToOpt.put("Calendar","cal");
 
50
         nameToOpt.put("Checkpoint","ckpt");
 
51
         nameToOpt.put("Configuration","conf");
 
52
         nameToOpt.put("ClusterQueue","q");
 
53
         //nameToOpt.put("ExecHost","e");
 
54
         nameToOpt.put("Hostgroup","hgrp");
 
55
         nameToOpt.put("ParallelEnvironment","p");
 
56
         nameToOpt.put("Project","prj");
 
57
         //nameToOpt.put("ResourceQuotaSet","rqs");
 
58
         nameToOpt.put("User","user");
 
59
      }
 
60
      
 
61
      java.util.Map<String, String> getMap() {
 
62
         return nameToOpt;
 
63
      }
 
64
      
 
65
      public void genDefaultMethodsForType(String type) {
 
66
         if (!nameToOpt.containsKey(type)) {
 
67
            throw new IllegalStateException("<QConfCommand> failed: Unknown option type "+type);
 
68
         }
 
69
         String opt = (String) nameToOpt.get(type);
 
70
         genAddMethod(type, "-a"+opt, 0, 1);
 
71
         genAddFromFileMethod(type, "-A"+opt, 1, 0);
 
72
         genModifyMethod(type, "-m"+opt, 1, 0);
 
73
         genModifyFromFileMethod(type, "-M"+opt, 1, 0);
 
74
         genShowMethod(type, "-s"+opt, 1, MAX_ARG_VALUE);
 
75
         genShowListMethod(type, "-s"+opt+"l", 0, 0);
 
76
         genDeleteMethod(type, "-d"+opt, 1, MAX_ARG_VALUE);
 
77
      }
 
78
      
 
79
      void genAddMethod(String objectType, String optionString, int mandatory, int optional) {  
 
80
      %>
 
81
   /**
 
82
    *   Implements qconf <%=optionString%> option
 
83
    *   @param  oi <b>OptionInfo</b> option enviroment object
 
84
    *   @throws JGDIException on any error on the GDI layer
 
85
    */
 
86
   @OptionAnnotation(value = "<%=optionString%>", min = <%=mandatory%>, extra = <%=optional%>)
 
87
   public void add<%=objectType%>(final OptionInfo oi) throws JGDIException {
 
88
      oi.optionDone();
 
89
      String arg = oi.getFirstArg();
 
90
      List<JGDIAnswer> answer = new LinkedList<JGDIAnswer>();
 
91
      // create an object with defaults set
 
92
      <%=objectType%> obj = new <%=objectType%>Impl(true);
 
93
      if (arg != null) {
 
94
         obj.setName(arg);
 
95
      }
 
96
      String userTypedText = runEditor(GEObjectEditor.getConfigurablePropertiesAsText(obj));
 
97
 
 
98
      if (userTypedText != null) {
 
99
         GEObjectEditor.updateObjectWithText(jgdi, obj, userTypedText);
 
100
         jgdi.add<%=objectType%>WithAnswer(obj, answer);
 
101
         printAnswers(answer);
 
102
      }
 
103
   }   
 
104
   <%
 
105
       } //end genAddMethod
 
106
       
 
107
       void genAddFromFileMethod(String objectType, String optionString, int mandatory, int optional) {
 
108
       %>
 
109
   /**
 
110
    *   Implements qconf <%=optionString%> option
 
111
    *   @param  oi <b>OptionInfo</b> option enviroment object
 
112
    *   @throws JGDIException on any error on the GDI layer
 
113
    */
 
114
   @OptionAnnotation(value = "<%=optionString%>", min = <%=mandatory%>, extra = <%=optional%>)
 
115
   public void addFromFile<%=objectType%>(final OptionInfo oi) throws JGDIException {
 
116
      //Just look at the filename
 
117
      final String fileName = oi.getArgs().get(0);
 
118
      oi.optionDone();
 
119
      List<JGDIAnswer> answer = new LinkedList<JGDIAnswer>();
 
120
      <%=objectType%> obj = new <%=objectType%>Impl(true);
 
121
      String inputText = readFile(oi);
 
122
      <%if (objectType.equals("Configuration")) {%>
 
123
      final String keyAttrValue = new File(fileName).getName();
 
124
      <%} else {%>
 
125
      final String keyAttrValue = getKeyAttributeValueFromString(err, "<%=objectType%>", fileName, inputText);
 
126
      <% } %>
 
127
      if (keyAttrValue == null) {
 
128
         return;
 
129
      }
 
130
      obj.setName(keyAttrValue);
 
131
      GEObjectEditor.updateObjectWithText(jgdi, obj, inputText);
 
132
      jgdi.add<%=objectType%>WithAnswer(obj, answer);
 
133
      printAnswers(answer);
 
134
   }  
 
135
   <%
 
136
       } //end genAddFromFileMethod  
 
137
       
 
138
       void genModifyMethod(String objectType, String optionString, int mandatory, int optional) {
 
139
       %>
 
140
   /**
 
141
    *   Implements qconf <%=optionString%> option
 
142
    *   @param  oi <b>OptionInfo</b> option enviroment object
 
143
    *   @throws JGDIException on any error on the GDI layer
 
144
    */
 
145
   @OptionAnnotation(value = "<%=optionString%>", min = <%=mandatory%>, extra = <%=optional%>)
 
146
   public void modify<%=objectType%>(final OptionInfo oi) throws JGDIException {
 
147
      final String arg = oi.getFirstArg();
 
148
      List<JGDIAnswer> answer = new LinkedList<JGDIAnswer>();
 
149
      <% if ( mandatory == 0 && optional == 0 ) { %>
 
150
      <%=objectType%> obj = jgdi.get<%=objectType%>WithAnswer(answer);
 
151
      <% } else { %>
 
152
      <%=objectType%> obj = jgdi.get<%=objectType%>WithAnswer(arg, answer);
 
153
      <% }%>
 
154
      if (obj != null) {
 
155
         //clear the answers from the get request
 
156
         answer.clear();
 
157
         String userTypedText = runEditor(GEObjectEditor.getConfigurablePropertiesAsText(obj));
 
158
         if (userTypedText != null) {
 
159
            GEObjectEditor.updateObjectWithText(jgdi, obj, userTypedText);
 
160
            jgdi.update<%=objectType%>WithAnswer(obj, answer);
 
161
         }
 
162
         printAnswers(answer);
 
163
      } else {
 
164
         err.println(getErrorMessage("InvalidObjectArgument", oi.getOd().getOption(), arg));
 
165
         setExitCode(getCustomExitCode("InvalidObjectArgument", oi.getOd().getOption()));
 
166
      }
 
167
      oi.optionDone();
 
168
   }  
 
169
   <%
 
170
       } //end genModifyMethod  
 
171
       
 
172
       void genModifyFromFileMethod(String objectType, String optionString, int mandatory, int optional) {
 
173
       %>
 
174
   /**
 
175
    *   Implements qconf <%=optionString%> option
 
176
    *   @param  oi <b>OptionInfo</b> option enviroment object
 
177
    *   @throws JGDIException on any error on the GDI layer
 
178
    */
 
179
   @OptionAnnotation(value = "<%=optionString%>", min = <%=mandatory%>, extra = <%=optional%>)
 
180
   public void modifyFromFile<%=objectType%>(final OptionInfo oi) throws JGDIException {
 
181
      //Just look at the filename
 
182
      final String fileName = oi.getArgs().get(0);
 
183
      oi.optionDone();
 
184
      List<JGDIAnswer> answer = new LinkedList<JGDIAnswer>();
 
185
      String inputText = readFile(oi);
 
186
      <%=objectType%> obj;
 
187
      <%if (objectType.equals("SchedConf")) {%>
 
188
      obj = jgdi.getSchedConfWithAnswer(answer);
 
189
      <%} else {%>
 
190
      final String keyAttrValue = getKeyAttributeValueFromString(err, "<%=objectType%>", fileName, inputText);
 
191
      if (keyAttrValue == null) {
 
192
         return;
 
193
      }
 
194
      obj = jgdi.get<%=objectType%>WithAnswer(keyAttrValue, answer);
 
195
      <%} %>
 
196
      printAnswers(answer);
 
197
      answer.clear();
 
198
      if (obj != null) {
 
199
          GEObjectEditor.updateObjectWithText(jgdi, obj, inputText);
 
200
          jgdi.update<%=objectType%>WithAnswer(obj, answer);
 
201
          printAnswers(answer);
 
202
      } else {
 
203
          //TODO LP: Check this is ever displayed
 
204
          <%if (objectType.equals("SchedConf")) {%>
 
205
          err.println(getErrorMessage("InvalidObjectArgument", oi.getOd().getOption()));
 
206
          <%} else {%>
 
207
          err.println(getErrorMessage("InvalidObjectArgument", oi.getOd().getOption(), keyAttrValue));
 
208
          <%} %>
 
209
          setExitCode(getCustomExitCode("InvalidObjectArgument", oi.getOd().getOption()));
 
210
      }
 
211
   }  
 
212
   <%
 
213
       } //end genModifyFromFileMethod  
 
214
       
 
215
       void genShowMethod(String objectType, String optionString, int mandatory, int optional) {
 
216
       %>
 
217
   /**
 
218
    *   Implements qconf <%=optionString%> option
 
219
    *   @param  oi <b>OptionInfo</b> option enviroment object
 
220
    *   @throws JGDIException on any error on the GDI layer
 
221
    */
 
222
   @OptionAnnotation(value = "<%=optionString%>", min = <%=mandatory%>, extra = <%=optional%>)
 
223
   public void show<%=objectType%>(final OptionInfo oi) throws JGDIException {
 
224
      final String arg = oi.getFirstArg();
 
225
      List<JGDIAnswer> answer = new LinkedList<JGDIAnswer>();
 
226
      <% if ( mandatory == 0 && optional == 0 ) { %>
 
227
      <%=objectType%> obj = jgdi.get<%=objectType%>WithAnswer(answer);
 
228
      <% } else { %>
 
229
      <%=objectType%> obj = jgdi.get<%=objectType%>WithAnswer(arg, answer);
 
230
      <% }%>
 
231
      printAnswers(answer);
 
232
      //Display error message in no such object exists
 
233
      if (obj == null) {
 
234
          err.println(getErrorMessage("InvalidObjectArgument", oi.getOd().getOption(), arg));
 
235
          setExitCode(getCustomExitCode("InvalidObjectArgument", oi.getOd().getOption()));
 
236
          return;
 
237
      }
 
238
      //Show the object
 
239
      String text = GEObjectEditor.getAllPropertiesAsText(obj);
 
240
      out.print(text);
 
241
   } 
 
242
   <%
 
243
       } //end genShowMethod  
 
244
       
 
245
       void genShowListMethod(String objectType, String optionString, int mandatory, int optional) {
 
246
       %>
 
247
   /**
 
248
    *   Implements qconf <%=optionString%> option
 
249
    *   @param  oi <b>OptionInfo</b> option enviroment object
 
250
    *   @throws JGDIException on any error on the GDI layer
 
251
    */
 
252
   @OptionAnnotation(value = "<%=optionString%>", min = <%=mandatory%>, extra = <%=optional%>)
 
253
   public void showList<%=objectType%>(final OptionInfo oi) throws JGDIException {
 
254
      List<JGDIAnswer> answer = new LinkedList<JGDIAnswer>();
 
255
      List< <%=objectType%> > list = (List< <%=objectType%> >)jgdi.get<%=objectType%>ListWithAnswer(answer);
 
256
      printAnswers(answer);
 
257
      List<String> values = new LinkedList<String>();
 
258
      for (<%=objectType%> obj : list) {
 
259
         values.add(obj.getName());
 
260
      }
 
261
      <% if (objectType.equals("Configuration") || objectType.equals("UserSet")) { %>
 
262
      values.remove("global");
 
263
      <%} else if (objectType.equals("ExecHost")) { %>
 
264
      values.remove("global");
 
265
      values.remove("template");
 
266
      <% } %>
 
267
      //Show correct error message if list is empty
 
268
      if (values.size() == 0) {
 
269
          err.println(getErrorMessage("NoObjectFound", oi.getOd().getOption()));
 
270
          setExitCode(getCustomExitCode("NoObjectFound", oi.getOd().getOption()));
 
271
          return;
 
272
      }
 
273
      //Otherwise print sorted list
 
274
      Collections.sort(values);
 
275
      for (String val : values) {
 
276
        out.println(val);
 
277
      }
 
278
      oi.optionDone();
 
279
   }   
 
280
   <%
 
281
       } //end genShowListMethod
 
282
       
 
283
       void genDeleteMethod(String objectType, String optionString, int mandatory, int optional) {
 
284
       %>
 
285
   /**
 
286
    *   Implements qconf <%=optionString%> option
 
287
    *   @param  oi <b>OptionInfo</b> option enviroment object
 
288
    *   @throws JGDIException on any error on the GDI layer
 
289
    */
 
290
   @OptionAnnotation(value = "<%=optionString%>", min = <%=mandatory%>, extra = <%=optional%>)
 
291
   public void delete<%=objectType%>(final OptionInfo oi) throws JGDIException {
 
292
      List<JGDIAnswer> answers = new LinkedList<JGDIAnswer>();
 
293
      int size = oi.getArgs().size();
 
294
      final String[] vals = oi.getArgs().toArray(new String[size]);
 
295
      oi.optionDone();
 
296
      jgdi.delete<%=objectType%>sWithAnswer(vals, answers);
 
297
      printAnswers(answers);
 
298
   }
 
299
   <%
 
300
       } //end genDeleteMethod  
 
301
       
 
302
  } //end Class MapInit
 
303
  
 
304
  
 
305
  // ---------------------------------------------------------------------------
 
306
  // Build Generator instances
 
307
  // ---------------------------------------------------------------------------
 
308
  MapInit init = new MapInit();
 
309
%>
 
310
package com.sun.grid.jgdi.util.shell;
 
311
 
 
312
import com.sun.grid.jgdi.JGDI;
 
313
import com.sun.grid.jgdi.JGDIException;
 
314
import com.sun.grid.jgdi.configuration.*;
 
315
import com.sun.grid.jgdi.util.shell.AnnotatedCommand;
 
316
import com.sun.grid.jgdi.util.shell.editor.EditorUtil;
 
317
import com.sun.grid.jgdi.util.shell.editor.GEObjectEditor;
 
318
import com.sun.grid.jgdi.util.shell.editor.TextEditor;
 
319
import java.io.File;
 
320
import java.io.FileReader;
 
321
import java.io.FileWriter;
 
322
import java.io.IOException;
 
323
import java.io.LineNumberReader;
 
324
import java.io.PrintWriter;
 
325
import java.io.StringReader;
 
326
import java.util.LinkedList;
 
327
import java.util.Collections;
 
328
import java.util.List;
 
329
 
 
330
/**
 
331
 * Generated abstract class for handling generic JGDI objects.
 
332
 * Implements generic qconf command options.
 
333
 * NOTE: QConfCommand should extend this class.
 
334
 * @see com.sun.grid.jgdi.util.shell.QConfCommand
 
335
 */
 
336
public abstract class QConfCommandGenerated extends AnnotatedCommand {
 
337
 
 
338
   
 
339
<% for (String objType : init.getMap().keySet()) {
 
340
     init.genDefaultMethodsForType(objType);
 
341
  }
 
342
  //ExecHost
 
343
  init.genAddFromFileMethod("ExecHost", "-Ae", 1, 0);
 
344
  init.genModifyMethod("ExecHost", "-me", 1, 0);
 
345
  init.genModifyFromFileMethod("ExecHost", "-Me", 1, 0);
 
346
  init.genShowMethod("ExecHost", "-se", 1, init.MAX_ARG_VALUE);
 
347
  init.genShowListMethod("ExecHost", "-sel", 0, 0);
 
348
  init.genDeleteMethod("ExecHost", "-de", 1, init.MAX_ARG_VALUE);
 
349
  //SchedConf
 
350
  init.genModifyMethod("SchedConf","-msconf", 0, 0);
 
351
  init.genModifyFromFileMethod("SchedConf", "-Msconf", 1, 0);
 
352
  init.genShowMethod("SchedConf", "-ssconf",0, 0);
 
353
  //UserSet
 
354
  init.genAddFromFileMethod("UserSet","-Au", 1, 0);
 
355
  init.genModifyMethod("UserSet", "-mu", 1, 0);
 
356
  init.genModifyFromFileMethod("UserSet","-Mu",  1, 0);
 
357
  init.genShowMethod("UserSet", "-su", 1, init.MAX_ARG_VALUE);
 
358
  init.genShowListMethod("UserSet", "-sul", 0, 0);
 
359
  //Operator
 
360
  init.genShowListMethod("Operator", "-so", 0, 0);
 
361
  //Manager
 
362
  init.genShowListMethod("Manager", "-sm", 0, 0);
 
363
  //SubmitHost
 
364
  init.genShowListMethod("SubmitHost", "-ss", 0, 0);
 
365
  //AdminHost
 
366
  init.genShowListMethod("AdminHost", "-sh", 0, 0);
 
367
  //ResourceQuotaSet
 
368
  init.genAddMethod("ResourceQuotaSet", "-arqs", 0, init.MAX_ARG_VALUE);
 
369
  init.genAddFromFileMethod("ResourceQuotaSet", "-Arqs", 1, 0);
 
370
  init.genModifyFromFileMethod("ResourceQuotaSet", "-Mrqs", 1, 0);
 
371
  init.genShowListMethod("ResourceQuotaSet", "-srqsl", 0, 0);
 
372
  init.genDeleteMethod("ResourceQuotaSet", "-drqs", 1, init.MAX_ARG_VALUE);
 
373
%>
 
374
  <%@include file="java_qconf_cmd.static"%>
 
375
}
 
376