1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
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
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.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
33
* Generated from java_jmx_jgdi.jsp
34
* !!! DO NOT EDIT THIS FILE !!!
40
* Helper class to initialize option Map.
43
java.util.Map<String, String> nameToOpt = new java.util.HashMap<String, String>();
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;
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");
61
java.util.Map<String, String> getMap() {
65
public void genDefaultMethodsForType(String type) {
66
if (!nameToOpt.containsKey(type)) {
67
throw new IllegalStateException("<QConfCommand> failed: Unknown option type "+type);
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);
79
void genAddMethod(String objectType, String optionString, int mandatory, int optional) {
82
* Implements qconf <%=optionString%> option
83
* @param oi <b>OptionInfo</b> option enviroment object
84
* @throws JGDIException on any error on the GDI layer
86
@OptionAnnotation(value = "<%=optionString%>", min = <%=mandatory%>, extra = <%=optional%>)
87
public void add<%=objectType%>(final OptionInfo oi) throws JGDIException {
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);
96
String userTypedText = runEditor(GEObjectEditor.getConfigurablePropertiesAsText(obj));
98
if (userTypedText != null) {
99
GEObjectEditor.updateObjectWithText(jgdi, obj, userTypedText);
100
jgdi.add<%=objectType%>WithAnswer(obj, answer);
101
printAnswers(answer);
107
void genAddFromFileMethod(String objectType, String optionString, int mandatory, int optional) {
110
* Implements qconf <%=optionString%> option
111
* @param oi <b>OptionInfo</b> option enviroment object
112
* @throws JGDIException on any error on the GDI layer
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);
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();
125
final String keyAttrValue = getKeyAttributeValueFromString(err, "<%=objectType%>", fileName, inputText);
127
if (keyAttrValue == null) {
130
obj.setName(keyAttrValue);
131
GEObjectEditor.updateObjectWithText(jgdi, obj, inputText);
132
jgdi.add<%=objectType%>WithAnswer(obj, answer);
133
printAnswers(answer);
136
} //end genAddFromFileMethod
138
void genModifyMethod(String objectType, String optionString, int mandatory, int optional) {
141
* Implements qconf <%=optionString%> option
142
* @param oi <b>OptionInfo</b> option enviroment object
143
* @throws JGDIException on any error on the GDI layer
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);
152
<%=objectType%> obj = jgdi.get<%=objectType%>WithAnswer(arg, answer);
155
//clear the answers from the get request
157
String userTypedText = runEditor(GEObjectEditor.getConfigurablePropertiesAsText(obj));
158
if (userTypedText != null) {
159
GEObjectEditor.updateObjectWithText(jgdi, obj, userTypedText);
160
jgdi.update<%=objectType%>WithAnswer(obj, answer);
162
printAnswers(answer);
164
err.println(getErrorMessage("InvalidObjectArgument", oi.getOd().getOption(), arg));
165
setExitCode(getCustomExitCode("InvalidObjectArgument", oi.getOd().getOption()));
170
} //end genModifyMethod
172
void genModifyFromFileMethod(String objectType, String optionString, int mandatory, int optional) {
175
* Implements qconf <%=optionString%> option
176
* @param oi <b>OptionInfo</b> option enviroment object
177
* @throws JGDIException on any error on the GDI layer
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);
184
List<JGDIAnswer> answer = new LinkedList<JGDIAnswer>();
185
String inputText = readFile(oi);
187
<%if (objectType.equals("SchedConf")) {%>
188
obj = jgdi.getSchedConfWithAnswer(answer);
190
final String keyAttrValue = getKeyAttributeValueFromString(err, "<%=objectType%>", fileName, inputText);
191
if (keyAttrValue == null) {
194
obj = jgdi.get<%=objectType%>WithAnswer(keyAttrValue, answer);
196
printAnswers(answer);
199
GEObjectEditor.updateObjectWithText(jgdi, obj, inputText);
200
jgdi.update<%=objectType%>WithAnswer(obj, answer);
201
printAnswers(answer);
203
//TODO LP: Check this is ever displayed
204
<%if (objectType.equals("SchedConf")) {%>
205
err.println(getErrorMessage("InvalidObjectArgument", oi.getOd().getOption()));
207
err.println(getErrorMessage("InvalidObjectArgument", oi.getOd().getOption(), keyAttrValue));
209
setExitCode(getCustomExitCode("InvalidObjectArgument", oi.getOd().getOption()));
213
} //end genModifyFromFileMethod
215
void genShowMethod(String objectType, String optionString, int mandatory, int optional) {
218
* Implements qconf <%=optionString%> option
219
* @param oi <b>OptionInfo</b> option enviroment object
220
* @throws JGDIException on any error on the GDI layer
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);
229
<%=objectType%> obj = jgdi.get<%=objectType%>WithAnswer(arg, answer);
231
printAnswers(answer);
232
//Display error message in no such object exists
234
err.println(getErrorMessage("InvalidObjectArgument", oi.getOd().getOption(), arg));
235
setExitCode(getCustomExitCode("InvalidObjectArgument", oi.getOd().getOption()));
239
String text = GEObjectEditor.getAllPropertiesAsText(obj);
243
} //end genShowMethod
245
void genShowListMethod(String objectType, String optionString, int mandatory, int optional) {
248
* Implements qconf <%=optionString%> option
249
* @param oi <b>OptionInfo</b> option enviroment object
250
* @throws JGDIException on any error on the GDI layer
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());
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");
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()));
273
//Otherwise print sorted list
274
Collections.sort(values);
275
for (String val : values) {
281
} //end genShowListMethod
283
void genDeleteMethod(String objectType, String optionString, int mandatory, int optional) {
286
* Implements qconf <%=optionString%> option
287
* @param oi <b>OptionInfo</b> option enviroment object
288
* @throws JGDIException on any error on the GDI layer
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]);
296
jgdi.delete<%=objectType%>sWithAnswer(vals, answers);
297
printAnswers(answers);
300
} //end genDeleteMethod
302
} //end Class MapInit
305
// ---------------------------------------------------------------------------
306
// Build Generator instances
307
// ---------------------------------------------------------------------------
308
MapInit init = new MapInit();
310
package com.sun.grid.jgdi.util.shell;
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;
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;
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
336
public abstract class QConfCommandGenerated extends AnnotatedCommand {
339
<% for (String objType : init.getMap().keySet()) {
340
init.genDefaultMethodsForType(objType);
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);
350
init.genModifyMethod("SchedConf","-msconf", 0, 0);
351
init.genModifyFromFileMethod("SchedConf", "-Msconf", 1, 0);
352
init.genShowMethod("SchedConf", "-ssconf",0, 0);
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);
360
init.genShowListMethod("Operator", "-so", 0, 0);
362
init.genShowListMethod("Manager", "-sm", 0, 0);
364
init.genShowListMethod("SubmitHost", "-ss", 0, 0);
366
init.genShowListMethod("AdminHost", "-sh", 0, 0);
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);
374
<%@include file="java_qconf_cmd.static"%>