|
@@ -58,23 +58,26 @@ public abstract class AbstractProviderService implements ProviderService,
|
|
|
Service service)
|
|
|
throws IOException;
|
|
|
|
|
|
- public void buildContainerLaunchContext(AbstractLauncher launcher,
|
|
|
+ public Map<String, String> buildContainerTokens(ComponentInstance instance,
|
|
|
+ Container container,
|
|
|
+ ContainerLaunchService.ComponentLaunchContext compLaunchContext) {
|
|
|
+ // Generate tokens (key-value pair) for config substitution.
|
|
|
+ // Get pre-defined tokens
|
|
|
+ Map<String, String> globalTokens =
|
|
|
+ instance.getComponent().getScheduler().globalTokens;
|
|
|
+ Map<String, String> tokensForSubstitution = ProviderUtils
|
|
|
+ .initCompTokensForSubstitute(instance, container,
|
|
|
+ compLaunchContext);
|
|
|
+ tokensForSubstitution.putAll(globalTokens);
|
|
|
+ return tokensForSubstitution;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void buildContainerEnvironment(AbstractLauncher launcher,
|
|
|
Service service, ComponentInstance instance,
|
|
|
SliderFileSystem fileSystem, Configuration yarnConf, Container container,
|
|
|
- ContainerLaunchService.ComponentLaunchContext compLaunchContext)
|
|
|
- throws IOException, SliderException {
|
|
|
- processArtifact(launcher, instance, fileSystem, service);
|
|
|
-
|
|
|
- ServiceContext context =
|
|
|
- instance.getComponent().getScheduler().getContext();
|
|
|
- // Generate tokens (key-value pair) for config substitution.
|
|
|
- // Get pre-defined tokens
|
|
|
- Map<String, String> globalTokens =
|
|
|
- instance.getComponent().getScheduler().globalTokens;
|
|
|
- Map<String, String> tokensForSubstitution = ProviderUtils
|
|
|
- .initCompTokensForSubstitute(instance, container,
|
|
|
- compLaunchContext);
|
|
|
- tokensForSubstitution.putAll(globalTokens);
|
|
|
+ ContainerLaunchService.ComponentLaunchContext compLaunchContext,
|
|
|
+ Map<String, String> tokensForSubstitution)
|
|
|
+ throws IOException, SliderException {
|
|
|
// Set the environment variables in launcher
|
|
|
launcher.putEnv(ServiceUtils.buildEnvMap(
|
|
|
compLaunchContext.getConfiguration(), tokensForSubstitution));
|
|
@@ -90,17 +93,14 @@ public abstract class AbstractProviderService implements ProviderService,
|
|
|
for (Entry<String, String> entry : launcher.getEnv().entrySet()) {
|
|
|
tokensForSubstitution.put($(entry.getKey()), entry.getValue());
|
|
|
}
|
|
|
- //TODO add component host tokens?
|
|
|
-// ProviderUtils.addComponentHostTokens(tokensForSubstitution, amState);
|
|
|
-
|
|
|
- // create config file on hdfs and add local resource
|
|
|
- ProviderUtils.createConfigFileAndAddLocalResource(launcher, fileSystem,
|
|
|
- compLaunchContext, tokensForSubstitution, instance, context);
|
|
|
-
|
|
|
- // handles static files (like normal file / archive file) for localization.
|
|
|
- ProviderUtils.handleStaticFilesForLocalization(launcher, fileSystem,
|
|
|
- compLaunchContext);
|
|
|
+ }
|
|
|
|
|
|
+ public void buildContainerLaunchCommand(AbstractLauncher launcher,
|
|
|
+ Service service, ComponentInstance instance,
|
|
|
+ SliderFileSystem fileSystem, Configuration yarnConf, Container container,
|
|
|
+ ContainerLaunchService.ComponentLaunchContext compLaunchContext,
|
|
|
+ Map<String, String> tokensForSubstitution)
|
|
|
+ throws IOException, SliderException {
|
|
|
// substitute launch command
|
|
|
String launchCommand = compLaunchContext.getLaunchCommand();
|
|
|
// docker container may have empty commands
|
|
@@ -112,10 +112,15 @@ public abstract class AbstractProviderService implements ProviderService,
|
|
|
operation.addOutAndErrFiles(OUT_FILE, ERR_FILE);
|
|
|
launcher.addCommand(operation.build());
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ public void buildContainerRetry(AbstractLauncher launcher,
|
|
|
+ Configuration yarnConf,
|
|
|
+ ContainerLaunchService.ComponentLaunchContext compLaunchContext) {
|
|
|
// By default retry forever every 30 seconds
|
|
|
launcher.setRetryContext(
|
|
|
- YarnServiceConf.getInt(CONTAINER_RETRY_MAX, DEFAULT_CONTAINER_RETRY_MAX,
|
|
|
+ YarnServiceConf.getInt(CONTAINER_RETRY_MAX,
|
|
|
+ DEFAULT_CONTAINER_RETRY_MAX,
|
|
|
compLaunchContext.getConfiguration(), yarnConf),
|
|
|
YarnServiceConf.getInt(CONTAINER_RETRY_INTERVAL,
|
|
|
DEFAULT_CONTAINER_RETRY_INTERVAL,
|
|
@@ -124,4 +129,38 @@ public abstract class AbstractProviderService implements ProviderService,
|
|
|
DEFAULT_CONTAINER_FAILURES_VALIDITY_INTERVAL,
|
|
|
compLaunchContext.getConfiguration(), yarnConf));
|
|
|
}
|
|
|
+
|
|
|
+ public void buildContainerLaunchContext(AbstractLauncher launcher,
|
|
|
+ Service service, ComponentInstance instance,
|
|
|
+ SliderFileSystem fileSystem, Configuration yarnConf, Container container,
|
|
|
+ ContainerLaunchService.ComponentLaunchContext compLaunchContext)
|
|
|
+ throws IOException, SliderException {
|
|
|
+ processArtifact(launcher, instance, fileSystem, service);
|
|
|
+
|
|
|
+ ServiceContext context =
|
|
|
+ instance.getComponent().getScheduler().getContext();
|
|
|
+ // Generate tokens (key-value pair) for config substitution.
|
|
|
+ Map<String, String> tokensForSubstitution =
|
|
|
+ buildContainerTokens(instance, container, compLaunchContext);
|
|
|
+
|
|
|
+ // Setup launch context environment
|
|
|
+ buildContainerEnvironment(launcher, service, instance,
|
|
|
+ fileSystem, yarnConf, container, compLaunchContext,
|
|
|
+ tokensForSubstitution);
|
|
|
+
|
|
|
+ // create config file on hdfs and add local resource
|
|
|
+ ProviderUtils.createConfigFileAndAddLocalResource(launcher, fileSystem,
|
|
|
+ compLaunchContext, tokensForSubstitution, instance, context);
|
|
|
+
|
|
|
+ // handles static files (like normal file / archive file) for localization.
|
|
|
+ ProviderUtils.handleStaticFilesForLocalization(launcher, fileSystem,
|
|
|
+ compLaunchContext);
|
|
|
+
|
|
|
+ // replace launch command with token specific information
|
|
|
+ buildContainerLaunchCommand(launcher, service, instance, fileSystem,
|
|
|
+ yarnConf, container, compLaunchContext, tokensForSubstitution);
|
|
|
+
|
|
|
+ // Setup container retry settings
|
|
|
+ buildContainerRetry(launcher, yarnConf, compLaunchContext);
|
|
|
+ }
|
|
|
}
|