Search in sources :

Example 11 with CmdletInfo

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

the class CmdletManager method cmdletFinished.

// Todo: optimize this function.
private void cmdletFinished(long cmdletId) throws IOException {
    numCmdletsFinished.incrementAndGet();
    CmdletInfo cmdletInfo = idToCmdlets.get(cmdletId);
    if (cmdletInfo == null) {
        LOG.debug("CmdletInfo [id={}] does not exist in idToCmdlets.", cmdletId);
        return;
    }
    dispatcher.onCmdletFinished(cmdletInfo.getCid());
    runningCmdlets.remove(cmdletId);
    idToLaunchCmdlet.remove(cmdletId);
    flushCmdletInfo(cmdletInfo);
}
Also used : CmdletInfo(org.smartdata.model.CmdletInfo)

Example 12 with CmdletInfo

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

the class CmdletManager method onCmdletStatusUpdate.

public void onCmdletStatusUpdate(CmdletStatus status) throws IOException {
    if (status == null) {
        return;
    }
    long cmdletId = status.getCmdletId();
    CmdletInfo cmdletInfo = idToCmdlets.get(cmdletId);
    if (cmdletInfo != null) {
        synchronized (cmdletInfo) {
            if (CmdletState.isTerminalState(cmdletInfo.getState())) {
                return;
            }
            CmdletState state = status.getCurrentState();
            cmdletInfo.setState(state);
            cmdletInfo.setStateChangedTime(status.getStateUpdateTime());
            if (CmdletState.isTerminalState(state)) {
                cmdletFinished(cmdletId);
            } else if (state == CmdletState.DISPATCHED) {
                flushCmdletInfo(cmdletInfo);
            }
        }
    }
}
Also used : CmdletState(org.smartdata.model.CmdletState) CmdletInfo(org.smartdata.model.CmdletInfo)

Example 13 with CmdletInfo

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

Example 14 with CmdletInfo

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

the class TestCmdletDao method testUpdateCmdlet.

@Test
public void testUpdateCmdlet() throws Exception {
    CmdletInfo cmdlet1 = new CmdletInfo(0, 1, CmdletState.EXECUTING, "test", 123123333L, 232444444L);
    CmdletInfo cmdlet2 = new CmdletInfo(1, 78, CmdletState.PAUSED, "tt", 123178333L, 232444994L);
    cmdletDao.insert(new CmdletInfo[] { cmdlet1, cmdlet2 });
    cmdlet1.setState(CmdletState.DONE);
    cmdletDao.update(cmdlet1);
    CmdletInfo dbcmdlet1 = cmdletDao.getById(cmdlet1.getCid());
    Assert.assertTrue(dbcmdlet1.equals(cmdlet1));
    try {
        cmdletDao.getById(2000L);
    } catch (EmptyResultDataAccessException e) {
        Assert.assertTrue(true);
    }
}
Also used : EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 15 with CmdletInfo

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

the class TestCmdletDao method testMaxId.

@Test
public void testMaxId() throws Exception {
    CmdletInfo cmdlet1 = new CmdletInfo(0, 1, CmdletState.EXECUTING, "test", 123123333L, 232444444L);
    CmdletInfo cmdlet2 = new CmdletInfo(1, 78, CmdletState.PAUSED, "tt", 123178333L, 232444994L);
    Assert.assertTrue(cmdletDao.getMaxId() == 0);
    cmdletDao.insert(new CmdletInfo[] { cmdlet1, cmdlet2 });
    Assert.assertTrue(cmdletDao.getMaxId() == 2);
}
Also used : 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