use of org.apache.nifi.web.api.dto.RegistryDTO in project nifi by apache.
the class TestRegistryClientResult method testWriteSimpleRegistryClientsResult.
@Test
public void testWriteSimpleRegistryClientsResult() throws IOException {
final RegistryDTO r1 = new RegistryDTO();
r1.setName("Registry 1");
r1.setUri("http://thisisalonglonglonglonglonglonglonglonglonguri.com:18080");
r1.setId(UUID.fromString("ea752054-22c6-4fc0-b851-967d9a3837cb").toString());
final RegistryDTO r2 = new RegistryDTO();
r2.setName("Registry 2 with a longer than usual name");
r2.setUri("http://localhost:18080");
r2.setId(UUID.fromString("ddf5f289-7502-46df-9798-4b0457c1816b").toString());
final RegistryClientEntity clientEntity1 = new RegistryClientEntity();
clientEntity1.setId(r1.getId());
clientEntity1.setComponent(r1);
final RegistryClientEntity clientEntity2 = new RegistryClientEntity();
clientEntity2.setId(r2.getId());
clientEntity2.setComponent(r2);
final Set<RegistryClientEntity> clientEntities = new HashSet<>();
clientEntities.add(clientEntity1);
clientEntities.add(clientEntity2);
final RegistryClientsEntity registryClientsEntity = new RegistryClientsEntity();
registryClientsEntity.setRegistries(clientEntities);
final RegistryClientsResult result = new RegistryClientsResult(ResultType.SIMPLE, registryClientsEntity);
result.write(printStream);
final String resultOut = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
// System.out.println(resultOut);
final String expected = "\n" + "# Name Id Uri \n" + "- ------------------------------------ ------------------------------------ --------------------------------------------------------------- \n" + "1 Registry 1 ea752054-22c6-4fc0-b851-967d9a3837cb http://thisisalonglonglonglonglonglonglonglonglonguri.com:18080 \n" + "2 Registry 2 with a longer than usu... ddf5f289-7502-46df-9798-4b0457c1816b http://localhost:18080 \n" + "\n";
Assert.assertEquals(expected, resultOut);
}
use of org.apache.nifi.web.api.dto.RegistryDTO 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