Search in sources :

Example 1 with CmdletDescriptor

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

the class TestCmdletManager method testReloadCmdletsInDB.

@Test(timeout = 40000)
public void testReloadCmdletsInDB() throws Exception {
    waitTillSSMExitSafeMode();
    CmdletManager cmdletManager = ssm.getCmdletManager();
    // Stop cmdletmanager
    // cmdletManager.stop();
    cmdletManager.setTimeout(1000);
    MetaStore metaStore = ssm.getMetaStore();
    String cmd = "write -file /test -length 1024; read -file /test";
    CmdletDescriptor cmdletDescriptor = generateCmdletDescriptor(cmd);
    long submitTime = System.currentTimeMillis();
    CmdletInfo cmdletInfo0 = new CmdletInfo(0, cmdletDescriptor.getRuleId(), CmdletState.DISPATCHED, cmdletDescriptor.getCmdletString(), submitTime, submitTime);
    CmdletInfo cmdletInfo1 = new CmdletInfo(1, cmdletDescriptor.getRuleId(), CmdletState.PENDING, cmdletDescriptor.getCmdletString(), submitTime, submitTime);
    List<ActionInfo> actionInfos0 = cmdletManager.createActionInfos(cmdletDescriptor, cmdletInfo0.getCid());
    flushToDB(metaStore, actionInfos0, cmdletInfo0);
    List<ActionInfo> actionInfos1 = cmdletManager.createActionInfos(cmdletDescriptor, cmdletInfo1.getCid());
    flushToDB(metaStore, actionInfos1, cmdletInfo1);
    // init cmdletmanager
    cmdletManager.init();
    // cmdletManager.start();
    CmdletInfo cmdlet0 = cmdletManager.getCmdletInfo(cmdletInfo0.getCid());
    CmdletInfo cmdlet1 = cmdletManager.getCmdletInfo(cmdletInfo1.getCid());
    while (cmdlet0.getState() != CmdletState.FAILED && cmdlet1.getState() != CmdletState.DONE) {
        Thread.sleep(100);
    }
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor) MetaStore(org.smartdata.metastore.MetaStore) ActionInfo(org.smartdata.model.ActionInfo) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 2 with CmdletDescriptor

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

the class TestCmdletManager method testGetListDeleteCmdlet.

@Test
public void testGetListDeleteCmdlet() throws Exception {
    waitTillSSMExitSafeMode();
    MetaStore metaStore = ssm.getMetaStore();
    String cmd = "allssd -file /testMoveFile/file1 ; cache -file /testCacheFile ; " + "write -file /test -length 1024";
    CmdletDescriptor cmdletDescriptor = generateCmdletDescriptor(cmd);
    CmdletInfo cmdletInfo = new CmdletInfo(0, cmdletDescriptor.getRuleId(), CmdletState.PENDING, cmdletDescriptor.getCmdletString(), 123178333L, 232444994L);
    CmdletInfo[] cmdlets = { cmdletInfo };
    metaStore.insertCmdlets(cmdlets);
    CmdletManager cmdletManager = ssm.getCmdletManager();
    Assert.assertTrue(cmdletManager.listCmdletsInfo(1, null).size() == 1);
    Assert.assertTrue(cmdletManager.getCmdletInfo(0) != null);
    cmdletManager.deleteCmdlet(0);
    Assert.assertTrue(cmdletManager.listCmdletsInfo(1, null).size() == 0);
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor) MetaStore(org.smartdata.metastore.MetaStore) CmdletInfo(org.smartdata.model.CmdletInfo) Test(org.junit.Test)

Example 3 with CmdletDescriptor

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

the class ErasureCodingPlugin method onNewRuleExecutor.

@Override
public void onNewRuleExecutor(RuleInfo ruleInfo, TranslateResult tResult) {
    long ruleId = ruleInfo.getId();
    CmdletDescriptor des = tResult.getCmdDescriptor();
    for (int i = 0; i < des.getActionSize(); i++) {
        if (des.getActionName(i).equals("ec")) {
            String policy = des.getActionArgs(i).get("-policy");
            if (policy == null) {
                continue;
            }
            if (!ecPolicies.containsKey(ruleId)) {
                ecPolicies.put(ruleId, new ArrayList<String>());
            }
            ecPolicies.get(ruleId).add(policy);
        }
    }
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor)

Example 4 with CmdletDescriptor

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

the class RuleExecutor method submitCmdlets.

private int submitCmdlets(RuleInfo ruleInfo, List<String> files) {
    long ruleId = ruleInfo.getId();
    if (files == null || files.size() == 0 || ruleManager.getCmdletManager() == null) {
        return 0;
    }
    int nSubmitted = 0;
    List<RuleExecutorPlugin> plugins = RuleExecutorPluginManager.getPlugins();
    String template = tr.getCmdDescriptor().toCmdletString();
    for (String file : files) {
        if (!exited) {
            try {
                CmdletDescriptor cmd = new CmdletDescriptor(template, ruleId);
                cmd.setCmdletParameter(CmdletDescriptor.HDFS_FILE_PATH, file);
                for (RuleExecutorPlugin plugin : plugins) {
                    cmd = plugin.preSubmitCmdletDescriptor(ruleInfo, tr, cmd);
                }
                long cid = ruleManager.getCmdletManager().submitCmdlet(cmd);
                // Not really submitted if cid is -1.
                if (cid != -1) {
                    nSubmitted++;
                }
            } catch (QueueFullException e) {
                break;
            } catch (IOException e) {
                // it's common here, ignore this and continue submit
                LOG.debug("Failed to submit cmdlet for file: " + file, e);
            } catch (ParseException e) {
                LOG.error("Failed to submit cmdlet for file: " + file, e);
            }
        } else {
            break;
        }
    }
    return nSubmitted;
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor) QueueFullException(org.smartdata.exception.QueueFullException) RuleExecutorPlugin(org.smartdata.model.rule.RuleExecutorPlugin) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 5 with CmdletDescriptor

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

CmdletDescriptor (org.smartdata.model.CmdletDescriptor)11 Test (org.junit.Test)5 ActionInfo (org.smartdata.model.ActionInfo)3 CmdletInfo (org.smartdata.model.CmdletInfo)3 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 MetaStore (org.smartdata.metastore.MetaStore)2 MetaStoreException (org.smartdata.metastore.MetaStoreException)2 HashMap (java.util.HashMap)1 QueueFullException (org.smartdata.exception.QueueFullException)1 BackUpInfo (org.smartdata.model.BackUpInfo)1 FileDiff (org.smartdata.model.FileDiff)1 RuleExecutorPlugin (org.smartdata.model.rule.RuleExecutorPlugin)1 TranslateResult (org.smartdata.model.rule.TranslateResult)1