Пример #1
0
  /**
   * Updates the specified input port.
   *
   * @param httpServletRequest request
   * @param id The id of the input port to update.
   * @param portEntity A inputPortEntity.
   * @return A inputPortEntity.
   */
  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  @Path("{id}")
  // TODO - @PreAuthorize("hasRole('ROLE_DFM')")
  @ApiOperation(
      value = "Updates an input port",
      response = InputPortEntity.class,
      authorizations = {@Authorization(value = "Data Flow Manager", type = "ROLE_DFM")})
  @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") String id,
      @ApiParam(value = "The input port configuration details.", required = true)
          InputPortEntity portEntity) {

    if (portEntity == null || portEntity.getInputPort() == null) {
      throw new IllegalArgumentException("Input port details must be specified.");
    }

    if (portEntity.getRevision() == null) {
      throw new IllegalArgumentException("Revision must be specified.");
    }

    // ensure the ids are the same
    final PortDTO requestPortDTO = portEntity.getInputPort();
    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));
    }

    // replicate if cluster manager
    if (properties.isClusterManager()) {
      // change content type to JSON for serializing entity
      final Map<String, String> headersToOverride = new HashMap<>();
      headersToOverride.put("content-type", MediaType.APPLICATION_JSON);

      // replicate the request
      return clusterManager
          .applyRequest(
              HttpMethod.PUT,
              getAbsolutePath(),
              updateClientId(portEntity),
              getHeaders(headersToOverride))
          .getResponse();
    }

    // handle expects request (usually from the cluster manager)
    final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER);
    if (expects != null) {
      serviceFacade.verifyUpdateInputPort(requestPortDTO);
      return generateContinueResponse().build();
    }

    // update the input port
    final RevisionDTO revision = portEntity.getRevision();
    final ConfigurationSnapshot<PortDTO> controllerResponse =
        serviceFacade.updateInputPort(
            new Revision(revision.getVersion(), revision.getClientId()), requestPortDTO);

    // get the results
    final PortDTO responsePortDTO = controllerResponse.getConfiguration();
    populateRemainingInputPortContent(responsePortDTO);

    // get the updated revision
    final RevisionDTO updatedRevision = new RevisionDTO();
    updatedRevision.setClientId(revision.getClientId());
    updatedRevision.setVersion(controllerResponse.getVersion());

    // build the response entity
    final InputPortEntity entity = new InputPortEntity();
    entity.setRevision(updatedRevision);
    entity.setInputPort(responsePortDTO);

    if (controllerResponse.isNew()) {
      return clusterContext(generateCreatedResponse(URI.create(responsePortDTO.getUri()), entity))
          .build();
    } else {
      return clusterContext(generateOkResponse(entity)).build();
    }
  }
Пример #2
0
 /** Populates the uri for the specified input ports. */
 public PortDTO populateRemainingInputPortContent(PortDTO inputPort) {
   // populate the input port uri
   inputPort.setUri(generateResourceUri("input-ports", inputPort.getId()));
   return inputPort;
 }
Пример #3
0
  /**
   * Updates the specified output port.
   *
   * @param httpServletRequest request
   * @param id The id of the output port to update.
   * @param requestPortEntity A outputPortEntity.
   * @return A outputPortEntity.
   */
  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  @Path("{id}")
  @ApiOperation(
      value = "Updates an output port",
      response = PortEntity.class,
      authorizations = {@Authorization(value = "Write - /output-ports/{uuid}", type = "")})
  @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 updateOutputPort(
      @Context final HttpServletRequest httpServletRequest,
      @ApiParam(value = "The output port id.", required = true) @PathParam("id") final String id,
      @ApiParam(value = "The output port configuration details.", required = true)
          final PortEntity requestPortEntity) {

    if (requestPortEntity == null || requestPortEntity.getComponent() == null) {
      throw new IllegalArgumentException("Output port details must be specified.");
    }

    if (requestPortEntity.getRevision() == null) {
      throw new IllegalArgumentException("Revision must be specified.");
    }

    // ensure the ids are the same
    PortDTO requestPortDTO = requestPortEntity.getComponent();
    if (!id.equals(requestPortDTO.getId())) {
      throw new IllegalArgumentException(
          String.format(
              "The output port id (%s) in the request body does not equal the "
                  + "output 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.getOutputPort(id);
          authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
        },
        () -> serviceFacade.verifyUpdateOutputPort(requestPortDTO),
        (revision, portEntity) -> {
          final PortDTO portDTO = portEntity.getComponent();

          // update the output port
          final PortEntity entity = serviceFacade.updateOutputPort(revision, portDTO);
          populateRemainingOutputPortEntityContent(entity);

          return clusterContext(generateOkResponse(entity)).build();
        });
  }