private void LoadBatchRequestFile(string filePath) { try { if(!File.Exists(filePath)) { throw new FileNotFoundException("Batch Request File Not Found", filePath); } string jsonData = File.ReadAllText(filePath); if(string.IsNullOrEmpty(jsonData)) { throw new ArgumentException(string.Format("File is empty \"{0}\"", filePath)); } _batchRequest = JsonConvert.DeserializeObject<DeployBatchRequest>(jsonData); _txtRequestFileName.Text = filePath; _pnlAllComponents.Controls.Clear(); foreach(var item in _batchRequest.ItemList) { var ctrl = new ComponentSelectionControl(item); _pnlAllComponents.Controls.Add(ctrl); } _pnlDeploymentInfo.Visible = true; _btnContinue.Visible = true; } catch(Exception err) { WinFormsHelper.DisplayError(string.Format("Error loading batch file name \"{0}\": {1}", filePath, err.Message), err); } }
public ExportHistoryForm(IDIFactory diFactory, DeployBatchRequest batchRequest, string workingDirectory) { _diFactory = diFactory; _batchRequest = batchRequest; _workingDirectory = workingDirectory; InitializeComponent(); }
public ViewDeploymentHistoryForm(IDIFactory diFactory, DeployBatchRequest batchRequest, string workingDirectory) { _batchRequest = batchRequest; _workingDirectory = workingDirectory; _diFactory = diFactory; InitializeComponent(); _grdHistory.AutoGenerateColumns = false; }
public RunDeploymentForm(IDIFactory diFactory, DeployBatchRequest batchRequest, List<OfflineComponentSelection> selectionList, string workingDirectory) { InitializeComponent(); _batchRequest = batchRequest; _selectionList = selectionList; _workingDirectory = workingDirectory; _diFactory = diFactory; }
public void Notify(DeployBatchRequest batchRequest) { if(this.BatchRequestNotificationReceived != null) { var args = new EventArgs<DeployBatchRequest>(batchRequest); this.BatchRequestNotificationReceived(this, args); } }
private DeployBatchStatus BuildDeployBatchStatus(DeployBatchRequest deployBatchRequest) { var status = new DeployBatchStatus { Request = deployBatchRequest, DeployBatchRequestId = deployBatchRequest.Id, DeployStateList = _deployStateRepository.GetDeployStateSummaryListByDeployBatchRequestItemId(deployBatchRequest.Id) }; return status; }
private void RunDeployment(DeployBatchRequest deployBatchRequest) { string subDirName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + deployBatchRequest.Id; string deployDirectory = Path.Combine(_systemSettings.DeployWorkingDirectory, subDirName); if (Directory.Exists(deployDirectory)) { //if directory already exists, start adding "_1", "_2", until we get a directory that does not exist int counter = 1; string newDeployDirectory = deployDirectory; while (Directory.Exists(newDeployDirectory)) { newDeployDirectory = deployDirectory + "_" + counter.ToString(); counter++; } deployDirectory = newDeployDirectory; } var runtimeSettings = new RuntimeSystemSettings { LocalDeployDirectory = deployDirectory }; Directory.CreateDirectory(runtimeSettings.LocalDeployDirectory); _cleanupManager.QueueFolderForCleanup(runtimeSettings.LocalMachineName, runtimeSettings.LocalDeployDirectory, _systemSettings.DeploymentFolderCleanupMinutes); foreach (var item in deployBatchRequest.ItemList) { foreach (var machine in item.MachineList) { if (_deployRequestManager.HasCancelRequested(deployBatchRequest.Id)) { _deployStateManager.MarkBatchDeploymentCancelled(deployBatchRequest.Id, deployBatchRequest.CancelMessage); return; } var deployState = _deployStateManager.GetOrCreateDeployState(item.Build.ProjectId, item.Build.Id, machine.EnvironmentId, machine.Id, deployBatchRequest.Id); if (deployState.Status != EnumDeployStatus.Success) { try { _deployStateManager.MarkDeploymentInProcess(deployState.Id); var machineIdList = new List<string> { machine.Id }; _deployRunner.Deploy(deployState.Id, machine.EnvironmentId, item.Build.Id, machineIdList, runtimeSettings); _deployStateManager.MarkDeploymentSuccess(deployState.Id); } catch (Exception err) { _deployStateManager.MarkDeploymentFailed(deployState.Id, err); throw; } } } } _deployStateManager.MarkBatchDeploymentSuccess(deployBatchRequest.Id); this._logger.Info("Deployment complete: " + deployBatchRequest.Id); }
private void RunDeployment(DeployBatchRequest deployBatchRequest) { string subDirName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + deployBatchRequest.Id; string deployDirectory = Path.Combine(_systemSettings.DeployWorkingDirectory, subDirName); if (Directory.Exists(deployDirectory)) { //if directory already exists, start adding "_1", "_2", until we get a directory that does not exist int counter = 1; string newDeployDirectory = deployDirectory; while (Directory.Exists(newDeployDirectory)) { newDeployDirectory = deployDirectory + "_" + counter.ToString(); counter++; } deployDirectory = newDeployDirectory; } var runtimeSettings = new RuntimeSystemSettings { LocalDeployDirectory = deployDirectory, LocalMachineName = Environment.MachineName }; Directory.CreateDirectory(runtimeSettings.LocalDeployDirectory); _cleanupManager.QueueFolderForCleanup(runtimeSettings.LocalMachineName, runtimeSettings.LocalDeployDirectory, _systemSettings.DeploymentFolderCleanupMinutes); var plan = _deploymentPlanBuilder.Build(deployBatchRequest); //_deployStateManager.SaveDeploymentPlan(plan); foreach (var parallelBatchList in plan.ParallelBatchList) { var taskList = new List<Task>(); foreach (var machineQueue in parallelBatchList.MachineQueueList) { string machineQueueId = machineQueue.Id; var task = Task.Factory.StartNew(() => DeployMachineQueue(plan, machineQueueId, runtimeSettings)); taskList.Add(task); } var taskArray = taskList.ToArray(); Task.WaitAll(taskArray); if (_deployRequestManager.IsStopped(deployBatchRequest.Id)) { break; } } _deployStateManager.MarkBatchDeploymentSuccess(deployBatchRequest.Id); this._logger.Info("Deployment complete: " + deployBatchRequest.Id); }
public DeployBatchRequest CreateBatchRequest(List<DeployBatchRequestItem> itemList, EnumDeployStatus status, string deploymentLabel) { if(itemList == null || itemList.Count == 0) { throw new ArgumentNullException("itemList"); } foreach (var item in itemList) { if(string.IsNullOrEmpty(item.Id)) { item.Id = Guid.NewGuid().ToString(); } } if(status == EnumDeployStatus.Unknown) { status = EnumDeployStatus.NotStarted; } string message = string.Format("{0} created deployment request with status of {1} at {2} UTC.", _userIdentity.UserName, EnumHelper.GetDisplayValue(status), DateTime.UtcNow); var request = new DeployBatchRequest { Id = Guid.NewGuid().ToString(), SubmittedDateTimeUtc = DateTime.UtcNow, SubmittedByUserName = _userIdentity.UserName, DeploymentLabel = deploymentLabel, ItemList = itemList, LastStatusMessage = message, Status = status, CreatedDateTimeUtc = DateTime.UtcNow, CreatedByUserName = _userIdentity.UserName, UpdatedDateTimeUtc = DateTime.UtcNow, UpdatedByUserName = _userIdentity.UserName }; request.MessageList.Add(message); _documentSession.StoreSaveEvict(request); return request; }
public void Initialize(string offlineDeploymentRunId, DeployBatchRequest deployBatchRequest, List<OfflineComponentSelection> selectionList, string workingDirectory) { if(!string.IsNullOrEmpty(offlineDeploymentRunId)) { string runDirectory = Path.Combine(workingDirectory, "runs"); string runFileName = Path.Combine(runDirectory, offlineDeploymentRunId + ".json"); if (!File.Exists(runFileName)) { throw new FileNotFoundException("Missing run file", runFileName); } var json = File.ReadAllText(runFileName); _deploymentRun = JsonConvert.DeserializeObject<OfflineDeploymentRun>(json); } else { _deploymentRun = new OfflineDeploymentRun { Id = Guid.NewGuid().ToString(), DeployBatchRequest = deployBatchRequest, SelectionList = selectionList }; } _workingDirectory = workingDirectory; }
public void SendDeployCancelledNotification(DeployBatchRequest deployRequest) { }
public void SendDeploySuccessNotification(DeployBatchRequest deployRequest) { }
public void SendDeployStartedNotification(DeployBatchRequest deployRequest) { }
public void SendDeployApprovedNotification(DeployBatchRequest deployRequest) { }
public SelectMachineForm(DeployBatchRequest batchRequest) { InitializeComponent(); _batchRequest = batchRequest; }
private DeployBatchRequest DeployBuilds(string apiUrl, string userName, string password, string environmentName, params DeployBuild[] buildData) { if(string.IsNullOrEmpty(environmentName)) { return null; } string url = apiUrl; if (!url.EndsWith("/")) { url += "/"; } if (!url.EndsWith("/api/", StringComparison.CurrentCultureIgnoreCase)) { url += "api/"; } Cookie authCookie = null; if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { authCookie = GetAuthCookie(apiUrl, userName, password); } using (var client = new JsonServiceClient(url)) { //var x = client.Send<DeployFileDto>(deployFile); client.Credentials = System.Net.CredentialCache.DefaultCredentials; client.Timeout = TimeSpan.FromMinutes(5); client.ReadWriteTimeout = TimeSpan.FromMinutes(5); if (authCookie != null) { client.CookieContainer.Add(authCookie); } var projectIdList = buildData.Select(i=>i.ProjectId).Distinct().ToList(); var componentIdMachines = new Dictionary<string, DeployMachine>(); foreach(var build in buildData) { string projectUrl = url + "project/?format=json&id=" + System.Uri.EscapeDataString(build.ProjectId); var project = client.Get<DeployProject>(projectUrl); var environment = project.EnvironmentList.FirstOrDefault(i=> environmentName.Equals(i.EnvironmentName, StringComparison.CurrentCultureIgnoreCase)); if(environment == null) { throw new Exception("Unable to find environment " + environmentName + " in project " + project.ProjectName); } var component = project.GetComponent(build.ProjectComponentId); if(component.UseConfigurationGroup && !string.IsNullOrEmpty(component.ConfigurationId)) { var environmentConfiguration = environment.GetConfigurationItem(component.ConfigurationId); foreach(var machine in environmentConfiguration.MachineList) { componentIdMachines.Add(component.Id, machine); } } else { var environmentComponent = environment.GetComponentItem(component.Id); foreach(var machine in environmentComponent.MachineList) { componentIdMachines.Add(component.Id, machine); } } } var deployBatchRequest = new DeployBatchRequest { DeploymentLabel = "Auto-Deploy " + DateTime.UtcNow.ToString(), Status = EnumDeployStatus.Requested, ItemList = (from b in buildData select new DeployBatchRequestItem { Build = b, MachineList = componentIdMachines.Where(i=>i.Key == b.ProjectComponentId).Select(i=>i.Value).ToList() }).ToList() }; var batchRequestUrl = url + "deploy/batch/request"; _logger.Debug("Posting DeployBatchRequest object to URL {0}, sending{1}", batchRequestUrl, deployBatchRequest.ToJson()); DeployBatchRequest response; try { response = client.Post<DeployBatchRequest>(batchRequestUrl, deployBatchRequest); } catch (Exception err) { _logger.WarnException(string.Format("Error posting DeployBatchRequest object to URL {0}: {1}, ERROR: {2}", url, deployBatchRequest.ToJson(), err.ToString()), err); throw; } _logger.Debug("Posting DeployBuild object to URL {0}, returned {1}", url, response.ToJson()); return response; } }
public DeploymentPlan Build(DeployBatchRequest deployBatchRequest) { var returnValue = new DeploymentPlan() { DeployBatchRequestId = deployBatchRequest.Id }; DeploymentPlanParallelBatch currentParallelBatch = null; var itemList = FilterItemList(deployBatchRequest.ItemList); if(itemList != null) { foreach (var item in itemList) { EnumDeploymentIsolationType isolationType = _projectManager.GetComponentIsolationType(item.Build.ProjectId, item.Build.ProjectComponentId); if(isolationType == EnumDeploymentIsolationType.IsolatedPerDeployment) { currentParallelBatch = null; foreach(var machine in item.MachineList) { var parallelBatchItem = new DeploymentPlanParallelBatch { IsolationType = EnumDeploymentIsolationType.IsolatedPerDeployment, MachineQueueList = new List<DeploymentPlanMachineQueue> { new DeploymentPlanMachineQueue() { Id = Guid.NewGuid().ToString(), MachineName = machine.MachineName, MachineQueueItemList = new List<DeploymentPlanMachineQueueItem> { new DeploymentPlanMachineQueueItem { MachineId = machine.Id, DeployBatchRequestItem = item } } } } }; returnValue.ParallelBatchList.Add(parallelBatchItem); } } else if (isolationType == EnumDeploymentIsolationType.IsolatedPerMachine) { if (currentParallelBatch == null || currentParallelBatch.IsolationType != EnumDeploymentIsolationType.IsolatedPerMachine) { currentParallelBatch = new DeploymentPlanParallelBatch { IsolationType = EnumDeploymentIsolationType.IsolatedPerMachine }; returnValue.ParallelBatchList.Add(currentParallelBatch); } foreach(var machine in item.MachineList) { var machineQueue = currentParallelBatch.MachineQueueList.FirstOrDefault(i=>i.MachineName.Equals(machine.MachineName, StringComparison.CurrentCultureIgnoreCase)); if(machineQueue == null) { machineQueue = new DeploymentPlanMachineQueue { Id = Guid.NewGuid().ToString(), MachineName = machine.MachineName }; currentParallelBatch.MachineQueueList.Add(machineQueue); } var machineQueueItem = new DeploymentPlanMachineQueueItem { MachineId = machine.Id, DeployBatchRequestItem = item }; machineQueue.MachineQueueItemList.Add(machineQueueItem); } } else if(isolationType == EnumDeploymentIsolationType.NoIsolation) { if (currentParallelBatch == null || currentParallelBatch.IsolationType != EnumDeploymentIsolationType.NoIsolation) { currentParallelBatch = new DeploymentPlanParallelBatch { IsolationType = EnumDeploymentIsolationType.NoIsolation }; returnValue.ParallelBatchList.Add(currentParallelBatch); } foreach (var machine in item.MachineList) { var machineQueue = new DeploymentPlanMachineQueue { Id = Guid.NewGuid().ToString(), MachineName = machine.MachineName }; currentParallelBatch.MachineQueueList.Add(machineQueue); var machineQueueItem = new DeploymentPlanMachineQueueItem { MachineId = machine.Id, DeployBatchRequestItem = item }; machineQueue.MachineQueueItemList.Add(machineQueueItem); } } else { throw new UnknownEnumValueException(isolationType); } } } return returnValue; }
public RunDeploymentForm(IDIFactory diFactory, OfflineDeploymentRun offlineDeploymentRun, string workingDirectory) { InitializeComponent(); _offlineDeploymentRunId = offlineDeploymentRun.Id; _batchRequest = offlineDeploymentRun.DeployBatchRequest; _selectionList = offlineDeploymentRun.SelectionList; _workingDirectory = workingDirectory; _diFactory = diFactory; }
public void SendDeployCancelledNotification(DeployBatchRequest deployRequest) { var projectIdList = deployRequest.ItemList.Select(i => i.Build.ProjectId).Distinct().ToList(); var emailAddresseList = GetNotificationEmailAddresses(projectIdList, i => i.DeployStarted); if (emailAddresseList != null && emailAddresseList.Count > 0) { var dataObject = new { DeployBatchStatus = new DeployBatchStatus { DeployBatchRequestId = deployRequest.Id, Request = _deployRepository.GetBatchRequest(deployRequest.Id), DeployStateList = _deployStateRepository.GetDeployStateSummaryListByDeployBatchRequestItemId(deployRequest.Id) }, DisplayTimeZoneIdentifier = _systemSettings.DisplayTimeZoneIdentifier, DeployStatusUrl = _urlGenerator.DeployStatusUrl(deployRequest.Id) }; var template = _razorTemplateRepository.GetTemplate("DeployCancelledEmail", _notificationResourceViews.DeployCancelledEmailView); var machineNames = string.Join(",", deployRequest.ItemList.SelectMany(i => i.MachineList.Select(j => j.MachineName)).Distinct().ToArray()); string deployLabel = deployRequest.DeploymentLabel; string subject = string.Format("Deployment Cancelled: {0} ({1})", StringHelper.IsNullOrEmpty(deployLabel, string.Empty), machineNames); _emailQueue.QueueMessage(subject, emailAddresseList, dataObject, template.ViewData); } }
void _runDeploymentWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { if(e.UserState is DeployState) { var state = (DeployState)e.UserState; var item = _gridItemList.FirstOrDefault(i=>i.DeployBatchRequestItemId == state.DeployBatchRequestItemId); if(item != null) { item.Update(state); _grdStatus.Refresh(); } } else if(e.UserState is DeployBatchRequest) { _batchRequest = (DeployBatchRequest)e.UserState; this.UpdateBatchDetails(); } }