Skip to content

Commit

Permalink
Remove workload support following dotnet/aspire#5185
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifAqqad committed Sep 4, 2024
1 parent 39fb67f commit 571520f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 239 deletions.
6 changes: 0 additions & 6 deletions src/AspireRunner.AspNetCore/AspireDashboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ public Task StartAsync(CancellationToken cancellationToken)
{
logger.LogInformation("Starting the Aspire Dashboard Service");

if (!await dashboardManager.InitializeAsync())
{
logger.LogError("Failed to initialize the Aspire Dashboard Manager");
return;
}

_aspireDashboard = await dashboardManager.GetDashboardAsync(options.Value, loggerFactory.CreateLogger<AspireDashboard>());
logger.LogInformation("Found Aspire Dashboard version {Version}", _aspireDashboard.Version);

Expand Down
2 changes: 0 additions & 2 deletions src/AspireRunner.Core/AspireDashboard.Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

public partial class AspireDashboard
{
internal const string WorkloadId = "aspire";

internal const string SdkName = "Aspire.Dashboard.Sdk";

internal const string DllName = "Aspire.Dashboard.dll";
Expand Down
79 changes: 13 additions & 66 deletions src/AspireRunner.Core/AspireDashboardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,25 @@ public class AspireDashboardManager
private readonly NugetHelper _nugetHelper;
private readonly ILogger<AspireDashboardManager> _logger;

private bool _initialized;
private string _runnerFolder = null!;
private string _nugetPackageName = null!;
private readonly string _runnerFolder;
private readonly string _nugetPackageName;

public AspireDashboardManager(DotnetCli dotnetCli, NugetHelper nugetHelper, ILogger<AspireDashboardManager> logger)
{
_logger = logger;
_dotnetCli = dotnetCli;
_nugetHelper = nugetHelper;
}

public async Task<bool> InitializeAsync()
{
if (_initialized)
{
return true;
}

if (!await _dotnetCli.InitializeAsync())
{
return false;
}

_nugetPackageName = $"{AspireDashboard.SdkName}.{PlatformHelper.Rid()}";
_runnerFolder = Path.Combine(_dotnetCli.DataPath, AspireDashboard.DataFolder);

if (!Directory.Exists(_runnerFolder))
{
Directory.CreateDirectory(_runnerFolder);
}

return _initialized = true;
}

public async Task<AspireDashboard> GetDashboardAsync(AspireDashboardOptions options, ILogger<AspireDashboard>? logger = null)
{
if (!_initialized)
{
throw new InvalidOperationException($"{nameof(AspireDashboardManager)} must be initialized before calling this method.");
}

var installedRuntimes = (await _dotnetCli.GetInstalledRuntimesAsync())
.Where(r => r.Name is AspireDashboard.AspRuntimeName && r.Version >= AspireDashboard.MinimumRuntimeVersion)
.Select(r => r.Version)
Expand All @@ -62,8 +41,7 @@ public async Task<AspireDashboard> GetDashboardAsync(AspireDashboardOptions opti
throw new ApplicationException($"The dashboard requires version '{AspireDashboard.MinimumRuntimeVersion}' or newer of the '{AspireDashboard.AspRuntimeName}' runtime");
}

var (isInstalled, isWorkload) = await IsInstalledAsync();
if (!isInstalled)
if (!IsInstalled())
{
if (!options.Runner.AutoDownload)
{
Expand All @@ -81,14 +59,13 @@ public async Task<AspireDashboard> GetDashboardAsync(AspireDashboardOptions opti

_logger.LogInformation("Successfully downloaded the Aspire Dashboard (version {Version})", downloadedVersion);
}
else if (!isWorkload && options.Runner.AutoDownload)
else if (options.Runner.AutoDownload)
{
// We are using the runner-managed dashboards, so we can try to update
await TryUpdateAsync(installedRuntimes);
}

_logger.LogTrace("Aspire Installation Source: {Source}", isWorkload ? "Workload" : "NuGet");
var installedDashboard = GetLatestInstalledVersion(isWorkload);
var installedDashboard = GetLatestInstalledVersion();
if (installedDashboard == null)
{
throw new ApplicationException("Failed to locate the Aspire Dashboard installation path");
Expand All @@ -100,52 +77,27 @@ public async Task<AspireDashboard> GetDashboardAsync(AspireDashboardOptions opti
return new AspireDashboard(_dotnetCli, version, path, options, logger ?? new NullLogger<AspireDashboard>());
}

public async Task<(bool Installed, bool Workload)> IsInstalledAsync()
public bool IsInstalled()
{
if (!_initialized)
{
throw new InvalidOperationException($"{nameof(AspireDashboardManager)} must be initialized before calling this method.");
}

if (_dotnetCli.SdkPath != null)
{
var workloads = await _dotnetCli.GetInstalledWorkloadsAsync();
if (workloads.Contains(AspireDashboard.WorkloadId))
{
return (true, true);
}
}

var downloadsFolder = Path.Combine(_runnerFolder, AspireDashboard.DownloadFolder);
return (
Installed: Directory.Exists(downloadsFolder) && Directory.EnumerateDirectories(downloadsFolder, "*.*").Any(),
Workload: false
);
return Directory.Exists(downloadsFolder) && Directory.EnumerateDirectories(downloadsFolder, "*.*").Any();
}

public async Task<Version?> InstallAsync(Version[] installedRuntimes, Version? version = null)
{
if (!_initialized)
{
throw new InvalidOperationException($"{nameof(AspireDashboardManager)} must be initialized before calling this method.");
}

if (version == null)
{
version = await FetchLatestVersionAsync(installedRuntimes);
}

var downloadSucceesful = await _nugetHelper.DownloadPackageAsync(_nugetPackageName, version, Path.Combine(_runnerFolder, AspireDashboard.DownloadFolder, version.ToString()));
var downloadSucceesful =
await _nugetHelper.DownloadPackageAsync(_nugetPackageName, version, Path.Combine(_runnerFolder, AspireDashboard.DownloadFolder, version.ToString()));

return downloadSucceesful ? version : null;
}

public async Task TryUpdateAsync(Version[] installedRuntimes, Version? preferredVersion = null)
{
if (!_initialized)
{
throw new InvalidOperationException($"{nameof(AspireDashboardManager)} must be initialized before calling this method.");
}

try
{
var availableVersions = await _nugetHelper.GetPackageVersionsAsync(_nugetPackageName);
Expand Down Expand Up @@ -195,16 +147,11 @@ public async Task TryUpdateAsync(Version[] installedRuntimes, Version? preferred
}
}

private (Version Version, string Path)? GetLatestInstalledVersion(bool workload)
private (Version Version, string Path)? GetLatestInstalledVersion()
{
var dashboardsFolder = Path.Combine(_runnerFolder, AspireDashboard.DownloadFolder);
try
{
var dashboardsFolder = workload ?
_dotnetCli.GetPacksFolders()
.SelectMany(Directory.GetDirectories)
.First(dir => dir.Contains(AspireDashboard.SdkName))
: Path.Combine(_runnerFolder, AspireDashboard.DownloadFolder);

var installedVersions = Directory.GetDirectories(dashboardsFolder)
.Select(d =>
{
Expand Down
37 changes: 0 additions & 37 deletions src/AspireRunner.Core/Helpers/DotnetCli.Regex.cs

This file was deleted.

Loading

0 comments on commit 571520f

Please sign in to comment.