Search in sources :

Example 36 with PortEntity

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

the class InputPortResource method updateInputPort.

/**
 * Updates the specified input port.
 *
 * @param httpServletRequest request
 * @param id                 The id of the input port to update.
 * @param requestPortEntity         A inputPortEntity.
 * @return A inputPortEntity.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Updates an input port", response = PortEntity.class, authorizations = { @Authorization(value = "Write - /input-ports/{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 updateInputPort(@Context HttpServletRequest httpServletRequest, @ApiParam(value = "The input port id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The input port configuration details.", required = true) final PortEntity requestPortEntity) {
    if (requestPortEntity == null || requestPortEntity.getComponent() == null) {
        throw new IllegalArgumentException("Input port details must be specified.");
    }
    if (requestPortEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }
    // ensure the ids are the same
    final PortDTO requestPortDTO = requestPortEntity.getComponent();
    if (!id.equals(requestPortDTO.getId())) {
        throw new IllegalArgumentException(String.format("The input port id (%s) in the request body does not equal the " + "input port id of the requested resource (%s).", requestPortDTO.getId(), id));
    }
    final PositionDTO proposedPosition = requestPortDTO.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, requestPortEntity);
    }
    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = getRevision(requestPortEntity, id);
    return withWriteLock(serviceFacade, requestPortEntity, requestRevision, lookup -> {
        Authorizable authorizable = lookup.getInputPort(id);
        authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, () -> serviceFacade.verifyUpdateInputPort(requestPortDTO), (revision, portEntity) -> {
        final PortDTO portDTO = portEntity.getComponent();
        // update the input port
        final PortEntity entity = serviceFacade.updateInputPort(revision, portDTO);
        populateRemainingInputPortEntityContent(entity);
        return generateOkResponse(entity).build();
    });
}
Also used : Revision(org.apache.nifi.web.Revision) PortDTO(org.apache.nifi.web.api.dto.PortDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) PortEntity(org.apache.nifi.web.api.entity.PortEntity) 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 37 with PortEntity

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

the class OutputPortResource method removeOutputPort.

/**
 * Removes the specified output port.
 *
 * @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 output port to remove.
 * @return A outputPortEntity.
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Deletes an output port", response = PortEntity.class, authorizations = { @Authorization(value = "Write - /output-ports/{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 removeOutputPort(@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 output port id.", required = true) @PathParam("id") final String id) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.DELETE);
    }
    final PortEntity requestPortEntity = new PortEntity();
    requestPortEntity.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, requestPortEntity, requestRevision, lookup -> {
        final Authorizable outputPort = lookup.getOutputPort(id);
        // ensure write permission to the output port
        outputPort.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
        // ensure write permission to the parent process group
        outputPort.getParentAuthorizable().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, () -> serviceFacade.verifyDeleteOutputPort(id), (revision, portEntity) -> {
        // delete the specified output port
        final PortEntity entity = serviceFacade.deleteOutputPort(revision, portEntity.getId());
        return generateOkResponse(entity).build();
    });
}
Also used : Revision(org.apache.nifi.web.Revision) Authorizable(org.apache.nifi.authorization.resource.Authorizable) PortEntity(org.apache.nifi.web.api.entity.PortEntity) 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 38 with PortEntity

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

the class ProcessGroupResource method getInputPorts.

/**
 * Retrieves all the of input ports in this NiFi.
 *
 * @return A inputPortsEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/input-ports")
@ApiOperation(value = "Gets all input ports", response = InputPortsEntity.class, authorizations = { @Authorization(value = "Read - /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 getInputPorts(@ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable processGroup = lookup.getProcessGroup(groupId).getAuthorizable();
        processGroup.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    });
    // get all the input ports
    final Set<PortEntity> inputPorts = serviceFacade.getInputPorts(groupId);
    final InputPortsEntity entity = new InputPortsEntity();
    entity.setInputPorts(inputPortResource.populateRemainingInputPortEntitiesContent(inputPorts));
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : InputPortsEntity(org.apache.nifi.web.api.entity.InputPortsEntity) 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) PortEntity(org.apache.nifi.web.api.entity.PortEntity) 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 39 with PortEntity

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

the class ITInputPortAccessControl method testReadWriteUserPutInputPortThroughInheritedPolicy.

/**
 * Ensures the READ_WRITE user can put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testReadWriteUserPutInputPortThroughInheritedPolicy() throws Exception {
    final PortEntity entity = createInputPort(NiFiTestAuthorizer.NO_POLICY_COMPONENT_NAME);
    final String updatedName = "Updated name" + count++;
    // attempt to update the name
    final long version = entity.getRevision().getVersion();
    entity.getRevision().setClientId(READ_WRITE_CLIENT_ID);
    entity.getComponent().setName(updatedName);
    // perform the request
    final Response response = updateInputPort(helper.getReadWriteUser(), entity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final PortEntity responseEntity = response.readEntity(PortEntity.class);
    // verify
    assertEquals(AccessControlHelper.READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
    assertEquals(updatedName, responseEntity.getComponent().getName());
}
Also used : Response(javax.ws.rs.core.Response) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Test(org.junit.Test)

Example 40 with PortEntity

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

the class ITInputPortAccessControl method testReadWriteUserPutInputPort.

/**
 * Ensures the READ_WRITE user can put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testReadWriteUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getReadWriteUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
    final String updatedName = "Updated Name" + count++;
    // attempt to update the name
    final long version = entity.getRevision().getVersion();
    entity.getRevision().setClientId(AccessControlHelper.READ_WRITE_CLIENT_ID);
    entity.getComponent().setName(updatedName);
    // perform the request
    final Response response = updateInputPort(helper.getReadWriteUser(), entity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final PortEntity responseEntity = response.readEntity(PortEntity.class);
    // verify
    assertEquals(READ_WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
    assertEquals(updatedName, responseEntity.getComponent().getName());
}
Also used : Response(javax.ws.rs.core.Response) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Test(org.junit.Test)

Aggregations

PortEntity (org.apache.nifi.web.api.entity.PortEntity)52 Response (javax.ws.rs.core.Response)23 Test (org.junit.Test)18 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)17 Authorizable (org.apache.nifi.authorization.resource.Authorizable)16 PortDTO (org.apache.nifi.web.api.dto.PortDTO)16 HashMap (java.util.HashMap)13 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Map (java.util.Map)10 Consumes (javax.ws.rs.Consumes)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)10 FlowDTO (org.apache.nifi.web.api.dto.flow.FlowDTO)9 ProcessGroupFlowEntity (org.apache.nifi.web.api.entity.ProcessGroupFlowEntity)9 ConnectionEntity (org.apache.nifi.web.api.entity.ConnectionEntity)8 FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)8 LabelEntity (org.apache.nifi.web.api.entity.LabelEntity)8 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)8