in buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/fixture/hadoop/tasks/DfsCopy.groovy [111:165]
void runHdfsDfsCp() {
// Verification
if (clusterConfiguration == null) {
throw new GradleException("No cluster configuration found")
}
if (localSource == null && dfsSource == null) {
throw new GradleException("No source given")
}
if (localDestination == null && dfsDestination == null) {
throw new GradleException("No destination given")
}
// Gateway conf
InstanceConfiguration hadoopGateway = getInstance()
// Determine command
File baseDir = hadoopGateway.getBaseDir()
File homeDir = new File(baseDir, hadoopGateway.getServiceDescriptor().homeDirName(hadoopGateway))
File binDir = new File(homeDir, hadoopGateway.serviceDescriptor.scriptDir(hadoopGateway))
String commandName = 'hdfs' // TODO: or hdfs.cmd for Windows
File command = new File(binDir, commandName)
List<String> copyCommandLine = [command.toString()]
if (localSource != null && localDestination != null) {
project.copy { CopySpec spec ->
spec.from(localSource.toString())
spec.into(localDestination.toString())
}
return // Exit early
} else if (localSource != null && dfsDestination != null) {
copyCommandLine.addAll(['dfs', '-copyFromLocal', localSource.toString(), dfsDestination.toString()])
} else if (dfsSource != null && localDestination != null) {
copyCommandLine.addAll(['dfs', '-copyToLocal', dfsSource.toString(), localDestination.toString()])
} else if (dfsSource != null && dfsDestination != null) {
copyCommandLine.addAll(['dfs', '-cp', dfsSource.toString(), dfsDestination.toString()])
}
// Combine env and sysprops
Map<String, String> finalEnv = collectEnvVars()
// First ensure destination directories exist
if (dfsDestination != null) {
List<String> mkdirCommandLine = [command.toString(), 'dfs', '-mkdir', '-p', dfsDestination.parentFile.toString()]
project.exec { ExecSpec spec ->
spec.commandLine(mkdirCommandLine)
spec.environment(finalEnv)
}
}
// Do command
project.exec { ExecSpec spec ->
spec.commandLine(copyCommandLine)
spec.environment(finalEnv)
}
}