Java Code Examples for org.apache.nifi.web.api.dto.ConnectableDTO#setGroupId()

The following examples show how to use org.apache.nifi.web.api.dto.ConnectableDTO#setGroupId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
public ConnectableDTO createConnectableDTO(final ProcessorEntity processor) {
    final ConnectableDTO dto = new ConnectableDTO();
    dto.setGroupId(processor.getComponent().getParentGroupId());
    dto.setId(processor.getId());
    dto.setName(processor.getComponent().getName());
    dto.setRunning("RUNNING".equalsIgnoreCase(processor.getComponent().getState()));
    dto.setType("PROCESSOR");

    return dto;
}
 
Example 2
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
public ConnectableDTO createConnectableDTO(final PortEntity port) {
    final ConnectableDTO dto = new ConnectableDTO();
    dto.setGroupId(port.getComponent().getParentGroupId());
    dto.setId(port.getId());
    dto.setName(port.getComponent().getName());
    dto.setRunning("RUNNING".equalsIgnoreCase(port.getComponent().getState()));
    dto.setType(port.getPortType());

    return dto;
}
 
Example 3
Source File: FlowFromDOMFactory.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public static ConnectionDTO getConnection(final Element element) {
    final ConnectionDTO dto = new ConnectionDTO();
    dto.setId(getString(element, "id"));
    dto.setName(getString(element, "name"));
    dto.setLabelIndex(getOptionalInt(element, "labelIndex"));
    dto.setzIndex(getOptionalLong(element, "zIndex"));

    final List<PositionDTO> bends = new ArrayList<>();
    final Element bendPointsElement = DomUtils.getChild(element, "bendPoints");
    if (bendPointsElement != null) {
        for (final Element bendPointElement : getChildrenByTagName(bendPointsElement, "bendPoint")) {
            final PositionDTO bend = getPosition(bendPointElement);
            bends.add(bend);
        }
    }
    dto.setBends(bends);

    final ConnectableDTO sourceConnectable = new ConnectableDTO();
    dto.setSource(sourceConnectable);
    sourceConnectable.setId(getString(element, "sourceId"));
    sourceConnectable.setGroupId(getString(element, "sourceGroupId"));
    sourceConnectable.setType(getString(element, "sourceType"));

    final ConnectableDTO destConnectable = new ConnectableDTO();
    dto.setDestination(destConnectable);
    destConnectable.setId(getString(element, "destinationId"));
    destConnectable.setGroupId(getString(element, "destinationGroupId"));
    destConnectable.setType(getString(element, "destinationType"));

    final Set<String> relationships = new HashSet<>();
    final List<Element> relationshipNodeList = getChildrenByTagName(element, "relationship");
    for (final Element relationshipElem : relationshipNodeList) {
        relationships.add(relationshipElem.getTextContent());
    }
    dto.setSelectedRelationships(relationships);

    dto.setBackPressureObjectThreshold(getLong(element, "maxWorkQueueSize"));

    final String maxDataSize = getString(element, "maxWorkQueueDataSize");
    if (maxDataSize != null && !maxDataSize.trim().isEmpty()) {
        dto.setBackPressureDataSizeThreshold(maxDataSize);
    }

    String expiration = getString(element, "flowFileExpiration");
    if (expiration == null) {
        expiration = "0 sec";
    }
    dto.setFlowFileExpiration(expiration);

    final List<String> prioritizerClasses = new ArrayList<>();
    final List<Element> prioritizerNodeList = getChildrenByTagName(element, "queuePrioritizerClass");
    for (final Element prioritizerElement : prioritizerNodeList) {
        prioritizerClasses.add(prioritizerElement.getTextContent().trim());
    }
    dto.setPrioritizers(prioritizerClasses);

    return dto;
}
 
Example 4
Source File: ITConnectionAccessControl.java    From nifi with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 5
Source File: FlowFromDOMFactory.java    From nifi with Apache License 2.0 4 votes vote down vote up
public static ConnectionDTO getConnection(final Element element) {
    final ConnectionDTO dto = new ConnectionDTO();
    dto.setId(getString(element, "id"));
    dto.setName(getString(element, "name"));
    dto.setLabelIndex(getOptionalInt(element, "labelIndex"));
    dto.setzIndex(getOptionalLong(element, "zIndex"));
    dto.setVersionedComponentId(getString(element, "versionedComponentId"));

    final List<PositionDTO> bends = new ArrayList<>();
    final Element bendPointsElement = DomUtils.getChild(element, "bendPoints");
    if (bendPointsElement != null) {
        for (final Element bendPointElement : getChildrenByTagName(bendPointsElement, "bendPoint")) {
            final PositionDTO bend = getPosition(bendPointElement);
            bends.add(bend);
        }
    }
    dto.setBends(bends);

    final ConnectableDTO sourceConnectable = new ConnectableDTO();
    dto.setSource(sourceConnectable);
    sourceConnectable.setId(getString(element, "sourceId"));
    sourceConnectable.setGroupId(getString(element, "sourceGroupId"));
    sourceConnectable.setType(getString(element, "sourceType"));

    final ConnectableDTO destConnectable = new ConnectableDTO();
    dto.setDestination(destConnectable);
    destConnectable.setId(getString(element, "destinationId"));
    destConnectable.setGroupId(getString(element, "destinationGroupId"));
    destConnectable.setType(getString(element, "destinationType"));

    final Set<String> relationships = new HashSet<>();
    final List<Element> relationshipNodeList = getChildrenByTagName(element, "relationship");
    for (final Element relationshipElem : relationshipNodeList) {
        relationships.add(relationshipElem.getTextContent());
    }
    dto.setSelectedRelationships(relationships);

    dto.setBackPressureObjectThreshold(getLong(element, "maxWorkQueueSize"));

    final String maxDataSize = getString(element, "maxWorkQueueDataSize");
    if (maxDataSize != null && !maxDataSize.trim().isEmpty()) {
        dto.setBackPressureDataSizeThreshold(maxDataSize);
    }

    String expiration = getString(element, "flowFileExpiration");
    if (expiration == null) {
        expiration = "0 sec";
    }
    dto.setFlowFileExpiration(expiration);

    final List<String> prioritizerClasses = new ArrayList<>();
    final List<Element> prioritizerNodeList = getChildrenByTagName(element, "queuePrioritizerClass");
    for (final Element prioritizerElement : prioritizerNodeList) {
        prioritizerClasses.add(prioritizerElement.getTextContent().trim());
    }
    dto.setPrioritizers(prioritizerClasses);

    dto.setLoadBalanceStrategy(getString(element, "loadBalanceStrategy"));
    dto.setLoadBalancePartitionAttribute(getString(element, "partitioningAttribute"));
    dto.setLoadBalanceCompression(getString(element, "loadBalanceCompression"));

    return dto;
}
 
Example 6
Source File: RemoteProcessGroupIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected void testRPGBackToSelf(final SiteToSiteTransportProtocol protocol, final String portName) throws NiFiClientException, IOException, InterruptedException {
    final NiFiClientUtil util = getClientUtil();

    // Create a flow that is InputPort -> CountEvents
    final PortEntity port = util.createRemoteInputPort("root", portName);
    final ProcessorEntity count = getClientUtil().createProcessor("CountEvents");
    util.setAutoTerminatedRelationships(count, "success");

    // Create a flow that is GenerateFlowFile -> RPG, connected to the input port
    final ProcessorEntity generateFlowFile = getClientUtil().createProcessor("GenerateFlowFile");
    RemoteProcessGroupEntity rpg = getClientUtil().createRPG("root", protocol);

    util.updateProcessorProperties(generateFlowFile, Collections.singletonMap("File Size", "1 KB"));
    util.updateProcessorProperties(generateFlowFile, Collections.singletonMap("Batch Size", "3"));
    util.updateProcessorSchedulingPeriod(generateFlowFile, "10 min");

    final String rpgId = rpg.getId();

    // Wait for the port to become available. We have to check for the specific port ID because otherwise,
    // the RPG may have an old Port ID cached, since we are running an HTTP-based test and a RAW-based test
    waitFor(() -> {
        try {
            final RemoteProcessGroupEntity entity = getNifiClient().getRemoteProcessGroupClient().getRemoteProcessGroup(rpgId);
            final Set<RemoteProcessGroupPortDTO> ports = entity.getComponent().getContents().getInputPorts();
            if (ports.isEmpty()) {
                return false;
            }

            for (final RemoteProcessGroupPortDTO dto : ports) {
                if (dto.getTargetId().equals(port.getId())) {
                    return true;
                }
            }

            return false;
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail("Could not retrieve RPG with ID " + rpgId);
            return false;
        }
    });

    rpg = getNifiClient().getRemoteProcessGroupClient().getRemoteProcessGroup(rpg.getId());
    final String rpgPortId = rpg.getComponent().getContents().getInputPorts().stream()
        .filter(dto -> dto.getTargetId().equals(port.getId()))
        .findFirst() // find the port with the desired ID
        .get() // get the Port
        .getId(); // get the Port's ID

    final ConnectableDTO destination = new ConnectableDTO();
    destination.setId(rpgPortId);
    destination.setGroupId(rpg.getId());
    destination.setType("REMOTE_INPUT_PORT");

    final ConnectionEntity generateToRPG = getClientUtil().createConnection(util.createConnectableDTO(generateFlowFile), destination, "success");
    final ConnectionEntity portToCount = getClientUtil().createConnection(util.createConnectableDTO(port), util.createConnectableDTO(count), "");

    getNifiClient().getInputPortClient().startInputPort(port);
    getNifiClient().getProcessorClient().startProcessor(generateFlowFile);
    getNifiClient().getRemoteProcessGroupClient().startTransmitting(rpg);

    waitFor(() -> util.getQueueSize(generateToRPG.getId()).getObjectCount() == 0);
    waitFor(() -> util.getQueueSize(portToCount.getId()).getObjectCount() == 3 * getNumberOfNodes());
}