Search in sources :

Example 1 with LaunchAction

use of org.smartdata.model.LaunchAction in project SSM by Intel-bigdata.

the class CmdletManager method scheduleCmdletActions.

private ScheduleResult scheduleCmdletActions(CmdletInfo info, LaunchCmdlet launchCmdlet) {
    List<Long> actIds = info.getAids();
    int idx = 0;
    int schIdx = 0;
    ActionInfo actionInfo;
    LaunchAction launchAction;
    List<ActionScheduler> actSchedulers;
    boolean skipped = false;
    ScheduleResult scheduleResult = ScheduleResult.SUCCESS_NO_EXECUTION;
    ScheduleResult resultTmp;
    for (idx = 0; idx < actIds.size(); idx++) {
        actionInfo = idToActions.get(actIds.get(idx));
        launchAction = launchCmdlet.getLaunchActions().get(idx);
        actSchedulers = schedulers.get(actionInfo.getActionName());
        if (actSchedulers == null || actSchedulers.size() == 0) {
            skipped = true;
            continue;
        }
        for (schIdx = 0; schIdx < actSchedulers.size(); schIdx++) {
            ActionScheduler s = actSchedulers.get(schIdx);
            try {
                resultTmp = s.onSchedule(info, actionInfo, launchCmdlet, launchAction, idx);
            } catch (Throwable t) {
                actionInfo.appendLogLine("\nOnSchedule exception: " + t);
                resultTmp = ScheduleResult.FAIL;
            }
            if (resultTmp != ScheduleResult.SUCCESS && resultTmp != ScheduleResult.SUCCESS_NO_EXECUTION) {
                scheduleResult = resultTmp;
            } else {
                if (scheduleResult == ScheduleResult.SUCCESS_NO_EXECUTION) {
                    scheduleResult = resultTmp;
                }
            }
            if (scheduleResult != ScheduleResult.SUCCESS && scheduleResult != ScheduleResult.SUCCESS_NO_EXECUTION) {
                break;
            }
        }
        if (scheduleResult != ScheduleResult.SUCCESS && scheduleResult != ScheduleResult.SUCCESS_NO_EXECUTION) {
            break;
        }
    }
    if (scheduleResult == ScheduleResult.SUCCESS || scheduleResult == ScheduleResult.SUCCESS_NO_EXECUTION) {
        idx--;
        schIdx--;
        if (skipped) {
            scheduleResult = ScheduleResult.SUCCESS;
        }
    }
    postscheduleCmdletActions(info, actIds, scheduleResult, idx, schIdx);
    return scheduleResult;
}
Also used : ScheduleResult(org.smartdata.model.action.ScheduleResult) LaunchAction(org.smartdata.model.LaunchAction) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActionScheduler(org.smartdata.model.action.ActionScheduler) ActionInfo(org.smartdata.model.ActionInfo)

Example 2 with LaunchAction

use of org.smartdata.model.LaunchAction 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 LaunchAction

use of org.smartdata.model.LaunchAction in project SSM by Intel-bigdata.

the class CmdletFactory method createCmdlet.

public Cmdlet createCmdlet(LaunchCmdlet launchCmdlet) throws ActionException {
    List<SmartAction> actions = new ArrayList<>();
    int idx = 0;
    for (LaunchAction action : launchCmdlet.getLaunchActions()) {
        idx++;
        actions.add(createAction(launchCmdlet.getCmdletId(), idx == launchCmdlet.getLaunchActions().size(), action));
    }
    Cmdlet cmdlet = new Cmdlet(actions);
    cmdlet.setId(launchCmdlet.getCmdletId());
    return cmdlet;
}
Also used : LaunchCmdlet(org.smartdata.protocol.message.LaunchCmdlet) LaunchAction(org.smartdata.model.LaunchAction) ArrayList(java.util.ArrayList) SmartAction(org.smartdata.action.SmartAction)

Example 4 with LaunchAction

use of org.smartdata.model.LaunchAction in project SSM by Intel-bigdata.

the class CmdletManager method createLaunchCmdlet.

private LaunchCmdlet createLaunchCmdlet(CmdletInfo cmdletInfo) {
    if (cmdletInfo == null) {
        return null;
    }
    Map<String, String> args;
    List<LaunchAction> launchActions = new ArrayList<>();
    for (Long aid : cmdletInfo.getAids()) {
        if (idToActions.containsKey(aid)) {
            ActionInfo toLaunch = idToActions.get(aid);
            args = new HashMap<>();
            args.putAll(toLaunch.getArgs());
            launchActions.add(new LaunchAction(toLaunch.getActionId(), toLaunch.getActionName(), args));
        }
    }
    return new LaunchCmdlet(cmdletInfo.getCid(), launchActions);
}
Also used : LaunchAction(org.smartdata.model.LaunchAction) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) LaunchCmdlet(org.smartdata.protocol.message.LaunchCmdlet) ActionInfo(org.smartdata.model.ActionInfo)

Example 5 with LaunchAction

use of org.smartdata.model.LaunchAction in project SSM by Intel-bigdata.

the class TestCmdletFactory method testCreateAction.

@Test
public void testCreateAction() throws ActionException {
    SmartContext smartContext = mock(SmartContext.class);
    SmartConf conf = new SmartConf();
    conf.set(DFS_NAMENODE_HTTP_ADDRESS_KEY, "http://0.0.0.0:8088");
    conf.set(SmartConfKeys.SMART_DFS_NAMENODE_RPCSERVER_KEY, "hdfs://0.0.0.0:8089");
    when(smartContext.getConf()).thenReturn(conf);
    CmdletFactory cmdletFactory = new CmdletFactory(smartContext);
    LaunchAction launchAction1 = new LaunchAction(10, "allssd", new HashMap<String, String>());
// SmartAction action = cmdletFactory.createAction(launchAction1);
// Assert.assertNotNull(action);
// Assert.assertEquals(10, action.getActionId());
// 
// LaunchAction launchAction = new LaunchAction(10, "test", new HashMap<String, String>());
// expectedException.expect(ActionException.class);
// Assert.assertNull(cmdletFactory.createAction(launchAction));
}
Also used : LaunchAction(org.smartdata.model.LaunchAction) SmartContext(org.smartdata.SmartContext) SmartConf(org.smartdata.conf.SmartConf) Test(org.junit.Test)

Aggregations

LaunchAction (org.smartdata.model.LaunchAction)5 ArrayList (java.util.ArrayList)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ActionInfo (org.smartdata.model.ActionInfo)2 LaunchCmdlet (org.smartdata.protocol.message.LaunchCmdlet)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 SmartContext (org.smartdata.SmartContext)1 ActionException (org.smartdata.action.ActionException)1 SmartAction (org.smartdata.action.SmartAction)1 SmartConf (org.smartdata.conf.SmartConf)1 ActionScheduler (org.smartdata.model.action.ActionScheduler)1 ScheduleResult (org.smartdata.model.action.ScheduleResult)1 ActionStatus (org.smartdata.protocol.message.ActionStatus)1 CmdletStatus (org.smartdata.protocol.message.CmdletStatus)1