use of org.smartdata.common.command.CommandInfo in project SSM by Intel-bigdata.
the class TestCommandExecutor method generateTestCases.
private void generateTestCases() throws Exception {
DBAdapter dbAdapter = ssm.getDBAdapter();
CommandDescriptor commandDescriptor = generateCommandDescriptor();
CommandInfo commandInfo = new CommandInfo(0, commandDescriptor.getRuleId(), ActionType.CacheFile, CommandState.PENDING, commandDescriptor.getCommandString(), 123178333l, 232444994l);
CommandInfo[] commands = { commandInfo };
dbAdapter.insertCommandsTable(commands);
}
use of org.smartdata.common.command.CommandInfo in project SSM by Intel-bigdata.
the class CommandExecutor method schedule.
/**
* Get command to for execution.
*
* @return
*/
private synchronized Command schedule() throws IOException {
// currently FIFO
// List<Long> cmds = getCommands(CommandState.PENDING);
Set<Long> cmdsPending = cmdsInState.get(CommandState.PENDING.getValue());
Set<Long> cmdsExecuting = cmdsInState.get(CommandState.EXECUTING.getValue());
if (cmdsPending.size() == 0) {
// Put them into cmdsAll and cmdsInState
if (statusCache.size() != 0) {
batchCommandStatusUpdate();
}
List<CommandInfo> dbcmds = getPendingCommandsFromDB();
if (dbcmds == null) {
return null;
}
for (CommandInfo c : dbcmds) {
// if command alread in update cache or queue then skip
if (cmdsAll.containsKey(c.getCid())) {
continue;
}
cmdsAll.put(c.getCid(), c);
cmdsPending.add(c.getCid());
}
if (cmdsPending.size() == 0) {
return null;
}
}
// TODO Replace FIFO
// Currently only get and run the first cmd
long curr = cmdsPending.iterator().next();
Command ret = getCommandFromCmdInfo(cmdsAll.get(curr));
cmdsPending.remove(curr);
cmdsExecuting.add(curr);
ret.setState(CommandState.EXECUTING);
return ret;
}
use of org.smartdata.common.command.CommandInfo in project SSM by Intel-bigdata.
the class CommandExecutor method disableCommand.
public void disableCommand(long cid) throws IOException {
// Remove from Cache
if (inCache(cid)) {
LOG.info("Disable Command {}", cid);
// Command is finished, then return
if (inUpdateCache(cid)) {
return;
}
CommandInfo cmdinfo = cmdsAll.get(cid);
cmdinfo.setState(CommandState.DISABLED);
// Disable this command in cache
if (inExecutingList(cid)) {
// Remove from Executing queue
removeFromExecuting(cid, cmdinfo.getRid(), cmdinfo.getState());
// Kill thread
commandPool.deleteCommand(cid);
} else {
// Remove from Pending queue
cmdsInState.get(CommandState.PENDING.getValue()).remove(cid);
}
// in next batch update
synchronized (statusCache) {
statusCache.add(new CmdTuple(cid, cmdinfo.getRid(), CommandState.DISABLED));
}
}
}
use of org.smartdata.common.command.CommandInfo in project SSM by Intel-bigdata.
the class CommandExecutor method submitCommand.
public synchronized long submitCommand(CommandDescriptor commandDescriptor) throws IOException {
if (commandDescriptor == null) {
LOG.error("Command Descriptor!");
throw new IOException();
// return -1;
}
long submitTime = System.currentTimeMillis();
CommandInfo cmdinfo = new CommandInfo(0, commandDescriptor.getRuleId(), ActionType.ArchiveFile, CommandState.PENDING, commandDescriptor.getCommandString(), submitTime, submitTime);
return submitCommand(cmdinfo);
}
use of org.smartdata.common.command.CommandInfo in project SSM by Intel-bigdata.
the class CommandExecutor method deleteCommand.
public void deleteCommand(long cid) throws IOException {
// Remove from Cache
if (inCache(cid)) {
// Command is finished, then return
CommandInfo cmdinfo = cmdsAll.get(cid);
// Disable this command in cache
if (inExecutingList(cid)) {
// Remove from Executing queue
removeFromExecuting(cid, cmdinfo.getRid(), cmdinfo.getState());
// Kill thread
commandPool.deleteCommand(cid);
} else if (inUpdateCache(cid)) {
removeFromUpdateCache(cid);
} else {
// Remove from Pending queue
cmdsInState.get(CommandState.PENDING.getValue()).remove(cid);
}
// Mark as cancelled, this status will be update to DB
// in next batch update
cmdsAll.remove(cid);
}
try {
adapter.deleteCommand(cid);
} catch (SQLException e) {
LOG.error(e.getMessage());
throw new IOException(e);
}
}
Aggregations