Search in sources :

Example 16 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader in project zookeeper by apache.

the class ZooKeeper method multiInternal.

protected void multiInternal(MultiTransactionRecord request, MultiCallback cb, Object ctx) {
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.multi);
    MultiResponse response = new MultiResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, null, null, ctx, null);
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) RequestHeader(org.apache.zookeeper.proto.RequestHeader)

Example 17 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader in project zookeeper by apache.

the class ZooKeeperAdmin method reconfigure.

/**
     * The Asynchronous version of reconfig.
     *
     * @see #reconfigure
     *
     **/
public void reconfigure(String joiningServers, String leavingServers, String newMembers, long fromConfig, DataCallback cb, Object ctx) {
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.reconfig);
    ReconfigRequest request = new ReconfigRequest(joiningServers, leavingServers, newMembers, fromConfig);
    GetDataResponse response = new GetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, ZooDefs.CONFIG_NODE, ZooDefs.CONFIG_NODE, ctx, null);
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) RequestHeader(org.apache.zookeeper.proto.RequestHeader) GetDataResponse(org.apache.zookeeper.proto.GetDataResponse) ReconfigRequest(org.apache.zookeeper.proto.ReconfigRequest)

Example 18 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader in project zookeeper by apache.

the class NIOServerCnxn method process.

/*
     * (non-Javadoc)
     *
     * @see org.apache.zookeeper.server.ServerCnxnIface#process(org.apache.zookeeper.proto.WatcherEvent)
     */
@Override
public void process(WatchedEvent event) {
    ReplyHeader h = new ReplyHeader(-1, -1L, 0);
    if (LOG.isTraceEnabled()) {
        ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK, "Deliver event " + event + " to 0x" + Long.toHexString(this.sessionId) + " through " + this);
    }
    // Convert WatchedEvent to a type that can be sent over the wire
    WatcherEvent e = event.getWrapper();
    sendResponse(h, e, "notification");
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) WatcherEvent(org.apache.zookeeper.proto.WatcherEvent)

Example 19 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader in project zookeeper by apache.

the class ZooKeeperServer method processPacket.

public void processPacket(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOException {
    // We have the request, now process and setup for next
    InputStream bais = new ByteBufferInputStream(incomingBuffer);
    BinaryInputArchive bia = BinaryInputArchive.getArchive(bais);
    RequestHeader h = new RequestHeader();
    h.deserialize(bia, "header");
    // Through the magic of byte buffers, txn will not be
    // pointing
    // to the start of the txn
    incomingBuffer = incomingBuffer.slice();
    if (h.getType() == OpCode.auth) {
        LOG.info("got auth packet " + cnxn.getRemoteSocketAddress());
        AuthPacket authPacket = new AuthPacket();
        ByteBufferInputStream.byteBuffer2Record(incomingBuffer, authPacket);
        String scheme = authPacket.getScheme();
        ServerAuthenticationProvider ap = ProviderRegistry.getServerProvider(scheme);
        Code authReturn = KeeperException.Code.AUTHFAILED;
        if (ap != null) {
            try {
                authReturn = ap.handleAuthentication(new ServerAuthenticationProvider.ServerObjs(this, cnxn), authPacket.getAuth());
            } catch (RuntimeException e) {
                LOG.warn("Caught runtime exception from AuthenticationProvider: " + scheme + " due to " + e);
                authReturn = KeeperException.Code.AUTHFAILED;
            }
        }
        if (authReturn == KeeperException.Code.OK) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Authentication succeeded for scheme: " + scheme);
            }
            LOG.info("auth success " + cnxn.getRemoteSocketAddress());
            ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.OK.intValue());
            cnxn.sendResponse(rh, null, null);
        } else {
            if (ap == null) {
                LOG.warn("No authentication provider for scheme: " + scheme + " has " + ProviderRegistry.listProviders());
            } else {
                LOG.warn("Authentication failed for scheme: " + scheme);
            }
            // send a response...
            ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.AUTHFAILED.intValue());
            cnxn.sendResponse(rh, null, null);
            // ... and close connection
            cnxn.sendBuffer(ServerCnxnFactory.closeConn);
            cnxn.disableRecv();
        }
        return;
    } else {
        if (h.getType() == OpCode.sasl) {
            Record rsp = processSasl(incomingBuffer, cnxn);
            ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.OK.intValue());
            // not sure about 3rd arg..what is it?
            cnxn.sendResponse(rh, rsp, "response");
        } else {
            Request si = new Request(cnxn, cnxn.getSessionId(), h.getXid(), h.getType(), incomingBuffer, cnxn.getAuthInfo());
            si.setOwner(ServerCnxn.me);
            // Always treat packet from the client as a possible
            // local request.
            setLocalSessionFlag(si);
            submitRequest(si);
        }
    }
    cnxn.incrOutstandingRequests(h);
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) InputStream(java.io.InputStream) ConnectRequest(org.apache.zookeeper.proto.ConnectRequest) GetSASLRequest(org.apache.zookeeper.proto.GetSASLRequest) ServerAuthenticationProvider(org.apache.zookeeper.server.auth.ServerAuthenticationProvider) Code(org.apache.zookeeper.KeeperException.Code) OpCode(org.apache.zookeeper.ZooDefs.OpCode) BinaryInputArchive(org.apache.jute.BinaryInputArchive) AuthPacket(org.apache.zookeeper.proto.AuthPacket) RequestHeader(org.apache.zookeeper.proto.RequestHeader) Record(org.apache.jute.Record)

Example 20 with ReplyHeader

use of org.apache.zookeeper.proto.ReplyHeader in project zookeeper by apache.

the class ReadOnlyRequestProcessor method run.

public void run() {
    try {
        while (!finished) {
            Request request = queuedRequests.take();
            // log request
            long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK;
            if (request.type == OpCode.ping) {
                traceMask = ZooTrace.CLIENT_PING_TRACE_MASK;
            }
            if (LOG.isTraceEnabled()) {
                ZooTrace.logRequest(LOG, traceMask, 'R', request, "");
            }
            if (Request.requestOfDeath == request) {
                break;
            }
            // filter read requests
            switch(request.type) {
                case OpCode.sync:
                case OpCode.create:
                case OpCode.create2:
                case OpCode.createTTL:
                case OpCode.createContainer:
                case OpCode.delete:
                case OpCode.deleteContainer:
                case OpCode.setData:
                case OpCode.reconfig:
                case OpCode.setACL:
                case OpCode.multi:
                case OpCode.check:
                    ReplyHeader hdr = new ReplyHeader(request.cxid, zks.getZKDatabase().getDataTreeLastProcessedZxid(), Code.NOTREADONLY.intValue());
                    try {
                        request.cnxn.sendResponse(hdr, null, null);
                    } catch (IOException e) {
                        LOG.error("IO exception while sending response", e);
                    }
                    continue;
            }
            // proceed to the next processor
            if (nextProcessor != null) {
                nextProcessor.processRequest(request);
            }
        }
    } catch (RequestProcessorException e) {
        if (e.getCause() instanceof XidRolloverException) {
            LOG.info(e.getCause().getMessage());
        }
        handleException(this.getName(), e);
    } catch (Exception e) {
        handleException(this.getName(), e);
    }
    LOG.info("ReadOnlyRequestProcessor exited loop!");
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) XidRolloverException(org.apache.zookeeper.server.quorum.Leader.XidRolloverException) Request(org.apache.zookeeper.server.Request) IOException(java.io.IOException) XidRolloverException(org.apache.zookeeper.server.quorum.Leader.XidRolloverException) IOException(java.io.IOException)

Aggregations

ReplyHeader (org.apache.zookeeper.proto.ReplyHeader)39 RequestHeader (org.apache.zookeeper.proto.RequestHeader)33 GetDataResponse (org.apache.zookeeper.proto.GetDataResponse)7 Record (org.apache.jute.Record)6 GetDataRequest (org.apache.zookeeper.proto.GetDataRequest)5 SetDataResponse (org.apache.zookeeper.proto.SetDataResponse)5 IOException (java.io.IOException)4 ExistsRequest (org.apache.zookeeper.proto.ExistsRequest)4 AuthPacket (org.apache.zookeeper.proto.AuthPacket)3 Create2Response (org.apache.zookeeper.proto.Create2Response)3 CreateResponse (org.apache.zookeeper.proto.CreateResponse)3 GetACLRequest (org.apache.zookeeper.proto.GetACLRequest)3 GetACLResponse (org.apache.zookeeper.proto.GetACLResponse)3 GetChildren2Request (org.apache.zookeeper.proto.GetChildren2Request)3 GetChildren2Response (org.apache.zookeeper.proto.GetChildren2Response)3 GetChildrenRequest (org.apache.zookeeper.proto.GetChildrenRequest)3 GetChildrenResponse (org.apache.zookeeper.proto.GetChildrenResponse)3 SetACLResponse (org.apache.zookeeper.proto.SetACLResponse)3 KeeperException (org.apache.zookeeper.KeeperException)2 Code (org.apache.zookeeper.KeeperException.Code)2