Search in sources :

Example 21 with CmdletInfo

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

the class CmdletManager method dropRuleCmdlets.

/**
 * Drop all unfinished cmdlets.
 *
 * @param ruleId
 * @throws IOException
 */
public void dropRuleCmdlets(long ruleId) throws IOException {
    List<Long> cids = new ArrayList<>();
    for (CmdletInfo info : idToCmdlets.values()) {
        if (info.getRid() == ruleId && !CmdletState.isTerminalState(info.getState())) {
            cids.add(info.getCid());
        }
    }
    batchDeleteCmdlet(cids);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) CmdletInfo(org.smartdata.model.CmdletInfo)

Example 22 with CmdletInfo

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

the class CmdletManager method submitCmdlet.

public long submitCmdlet(CmdletDescriptor cmdletDescriptor) throws IOException {
    // with the same rule id and cmdlet string, return -1.
    if (tracker.contains(cmdletDescriptor)) {
        LOG.debug("Refuse to repeatedly submit Cmdlet for {}", cmdletDescriptor);
        return -1;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Received Cmdlet -> [ %s ]", cmdletDescriptor.getCmdletString()));
    }
    if (maxNumPendingCmdlets <= pendingCmdlet.size() + schedulingCmdlet.size()) {
        throw new QueueFullException("Pending cmdlets exceeds value specified by key '" + SmartConfKeys.SMART_CMDLET_MAX_NUM_PENDING_KEY + "' = " + maxNumPendingCmdlets);
    }
    long submitTime = System.currentTimeMillis();
    CmdletInfo cmdletInfo = new CmdletInfo(maxCmdletId.getAndIncrement(), cmdletDescriptor.getRuleId(), CmdletState.PENDING, cmdletDescriptor.getCmdletString(), submitTime, submitTime, submitTime + cmdletDescriptor.getDeferIntervalMs());
    List<ActionInfo> actionInfos = createActionInfos(cmdletDescriptor, cmdletInfo.getCid());
    // Check action names
    checkActionNames(cmdletDescriptor);
    // Check if action path is in whitelist
    if (WhitelistHelper.isEnabled(getContext().getConf())) {
        if (!WhitelistHelper.isCmdletInWhitelist(cmdletDescriptor)) {
            throw new IOException("This path is not in the whitelist.");
        }
    }
    // Let Scheduler check actioninfo onsubmit and add them to cmdletinfo
    checkActionsOnSubmit(cmdletInfo, actionInfos);
    // Insert cmdletinfo and actionInfos to metastore and cache.
    syncCmdAction(cmdletInfo, actionInfos);
    // Track in the submission portal. For cmdlets recovered from DB
    // (see #recover), they will be not be tracked.
    tracker.track(cmdletInfo.getCid(), cmdletDescriptor);
    return cmdletInfo.getCid();
}
Also used : QueueFullException(org.smartdata.exception.QueueFullException) ActionInfo(org.smartdata.model.ActionInfo) IOException(java.io.IOException) CmdletInfo(org.smartdata.model.CmdletInfo)

Example 23 with CmdletInfo

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

the class CmdletManager method updateCmdletExecHost.

public void updateCmdletExecHost(long cmdletId, String host) throws IOException {
    CmdletInfo cmdlet = getCmdletInfo(cmdletId);
    if (cmdlet == null) {
        return;
    }
    ActionInfo action;
    for (long id : cmdlet.getAids()) {
        action = getActionInfo(id);
        if (action != null) {
            action.setExecHost(host);
        }
    }
}
Also used : ActionInfo(org.smartdata.model.ActionInfo) CmdletInfo(org.smartdata.model.CmdletInfo)

Example 24 with CmdletInfo

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

the class ServerProtocolsServerSideTranslator method listCmdletInfo.

@Override
public ListCmdletInfoResponseProto listCmdletInfo(RpcController controller, ListCmdletInfoRequestProto req) throws ServiceException {
    try {
        List<CmdletInfo> list = server.listCmdletInfo(req.getRuleID(), CmdletState.fromValue(req.getCmdletState()));
        if (list == null) {
            return ListCmdletInfoResponseProto.newBuilder().build();
        }
        List<CmdletInfoProto> protoList = new ArrayList<>();
        for (CmdletInfo info : list) {
            protoList.add(ProtoBufferHelper.convert(info));
        }
        return ListCmdletInfoResponseProto.newBuilder().addAllCmdletInfos(protoList).build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CmdletInfoProto(org.smartdata.protocol.AdminServerProto.CmdletInfoProto) CmdletInfo(org.smartdata.model.CmdletInfo)

Example 25 with CmdletInfo

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

the class TestActionRpc method testActionProgress.

@Test
public void testActionProgress() throws Exception {
    waitTillSSMExitSafeMode();
    SmartAdmin admin = new SmartAdmin(smartContext.getConf());
    long cmdId = admin.submitCmdlet("sleep -ms 6000");
    try {
        CmdletInfo cinfo = admin.getCmdletInfo(cmdId);
        long actId = cinfo.getAids().get(0);
        ActionInfo actionInfo;
        while (true) {
            actionInfo = admin.getActionInfo(actId);
            if (actionInfo.isFinished()) {
                Assert.fail("No intermediate progress observed.");
            }
            if (actionInfo.getProgress() > 0 && actionInfo.getProgress() < 1.0) {
                return;
            }
            Thread.sleep(500);
        }
    } finally {
        admin.close();
    }
}
Also used : SmartAdmin(org.smartdata.admin.SmartAdmin) ActionInfo(org.smartdata.model.ActionInfo) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Aggregations

CmdletInfo (org.smartdata.model.CmdletInfo)37 Test (org.junit.Test)18 ActionInfo (org.smartdata.model.ActionInfo)16 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 HashMap (java.util.HashMap)4 MetaStore (org.smartdata.metastore.MetaStore)3 CmdletDescriptor (org.smartdata.model.CmdletDescriptor)3 CmdletState (org.smartdata.model.CmdletState)3 RuleInfo (org.smartdata.model.RuleInfo)3 CmdletStatus (org.smartdata.protocol.message.CmdletStatus)3 ServiceException (com.google.protobuf.ServiceException)2 ParseException (java.text.ParseException)2 SmartAdmin (org.smartdata.admin.SmartAdmin)2 QueueFullException (org.smartdata.exception.QueueFullException)2 MetaStoreException (org.smartdata.metastore.MetaStoreException)2 FileInfo (org.smartdata.model.FileInfo)2 CmdletInfoProto (org.smartdata.protocol.AdminServerProto.CmdletInfoProto)2 ActionStatus (org.smartdata.protocol.message.ActionStatus)2