Skip to content

Commit 0658c9b

Browse files
committed
Move EnvVar variable into AssemblyLoader. Add EnvVar to PythonFunction.
1 parent 6f495a1 commit 0658c9b

File tree

4 files changed

+22
-41
lines changed

4 files changed

+22
-41
lines changed

src/csharp/Microsoft.Spark/Services/ConfigurationService.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ internal sealed class ConfigurationService : IConfigurationService
2222
private const string DotnetBackendPortEnvVarName = "DOTNETBACKEND_PORT";
2323
private const int DotnetBackendDebugPort = 5567;
2424

25-
private const string DotNetApplicationArchiveEnvVarName = "DOTNET_APPLICATION_ARCHIVE";
26-
private string _applicationArchive;
27-
2825
private static readonly string s_procBaseFileName = "Microsoft.Spark.Worker";
2926
private static readonly string s_procFileName =
3027
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
@@ -80,26 +77,5 @@ public string GetWorkerExePath()
8077
_workerPath = s_procFileName;
8178
return _workerPath;
8279
}
83-
84-
public string GetApplicationArchiveName()
85-
{
86-
if(_applicationArchive != null)
87-
{
88-
return _applicationArchive;
89-
}
90-
91-
string appArchive = Environment.GetEnvironmentVariable(DotNetApplicationArchiveEnvVarName);
92-
93-
if(!string.IsNullOrEmpty(appArchive))
94-
{
95-
_logger.LogInfo("Application archive variable not set.");
96-
return null;
97-
}
98-
99-
_logger.LogInfo($"Application archive is {appArchive}.");
100-
101-
_applicationArchive = appArchive;
102-
return _applicationArchive;
103-
}
10480
}
10581
}

src/csharp/Microsoft.Spark/Services/IConfigurationService.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,5 @@ internal interface IConfigurationService
1818
/// The full path to the .NET worker executable.
1919
/// </summary>
2020
string GetWorkerExePath();
21-
22-
/// <summary>
23-
/// The name of the Application Archive.
24-
/// </summary>
25-
/// <returns></returns>
26-
string GetApplicationArchiveName();
2721
}
2822
}

src/csharp/Microsoft.Spark/Utils/AssemblyLoader.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Microsoft.Spark.Utils
1515
internal static class AssemblySearchPathResolver
1616
{
1717
internal const string AssemblySearchPathsEnvVarName = "DOTNET_ASSEMBLY_SEARCH_PATHS";
18+
internal const string DotNetApplicationArchiveEnvVarName = "DOTNET_APPLICATION_ARCHIVE";
1819

1920
/// <summary>
2021
/// Returns the paths to search when loading assemblies in the following order of
@@ -58,22 +59,21 @@ internal static string[] GetAssemblySearchPaths()
5859
searchPaths.Add(Directory.GetCurrentDirectory());
5960
searchPaths.Add(AppDomain.CurrentDomain.BaseDirectory);
6061

61-
string archiveName = SparkEnvironment.ConfigurationService.GetApplicationArchiveName();
62+
string archiveName = Environment.GetEnvironmentVariable(
63+
DotNetApplicationArchiveEnvVarName);
6264
if(!string.IsNullOrEmpty(archiveName))
6365
{
64-
string archivePath = Path.Combine(Directory.GetCurrentDirectory(), archiveName);
65-
if (File.Exists(archivePath))
66-
{
67-
string extractedPath = Path.Combine(
68-
Path.GetDirectoryName(archivePath),
66+
string
67+
archivePath = Path.Combine(Directory.GetCurrentDirectory(), archiveName),
68+
extractPath = Path.Combine(Directory.GetCurrentDirectory(),
6969
Path.GetFileNameWithoutExtension(archiveName));
70-
if (!File.Exists(extractedPath))
71-
{
72-
ZipFile.ExtractToDirectory(archivePath, extractedPath);
73-
searchPaths.Add(extractedPath);
74-
}
70+
if (File.Exists(archivePath) && !File.Exists(extractPath))
71+
{
72+
ZipFile.ExtractToDirectory(archivePath, extractPath);
73+
searchPaths.Add(extractPath);
7574
}
7675
}
76+
7777
return searchPaths.ToArray();
7878
}
7979
}

src/csharp/Microsoft.Spark/Utils/UdfUtils.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ private static JvmObjectReference CreateEnvVarsForPythonFunction(IJvmBridge jvm)
177177
assemblySearchPath);
178178
}
179179

180+
string assemblyArchivePath = Environment.GetEnvironmentVariable(
181+
AssemblySearchPathResolver.DotNetApplicationArchiveEnvVarName);
182+
if (!string.IsNullOrEmpty(assemblyArchivePath))
183+
{
184+
jvm.CallNonStaticJavaMethod(
185+
environmentVars,
186+
"put",
187+
AssemblySearchPathResolver.DotNetApplicationArchiveEnvVarName,
188+
assemblyArchivePath);
189+
}
190+
180191
return environmentVars;
181192
}
182193

0 commit comments

Comments
 (0)