in genie-agent/src/main/java/com/netflix/genie/agent/cli/ResolveJobSpecCommand.java [65:137]
public ExitCode run() {
log.info("Resolving job specification");
final ObjectMapper prettyJsonMapper = GenieObjectMapper.getMapper()
.copy() // Don't reconfigure the shared mapper
.enable(SerializationFeature.INDENT_OUTPUT);
final JobSpecification spec;
final String jobId = resolveJobSpecCommandArguments.getSpecificationId();
if (!StringUtils.isBlank(jobId)) {
// Do a specification lookup if an id is given
log.info("Looking up specification of job {}", jobId);
try {
spec = agentJobService.getJobSpecification(jobId);
} catch (final JobSpecificationResolutionException e) {
throw new RuntimeException("Failed to get spec: " + jobId, e);
}
} else {
// Compose a job request from argument
final AgentJobRequest agentJobRequest;
try {
final ArgumentDelegates.JobRequestArguments jobArgs
= resolveJobSpecCommandArguments.getJobRequestArguments();
agentJobRequest = jobRequestConverter.agentJobRequestArgsToDTO(jobArgs);
} catch (final JobRequestConverter.ConversionException e) {
throw new RuntimeException("Failed to construct job request from arguments", e);
}
// Print request
if (!resolveJobSpecCommandArguments.isPrintRequestDisabled()) {
try {
System.out.println(prettyJsonMapper.writeValueAsString(agentJobRequest));
} catch (final JsonProcessingException e) {
throw new RuntimeException("Failed to map request to JSON", e);
}
}
// Resolve via service
try {
spec = agentJobService.resolveJobSpecificationDryRun(agentJobRequest);
} catch (final JobSpecificationResolutionException e) {
throw new RuntimeException("Failed to resolve job specification", e);
}
}
// Translate response to JSON
final String specJsonString;
try {
specJsonString = prettyJsonMapper.writeValueAsString(spec);
} catch (final JsonProcessingException e) {
throw new RuntimeException("Failed to map specification to JSON", e);
}
// Print specification
System.out.println(specJsonString);
// Write specification to file
final File outputFile = resolveJobSpecCommandArguments.getOutputFile();
if (outputFile != null) {
try {
Files.write(
outputFile.toPath(),
specJsonString.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE_NEW
);
} catch (final IOException e) {
throw new RuntimeException("Failed to write request to: " + outputFile.getAbsolutePath(), e);
}
}
return ExitCode.SUCCESS;
}