use of org.apache.zookeeper.server.jersey.jaxb.ZError in project zookeeper by apache.
the class ZNodeResource method deleteZNode.
@DELETE
@Produces({ MediaType.APPLICATION_JSON, "application/javascript", MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
public void deleteZNode(@PathParam("path") String path, @DefaultValue("-1") @QueryParam("version") String versionParam, @Context UriInfo ui) throws InterruptedException, KeeperException {
ensurePathNotNull(path);
int version;
try {
version = Integer.parseInt(versionParam);
} catch (NumberFormatException e) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad version " + versionParam)).build());
}
zk.delete(path, version);
}
use of org.apache.zookeeper.server.jersey.jaxb.ZError in project zookeeper by apache.
the class ZNodeResource method setZNodeAsOctet.
@PUT
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public void setZNodeAsOctet(@PathParam("path") String path, @DefaultValue("-1") @QueryParam("version") String versionParam, @DefaultValue("false") @QueryParam("null") String setNull, @Context UriInfo ui, byte[] data) throws InterruptedException, KeeperException {
ensurePathNotNull(path);
int version;
try {
version = Integer.parseInt(versionParam);
} catch (NumberFormatException e) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad version " + versionParam)).build());
}
if (setNull.equals("true")) {
data = null;
}
zk.setData(path, data, version);
}
use of org.apache.zookeeper.server.jersey.jaxb.ZError in project zookeeper by apache.
the class SessionsResource method createSession.
@POST
@Produces({ MediaType.APPLICATION_JSON, "application/javascript", MediaType.APPLICATION_XML })
public Response createSession(@QueryParam("op") String op, @DefaultValue("5") @QueryParam("expire") String expire, @Context UriInfo ui) {
if (!op.equals("create")) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), "")).build());
}
int expireInSeconds;
try {
expireInSeconds = Integer.parseInt(expire);
} catch (NumberFormatException e) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).build());
}
String uuid = UUID.randomUUID().toString();
while (ZooKeeperService.isConnected(contextPath, uuid)) {
uuid = UUID.randomUUID().toString();
}
// establish the connection to the ZooKeeper cluster
try {
ZooKeeperService.getClient(contextPath, uuid, expireInSeconds);
} catch (IOException e) {
LOG.error("Failed while trying to create a new session", e);
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).build());
}
URI uri = ui.getAbsolutePathBuilder().path(uuid).build();
return Response.created(uri).entity(new JSONWithPadding(new ZSession(uuid, uri.toString()))).build();
}
use of org.apache.zookeeper.server.jersey.jaxb.ZError 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.zookeeper.server.jersey.jaxb.ZError 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();
}
Aggregations