Search in sources :

Example 6 with CmdletDescriptor

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

the class TestCmdletManager method testCreateFromDescriptor.

@Test
public void testCreateFromDescriptor() throws Exception {
    waitTillSSMExitSafeMode();
    String cmd = "allssd -file /testMoveFile/file1 ; cache -file /testCacheFile ; " + "write -file /test -length 1024";
    CmdletDescriptor cmdletDescriptor = generateCmdletDescriptor(cmd);
    List<ActionInfo> actionInfos = ssm.getCmdletManager().createActionInfos(cmdletDescriptor, 0);
    Assert.assertTrue(cmdletDescriptor.getActionSize() == actionInfos.size());
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor) ActionInfo(org.smartdata.model.ActionInfo) Test(org.junit.Test)

Example 7 with CmdletDescriptor

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

the class TestCmdletManager method generateCmdletDescriptor.

private CmdletDescriptor generateCmdletDescriptor(String cmd) throws Exception {
    CmdletDescriptor cmdletDescriptor = new CmdletDescriptor(cmd);
    cmdletDescriptor.setRuleId(1);
    return cmdletDescriptor;
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor)

Example 8 with CmdletDescriptor

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

the class SmartRuleStringParser method translate.

public TranslateResult translate() throws IOException {
    TranslateResult tr = doTranslate(rule);
    CmdletDescriptor cmdDes = tr.getCmdDescriptor();
    if (cmdDes.getActionSize() == 0) {
        throw new IOException("No cmdlet specified in Rule");
    }
    String actName = cmdDes.getActionName(0);
    if (cmdDes.getActionSize() != 1 || optCond.get(actName) == null) {
        return tr;
    }
    String repl = optCond.get(actName);
    if (cmdDes.getActionName(0).equals("ec") || cmdDes.getActionName(0).equals("unec")) {
        String policy;
        if (cmdDes.getActionName(0).equals("ec")) {
            policy = cmdDes.getActionArgs(0).get("-policy");
            if (policy == null) {
                policy = conf.getTrimmed("dfs.namenode.ec.system.default.policy", "RS-6-3-1024k");
            }
        } else {
            policy = SmartConstants.REPLICATION_CODEC_NAME;
        }
        repl = "ecPolicy != \"" + policy + "\"";
    }
    int[] condPosition = tr.getCondPosition();
    String cond = rule.substring(condPosition[0], condPosition[1] + 1);
    String optRule = rule.replace(cond, repl + " and (" + cond + ")");
    return doTranslate(optRule);
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor) TranslateResult(org.smartdata.model.rule.TranslateResult) IOException(java.io.IOException)

Example 9 with CmdletDescriptor

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

the class FileCopyDrPlugin method onNewRuleExecutor.

public void onNewRuleExecutor(final RuleInfo ruleInfo, TranslateResult tResult) {
    long ruleId = ruleInfo.getId();
    List<String> pathsCheckGlob = tResult.getGlobPathCheck();
    if (pathsCheckGlob.size() == 0) {
        pathsCheckGlob = Arrays.asList("/*");
    }
    List<String> pathsCheck = getPathMatchesList(pathsCheckGlob);
    String dirs = StringUtil.join(",", pathsCheck);
    CmdletDescriptor des = tResult.getCmdDescriptor();
    for (int i = 0; i < des.getActionSize(); i++) {
        if (des.getActionName(i).equals("sync")) {
            List<String> statements = tResult.getSqlStatements();
            String before = statements.get(statements.size() - 1);
            String after = before.replace(";", " UNION " + referenceNonExists(tResult, pathsCheck));
            statements.set(statements.size() - 1, after);
            BackUpInfo backUpInfo = new BackUpInfo();
            backUpInfo.setRid(ruleId);
            backUpInfo.setSrc(dirs);
            String dest = des.getActionArgs(i).get(SyncAction.DEST);
            if (!dest.endsWith("/")) {
                dest += "/";
                des.addActionArg(i, SyncAction.DEST, dest);
            }
            backUpInfo.setDest(dest);
            backUpInfo.setPeriod(tResult.getTbScheduleInfo().getMinimalEvery());
            des.addActionArg(i, SyncAction.SRC, dirs);
            LOG.debug("Rule executor added for sync rule {} src={}  dest={}", ruleInfo, dirs, dest);
            synchronized (backups) {
                if (!backups.containsKey(ruleId)) {
                    backups.put(ruleId, new LinkedList<BackUpInfo>());
                }
            }
            List<BackUpInfo> infos = backups.get(ruleId);
            synchronized (infos) {
                try {
                    metaStore.deleteBackUpInfo(ruleId);
                    // Add base Sync tag
                    FileDiff fileDiff = new FileDiff(FileDiffType.BASESYNC);
                    fileDiff.setSrc(backUpInfo.getSrc());
                    fileDiff.getParameters().put("-dest", backUpInfo.getDest());
                    metaStore.insertFileDiff(fileDiff);
                    metaStore.insertBackUpInfo(backUpInfo);
                    infos.add(backUpInfo);
                } catch (MetaStoreException e) {
                    LOG.error("Insert backup info error:" + backUpInfo, e);
                }
            }
            break;
        }
    }
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor) MetaStoreException(org.smartdata.metastore.MetaStoreException) BackUpInfo(org.smartdata.model.BackUpInfo) FileDiff(org.smartdata.model.FileDiff)

Example 10 with CmdletDescriptor

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

the class TestCmdletDescriptor method testTrans.

@Test
public void testTrans() throws Exception {
    CmdletDescriptor des = new CmdletDescriptor();
    Map<String, String> args1 = new HashMap<>();
    args1.put("-filePath", "/dir/foo x");
    args1.put("-len", "100");
    Map<String, String> args2 = new HashMap<>();
    args2.put("-version", "");
    Map<String, String> args3 = new HashMap<>();
    args3.put("-storage", "ONE_SSD");
    args3.put("-time", "2016-03-19 19:42:00");
    des.addAction("action1", args1);
    des.addAction("action2", args2);
    des.addAction("action3", args3);
    String cmdString = des.getCmdletString();
    CmdletDescriptor transDes = new CmdletDescriptor(cmdString);
    Assert.assertTrue(des.getActionSize() == transDes.getActionSize());
    Assert.assertTrue(transDes.equals(des));
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor) HashMap(java.util.HashMap) Test(org.junit.Test)

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