Skip to content

Commit

Permalink
#2 Remove unnecessary driver state.
Browse files Browse the repository at this point in the history
  • Loading branch information
sevensolutions committed Jul 15, 2023
1 parent e003749 commit 196f547
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 50 deletions.
27 changes: 4 additions & 23 deletions src/NomadIIS/Services/Grpc/DriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,14 @@ public override async Task<StartTaskResponse> StartTask ( StartTaskRequest reque

try
{
var state = await handle.RunAsync( _logger, task );

var driverState = MessagePackSerializer.Serialize( state );
await handle.RunAsync( _logger, task );

return new StartTaskResponse()
{
Handle = new TaskHandle()
{
State = TaskState.Running,
Config = task,
DriverState = ByteString.CopyFrom( driverState ),
Version = 1 // Driver State Version
},
Result = StartTaskResponse.Types.Result.Success
Expand Down Expand Up @@ -249,26 +246,10 @@ public override Task<RecoverTaskResponse> RecoverTask ( RecoverTaskRequest reque
{
_logger.LogDebug( nameof( RecoverTask ) );

var driverState = request.Handle.DriverState;
if ( driverState is not null )
{
if ( request.Handle.Version != 1 )
throw new NotSupportedException( $"Unsupported driver state version {request.Handle.Version}." );

// TODOPEI
/*
13:24:09 [] ERR Grpc.AspNetCore.Server.ServerCallHandler: Error when executing service method 'RecoverTask'.
MessagePack.MessagePackSerializationException: Failed to deserialize TaskDriver.Services.IisTaskHandleState value.
---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
*/

var state = MessagePackSerializer.Deserialize<IisTaskHandleState>( driverState.Memory );
var handle = _managementService.CreateHandle( request.TaskId );

var handle = _managementService.CreateHandle( request.TaskId );

if ( handle is not null )
handle.RecoverState( request, state );
}
if ( handle is not null )
handle.RecoverState( request );

return Task.FromResult( new RecoverTaskResponse() );
}
Expand Down
20 changes: 8 additions & 12 deletions src/NomadIIS/Services/IisTaskHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ internal IisTaskHandle ( ManagementService owner, string taskId )

public string TaskId { get; }

public async Task<IisTaskHandleState> RunAsync ( ILogger<DriverService> logger, TaskConfig task )
public async Task RunAsync ( ILogger<DriverService> logger, TaskConfig task )
{
_taskConfig = task;
_startDate = DateTime.UtcNow;

var ports = task.Resources.Ports;

_appPoolName = $"nomad-{Guid.NewGuid():N}";
_appPoolName = GetAppPoolName( task );
_websiteName = _appPoolName;

var config = task.MsgpackDriverConfig.DecodeAsTaskConfig();
Expand Down Expand Up @@ -150,12 +150,6 @@ await _owner.LockAsync( serverManager =>

await SendTaskEventAsync( $"Application started, Name: {_appPoolName}" );

return new IisTaskHandleState()
{
AppPoolName = _appPoolName,
WebsiteName = _websiteName
};

void AddEnvironmentVariable( ConfigurationElementCollection envVarsCollection, string key, string value )
{
if ( !string.IsNullOrEmpty( key ) && !string.IsNullOrEmpty( value ) )
Expand Down Expand Up @@ -214,12 +208,11 @@ public async Task DestroyAsync ( ILogger<DriverService> logger )
await StopAsync( logger );
}

public void RecoverState ( RecoverTaskRequest request, IisTaskHandleState state )
public void RecoverState ( RecoverTaskRequest request )
{
_taskConfig = request.Handle.Config;
_appPoolName = state.AppPoolName;
_websiteName = state.WebsiteName;
_startDate = state.StartDate;
_appPoolName = GetAppPoolName( request.Handle.Config );
_websiteName = _appPoolName;
}

public async Task SignalAsync ( ILogger<DriverService> logger, string signal )
Expand Down Expand Up @@ -352,6 +345,9 @@ public void Dispose ()
_owner.Delete( this );
}

private static string GetAppPoolName ( TaskConfig taskConfig )
=> $"{taskConfig.AllocId}-{taskConfig.Name}";

private ApplicationPool GetApplicationPool ( ServerManager serverManager )
=> FindApplicationPool( serverManager ) ?? throw new KeyNotFoundException( $"No AppPool with name {_appPoolName} found." );
private ApplicationPool? FindApplicationPool ( ServerManager serverManager )
Expand Down
15 changes: 0 additions & 15 deletions src/NomadIIS/Services/IisTaskHandleState.cs

This file was deleted.

0 comments on commit 196f547

Please sign in to comment.