Search in sources :

Example 21 with FileDiff

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]));
}
Also used : FileDiff(org.smartdata.model.FileDiff) Test(org.junit.Test)

Example 22 with FileDiff

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));
}
Also used : FileDiffState(org.smartdata.model.FileDiffState) ArrayList(java.util.ArrayList) FileDiff(org.smartdata.model.FileDiff) Test(org.junit.Test)

Example 23 with FileDiff

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;
        }
    }
}
Also used : CmdletDescriptor(org.smartdata.model.CmdletDescriptor) MetaStoreException(org.smartdata.metastore.MetaStoreException) BackUpInfo(org.smartdata.model.BackUpInfo) FileDiff(org.smartdata.model.FileDiff)

Example 24 with FileDiff

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);
    }
}
Also used : FileDiff(org.smartdata.model.FileDiff) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) SQLException(java.sql.SQLException)

Aggregations

FileDiff (org.smartdata.model.FileDiff)24 Test (org.junit.Test)12 FileInfo (org.smartdata.model.FileInfo)12 BackUpInfo (org.smartdata.model.BackUpInfo)9 AlluxioURI (alluxio.AlluxioURI)8 URIStatus (alluxio.client.file.URIStatus)8 ArrayList (java.util.ArrayList)6 FileSystem (alluxio.client.file.FileSystem)5 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)5 AlluxioEntryApplier (org.smartdata.alluxio.metric.fetcher.AlluxioEntryApplier)5 IOException (java.io.IOException)4 AlluxioException (alluxio.exception.AlluxioException)3 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)3 FsPermission (org.apache.hadoop.fs.permission.FsPermission)2 DFSClient (org.apache.hadoop.hdfs.DFSClient)2 Event (org.apache.hadoop.hdfs.inotify.Event)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1