Search in sources :

Example 11 with BackUpInfo

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

the class InotifyEventApplier method insertDeleteDiff.

private void insertDeleteDiff(String path) throws MetaStoreException {
    // TODO: remove "/" appended in src or dest in backup_file table
    String pathWithSlash = path.endsWith("/") ? path : path + "/";
    if (inBackup(pathWithSlash)) {
        List<BackUpInfo> backUpInfos = metaStore.getBackUpInfoBySrc(pathWithSlash);
        for (BackUpInfo backUpInfo : backUpInfos) {
            String destPath = pathWithSlash.replaceFirst(backUpInfo.getSrc(), backUpInfo.getDest());
            try {
                // tackle root path case
                URI namenodeUri = new URI(destPath);
                String root = "hdfs://" + namenodeUri.getHost() + ":" + String.valueOf(namenodeUri.getPort());
                if (destPath.equals(root) || destPath.equals(root + "/") || destPath.equals("/")) {
                    for (String srcFilePath : getFilesUnderDir(pathWithSlash)) {
                        FileDiff fileDiff = new FileDiff(FileDiffType.DELETE);
                        fileDiff.setSrc(srcFilePath);
                        String destFilePath = srcFilePath.replaceFirst(backUpInfo.getSrc(), backUpInfo.getDest());
                        fileDiff.getParameters().put("-dest", destFilePath);
                        metaStore.insertFileDiff(fileDiff);
                    }
                } else {
                    FileDiff fileDiff = new FileDiff(FileDiffType.DELETE);
                    // use the path getting from event with no slash appended
                    fileDiff.setSrc(path);
                    // put sync's dest path in parameter for delete use
                    fileDiff.getParameters().put("-dest", destPath);
                    metaStore.insertFileDiff(fileDiff);
                }
            } catch (URISyntaxException e) {
                LOG.error("Error occurs!", e);
            }
        }
    }
}
Also used : BackUpInfo(org.smartdata.model.BackUpInfo) FileDiff(org.smartdata.model.FileDiff) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 12 with BackUpInfo

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

the class TestAlluxioEntryApplier method testSetAttributeApplier.

@Test
public void testSetAttributeApplier() throws Exception {
    FileSystem fs = Mockito.mock(FileSystem.class);
    AlluxioEntryApplier entryApplier = new AlluxioEntryApplier(metaStore, fs);
    FileInfo fooFile = FileInfo.newBuilder().setFileId(33554431).setIsdir(false).setPath("/foo/foobar").build();
    metaStore.insertFile(fooFile);
    BackUpInfo backUpInfo = new BackUpInfo(1L, "/foo/foobar", "remote/dest/", 10);
    metaStore.insertBackUpInfo(backUpInfo);
    alluxio.wire.FileInfo info1 = new alluxio.wire.FileInfo().setFileId(33554431).setPath("/foo/foobar").setLength(100L).setFolder(false).setBlockSizeBytes(210000).setLastModificationTimeMs(1515665470681L).setCreationTimeMs(1515665470681L).setMode(493).setOwner("user1").setGroup("group1");
    URIStatus status1 = new URIStatus(info1);
    Mockito.when(fs.getStatus(new AlluxioURI("/foo/foobar"))).thenReturn(status1);
    SetAttributeEntry setAttributeEntry = SetAttributeEntry.newBuilder().setId(33554431).setOpTimeMs(1515667208590658L).setPermission(511).build();
    JournalEntry setAttributeJEntry = JournalEntry.newBuilder().setSetAttribute(setAttributeEntry).build();
    entryApplier.apply(setAttributeJEntry);
    List<FileDiff> fileDiffs = metaStore.getFileDiffsByFileName("/foo/foobar");
    Assert.assertTrue(fileDiffs.size() > 0);
    for (FileDiff fileDiff : fileDiffs) {
        if (fileDiff.getDiffType().equals(FileDiffType.METADATA)) {
            Assert.assertEquals("511", fileDiff.getParameters().get("-permission"));
        }
    }
}
Also used : AlluxioEntryApplier(org.smartdata.alluxio.metric.fetcher.AlluxioEntryApplier) URIStatus(alluxio.client.file.URIStatus) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) FileInfo(org.smartdata.model.FileInfo) BackUpInfo(org.smartdata.model.BackUpInfo) FileSystem(alluxio.client.file.FileSystem) FileDiff(org.smartdata.model.FileDiff) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 13 with BackUpInfo

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

the class TestMetaStore method testDeleteBackUpInfo.

@Test
public void testDeleteBackUpInfo() throws MetaStoreException {
    BackUpInfo backUpInfo1 = new BackUpInfo(1, "test1", "test1", 1);
    metaStore.insertBackUpInfo(backUpInfo1);
    Assert.assertTrue(metaStore.srcInbackup("test1/dfafdsaf"));
    Assert.assertFalse(metaStore.srcInbackup("test2"));
    metaStore.deleteBackUpInfo(1);
    Assert.assertTrue(metaStore.listAllBackUpInfo().size() == 0);
    metaStore.insertBackUpInfo(backUpInfo1);
    metaStore.deleteAllBackUpInfo();
    Assert.assertTrue(metaStore.listAllBackUpInfo().size() == 0);
}
Also used : BackUpInfo(org.smartdata.model.BackUpInfo) Test(org.junit.Test)

Example 14 with BackUpInfo

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

the class TestMetaStore method testGetBackUpInfoById.

@Test
public void testGetBackUpInfoById() throws MetaStoreException {
    BackUpInfo backUpInfo1 = new BackUpInfo(1, "test1", "test1", 1);
    metaStore.insertBackUpInfo(backUpInfo1);
    Assert.assertTrue(metaStore.getBackUpInfo(1).equals(backUpInfo1));
}
Also used : BackUpInfo(org.smartdata.model.BackUpInfo) Test(org.junit.Test)

Example 15 with BackUpInfo

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

the class TestBackUpInfoDao method testUpdate.

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

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