Search in sources :

Example 1 with GrpcChannelBuilder

use of alluxio.grpc.GrpcChannelBuilder in project alluxio by Alluxio.

the class HubClusterTest method testExecAllNodes.

@Test
public void testExecAllNodes() throws Exception {
    List<HubNodeAddress> nodes = Stream.of(1, 2, 3, 4, 5).map(i -> generateNodeAddress()).collect(Collectors.toList());
    nodes.forEach(mCluster::add);
    try (MockedStatic<GrpcChannelBuilder> mock = Mockito.mockStatic(GrpcChannelBuilder.class)) {
        GrpcChannelBuilder mockBuilder = mock(GrpcChannelBuilder.class);
        doReturn(mockBuilder).when(mockBuilder).setSubject(any());
        doReturn(mock(GrpcChannel.class)).when(mockBuilder).build();
        mock.when(() -> GrpcChannelBuilder.newBuilder(any(), any())).thenReturn(mockBuilder);
        AtomicInteger i = new AtomicInteger(0);
        // Test node single exec
        mCluster.exec(Collections.singleton(nodes.get(0)), getTestConfig(), (client) -> i.incrementAndGet(), mSvc);
        assertEquals(1, i.get());
        i.set(0);
        // Test multiple node exec
        mCluster.exec(new HashSet<>(nodes.subList(0, 3)), getTestConfig(), (client) -> i.incrementAndGet(), mSvc);
        assertEquals(3, i.get());
        i.set(0);
        // Test 0 node exec
        mCluster.exec(Collections.emptySet(), getTestConfig(), (client) -> i.incrementAndGet(), mSvc);
        assertEquals(0, i.get());
        i.set(0);
        // test non existing node exec
        mCluster.exec(Collections.singleton(generateNodeAddress()), getTestConfig(), (client) -> i.incrementAndGet(), mSvc);
        assertEquals(0, i.get());
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Random(java.util.Random) HashSet(java.util.HashSet) AlluxioNodeType(alluxio.hub.proto.AlluxioNodeType) HubNodeState(alluxio.hub.proto.HubNodeState) GrpcChannel(alluxio.grpc.GrpcChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HubNodeAddress(alluxio.hub.proto.HubNodeAddress) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) HubTestUtils.generateNodeAddress(alluxio.hub.manager.util.HubTestUtils.generateNodeAddress) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) HubTestUtils.hubStatusToAlluxioStatus(alluxio.hub.manager.util.HubTestUtils.hubStatusToAlluxioStatus) AlluxioNodeStatus(alluxio.hub.proto.AlluxioNodeStatus) Executors(java.util.concurrent.Executors) BaseHubTest(alluxio.hub.test.BaseHubTest) Mockito(org.mockito.Mockito) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) MockedStatic(org.mockito.MockedStatic) List(java.util.List) Rule(org.junit.Rule) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) TestLoggerRule(alluxio.TestLoggerRule) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) HubNodeAddress(alluxio.hub.proto.HubNodeAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) GrpcChannel(alluxio.grpc.GrpcChannel) Test(org.junit.Test) BaseHubTest(alluxio.hub.test.BaseHubTest)

Example 2 with GrpcChannelBuilder

use of alluxio.grpc.GrpcChannelBuilder in project alluxio by Alluxio.

the class RpcClient method createChannel.

/**
 * Creates a gRPC channel that uses NOSASL for security authentication type.
 *
 * @param addr the address to connect to
 * @param conf the configuration used to make the connection
 * @return new instance of {@link GrpcChannel}
 * @throws AlluxioStatusException
 */
public static GrpcChannel createChannel(InetSocketAddress addr, AlluxioConfiguration conf) throws AlluxioStatusException {
    InstancedConfiguration modifiedConfig = InstancedConfiguration.defaults();
    Map<String, Object> properties = new HashMap<>(conf.toMap());
    properties.put(PropertyKey.SECURITY_AUTHENTICATION_TYPE.getName(), AuthType.NOSASL.toString());
    modifiedConfig.merge(properties, Source.RUNTIME);
    LOG.info("Auth type = {}", modifiedConfig.get(PropertyKey.SECURITY_AUTHENTICATION_TYPE));
    GrpcChannelBuilder builder = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(addr), modifiedConfig);
    return builder.setSubject(ServerUserState.global().getSubject()).build();
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) HashMap(java.util.HashMap) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder)

Example 3 with GrpcChannelBuilder

use of alluxio.grpc.GrpcChannelBuilder in project alluxio by Alluxio.

the class GrpcSecurityTest method testSimpleAuthentication.

@Test
public void testSimpleAuthentication() throws Exception {
    GrpcServer server = createServer(AuthType.SIMPLE);
    try {
        server.start();
        UserState us = UserState.Factory.create(mConfiguration);
        GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration).setSubject(us.getSubject());
        channelBuilder.build();
    } finally {
        server.shutdown();
    }
}
Also used : UserState(alluxio.security.user.UserState) GrpcServer(alluxio.grpc.GrpcServer) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) Test(org.junit.Test)

Example 4 with GrpcChannelBuilder

use of alluxio.grpc.GrpcChannelBuilder in project alluxio by Alluxio.

the class GrpcSecurityTest method testDisabledAuthentication.

@Test
public void testDisabledAuthentication() throws Exception {
    GrpcServer server = createServer(AuthType.SIMPLE);
    try {
        server.start();
        GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration);
        channelBuilder.disableAuthentication().build();
    } finally {
        server.shutdown();
    }
}
Also used : GrpcServer(alluxio.grpc.GrpcServer) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) Test(org.junit.Test)

Example 5 with GrpcChannelBuilder

use of alluxio.grpc.GrpcChannelBuilder in project alluxio by Alluxio.

the class GrpcSecurityTest method testCustomAuthentication.

@Test
public void testCustomAuthentication() throws Exception {
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.CUSTOM.getAuthName());
    mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER_CLASS, ExactlyMatchAuthenticationProvider.class.getName());
    GrpcServer server = createServer(AuthType.CUSTOM);
    try {
        server.start();
        GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration);
        channelBuilder.setSubject(createSubject(ExactlyMatchAuthenticationProvider.USERNAME, ExactlyMatchAuthenticationProvider.PASSWORD)).build();
    } finally {
        server.shutdown();
    }
}
Also used : GrpcServer(alluxio.grpc.GrpcServer) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) Test(org.junit.Test)

Aggregations

GrpcChannelBuilder (alluxio.grpc.GrpcChannelBuilder)9 Test (org.junit.Test)8 GrpcServer (alluxio.grpc.GrpcServer)6 BaseHubTest (alluxio.hub.test.BaseHubTest)2 TestLoggerRule (alluxio.TestLoggerRule)1 InstancedConfiguration (alluxio.conf.InstancedConfiguration)1 GrpcChannel (alluxio.grpc.GrpcChannel)1 HubTestUtils.generateNodeAddress (alluxio.hub.manager.util.HubTestUtils.generateNodeAddress)1 HubTestUtils.hubStatusToAlluxioStatus (alluxio.hub.manager.util.HubTestUtils.hubStatusToAlluxioStatus)1 AlluxioNodeStatus (alluxio.hub.proto.AlluxioNodeStatus)1 AlluxioNodeType (alluxio.hub.proto.AlluxioNodeType)1 HubNodeAddress (alluxio.hub.proto.HubNodeAddress)1 HubNodeState (alluxio.hub.proto.HubNodeState)1 ManagerAgentServiceGrpc (alluxio.hub.proto.ManagerAgentServiceGrpc)1 CountingRetry (alluxio.retry.CountingRetry)1 UserState (alluxio.security.user.UserState)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1