Skip to content

Commit

Permalink
fix(jobcontroller): better error message if property file not found o…
Browse files Browse the repository at this point in the history
…n job (#3783)

When we fail to find the props file specified for a titus task we get a cryptic
error message "cannot access first() element of empty list"
Propagate the actual error when the properties file can't be found
  • Loading branch information
marchello2000 committed Jun 14, 2019
1 parent b9b3dd0 commit cd9fb53
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.netflix.spinnaker.clouddriver.titus.TitusClientProvider
import com.netflix.spinnaker.clouddriver.titus.client.TitusClient
import com.netflix.spinnaker.clouddriver.titus.client.model.Job
import com.netflix.spinnaker.clouddriver.titus.model.TitusJobStatus
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException
import groovy.util.logging.Slf4j
import okhttp3.OkHttpClient
import okhttp3.Request
Expand Down Expand Up @@ -88,15 +89,13 @@ class TitusJobProvider implements JobProvider<TitusJobStatus> {
try {
amazonS3DataProvider.getAdhocData("titus", "${s3.accountName}:${s3.region}:${s3.bucket}", "${s3.key}/${fileName}", outputStream)
} catch (Exception e) {
log.warn("File [${fileName}] does not exist for job [${job.tasks.last().id}].")
return null
throw new NotFoundException("File [${fileName}] does not exist for job [${job.tasks.last().id}].", e)
}
fileContents = new ByteArrayInputStream(outputStream.toByteArray())
} else {
Map files = titusClient.logsDownload(job.tasks.last().id)
if (!files.containsKey(fileName)) {
log.warn("File [${fileName}] does not exist for job [${job.tasks.last().id}].")
return null
throw new NotFoundException("File [${fileName}] does not exist for job [${job.tasks.last().id}].")
}
fileContents = client.newCall(new Request.Builder().url(files.get(fileName) as String).build()).execute().body().byteStream()
}
Expand All @@ -113,9 +112,11 @@ class TitusJobProvider implements JobProvider<TitusJobStatus> {
propertiesFile.load(fileContents)
results = results << propertiesFile
}

return results
}
null

return Collections.emptyMap()
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,20 @@ class JobController {
@ApiOperation(value = "Collect a file from a job", notes = "Collects the file result of a job.")
@RequestMapping(value = "/{account}/{location}/{id}/{fileName:.+}", method = RequestMethod.GET)
Map<String, Object> getFileContents(
@ApiParam(value = "Application name", required = true) @PathVariable String application,
@ApiParam(value = "Account job was created by", required = true) @PathVariable String account,
@ApiParam(value = "Namespace, region, or zone job is running in", required = true) @PathVariable String location,
@ApiParam(value = "Unique identifier of job being looked up", required = true) @PathVariable String id,
@ApiParam(value = "File name to look up", required = true) @PathVariable String fileName
@ApiParam(value = "Application name", required = true) @PathVariable String application,
@ApiParam(value = "Account job was created by", required = true) @PathVariable String account,
@ApiParam(value = "Namespace, region, or zone job is running in", required = true) @PathVariable String location,
@ApiParam(value = "Unique identifier of job being looked up", required = true) @PathVariable String id,
@ApiParam(value = "File name to look up", required = true) @PathVariable String fileName
) {
jobProviders.findResults {
Collection<Map<String, Object>> results = jobProviders.findResults {
it.getFileContents(account, location, id, fileName)
}.first()
}

if (!results.isEmpty()) {
return results.first()
}

return Collections.emptyMap()
}
}

0 comments on commit cd9fb53

Please sign in to comment.