use of com.hubspot.singularity.SingularitySandboxFile in project Singularity by HubSpot.
the class SandboxResource method browse.
@GET
@Path("/{taskId}/browse")
@ApiOperation("Retrieve information about a specific task's sandbox.")
public SingularitySandbox browse(@Auth SingularityUser user, @ApiParam("The task ID to browse") @PathParam("taskId") String taskId, @ApiParam("The path to browse from") @QueryParam("path") String path) {
authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.READ);
// Remove all trailing slashes from the path
if (path != null) {
path = path.replaceAll("\\/+$", "");
}
final String currentDirectory = getCurrentDirectory(taskId, path);
final SingularityTaskHistory history = checkHistory(taskId, user);
final String slaveHostname = history.getTask().getHostname();
final String pathToRoot = history.getDirectory().get();
final String fullPath = new File(pathToRoot, currentDirectory).toString();
final int substringTruncationLength = currentDirectory.length() == 0 ? pathToRoot.length() + 1 : pathToRoot.length() + currentDirectory.length() + 2;
try {
Collection<MesosFileObject> mesosFiles = sandboxManager.browse(slaveHostname, fullPath);
List<SingularitySandboxFile> sandboxFiles = Lists.newArrayList(Iterables.transform(mesosFiles, new Function<MesosFileObject, SingularitySandboxFile>() {
@Override
public SingularitySandboxFile apply(MesosFileObject input) {
return new SingularitySandboxFile(input.getPath().substring(substringTruncationLength), input.getMtime(), input.getSize(), input.getMode());
}
}));
return new SingularitySandbox(sandboxFiles, pathToRoot, currentDirectory, slaveHostname);
} catch (SlaveNotFoundException snfe) {
throw notFound("Slave @ %s was not found, it is probably offline", slaveHostname);
}
}
Aggregations