AuxServices extends AbstractService implements ServiceStateChangeListener, EventHandler<AuxServicesEvent> { Collection<AuxiliaryService> getServices() { return Collections.unmodifiableCollection(serviceMap.values()); } AuxServices(AuxiliaryLocalPathHandler auxiliaryLocalPathHandler,
      Context nmContext, DeletionService deletionService); Map<String, ByteBuffer> getMetaData(); @Override void serviceInit(Configuration conf); @Override void serviceStart(); @Override void serviceStop(); @Override void stateChanged(Service service); @Override void handle(AuxServicesEvent event); static final String NM_AUX_SERVICE_DIR; static final FsPermission NM_AUX_SERVICE_DIR_PERM; }
@Test public void testAuxUnexpectedStop() { Configuration conf = new Configuration(); conf.setStrings(YarnConfiguration.NM_AUX_SERVICES, new String[] { "Asrv", "Bsrv" }); conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "Asrv"), ServiceA.class, Service.class); conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "Bsrv"), ServiceB.class, Service.class); final AuxServices aux = new AuxServices(MOCK_AUX_PATH_HANDLER, MOCK_CONTEXT, MOCK_DEL_SERVICE); aux.init(conf); aux.start(); Service s = aux.getServices().iterator().next(); s.stop(); assertEquals("Auxiliary service stopped, but AuxService unaffected.", STOPPED, aux.getServiceState()); assertTrue(aux.getServices().isEmpty()); }
@Test public void testAuxServiceRecoverySetup() throws IOException { Configuration conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.NM_RECOVERY_ENABLED, true); conf.set(YarnConfiguration.NM_RECOVERY_DIR, TEST_DIR.toString()); conf.setStrings(YarnConfiguration.NM_AUX_SERVICES, new String[] { "Asrv", "Bsrv" }); conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "Asrv"), RecoverableServiceA.class, Service.class); conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "Bsrv"), RecoverableServiceB.class, Service.class); try { final AuxServices aux = new AuxServices(MOCK_AUX_PATH_HANDLER, MOCK_CONTEXT, MOCK_DEL_SERVICE); aux.init(conf); Assert.assertEquals(2, aux.getServices().size()); File auxStorageDir = new File(TEST_DIR, AuxServices.STATE_STORE_ROOT_NAME); Assert.assertEquals(2, auxStorageDir.listFiles().length); aux.close(); } finally { FileUtil.fullyDelete(TEST_DIR); } }
@Test public void testAuxServicesConfChange() { Configuration conf = new Configuration(); conf.setStrings(YarnConfiguration.NM_AUX_SERVICES, new String[]{"ConfChangeAuxService"}); conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "ConfChangeAuxService"), ConfChangeAuxService.class, Service.class); AuxServices aux = new AuxServices(MOCK_AUX_PATH_HANDLER, MOCK_CONTEXT, MOCK_DEL_SERVICE); conf.set("dummyConfig", "testValue"); aux.init(conf); aux.start(); for (AuxiliaryService s : aux.getServices()) { assertEquals(STARTED, s.getServiceState()); assertEquals(conf.get("dummyConfig"), "testValue"); } aux.stop(); }