Search in sources :

Example 1 with RegistryClientEntity

use of org.apache.nifi.web.api.entity.RegistryClientEntity 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 RegistryClientEntity

use of org.apache.nifi.web.api.entity.RegistryClientEntity in project nifi by apache.

the class ControllerResource method getRegistryClient.

/**
 * Retrieves the specified registry.
 *
 * @param id The id of the registry to retrieve
 * @return A registryClientEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("/registry-clients/{id}")
@ApiOperation(value = "Gets a registry client", response = RegistryClientEntity.class, authorizations = { @Authorization(value = "Read - /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 getRegistryClient(@ApiParam(value = "The registry id.", required = true) @PathParam("id") final String id) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // authorize access
    authorizeController(RequestAction.READ);
    // get the registry
    final RegistryClientEntity entity = serviceFacade.getRegistryClient(id);
    populateRemainingRegistryEntityContent(entity);
    return generateOkResponse(entity).build();
}
Also used : RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with RegistryClientEntity

use of org.apache.nifi.web.api.entity.RegistryClientEntity in project nifi by apache.

the class EntityFactory method createRegistryClientEntity.

public RegistryClientEntity createRegistryClientEntity(final RegistryDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) {
    final RegistryClientEntity entity = new RegistryClientEntity();
    entity.setRevision(revision);
    entity.setPermissions(permissions);
    if (dto != null) {
        entity.setId(dto.getId());
        if (permissions != null && permissions.getCanRead()) {
            entity.setComponent(dto);
        }
    }
    return entity;
}
Also used : RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity)

Example 4 with RegistryClientEntity

use of org.apache.nifi.web.api.entity.RegistryClientEntity in project nifi by apache.

the class PGImport method doExecute.

@Override
public StringResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException {
    final String bucketId = getRequiredArg(properties, CommandOption.BUCKET_ID);
    final String flowId = getRequiredArg(properties, CommandOption.FLOW_ID);
    final Integer flowVersion = getRequiredIntArg(properties, CommandOption.FLOW_VERSION);
    // if a registry client is specified use it, otherwise see if there is only one available and use that,
    // if more than one is available then throw an exception because we don't know which one to use
    String registryId = getArg(properties, CommandOption.REGISTRY_CLIENT_ID);
    if (StringUtils.isBlank(registryId)) {
        final RegistryClientsEntity registries = client.getControllerClient().getRegistryClients();
        final Set<RegistryClientEntity> entities = registries.getRegistries();
        if (entities == null || entities.isEmpty()) {
            throw new NiFiClientException("No registry clients available");
        }
        if (entities.size() == 1) {
            registryId = entities.stream().findFirst().get().getId();
        } else {
            throw new MissingOptionException(CommandOption.REGISTRY_CLIENT_ID.getLongName() + " must be provided when there is more than one available");
        }
    }
    // get the optional id of the parent PG, otherwise fallback to the root group
    String parentPgId = getArg(properties, CommandOption.PG_ID);
    if (StringUtils.isBlank(parentPgId)) {
        final FlowClient flowClient = client.getFlowClient();
        parentPgId = flowClient.getRootGroupId();
    }
    final VersionControlInformationDTO versionControlInfo = new VersionControlInformationDTO();
    versionControlInfo.setRegistryId(registryId);
    versionControlInfo.setBucketId(bucketId);
    versionControlInfo.setFlowId(flowId);
    versionControlInfo.setVersion(flowVersion);
    final ProcessGroupBox pgBox = client.getFlowClient().getSuggestedProcessGroupCoordinates(parentPgId);
    final PositionDTO posDto = new PositionDTO();
    posDto.setX(Integer.valueOf(pgBox.getX()).doubleValue());
    posDto.setY(Integer.valueOf(pgBox.getY()).doubleValue());
    final ProcessGroupDTO pgDto = new ProcessGroupDTO();
    pgDto.setVersionControlInformation(versionControlInfo);
    pgDto.setPosition(posDto);
    final ProcessGroupEntity pgEntity = new ProcessGroupEntity();
    pgEntity.setComponent(pgDto);
    pgEntity.setRevision(getInitialRevisionDTO());
    final ProcessGroupClient pgClient = client.getProcessGroupClient();
    final ProcessGroupEntity createdEntity = pgClient.createProcessGroup(parentPgId, pgEntity);
    return new StringResult(createdEntity.getId(), getContext().isInteractive());
}
Also used : NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) RegistryClientsEntity(org.apache.nifi.web.api.entity.RegistryClientsEntity) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) FlowClient(org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient) ProcessGroupBox(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) ProcessGroupClient(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupClient) MissingOptionException(org.apache.commons.cli.MissingOptionException)

Example 5 with RegistryClientEntity

use of org.apache.nifi.web.api.entity.RegistryClientEntity 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)

Aggregations

RegistryClientEntity (org.apache.nifi.web.api.entity.RegistryClientEntity)11 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 RegistryDTO (org.apache.nifi.web.api.dto.RegistryDTO)5 Revision (org.apache.nifi.web.Revision)3 RegistryClientsEntity (org.apache.nifi.web.api.entity.RegistryClientsEntity)3 GET (javax.ws.rs.GET)2 StringResult (org.apache.nifi.toolkit.cli.impl.result.StringResult)2 HashSet (java.util.HashSet)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 MissingOptionException (org.apache.commons.cli.MissingOptionException)1 CommandException (org.apache.nifi.toolkit.cli.api.CommandException)1 ControllerClient (org.apache.nifi.toolkit.cli.impl.client.nifi.ControllerClient)1 FlowClient (org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient)1 NiFiClientException (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException)1