Search in sources :

Example 16 with BackUpInfo

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

the class TestBackUpInfoDao method testInsertAndGetSingleRecord.

@Test
public void testInsertAndGetSingleRecord() {
    BackUpInfo backUpInfo = new BackUpInfo();
    backUpInfo.setRid(1);
    backUpInfo.setPeriod(1);
    backUpInfo.setDest("");
    backUpInfo.setSrc("");
    backUpInfoDao.insert(backUpInfo);
    Assert.assertTrue(backUpInfoDao.getByRid(1).equals(backUpInfo));
}
Also used : BackUpInfo(org.smartdata.model.BackUpInfo) Test(org.junit.Test)

Example 17 with BackUpInfo

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

the class TestBackUpInfoDao method testDelete.

@Test
public void testDelete() {
    backUpInfoDao.delete(1L);
    BackUpInfo[] backUpInfos = new BackUpInfo[2];
    backUpInfos[0] = new BackUpInfo(1, "test", "test", 1);
    backUpInfos[1] = new BackUpInfo(2, "test", "test", 1);
    backUpInfoDao.insert(backUpInfos);
    backUpInfoDao.delete(1L);
    Assert.assertTrue(backUpInfoDao.getByRid(2).equals(backUpInfos[1]));
    try {
        backUpInfoDao.getByRid(1);
    } catch (EmptyResultDataAccessException e) {
    }
}
Also used : BackUpInfo(org.smartdata.model.BackUpInfo) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Test(org.junit.Test)

Example 18 with BackUpInfo

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

the class TestMetaStore method testInsertAndListAllBackUpInfo.

@Test
public void testInsertAndListAllBackUpInfo() throws MetaStoreException {
    BackUpInfo backUpInfo1 = new BackUpInfo(1, "test1", "test1", 1);
    BackUpInfo backUpInfo2 = new BackUpInfo(2, "test2", "test2", 2);
    BackUpInfo backUpInfo3 = new BackUpInfo(3, "test3", "test3", 3);
    metaStore.insertBackUpInfo(backUpInfo1);
    metaStore.insertBackUpInfo(backUpInfo2);
    metaStore.insertBackUpInfo(backUpInfo3);
    List<BackUpInfo> backUpInfos = metaStore.listAllBackUpInfo();
    Assert.assertTrue(backUpInfos.get(0).equals(backUpInfo1));
    Assert.assertTrue(backUpInfos.get(1).equals(backUpInfo2));
    Assert.assertTrue(backUpInfos.get(2).equals(backUpInfo3));
}
Also used : BackUpInfo(org.smartdata.model.BackUpInfo) Test(org.junit.Test)

Example 19 with BackUpInfo

use of org.smartdata.model.BackUpInfo 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 20 with BackUpInfo

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

the class MetaStore method srcInbackup.

public boolean srcInbackup(String src) throws MetaStoreException {
    if (setBackSrc == null) {
        setBackSrc = new HashSet<>();
        List<BackUpInfo> backUpInfos = listAllBackUpInfo();
        for (BackUpInfo backUpInfo : backUpInfos) {
            setBackSrc.add(backUpInfo.getSrc());
        }
    }
    // LOG.info("Backup src = {}, setBackSrc {}", src, setBackSrc);
    for (String srcDir : setBackSrc) {
        if (src.startsWith(srcDir)) {
            return true;
        }
    }
    return false;
}
Also used : BackUpInfo(org.smartdata.model.BackUpInfo)

Aggregations

BackUpInfo (org.smartdata.model.BackUpInfo)20 Test (org.junit.Test)16 FileDiff (org.smartdata.model.FileDiff)9 FileInfo (org.smartdata.model.FileInfo)7 AlluxioURI (alluxio.AlluxioURI)5 FileSystem (alluxio.client.file.FileSystem)5 URIStatus (alluxio.client.file.URIStatus)5 JournalEntry (alluxio.proto.journal.Journal.JournalEntry)5 AlluxioEntryApplier (org.smartdata.alluxio.metric.fetcher.AlluxioEntryApplier)5 ArrayList (java.util.ArrayList)3 FsPermission (org.apache.hadoop.fs.permission.FsPermission)2 DFSClient (org.apache.hadoop.hdfs.DFSClient)2 Event (org.apache.hadoop.hdfs.inotify.Event)2 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)2 RuleInfo (org.smartdata.model.RuleInfo)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 MetaStoreException (org.smartdata.metastore.MetaStoreException)1 ActionInfo (org.smartdata.model.ActionInfo)1