public StagingTask(StagingStartMessageRequest message) { UhuruSection uhuruSection = (UhuruSection)ConfigurationManager.GetSection("uhuru"); this.TaskId = message.TaskID; this.Message = message; this.workspace = new StagingWorkspace(Path.Combine(uhuruSection.DEA.BaseDir, "staging"), message.TaskID); this.buildpacksDir = Path.GetFullPath(uhuruSection.DEA.Staging.BuildpacksDirectory); this.stagingTimeout = uhuruSection.DEA.Staging.StagingTimeoutMs; this.gitExe = Path.GetFullPath(uhuruSection.DEA.Staging.GitExecutable); var prisonInfo = new ProcessPrisonCreateInfo(); prisonInfo.Id = this.TaskId; prisonInfo.TotalPrivateMemoryLimit = (long)this.Message.Properties.Resources.MemoryMbytes * 1024 * 1024; if (uhuruSection.DEA.UseDiskQuota) { prisonInfo.DiskQuotaBytes = (long)this.Message.Properties.Resources.DiskMbytes * 1024 * 1024; prisonInfo.DiskQuotaPath = this.workspace.BaseDir; } if (uhuruSection.DEA.UploadThrottleBitsps > 0) { prisonInfo.NetworkOutboundRateLimitBitsPerSecond = uhuruSection.DEA.UploadThrottleBitsps; } this.prison = new ProcessPrison(); prison.Create(prisonInfo); }
private void StartStagingInstance(StagingInstance instance, StagingStartMessageRequest pmessage) { StagingWorkspace workspace = new StagingWorkspace(instance.Properties.Directory); try { try { instance.Lock.EnterWriteLock(); instance.Properties.UseDiskQuota = this.useDiskQuota; instance.Properties.UploadThrottleBitsps = this.uploadThrottleBitsps; UriBuilder streamingLog = new UriBuilder(); streamingLog.Host = this.ExternalHost; streamingLog.Scheme = "http"; streamingLog.Path = string.Format("/staging_tasks/{0}/file_path", pmessage.TaskID); streamingLog.Query = string.Format("path={0}×tamp={1}", workspace.StagingLogSuffix, RubyCompatibility.DateTimeToEpochSeconds(DateTime.Now)); instance.Properties.StreamingLogUrl = DEAUtilities.GetHmacedUri(streamingLog.Uri.ToString(), this.directoryServerHmacKey, new string[] { "path", "timestamp" }).ToString(); instance.Workspace = workspace; instance.Properties.TaskLog = workspace.StagingLogPath; } finally { instance.Lock.ExitWriteLock(); } instance.AfterSetup += new StagingInstance.StagingTaskEventHandler(this.AfterStagingSetup); Logger.Info("Started staging task {0}", instance.Properties.TaskId); try { instance.SetupStagingEnvironment(); } catch (Exception ex) { Logger.Error("Error setting up staging environment: ", ex.ToString()); throw ex; } instance.UnpackDroplet(); instance.PrepareStagingDirs(); instance.GetBuildpack(pmessage, this.gitPath, this.buildpacksDir); this.stagingTaskRegistry.ScheduleSnapshotStagingState(); try { Logger.Info("Staging task {0}: Running compilation script", pmessage.TaskID); instance.CreatePrison(); this.stagingTaskRegistry.ScheduleSnapshotStagingState(); instance.CompileProcess = instance.Buildpack.StartCompile(instance.Prison); instance.Lock.EnterWriteLock(); instance.Properties.Start = DateTime.Now; } finally { if(instance.Lock.IsWriteLockHeld) { instance.Lock.ExitWriteLock(); } } } catch (Exception ex) { instance.StagingException = ex; instance.Properties.Stopped = true; Logger.Error(ex.ToString()); } }