use of org.smartdata.model.FileDiff in project SSM by Intel-bigdata.
the class TestFileDiffDao method testUpdate.
@Test
public void testUpdate() {
FileDiff[] fileDiffs = new FileDiff[2];
fileDiffs[0] = new FileDiff();
fileDiffs[0].setDiffId(1);
fileDiffs[0].setRuleId(1);
fileDiffs[0].setParameters(new HashMap<String, String>());
fileDiffs[0].setSrc("test");
fileDiffs[0].setState(FileDiffState.PENDING);
fileDiffs[0].setDiffType(FileDiffType.APPEND);
fileDiffs[0].setCreateTime(1);
fileDiffs[1] = new FileDiff();
fileDiffs[1].setDiffId(2);
fileDiffs[0].setRuleId(1);
fileDiffs[1].setParameters(new HashMap<String, String>());
fileDiffs[1].setSrc("src");
fileDiffs[1].setState(FileDiffState.PENDING);
fileDiffs[1].setDiffType(FileDiffType.APPEND);
fileDiffs[1].setCreateTime(1);
fileDiffDao.insert(fileDiffs);
fileDiffDao.update(1, FileDiffState.RUNNING);
fileDiffs[0].setState(FileDiffState.RUNNING);
Assert.assertTrue(fileDiffDao.getById(1).equals(fileDiffs[0]));
Assert.assertTrue(fileDiffDao.getPendingDiff().size() == 1);
fileDiffs[0].getParameters().put("-offset", "0");
fileDiffs[0].setSrc("test1");
fileDiffs[1].setCreateTime(2);
fileDiffs[1].setRuleId(2);
fileDiffs[1].setDiffType(FileDiffType.RENAME);
fileDiffDao.update(fileDiffs);
Assert.assertTrue(fileDiffDao.getById(1).equals(fileDiffs[0]));
Assert.assertTrue(fileDiffDao.getById(2).equals(fileDiffs[1]));
}
use of org.smartdata.model.FileDiff in project SSM by Intel-bigdata.
the class TestFileDiffDao method testBatchUpdateAndQuery.
@Test
public void testBatchUpdateAndQuery() {
FileDiff[] fileDiffs = new FileDiff[2];
fileDiffs[0] = new FileDiff();
fileDiffs[0].setDiffId(1);
fileDiffs[0].setParameters(new HashMap<String, String>());
fileDiffs[0].setSrc("test");
fileDiffs[0].setState(FileDiffState.RUNNING);
fileDiffs[0].setDiffType(FileDiffType.APPEND);
fileDiffs[0].setCreateTime(1);
fileDiffs[1] = new FileDiff();
fileDiffs[1].setDiffId(2);
fileDiffs[1].setParameters(new HashMap<String, String>());
fileDiffs[1].setSrc("src");
fileDiffs[1].setState(FileDiffState.PENDING);
fileDiffs[1].setDiffType(FileDiffType.APPEND);
fileDiffs[1].setCreateTime(1);
fileDiffDao.insert(fileDiffs);
List<FileDiff> fileInfoList = fileDiffDao.getAll();
for (int i = 0; i < 2; i++) {
Assert.assertTrue(fileInfoList.get(i).equals(fileDiffs[i]));
}
// update
List<Long> dids = new ArrayList<>();
dids.add(1L);
dids.add(2L);
List<String> parameters = new ArrayList<>();
parameters.add(fileDiffs[0].getParametersJsonString());
parameters.add(fileDiffs[1].getParametersJsonString());
List<FileDiffState> fileDiffStates = new ArrayList<>();
fileDiffStates.add(FileDiffState.APPLIED);
fileDiffStates.add(fileDiffs[1].getState());
fileDiffDao.batchUpdate(dids, fileDiffStates, parameters);
fileInfoList = fileDiffDao.getAll();
Assert.assertTrue(fileInfoList.get(0).getState().equals(FileDiffState.APPLIED));
fileDiffDao.batchUpdate(dids, FileDiffState.MERGED);
Assert.assertTrue(fileDiffDao.getAll().get(0).getState().equals(FileDiffState.MERGED));
}
use of org.smartdata.model.FileDiff 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.FileDiff in project SSM by Intel-bigdata.
the class MetaStore method updateFileDiff.
public boolean updateFileDiff(FileDiff fileDiff) throws MetaStoreException {
long did = fileDiff.getDiffId();
FileDiff preFileDiff = getFileDiff(did);
if (preFileDiff == null) {
insertFileDiff(fileDiff);
}
try {
return fileDiffDao.update(fileDiff) >= 0;
} catch (Exception e) {
throw new MetaStoreException(e);
}
}
Aggregations