Search in sources :

Example 16 with RequestHeader

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

the class ZooKeeper method getConfig.

/**
     * Return the last committed configuration (as known to the server to which the client is connected)
     * and the stat of the configuration.
     * <p>
     * If the watch is non-null and the call is successful (no exception is
     * thrown), a watch will be left on the configuration node (ZooDefs.CONFIG_NODE). The watch
     * will be triggered by a successful reconfig operation
     * <p>
     * A KeeperException with error code KeeperException.NoNode will be thrown
     * if the configuration node doesn't exists.
     *
     * @param watcher explicit watcher
     * @param stat the stat of the configuration node ZooDefs.CONFIG_NODE
     * @return configuration data stored in ZooDefs.CONFIG_NODE
     * @throws KeeperException If the server signals an error with a non-zero error code
     * @throws InterruptedException If the server transaction is interrupted.
     */
public byte[] getConfig(Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
    final String configZnode = ZooDefs.CONFIG_NODE;
    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new DataWatchRegistration(watcher, configZnode);
    }
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getData);
    GetDataRequest request = new GetDataRequest();
    request.setPath(configZnode);
    request.setWatch(watcher != null);
    GetDataResponse response = new GetDataResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, wcb);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), configZnode);
    }
    if (stat != null) {
        DataTree.copyStat(response.getStat(), stat);
    }
    return response.getData();
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) RequestHeader(org.apache.zookeeper.proto.RequestHeader) GetDataResponse(org.apache.zookeeper.proto.GetDataResponse) GetDataRequest(org.apache.zookeeper.proto.GetDataRequest)

Example 17 with RequestHeader

use of org.apache.zookeeper.proto.RequestHeader 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 18 with RequestHeader

use of org.apache.zookeeper.proto.RequestHeader 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 19 with RequestHeader

use of org.apache.zookeeper.proto.RequestHeader 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 RequestHeader

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

the class WatchLeakTest method createWatchesMessage.

/**
     * Create a watches message with a single watch on /
     *
     * @return a message that attempts to set 1 watch on /
     */
private ByteBuffer createWatchesMessage() {
    List<String> dataWatches = new ArrayList<String>(1);
    dataWatches.add("/");
    List<String> existWatches = Collections.emptyList();
    List<String> childWatches = Collections.emptyList();
    SetWatches sw = new SetWatches(1L, dataWatches, existWatches, childWatches);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setWatches);
    h.setXid(-8);
    MockPacket p = new MockPacket(h, new ReplyHeader(), sw, null, null);
    return p.createAndReturnBB();
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) SetWatches(org.apache.zookeeper.proto.SetWatches) ArrayList(java.util.ArrayList) RequestHeader(org.apache.zookeeper.proto.RequestHeader) MockPacket(org.apache.zookeeper.MockPacket)

Aggregations

RequestHeader (org.apache.zookeeper.proto.RequestHeader)36 ReplyHeader (org.apache.zookeeper.proto.ReplyHeader)33 GetDataResponse (org.apache.zookeeper.proto.GetDataResponse)6 Record (org.apache.jute.Record)5 GetDataRequest (org.apache.zookeeper.proto.GetDataRequest)4 SetDataResponse (org.apache.zookeeper.proto.SetDataResponse)4 AuthPacket (org.apache.zookeeper.proto.AuthPacket)3 CreateRequest (org.apache.zookeeper.proto.CreateRequest)3 ExistsRequest (org.apache.zookeeper.proto.ExistsRequest)3 InputStream (java.io.InputStream)2 ConnectRequest (org.apache.zookeeper.proto.ConnectRequest)2 Create2Response (org.apache.zookeeper.proto.Create2Response)2 CreateResponse (org.apache.zookeeper.proto.CreateResponse)2 DeleteRequest (org.apache.zookeeper.proto.DeleteRequest)2 GetACLRequest (org.apache.zookeeper.proto.GetACLRequest)2 GetACLResponse (org.apache.zookeeper.proto.GetACLResponse)2 GetChildren2Request (org.apache.zookeeper.proto.GetChildren2Request)2 GetChildren2Response (org.apache.zookeeper.proto.GetChildren2Response)2 GetChildrenRequest (org.apache.zookeeper.proto.GetChildrenRequest)2 GetChildrenResponse (org.apache.zookeeper.proto.GetChildrenResponse)2