Skip to content

Commit

Permalink
validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JFriel committed Aug 9, 2024
1 parent fcb6d25 commit 6872af4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Rdmp.Core/CommandLine/Runners/ExtractionRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ExtractionRunner : ManyRunner
private object _oLock = new();
public Dictionary<ISelectedDataSets, ExtractCommand> ExtractCommands { get; private set; }

public ExtractionRunner(IBasicActivateItems activator, ExtractionOptions extractionOpts) : base(activator,extractionOpts)
public ExtractionRunner(IBasicActivateItems activator, ExtractionOptions extractionOpts) : base(extractionOpts)
{
_options = extractionOpts;
_activator = activator;
Expand Down
10 changes: 1 addition & 9 deletions Rdmp.Core/CommandLine/Runners/ManyRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace Rdmp.Core.CommandLine.Runners;
public abstract class ManyRunner : Runner
{
private readonly ConcurrentRDMPCommandLineOptions _options;
private readonly IBasicActivateItems _activator;

protected IRDMPPlatformRepositoryServiceLocator RepositoryLocator { get; private set; }
protected GracefulCancellationToken Token { get; private set; }
Expand All @@ -37,9 +36,8 @@ public abstract class ManyRunner : Runner
/// </summary>
private readonly object _oLock = new();

protected ManyRunner(IBasicActivateItems activator, ConcurrentRDMPCommandLineOptions options)
protected ManyRunner(ConcurrentRDMPCommandLineOptions options)
{
_activator = activator;
_options = options;
}

Expand Down Expand Up @@ -94,12 +92,6 @@ public override int Run(IRDMPPlatformRepositoryServiceLocator repositoryLocator,
foreach (var checkable in checkables)
{
semaphore?.WaitOne();
if(checkable is IDataFlowPipelineEngine)
{
if (((IDataFlowPipelineEngine)checkable).DestinationObject is IInteractiveCheckable){
((IInteractiveCheckable)(((IDataFlowPipelineEngine)checkable).DestinationObject)).SetActivator(_activator);
}
}
var checkable1 = checkable;
var memory = new ToMemoryCheckNotifier(checkNotifier);

Expand Down
9 changes: 7 additions & 2 deletions Rdmp.Core/CommandLine/Runners/ReleaseRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ namespace Rdmp.Core.CommandLine.Runners;
public class ReleaseRunner : ManyRunner
{
private readonly ReleaseOptions _options;
private readonly IBasicActivateItems _activator;
private Pipeline _pipeline;
private IProject _project;
private IExtractionConfiguration[] _configurations;
private ISelectedDataSets[] _selectedDatasets;

public ReleaseRunner(IBasicActivateItems activator, ReleaseOptions options) : base(activator, options)
public ReleaseRunner(IBasicActivateItems activator, ReleaseOptions options) : base(options)
{
_activator = activator;
_options = options;
}

Expand Down Expand Up @@ -118,9 +120,12 @@ protected override ICheckable[] GetCheckables(ICheckNotifier checkNotifier)
if (useCase != null)
{
var engine = useCase.GetEngine(_pipeline, ThrowImmediatelyDataLoadEventListener.Quiet);
if (((IDataFlowPipelineEngine)engine).DestinationObject is IInteractiveCheckable)
{
((IInteractiveCheckable)(((IDataFlowPipelineEngine)engine).DestinationObject)).SetActivator(_activator);
}
toReturn.Add(engine);
}

return toReturn.ToArray();
}

Expand Down
59 changes: 54 additions & 5 deletions Rdmp.Core/DataExport/DataRelease/AWSS3BucketReleaseDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.IO;
using Rdmp.Core.DataExport.DataExtraction;
using Rdmp.Core.DataExport.DataRelease.Audit;
using NPOI.HPSF;

namespace Rdmp.Core.DataExport.DataRelease;

Expand Down Expand Up @@ -67,13 +68,57 @@ public void Abort(IDataLoadEventListener listener)

}

private void StoreInteractiveConfig(string value, string fileName)
{
var file = Path.Combine(Path.GetTempPath(), fileName);
if (File.Exists(file))
{
File.Delete(file);
}
using (StreamWriter outputFile = new StreamWriter(file))
{
outputFile.Write(value);
}
}


private void RetrieveInteractiveConfiguration()
{
var file = Path.Combine(Path.GetTempPath(), "RDMP_AWS_REGION.txt");
if (File.Exists(file))
{
AWS_Region = File.ReadAllText(file);
File.Delete(file);
}
file = Path.Combine(Path.GetTempPath(), "RDMP_AWS_PROFILE.txt");
if (File.Exists(file))
{
AWS_Profile = File.ReadAllText(file);
File.Delete(file);
}
file = Path.Combine(Path.GetTempPath(), "RDMP_AWS_BUCKET_NAME.txt");
if (File.Exists(file))
{
BucketName = File.ReadAllText(file);
File.Delete(file);
}
file = Path.Combine(Path.GetTempPath(), "RDMP_AWS_BUCKET_FOLDER.txt");
if (File.Exists(file))
{
BucketFolder = File.ReadAllText(file);
File.Delete(file);
}
}

public void Check(ICheckNotifier notifier)
{
((ICheckable)ReleaseSettings).Check(notifier);
if (ConfigureInteractivelyOnRelease && _activator is not null && _activator.IsInteractive)
{
_activator.TypeText("Set AWS Region", "What AWS region is your bucket in?", 128, AWS_Region, out var newRegion, false);
AWS_Region = newRegion;
StoreInteractiveConfig(AWS_Region, "RDMP_AWS_REGION.txt");

}
if (string.IsNullOrWhiteSpace(AWS_Region))
{
Expand All @@ -85,18 +130,23 @@ public void Check(ICheckNotifier notifier)
{
_activator.TypeText("Set AWS Profile", "What AWS profile do you want to use?", 128, AWS_Profile, out var newProfile, false);
AWS_Profile = newProfile;
StoreInteractiveConfig(AWS_Profile, "RDMP_AWS_PROFILE.txt");

}
if (string.IsNullOrWhiteSpace(AWS_Profile))
{
notifier.OnCheckPerformed(new CheckEventArgs("No AWS Profile Specified.", CheckResult.Fail));
return;
}


_s3Helper = new AWSS3(AWS_Profile, _region);

if (ConfigureInteractivelyOnRelease && _activator is not null && _activator.IsInteractive)
{
_activator.TypeText("Set S3 Bucket", "What S3 Bucket do you want to use?", 128, BucketName, out var newBucket, false);
BucketName = newBucket;
StoreInteractiveConfig(BucketName, "RDMP_AWS_BUCKET_NAME.txt");
}

try
Expand All @@ -105,21 +155,21 @@ public void Check(ICheckNotifier notifier)
}
catch (Exception e)
{
notifier.OnCheckPerformed(new CheckEventArgs(e.Message, CheckResult.Fail));
notifier.OnCheckPerformed(new CheckEventArgs("Unable to locate bucket", CheckResult.Fail, e));
return;
}
if (ConfigureInteractivelyOnRelease && _activator is not null && _activator.IsInteractive)
{
_activator.TypeText("Set Subdirectory", "What is the name of the subfolder you want to use?", 128, BucketFolder, out var newFolder, false);
BucketFolder = newFolder;
StoreInteractiveConfig(BucketFolder, "RDMP_AWS_BUCKET_FOLDER.txt");

}
if (_s3Helper.DoesObjectExists(!string.IsNullOrWhiteSpace(BucketFolder) ? $"{BucketFolder}/contents.txt" : "contents.txt", _bucket.BucketName).Result)
{
notifier.OnCheckPerformed(new CheckEventArgs("Bucket Folder Already exists", CheckResult.Fail));
return;
}


}

public void Dispose(IDataLoadEventListener listener, Exception pipelineFailureExceptionIfAny)
Expand Down Expand Up @@ -182,6 +232,7 @@ public ReleaseAudit ProcessPipelineData(ReleaseAudit releaseAudit, IDataLoadEven
{
if (releaseAudit == null)
return null;
RetrieveInteractiveConfiguration();
_region = RegionEndpoint.GetBySystemName(AWS_Region);
_s3Helper = new AWSS3(AWS_Profile, _region);
_bucket = Task.Run(async () => await _s3Helper.GetBucket(BucketName)).Result;
Expand All @@ -208,8 +259,6 @@ public ReleaseAudit ProcessPipelineData(ReleaseAudit releaseAudit, IDataLoadEven
$"Deleted {recordsDeleted} old CumulativeExtractionResults (That were not included in the final Patch you are preparing)"));

}
_region = RegionEndpoint.GetBySystemName(AWS_Region);
_s3Helper = new AWSS3(AWS_Profile, _region);
_engine = new AWSReleaseEngine(_project, ReleaseSettings, _s3Helper, _bucket, BucketFolder, listener, releaseAudit);
_engine.DoRelease(_releaseData.ConfigurationsForRelease, _releaseData.EnvironmentPotentials,
_releaseData.ReleaseState == ReleaseState.DoingPatch);
Expand Down

0 comments on commit 6872af4

Please sign in to comment.