Java Code Examples for org.apache.hadoop.yarn.ipc.YarnRPC#getProxy()
The following examples show how to use
org.apache.hadoop.yarn.ipc.YarnRPC#getProxy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSharedCacheUploaderService.java From big-c with Apache License 2.0 | 6 votes |
@Before public void startUp() { Configuration conf = new Configuration(); conf.set(YarnConfiguration.SCM_STORE_CLASS, InMemorySCMStore.class.getName()); conf.set(YarnConfiguration.SHARED_CACHE_ROOT, testDir.getPath()); AppChecker appChecker = spy(new DummyAppChecker()); store = new InMemorySCMStore(appChecker); store.init(conf); store.start(); service = new SharedCacheUploaderService(store); service.init(conf); service.start(); YarnRPC rpc = YarnRPC.create(new Configuration()); InetSocketAddress scmAddress = conf.getSocketAddr(YarnConfiguration.SCM_UPLOADER_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_UPLOADER_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_UPLOADER_SERVER_PORT); proxy = (SCMUploaderProtocol) rpc.getProxy( SCMUploaderProtocol.class, scmAddress, conf); }
Example 2
Source File: TestSharedCacheUploaderService.java From hadoop with Apache License 2.0 | 6 votes |
@Before public void startUp() { Configuration conf = new Configuration(); conf.set(YarnConfiguration.SCM_STORE_CLASS, InMemorySCMStore.class.getName()); conf.set(YarnConfiguration.SHARED_CACHE_ROOT, testDir.getPath()); AppChecker appChecker = spy(new DummyAppChecker()); store = new InMemorySCMStore(appChecker); store.init(conf); store.start(); service = new SharedCacheUploaderService(store); service.init(conf); service.start(); YarnRPC rpc = YarnRPC.create(new Configuration()); InetSocketAddress scmAddress = conf.getSocketAddr(YarnConfiguration.SCM_UPLOADER_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_UPLOADER_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_UPLOADER_SERVER_PORT); proxy = (SCMUploaderProtocol) rpc.getProxy( SCMUploaderProtocol.class, scmAddress, conf); }
Example 3
Source File: TestClientSCMProtocolService.java From hadoop with Apache License 2.0 | 6 votes |
@Before public void startUp() { Configuration conf = new Configuration(); conf.set(YarnConfiguration.SCM_STORE_CLASS, InMemorySCMStore.class.getName()); conf.set(YarnConfiguration.SHARED_CACHE_ROOT, testDir.getPath()); AppChecker appChecker = spy(new DummyAppChecker()); store = new InMemorySCMStore(appChecker); store.init(conf); store.start(); service = new ClientProtocolService(store); service.init(conf); service.start(); YarnRPC rpc = YarnRPC.create(new Configuration()); InetSocketAddress scmAddress = conf.getSocketAddr(YarnConfiguration.SCM_CLIENT_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_CLIENT_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_CLIENT_SERVER_PORT); clientSCMProxy = (ClientSCMProtocol) rpc.getProxy(ClientSCMProtocol.class, scmAddress, conf); }
Example 4
Source File: TestClientSCMProtocolService.java From big-c with Apache License 2.0 | 6 votes |
@Before public void startUp() { Configuration conf = new Configuration(); conf.set(YarnConfiguration.SCM_STORE_CLASS, InMemorySCMStore.class.getName()); conf.set(YarnConfiguration.SHARED_CACHE_ROOT, testDir.getPath()); AppChecker appChecker = spy(new DummyAppChecker()); store = new InMemorySCMStore(appChecker); store.init(conf); store.start(); service = new ClientProtocolService(store); service.init(conf); service.start(); YarnRPC rpc = YarnRPC.create(new Configuration()); InetSocketAddress scmAddress = conf.getSocketAddr(YarnConfiguration.SCM_CLIENT_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_CLIENT_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_CLIENT_SERVER_PORT); clientSCMProxy = (ClientSCMProtocol) rpc.getProxy(ClientSCMProtocol.class, scmAddress, conf); }
Example 5
Source File: TestSCMAdminProtocolService.java From hadoop with Apache License 2.0 | 5 votes |
@Before public void startUp() { Configuration conf = new Configuration(); conf.set(YarnConfiguration.SCM_STORE_CLASS, InMemorySCMStore.class.getName()); cleaner = mock(CleanerService.class); service = spy(new SCMAdminProtocolService(cleaner)); service.init(conf); service.start(); YarnRPC rpc = YarnRPC.create(new Configuration()); InetSocketAddress scmAddress = conf.getSocketAddr(YarnConfiguration.SCM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_SCM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_SCM_ADMIN_PORT); SCMAdminProxy = (SCMAdminProtocol) rpc.getProxy(SCMAdminProtocol.class, scmAddress, conf); mockAdmin = mock(SCMAdminProtocol.class); adminCLI = new SCMAdmin(new Configuration()) { @Override protected SCMAdminProtocol createSCMAdminProtocol() throws IOException { return mockAdmin; } }; }
Example 6
Source File: SharedCacheUploadService.java From hadoop with Apache License 2.0 | 5 votes |
private SCMUploaderProtocol createSCMClient(Configuration conf) { YarnRPC rpc = YarnRPC.create(conf); InetSocketAddress scmAddress = conf.getSocketAddr(YarnConfiguration.SCM_UPLOADER_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_UPLOADER_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_UPLOADER_SERVER_PORT); return (SCMUploaderProtocol)rpc.getProxy( SCMUploaderProtocol.class, scmAddress, conf); }
Example 7
Source File: ClientServiceDelegate.java From big-c with Apache License 2.0 | 5 votes |
MRClientProtocol instantiateAMProxy(final InetSocketAddress serviceAddr) throws IOException { LOG.trace("Connecting to ApplicationMaster at: " + serviceAddr); YarnRPC rpc = YarnRPC.create(conf); MRClientProtocol proxy = (MRClientProtocol) rpc.getProxy(MRClientProtocol.class, serviceAddr, conf); usingAMProxy.set(true); LOG.trace("Connected to ApplicationMaster at: " + serviceAddr); return proxy; }
Example 8
Source File: SharedCacheUploadService.java From big-c with Apache License 2.0 | 5 votes |
private SCMUploaderProtocol createSCMClient(Configuration conf) { YarnRPC rpc = YarnRPC.create(conf); InetSocketAddress scmAddress = conf.getSocketAddr(YarnConfiguration.SCM_UPLOADER_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_UPLOADER_SERVER_ADDRESS, YarnConfiguration.DEFAULT_SCM_UPLOADER_SERVER_PORT); return (SCMUploaderProtocol)rpc.getProxy( SCMUploaderProtocol.class, scmAddress, conf); }
Example 9
Source File: TestSCMAdminProtocolService.java From big-c with Apache License 2.0 | 5 votes |
@Before public void startUp() { Configuration conf = new Configuration(); conf.set(YarnConfiguration.SCM_STORE_CLASS, InMemorySCMStore.class.getName()); cleaner = mock(CleanerService.class); service = spy(new SCMAdminProtocolService(cleaner)); service.init(conf); service.start(); YarnRPC rpc = YarnRPC.create(new Configuration()); InetSocketAddress scmAddress = conf.getSocketAddr(YarnConfiguration.SCM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_SCM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_SCM_ADMIN_PORT); SCMAdminProxy = (SCMAdminProtocol) rpc.getProxy(SCMAdminProtocol.class, scmAddress, conf); mockAdmin = mock(SCMAdminProtocol.class); adminCLI = new SCMAdmin(new Configuration()) { @Override protected SCMAdminProtocol createSCMAdminProtocol() throws IOException { return mockAdmin; } }; }
Example 10
Source File: SCMAdmin.java From big-c with Apache License 2.0 | 5 votes |
protected SCMAdminProtocol createSCMAdminProtocol() throws IOException { // Get the current configuration final YarnConfiguration conf = new YarnConfiguration(getConf()); // Create the admin client final InetSocketAddress addr = conf.getSocketAddr( YarnConfiguration.SCM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_SCM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_SCM_ADMIN_PORT); final YarnRPC rpc = YarnRPC.create(conf); SCMAdminProtocol scmAdminProtocol = (SCMAdminProtocol) rpc.getProxy(SCMAdminProtocol.class, addr, conf); return scmAdminProtocol; }
Example 11
Source File: GetGroupsForTesting.java From hadoop with Apache License 2.0 | 5 votes |
@Override protected GetUserMappingsProtocol getUgmProtocol() throws IOException { Configuration conf = getConf(); final InetSocketAddress addr = conf.getSocketAddr( YarnConfiguration.RM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_RM_ADMIN_ADDRESS, YarnConfiguration.DEFAULT_RM_ADMIN_PORT); final YarnRPC rpc = YarnRPC.create(conf); ResourceManagerAdministrationProtocol adminProtocol = (ResourceManagerAdministrationProtocol) rpc.getProxy( ResourceManagerAdministrationProtocol.class, addr, getConf()); return adminProtocol; }
Example 12
Source File: TestMRJobsWithHistoryService.java From hadoop with Apache License 2.0 | 5 votes |
private HSClientProtocol instantiateHistoryProxy() { final String serviceAddr = mrCluster.getConfig().get(JHAdminConfig.MR_HISTORY_ADDRESS); final YarnRPC rpc = YarnRPC.create(conf); HSClientProtocol historyClient = (HSClientProtocol) rpc.getProxy(HSClientProtocol.class, NetUtils.createSocketAddr(serviceAddr), mrCluster.getConfig()); return historyClient; }
Example 13
Source File: ContainerLocalizer.java From big-c with Apache License 2.0 | 4 votes |
LocalizationProtocol getProxy(final InetSocketAddress nmAddr) { YarnRPC rpc = YarnRPC.create(conf); return (LocalizationProtocol) rpc.getProxy(LocalizationProtocol.class, nmAddr, conf); }
Example 14
Source File: SharedCacheClientImpl.java From big-c with Apache License 2.0 | 4 votes |
@VisibleForTesting protected ClientSCMProtocol createClientProxy() { YarnRPC rpc = YarnRPC.create(getConfig()); return (ClientSCMProtocol) rpc.getProxy(ClientSCMProtocol.class, this.scmAddress, getConfig()); }
Example 15
Source File: TestRPC.java From big-c with Apache License 2.0 | 4 votes |
private void test(String rpcClass) throws Exception { Configuration conf = new Configuration(); conf.set(YarnConfiguration.IPC_RPC_IMPL, rpcClass); 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(); RPC.setProtocolEngine(conf, ContainerManagementProtocolPB.class, ProtobufRpcEngine.class); ContainerManagementProtocol proxy = (ContainerManagementProtocol) rpc.getProxy(ContainerManagementProtocol.class, NetUtils.getConnectAddress(server), conf); ContainerLaunchContext containerLaunchContext = recordFactory.newRecordInstance(ContainerLaunchContext.class); ApplicationId applicationId = ApplicationId.newInstance(0, 0); ApplicationAttemptId applicationAttemptId = ApplicationAttemptId.newInstance(applicationId, 0); ContainerId containerId = ContainerId.newContainerId(applicationAttemptId, 100); NodeId nodeId = NodeId.newInstance("localhost", 1234); Resource resource = Resource.newInstance(1234, 2); ContainerTokenIdentifier containerTokenIdentifier = new ContainerTokenIdentifier(containerId, "localhost", "user", resource, System.currentTimeMillis() + 10000, 42, 42, Priority.newInstance(0), 0); Token containerToken = newContainerToken(nodeId, "password".getBytes(), containerTokenIdentifier); StartContainerRequest scRequest = StartContainerRequest.newInstance(containerLaunchContext, containerToken); List<StartContainerRequest> list = new ArrayList<StartContainerRequest>(); list.add(scRequest); StartContainersRequest allRequests = StartContainersRequest.newInstance(list); proxy.startContainers(allRequests); List<ContainerId> containerIds = new ArrayList<ContainerId>(); containerIds.add(containerId); GetContainerStatusesRequest gcsRequest = GetContainerStatusesRequest.newInstance(containerIds); GetContainerStatusesResponse response = proxy.getContainerStatuses(gcsRequest); List<ContainerStatus> statuses = response.getContainerStatuses(); //test remote exception boolean exception = false; try { StopContainersRequest stopRequest = recordFactory.newRecordInstance(StopContainersRequest.class); stopRequest.setContainerIds(containerIds); proxy.stopContainers(stopRequest); } catch (YarnException e) { exception = true; Assert.assertTrue(e.getMessage().contains(EXCEPTION_MSG)); Assert.assertTrue(e.getMessage().contains(EXCEPTION_CAUSE)); System.out.println("Test Exception is " + e.getMessage()); } catch (Exception ex) { ex.printStackTrace(); } Assert.assertTrue(exception); server.stop(); Assert.assertNotNull(statuses.get(0)); Assert.assertEquals(ContainerState.RUNNING, statuses.get(0).getState()); }
Example 16
Source File: TestClientRMService.java From big-c with Apache License 2.0 | 4 votes |
@Test public void testGetNodeLabels() throws Exception { MockRM rm = new MockRM() { protected ClientRMService createClientRMService() { return new ClientRMService(this.rmContext, scheduler, this.rmAppManager, this.applicationACLsManager, this.queueACLsManager, this.getRMContext() .getRMDelegationTokenSecretManager()); }; }; rm.start(); RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager(); labelsMgr.addToCluserNodeLabels(ImmutableSet.of("x", "y")); Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>(); map.put(NodeId.newInstance("host1", 0), ImmutableSet.of("x")); map.put(NodeId.newInstance("host2", 0), ImmutableSet.of("y")); labelsMgr.replaceLabelsOnNode(map); // Create a client. Configuration conf = new Configuration(); YarnRPC rpc = YarnRPC.create(conf); InetSocketAddress rmAddress = rm.getClientRMService().getBindAddress(); LOG.info("Connecting to ResourceManager at " + rmAddress); ApplicationClientProtocol client = (ApplicationClientProtocol) rpc.getProxy( ApplicationClientProtocol.class, rmAddress, conf); // Get node labels collection GetClusterNodeLabelsResponse response = client.getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance()); Assert.assertTrue(response.getNodeLabels().containsAll( Arrays.asList("x", "y"))); // Get node labels mapping GetNodesToLabelsResponse response1 = client.getNodeToLabels(GetNodesToLabelsRequest.newInstance()); Map<NodeId, Set<String>> nodeToLabels = response1.getNodeToLabels(); Assert.assertTrue(nodeToLabels.keySet().containsAll( Arrays.asList(NodeId.newInstance("host1", 0), NodeId.newInstance("host2", 0)))); Assert.assertTrue(nodeToLabels.get(NodeId.newInstance("host1", 0)) .containsAll(Arrays.asList("x"))); Assert.assertTrue(nodeToLabels.get(NodeId.newInstance("host2", 0)) .containsAll(Arrays.asList("y"))); rpc.stopProxy(client, conf); rm.close(); }
Example 17
Source File: TestClientRMService.java From big-c with Apache License 2.0 | 4 votes |
@Test public void testGetClusterNodes() throws Exception { MockRM rm = new MockRM() { protected ClientRMService createClientRMService() { return new ClientRMService(this.rmContext, scheduler, this.rmAppManager, this.applicationACLsManager, this.queueACLsManager, this.getRMContext().getRMDelegationTokenSecretManager()); }; }; rm.start(); RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager(); labelsMgr.addToCluserNodeLabels(ImmutableSet.of("x", "y")); // Add a healthy node with label = x MockNM node = rm.registerNode("host1:1234", 1024); Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>(); map.put(node.getNodeId(), ImmutableSet.of("x")); labelsMgr.replaceLabelsOnNode(map); rm.sendNodeStarted(node); node.nodeHeartbeat(true); // Add and lose a node with label = y MockNM lostNode = rm.registerNode("host2:1235", 1024); rm.sendNodeStarted(lostNode); lostNode.nodeHeartbeat(true); rm.NMwaitForState(lostNode.getNodeId(), NodeState.RUNNING); rm.sendNodeLost(lostNode); // Create a client. Configuration conf = new Configuration(); YarnRPC rpc = YarnRPC.create(conf); InetSocketAddress rmAddress = rm.getClientRMService().getBindAddress(); LOG.info("Connecting to ResourceManager at " + rmAddress); ApplicationClientProtocol client = (ApplicationClientProtocol) rpc .getProxy(ApplicationClientProtocol.class, rmAddress, conf); // Make call GetClusterNodesRequest request = GetClusterNodesRequest.newInstance(EnumSet.of(NodeState.RUNNING)); List<NodeReport> nodeReports = client.getClusterNodes(request).getNodeReports(); Assert.assertEquals(1, nodeReports.size()); Assert.assertNotSame("Node is expected to be healthy!", NodeState.UNHEALTHY, nodeReports.get(0).getNodeState()); // Check node's label = x Assert.assertTrue(nodeReports.get(0).getNodeLabels().contains("x")); // Now make the node unhealthy. node.nodeHeartbeat(false); // Call again nodeReports = client.getClusterNodes(request).getNodeReports(); Assert.assertEquals("Unhealthy nodes should not show up by default", 0, nodeReports.size()); // Change label of host1 to y map = new HashMap<NodeId, Set<String>>(); map.put(node.getNodeId(), ImmutableSet.of("y")); labelsMgr.replaceLabelsOnNode(map); // Now query for UNHEALTHY nodes request = GetClusterNodesRequest.newInstance(EnumSet.of(NodeState.UNHEALTHY)); nodeReports = client.getClusterNodes(request).getNodeReports(); Assert.assertEquals(1, nodeReports.size()); Assert.assertEquals("Node is expected to be unhealthy!", NodeState.UNHEALTHY, nodeReports.get(0).getNodeState()); Assert.assertTrue(nodeReports.get(0).getNodeLabels().contains("y")); // Remove labels of host1 map = new HashMap<NodeId, Set<String>>(); map.put(node.getNodeId(), ImmutableSet.of("y")); labelsMgr.removeLabelsFromNode(map); // Query all states should return all nodes rm.registerNode("host3:1236", 1024); request = GetClusterNodesRequest.newInstance(EnumSet.allOf(NodeState.class)); nodeReports = client.getClusterNodes(request).getNodeReports(); Assert.assertEquals(3, nodeReports.size()); // All host1-3's label should be empty (instead of null) for (NodeReport report : nodeReports) { Assert.assertTrue(report.getNodeLabels() != null && report.getNodeLabels().isEmpty()); } rpc.stopProxy(client, conf); rm.close(); }
Example 18
Source File: TestRPC.java From hadoop with Apache License 2.0 | 4 votes |
private void test(String rpcClass) throws Exception { Configuration conf = new Configuration(); conf.set(YarnConfiguration.IPC_RPC_IMPL, rpcClass); 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(); RPC.setProtocolEngine(conf, ContainerManagementProtocolPB.class, ProtobufRpcEngine.class); ContainerManagementProtocol proxy = (ContainerManagementProtocol) rpc.getProxy(ContainerManagementProtocol.class, NetUtils.getConnectAddress(server), conf); ContainerLaunchContext containerLaunchContext = recordFactory.newRecordInstance(ContainerLaunchContext.class); ApplicationId applicationId = ApplicationId.newInstance(0, 0); ApplicationAttemptId applicationAttemptId = ApplicationAttemptId.newInstance(applicationId, 0); ContainerId containerId = ContainerId.newContainerId(applicationAttemptId, 100); NodeId nodeId = NodeId.newInstance("localhost", 1234); Resource resource = Resource.newInstance(1234, 2); ContainerTokenIdentifier containerTokenIdentifier = new ContainerTokenIdentifier(containerId, "localhost", "user", resource, System.currentTimeMillis() + 10000, 42, 42, Priority.newInstance(0), 0); Token containerToken = newContainerToken(nodeId, "password".getBytes(), containerTokenIdentifier); StartContainerRequest scRequest = StartContainerRequest.newInstance(containerLaunchContext, containerToken); List<StartContainerRequest> list = new ArrayList<StartContainerRequest>(); list.add(scRequest); StartContainersRequest allRequests = StartContainersRequest.newInstance(list); proxy.startContainers(allRequests); List<ContainerId> containerIds = new ArrayList<ContainerId>(); containerIds.add(containerId); GetContainerStatusesRequest gcsRequest = GetContainerStatusesRequest.newInstance(containerIds); GetContainerStatusesResponse response = proxy.getContainerStatuses(gcsRequest); List<ContainerStatus> statuses = response.getContainerStatuses(); //test remote exception boolean exception = false; try { StopContainersRequest stopRequest = recordFactory.newRecordInstance(StopContainersRequest.class); stopRequest.setContainerIds(containerIds); proxy.stopContainers(stopRequest); } catch (YarnException e) { exception = true; Assert.assertTrue(e.getMessage().contains(EXCEPTION_MSG)); Assert.assertTrue(e.getMessage().contains(EXCEPTION_CAUSE)); System.out.println("Test Exception is " + e.getMessage()); } catch (Exception ex) { ex.printStackTrace(); } Assert.assertTrue(exception); server.stop(); Assert.assertNotNull(statuses.get(0)); Assert.assertEquals(ContainerState.RUNNING, statuses.get(0).getState()); }
Example 19
Source File: TestClientRMService.java From hadoop with Apache License 2.0 | 4 votes |
@Test public void testGetNodeLabels() throws Exception { MockRM rm = new MockRM() { protected ClientRMService createClientRMService() { return new ClientRMService(this.rmContext, scheduler, this.rmAppManager, this.applicationACLsManager, this.queueACLsManager, this.getRMContext() .getRMDelegationTokenSecretManager()); }; }; rm.start(); RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager(); labelsMgr.addToCluserNodeLabels(ImmutableSet.of("x", "y")); Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>(); map.put(NodeId.newInstance("host1", 0), ImmutableSet.of("x")); map.put(NodeId.newInstance("host2", 0), ImmutableSet.of("y")); labelsMgr.replaceLabelsOnNode(map); // Create a client. Configuration conf = new Configuration(); YarnRPC rpc = YarnRPC.create(conf); InetSocketAddress rmAddress = rm.getClientRMService().getBindAddress(); LOG.info("Connecting to ResourceManager at " + rmAddress); ApplicationClientProtocol client = (ApplicationClientProtocol) rpc.getProxy( ApplicationClientProtocol.class, rmAddress, conf); // Get node labels collection GetClusterNodeLabelsResponse response = client.getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance()); Assert.assertTrue(response.getNodeLabels().containsAll( Arrays.asList("x", "y"))); // Get node labels mapping GetNodesToLabelsResponse response1 = client.getNodeToLabels(GetNodesToLabelsRequest.newInstance()); Map<NodeId, Set<String>> nodeToLabels = response1.getNodeToLabels(); Assert.assertTrue(nodeToLabels.keySet().containsAll( Arrays.asList(NodeId.newInstance("host1", 0), NodeId.newInstance("host2", 0)))); Assert.assertTrue(nodeToLabels.get(NodeId.newInstance("host1", 0)) .containsAll(Arrays.asList("x"))); Assert.assertTrue(nodeToLabels.get(NodeId.newInstance("host2", 0)) .containsAll(Arrays.asList("y"))); rpc.stopProxy(client, conf); rm.close(); }
Example 20
Source File: TestContainerLaunchRPC.java From hadoop with Apache License 2.0 | 4 votes |
private void testRPCTimeout(String rpcClass) throws Exception { Configuration conf = new Configuration(); // set timeout low for the test conf.setInt("yarn.rpc.nm-command-timeout", 3000); conf.set(YarnConfiguration.IPC_RPC_IMPL, rpcClass); 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(); try { ContainerManagementProtocol proxy = (ContainerManagementProtocol) rpc.getProxy( ContainerManagementProtocol.class, server.getListenerAddress(), conf); ContainerLaunchContext containerLaunchContext = recordFactory .newRecordInstance(ContainerLaunchContext.class); ApplicationId applicationId = ApplicationId.newInstance(0, 0); ApplicationAttemptId applicationAttemptId = ApplicationAttemptId.newInstance(applicationId, 0); ContainerId containerId = ContainerId.newContainerId(applicationAttemptId, 100); NodeId nodeId = NodeId.newInstance("localhost", 1234); Resource resource = Resource.newInstance(1234, 2, 3); ContainerTokenIdentifier containerTokenIdentifier = new ContainerTokenIdentifier(containerId, "localhost", "user", resource, System.currentTimeMillis() + 10000, 42, 42, Priority.newInstance(0), 0); Token containerToken = TestRPC.newContainerToken(nodeId, "password".getBytes(), containerTokenIdentifier); StartContainerRequest scRequest = StartContainerRequest.newInstance(containerLaunchContext, containerToken); List<StartContainerRequest> list = new ArrayList<StartContainerRequest>(); list.add(scRequest); StartContainersRequest allRequests = StartContainersRequest.newInstance(list); try { proxy.startContainers(allRequests); } catch (Exception e) { LOG.info(StringUtils.stringifyException(e)); Assert.assertEquals("Error, exception is not: " + SocketTimeoutException.class.getName(), SocketTimeoutException.class.getName(), e.getClass().getName()); return; } } finally { server.stop(); } Assert.fail("timeout exception should have occurred!"); }