Search in sources :

Example 21 with RequestHeader

use of org.apache.zookeeper_voltpatches.proto.RequestHeader in project voltdb by VoltDB.

the class ZooKeeper method setData.

/**
     * The Asynchronous version of setData. The request doesn't actually until
     * the asynchronous callback is called.
     *
     * @see #setData(String, byte[], int)
     */
public void setData(final String path, byte[] data, int version, StatCallback cb, Object ctx) {
    verbotenThreadCheck();
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setData);
    SetDataRequest request = new SetDataRequest();
    request.setPath(serverPath);
    request.setData(data);
    request.setVersion(version);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, clientPath, serverPath, ctx, null);
}
Also used : ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader) SetDataRequest(org.apache.zookeeper_voltpatches.proto.SetDataRequest) SetDataResponse(org.apache.zookeeper_voltpatches.proto.SetDataResponse)

Example 22 with RequestHeader

use of org.apache.zookeeper_voltpatches.proto.RequestHeader in project voltdb by VoltDB.

the class ZooKeeper method getACL.

/**
     * Return the ACL and stat of the node of the given path.
     * <p>
     * A KeeperException with error code KeeperException.NoNode will be thrown
     * if no node with the given path exists.
     *
     * @param path
     *            the given path for the node
     * @param stat
     *            the stat of the node will be copied to this parameter.
     * @return the ACL array of the given node.
     * @throws InterruptedException
     *             If the server transaction is interrupted.
     * @throws KeeperException
     *             If the server signals an error with a non-zero error code.
     * @throws IllegalArgumentException
     *             if an invalid path is specified
     */
public List<ACL> getACL(final String path, Stat stat) throws KeeperException, InterruptedException {
    verbotenThreadCheck();
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getACL);
    GetACLRequest request = new GetACLRequest();
    request.setPath(serverPath);
    GetACLResponse response = new GetACLResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath);
    }
    DataTree.copyStat(response.getStat(), stat);
    return response.getAcl();
}
Also used : ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) GetACLRequest(org.apache.zookeeper_voltpatches.proto.GetACLRequest) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader) GetACLResponse(org.apache.zookeeper_voltpatches.proto.GetACLResponse)

Example 23 with RequestHeader

use of org.apache.zookeeper_voltpatches.proto.RequestHeader in project voltdb by VoltDB.

the class ZooKeeper method create.

/**
     * Create a node with the given path. The node data will be the given data,
     * and node acl will be the given acl.
     * <p>
     * The flags argument specifies whether the created node will be ephemeral
     * or not.
     * <p>
     * An ephemeral node will be removed by the ZooKeeper automatically when the
     * session associated with the creation of the node expires.
     * <p>
     * The flags argument can also specify to create a sequential node. The
     * actual path name of a sequential node will be the given path plus a
     * suffix "i" where i is the current sequential number of the node. The
     * sequence number is always fixed length of 10 digits, 0 padded. Once such
     * a node is created, the sequential number will be incremented by one.
     * <p>
     * If a node with the same actual path already exists in the ZooKeeper, a
     * KeeperException with error code KeeperException.NodeExists will be
     * thrown. Note that since a different actual path is used for each
     * invocation of creating sequential node with the same path argument, the
     * call will never throw "file exists" KeeperException.
     * <p>
     * If the parent node does not exist in the ZooKeeper, a KeeperException
     * with error code KeeperException.NoNode will be thrown.
     * <p>
     * An ephemeral node cannot have children. If the parent node of the given
     * path is ephemeral, a KeeperException with error code
     * KeeperException.NoChildrenForEphemerals will be thrown.
     * <p>
     * This operation, if successful, will trigger all the watches left on the
     * node of the given path by exists and getData API calls, and the watches
     * left on the parent node by getChildren API calls.
     * <p>
     * If a node is created successfully, the ZooKeeper server will trigger the
     * watches on the path left by exists calls, and the watches on the parent
     * of the node by getChildren calls.
     * <p>
     * The maximum allowable size of the data array is 1 MB (1,048,576 bytes).
     * Arrays larger than this will cause a KeeperExecption to be thrown.
     *
     * @param path
     *            the path for the node
     * @param data
     *            the initial data for the node
     * @param acl
     *            the acl for the node
     * @param createMode
     *            specifying whether the node to be created is ephemeral and/or
     *            sequential
     * @return the actual path of the created node
     * @throws KeeperException
     *             if the server returns a non-zero error code
     * @throws KeeperException.InvalidACLException
     *             if the ACL is invalid, null, or empty
     * @throws InterruptedException
     *             if the transaction is interrupted
     * @throws IllegalArgumentException
     *             if an invalid path is specified
     */
public String create(final String path, byte[] data, List<ACL> acl, CreateMode createMode) throws KeeperException, InterruptedException {
    verbotenThreadCheck();
    final String clientPath = path;
    PathUtils.validatePath(clientPath, createMode.isSequential());
    final String serverPath = prependChroot(clientPath);
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.create);
    CreateRequest request = new CreateRequest();
    CreateResponse response = new CreateResponse();
    request.setData(data);
    request.setFlags(createMode.toFlag());
    request.setPath(serverPath);
    if (acl != null && acl.size() == 0) {
        throw new KeeperException.InvalidACLException();
    }
    request.setAcl(acl);
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath);
    }
    if (cnxn.chrootPath == null) {
        return response.getPath();
    } else {
        return response.getPath().substring(cnxn.chrootPath.length());
    }
}
Also used : ReplyHeader(org.apache.zookeeper_voltpatches.proto.ReplyHeader) CreateRequest(org.apache.zookeeper_voltpatches.proto.CreateRequest) CreateResponse(org.apache.zookeeper_voltpatches.proto.CreateResponse) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader)

Example 24 with RequestHeader

use of org.apache.zookeeper_voltpatches.proto.RequestHeader in project voltdb by VoltDB.

the class ClientCnxn method addAuthInfo.

public void addAuthInfo(String scheme, byte[] auth) {
    if (!zooKeeper.state.isAlive()) {
        return;
    }
    authInfo.add(new AuthData(scheme, auth));
    queuePacket(new RequestHeader(-4, OpCode.auth), null, new AuthPacket(0, scheme, auth), null, null, null, null, null, null);
}
Also used : AuthPacket(org.apache.zookeeper_voltpatches.proto.AuthPacket) RequestHeader(org.apache.zookeeper_voltpatches.proto.RequestHeader)

Aggregations

RequestHeader (org.apache.zookeeper_voltpatches.proto.RequestHeader)24 ReplyHeader (org.apache.zookeeper_voltpatches.proto.ReplyHeader)20 SetDataResponse (org.apache.zookeeper_voltpatches.proto.SetDataResponse)4 AuthPacket (org.apache.zookeeper_voltpatches.proto.AuthPacket)2 CreateRequest (org.apache.zookeeper_voltpatches.proto.CreateRequest)2 CreateResponse (org.apache.zookeeper_voltpatches.proto.CreateResponse)2 DeleteRequest (org.apache.zookeeper_voltpatches.proto.DeleteRequest)2 ExistsRequest (org.apache.zookeeper_voltpatches.proto.ExistsRequest)2 GetACLRequest (org.apache.zookeeper_voltpatches.proto.GetACLRequest)2 GetACLResponse (org.apache.zookeeper_voltpatches.proto.GetACLResponse)2 GetChildren2Request (org.apache.zookeeper_voltpatches.proto.GetChildren2Request)2 GetChildren2Response (org.apache.zookeeper_voltpatches.proto.GetChildren2Response)2 GetChildrenRequest (org.apache.zookeeper_voltpatches.proto.GetChildrenRequest)2 GetChildrenResponse (org.apache.zookeeper_voltpatches.proto.GetChildrenResponse)2 GetDataRequest (org.apache.zookeeper_voltpatches.proto.GetDataRequest)2 GetDataResponse (org.apache.zookeeper_voltpatches.proto.GetDataResponse)2 SetACLRequest (org.apache.zookeeper_voltpatches.proto.SetACLRequest)2 SetACLResponse (org.apache.zookeeper_voltpatches.proto.SetACLResponse)2 SetDataRequest (org.apache.zookeeper_voltpatches.proto.SetDataRequest)2 InputStream (java.io.InputStream)1