예제 #1
0
        public void TestThatExecutionSequenceIsValid()
        {
            var config = new ConDepConfig {
                EnvironmentName = "bogusEnv"
            };
            var server = new ServerConfig {
                Name = "jat-web03"
            };

            config.Servers = new[] { server };

            var infrastructureSequence = new InfrastructureSequence();
            var preOpsSequence         = new PreOpsSequence(new WebDeployHandlerMock());

            var webDeploy             = new WebDeployHandlerMock();
            var infrastructureBuilder = new InfrastructureBuilder(infrastructureSequence, webDeploy);

            _infra.Configure(infrastructureBuilder, config);

            var local = new LocalOperationsBuilder(_sequenceManager.NewLocalSequence("Test"), infrastructureSequence, preOpsSequence, config.Servers, webDeploy);

            _app.Configure(local, config);

            var notification = new Notification();

            Assert.That(_sequenceManager.IsValid(notification));
        }
예제 #2
0
        public void TestThatExecutionSequenceIsValid()
        {
            var config = new ConDepEnvConfig {
                EnvironmentName = "bogusEnv"
            };
            var server = new ServerConfig {
                Name = "jat-web03"
            };

            config.Servers = new[] { server };

            var sequenceManager = new ExecutionSequenceManager(config.Servers, new DefaultLoadBalancer());

            var settings = new ConDepSettings();

            settings.Config = config;

            var local = new LocalOperationsBuilder(sequenceManager.NewLocalSequence("Test"));

            //Configure.LocalOperations = local;
            _app.Configure(local, settings);

            var notification = new Notification();

            Assert.That(sequenceManager.IsValid(notification));
        }
예제 #3
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);
                }
            }
        }
예제 #4
0
        private void Execute(Assembly assembly, ConDepConfig envConfig, ConDepOptions options, IReportStatus status)
        {
            if (assembly == null)
            {
                throw new ArgumentException("assembly");
            }
            if (envConfig == null)
            {
                throw new ArgumentException("envSettings");
            }
            if (options == null)
            {
                throw new ArgumentException("options");
            }
            if (status == null)
            {
                throw new ArgumentException("status");
            }

            var applications = CreateApplicationArtifacts(options, assembly);

            if (!options.WebDeployExist)
            {
                var serverValidator = new RemoteServerValidator(envConfig.Servers);
                if (!serverValidator.IsValid())
                {
                    Logger.Error("Not all servers fulfill ConDep's requirements. Aborting execution.");
                    return;
                }
            }

            var webDeploy = new WebDeployHandler();
            var lbLookup  = new LoadBalancerLookup(envConfig.LoadBalancer);

            var sequenceManager = new ExecutionSequenceManager(lbLookup.GetLoadBalancer());

            var notification = new Notification();
            var postOpSeq    = new PostOpsSequence();

            foreach (var application in applications)
            {
                var infrastructureSequence = new InfrastructureSequence();
                var preOpsSequence         = new PreOpsSequence(webDeploy);
                if (!options.DeployOnly)
                {
                    var infrastructureBuilder = new InfrastructureBuilder(infrastructureSequence, webDeploy);
                    Configure.InfrastructureOperations = infrastructureBuilder;

                    if (HasInfrastructureDefined(application))
                    {
                        var infrastructureInstance = GetInfrastructureArtifactForApplication(assembly, application);
                        if (!infrastructureSequence.IsValid(notification))
                        {
                            notification.Throw();
                        }
                        infrastructureInstance.Configure(infrastructureBuilder, envConfig);
                    }
                }

                var local = new LocalOperationsBuilder(sequenceManager.NewLocalSequence(application.GetType().Name), infrastructureSequence, preOpsSequence, envConfig.Servers, webDeploy);
                Configure.LocalOperations = local;

                application.Configure(local, envConfig);
            }

            if (!sequenceManager.IsValid(notification))
            {
                notification.Throw();
            }

            sequenceManager.Execute(status, envConfig, options);
            postOpSeq.Execute(status, options);
        }