Search in sources :

Example 36 with PUT

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);
    }
}
Also used : RestException(com.yahoo.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) RestException(com.yahoo.pulsar.broker.web.RestException) KeeperException(org.apache.zookeeper.KeeperException) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 37 with PUT

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);
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) Policies(com.yahoo.pulsar.common.policies.data.Policies) PersistencePolicies(com.yahoo.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(com.yahoo.pulsar.common.policies.data.RetentionPolicies) RestException(com.yahoo.pulsar.broker.web.RestException) RestException(com.yahoo.pulsar.broker.web.RestException) WebApplicationException(javax.ws.rs.WebApplicationException) SubscriptionBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) KeeperException(org.apache.zookeeper.KeeperException) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 38 with PUT

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);
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) Policies(com.yahoo.pulsar.common.policies.data.Policies) PersistencePolicies(com.yahoo.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(com.yahoo.pulsar.common.policies.data.RetentionPolicies) RestException(com.yahoo.pulsar.broker.web.RestException) RestException(com.yahoo.pulsar.broker.web.RestException) WebApplicationException(javax.ws.rs.WebApplicationException) SubscriptionBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) KeeperException(org.apache.zookeeper.KeeperException) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 39 with PUT

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();
    }
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 40 with PUT

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();
    }
}
Also used : Anchor(org.nhindirect.config.model.Anchor) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

PUT (javax.ws.rs.PUT)203 Path (javax.ws.rs.Path)172 Consumes (javax.ws.rs.Consumes)108 Produces (javax.ws.rs.Produces)72 ApiOperation (io.swagger.annotations.ApiOperation)70 ApiResponses (io.swagger.annotations.ApiResponses)53 Timed (com.codahale.metrics.annotation.Timed)36 AuditEvent (org.graylog2.audit.jersey.AuditEvent)36 URI (java.net.URI)24 Response (javax.ws.rs.core.Response)23 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)19 IOException (java.io.IOException)18 BeanWrapper (org.springframework.beans.BeanWrapper)16 BadRequestException (javax.ws.rs.BadRequestException)14 NotFoundException (javax.ws.rs.NotFoundException)14 WebApplicationException (javax.ws.rs.WebApplicationException)12 UriBuilder (javax.ws.rs.core.UriBuilder)12 UUID (java.util.UUID)11 GET (javax.ws.rs.GET)11 POST (javax.ws.rs.POST)11