NodeManager extends CompositeService implements EventHandler<NodeManagerEvent> { protected NodeLabelsProvider createNodeLabelsProvider(Configuration conf) throws IOException { NodeLabelsProvider provider = null; String providerString = conf.get(YarnConfiguration.NM_NODE_LABELS_PROVIDER_CONFIG, null); if (providerString == null || providerString.trim().length() == 0) { return provider; } switch (providerString.trim().toLowerCase()) { case YarnConfiguration.CONFIG_NODE_LABELS_PROVIDER: provider = new ConfigurationNodeLabelsProvider(); break; case YarnConfiguration.SCRIPT_NODE_LABELS_PROVIDER: provider = new ScriptBasedNodeLabelsProvider(); break; default: try { Class<? extends NodeLabelsProvider> labelsProviderClass = conf.getClass(YarnConfiguration.NM_NODE_LABELS_PROVIDER_CONFIG, null, NodeLabelsProvider.class); provider = labelsProviderClass.newInstance(); } catch (InstantiationException | IllegalAccessException | RuntimeException e) { LOG.error("Failed to create NodeLabelsProvider based on Configuration", e); throw new IOException( "Failed to create NodeLabelsProvider : " + e.getMessage(), e); } } if (LOG.isDebugEnabled()) { LOG.debug("Distributed Node Labels is enabled" + " with provider class as : " + provider.getClass().toString()); } return provider; } NodeManager(); static long getNMStartupTime(); static NodeHealthScriptRunner getNodeHealthScriptRunner(Configuration conf); String getName(); NodeHealthCheckerService getNodeHealthChecker(); @Override void handle(NodeManagerEvent event); @VisibleForTesting Context getNMContext(); static void main(String[] args); @VisibleForTesting @Private NodeStatusUpdater getNodeStatusUpdater(); static final int SHUTDOWN_HOOK_PRIORITY; }
@Test public void testCreationOfNodeLabelsProviderService() throws InterruptedException { try { NodeManager nodeManager = new NodeManager(); Configuration conf = new Configuration(); NodeLabelsProvider labelsProviderService = nodeManager.createNodeLabelsProvider(conf); Assert .assertNull( "LabelsProviderService should not be initialized in default configuration", labelsProviderService); conf.set( YarnConfiguration.NM_NODE_LABELS_PROVIDER_CONFIG, "org.apache.hadoop.yarn.server.nodemanager.nodelabels.ConfigurationNodeLabelsProvider"); labelsProviderService = nodeManager.createNodeLabelsProvider(conf); Assert.assertNotNull("LabelsProviderService should be initialized When " + "node labels provider class is configured", labelsProviderService); conf.set(YarnConfiguration.NM_NODE_LABELS_PROVIDER_CONFIG, "org.apache.hadoop.yarn.server.nodemanager.NodeManager"); try { labelsProviderService = nodeManager.createNodeLabelsProvider(conf); Assert.fail("Expected to throw IOException on Invalid configuration"); } catch (IOException e) { } Assert.assertNotNull("LabelsProviderService should be initialized When " + "node labels provider class is configured", labelsProviderService); conf.set(YarnConfiguration.NM_NODE_LABELS_PROVIDER_CONFIG, YarnConfiguration.CONFIG_NODE_LABELS_PROVIDER); labelsProviderService = nodeManager.createNodeLabelsProvider(conf); Assert.assertNotNull("LabelsProviderService should be initialized When " + "node labels provider class is configured", labelsProviderService); } catch (Exception e) { Assert.fail("Exception caught"); e.printStackTrace(); } }