-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inventorize disks in eryph storage independently of catlets (#293)
* Inventory disks independently of catlets * Monitor disk stores for changes and trigger inventory * Use database transactions for Rebus unit-of-work * Introduce deleted flag for disks * Block inventory updates when the project is being deleted * Fix incorrect status tracking in DestroyResourcesSaga Closes #211
- Loading branch information
1 parent
140ab15
commit 738c777
Showing
65 changed files
with
1,513 additions
and
677 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/core/src/Eryph.Messages/Resources/Catlets/Commands/RemoveVirtualDiskCommandResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Eryph.Messages.Resources.Catlets.Commands; | ||
|
||
public class RemoveVirtualDiskCommandResponse | ||
{ | ||
public DateTimeOffset Timestamp { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 9 additions & 8 deletions
17
src/core/src/Eryph.Messages/Resources/Commands/DestroyResourcesResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
using Eryph.Resources; | ||
using System.Collections.Generic; | ||
using Eryph.Resources; | ||
|
||
namespace Eryph.Messages.Resources.Commands | ||
namespace Eryph.Messages.Resources.Commands; | ||
|
||
public class DestroyResourcesResponse | ||
{ | ||
public class DestroyResourcesResponse | ||
{ | ||
public Resource[] DestroyedResources { get; set; } | ||
public Resource[] DetachedResources { get; set; } | ||
} | ||
} | ||
public required IReadOnlyList<Resource> DestroyedResources { get; set; } | ||
|
||
public required IReadOnlyList<Resource> DetachedResources { get; set; } | ||
} |
10 changes: 7 additions & 3 deletions
10
src/core/src/Eryph.Messages/Resources/Disks/RemoveDisksCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
using Eryph.Resources.Disks; | ||
using System; | ||
using System.Collections.Generic; | ||
using Eryph.Resources.Disks; | ||
|
||
namespace Eryph.Messages.Resources.Disks; | ||
|
||
public class CheckDisksExistsReply | ||
{ | ||
public DiskInfo[] MissingDisks { get; set; } | ||
} | ||
public IReadOnlyList<DiskInfo> MissingDisks { get; set; } | ||
|
||
public DateTimeOffset Timestamp { get; set; } | ||
} |
17 changes: 17 additions & 0 deletions
17
src/core/src/Eryph.Messages/Resources/Disks/UpdateDiskInventoryCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Eryph.Resources.Disks; | ||
|
||
namespace Eryph.Messages.Resources.Disks; | ||
|
||
public class UpdateDiskInventoryCommand | ||
{ | ||
public string AgentName { get; init; } | ||
|
||
public DateTimeOffset Timestamp { get; init; } | ||
|
||
public IList<DiskInfo> Inventory { get; init; } | ||
} |
61 changes: 61 additions & 0 deletions
61
src/core/src/Eryph.VmManagement/Inventory/DiskStoreInventory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Eryph.Core; | ||
using Eryph.Core.VmAgent; | ||
using Eryph.Resources.Disks; | ||
using Eryph.VmManagement.Storage; | ||
using LanguageExt; | ||
using LanguageExt.Common; | ||
|
||
using static LanguageExt.Prelude; | ||
using static LanguageExt.Seq; | ||
|
||
namespace Eryph.VmManagement.Inventory; | ||
|
||
public static class DiskStoreInventory | ||
{ | ||
public static Aff<Seq<Either<Error, DiskInfo>>> InventoryStores( | ||
IFileSystemService fileSystemService, | ||
IPowershellEngine powershellEngine, | ||
VmHostAgentConfiguration vmHostAgentConfig) => | ||
from _ in SuccessAff(unit) | ||
let storePaths = append( | ||
vmHostAgentConfig.Environments.ToSeq() | ||
.Bind(e => e.Datastores.ToSeq()) | ||
.Map(ds => ds.Path), | ||
vmHostAgentConfig.Environments.ToSeq() | ||
.Map(e => e.Defaults.Volumes), | ||
vmHostAgentConfig.Datastores.ToSeq() | ||
.Map(ds => ds.Path), | ||
Seq1(vmHostAgentConfig.Defaults.Volumes)) | ||
from diskInfos in storePaths | ||
.Map(storePath => InventoryStore(fileSystemService, powershellEngine, vmHostAgentConfig, storePath)) | ||
.SequenceSerial() | ||
select diskInfos.Flatten(); | ||
|
||
public static Aff<Seq<Either<Error, DiskInfo>>> InventoryStore( | ||
IFileSystemService fileSystemService, | ||
IPowershellEngine powershellEngine, | ||
VmHostAgentConfiguration vmHostAgentConfig, | ||
string path) => | ||
from vhdFiles in Eff(() => fileSystemService.GetFiles(path, "*.vhdx", SearchOption.AllDirectories)) | ||
from diskInfos in vhdFiles.ToSeq() | ||
.Map(vhdFile => InventoryDisk(powershellEngine, vmHostAgentConfig, vhdFile)) | ||
.SequenceParallel() | ||
select diskInfos; | ||
|
||
private static Aff<Either<Error, DiskInfo>> InventoryDisk( | ||
IPowershellEngine powershellEngine, | ||
VmHostAgentConfiguration vmHostAgentConfig, | ||
string diskPath) => | ||
from diskSettings in DiskStorageSettings.FromVhdPath(powershellEngine, vmHostAgentConfig, diskPath) | ||
.ToAff(identity) | ||
.Map(Right<Error, DiskStorageSettings>) | ||
| @catch(e => SuccessAff(Left<Error, DiskStorageSettings>( | ||
Error.New($"Inventory of virtual disk '{diskPath}' failed", e)))) | ||
select diskSettings.Map(s => s.CreateDiskInfo()); | ||
} |
11 changes: 10 additions & 1 deletion
11
.../20241203163012_InitialCreate.Designer.cs → .../20250122141438_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
.../20241203163008_InitialCreate.Designer.cs → .../20250122141433_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.