Search in sources :

Example 1 with BackUpInfo

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

the class TestInotifyEventApplier method testApplierCreateEvent.

@Test
public void testApplierCreateEvent() throws Exception {
    DFSClient client = Mockito.mock(DFSClient.class);
    InotifyEventApplier applier = new InotifyEventApplier(metaStore, client);
    BackUpInfo backUpInfo = new BackUpInfo(1L, "/file1", "remote/dest/", 10);
    metaStore.insertBackUpInfo(backUpInfo);
    HdfsFileStatus status1 = CompatibilityHelperLoader.getHelper().createHdfsFileStatus(0, false, 2, 123, 0, 0, new FsPermission("777"), "test", "group", new byte[0], new byte[0], 1010, 0, null, (byte) 0);
    Mockito.when(client.getFileInfo("/file1")).thenReturn(status1);
    List<Event> events = new ArrayList<>();
    Event.CreateEvent createEvent = new Event.CreateEvent.Builder().path("/file1").defaultBlockSize(123).ownerName("test").replication(2).perms(new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.NONE)).build();
    events.add(createEvent);
    Mockito.when(client.getFileInfo("/file1")).thenReturn(status1);
    applier.apply(events);
    Assert.assertTrue(metaStore.getFile("/file1").getOwner().equals("test"));
    // judge file diff
    List<FileDiff> fileDiffs = metaStore.getFileDiffsByFileName("/file1");
    Assert.assertTrue(fileDiffs.size() > 0);
    for (FileDiff fileDiff : fileDiffs) {
        if (fileDiff.getDiffType().equals(FileDiffType.APPEND)) {
            // find create diff and compare
            Assert.assertTrue(fileDiff.getParameters().get("-owner").equals("test"));
        }
    }
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) BackUpInfo(org.smartdata.model.BackUpInfo) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) ArrayList(java.util.ArrayList) Event(org.apache.hadoop.hdfs.inotify.Event) FileDiff(org.smartdata.model.FileDiff) FsPermission(org.apache.hadoop.fs.permission.FsPermission) Test(org.junit.Test)

Example 2 with BackUpInfo

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

the class TestAlluxioEntryApplier method testRenameApplier.

@Test
public void testRenameApplier() throws Exception {
    FileSystem fs = Mockito.mock(FileSystem.class);
    AlluxioEntryApplier entryApplier = new AlluxioEntryApplier(metaStore, fs);
    FileInfo fooFile = FileInfo.newBuilder().setFileId(50331647).setIsdir(false).setPath("/bar/foobar1").build();
    metaStore.insertFile(fooFile);
    BackUpInfo backUpInfo = new BackUpInfo(1L, "/bar/foobar1", "remote/dest/", 10);
    metaStore.insertBackUpInfo(backUpInfo);
    alluxio.wire.FileInfo info1 = new alluxio.wire.FileInfo().setFileId(50331647).setPath("/bar/foobar1").setLength(300L).setFolder(false).setBlockSizeBytes(310000).setLastModificationTimeMs(1515665270681L).setCreationTimeMs(1515665270681L).setMode(493).setOwner("user1").setGroup("group1");
    URIStatus status1 = new URIStatus(info1);
    Mockito.when(fs.getStatus(new AlluxioURI("/bar/foobar1"))).thenReturn(status1);
    RenameEntry renameEntry = RenameEntry.newBuilder().setId(50331647).setOpTimeMs(1515666148444L).setDstPath("/bar/foobar1_new").build();
    JournalEntry renameJEntry = JournalEntry.newBuilder().setRename(renameEntry).build();
    entryApplier.apply(renameJEntry);
    List<FileDiff> fileDiffs = metaStore.getFileDiffsByFileName("/bar/foobar1");
    Assert.assertTrue(fileDiffs.size() > 0);
    for (FileDiff fileDiff : fileDiffs) {
        if (fileDiff.getDiffType().equals(FileDiffType.RENAME)) {
            Assert.assertEquals("/bar/foobar1", fileDiff.getSrc());
            Assert.assertEquals("/bar/foobar1_new", fileDiff.getParameters().get("-dest"));
        }
    }
}
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 3 with BackUpInfo

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

the class TestAlluxioEntryApplier method testInodeLastMTimeApplier.

@Test
public void testInodeLastMTimeApplier() throws Exception {
    FileSystem fs = Mockito.mock(FileSystem.class);
    AlluxioEntryApplier entryApplier = new AlluxioEntryApplier(metaStore, fs);
    FileInfo fooFile = FileInfo.newBuilder().setFileId(5).setIsdir(true).setPath("/baz").build();
    metaStore.insertFile(fooFile);
    BackUpInfo backUpInfo = new BackUpInfo(1L, "/baz", "remote/dest/", 10);
    metaStore.insertBackUpInfo(backUpInfo);
    alluxio.wire.FileInfo info1 = new alluxio.wire.FileInfo().setFileId(5).setPath("/baz").setLength(0L).setFolder(true).setBlockSizeBytes(1000000).setLastModificationTimeMs(1515665470681L).setCreationTimeMs(1515665470681L).setMode(493).setOwner("user1").setGroup("group1");
    URIStatus status1 = new URIStatus(info1);
    Mockito.when(fs.getStatus(new AlluxioURI("/baz"))).thenReturn(status1);
    InodeLastModificationTimeEntry inodeLastMTimeEntry = InodeLastModificationTimeEntry.newBuilder().setId(5).setLastModificationTimeMs(1515667810911L).build();
    JournalEntry inodeLastMTimeJEntry = JournalEntry.newBuilder().setInodeLastModificationTime(inodeLastMTimeEntry).build();
    entryApplier.apply(inodeLastMTimeJEntry);
    List<FileDiff> fileDiffs = metaStore.getFileDiffsByFileName("/baz");
    Assert.assertTrue(fileDiffs.size() > 0);
    for (FileDiff fileDiff : fileDiffs) {
        if (fileDiff.getDiffType().equals(FileDiffType.METADATA)) {
            Assert.assertEquals("/baz", fileDiff.getSrc());
            Assert.assertEquals("1515667810911", fileDiff.getParameters().get("-mtime"));
        }
    }
}
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 4 with BackUpInfo

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

the class TestAlluxioEntryApplier method testInodeFileApplier.

@Test
public void testInodeFileApplier() throws Exception {
    FileSystem fs = Mockito.mock(FileSystem.class);
    AlluxioEntryApplier entryApplier = new AlluxioEntryApplier(metaStore, fs);
    FileInfo fooDir = FileInfo.newBuilder().setFileId(6).setIsdir(true).setPath("/foo").build();
    metaStore.insertFile(fooDir);
    BackUpInfo backUpInfo = new BackUpInfo(1L, "/foo/foobar1", "remote/dest/", 10);
    metaStore.insertBackUpInfo(backUpInfo);
    alluxio.wire.FileInfo info1 = new alluxio.wire.FileInfo().setFileId(33554431).setPath("/foo/foobar1").setLength(10L).setFolder(false).setBlockSizeBytes(536870912).setLastModificationTimeMs(1515665470681L).setCreationTimeMs(1515665470681L).setMode(420).setOwner("user1").setGroup("group1");
    URIStatus status1 = new URIStatus(info1);
    Mockito.when(fs.getStatus(new AlluxioURI("/foo/foobar1"))).thenReturn(status1);
    InodeFileEntry inodeFileEntry = InodeFileEntry.newBuilder().setId(33554431).setParentId(6).setName("foobar1").setPersistenceState("NOT_PERSISTED").setPinned(false).setCreationTimeMs(1515665470681L).setBlockSizeBytes(536870912).setLength(10L).setCompleted(false).setCacheable(true).setTtl(-1L).setOwner("user1").setGroup("group1").setMode(420).setTtlAction(PTtlAction.DELETE).build();
    JournalEntry inodeFileJEntry = JournalEntry.newBuilder().setInodeFile(inodeFileEntry).build();
    entryApplier.apply(inodeFileJEntry);
    Assert.assertEquals(33554431, metaStore.getFile("/foo/foobar1").getFileId());
    Assert.assertEquals("user1", metaStore.getFile("/foo/foobar1").getOwner());
    Assert.assertEquals(536870912, metaStore.getFile("/foo/foobar1").getBlocksize());
    List<FileDiff> fileDiffs = metaStore.getFileDiffsByFileName("/foo/foobar1");
    Assert.assertTrue(fileDiffs.size() > 0);
    for (FileDiff fileDiff : fileDiffs) {
        if (fileDiff.getDiffType().equals(FileDiffType.APPEND)) {
            Assert.assertTrue(fileDiff.getParameters().get("-owner").equals("user1"));
            Assert.assertTrue(fileDiff.getParameters().get("-mtime").equals("1515665470681"));
            Assert.assertTrue(fileDiff.getParameters().get("-length").equals("10"));
        }
    }
}
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 5 with BackUpInfo

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

the class TestAlluxioEntryApplier method testDeleteFileApplier.

@Test
public void testDeleteFileApplier() throws Exception {
    FileSystem fs = Mockito.mock(FileSystem.class);
    AlluxioEntryApplier entryApplier = new AlluxioEntryApplier(metaStore, fs);
    FileInfo fooFile = FileInfo.newBuilder().setFileId(100663295).setIsdir(false).setPath("/foo/foobar_del").build();
    metaStore.insertFile(fooFile);
    BackUpInfo backUpInfo = new BackUpInfo(1L, "/foo/foobar_del", "remote/dest/", 10);
    metaStore.insertBackUpInfo(backUpInfo);
    alluxio.wire.FileInfo info1 = new alluxio.wire.FileInfo().setFileId(100663295).setPath("/foo/foobar_del").setLength(500L).setFolder(false).setBlockSizeBytes(510000).setLastModificationTimeMs(1515665270681L).setCreationTimeMs(1515665270681L).setMode(493).setOwner("user1").setGroup("group1");
    URIStatus status1 = new URIStatus(info1);
    Mockito.when(fs.getStatus(new AlluxioURI("/foo/foobar_del"))).thenReturn(status1);
    DeleteFileEntry deleteFileEntry = DeleteFileEntry.newBuilder().setId(100663295).setOpTimeMs(1515737580798L).setAlluxioOnly(true).setRecursive(false).build();
    JournalEntry deleteFileJEntry = JournalEntry.newBuilder().setDeleteFile(deleteFileEntry).build();
    entryApplier.apply(deleteFileJEntry);
    List<FileDiff> fileDiffs = metaStore.getFileDiffsByFileName("/foo/foobar_del");
    Assert.assertTrue(fileDiffs.size() > 0);
    for (FileDiff fileDiff : fileDiffs) {
        if (fileDiff.getDiffType().equals(FileDiffType.DELETE)) {
            Assert.assertEquals("/foo/foobar_del", fileDiff.getSrc());
        }
    }
}
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)

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