Search in sources :

Example 16 with Mode

use of alluxio.security.authorization.Mode in project SSM by Intel-bigdata.

the class TestAlluxioEntryFetcher method testEntryFetcher.

@Test
public void testEntryFetcher() throws Exception {
    URI journalLocation = JournalUtils.getJournalLocation();
    SmartConf conf = new SmartConf();
    conf.set(SmartConfKeys.SMART_ALLUXIO_MASTER_JOURNAL_DIR_KEY, journalLocation.getPath());
    EntryApplierForTest entryApplierForTest = new EntryApplierForTest(metaStore, fs);
    final AlluxioEntryFetcher entryFetcher = new AlluxioEntryFetcher(fs, metaStore, Executors.newScheduledThreadPool(2), entryApplierForTest, new Callable() {

        @Override
        public Object call() throws Exception {
            // Do nothing
            return null;
        }
    }, conf);
    Assert.assertFalse(AlluxioEntryFetcher.canReadFromLastSeqNum(100L));
    /**
     * Generate such local structure
     *      ├── foo |
     *              ├── foobar1
     *              └── foobar2
     *      ├── bar |
     *              └── foobar3
     *      └── foobar4
     */
    fs.createDirectory(new AlluxioURI("/foo"));
    fs.createDirectory(new AlluxioURI("/bar"));
    FileSystemTestUtils.createByteFile(fs, "/foo/foobar1", WriteType.CACHE_THROUGH, 10);
    FileSystemTestUtils.createByteFile(fs, "/foo/foobar2", WriteType.CACHE_THROUGH, 20);
    FileSystemTestUtils.createByteFile(fs, "/bar/foobar3", WriteType.CACHE_THROUGH, 30);
    FileSystemTestUtils.createByteFile(fs, "/foobar4", WriteType.CACHE_THROUGH, 40);
    Thread thread = new Thread() {

        public void run() {
            try {
                entryFetcher.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };
    thread.start();
    // need wait long enough to finish namespace fetcher
    Thread.sleep(10 * 1000);
    fs.setAttribute(new AlluxioURI("/foo/foobar1"), SetAttributeOptions.defaults().setPersisted(true));
    fs.setAttribute(new AlluxioURI("/foo/foobar2"), SetAttributeOptions.defaults().setPinned(true));
    fs.setAttribute(new AlluxioURI("/bar/foobar3"), SetAttributeOptions.defaults().setTtl(1000000L));
    String mLocalUfsRoot = mTemporaryFolder.getRoot().getAbsolutePath();
    UnderFileSystem mLocalUfs = UnderFileSystem.Factory.create(mLocalUfsRoot);
    String mountpath = PathUtils.concatPath(mLocalUfsRoot, "mtd_ufs");
    mLocalUfs.mkdirs(mountpath);
    Assert.assertTrue(new File(mountpath).exists());
    fs.mount(new AlluxioURI("/mtd_t"), new AlluxioURI(mountpath), MountOptions.defaults());
    fs.rename(new AlluxioURI("/foo/foobar1"), new AlluxioURI("/foo/foo1"), RenameOptions.defaults());
    fs.delete(new AlluxioURI("/bar/foobar3"), DeleteOptions.defaults().setRecursive(true));
    fs.createDirectory(new AlluxioURI("/baz"));
    FileSystemTestUtils.createByteFile(fs, "/baz/foobar5", WriteType.CACHE_THROUGH, 50);
    Mode mode = new Mode((short) 0755);
    fs.setAttribute(new AlluxioURI("/baz/foobar5"), SetAttributeOptions.defaults().setMode(mode));
    // free action does not generate journal entry
    fs.free(new AlluxioURI("/baz"), FreeOptions.defaults().setRecursive(true));
    while (entryApplierForTest.getEntries().size() != 16) {
        Thread.sleep(100);
    }
    List<JournalEntry> entries = entryApplierForTest.getEntries();
    Assert.assertTrue(entries.get(0).hasSetAttribute() && entries.get(0).getSetAttribute().hasPersisted());
    Assert.assertTrue(entries.get(1).hasSetAttribute() && entries.get(1).getSetAttribute().hasPinned());
    Assert.assertTrue(entries.get(2).hasSetAttribute() && entries.get(2).getSetAttribute().hasTtl());
    Assert.assertTrue(entries.get(3).hasInodeLastModificationTime());
    Assert.assertTrue(entries.get(4).hasInodeDirectoryIdGenerator());
    Assert.assertTrue(entries.get(5).hasInodeDirectory());
    Assert.assertTrue(entries.get(6).hasAddMountPoint());
    Assert.assertTrue(entries.get(7).hasRename());
    Assert.assertTrue(entries.get(8).hasDeleteFile());
    Assert.assertTrue(entries.get(9).hasInodeLastModificationTime());
    Assert.assertTrue(entries.get(10).hasInodeDirectoryIdGenerator());
    Assert.assertTrue(entries.get(11).hasInodeDirectory());
    Assert.assertTrue(entries.get(12).hasInodeLastModificationTime());
    Assert.assertTrue(entries.get(13).hasInodeFile());
    Assert.assertTrue(entries.get(14).hasCompleteFile());
    Assert.assertTrue(entries.get(15).hasSetAttribute() && entries.get(15).getSetAttribute().hasPermission());
    entryFetcher.stop();
    Assert.assertTrue(metaStore.containSystemInfo(SmartConstants.SMART_ALLUXIO_LAST_ENTRY_SN));
    Assert.assertTrue(AlluxioEntryFetcher.canReadFromLastSeqNum(Long.parseLong(metaStore.getSystemInfoByProperty(SmartConstants.SMART_ALLUXIO_LAST_ENTRY_SN).getValue())));
}
Also used : Mode(alluxio.security.authorization.Mode) AlluxioEntryFetcher(org.smartdata.alluxio.metric.fetcher.AlluxioEntryFetcher) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) URI(java.net.URI) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) Callable(java.util.concurrent.Callable) IOException(java.io.IOException) SmartConf(org.smartdata.conf.SmartConf) UnderFileSystem(alluxio.underfs.UnderFileSystem) File(java.io.File) AlluxioURI(alluxio.AlluxioURI)

Example 17 with Mode

use of alluxio.security.authorization.Mode in project alluxio by Alluxio.

the class AlluxioJniFuseFileSystem method chmodInternal.

private int chmodInternal(String path, long mode) {
    AlluxioURI uri = mPathResolverCache.getUnchecked(path);
    SetAttributePOptions options = SetAttributePOptions.newBuilder().setMode(new Mode((short) mode).toProto()).build();
    try {
        mFileSystem.setAttribute(uri, options);
    } catch (Throwable t) {
        LOG.error("Failed to change {} to mode {}", path, mode, t);
        return AlluxioFuseUtils.getErrorCode(t);
    }
    return 0;
}
Also used : SetAttributePOptions(alluxio.grpc.SetAttributePOptions) Mode(alluxio.security.authorization.Mode) AlluxioURI(alluxio.AlluxioURI)

Example 18 with Mode

use of alluxio.security.authorization.Mode in project alluxio by Alluxio.

the class CpCommandIntegrationTest method copyFileWithPreservedAttributes.

/**
 * Tests copying a file with attributes preserved.
 */
@Test
public void copyFileWithPreservedAttributes() throws Exception {
    InstancedConfiguration conf = new InstancedConfiguration(ServerConfiguration.global());
    // avoid chown on UFS since test might not be run with root
    conf.set(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, "MUST_CACHE");
    try (FileSystemShell fsShell = new FileSystemShell(conf)) {
        String testDir = FileSystemShellUtilsTest.resetFileHierarchy(sFileSystem);
        AlluxioURI srcFile = new AlluxioURI(testDir + "/foobar4");
        String owner = TEST_USER_1.getUser();
        String group = "staff";
        short mode = 0422;
        List<AclEntry> entries = new ArrayList<>();
        entries.add(new AclEntry.Builder().setType(AclEntryType.NAMED_USER).setSubject(TEST_USER_2.getUser()).addAction(AclAction.READ).addAction(AclAction.WRITE).addAction(AclAction.EXECUTE).build());
        entries.add(new AclEntry.Builder().setType(AclEntryType.NAMED_GROUP).setSubject(group).addAction(AclAction.WRITE).addAction(AclAction.EXECUTE).build());
        sFileSystem.setAttribute(srcFile, SetAttributePOptions.newBuilder().setOwner(owner).setGroup(group).setMode(new Mode(mode).toProto()).setPinned(true).setReplicationMin(2).setReplicationMax(4).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(12345)).build());
        sFileSystem.setAcl(srcFile, SetAclAction.MODIFY, entries);
        int ret = fsShell.run("cp", "-p", testDir + "/foobar4", testDir + "/bar");
        AlluxioURI dstFile = new AlluxioURI(testDir + "/bar/foobar4");
        Assert.assertEquals(0, ret);
        Assert.assertTrue(sFileSystem.exists(dstFile));
        verifyPreservedAttributes(srcFile, dstFile);
    }
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mode(alluxio.security.authorization.Mode) AclEntry(alluxio.security.authorization.AclEntry) ArrayList(java.util.ArrayList) FileSystemShell(alluxio.cli.fs.FileSystemShell) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AlluxioURI(alluxio.AlluxioURI) AbstractFileSystemShellTest(alluxio.client.cli.fs.AbstractFileSystemShellTest) Test(org.junit.Test) FileSystemShellUtilsTest(alluxio.client.cli.fs.FileSystemShellUtilsTest)

Example 19 with Mode

use of alluxio.security.authorization.Mode in project alluxio by Alluxio.

the class CpCommandIntegrationTest method copyDirectoryWithPreservedAttributes.

/**
 * Tests copying a folder with attributes preserved.
 */
@Test
public void copyDirectoryWithPreservedAttributes() throws Exception {
    InstancedConfiguration conf = new InstancedConfiguration(ServerConfiguration.global());
    conf.set(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, "MUST_CACHE");
    try (FileSystemShell fsShell = new FileSystemShell(conf)) {
        String testDir = FileSystemShellUtilsTest.resetFileHierarchy(sFileSystem);
        String newDir = "/copy";
        String subDir = "/foo";
        String file = "/foobar4";
        String owner = TEST_USER_1.getUser();
        String group = "staff";
        short mode = 0422;
        List<AclEntry> entries = new ArrayList<>();
        entries.add(new AclEntry.Builder().setType(AclEntryType.NAMED_USER).setSubject(TEST_USER_2.getUser()).addAction(AclAction.READ).addAction(AclAction.WRITE).addAction(AclAction.EXECUTE).build());
        entries.add(new AclEntry.Builder().setType(AclEntryType.NAMED_GROUP).setSubject(group).addAction(AclAction.WRITE).addAction(AclAction.EXECUTE).build());
        AlluxioURI srcDir = new AlluxioURI(testDir);
        sFileSystem.setAttribute(srcDir, SetAttributePOptions.newBuilder().setRecursive(true).setOwner(owner).setGroup(group).setMode(new Mode(mode).toProto()).setPinned(true).setReplicationMin(2).setReplicationMax(4).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(12345)).build());
        sFileSystem.setAcl(srcDir, SetAclAction.MODIFY, entries, SetAclPOptions.newBuilder().setRecursive(true).build());
        int ret = fsShell.run("cp", "-R", "-p", testDir, newDir);
        AlluxioURI dstDir = new AlluxioURI(newDir);
        Assert.assertEquals(0, ret);
        Assert.assertTrue(sFileSystem.exists(dstDir));
        verifyPreservedAttributes(srcDir, dstDir);
        verifyPreservedAttributes(srcDir.join(subDir), dstDir.join(subDir));
        verifyPreservedAttributes(srcDir.join(file), dstDir.join(file));
    }
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mode(alluxio.security.authorization.Mode) AclEntry(alluxio.security.authorization.AclEntry) ArrayList(java.util.ArrayList) FileSystemShell(alluxio.cli.fs.FileSystemShell) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AlluxioURI(alluxio.AlluxioURI) AbstractFileSystemShellTest(alluxio.client.cli.fs.AbstractFileSystemShellTest) Test(org.junit.Test) FileSystemShellUtilsTest(alluxio.client.cli.fs.FileSystemShellUtilsTest)

Example 20 with Mode

use of alluxio.security.authorization.Mode in project alluxio by Alluxio.

the class ReadOnlyMountIntegrationTest method chmod.

@Test
public void chmod() throws IOException, AlluxioException {
    AlluxioURI uri = new AlluxioURI(FILE_PATH + "_chmod");
    try {
        mFileSystem.setAttribute(uri, SetAttributePOptions.newBuilder().setMode(new Mode((short) 0555).toProto()).build());
        Assert.fail("chomd should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertThat(e.getMessage(), containsString(ExceptionMessage.MOUNT_READONLY.getMessage(uri, MOUNT_PATH)));
    }
}
Also used : Mode(alluxio.security.authorization.Mode) AccessControlException(alluxio.exception.AccessControlException) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

Mode (alluxio.security.authorization.Mode)78 Test (org.junit.Test)47 AlluxioURI (alluxio.AlluxioURI)43 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)15 UnderFileSystem (alluxio.underfs.UnderFileSystem)14 Random (java.util.Random)14 IOException (java.io.IOException)11 UfsMode (alluxio.underfs.UfsMode)9 URIStatus (alluxio.client.file.URIStatus)8 FileInfo (alluxio.wire.FileInfo)8 ArrayList (java.util.ArrayList)8 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)7 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 WriteType (alluxio.client.WriteType)5 AlluxioException (alluxio.exception.AlluxioException)5 LockedInodePath (alluxio.master.file.meta.LockedInodePath)5 AclEntry (alluxio.security.authorization.AclEntry)5 AuthenticatedClientUserResource (alluxio.AuthenticatedClientUserResource)4 AuthenticatedUserRule (alluxio.AuthenticatedUserRule)4