示例#1
0
 public RemoteOperationsBuilder(ServerConfig server, ConDepSettings settings, CancellationToken token) : base(server, settings, token)
 {
     Deploy    = new RemoteDeploymentBuilder(server, settings, token);
     Execute   = new RemoteExecutionBuilder(server, settings, token);
     Configure = new RemoteConfigurationBuilder(server, settings, token);
     Install   = new RemoteInstallationBuilder(server, settings, token);
 }
        public static ConDepExecutionResult ExecuteFromAssembly(ConDepSettings conDepSettings, CancellationToken token)
        {
            try
            {
                if (conDepSettings.Options.Assembly == null)
                {
                    throw new ArgumentException("assembly");
                }

                var lbLookup = new LoadBalancerLookup(conDepSettings.Config.LoadBalancer);
                var runbookConfigurationHandler = new RunbookConfigurationHandler(new RunbookHandler(), new RunbookDependencyHandler(), lbLookup.GetLoadBalancer());
                //var sequenceManager = artifactConfigHandler.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(new ConDepConfigurationExecutor().Execute(conDepSettings, clientValidator, serverValidator, runbookConfigurationHandler.GetRunbooksToExecute(conDepSettings), new ServerHandler(), token));
            }
            catch (Exception ex)
            {
                Logger.Error("An error sneaked by.", ex);
                throw;
            }
        }
示例#3
0
        public void Execute(ServerConfig server, IReportStatus status, ConDepSettings settings, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            Logger.WithLogSection("Pre-Operations", () =>
            {
                server.GetServerInfo().TempFolderDos = string.Format(TMP_FOLDER, "%windir%");
                Logger.Info(string.Format("Dos temp folder is {0}", server.GetServerInfo().TempFolderDos));

                server.GetServerInfo().TempFolderPowerShell = string.Format(TMP_FOLDER, "$env:windir");
                Logger.Info(string.Format("PowerShell temp folder is {0}", server.GetServerInfo().TempFolderPowerShell));

                //var scriptPublisher = new PowerShellScriptPublisher(settings);
                //Logger.WithLogSection("Copying internal ConDep scripts", () => scriptPublisher.PublishDslScripts(server));

                PublishConDepNode(server, settings);

                var scriptPublisher = new PowerShellScriptPublisher(settings);
                Logger.WithLogSection("Copying external scripts", () => scriptPublisher.PublishScripts(server));
                Logger.WithLogSection("Copying remote helper assembly", () => scriptPublisher.PublishRemoteHelperAssembly(server));

                InstallChocolatey(server, settings);
                //Logger.WithLogSection("Copying external scripts", () => scriptPublisher.PublishExternalScripts(server));
            });
        }
示例#4
0
        public override Result Execute(ConDepSettings settings, CancellationToken token)
        {
            var dynamicAwsConfig = settings.Config.OperationsConfig.Aws;

            var client = new Amazon.S3.AmazonS3Client(GetAwsCredentials(dynamicAwsConfig), RegionEndpoint.GetBySystemName((string)dynamicAwsConfig.Region));

            var response = client.GetObject(_bucket, _key);

            response.WriteResponseStreamToFile(_dstFile);

            var result = Result.SuccessUnChanged();

            result.Data.BucketName     = response.BucketName;
            result.Data.ContentLength  = response.ContentLength;
            result.Data.Expiration     = response.Expiration;
            result.Data.Expires        = response.Expires;
            result.Data.HttpStatusCode = response.HttpStatusCode;
            result.Data.Key            = response.Key;
            result.Data.LastModified   = response.LastModified;
            result.Data.ServerSideEncryptionCustomerMethod = response.ServerSideEncryptionCustomerMethod;
            result.Data.ServerSideEncryptionMethod         = response.ServerSideEncryptionMethod;
            result.Data.StorageClass            = response.StorageClass;
            result.Data.VersionId               = response.VersionId;
            result.Data.WebsiteRedirectLocation = response.WebsiteRedirectLocation;
            return(result);
        }
示例#5
0
        private IAmazonEC2 GetAwsClient(ConDepSettings settings, AwsEc2DiscoverOptionsValues awsOptions)
        {
            var creds  = GetAwsCredentials(settings, awsOptions);
            var region = GetAwsRegion(settings, awsOptions);

            return(new AmazonEC2Client(creds, region));
        }
示例#6
0
 public OperationsBuilder(int serial, ConDepSettings settings, ILookupLoadBalancer loadBalancerLocator, CancellationToken token)
 {
     _serial              = serial;
     _settings            = settings;
     _loadBalancerLocator = loadBalancerLocator;
     _token = token;
 }
示例#7
0
        public override Result Execute(ConDepSettings settings, CancellationToken token)
        {
            var result = Result.SuccessChanged();

            Thread.Sleep(1000);
            var webRequest = System.Net.WebRequest.Create(_url);

            webRequest.Method        = "GET";
            webRequest.ContentLength = 0;
            webRequest.ContentType   = "application/x-www-form-urlencoded";

            ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

            HttpStatusCode statusCode = ((HttpWebResponse)webRequest.GetResponse()).StatusCode;

            result.Data.StatusCode = statusCode.ToString();
            result.Data.Url        = _url;

            if (statusCode == HttpStatusCode.OK)
            {
                Logger.Info("HTTP {0} Succeeded: {1}", "GET", _url);
            }
            else
            {
                Logger.Error("GET request did not return with 200 (OK), but {0} ({1})", (int)statusCode, statusCode);
                result.Success = false;
            }
            return(result);
        }
 public AwsOperationsBuilder(IOfferLocalOperations localOps, ConDepSettings settings, CancellationToken token) : base(settings, token)
 {
     LocalOperations = localOps;
     Ec2             = new AwsEc2OperationsBuilder(this, settings, token);
     Elb             = new AwsElbOperationsBuilder(this, settings, token);
     S3 = new AwsS3OperationsBuilder(this, settings, token);
 }
示例#9
0
        private AWSCredentials GetAwsCredentials(ConDepSettings settings, AwsEc2DiscoverOptionsValues awsOptions)
        {
            if (awsOptions.Credentials != null)
            {
                return(awsOptions.Credentials);
            }

            var dynamicAwsConfig = settings.Config.OperationsConfig.Aws;

            if (dynamicAwsConfig != null)
            {
                string profileName = dynamicAwsConfig.Credentials.ProfileName;
                if (string.IsNullOrEmpty(profileName))
                {
                    if (dynamicAwsConfig.Credentials.AccessKey == null)
                    {
                        throw new OperationConfigException(string.Format("Configuration in environment configuration file for Credentials.AccessKey must be present for operation {0}. Optionally you can use AWS credential profile instead, but then ProfileName must be present.", GetType().Name));
                    }
                    if (dynamicAwsConfig.Credentials.SecretKey == null)
                    {
                        throw new OperationConfigException(string.Format("Configuration in environment configuration file for Credentials.SecretKey must be present for operation {0}. Optionally you can use AWS credential profile instead, but then ProfileName must be present.", GetType().Name));
                    }

                    return(new BasicAWSCredentials((string)dynamicAwsConfig.Credentials.AccessKey, (string)dynamicAwsConfig.Credentials.SecretKey));
                }

                return(new StoredProfileAWSCredentials((string)dynamicAwsConfig.Credentials.ProfileName));
            }

            throw new OperationConfigException(string.Format("AWS Credentials must be provided either through DSL or in configuration for operation {0}.", GetType().Name));
        }
示例#10
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));
        }
示例#11
0
        public override void Execute(IReportStatus status, ConDepSettings settings, CancellationToken token)
        {
            var configFilePath    = Path.Combine(_configDirPath, _configName);
            var transformFilePath = Path.Combine(_configDirPath, _transformName);
            var backupPath        = "";

            if (ConDepConfigBackupExist(_configDirPath, _configName))
            {
                Logger.Info("Using [{0}] as configuration file to transform", _configDirPath + CONDEP_CONFIG_EXTENSION);
                backupPath = Path.Combine(_configDirPath, _configName + CONDEP_CONFIG_EXTENSION);
            }
            else
            {
                BackupConfigFile(_configDirPath, _configName);
            }

            Logger.Info("Transforming [{0}] using [{1}]", configFilePath, transformFilePath);
            var trans = new SlowCheetah.Tasks.TransformXml
            {
                BuildEngine = new TransformConfigBuildEngine(),
                Source      = string.IsNullOrWhiteSpace(backupPath) ? configFilePath : backupPath,
                Transform   = transformFilePath,
                Destination = configFilePath
            };

            var success = trans.Execute();

            if (!success)
            {
                throw new CondepWebConfigTransformException(string.Format("Failed to transform [{0}] file.", _configName));
            }
        }
示例#12
0
        public void DryRun(ConDepSettings settings)
        {
            Logger.WithLogSection("Local Operations", () =>
            {
                foreach (var item in _localSequences)
                {
                    Logger.WithLogSection(item.Name, () => { item.DryRun(); });
                }
            });

            var loadBalancer = GetDryRunLoadBalancer();

            Logger.WithLogSection("Remote Operations", () =>
            {
                foreach (var server in _servers)
                {
                    Logger.WithLogSection(server.Name, () =>
                    {
                        loadBalancer.BringOffline(server, new StatusReporter(), settings, new CancellationToken());
                        foreach (var item in _remoteSequences)
                        {
                            Logger.WithLogSection(item.Name, () => { item.DryRun(); });
                        }
                        loadBalancer.BringOnline(server, new StatusReporter(), settings, new CancellationToken());
                    });
                }
            });
        }
        public void LoadOptionsFromConfig(ConDepSettings settings)
        {
            if (settings.Config.OperationsConfig == null || (settings.Config.OperationsConfig.AwsBootstrapOperation == null && settings.Config.OperationsConfig.AwsBootstrapOperation == null))
            {
                return;
            }

            var dynamicAwsConfig = settings.Config.OperationsConfig.Aws;

            try
            {
                if (dynamicAwsConfig != null)
                {
                    if (string.IsNullOrWhiteSpace(_options.PrivateKeyFileLocation) && !string.IsNullOrWhiteSpace((string)dynamicAwsConfig.PrivateKeyFileLocation))
                    {
                        _options.PrivateKeyFileLocation = dynamicAwsConfig.PrivateKeyFileLocation;
                    }
                    if (_options.RegionEndpoint == null && !string.IsNullOrWhiteSpace((string)dynamicAwsConfig.Region))
                    {
                        _options.RegionEndpoint = RegionEndpoint.GetBySystemName((string)dynamicAwsConfig.Region);
                    }

                    if (_options.Credentials == null)
                    {
                        string profileName = dynamicAwsConfig.Credentials.ProfileName;
                        if (string.IsNullOrEmpty(profileName))
                        {
                            if (dynamicAwsConfig.Credentials.AccessKey == null)
                            {
                                throw new OperationConfigException(
                                          string.Format(
                                              "Configuration in environment configuration file for Credentials.AccessKey must be present for operation {0}. Optionally you can use AWS credential profile instead, but then ProfileName must be present.",
                                              GetType().Name));
                            }
                            if (dynamicAwsConfig.Credentials.SecretKey == null)
                            {
                                throw new OperationConfigException(
                                          string.Format(
                                              "Configuration in environment configuration file for Credentials.SecretKey must be present for operation {0}. Optionally you can use AWS credential profile instead, but then ProfileName must be present.",
                                              GetType().Name));
                            }

                            _options.Credentials = new BasicAWSCredentials((string)dynamicAwsConfig.Credentials.AccessKey, (string)dynamicAwsConfig.Credentials.SecretKey);
                        }
                        else
                        {
                            _options.Credentials = new StoredProfileAWSCredentials((string)dynamicAwsConfig.Credentials.ProfileName);
                        }
                    }
                }
            }
            catch (RuntimeBinderException binderException)
            {
                throw new OperationConfigException(
                          string.Format("Configuration extraction for {0} failed during binding. Please check inner exception for details.",
                                        GetType().Name), binderException);
            }
        }
示例#14
0
 public void Execute(IReportStatus status, ConDepSettings settings, CancellationToken token)
 {
     foreach (var element in _sequence)
     {
         token.ThrowIfCancellationRequested();
         IExecuteLocally internalElement = element;
         Logger.WithLogSection(internalElement.Name, () => element.Execute(status, settings, token));
     }
 }
        public override void BringOnline(ServerConfig server, ConDepSettings settings, CancellationToken token)
        {
            if (server.LoadBalancerState.CurrentState == LoadBalanceState.Online)
            {
                return;
            }

            BringOnline(server, settings, _loadBalancer, token);
        }
        public override Result Execute(ConDepSettings settings, CancellationToken token)
        {
            LoadOptionsFromConfig(settings);
            ValidateMandatoryOptions(options);
            var imageDeregisterer = new Ec2ImageDeregisterer(options, deregisterOptions);

            imageDeregisterer.Deregister();
            return(Result.SuccessChanged());
        }
示例#17
0
        public void Setup()
        {
            var tokenSource = new CancellationTokenSource();

            _token = tokenSource.Token;

            new Logger().AutoResolveLogger();
            _settingsStopAfterMarkedServer = new ConDepSettings
            {
                Config =
                {
                    EnvironmentName = "bogus",
                    LoadBalancer    = new LoadBalancerConfig
                    {
                        Name        = "bogus"
                    }
                },
                Options =
                {
                    StopAfterMarkedServer = true,
                    SuspendMode           = LoadBalancerSuspendMethod.Graceful
                }
            };

            _settingsContinueAfterMarkedServer = new ConDepSettings
            {
                Config =
                {
                    EnvironmentName = "bogus",
                    LoadBalancer    = new LoadBalancerConfig
                    {
                        Name        = "bogus"
                    }
                },
                Options =
                {
                    ContinueAfterMarkedServer = true,
                    SuspendMode               = LoadBalancerSuspendMethod.Graceful
                }
            };

            _settingsDefault = new ConDepSettings
            {
                Config =
                {
                    EnvironmentName = "bogus",
                    LoadBalancer    = new LoadBalancerConfig
                    {
                        Name        = "bogus"
                    }
                },
                Options =
                {
                    SuspendMode = LoadBalancerSuspendMethod.Graceful
                }
            };
        }
示例#18
0
        public void PopulateWithDependencies(IProvideArtifact artifact, ConDepSettings settings)
        {
            if (!HasDependenciesDefined(artifact))
            {
                return;
            }

            artifact.Dependencies = GetDependeciesForArtifact(artifact, settings);
        }