public void ReceiveStatus(string hostname, AgentStatusReport agentStatus) { if (agentStatus.updating != null) { _logger.Debug("agent {0} report: {1}", hostname, string.Join(", ", agentStatus.updating.ToArray())); } var agent = GetAgent(hostname) ?? RegisterAgent(hostname); _ravenSession.Advanced.Refresh(agent); // set agent status and update SetAgentStatus(agentStatus, agent); }
public static AgentStatusReport BuildStatus(IPackagesList availablePackages, ILocalPackageCache packageCache, IInstalledPackageArchive installCache, RunningInstallationTaskList runningTasks, IAgentSettingsManager settingsManager, ICurrentlyDownloadingList currentlyDownloadingList, CompletedInstallationTaskList completedInstallations) { // copying these collections to variables because sometimes they get modified while building the status report object string[] updating = new string[currentlyDownloadingList != null ? currentlyDownloadingList.Count : 0]; if (currentlyDownloadingList != null) currentlyDownloadingList.CopyTo(updating, 0); IPackage[] packages = new IPackage[availablePackages != null ? availablePackages.Count : 0]; if (availablePackages != null) availablePackages.CopyTo(packages, 0); var watchedPackageList = availablePackages.GetWatched().ToList(); IPackage[] watchedPackages = new IPackage[watchedPackageList != null ? watchedPackageList.Count : 0]; if (watchedPackageList != null) watchedPackageList.CopyTo(watchedPackages); InstallationTask[] tasks=new InstallationTask[runningTasks != null ? runningTasks.Count : 0]; if (runningTasks != null) runningTasks.CopyTo(tasks); var status = new AgentStatusReport { packages = BuildPackageInformation(watchedPackages, installCache, tasks, completedInstallations), currentTasks = tasks.Select(t => { var installation = new InstallTaskViewModel(); installation.Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(); if (t.Task != null) { installation.Status = Enum.GetName(typeof (TaskStatus), t.Task.Status); } installation.PackageId = t.PackageId; installation.Version = t.Version; installation.LastMessage = t.ProgressReports.Count > 0 ? t.ProgressReports. LastOrDefault(). Message : ""; return installation; }).ToList(), availableVersions = packages.Select(p => p.Version.ToString()).Distinct().OrderByDescending(s => s).ToList(), environment = settingsManager.Settings.DeploymentEnvironment, updating = updating.ToList(), isUpdating = currentlyDownloadingList.Downloading }; status.OutOfDate = status.packages.Any(p => p.OutOfDate); return status; }
private void SetAgentStatus(AgentStatusReport agentStatus, AgentRecord agent) { if (agentStatus.packages != null) { _ravenSession.Advanced.GetEtagFor(agent); agent.Packages = agentStatus.packages .Where(p => p.AvailableVersions != null) .Select(p => new PackageViewModel { availableVersions = p.AvailableVersions.ToArray(), currentTask = p.CurrentTask, installedVersion = p.InstalledVersion, packageId = p.PackageId, installed = p.Installed, installationResult = p.InstallationResult }).ToList(); } agent.CurrentTasks = agentStatus.currentTasks; agent.AvailableVersions = agentStatus.availableVersions; agent.Environment = agentStatus.environment; agent.Contacted = true; agent.LastContact = DateTime.Now; agent.Updating = agentStatus.updating ?? new List<string>(); if (agent.Updating.Count > 0) { agent.ShowUpdatingStatusUntil = DateTime.Now.AddSeconds(5); } _ravenSession.Store(agent); System.Diagnostics.Debug.WriteLine("Update agent"); try { _ravenSession.SaveChanges(); } catch (ConcurrencyException) { _logger.Debug("agent status update was rejected because etag was old"); } }
public void SetStatus(string hostname, AgentStatusReport agentStatus) { SetAgentStatus(agentStatus, GetAgent(hostname)); }
public ActionResult Status(string hostname, AgentStatusReport agentStatus) { try { _agentManager.ReceiveStatus(hostname, agentStatus); } catch (Exception ex) { _log.Info(ex, "agent status update failed"); } return new HttpStatusCodeResult((int)HttpStatusCode.Accepted); }