Skip to content
This repository has been archived by the owner on Jun 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #19 from ALM-Rangers/develop
Browse files Browse the repository at this point in the history
Manual interventions in rollback blocks should not crash the application
  • Loading branch information
DanielBMann9000 committed Apr 21, 2016
2 parents fd6f830 + b212a86 commit 666d6ce
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RollbackActionResolutionResult.cs" company="Microsoft Corporation">
// Copyright Microsoft Corporation. All Rights Reserved. This code released under the terms of the MIT License (MIT, https://github.com/ALM-Rangers/Migrate-assets-from-RM-server-to-VSO/blob/master/License.txt). This is sample code only, do not use in production environments.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Microsoft.ALMRangers.RMWorkflowMigrator.Generator.PowerShell.Model
{
using System.Collections.Generic;

public class RollbackActionResolutionResult
{
public IEnumerable<ScriptAction> Actions { get; set; }
public IEnumerable<ScriptManualIntervention> ManualInterventions { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</Compile>
<Compile Include="FileSystem.cs" />
<Compile Include="IFileSystem.cs" />
<Compile Include="Model\RollbackActionResolutionResult.cs" />
<Compile Include="Templates\ManualInterventionTemplate.cs">
<DependentUpon>ManualInterventionTemplate.tt</DependentUpon>
<AutoGen>True</AutoGen>
Expand Down
38 changes: 23 additions & 15 deletions src/RMWorkflowMigrator.Generator.PowerShell/ScriptGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,13 @@ stuff extracted from the RM XAML workflow and stuff we pull out of the RM databa
Thus, we need to flatten out the list of parameters across the entire server/tag container and "uniqueify" them.
*/
var elementsToResolve =
rollbackActions.SelectMany(ra => ra.Value).Union(scriptActionElements).OrderBy(s => s.Sequence);
rollbackActions.SelectMany(ra => ra.Value.Actions).Union(scriptActionElements).OrderBy(s => s.Sequence);

UniquePropertyResolver.ResolveProperties(elementsToResolve);

// Invoke the T4 template for the container and for any rollback/rollback always blocks and write them out to disk
var rollbackParameters =
rollbackActions.SelectMany(s => s.Value).SelectMany(s => s.ConfigurationVariables).ToList();
rollbackActions.SelectMany(s => s.Value.Actions).SelectMany(s => s.ConfigurationVariables).ToList();
var scriptParameters = scriptActionElements.SelectMany(s => s.ConfigurationVariables).ToList();

var releaseScriptText = CreateScriptFromTemplate(
Expand All @@ -362,11 +362,11 @@ stuff extracted from the RM XAML workflow and stuff we pull out of the RM databa
foreach (var rollbackGroup in rollbackActions)
{
string rollbackScriptName = $"{rollbackGroup.Key}.ps1";

var rollbackScript = CreateScriptFromTemplate(
rollbackGroup.Value,
scriptManualInterventionElements,
rollbackGroup.Value.SelectMany(s => s.ConfigurationVariables).Distinct(new ConfigurationVariableEqualityComparer()),
rollbackGroup.Value.Actions,
rollbackGroup.Value.ManualInterventions,
rollbackGroup.Value.Actions.SelectMany(s => s.ConfigurationVariables).Distinct(new ConfigurationVariableEqualityComparer()),
false);
this.fs.WriteAllText(Path.Combine(targetPath, rollbackScriptName), rollbackScript);
}
Expand Down Expand Up @@ -396,12 +396,12 @@ stuff extracted from the RM XAML workflow and stuff we pull out of the RM databa
}
}

private async Task<Dictionary<string, List<ScriptAction>>> ResolveRollbackActions(
private async Task<Dictionary<string, RollbackActionResolutionResult>> ResolveRollbackActions(
int stageId,
IEnumerable<ReleaseAction> actions,
IReadOnlyCollection<ScriptAction> scriptElements)
{
var rollbackActions = new Dictionary<string, List<ScriptAction>>();
var rollbackActions = new Dictionary<string, RollbackActionResolutionResult>();

// Group the rollback action parameters
var groupedRollbackActions =
Expand All @@ -421,6 +421,7 @@ private async Task<Dictionary<string, List<ScriptAction>>> ResolveRollbackAction
foreach (var rollbackGroup in groupedRollbackActions)
{
var rollbackScriptActions = new List<ScriptAction>();
var rollbackManualInterventions = new List<ScriptManualIntervention>();
if (rollbackGroup.Item == null)
{
continue;
Expand Down Expand Up @@ -450,12 +451,19 @@ private async Task<Dictionary<string, List<ScriptAction>>> ResolveRollbackAction
this.ScriptGenerationNotification?.Invoke(
this,
GetActionGenerationArgs(rollbackAction, ActionStart));
var component =
await this.componentRepo.GetComponentByIdAsync(rollbackAction.WorkflowActivityId, stageId);
await this.deployerToolRepo.WriteToolToDiskAsync(component.DeployerToolId, this.deployerToolsPath);
var action = CreateScriptAction(component, rollbackAction);
action.Sequence += rollbackGroup.Item.Sequence;
rollbackScriptActions.Add(action);
if (rollbackAction.ItemType != BlockType.ManualIntervention)
{
var component =
await this.componentRepo.GetComponentByIdAsync(rollbackAction.WorkflowActivityId, stageId);
await this.deployerToolRepo.WriteToolToDiskAsync(component.DeployerToolId, this.deployerToolsPath);
var action = CreateScriptAction(component, rollbackAction);
action.Sequence += rollbackGroup.Item.Sequence;
rollbackScriptActions.Add(action);
}
else
{
rollbackManualInterventions.Add(await this.CreateScriptManualIntervention((ManualIntervention)rollbackAction));
}
this.ScriptGenerationNotification?.Invoke(this, GetActionGenerationArgs(rollbackAction, ActionEnd));
}

Expand All @@ -464,7 +472,7 @@ private async Task<Dictionary<string, List<ScriptAction>>> ResolveRollbackAction
scriptElementToAttachRollback.RollbackScripts.Add(rollbackGroup.Key, rollbackScriptActions);
}

rollbackActions.Add(rollbackGroup.Key, rollbackScriptActions);
rollbackActions.Add(rollbackGroup.Key, new RollbackActionResolutionResult { Actions = rollbackScriptActions, ManualInterventions = rollbackManualInterventions });
this.ScriptGenerationNotification?.Invoke(
this,
GetContainerGenerationArgs(rollbackGroup.Item, ContainerEnd));
Expand Down
Loading

0 comments on commit 666d6ce

Please sign in to comment.