-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathCustomStrValidationLambda.cs
More file actions
90 lines (77 loc) · 3.19 KB
/
CustomStrValidationLambda.cs
File metadata and controls
90 lines (77 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.IO;
using Amazon.Lambda.Core;
using Cloud;
using Cloud.Messages.StrValidation;
using Cloud.Notifications;
using Cloud.Utilities;
using CommandLine.Utilities;
using ErrorHandling;
using ErrorHandling.Exceptions;
using Genome;
using IO;
using Nirvana;
using RepeatExpansions.IO;
using VariantAnnotation.Interface.Providers;
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace CustomStrValidationLambda
{
public class CustomStrValidationLambda
{
public ValidationResult Run(ValidationConfig config, ILambdaContext context)
{
string snsTopicArn = null;
try
{
LogUtilities.UpdateLogger(context.Logger, null);
LogUtilities.LogLambdaInfo(context, CommandLineUtilities.InformationalVersion);
LogUtilities.LogObject("Config", config);
LogUtilities.Log(new[] { LambdaUrlHelper.UrlBaseEnvironmentVariableName, LambdaUtilities.SnsTopicKey });
LambdaUtilities.GarbageCollect();
snsTopicArn = LambdaUtilities.GetEnvironmentVariable(LambdaUtilities.SnsTopicKey);
config.Validate();
GenomeAssembly genomeAssembly = GenomeAssemblyHelper.Convert(config.genomeAssembly);
string nirvanaS3Ref = LambdaUrlHelper.GetRefUrl(genomeAssembly);
var refProvider = ProviderUtilities.GetSequenceProvider(nirvanaS3Ref);
using (var stream = PersistentStreamUtils.GetReadStream(config.customStrUrl))
TryLoadStrFile(stream, genomeAssembly, refProvider);
}
catch (Exception exception)
{
return HandleException(config.id, exception, snsTopicArn);
}
return GetSuccessOutput(config.id);
}
private static void TryLoadStrFile(Stream stream, GenomeAssembly genomeAssembly, ISequenceProvider refProvider)
{
try
{
RepeatExpansionReader.Load(stream, genomeAssembly, refProvider.RefNameToChromosome,
refProvider.RefIndexToChromosome.Count);
}
catch (Exception exception)
{
throw new UserErrorException(exception.Message);
}
}
private static ValidationResult HandleException(string id, Exception exception, string snsTopicArn)
{
Logger.Log(exception);
string snsMessage = SNS.CreateMessage(exception.Message, "exception", exception.StackTrace);
SNS.SendMessage(snsTopicArn, snsMessage);
ErrorCategory errorCategory = ExceptionUtilities.ExceptionToErrorCategory(exception);
var errorMessagePrefix = errorCategory == ErrorCategory.UserError ? "User error" : "Nirvana error";
return new ValidationResult
{
id = id,
status = $"{errorMessagePrefix}: {exception.Message}"
};
}
private static ValidationResult GetSuccessOutput(string id) =>
new ValidationResult
{
id = id,
status = LambdaUtilities.SuccessMessage
};
}
}