YARN-1065. NM should provide AuxillaryService data to the container (Xuan Gong via bikas)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1520135 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cd663baf16
commit
49afc64cd4
|
@ -86,6 +86,9 @@ Release 2.1.1-beta - UNRELEASED
|
|||
applications together with running apps by default, following up YARN-1074.
|
||||
(Xuan Gong via vinodkv)
|
||||
|
||||
YARN-1065. NM should provide AuxillaryService data to the container (Xuan
|
||||
Gong via bikas)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
BUG FIXES
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.yarn.util;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
|
||||
public class AuxiliaryServiceHelper {
|
||||
|
||||
public final static String NM_AUX_SERVICE = "NM_AUX_SERVICE_";
|
||||
|
||||
public static ByteBuffer getServiceDataFromEnv(String serviceName,
|
||||
Map<String, String> env) {
|
||||
byte[] metaData =
|
||||
Base64.decodeBase64(env.get(getPrefixServiceName(serviceName)));
|
||||
return ByteBuffer.wrap(metaData);
|
||||
}
|
||||
|
||||
public static void setServiceDataIntoEnv(String serviceName,
|
||||
ByteBuffer metaData, Map<String, String> env) {
|
||||
byte[] byteData = metaData.array();
|
||||
env.put(getPrefixServiceName(serviceName),
|
||||
Base64.encodeBase64String(byteData));
|
||||
}
|
||||
|
||||
private static String getPrefixServiceName(String serviceName) {
|
||||
return NM_AUX_SERVICE + serviceName;
|
||||
}
|
||||
}
|
|
@ -216,7 +216,7 @@ public class ContainerManagerImpl extends CompositeService implements
|
|||
|
||||
protected ContainersLauncher createContainersLauncher(Context context,
|
||||
ContainerExecutor exec) {
|
||||
return new ContainersLauncher(context, this.dispatcher, exec, dirsHandler);
|
||||
return new ContainersLauncher(context, this.dispatcher, exec, dirsHandler, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -410,7 +410,7 @@ public class ContainerManagerImpl extends CompositeService implements
|
|||
}
|
||||
}
|
||||
|
||||
return StartContainersResponse.newInstance(auxiliaryServices.getMetaData(),
|
||||
return StartContainersResponse.newInstance(getAuxServiceMetaData(),
|
||||
succeededContainers, failedContainers);
|
||||
}
|
||||
|
||||
|
@ -759,4 +759,7 @@ public class ContainerManagerImpl extends CompositeService implements
|
|||
return this.context;
|
||||
}
|
||||
|
||||
public Map<String, ByteBuffer> getAuxServiceMetaData() {
|
||||
return this.auxiliaryServices.getMetaData();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
|
@ -60,6 +61,7 @@ import org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor.ExitCode;
|
|||
import org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor.Signal;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.Context;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerDiagnosticsUpdateEvent;
|
||||
|
@ -70,6 +72,7 @@ import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.Cont
|
|||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ResourceLocalizationService;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader;
|
||||
import org.apache.hadoop.yarn.util.Apps;
|
||||
import org.apache.hadoop.yarn.util.AuxiliaryServiceHelper;
|
||||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||
|
||||
public class ContainerLaunch implements Callable<Integer> {
|
||||
|
@ -88,6 +91,7 @@ public class ContainerLaunch implements Callable<Integer> {
|
|||
private final Container container;
|
||||
private final Configuration conf;
|
||||
private final Context context;
|
||||
private final ContainerManagerImpl containerManager;
|
||||
|
||||
private volatile AtomicBoolean shouldLaunchContainer = new AtomicBoolean(false);
|
||||
private volatile AtomicBoolean completed = new AtomicBoolean(false);
|
||||
|
@ -101,7 +105,8 @@ public class ContainerLaunch implements Callable<Integer> {
|
|||
|
||||
public ContainerLaunch(Context context, Configuration configuration,
|
||||
Dispatcher dispatcher, ContainerExecutor exec, Application app,
|
||||
Container container, LocalDirsHandlerService dirsHandler) {
|
||||
Container container, LocalDirsHandlerService dirsHandler,
|
||||
ContainerManagerImpl containerManager) {
|
||||
this.context = context;
|
||||
this.conf = configuration;
|
||||
this.app = app;
|
||||
|
@ -109,6 +114,7 @@ public class ContainerLaunch implements Callable<Integer> {
|
|||
this.container = container;
|
||||
this.dispatcher = dispatcher;
|
||||
this.dirsHandler = dirsHandler;
|
||||
this.containerManager = containerManager;
|
||||
this.sleepDelayBeforeSigKill =
|
||||
conf.getLong(YarnConfiguration.NM_SLEEP_DELAY_BEFORE_SIGKILL_MS,
|
||||
YarnConfiguration.DEFAULT_NM_SLEEP_DELAY_BEFORE_SIGKILL_MS);
|
||||
|
@ -227,7 +233,6 @@ public class ContainerLaunch implements Callable<Integer> {
|
|||
ApplicationConstants.CONTAINER_TOKEN_FILE_ENV_NAME,
|
||||
new Path(containerWorkDir,
|
||||
FINAL_CONTAINER_TOKENS_FILE).toUri().getPath());
|
||||
|
||||
// Sanitize the container's environment
|
||||
sanitizeEnv(environment, containerWorkDir, appDirs, containerLogDirs,
|
||||
localResources);
|
||||
|
@ -680,6 +685,12 @@ public class ContainerLaunch implements Callable<Integer> {
|
|||
environment.put(Environment.CLASSPATH.name(), classPathJar);
|
||||
}
|
||||
}
|
||||
// put AuxiliaryService data to environment
|
||||
for (Map.Entry<String, ByteBuffer> meta : containerManager
|
||||
.getAuxServiceMetaData().entrySet()) {
|
||||
AuxiliaryServiceHelper.setServiceDataIntoEnv(
|
||||
meta.getKey(), meta.getValue(), environment);
|
||||
}
|
||||
}
|
||||
|
||||
static void writeLaunchEnv(OutputStream out,
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor;
|
|||
import org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor.ExitCode;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.Context;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEventType;
|
||||
|
@ -65,6 +66,7 @@ public class ContainersLauncher extends AbstractService
|
|||
private final Context context;
|
||||
private final ContainerExecutor exec;
|
||||
private final Dispatcher dispatcher;
|
||||
private final ContainerManagerImpl containerManager;
|
||||
|
||||
private LocalDirsHandlerService dirsHandler;
|
||||
@VisibleForTesting
|
||||
|
@ -89,12 +91,14 @@ public class ContainersLauncher extends AbstractService
|
|||
|
||||
|
||||
public ContainersLauncher(Context context, Dispatcher dispatcher,
|
||||
ContainerExecutor exec, LocalDirsHandlerService dirsHandler) {
|
||||
ContainerExecutor exec, LocalDirsHandlerService dirsHandler,
|
||||
ContainerManagerImpl containerManager) {
|
||||
super("containers-launcher");
|
||||
this.exec = exec;
|
||||
this.context = context;
|
||||
this.dispatcher = dispatcher;
|
||||
this.dirsHandler = dirsHandler;
|
||||
this.containerManager = containerManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,7 +132,7 @@ public class ContainersLauncher extends AbstractService
|
|||
|
||||
ContainerLaunch launch =
|
||||
new ContainerLaunch(context, getConfig(), dispatcher, exec, app,
|
||||
event.getContainer(), dirsHandler);
|
||||
event.getContainer(), dirsHandler, containerManager);
|
||||
running.put(containerId,
|
||||
new RunningContainer(containerLauncher.submit(launch),
|
||||
launch));
|
||||
|
|
|
@ -145,7 +145,7 @@ public class DummyContainerManager extends ContainerManagerImpl {
|
|||
protected ContainersLauncher createContainersLauncher(Context context,
|
||||
ContainerExecutor exec) {
|
||||
return new ContainersLauncher(context, super.dispatcher, exec,
|
||||
super.dirsHandler) {
|
||||
super.dirsHandler, this) {
|
||||
@Override
|
||||
public void handle(ContainersLauncherEvent event) {
|
||||
Container container = event.getContainer();
|
||||
|
|
|
@ -20,8 +20,11 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
|
@ -211,6 +214,16 @@ public abstract class BaseContainerManagerTest {
|
|||
NMTokenIdentifier nmTokenIdentifier) throws InvalidToken {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ByteBuffer> getAuxServiceMetaData() {
|
||||
Map<String, ByteBuffer> serviceData = new HashMap<String, ByteBuffer>();
|
||||
serviceData.put("AuxService1",
|
||||
ByteBuffer.wrap("AuxServiceMetaData1".getBytes()));
|
||||
serviceData.put("AuxService2",
|
||||
ByteBuffer.wrap("AuxServiceMetaData2".getBytes()));
|
||||
return serviceData;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -650,7 +650,7 @@ public class TestContainer {
|
|||
Context context = mock(Context.class);
|
||||
when(context.getApplications()).thenReturn(
|
||||
new ConcurrentHashMap<ApplicationId, Application>());
|
||||
launcher = new ContainersLauncher(context, dispatcher, null, null);
|
||||
launcher = new ContainersLauncher(context, dispatcher, null, null, null);
|
||||
// create a mock ExecutorService, which will not really launch
|
||||
// ContainerLaunch at all.
|
||||
launcher.containerLauncher = mock(ExecutorService.class);
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -28,6 +29,7 @@ import java.io.FileOutputStream;
|
|||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -37,6 +39,7 @@ import java.util.Map;
|
|||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileUtil;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
|
@ -70,11 +73,13 @@ import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
|
|||
import org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor.ExitCode;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.DefaultContainerExecutor;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.BaseContainerManagerTest;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManagerImpl;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEventType;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerExitEvent;
|
||||
import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ContainerLocalizer;
|
||||
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
|
||||
import org.apache.hadoop.yarn.util.AuxiliaryServiceHelper;
|
||||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||
import org.apache.hadoop.yarn.util.LinuxResourceCalculatorPlugin;
|
||||
import org.apache.hadoop.yarn.util.ResourceCalculatorPlugin;
|
||||
|
@ -381,6 +386,12 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|||
+ processStartFile);
|
||||
fileWriter.println("@echo " + Environment.HOME.$() + ">> "
|
||||
+ processStartFile);
|
||||
for (String serviceName : containerManager.getAuxServiceMetaData()
|
||||
.keySet()) {
|
||||
fileWriter.println("@echo" + AuxiliaryServiceHelper.NM_AUX_SERVICE
|
||||
+ serviceName + " >> "
|
||||
+ processStartFile);
|
||||
}
|
||||
fileWriter.println("@echo " + cId + ">> " + processStartFile);
|
||||
fileWriter.println("@ping -n 100 127.0.0.1 >nul");
|
||||
} else {
|
||||
|
@ -403,6 +414,12 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|||
+ processStartFile);
|
||||
fileWriter.write("\necho $" + Environment.HOME.name() + " >> "
|
||||
+ processStartFile);
|
||||
for (String serviceName : containerManager.getAuxServiceMetaData()
|
||||
.keySet()) {
|
||||
fileWriter.write("\necho $" + AuxiliaryServiceHelper.NM_AUX_SERVICE
|
||||
+ serviceName + " >> "
|
||||
+ processStartFile);
|
||||
}
|
||||
fileWriter.write("\necho $$ >> " + processStartFile);
|
||||
fileWriter.write("\nexec sleep 100");
|
||||
}
|
||||
|
@ -487,6 +504,12 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|||
YarnConfiguration.DEFAULT_NM_USER_HOME_DIR),
|
||||
reader.readLine());
|
||||
|
||||
for (String serviceName : containerManager.getAuxServiceMetaData().keySet()) {
|
||||
Assert.assertEquals(
|
||||
containerManager.getAuxServiceMetaData().get(serviceName),
|
||||
ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes())));
|
||||
}
|
||||
|
||||
Assert.assertEquals(cId.toString(), containerLaunchContext
|
||||
.getEnvironment().get(Environment.CONTAINER_ID.name()));
|
||||
Assert.assertEquals(context.getNodeId().getHost(), containerLaunchContext
|
||||
|
@ -557,6 +580,16 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|||
DefaultContainerExecutor.containerIsAlive(pid));
|
||||
}
|
||||
|
||||
@Test (timeout = 5000)
|
||||
public void testAuxiliaryServiceHelper() throws Exception {
|
||||
Map<String, String> env = new HashMap<String, String>();
|
||||
String serviceName = "testAuxiliaryService";
|
||||
ByteBuffer bb = ByteBuffer.wrap("testAuxiliaryService".getBytes());
|
||||
AuxiliaryServiceHelper.setServiceDataIntoEnv(serviceName, bb, env);
|
||||
Assert.assertEquals(bb,
|
||||
AuxiliaryServiceHelper.getServiceDataFromEnv(serviceName, env));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelayedKill() throws Exception {
|
||||
containerManager.start();
|
||||
|
@ -703,7 +736,7 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|||
};
|
||||
when(dispatcher.getEventHandler()).thenReturn(eventHandler);
|
||||
ContainerLaunch launch = new ContainerLaunch(context, new Configuration(),
|
||||
dispatcher, exec, null, container, dirsHandler);
|
||||
dispatcher, exec, null, container, dirsHandler, containerManager);
|
||||
launch.call();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue