Search in sources :

Example 11 with RegistryClientEntity

use of org.apache.nifi.web.api.entity.RegistryClientEntity in project nifi by apache.

the class ControllerResource method updateRegistryClient.

/**
 * Updates the specified registry.
 *
 * @param httpServletRequest      request
 * @param id                      The id of the controller service to update.
 * @param requestRegistryEntity A controllerServiceEntity.
 * @return A controllerServiceEntity.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/registry-clients/{id}")
@ApiOperation(value = "Updates a registry client", response = RegistryClientEntity.class, authorizations = { @Authorization(value = "Write - /controller") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response updateRegistryClient(@Context HttpServletRequest httpServletRequest, @ApiParam(value = "The registry id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The registry configuration details.", required = true) final RegistryClientEntity requestRegistryEntity) {
    if (requestRegistryEntity == null || requestRegistryEntity.getComponent() == null) {
        throw new IllegalArgumentException("Registry details must be specified.");
    }
    if (requestRegistryEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }
    // ensure the ids are the same
    final RegistryDTO requestRegistryClient = requestRegistryEntity.getComponent();
    if (!id.equals(requestRegistryClient.getId())) {
        throw new IllegalArgumentException(String.format("The registry id (%s) in the request body does not equal the " + "registry id of the requested resource (%s).", requestRegistryClient.getId(), id));
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestRegistryEntity);
    }
    if (requestRegistryClient.getName() != null && StringUtils.isBlank(requestRegistryClient.getName())) {
        throw new IllegalArgumentException("Registry name must be specified.");
    }
    if (requestRegistryClient.getUri() != null && StringUtils.isBlank(requestRegistryClient.getUri())) {
        throw new IllegalArgumentException("Registry URL must be specified.");
    }
    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = getRevision(requestRegistryEntity, id);
    return withWriteLock(serviceFacade, requestRegistryEntity, requestRevision, lookup -> {
        authorizeController(RequestAction.WRITE);
    }, null, (revision, registryEntity) -> {
        final RegistryDTO registry = registryEntity.getComponent();
        // update the controller service
        final RegistryClientEntity entity = serviceFacade.updateRegistryClient(revision, registry);
        populateRemainingRegistryEntityContent(entity);
        return generateOkResponse(entity).build();
    });
}
Also used : Revision(org.apache.nifi.web.Revision) RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

RegistryClientEntity (org.apache.nifi.web.api.entity.RegistryClientEntity)11 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 RegistryDTO (org.apache.nifi.web.api.dto.RegistryDTO)5 Revision (org.apache.nifi.web.Revision)3 RegistryClientsEntity (org.apache.nifi.web.api.entity.RegistryClientsEntity)3 GET (javax.ws.rs.GET)2 StringResult (org.apache.nifi.toolkit.cli.impl.result.StringResult)2 HashSet (java.util.HashSet)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 MissingOptionException (org.apache.commons.cli.MissingOptionException)1 CommandException (org.apache.nifi.toolkit.cli.api.CommandException)1 ControllerClient (org.apache.nifi.toolkit.cli.impl.client.nifi.ControllerClient)1 FlowClient (org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient)1 NiFiClientException (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException)1