Search in sources :

Example 6 with CommandInfo

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);
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) CommandInfo(org.smartdata.common.command.CommandInfo)

Example 7 with CommandInfo

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;
}
Also used : CommandInfo(org.smartdata.common.command.CommandInfo)

Example 8 with CommandInfo

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));
        }
    }
}
Also used : CommandInfo(org.smartdata.common.command.CommandInfo)

Example 9 with CommandInfo

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);
}
Also used : CommandInfo(org.smartdata.common.command.CommandInfo) IOException(java.io.IOException)

Example 10 with CommandInfo

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);
    }
}
Also used : CommandInfo(org.smartdata.common.command.CommandInfo) SQLException(java.sql.SQLException) IOException(java.io.IOException)

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