Search in sources :

Example 1 with CollectionOverlap

use of org.apache.nifi.minifi.commons.schema.common.CollectionOverlap in project nifi-minifi by apache.

the class ConfigSchemaV1 method getConnectionSchemas.

protected List<ConnectionSchema> getConnectionSchemas(List<ProcessorSchema> processors, List<String> validationIssues) {
    Set<UUID> ids = new HashSet<>();
    Map<String, String> processorNameToIdMap = new HashMap<>();
    // We can't look up id by name for names that appear more than once
    Set<String> duplicateProcessorNames = new HashSet<>();
    if (processors != null) {
        processors.stream().forEachOrdered(p -> processorNameToIdMap.put(p.getName(), p.getId()));
        duplicateProcessorNames = new CollectionOverlap<>(processors.stream().map(ProcessorSchema::getName)).getDuplicates();
    }
    Set<String> remoteInputPortIds = new HashSet<>();
    if (remoteProcessingGroups != null) {
        remoteInputPortIds.addAll(remoteProcessingGroups.stream().filter(r -> r.getInputPorts() != null).flatMap(r -> r.getInputPorts().stream()).map(RemotePortSchema::getId).collect(Collectors.toSet()));
    }
    Set<String> problematicDuplicateNames = new HashSet<>();
    List<ConnectionSchema> connectionSchemas = new ArrayList<>(connections.size());
    for (ConnectionSchemaV1 connection : connections) {
        ConnectionSchema convert = connection.convert();
        convert.setId(getUniqueId(ids, convert.getName()));
        String sourceName = connection.getSourceName();
        if (remoteInputPortIds.contains(sourceName)) {
            convert.setSourceId(sourceName);
        } else {
            if (duplicateProcessorNames.contains(sourceName)) {
                problematicDuplicateNames.add(sourceName);
            }
            String sourceId = processorNameToIdMap.get(sourceName);
            if (!StringUtil.isNullOrEmpty(sourceId)) {
                convert.setSourceId(sourceId);
            }
        }
        String destinationName = connection.getDestinationName();
        if (remoteInputPortIds.contains(destinationName)) {
            convert.setDestinationId(destinationName);
        } else {
            if (duplicateProcessorNames.contains(destinationName)) {
                problematicDuplicateNames.add(destinationName);
            }
            String destinationId = processorNameToIdMap.get(destinationName);
            if (!StringUtil.isNullOrEmpty(destinationId)) {
                convert.setDestinationId(destinationId);
            }
        }
        connectionSchemas.add(convert);
    }
    if (problematicDuplicateNames.size() > 0) {
        validationIssues.add(CANNOT_LOOK_UP_PROCESSOR_ID_FROM_PROCESSOR_NAME_DUE_TO_DUPLICATE_PROCESSOR_NAMES + problematicDuplicateNames.stream().collect(Collectors.joining(", ")));
    }
    return connectionSchemas;
}
Also used : RemotePortSchema(org.apache.nifi.minifi.commons.schema.RemotePortSchema) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema) ProcessorSchema(org.apache.nifi.minifi.commons.schema.ProcessorSchema) BaseSchema(org.apache.nifi.minifi.commons.schema.common.BaseSchema) FLOW_CONTROLLER_PROPS_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.FLOW_CONTROLLER_PROPS_KEY) HashMap(java.util.HashMap) PROCESSORS_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.PROCESSORS_KEY) ContentRepositorySchema(org.apache.nifi.minifi.commons.schema.ContentRepositorySchema) ArrayList(java.util.ArrayList) PROVENANCE_REPORTING_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.PROVENANCE_REPORTING_KEY) FlowControllerSchema(org.apache.nifi.minifi.commons.schema.FlowControllerSchema) HashSet(java.util.HashSet) TOP_LEVEL_NAME(org.apache.nifi.minifi.commons.schema.ConfigSchema.TOP_LEVEL_NAME) CONNECTIONS_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.CONNECTIONS_KEY) ProvenanceRepositorySchema(org.apache.nifi.minifi.commons.schema.ProvenanceRepositorySchema) SECURITY_PROPS_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.SECURITY_PROPS_KEY) StringUtil(org.apache.nifi.minifi.commons.schema.common.StringUtil) Map(java.util.Map) CollectionOverlap(org.apache.nifi.minifi.commons.schema.common.CollectionOverlap) FLOWFILE_REPO_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.FLOWFILE_REPO_KEY) CorePropertiesSchema(org.apache.nifi.minifi.commons.schema.CorePropertiesSchema) FlowFileRepositorySchema(org.apache.nifi.minifi.commons.schema.FlowFileRepositorySchema) ConvertableSchema(org.apache.nifi.minifi.commons.schema.common.ConvertableSchema) Set(java.util.Set) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema) CORE_PROPS_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.CORE_PROPS_KEY) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ProvenanceReportingSchema(org.apache.nifi.minifi.commons.schema.ProvenanceReportingSchema) COMPONENT_STATUS_REPO_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.COMPONENT_STATUS_REPO_KEY) SecurityPropertiesSchema(org.apache.nifi.minifi.commons.schema.SecurityPropertiesSchema) List(java.util.List) VERSION(org.apache.nifi.minifi.commons.schema.ConfigSchema.VERSION) PROVENANCE_REPO_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.PROVENANCE_REPO_KEY) CONTENT_REPO_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.CONTENT_REPO_KEY) REMOTE_PROCESS_GROUPS_KEY(org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.REMOTE_PROCESS_GROUPS_KEY) ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) ComponentStatusRepositorySchema(org.apache.nifi.minifi.commons.schema.ComponentStatusRepositorySchema) ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) HashMap(java.util.HashMap) RemotePortSchema(org.apache.nifi.minifi.commons.schema.RemotePortSchema) ArrayList(java.util.ArrayList) UUID(java.util.UUID) CollectionOverlap(org.apache.nifi.minifi.commons.schema.common.CollectionOverlap) HashSet(java.util.HashSet)

Aggregations

StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 ComponentStatusRepositorySchema (org.apache.nifi.minifi.commons.schema.ComponentStatusRepositorySchema)1 ConfigSchema (org.apache.nifi.minifi.commons.schema.ConfigSchema)1 TOP_LEVEL_NAME (org.apache.nifi.minifi.commons.schema.ConfigSchema.TOP_LEVEL_NAME)1 VERSION (org.apache.nifi.minifi.commons.schema.ConfigSchema.VERSION)1 ConnectionSchema (org.apache.nifi.minifi.commons.schema.ConnectionSchema)1 ContentRepositorySchema (org.apache.nifi.minifi.commons.schema.ContentRepositorySchema)1 CorePropertiesSchema (org.apache.nifi.minifi.commons.schema.CorePropertiesSchema)1 FlowControllerSchema (org.apache.nifi.minifi.commons.schema.FlowControllerSchema)1 FlowFileRepositorySchema (org.apache.nifi.minifi.commons.schema.FlowFileRepositorySchema)1 ProcessorSchema (org.apache.nifi.minifi.commons.schema.ProcessorSchema)1 ProvenanceReportingSchema (org.apache.nifi.minifi.commons.schema.ProvenanceReportingSchema)1