public DeployResultViewModel(DeployResult result) { Id = result.Id; ShortId = result.Id.Substring(0, 10); Message = result.Message; Author = result.Author; EmailHash = String.IsNullOrEmpty(result.AuthorEmail) ? null : HelperMethods.Hash(result.AuthorEmail); ; Status = result.Status; DisplayStatus = result.Status.ToString(); StatusText = result.StatusText; DeployEndTime = result.EndTime; DeployStartTime = result.StartTime; Current = result.Current; }
public void HandleAutoSwap(bool verifyActiveDeploymentIdChanged) { if (!IsAutoSwapEnabled()) { return; } var tracer = _traceFactory.GetTracer(); string currentActiveDeploymentId = _deploymentStatusManager.ActiveDeploymentId; if (verifyActiveDeploymentIdChanged && currentActiveDeploymentId == _initialActiveDeplymentId) { tracer.Trace("Deployment haven't changed, no need for auto swap", currentActiveDeploymentId); return; } DeployResult latestDeploymentResult = _deploymentManager.GetResult(currentActiveDeploymentId); if (latestDeploymentResult.Status != DeployStatus.Success) { tracer.Trace("Auto swap is not requested as the deployment did not succeed", latestDeploymentResult.Id, latestDeploymentResult.Status); return; } try { FileSystemHelpers.WriteAllTextToFile(_autoSwapLockFilePath, String.Empty); } catch (Exception ex) { tracer.TraceError(ex); } string operationId = "AUTOSWAP" + Guid.NewGuid(); string deploymentId = latestDeploymentResult.Id; HttpResponse response = HttpContext.Current.Response; response.Headers.Add("X-MS-SWAP-OPERATIONID", operationId); response.Headers.Add("X-MS-SWAP-SLOTNAME", _autoSwapSlotName); response.Headers.Add("X-MS-SWAP-DEPLOYMENTID", deploymentId); tracer.Trace("Requesting auto swap to slot name - '{0}', operation id - '{1}', deployment id - '{2}'".FormatInvariant(_autoSwapSlotName, operationId, deploymentId)); }
private void ReportStatus(string id) { var result = GetResult(id); // There's no status as yet so report as pending if (result == null) { result = new DeployResult { Id = id, Status = DeployStatus.Pending }; } if (StatusChanged != null) { StatusChanged(result); } }
private IEnumerable <DeployResult> EnumerateResults() { if (!FileSystemHelpers.DirectoryExists(_environment.DeploymentsPath)) { yield break; } string activeDeploymentId = _status.ActiveDeploymentId; bool isDeploying = IsDeploying; foreach (var id in FileSystemHelpers.GetDirectories(_environment.DeploymentsPath)) { DeployResult result = GetResult(id, activeDeploymentId, isDeploying); if (result != null) { yield return(result); } } }
private IEnumerable <DeployResult> EnumerateResults() { if (!FileSystemHelpers.DirectoryExists(_environment.DeploymentsPath)) { yield break; } string activeDeploymentId = _status.ActiveDeploymentId; bool isDeploying = IsDeploying; foreach (var id in FileSystemHelpers.GetDirectoryNames(_environment.DeploymentsPath).Where(p => !p.Equals(@"tools", StringComparison.OrdinalIgnoreCase))) { DeployResult result = GetResult(id, activeDeploymentId, isDeploying); if (result != null) { yield return(result); } } }
private IEnumerable <DeployResult> EnumerateResults() { if (!_fileSystem.Directory.Exists(_environment.DeploymentCachePath)) { yield break; } string activeDeploymentId = ActiveDeploymentId; bool isDeploying = IsDeploying; foreach (var id in _fileSystem.Directory.GetDirectories(_environment.DeploymentCachePath)) { DeployResult result = GetResult(id, activeDeploymentId, isDeploying); if (result != null) { yield return(result); } } }
private void OnDeploymentStatusChanged(DeployResult result) { var clients = Hub.GetClients<Kudu.SignalR.Hubs.Deployment>(); clients[Name].updateDeployStatus(new DeployResultViewModel(result)); }
private bool IsLatestPendingDeployment(ref string id, out DeployResult pending) { if (String.Equals(Constants.LatestDeployment, id)) { using (_tracer.Step("DeploymentService.GetLatestDeployment")) { var results = _deploymentManager.GetResults(); pending = results.Where(r => r.Status != DeployStatus.Success && r.Status != DeployStatus.Failed).FirstOrDefault(); if (pending != null) { _tracer.Trace("Deployment {0} is {1}", pending.Id, pending.Status); return true; } var latest = results.Where(r => r.EndTime != null).OrderBy(r => r.EndTime.Value).LastOrDefault(); if (latest != null) { _tracer.Trace("Deployment {0} is {1} at {2}", latest.Id, latest.Status, latest.EndTime.Value.ToString("o")); id = latest.Id; } else { _tracer.Trace("Could not find latest deployment!"); } } } pending = null; return false; }
public bool TryParseDeployResult(string id, JObject payload, out DeployResult deployResult) { deployResult = null; if (String.IsNullOrEmpty(id) || payload == null) { return false; } var status = payload.Value<int?>("status"); if (status == null || (status.Value != 3 && status.Value != 4)) { return false; } var message = payload.Value<string>("message"); if (String.IsNullOrEmpty(message)) { return false; } var deployer = payload.Value<string>("deployer"); if (String.IsNullOrEmpty(deployer)) { return false; } var author = payload.Value<string>("author"); if (String.IsNullOrEmpty(author)) { return false; } deployResult = new DeployResult { Id = id, Status = (DeployStatus)status.Value, Message = message, Deployer = deployer, Author = author }; // optionals var now = DateTime.UtcNow; deployResult.AuthorEmail = payload.Value<string>("author_email"); deployResult.StartTime = payload.Value<DateTime?>("start_time") ?? now; deployResult.EndTime = payload.Value<DateTime?>("end_time") ?? now; // only success status can be active var active = payload.Value<bool?>("active"); if (active == null) { deployResult.Current = deployResult.Status == DeployStatus.Success; } else { if (active.Value && deployResult.Status != DeployStatus.Success) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Only successful status can be active!")); } deployResult.Current = active.Value; } return true; }
public void CreateDeployment(DeployResult deployResult, string details) { var id = deployResult.Id; string path = Path.Combine(_environment.DeploymentsPath, id); IDeploymentStatusFile statusFile = _status.Open(id); if (statusFile != null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, String.Format("Deployment with id '{0}' exists", id))); } FileSystemHelpers.EnsureDirectory(path); statusFile = _status.Create(id); statusFile.Status = deployResult.Status; statusFile.Message = deployResult.Message; statusFile.Deployer = deployResult.Deployer; statusFile.Author = deployResult.Author; statusFile.AuthorEmail = deployResult.AuthorEmail; statusFile.StartTime = deployResult.StartTime; statusFile.EndTime = deployResult.EndTime; // miscellaneous statusFile.Complete = true; statusFile.IsReadOnly = true; statusFile.IsTemporary = false; statusFile.ReceivedTime = deployResult.StartTime; // keep it simple regardless of success or failure statusFile.LastSuccessEndTime = deployResult.EndTime; statusFile.Save(); if (deployResult.Current) { _status.ActiveDeploymentId = id; } var logger = new StructuredTextLogger(Path.Combine(path, DeploymentManager.TextLogFile), _analytics); ILogger innerLogger; if (deployResult.Status == DeployStatus.Success) { innerLogger = logger.Log("Deployment successful."); } else { innerLogger = logger.Log("Deployment failed.", LogEntryType.Error); } if (!String.IsNullOrEmpty(details)) { innerLogger.Log(details); } }
private void OnDeploymentStatusChanged(DeployResult result) { // HACK: This is kinda hacky for now since Signalr doesn't have good support // for sending messages through hubs from arbitrary code. I promise it will get better var connection = Connection.GetConnection<HubDispatcher>(); ClientAgent.Invoke(connection, "updateDeployStatus", typeof(SourceControl).FullName, "updateDeployStatus", new[] { new DeployResultViewModel(result) }); }
public DeployResultViewModel(DeployResult result) { Id = result.Id; Status = result.Status.ToString(); }
private void NotifyStatus(string id) { var result = GetResult(id); if (result == null) { result = new DeployResult { Id = id, Status = DeployStatus.Pending }; } if (StatusChanged != null) { StatusChanged(result); } }