public CommandResult runCommand(String cmd, String... args) { return getCommandRunner().run(cmd, args); }
String command = "list-jdbc-resources"; CommandRunner commandRunner = glassfish.getCommandRunner(); CommandResult commandResult = commandRunner.run(command); System.out.println("jdbc resources=" + commandResult.getOutput()); Logger.getLogger(this.getClass().getName()).log(Level.INFO,"jdbc resources=" +commandResult.getOutput());
@Resource(mappedName = "org.glassfish.embeddable.CommandRunner") CommandRunner commandRunner; public void configureLoginRealm() { CommandResult commandResult = commandRunner.run("create-auth-realm", "--classname=com.blah.blah.SecureJDBCRealm", "--property=jaas-context= secureJDBCRealm", "secure-JDBC-realm"); log.debug(commandResult.getExitStatus().toString() + " " + commandResult.getOutput()); Throwable throwable = commandResult.getFailureCause(); if (throwable != null) { log.error(throwable.getMessage(), throwable); } }
@Override public void configure(Properties props) throws GlassFishException { CommandRunner commandRunner = null; for (Object obj : props.keySet()) { String key = (String) obj; if (key.startsWith(CONFIG_PROP_PREFIX)) { if (commandRunner == null) { // only create the CommandRunner if needed commandRunner = habitat.getService(CommandRunner.class); } CommandResult result = commandRunner.run("set", key.substring(CONFIG_PROP_PREFIX.length()) + "=" + props.getProperty(key)); if (result.getExitStatus() != CommandResult.ExitStatus.SUCCESS) { throw new GlassFishException(result.getOutput()); } } } } }
@Override public void configure(Properties props) throws GlassFishException { CommandRunner commandRunner = null; for (Object obj : props.keySet()) { String key = (String) obj; if (key.startsWith(CONFIG_PROP_PREFIX)) { if (commandRunner == null) { // only create the CommandRunner if needed commandRunner = habitat.getService(CommandRunner.class); } CommandResult result = commandRunner.run("set", key.substring(CONFIG_PROP_PREFIX.length()) + "=" + props.getProperty(key)); if (result.getExitStatus() != CommandResult.ExitStatus.SUCCESS) { throw new GlassFishException(result.getOutput()); } } } } }
private String executeCommand(String command, String... parameterList) throws Throwable { CommandRunner runner = glassfish.getCommandRunner(); CommandResult result = runner.run(command, parameterList); String output = null; switch (result.getExitStatus()) { case FAILURE: case WARNING: throw result.getFailureCause(); case SUCCESS: output = result.getOutput(); log.info("command " + command + " parameters" + parameterList + " result: " + output); break; } return output; }
public void removeVirtualCluster(String virtualClusterName) { try { VirtualCluster virtualCluster = virtualClusters.byName(virtualClusterName); if (virtualCluster != null) { virtualClusters.remove(virtualCluster); // removes config. } } catch (Exception ex) { logger.log(Level.WARNING,localStrings.getString("exception.while.remove.cluster",ex.getLocalizedMessage()),ex); } /* stop-cluster is deliberately commented. invoking stop-cluster causes the re-deploy to fail next time (due to IMS layer fails to create virtual-machine config). But since all the instances in the cluster are already stopped we don't really need to call stop-cluster. CommandResult commandResult = commandRunner.run("stop-cluster", virtualClusterName); Throwable failureCause = commandResult.getFailureCause(); if (failureCause != null) { logger.log(Level.WARNING, failureCause.getLocalizedMessage(), failureCause); } */ CommandResult commandResult = commandRunner.run("delete-cluster", virtualClusterName); Object args[]=new Object[]{virtualClusterName,commandResult.getOutput()}; logger.log(Level.INFO,"delete.cluster.exec.output",args); Throwable failureCause = commandResult.getFailureCause(); if (failureCause != null) { args[0]= failureCause.getLocalizedMessage(); args[1]=failureCause; logger.log(Level.WARNING,localStrings.getString("failure.cause",args[0]),args[1]); } }
CommandResult result = cmdRunner.run(tokens[0], Arrays.copyOfRange(tokens, 1, tokens.length)); System.out.println(result.getExitStatus()); System.out.println(result.getOutput());
CommandResult result = cmdRunner.run(tokens[0], Arrays.copyOfRange(tokens, 1, tokens.length)); System.out.println(result.getExitStatus()); System.out.println(result.getOutput());
CommandResult result = commandRunner.run("create-cluster", virtualClusterName); Object args[]=new Object[]{virtualClusterName,result.getOutput()}; logger.log(Level.INFO,"create.cluster.exec.output",args);
CommandResult result = commandRunner.run("delete-cluster", virtualClusterName); Object[] args = new Object[] {virtualClusterName,result.getOutput()}; logger.log(Level.FINEST,localStrings.getString("delete.cluster.exec.output",args));