Search in sources :

Example 1 with IgfsControlResponse

use of org.apache.ignite.internal.igfs.common.IgfsControlResponse in project ignite by apache.

the class IgfsIpcHandler method processPathControlRequest.

/**
 * Processes path control request.
 *
 * @param ses Session.
 * @param cmd Command.
 * @param msg Message.
 * @return Response message.
 * @throws IgniteCheckedException If failed.
 */
private IgfsMessage processPathControlRequest(final IgfsClientSession ses, final IgfsIpcCommand cmd, IgfsMessage msg) throws IgniteCheckedException {
    final IgfsPathControlRequest req = (IgfsPathControlRequest) msg;
    if (log.isDebugEnabled())
        log.debug("Processing path control request [igfsName=" + igfs.name() + ", req=" + req + ']');
    final IgfsControlResponse res = new IgfsControlResponse();
    final String userName = req.userName();
    assert userName != null;
    try {
        IgfsUserContext.doAs(userName, new IgniteOutClosure<Object>() {

            @Override
            public Void apply() {
                switch(cmd) {
                    case EXISTS:
                        res.response(igfs.exists(req.path()));
                        break;
                    case INFO:
                        res.response(igfs.info(req.path()));
                        break;
                    case PATH_SUMMARY:
                        res.response(igfs.summary(req.path()));
                        break;
                    case UPDATE:
                        res.response(igfs.update(req.path(), req.properties()));
                        break;
                    case RENAME:
                        igfs.rename(req.path(), req.destinationPath());
                        res.response(true);
                        break;
                    case DELETE:
                        res.response(igfs.delete(req.path(), req.flag()));
                        break;
                    case MAKE_DIRECTORIES:
                        igfs.mkdirs(req.path(), req.properties());
                        res.response(true);
                        break;
                    case LIST_PATHS:
                        res.paths(igfs.listPaths(req.path()));
                        break;
                    case LIST_FILES:
                        res.files(igfs.listFiles(req.path()));
                        break;
                    case SET_TIMES:
                        igfs.setTimes(req.path(), req.modificationTime(), req.accessTime());
                        res.response(true);
                        break;
                    case AFFINITY:
                        res.locations(igfs.affinity(req.path(), req.start(), req.length()));
                        break;
                    case OPEN_READ:
                        {
                            IgfsInputStream igfsIn = !req.flag() ? igfs.open(req.path(), bufSize) : igfs.open(req.path(), bufSize, req.sequentialReadsBeforePrefetch());
                            long streamId = registerResource(ses, igfsIn);
                            if (log.isDebugEnabled())
                                log.debug("Opened IGFS input stream for file read [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
                            res.response(new IgfsInputStreamDescriptor(streamId, igfsIn.length()));
                            break;
                        }
                    case OPEN_CREATE:
                        {
                            long streamId = registerResource(ses, igfs.create(// Path.
                            req.path(), // Buffer size.
                            bufSize, // Overwrite if exists.
                            req.flag(), // Affinity key based on replication factor.
                            affinityKey(req), // Replication factor.
                            req.replication(), // Block size.
                            req.blockSize(), // File properties.
                            req.properties()));
                            if (log.isDebugEnabled())
                                log.debug("Opened IGFS output stream for file create [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
                            res.response(streamId);
                            break;
                        }
                    case OPEN_APPEND:
                        {
                            long streamId = registerResource(ses, igfs.append(// Path.
                            req.path(), // Buffer size.
                            bufSize, // Create if absent.
                            req.flag(), // File properties.
                            req.properties()));
                            if (log.isDebugEnabled())
                                log.debug("Opened IGFS output stream for file append [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
                            res.response(streamId);
                            break;
                        }
                    default:
                        assert false : "Unhandled path control request command: " + cmd;
                        break;
                }
                return null;
            }
        });
    } catch (IgniteException e) {
        throw new IgniteCheckedException(e);
    }
    if (log.isDebugEnabled())
        log.debug("Finished processing path control request [igfsName=" + igfs.name() + ", req=" + req + ", res=" + res + ']');
    return res;
}
Also used : IgfsInputStream(org.apache.ignite.igfs.IgfsInputStream) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgfsPathControlRequest(org.apache.ignite.internal.igfs.common.IgfsPathControlRequest) IgfsControlResponse(org.apache.ignite.internal.igfs.common.IgfsControlResponse)

Example 2 with IgfsControlResponse

use of org.apache.ignite.internal.igfs.common.IgfsControlResponse in project ignite by apache.

the class IgfsIpcHandler method processStatusRequest.

/**
 * Processes status request.
 *
 * @return Status response.
 * @throws IgniteCheckedException If failed.
 */
private IgfsMessage processStatusRequest() throws IgniteCheckedException {
    IgfsStatus status = igfs.globalSpace();
    IgfsControlResponse res = new IgfsControlResponse();
    res.status(status);
    return res;
}
Also used : IgfsControlResponse(org.apache.ignite.internal.igfs.common.IgfsControlResponse)

Example 3 with IgfsControlResponse

use of org.apache.ignite.internal.igfs.common.IgfsControlResponse in project ignite by apache.

the class IgfsIpcHandler method processHandshakeRequest.

/**
 * Processes handshake request.
 *
 * @param req Handshake request.
 * @return Response message.
 * @throws IgniteCheckedException In case of handshake failure.
 */
private IgfsMessage processHandshakeRequest(IgfsHandshakeRequest req) throws IgniteCheckedException {
    if (req.igfsName() != null && !F.eq(igfs.name(), req.igfsName()))
        throw new IgniteCheckedException("Failed to perform handshake because existing IGFS name " + "differs from requested [requested=" + req.igfsName() + ", existing=" + igfs.name() + ']');
    IgfsControlResponse res = new IgfsControlResponse();
    igfs.clientLogDirectory(req.logDirectory());
    IgfsHandshakeResponse handshake = new IgfsHandshakeResponse(igfs.name(), igfs.groupBlockSize(), igfs.globalSampling());
    res.handshake(handshake);
    return res;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgfsControlResponse(org.apache.ignite.internal.igfs.common.IgfsControlResponse)

Example 4 with IgfsControlResponse

use of org.apache.ignite.internal.igfs.common.IgfsControlResponse in project ignite by apache.

the class IgfsIpcHandler method processStreamControlRequest.

/**
 * Processes stream control request.
 *
 * @param ses Session.
 * @param cmd Command.
 * @param msg Message.
 * @param in Data input to read.
 * @return Response message if needed.
 * @throws IgniteCheckedException If failed.
 * @throws IOException If failed.
 */
private IgfsMessage processStreamControlRequest(IgfsClientSession ses, IgfsIpcCommand cmd, IgfsMessage msg, DataInput in) throws IgniteCheckedException, IOException {
    IgfsStreamControlRequest req = (IgfsStreamControlRequest) msg;
    Long rsrcId = req.streamId();
    IgfsControlResponse resp = new IgfsControlResponse();
    switch(cmd) {
        case CLOSE:
            {
                Closeable res = resource(ses, rsrcId);
                if (log.isDebugEnabled())
                    log.debug("Requested to close resource [igfsName=" + igfs.name() + ", rsrcId=" + rsrcId + ", res=" + res + ']');
                if (res == null)
                    throw new IgniteCheckedException("Resource to close not found: " + rsrcId);
                try {
                    res.close();
                } catch (IOException e) {
                    // Unwrap OutOfSpaceException, if has one.
                    IgfsOutOfSpaceException space = X.cause(e, IgfsOutOfSpaceException.class);
                    if (space != null)
                        throw space;
                    throw e;
                }
                boolean success = ses.unregisterResource(rsrcId, res);
                assert success : "Failed to unregister resource [igfsName=" + igfs.name() + ", rsrcId=" + rsrcId + ", res=" + res + ']';
                if (log.isDebugEnabled())
                    log.debug("Closed IGFS stream [igfsName=" + igfs.name() + ", streamId=" + rsrcId + ", ses=" + ses + ']');
                resp.response(true);
                break;
            }
        case READ_BLOCK:
            {
                long pos = req.position();
                int size = req.length();
                IgfsInputStreamImpl igfsIn = (IgfsInputStreamImpl) resource(ses, rsrcId);
                if (igfsIn == null)
                    throw new IgniteCheckedException("Input stream not found (already closed?): " + rsrcId);
                byte[][] chunks = igfsIn.readChunks(pos, size);
                resp.response(chunks);
                // Calculate number of read bytes.
                // len = len(first) + (n - 2) * len(block) + len(last).
                int len = 0;
                if (chunks.length > 0)
                    len += chunks[0].length;
                if (chunks.length > 1)
                    len += chunks[chunks.length - 1].length;
                if (chunks.length > 2)
                    len += chunks[1].length * (chunks.length - 2);
                resp.length(len);
                break;
            }
        case WRITE_BLOCK:
            {
                IgfsOutputStream out = (IgfsOutputStream) resource(ses, rsrcId);
                if (out == null)
                    throw new IgniteCheckedException("Output stream not found (already closed?): " + rsrcId);
                int writeLen = req.length();
                try {
                    out.transferFrom(in, writeLen);
                    if (errWrite)
                        throw new IOException("Failed to write data to server (test).");
                    // No response needed.
                    return null;
                } catch (IOException e) {
                    resp.error(rsrcId, e.getMessage());
                    break;
                }
            }
        default:
            assert false;
            break;
    }
    return resp;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Closeable(java.io.Closeable) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgfsStreamControlRequest(org.apache.ignite.internal.igfs.common.IgfsStreamControlRequest) IOException(java.io.IOException) IgfsOutOfSpaceException(org.apache.ignite.igfs.IgfsOutOfSpaceException) IgfsControlResponse(org.apache.ignite.internal.igfs.common.IgfsControlResponse) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 5 with IgfsControlResponse

use of org.apache.ignite.internal.igfs.common.IgfsControlResponse in project ignite by apache.

the class IgfsIpcHandler method processModeResolver.

/**
 * Process mode resolver request.
 *
 * @return Status response.
 */
private IgfsMessage processModeResolver() {
    IgfsControlResponse res = new IgfsControlResponse();
    res.modeResolver(((IgfsImpl) igfs).modeResolver());
    return res;
}
Also used : IgfsControlResponse(org.apache.ignite.internal.igfs.common.IgfsControlResponse)

Aggregations

IgfsControlResponse (org.apache.ignite.internal.igfs.common.IgfsControlResponse)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IgniteException (org.apache.ignite.IgniteException)1 IgfsInputStream (org.apache.ignite.igfs.IgfsInputStream)1 IgfsOutOfSpaceException (org.apache.ignite.igfs.IgfsOutOfSpaceException)1 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)1 IgfsPathControlRequest (org.apache.ignite.internal.igfs.common.IgfsPathControlRequest)1 IgfsStreamControlRequest (org.apache.ignite.internal.igfs.common.IgfsStreamControlRequest)1