1 23 24 77 78 package org.apache.tools.ant.taskdefs.optional.sun.appserv; 79 80 import org.apache.tools.ant.Project; 81 import org.apache.tools.ant.BuildException; 82 83 import java.util.Map ; 84 import java.util.HashMap ; 85 86 105 public class InstanceTask extends AppServerAdmin { 106 private String action = null; 107 108 112 private static final String ACTION_START = "start"; 113 private static final String ACTION_STOP = "stop"; 114 private static final String ACTION_RESTART = "restart"; 115 private static final String ACTION_CREATE = "create"; 116 private static final String ACTION_DELETE = "delete"; 117 118 private static final Map ACTION_MAP = new HashMap (5); 119 static { 120 ACTION_MAP.put(ACTION_START, "start-instance"); 121 ACTION_MAP.put(ACTION_STOP, "stop-instance"); 122 ACTION_MAP.put(ACTION_RESTART, "restart-instance"); 123 ACTION_MAP.put(ACTION_CREATE, "create-instance"); 124 ACTION_MAP.put(ACTION_DELETE, "delete-instance"); 125 }; 126 127 LocalStringsManager lsm = new LocalStringsManager(); 128 129 130 135 public void setAction(String action) { 136 this.action = action; 137 } 138 139 protected Server getNewServer() { 140 return new InstanceServer(server); 141 } 142 143 149 public void setNodeagent(String nodeagent) { 150 ((InstanceServer)server).setNodeagent(nodeagent); } 152 153 159 public void setProperty(String property) { 160 ((InstanceServer)server).setProperty(property); } 162 163 169 public void setConfig(String config) { 170 ((InstanceServer)server).setConfig(config); } 172 173 179 public void setCluster(String cluster) { 180 ((InstanceServer)server).setCluster(cluster); } 182 183 190 public void setDebug(boolean debug) { 191 final String msg = lsm.getString("AttributeNotSupported", 192 new Object [] {"debug"}); 193 log(msg, Project.MSG_WARN); 194 } 196 197 204 public void setLocal(boolean local) { 205 final String msg = lsm.getString("AttributeNotSupported", 206 new Object [] {"local"}); 207 log(msg, Project.MSG_WARN); 208 } 210 211 218 public void setDomain(String domain) { 219 final String msg = lsm.getString("AttributeNotSupported", 220 new Object [] {"domain"}); 221 log(msg, Project.MSG_WARN); 222 } 224 225 230 public void setInstanceport(int instanceport) { 231 final String msg = lsm.getString("AttributeNotSupported", 232 new Object [] {"instanceport"}); 233 log(msg, Project.MSG_WARN); 234 } 236 237 protected void checkConfiguration() throws BuildException { 238 if (action == null) { 239 final String msg = lsm.getString("ActionCommandMustBeSpecified"); 240 throw new BuildException(msg, getLocation()); 241 } 242 243 if (!ACTION_MAP.containsKey(action)) { 244 final String msg = lsm.getString("InvalidActionCommand", new Object [] {action}); 245 throw new BuildException(msg, getLocation()); 246 } 247 super.checkConfiguration(); 248 } 249 250 protected void checkConfiguration(Server aServer) throws BuildException { 251 if (aServer.getInstance() == null) { 252 final String msg = lsm.getString("InstanceAttributeRequired"); 253 throw new BuildException(msg, getLocation()); 254 } 255 InstanceServer instanceSvr = (InstanceServer) aServer; 256 286 if (!instanceSvr.hasPassword()) { 287 final String msg = lsm.getString("PasswordAttributeNotSpecified"); 288 throw new BuildException(msg, getLocation()); 289 } 290 if (action.equals(ACTION_CREATE)) { 291 if (instanceSvr.getNodeagent() == null) { 292 final String msg = lsm.getString("AttributeMustBeSpecified", new Object [] {"nodeagent"}); 293 throw new BuildException(msg, getLocation()); 294 } 295 } 296 } 297 298 protected void execute(Server aServer) throws BuildException { 299 InstanceServer instanceSvr = (InstanceServer) aServer; 300 301 if ( instanceSvr.getConfig() != null && 302 instanceSvr.getCluster() != null ) { 303 final String msg = lsm.getString("MutuallyExclusivelyAttribute", 304 new Object [] {"config", "cluster"}); 305 throw new BuildException(msg, getLocation()); 306 } 307 308 StringBuffer cmd = new StringBuffer ((String ) ACTION_MAP.get(action)); 309 cmd.append(instanceSvr.getCommandParameters(false)); 310 if (action.equals(ACTION_CREATE)) { 311 cmd.append(" --nodeagent " + instanceSvr.getNodeagent()); 313 if (instanceSvr.getConfig() != null) 314 cmd.append(" --config " + instanceSvr.getConfig()); 315 if (instanceSvr.getCluster() != null) 316 cmd.append(" --cluster " + instanceSvr.getCluster()); 317 if (instanceSvr.getProperty() != null) 318 cmd.append(" --property " + instanceSvr.getProperty()); 319 } else if (action.equals(ACTION_START)) { 320 } 322 332 cmd.append(' ').append(instanceSvr.getInstance()); 333 334 execAdminCommand(cmd.toString()); 335 336 346 } 347 348 356 public class InstanceServer extends Server { 357 private boolean debug; private boolean local; private String domain; private int instanceport; private String nodeagent; private String config; private String cluster; private String property; 366 372 private boolean debugIsSet = false; 373 private boolean localIsSet = false; 374 375 private static final boolean DEFAULT_DEBUG = false; 376 private static final boolean DEFAULT_LOCAL = false; 377 378 382 public InstanceServer() { 383 this(null); 384 } 385 386 392 public InstanceServer(Server theParent) { 393 super(theParent); 394 } 395 396 403 public void setDebug(boolean debug) { 404 this.debug = debug; 405 debugIsSet = true; } 407 408 414 protected boolean isDebug() { 415 InstanceServer theParent = (InstanceServer) getParent(); 416 if (!debugIsSet) { 417 return (theParent == null) ? DEFAULT_DEBUG : theParent.isDebug(); 418 } 419 return debug; 420 } 421 422 429 public void setLocal(boolean local) { 430 this.local = local; 431 localIsSet = true; } 433 434 441 protected boolean isLocal() { 442 InstanceServer theParent = (InstanceServer) getParent(); 443 if (!localIsSet) { 444 return (theParent == null) ? DEFAULT_LOCAL : theParent.isLocal(); 445 } 446 return local; 447 } 448 449 456 public void setDomain(String domain) { 457 this.domain = domain; 458 } 459 460 465 protected String getDomain() { 466 InstanceServer theParent = (InstanceServer) getParent(); 467 if (domain == null) { 468 return (theParent == null) ? null : theParent.getDomain(); 469 } 470 return domain; 471 } 472 473 479 public void setInstanceport(int instanceport) { 480 this.instanceport = instanceport; 481 } 482 483 489 protected int getInstanceport() { 490 InstanceServer theParent = (InstanceServer) getParent(); 491 if ((instanceport == 0) && (theParent != null)) { 492 return theParent.getInstanceport(); 493 } 494 return instanceport; 495 } 496 497 503 public void setNodeagent(String nodeagent) { 504 this.nodeagent = nodeagent; 505 } 506 507 513 protected String getNodeagent() { 514 InstanceServer theParent = (InstanceServer) getParent(); 515 return nodeagent; 516 } 517 518 524 public void setCluster(String cluster) { 525 this.cluster = cluster; 526 } 527 528 534 protected String getCluster() { 535 InstanceServer theParent = (InstanceServer) getParent(); 536 return cluster; 537 } 538 544 public void setConfig(String config) { 545 this.config = config; 546 } 547 548 554 protected String getConfig() { 555 return config; 556 } 557 563 public void setProperty(String property) { 564 this.property = property; 565 } 566 567 573 protected String getProperty() { 574 return property; 575 } 576 } 577 } 578 | Popular Tags |