Github user JPercivall commented on a diff in the pull request:
https://github.com/apache/nifi-minifi/pull/33#discussion_r79514742
--- Diff:
minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/ConfigSchema.java
---
@@ -96,51 +100,154 @@ public ConfigSchema(Map map) {
addIssuesIfNotNull(provenanceReportingProperties);
addIssuesIfNotNull(provenanceRepositorySchema);
+ Set<String> processorIds = new HashSet<>();
if (processors != null) {
-
checkForDuplicateNames(FOUND_THE_FOLLOWING_DUPLICATE_PROCESSOR_NAMES,
processors.stream().map(ProcessorSchema::getName).collect(Collectors.toList()));
+ List<String> processorIdList =
processors.stream().map(ProcessorSchema::getId).collect(Collectors.toList());
+ checkForDuplicates(this::addValidationIssue,
FOUND_THE_FOLLOWING_DUPLICATE_PROCESSOR_IDS, processorIdList);
for (ProcessorSchema processorSchema : processors) {
addIssuesIfNotNull(processorSchema);
}
+ processorIds.addAll(processorIdList);
}
if (connections != null) {
-
checkForDuplicateNames(FOUND_THE_FOLLOWING_DUPLICATE_CONNECTION_NAMES,
connections.stream().map(ConnectionSchema::getName).collect(Collectors.toList()));
+ List<String> idList =
connections.stream().map(ConnectionSchema::getId).filter(s ->
!StringUtil.isNullOrEmpty(s)).collect(Collectors.toList());
+ checkForDuplicates(this::addValidationIssue,
FOUND_THE_FOLLOWING_DUPLICATE_CONNECTION_IDS, idList);
for (ConnectionSchema connectionSchema : connections) {
addIssuesIfNotNull(connectionSchema);
}
}
+ Set<String> remoteInputPortIds = new HashSet<>();
if (remoteProcessingGroups != null) {
-
checkForDuplicateNames(FOUND_THE_FOLLOWING_DUPLICATE_REMOTE_PROCESSING_GROUP_NAMES,
remoteProcessingGroups.stream().map(RemoteProcessingGroupSchema::getName).collect(Collectors.toList()));
+ checkForDuplicates(this::addValidationIssue,
FOUND_THE_FOLLOWING_DUPLICATE_REMOTE_PROCESSING_GROUP_NAMES,
+
remoteProcessingGroups.stream().map(RemoteProcessingGroupSchema::getName).collect(Collectors.toList()));
for (RemoteProcessingGroupSchema remoteProcessingGroupSchema :
remoteProcessingGroups) {
addIssuesIfNotNull(remoteProcessingGroupSchema);
}
+ List<RemoteProcessingGroupSchema> remoteProcessingGroups =
getRemoteProcessingGroups();
+ if (remoteProcessingGroups != null) {
+ List<String> remoteInputPortIdList =
remoteProcessingGroups.stream().filter(r -> r.getInputPorts() != null)
+ .flatMap(r ->
r.getInputPorts().stream()).map(RemoteInputPortSchema::getId).collect(Collectors.toList());
+ checkForDuplicates(this::addValidationIssue,
FOUND_THE_FOLLOWING_DUPLICATE_REMOTE_INPUT_PORT_IDS, remoteInputPortIdList);
+ remoteInputPortIds.addAll(remoteInputPortIdList);
+ }
+ }
+
+ Set<String> duplicateIds = new HashSet<>(processorIds);
+ duplicateIds.retainAll(remoteInputPortIds);
+ if (duplicateIds.size() > 0) {
+ addValidationIssue(FOUND_THE_FOLLOWING_DUPLICATE_IDS +
duplicateIds.stream().sorted().collect(Collectors.joining(", ")));
+ }
+ }
+
+ protected List<ProcessorSchema> getProcessorSchemas(List<Map>
processorMaps) {
+ if (processorMaps == null) {
+ return null;
}
+ List<ProcessorSchema> processors =
convertListToType(processorMaps, "processor", ProcessorSchema.class,
PROCESSORS_KEY);
+
+ Map<String, Integer> idMap =
processors.stream().map(ProcessorSchema::getId).filter(
+ s ->
!StringUtil.isNullOrEmpty(s)).collect(Collectors.toMap(Function.identity(), s
-> 2, Integer::compareTo));
+
+ // Set unset ids
+ processors.stream().filter(connection ->
StringUtil.isNullOrEmpty(connection.getId())).forEachOrdered(processor ->
processor.setId(getUniqueId(idMap, processor.getName())));
+
+ return processors;
}
- private void checkForDuplicateNames(String errorMessagePrefix,
List<String> names) {
- if (names != null) {
- Set<String> seenNames = new HashSet<>();
- Set<String> duplicateNames = new TreeSet<>();
- for (String name : names) {
- if (!seenNames.add(name)) {
- duplicateNames.add(name);
+ protected List<ConnectionSchema> getConnectionSchemas(List<Map>
connectionMaps) {
+ if (connectionMaps == null) {
+ return null;
+ }
+ List<ConnectionSchema> connections =
convertListToType(connectionMaps, "connection", ConnectionSchema.class,
CONNECTIONS_KEY);
+ Map<String, Integer> idMap =
connections.stream().map(ConnectionSchema::getId).filter(
+ s ->
!StringUtil.isNullOrEmpty(s)).collect(Collectors.toMap(Function.identity(), s
-> 2, Integer::compareTo));
+
+ 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<>();
+
+ List<ProcessorSchema> processors = getProcessors();
+ if (processors != null) {
+ processors.stream().forEachOrdered(p ->
processorNameToIdMap.put(p.getName(), p.getId()));
+
+ Set<String> processorNames = new HashSet<>();
+
processors.stream().map(ProcessorSchema::getName).forEachOrdered(n -> {
+ if (!processorNames.add(n)) {
+ duplicateProcessorNames.add(n);
}
+ });
+ }
+
+ Set<String> remoteInputPortIds = new HashSet<>();
+ List<RemoteProcessingGroupSchema> remoteProcessingGroups =
getRemoteProcessingGroups();
+ if (remoteProcessingGroups != null) {
+
remoteInputPortIds.addAll(remoteProcessingGroups.stream().filter(r ->
r.getInputPorts() != null)
+ .flatMap(r ->
r.getInputPorts().stream()).map(RemoteInputPortSchema::getId).collect(Collectors.toSet()));
+ }
+
+ Set<String> problematicDuplicateNames = new HashSet<>();
+ // Set unset ids
+ connections.stream().filter(connection ->
StringUtil.isNullOrEmpty(connection.getId())).forEachOrdered(connection ->
connection.setId(getUniqueId(idMap, connection.getName())));
+
+ connections.stream().filter(connection ->
StringUtil.isNullOrEmpty(connection.getSourceId())).forEach(connection -> {
+ String sourceName = connection.getSourceName();
+ if (remoteInputPortIds.contains(sourceName)) {
+ connection.setSourceId(sourceName);
+ } else {
+ if (duplicateProcessorNames.contains(sourceName)) {
+ problematicDuplicateNames.add(sourceName);
+ }
+
connection.setSourceId(processorNameToIdMap.get(sourceName));
--- End diff --
This (and the corresponding line for dest names) should check if source
name is actually in the list of processors (it's already checking if it's in
the list of remote input ports). I tested a flow where I didn't put the right
name for "source name" and got this confusing error message:
Exception in thread "main" java.io.IOException: Unable to successfully
transform the provided configuration
at
org.apache.nifi.minifi.bootstrap.RunMiNiFi.performTransformation(RunMiNiFi.java:1543)
at org.apache.nifi.minifi.bootstrap.RunMiNiFi.start(RunMiNiFi.java:1083)
at org.apache.nifi.minifi.bootstrap.RunMiNiFi.main(RunMiNiFi.java:215)
Caused by:
org.apache.nifi.minifi.bootstrap.exception.InvalidConfigurationException:
Failed to transform config file due to:['source id' in section 'Connections'
because it was not found and it is required]
at
org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.transformConfigFile(ConfigTransformer.java:92)
at
org.apache.nifi.minifi.bootstrap.RunMiNiFi.performTransformation(RunMiNiFi.java:1539)
... 2 more
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---