Search in sources :

Example 1 with RegistryDTO

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();
    });
}
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) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with RegistryDTO

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());
}
Also used : RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO)

Example 3 with RegistryDTO

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);
}
Also used : PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) VariableRegistryDTO(org.apache.nifi.web.api.dto.VariableRegistryDTO) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO)

Example 4 with RegistryDTO

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);
    }
}
Also used : NiFiClient(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient) Properties(java.util.Properties) RegistryClientsEntity(org.apache.nifi.web.api.entity.RegistryClientsEntity) NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) RegistryClientIDResult(org.apache.nifi.toolkit.cli.impl.result.RegistryClientIDResult) CommandOption(org.apache.nifi.toolkit.cli.impl.command.CommandOption) AbstractNiFiCommand(org.apache.nifi.toolkit.cli.impl.command.nifi.AbstractNiFiCommand) IOException(java.io.IOException) CommandException(org.apache.nifi.toolkit.cli.api.CommandException) StringUtils(org.apache.commons.lang3.StringUtils) Context(org.apache.nifi.toolkit.cli.api.Context) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO) NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) RegistryClientsEntity(org.apache.nifi.web.api.entity.RegistryClientsEntity) RegistryClientIDResult(org.apache.nifi.toolkit.cli.impl.result.RegistryClientIDResult) CommandException(org.apache.nifi.toolkit.cli.api.CommandException) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO)

Example 5 with RegistryDTO

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);
}
Also used : Table(org.apache.nifi.toolkit.cli.impl.result.writer.Table) DynamicTableWriter(org.apache.nifi.toolkit.cli.impl.result.writer.DynamicTableWriter) TableWriter(org.apache.nifi.toolkit.cli.impl.result.writer.TableWriter) RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO) DynamicTableWriter(org.apache.nifi.toolkit.cli.impl.result.writer.DynamicTableWriter)

Aggregations

RegistryDTO (org.apache.nifi.web.api.dto.RegistryDTO)7 RegistryClientEntity (org.apache.nifi.web.api.entity.RegistryClientEntity)5 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Revision (org.apache.nifi.web.Revision)2 RegistryClientsEntity (org.apache.nifi.web.api.entity.RegistryClientsEntity)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 StringUtils (org.apache.commons.lang3.StringUtils)1 CommandException (org.apache.nifi.toolkit.cli.api.CommandException)1 Context (org.apache.nifi.toolkit.cli.api.Context)1 NiFiClient (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient)1 NiFiClientException (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException)1 CommandOption (org.apache.nifi.toolkit.cli.impl.command.CommandOption)1