Search in sources :

Example 6 with ConnectionSchema

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

the class NiFiRegConnectionSchemaFunction method apply.

@Override
public ConnectionSchema apply(final VersionedConnection versionedConnection) {
    Map<String, Object> map = new HashMap<>();
    map.put(ID_KEY, versionedConnection.getIdentifier());
    map.put(NAME_KEY, versionedConnection.getName());
    map.put(ConnectionSchema.SOURCE_ID_KEY, versionedConnection.getSource().getId());
    Set<String> selectedRelationships = nullToEmpty(versionedConnection.getSelectedRelationships());
    map.put(ConnectionSchema.SOURCE_RELATIONSHIP_NAMES_KEY, selectedRelationships.stream().sorted().collect(Collectors.toList()));
    map.put(ConnectionSchema.DESTINATION_ID_KEY, versionedConnection.getDestination().getId());
    map.put(ConnectionSchema.MAX_WORK_QUEUE_SIZE_KEY, versionedConnection.getBackPressureObjectThreshold());
    map.put(ConnectionSchema.MAX_WORK_QUEUE_DATA_SIZE_KEY, versionedConnection.getBackPressureDataSizeThreshold());
    map.put(ConnectionSchema.FLOWFILE_EXPIRATION__KEY, versionedConnection.getFlowFileExpiration());
    List<String> queuePrioritizers = nullToEmpty(versionedConnection.getPrioritizers());
    if (queuePrioritizers.size() > 0) {
        map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, queuePrioritizers.get(0));
    }
    ConnectionSchema connectionSchema = new ConnectionSchema(map);
    if (ConnectableType.FUNNEL.name().equals(versionedConnection.getSource().getType())) {
        connectionSchema.addValidationIssue("Connection " + versionedConnection.getName() + " has type " + ConnectableType.FUNNEL.name() + " which is not supported by MiNiFi");
    }
    if (queuePrioritizers.size() > 1) {
        connectionSchema.addValidationIssue(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, CONNECTIONS_KEY, " has more than one queue prioritizer");
    }
    return connectionSchema;
}
Also used : ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) HashMap(java.util.HashMap)

Example 7 with ConnectionSchema

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

the class ConnectionSchemaFunction method apply.

@Override
public ConnectionSchema apply(ConnectionDTO connectionDTO) {
    Map<String, Object> map = new HashMap<>();
    map.put(ID_KEY, connectionDTO.getId());
    map.put(NAME_KEY, connectionDTO.getName());
    map.put(ConnectionSchema.SOURCE_ID_KEY, connectionDTO.getSource().getId());
    Set<String> selectedRelationships = nullToEmpty(connectionDTO.getSelectedRelationships());
    map.put(ConnectionSchema.SOURCE_RELATIONSHIP_NAMES_KEY, selectedRelationships.stream().sorted().collect(Collectors.toList()));
    map.put(ConnectionSchema.DESTINATION_ID_KEY, connectionDTO.getDestination().getId());
    map.put(ConnectionSchema.MAX_WORK_QUEUE_SIZE_KEY, connectionDTO.getBackPressureObjectThreshold());
    map.put(ConnectionSchema.MAX_WORK_QUEUE_DATA_SIZE_KEY, connectionDTO.getBackPressureDataSizeThreshold());
    map.put(ConnectionSchema.FLOWFILE_EXPIRATION__KEY, connectionDTO.getFlowFileExpiration());
    List<String> queuePrioritizers = nullToEmpty(connectionDTO.getPrioritizers());
    if (queuePrioritizers.size() > 0) {
        map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, queuePrioritizers.get(0));
    }
    ConnectionSchema connectionSchema = new ConnectionSchema(map);
    if (ConnectableType.FUNNEL.name().equals(connectionDTO.getSource().getType())) {
        connectionSchema.addValidationIssue("Connection " + connectionDTO.getName() + " has type " + ConnectableType.FUNNEL.name() + " which is not supported by MiNiFi");
    }
    if (queuePrioritizers.size() > 1) {
        connectionSchema.addValidationIssue(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, CONNECTIONS_KEY, " has more than one queue prioritizer");
    }
    return connectionSchema;
}
Also used : ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) HashMap(java.util.HashMap)

Example 8 with ConnectionSchema

use of org.apache.nifi.minifi.commons.schema.ConnectionSchema 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)

Example 9 with ConnectionSchema

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

the class ConfigTransformerTest method testEmptyQueuePrioritizerNotWritten.

@Test
public void testEmptyQueuePrioritizerNotWritten() throws ConfigurationChangeException, XPathExpressionException {
    Map<String, Object> map = new HashMap<>();
    map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, "");
    ConfigTransformer.addConnection(config, new ConnectionSchema(map), new ParentGroupIdResolver(new ProcessGroupSchema(Collections.emptyMap(), ConfigSchema.TOP_LEVEL_NAME)));
    XPath xpath = xPathFactory.newXPath();
    String expression = "connection/queuePrioritizerClass";
    assertNull(xpath.evaluate(expression, config, XPathConstants.NODE));
}
Also used : ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) XPath(javax.xml.xpath.XPath) HashMap(java.util.HashMap) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema) ProcessGroupSchema(org.apache.nifi.minifi.commons.schema.ProcessGroupSchema) Test(org.junit.Test)

Aggregations

ConnectionSchema (org.apache.nifi.minifi.commons.schema.ConnectionSchema)9 HashMap (java.util.HashMap)7 RemoteProcessGroupSchema (org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema)6 ProcessGroupSchema (org.apache.nifi.minifi.commons.schema.ProcessGroupSchema)4 Test (org.junit.Test)4 Map (java.util.Map)3 XPath (javax.xml.xpath.XPath)3 ConfigSchema (org.apache.nifi.minifi.commons.schema.ConfigSchema)3 ProcessorSchema (org.apache.nifi.minifi.commons.schema.ProcessorSchema)3 RemotePortSchema (org.apache.nifi.minifi.commons.schema.RemotePortSchema)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 ConvertableSchema (org.apache.nifi.minifi.commons.schema.common.ConvertableSchema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1