/** * Creates a {@link Program} that can be executed by the given {@link ProgramRunner}. * * @param cConf the CDAP configuration * @param programRunner the {@link ProgramRunner} for executing the program. If provided and if it implements * {@link ProgramClassLoaderProvider}, then the * {@link ClassLoader} created for the {@link Program} will be determined based on it. * Otherwise, the {@link ClassLoader} will only have visibility * to cdap-api and hadoop classes. * @param programDescriptor description of the program to create * @param programJarLocation the {@link Location} of the program jar file * @param unpackedDir a directory that the program jar file was unpacked to * @return a new {@link Program} instance. */ public static Program create(CConfiguration cConf, @Nullable ProgramRunner programRunner, ProgramDescriptor programDescriptor, Location programJarLocation, File unpackedDir) { ClassLoader parentClassLoader = null; if (programRunner instanceof ProgramClassLoaderProvider) { parentClassLoader = ((ProgramClassLoaderProvider) programRunner).createProgramClassLoaderParent(); } if (parentClassLoader == null) { parentClassLoader = FilterClassLoader.create(Programs.class.getClassLoader()); } return new DefaultProgram(programDescriptor, programJarLocation, new ProgramClassLoader(cConf, unpackedDir, parentClassLoader)); }
/** * Creates a {@link Program} that can be executed by the given {@link ProgramRunner}. * * @param cConf the CDAP configuration * @param programRunner the {@link ProgramRunner} for executing the program. If provided and if it implements * {@link ProgramClassLoaderProvider}, then the * {@link ClassLoader} created for the {@link Program} will be determined based on it. * Otherwise, the {@link ClassLoader} will only have visibility * to cdap-api and hadoop classes. * @param programDescriptor description of the program to create * @param programJarLocation the {@link Location} of the program jar file * @param unpackedDir a directory that the program jar file was unpacked to * @return a new {@link Program} instance. */ public static Program create(CConfiguration cConf, @Nullable ProgramRunner programRunner, ProgramDescriptor programDescriptor, Location programJarLocation, File unpackedDir) { ClassLoader parentClassLoader = null; if (programRunner instanceof ProgramClassLoaderProvider) { parentClassLoader = ((ProgramClassLoaderProvider) programRunner).createProgramClassLoaderParent(); } if (parentClassLoader == null) { parentClassLoader = FilterClassLoader.create(Programs.class.getClassLoader()); } return new DefaultProgram(programDescriptor, programJarLocation, new ProgramClassLoader(cConf, unpackedDir, parentClassLoader)); }
programClassLoader = new ProgramClassLoader( cConf, unpackDir, ((ProgramClassLoaderProvider) programRunner).createProgramClassLoaderParent()); programClassLoader = new ProgramClassLoader(cConf, unpackDir, FilterClassLoader.create(getClass().getClassLoader()));
private static Program createProgram(CConfiguration cConf, SparkRuntimeContextConfig contextConfig) throws IOException { File programJar = new File(PROGRAM_JAR_NAME); File programDir = new File(PROGRAM_JAR_EXPANDED_NAME); ClassLoader parentClassLoader = new FilterClassLoader(SparkRuntimeContextProvider.class.getClassLoader(), SparkResourceFilters.SPARK_PROGRAM_CLASS_LOADER_FILTER); ClassLoader classLoader = new ProgramClassLoader(cConf, programDir, parentClassLoader); return new DefaultProgram(new ProgramDescriptor(contextConfig.getProgramId(), contextConfig.getApplicationSpecification()), Locations.toLocation(programJar), classLoader); }
programClassLoader = new ProgramClassLoader( cConf, unpackDir, ((ProgramClassLoaderProvider) programRunner).createProgramClassLoaderParent()); programClassLoader = new ProgramClassLoader(cConf, unpackDir, FilterClassLoader.create(getClass().getClassLoader()));
/** * Creates a program {@link ClassLoader} based on the MR job config. */ private static ClassLoader createProgramClassLoader(MapReduceContextConfig contextConfig) { // In distributed mode, the program is created by expanding the program jar. // The program jar is localized to container with the program jar name. // It's ok to expand to a temp dir in local directory, as the YARN container will be gone. Location programLocation = Locations.toLocation(new File(contextConfig.getProgramJarName())); try { File unpackDir = DirUtils.createTempDir(new File(System.getProperty("user.dir"))); LOG.info("Create ProgramClassLoader from {}, expand to {}", programLocation, unpackDir); BundleJarUtil.unJar(programLocation, unpackDir); return new ProgramClassLoader(contextConfig.getCConf(), unpackDir, FilterClassLoader.create(contextConfig.getHConf().getClassLoader())); } catch (IOException e) { LOG.error("Failed to create ProgramClassLoader", e); throw Throwables.propagate(e); } }
private static Program createProgram(CConfiguration cConf, SparkRuntimeContextConfig contextConfig) throws IOException { File programJar = new File(PROGRAM_JAR_NAME); File programDir = new File(PROGRAM_JAR_EXPANDED_NAME); ClassLoader parentClassLoader = new FilterClassLoader(SparkRuntimeContextProvider.class.getClassLoader(), SparkResourceFilters.SPARK_PROGRAM_CLASS_LOADER_FILTER); ClassLoader classLoader = new ProgramClassLoader(cConf, programDir, parentClassLoader); return new DefaultProgram(new ProgramDescriptor(contextConfig.getProgramId(), contextConfig.getApplicationSpecification()), Locations.toLocation(programJar), classLoader); }
private static Program createProgram(CConfiguration cConf, SparkRuntimeContextConfig contextConfig) throws IOException { File programJar = new File(PROGRAM_JAR_NAME); File programDir = new File(PROGRAM_JAR_EXPANDED_NAME); ClassLoader parentClassLoader = new FilterClassLoader(SparkRuntimeContextProvider.class.getClassLoader(), SparkResourceFilters.SPARK_PROGRAM_CLASS_LOADER_FILTER); ClassLoader classLoader = new ProgramClassLoader(cConf, programDir, parentClassLoader); return new DefaultProgram(new ProgramDescriptor(contextConfig.getProgramId(), contextConfig.getApplicationSpecification()), Locations.toLocation(programJar), classLoader); }
/** * Creates a program {@link ClassLoader} based on the MR job config. */ private static ClassLoader createProgramClassLoader(MapReduceContextConfig contextConfig) { // In distributed mode, the program is created by expanding the program jar. // The program jar is localized to container with the program jar name. // It's ok to expand to a temp dir in local directory, as the YARN container will be gone. Location programLocation = Locations.toLocation(new File(contextConfig.getProgramJarName())); try { File unpackDir = DirUtils.createTempDir(new File(System.getProperty("user.dir"))); LOG.info("Create ProgramClassLoader from {}, expand to {}", programLocation, unpackDir); BundleJarUtil.unJar(programLocation, unpackDir); return new ProgramClassLoader(contextConfig.getCConf(), unpackDir, FilterClassLoader.create(contextConfig.getHConf().getClassLoader())); } catch (IOException e) { LOG.error("Failed to create ProgramClassLoader", e); throw Throwables.propagate(e); } }
private static ProgramClassLoader createAppClassLoader(File jarFile) throws IOException { File unpackDir = DirUtils.createTempDir(TMP_FOLDER.newFolder()); BundleJarUtil.unJar(jarFile, unpackDir); return new ProgramClassLoader(cConf, unpackDir, FilterClassLoader.create(ArtifactRepositoryTest.class.getClassLoader())); }