use of org.apache.nifi.web.api.entity.RegistryClientEntity in project nifi by apache.
the class UpdateRegistryClient method doExecute.
@Override
public VoidResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException, CommandException {
final ControllerClient controllerClient = client.getControllerClient();
final String id = getRequiredArg(properties, CommandOption.REGISTRY_CLIENT_ID);
final RegistryClientEntity existingRegClient = controllerClient.getRegistryClient(id);
if (existingRegClient == null) {
throw new CommandException("Registry client does not exist for id " + id);
}
final String name = getArg(properties, CommandOption.REGISTRY_CLIENT_NAME);
final String url = getArg(properties, CommandOption.REGISTRY_CLIENT_URL);
final String desc = getArg(properties, CommandOption.REGISTRY_CLIENT_DESC);
if (StringUtils.isBlank(name) && StringUtils.isBlank(url) && StringUtils.isBlank(desc)) {
throw new CommandException("Name, url, and desc were all blank, nothing to update");
}
if (StringUtils.isNotBlank(name)) {
existingRegClient.getComponent().setName(name);
}
if (StringUtils.isNotBlank(url)) {
existingRegClient.getComponent().setUri(url);
}
if (StringUtils.isNotBlank(desc)) {
existingRegClient.getComponent().setDescription(desc);
}
final String clientId = getContext().getSession().getNiFiClientID();
existingRegClient.getRevision().setClientId(clientId);
controllerClient.updateRegistryClient(existingRegClient);
return VoidResult.getInstance();
}
use of org.apache.nifi.web.api.entity.RegistryClientEntity in project nifi by apache.
the class RegistryClientsResult method writeSimpleResult.
@Override
protected void writeSimpleResult(final PrintStream output) {
final Set<RegistryClientEntity> clients = registryClients.getRegistries();
if (clients == null || clients.isEmpty()) {
return;
}
final List<RegistryDTO> registries = clients.stream().map(RegistryClientEntity::getComponent).sorted(Comparator.comparing(RegistryDTO::getName)).collect(Collectors.toList());
final Table table = new Table.Builder().column("#", 3, 3, false).column("Name", 20, 36, true).column("Id", 36, 36, false).column("Uri", 3, Integer.MAX_VALUE, false).build();
for (int i = 0; i < registries.size(); i++) {
RegistryDTO r = registries.get(i);
table.addRow("" + (i + 1), r.getName(), r.getId(), r.getUri());
}
final TableWriter tableWriter = new DynamicTableWriter();
tableWriter.write(table, output);
}
use of org.apache.nifi.web.api.entity.RegistryClientEntity 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.entity.RegistryClientEntity in project nifi by apache.
the class ControllerResource method getRegistryClients.
// ----------
// registries
// ----------
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("registry-clients")
@ApiOperation(value = "Gets the listing of available registry clients", response = RegistryClientsEntity.class, authorizations = { @Authorization(value = "Read - /flow") })
@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 getRegistryClients() {
authorizeController(RequestAction.READ);
if (isReplicateRequest()) {
return replicate(HttpMethod.GET);
}
final Set<RegistryClientEntity> registries = serviceFacade.getRegistryClients();
registries.forEach(registry -> populateRemainingRegistryEntityContent(registry));
final RegistryClientsEntity registryEntities = new RegistryClientsEntity();
registryEntities.setRegistries(registries);
return generateOkResponse(registryEntities).build();
}
use of org.apache.nifi.web.api.entity.RegistryClientEntity in project nifi by apache.
the class ControllerResource method deleteRegistryClient.
/**
* Removes the specified registry.
*
* @param httpServletRequest request
* @param version The revision is used to verify the client is working with
* the latest version of the flow.
* @param clientId Optional client id. If the client id is not specified, a
* new one will be generated. This value (whether specified or generated) is
* included in the response.
* @param id The id of the registry to remove.
* @return A entity containing the client id and an updated revision.
*/
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("/registry-clients/{id}")
@ApiOperation(value = "Deletes 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 deleteRegistryClient(@Context HttpServletRequest httpServletRequest, @ApiParam(value = "The revision is used to verify the client is working with the latest version of the flow.", required = false) @QueryParam(VERSION) final LongParameter version, @ApiParam(value = "If the client id is not specified, new one will be generated. This value (whether specified or generated) is included in the response.", required = false) @QueryParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) final ClientIdParameter clientId, @ApiParam(value = "The registry id.", required = true) @PathParam("id") final String id) {
if (isReplicateRequest()) {
return replicate(HttpMethod.DELETE);
}
final RegistryClientEntity requestRegistryClientEntity = new RegistryClientEntity();
requestRegistryClientEntity.setId(id);
// handle expects request (usually from the cluster manager)
final Revision requestRevision = new Revision(version == null ? null : version.getLong(), clientId.getClientId(), id);
return withWriteLock(serviceFacade, requestRegistryClientEntity, requestRevision, lookup -> {
authorizeController(RequestAction.WRITE);
}, () -> serviceFacade.verifyDeleteRegistry(id), (revision, registryEntity) -> {
// delete the specified registry
final RegistryClientEntity entity = serviceFacade.deleteRegistryClient(revision, registryEntity.getId());
return generateOkResponse(entity).build();
});
}
Aggregations