Search in sources :

Example 1 with SmartAction

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

the class Command method runActions.

public void runActions() {
    for (SmartAction act : actions) {
        currentActionIndex++;
        if (act == null || !running) {
            continue;
        }
        act.run();
        // Run actions sequentially!
        while (!act.getActionStatus().isFinished()) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                if (!running) {
                    break;
                }
            }
        }
    }
}
Also used : SmartAction(org.smartdata.actions.SmartAction)

Example 2 with SmartAction

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

the class CommandExecutor method getActionInfo.

public ActionInfo getActionInfo(long actionID) {
    SmartAction smartAction = actionPool.get(actionID);
    ActionStatus status = smartAction.getActionStatus();
    return new ActionInfo(status.getId(), 0, smartAction.getName(), smartAction.getArguments(), status.getResultPrintStream().toString(), status.getLogPrintStream().toString(), status.isSuccessful(), status.getStartTime(), status.isSuccessful(), status.getRunningTime(), status.getPercentage());
}
Also used : SmartAction(org.smartdata.actions.SmartAction) ActionInfo(org.smartdata.common.actions.ActionInfo) ActionStatus(org.smartdata.actions.ActionStatus)

Example 3 with SmartAction

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

the class CommandExecutor method listNewCreatedActions.

public List<ActionInfo> listNewCreatedActions(int maxNumActions) throws IOException {
    ArrayList<ActionInfo> actionInfos = new ArrayList<>();
    boolean flag = true;
    for (Command cmd : commandPool.getcommands()) {
        long cmdId = cmd.getId();
        for (SmartAction smartAction : cmd.getActions()) {
            ActionStatus status = smartAction.getActionStatus();
            actionInfos.add(new ActionInfo(status.getId(), cmdId, smartAction.getName(), smartAction.getArguments(), status.getResultPrintStream().toString(), status.getLogPrintStream().toString(), status.isSuccessful(), status.getStartTime(), status.isSuccessful(), status.getRunningTime(), status.getPercentage()));
        }
    }
    // Sort and get top maxNumActions
    Collections.sort(actionInfos, new ActionInfoComparator());
    if (maxNumActions >= actionInfos.size()) {
        return actionInfos;
    } else {
        return actionInfos.subList(0, maxNumActions);
    }
}
Also used : ActionInfoComparator(org.smartdata.common.actions.ActionInfoComparator) ArrayList(java.util.ArrayList) SmartAction(org.smartdata.actions.SmartAction) ActionInfo(org.smartdata.common.actions.ActionInfo) ActionStatus(org.smartdata.actions.ActionStatus)

Example 4 with SmartAction

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

the class CommandExecutor method createActionsFromParameters.

@VisibleForTesting
SmartAction[] createActionsFromParameters(CommandDescriptor commandDescriptor) throws IOException {
    if (commandDescriptor == null) {
        return null;
    }
    // commandDescriptor.();
    List<SmartAction> actions = new ArrayList<>();
    SmartAction current;
    for (int index = 0; index < commandDescriptor.size(); index++) {
        current = createAction(commandDescriptor.getActionName(index));
        actionPool.put(current.getActionStatus().getId(), current);
        if (current == null) {
            LOG.error("New Action Instance from {} error!", commandDescriptor.getActionName(index));
        }
        current.setContext(smartContext);
        current.init(commandDescriptor.getActionArgs(index));
        actions.add(current);
    }
    return actions.toArray(new SmartAction[commandDescriptor.size()]);
}
Also used : ArrayList(java.util.ArrayList) SmartAction(org.smartdata.actions.SmartAction) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with SmartAction

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

the class CommandExecutor method createAction.

private SmartAction createAction(String name) throws IOException {
    SmartAction smartAction = actionRegistry.createAction(name);
    smartAction.setContext(smartContext);
    if (smartAction instanceof HdfsAction) {
        ((HdfsAction) smartAction).setDfsClient(new SmartDFSClient(ssm.getNamenodeURI(), smartContext.getConf(), getRpcServerAddress()));
    }
    smartAction.getActionStatus().setId(currentActionId);
    currentActionId++;
    return smartAction;
}
Also used : HdfsAction(org.smartdata.actions.hdfs.HdfsAction) SmartAction(org.smartdata.actions.SmartAction) SmartDFSClient(org.smartdata.client.SmartDFSClient)

Aggregations

SmartAction (org.smartdata.actions.SmartAction)5 ArrayList (java.util.ArrayList)2 ActionStatus (org.smartdata.actions.ActionStatus)2 ActionInfo (org.smartdata.common.actions.ActionInfo)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HdfsAction (org.smartdata.actions.hdfs.HdfsAction)1 SmartDFSClient (org.smartdata.client.SmartDFSClient)1 ActionInfoComparator (org.smartdata.common.actions.ActionInfoComparator)1