Package com.bj58.spat.gaea.server.performance

Examples of com.bj58.spat.gaea.server.performance.Command


public class ExecTest {

  @Test
  public void testCreateCommand() {
    Exec exec = new Exec();
    Command command1 = exec.createCommand("exec|netstat -na");
    assertEquals(CommandType.Exec, command1.getCommandType());
    assertEquals("netstat -na", command1.getCommand());
   
    Command command2 = exec.createCommand("exec|killall java");
    assertEquals(CommandType.Illegal, command2.getCommandType());
  }
View Full Code Here


  @Override
  public Command createCommand(String commandStr) {
    if(commandStr != null && !commandStr.equalsIgnoreCase("")) {
      if(commandStr.equalsIgnoreCase("quit")) {
        Command entity = new Command();
        entity.setCommandType(CommandType.Quit);
        return entity;
      }
    }
    return null;
  }
View Full Code Here

    if (commandStr != null && !commandStr.equalsIgnoreCase("")) {
      String[] args = commandStr.split("\\|");
      if (args[0].trim().equalsIgnoreCase("exec")) {
        String execStr = commandStr.replaceFirst("exec\\|", "");
        if (execStr.startsWith("netstat") || execStr.startsWith("top")) {
          Command entity = new Command();
          entity.setCommandType(CommandType.Exec);
          if(execStr.equalsIgnoreCase("top")){
            entity.setCommand("top -bn 1");
          } else if(execStr.equalsIgnoreCase("netstat")){
            entity.setCommand(execStr);
          }
          return entity;
        }
      }
    }
View Full Code Here

  @Override
  public Command createCommand(String commandStr) {
    if(commandStr != null && !commandStr.equalsIgnoreCase("")) {
      String[] args = commandStr.split("\\|");
      if(args[0].trim().equalsIgnoreCase("count")) {
        Command entity = new Command();
        entity.setCommandType(CommandType.Count);
        entity.setSecond(1);
        entity.setMethod("#all#");
        if(args.length > 1) {
          for(int i=1; i<args.length; i++) {
            if(args[i].trim().startsWith("second")) {
              entity.setSecond(Integer.parseInt(args[i].trim().replaceFirst("second ", "").trim()));
            } else if(args[i].trim().startsWith("method")) {
              entity.setMethod(args[i].trim().replaceFirst("method ", "").trim());
            }
          }
        }
        return entity;
      }
View Full Code Here

public class CRLF extends CommandHelperBase {

  @Override
  public Command createCommand(String commandStr) {
    if(commandStr == null || commandStr.equalsIgnoreCase("")) {
      Command entity = new Command();
      entity.setCommandType(CommandType.CRLF);
      return entity;
    }
    return null;
  }
View Full Code Here

*/
public class Illegal implements ICommandHelper {

  @Override
  public Command createCommand(String commandStr) {
    Command entity = new Command();
    entity.setCommandType(CommandType.Illegal);
    return entity;
  }
View Full Code Here

      String[] args = commandStr.split("\\|");
      if(args[0].trim().equalsIgnoreCase("time")) {
        List<String> grepList = new ArrayList<String>();
        List<ShowColumn> scList = new ArrayList<ShowColumn>();
       
        Command entity = new Command();
        scList.add(ShowColumn.All);
        entity.setCommandType(CommandType.Time);
       
        for(int i=1; i<args.length; i++) {
          if(args[i].trim().startsWith("grep")) {
            grepList.add(args[i].trim().replaceFirst("grep ", "").trim());
          } else if(args[i].trim().startsWith("group")) {
            entity.setGroup(Integer.parseInt(args[i].trim().replaceFirst("group ", "").trim()));
          } else if(args[i].trim().startsWith("column")) {
            scList.clear();
            String cs = args[i].trim().replaceFirst("column -", "");
            if(cs.indexOf("a") >= 0) {
              if(!scList.contains(ShowColumn.All)) {
                scList.add(ShowColumn.All);
              }
            } else {
              String[] csAry = cs.split("");
              for(String item : csAry) {
                if(item.equalsIgnoreCase("t")) {
                  if(!scList.contains(ShowColumn.Time)) {
                    scList.add(ShowColumn.Time);
                  }
                } else if(item.equalsIgnoreCase("k")) {
                  if(!scList.contains(ShowColumn.Key)) {
                    scList.add(ShowColumn.Key);
                  }
                } else if(item.equalsIgnoreCase("d")) {
                  if(!scList.contains(ShowColumn.Description)) {
                    scList.add(ShowColumn.Description);
                  }
                }
              }
            }
          }
        }
        entity.setGrep(grepList);
        entity.setColumnList(scList);
        return entity;
      }
    }
    return null;
  }
View Full Code Here

  @Override
  public Command createCommand(String commandStr) {
    if(commandStr != null && !commandStr.equalsIgnoreCase("")) {
      if(commandStr.equalsIgnoreCase("help")) {
        Command entity = new Command();
        entity.setCommandType(CommandType.Help);
        return entity;
      }
    }
    return null;
  }
View Full Code Here

  @Override
  public Command createCommand(String commandStr) {
    if(commandStr != null && !commandStr.equalsIgnoreCase("")) {
      if(commandStr.equalsIgnoreCase("control")) {
        Command entity = new Command();
        entity.setCommandType(CommandType.Control);
        return entity;
      }
    }
    return null;
  }
View Full Code Here

public class CommandTest {

  @Test
  public void testGetCommandString() {
    Command command1 = Command.create("time|grep abc|group 10|column -kd");
    assertEquals(CommandType.Time, command1.getCommandType());
    assertEquals("abc", command1.getGrep().get(0));
    assertEquals(ShowColumn.Key, command1.getColumnList().get(0));
    assertEquals(ShowColumn.Description, command1.getColumnList().get(1));
    assertEquals(2, command1.getColumnList().size());
    assertEquals(10, command1.getGroup());
   
   
    Command command2 = Command.create("exec|netstat -na");
    assertEquals(CommandType.Exec, command2.getCommandType());
    assertEquals("netstat -na", command2.getCommand());
   
   
    Command command3 = Command.create("time|grep abc");
    assertEquals(CommandType.Time, command3.getCommandType());
    assertEquals("abc", command3.getGrep().get(0));
    assertEquals(ShowColumn.All, command3.getColumnList().get(0));
    assertEquals(1, command3.getColumnList().size());
    assertEquals(0, command3.getGroup());
   
   
    Command command4 = Command.create("count");
    assertEquals(CommandType.Count, command4.getCommandType());
    assertEquals("#all#", command4.getMethod());
    assertEquals(1, command4.getSecond());
  }
View Full Code Here

TOP

Related Classes of com.bj58.spat.gaea.server.performance.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.