Search in sources :

Example 1 with CommandInfo

use of org.smartdata.common.command.CommandInfo in project SSM by Intel-bigdata.

the class ClientSmartProtocolServerSideTranslatorPB method listCommandInfo.

@Override
public ListCommandInfoResponseProto listCommandInfo(RpcController controller, ListCommandInfoRequestProto req) throws ServiceException {
    try {
        List<CommandInfo> list = server.listCommandInfo(req.getRuleID(), CommandState.fromValue(req.getCommandState()));
        if (list == null)
            return ListCommandInfoResponseProto.newBuilder().build();
        List<CommandInfoProto> protoList = new ArrayList<>();
        for (CommandInfo info : list) {
            protoList.add(PBHelper.convert(info));
        }
        return ListCommandInfoResponseProto.newBuilder().addAllCommandInfos(protoList).build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : CommandInfo(org.smartdata.common.command.CommandInfo) ServiceException(com.google.protobuf.ServiceException) ArrayList(java.util.ArrayList) CommandInfoProto(org.smartdata.common.protocol.AdminServerProto.CommandInfoProto) IOException(java.io.IOException)

Example 2 with CommandInfo

use of org.smartdata.common.command.CommandInfo in project SSM by Intel-bigdata.

the class SmartAdminProtocolAdminSideTranslatorPB method listCommandInfo.

@Override
public List<CommandInfo> listCommandInfo(long rid, CommandState commandState) throws IOException {
    ListCommandInfoRequestProto req = ListCommandInfoRequestProto.newBuilder().setRuleID(rid).setCommandState(commandState.getValue()).build();
    try {
        List<CommandInfoProto> protoslist = rpcProxy.listCommandInfo(null, req).getCommandInfosList();
        if (protoslist == null)
            return new ArrayList<>();
        List<CommandInfo> list = new ArrayList<>();
        for (CommandInfoProto infoProto : protoslist) {
            list.add(PBHelper.convert(infoProto));
        }
        return list;
    } catch (ServiceException e) {
        throw PBHelper.getRemoteException(e);
    }
}
Also used : CommandInfo(org.smartdata.common.command.CommandInfo) ListCommandInfoRequestProto(org.smartdata.common.protocol.AdminServerProto.ListCommandInfoRequestProto) ServiceException(com.google.protobuf.ServiceException) ArrayList(java.util.ArrayList) CommandInfoProto(org.smartdata.common.protocol.AdminServerProto.CommandInfoProto)

Example 3 with CommandInfo

use of org.smartdata.common.command.CommandInfo in project SSM by Intel-bigdata.

the class TestCommandExecutor method testCommandExecutorHelper.

private void testCommandExecutorHelper() throws Exception {
    DBAdapter dbAdapter = ssm.getDBAdapter();
    String cidCondition = ">= 1 ";
    String ridCondition = ">= 1 ";
    while (true) {
        Thread.sleep(2000);
        int current = ssm.getCommandExecutor().cacheSize();
        System.out.printf("Command Cache size = %d\n ", current);
        if (current == 0) {
            break;
        }
    }
    List<CommandInfo> com = dbAdapter.getCommandsTableItem(cidCondition, ridCondition, CommandState.DONE);
    System.out.printf("Size = %d\n", com.size());
    // Check Status
    Assert.assertTrue(com.size() == 1);
    Assert.assertTrue(com.get(0).getState() == CommandState.DONE);
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) CommandInfo(org.smartdata.common.command.CommandInfo)

Example 4 with CommandInfo

use of org.smartdata.common.command.CommandInfo in project SSM by Intel-bigdata.

the class TestDBMethod method testInsertCommandsTable.

@Test
public void testInsertCommandsTable() throws Exception {
    String dbFile = TestDBUtil.getUniqueDBFilePath();
    Connection conn = null;
    try {
        conn = Util.createSqliteConnection(dbFile);
        Util.initializeDataBase(conn);
        DBAdapter dbAdapter = new DBAdapter(conn);
        CommandInfo command1 = new CommandInfo(0, 1, ActionType.None, CommandState.EXECUTING, "test", 123123333l, 232444444l);
        CommandInfo command2 = new CommandInfo(0, 78, ActionType.ConvertToEC, CommandState.PAUSED, "tt", 123178333l, 232444994l);
        CommandInfo[] commands = { command1, command2 };
        dbAdapter.insertCommandsTable(commands);
        String cidCondition = ">= 2 ";
        String ridCondition = "= 78 ";
        CommandState state = null;
        CommandState state1 = CommandState.PAUSED;
        List<CommandInfo> com = dbAdapter.getCommandsTableItem(cidCondition, ridCondition, state);
        Assert.assertTrue(com.get(0).getActionType() == ActionType.ConvertToEC);
        Assert.assertTrue(com.get(0).getState() == CommandState.PAUSED);
        List<CommandInfo> com1 = dbAdapter.getCommandsTableItem(null, null, state1);
        Assert.assertTrue(com1.get(0).getState() == CommandState.PAUSED);
    } finally {
        if (conn != null) {
            conn.close();
        }
        File file = new File(dbFile);
        file.deleteOnExit();
    }
}
Also used : CommandInfo(org.smartdata.common.command.CommandInfo) Connection(java.sql.Connection) CommandState(org.smartdata.common.CommandState) File(java.io.File) Test(org.junit.Test)

Example 5 with CommandInfo

use of org.smartdata.common.command.CommandInfo in project SSM by Intel-bigdata.

the class TestDBMethod method testUpdateCommand.

@Test
public void testUpdateCommand() throws Exception {
    String dbFile = TestDBUtil.getUniqueDBFilePath();
    Connection conn = null;
    try {
        conn = Util.createSqliteConnection(dbFile);
        Util.initializeDataBase(conn);
        DBAdapter dbAdapter = new DBAdapter(conn);
        CommandInfo command1 = new CommandInfo(0, 1, ActionType.None, CommandState.PENDING, "test", 123123333l, 232444444l);
        CommandInfo command2 = new CommandInfo(0, 78, ActionType.ConvertToEC, CommandState.PENDING, "tt", 123178333l, 232444994l);
        CommandInfo[] commands = { command1, command2 };
        dbAdapter.insertCommandsTable(commands);
        String cidCondition = ">= 1 ";
        String ridCondition = "= 78 ";
        List<CommandInfo> com = dbAdapter.getCommandsTableItem(cidCondition, ridCondition, CommandState.PENDING);
        for (CommandInfo cmd : com) {
            // System.out.printf("Cid = %d \n", cmd.getCid());
            dbAdapter.updateCommandStatus(cmd.getCid(), cmd.getRid(), CommandState.DONE);
        }
        List<CommandInfo> com1 = dbAdapter.getCommandsTableItem(cidCondition, ridCondition, CommandState.DONE);
        Assert.assertTrue(com1.size() == 1);
        Assert.assertTrue(com1.get(0).getState() == CommandState.DONE);
    } finally {
        if (conn != null) {
            conn.close();
        }
        File file = new File(dbFile);
        file.deleteOnExit();
    }
}
Also used : CommandInfo(org.smartdata.common.command.CommandInfo) Connection(java.sql.Connection) File(java.io.File) Test(org.junit.Test)

Aggregations

CommandInfo (org.smartdata.common.command.CommandInfo)14 IOException (java.io.IOException)3 Test (org.junit.Test)3 ServiceException (com.google.protobuf.ServiceException)2 File (java.io.File)2 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 CommandInfoProto (org.smartdata.common.protocol.AdminServerProto.CommandInfoProto)2 DBAdapter (org.smartdata.server.metastore.DBAdapter)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 CommandState (org.smartdata.common.CommandState)1 ListCommandInfoRequestProto (org.smartdata.common.protocol.AdminServerProto.ListCommandInfoRequestProto)1