use of io.hops.common.Pair in project hopsworks by logicalclocks.
the class InferenceHttpClient method handleInferenceResponse.
/**
* Handles a HTTP response to an inference request. Parses the response into a tuple of (statusCode, responseStr)
*
* @param response the HTTP response to handle
* @return a tuple of (statusCode, responseStr)
* @throws InferenceException in case there was an error handling the response
*/
public Pair<Integer, String> handleInferenceResponse(CloseableHttpResponse response) throws InferenceException {
try {
if (response == null) {
throw new InferenceException(RESTCodes.InferenceErrorCode.EMPTY_RESPONSE, Level.INFO, "Received null response");
}
HttpEntity httpEntity = response.getEntity();
if (httpEntity == null) {
throw new InferenceException(RESTCodes.InferenceErrorCode.EMPTY_RESPONSE, Level.INFO, "Received null response");
}
try {
// Return prediction
String responseStr = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
return new Pair<>(response.getStatusLine().getStatusCode(), responseStr);
} catch (IOException e) {
throw new InferenceException(RESTCodes.InferenceErrorCode.ERROR_READING_RESPONSE, Level.INFO, "", e.getMessage(), e);
}
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException ioe) {
logger.log(Level.FINE, "Error closing response", ioe);
}
}
}
use of io.hops.common.Pair in project hopsworks by logicalclocks.
the class InodeController method getProjectAndDatasetRootForInode.
/**
* Get the project and dataset base directory of which the given Inode is a
* descendant.
* <p/>
* @param i
* @return The Inodes representing the project and dataset root directories.
* [ProjectInode, DatasetInode]
* @throws IllegalStateException when the given Inode is not under a project
* root directory.
*/
public Pair<Inode, Inode> getProjectAndDatasetRootForInode(Inode i) throws IllegalStateException {
Inode project = i;
Inode dataset = i;
do {
dataset = project;
project = inodeFacade.findParent(project);
if (project == null) {
throw new IllegalStateException("Transversing the path from folder did not encounter project root folder.");
}
} while (!isProjectRoot(project));
return new Pair<>(project, dataset);
}
use of io.hops.common.Pair in project hopsworks by logicalclocks.
the class DatasetController method recChangeOwnershipAndPermission.
public void recChangeOwnershipAndPermission(Path path, FsPermission permission, String username, String group, DistributedFileSystemOps dfso, DistributedFileSystemOps udfso) throws IOException {
// Set permission/ownership for the root
if (username != null && group != null && dfso != null) {
dfso.setOwner(path, username, group);
}
udfso.setPermission(path, permission);
Inode rootInode = inodeController.getInodeAtPath(path.toString());
// Keep a list of directories to avoid using recursion
// Remember also the path to avoid going to the database for path resolution
Stack<Pair<Inode, Path>> dirs = new Stack<>();
if (rootInode.isDir()) {
dirs.push(new Pair<>(rootInode, path));
}
while (!dirs.isEmpty()) {
Pair<Inode, Path> dirInode = dirs.pop();
for (Inode child : inodeController.getChildren(dirInode.getL())) {
Path childPath = new Path(dirInode.getR(), child.getInodePK().getName());
if (username != null && group != null && dfso != null) {
dfso.setOwner(childPath, username, group);
}
udfso.setPermission(childPath, permission);
if (child.isDir()) {
dirs.push(new Pair<>(child, childPath));
}
}
}
}
Aggregations