Search in sources :

Example 11 with ActionInfo

use of org.smartdata.model.ActionInfo 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 12 with ActionInfo

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

the class CmdletManager method searchAction.

public ActionGroup searchAction(String path, long pageIndex, long numPerPage, List<String> orderBy, List<Boolean> isDesc) throws IOException {
    try {
        if (pageIndex == Long.parseLong("0")) {
            if (tmpActions.totalNumOfActions != 0) {
                return tmpActions;
            } else {
                pageIndex = 1;
            }
        }
        long[] total = new long[1];
        List<ActionInfo> infos = metaStore.searchAction(path, (pageIndex - 1) * numPerPage, numPerPage, orderBy, isDesc, total);
        for (ActionInfo info : infos) {
            LOG.debug("[metaStore search] " + info.getActionName());
            ActionInfo memInfo = idToActions.get(info.getActionId());
            if (memInfo != null) {
                info.setCreateTime(memInfo.getCreateTime());
                info.setProgress(memInfo.getProgress());
            }
        }
        tmpActions = new ActionGroup(infos, total[0]);
        return tmpActions;
    } catch (MetaStoreException e) {
        LOG.error("Search [ {} ], Get Finished Actions by search from DB error", path, e);
        throw new IOException(e);
    }
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) ActionInfo(org.smartdata.model.ActionInfo) IOException(java.io.IOException)

Example 13 with ActionInfo

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

the class CmdletManager method listNewCreatedActions.

public List<ActionInfo> listNewCreatedActions(int actionNum) throws IOException {
    try {
        Map<Long, ActionInfo> actionInfos = new HashMap<>();
        for (ActionInfo info : metaStore.getNewCreatedActions(actionNum)) {
            actionInfos.put(info.getActionId(), info);
        }
        actionInfos.putAll(idToActions);
        return Lists.newArrayList(actionInfos.values());
    } catch (MetaStoreException e) {
        LOG.error("Get Finished Actions from DB error", e);
        throw new IOException(e);
    }
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActionInfo(org.smartdata.model.ActionInfo) IOException(java.io.IOException)

Example 14 with ActionInfo

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

the class CmdletManager method onActionStatusUpdate.

public void onActionStatusUpdate(ActionStatus status) throws IOException, ActionException {
    if (status == null) {
        return;
    }
    long actionId = status.getActionId();
    if (idToActions.containsKey(actionId)) {
        ActionInfo actionInfo = idToActions.get(actionId);
        CmdletInfo cmdletInfo = idToCmdlets.get(status.getCmdletId());
        synchronized (actionInfo) {
            if (!actionInfo.isFinished()) {
                actionInfo.setLog(status.getLog());
                actionInfo.setResult(status.getResult());
                if (!status.isFinished()) {
                    actionInfo.setProgress(status.getPercentage());
                    if (actionInfo.getCreateTime() == 0) {
                        actionInfo.setCreateTime(cmdletInfo.getGenerateTime());
                    }
                    actionInfo.setFinishTime(System.currentTimeMillis());
                } else {
                    actionInfo.setProgress(1.0F);
                    actionInfo.setFinished(true);
                    actionInfo.setCreateTime(status.getStartTime());
                    actionInfo.setFinishTime(status.getFinishTime());
                    if (status.getThrowable() != null) {
                        actionInfo.setSuccessful(false);
                    } else {
                        actionInfo.setSuccessful(true);
                        updateStorageIfNeeded(actionInfo);
                    }
                    int actionIndex = 0;
                    for (long id : cmdletInfo.getAids()) {
                        if (id == actionId) {
                            break;
                        }
                        actionIndex++;
                    }
                    for (ActionScheduler p : schedulers.get(actionInfo.getActionName())) {
                        p.onActionFinished(cmdletInfo, actionInfo, actionIndex);
                    }
                }
            }
        }
    } else {
    // Updating action info which is not pending or running
    }
}
Also used : ActionScheduler(org.smartdata.model.action.ActionScheduler) ActionInfo(org.smartdata.model.ActionInfo) CmdletInfo(org.smartdata.model.CmdletInfo)

Example 15 with ActionInfo

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

the class CmdletManager method reloadCmdletsInDB.

private void reloadCmdletsInDB() throws IOException {
    LOG.info("reloading the dispatched and pending cmdlets in DB.");
    List<CmdletInfo> cmdletInfos;
    try {
        cmdletInfos = metaStore.getCmdlets(CmdletState.DISPATCHED);
        if (cmdletInfos != null && cmdletInfos.size() != 0) {
            for (CmdletInfo cmdletInfo : cmdletInfos) {
                // track reload cmdlets
                CmdletDescriptor cmdletDescriptor = CmdletDescriptor.fromCmdletString(cmdletInfo.getParameters());
                cmdletDescriptor.setRuleId(cmdletInfo.getRid());
                tracker.track(cmdletInfo.getCid(), cmdletDescriptor);
                List<ActionInfo> actionInfos = getActions(cmdletInfo.getAids());
                for (ActionInfo actionInfo : actionInfos) {
                    actionInfo.setCreateTime(cmdletInfo.getGenerateTime());
                    actionInfo.setFinishTime(System.currentTimeMillis());
                    // Recover scheduler status according to dispatched action.
                    recoverSchedulerStatus(actionInfo);
                }
                syncCmdAction(cmdletInfo, actionInfos);
            }
        }
        cmdletInfos = metaStore.getCmdlets(CmdletState.PENDING);
        if (cmdletInfos != null && cmdletInfos.size() != 0) {
            for (CmdletInfo cmdletInfo : cmdletInfos) {
                CmdletDescriptor cmdletDescriptor = CmdletDescriptor.fromCmdletString(cmdletInfo.getParameters());
                cmdletDescriptor.setRuleId(cmdletInfo.getRid());
                // Pending task also needs to be tracked.
                tracker.track(cmdletInfo.getCid(), cmdletDescriptor);
                LOG.debug(String.format("Reload pending cmdlet: {}", cmdletInfo));
                List<ActionInfo> actionInfos = getActions(cmdletInfo.getAids());
                syncCmdAction(cmdletInfo, actionInfos);
            }
        }
    } catch (MetaStoreException e) {
        LOG.error("DB connection error occurs when ssm is reloading cmdlets!");
        return;
    } catch (ParseException pe) {
        LOG.error("Failed to parse cmdlet string for tracking task", pe);
    }
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor) MetaStoreException(org.smartdata.metastore.MetaStoreException) ActionInfo(org.smartdata.model.ActionInfo) ParseException(java.text.ParseException) CmdletInfo(org.smartdata.model.CmdletInfo)

Aggregations

ActionInfo (org.smartdata.model.ActionInfo)48 Test (org.junit.Test)23 HashMap (java.util.HashMap)16 CmdletInfo (org.smartdata.model.CmdletInfo)16 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 SmartAdmin (org.smartdata.admin.SmartAdmin)5 MetaStore (org.smartdata.metastore.MetaStore)5 Path (org.apache.hadoop.fs.Path)4 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)4 MetaStoreException (org.smartdata.metastore.MetaStoreException)4 FileInfo (org.smartdata.model.FileInfo)4 CmdletDescriptor (org.smartdata.model.CmdletDescriptor)3 ActionScheduler (org.smartdata.model.action.ActionScheduler)3 ServiceException (com.google.protobuf.ServiceException)2 ParseException (java.text.ParseException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 QueueFullException (org.smartdata.exception.QueueFullException)2 DetailedFileAction (org.smartdata.model.DetailedFileAction)2