Beispiel #1
0
        public IReportStatus Execute(IReportStatus status, ConDepOptions options)
        {
            foreach (var server in _servers)
            {
                try
                {
                    Logger.LogSectionStart(server.Name);

                    if (!options.WebDeployExist)
                    {
                        using (new WebDeployDeployer(server))
                        {
                            ExecuteOnServer(server, status, options);
                        }
                    }
                    else
                    {
                        ExecuteOnServer(server, status, options);
                    }
                }
                finally
                {
                    Logger.LogSectionEnd(server.Name);
                }
            }
            return status;
        }
Beispiel #2
0
        public IReportStatus Execute(ServerConfig server, IReportStatus status, ConDepOptions options)
        {
            try
            {
                Logger.LogSectionStart("Infrastructure");
                foreach (var element in _sequence)
                {
                    if (element is IOperateRemote)
                    {
                        ((IOperateRemote)element).Execute(server, status, options);
                        if (status.HasErrors)
                            return status;
                    }
                    else if (element is CompositeSequence)
                    {
                        ((CompositeSequence)element).Execute(server, status, options);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    if (status.HasErrors)
                        return status;
                }
            }
            finally
            {
                Logger.LogSectionEnd("Infrastructure");
            }

            return status;
        }
Beispiel #3
0
        public IReportStatus Execute(ServerConfig server, IReportStatus status, ConDepOptions options)
        {
            try
            {
                Logger.LogSectionStart(_compositeName);
                foreach (var element in _sequence)
                {
                    if (element is CompositeSequence)
                    {
                        ((CompositeSequence)element).Execute(server, status, options);
                    }
                    else if (element is IOperateRemote)
                    {
                        ((IOperateRemote)element).Execute(server, status, options);
                    }

                    if (status.HasErrors)
                        return status;
                }
            }
            finally
            {
                Logger.LogSectionEnd(_compositeName);
            }
            return status;
        }
 public IReportStatus Execute(IReportStatus status, ConDepConfig config, ConDepOptions options)
 {
     foreach (var localSequence in _sequence)
     {
         localSequence.Execute(status, config, options);
         if (status.HasErrors)
             return status;
     }
     return status;
 }
Beispiel #5
0
        public IReportStatus Execute(ServerConfig server, IReportStatus status, ConDepOptions options)
        {
            bool sectionAdded = false;
            try
            {
                if (ConDepGlobals.ServersWithPreOps.ContainsKey(server.Name))
                    return status;

                ConDepGlobals.ServersWithPreOps.Add(server.Name, server);
                Logger.LogSectionStart("Pre-Operations");
                sectionAdded = true;

                var remotePreOps = new PreRemoteOps(server, this, options, _webDeploy);
                remotePreOps.Configure();
                remotePreOps.Execute(status);

                foreach (var element in _sequence)
                {
                    if (element is IOperateRemote)
                    {
                        ((IOperateRemote)element).Execute(server, status, options);
                        if (status.HasErrors)
                            return status;
                    }
                    else if (element is CompositeSequence)
                    {
                        ((CompositeSequence)element).Execute(server, status, options);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    if (status.HasErrors)
                        return status;
                }

                return status;
            }
            finally
            {
                if(sectionAdded)
                {
                    Logger.LogSectionEnd("Pre-Operations");
                }
            }
        }
        public IReportStatus Execute(ServerConfig server, IReportStatus status, ConDepOptions options)
        {
            try
            {
                Logger.LogSectionStart("Infrastructure");
                foreach (var element in _sequence)
                {
                    element.Execute(server, status, options);
                    if (status.HasErrors)
                        return status;
                }
            }
            finally
            {
                Logger.LogSectionEnd("Infrastructure");
            }

            return status;
        }
Beispiel #7
0
        public IReportStatus Execute(IReportStatus status, ConDepOptions options)
        {
            try
            {
                Logger.LogSectionStart("Remote Operations");

                switch (_loadBalancer.Mode)
                {
                    case LbMode.Sticky:
                        return ExecuteWithSticky(options, status);
                    case LbMode.RoundRobin:
                        return ExecuteWithRoundRobin(options, status);
                    default:
                        throw new ConDepLoadBalancerException(string.Format("Load Balancer mode [{0}] not supported.",
                                                                      _loadBalancer.Mode));
                }
            }
            finally
            {
                Logger.LogSectionEnd("Remote Operations");
            }
        }
Beispiel #8
0
 public ConDepSettings()
 {
     Config  = new ConDepEnvConfig();
     Options = new ConDepOptions();
 }
        //private static Assembly ResolveConDepAssemblies(object sender, ResolveEventArgs args)
        //{
        //    var assemblyName = args.Name.Split(',')[0];
        //    var assemblyLocation = Path.Combine(typeof(ConDepConfigurationExecutor).Assembly.CodeBase, assemblyName);
        //    if (File.Exists(assemblyLocation + ".dll"))
        //    {
        //        return Assembly.LoadFrom(assemblyLocation + ".dll");
        //    }
        //    return null;
        //}
        //private static Assembly ResolveAssemblyLocation(object sender, ResolveEventArgs args)
        //{
        //    var assemblyName = args.Name.Split(',')[0];
        //    var assemblyLocation = Path.Combine(_assemblySearchPath, assemblyName);
        //    if (File.Exists(assemblyLocation + ".dll"))
        //    {
        //        return Assembly.LoadFrom(assemblyLocation + ".dll");
        //    }
        //    return null;
        //}
        public ConDepExecutionResult Execute(Guid executionId, string assemblyPath, ConDepOptions options, ITokenSource token)
        {
            throw new NotImplementedException();
            //try
            //{
            //    // 1. Initialize Logger
            //    // 2. Load ConDep Assembly and assign to Options
            //    // 3. Load Env Config and add to Settings
            //    // 4.
            //    Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyPath));
            //    Logger.Initialize(new RelayApiLogger(executionId));
            //    Logger.TraceLevel = options.TraceLevel > 0 ? options.TraceLevel : TraceLevel.Info;

            //    Logger.Info("Trace level set to " + Logger.TraceLevel);

            //    var configAssemblyLoader = new ConDepAssemblyHandler(assemblyPath);
            //    options.Assembly = configAssemblyLoader.GetAssembly();

            //    var conDepSettings = new ConDepSettings
            //    {
            //        Options = options
            //    };
            //    conDepSettings.Config = ConfigHandler.GetEnvConfig(conDepSettings);

            //    if (conDepSettings.Options.Assembly == null) throw new ArgumentException("assembly");

            //    var lbLookup = new LoadBalancerLookup(conDepSettings.Config.LoadBalancer);
            //    var runbookConfigHandler = new RunbookConfigurationHandler(new RunbookHandler(), new RunbookDependencyHandler(), lbLookup.GetLoadBalancer());
            //    var sequenceManager = runbookConfigHandler.CreateExecutionSequence(conDepSettings);

            //    var clientValidator = new ClientValidator();

            //    var serverInfoHarvester = HarvesterFactory.GetHarvester(conDepSettings);
            //    var serverValidator = new RemoteServerValidator(conDepSettings.Config.Servers,
            //                                                    serverInfoHarvester, new PowerShellExecutor());

            //    if (conDepSettings.Options.DryRun)
            //    {
            //        Logger.Warn("Showing execution sequence from dry run:");
            //        sequenceManager.DryRun(conDepSettings);
            //        return new ConDepExecutionResult(true);
            //    }

            //    return Execute(conDepSettings, clientValidator, serverValidator, sequenceManager, token.Token);
            //}
            //catch (Exception ex)
            //{
            //    try
            //    {
            //        Logger.Error("An error sneaked by.", ex);
            //    }
            //    catch { }

            //    var result = new ConDepExecutionResult(false);
            //    result.AddException(ex);
            //    return result;
            //    //throw;
            //}
        }
Beispiel #10
0
 public ConDepSettings()
 {
     Config = new ConDepEnvConfig();
     Options = new ConDepOptions();
 }
Beispiel #11
0
        private IReportStatus ExecuteOnServer(ServerConfig server, IReportStatus status, ConDepOptions options, ILoadBalance loadBalancer, bool bringServerOfflineBeforeExecution, bool bringServerOnlineAfterExecution)
        {
            var errorDuringLoadBalancing = false;
            try
            {
                Logger.LogSectionStart(server.Name);

                if (bringServerOfflineBeforeExecution)
                {
                    Logger.Info(string.Format("Taking server [{0}] offline in load balancer.", server.Name));
                    loadBalancer.BringOffline(server.Name, server.LoadBalancerFarm,
                                                LoadBalancerSuspendMethod.Suspend, status);
                }

                ExecuteOnServer(server, status, options);
                return status;
            }
            catch
            {
                errorDuringLoadBalancing = true;
                throw;
            }
            finally
            {
                try
                {
                    if (bringServerOnlineAfterExecution && !status.HasErrors && !errorDuringLoadBalancing)
                    {
                        Logger.Info(string.Format("Taking server [{0}] online in load balancer.", server.Name));
                        loadBalancer.BringOnline(server.Name, server.LoadBalancerFarm, status);
                    }
                }
                finally
                {
                    Logger.LogSectionEnd(server.Name);
                }
            }
        }
Beispiel #12
0
        private IReportStatus ExecuteWithSticky(ConDepOptions options, IReportStatus status)
        {
            var servers = _servers.ToList();
            ServerConfig manuelTestServer;

            if (options.StopAfterMarkedServer)
            {
                manuelTestServer = servers.SingleOrDefault(x => x.StopServer) ?? servers.First();
                return ExecuteOnServer(manuelTestServer, status, options, _loadBalancer, true, false);
            }

            if (options.ContinueAfterMarkedServer)
            {
                manuelTestServer = servers.SingleOrDefault(x => x.StopServer) ?? servers.First();
                _loadBalancer.BringOnline(manuelTestServer.Name, manuelTestServer.LoadBalancerFarm, status);
                servers.Remove(manuelTestServer);
            }

            foreach (var server in servers)
            {
                ExecuteOnServer(server, status, options, _loadBalancer, true, true);

                if (status.HasErrors)
                    return status;

            }
            return status;
        }
Beispiel #13
0
        private IReportStatus ExecuteWithRoundRobin(ConDepOptions options, IReportStatus status)
        {
            var servers = _servers.ToList();
            var roundRobinMaxOfflineServers = (int)Math.Ceiling(((double)servers.Count) / 2);
            ServerConfig manuelTestServer = null;

            if (options.StopAfterMarkedServer)
            {
                manuelTestServer = servers.SingleOrDefault(x => x.StopServer) ?? servers.First();
                return ExecuteOnServer(manuelTestServer, status, options, _loadBalancer, true, false);
            }

            if (options.ContinueAfterMarkedServer)
            {
                manuelTestServer = servers.SingleOrDefault(x => x.StopServer) ?? servers.First();
                servers.Remove(manuelTestServer);

                if (roundRobinMaxOfflineServers == 1)
                {
                    _loadBalancer.BringOnline(manuelTestServer.Name, manuelTestServer.LoadBalancerFarm, status);
                }
            }

            if (servers.Count == 1)
            {
                return ExecuteOnServer(servers.First(), status, options, _loadBalancer, true, true);
            }

            for (int execCount = 0; execCount < servers.Count; execCount++)
            {
                if (execCount == roundRobinMaxOfflineServers - (manuelTestServer == null ? 0 : 1))
                {
                    TurnRoundRobinServersAround(_loadBalancer, servers, roundRobinMaxOfflineServers, manuelTestServer, status);
                }

                bool bringOnline = !(roundRobinMaxOfflineServers - (manuelTestServer == null ? 0 : 1) > execCount);
                ExecuteOnServer(servers[execCount], status, options, _loadBalancer, !bringOnline, bringOnline);

                if (status.HasErrors)
                    return status;
            }

            return status;
        }
Beispiel #14
0
        private IReportStatus ExecuteOnServer(ServerConfig server, IReportStatus status, ConDepOptions options)
        {
            _infrastructureSequence.Execute(server, status, options);

            if (status.HasErrors)
                return status;

            foreach (var element in _sequence)
            {
                if (element.GetType().IsAssignableFrom(typeof(IRequireRemotePowerShellScript)))
                {
                    var scriptPaths = ((IRequireRemotePowerShellScript)element).ScriptPaths;
                    RemotePowerShellScripts.Add(scriptPaths);
                    //DeployPowerShellScripts(scriptPaths);
                }

                if (element is IOperateRemote)
                {
                    ((IOperateRemote)element).Execute(server, status, options);
                    if (status.HasErrors)
                        return status;
                }
                else if (element is CompositeSequence)
                {
                    ((CompositeSequence)element).Execute(server, status, options);
                }
                else
                {
                    throw new NotSupportedException();
                }

                if (status.HasErrors)
                    return status;
            }
            return status;
        }