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();
});
}
Aggregations