Skip to content

Commit

Permalink
Source allxfer directory from config (#9)
Browse files Browse the repository at this point in the history
* updating to use configuration for allxfer directory

* Typo
  • Loading branch information
bigtallcampbell authored Jun 26, 2024
1 parent 8d27cfb commit afca5af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/Models/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public PLUG_IN() {

public int FILEMOVER_POLLING_MS { get; set; }
public string LEAVE_SOURCE_FILE_PROPERTY_VALUE { get; set; }
public string ALL_XFER_DIR { get; set; }

public APP_CONFIG() : base() {
FILEMOVER_POLLING_MS = int.Parse(Core.GetConfigSetting("filemoverpollingms").Result);
LEAVE_SOURCE_FILE_PROPERTY_VALUE = Core.GetConfigSetting("leavesourcefilepropertyvalue").Result;
ALL_XFER_DIR = Path.Combine(Core.GetConfigSetting("spacefx_cache").Result, Core.GetConfigSetting("allxferdirectory").Result);
}
}
}
21 changes: 9 additions & 12 deletions src/Services/FileMoverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class FileMoverService : BackgroundService {
private readonly BlockingCollection<MessageFormats.HostServices.Link.LinkResponse> _linkResponseQueue;
private readonly Models.APP_CONFIG _appConfig;
private readonly Core.Client _client;
private string _all_xfer_dir = string.Empty;
private readonly string PLATFORM_MTS_ID = $"platform-{nameof(MessageFormats.Common.PlatformServices.Mts).ToLower()}";
private readonly JsonSerializerOptions jsonOptions = new() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault, PropertyNameCaseInsensitive = true, MaxDepth = 100, WriteIndented = true };
public FileMoverService(ILogger<FileMoverService> logger, IServiceProvider serviceProvider, Utils.PluginDelegates pluginDelegates, Core.Services.PluginLoader pluginLoader, Core.Client client) {
Expand All @@ -21,7 +20,6 @@ public FileMoverService(ILogger<FileMoverService> logger, IServiceProvider servi
_appConfig = new Models.APP_CONFIG();
_linkResponseQueue = new();
_client = client;
_all_xfer_dir = client.GetXFerDirectories().Result.root_directory.Replace("xfer", "allxfer");
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
Expand All @@ -46,17 +44,16 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
linkResponse.LinkRequest.DestinationAppId = linkResponse.LinkRequest.DestinationAppId.ToLower();


string destDirPath = Path.Combine(_all_xfer_dir, linkResponse.LinkRequest.DestinationAppId, "inbox");
string sourceDirPath = Path.Combine(_all_xfer_dir, linkResponse.LinkRequest.RequestHeader.AppId, "outbox");
string destDirPath = Path.Combine(_appConfig.ALL_XFER_DIR, linkResponse.LinkRequest.DestinationAppId, "inbox");
string sourceDirPath = Path.Combine(_appConfig.ALL_XFER_DIR, linkResponse.LinkRequest.RequestHeader.AppId, "outbox");

_logger.LogDebug("Checking if directory exists ('{xfer_directory}/{sourceAppName}') (trackingId: '{trackingId}' / correlationId: '{correlationId}')", _all_xfer_dir, linkResponse.LinkRequest.RequestHeader.AppId, linkResponse.LinkRequest.RequestHeader.TrackingId, linkResponse.LinkRequest.RequestHeader.CorrelationId);
_logger.LogDebug("Checking if directory exists ('{xfer_directory}/{sourceAppName}') (trackingId: '{trackingId}' / correlationId: '{correlationId}')", _appConfig.ALL_XFER_DIR, linkResponse.LinkRequest.RequestHeader.AppId, linkResponse.LinkRequest.RequestHeader.TrackingId, linkResponse.LinkRequest.RequestHeader.CorrelationId);

if (!Directory.Exists(Path.Combine(_all_xfer_dir, linkResponse.LinkRequest.RequestHeader.AppId))) {
_logger.LogError("Received a Link Request with an inaccessibale source path. Source path '{sourcePath}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", Path.Combine(_all_xfer_dir, linkResponse.LinkRequest.RequestHeader.AppId), linkResponse.LinkRequest.RequestHeader.TrackingId, linkResponse.LinkRequest.RequestHeader.CorrelationId);
linkResponse.ResponseHeader.Status = MessageFormats.Common.StatusCodes.NotFound;
linkResponse.ResponseHeader.Message = string.Format($"Link Service can't access '{Path.Combine(_all_xfer_dir, linkResponse.LinkRequest.RequestHeader.AppId)}'. Unable to process LinkRequest.");
await SendResponseToApps(linkResponse);
continue;
if (!Directory.Exists(Path.Combine(_appConfig.ALL_XFER_DIR, linkResponse.LinkRequest.RequestHeader.AppId))) {
_logger.LogInformation("Received a Link Request with an inaccessibale source path. Source path '{sourcePath}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", Path.Combine(_appConfig.ALL_XFER_DIR, linkResponse.LinkRequest.RequestHeader.AppId), linkResponse.LinkRequest.RequestHeader.TrackingId, linkResponse.LinkRequest.RequestHeader.CorrelationId);
System.IO.Directory.CreateDirectory(Path.Combine(_appConfig.ALL_XFER_DIR, linkResponse.LinkRequest.RequestHeader.AppId));
System.IO.Directory.CreateDirectory(Path.Combine(_appConfig.ALL_XFER_DIR, linkResponse.LinkRequest.RequestHeader.AppId, "inbox"));
System.IO.Directory.CreateDirectory(Path.Combine(_appConfig.ALL_XFER_DIR, linkResponse.LinkRequest.RequestHeader.AppId, "outbox"));
}

// Run through checks for valid Subdirectory
Expand Down Expand Up @@ -85,7 +82,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) {

// Check if we have a valid source directory
if (!Directory.Exists(Path.Combine(sourceDirPath, linkResponse.LinkRequest.Subdirectory))) {
_logger.LogError("Received a Link Request with an inaccessibale source path. Source path '{sourcePath}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", Path.Combine(_all_xfer_dir, linkResponse.LinkRequest.RequestHeader.AppId, linkResponse.LinkRequest.Subdirectory), linkResponse.LinkRequest.RequestHeader.TrackingId, linkResponse.LinkRequest.RequestHeader.CorrelationId);
_logger.LogError("Received a Link Request with an inaccessibale source path. Source path '{sourcePath}' (trackingId: '{trackingId}' / correlationId: '{correlationId}')", Path.Combine(_appConfig.ALL_XFER_DIR, linkResponse.LinkRequest.RequestHeader.AppId, linkResponse.LinkRequest.Subdirectory), linkResponse.LinkRequest.RequestHeader.TrackingId, linkResponse.LinkRequest.RequestHeader.CorrelationId);
linkResponse.ResponseHeader.Status = MessageFormats.Common.StatusCodes.NotFound;
linkResponse.ResponseHeader.Message = string.Format($"Link Service can't access '{Path.Combine(sourceDirPath, linkResponse.LinkRequest.Subdirectory)}'; directory doesn't exist.. Unable to process LinkRequest.");
await SendResponseToApps(linkResponse);
Expand Down

0 comments on commit afca5af

Please sign in to comment.