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