Skip to content

Commit

Permalink
Executables
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Sep 12, 2024
1 parent 3d92b24 commit 5c17fb3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 61 deletions.
7 changes: 4 additions & 3 deletions src/Aspire.Dashboard/Components/Pages/Resources.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ private async Task ExecuteResourceCommandAsync(ResourceViewModel resource, Comma
}
}

var resourceName = resource.IsExecutable(allowSubtypes: true)
? resource.DisplayName
: resource.Name;
//var resourceName = resource.IsExecutable(allowSubtypes: true)
// ? resource.DisplayName
// : resource.Name;
var resourceName = resource.Name;

var response = await DashboardClient.ExecuteResourceCommandAsync(resourceName, resource.ResourceType, command, CancellationToken.None);

Expand Down
112 changes: 58 additions & 54 deletions src/Aspire.Hosting/Dcp/ApplicationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,84 +1041,88 @@ private void PrepareProjectExecutables()

var replicas = project.GetReplicaCount();

var ers = ExecutableReplicaSet.Create(GetObjectNameForResource(project), replicas, "dotnet");
var exeSpec = ers.Spec.Template.Spec;
exeSpec.WorkingDirectory = Path.GetDirectoryName(projectMetadata.ProjectPath);
for (var i = 0; i < replicas; i++)
{
var nameSuffix = GetRandomNameSuffix();
var exeName = GetObjectNameForResource(project, nameSuffix);

IAnnotationHolder annotationHolder = ers.Spec.Template;
annotationHolder.Annotate(CustomResource.OtelServiceNameAnnotation, (replicas > 1) ? ers.Metadata.Name : project.Name);
// The OTEL service instance ID annotation will be generated and applied automatically by DCP.
annotationHolder.Annotate(CustomResource.ResourceNameAnnotation, project.Name);
var exeSpec = Executable.Create(exeName, "dotnet");
exeSpec.Spec.WorkingDirectory = Path.GetDirectoryName(projectMetadata.ProjectPath);

SetInitialResourceState(project, annotationHolder);
exeSpec.Annotate(CustomResource.OtelServiceNameAnnotation, project.Name);
exeSpec.Annotate(CustomResource.OtelServiceInstanceIdAnnotation, nameSuffix);
exeSpec.Annotate(CustomResource.ResourceNameAnnotation, project.Name);

var projectLaunchConfiguration = new ProjectLaunchConfiguration();
projectLaunchConfiguration.ProjectPath = projectMetadata.ProjectPath;
SetInitialResourceState(project, exeSpec);

if (!string.IsNullOrEmpty(configuration[DebugSessionPortVar]))
{
exeSpec.ExecutionType = ExecutionType.IDE;
var projectLaunchConfiguration = new ProjectLaunchConfiguration();
projectLaunchConfiguration.ProjectPath = projectMetadata.ProjectPath;

projectLaunchConfiguration.DisableLaunchProfile = project.TryGetLastAnnotation<ExcludeLaunchProfileAnnotation>(out _);
if (!projectLaunchConfiguration.DisableLaunchProfile && project.TryGetLastAnnotation<LaunchProfileAnnotation>(out var lpa))
if (!string.IsNullOrEmpty(configuration[DebugSessionPortVar]))
{
projectLaunchConfiguration.LaunchProfile = lpa.LaunchProfileName;
exeSpec.Spec.ExecutionType = ExecutionType.IDE;

projectLaunchConfiguration.DisableLaunchProfile = project.TryGetLastAnnotation<ExcludeLaunchProfileAnnotation>(out _);
if (!projectLaunchConfiguration.DisableLaunchProfile && project.TryGetLastAnnotation<LaunchProfileAnnotation>(out var lpa))
{
projectLaunchConfiguration.LaunchProfile = lpa.LaunchProfileName;
}
}
}
else
{
exeSpec.ExecutionType = ExecutionType.Process;
if (configuration.GetBool("DOTNET_WATCH") is not true)
else
{
exeSpec.Args = [
"run",
exeSpec.Spec.ExecutionType = ExecutionType.Process;
if (configuration.GetBool("DOTNET_WATCH") is not true)
{
exeSpec.Spec.Args = [
"run",
"--no-build",
"--project",
projectMetadata.ProjectPath,
];
}
else
{
exeSpec.Args = [
"watch",
}
else
{
exeSpec.Spec.Args = [
"watch",
"--non-interactive",
"--no-hot-reload",
"--project",
projectMetadata.ProjectPath
];
}
];
}

if (!string.IsNullOrEmpty(_distributedApplicationOptions.Configuration))
{
exeSpec.Args.AddRange(new [] {"-c", _distributedApplicationOptions.Configuration});
}
if (!string.IsNullOrEmpty(_distributedApplicationOptions.Configuration))
{
exeSpec.Spec.Args.AddRange(new[] { "-c", _distributedApplicationOptions.Configuration });
}

// We pretty much always want to suppress the normal launch profile handling
// because the settings from the profile will override the ambient environment settings, which is not what we want
// (the ambient environment settings for service processes come from the application model
// and should be HIGHER priority than the launch profile settings).
// This means we need to apply the launch profile settings manually--the invocation parameters here,
// and the environment variables/application URLs inside CreateExecutableAsync().
exeSpec.Args.Add("--no-launch-profile");
// We pretty much always want to suppress the normal launch profile handling
// because the settings from the profile will override the ambient environment settings, which is not what we want
// (the ambient environment settings for service processes come from the application model
// and should be HIGHER priority than the launch profile settings).
// This means we need to apply the launch profile settings manually--the invocation parameters here,
// and the environment variables/application URLs inside CreateExecutableAsync().
exeSpec.Spec.Args.Add("--no-launch-profile");

var launchProfile = project.GetEffectiveLaunchProfile()?.LaunchProfile;
if (launchProfile is not null && !string.IsNullOrWhiteSpace(launchProfile.CommandLineArgs))
{
var cmdArgs = CommandLineArgsParser.Parse(launchProfile.CommandLineArgs);
if (cmdArgs.Count > 0)
var launchProfile = project.GetEffectiveLaunchProfile()?.LaunchProfile;
if (launchProfile is not null && !string.IsNullOrWhiteSpace(launchProfile.CommandLineArgs))
{
exeSpec.Args.Add("--");
exeSpec.Args.AddRange(cmdArgs);
var cmdArgs = CommandLineArgsParser.Parse(launchProfile.CommandLineArgs);
if (cmdArgs.Count > 0)
{
exeSpec.Spec.Args.Add("--");
exeSpec.Spec.Args.AddRange(cmdArgs);
}
}
}
}

// We want this annotation even if we are not using IDE execution; see ToSnapshot() for details.
annotationHolder.AnnotateAsObjectList(Executable.LaunchConfigurationsAnnotation, projectLaunchConfiguration);
// We want this annotation even if we are not using IDE execution; see ToSnapshot() for details.
exeSpec.AnnotateAsObjectList(Executable.LaunchConfigurationsAnnotation, projectLaunchConfiguration);

var exeAppResource = new AppResource(project, ers);
AddServicesProducedInfo(project, annotationHolder, exeAppResource);
_appResources.Add(exeAppResource);
var exeAppResource = new AppResource(project, exeSpec);
AddServicesProducedInfo(project, exeSpec, exeAppResource);
_appResources.Add(exeAppResource);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public async Task PublishAsync(HealthReport report, CancellationToken cancellati
// Make sure every annotation is represented as health in the report, and if an entry is missing that means it is unhealthy.
var status = annotations.All(a => report.Entries.TryGetValue(a.Key, out var entry) && entry.Status == HealthStatus.Healthy) ? HealthStatus.Healthy : HealthStatus.Unhealthy;

await resourceNotificationService.PublishUpdateAsync(resource, s => s with
{
HealthStatus = status
}).ConfigureAwait(false);
_ = resourceNotificationService;
await Task.Yield();
//await resourceNotificationService.PublishUpdateAsync(resource, s => s with
//{
// HealthStatus = status
//}).ConfigureAwait(false);
}
}
}
Expand Down

0 comments on commit 5c17fb3

Please sign in to comment.