List of usage examples for org.apache.hadoop.yarn.server.nodemanager.containermanager.container Container getLaunchContext
ContainerLaunchContext getLaunchContext();
From source file:com.github.sakserv.minicluster.yarn.InJvmContainerExecutor.java
License:Apache License
/** * Overrides the parent method while still invoking it. Since * {@link #isContainerActive(ContainerId)} method is also overridden here and * always returns 'false' the super.launchContainer(..) will only go through * the prep routine (e.g., creating temp dirs etc.) while never launching the * actual container via the launch script. This will ensure that all the * expectations of the container to be launched (e.g., symlinks etc.) are * satisfied. The actual launch will be performed by invoking * {@link #doLaunch(Container, Path)} method. *///from w w w .j a va 2s .c om public int launchContainer(ContainerStartContext containerStartContext) throws IOException { Container container = containerStartContext.getContainer(); Path containerWorkDir = containerStartContext.getContainerWorkDir(); super.launchContainer(containerStartContext); int exitCode = 0; if (container.getLaunchContext().getCommands().toString().contains("bin/java")) { ExecJavaCliParser result = this.createExecCommandParser(containerWorkDir.toString()); try { exitCode = this.doLaunch(container, containerWorkDir); if (logger.isInfoEnabled()) { logger.info(("Returned: " + exitCode)); } } catch (Exception e) { e.printStackTrace(); } } else { String cmd = container.getLaunchContext().getCommands().get(0); if (logger.isInfoEnabled()) { logger.info("Running Command: " + cmd); } ExecShellCliParser execShellCliParser = new ExecShellCliParser(cmd); try { exitCode = execShellCliParser.runCommand(); } catch (Exception e) { e.printStackTrace(); } if (logger.isInfoEnabled()) { logger.info(("Returned: " + exitCode)); } } return exitCode; }
From source file:com.github.sakserv.minicluster.yarn.InJvmContainerExecutor.java
License:Apache License
/** * Overrides the parent method while still invoking it. Since * {@link #isContainerActive(ContainerId)} method is also overridden here and * always returns 'false' the super.launchContainer(..) will only go through * the prep routine (e.g., creating temp dirs etc.) while never launching the * actual container via the launch script. This will ensure that all the * expectations of the container to be launched (e.g., symlinks etc.) are * satisfied. The actual launch will be performed by invoking * {@link #doLaunch(Container, Path)} method. *///from www . j a va 2s .com public int launchContainer(Container container, Path nmPrivateContainerScriptPath, Path nmPrivateTokensPath, String userName, String appId, Path containerWorkDir, List<String> localDirs, List<String> logDirs) throws IOException { ContainerStartContext containerStartContext = new ContainerStartContext.Builder().setContainer(container) .setLocalizedResources(container.getLocalizedResources()) .setNmPrivateContainerScriptPath(nmPrivateContainerScriptPath) .setNmPrivateTokensPath(nmPrivateTokensPath).setUser(userName).setAppId(appId) .setContainerWorkDir(containerWorkDir).setLocalDirs(localDirs).setLocalDirs(logDirs).build(); super.launchContainer(containerStartContext); int exitCode = 0; if (container.getLaunchContext().getCommands().toString().contains("bin/java")) { ExecJavaCliParser result = this.createExecCommandParser(containerWorkDir.toString()); try { exitCode = this.doLaunch(container, containerWorkDir); if (logger.isInfoEnabled()) { logger.info(("Returned: " + exitCode)); } } catch (Exception e) { e.printStackTrace(); } } else { String cmd = container.getLaunchContext().getCommands().get(0); if (logger.isInfoEnabled()) { logger.info("Running Command: " + cmd); } ExecShellCliParser execShellCliParser = new ExecShellCliParser(cmd); try { exitCode = execShellCliParser.runCommand(); } catch (Exception e) { e.printStackTrace(); } if (logger.isInfoEnabled()) { logger.info(("Returned: " + exitCode)); } } return exitCode; }
From source file:com.github.sakserv.minicluster.yarn.InJvmContainerExecutor.java
License:Apache License
/** * Will launch containers within the same JVM as this Container Executor. It * will do so by: - extracting Container's class name and program arguments * from the launch script (e.g., launch_container.sh) - Creating an isolated * ClassLoader for each container - Calling doLaunchContainer(..) method to * launch Container//from w w w.ja va 2 s.c o m */ private int doLaunch(Container container, Path containerWorkDir) throws Exception { Map<String, String> environment = container.getLaunchContext().getEnvironment(); EnvironmentUtils.putAll(environment); Set<URL> additionalClassPathUrls = this.filterAndBuildUserClasspath(container); ExecJavaCliParser javaCliParser = this.createExecCommandParser(containerWorkDir.toString()); UserGroupInformation.setLoginUser(null); try { // create Isolated Class Loader for each container and set it as context // class loader URLClassLoader containerCl = new URLClassLoader( additionalClassPathUrls.toArray(additionalClassPathUrls.toArray(new URL[] {})), null); Thread.currentThread().setContextClassLoader(containerCl); String containerLauncher = javaCliParser.getMain(); Class<?> containerClass = Class.forName(containerLauncher, true, containerCl); Method mainMethod = containerClass.getMethod("main", new Class[] { String[].class }); mainMethod.setAccessible(true); String[] arguments = javaCliParser.getMainArguments(); this.doLaunchContainer(containerClass, mainMethod, arguments); } catch (Exception e) { logger.error("Failed to launch container " + container, e); container.handle(new ContainerDiagnosticsUpdateEvent(container.getContainerId(), e.getMessage())); return -1; } finally { logger.info("Removing symlinks"); this.cleanUp(); } return 0; }
From source file:com.hortonworks.minicluster.InJvmContainerExecutor.java
License:Apache License
/** * Will launch containers within the same JVM as this Container Executor. It * will do so by: - extracting Container's class name and program arguments * from the launch script (e.g., launch_container.sh) - Creating an isolated * ClassLoader for each container - Calling doLaunchContainer(..) method to * launch Container//from w ww . j a v a2 s . c o m */ private int doLaunch(Container container, Path containerWorkDir) { Map<String, String> environment = container.getLaunchContext().getEnvironment(); EnvironmentUtils.putAll(environment); Set<URL> additionalClassPathUrls = this.filterAndBuildUserClasspath(container); ExecJavaCliParser javaCliParser = this.createExecCommandParser(containerWorkDir.toString()); UserGroupInformation.setLoginUser(null); try { // create Isolated Class Loader for each container and set it as context // class loader URLClassLoader containerCl = new URLClassLoader( additionalClassPathUrls.toArray(additionalClassPathUrls.toArray(new URL[] {})), null); Thread.currentThread().setContextClassLoader(containerCl); String containerLauncher = javaCliParser.getMain(); Class<?> containerClass = Class.forName(containerLauncher, true, containerCl); Method mainMethod = containerClass.getMethod("main", new Class[] { String[].class }); mainMethod.setAccessible(true); String[] arguments = javaCliParser.getMainArguments(); this.doLaunchContainer(containerClass, mainMethod, arguments); } catch (Exception e) { logger.error("Failed to launch container " + container, e); container.handle(new ContainerDiagnosticsUpdateEvent(container.getContainerId(), e.getMessage())); return -1; } finally { logger.info("Removing symlinks"); this.cleanUp(); } return 0; }
From source file:oz.hadoop.yarn.test.cluster.InJvmContainerExecutor.java
License:Apache License
/** * *///from w ww .j a v a 2 s.com @Override public int launchContainer(final Container container, Path nmPrivateContainerScriptPath, Path nmPrivateTokensPath, String userName, String appId, final Path containerWorkDir, List<String> localDirs, List<String> logDirs) throws IOException { System.out.println("ENV: " + container.getLaunchContext().getEnvironment()); if ("JAVA".equalsIgnoreCase(container.getLaunchContext().getEnvironment().get("CONTAINER_TYPE"))) { this.prepareContainerDirectories(container, nmPrivateContainerScriptPath, nmPrivateTokensPath, userName, appId, containerWorkDir, localDirs, logDirs); return this.launchJavaContainer(container, containerWorkDir); } else { return super.launchContainer(container, nmPrivateContainerScriptPath, nmPrivateTokensPath, userName, appId, containerWorkDir, localDirs, logDirs); } }
From source file:oz.hadoop.yarn.test.cluster.InJvmContainerExecutor.java
License:Apache License
/** * *///from ww w . j a va 2s . co m private int doLaunch(Container container, Path containerWorkDir) { Set<Path> paths = this.getIncomingClassPathEntries(container); String currentClassPath = System.getProperty("java.class.path"); final Set<URL> additionalClassPathUrls = new HashSet<>(); if (logger.isDebugEnabled()) { logger.debug("Building additional classpath for the container: " + container); } List<String> ae = Arrays.asList(additionalClassPathExclusions); // for logging purposes for (Path path : paths) { String resourceName = path.getName(); if (currentClassPath.contains(resourceName)) { if (logger.isDebugEnabled()) { logger.debug("\t skipping " + resourceName + ". Already in the classpath."); } } else { if (!this.shouldExclude(path.getName())) { if (logger.isDebugEnabled()) { logger.debug("\t adding " + resourceName + " to the classpath"); } try { additionalClassPathUrls.add(path.toUri().toURL()); } catch (Exception e) { throw new IllegalArgumentException(e); } } else { if (logger.isDebugEnabled()) { logger.debug( "Excluding " + path.getName() + " based on 'additionalClassPathExclusions': " + ae); } } } } Map<String, String> environment = container.getLaunchContext().getEnvironment(); try { URLClassLoader cl = new URLClassLoader(additionalClassPathUrls.toArray(new URL[] {})); String containerLauncher = environment.get("CONTAINER_LAUNCHER"); Class<?> amClass = Class.forName(containerLauncher, true, cl); Method mainMethod = amClass.getMethod("main", new Class[] { String[].class }); mainMethod.setAccessible(true); String mainArgs = environment.get("CONTAINER_ARG"); String[] arguments = new String[] { mainArgs, containerLauncher }; mainMethod.invoke(null, (Object) arguments); } catch (Exception e) { logger.error("Failed to launch container " + container, e); container.handle(new ContainerDiagnosticsUpdateEvent(container.getContainerId(), e.getMessage())); return -1968; } return 0; }