Search in sources :

Example 1 with LsHandler

use of org.jboss.as.cli.handlers.LsHandler in project wildfly-core by wildfly.

the class CommandContextImpl method initCommands.

private void initCommands(boolean bootInvoker) throws CommandLineException, CommandLineParserException {
    // aesh commands
    cmdRegistry.addCommand(new VersionCommand());
    cmdRegistry.addCommand(new HelpCommand(cmdRegistry));
    if (!bootInvoker) {
        cmdRegistry.addCommand(new ConnectCommand());
    }
    DeploymentCommand.registerDeploymentCommands(this, aeshCommands.getRegistry());
    // aesh extensions, for now add grep to make | operator
    // usable.
    cmdRegistry.addThirdPartyCommand(new Grep(), Collections.emptyMap());
    cmdRegistry.registerHandler(new AttachmentHandler(this), "attachment");
    cmdRegistry.registerHandler(new PrefixHandler(), "cd", "cn");
    if (!bootInvoker) {
        cmdRegistry.registerHandler(new ClearScreenHandler(), "clear", "cls");
    }
    cmdRegistry.registerHandler(new CommandCommandHandler(cmdRegistry), "command");
    cmdRegistry.registerHandler(new EchoDMRHandler(), "echo-dmr");
    cmdRegistry.registerHandler(new HistoryHandler(), "history");
    cmdRegistry.registerHandler(new LsHandler(this), "ls");
    cmdRegistry.registerHandler(new ASModuleHandler(this), "module");
    cmdRegistry.registerHandler(new PrintWorkingNodeHandler(), "pwd", "pwn");
    cmdRegistry.registerHandler(new QuitHandler(), "quit", "q", "exit");
    cmdRegistry.registerHandler(new ReadAttributeHandler(this), "read-attribute");
    cmdRegistry.registerHandler(new ReadOperationHandler(this), "read-operation");
    cmdRegistry.registerHandler(new ConnectionInfoHandler(), "connection-info");
    // command-timeout
    cmdRegistry.registerHandler(new CommandTimeoutHandler(), "command-timeout");
    // variables
    cmdRegistry.registerHandler(new SetVariableHandler(), "set");
    cmdRegistry.registerHandler(new EchoVariableHandler(), "echo");
    cmdRegistry.registerHandler(new UnsetVariableHandler(), "unset");
    // deployment
    cmdRegistry.registerHandler(new DeployHandler(this), true, "deploy");
    cmdRegistry.registerHandler(new UndeployHandler(this), true, "undeploy");
    cmdRegistry.registerHandler(new DeploymentInfoHandler(this), true, "deployment-info");
    cmdRegistry.registerHandler(new DeploymentOverlayHandler(this), "deployment-overlay");
    // batch commands
    cmdRegistry.registerHandler(new BatchHandler(this), "batch");
    cmdRegistry.registerHandler(new BatchDiscardHandler(), "discard-batch");
    cmdRegistry.registerHandler(new BatchListHandler(), "list-batch");
    cmdRegistry.registerHandler(new BatchHoldbackHandler(), "holdback-batch");
    cmdRegistry.registerHandler(new BatchRunHandler(this), "run-batch");
    cmdRegistry.registerHandler(new BatchClearHandler(), "clear-batch");
    cmdRegistry.registerHandler(new BatchRemoveLineHandler(), "remove-batch-line");
    cmdRegistry.registerHandler(new BatchMoveLineHandler(), "move-batch-line");
    cmdRegistry.registerHandler(new BatchEditLineHandler(), "edit-batch-line");
    // try-catch
    cmdRegistry.registerHandler(new TryHandler(), "try");
    cmdRegistry.registerHandler(new CatchHandler(), "catch");
    cmdRegistry.registerHandler(new FinallyHandler(), "finally");
    cmdRegistry.registerHandler(new EndTryHandler(), "end-try");
    // if else
    cmdRegistry.registerHandler(new IfHandler(), "if");
    cmdRegistry.registerHandler(new ElseHandler(), "else");
    cmdRegistry.registerHandler(new EndIfHandler(), "end-if");
    // for
    cmdRegistry.registerHandler(new ForHandler(), "for");
    cmdRegistry.registerHandler(new DoneHandler(), "done");
    // data-source
    final DefaultCompleter driverNameCompleter = new DefaultCompleter(JDBCDriverNameProvider.INSTANCE);
    final GenericTypeOperationHandler dsHandler = new GenericTypeOperationHandler(this, "/subsystem=datasources/data-source", null);
    dsHandler.addValueCompleter(Util.DRIVER_NAME, driverNameCompleter);
    // override the add operation with the handler that accepts connection props
    final DataSourceAddCompositeHandler dsAddHandler = new DataSourceAddCompositeHandler(this, "/subsystem=datasources/data-source");
    dsAddHandler.addValueCompleter(Util.DRIVER_NAME, driverNameCompleter);
    dsHandler.addHandler(Util.ADD, dsAddHandler);
    cmdRegistry.registerHandler(dsHandler, dsHandler.getCommandName());
    final GenericTypeOperationHandler xaDsHandler = new GenericTypeOperationHandler(this, "/subsystem=datasources/xa-data-source", null);
    xaDsHandler.addValueCompleter(Util.DRIVER_NAME, driverNameCompleter);
    // override the xa add operation with the handler that accepts xa props
    final XADataSourceAddCompositeHandler xaDsAddHandler = new XADataSourceAddCompositeHandler(this, "/subsystem=datasources/xa-data-source");
    xaDsAddHandler.addValueCompleter(Util.DRIVER_NAME, driverNameCompleter);
    xaDsHandler.addHandler(Util.ADD, xaDsAddHandler);
    cmdRegistry.registerHandler(xaDsHandler, xaDsHandler.getCommandName());
    cmdRegistry.registerHandler(new JDBCDriverInfoHandler(this), "jdbc-driver-info");
    // rollout plan
    final GenericTypeOperationHandler rolloutPlan = new GenericTypeOperationHandler(this, "/management-client-content=rollout-plans/rollout-plan", null);
    rolloutPlan.addValueConverter("content", HeadersArgumentValueConverter.INSTANCE);
    rolloutPlan.addValueCompleter("content", RolloutPlanCompleter.INSTANCE);
    cmdRegistry.registerHandler(rolloutPlan, rolloutPlan.getCommandName());
    // supported but hidden from tab-completion until stable implementation
    cmdRegistry.registerHandler(new ArchiveHandler(this), false, "archive");
    AtomicReference<EmbeddedProcessLaunch> embeddedServerLaunch = null;
    if (!bootInvoker) {
        embeddedServerLaunch = EmbeddedControllerHandlerRegistrar.registerEmbeddedCommands(cmdRegistry, this);
        cmdRegistry.registerHandler(new ReloadHandler(this, embeddedServerLaunch), "reload");
        cmdRegistry.registerHandler(new ShutdownHandler(this, embeddedServerLaunch), "shutdown");
    }
    cmdRegistry.addCommand(new SecurityCommand(this, embeddedServerLaunch));
    if (!bootInvoker) {
        registerExtraHandlers();
    }
    extLoader = new ExtensionsLoader(cmdRegistry, aeshCommands.getRegistry(), this);
}
Also used : ArchiveHandler(org.jboss.as.cli.handlers.ArchiveHandler) ASModuleHandler(org.jboss.as.cli.handlers.module.ASModuleHandler) VersionCommand(org.jboss.as.cli.impl.aesh.cmd.VersionCommand) DeploymentInfoHandler(org.jboss.as.cli.handlers.DeploymentInfoHandler) ElseHandler(org.jboss.as.cli.handlers.ifelse.ElseHandler) DeploymentOverlayHandler(org.jboss.as.cli.handlers.DeploymentOverlayHandler) SecurityCommand(org.jboss.as.cli.impl.aesh.cmd.security.SecurityCommand) BatchHoldbackHandler(org.jboss.as.cli.handlers.batch.BatchHoldbackHandler) DoneHandler(org.jboss.as.cli.handlers.loop.DoneHandler) GenericTypeOperationHandler(org.jboss.as.cli.handlers.GenericTypeOperationHandler) ShutdownHandler(org.jboss.as.cli.handlers.ShutdownHandler) PrefixHandler(org.jboss.as.cli.handlers.PrefixHandler) ReloadHandler(org.jboss.as.cli.handlers.ReloadHandler) EmbeddedProcessLaunch(org.jboss.as.cli.embedded.EmbeddedProcessLaunch) CommandTimeoutHandler(org.jboss.as.cli.handlers.CommandTimeoutHandler) ClearScreenHandler(org.jboss.as.cli.handlers.ClearScreenHandler) XADataSourceAddCompositeHandler(org.jboss.as.cli.handlers.jca.XADataSourceAddCompositeHandler) JDBCDriverInfoHandler(org.jboss.as.cli.handlers.jca.JDBCDriverInfoHandler) EchoVariableHandler(org.jboss.as.cli.handlers.EchoVariableHandler) BatchRemoveLineHandler(org.jboss.as.cli.handlers.batch.BatchRemoveLineHandler) PrintWorkingNodeHandler(org.jboss.as.cli.handlers.PrintWorkingNodeHandler) EchoDMRHandler(org.jboss.as.cli.handlers.EchoDMRHandler) HelpCommand(org.jboss.as.cli.impl.aesh.cmd.HelpCommand) EndTryHandler(org.jboss.as.cli.handlers.trycatch.EndTryHandler) TryHandler(org.jboss.as.cli.handlers.trycatch.TryHandler) EndTryHandler(org.jboss.as.cli.handlers.trycatch.EndTryHandler) ReadAttributeHandler(org.jboss.as.cli.handlers.ReadAttributeHandler) BatchListHandler(org.jboss.as.cli.handlers.batch.BatchListHandler) ReadOperationHandler(org.jboss.as.cli.handlers.ReadOperationHandler) CommandCommandHandler(org.jboss.as.cli.handlers.CommandCommandHandler) XADataSourceAddCompositeHandler(org.jboss.as.cli.handlers.jca.XADataSourceAddCompositeHandler) DataSourceAddCompositeHandler(org.jboss.as.cli.handlers.jca.DataSourceAddCompositeHandler) FinallyHandler(org.jboss.as.cli.handlers.trycatch.FinallyHandler) BatchEditLineHandler(org.jboss.as.cli.handlers.batch.BatchEditLineHandler) CatchHandler(org.jboss.as.cli.handlers.trycatch.CatchHandler) DeployHandler(org.jboss.as.cli.handlers.DeployHandler) QuitHandler(org.jboss.as.cli.handlers.QuitHandler) SetVariableHandler(org.jboss.as.cli.handlers.SetVariableHandler) BatchClearHandler(org.jboss.as.cli.handlers.batch.BatchClearHandler) AttachmentHandler(org.jboss.as.cli.handlers.AttachmentHandler) Grep(org.aesh.extensions.grep.Grep) UndeployHandler(org.jboss.as.cli.handlers.UndeployHandler) BatchRunHandler(org.jboss.as.cli.handlers.batch.BatchRunHandler) LsHandler(org.jboss.as.cli.handlers.LsHandler) BatchHandler(org.jboss.as.cli.handlers.batch.BatchHandler) ConnectionInfoHandler(org.jboss.as.cli.handlers.ConnectionInfoHandler) BatchDiscardHandler(org.jboss.as.cli.handlers.batch.BatchDiscardHandler) EndIfHandler(org.jboss.as.cli.handlers.ifelse.EndIfHandler) HistoryHandler(org.jboss.as.cli.handlers.HistoryHandler) BatchMoveLineHandler(org.jboss.as.cli.handlers.batch.BatchMoveLineHandler) ForHandler(org.jboss.as.cli.handlers.loop.ForHandler) ConnectCommand(org.jboss.as.cli.impl.aesh.cmd.ConnectCommand) UnsetVariableHandler(org.jboss.as.cli.handlers.UnsetVariableHandler) IfHandler(org.jboss.as.cli.handlers.ifelse.IfHandler) EndIfHandler(org.jboss.as.cli.handlers.ifelse.EndIfHandler)

Example 2 with LsHandler

use of org.jboss.as.cli.handlers.LsHandler in project wildfly-core by wildfly.

the class CommandTimeoutHandlerTestCase method testComandExecutor.

@Test
public void testComandExecutor() throws Exception {
    CommandExecutor executor = new CommandExecutor(ctx);
    CommandHandler ls = new LsHandler(ctx);
    ctx.setCommandTimeout(100);
    // Required in order for the ctx to be in sync when calling the handler directly.
    ctx.handle("ls");
    {
        List<Boolean> holder = new ArrayList<>();
        CommandHandlerWrapper wrapper = new CommandHandlerWrapper(ctx, ls, (context) -> {
            holder.add(true);
            TimeoutCommandContext tc = (TimeoutCommandContext) context;
            tc.setLastHandlerTask(null);
            ls.handle(context);
            Future<?> future = tc.getLastTask();
            if (future == null || !future.isDone()) {
                throw new CommandLineException("Future is not done " + future);
            }
        });
        executor.execute(wrapper, 100, TimeUnit.SECONDS);
        if (holder.size() != 1) {
            throw new Exception("Handler not called");
        }
    }
    {
        List<Object> holder = new ArrayList<>();
        CommandHandlerWrapper wrapper = new CommandHandlerWrapper(ctx, ls, (context) -> {
            TimeoutCommandContext tc = (TimeoutCommandContext) context;
            tc.setLastHandlerTask(null);
            try {
                long sleep = TimeoutUtil.adjust(1000);
                Thread.sleep(sleep);
                holder.add(null);
            } catch (InterruptedException ex) {
                holder.add(ex);
                Thread.currentThread().interrupt();
            }
            try {
                ls.handle(context);
                holder.add(null);
            } catch (Exception ex) {
                // Expecting a timeout exception,
                // the task has already been canceled.
                holder.add(ex);
            }
            Future<?> future = tc.getLastTask();
            holder.add(future);
        });
        try {
            executor.execute(wrapper, 100, TimeUnit.MILLISECONDS);
            throw new RuntimeException("Should have failed");
        } catch (TimeoutException ex) {
        // XXX OK expected.
        }
        // Wait for the task to terminate and check the various steps.
        int waitTime = 1000;
        while (holder.size() != 3 && waitTime > 0) {
            Thread.sleep(100);
            waitTime -= 100;
        }
        if (holder.size() != 3) {
            throw new Exception("Task didn't terminate");
        }
        if (holder.get(0) == null) {
            throw new Exception("Task thread not interrupted");
        }
        if (holder.get(1) == null) {
            throw new Exception("Ls has not timeouted");
        }
        if (holder.get(2) != null) {
            throw new Exception("Future task is not null. Steps: " + holder);
        }
    }
}
Also used : ServerController(org.wildfly.core.testrunner.ServerController) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunWith(org.junit.runner.RunWith) TimeoutException(java.util.concurrent.TimeoutException) LsHandler(org.jboss.as.cli.handlers.LsHandler) CliInitializationException(org.jboss.as.cli.CliInitializationException) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) EmptySubsystemParser(org.jboss.as.test.integration.management.extension.EmptySubsystemParser) ExtensionUtils(org.jboss.as.test.integration.management.extension.ExtensionUtils) WildflyTestRunner(org.wildfly.core.testrunner.WildflyTestRunner) Future(java.util.concurrent.Future) CommandExecutor(org.jboss.as.cli.impl.CommandExecutor) After(org.junit.After) CommandArgument(org.jboss.as.cli.CommandArgument) Before(org.junit.Before) CommandHandler(org.jboss.as.cli.CommandHandler) Collection(java.util.Collection) IOException(java.io.IOException) Test(org.junit.Test) BlockerExtension(org.jboss.as.test.integration.management.extension.blocker.BlockerExtension) Util(org.jboss.as.cli.Util) TestSuiteEnvironment(org.jboss.as.test.shared.TestSuiteEnvironment) CommandLineException(org.jboss.as.cli.CommandLineException) TimeUnit(java.util.concurrent.TimeUnit) TimeoutCommandContext(org.jboss.as.cli.impl.CommandExecutor.TimeoutCommandContext) List(java.util.List) CommandContext(org.jboss.as.cli.CommandContext) TimeoutUtil(org.jboss.as.test.shared.TimeoutUtil) ModelNode(org.jboss.dmr.ModelNode) ServerControl(org.wildfly.core.testrunner.ServerControl) CommandContextFactory(org.jboss.as.cli.CommandContextFactory) CommandContextConfiguration(org.jboss.as.cli.impl.CommandContextConfiguration) Assert.assertEquals(org.junit.Assert.assertEquals) CommandExecutor(org.jboss.as.cli.impl.CommandExecutor) CommandHandler(org.jboss.as.cli.CommandHandler) TimeoutCommandContext(org.jboss.as.cli.impl.CommandExecutor.TimeoutCommandContext) CommandLineException(org.jboss.as.cli.CommandLineException) TimeoutException(java.util.concurrent.TimeoutException) CliInitializationException(org.jboss.as.cli.CliInitializationException) IOException(java.io.IOException) CommandLineException(org.jboss.as.cli.CommandLineException) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) LsHandler(org.jboss.as.cli.handlers.LsHandler) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

LsHandler (org.jboss.as.cli.handlers.LsHandler)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 Inject (javax.inject.Inject)1 Grep (org.aesh.extensions.grep.Grep)1 CliInitializationException (org.jboss.as.cli.CliInitializationException)1 CommandArgument (org.jboss.as.cli.CommandArgument)1 CommandContext (org.jboss.as.cli.CommandContext)1 CommandContextFactory (org.jboss.as.cli.CommandContextFactory)1 CommandHandler (org.jboss.as.cli.CommandHandler)1 CommandLineException (org.jboss.as.cli.CommandLineException)1 Util (org.jboss.as.cli.Util)1 EmbeddedProcessLaunch (org.jboss.as.cli.embedded.EmbeddedProcessLaunch)1 ArchiveHandler (org.jboss.as.cli.handlers.ArchiveHandler)1