org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO Java Examples

The following examples show how to use org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO. 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: RemoteProcessGroupSchemaTest.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    remoteInputPortSchemaTest.setup();

    dto = new RemoteProcessGroupDTO();
    dto.setId(testId);
    dto.setName(testName);
    dto.setTargetUri(testUrl);

    RemoteProcessGroupContentsDTO contents = new RemoteProcessGroupContentsDTO();
    contents.setInputPorts(Arrays.asList(remoteInputPortSchemaTest.dto).stream().collect(Collectors.toSet()));
    dto.setContents(contents);

    dto.setComments(testComment);
    dto.setCommunicationsTimeout(testTimeout);
    dto.setYieldDuration(testYieldPeriod);
    dto.setTransportProtocol(transportProtocol);

    map = new HashMap<>();

    map.put(CommonPropertyKeys.ID_KEY, testId);
    map.put(CommonPropertyKeys.NAME_KEY, testName);
    map.put(RemoteProcessGroupSchema.URL_KEY, testUrl);
    map.put(CommonPropertyKeys.INPUT_PORTS_KEY, new ArrayList<>(Arrays.asList(remoteInputPortSchemaTest.map)));
    map.put(CommonPropertyKeys.COMMENT_KEY, testComment);
    map.put(RemoteProcessGroupSchema.TIMEOUT_KEY, testTimeout);
    map.put(CommonPropertyKeys.YIELD_PERIOD_KEY, testYieldPeriod);
    map.put(RemoteProcessGroupSchema.TRANSPORT_PROTOCOL_KEY, transportProtocol);
}
 
Example #2
Source File: RemoteProcessGroupEntityMerger.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private static void mergeDtos(final RemoteProcessGroupDTO clientDto, final Map<NodeIdentifier, RemoteProcessGroupDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }

    final RemoteProcessGroupContentsDTO remoteProcessGroupContents = clientDto.getContents();

    final Map<String, Set<NodeIdentifier>> authorizationErrorMap = new HashMap<>();
    final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
    Boolean mergedIsTargetSecure = null;
    final Set<RemoteProcessGroupPortDTO> mergedInputPorts = new HashSet<>();
    final Set<RemoteProcessGroupPortDTO> mergedOutputPorts = new HashSet<>();

    for (final Map.Entry<NodeIdentifier, RemoteProcessGroupDTO> nodeEntry : dtoMap.entrySet()) {
        final RemoteProcessGroupDTO nodeRemoteProcessGroup = nodeEntry.getValue();

        // consider the node remote process group when authorized
        if (nodeRemoteProcessGroup != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();

            // merge the authorization errors
            ErrorMerger.mergeErrors(authorizationErrorMap, nodeId, nodeRemoteProcessGroup.getAuthorizationIssues());
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeRemoteProcessGroup.getValidationErrors());

            // use the first target secure flag since they will all be the same
            final Boolean nodeIsTargetSecure = nodeRemoteProcessGroup.isTargetSecure();
            if (mergedIsTargetSecure == null) {
                mergedIsTargetSecure = nodeIsTargetSecure;
            }

            // merge the ports in the contents
            final RemoteProcessGroupContentsDTO nodeRemoteProcessGroupContentsDto = nodeRemoteProcessGroup.getContents();
            if (remoteProcessGroupContents != null && nodeRemoteProcessGroupContentsDto != null) {
                if (nodeRemoteProcessGroupContentsDto.getInputPorts() != null) {
                    mergedInputPorts.addAll(nodeRemoteProcessGroupContentsDto.getInputPorts());
                }
                if (nodeRemoteProcessGroupContentsDto.getOutputPorts() != null) {
                    mergedOutputPorts.addAll(nodeRemoteProcessGroupContentsDto.getOutputPorts());
                }
            }
        }

    }

    if (remoteProcessGroupContents != null) {
        if (!mergedInputPorts.isEmpty()) {
            remoteProcessGroupContents.setInputPorts(mergedInputPorts);
        }
        if (!mergedOutputPorts.isEmpty()) {
            remoteProcessGroupContents.setOutputPorts(mergedOutputPorts);
        }
    }

    if (mergedIsTargetSecure != null) {
        clientDto.setTargetSecure(mergedIsTargetSecure);
    }

    // set the merged the validation errors
    clientDto.setAuthorizationIssues(ErrorMerger.normalizedMergedErrors(authorizationErrorMap, dtoMap.size()));
    clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
 
Example #3
Source File: RemoteProcessGroupSchemaFunction.java    From nifi-minifi with Apache License 2.0 4 votes vote down vote up
@Override
public RemoteProcessGroupSchema apply(RemoteProcessGroupDTO remoteProcessGroupDTO) {
    Map<String, Object> map = new HashMap<>();
    map.put(CommonPropertyKeys.ID_KEY, remoteProcessGroupDTO.getId());
    map.put(CommonPropertyKeys.NAME_KEY, remoteProcessGroupDTO.getName());


    // Prefer the targetUris if populated, otherwise, default to using the singular targetUri
    final String targetUris = remoteProcessGroupDTO.getTargetUris();
    map.put(RemoteProcessGroupSchema.URL_KEY,
            StringUtils.isNotBlank(targetUris) ? targetUris : remoteProcessGroupDTO.getTargetUri());

    RemoteProcessGroupContentsDTO contents = remoteProcessGroupDTO.getContents();
    if (contents != null) {
        Set<RemoteProcessGroupPortDTO> inputPorts = contents.getInputPorts();
        if (inputPorts != null) {
            map.put(CommonPropertyKeys.INPUT_PORTS_KEY, inputPorts.stream()
                    .map(remotePortSchemaFunction)
                    .map(RemotePortSchema::toMap)
                    .collect(Collectors.toList()));
        }
        Set<RemoteProcessGroupPortDTO> outputPorts = contents.getOutputPorts();
        if (outputPorts != null) {
            map.put(CommonPropertyKeys.OUTPUT_PORTS_KEY, outputPorts.stream()
                    .map(remotePortSchemaFunction)
                    .map(RemotePortSchema::toMap)
                    .collect(Collectors.toList()));
        }
    }

    map.put(CommonPropertyKeys.COMMENT_KEY, remoteProcessGroupDTO.getComments());
    map.put(RemoteProcessGroupSchema.TIMEOUT_KEY, remoteProcessGroupDTO.getCommunicationsTimeout());
    map.put(CommonPropertyKeys.YIELD_PERIOD_KEY, remoteProcessGroupDTO.getYieldDuration());
    map.put(RemoteProcessGroupSchema.TRANSPORT_PROTOCOL_KEY, remoteProcessGroupDTO.getTransportProtocol());
    map.put(RemoteProcessGroupSchema.PROXY_HOST_KEY, remoteProcessGroupDTO.getProxyHost());
    map.put(RemoteProcessGroupSchema.PROXY_PORT_KEY, remoteProcessGroupDTO.getProxyPort());
    map.put(RemoteProcessGroupSchema.PROXY_USER_KEY, remoteProcessGroupDTO.getProxyUser());
    map.put(RemoteProcessGroupSchema.PROXY_PASSWORD_KEY, remoteProcessGroupDTO.getProxyPassword());
    map.put(RemoteProcessGroupSchema.LOCAL_NETWORK_INTERFACE_KEY, remoteProcessGroupDTO.getLocalNetworkInterface());
    return new RemoteProcessGroupSchema(map);
}
 
Example #4
Source File: RemoteProcessGroupEntityMerger.java    From nifi with Apache License 2.0 4 votes vote down vote up
private static void mergeDtos(final RemoteProcessGroupDTO clientDto, final Map<NodeIdentifier, RemoteProcessGroupDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }

    final RemoteProcessGroupContentsDTO remoteProcessGroupContents = clientDto.getContents();

    final Map<String, Set<NodeIdentifier>> authorizationErrorMap = new HashMap<>();
    final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();

    Boolean mergedIsTargetSecure = null;
    Set<RemoteProcessGroupPortDTO> mergedInputPorts = null;
    Set<RemoteProcessGroupPortDTO> mergedOutputPorts = null;

    for (final Map.Entry<NodeIdentifier, RemoteProcessGroupDTO> nodeEntry : dtoMap.entrySet()) {
        final RemoteProcessGroupDTO nodeRemoteProcessGroup = nodeEntry.getValue();

        // consider the node remote process group when authorized
        if (nodeRemoteProcessGroup != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();

            // merge the authorization errors
            ErrorMerger.mergeErrors(authorizationErrorMap, nodeId, nodeRemoteProcessGroup.getAuthorizationIssues());
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeRemoteProcessGroup.getValidationErrors());

            // use the first target secure flag since they will all be the same
            final Boolean nodeIsTargetSecure = nodeRemoteProcessGroup.isTargetSecure();
            if (mergedIsTargetSecure == null) {
                mergedIsTargetSecure = nodeIsTargetSecure;
            }

            // merge the ports in the contents
            final RemoteProcessGroupContentsDTO nodeRemoteProcessGroupContentsDto = nodeRemoteProcessGroup.getContents();
            if (remoteProcessGroupContents != null && nodeRemoteProcessGroupContentsDto != null) {
                final Set<RemoteProcessGroupPortDTO> nodeInputPorts = nodeRemoteProcessGroupContentsDto.getInputPorts();
                if (nodeInputPorts != null) {
                    if (mergedInputPorts == null) {
                        mergedInputPorts = new HashSet<>(nodeInputPorts);
                    } else {
                        mergedInputPorts.retainAll(nodeInputPorts);
                    }
                }

                final Set<RemoteProcessGroupPortDTO> nodeOutputPorts = nodeRemoteProcessGroupContentsDto.getOutputPorts();
                if (nodeOutputPorts != null) {
                    if (mergedOutputPorts == null) {
                        mergedOutputPorts = new HashSet<>(nodeOutputPorts);
                    } else {
                        mergedOutputPorts.retainAll(nodeOutputPorts);
                    }
                }
            }
        }
    }

    if (remoteProcessGroupContents != null) {
        if (mergedInputPorts == null) {
            remoteProcessGroupContents.setInputPorts(Collections.emptySet());
            clientDto.setInputPortCount(0);
        } else {
            remoteProcessGroupContents.setInputPorts(mergedInputPorts);
            clientDto.setInputPortCount(mergedInputPorts.size());
        }

        if (mergedOutputPorts == null) {
            remoteProcessGroupContents.setOutputPorts(Collections.emptySet());
            clientDto.setOutputPortCount(0);
        } else {
            remoteProcessGroupContents.setOutputPorts(mergedOutputPorts);
            clientDto.setOutputPortCount(mergedOutputPorts.size());
        }
    }

    if (mergedIsTargetSecure != null) {
        clientDto.setTargetSecure(mergedIsTargetSecure);
    }

    // set the merged the validation errors
    clientDto.setAuthorizationIssues(ErrorMerger.normalizedMergedErrors(authorizationErrorMap, dtoMap.size()));
    clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
 
Example #5
Source File: RemoteProcessGroupEntityMergerTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testMergeRemoteProcessGroups() throws Exception {
    final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1", 8080, "host-1", 19998, null, null, null, false);
    final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2", 8081, "host-2", 19999, null, null, null, false);

    final PermissionsDTO permissions = new PermissionsDTO();
    permissions.setCanRead(true);
    permissions.setCanWrite(true);

    final PermissionsDTO opsPermissions = new PermissionsDTO();
    opsPermissions.setCanRead(false);
    opsPermissions.setCanWrite(false);

    final RemoteProcessGroupStatusDTO status = new RemoteProcessGroupStatusDTO();
    status.setAggregateSnapshot(new RemoteProcessGroupStatusSnapshotDTO());

    final RemoteProcessGroupPortDTO in1_1 = new RemoteProcessGroupPortDTO();
    in1_1.setName("in1");

    final RemoteProcessGroupPortDTO in1_2 = new RemoteProcessGroupPortDTO();
    in1_2.setName("in2");

    final Set<RemoteProcessGroupPortDTO> inputs1 = new HashSet<>();
    inputs1.add(in1_1);
    inputs1.add(in1_2);

    final RemoteProcessGroupPortDTO out1_1 = new RemoteProcessGroupPortDTO();
    out1_1.setName("out1");

    final Set<RemoteProcessGroupPortDTO> outputs1 = new HashSet<>();
    outputs1.add(out1_1);

    final RemoteProcessGroupContentsDTO contents1 = new RemoteProcessGroupContentsDTO();
    contents1.setInputPorts(inputs1);
    contents1.setOutputPorts(outputs1);

    final RemoteProcessGroupDTO rpg1 = new RemoteProcessGroupDTO();
    rpg1.setContents(contents1);

    final RemoteProcessGroupEntity entity1 = new RemoteProcessGroupEntity();
    entity1.setPermissions(permissions);
    entity1.setOperatePermissions(opsPermissions);
    entity1.setStatus(status);
    entity1.setComponent(rpg1);

    final RemoteProcessGroupPortDTO in2_1 = new RemoteProcessGroupPortDTO();
    in2_1.setName("in1");

    final Set<RemoteProcessGroupPortDTO> inputs2 = new HashSet<>();
    inputs2.add(in2_1);

    final RemoteProcessGroupPortDTO out2_1 = new RemoteProcessGroupPortDTO();
    out2_1.setName("out1");

    final RemoteProcessGroupPortDTO out2_2 = new RemoteProcessGroupPortDTO();
    out2_2.setName("out2");

    final Set<RemoteProcessGroupPortDTO> outputs2 = new HashSet<>();
    outputs2.add(out2_1);
    outputs2.add(out2_2);

    final RemoteProcessGroupContentsDTO contents2 = new RemoteProcessGroupContentsDTO();
    contents2.setInputPorts(inputs2);
    contents2.setOutputPorts(outputs2);

    final RemoteProcessGroupDTO rpg2 = new RemoteProcessGroupDTO();
    rpg2.setContents(contents2);

    final RemoteProcessGroupEntity entity2 = new RemoteProcessGroupEntity();
    entity2.setPermissions(permissions);
    entity2.setOperatePermissions(opsPermissions);
    entity2.setStatus(status);
    entity2.setComponent(rpg2);

    final Map<NodeIdentifier, RemoteProcessGroupEntity> nodeMap = new HashMap<>();
    nodeMap.put(node1, entity1);
    nodeMap.put(node2, entity2);

    final RemoteProcessGroupEntityMerger merger = new RemoteProcessGroupEntityMerger();
    merger.merge(entity1, nodeMap);

    // should only include ports in common to all rpg's
    assertEquals(1, entity1.getComponent().getContents().getInputPorts().size());
    assertEquals("in1", entity1.getComponent().getContents().getInputPorts().iterator().next().getName());
    assertEquals(1, entity1.getComponent().getContents().getOutputPorts().size());
    assertEquals("out1", entity1.getComponent().getContents().getOutputPorts().iterator().next().getName());
}
 
Example #6
Source File: RemoteProcessGroupEntityMergerTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoPortsAvailableOnOneNode() throws Exception {
    final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1", 8080, "host-1", 19998, null, null, null, false);
    final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2", 8081, "host-2", 19999, null, null, null, false);

    final PermissionsDTO permissions = new PermissionsDTO();
    permissions.setCanRead(true);
    permissions.setCanWrite(true);

    final PermissionsDTO opsPermissions = new PermissionsDTO();
    opsPermissions.setCanRead(false);
    opsPermissions.setCanWrite(false);

    final RemoteProcessGroupStatusDTO status = new RemoteProcessGroupStatusDTO();
    status.setAggregateSnapshot(new RemoteProcessGroupStatusSnapshotDTO());

    final RemoteProcessGroupPortDTO in1_1 = new RemoteProcessGroupPortDTO();
    in1_1.setName("in1");

    final RemoteProcessGroupPortDTO in1_2 = new RemoteProcessGroupPortDTO();
    in1_2.setName("in2");

    final Set<RemoteProcessGroupPortDTO> inputs1 = new HashSet<>();
    inputs1.add(in1_1);
    inputs1.add(in1_2);

    final RemoteProcessGroupPortDTO out1_1 = new RemoteProcessGroupPortDTO();
    out1_1.setName("out1");

    final Set<RemoteProcessGroupPortDTO> outputs1 = new HashSet<>();
    outputs1.add(out1_1);

    final RemoteProcessGroupContentsDTO contents1 = new RemoteProcessGroupContentsDTO();
    contents1.setInputPorts(inputs1);
    contents1.setOutputPorts(outputs1);

    final RemoteProcessGroupDTO rpg1 = new RemoteProcessGroupDTO();
    rpg1.setContents(contents1);
    rpg1.setInputPortCount(2);
    rpg1.setOutputPortCount(1);

    final RemoteProcessGroupEntity entity1 = new RemoteProcessGroupEntity();
    entity1.setPermissions(permissions);
    entity1.setOperatePermissions(opsPermissions);
    entity1.setStatus(status);
    entity1.setComponent(rpg1);

    final Set<RemoteProcessGroupPortDTO> inputs2 = new HashSet<>();
    final Set<RemoteProcessGroupPortDTO> outputs2 = new HashSet<>();

    final RemoteProcessGroupContentsDTO contents2 = new RemoteProcessGroupContentsDTO();
    contents2.setInputPorts(inputs2);
    contents2.setOutputPorts(outputs2);

    final RemoteProcessGroupDTO rpg2 = new RemoteProcessGroupDTO();
    rpg2.setContents(contents2);
    rpg2.setInputPortCount(0);
    rpg2.setOutputPortCount(0);

    final RemoteProcessGroupEntity entity2 = new RemoteProcessGroupEntity();
    entity2.setPermissions(permissions);
    entity2.setOperatePermissions(opsPermissions);
    entity2.setStatus(status);
    entity2.setComponent(rpg2);

    final Map<NodeIdentifier, RemoteProcessGroupEntity> nodeMap = new HashMap<>();
    nodeMap.put(node1, entity1);
    nodeMap.put(node2, entity2);

    final RemoteProcessGroupEntityMerger merger = new RemoteProcessGroupEntityMerger();
    merger.merge(entity1, nodeMap);

    // should only include ports in common to all rpg's
    assertEquals(0, entity1.getComponent().getContents().getInputPorts().size());
    assertEquals(0, entity1.getComponent().getContents().getOutputPorts().size());
    assertEquals(0, entity1.getComponent().getInputPortCount().intValue());
    assertEquals(0, entity1.getComponent().getOutputPortCount().intValue());
}