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);
}
}
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);
}
}
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);
}
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();
}
}
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();
}
}
Aggregations