/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public override void StartLocalizer(Path nmPrivateContainerTokensPath, IPEndPoint nmAddr, string user, string appId, string locId, LocalDirsHandlerService dirsHandler ) { lock (this) { IList <string> localDirs = dirsHandler.GetLocalDirs(); IList <string> logDirs = dirsHandler.GetLogDirs(); ContainerLocalizer localizer = new ContainerLocalizer(lfs, user, appId, locId, GetPaths (localDirs), RecordFactoryProvider.GetRecordFactory(GetConf())); CreateUserLocalDirs(localDirs, user); CreateUserCacheDirs(localDirs, user); CreateAppDirs(localDirs, user, appId); CreateAppLogDirs(appId, logDirs, user); // randomly choose the local directory Path appStorageDir = GetWorkingDir(localDirs, user, appId); string tokenFn = string.Format(ContainerLocalizer.TokenFileNameFmt, locId); Path tokenDst = new Path(appStorageDir, tokenFn); CopyFile(nmPrivateContainerTokensPath, tokenDst, user); Log.Info("Copying from " + nmPrivateContainerTokensPath + " to " + tokenDst); lfs.SetWorkingDirectory(appStorageDir); Log.Info("CWD set to " + appStorageDir + " = " + lfs.GetWorkingDirectory()); // TODO: DO it over RPC for maintaining similarity? localizer.RunLocalization(nmAddr); } }
public virtual void BuildMainArgs(IList <string> command, string user, string appId , string locId, IPEndPoint nmAddr, IList <string> localDirs) { ContainerLocalizer.BuildMainArgs(command, user, appId, locId, nmAddr, localDirs); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public override void StartLocalizer(Path nmPrivateContainerTokens, IPEndPoint nmAddr , string user, string appId, string locId, LocalDirsHandlerService dirsHandler) { IList <string> localDirs = dirsHandler.GetLocalDirs(); IList <string> logDirs = dirsHandler.GetLogDirs(); Path classpathJarPrivateDir = dirsHandler.GetLocalPathForWrite(ResourceLocalizationService .NmPrivateDir); CreateUserLocalDirs(localDirs, user); CreateUserCacheDirs(localDirs, user); CreateAppDirs(localDirs, user, appId); CreateAppLogDirs(appId, logDirs, user); Path appStorageDir = GetWorkingDir(localDirs, user, appId); string tokenFn = string.Format(ContainerLocalizer.TokenFileNameFmt, locId); Path tokenDst = new Path(appStorageDir, tokenFn); CopyFile(nmPrivateContainerTokens, tokenDst, user); FilePath cwdApp = new FilePath(appStorageDir.ToString()); if (Log.IsDebugEnabled()) { Log.Debug(string.Format("cwdApp: %s", cwdApp)); } IList <string> command; command = new AList <string>(); //use same jvm as parent FilePath jvm = new FilePath(new FilePath(Runtime.GetProperty("java.home"), "bin") , "java.exe"); command.AddItem(jvm.ToString()); Path cwdPath = new Path(cwdApp.GetPath()); // Build a temp classpath jar. See ContainerLaunch.sanitizeEnv(). // Passing CLASSPATH explicitly is *way* too long for command line. string classPath = Runtime.GetProperty("java.class.path"); IDictionary <string, string> env = new Dictionary <string, string>(Sharpen.Runtime.GetEnv ()); string[] jarCp = FileUtil.CreateJarWithClassPath(classPath, classpathJarPrivateDir , cwdPath, env); string classPathJar = LocalizeClasspathJar(new Path(jarCp[0]), cwdPath, user).ToString (); command.AddItem("-classpath"); command.AddItem(classPathJar + jarCp[1]); string javaLibPath = Runtime.GetProperty("java.library.path"); if (javaLibPath != null) { command.AddItem("-Djava.library.path=" + javaLibPath); } ContainerLocalizer.BuildMainArgs(command, user, appId, locId, nmAddr, localDirs); string cmdLine = StringUtils.Join(command, " "); string localizerPid = string.Format(LocalizerPidFormat, locId); WindowsSecureContainerExecutor.WintuilsProcessStubExecutor stubExecutor = new WindowsSecureContainerExecutor.WintuilsProcessStubExecutor (cwdApp.GetAbsolutePath(), localizerPid, user, "nul:", cmdLine); try { stubExecutor.Execute(); stubExecutor.ValidateResult(); } finally { stubExecutor.Close(); try { KillContainer(localizerPid, ContainerExecutor.Signal.Kill); } catch (Exception e) { Log.Warn(string.Format("An exception occured during the cleanup of localizer job %s:%n%s" , localizerPid, StringUtils.StringifyException(e))); } } }