Search in sources :

Example 1 with Server

use of org.apache.hadoop.ipc.Server in project hadoop by apache.

the class TestNMAuditLogger method testNMAuditLoggerWithIP.

/**
   * Test {@link NMAuditLogger} with IP set.
   */
@Test
public void testNMAuditLoggerWithIP() throws Exception {
    Configuration conf = new Configuration();
    RPC.setProtocolEngine(conf, TestRpcService.class, ProtobufRpcEngine.class);
    // Create server side implementation
    MyTestRPCServer serverImpl = new MyTestRPCServer();
    BlockingService service = TestRpcServiceProtos.TestProtobufRpcProto.newReflectiveBlockingService(serverImpl);
    // start the IPC server
    Server server = new RPC.Builder(conf).setProtocol(TestRpcBase.TestRpcService.class).setInstance(service).setBindAddress("0.0.0.0").setPort(0).setNumHandlers(5).setVerbose(true).build();
    server.start();
    InetSocketAddress addr = NetUtils.getConnectAddress(server);
    // Make a client connection and test the audit log
    TestRpcService proxy = RPC.getProxy(TestRpcService.class, TestProtocol.versionID, addr, conf);
    // Start the testcase
    TestProtos.EmptyRequestProto pingRequest = TestProtos.EmptyRequestProto.newBuilder().build();
    proxy.ping(null, pingRequest);
    server.stop();
    RPC.stopProxy(proxy);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Server(org.apache.hadoop.ipc.Server) RPC(org.apache.hadoop.ipc.RPC) InetSocketAddress(java.net.InetSocketAddress) BlockingService(com.google.protobuf.BlockingService) TestProtos(org.apache.hadoop.ipc.protobuf.TestProtos) TestRpcBase(org.apache.hadoop.ipc.TestRpcBase) TestRpcService(org.apache.hadoop.ipc.TestRpcBase.TestRpcService) Test(org.junit.Test)

Example 2 with Server

use of org.apache.hadoop.ipc.Server in project hadoop by apache.

the class TestUmbilicalProtocolWithJobToken method testJobTokenRpc.

@Test
public void testJobTokenRpc() throws Exception {
    TaskUmbilicalProtocol mockTT = mock(TaskUmbilicalProtocol.class);
    doReturn(TaskUmbilicalProtocol.versionID).when(mockTT).getProtocolVersion(anyString(), anyLong());
    doReturn(ProtocolSignature.getProtocolSignature(mockTT, TaskUmbilicalProtocol.class.getName(), TaskUmbilicalProtocol.versionID, 0)).when(mockTT).getProtocolSignature(anyString(), anyLong(), anyInt());
    JobTokenSecretManager sm = new JobTokenSecretManager();
    final Server server = new RPC.Builder(conf).setProtocol(TaskUmbilicalProtocol.class).setInstance(mockTT).setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true).setSecretManager(sm).build();
    server.start();
    final UserGroupInformation current = UserGroupInformation.getCurrentUser();
    final InetSocketAddress addr = NetUtils.getConnectAddress(server);
    String jobId = current.getUserName();
    JobTokenIdentifier tokenId = new JobTokenIdentifier(new Text(jobId));
    Token<JobTokenIdentifier> token = new Token<JobTokenIdentifier>(tokenId, sm);
    sm.addTokenForJob(jobId, token);
    SecurityUtil.setTokenService(token, addr);
    LOG.info("Service address for token is " + token.getService());
    current.addToken(token);
    current.doAs(new PrivilegedExceptionAction<Object>() {

        @Override
        public Object run() throws Exception {
            TaskUmbilicalProtocol proxy = null;
            try {
                proxy = (TaskUmbilicalProtocol) RPC.getProxy(TaskUmbilicalProtocol.class, TaskUmbilicalProtocol.versionID, addr, conf);
                proxy.statusUpdate(null, null);
            } finally {
                server.stop();
                if (proxy != null) {
                    RPC.stopProxy(proxy);
                }
            }
            return null;
        }
    });
}
Also used : SaslRpcServer(org.apache.hadoop.security.SaslRpcServer) Server(org.apache.hadoop.ipc.Server) InetSocketAddress(java.net.InetSocketAddress) JobTokenIdentifier(org.apache.hadoop.mapreduce.security.token.JobTokenIdentifier) Text(org.apache.hadoop.io.Text) Token(org.apache.hadoop.security.token.Token) Matchers.anyString(org.mockito.Matchers.anyString) TaskUmbilicalProtocol(org.apache.hadoop.mapred.TaskUmbilicalProtocol) JobTokenSecretManager(org.apache.hadoop.mapreduce.security.token.JobTokenSecretManager) Matchers.anyObject(org.mockito.Matchers.anyObject) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 3 with Server

use of org.apache.hadoop.ipc.Server in project hadoop by apache.

the class TestRPCFactories method testPbServerFactory.

private void testPbServerFactory() {
    InetSocketAddress addr = new InetSocketAddress(0);
    Configuration conf = new Configuration();
    ApplicationMasterProtocol instance = new AMRMProtocolTestImpl();
    Server server = null;
    try {
        server = RpcServerFactoryPBImpl.get().getServer(ApplicationMasterProtocol.class, instance, addr, conf, null, 1);
        server.start();
    } catch (YarnRuntimeException e) {
        e.printStackTrace();
        Assert.fail("Failed to create server");
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) Configuration(org.apache.hadoop.conf.Configuration) Server(org.apache.hadoop.ipc.Server) InetSocketAddress(java.net.InetSocketAddress) ApplicationMasterProtocol(org.apache.hadoop.yarn.api.ApplicationMasterProtocol)

Example 4 with Server

use of org.apache.hadoop.ipc.Server in project hadoop by apache.

the class TestRPC method testUnknownCall.

@Test
public void testUnknownCall() {
    Configuration conf = new Configuration();
    conf.set(YarnConfiguration.IPC_RPC_IMPL, HadoopYarnProtoRPC.class.getName());
    YarnRPC rpc = YarnRPC.create(conf);
    String bindAddr = "localhost:0";
    InetSocketAddress addr = NetUtils.createSocketAddr(bindAddr);
    Server server = rpc.getServer(ContainerManagementProtocol.class, new DummyContainerManager(), addr, conf, null, 1);
    server.start();
    // Any unrelated protocol would do
    ApplicationClientProtocol proxy = (ApplicationClientProtocol) rpc.getProxy(ApplicationClientProtocol.class, NetUtils.getConnectAddress(server), conf);
    try {
        proxy.getNewApplication(Records.newRecord(GetNewApplicationRequest.class));
        Assert.fail("Excepted RPC call to fail with unknown method.");
    } catch (YarnException e) {
        Assert.assertTrue(e.getMessage().matches("Unknown method getNewApplication called on.*" + "org.apache.hadoop.yarn.proto.ApplicationClientProtocol" + "\\$ApplicationClientProtocolService\\$BlockingInterface " + "protocol."));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        server.stop();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Server(org.apache.hadoop.ipc.Server) InetSocketAddress(java.net.InetSocketAddress) YarnRPC(org.apache.hadoop.yarn.ipc.YarnRPC) HadoopYarnProtoRPC(org.apache.hadoop.yarn.ipc.HadoopYarnProtoRPC) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) GetNewApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest) Test(org.junit.Test)

Example 5 with Server

use of org.apache.hadoop.ipc.Server in project hadoop by apache.

the class TestRPC method testRPCOnCollectorNodeManagerProtocol.

@Test
public void testRPCOnCollectorNodeManagerProtocol() throws IOException {
    Configuration conf = new Configuration();
    conf.set(YarnConfiguration.IPC_RPC_IMPL, HadoopYarnProtoRPC.class.getName());
    YarnRPC rpc = YarnRPC.create(conf);
    String bindAddr = "localhost:0";
    InetSocketAddress addr = NetUtils.createSocketAddr(bindAddr);
    Server server = rpc.getServer(CollectorNodemanagerProtocol.class, new DummyNMCollectorService(), addr, conf, null, 1);
    server.start();
    // Test unrelated protocol wouldn't get response
    ApplicationClientProtocol unknownProxy = (ApplicationClientProtocol) rpc.getProxy(ApplicationClientProtocol.class, NetUtils.getConnectAddress(server), conf);
    try {
        unknownProxy.getNewApplication(Records.newRecord(GetNewApplicationRequest.class));
        Assert.fail("Excepted RPC call to fail with unknown method.");
    } catch (YarnException e) {
        Assert.assertTrue(e.getMessage().matches("Unknown method getNewApplication called on.*" + "org.apache.hadoop.yarn.proto.ApplicationClientProtocol" + "\\$ApplicationClientProtocolService\\$BlockingInterface " + "protocol."));
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Test CollectorNodemanagerProtocol get proper response
    CollectorNodemanagerProtocol proxy = (CollectorNodemanagerProtocol) rpc.getProxy(CollectorNodemanagerProtocol.class, NetUtils.getConnectAddress(server), conf);
    // normally response.
    try {
        ReportNewCollectorInfoRequest request = ReportNewCollectorInfoRequest.newInstance(DEFAULT_APP_ID, DEFAULT_COLLECTOR_ADDR);
        proxy.reportNewCollectorInfo(request);
    } catch (YarnException e) {
        Assert.fail("RPC call failured is not expected here.");
    }
    // DummyNMCollectorService)
    try {
        proxy.reportNewCollectorInfo(Records.newRecord(ReportNewCollectorInfoRequest.class));
        Assert.fail("Excepted RPC call to fail with YarnException.");
    } catch (YarnException e) {
        Assert.assertTrue(e.getMessage().contains(ILLEGAL_NUMBER_MESSAGE));
    }
    // Verify request with a valid app ID
    try {
        GetTimelineCollectorContextRequest request = GetTimelineCollectorContextRequest.newInstance(ApplicationId.newInstance(0, 1));
        GetTimelineCollectorContextResponse response = proxy.getTimelineCollectorContext(request);
        Assert.assertEquals("test_user_id", response.getUserId());
        Assert.assertEquals("test_flow_name", response.getFlowName());
        Assert.assertEquals("test_flow_version", response.getFlowVersion());
        Assert.assertEquals(12345678L, response.getFlowRunId());
    } catch (YarnException | IOException e) {
        Assert.fail("RPC call failured is not expected here.");
    }
    // Verify request with an invalid app ID
    try {
        GetTimelineCollectorContextRequest request = GetTimelineCollectorContextRequest.newInstance(ApplicationId.newInstance(0, 2));
        proxy.getTimelineCollectorContext(request);
        Assert.fail("RPC call failured is expected here.");
    } catch (YarnException | IOException e) {
        Assert.assertTrue(e instanceof YarnException);
        Assert.assertTrue(e.getMessage().contains("The application is not found."));
    }
    server.stop();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Server(org.apache.hadoop.ipc.Server) CollectorNodemanagerProtocol(org.apache.hadoop.yarn.server.api.CollectorNodemanagerProtocol) GetTimelineCollectorContextRequest(org.apache.hadoop.yarn.server.api.protocolrecords.GetTimelineCollectorContextRequest) InetSocketAddress(java.net.InetSocketAddress) ReportNewCollectorInfoRequest(org.apache.hadoop.yarn.server.api.protocolrecords.ReportNewCollectorInfoRequest) YarnRPC(org.apache.hadoop.yarn.ipc.YarnRPC) IOException(java.io.IOException) HadoopYarnProtoRPC(org.apache.hadoop.yarn.ipc.HadoopYarnProtoRPC) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) GetNewApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest) GetTimelineCollectorContextResponse(org.apache.hadoop.yarn.server.api.protocolrecords.GetTimelineCollectorContextResponse) Test(org.junit.Test)

Aggregations

Server (org.apache.hadoop.ipc.Server)33 Configuration (org.apache.hadoop.conf.Configuration)29 InetSocketAddress (java.net.InetSocketAddress)22 Test (org.junit.Test)17 IOException (java.io.IOException)14 ServiceException (com.google.protobuf.ServiceException)8 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)8 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)7 YarnRPC (org.apache.hadoop.yarn.ipc.YarnRPC)7 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)5 RPC (org.apache.hadoop.ipc.RPC)4 BlockingService (com.google.protobuf.BlockingService)3 SocketTimeoutException (java.net.SocketTimeoutException)3 ArrayList (java.util.ArrayList)3 ClientDatanodeProtocol (org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol)3 DatanodeID (org.apache.hadoop.hdfs.protocol.DatanodeID)3 ExtendedBlock (org.apache.hadoop.hdfs.protocol.ExtendedBlock)3 Text (org.apache.hadoop.io.Text)3 SaslRpcServer (org.apache.hadoop.security.SaslRpcServer)3 Token (org.apache.hadoop.security.token.Token)3