Search in sources :

Example 1 with ComponentEntity

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

the class ProvenanceResource method deleteProvenance.

/**
 * Deletes the provenance with the specified id.
 *
 * @param httpServletRequest request
 * @param id                 The id of the provenance
 * @param clusterNodeId      The id of node in the cluster to search. This is optional and only relevant when clustered. If clustered and it is not specified the entire cluster is searched.
 * @return A provenanceEntity
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Deletes a provenance query", response = ProvenanceEntity.class, authorizations = { @Authorization(value = "Read - /provenance") })
@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 deleteProvenance(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The id of the node where this query exists if clustered.", required = false) @QueryParam("clusterNodeId") final String clusterNodeId, @ApiParam(value = "The id of the provenance query.", required = true) @PathParam("id") final String id) {
    // replicate if cluster manager
    if (isReplicateRequest()) {
        // determine where this request should be sent
        if (clusterNodeId == null) {
            // replicate to all nodes
            return replicate(HttpMethod.DELETE);
        } else {
            return replicate(HttpMethod.DELETE, clusterNodeId);
        }
    }
    final ComponentEntity requestEntity = new ComponentEntity();
    requestEntity.setId(id);
    return withWriteLock(serviceFacade, requestEntity, lookup -> authorizeProvenanceRequest(), null, (entity) -> {
        // delete the provenance
        serviceFacade.deleteProvenance(entity.getId());
        // generate the response
        return generateOkResponse(new ProvenanceEntity()).build();
    });
}
Also used : ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) ProvenanceEntity(org.apache.nifi.web.api.entity.ProvenanceEntity) 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 2 with ComponentEntity

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

the class ProvenanceResource method deleteLineage.

/**
 * Deletes the lineage with the specified id.
 *
 * @param httpServletRequest request
 * @param clusterNodeId      The id of node in the cluster that the event/flowfile originated from. This is only required when clustered.
 * @param id                 The id of the lineage
 * @return A lineageEntity
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("lineage/{id}")
@ApiOperation(value = "Deletes a lineage query", response = LineageEntity.class, authorizations = { @Authorization(value = "Read - /provenance") })
@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 deleteLineage(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The id of the node where this query exists if clustered.", required = false) @QueryParam("clusterNodeId") final String clusterNodeId, @ApiParam(value = "The id of the lineage query.", required = true) @PathParam("id") final String id) {
    // replicate if cluster manager
    if (isReplicateRequest()) {
        return replicate(HttpMethod.DELETE, clusterNodeId);
    }
    final ComponentEntity requestEntity = new ComponentEntity();
    requestEntity.setId(id);
    return withWriteLock(serviceFacade, requestEntity, lookup -> authorizeProvenanceRequest(), null, (entity) -> {
        // delete the lineage
        serviceFacade.deleteLineage(entity.getId());
        // generate the response
        return generateOkResponse(new LineageEntity()).build();
    });
}
Also used : ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) LineageEntity(org.apache.nifi.web.api.entity.LineageEntity) 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 ComponentEntity

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

the class ComponentEntityMerger method merge.

/**
 * Merges the ComponentEntity responses according to their {@link org.apache.nifi.web.api.dto.PermissionsDTO}s.  Responsible for invoking
 * {@link ComponentEntityMerger#mergeComponents(EntityType, Map)}.
 *
 * @param clientEntity the entity being returned to the client
 * @param entityMap    all node responses
 */
@SuppressWarnings("unchecked")
default void merge(final EntityType clientEntity, final Map<NodeIdentifier, EntityType> entityMap) {
    for (final Map.Entry<NodeIdentifier, EntityType> entry : entityMap.entrySet()) {
        final EntityType entity = entry.getValue();
        PermissionsDtoMerger.mergePermissions(clientEntity.getPermissions(), entity.getPermissions());
    }
    if (clientEntity.getPermissions().getCanRead()) {
        final Map<NodeIdentifier, List<BulletinEntity>> bulletinEntities = new HashMap<>();
        for (final Map.Entry<NodeIdentifier, ? extends ComponentEntity> entry : entityMap.entrySet()) {
            final NodeIdentifier nodeIdentifier = entry.getKey();
            final ComponentEntity entity = entry.getValue();
            // consider the bulletins if present and authorized
            if (entity.getBulletins() != null) {
                entity.getBulletins().forEach(bulletin -> {
                    bulletinEntities.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
                });
            }
        }
        clientEntity.setBulletins(BulletinMerger.mergeBulletins(bulletinEntities, entityMap.size()));
        // sort the results
        Collections.sort(clientEntity.getBulletins(), BULLETIN_COMPARATOR);
        // prune the response to only include the max number of bulletins
        if (clientEntity.getBulletins().size() > MAX_BULLETINS_PER_COMPONENT) {
            clientEntity.setBulletins(clientEntity.getBulletins().subList(0, MAX_BULLETINS_PER_COMPONENT));
        }
        mergeComponents(clientEntity, entityMap);
    } else {
        clientEntity.setBulletins(null);
        // unchecked warning suppressed
        clientEntity.setComponent(null);
    }
}
Also used : BULLETIN_COMPARATOR(org.apache.nifi.cluster.manager.BulletinMerger.BULLETIN_COMPARATOR) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) List(java.util.List) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Permissible(org.apache.nifi.web.api.entity.Permissible) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) Map(java.util.Map) MAX_BULLETINS_PER_COMPONENT(org.apache.nifi.reporting.BulletinRepository.MAX_BULLETINS_PER_COMPONENT) HashMap(java.util.HashMap) Collections(java.util.Collections) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ComponentEntity

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

the class JerseyFlowClient method getSuggestedProcessGroupCoordinates.

@Override
public ProcessGroupBox getSuggestedProcessGroupCoordinates(final String parentId) throws NiFiClientException, IOException {
    if (StringUtils.isBlank(parentId)) {
        throw new IllegalArgumentException("Process group id cannot be null");
    }
    final ProcessGroupFlowEntity processGroup = getProcessGroup(parentId);
    final ProcessGroupFlowDTO processGroupFlowDTO = processGroup.getProcessGroupFlow();
    final FlowDTO flowDTO = processGroupFlowDTO.getFlow();
    final List<ComponentEntity> pgComponents = new ArrayList<>();
    pgComponents.addAll(flowDTO.getProcessGroups());
    pgComponents.addAll(flowDTO.getProcessors());
    pgComponents.addAll(flowDTO.getRemoteProcessGroups());
    pgComponents.addAll(flowDTO.getConnections());
    pgComponents.addAll(flowDTO.getFunnels());
    pgComponents.addAll(flowDTO.getInputPorts());
    pgComponents.addAll(flowDTO.getOutputPorts());
    pgComponents.addAll(flowDTO.getLabels());
    final Set<PositionDTO> positions = pgComponents.stream().map(ComponentEntity::getPosition).collect(Collectors.toSet());
    if (positions.isEmpty()) {
        return ProcessGroupBox.CANVAS_CENTER;
    }
    final List<ProcessGroupBox> coords = positions.stream().filter(Objects::nonNull).map(p -> new ProcessGroupBox(p.getX().intValue(), p.getY().intValue())).collect(Collectors.toList());
    final ProcessGroupBox freeSpot = coords.get(0).findFreeSpace(coords);
    return freeSpot;
}
Also used : ProcessGroupBox(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox) NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) Set(java.util.Set) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) Entity(javax.ws.rs.client.Entity) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Objects(java.util.Objects) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) MediaType(javax.ws.rs.core.MediaType) List(java.util.List) VersionedFlowSnapshotMetadataSetEntity(org.apache.nifi.web.api.entity.VersionedFlowSnapshotMetadataSetEntity) Map(java.util.Map) FlowClient(org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient) CurrentUserEntity(org.apache.nifi.web.api.entity.CurrentUserEntity) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) WebTarget(javax.ws.rs.client.WebTarget) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) Collections(java.util.Collections) ScheduleComponentsEntity(org.apache.nifi.web.api.entity.ScheduleComponentsEntity) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) ArrayList(java.util.ArrayList) ProcessGroupBox(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Objects(java.util.Objects)

Example 5 with ComponentEntity

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

the class CountersResource method updateCounter.

/**
 * Update the specified counter. This will reset the counter value to 0.
 *
 * @param httpServletRequest request
 * @param id                 The id of the counter.
 * @return A counterEntity.
 */
@PUT
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Updates the specified counter. This will reset the counter value to 0", notes = NON_GUARANTEED_ENDPOINT, response = CounterEntity.class, authorizations = { @Authorization(value = "Write - /counters") })
@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 updateCounter(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The id of the counter.") @PathParam("id") final String id) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT);
    }
    final ComponentEntity requestComponentEntity = new ComponentEntity();
    requestComponentEntity.setId(id);
    return withWriteLock(serviceFacade, requestComponentEntity, lookup -> {
        authorizeCounters(RequestAction.WRITE);
    }, null, (componentEntity) -> {
        // reset the specified counter
        final CounterDTO counter = serviceFacade.updateCounter(componentEntity.getId());
        // create the response entity
        final CounterEntity entity = new CounterEntity();
        entity.setCounter(counter);
        // generate the response
        return generateOkResponse(entity).build();
    });
}
Also used : CounterDTO(org.apache.nifi.web.api.dto.CounterDTO) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) CounterEntity(org.apache.nifi.web.api.entity.CounterEntity) 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)

Aggregations

ComponentEntity (org.apache.nifi.web.api.entity.ComponentEntity)6 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 Consumes (javax.ws.rs.Consumes)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 DELETE (javax.ws.rs.DELETE)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 PUT (javax.ws.rs.PUT)2 MediaType (javax.ws.rs.core.MediaType)2 Api (io.swagger.annotations.Api)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 Authorization (io.swagger.annotations.Authorization)1 IOException (java.io.IOException)1