Search in sources :

Example 1 with ActionStatus

use of org.smartdata.protocol.message.ActionStatus in project SSM by Intel-bigdata.

the class TestCmdletManager method testWithoutCluster.

@Test
public void testWithoutCluster() throws MetaStoreException, IOException, InterruptedException {
    long cmdletId = 10;
    long actionId = 101;
    MetaStore metaStore = mock(MetaStore.class);
    Assert.assertNotNull(metaStore);
    when(metaStore.getMaxCmdletId()).thenReturn(cmdletId);
    when(metaStore.getMaxActionId()).thenReturn(actionId);
    CmdletDispatcher dispatcher = mock(CmdletDispatcher.class);
    Assert.assertNotNull(dispatcher);
    when(dispatcher.canDispatchMore()).thenReturn(true);
    ServerContext serverContext = new ServerContext(new SmartConf(), metaStore);
    serverContext.setServiceMode(ServiceMode.HDFS);
    CmdletManager cmdletManager = new CmdletManager(serverContext);
    cmdletManager.init();
    cmdletManager.setDispatcher(dispatcher);
    cmdletManager.start();
    cmdletManager.submitCmdlet("echo");
    Thread.sleep(500);
    verify(metaStore, times(1)).insertCmdlets(any(CmdletInfo[].class));
    verify(metaStore, times(1)).insertActions(any(ActionInfo[].class));
    Thread.sleep(500);
    long startTime = System.currentTimeMillis();
    ActionStatus actionStatus = new ActionStatus(cmdletId, true, actionId, startTime, null);
    StatusReport statusReport = new StatusReport(Arrays.asList(actionStatus));
    cmdletManager.updateStatus(statusReport);
    ActionInfo actionInfo = cmdletManager.getActionInfo(actionId);
    CmdletInfo cmdletInfo = cmdletManager.getCmdletInfo(cmdletId);
    Assert.assertNotNull(actionInfo);
    cmdletManager.updateStatus(new CmdletStatusUpdate(cmdletId, System.currentTimeMillis(), CmdletState.EXECUTING));
    CmdletInfo info = cmdletManager.getCmdletInfo(cmdletId);
    Assert.assertNotNull(info);
    Assert.assertEquals(info.getParameters(), "echo");
    Assert.assertEquals(info.getAids().size(), 1);
    Assert.assertTrue(info.getAids().get(0) == actionId);
    Assert.assertEquals(info.getState(), CmdletState.EXECUTING);
    long finishTime = System.currentTimeMillis();
    actionStatus = new ActionStatus(cmdletId, true, actionId, null, startTime, finishTime, null, true);
    statusReport = new StatusReport(Arrays.asList(actionStatus));
    cmdletManager.updateStatus(statusReport);
    Assert.assertTrue(actionInfo.isFinished());
    Assert.assertTrue(actionInfo.isSuccessful());
    Assert.assertEquals(actionInfo.getCreateTime(), startTime);
    Assert.assertEquals(actionInfo.getFinishTime(), finishTime);
    Assert.assertEquals(cmdletInfo.getState(), CmdletState.DONE);
    cmdletManager.updateStatus(new CmdletStatusUpdate(cmdletId, System.currentTimeMillis(), CmdletState.DONE));
    Assert.assertEquals(info.getState(), CmdletState.DONE);
    Thread.sleep(500);
    verify(metaStore, times(2)).insertCmdlets(any(CmdletInfo[].class));
    verify(metaStore, times(2)).insertActions(any(ActionInfo[].class));
    cmdletManager.stop();
}
Also used : MetaStore(org.smartdata.metastore.MetaStore) StatusReport(org.smartdata.protocol.message.StatusReport) SmartConf(org.smartdata.conf.SmartConf) ActionInfo(org.smartdata.model.ActionInfo) CmdletStatusUpdate(org.smartdata.protocol.message.CmdletStatusUpdate) CmdletDispatcher(org.smartdata.server.engine.cmdlet.CmdletDispatcher) CmdletInfo(org.smartdata.model.CmdletInfo) ActionStatus(org.smartdata.protocol.message.ActionStatus) Test(org.junit.Test)

Example 2 with ActionStatus

use of org.smartdata.protocol.message.ActionStatus in project SSM by Intel-bigdata.

the class CmdletDispatcher method updateCmdActionStatus.

private void updateCmdActionStatus(LaunchCmdlet cmdlet, String host) {
    if (cmdletManager != null) {
        try {
            cmdletManager.updateCmdletExecHost(cmdlet.getCmdletId(), host);
        } catch (IOException e) {
        // Ignore this
        }
    }
    try {
        LaunchAction action;
        ActionStatus actionStatus;
        for (int i = 0; i < cmdlet.getLaunchActions().size(); i++) {
            action = cmdlet.getLaunchActions().get(i);
            actionStatus = new ActionStatus(cmdlet.getCmdletId(), i == cmdlet.getLaunchActions().size() - 1, action.getActionId(), System.currentTimeMillis());
            cmdletManager.onActionStatusUpdate(actionStatus);
        }
        CmdletStatus cmdletStatus = new CmdletStatus(cmdlet.getCmdletId(), System.currentTimeMillis(), CmdletState.DISPATCHED);
        cmdletManager.onCmdletStatusUpdate(cmdletStatus);
    } catch (IOException e) {
        LOG.info("update status failed.", e);
    } catch (ActionException e) {
        LOG.info("update action status failed.", e);
    }
}
Also used : LaunchAction(org.smartdata.model.LaunchAction) ActionException(org.smartdata.action.ActionException) CmdletStatus(org.smartdata.protocol.message.CmdletStatus) IOException(java.io.IOException) ActionStatus(org.smartdata.protocol.message.ActionStatus)

Example 3 with ActionStatus

use of org.smartdata.protocol.message.ActionStatus in project SSM by Intel-bigdata.

the class StatusReportTask method run.

@Override
public void run() {
    StatusReport statusReport = cmdletExecutor.getStatusReport();
    if (statusReport != null) {
        List<ActionStatus> actionStatuses = statusReport.getActionStatuses();
        for (ActionStatus actionStatus : actionStatuses) {
            idToActionStatus.put(actionStatus.getActionId(), actionStatus);
        }
        if (!idToActionStatus.values().isEmpty()) {
            int finishedNum = 0;
            for (ActionStatus actionStatus : idToActionStatus.values()) {
                if (actionStatus.isFinished()) {
                    finishedNum++;
                }
            }
            long currentTime = System.currentTimeMillis();
            if (currentTime - lastReportTime >= interval || (double) finishedNum / idToActionStatus.size() >= ratio) {
                statusReporter.report(new StatusReport(new ArrayList(idToActionStatus.values())));
                idToActionStatus.clear();
                lastReportTime = currentTime;
            }
        }
    }
}
Also used : StatusReport(org.smartdata.protocol.message.StatusReport) ArrayList(java.util.ArrayList) ActionStatus(org.smartdata.protocol.message.ActionStatus)

Example 4 with ActionStatus

use of org.smartdata.protocol.message.ActionStatus in project SSM by Intel-bigdata.

the class TestCmdletExecutor method testCmdletExecutor.

@Test
public void testCmdletExecutor() throws InterruptedException {
    final List<StatusMessage> statusMessages = new ArrayList<>();
    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 EchoAction();
    Map<String, String> args = new HashMap<>();
    args.put(EchoAction.PRINT_MESSAGE, "message success");
    action.setArguments(args);
    action.setActionId(101);
    Cmdlet cmdlet = new Cmdlet(Arrays.asList(action));
    executor.execute(cmdlet);
    Thread.sleep(2000);
    StatusReport lastReport = (StatusReport) statusMessages.get(statusMessages.size() - 1);
    ActionStatus status = lastReport.getActionStatuses().get(0);
    Assert.assertTrue(status.isFinished());
    Assert.assertNull(status.getThrowable());
    executor.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) StatusReporter(org.smartdata.protocol.message.StatusReporter) EchoAction(org.smartdata.action.EchoAction) Test(org.junit.Test)

Example 5 with ActionStatus

use of org.smartdata.protocol.message.ActionStatus in project SSM by Intel-bigdata.

the class CmdletManager method inferCmdletStatus.

private void inferCmdletStatus(ActionInfo actionInfo) throws IOException, ActionException {
    if (actionInfo == null) {
        return;
    }
    if (!actionInfo.isFinished()) {
        return;
    }
    long actionId = actionInfo.getActionId();
    long cmdletId = actionInfo.getCmdletId();
    CmdletInfo cmdletInfo = idToCmdlets.get(cmdletId);
    List<Long> aids = cmdletInfo.getAids();
    int index = aids.indexOf(actionId);
    if (!actionInfo.isSuccessful()) {
        for (int i = index + 1; i < aids.size(); i++) {
            // Use current action's finish time to set start/finish time for
            // subsequent action(s).
            ActionStatus actionStatus = ActionStatusFactory.createSkipActionStatus(cmdletId, i == aids.size() - 1, aids.get(i), actionInfo.getFinishTime(), actionInfo.getFinishTime());
            onActionStatusUpdate(actionStatus);
        }
        CmdletStatus cmdletStatus = new CmdletStatus(cmdletId, actionInfo.getFinishTime(), CmdletState.FAILED);
        onCmdletStatusUpdate(cmdletStatus);
    } else {
        if (index == aids.size() - 1) {
            CmdletStatus cmdletStatus = new CmdletStatus(cmdletId, actionInfo.getFinishTime(), CmdletState.DONE);
            onCmdletStatusUpdate(cmdletStatus);
        }
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CmdletStatus(org.smartdata.protocol.message.CmdletStatus) CmdletInfo(org.smartdata.model.CmdletInfo) ActionStatus(org.smartdata.protocol.message.ActionStatus)

Aggregations

ActionStatus (org.smartdata.protocol.message.ActionStatus)7 StatusReport (org.smartdata.protocol.message.StatusReport)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 SmartAction (org.smartdata.action.SmartAction)3 SmartConf (org.smartdata.conf.SmartConf)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 CmdletInfo (org.smartdata.model.CmdletInfo)2 CmdletStatus (org.smartdata.protocol.message.CmdletStatus)2 StatusMessage (org.smartdata.protocol.message.StatusMessage)2 StatusReporter (org.smartdata.protocol.message.StatusReporter)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Vector (java.util.Vector)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ActionException (org.smartdata.action.ActionException)1 EchoAction (org.smartdata.action.EchoAction)1 MetaStore (org.smartdata.metastore.MetaStore)1 ActionInfo (org.smartdata.model.ActionInfo)1 LaunchAction (org.smartdata.model.LaunchAction)1