cameronlee314 commented on a change in pull request #1173: SAMZA-2333: [AM
isolation] Use cytodynamics classloader to launch job coordinator
URL: https://github.com/apache/samza/pull/1173#discussion_r333755913
##########
File path:
samza-core/src/main/java/org/apache/samza/clustermanager/ClusterBasedJobCoordinator.java
##########
@@ -406,10 +409,72 @@ ContainerProcessManager
createContainerProcessManager(ClassLoader classLoader) {
}
/**
- * The entry point for the {@link ClusterBasedJobCoordinator}
- * @param args args
+ * The entry point for the {@link ClusterBasedJobCoordinator}.
*/
public static void main(String[] args) {
+ boolean isolationEnabled =
+
Boolean.parseBoolean(System.getenv(ShellCommandConfig.ENV_APPLICATION_MASTER_ISOLATION_ENABLED()));
+ if (!isolationEnabled) {
+ // no isolation enabled, so can just execute
runClusterBasedJobCoordinator directly
+ runClusterBasedJobCoordinator(args);
+ } else {
+ runWithIsolatedClassLoader(args);
+ }
+ }
+
+ /**
+ * Execute the coordinator using a separate isolated classloader.
+ */
+ private static void runWithIsolatedClassLoader(String[] args) {
+ ClassLoader isolatedClassLoader = new
IsolatingClassLoaderFactory().buildClassLoader();
+
+ // need to use the isolated classloader to load ClusterBasedJobCoordinator
and then run using that new class
+ Class<?> isolatedClusterBasedJobCoordinatorClass;
+ try {
+ isolatedClusterBasedJobCoordinatorClass =
+
isolatedClassLoader.loadClass(ClusterBasedJobCoordinator.class.getName());
+ } catch (ClassNotFoundException e) {
+ throw new SamzaException(
+ "Isolation was enabled, but unable to find
ClusterBasedJobCoordinator in isolated classloader", e);
+ }
+
+ // save the current context classloader so it can be reset after finishing
the call to runClusterBasedJobCoordinator
+ ClassLoader previousContextClassLoader =
Thread.currentThread().getContextClassLoader();
+ // this is needed because certain libraries use the context classloader
+ Thread.currentThread().setContextClassLoader(isolatedClassLoader);
+
+ try {
+
executeRunClusterBasedJobCoordinatorForClass(isolatedClusterBasedJobCoordinatorClass,
args);
+ } finally {
+ // reset the context class loader
Review comment:
Good practice, and might be important when multiple unit tests from the same
thread. Added a little more context to the comment.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services