Esempio n. 1
0
 public void Remove(AgentRecord agent)
 {
     if (_agentList.Any(a => a.Hostname == agent.Hostname))
     {
         _agentList.RemoveAll(a => a.Hostname == agent.Hostname);
     }
 }
Esempio n. 2
0
 public void SaveOrUpdate(AgentRecord agent)
 {
     using (var session = _documentStore.OpenSession())
     {
         session.Store(agent);
         session.SaveChanges();
     }
 }
Esempio n. 3
0
 public void Remove(AgentRecord agent)
 {
     using (var session = _documentStore.OpenSession())
     {
         session.Delete(agent);
         session.SaveChanges();
     }
 }
 public void SaveOrUpdate(AgentRecord agent)
 {
     using (var session = _documentStore.OpenSession())
     {
         session.Advanced.UseOptimisticConcurrency = true;
         session.Store(agent);
         session.SaveChanges();
     }
 }
Esempio n. 5
0
        public AgentRecord RegisterAgent(string hostname)
        {
            if (_ravenSession.Load<AgentRecord>(hostname) != null)
                throw new InvalidOperationException("Agent already registered");

            var agent = new AgentRecord(hostname);
            _ravenSession.Store(agent);

            return agent;
        }
 public void Remove(AgentRecord agent)
 {
     using (var session = _documentStore.OpenSession())
     using (var transaction = new TransactionScope())
     {
         session.Delete(agent);
         session.SaveChanges();
         transaction.Complete();
     }
 }
Esempio n. 7
0
        public void RegisterAgentAndGetStatus(string hostname)
        {
            if (_agentRepository.List().Any(a=>a.Hostname == hostname))
            {
                throw new InvalidOperationException("Agent already registered");
            }

            AgentRecord agent = new AgentRecord() { Hostname = hostname };
            new TaskFactory().StartNew(() => UpdateAgentStatus(agent));
            _agentRepository.SaveOrUpdate(agent);
        }
Esempio n. 8
0
 public void SaveOrUpdate(AgentRecord agent)
 {
     var existing = _agentList.SingleOrDefault(a => a.Hostname == agent.Hostname);
     if (existing != null)
     {
         _agentList[_agentList.IndexOf(existing)] = agent;
         existing = null;
     }
     else
     {
         _agentList.Add(agent);
     }
 }
Esempio n. 9
0
        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");
            }
        }
Esempio n. 10
0
 private void UpdateAgentStatus(AgentRecord agent)
 {
     AgentStatusReport agentStatus = null;
     try
     {
         agentStatus = _agentRemoteService.GetAgentStatus(agent.Hostname);
         agent.Packages = agentStatus.packages;
         agent.CurrentTasks = agentStatus.currentTasks;
         agent.AvailableVersions = agentStatus.availableVersions;
         agent.Environment = agentStatus.environment;
         agent.Contacted = true;
         _agentRepository.SaveOrUpdate(agent);
     }
     catch (Exception ex)
     {
         _logger.Warn("Failed to get agent status", ex);
         agent.Contacted = false;
     }
 }