Search in sources :

Example 1 with UserState

use of alluxio.security.user.UserState in project alluxio by Alluxio.

the class GrpcSecurityTest method createServer.

private GrpcServer createServer(AuthType authType) {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, authType.name());
    InetSocketAddress bindAddress = new InetSocketAddress(NetworkAddressUtils.getLocalHostName((int) mConfiguration.getMs(PropertyKey.NETWORK_HOST_RESOLUTION_TIMEOUT_MS)), 0);
    UserState us = UserState.Factory.create(mConfiguration);
    GrpcServerBuilder serverBuilder = GrpcServerBuilder.forAddress(GrpcServerAddress.create("localhost", bindAddress), mConfiguration, us);
    return serverBuilder.build();
}
Also used : GrpcServerBuilder(alluxio.grpc.GrpcServerBuilder) UserState(alluxio.security.user.UserState) InetSocketAddress(java.net.InetSocketAddress)

Example 2 with UserState

use of alluxio.security.user.UserState in project alluxio by Alluxio.

the class RemoteReadIntegrationTest method before.

@Before
public final void before() throws Exception {
    mFileSystem = mLocalAlluxioClusterResource.get().getClient();
    UserState us = UserState.Factory.create(ServerConfiguration.global());
    mFsContext = FileSystemContext.create(us.getSubject(), ServerConfiguration.global());
    mWriteAlluxio = CreateFilePOptions.newBuilder().setWriteType(WritePType.MUST_CACHE).setRecursive(true).build();
    mWriteUnderStore = CreateFilePOptions.newBuilder().setWriteType(WritePType.THROUGH).setRecursive(true).build();
    mReadCache = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE_PROMOTE).build();
    mReadNoCache = OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build();
}
Also used : UserState(alluxio.security.user.UserState) Before(org.junit.Before)

Example 3 with UserState

use of alluxio.security.user.UserState in project alluxio by Alluxio.

the class PersistenceTest method retryPersistJobRenameDelete.

/**
 * Tests that a persist file job is retried after the file is renamed and the src directory is
 * deleted.
 */
@Test(timeout = 20000)
public void retryPersistJobRenameDelete() throws Exception {
    UserState s = UserState.Factory.create(ServerConfiguration.global());
    AuthenticatedClientUser.set(s.getUser().getName());
    // Create src file and directory, checking the internal state.
    AlluxioURI alluxioDirSrc = new AlluxioURI("/src");
    mFileSystemMaster.createDirectory(alluxioDirSrc, CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
    AlluxioURI alluxioFileSrc = new AlluxioURI("/src/in_alluxio");
    FileInfo info = mFileSystemMaster.createFile(alluxioFileSrc, CreateFileContext.defaults().setWriteType(WriteType.MUST_CACHE));
    Assert.assertEquals(PersistenceState.NOT_PERSISTED.toString(), info.getPersistenceState());
    mFileSystemMaster.completeFile(alluxioFileSrc, CompleteFileContext.defaults());
    // Schedule the async persistence, checking the internal state.
    mFileSystemMaster.scheduleAsyncPersistence(alluxioFileSrc, ScheduleAsyncPersistenceContext.defaults());
    checkPersistenceRequested(alluxioFileSrc);
    // Mock the job service interaction.
    Random random = new Random();
    long jobId = random.nextLong();
    Mockito.when(mMockJobMasterClient.run(any(JobConfig.class))).thenReturn(jobId);
    // Execute the persistence scheduler heartbeat, checking the internal state.
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_PERSISTENCE_SCHEDULER);
    CommonUtils.waitFor("Scheduler heartbeat", (() -> getPersistJobs().size() > 0));
    checkPersistenceInProgress(alluxioFileSrc, jobId);
    // Mock the job service interaction.
    JobInfo jobInfo = createJobInfo(Status.CREATED);
    Mockito.when(mMockJobMasterClient.getJobStatus(Mockito.anyLong())).thenReturn(jobInfo);
    // Execute the persistence checker heartbeat, checking the internal state.
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_PERSISTENCE_CHECKER);
    CommonUtils.waitFor("Checker heartbeat", (() -> getPersistJobs().size() > 0));
    checkPersistenceInProgress(alluxioFileSrc, jobId);
    // Mock the job service interaction.
    jobInfo = createJobInfo(Status.COMPLETED);
    Mockito.when(mMockJobMasterClient.getJobStatus(Mockito.anyLong())).thenReturn(jobInfo);
    // Create the temporary UFS file.
    {
        Map<Long, PersistJob> persistJobs = getPersistJobs();
        PersistJob job = persistJobs.get(info.getFileId());
        UnderFileSystem ufs = UnderFileSystem.Factory.create(job.getTempUfsPath().toString(), UnderFileSystemConfiguration.defaults(ServerConfiguration.global()));
        UnderFileSystemUtils.touch(ufs, job.getTempUfsPath());
    }
    // Rename the src file before the persist is commited.
    mFileSystemMaster.createDirectory(new AlluxioURI("/dst"), CreateDirectoryContext.defaults().setWriteType(WriteType.CACHE_THROUGH));
    AlluxioURI alluxioFileDst = new AlluxioURI("/dst/in_alluxio");
    mFileSystemMaster.rename(alluxioFileSrc, alluxioFileDst, RenameContext.defaults());
    // Delete the src directory recursively.
    mFileSystemMaster.delete(alluxioDirSrc, DeleteContext.mergeFrom(DeletePOptions.newBuilder().setRecursive(true)));
    // Repeatedly execute the persistence checker heartbeat, checking the internal state.
    {
        // Execute the persistence checker heartbeat, checking the internal state. This should
        // write the persist file to renamed destination.
        HeartbeatScheduler.execute(HeartbeatContext.MASTER_PERSISTENCE_CHECKER);
        waitUntilPersisted(alluxioFileDst);
        HeartbeatScheduler.execute(HeartbeatContext.MASTER_PERSISTENCE_CHECKER);
        waitUntilPersisted(alluxioFileDst);
    }
}
Also used : UserState(alluxio.security.user.UserState) FileInfo(alluxio.wire.FileInfo) Random(java.util.Random) JobInfo(alluxio.job.wire.JobInfo) UnderFileSystem(alluxio.underfs.UnderFileSystem) Map(java.util.Map) JobConfig(alluxio.job.JobConfig) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with UserState

use of alluxio.security.user.UserState in project alluxio by Alluxio.

the class PersistenceTest method before.

@Before
public void before() throws Exception {
    UserState s = UserState.Factory.create(ServerConfiguration.global());
    AuthenticatedClientUser.set(s.getUser().getName());
    TemporaryFolder tmpFolder = new TemporaryFolder();
    tmpFolder.create();
    File ufsRoot = tmpFolder.newFolder();
    ServerConfiguration.set(PropertyKey.MASTER_JOURNAL_TYPE, JournalType.UFS);
    ServerConfiguration.set(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS, ufsRoot.getAbsolutePath());
    ServerConfiguration.set(PropertyKey.MASTER_PERSISTENCE_INITIAL_INTERVAL_MS, 0);
    ServerConfiguration.set(PropertyKey.MASTER_PERSISTENCE_MAX_INTERVAL_MS, 1000);
    ServerConfiguration.set(PropertyKey.MASTER_PERSISTENCE_MAX_TOTAL_WAIT_TIME_MS, 1000);
    mJournalFolder = tmpFolder.newFolder();
    mSafeModeManager = new DefaultSafeModeManager();
    mStartTimeMs = System.currentTimeMillis();
    mPort = ServerConfiguration.getInt(PropertyKey.MASTER_RPC_PORT);
    startServices();
}
Also used : UserState(alluxio.security.user.UserState) TemporaryFolder(org.junit.rules.TemporaryFolder) DefaultSafeModeManager(alluxio.master.DefaultSafeModeManager) File(java.io.File) Before(org.junit.Before)

Example 5 with UserState

use of alluxio.security.user.UserState in project alluxio by Alluxio.

the class GrpcSecurityTest method testAuthenticationRevoked.

@Test
public void testAuthenticationRevoked() throws Exception {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName());
    mConfiguration.set(PropertyKey.AUTHENTICATION_INACTIVE_CHANNEL_REAUTHENTICATE_PERIOD, "250ms");
    GrpcServer server = createServer(AuthType.SIMPLE);
    try {
        server.start();
        UserState us = UserState.Factory.create(mConfiguration);
        GrpcChannel channel = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration).setSubject(us.getSubject()).build();
        Assert.assertTrue(channel.isHealthy());
        /*
       * Sleeping will ensure that authentication sessions for the channel will expire on the
       * server. This should have propagated back to the client and its health status should reflect
       * that.
       *
       * Sleep more than authentication revocation timeout.
       */
        Thread.sleep(500);
        Assert.assertFalse(channel.isHealthy());
    } finally {
        server.shutdown();
    }
}
Also used : UserState(alluxio.security.user.UserState) GrpcServer(alluxio.grpc.GrpcServer) GrpcChannel(alluxio.grpc.GrpcChannel) Test(org.junit.Test)

Aggregations

UserState (alluxio.security.user.UserState)11 Test (org.junit.Test)5 GrpcServer (alluxio.grpc.GrpcServer)3 Before (org.junit.Before)3 AlluxioURI (alluxio.AlluxioURI)2 FileSystemMasterClient (alluxio.client.file.FileSystemMasterClient)2 GrpcChannel (alluxio.grpc.GrpcChannel)2 TestUserState (alluxio.security.user.TestUserState)2 File (java.io.File)2 InetSocketAddress (java.net.InetSocketAddress)2 TemporaryFolder (org.junit.rules.TemporaryFolder)2 UnauthenticatedException (alluxio.exception.status.UnauthenticatedException)1 GrpcChannelBuilder (alluxio.grpc.GrpcChannelBuilder)1 GrpcConnection (alluxio.grpc.GrpcConnection)1 GrpcServerBuilder (alluxio.grpc.GrpcServerBuilder)1 JobConfig (alluxio.job.JobConfig)1 JobInfo (alluxio.job.wire.JobInfo)1 DefaultSafeModeManager (alluxio.master.DefaultSafeModeManager)1 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1