Search in sources :

Example 1 with Pair

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);
        }
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) InferenceException(io.hops.hopsworks.exceptions.InferenceException) IOException(java.io.IOException) Pair(io.hops.common.Pair)

Example 2 with Pair

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);
}
Also used : Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) Pair(io.hops.common.Pair)

Example 3 with Pair

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));
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) Pair(io.hops.common.Pair) Stack(java.util.Stack)

Aggregations

Pair (io.hops.common.Pair)3 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)2 InferenceException (io.hops.hopsworks.exceptions.InferenceException)1 IOException (java.io.IOException)1 Stack (java.util.Stack)1 Path (org.apache.hadoop.fs.Path)1 HttpEntity (org.apache.http.HttpEntity)1