Search in sources :

Example 1 with DefaultProgram

use of co.cask.cdap.app.program.DefaultProgram in project cdap by caskdata.

the class SparkRuntimeContextProvider method createProgram.

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(), SparkRuntimeUtils.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);
}
Also used : FilterClassLoader(co.cask.cdap.common.lang.FilterClassLoader) ProgramClassLoader(co.cask.cdap.internal.app.runtime.ProgramClassLoader) FilterClassLoader(co.cask.cdap.common.lang.FilterClassLoader) ProgramClassLoader(co.cask.cdap.internal.app.runtime.ProgramClassLoader) DefaultProgram(co.cask.cdap.app.program.DefaultProgram) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) File(java.io.File)

Example 2 with DefaultProgram

use of co.cask.cdap.app.program.DefaultProgram in project cdap by caskdata.

the class MapReduceTaskContextProvider method createProgram.

/**
 * Creates a {@link Program} instance based on the information from the {@link MapReduceContextConfig}, using
 * the given program ClassLoader.
 */
private Program createProgram(MapReduceContextConfig contextConfig, ClassLoader programClassLoader) {
    Location programLocation;
    LocationFactory locationFactory = new LocalLocationFactory();
    if (isLocal(contextConfig.getHConf())) {
        // Just create a local location factory. It's for temp usage only as the program location is always absolute.
        programLocation = locationFactory.create(contextConfig.getProgramJarURI());
    } else {
        // In distributed mode, the program jar is localized to the container
        programLocation = locationFactory.create(new File(contextConfig.getProgramJarName()).getAbsoluteFile().toURI());
    }
    return new DefaultProgram(new ProgramDescriptor(contextConfig.getProgramId(), contextConfig.getApplicationSpecification()), programLocation, programClassLoader);
}
Also used : DefaultProgram(co.cask.cdap.app.program.DefaultProgram) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) File(java.io.File) Location(org.apache.twill.filesystem.Location) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory)

Aggregations

DefaultProgram (co.cask.cdap.app.program.DefaultProgram)2 ProgramDescriptor (co.cask.cdap.app.program.ProgramDescriptor)2 File (java.io.File)2 FilterClassLoader (co.cask.cdap.common.lang.FilterClassLoader)1 ProgramClassLoader (co.cask.cdap.internal.app.runtime.ProgramClassLoader)1 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)1 Location (org.apache.twill.filesystem.Location)1 LocationFactory (org.apache.twill.filesystem.LocationFactory)1