List of usage examples for org.apache.hadoop.fs FilterFileSystem exists
public boolean exists(Path f) throws IOException
From source file:org.apache.slider.providers.agent.TestAgentProviderService.java
License:Apache License
@Test public void testOrchestratedAppStart() throws IOException { // App has two components HBASE_MASTER and HBASE_REGIONSERVER // Start of HBASE_RS depends on the start of HBASE_MASTER InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes()); Metainfo metainfo = new MetainfoParser().parse(metainfo_1); ConfTree tree = new ConfTree(); tree.global.put(InternalKeys.INTERNAL_APPLICATION_IMAGE_PATH, "."); Configuration conf = new Configuration(); AgentProviderService aps = createAgentProviderService(conf); YarnRegistryViewForProviders registryViewForProviders = aps.getYarnRegistry(); assertNotNull(registryViewForProviders); ContainerLaunchContext ctx = createNiceMock(ContainerLaunchContext.class); AggregateConf instanceDefinition = new AggregateConf(); instanceDefinition.setInternal(tree); instanceDefinition.setAppConf(tree); instanceDefinition.getAppConfOperations().getGlobalOptions().put(AgentKeys.APP_DEF, "."); instanceDefinition.getAppConfOperations().getGlobalOptions().put(AgentKeys.AGENT_CONF, "."); instanceDefinition.getAppConfOperations().getGlobalOptions().put(AgentKeys.AGENT_VERSION, "."); Container container = createNiceMock(Container.class); String role_hm = "HBASE_MASTER"; String role_hrs = "HBASE_REGIONSERVER"; SliderFileSystem sliderFileSystem = createNiceMock(SliderFileSystem.class); ContainerLauncher launcher = createNiceMock(ContainerLauncher.class); ContainerLauncher launcher2 = createNiceMock(ContainerLauncher.class); Path generatedConfPath = new Path(".", "test"); MapOperations resourceComponent = new MapOperations(); MapOperations appComponent = new MapOperations(); Path containerTmpDirPath = new Path(".", "test"); FilterFileSystem mockFs = createNiceMock(FilterFileSystem.class); expect(sliderFileSystem.getFileSystem()).andReturn(mockFs).anyTimes(); expect(mockFs.exists(anyObject(Path.class))).andReturn(true); expect(sliderFileSystem.createAmResource(anyObject(Path.class), anyObject(LocalResourceType.class))) .andReturn(createNiceMock(LocalResource.class)).anyTimes(); expect(container.getId()).andReturn(new MockContainerId(1)).anyTimes(); expect(container.getNodeId()).andReturn(new MockNodeId("localhost")).anyTimes(); StateAccessForProviders access = createNiceMock(StateAccessForProviders.class); AgentProviderService mockAps = Mockito.spy(aps); doReturn(access).when(mockAps).getAmState(); doReturn(metainfo).when(mockAps).getApplicationMetainfo(any(SliderFileSystem.class), anyString()); doReturn(new HashMap<String, DefaultConfig>()).when(mockAps) .initializeDefaultConfigs(any(SliderFileSystem.class), anyString(), any(Metainfo.class)); try {//from w ww . j a v a 2 s . c om doReturn(true).when(mockAps).isMaster(anyString()); doNothing().when(mockAps).addInstallCommand(anyString(), anyString(), any(HeartBeatResponse.class), anyString(), Mockito.anyLong()); doNothing().when(mockAps).addStartCommand(anyString(), anyString(), any(HeartBeatResponse.class), anyString(), Mockito.anyLong(), Matchers.anyBoolean()); doNothing().when(mockAps).addGetConfigCommand(anyString(), anyString(), any(HeartBeatResponse.class)); doNothing().when(mockAps).publishFolderPaths(anyMap(), anyString(), anyString(), anyString()); doReturn(conf).when(mockAps).getConfig(); } catch (SliderException e) { } PublishedExportsSet pubExpSet = new PublishedExportsSet(); expect(access.isApplicationLive()).andReturn(true).anyTimes(); expect(access.getPublishedExportsSet()).andReturn(pubExpSet).anyTimes(); ClusterDescription desc = new ClusterDescription(); desc.setOption(OptionKeys.ZOOKEEPER_QUORUM, "host1:2181"); desc.setInfo(OptionKeys.APPLICATION_NAME, "HBASE"); expect(access.getClusterStatus()).andReturn(desc).anyTimes(); AggregateConf aggConf = new AggregateConf(); ConfTreeOperations treeOps = aggConf.getAppConfOperations(); treeOps.getOrAddComponent("HBASE_MASTER").put(AgentKeys.WAIT_HEARTBEAT, "0"); treeOps.getOrAddComponent("HBASE_REGIONSERVER").put(AgentKeys.WAIT_HEARTBEAT, "0"); treeOps.set(OptionKeys.APPLICATION_NAME, "HBASE"); expect(access.getInstanceDefinitionSnapshot()).andReturn(aggConf).anyTimes(); expect(access.getInternalsSnapshot()).andReturn(treeOps).anyTimes(); doNothing().when(mockAps).publishApplicationInstanceData(anyString(), anyString(), anyCollection()); replay(access, ctx, container, sliderFileSystem, mockFs); // build two containers try { mockAps.buildContainerLaunchContext(launcher, instanceDefinition, container, role_hm, sliderFileSystem, generatedConfPath, resourceComponent, appComponent, containerTmpDirPath); mockAps.buildContainerLaunchContext(launcher2, instanceDefinition, container, role_hrs, sliderFileSystem, generatedConfPath, resourceComponent, appComponent, containerTmpDirPath); // Both containers register Register reg = new Register(); reg.setResponseId(0); reg.setLabel("mockcontainer_1___HBASE_MASTER"); RegistrationResponse resp = mockAps.handleRegistration(reg); Assert.assertEquals(0, resp.getResponseId()); Assert.assertEquals(RegistrationStatus.OK, resp.getResponseStatus()); reg = new Register(); reg.setResponseId(0); reg.setLabel("mockcontainer_1___HBASE_REGIONSERVER"); resp = mockAps.handleRegistration(reg); Assert.assertEquals(0, resp.getResponseId()); Assert.assertEquals(RegistrationStatus.OK, resp.getResponseStatus()); // Both issue install command HeartBeat hb = new HeartBeat(); hb.setResponseId(1); hb.setHostname("mockcontainer_1___HBASE_MASTER"); HeartBeatResponse hbr = mockAps.handleHeartBeat(hb); Assert.assertEquals(2, hbr.getResponseId()); Mockito.verify(mockAps, Mockito.times(1)).addInstallCommand(anyString(), anyString(), any(HeartBeatResponse.class), anyString(), Mockito.anyLong()); hb = new HeartBeat(); hb.setResponseId(1); hb.setHostname("mockcontainer_1___HBASE_REGIONSERVER"); hbr = mockAps.handleHeartBeat(hb); Assert.assertEquals(2, hbr.getResponseId()); Mockito.verify(mockAps, Mockito.times(2)).addInstallCommand(anyString(), anyString(), any(HeartBeatResponse.class), anyString(), Mockito.anyLong()); // RS succeeds install but does not start hb = new HeartBeat(); hb.setResponseId(2); hb.setHostname("mockcontainer_1___HBASE_REGIONSERVER"); CommandReport cr = new CommandReport(); cr.setRole("HBASE_REGIONSERVER"); cr.setRoleCommand("INSTALL"); cr.setStatus("COMPLETED"); cr.setFolders(new HashMap<String, String>() { { put("a", "b"); } }); hb.setReports(Arrays.asList(cr)); hbr = mockAps.handleHeartBeat(hb); Assert.assertEquals(3, hbr.getResponseId()); Mockito.verify(mockAps, Mockito.times(0)).addStartCommand(anyString(), anyString(), any(HeartBeatResponse.class), anyString(), Mockito.anyLong(), Matchers.anyBoolean()); // RS still does not start hb = new HeartBeat(); hb.setResponseId(3); hb.setHostname("mockcontainer_1___HBASE_REGIONSERVER"); hbr = mockAps.handleHeartBeat(hb); Assert.assertEquals(4, hbr.getResponseId()); Mockito.verify(mockAps, Mockito.times(0)).addStartCommand(anyString(), anyString(), any(HeartBeatResponse.class), anyString(), Mockito.anyLong(), Matchers.anyBoolean()); // MASTER succeeds install and issues start hb = new HeartBeat(); hb.setResponseId(2); hb.setHostname("mockcontainer_1___HBASE_MASTER"); hb.setFqdn("host1"); cr = new CommandReport(); cr.setRole("HBASE_MASTER"); cr.setRoleCommand("INSTALL"); cr.setStatus("COMPLETED"); Map<String, String> ap = new HashMap<String, String>(); ap.put("a.port", "10233"); cr.setAllocatedPorts(ap); hb.setReports(Arrays.asList(cr)); hbr = mockAps.handleHeartBeat(hb); Assert.assertEquals(3, hbr.getResponseId()); Mockito.verify(mockAps, Mockito.times(1)).addStartCommand(anyString(), anyString(), any(HeartBeatResponse.class), anyString(), Mockito.anyLong(), Matchers.anyBoolean()); Map<String, String> allocatedPorts = mockAps.getAllocatedPorts(); Assert.assertTrue(allocatedPorts != null); Assert.assertTrue(allocatedPorts.size() == 1); Assert.assertTrue(allocatedPorts.containsKey("a.port")); // RS still does not start hb = new HeartBeat(); hb.setResponseId(4); hb.setHostname("mockcontainer_1___HBASE_REGIONSERVER"); hbr = mockAps.handleHeartBeat(hb); Assert.assertEquals(5, hbr.getResponseId()); Mockito.verify(mockAps, Mockito.times(1)).addStartCommand(anyString(), anyString(), any(HeartBeatResponse.class), anyString(), Mockito.anyLong(), Matchers.anyBoolean()); // MASTER succeeds start hb = new HeartBeat(); hb.setResponseId(3); hb.setHostname("mockcontainer_1___HBASE_MASTER"); cr = new CommandReport(); cr.setRole("HBASE_MASTER"); cr.setRoleCommand("START"); cr.setStatus("COMPLETED"); hb.setReports(Arrays.asList(cr)); mockAps.handleHeartBeat(hb); Mockito.verify(mockAps, Mockito.times(1)).addGetConfigCommand(anyString(), anyString(), any(HeartBeatResponse.class)); // RS starts now hb = new HeartBeat(); hb.setResponseId(5); hb.setHostname("mockcontainer_1___HBASE_REGIONSERVER"); hbr = mockAps.handleHeartBeat(hb); Assert.assertEquals(6, hbr.getResponseId()); Mockito.verify(mockAps, Mockito.times(2)).addStartCommand(anyString(), anyString(), any(HeartBeatResponse.class), anyString(), Mockito.anyLong(), Matchers.anyBoolean()); // JDK7 } catch (SliderException he) { log.warn(he.getMessage()); } catch (IOException he) { log.warn(he.getMessage()); } Mockito.verify(mockAps, Mockito.times(1)).publishFolderPaths(anyMap(), anyString(), anyString(), anyString()); }