Search in sources :

Example 11 with LabelEntity

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

the class FlowMerger method mergeResponses.

@Override
protected void mergeResponses(final ProcessGroupFlowDTO clientDto, final Map<NodeIdentifier, ProcessGroupFlowDTO> dtoMap, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses) {
    final FlowDTO flowDto = clientDto.getFlow();
    final Set<ConnectionEntity> clientConnections = flowDto.getConnections();
    final Set<ProcessorEntity> clientProcessors = flowDto.getProcessors();
    final Set<PortEntity> clientInputPorts = flowDto.getInputPorts();
    final Set<PortEntity> clientOutputPorts = flowDto.getOutputPorts();
    final Set<RemoteProcessGroupEntity> clientRemoteProcessGroups = flowDto.getRemoteProcessGroups();
    final Set<ProcessGroupEntity> clientProcessGroups = flowDto.getProcessGroups();
    final Set<LabelEntity> clientLabels = flowDto.getLabels();
    final Set<FunnelEntity> clientFunnels = flowDto.getFunnels();
    final Map<String, Map<NodeIdentifier, ConnectionEntity>> connections = new HashMap<>();
    final Map<String, Map<NodeIdentifier, FunnelEntity>> funnels = new HashMap<>();
    final Map<String, Map<NodeIdentifier, PortEntity>> inputPorts = new HashMap<>();
    final Map<String, Map<NodeIdentifier, LabelEntity>> labels = new HashMap<>();
    final Map<String, Map<NodeIdentifier, PortEntity>> outputPorts = new HashMap<>();
    final Map<String, Map<NodeIdentifier, ProcessorEntity>> processors = new HashMap<>();
    final Map<String, Map<NodeIdentifier, RemoteProcessGroupEntity>> rpgs = new HashMap<>();
    final Map<String, Map<NodeIdentifier, ProcessGroupEntity>> processGroups = new HashMap<>();
    // Create mapping of ComponentID -> [nodeId, entity on that node]
    for (final Map.Entry<NodeIdentifier, ProcessGroupFlowDTO> nodeGroupFlowEntry : dtoMap.entrySet()) {
        final NodeIdentifier nodeIdentifier = nodeGroupFlowEntry.getKey();
        final ProcessGroupFlowDTO nodeGroupFlowDto = nodeGroupFlowEntry.getValue();
        final FlowDTO nodeFlowDto = nodeGroupFlowDto.getFlow();
        // Merge connection statuses
        for (final ConnectionEntity entity : nodeFlowDto.getConnections()) {
            connections.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final FunnelEntity entity : nodeFlowDto.getFunnels()) {
            funnels.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final PortEntity entity : nodeFlowDto.getInputPorts()) {
            inputPorts.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final PortEntity entity : nodeFlowDto.getOutputPorts()) {
            outputPorts.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final LabelEntity entity : nodeFlowDto.getLabels()) {
            labels.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final ProcessorEntity entity : nodeFlowDto.getProcessors()) {
            processors.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final RemoteProcessGroupEntity entity : nodeFlowDto.getRemoteProcessGroups()) {
            rpgs.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
        for (final ProcessGroupEntity entity : nodeFlowDto.getProcessGroups()) {
            processGroups.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
        }
    }
    // 
    // Merge the components that are grouped together by ID
    // 
    // Merge connections
    ConnectionsEntityMerger.mergeConnections(clientConnections, connections);
    // Merge funnel statuses
    FunnelsEntityMerger.mergeFunnels(clientFunnels, funnels);
    // Merge input ports
    PortsEntityMerger.mergePorts(clientInputPorts, inputPorts);
    // Merge output ports
    PortsEntityMerger.mergePorts(clientOutputPorts, outputPorts);
    // Merge labels
    LabelsEntityMerger.mergeLabels(clientLabels, labels);
    // Merge processors
    ProcessorsEntityMerger.mergeProcessors(clientProcessors, processors);
    // Merge Remote Process Groups
    RemoteProcessGroupsEntityMerger.mergeRemoteProcessGroups(clientRemoteProcessGroups, rpgs);
    // Merge Process Groups
    ProcessGroupsEntityMerger.mergeProcessGroups(clientProcessGroups, processGroups);
}
Also used : LabelsEntityMerger(org.apache.nifi.cluster.manager.LabelsEntityMerger) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ConnectionsEntityMerger(org.apache.nifi.cluster.manager.ConnectionsEntityMerger) RemoteProcessGroupsEntityMerger(org.apache.nifi.cluster.manager.RemoteProcessGroupsEntityMerger) FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) ProcessGroupsEntityMerger(org.apache.nifi.cluster.manager.ProcessGroupsEntityMerger) FunnelsEntityMerger(org.apache.nifi.cluster.manager.FunnelsEntityMerger) Set(java.util.Set) HashMap(java.util.HashMap) PortEntity(org.apache.nifi.web.api.entity.PortEntity) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) PortsEntityMerger(org.apache.nifi.cluster.manager.PortsEntityMerger) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) Map(java.util.Map) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) ProcessorsEntityMerger(org.apache.nifi.cluster.manager.ProcessorsEntityMerger) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) URI(java.net.URI) Pattern(java.util.regex.Pattern) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) HashMap(java.util.HashMap) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) PortEntity(org.apache.nifi.web.api.entity.PortEntity) 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) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with LabelEntity

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

the class LabelsEndpointMerger method merge.

@Override
public NodeResponse merge(URI uri, String method, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses, NodeResponse clientResponse) {
    if (!canHandle(uri, method)) {
        throw new IllegalArgumentException("Cannot use Endpoint Mapper of type " + getClass().getSimpleName() + " to map responses for URI " + uri + ", HTTP Method " + method);
    }
    final LabelsEntity responseEntity = clientResponse.getClientResponse().readEntity(LabelsEntity.class);
    final Set<LabelEntity> labelEntities = responseEntity.getLabels();
    final Map<String, Map<NodeIdentifier, LabelEntity>> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final LabelsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(LabelsEntity.class);
        final Set<LabelEntity> nodeLabelEntities = nodeResponseEntity.getLabels();
        for (final LabelEntity nodeLabelEntity : nodeLabelEntities) {
            final String nodeLabelEntityId = nodeLabelEntity.getId();
            Map<NodeIdentifier, LabelEntity> innerMap = entityMap.get(nodeLabelEntityId);
            if (innerMap == null) {
                innerMap = new HashMap<>();
                entityMap.put(nodeLabelEntityId, innerMap);
            }
            innerMap.put(nodeResponse.getNodeId(), nodeLabelEntity);
        }
    }
    LabelsEntityMerger.mergeLabels(labelEntities, entityMap);
    // create a new client response
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : LabelsEntity(org.apache.nifi.web.api.entity.LabelsEntity) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with LabelEntity

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

the class ProcessGroupResource method getLabels.

/**
 * Retrieves all the of labels in this NiFi.
 *
 * @return A labelsEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/labels")
@ApiOperation(value = "Gets all labels", response = LabelsEntity.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 getLabels(@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 labels
    final Set<LabelEntity> labels = serviceFacade.getLabels(groupId);
    // create the response entity
    final LabelsEntity entity = new LabelsEntity();
    entity.setLabels(labelResource.populateRemainingLabelEntitiesContent(labels));
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) LabelsEntity(org.apache.nifi.web.api.entity.LabelsEntity) 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) 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 14 with LabelEntity

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

the class EntityFactory method createLabelEntity.

public LabelEntity createLabelEntity(final LabelDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) {
    final LabelEntity entity = new LabelEntity();
    entity.setRevision(revision);
    if (dto != null) {
        entity.setPermissions(permissions);
        entity.setId(dto.getId());
        entity.setPosition(dto.getPosition());
        final DimensionsDTO dimensions = new DimensionsDTO();
        dimensions.setHeight(dto.getHeight());
        dimensions.setWidth(dto.getWidth());
        entity.setDimensions(dimensions);
        if (permissions != null && permissions.getCanRead()) {
            entity.setComponent(dto);
        }
    }
    return entity;
}
Also used : LabelEntity(org.apache.nifi.web.api.entity.LabelEntity)

Example 15 with LabelEntity

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

the class ITLabelAccessControl method createLabel.

private LabelEntity createLabel(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/labels";
    // create the label
    LabelDTO label = new LabelDTO();
    label.setLabel(name);
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);
    // create the entity body
    LabelEntity entity = new LabelEntity();
    entity.setRevision(revision);
    entity.setComponent(label);
    // perform the request
    Response response = helper.getReadWriteUser().testPost(url, entity);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    // get the entity body
    entity = response.readEntity(LabelEntity.class);
    // verify creation
    label = entity.getComponent();
    assertEquals(name, label.getLabel());
    // get the label id
    return entity;
}
Also used : Response(javax.ws.rs.core.Response) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

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