Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run local args #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ private static IEnumerable<Assembly> GetETLAssemblies(string path)
}
}

private static IEnumerable<Tuple<Assembly, string>> FindAssemblyAndResource(string etlLibraryPath, string name)
private static IEnumerable<Tuple<Assembly, string>> FindAssemblyAndResource(string etlLibraryFolderPath, string name)
{
foreach (var assembly in GetETLAssemblies(etlLibraryPath))
foreach (var assembly in GetETLAssemblies(etlLibraryFolderPath))
{
foreach (var resourceName in assembly.GetManifestResourceNames())
{
Expand All @@ -46,26 +46,26 @@ private static Resource ReadResource(Assembly assembly, string resourceName)
return new Resource(resourceName.Split('.').TakeLast(2).First(), value);
}

private static Resource GetResource(string etlLibraryPath, string name)
private static Resource GetResource(string etlLibraryFolderPath, string name)
{
Console.WriteLine("GetResource: " + name);

var result = FindAssemblyAndResource(etlLibraryPath, name).FirstOrDefault();
var result = FindAssemblyAndResource(etlLibraryFolderPath, name).FirstOrDefault();
if (result != null)
{
var resource = ReadResource(result.Item1, result.Item2);
if (resource != null)
return resource;
}

throw new KeyNotFoundException($"GetResource | Resource: {name}; LibraryPath: {etlLibraryPath} - not exists");
throw new KeyNotFoundException($"GetResource | Resource: {name}; LibraryPath: {etlLibraryFolderPath} - not exists");
}

private static IEnumerable<Resource> GetResources(string etlLibraryPath, string name)
private static IEnumerable<Resource> GetResources(string etlLibraryFolderPath, string name)
{
Console.WriteLine("GetResources: " + name);

foreach (var ar in FindAssemblyAndResource(etlLibraryPath, name))
foreach (var ar in FindAssemblyAndResource(etlLibraryFolderPath, name))
{
var resource = ReadResource(ar.Item1, ar.Item2);
if (resource != null)
Expand All @@ -82,7 +82,7 @@ private static string NormalizeVendorName(string vendorName)
return result;
}

public static void LoadVendorSettings(string etlLibraryPath, IVendorSettings settings)
public static void LoadVendorSettings(string etlLibraryFolderPath, IVendorSettings settings)
{
Console.WriteLine("LoadVendorSettings | Vendor: " + settings.Vendor);

Expand All @@ -93,26 +93,26 @@ public static void LoadVendorSettings(string etlLibraryPath, IVendorSettings set

settings.SourceQueryDefinitions = [];
settings.CombinedLookupDefinitions = [];
settings.BatchScript ??= EtlLibrary.GetResource(etlLibraryPath, vendorFolder + "." + batch).Value;
settings.BatchScript ??= EtlLibrary.GetResource(etlLibraryFolderPath, vendorFolder + "." + batch).Value;

foreach (var definition in GetResources(etlLibraryPath, vendorFolder + ".Definitions."))
foreach (var definition in GetResources(etlLibraryFolderPath, vendorFolder + ".Definitions."))
{
var qd = new QueryDefinition().DeserializeFromXml(definition.Value);
qd.FileName = definition.Name;
settings.SourceQueryDefinitions.Add(qd);
}

foreach (var lookup in GetResources(etlLibraryPath, vendorFolder + ".CombinedLookups."))
foreach (var lookup in GetResources(etlLibraryFolderPath, vendorFolder + ".CombinedLookups."))
{
var ld = new LookupDefinition().DeserializeFromXml(lookup.Value);
ld.FileName = lookup.Name;
settings.CombinedLookupDefinitions.Add(ld);
}
}

public static Vendor CreateVendorInstance(string etlLibraryPath, string name)
public static Vendor CreateVendorInstance(string etlLibraryFolderPath, string name)
{
foreach (var assembly in GetETLAssemblies(etlLibraryPath))
foreach (var assembly in GetETLAssemblies(etlLibraryFolderPath))
{
var vendorTypes = assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(Vendor)) && !t.IsAbstract);
var vendorType = vendorTypes.FirstOrDefault(a => a.Name.Contains(name, StringComparison.CurrentCultureIgnoreCase));
Expand All @@ -133,12 +133,12 @@ public static Vendor CreateVendorInstance(string etlLibraryPath, string name)
}
}

throw new KeyNotFoundException($"CreateVendorInstance | Vendor: {name}; LibraryPath: {etlLibraryPath} - not exists");
throw new KeyNotFoundException($"CreateVendorInstance | Vendor: {name}; LibraryPath: {etlLibraryFolderPath} - not exists");
}

public static ConstructorInfo GetBuilderConstructor(string etlLibraryPath, Vendor vendor)
public static ConstructorInfo GetBuilderConstructor(string etlLibraryFolderPath, Vendor vendor)
{
foreach (var assembly in GetETLAssemblies(etlLibraryPath))
foreach (var assembly in GetETLAssemblies(etlLibraryFolderPath))
{
var builderTypes = assembly.GetTypes().
Where(t => t.IsSubclassOf(typeof(PersonBuilder)) && !t.IsAbstract);
Expand All @@ -151,7 +151,7 @@ public static ConstructorInfo GetBuilderConstructor(string etlLibraryPath, Vendo
}
}

throw new KeyNotFoundException($"GetBuilderConstructor | Vendor: {vendor}; LibraryPath: {etlLibraryPath} - not exists");
throw new KeyNotFoundException($"GetBuilderConstructor | Vendor: {vendor}; LibraryPath: {etlLibraryFolderPath} - not exists");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private void SetSourceReleaseDate()

private void SetVendorSettings()
{
Console.WriteLine("etlLibraryPath: " + EtlLibraryPath);
Console.WriteLine("etlLibraryFolderPath: " + EtlLibraryPath);
EtlLibrary.LoadVendorSettings(EtlLibraryPath, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int Main(string[] arguments)

IConfigurationRoot configuration = builder.Build();

vendor = EtlLibrary.CreateVendorInstance(configuration.GetSection("AppSettings")["etlLibraryPath"], vendorName);
vendor = EtlLibrary.CreateVendorInstance(configuration.GetSection("AppSettings")["etlLibraryFolderPath"], vendorName);

var builderConnectionString = configuration.GetConnectionString("Builder");

Expand Down Expand Up @@ -178,7 +178,7 @@ static int Main(string[] arguments)
Settings.Current.Building.RawVocabularyConnectionString = vocabularyConnectionString;
Settings.Current.Building.RawDestinationConnectionString = destinationConnectionString;
Settings.Current.Building.Vendor = vendor;
Settings.Current.Building.EtlLibraryPath = configuration.GetSection("AppSettings")["etlLibraryPath"];
Settings.Current.Building.EtlLibraryPath = configuration.GetSection("AppSettings")["etlLibraryFolderPath"];

if (!createNewBuildingId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"cdm_folder_csv": "",
"cdm_folder": "",
"vendor_settings": "",
"etlLibraryPath": "",
"etlLibraryFolderPath": "",

"spectrum_cluster": "",
"spectrum_db": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void Initialize()
}

public async Task<string> FunctionHandler2(string s3AwsAccessKeyId, string s3AwsSecretAccessKey, string bucket, string folder, Vendor vendor, int buildingId, int chunkId, string prefix,
int attempt, string etlLibraryPath)
int attempt, string etlLibraryFolderPath)
{
Dictionary<string, long> restorePoint = null;

Expand All @@ -122,7 +122,7 @@ public async Task<string> FunctionHandler2(string s3AwsAccessKeyId, string s3Aws
return null;
}

EtlLibraryPath = etlLibraryPath;
EtlLibraryPath = etlLibraryFolderPath;

Settings.Current.S3AwsAccessKeyId = s3AwsAccessKeyId;
Settings.Current.S3AwsSecretAccessKey = s3AwsSecretAccessKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class BuildingSettings : IVendorSettings

public string BatchScript { get; set; }

public void SetVendorSettings(string etlLibraryPath)
public void SetVendorSettings(string etlLibraryFolderPath)
{
EtlLibrary.LoadVendorSettings(etlLibraryPath, this);
EtlLibrary.LoadVendorSettings(etlLibraryFolderPath, this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ static Settings()

#region Methods

public static void Initialize(int buildingId, Vendor vendor, string etlLibraryPath)
public static void Initialize(int buildingId, Vendor vendor, string etlLibraryFolderPath)
{
Current.Building = new BuildingSettings { Id = buildingId, Vendor = vendor };
Current.Building.SetVendorSettings(etlLibraryPath);
Current.Building.SetVendorSettings(etlLibraryFolderPath);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion sources/Tests/RunETL/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<add key="BucketName" value="" />
<add key="AwsAccessKeyId" value="" />
<add key="AwsSecretAccessKey" value="" />
<add key="etlLibraryPath" value="" />
<add key="etlLibraryFolderPath" value="" />
</appSettings>
</configuration>
2 changes: 1 addition & 1 deletion sources/Tests/RunETL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void Main(string[] args)
{
chunkscnt = o.ChunksCnt.Value;
slicescnt = o.SlicesCnt.Value;
vendor = EtlLibrary.CreateVendorInstance(ConfigurationManager.AppSettings["etlLibraryPath"], o.Vendor);
vendor = EtlLibrary.CreateVendorInstance(ConfigurationManager.AppSettings["etlLibraryFolderPath"], o.Vendor);
buildingid = o.Buildingid.Value;
});

Expand Down
8 changes: 4 additions & 4 deletions sources/Tests/RunLocal/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ static void Main(string[] args)

Console.WriteLine($"{Directory.GetCurrentDirectory()}");

var etlLibraryPath = "";
Process(EtlLibrary.CreateVendorInstance(etlLibraryPath, args[0]), int.Parse(args[1]), int.Parse(args[2]), args[3], bool.Parse(args[4]), etlLibraryPath);
var vendor = EtlLibrary.CreateVendorInstance(args[5], args[0]);
Process(vendor, int.Parse(args[1]), int.Parse(args[2]), args[3], bool.Parse(args[4]), args[5]);

//int[] slicesNum = [24, 40, 48, 96, 192];

Expand All @@ -40,7 +40,7 @@ static void Main(string[] args)
Console.ReadLine();
}

private static string Process(Vendor vendor, int buildingId, int chunkId, string prefix, bool clean, string etlLibraryPath)
private static string Process(Vendor vendor, int buildingId, int chunkId, string prefix, bool clean, string etlLibraryFolderPath)
{
try
{
Expand Down Expand Up @@ -86,7 +86,7 @@ private static string Process(Vendor vendor, int buildingId, int chunkId, string
var client = new AmazonS3Client(_awsAccessKeyId, _awsSecretAccessKey, config);

var func = new Function(client);
var t = func.FunctionHandler2(_awsAccessKeyId, _awsSecretAccessKey, _bucket, _cdmFolder, vendor, buildingId, chunkId, prefix, 0, etlLibraryPath);
var t = func.FunctionHandler2(_awsAccessKeyId, _awsSecretAccessKey, _bucket, _cdmFolder, vendor, buildingId, chunkId, prefix, 0, etlLibraryFolderPath);
t.Wait();

Console.WriteLine($"chunkId={chunkId};prefix={prefix} - DONE");
Expand Down