Skip to content

Commit 080a4a1

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

File tree

4 files changed

+22
-42
lines changed

4 files changed

+22
-42
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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
using System.IO.Compression;
99
using System.Reflection;
1010
using System.Runtime.InteropServices;
11-
using Microsoft.Spark.Interop;
1211

1312
namespace Microsoft.Spark.Utils
1413
{
1514
internal static class AssemblySearchPathResolver
1615
{
1716
internal const string AssemblySearchPathsEnvVarName = "DOTNET_ASSEMBLY_SEARCH_PATHS";
17+
internal const string DotNetApplicationArchiveEnvVarName = "DOTNET_APPLICATION_ARCHIVE";
1818

1919
/// <summary>
2020
/// Returns the paths to search when loading assemblies in the following order of
@@ -58,22 +58,21 @@ internal static string[] GetAssemblySearchPaths()
5858
searchPaths.Add(Directory.GetCurrentDirectory());
5959
searchPaths.Add(AppDomain.CurrentDomain.BaseDirectory);
6060

61-
string archiveName = SparkEnvironment.ConfigurationService.GetApplicationArchiveName();
61+
string archiveName = Environment.GetEnvironmentVariable(
62+
DotNetApplicationArchiveEnvVarName);
6263
if(!string.IsNullOrEmpty(archiveName))
6364
{
64-
string archivePath = Path.Combine(Directory.GetCurrentDirectory(), archiveName);
65-
if (File.Exists(archivePath))
66-
{
67-
string extractedPath = Path.Combine(
68-
Path.GetDirectoryName(archivePath),
65+
string
66+
archivePath = Path.Combine(Directory.GetCurrentDirectory(), archiveName),
67+
extractPath = Path.Combine(Directory.GetCurrentDirectory(),
6968
Path.GetFileNameWithoutExtension(archiveName));
70-
if (!File.Exists(extractedPath))
71-
{
72-
ZipFile.ExtractToDirectory(archivePath, extractedPath);
73-
searchPaths.Add(extractedPath);
74-
}
69+
if (File.Exists(archivePath) && !File.Exists(extractPath))
70+
{
71+
ZipFile.ExtractToDirectory(archivePath, extractPath);
72+
searchPaths.Add(extractPath);
7573
}
7674
}
75+
7776
return searchPaths.ToArray();
7877
}
7978
}

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)