Ejemplo n.º 1
0
        private static void Validate(IValidateClient clientValidator, IValidateServer serverValidator)
        {
            clientValidator.Validate();

            if (!serverValidator.Validate())
            {
                throw new ConDepValidationException("Not all servers fulfill ConDep's requirements. Aborting execution.");
            }
        }
Ejemplo n.º 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);
            }
        }
        private static void Validate(IValidateClient clientValidator, IValidateServer serverValidator)
        {
            clientValidator.Validate();

            if (!serverValidator.Validate())
            {
                throw new ConDepValidationException("Not all servers fulfill ConDep's requirements. Aborting execution.");
            }
        }
Ejemplo n.º 5
0
        internal ConDepExecutionResult Execute(ConDepSettings settings, IValidateClient clientValidator, IValidateServer serverValidator, ExecutionSequenceManager execManager, 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 (execManager == null)
            {
                throw new ArgumentException("execManager");
            }

            ServicePointManager.ServerCertificateValidationCallback = ValidateConDepNodeServerCert;

            var status = new StatusReporter();

            try
            {
                Validate(clientValidator, serverValidator);

                ExecutePreOps(settings, status, token);
                _serverNodeInstalled = true;

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

                var notification = new Notification();
                if (!execManager.IsValid(notification))
                {
                    notification.Throw();
                }

                execManager.Execute(status, settings, token);
                return(new ConDepExecutionResult(true));
            }
            catch (OperationCanceledException)
            {
                Cancel(settings, status, token);
                return(new ConDepExecutionResult(false)
                {
                    Cancelled = true
                });
            }
            catch (AggregateException aggEx)
            {
                var result = new ConDepExecutionResult(false);
                aggEx.Handle(inner =>
                {
                    if (inner is OperationCanceledException)
                    {
                        Cancel(settings, status, 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, status, token);
                }
            }
        }