예제 #1
0
        public async Task <JobResult> Execute()
        {
            if (!File.Exists(AntaresDeploymentExecutablePath))
            {
                var ex = new FileNotFoundException("Cannot find file", Path.GetFileName(AntaresDeploymentExecutablePath));
                _logger.WriteError(_parameters, "Cannot find file", ex);
                throw ex;
            }

            var processStartInfo = new ProcessStartInfo();

            processStartInfo.FileName               = AntaresDeploymentExecutablePath;
            processStartInfo.Arguments              = $"SetupPrivateStampWithGeo {_parameters.CloudName} /SubscriptionId:b27cf603-5c35-4451-a33a-abba1a08c9c2 /VirtualDedicated:true /bvtCapableStamp:true /DefaultLocation:\"Central US\"";
            processStartInfo.UseShellExecute        = false;
            processStartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            processStartInfo.RedirectStandardError  = true;
            processStartInfo.RedirectStandardOutput = true;

            _logger.WriteInfo(_parameters, $"Start {processStartInfo.FileName} {processStartInfo.Arguments}");

            using (var createProcess = Process.Start(processStartInfo))
            {
                createProcess.BeginErrorReadLine();
                createProcess.BeginOutputReadLine();
                createProcess.OutputDataReceived += new DataReceivedEventHandler(OutputReceived);
                createProcess.ErrorDataReceived  += new DataReceivedEventHandler(ErrorReceived);
                createProcess.WaitForExit();
            }

            var definitionsPath          = $@"\\AntaresDeployment\PublicLockBox\{_parameters.CloudName}\developer.definitions";
            var cloudStampyFirewallRules =
                @"
<redefine name=""SqlFirewallAddressRangesList"" value=""131.107.0.0/16;167.220.0.0/16;65.55.188.0/24;104.44.112.0/24;157.58.30.0/24"" /><redefine name=""FirewallLockdownWhitelistedSources"" value=""131.107.0.0/16;167.220.0.0/16;65.55.188.0/24;104.44.112.0/24;157.58.30.0/24"" />
";

            if (!TryModifyDefinitions(definitionsPath, cloudStampyFirewallRules))
            {
                _statusMessageBuilder.AppendLine("Failed to add cloud stampy firewall rules to developer.definitions file.");
                _result.JobStatus = Status.Failed;
            }

            _result.Message   = _statusMessageBuilder.ToString();
            _result.JobStatus = JobStatus = _result.JobStatus == Status.None ? Status.Passed : _result.JobStatus;
            await Task.WhenAll(_azureLogsWriterUnfinishedJobs);

            return(_result);
        }
예제 #2
0
        public async Task <JobResult> Execute()
        {
            JobResult jobResult;

            if (!Directory.Exists(_args.BuildPath))
            {
                _logger.WriteError(_args, $"Failed to access fileshare: {_args.BuildPath}");
                jobResult = new JobResult
                {
                    JobStatus = Status.Failed,
                    Message   = $"Failed to access fileshare: {_args.BuildPath}"
                };

                return(jobResult);
            }

            if (!TryCreateTestConfig($@"\\antaresdeployment\PublicLockbox\{_args.CloudName}geo"))
            {
                jobResult           = new JobResult();
                jobResult.JobStatus = Status.Failed;
                jobResult.Message   = $"Failed to create TestCommon config file";
                return(jobResult);
            }

            if (_args.TestCategories == null || _args.TestCategories.Count == 0)
            {
                jobResult           = new JobResult();
                jobResult.JobStatus = Status.Failed;
                jobResult.Message   = $"Test names were not specified";
                return(jobResult);
            }

            var testClient = TestClientFactory.GetTestClient(_logger, _args);

            _logger.WriteInfo(_args, $"Execute {_args.TestCategories[0].First()} tests");
            var jResult = await JobStatusHelper.StartPeriodicStatusUpdates(this, (IJob)testClient, testClient.ExecuteTestAsync(_args.TestCategories[0].First()));

            return(jResult);
        }
예제 #3
0
파일: BuildJob.cs 프로젝트: hforeste/Stampy
        public async Task <JobResult> Execute()
        {
            var job     = (IJob)_buildClient;
            var jResult = await job.Execute();

            object buildPath = null;

            if (jResult.ResultDetails.TryGetValue("Build Share", out buildPath))
            {
                _logger.WriteInfo(_args, $"Finished executing build at {(string)buildPath}");
            }
            else
            {
                _logger.WriteError(_args, "Failed to get build path");
            }
            return(jResult);
        }
예제 #4
0
        private async Task CreateIfNotExistAppendAsync(string content)
        {
            try
            {
                var storageAccount   = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("StampyStorageConnectionString"));
                var fileShareClient  = storageAccount.CreateCloudFileClient();
                var fileShare        = fileShareClient.ListShares("stampy-job-results").FirstOrDefault();
                var root             = fileShare.GetRootDirectoryReference();
                var requestDirectory = root.GetDirectoryReference(_parameters.RequestId);

                var operationContext = new OperationContext();

                if (await requestDirectory.CreateIfNotExistsAsync(null, operationContext))
                {
                    _logger.WriteInfo(_parameters, string.Format("Created new file share to host deployment logs at {0}. HttpResult:{1}", requestDirectory.Uri, operationContext.LastResult.HttpStatusCode));
                }

                var logFileName   = Path.GetFileName(_localFilePath);
                var fileReference = requestDirectory.GetFileReference(logFileName);

                var buffer = Encoding.UTF8.GetBytes(content);

                if (!await fileReference.ExistsAsync())
                {
                    await fileReference.CreateAsync(0, null, null, operationContext);

                    _logger.WriteInfo(_parameters, $"Create deployment log file in azure. Location: {fileReference.Uri} HttpResult: {operationContext.LastResult.HttpStatusCode}");
                }

                await fileReference.ResizeAsync(fileReference.Properties.Length + buffer.Length, null, null, operationContext);

                if (operationContext.LastResult.HttpStatusCode != 200)
                {
                    _logger.WriteInfo(_parameters, $"Resize the azure file {fileReference.Uri} so to add new content. HttpResult: {operationContext.LastResult.HttpStatusCode}");
                }

                using (var fileStream = await fileReference.OpenWriteAsync(null, null, null, operationContext))
                {
                    fileStream.Seek(buffer.Length * -1, SeekOrigin.End);
                    await fileStream.WriteAsync(buffer, 0, buffer.Length);
                }

                if (string.IsNullOrWhiteSpace(ReportUri))
                {
                    SharedAccessFilePolicy sharedPolicy = new SharedAccessFilePolicy()
                    {
                        SharedAccessExpiryTime = DateTime.UtcNow.AddMonths(1),
                        Permissions            = SharedAccessFilePermissions.Read
                    };

                    var permissions = await fileShare.GetPermissionsAsync(null, null, null);

                    permissions.SharedAccessPolicies.Clear();
                    permissions.SharedAccessPolicies.Add("read", sharedPolicy);

                    await fileShare.SetPermissionsAsync(permissions, null, null, null);

                    ReportUri = new Uri(fileReference.StorageUri.PrimaryUri.ToString() + fileReference.GetSharedAccessSignature(null, "read")).ToString();
                }
            }catch (Exception ex)
            {
                _logger.WriteError(_parameters, $"Failed to write deployment log to azure file", ex);
                throw;
            }
        }