stream.close();
} else {
if (job.getSourceFile() != null && !job.getSourceFile().isEmpty()) {
// otherwise, just copy original file
if (!BaseService.getHdfsApi(context).copy(job.getSourceFile(), newSourceFilePath)) {
throw new ServiceFormattedException("Can't copy source file from " + job.getSourceFile() +
" to " + newPigScriptPath);
}
}
}
} catch (IOException e) {
throw new ServiceFormattedException("Can't create/copy source file: " + e.toString(), e);
} catch (InterruptedException e) {
throw new ServiceFormattedException("Can't create/copy source file: " + e.toString(), e);
}
try {
// content can be passed from front-end with substituted arguments
if (job.getForcedContent() != null && !job.getForcedContent().isEmpty()) {
String forcedContent = job.getForcedContent();
// variable for sourceFile can be passed from front-ent
forcedContent = forcedContent.replace("${sourceFile}",
context.getProperties().get("dataworker.defaultFs") + newSourceFilePath);
job.setForcedContent(null); // we should not store content in DB
save(job);
FSDataOutputStream stream = BaseService.getHdfsApi(context).create(newPigScriptPath, true);
stream.writeBytes(forcedContent);
stream.close();
} else {
// otherwise, just copy original file
if (!BaseService.getHdfsApi(context).copy(job.getPigScript(), newPigScriptPath)) {
throw new ServiceFormattedException("Can't copy pig script file from " + job.getPigScript() +
" to " + newPigScriptPath);
}
}
} catch (IOException e) {
throw new ServiceFormattedException("Can't create/copy pig script file: " + e.toString(), e);
} catch (InterruptedException e) {
throw new ServiceFormattedException("Can't create/copy pig script file: " + e.toString(), e);
}
if (job.getPythonScript() != null && !job.getPythonScript().isEmpty()) {
try {
if (!BaseService.getHdfsApi(context).copy(job.getPythonScript(), newPythonScriptPath)) {
throw new ServiceFormattedException("Can't copy python udf script file from " + job.getPythonScript() +
" to " + newPythonScriptPath);
}
} catch (IOException e) {
throw new ServiceFormattedException("Can't create/copy python udf file: " + e.toString(), e);
} catch (InterruptedException e) {
throw new ServiceFormattedException("Can't create/copy python udf file: " + e.toString(), e);
}
}
try {
FSDataOutputStream stream = BaseService.getHdfsApi(context).create(templetonParamsFilePath, true);
if (job.getTempletonArguments() != null) {
stream.writeBytes(job.getTempletonArguments());
}
stream.close();
} catch (IOException e) {
throw new ServiceFormattedException("Can't create params file: " + e.toString(), e);
} catch (InterruptedException e) {
throw new ServiceFormattedException("Can't create params file: " + e.toString(), e);
}
job.setPigScript(newPigScriptPath);
job.setStatusDir(statusdir);
job.setDateStarted(System.currentTimeMillis() / 1000L);
TempletonApi.JobData data = null;
try {
data = getTempletonApi().runPigQuery(new File(job.getPigScript()), statusdir, job.getTempletonArguments());
} catch (IOException templetonBadResponse) {
String msg = String.format("Templeton bad response: %s", templetonBadResponse.toString());
LOG.debug(msg);
throw new ServiceFormattedException(msg, templetonBadResponse);
}
job.setJobId(data.id);
JobPolling.pollJob(context, job);
}