/** * Copies a file to the target location. * * @param targetDir directory where the file should be copied to. * @return {@link Location} to the file or {@code null} if given file is {@code null}. */ private Location copyFileToLocation(File file, Location targetDir) throws IOException { Location targetLocation = targetDir.append(file.getName()).getTempFile(".jar"); Files.copy(file, Locations.newOutputSupplier(targetLocation)); return targetLocation; }
/** * Copies a file to the target location. * * @param targetDir directory where the file should be copied to. * @return {@link Location} to the file or {@code null} if given file is {@code null}. */ private Location copyFileToLocation(File file, Location targetDir) throws IOException { Location targetLocation = targetDir.append(file.getName()).getTempFile(".jar"); Files.copy(file, Locations.newOutputSupplier(targetLocation)); return targetLocation; }
/** * Creates a temp copy of the program jar. * * @return a new {@link Location} which contains the same content as the program jar */ private Location copyProgramJar(Location targetDir) throws IOException { Location programJarCopy = targetDir.append("program.jar"); ByteStreams.copy(Locations.newInputSupplier(programJarLocation), Locations.newOutputSupplier(programJarCopy)); LOG.debug("Copied Program Jar to {}, source: {}", programJarCopy, programJarLocation); return programJarCopy; }
/** * Creates a temp copy of the program jar. * * @return a new {@link Location} which contains the same content as the program jar */ private Location copyProgramJar(Location targetDir) throws IOException { Location programJarCopy = targetDir.append("program.jar"); ByteStreams.copy(Locations.newInputSupplier(programJarLocation), Locations.newOutputSupplier(programJarCopy)); LOG.debug("Copied Program Jar to {}, source: {}", programJarCopy, programJarLocation); return programJarCopy; }
/** * Creates a launcher jar that contains the MR AM main class and the MR task main class. It is for ClassLoader * construction before delegating the actual execution to the actual MR main classes. * * @see MapReduceContainerLauncher * @see ContainerLauncherGenerator */ private Location createLauncherJar(Location targetDir) throws IOException { Location launcherJar = targetDir.append("launcher.jar"); ContainerLauncherGenerator.generateLauncherJar( Arrays.asList( "org.apache.hadoop.mapreduce.v2.app.MRAppMaster", "org.apache.hadoop.mapred.YarnChild" ), MapReduceContainerLauncher.class, Locations.newOutputSupplier(launcherJar)); return launcherJar; }
/** * Prepares the {@link HBaseDDLExecutor} implementation for localization. */ @Nullable private String getLocalizedHBaseDDLExecutorDir(File tempDir, CConfiguration cConf, Job job, Location tempLocation) throws IOException { String ddlExecutorExtensionDir = cConf.get(Constants.HBaseDDLExecutor.EXTENSIONS_DIR); if (ddlExecutorExtensionDir == null) { // Nothing to localize return null; } String hbaseDDLExtensionJarName = "hbaseddlext.jar"; final File target = new File(tempDir, hbaseDDLExtensionJarName); BundleJarUtil.createJar(new File(ddlExecutorExtensionDir), target); Location targetLocation = tempLocation.append(hbaseDDLExtensionJarName); Files.copy(target, Locations.newOutputSupplier(targetLocation)); job.addCacheArchive(targetLocation.toURI()); return target.getName(); } }
/** * Prepares the {@link HBaseDDLExecutor} implementation for localization. */ @Nullable private String getLocalizedHBaseDDLExecutorDir(File tempDir, CConfiguration cConf, Job job, Location tempLocation) throws IOException { String ddlExecutorExtensionDir = cConf.get(Constants.HBaseDDLExecutor.EXTENSIONS_DIR); if (ddlExecutorExtensionDir == null) { // Nothing to localize return null; } String hbaseDDLExtensionJarName = "hbaseddlext.jar"; final File target = new File(tempDir, hbaseDDLExtensionJarName); BundleJarUtil.createJar(new File(ddlExecutorExtensionDir), target); Location targetLocation = tempLocation.append(hbaseDDLExtensionJarName); Files.copy(target, Locations.newOutputSupplier(targetLocation)); job.addCacheArchive(targetLocation.toURI()); return target.getName(); } }
FileContentWriter(StreamConfig streamConfig, ConcurrentStreamWriter streamWriter, Location directory, Map<String, String> headers) throws IOException { this.streamConfig = streamConfig; this.streamWriter = streamWriter; this.streamEventData = new MutableStreamEventData(); this.streamEvent = new MutableStreamEvent(); directory.mkdirs(); this.eventFile = directory.append("upload.dat"); this.indexFile = directory.append("upload.idx"); Map<String, String> properties = createStreamFileProperties(headers); properties.put(StreamDataFileConstants.Property.Key.UNI_TIMESTAMP, StreamDataFileConstants.Property.Value.CLOSE_TIMESTAMP); this.writer = new StreamDataFileWriter(Locations.newOutputSupplier(eventFile), Locations.newOutputSupplier(indexFile), streamConfig.getIndexInterval(), properties); }
private Location copyFileToHDFS(Location hdfsKeytabDir, File localFile) throws IOException { Location remoteFile = hdfsKeytabDir.append(localFile.getName()); Assert.assertTrue(remoteFile.createNew()); Files.copy(localFile, Locations.newOutputSupplier(remoteFile)); return remoteFile; }
Files.copy(uploadedFile, Locations.newOutputSupplier(tmpLocation));
Files.copy(uploadedFile, Locations.newOutputSupplier(tmpLocation));
private void writeConfig(StreamConfig config) throws IOException { Location configLocation = config.getLocation().append(CONFIG_FILE_NAME); Location tmpConfigLocation = configLocation.getTempFile(null); CharStreams.write(GSON.toJson(config), CharStreams.newWriterSupplier( Locations.newOutputSupplier(tmpConfigLocation), Charsets.UTF_8)); try { // Windows does not allow renaming if the destination file exists so we must delete the configLocation if (OSDetector.isWindows()) { configLocation.delete(); } tmpConfigLocation.renameTo(getConfigLocation(config.getStreamId())); } finally { Locations.deleteQuietly(tmpConfigLocation); } }