use of com.continuuity.weave.filesystem.Location in project weave by continuuity.
the class YarnWeavePreparer method saveKafka.
private void saveKafka(Map<String, LocalFile> localFiles) throws IOException {
LOG.debug("Copy {}", Constants.Files.KAFKA);
Location location = copyFromURL(getClass().getClassLoader().getResource(KAFKA_ARCHIVE), createTempLocation(Constants.Files.KAFKA));
LOG.debug("Done {}", Constants.Files.KAFKA);
localFiles.put(Constants.Files.KAFKA, createLocalFile(Constants.Files.KAFKA, location, true));
}
use of com.continuuity.weave.filesystem.Location in project weave by continuuity.
the class YarnWeavePreparer method createContainerJar.
private void createContainerJar(ApplicationBundler bundler, Map<String, LocalFile> localFiles) throws IOException {
try {
Set<Class<?>> classes = Sets.newIdentityHashSet();
classes.add(WeaveContainerMain.class);
classes.addAll(dependencies);
ClassLoader classLoader = getClassLoader();
for (RuntimeSpecification spec : weaveSpec.getRunnables().values()) {
classes.add(classLoader.loadClass(spec.getRunnableSpecification().getClassName()));
}
LOG.debug("Create and copy {}", Constants.Files.CONTAINER_JAR);
Location location = createTempLocation(Constants.Files.CONTAINER_JAR);
bundler.createBundle(location, classes, resources);
LOG.debug("Done {}", Constants.Files.CONTAINER_JAR);
localFiles.put(Constants.Files.CONTAINER_JAR, createLocalFile(Constants.Files.CONTAINER_JAR, location));
} catch (ClassNotFoundException e) {
throw Throwables.propagate(e);
}
}
use of com.continuuity.weave.filesystem.Location in project weave by continuuity.
the class YarnWeavePreparer method saveLauncher.
/**
* Creates the launcher.jar for launch the main application.
*/
private void saveLauncher(Map<String, LocalFile> localFiles) throws URISyntaxException, IOException {
LOG.debug("Create and copy {}", Constants.Files.LAUNCHER_JAR);
Location location = createTempLocation(Constants.Files.LAUNCHER_JAR);
final String launcherName = WeaveLauncher.class.getName();
// Create a jar file with the WeaveLauncher optionally a json serialized classpath.json in it.
final JarOutputStream jarOut = new JarOutputStream(location.getOutputStream());
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
Dependencies.findClassDependencies(classLoader, new Dependencies.ClassAcceptor() {
@Override
public boolean accept(String className, URL classUrl, URL classPathUrl) {
Preconditions.checkArgument(className.startsWith(launcherName), "Launcher jar should not have dependencies: %s", className);
try {
jarOut.putNextEntry(new JarEntry(className.replace('.', '/') + ".class"));
InputStream is = classUrl.openStream();
try {
ByteStreams.copy(is, jarOut);
} finally {
is.close();
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
return true;
}
}, WeaveLauncher.class.getName());
try {
if (!classPaths.isEmpty()) {
jarOut.putNextEntry(new JarEntry("classpath"));
jarOut.write(Joiner.on(':').join(classPaths).getBytes(Charsets.UTF_8));
}
} finally {
jarOut.close();
}
LOG.debug("Done {}", Constants.Files.LAUNCHER_JAR);
localFiles.put(Constants.Files.LAUNCHER_JAR, createLocalFile(Constants.Files.LAUNCHER_JAR, location));
}
use of com.continuuity.weave.filesystem.Location in project weave by continuuity.
the class ApplicationBundlerTest method testFindDependencies.
@Test
public void testFindDependencies() throws IOException, ClassNotFoundException {
Location location = new LocalLocationFactory(tmpDir.newFolder()).create("test.jar");
// Create a jar file with by tracing dependency
ApplicationBundler bundler = new ApplicationBundler(ImmutableList.<String>of());
bundler.createBundle(location, ApplicationBundler.class);
File targetDir = tmpDir.newFolder();
unjar(new File(location.toURI()), targetDir);
// Load the class back, it should be loaded by the custom classloader
ClassLoader classLoader = createClassLoader(targetDir);
Class<?> clz = classLoader.loadClass(ApplicationBundler.class.getName());
Assert.assertSame(classLoader, clz.getClassLoader());
// For system classes, they shouldn't be packaged, hence loaded by different classloader.
clz = classLoader.loadClass(Object.class.getName());
Assert.assertNotSame(classLoader, clz.getClassLoader());
}
use of com.continuuity.weave.filesystem.Location in project weave by continuuity.
the class YarnWeavePreparer method populateRunnableLocalFiles.
/**
* Based on the given {@link WeaveSpecification}, upload LocalFiles to Yarn Cluster.
* @param weaveSpec The {@link WeaveSpecification} for populating resource.
* @param localFiles A Multimap to store runnable name to transformed LocalFiles.
* @throws IOException
*/
private void populateRunnableLocalFiles(WeaveSpecification weaveSpec, Multimap<String, LocalFile> localFiles) throws IOException {
LOG.debug("Populating Runnable LocalFiles");
for (Map.Entry<String, RuntimeSpecification> entry : weaveSpec.getRunnables().entrySet()) {
String runnableName = entry.getKey();
for (LocalFile localFile : entry.getValue().getLocalFiles()) {
Location location;
URI uri = localFile.getURI();
if ("hdfs".equals(uri.getScheme())) {
// Assuming the location factory is HDFS one. If it is not, it will failed, which is the correct behavior.
location = locationFactory.create(uri);
} else {
URL url = uri.toURL();
LOG.debug("Create and copy {} : {}", runnableName, url);
// Preserves original suffix for expansion.
location = copyFromURL(url, createTempLocation(Paths.appendSuffix(url.getFile(), localFile.getName())));
LOG.debug("Done {} : {}", runnableName, url);
}
localFiles.put(runnableName, new DefaultLocalFile(localFile.getName(), location.toURI(), location.lastModified(), location.length(), localFile.isArchive(), localFile.getPattern()));
}
}
LOG.debug("Done Runnable LocalFiles");
}
Aggregations