Пример #1
0
        public ExecutionSequenceManager CreateExecutionSequence(ConDepSettings settings)
        {
            var artifact = _artifactHandler.GetArtifact(settings);

            _artifactDependencyHandler.PopulateWithDependencies(artifact, settings);

            var servers = _serverHandler.GetServers(artifact, settings);

            settings.Config.Servers = servers.ToList();

            var sequenceManager = new ExecutionSequenceManager(servers, _loadBalancer);

            if (artifact.Dependencies != null)
            {
                foreach (var dependency in artifact.Dependencies)
                {
                    ConfigureAtrifact(dependency, sequenceManager, settings);
                }
            }

            ConfigureAtrifact(artifact, sequenceManager, settings);
            return(sequenceManager);
        }
Пример #2
0
        internal ConDepExecutionResult Execute(ConDepSettings settings, IValidateClient clientValidator,
                                               IValidateServer serverValidator, IEnumerable <Runbook> runbooks, IDiscoverServers serverHandler,
                                               CancellationToken token)
        {
            if (settings == null)
            {
                throw new ArgumentException("settings");
            }
            if (settings.Config == null)
            {
                throw new ArgumentException("settings.Config");
            }
            if (settings.Options == null)
            {
                throw new ArgumentException("settings.Options");
            }
            if (clientValidator == null)
            {
                throw new ArgumentException("clientValidator");
            }
            if (serverValidator == null)
            {
                throw new ArgumentException("serverValidator");
            }
            if (runbooks == null)
            {
                throw new ArgumentException("runbook");
            }

            ServicePointManager.ServerCertificateValidationCallback = ValidateConDepNodeServerCert;

            try
            {
                Validate(clientValidator, serverValidator);

                ExecutePreOps(settings, token);
                _serverNodeInstalled = true;

                //Todo: Result of merge. Not sure if this is correct.
                token.Register(() => Cancel(settings, token));

                var lbLocator = new LoadBalancerLookup(settings.Config.LoadBalancer);
                foreach (var runbook in runbooks)
                {
                    var servers = serverHandler.GetServers(runbook, settings);
                    settings.Config.Servers = servers.ToList();
                    runbook.Execute(new OperationsBuilder(1, settings, lbLocator, token), settings);
                }

                return(new ConDepExecutionResult(true));
            }
            catch (OperationCanceledException)
            {
                Cancel(settings, token);
                return(new ConDepExecutionResult(false)
                {
                    Cancelled = true
                });
            }
            catch (AggregateException aggEx)
            {
                var result = new ConDepExecutionResult(false);
                aggEx.Handle(inner =>
                {
                    if (inner is OperationCanceledException)
                    {
                        Cancel(settings, token);
                        result.Cancelled = true;
                        Logger.Warn("ConDep execution cancelled.");
                    }
                    else
                    {
                        result.AddException(inner);
                        Logger.Error("ConDep execution failed.", inner);
                    }

                    return(true);
                });
                return(result);
            }
            catch (Exception ex)
            {
                var result = new ConDepExecutionResult(false);
                result.AddException(ex);
                Logger.Error("ConDep execution failed.", ex);
                return(result);
            }
            finally
            {
                if (!_cancelled)
                {
                    ExecutePostOps(settings, token);
                }
            }
        }
        internal ConDepExecutionResult Execute(ConDepSettings settings, IValidateClient clientValidator, IValidateServer serverValidator, IEnumerable<Runbook> runbooks, IDiscoverServers serverHandler, CancellationToken token)
        {
            if (settings == null) { throw new ArgumentException("settings"); }
            if (settings.Config == null) { throw new ArgumentException("settings.Config"); }
            if (settings.Options == null) { throw new ArgumentException("settings.Options"); }
            if (clientValidator == null) { throw new ArgumentException("clientValidator"); }
            if (serverValidator == null) { throw new ArgumentException("serverValidator"); }
            if (runbooks == null) { throw new ArgumentException("runbook"); }

            ServicePointManager.ServerCertificateValidationCallback = ValidateConDepNodeServerCert;

            try
            {
                Validate(clientValidator, serverValidator);

                ExecutePreOps(settings, token);
                _serverNodeInstalled = true;

                //Todo: Result of merge. Not sure if this is correct.
                token.Register(() => Cancel(settings, token));

                var lbLocator = new LoadBalancerLookup(settings.Config.LoadBalancer);
                foreach (var runbook in runbooks)
                {
                    var servers = serverHandler.GetServers(runbook, settings);
                    settings.Config.Servers = servers.ToList();
                    runbook.Execute(new OperationsBuilder(1, settings, lbLocator, token), settings);
                }

                return new ConDepExecutionResult(true);
            }
            catch (OperationCanceledException)
            {
                Cancel(settings, token);
                return new ConDepExecutionResult(false) { Cancelled = true };
            }
            catch (AggregateException aggEx)
            {
                var result = new ConDepExecutionResult(false);
                aggEx.Handle(inner =>
                {
                    if (inner is OperationCanceledException)
                    {
                        Cancel(settings, token);
                        result.Cancelled = true;
                        Logger.Warn("ConDep execution cancelled.");
                    }
                    else
                    {
                        result.AddException(inner);
                        Logger.Error("ConDep execution failed.", inner);
                    }

                    return true;
                });
                return result;
            }
            catch (Exception ex)
            {
                var result = new ConDepExecutionResult(false);
                result.AddException(ex);
                Logger.Error("ConDep execution failed.", ex);
                return result;
            }
            finally
            {
                if (!_cancelled) ExecutePostOps(settings, token);
            }
        }