示例#1
0
        private void AfterStagingFinished(StagingInstance instance)
        {
            StagingStartMessageResponse response = new StagingStartMessageResponse();
            try
            {
                if (instance.StagingException == null)
                {
                    try
                    {
                        Logger.Info("Staging task {0}: Saving buildpackInfo", instance.Properties.TaskId);
                        StagingInfo.SaveBuildpackInfo(Path.Combine(instance.Workspace.StagedDir, StagingWorkspace.StagingInfo), instance.Buildpack.Name, instance.GetStartCommand());
                        this.stagingTaskRegistry.ScheduleSnapshotStagingState();

                        Logger.Debug("Staging task {0}: Packing droplet {1}", instance.Properties.TaskId, instance.Workspace.StagedDropletPath);
                        Directory.CreateDirectory(instance.Workspace.StagedDropletDir);
                        string tempFile = Path.ChangeExtension(instance.Workspace.StagedDropletPath, "tar");
                        DEAUtilities.TarDirectory(instance.Workspace.StagedDir, tempFile);
                        DEAUtilities.GzipFile(tempFile, instance.Workspace.StagedDropletPath);
                        File.Delete(tempFile);

                        if (File.Exists(instance.Workspace.StagedDropletPath))
                        {
                            using (Stream stream = File.OpenRead(instance.Workspace.StagedDropletPath))
                            {
                                using (SHA1 sha = SHA1.Create())
                                {
                                    response.DropletSHA = BitConverter.ToString(sha.ComputeHash(stream)).Replace("-", string.Empty);
                                }
                            }
                        }

                        this.StartStagedDropletInstance(instance, response.DropletSHA);

                        Uri uri = new Uri(instance.Properties.UploadURI);
                        Logger.Debug("Staging task {0}: Uploading droplet {1} to {2}", instance.Properties.TaskId, instance.Workspace.StagedDropletPath, instance.Properties.UploadURI);
                        DEAUtilities.HttpUploadFile(instance.Properties.UploadURI, new FileInfo(instance.Workspace.StagedDropletPath), "upload[droplet]", "application/octet-stream", uri.UserInfo);
                    }
                    catch (Exception ex)
                    {
                        instance.StagingException = ex;
                    }
                    try
                    {
                        Directory.CreateDirectory(instance.Workspace.Cache);
                        string tempFile = Path.ChangeExtension(instance.Workspace.StagedBuildpackCachePath, "tar");
                        DEAUtilities.TarDirectory(instance.Workspace.Cache, tempFile);
                        DEAUtilities.GzipFile(tempFile, instance.Workspace.StagedBuildpackCachePath);
                        Uri uri = new Uri(instance.Properties.BuildpackCacheUploadURI);
                        Logger.Debug("Staging task {0}: Uploading buildpack cache {1} to {2}", instance.Properties.TaskId, instance.Workspace.StagedBuildpackCachePath, instance.Properties.BuildpackCacheUploadURI);
                        DEAUtilities.HttpUploadFile(instance.Properties.BuildpackCacheUploadURI, new FileInfo(instance.Workspace.StagedBuildpackCachePath), "upload[droplet]", "application/octet-stream", uri.UserInfo);
                    }
                    catch
                    {
                        Logger.Debug("Staging task {0}: Cannot pack buildpack cache", instance.Properties.TaskId);
                    }
                }

                if (instance.StagingException != null)
                {
                    response.Error = instance.StagingException.ToString();
                }

                response.TaskId = instance.Properties.TaskId;

                // try to read log. don't throw exception if it fails
                try
                {
                    response.TaskLog = File.ReadAllText(instance.Properties.TaskLog);
                }
                catch { }

                if (instance.Properties.DetectedBuildpack != null)
                {
                    response.DetectedBuildpack = instance.Properties.DetectedBuildpack;
                }

                this.deaReactor.SendReply(instance.Properties.Reply, response.SerializeToJson());
                Logger.Debug("Staging task {0}: sent reply {1}", instance.Properties.TaskId, response.SerializeToJson());
            }
            finally
            {
                Logger.Debug("Cleaning up directory {0}", instance.Workspace.BaseDir);
                instance.Cleanup();
            }
        }
示例#2
0
 private void AfterStagingSetup(StagingInstance instance)
 {
     StagingStartMessageResponse response = new StagingStartMessageResponse();
     response.TaskId = instance.Properties.TaskId;
     response.TaskStreamingLogURL = instance.Properties.StreamingLogUrl;
     if (instance.StagingException != null)
     {
         response.Error = instance.StagingException.ToString();
     }
     this.deaReactor.SendReply(instance.Properties.Reply, response.SerializeToJson());
     Logger.Debug("Staging task {0}: sent reply {1}", instance.Properties.TaskId, response.SerializeToJson());
 }
示例#3
0
 private void StopStaging(StagingInstance instance, string reply_to)
 {
     try
     {
         if (instance.Properties.Stopped)
         {
             return;
         }
         instance.Lock.EnterWriteLock();
         instance.Properties.Stopped = true;
         StagingStartMessageResponse response = new StagingStartMessageResponse();
         response.TaskId = instance.Properties.TaskId;
         this.deaReactor.SendReply(reply_to, response.SerializeToJson());
     }
     catch (Exception ex)
     {
         Logger.Error("Could not stop staging task {0}: {1}", instance.Properties.TaskId, ex.ToString());
     }
     finally
     {
         instance.Lock.ExitWriteLock();
     }
 }