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);
}
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);
}
}
}
}
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);
}
}
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);
}
}
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);
}
Aggregations