use of org.apache.nifi.web.api.dto.RegistryDTO in project nifi by apache.
the class ControllerResource method createRegistryClient.
/**
* Creates a new Registry.
*
* @param httpServletRequest request
* @param requestRegistryClientEntity A registryClientEntity.
* @return A registryClientEntity.
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("registry-clients")
@ApiOperation(value = "Creates a new 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 = 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 createRegistryClient(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The registry configuration details.", required = true) final RegistryClientEntity requestRegistryClientEntity) {
if (requestRegistryClientEntity == null || requestRegistryClientEntity.getComponent() == null) {
throw new IllegalArgumentException("Registry details must be specified.");
}
if (requestRegistryClientEntity.getRevision() == null || (requestRegistryClientEntity.getRevision().getVersion() == null || requestRegistryClientEntity.getRevision().getVersion() != 0)) {
throw new IllegalArgumentException("A revision of 0 must be specified when creating a new Registry.");
}
final RegistryDTO requestRegistryClient = requestRegistryClientEntity.getComponent();
if (requestRegistryClient.getId() != null) {
throw new IllegalArgumentException("Registry ID cannot be specified.");
}
if (StringUtils.isBlank(requestRegistryClient.getName())) {
throw new IllegalArgumentException("Registry name must be specified.");
}
if (StringUtils.isBlank(requestRegistryClient.getUri())) {
throw new IllegalArgumentException("Registry URL must be specified.");
}
if (isReplicateRequest()) {
return replicate(HttpMethod.POST, requestRegistryClientEntity);
}
return withWriteLock(serviceFacade, requestRegistryClientEntity, lookup -> {
authorizeController(RequestAction.WRITE);
}, null, (registryEntity) -> {
final RegistryDTO registry = registryEntity.getComponent();
// set the processor id as appropriate
registry.setId(generateUuid());
// create the reporting task and generate the json
final Revision revision = getRevision(registryEntity, registry.getId());
final RegistryClientEntity entity = serviceFacade.createRegistryClient(revision, registry);
populateRemainingRegistryEntityContent(entity);
// build the response
return generateCreatedResponse(URI.create(entity.getUri()), entity).build();
});
}
use of org.apache.nifi.web.api.dto.RegistryDTO in project nifi by apache.
the class CreateRegistryClient method doExecute.
@Override
public StringResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException {
final String name = getRequiredArg(properties, CommandOption.REGISTRY_CLIENT_NAME);
final String url = getRequiredArg(properties, CommandOption.REGISTRY_CLIENT_URL);
final String desc = getArg(properties, CommandOption.REGISTRY_CLIENT_DESC);
final RegistryDTO registryDTO = new RegistryDTO();
registryDTO.setName(name);
registryDTO.setUri(url);
registryDTO.setDescription(desc);
final RegistryClientEntity clientEntity = new RegistryClientEntity();
clientEntity.setComponent(registryDTO);
clientEntity.setRevision(getInitialRevisionDTO());
final RegistryClientEntity createdEntity = client.getControllerClient().createRegistryClient(clientEntity);
return new StringResult(createdEntity.getId(), getContext().isInteractive());
}
use of org.apache.nifi.web.api.dto.RegistryDTO in project nifi by apache.
the class StandardNiFiServiceFacade method createRegistryClientEntity.
private RegistryClientEntity createRegistryClientEntity(final FlowRegistry flowRegistry) {
if (flowRegistry == null) {
return null;
}
final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(flowRegistry.getIdentifier()));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(authorizableLookup.getController());
final RegistryDTO dto = dtoFactory.createRegistryDto(flowRegistry);
return entityFactory.createRegistryClientEntity(dto, revision, permissions);
}
use of org.apache.nifi.web.api.dto.RegistryDTO in project nifi by apache.
the class GetRegistryClientId method doExecute.
@Override
public RegistryClientIDResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, CommandException {
final String regClientName = getArg(properties, CommandOption.REGISTRY_CLIENT_NAME);
final String regClientUrl = getArg(properties, CommandOption.REGISTRY_CLIENT_URL);
if (!StringUtils.isBlank(regClientName) && !StringUtils.isBlank(regClientUrl)) {
throw new CommandException("Name and URL cannot be specified at the same time");
}
if (StringUtils.isBlank(regClientName) && StringUtils.isBlank(regClientUrl)) {
throw new CommandException("Name or URL must be specified");
}
final RegistryClientsEntity registries = client.getControllerClient().getRegistryClients();
RegistryDTO registry;
if (!StringUtils.isBlank(regClientName)) {
registry = registries.getRegistries().stream().map(r -> r.getComponent()).filter(r -> r.getName().equalsIgnoreCase(regClientName.trim())).findFirst().orElse(null);
} else {
registry = registries.getRegistries().stream().map(r -> r.getComponent()).filter(r -> r.getUri().equalsIgnoreCase(regClientUrl.trim())).findFirst().orElse(null);
}
if (registry == null) {
throw new NiFiClientException("No registry client exists with the name '" + regClientName + "'");
} else {
return new RegistryClientIDResult(getResultType(properties), registry);
}
}
use of org.apache.nifi.web.api.dto.RegistryDTO 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);
}
Aggregations