use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.CreateMode in project zookeeper by apache.
the class InstanceContainer method mknod.
private void mknod(String path, CreateMode mode) throws KeeperException, InterruptedException {
String[] subpath = path.split("/");
StringBuilder sb = new StringBuilder();
// We start at 1 because / will create an empty part first
for (int i = 1; i < subpath.length; i++) {
sb.append("/");
sb.append(subpath[i]);
CreateMode m = CreateMode.PERSISTENT;
if (i == subpath.length - 1) {
m = mode;
}
mknod_inner(sb.toString(), m);
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.CreateMode in project zookeeper by apache.
the class CreateTTLTest method testBadUsage.
@Test
public void testBadUsage() throws KeeperException, InterruptedException {
for (CreateMode createMode : CreateMode.values()) {
try {
zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode, new Stat(), createMode.isTTL() ? 0 : 100);
fail("should have thrown IllegalArgumentException");
} catch (IllegalArgumentException dummy) {
// correct
}
}
for (CreateMode createMode : CreateMode.values()) {
AsyncCallback.Create2Callback callback = (rc, path, ctx, name, stat) -> {
// NOP
};
try {
zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode, callback, null, createMode.isTTL() ? 0 : 100);
fail("should have thrown IllegalArgumentException");
} catch (IllegalArgumentException dummy) {
// correct
}
}
try {
Op op = Op.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, 0);
zk.multi(Collections.singleton(op));
fail("should have thrown IllegalArgumentException");
} catch (IllegalArgumentException dummy) {
// correct
}
try {
Op op = Op.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, 0);
zk.multi(Collections.singleton(op));
fail("should have thrown IllegalArgumentException");
} catch (IllegalArgumentException dummy) {
// correct
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.CreateMode in project zookeeper by apache.
the class ZNodeResource method createZNodeAsOctet.
@POST
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response createZNodeAsOctet(@PathParam("path") String path, @DefaultValue("create") @QueryParam("op") String op, @QueryParam("name") String name, @DefaultValue("false") @QueryParam("null") String setNull, @DefaultValue("false") @QueryParam("sequence") String sequence, @Context UriInfo ui, byte[] data) throws InterruptedException, KeeperException {
ensurePathNotNull(path);
if (path.equals("/")) {
path += name;
} else {
path += "/" + name;
}
if (!op.equals("create")) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad operaton " + op)).build());
}
if (setNull.equals("true")) {
data = null;
}
CreateMode createMode;
if (sequence.equals("true")) {
createMode = CreateMode.PERSISTENT_SEQUENTIAL;
} else {
createMode = CreateMode.PERSISTENT;
}
String newPath = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode);
URI uri = ui.getAbsolutePathBuilder().path(newPath).build();
return Response.created(uri).entity(new ZPath(newPath, ui.getAbsolutePath().toString())).build();
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.CreateMode in project zookeeper by apache.
the class ZNodeResource method createZNode.
@POST
@Produces({ MediaType.APPLICATION_JSON, "application/javascript", MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response createZNode(@PathParam("path") String path, @QueryParam("callback") String callback, @DefaultValue("create") @QueryParam("op") String op, @QueryParam("name") String name, @DefaultValue("base64") @QueryParam("dataformat") String dataformat, @DefaultValue("false") @QueryParam("null") String setNull, @DefaultValue("false") @QueryParam("sequence") String sequence, @DefaultValue("false") @QueryParam("ephemeral") String ephemeral, @Context UriInfo ui, byte[] data) throws InterruptedException, KeeperException {
ensurePathNotNull(path);
if (path.equals("/")) {
path += name;
} else {
path += "/" + name;
}
if (!op.equals("create")) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad operaton " + op)).build());
}
if (setNull.equals("true")) {
data = null;
}
CreateMode createMode;
if (sequence.equals("true")) {
if (ephemeral.equals("false")) {
createMode = CreateMode.PERSISTENT_SEQUENTIAL;
} else {
createMode = CreateMode.EPHEMERAL_SEQUENTIAL;
}
} else if (ephemeral.equals("false")) {
createMode = CreateMode.PERSISTENT;
} else {
createMode = CreateMode.EPHEMERAL;
}
String newPath = zk.create(path, data, Ids.OPEN_ACL_UNSAFE, createMode);
URI uri = ui.getAbsolutePathBuilder().path(newPath).build();
return Response.created(uri).entity(new JSONWithPadding(new ZPath(newPath, ui.getAbsolutePath().toString()))).build();
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.CreateMode in project tesb-rt-se by Talend.
the class EndpointNodeImpl method setExpiryTime.
@Override
public void setExpiryTime(Date expiryTime, boolean persistent) throws ServiceLocatorException, InterruptedException {
NodePath expNodePath = child(TIMETOLIVE);
String strTime = Long.toString(expiryTime.getTime());
byte[] content = strTime.getBytes(UTF8);
CreateMode mode = persistent ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL;
zkBackend.ensurePathExists(expNodePath, mode, content);
}
Aggregations