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;
}
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;
}
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;
}
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));
}
Aggregations