Search in sources :

Example 1 with Command

use of act.cli.Command in project actframework by actframework.

the class RouterAdmin method listRoutes.

@Command(name = "act.route.list, act.route.print", help = "list routes")
@PropertySpec("method,path,compactHandler")
public Object listRoutes(@Optional("list routes in tree view") boolean tree, @Optional("specify the port name") String name, @Optional("specify route filter") String q) {
    final Router router = S.blank(name) ? app.router() : app.router(name);
    if (S.notBlank(q)) {
        if (q.contains(".") || q.contains("[") || q.contains("*")) {
        // already regex
        } else {
            // make it a regex
            q = ".*" + q + ".*";
        }
    }
    if (tree) {
        TreeNode root = new TreeNode() {

            @Override
            public String id() {
                return "root";
            }

            @Override
            public String label() {
                return "Router";
            }

            @Override
            public List<TreeNode> children() {
                List<TreeNode> l = new ArrayList<>();
                l.add(router._GET);
                l.add(router._POST);
                l.add(router._PUT);
                l.add(router._DEL);
                return l;
            }
        };
        return S.blank(q) ? root : new FilteredTreeNode(root, TreeNodeFilter.Common.pathMatches(q));
    } else {
        return routeInfoList(name, q);
    }
}
Also used : FilteredTreeNode(act.cli.tree.FilteredTreeNode) TreeNode(act.cli.tree.TreeNode) ArrayList(java.util.ArrayList) FilteredTreeNode(act.cli.tree.FilteredTreeNode) PropertySpec(act.util.PropertySpec) Command(act.cli.Command)

Example 2 with Command

use of act.cli.Command in project actframework by actframework.

the class LogAdmin method setLogLevel.

@Command(name = "act.log.level.update", help = "Update LOGGER level. Valid levels are:\n\t" + "5 - fatal\n\t" + "4 - error\n\t" + "3 - warn\n\t" + "2 - info\n\t" + "1 - debug\n\t" + "0 - trace")
public String setLogLevel(@Required("specify LOGGER name") String name, @Required("specify log level") int level) {
    Level lvl = convert(level);
    Logger logger = LogManager.get(name);
    logger.setLevel(lvl);
    return S.fmt("LOGGER[%s] level set to %s", name, lvl.toString());
}
Also used : Level(org.osgl.logging.Logger.Level) Logger(org.osgl.logging.Logger) Command(act.cli.Command)

Example 3 with Command

use of act.cli.Command in project actframework by actframework.

the class DaemonAdmin method status.

@Command(name = "act.daemon.status", help = "Report app daemon status")
public void status(@Required("specify daemon id") String id, CliContext context, @Provided JodaDateTimeCodec fmt) {
    Daemon daemon = get(id, context);
    Daemon.State state = daemon.state();
    DateTime ts = daemon.timestamp();
    Exception lastError = daemon.lastError();
    context.println("Daemon[%s]: %s at %s", id, state, fmt.toString(ts));
    if (null != lastError) {
        DateTime errTs = daemon.errorTimestamp();
        if (null != errTs) {
            context.println("Last error: %s at %s", E.stackTrace(lastError), fmt.toString(errTs));
        } else {
            context.println("Last error: %s", E.stackTrace(lastError));
        }
    }
    Map<String, Object> attributes = daemon.getAttributes();
    if (!attributes.isEmpty()) {
        context.println("Attributes: %s", attributes);
    }
}
Also used : DateTime(org.joda.time.DateTime) Command(act.cli.Command)

Aggregations

Command (act.cli.Command)3 FilteredTreeNode (act.cli.tree.FilteredTreeNode)1 TreeNode (act.cli.tree.TreeNode)1 PropertySpec (act.util.PropertySpec)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 Logger (org.osgl.logging.Logger)1 Level (org.osgl.logging.Logger.Level)1