Search in sources :

Example 11 with ConnectionEntity

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

the class ITConnectionAccessControl method createConnection.

private ConnectionEntity createConnection(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/connections";
    // get two processors
    final ProcessorEntity one = ITProcessorAccessControl.createProcessor(helper, "one");
    final ProcessorEntity two = ITProcessorAccessControl.createProcessor(helper, "two");
    // create the source connectable
    ConnectableDTO source = new ConnectableDTO();
    source.setId(one.getId());
    source.setGroupId(one.getComponent().getParentGroupId());
    source.setType(ConnectableType.PROCESSOR.name());
    // create the target connectable
    ConnectableDTO target = new ConnectableDTO();
    target.setId(two.getId());
    target.setGroupId(two.getComponent().getParentGroupId());
    target.setType(ConnectableType.PROCESSOR.name());
    // create the relationships
    Set<String> relationships = new HashSet<>();
    relationships.add("success");
    // create the connection
    ConnectionDTO connection = new ConnectionDTO();
    connection.setName(name);
    connection.setSource(source);
    connection.setDestination(target);
    connection.setSelectedRelationships(relationships);
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);
    // create the entity body
    ConnectionEntity entity = new ConnectionEntity();
    entity.setRevision(revision);
    entity.setComponent(connection);
    // 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(ConnectionEntity.class);
    // verify creation
    connection = entity.getComponent();
    assertEquals(name, connection.getName());
    // get the connection
    return entity;
}
Also used : Response(javax.ws.rs.core.Response) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) HashSet(java.util.HashSet)

Example 12 with ConnectionEntity

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

the class ITConnectionAccessControl method testReadWriteUserPutConnectionThroughInheritedPolicy.

/**
 * Ensures the READ_WRITE user can put a connection.
 *
 * @throws Exception ex
 */
@Test
public void testReadWriteUserPutConnectionThroughInheritedPolicy() throws Exception {
    final ConnectionEntity entity = createConnection(NiFiTestAuthorizer.NO_POLICY_COMPONENT_NAME);
    final String updatedName = "Updated name";
    // 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 = updateConnection(helper.getReadWriteUser(), entity);
    // ensure successful response
    assertEquals(200, response.getStatus());
    // get the response
    final ConnectionEntity responseEntity = response.readEntity(ConnectionEntity.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) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) Test(org.junit.Test)

Example 13 with ConnectionEntity

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

the class ConnectionsEndpointMerger method merge.

@Override
public final NodeResponse merge(final URI uri, final String method, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final 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 ConnectionsEntity responseEntity = clientResponse.getClientResponse().readEntity(ConnectionsEntity.class);
    final Set<ConnectionEntity> connectionEntities = responseEntity.getConnections();
    final Map<String, Map<NodeIdentifier, ConnectionEntity>> entityMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final ConnectionsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(ConnectionsEntity.class);
        final Set<ConnectionEntity> nodeConnectionEntities = nodeResponseEntity.getConnections();
        for (final ConnectionEntity nodeConnectionEntity : nodeConnectionEntities) {
            final String nodeConnectionEntityId = nodeConnectionEntity.getId();
            Map<NodeIdentifier, ConnectionEntity> innerMap = entityMap.get(nodeConnectionEntityId);
            if (innerMap == null) {
                innerMap = new HashMap<>();
                entityMap.put(nodeConnectionEntityId, innerMap);
            }
            innerMap.put(nodeResponse.getNodeId(), nodeConnectionEntity);
        }
    }
    ConnectionsEntityMerger.mergeConnections(connectionEntities, entityMap);
    // create a new client response
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : ConnectionsEntity(org.apache.nifi.web.api.entity.ConnectionsEntity) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with ConnectionEntity

use of org.apache.nifi.web.api.entity.ConnectionEntity 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 15 with ConnectionEntity

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

the class NiFiProcessGroupsRestClientV1 method createConnection.

@Nonnull
@Override
public ConnectionDTO createConnection(@Nonnull final String processGroupId, @Nonnull final ConnectableDTO source, @Nonnull final ConnectableDTO dest) {
    final ConnectionEntity entity = new ConnectionEntity();
    final ConnectionDTO connection = new ConnectionDTO();
    connection.setDestination(dest);
    connection.setName(source.getName() + "-" + dest.getName());
    connection.setSource(source);
    entity.setComponent(connection);
    final RevisionDTO revision = new RevisionDTO();
    revision.setVersion(0L);
    entity.setRevision(revision);
    try {
        return client.post(BASE_PATH + processGroupId + "/connections", entity, ConnectionEntity.class).getComponent();
    } catch (final NotFoundException e) {
        throw new NifiComponentNotFoundException(processGroupId, NifiConstants.NIFI_COMPONENT_TYPE.PROCESS_GROUP, e);
    }
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Nonnull(javax.annotation.Nonnull)

Aggregations

ConnectionEntity (org.apache.nifi.web.api.entity.ConnectionEntity)25 Response (javax.ws.rs.core.Response)9 Test (org.junit.Test)9 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponses (io.swagger.annotations.ApiResponses)7 Consumes (javax.ws.rs.Consumes)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 Authorizable (org.apache.nifi.authorization.resource.Authorizable)7 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)7 ConnectionAuthorizable (org.apache.nifi.authorization.ConnectionAuthorizable)5 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)5 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)4 URI (java.net.URI)3 HashMap (java.util.HashMap)3 POST (javax.ws.rs.POST)3 Revision (org.apache.nifi.web.Revision)3 FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)3 LabelEntity (org.apache.nifi.web.api.entity.LabelEntity)3 PortEntity (org.apache.nifi.web.api.entity.PortEntity)3