Search in sources :

Example 1 with LabelEntity

use of org.apache.nifi.web.api.entity.LabelEntity in project kylo by Teradata.

the class NiFiProcessGroupsRestClientV1 method toFlowSnippet.

/**
 * Converts the specified flow to a flow snippet.
 *
 * @param flow the flow
 * @return the flow snippet
 */
@Nonnull
private FlowSnippetDTO toFlowSnippet(@Nonnull final FlowDTO flow, boolean recursive) {
    final FlowSnippetDTO snippet = new FlowSnippetDTO();
    snippet.setConnections(flow.getConnections().stream().map(ConnectionEntity::getComponent).collect(Collectors.toSet()));
    snippet.setControllerServices(Collections.emptySet());
    snippet.setFunnels(flow.getFunnels().stream().map(FunnelEntity::getComponent).collect(Collectors.toSet()));
    snippet.setInputPorts(flow.getInputPorts().stream().map(PortEntity::getComponent).collect(Collectors.toSet()));
    snippet.setLabels(flow.getLabels().stream().map(LabelEntity::getComponent).collect(Collectors.toSet()));
    snippet.setOutputPorts(flow.getOutputPorts().stream().map(PortEntity::getComponent).collect(Collectors.toSet()));
    snippet.setProcessGroups(flow.getProcessGroups().stream().map(ProcessGroupEntity::getComponent).collect(Collectors.toSet()));
    snippet.setProcessors(flow.getProcessors().stream().map(ProcessorEntity::getComponent).collect(Collectors.toSet()));
    snippet.setRemoteProcessGroups(flow.getRemoteProcessGroups().stream().map(RemoteProcessGroupEntity::getComponent).collect(Collectors.toSet()));
    // Add flow for child process groups
    if (recursive) {
        for (final ProcessGroupDTO processGroup : snippet.getProcessGroups()) {
            processGroup.setContents(getFlowSnippet(processGroup.getId(), true));
        }
    }
    return snippet;
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Nonnull(javax.annotation.Nonnull)

Example 2 with LabelEntity

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

the class LabelResource method removeLabel.

/**
 * Removes the specified label.
 *
 * @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 label to remove.
 * @return A entity containing the client id and an updated revision.
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Deletes a label", response = LabelEntity.class, authorizations = { @Authorization(value = "Write - /labels/{uuid}"), @Authorization(value = "Write - Parent Process Group - /process-groups/{uuid}") })
@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 removeLabel(@Context final 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 label id.", required = true) @PathParam("id") final String id) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.DELETE);
    }
    final LabelEntity requestLabelEntity = new LabelEntity();
    requestLabelEntity.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, requestLabelEntity, requestRevision, lookup -> {
        final Authorizable label = lookup.getLabel(id);
        // ensure write permission to the label
        label.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
        // ensure write permission to the parent process group
        label.getParentAuthorizable().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, null, (revision, labelEntity) -> {
        // delete the specified label
        final LabelEntity entity = serviceFacade.deleteLabel(revision, labelEntity.getId());
        return generateOkResponse(entity).build();
    });
}
Also used : LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) Revision(org.apache.nifi.web.Revision) Authorizable(org.apache.nifi.authorization.resource.Authorizable) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with LabelEntity

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

the class LabelResource method getLabel.

/**
 * Retrieves the specified label.
 *
 * @param id The id of the label to retrieve
 * @return A labelEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Gets a label", response = LabelEntity.class, authorizations = { @Authorization(value = "Read - /labels/{uuid}") })
@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 getLabel(@ApiParam(value = "The label id.", required = true) @PathParam("id") final String id) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable label = lookup.getLabel(id);
        label.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    });
    // get the label
    final LabelEntity entity = serviceFacade.getLabel(id);
    populateRemainingLabelEntityContent(entity);
    return generateOkResponse(entity).build();
}
Also used : LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) Authorizable(org.apache.nifi.authorization.resource.Authorizable) 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 4 with LabelEntity

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

the class LabelResource method updateLabel.

/**
 * Updates the specified label.
 *
 * @param httpServletRequest request
 * @param id                 The id of the label to update.
 * @param requestLabelEntity        A labelEntity.
 * @return A labelEntity.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Updates a label", response = LabelEntity.class, authorizations = { @Authorization(value = "Write - /labels/{uuid}") })
@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 updateLabel(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The label id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The label configuration details.", required = true) final LabelEntity requestLabelEntity) {
    if (requestLabelEntity == null || requestLabelEntity.getComponent() == null) {
        throw new IllegalArgumentException("Label details must be specified.");
    }
    if (requestLabelEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }
    // ensure the ids are the same
    final LabelDTO requestLabelDTO = requestLabelEntity.getComponent();
    if (!id.equals(requestLabelDTO.getId())) {
        throw new IllegalArgumentException(String.format("The label id (%s) in the request body does not equal the " + "label id of the requested resource (%s).", requestLabelDTO.getId(), id));
    }
    final PositionDTO proposedPosition = requestLabelDTO.getPosition();
    if (proposedPosition != null) {
        if (proposedPosition.getX() == null || proposedPosition.getY() == null) {
            throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified.");
        }
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestLabelEntity);
    }
    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = getRevision(requestLabelEntity, id);
    return withWriteLock(serviceFacade, requestLabelEntity, requestRevision, lookup -> {
        Authorizable authorizable = lookup.getLabel(id);
        authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, null, (revision, labelEntity) -> {
        final LabelDTO labelDTO = labelEntity.getComponent();
        // update the label
        final LabelEntity entity = serviceFacade.updateLabel(revision, labelDTO);
        populateRemainingLabelEntityContent(entity);
        return generateOkResponse(entity).build();
    });
}
Also used : LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) Revision(org.apache.nifi.web.Revision) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with LabelEntity

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

the class ProcessGroupResource method createLabel.

// ------
// labels
// ------
/**
 * Creates a new Label.
 *
 * @param httpServletRequest request
 * @param groupId            The group id
 * @param requestLabelEntity        A labelEntity.
 * @return A labelEntity.
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/labels")
@ApiOperation(value = "Creates a label", response = LabelEntity.class, authorizations = { @Authorization(value = "Write - /process-groups/{uuid}") })
@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 createLabel(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId, @ApiParam(value = "The label configuration details.", required = true) final LabelEntity requestLabelEntity) {
    if (requestLabelEntity == null || requestLabelEntity.getComponent() == null) {
        throw new IllegalArgumentException("Label details must be specified.");
    }
    if (requestLabelEntity.getRevision() == null || (requestLabelEntity.getRevision().getVersion() == null || requestLabelEntity.getRevision().getVersion() != 0)) {
        throw new IllegalArgumentException("A revision of 0 must be specified when creating a new Label.");
    }
    if (requestLabelEntity.getComponent().getId() != null) {
        throw new IllegalArgumentException("Label ID cannot be specified.");
    }
    final PositionDTO proposedPosition = requestLabelEntity.getComponent().getPosition();
    if (proposedPosition != null) {
        if (proposedPosition.getX() == null || proposedPosition.getY() == null) {
            throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified.");
        }
    }
    if (requestLabelEntity.getComponent().getParentGroupId() != null && !groupId.equals(requestLabelEntity.getComponent().getParentGroupId())) {
        throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestLabelEntity.getComponent().getParentGroupId(), groupId));
    }
    requestLabelEntity.getComponent().setParentGroupId(groupId);
    if (isReplicateRequest()) {
        return replicate(HttpMethod.POST, requestLabelEntity);
    }
    return withWriteLock(serviceFacade, requestLabelEntity, lookup -> {
        final Authorizable processGroup = lookup.getProcessGroup(groupId).getAuthorizable();
        processGroup.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, null, labelEntity -> {
        // set the processor id as appropriate
        labelEntity.getComponent().setId(generateUuid());
        // create the label and generate the json
        final Revision revision = getRevision(labelEntity, labelEntity.getComponent().getId());
        final LabelEntity entity = serviceFacade.createLabel(revision, groupId, labelEntity.getComponent());
        labelResource.populateRemainingLabelEntityContent(entity);
        // build the response
        return generateCreatedResponse(URI.create(entity.getUri()), entity).build();
    });
}
Also used : LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) Revision(org.apache.nifi.web.Revision) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) TemplateContentsAuthorizable(org.apache.nifi.authorization.TemplateContentsAuthorizable) ProcessGroupAuthorizable(org.apache.nifi.authorization.ProcessGroupAuthorizable) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) 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)

Aggregations

LabelEntity (org.apache.nifi.web.api.entity.LabelEntity)22 Response (javax.ws.rs.core.Response)9 Test (org.junit.Test)9 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 Authorizable (org.apache.nifi.authorization.resource.Authorizable)5 LabelDTO (org.apache.nifi.web.api.dto.LabelDTO)5 HashMap (java.util.HashMap)3 Revision (org.apache.nifi.web.Revision)3 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)3 ConnectionEntity (org.apache.nifi.web.api.entity.ConnectionEntity)3 FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)3 PortEntity (org.apache.nifi.web.api.entity.PortEntity)3 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)3 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)3 Map (java.util.Map)2 GET (javax.ws.rs.GET)2