use of javax.ws.rs.PUT in project pulsar by yahoo.
the class Properties method createProperty.
@PUT
@Path("/{property}")
@ApiOperation(value = "Create a new property.", notes = "This operation requires Pulsar super-user privileges.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 409, message = "Property already exist"), @ApiResponse(code = 412, message = "Property name is not valid") })
public void createProperty(@PathParam("property") String property, PropertyAdmin config) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
try {
NamedEntity.checkName(property);
zkCreate(path("policies", property), jsonMapper().writeValueAsBytes(config));
log.info("[{}] Created property {}", clientAppId(), property);
} catch (KeeperException.NodeExistsException e) {
log.warn("[{}] Failed to create already existing property {}", clientAppId(), property);
throw new RestException(Status.CONFLICT, "Property already exist");
} catch (IllegalArgumentException e) {
log.warn("[{}] Failed to create property with invalid name {}", clientAppId(), property, e);
throw new RestException(Status.PRECONDITION_FAILED, "Property name is not valid");
} catch (Exception e) {
log.error("[{}] Failed to create property {}", clientAppId(), property, e);
throw new RestException(e);
}
}
use of javax.ws.rs.PUT in project pulsar by yahoo.
the class Namespaces method unloadNamespaceBundle.
@PUT
@Path("/{property}/{cluster}/{namespace}/{bundle}/unload")
@ApiOperation(value = "Unload a namespace bundle")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
public void unloadNamespaceBundle(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
log.info("[{}] Unloading namespace bundle {}/{}/{}/{}", clientAppId(), property, cluster, namespace, bundleRange);
validateSuperUserAccess();
Policies policies = getNamespacePolicies(property, cluster, namespace);
if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) {
validateClusterOwnership(cluster);
validateClusterForProperty(property, cluster);
}
NamespaceName fqnn = new NamespaceName(property, cluster, namespace);
validatePoliciesReadOnlyAccess();
NamespaceBundle nsBundle = validateNamespaceBundleOwnership(fqnn, policies.bundles, bundleRange, authoritative, true);
try {
pulsar().getNamespaceService().unloadNamespaceBundle(nsBundle);
log.info("[{}] Successfully unloaded namespace bundle {}", clientAppId(), nsBundle.toString());
} catch (Exception e) {
log.error("[{}] Failed to unload namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e);
throw new RestException(e);
}
}
use of javax.ws.rs.PUT in project pulsar by yahoo.
the class Namespaces method splitNamespaceBundle.
@PUT
@Path("/{property}/{cluster}/{namespace}/{bundle}/split")
@ApiOperation(value = "Split a namespace bundle")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
public void splitNamespaceBundle(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("bundle") String bundleRange, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
log.info("[{}] Split namespace bundle {}/{}/{}/{}", clientAppId(), property, cluster, namespace, bundleRange);
validateSuperUserAccess();
Policies policies = getNamespacePolicies(property, cluster, namespace);
if (!cluster.equals(Namespaces.GLOBAL_CLUSTER)) {
validateClusterOwnership(cluster);
validateClusterForProperty(property, cluster);
}
NamespaceName fqnn = new NamespaceName(property, cluster, namespace);
validatePoliciesReadOnlyAccess();
NamespaceBundle nsBundle = validateNamespaceBundleOwnership(fqnn, policies.bundles, bundleRange, authoritative, true);
try {
pulsar().getNamespaceService().splitAndOwnBundle(nsBundle).get();
log.info("[{}] Successfully split namespace bundle {}", clientAppId(), nsBundle.toString());
} catch (Exception e) {
log.error("[{}] Failed to split namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e);
throw new RestException(e);
}
}
use of javax.ws.rs.PUT in project nhin-d by DirectProject.
the class AddressResource method addAddress.
/**
* Adds an address to the system and associates it with a domain.
* @param uriInfo Injected URI context used for building the location URI.
* @param address The address to add.
* @return Returns status 201 if added successfully, 404 if the domain does not exist, or 409 if
* the address already exists.
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response addAddress(@Context UriInfo uriInfo, Address address) {
// make sure the domain exists
if (address.getDomainName() == null || address.getDomainName().isEmpty())
return Response.status(Status.BAD_REQUEST).cacheControl(noCache).build();
org.nhindirect.config.store.Domain domain;
try {
domain = domainDao.getDomainByName(address.getDomainName());
if (domain == null)
return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error looking up existing domain.", e);
return Response.serverError().cacheControl(noCache).build();
}
// check to see if it already exists
try {
if (dao.get(address.getEmailAddress()) != null)
return Response.status(Status.CONFLICT).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error looking up existing address.", e);
return Response.serverError().cacheControl(noCache).build();
}
final org.nhindirect.config.store.Address toAdd = EntityModelConversion.toEntityAddress(address);
toAdd.setDomain(domain);
try {
dao.add(toAdd);
final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
final URI newLoc = newLocBuilder.path("address/" + address.getEmailAddress()).build();
return Response.created(newLoc).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error adding address.", e);
return Response.serverError().cacheControl(noCache).build();
}
}
use of javax.ws.rs.PUT in project nhin-d by DirectProject.
the class AnchorResource method addAnchor.
/**
* Adds an anchor to the system.
* @param uriInfo Injected URI context used for building the location URI.
* @param anchor The anchor to add to the system.
* @return Returns a status of 201 if the anchor was added, or a status of 409 if the anchor already exists for
* a specific owner.
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response addAnchor(@Context UriInfo uriInfo, Anchor anchor) {
// check to see if it already exists
try {
final String thumbprint = (anchor.getThumbprint() == null || anchor.getThumbprint().isEmpty()) ? Thumbprint.toThumbprint(anchor.getAnchorAsX509Certificate()).toString() : anchor.getThumbprint();
final Collection<org.nhindirect.config.store.Anchor> existingAnchors = anchorDao.list(Arrays.asList(anchor.getOwner()));
for (org.nhindirect.config.store.Anchor existingAnchor : existingAnchors) {
if (existingAnchor.getThumbprint().equalsIgnoreCase(thumbprint))
return Response.status(Status.CONFLICT).cacheControl(noCache).build();
}
} catch (Exception e) {
log.error("Error looking up existing anchor.", e);
return Response.serverError().cacheControl(noCache).build();
}
try {
anchorDao.add(EntityModelConversion.toEntityAnchor(anchor));
final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
final URI newLoc = newLocBuilder.path("anchor/" + anchor.getOwner()).build();
return Response.created(newLoc).cacheControl(noCache).build();
} catch (Exception e) {
log.error("Error adding anchor.", e);
return Response.serverError().cacheControl(noCache).build();
}
}
Aggregations