示例#1
0
        public void RunSync(CancellationToken cancellationToken)
        {
            _hostContext.Observer.TryNotify(() => new HostStartedEvent(_hostContext.Identity));

            try
            {
                _currentDeployment     = null;
                _currentSolution       = null;
                _currentDeploymentEtag = null;

                _autoLoadHeadDeploymentTimer.Change(0, _autoLoadHeadDeploymentIntervalMs);
                _watchdogTimer.Change(_watchdogIntervalMs, _watchdogIntervalMs);

                foreach (var command in _commandQueue.GetConsumingEnumerable(cancellationToken))
                {
                    Do((dynamic)command, cancellationToken);
                }
            }
            finally
            {
                _autoLoadHeadDeploymentTimer.Change(Timeout.Infinite, _autoLoadHeadDeploymentIntervalMs);
                _watchdogTimer.Change(Timeout.Infinite, _watchdogIntervalMs);
                _hostContext.Observer.TryNotify(() => new HostStoppedEvent(_hostContext.Identity));
            }
        }
示例#2
0
        void OnDeploymentChanged(SolutionHead newDeployment, SolutionDefinition newSolution, CancellationToken cancellationToken)
        {
            // 0. ANALYZE CELL LAYOUT CHANGES

            var removed = new Dictionary<string, Cell>(_cells);
            var added = new List<CellDefinition>();
            var remaining = new List<CellDefinition>();

            Dictionary<string, CellDefinition> old;
            if (_currentSolution == null || _currentSolution.SolutionName != newSolution.SolutionName)
            {
                // we do not reuse cells in completely unrelated solutions (i.e. solution name changed)
                _hostContext.Observer.TryNotify(() => new NewUnrelatedSolutionDetectedEvent(_hostContext.Identity, newDeployment, newSolution));
                old = new Dictionary<string, CellDefinition>();
                added.AddRange(newSolution.Cells);
            }
            else
            {
                // keep remaining cells (only touch cells that actually change in some way)
                _hostContext.Observer.TryNotify(() => new NewDeploymentOfSolutionDetectedEvent(_hostContext.Identity, newDeployment, newSolution));
                old = _currentSolution.Cells.ToDictionary(cellDefinition => cellDefinition.CellName);
                foreach (var newCellDefinition in newSolution.Cells)
                {
                    if (old.ContainsKey(newCellDefinition.CellName))
                    {
                        removed.Remove(newCellDefinition.CellName);
                        remaining.Add(newCellDefinition);
                    }
                    else
                    {
                        added.Add(newCellDefinition);
                    }
                }
            }

            // 1. UPDATE

            _currentSolution = newSolution;
            _currentDeployment = newDeployment;

            // 2. REMOVE CELLS NO LONGER PRESENT

            foreach (var cell in removed)
            {
                _cells.Remove(cell.Key);
                cell.Value.Cancel();
            }

            // 3. UPDATE CELLS STILL PRESENT

            foreach (var newCellDefinition in remaining)
            {
                var oldCellDefinition = old[newCellDefinition.CellName];
                if (!newCellDefinition.Equals(oldCellDefinition))
                {
                    _cells[newCellDefinition.CellName].OnCellDefinitionChanged(newCellDefinition, newDeployment);
                }
            }

            // 4. ADD NEW CELLS

            foreach (var cellDefinition in added)
            {
                var cellName = cellDefinition.CellName;
                _cells.Add(cellName, Cell.Run(_hostContext, _commandQueue.Add, cellDefinition, newDeployment, newSolution.SolutionName, cancellationToken));
            }
        }
示例#3
0
        public void RunSync(CancellationToken cancellationToken)
        {
            _hostContext.Observer.TryNotify(() => new HostStartedEvent(_hostContext.Identity));

            try
            {
                _currentDeployment = null;
                _currentSolution = null;
                _currentDeploymentEtag = null;

                _autoLoadHeadDeploymentTimer.Change(0, _autoLoadHeadDeploymentIntervalMs);
                _watchdogTimer.Change(_watchdogIntervalMs, _watchdogIntervalMs);

                foreach (var command in _commandQueue.GetConsumingEnumerable(cancellationToken))
                {
                    Do((dynamic)command, cancellationToken);
                }
            }
            finally
            {
                _autoLoadHeadDeploymentTimer.Change(Timeout.Infinite, _autoLoadHeadDeploymentIntervalMs);
                _watchdogTimer.Change(Timeout.Infinite, _watchdogIntervalMs);
                _hostContext.Observer.TryNotify(() => new HostStoppedEvent(_hostContext.Identity));
            }
        }
 public NewUnrelatedSolutionDetectedEvent(HostLifeIdentity host, SolutionHead deployment, SolutionDefinition solution)
 {
     Host       = host;
     Deployment = deployment;
     Solution   = solution;
 }
示例#5
0
        void OnDeploymentChanged(SolutionHead newDeployment, SolutionDefinition newSolution, CancellationToken cancellationToken)
        {
            // 0. ANALYZE CELL LAYOUT CHANGES

            var removed   = new Dictionary <string, Cell>(_cells);
            var added     = new List <CellDefinition>();
            var remaining = new List <CellDefinition>();

            Dictionary <string, CellDefinition> old;

            if (_currentSolution == null || _currentSolution.SolutionName != newSolution.SolutionName)
            {
                // we do not reuse cells in completely unrelated solutions (i.e. solution name changed)
                _hostContext.Observer.TryNotify(() => new NewUnrelatedSolutionDetectedEvent(_hostContext.Identity, newDeployment, newSolution));
                old = new Dictionary <string, CellDefinition>();
                added.AddRange(newSolution.Cells);
            }
            else
            {
                // keep remaining cells (only touch cells that actually change in some way)
                _hostContext.Observer.TryNotify(() => new NewDeploymentOfSolutionDetectedEvent(_hostContext.Identity, newDeployment, newSolution));
                old = _currentSolution.Cells.ToDictionary(cellDefinition => cellDefinition.CellName);
                foreach (var newCellDefinition in newSolution.Cells)
                {
                    if (old.ContainsKey(newCellDefinition.CellName))
                    {
                        removed.Remove(newCellDefinition.CellName);
                        remaining.Add(newCellDefinition);
                    }
                    else
                    {
                        added.Add(newCellDefinition);
                    }
                }
            }

            // 1. UPDATE

            _currentSolution   = newSolution;
            _currentDeployment = newDeployment;

            // 2. REMOVE CELLS NO LONGER PRESENT

            foreach (var cell in removed)
            {
                _cells.Remove(cell.Key);
                cell.Value.Cancel();
            }

            // 3. UPDATE CELLS STILL PRESENT

            foreach (var newCellDefinition in remaining)
            {
                var oldCellDefinition = old[newCellDefinition.CellName];
                if (!newCellDefinition.Equals(oldCellDefinition))
                {
                    _cells[newCellDefinition.CellName].OnCellDefinitionChanged(newCellDefinition, newDeployment);
                }
            }

            // 4. ADD NEW CELLS

            foreach (var cellDefinition in added)
            {
                var cellName = cellDefinition.CellName;
                _cells.Add(cellName, Cell.Run(_hostContext, _commandQueue.Add, cellDefinition, newDeployment, newSolution.SolutionName, cancellationToken));
            }
        }
 public NewDeploymentOfSolutionDetectedEvent(HostLifeIdentity host, SolutionHead deployment, SolutionDefinition solution)
 {
     Host = host;
     Deployment = deployment;
     Solution = solution;
 }