Search in sources :

Example 6 with SmartAction

use of org.smartdata.action.SmartAction in project SSM by Intel-bigdata.

the class Cmdlet method getActionStatuses.

public synchronized List<ActionStatus> getActionStatuses() throws UnsupportedEncodingException {
    if (actionReportList.isEmpty()) {
        return null;
    }
    // get status in the order of the descend action id.
    // The cmdletmanager should update action status in the ascend order.
    List<ActionStatus> statuses = new ArrayList<>();
    Iterator<SmartAction> iter = actionReportList.iterator();
    while (iter.hasNext()) {
        SmartAction action = iter.next();
        ActionStatus status = action.getActionStatus();
        statuses.add(status);
        if (status.isFinished()) {
            iter.remove();
        }
    }
    return Lists.reverse(statuses);
}
Also used : ArrayList(java.util.ArrayList) SmartAction(org.smartdata.action.SmartAction) ActionStatus(org.smartdata.protocol.message.ActionStatus)

Example 7 with SmartAction

use of org.smartdata.action.SmartAction in project SSM by Intel-bigdata.

the class Cmdlet method runAllActions.

private void runAllActions() {
    state = CmdletState.EXECUTING;
    stateUpdateTime = System.currentTimeMillis();
    Iterator<SmartAction> iter = actions.iterator();
    while (iter.hasNext()) {
        SmartAction act = iter.next();
        if (act == null) {
            continue;
        }
        // Init Action
        // TODO: this statement maybe can be removed.
        act.init(act.getArguments());
        act.run();
        if (!act.isSuccessful()) {
            while (iter.hasNext()) {
                SmartAction nextAct = iter.next();
                synchronized (this) {
                    actionReportList.remove(nextAct);
                }
            }
            state = CmdletState.FAILED;
            stateUpdateTime = System.currentTimeMillis();
            LOG.error("Executing Cmdlet [id={}] meets failed.", getId());
            return;
        }
    }
    state = CmdletState.DONE;
    stateUpdateTime = System.currentTimeMillis();
// TODO catch MetaStoreException and handle
}
Also used : SmartAction(org.smartdata.action.SmartAction)

Example 8 with SmartAction

use of org.smartdata.action.SmartAction in project SSM by Intel-bigdata.

the class TestCmdletExecutor method testStop.

@Test
public void testStop() throws InterruptedException {
    final List<StatusMessage> statusMessages = new Vector<>();
    StatusReporter reporter = new StatusReporter() {

        @Override
        public void report(StatusMessage status) {
            statusMessages.add(status);
        }
    };
    CmdletExecutor executor = new CmdletExecutor(new SmartConf());
    StatusReportTask statusReportTask = new StatusReportTask(reporter, executor, new SmartConf());
    ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    executorService.scheduleAtFixedRate(statusReportTask, 100, 10, TimeUnit.MILLISECONDS);
    SmartAction action = new HangingAction();
    action.setActionId(101);
    Cmdlet cmdlet = new Cmdlet(Arrays.asList(action));
    cmdlet.setId(10);
    executor.execute(cmdlet);
    Thread.sleep(1000);
    executor.stop(10L);
    Thread.sleep(2000);
    StatusReport lastReport = (StatusReport) statusMessages.get(statusMessages.size() - 1);
    ActionStatus status = lastReport.getActionStatuses().get(0);
    Assert.assertTrue(status.isFinished());
    Assert.assertNotNull(status.getThrowable());
    executor.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StatusMessage(org.smartdata.protocol.message.StatusMessage) ActionStatus(org.smartdata.protocol.message.ActionStatus) StatusReport(org.smartdata.protocol.message.StatusReport) SmartAction(org.smartdata.action.SmartAction) SmartConf(org.smartdata.conf.SmartConf) Vector(java.util.Vector) StatusReporter(org.smartdata.protocol.message.StatusReporter) Test(org.junit.Test)

Aggregations

SmartAction (org.smartdata.action.SmartAction)8 ArrayList (java.util.ArrayList)3 ActionStatus (org.smartdata.protocol.message.ActionStatus)3 HashMap (java.util.HashMap)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Test (org.junit.Test)2 SmartConf (org.smartdata.conf.SmartConf)2 HdfsAction (org.smartdata.hdfs.action.HdfsAction)2 StatusMessage (org.smartdata.protocol.message.StatusMessage)2 StatusReport (org.smartdata.protocol.message.StatusReport)2 StatusReporter (org.smartdata.protocol.message.StatusReporter)2 IOException (java.io.IOException)1 Vector (java.util.Vector)1 ActionException (org.smartdata.action.ActionException)1 EchoAction (org.smartdata.action.EchoAction)1 CacheFileAction (org.smartdata.hdfs.action.CacheFileAction)1 AbstractMoveFileAction (org.smartdata.hdfs.action.move.AbstractMoveFileAction)1 SmartDFSClient (org.smartdata.hdfs.client.SmartDFSClient)1 MetaStoreException (org.smartdata.metastore.MetaStoreException)1 LaunchAction (org.smartdata.model.LaunchAction)1