Repository: incubator-reef Updated Branches: refs/heads/master e742d7ebc -> 3cac2d4af
[REEF-642]:Remove custom assembly loading logic This addressed the issue by adding a DriverLauncher which invokes java using jni JIRA: [REEF-642](https://issues.apache.org/jira/browse/REEF-642) This closes #475 Author: Beysim Sezgin <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/3cac2d4a Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/3cac2d4a Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/3cac2d4a Branch: refs/heads/master Commit: 3cac2d4af376d38eeb0951fec06c643e23e26b8e Parents: e742d7e Author: Beysim Sezgin <[email protected]> Authored: Wed Sep 9 12:11:38 2015 -0700 Committer: Julia Wang <[email protected]> Committed: Fri Sep 11 15:17:27 2015 -0700 ---------------------------------------------------------------------- .../Org.Apache.REEF.Bridge/DriverLauncher.cpp | 381 +++++++++++++++++++ lang/cs/Org.Apache.REEF.Bridge/InteropUtil.h | 7 +- .../cs/Org.Apache.REEF.Bridge/JavaClrBridge.cpp | 66 ++++ .../Org.Apache.REEF.Bridge.vcxproj | 10 +- .../API/IJobSubmission.cs | 7 + .../API/IJobSubmissionBuilder.cs | 8 + .../Org.Apache.REEF.Client/API/JobSubmission.cs | 21 +- .../API/JobSubmissionBuilder.cs | 16 +- .../Common/DriverFolderPreparationHelper.cs | 54 ++- .../Org.Apache.REEF.Client.csproj | 18 +- .../Files/REEFFileNames.cs | 20 +- .../Bridge/ClrHandlerHelper.cs | 2 +- ...assHierarchyGeneratingDriverStartObserver.cs | 26 +- .../Org.Apache.REEF.Tang/Util/AssemblyLoader.cs | 31 ++ lang/cs/Org.Apache.REEF.sln | Bin 33120 -> 32124 bytes .../apache/reef/bridge/client/LocalClient.java | 12 +- .../bridge/client/YarnJobSubmissionClient.java | 12 +- .../javabridge/AllocatedEvaluatorBridge.java | 11 +- .../org/apache/reef/javabridge/LibLoader.java | 144 ------- .../reef/javabridge/generic/JobDriver.java | 24 +- .../runtime/common/files/REEFFileNames.java | 22 +- .../common/launch/JavaLaunchCommandBuilder.java | 14 + .../parameters/DriverLaunchCommandPrefix.java | 30 ++ .../client/PreparedDriverFolderLauncher.java | 8 +- .../yarn/client/YarnSubmissionHelper.java | 24 +- 25 files changed, 715 insertions(+), 253 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Bridge/DriverLauncher.cpp ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/DriverLauncher.cpp b/lang/cs/Org.Apache.REEF.Bridge/DriverLauncher.cpp new file mode 100644 index 0000000..d458ae4 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/DriverLauncher.cpp @@ -0,0 +1,381 @@ +/** +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +#include "InteropUtil.h" +using namespace std; + +// Function signatuire for creating java vm +typedef jint(JNICALL *JNI_CreateJavaVM_FN)(JavaVM **pvm, void **penv, void *args); + +// The environment variable that points to java directory. +LPCTSTR JAVA_HOME = L"JAVA_HOME"; + +// Where should we try to load jvm dll from? +// Try server version first. Path relative to $(JAVA_HOME) +LPCTSTR JVM_DLL1 = L"\\jre\\bin\\server\\jvm.dll"; + +// If we could not find server jvm, Try client version. +// Path relative to $(JAVA_HOME) +LPCTSTR JVM_DLL2 = L"\\jre\\bin\\client\\jvm.dll"; + +// Name of the function that creates a java VM +const char* JNI_CreateJavaVM_Func_Name = "JNI_CreateJavaVM"; + +// Sometimes classpath is split into 2 arguments. Compensate for it. +const char* JavaOptionClassPath = "-classpath"; + +// JNI signature for Java String. +const char* JavaMainMethodSignature = "([Ljava/lang/String;)V"; + +// class name for NativeInterop +const char* NativeInteropClass = "org/apache/reef/javabridge/NativeInterop"; + +const int maxPathBufSize = 16 * 1024; +const char ClassPathSeparatorCharForWindows = ';'; + +// we look for this to delineate java vm arguments from app arguments. +// todo: be smarter about this. Accomodate arbitrary apps. +const char* launcherClass = "org.apache.reef.runtime.common.REEFLauncher"; + +// method to invoke +const char* JavaMainMethodName = "main"; + +//Prefix for classpath. This is how we tell JNI about the classpath. +const char* JavaClassPath = "-Djava.class.path="; + + +typedef enum { + ErrSuccess = 0, + ErrGetEnvironmentVariable = 1, + ErrLoadLibraryJVM = 2, + ErrGetProcAddress = 3, + ErrCreateJavaVM = 4, + ErrFindClassEntry = 5, + ErrGetStaticMethodID = 6, + ErrFindClassString = 7, + ErrNewObjectArray = 8, +} ErrorEnum; + +// +// figure out where jvm options end, entry class method and its parameters begin +// +void GetCounts( + int cArgs, + char*argv[], + int& optionCount, + int& firstOptionOrdinal, + int& argCount, + int& firstArgOrdinal) +{ + bool option = true; + optionCount = 0; + firstOptionOrdinal = 2; + argCount = 0; + firstArgOrdinal = -1; + + for (int i = firstOptionOrdinal; i < cArgs; i++) { + if (option && 0 == strcmp(argv[i], launcherClass)) { + option = false; + firstArgOrdinal = i; + } + if (option) { + ++optionCount; + } + else { + ++argCount; + } + } +} + +// +// Set JVM option. JNI does not support unicode +// +void SetOption(JavaVMOption *option, char *src) +{ + size_t len = strlen(src) + 1; + char* pszOption = new char[len]; + strcpy_s(pszOption, len, src); + option->optionString = pszOption; + option->extraInfo = nullptr; +} + +// +// Jni does not expand * and *.jar +// We need to do it ourselves. +// +char *ExpandJarPaths(char *jarPaths) +{ + String^ classPathSeparatorStringForWindows = L";"; + const char classPathSeparatorCharForrWindows = ';'; + String^ jarExtension = L".jar"; + String^ anyJarExtension = L"*.jar"; + String^ asterisk = L"*"; + + const int StringBuilderInitalSize = 1024 * 16; + System::Text::StringBuilder^ sb = gcnew System::Text::StringBuilder(StringBuilderInitalSize); + sb->Append(gcnew String(JavaClassPath)); + String^ pathString = gcnew String(jarPaths); + array<String^>^ rawPaths = pathString->Split(classPathSeparatorCharForrWindows); + for (int i = 0; i < rawPaths->Length; i++) + { + String^ oldPath = rawPaths[i]; + int oldPathLength = oldPath->Length; + String^ path; + bool shouldExpand = false; + if (oldPath->EndsWith(asterisk)) + { + path = oldPath + jarExtension; + shouldExpand = true; + } + else if (oldPath->EndsWith(anyJarExtension)) + { + path = oldPath; + shouldExpand = true; + } + else + { + sb->Append(classPathSeparatorStringForWindows); + sb->Append(oldPath); + } + if (shouldExpand) + { + try + { + auto filesDir = System::IO::Path::GetDirectoryName(path); + auto fileName = System::IO::Path::GetFileName(path); + auto directoryInfo = gcnew System::IO::DirectoryInfo(filesDir); + auto files = directoryInfo->GetFiles(fileName); + for (int i = 0; i < files->Length; i++) + { + auto fullName = System::IO::Path::Combine(files[i]->Directory->ToString(), files[i]->ToString()); + sb->Append(classPathSeparatorStringForWindows); + sb->Append(fullName); + } + } + catch (System::IO::DirectoryNotFoundException^) + { + //Ignore invalid paths. + } + } + } + auto newPaths = sb->ToString(); + int len = newPaths->Length; + char* finalPath = new char[len + 1]; + auto hglobal = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(newPaths); + memcpy(finalPath, (void*)hglobal, len + 1); + System::Runtime::InteropServices::Marshal::FreeHGlobal(hglobal); + return finalPath; +} + +JavaVMOption* GetJavaOptions(char *argv[], int& optionCount, int firstOptionOrdinal) +{ + JavaVMOption* options = new JavaVMOption[optionCount + 1]; + char classPathBuf[maxPathBufSize]; + int sourceOrdinal = firstOptionOrdinal; + + for (int i = 0; i < optionCount; i++) { + SetOption(options + i, argv[sourceOrdinal]); + if (0 == strcmp(argv[i + firstOptionOrdinal], JavaOptionClassPath) && ((i + 1) < optionCount)) { + strcpy_s(classPathBuf, argv[++sourceOrdinal]); + for (char* ptr = classPathBuf; *ptr; ptr++) { + if (*ptr == '/') { + *ptr = '\\'; + } + } + strcat_s(classPathBuf, ";local\\*;global\\*"); + auto expandedPath = ExpandJarPaths(classPathBuf); + SetOption(options + i, expandedPath); + --optionCount; + } + ++sourceOrdinal; + } + + return options; +} + +int Get_CreateJavaVM_Function(JNI_CreateJavaVM_FN& fn_JNI_CreateJavaVM) +{ + wchar_t jvmDllPath1[maxPathBufSize]; + wchar_t jvmDllPath2[maxPathBufSize]; + DWORD rc = GetEnvironmentVariable(JAVA_HOME, jvmDllPath1, maxPathBufSize); + if (0 == rc) { + wprintf(L"Could not GetEnvironmentVariable %ls\n", JAVA_HOME); + return ErrGetEnvironmentVariable; + } + + wcscat_s(jvmDllPath1, maxPathBufSize, JVM_DLL1); + + HMODULE jvm_dll = LoadLibrary(jvmDllPath1); + if (jvm_dll == NULL) { + wprintf(L"Could not load dll %ls\n", jvmDllPath1); + GetEnvironmentVariable(JAVA_HOME, jvmDllPath2, maxPathBufSize); + wcscat_s(jvmDllPath2, maxPathBufSize, JVM_DLL2); + jvm_dll = LoadLibrary(jvmDllPath2); + if (jvm_dll == NULL) { + wprintf(L"Could not load dll %ls\n", jvmDllPath2); + return ErrLoadLibraryJVM; + } + } + + fn_JNI_CreateJavaVM = (JNI_CreateJavaVM_FN)GetProcAddress(jvm_dll, JNI_CreateJavaVM_Func_Name); + if (fn_JNI_CreateJavaVM == NULL) { + printf("Could not GetProcAddress %s\n", JNI_CreateJavaVM_Func_Name); + return ErrGetProcAddress; + } + + return ErrSuccess; +} + +// +// Creates Java vm with the given options +// +int CreateJVM(JNIEnv*& env, JavaVM*& jvm, JavaVMOption* options, int optionCount) { + JNI_CreateJavaVM_FN fn_JNI_CreateJavaVM; + int failureCode = 0; + if ((failureCode = Get_CreateJavaVM_Function(fn_JNI_CreateJavaVM)) != ErrSuccess) { + return failureCode; + } + + for (int i = 0; i < optionCount; i++) { + printf("Option %d [%s]\n", i, options[i].optionString); + } + fflush(stdout); + JavaVMInitArgs vm_args; + memset(&vm_args, 0, sizeof(vm_args)); + vm_args.version = JNI_VERSION_1_6; + vm_args.nOptions = optionCount; + vm_args.options = options; + vm_args.ignoreUnrecognized = JNI_FALSE; + long status = fn_JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); + if (status) { + printf("Could not fn_JNI_CreateJavaVM\n"); + return ErrCreateJavaVM; + } + return ErrSuccess; +} + +// +// Invokes main method of entry class. +// I.E. org/apache/reef/runtime/common/REEFLauncher +// +int CallMainMethodOfEntryClass( + JNIEnv* env, + char* argv[], + int firstArgOrdinal, + int argCount) +{ + // int the entry class name, Replace '.' with '/' + char classBuf[maxPathBufSize]; + strcpy_s(classBuf, argv[firstArgOrdinal]); + for (char* ptr = classBuf; *ptr; ptr++) { + if (*ptr == '.') { + *ptr = '/'; + } + } + + // Find the entry class + jclass mainClass = env->FindClass(classBuf); + if (!mainClass) { + printf("Failed to find class '%s'", classBuf); + fflush(stdout); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + } + fflush(stdout); + return ErrFindClassEntry; + } + + // find method 'static void main (String[] args)' + jmethodID mainMethod = env->GetStaticMethodID(mainClass, JavaMainMethodName, JavaMainMethodSignature); + if (!mainMethod) { + printf("Failed to find jmethodID of 'main'"); + return ErrGetStaticMethodID; + } + + // Find string class + jclass stringClass = env->FindClass("java/lang/String"); + if (!stringClass) { + printf("Failed to find java/lang/String"); + return ErrFindClassString; + } + stringClass = reinterpret_cast<jclass>(env->NewGlobalRef(stringClass)); + + // Allocate string[] for main method parameter + jobjectArray args = env->NewObjectArray(argCount - 1, stringClass, 0); + if (!args) { + printf("Failed to create args array"); + return ErrNewObjectArray; + } + args = reinterpret_cast<jobjectArray>(env->NewGlobalRef(args)); + + // Copy parameters for main method + for (int i = 0; i < argCount - 1; ++i) { + env->SetObjectArrayElement(args, i, env->NewStringUTF(argv[firstArgOrdinal + 1 + i])); + } + + // Find the _NativeInterop class + jclass nativeInteropClass = env->FindClass(NativeInteropClass); + if (nativeInteropClass) { + nativeInteropClass = reinterpret_cast<jclass>(env->NewGlobalRef(nativeInteropClass)); + printf("Found class '%s'", NativeInteropClass); + Java_org_apache_reef_javabridge_NativeInterop_registerNatives(env, nativeInteropClass); + } + else { + printf("Did not find class '%s'", NativeInteropClass); + } + fflush(stdout); + + // call main method with parameters + env->CallStaticVoidMethod(mainClass, mainMethod, args); + + return ErrSuccess; +} + +int main(int cArgs, char *argv[]) +{ + int optionCount; + int firstOptionOrdinal; + int argCount; + int firstArgOrdinal; + + GetCounts(cArgs, argv, optionCount, firstOptionOrdinal, argCount, firstArgOrdinal); + JavaVMOption* options = GetJavaOptions(argv, optionCount, firstOptionOrdinal); + + JNIEnv *env; + JavaVM *jvm; + int failureCode = 0; + if ((failureCode = CreateJVM(env, jvm, options, optionCount)) != ErrSuccess) { + fflush(stdout); + return failureCode; + } + + if ((failureCode = CallMainMethodOfEntryClass(env, argv, firstArgOrdinal, argCount)) != ErrSuccess) { + fflush(stdout); + return failureCode; + } + + // Check for errors. + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + } + + // Finally, destroy the JavaVM + jvm->DestroyJavaVM(); + + return 0; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.h ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.h b/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.h index 16aede6..f926eb4 100644 --- a/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.h +++ b/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.h @@ -66,4 +66,9 @@ JNIEnv* RetrieveEnv(JavaVM* jvm); void HandleClr2JavaError( JNIEnv *env, String^ errorMessage, - jobject javaObject); \ No newline at end of file + jobject javaObject); + +extern "C" { + JNIEXPORT void JNICALL + Java_org_apache_reef_javabridge_NativeInterop_registerNatives(JNIEnv *env, jclass cls); +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.cpp ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.cpp b/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.cpp index a90c44c..45b3fcb 100644 --- a/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.cpp +++ b/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.cpp @@ -527,3 +527,69 @@ JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_clrSystemDr ManagedLog::LOGGER->LogError(errorMessage, ex); } } + +static JNINativeMethod methods[] = { + { "loadClrAssembly", "(Ljava/lang/String;)V", (void*)&Java_org_apache_reef_javabridge_NativeInterop_loadClrAssembly }, + + { "clrBufferedLog", "(ILjava/lang/String;)V", (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrBufferedLog }, + + { "callClrSystemOnStartHandler", "(Ljava/lang/String;Ljava/lang/String;Lorg/apache/reef/javabridge/EvaluatorRequestorBridge;)[J", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_callClrSystemOnStartHandler }, + + { "clrSystemAllocatedEvaluatorHandlerOnNext", "(JLorg/apache/reef/javabridge/AllocatedEvaluatorBridge;Lorg/apache/reef/javabridge/InteropLogger;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemAllocatedEvaluatorHandlerOnNext }, + + { "clrSystemActiveContextHandlerOnNext", "(JLorg/apache/reef/javabridge/ActiveContextBridge;Lorg/apache/reef/javabridge/InteropLogger;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemActiveContextHandlerOnNext }, + + { "clrSystemTaskMessageHandlerOnNext", "(J[BLorg/apache/reef/javabridge/TaskMessageBridge;Lorg/apache/reef/javabridge/InteropLogger;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemTaskMessageHandlerOnNext }, + + { "clrSystemFailedTaskHandlerOnNext", "(JLorg/apache/reef/javabridge/FailedTaskBridge;Lorg/apache/reef/javabridge/InteropLogger;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemFailedTaskHandlerOnNext }, + + { "clrSystemHttpServerHandlerOnNext", "(JLorg/apache/reef/javabridge/HttpServerEventBridge;Lorg/apache/reef/javabridge/InteropLogger;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemHttpServerHandlerOnNext }, + + { "clrSystemFailedEvaluatorHandlerOnNext", "(JLorg/apache/reef/javabridge/FailedEvaluatorBridge;Lorg/apache/reef/javabridge/InteropLogger;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemFailedEvaluatorHandlerOnNext }, + + { "clrSystemCompletedTaskHandlerOnNext", "(JLorg/apache/reef/javabridge/CompletedTaskBridge;Lorg/apache/reef/javabridge/InteropLogger;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemCompletedTaskHandlerOnNext }, + + { "clrSystemRunningTaskHandlerOnNext", "(JLorg/apache/reef/javabridge/RunningTaskBridge;Lorg/apache/reef/javabridge/InteropLogger;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemRunningTaskHandlerOnNext }, + + { "clrSystemSuspendedTaskHandlerOnNext", "(JLorg/apache/reef/javabridge/SuspendedTaskBridge;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemSuspendedTaskHandlerOnNext }, + + { "clrSystemCompletedEvaluatorHandlerOnNext", "(JLorg/apache/reef/javabridge/CompletedEvaluatorBridge;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemCompletedEvaluatorHandlerOnNext }, + + { "clrSystemClosedContextHandlerOnNext", "(JLorg/apache/reef/javabridge/ClosedContextBridge;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemClosedContextHandlerOnNext }, + + { "clrSystemFailedContextHandlerOnNext", "(JLorg/apache/reef/javabridge/FailedContextBridge;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemFailedContextHandlerOnNext }, + + { "clrSystemContextMessageHandlerOnNext", "(JLorg/apache/reef/javabridge/ContextMessageBridge;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemContextMessageHandlerOnNext }, + + { "callClrSystemOnRestartHandlerOnNext", "(Ljava/lang/String;Ljava/lang/String;Lorg/apache/reef/javabridge/EvaluatorRequestorBridge;)[J", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_callClrSystemOnRestartHandlerOnNext }, + + { "clrSystemDriverRestartActiveContextHandlerOnNext", "(JLorg/apache/reef/javabridge/ActiveContextBridge;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemDriverRestartActiveContextHandlerOnNext }, + + { "clrSystemDriverRestartRunningTaskHandlerOnNext", "(JLorg/apache/reef/javabridge/RunningTaskBridge;)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemDriverRestartRunningTaskHandlerOnNext }, + + { "clrSystemDriverRestartCompletedHandlerOnNext", "(J)V", + (void*)&Java_org_apache_reef_javabridge_NativeInterop_clrSystemDriverRestartCompletedHandlerOnNext }, +}; + +JNIEXPORT void JNICALL +Java_org_apache_reef_javabridge_NativeInterop_registerNatives(JNIEnv *env, jclass cls) +{ + env->RegisterNatives(cls, methods, sizeof(methods) / sizeof(methods[0])); +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj b/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj index eaaaaf9..961fb1b 100644 --- a/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj +++ b/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj @@ -22,6 +22,7 @@ under the License. <Platform Condition="'$(Platform)' == ''">x64</Platform> <SolutionDir Condition="'$(SolutionDir)' == ''">..</SolutionDir> <RestorePackages>true</RestorePackages> + <ConfigurationType>Application</ConfigurationType> </PropertyGroup> <Import Project="$(SolutionDir)\build.props" /> <ItemGroup Label="ProjectConfigurations"> @@ -42,14 +43,12 @@ under the License. </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> - <ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> <PlatformToolset>v120</PlatformToolset> <CLRSupport>true</CLRSupport> <CharacterSet>Unicode</CharacterSet> </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> - <ConfigurationType>DynamicLibrary</ConfigurationType> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <UseDebugLibraries>false</UseDebugLibraries> <PlatformToolset>v120</PlatformToolset> <CLRSupport>true</CLRSupport> @@ -134,6 +133,7 @@ under the License. <ClCompile Include="CompletedEvaluatorClr2Java.cpp" /> <ClCompile Include="CompletedTaskClr2Java.cpp" /> <ClCompile Include="ContextMessageClr2Java.cpp" /> + <ClCompile Include="DriverLauncher.cpp" /> <ClCompile Include="DriverRestartedClr2Java.cpp" /> <ClCompile Include="DriverRestartCompletedClr2Java.cpp" /> <ClCompile Include="EvaluatorRequestorClr2Java.cpp" /> @@ -175,11 +175,7 @@ under the License. <Project>{a6baa2a7-f52f-4329-884e-1bcf711d6805}</Project> </ProjectReference> </ItemGroup> - <ItemGroup> - <None Include="Org.Apache.REEF.Bridge.nuspec" /> - </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> - <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> </Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Client/API/IJobSubmission.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/API/IJobSubmission.cs b/lang/cs/Org.Apache.REEF.Client/API/IJobSubmission.cs index 08fd91b..55aad55 100644 --- a/lang/cs/Org.Apache.REEF.Client/API/IJobSubmission.cs +++ b/lang/cs/Org.Apache.REEF.Client/API/IJobSubmission.cs @@ -61,5 +61,12 @@ namespace Org.Apache.REEF.Client.API /// The Job's identifier /// </summary> string JobIdentifier { get; } + + /// <summary> + /// Driver config file contents (Org.Apache.REEF.Bridge.exe.config) contents + /// Can be used to redirect assembly versions + /// </summary> + string DriverConfigurationFileContents { get; } + } } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Client/API/IJobSubmissionBuilder.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/API/IJobSubmissionBuilder.cs b/lang/cs/Org.Apache.REEF.Client/API/IJobSubmissionBuilder.cs index af8b51f..ed9c22d 100644 --- a/lang/cs/Org.Apache.REEF.Client/API/IJobSubmissionBuilder.cs +++ b/lang/cs/Org.Apache.REEF.Client/API/IJobSubmissionBuilder.cs @@ -76,5 +76,13 @@ namespace Org.Apache.REEF.Client.API /// Set driver memory in megabytes /// </summary> IJobSubmissionBuilder SetDriverMemory(int driverMemoryInMb); + + /// <summary> + /// Driver config file contents (Org.Apache.REEF.Bridge.exe.config) contents + /// Can be used to redirect assembly versions + /// </summary> + /// <param name="driverConfigurationFileContents">Driver configuration file contents.</param> + /// <returns>IJobSubmissionBuilder</returns> + IJobSubmissionBuilder SetDriverConfigurationFileContents(string driverConfigurationFileContents); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Client/API/JobSubmission.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/API/JobSubmission.cs b/lang/cs/Org.Apache.REEF.Client/API/JobSubmission.cs index da77ece..7c522d8 100644 --- a/lang/cs/Org.Apache.REEF.Client/API/JobSubmission.cs +++ b/lang/cs/Org.Apache.REEF.Client/API/JobSubmission.cs @@ -17,9 +17,7 @@ * under the License. */ -using System; using System.Collections.Generic; -using System.IO; using Org.Apache.REEF.Tang.Interface; namespace Org.Apache.REEF.Client.API @@ -34,8 +32,9 @@ namespace Org.Apache.REEF.Client.API private readonly ISet<string> _globalFiles; private readonly ISet<string> _localAssemblies; private readonly ISet<string> _localFiles; - private int _driverMemory ; - private string _jobIdentifier; + private readonly int _driverMemory; + private readonly string _jobIdentifier; + private readonly string _driverConfigurationFileContents; internal JobSubmission( ISet<IConfiguration> driverConfigurations, @@ -44,7 +43,8 @@ namespace Org.Apache.REEF.Client.API ISet<string> localAssemblies, ISet<string> localFiles, int driverMemory, - string jobIdentifier) + string jobIdentifier, + string driverConfigurationFileContents) { _driverConfigurations = driverConfigurations; _globalAssemblies = globalAssemblies; @@ -53,6 +53,7 @@ namespace Org.Apache.REEF.Client.API _localFiles = localFiles; _driverMemory = driverMemory; _jobIdentifier = jobIdentifier; + _driverConfigurationFileContents = driverConfigurationFileContents; } /// <summary> @@ -98,5 +99,15 @@ namespace Org.Apache.REEF.Client.API get { return _jobIdentifier; } } + /// <summary> + /// Driver config file contents (Org.Apache.REEF.Bridge.exe.config) + /// Can be use to redirect assembly versions + /// </summary> + string IJobSubmission.DriverConfigurationFileContents + { + get { return _driverConfigurationFileContents; } + } + + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Client/API/JobSubmissionBuilder.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/API/JobSubmissionBuilder.cs b/lang/cs/Org.Apache.REEF.Client/API/JobSubmissionBuilder.cs index f56bffd..c681206 100644 --- a/lang/cs/Org.Apache.REEF.Client/API/JobSubmissionBuilder.cs +++ b/lang/cs/Org.Apache.REEF.Client/API/JobSubmissionBuilder.cs @@ -34,6 +34,7 @@ namespace Org.Apache.REEF.Client.API private int _driverMemory = 512; private string _jobIdentifier; private readonly ISet<IConfigurationProvider> _configurationProviders; + private string _driverConfigurationFileContents; internal JobSubmissionBuilder(ISet<IConfigurationProvider> configurationProviders) { @@ -141,6 +142,19 @@ namespace Org.Apache.REEF.Client.API } /// <summary> + /// Driver config file contents (Org.Apache.REEF.Bridge.exe.config) contents + /// Can be use to redirect assembly versions + /// </summary> + /// <param name="driverConfigurationFileContents">Driver configuration file contents.</param> + /// <returns>this</returns> + public IJobSubmissionBuilder SetDriverConfigurationFileContents(string driverConfigurationFileContents) + { + _driverConfigurationFileContents = driverConfigurationFileContents; + return this; + } + + + /// <summary> /// Finds the path to the assembly the given Type was loaded from. /// </summary> /// <param name="type"></param> @@ -163,7 +177,7 @@ namespace Org.Apache.REEF.Client.API } return new JobSubmission(_driverConfigurations, _globalAssemblies, _globalFiles, _localAssemblies, - _localFiles, _driverMemory, _jobIdentifier); + _localFiles, _driverMemory, _jobIdentifier, _driverConfigurationFileContents); } } } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Client/Common/DriverFolderPreparationHelper.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/Common/DriverFolderPreparationHelper.cs b/lang/cs/Org.Apache.REEF.Client/Common/DriverFolderPreparationHelper.cs index 7c9a37f..336685f 100644 --- a/lang/cs/Org.Apache.REEF.Client/Common/DriverFolderPreparationHelper.cs +++ b/lang/cs/Org.Apache.REEF.Client/Common/DriverFolderPreparationHelper.cs @@ -38,13 +38,30 @@ namespace Org.Apache.REEF.Client.Common { private const string DLLFileNameExtension = ".dll"; private const string EXEFileNameExtension = ".exe"; - + private const string BridgeExe = "Org.Apache.REEF.Bridge.exe"; + private const string ClrDriverFullName = "ClrDriverFullName"; + private const string DefaultDriverConfigurationFileContents = + @"<configuration>" + + @" <runtime>" + + @" <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">" + + @" <probing privatePath=""local;global""/>" + + @" </assemblyBinding>" + + @" </runtime>" + + @"</configuration>"; + + // We embed certain binaries in client dll. + // Following items in tuples refer to resource names in Org.Apache.REEF.Client.dll + // The first resource item contains the name of the file + // such as "reef-bridge-java-0.13.0-incubating-SNAPSHOT-shaded.jar". The second resource + // item contains the byte contents for said file. + // Please note that the identifiers below need to be in sync with 2 other files + // 1. $(SolutionDir)\Org.Apache.REEF.Client\Properties\Resources.xml + // 2. $(SolutionDir)\Org.Apache.REEF.Client\Org.Apache.REEF.Client.csproj private readonly static Tuple<string, string>[] clientFileResources = new Tuple<string, string>[] { new Tuple<string, string>("ClientJarFullName", "reef_bridge_client"), new Tuple<string, string>("DriverJarFullName", "reef_bridge_driver"), - // enable with next pull request - // new Tuple<string, string>("ClrDriverFullName", "reef_clrdriver"), + new Tuple<string, string>(ClrDriverFullName, "reef_clrdriver"), }; private static readonly Logger Logger = Logger.GetLogger(typeof(DriverFolderPreparationHelper)); @@ -73,7 +90,7 @@ namespace Org.Apache.REEF.Client.Common Logger.Log(Level.Info, "Preparing Driver filesystem layout in " + driverFolderPath); // Setup the folder structure - CreateDefaultFolderStructure(driverFolderPath); + CreateDefaultFolderStructure(jobSubmission, driverFolderPath); // Add the jobSubmission into that folder structure _fileSets.AddJobFiles(jobSubmission); @@ -112,12 +129,31 @@ namespace Org.Apache.REEF.Client.Common /// <summary> /// Creates the driver folder structure in this given folder as the root /// </summary> - /// <param name="driverFolderPath"></param> - internal void CreateDefaultFolderStructure(string driverFolderPath) + /// <param name="jobSubmission">Job submission information</param> + /// <param name="driverFolderPath">Driver folder path</param> + internal void CreateDefaultFolderStructure(IJobSubmission jobSubmission, string driverFolderPath) { Directory.CreateDirectory(Path.Combine(driverFolderPath, _fileNames.GetReefFolderName())); Directory.CreateDirectory(Path.Combine(driverFolderPath, _fileNames.GetLocalFolderPath())); Directory.CreateDirectory(Path.Combine(driverFolderPath, _fileNames.GetGlobalFolderPath())); + + var resourceHelper = new ResourceHelper(typeof(DriverFolderPreparationHelper).Assembly); + foreach (var fileResources in clientFileResources) + { + var fileName = resourceHelper.GetString(fileResources.Item1); + if (ClrDriverFullName == fileResources.Item1) + { + fileName = Path.Combine(driverFolderPath, _fileNames.GetBridgeExePath()); + } + File.WriteAllBytes(fileName, resourceHelper.GetBytes(fileResources.Item2)); + } + + var config = DefaultDriverConfigurationFileContents; + if (!string.IsNullOrEmpty(jobSubmission.DriverConfigurationFileContents)) + { + config = jobSubmission.DriverConfigurationFileContents; + } + File.WriteAllText(Path.Combine(driverFolderPath, _fileNames.GetBridgeExeConfigPath()), config); } /// <summary> @@ -125,12 +161,6 @@ namespace Org.Apache.REEF.Client.Common /// </summary> private void AddAssemblies() { - var resourceHelper = new ResourceHelper(typeof(DriverFolderPreparationHelper).Assembly); - foreach (var fileResources in clientFileResources) - { - File.WriteAllBytes(resourceHelper.GetString(fileResources.Item1), resourceHelper.GetBytes(fileResources.Item2)); - } - // TODO: Be more precise, e.g. copy the JAR only to the driver. var assemblies = Directory.GetFiles(@".\").Where(IsAssemblyToCopy); _fileSets.AddToGlobalFiles(assemblies); http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj b/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj index 348c7fa..32861e1 100644 --- a/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj +++ b/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj @@ -99,6 +99,10 @@ under the License. <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Bridge\Org.Apache.REEF.Bridge.vcxproj"> <Project>{4e69d40a-26d6-4d4a-b96d-729946c07fe1}</Project> <Name>Org.Apache.REEF.Bridge</Name> + <ReferenceOutputAssembly>false</ReferenceOutputAssembly> + <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies> + <LinkLibraryDependencies>false</LinkLibraryDependencies> + <UseLibraryDependencyInputs>false</UseLibraryDependencyInputs> </ProjectReference> <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Evaluator\Org.Apache.REEF.Evaluator.csproj"> <Project>{1b983182-9c30-464c-948d-f87eb93a8240}</Project> @@ -108,14 +112,6 @@ under the License. <Project>{75503f90-7b82-4762-9997-94b5c68f15db}</Project> <Name>Org.Apache.REEF.Examples</Name> </ProjectReference> - <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.ClrDriver\Org.Apache.REEF.ClrDriver.vcxproj"> - <Project>{0097e4ac-0cc9-450c-bc22-acd5b2d55e70}</Project> - <Name>Org.Apache.REEF.ClrDriver</Name> - <ReferenceOutputAssembly>false</ReferenceOutputAssembly> - <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies> - <LinkLibraryDependencies>false</LinkLibraryDependencies> - <UseLibraryDependencyInputs>false</UseLibraryDependencyInputs> - </ProjectReference> </ItemGroup> <ItemGroup> <EmbeddedResource Include="$(TempResxFile)"> @@ -171,7 +167,7 @@ under the License. var binDir = @"lang\cs\bin\x64"; var resxInputPath = Path.Combine(ProjectFolder, srcDir, "Resources.xml"); var resourceDir = Path.Combine(ProjectFolder, binDir, DebugOrRelease, "Org.Apache.REEF.Bridge.JAR"); - var clrDriverDir = Path.Combine(ProjectFolder, binDir, DebugOrRelease, "Org.Apache.REEF.ClrDriver"); + var clrDriverDir = Path.Combine(ProjectFolder, binDir, DebugOrRelease, "Org.Apache.REEF.Bridge"); var byteArrayType = ";System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"; var jarRest = reefVersion + "-shaded.jar" + byteArrayType; @@ -179,10 +175,10 @@ under the License. dllResources.Add("reef_bridge_client", resourceDir + @"\reef-bridge-client-" + jarRest); dllResources.Add("reef_bridge_driver", resourceDir + @"\reef-bridge-java-" + jarRest); dllResources.Add("evaluator", resourceDir + "Org.Apache.REEF.Evaluator.exe" + byteArrayType); - dllResources.Add("reef_clrdriver", clrDriverDir + @"\Org.Apache.REEF.ClrDriver.exe" + byteArrayType); + dllResources.Add("reef_clrdriver", clrDriverDir + @"\Org.Apache.REEF.Bridge.exe" + byteArrayType); dllResources.Add("ClientJarFullName", "reef-bridge-client-" + reefVersion + "-shaded.jar"); dllResources.Add("DriverJarFullName", "reef-bridge-java-" + reefVersion + "-shaded.jar"); - dllResources.Add("ClrDriverFullName", "Org.Apache.REEF.ClrDriver.exe"); + dllResources.Add("ClrDriverFullName", "Org.Apache.REEF.Bridge.exe"); XElement root = XElement.Load(resxInputPath); var resources = root.Descendants().Where(x => x.Name.LocalName == "data").ToList(); http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Common/Files/REEFFileNames.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Common/Files/REEFFileNames.cs b/lang/cs/Org.Apache.REEF.Common/Files/REEFFileNames.cs index 8e921d2..5316301 100644 --- a/lang/cs/Org.Apache.REEF.Common/Files/REEFFileNames.cs +++ b/lang/cs/Org.Apache.REEF.Common/Files/REEFFileNames.cs @@ -48,7 +48,8 @@ namespace Org.Apache.REEF.Common.Files private const string DRIVER_CONFIGURATION_NAME = "driver.conf"; private const string EVALUATOR_CONFIGURATION_NAME = "evaluator.conf"; private const string CLR_DRIVER_CONFIGURATION_NAME = "clrdriver.conf"; - private const string BRIDGE_DLL_NAME = "Org.Apache.REEF.Bridge.dll"; + private const string BRIDGE_EXE_NAME = "Org.Apache.REEF.Bridge.exe"; + private const string BRIDGE_EXE_CONFIG_NAME = "Org.Apache.REEF.Bridge.exe.config"; [Inject] public REEFFileNames() @@ -211,12 +212,21 @@ namespace Org.Apache.REEF.Common.Files } /// <summary> - /// The name of the Bridge DLL. + /// The path of the Driver Launcher exe. /// </summary> - /// <returns>The name of the Bridge DLL.</returns> - public string GetBridgeDLLName() + /// <returns>path of the Driver Launcher EXE.</returns> + public string GetBridgeExePath() { - return BRIDGE_DLL_NAME; + return Path.Combine(REEF_BASE_FOLDER, BRIDGE_EXE_NAME); + } + + /// <summary> + /// The path of the Driver Launcher exe config . + /// </summary> + /// <returns>path of the Driver Launcher exe config.</returns> + public string GetBridgeExeConfigPath() + { + return Path.Combine(REEF_BASE_FOLDER, BRIDGE_EXE_CONFIG_NAME); } private static readonly string GLOBAL_FOLDER_PATH = Path.Combine(REEF_BASE_FOLDER, GLOBAL_FOLDER); http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrHandlerHelper.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrHandlerHelper.cs b/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrHandlerHelper.cs index 7524d97..a13a445 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrHandlerHelper.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrHandlerHelper.cs @@ -41,7 +41,7 @@ namespace Org.Apache.REEF.Driver.Bridge { get { - return new[] { "Microsoft.Hadoop.Avro.dll", "Org.Apache.REEF.Driver.dll", "Org.Apache.REEF.Common.dll", "Org.Apache.REEF.Utilities.dll", "Org.Apache.REEF.Network.dll", "Org.Apache.REEF.Tang.dll", "Org.Apache.REEF.Wake.dll", "Org.Apache.REEF.Bridge.dll", "Newtonsoft.Json.dll", "protobuf-net.dll" }; + return new[] { "Microsoft.Hadoop.Avro.dll", "Org.Apache.REEF.Driver.dll", "Org.Apache.REEF.Common.dll", "Org.Apache.REEF.Utilities.dll", "Org.Apache.REEF.Network.dll", "Org.Apache.REEF.Tang.dll", "Org.Apache.REEF.Wake.dll", "Newtonsoft.Json.dll", "protobuf-net.dll" }; } } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Driver/ClassHierarchyGeneratingDriverStartObserver.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/ClassHierarchyGeneratingDriverStartObserver.cs b/lang/cs/Org.Apache.REEF.Driver/ClassHierarchyGeneratingDriverStartObserver.cs index 5578e18..3efcfbf 100644 --- a/lang/cs/Org.Apache.REEF.Driver/ClassHierarchyGeneratingDriverStartObserver.cs +++ b/lang/cs/Org.Apache.REEF.Driver/ClassHierarchyGeneratingDriverStartObserver.cs @@ -110,32 +110,8 @@ namespace Org.Apache.REEF.Driver .Where(e => !(string.IsNullOrWhiteSpace(e))) .Select(Path.GetFullPath) .Where(File.Exists) - .Where(IsAssembly) + .Where(Org.Apache.REEF.Tang.Util.AssemblyLoader.IsAssembly) .Select(Path.GetFileNameWithoutExtension)); } - - [DllImport("Org.Apache.REEF.Bridge.dll", CharSet = CharSet.Unicode, SetLastError = true)] - static extern int IsManagedBinary(string lpFileName); - - private enum BinaryType - { - None = 0, - Native = 1, - Clr = 2 - }; - - /// <summary> - /// </summary> - /// <param name="path"></param> - /// <returns>True, if the path given is an assembly</returns> - private static Boolean IsAssembly(string path) - { - if (string.IsNullOrWhiteSpace(path)) - { - return false; - } - var extension = Path.GetExtension(path).ToLower(); - return (extension == ".dll" || extension == ".exe") && (BinaryType.Clr == ((BinaryType)IsManagedBinary(path))); - } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.Tang/Util/AssemblyLoader.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Util/AssemblyLoader.cs b/lang/cs/Org.Apache.REEF.Tang/Util/AssemblyLoader.cs index 18984dd..238914f 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Util/AssemblyLoader.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Util/AssemblyLoader.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Reflection; using Org.Apache.REEF.Utilities.Logging; @@ -67,5 +68,35 @@ namespace Org.Apache.REEF.Tang.Util } return t; } + + /// <summary> + /// </summary> + /// <param name="path"></param> + /// <returns>True, if the path given is an assembly</returns> + public static Boolean IsAssembly(string path) + { + if (string.IsNullOrWhiteSpace(path) || Path.GetExtension(path).ToLower() != ".dll") + { + return false; + } + + try + { + var assembly = System.Reflection.AssemblyName.GetAssemblyName(path); + return true; + } + catch (System.IO.FileNotFoundException) + { + return false; + } + catch (System.BadImageFormatException) + { + return false; + } + catch (System.IO.FileLoadException) + { + return true; + } + } } } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/cs/Org.Apache.REEF.sln ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.sln b/lang/cs/Org.Apache.REEF.sln index 409cbf4..2691796 100644 Binary files a/lang/cs/Org.Apache.REEF.sln and b/lang/cs/Org.Apache.REEF.sln differ http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/java/reef-bridge-client/src/main/java/org/apache/reef/bridge/client/LocalClient.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-bridge-client/src/main/java/org/apache/reef/bridge/client/LocalClient.java b/lang/java/reef-bridge-client/src/main/java/org/apache/reef/bridge/client/LocalClient.java index 0a508b4..c66c6cd 100644 --- a/lang/java/reef-bridge-client/src/main/java/org/apache/reef/bridge/client/LocalClient.java +++ b/lang/java/reef-bridge-client/src/main/java/org/apache/reef/bridge/client/LocalClient.java @@ -22,6 +22,7 @@ import org.apache.reef.client.parameters.DriverConfigurationProviders; import org.apache.reef.io.TcpPortConfigurationProvider; import org.apache.reef.runtime.common.driver.parameters.ClientRemoteIdentifier; import org.apache.reef.runtime.common.files.REEFFileNames; +import org.apache.reef.runtime.common.launch.parameters.DriverLaunchCommandPrefix; import org.apache.reef.runtime.local.client.DriverConfigurationProvider; import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration; import org.apache.reef.runtime.local.client.PreparedDriverFolderLauncher; @@ -36,6 +37,7 @@ import org.apache.reef.wake.remote.ports.parameters.TcpPortRangeTryCount; import javax.inject.Inject; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Set; /** @@ -106,8 +108,8 @@ public class LocalClient { final int tcpTryCount = Integer.valueOf(args[5]); - final Configuration runtimeConfiguration = getRuntimeConfiguration(numberOfEvaluators, runtimeRootFolder, - tcpBeginPort, tcpRangeCount, tcpTryCount); + final Configuration runtimeConfiguration = getRuntimeConfiguration(new File(args[0]), numberOfEvaluators, + runtimeRootFolder, tcpBeginPort, tcpRangeCount, tcpTryCount); final LocalClient client = Tang.Factory.getTang() .newInjector(runtimeConfiguration) @@ -117,17 +119,23 @@ public class LocalClient { } private static Configuration getRuntimeConfiguration( + final File jobFolder, final int numberOfEvaluators, final String runtimeRootFolder, final int tcpBeginPort, final int tcpRangeCount, final int tcpTryCount) { final Configuration runtimeConfiguration = getRuntimeConfiguration(numberOfEvaluators, runtimeRootFolder); + ArrayList<String> driverLaunchCommandPrefixList = new ArrayList<String>(); + String path = new File(jobFolder, new REEFFileNames().getDriverLauncherExeFile().toString()).toString(); + + driverLaunchCommandPrefixList.add(path); final Configuration userproviderConfiguration = Tang.Factory.getTang().newConfigurationBuilder() .bindSetEntry(DriverConfigurationProviders.class, TcpPortConfigurationProvider.class) .bindNamedParameter(TcpPortRangeBegin.class, Integer.toString(tcpBeginPort)) .bindNamedParameter(TcpPortRangeCount.class, Integer.toString(tcpRangeCount)) .bindNamedParameter(TcpPortRangeTryCount.class, Integer.toString(tcpTryCount)) + .bindList(DriverLaunchCommandPrefix.class, driverLaunchCommandPrefixList) .build(); return Configurations.merge(runtimeConfiguration, userproviderConfiguration); } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/java/reef-bridge-client/src/main/java/org/apache/reef/bridge/client/YarnJobSubmissionClient.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-bridge-client/src/main/java/org/apache/reef/bridge/client/YarnJobSubmissionClient.java b/lang/java/reef-bridge-client/src/main/java/org/apache/reef/bridge/client/YarnJobSubmissionClient.java index a2cfad0..4ebda31 100644 --- a/lang/java/reef-bridge-client/src/main/java/org/apache/reef/bridge/client/YarnJobSubmissionClient.java +++ b/lang/java/reef-bridge-client/src/main/java/org/apache/reef/bridge/client/YarnJobSubmissionClient.java @@ -30,6 +30,7 @@ import org.apache.reef.javabridge.generic.JobDriver; import org.apache.reef.runtime.common.driver.parameters.ClientRemoteIdentifier; import org.apache.reef.runtime.common.files.ClasspathProvider; import org.apache.reef.runtime.common.files.REEFFileNames; +import org.apache.reef.runtime.common.launch.parameters.DriverLaunchCommandPrefix; import org.apache.reef.runtime.yarn.client.SecurityTokenProvider; import org.apache.reef.runtime.yarn.client.YarnClientConfiguration; import org.apache.reef.runtime.yarn.client.YarnSubmissionHelper; @@ -52,6 +53,8 @@ import javax.inject.Inject; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -70,6 +73,7 @@ public final class YarnJobSubmissionClient { private final int maxApplicationSubmissions; private final int driverRestartEvaluatorRecoverySeconds; private final SecurityTokenProvider tokenProvider; + private final List<String> commandPrefixList; @Inject YarnJobSubmissionClient(final JobUploader uploader, @@ -79,6 +83,7 @@ public final class YarnJobSubmissionClient { final ClasspathProvider classpath, @Parameter(MaxApplicationSubmissions.class) final int maxApplicationSubmissions, + @Parameter(DriverLaunchCommandPrefix.class) final List<String> commandPrefixList, @Parameter(SubmissionDriverRestartEvaluatorRecoverySeconds.class) final int driverRestartEvaluatorRecoverySeconds, final SecurityTokenProvider tokenProvider) { @@ -90,6 +95,7 @@ public final class YarnJobSubmissionClient { this.maxApplicationSubmissions = maxApplicationSubmissions; this.driverRestartEvaluatorRecoverySeconds = driverRestartEvaluatorRecoverySeconds; this.tokenProvider = tokenProvider; + this.commandPrefixList = commandPrefixList; } private Configuration addYarnDriverConfiguration(final File driverFolder, @@ -177,7 +183,7 @@ public final class YarnJobSubmissionClient { // ------------------------------------------------------------------------ // Get an application ID try (final YarnSubmissionHelper submissionHelper = - new YarnSubmissionHelper(yarnConfiguration, fileNames, classpath, tokenProvider)) { + new YarnSubmissionHelper(yarnConfiguration, fileNames, classpath, tokenProvider, commandPrefixList)) { // ------------------------------------------------------------------------ @@ -230,10 +236,14 @@ public final class YarnJobSubmissionClient { .bindNamedParameter(TcpPortRangeTryCount.class, Integer.toString(tcpTryCount)) .build(); + ArrayList<String> driverLaunchCommandPrefixList = new ArrayList<String>(); + driverLaunchCommandPrefixList.add(new REEFFileNames().getDriverLauncherExeFile().toString()); + final Configuration yarnJobSubmissionClientParamsConfig = Tang.Factory.getTang().newConfigurationBuilder() .bindNamedParameter(SubmissionDriverRestartEvaluatorRecoverySeconds.class, Integer.toString(driverRecoveryTimeout)) .bindNamedParameter(MaxApplicationSubmissions.class, Integer.toString(maxApplicationSubmissions)) + .bindList(DriverLaunchCommandPrefix.class, driverLaunchCommandPrefixList) .build(); return Configurations.merge(yarnClientConfig, providerConfig, yarnJobSubmissionClientParamsConfig); http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/AllocatedEvaluatorBridge.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/AllocatedEvaluatorBridge.java b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/AllocatedEvaluatorBridge.java index 482cd16..d390515 100644 --- a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/AllocatedEvaluatorBridge.java +++ b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/AllocatedEvaluatorBridge.java @@ -18,6 +18,7 @@ */ package org.apache.reef.javabridge; +import org.apache.reef.io.naming.Identifiable; import org.apache.reef.runtime.common.driver.evaluator.AllocatedEvaluatorImpl; import org.apache.reef.driver.evaluator.AllocatedEvaluator; import org.apache.reef.tang.ClassHierarchy; @@ -30,7 +31,7 @@ import java.util.logging.Logger; /** * The AllocatedEvaluatorBridge object to bridge operations between REEF .NET and Java allocated evaluator operations. */ -public final class AllocatedEvaluatorBridge extends NativeBridge { +public final class AllocatedEvaluatorBridge extends NativeBridge implements Identifiable { private static final Logger LOG = Logger.getLogger(AllocatedEvaluatorBridge.class.getName()); @@ -180,6 +181,14 @@ public final class AllocatedEvaluatorBridge extends NativeBridge { } /** + * @return the evaluator id. + */ + @Override + public String getId() { + return evaluatorId; + } + + /** * Closes the Java AllocatedEvaluator. */ @Override http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/LibLoader.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/LibLoader.java b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/LibLoader.java deleted file mode 100644 index 5ec69c4..0000000 --- a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/LibLoader.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.reef.javabridge; - -import org.apache.reef.runtime.common.files.REEFFileNames; -import org.apache.reef.util.logging.LoggingScope; -import org.apache.reef.util.logging.LoggingScopeFactory; - -import javax.inject.Inject; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FilenameFilter; -import java.io.IOException; -import java.util.Date; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Loading CLR libraries. - */ -public final class LibLoader { - - private static final Logger LOG = Logger.getLogger(LibLoader.class.getName()); - - private static final String DLL_EXTENSION = ".dll"; - - private final LoggingScopeFactory loggingScopeFactory; - - private final REEFFileNames reefFileNames; - - @Inject - private LibLoader(final LoggingScopeFactory loggingScopeFactory, final REEFFileNames reefFileNames) { - this.loggingScopeFactory = loggingScopeFactory; - this.reefFileNames = reefFileNames; - } - - /** - * Load CLR libraries. - */ - public void loadLib() throws IOException { - LOG.log(Level.INFO, "Loading DLLs for driver at time {0}." + new Date().toString()); - try (final LoggingScope lb = loggingScopeFactory.loadLib()) { - - // Load the native library connecting C# and Java - this.loadBridgeDLL(); - - // Load all DLLs in local - loadAllManagedDLLs(this.reefFileNames.getLocalFolder()); - - // Load all DLLs in global - loadAllManagedDLLs(this.reefFileNames.getGlobalFolder()); - } - LOG.log(Level.INFO, "Done loading DLLs for Driver at time {0}." + new Date().toString()); - } - - /** - * Loads the Bridge DLL. - * <p> - * If the file is found in the reef/local folder, it is used. Else, we load the one in reef/global. If that isn't - * present, this method throws an IOException - * - * @throws FileNotFoundException if neither file is available. - * @throws Throwable if the DLL is found, but System.load() throws an exception. - */ - private void loadBridgeDLL() throws FileNotFoundException { - final File bridgeDLLFile = this.getBridgeDllFile(); - LOG.log(Level.FINEST, "Attempting to load the bridge DLL from {0}", bridgeDLLFile); - System.load(bridgeDLLFile.getAbsolutePath()); - LOG.log(Level.INFO, "Loaded the bridge DLL from {0}", bridgeDLLFile); - } - - /** - * Returns the File holding the bridge DLL. - * <p> - * This method prefers the one in reef/local. If that isn't found, the one in reef/global is used. If neither exists, - * a FileNotFoundException is thrown. - * - * @throws FileNotFoundException if neither file is available. - */ - private File getBridgeDllFile() throws FileNotFoundException { - final File bridgeDllInLocal = reefFileNames.getBridgeDLLInLocalFolderFile(); - if (bridgeDllInLocal.exists()) { - return bridgeDllInLocal; - } else { - final File bridgeDllInGlobal = reefFileNames.getBridgeDLLInGlobalFolderFile(); - if (bridgeDllInGlobal.exists()) { - return bridgeDllInGlobal; - } - } - // If we got here, neither file exists. - throw new FileNotFoundException("Couldn't find the bridge DLL in the local or global folder."); - } - - /** - * Loads all managed DLLs found in the given folder. - * - * @param folder - */ - private static void loadAllManagedDLLs(final File folder) { - LOG.log(Level.INFO, "Loading all managed DLLs from {0}", folder.getAbsolutePath()); - final File[] files = folder.listFiles(new FilenameFilter() { - public boolean accept(final File dir, final String name) { - return name.toLowerCase().endsWith(DLL_EXTENSION); - } - }); - - for (final File f : files) { - loadManagedDLL(f); - } - } - - /** - * Loads the given DLL. - * - * @param dllFile - */ - private static void loadManagedDLL(final File dllFile) { - final String absolutePath = dllFile.getAbsolutePath(); - try { - LOG.log(Level.FINE, "Loading Managed DLL {0} ", absolutePath); - NativeInterop.loadClrAssembly(absolutePath); - } catch (final Exception e) { - LOG.log(Level.SEVERE, "Unable to load managed DLL {0}", absolutePath); - throw e; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobDriver.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobDriver.java b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobDriver.java index 9abdee6..054408e 100644 --- a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobDriver.java +++ b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobDriver.java @@ -97,11 +97,6 @@ public final class JobDriver { private final DriverStatusManager driverStatusManager; /** - * NativeInterop has function to load libs when driver starts. - */ - private final LibLoader libLoader; - - /** * Factory to setup new CLR process configurations. */ private final CLRProcessFactory clrProcessFactory; @@ -139,6 +134,11 @@ public final class JobDriver { private long driverRestartFailedEvaluatorHandler = 0; private boolean clrBridgeSetup = false; private boolean isRestarted = false; + // We are holding on to following on bridge side. + // Need to add references here so that GC does not collect them. + private final HashMap<String, AllocatedEvaluatorBridge> allocatedEvaluatorBridges = + new HashMap<String, AllocatedEvaluatorBridge>(); + private EvaluatorRequestorBridge evaluatorRequestorBridge; /** * Job driver constructor. @@ -157,7 +157,6 @@ public final class JobDriver { final EvaluatorRequestor evaluatorRequestor, final DriverStatusManager driverStatusManager, final LoggingScopeFactory loggingScopeFactory, - final LibLoader libLoader, final LocalAddressProvider localAddressProvider, final ActiveContextBridgeFactory activeContextBridgeFactory, final AllocatedEvaluatorBridgeFactory allocatedEvaluatorBridgeFactory, @@ -172,7 +171,6 @@ public final class JobDriver { this.allocatedEvaluatorBridgeFactory = allocatedEvaluatorBridgeFactory; this.nameServerInfo = localAddressProvider.getLocalAddress() + ":" + this.nameServer.getPort(); this.loggingScopeFactory = loggingScopeFactory; - this.libLoader = libLoader; this.clrProcessFactory = clrProcessFactory; } @@ -181,13 +179,6 @@ public final class JobDriver { // we can begin logging LOG.log(Level.INFO, "Initializing CLRBufferedLogHandler..."); try (final LoggingScope lb = this.loggingScopeFactory.setupBridge()) { - - try { - libLoader.loadLib(); - } catch (final IOException e) { - throw new RuntimeException("Fail to load CLR libraries"); - } - final CLRBufferedLogHandler handler = getCLRBufferedLogHandler(); if (handler == null) { LOG.log(Level.WARNING, "CLRBufferedLogHandler could not be initialized"); @@ -197,7 +188,7 @@ public final class JobDriver { } final String portNumber = httpServer == null ? null : Integer.toString((httpServer.getPort())); - final EvaluatorRequestorBridge evaluatorRequestorBridge = + this.evaluatorRequestorBridge = new EvaluatorRequestorBridge(JobDriver.this.evaluatorRequestor, false, loggingScopeFactory); final long[] handlers = initializer.getClrHandlers(portNumber, evaluatorRequestorBridge); if (handlers != null) { @@ -270,6 +261,7 @@ public final class JobDriver { } final AllocatedEvaluatorBridge allocatedEvaluatorBridge = this.allocatedEvaluatorBridgeFactory.getAllocatedEvaluatorBridge(eval, this.nameServerInfo); + allocatedEvaluatorBridges.put(allocatedEvaluatorBridge.getId(), allocatedEvaluatorBridge); NativeInterop.clrSystemAllocatedEvaluatorHandlerOnNext(JobDriver.this.allocatedEvaluatorHandler, allocatedEvaluatorBridge, this.interopLogger); } @@ -434,6 +426,7 @@ public final class JobDriver { @Override public void onNext(final FailedEvaluator eval) { JobDriver.this.handleFailedEvaluator(eval, false); + allocatedEvaluatorBridges.remove(eval.getId()); } } @@ -723,6 +716,7 @@ public final class JobDriver { // if CLR implements the completed evaluator handler, handle it in CLR LOG.log(Level.INFO, "Handling the event of completed evaluator in CLR bridge."); NativeInterop.clrSystemCompletedEvaluatorHandlerOnNext(completedEvaluatorHandler, completedEvaluatorBridge); + allocatedEvaluatorBridges.remove(completedEvaluatorBridge.getId()); } } } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/REEFFileNames.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/REEFFileNames.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/REEFFileNames.java index 04f0ae0..68a6fb0 100644 --- a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/REEFFileNames.java +++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/REEFFileNames.java @@ -47,7 +47,7 @@ public final class REEFFileNames { private static final String DRIVER_STDOUT = "driver.stdout"; private static final String EVALUATOR_STDERR = "evaluator.stderr"; private static final String EVALUATOR_STDOUT = "evaluator.stdout"; - private static final String BRIDGE_DLL_NAME = "Org.Apache.REEF.Bridge.dll"; + private static final String BRIDGE_EXE_NAME = "Org.Apache.REEF.Bridge.exe"; @Inject @@ -58,28 +58,20 @@ public final class REEFFileNames { /** * @return the filename of the CPP DLL for the bridge. */ - public String getBridgeDLLName() { - return BRIDGE_DLL_NAME; + public String getBridgeExeName() { + return BRIDGE_EXE_NAME; } /** - * reef/local/BRIDGE_DLL_NAME. + * reef/BRIDGE_EXE_NAME. * - * @return the File pointing to the DLL containing the DLL for the bridge. + * @return the File pointing to the EXE that is the clr driver launcher. */ - public File getBridgeDLLInLocalFolderFile() { - return new File(getLocalFolder(), getBridgeDLLName()); + public File getDriverLauncherExeFile() { + return new File(getREEFFolderName(), getBridgeExeName()); } /** - * @return a File pointing to the Bridge DLL in the global folder. - */ - public File getBridgeDLLInGlobalFolderFile() { - return new File(getGlobalFolder(), getBridgeDLLName()); - } - - - /** * The name of the REEF folder inside of the working directory of an Evaluator or Driver. */ public String getREEFFolderName() { http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/JavaLaunchCommandBuilder.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/JavaLaunchCommandBuilder.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/JavaLaunchCommandBuilder.java index 9fdf50f..87df61c 100644 --- a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/JavaLaunchCommandBuilder.java +++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/JavaLaunchCommandBuilder.java @@ -44,19 +44,33 @@ public final class JavaLaunchCommandBuilder implements LaunchCommandBuilder { private String classPath = null; private Boolean assertionsEnabled = null; private Map<String, JVMOption> options = new HashMap<>(); + private final List<String> commandPrefixList; /** * Constructor that populates default options. */ public JavaLaunchCommandBuilder() { + this(null); + } + + /** + * Constructor that populates prefix. + */ + public JavaLaunchCommandBuilder(final List<String> commandPrefixList) { for (final String defaultOption : DEFAULT_OPTIONS) { addOption(defaultOption); } + this.commandPrefixList = commandPrefixList; } @Override public List<String> build() { return new ArrayList<String>() {{ + if (commandPrefixList != null) { + for (final String cmd : commandPrefixList) { + add(cmd); + } + } if (javaPath == null || javaPath.isEmpty()) { add(DEFAULT_JAVA_PATH); http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/DriverLaunchCommandPrefix.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/DriverLaunchCommandPrefix.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/DriverLaunchCommandPrefix.java new file mode 100644 index 0000000..c598288 --- /dev/null +++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/DriverLaunchCommandPrefix.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.reef.runtime.common.launch.parameters; + +import org.apache.reef.tang.annotations.Name; +import org.apache.reef.tang.annotations.NamedParameter; +import java.util.List; + +/** + * List of strings to be prepended to driver launch command (I.E. wrapper, debugger..). + */ +@NamedParameter(doc = "List of strings to be prepended to driver launch command.") +public final class DriverLaunchCommandPrefix implements Name<List<String>> { +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/PreparedDriverFolderLauncher.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/PreparedDriverFolderLauncher.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/PreparedDriverFolderLauncher.java index 2f0c691..cfa748d 100644 --- a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/PreparedDriverFolderLauncher.java +++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/PreparedDriverFolderLauncher.java @@ -24,6 +24,7 @@ import org.apache.reef.runtime.common.files.REEFFileNames; import org.apache.reef.runtime.common.launch.JavaLaunchCommandBuilder; import org.apache.reef.runtime.local.process.LoggingRunnableProcessObserver; import org.apache.reef.runtime.local.process.RunnableProcess; +import org.apache.reef.tang.annotations.Parameter; import javax.inject.Inject; import java.io.File; @@ -31,6 +32,7 @@ import java.util.List; import java.util.concurrent.ExecutorService; import java.util.logging.Level; import java.util.logging.Logger; +import org.apache.reef.runtime.common.launch.parameters.DriverLaunchCommandPrefix; /** * Launcher for a already prepared driver folder. @@ -45,6 +47,8 @@ public class PreparedDriverFolderLauncher { private final ExecutorService executor; private final REEFFileNames fileNames; private final ClasspathProvider classpath; + private final List<String> commandPrefixList; + /** * The (hard-coded) amount of memory to be used for the driver. */ @@ -54,10 +58,12 @@ public class PreparedDriverFolderLauncher { @Inject PreparedDriverFolderLauncher(final ExecutorService executor, final REEFFileNames fileNames, + @Parameter(DriverLaunchCommandPrefix.class) final List<String> commandPrefixList, final ClasspathProvider classpath) { this.executor = executor; this.fileNames = fileNames; this.classpath = classpath; + this.commandPrefixList = commandPrefixList; } /** @@ -84,7 +90,7 @@ public class PreparedDriverFolderLauncher { private List<String> makeLaunchCommand(final String jobId, final String clientRemoteId) { - final List<String> command = new JavaLaunchCommandBuilder() + final List<String> command = new JavaLaunchCommandBuilder(commandPrefixList) .setConfigurationFileName(this.fileNames.getDriverConfigurationPath()) .setClassPath(this.classpath.getDriverClasspath()) .setMemory(DRIVER_MEMORY) http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/3cac2d4a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnSubmissionHelper.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnSubmissionHelper.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnSubmissionHelper.java index a8ef709..8723ac3 100644 --- a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnSubmissionHelper.java +++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnSubmissionHelper.java @@ -56,11 +56,13 @@ public final class YarnSubmissionHelper implements Closeable{ private final SecurityTokenProvider tokenProvider; private boolean preserveEvaluators; private int maxAppSubmissions; + private final List<String> commandPrefixList; public YarnSubmissionHelper(final YarnConfiguration yarnConfiguration, final REEFFileNames fileNames, final ClasspathProvider classpath, - final SecurityTokenProvider tokenProvider) throws IOException, YarnException { + final SecurityTokenProvider tokenProvider, + final List<String> commandPrefixList) throws IOException, YarnException { this.fileNames = fileNames; this.classpath = classpath; @@ -78,13 +80,23 @@ public final class YarnSubmissionHelper implements Closeable{ this.maxAppSubmissions = 1; this.preserveEvaluators = false; this.tokenProvider = tokenProvider; + this.commandPrefixList = commandPrefixList; LOG.log(Level.FINEST, "YARN Application ID: {0}", applicationId); } - /** - * - * @return the application ID assigned by YARN. - */ + public YarnSubmissionHelper(final YarnConfiguration yarnConfiguration, + final REEFFileNames fileNames, + final ClasspathProvider classpath, + final SecurityTokenProvider tokenProvider) throws IOException, YarnException { + this(yarnConfiguration, fileNames, classpath, tokenProvider, null); + } + + + + /** + * + * @return the application ID assigned by YARN. + */ public int getApplicationId() { return this.applicationId.getId(); } @@ -183,7 +195,7 @@ public final class YarnSubmissionHelper implements Closeable{ public void submit() throws IOException, YarnException { // SET EXEC COMMAND - final List<String> launchCommand = new JavaLaunchCommandBuilder() + final List<String> launchCommand = new JavaLaunchCommandBuilder(commandPrefixList) .setConfigurationFileName(this.fileNames.getDriverConfigurationPath()) .setClassPath(this.classpath.getDriverClasspath()) .setMemory(this.applicationSubmissionContext.getResource().getMemory())
