exceptionfactory commented on code in PR #10530:
URL: https://github.com/apache/nifi/pull/10530#discussion_r2529958962
##########
nifi-extension-bundles/nifi-extension-utils/nifi-event-listen/src/main/java/org/apache/nifi/processor/util/listen/AbstractListenEventProcessor.java:
##########
@@ -194,6 +200,21 @@ public void onScheduled(final ProcessContext context)
throws IOException {
readerThread.start();
}
+ @Override
+ public List<ListenPort> getListenPorts(final ConfigurationContext context)
{
+ final Integer portNumber =
context.getProperty(PORT).evaluateAttributeExpressions().asInteger();
+ if (portNumber != null) {
+ final ListenPort port = StandardListenPort.builder()
+ .portNumber(portNumber)
+ .portName(PORT.getDisplayName())
+ .transportProtocol(TransportProtocol.TCP)
+ .applicationProtocols(List.of("ftp"))
+ .build();
+ return List.of(port);
+ }
+ return Collections.emptyList();
Review Comment:
Recommend refactoring to a single return:
```suggestion
final Integer portNumber =
context.getProperty(PORT).evaluateAttributeExpressions().asInteger();
final List<ListenPort> ports;
if (portNumber == null) {
ports = List.of();
} else {
final ListenPort port = StandardListenPort.builder()
.portNumber(portNumber)
.portName(PORT.getDisplayName())
.transportProtocol(TransportProtocol.TCP)
.applicationProtocols(List.of("ftp"))
.build();
ports = List.of(port);
}
return ports;
```
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenTCP.java:
##########
@@ -87,10 +93,19 @@
@WritesAttribute(attribute = "client.certificate.subject.dn",
description = "For connections using mutual TLS, the Distinguished Name of the
" +
"client certificate's owner (subject) is attached to the
FlowFile.")
})
-public class ListenTCP extends AbstractProcessor {
+public class ListenTCP extends AbstractProcessor implements ListenComponent {
private static final String CLIENT_CERTIFICATE_SUBJECT_DN_ATTRIBUTE =
"client.certificate.subject.dn";
private static final String CLIENT_CERTIFICATE_ISSUER_DN_ATTRIBUTE =
"client.certificate.issuer.dn";
+ public static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The port to listen on for TCP connections.")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
+
.identifiesListenPort(org.apache.nifi.components.listen.TransportProtocol.TCP)
Review Comment:
```suggestion
.identifiesListenPort(TransportProtocol.TCP)
```
##########
nifi-extension-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/ListenTrapSNMP.java:
##########
@@ -70,13 +76,14 @@
@WritesAttribute(attribute = SNMPUtils.SNMP_PROP_PREFIX + "*", description =
"Attributes retrieved from the SNMP response. It may include:"
+ " snmp$errorIndex, snmp$errorStatus, snmp$errorStatusText,
snmp$nonRepeaters, snmp$requestID, snmp$type, snmp$variableBindings")
@RequiresInstanceClassLoading
-public class ListenTrapSNMP extends AbstractSessionFactoryProcessor implements
VerifiableProcessor {
+public class ListenTrapSNMP extends AbstractSessionFactoryProcessor implements
VerifiableProcessor, ListenComponent {
public static final PropertyDescriptor SNMP_MANAGER_PORT = new
PropertyDescriptor.Builder()
.name("SNMP Manager Port")
.description("The port where the SNMP Manager listens to the
incoming traps.")
.required(true)
.addValidator(StandardValidators.PORT_VALIDATOR)
+ .identifiesListenPort(TransportProtocol.UDP, "snmptrap")
Review Comment:
It seems like this should be `snmp`:
```suggestion
.identifiesListenPort(TransportProtocol.UDP, "snmp")
```
##########
nifi-extension-bundles/nifi-opentelemetry-bundle/nifi-opentelemetry-processors/src/main/java/org/apache/nifi/processors/opentelemetry/ListenOTLP.java:
##########
@@ -85,6 +90,7 @@ public class ListenOTLP extends AbstractProcessor {
.description("TCP port number on which to listen for OTLP Export
Service Requests over HTTP and gRPC")
.required(true)
.defaultValue("4317")
+ .identifiesListenPort(TransportProtocol.TCP, "http/1.1", "h2",
"grpc", "otlp")
Review Comment:
Although minor, what do you think about defining static variables for these
protocols and reusing in the `getListenPorts()` method?
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenTCP.java:
##########
@@ -211,6 +226,20 @@ public void onScheduled(ProcessContext context) throws
IOException {
}
}
+ @Override
+ public List<ListenPort> getListenPorts(final ConfigurationContext context)
{
+ final Integer portNumber =
context.getProperty(PORT).evaluateAttributeExpressions().asInteger();
+ if (portNumber != null) {
+ final ListenPort port = StandardListenPort.builder()
+ .portNumber(portNumber)
+ .portName(PORT.getDisplayName())
+
.transportProtocol(org.apache.nifi.components.listen.TransportProtocol.TCP)
Review Comment:
```suggestion
.transportProtocol(TransportProtocol.TCP)
```
##########
nifi-extension-bundles/nifi-extension-utils/nifi-event-listen/src/main/java/org/apache/nifi/processor/util/listen/AbstractListenEventProcessor.java:
##########
@@ -56,13 +61,14 @@
*
* @param <E> the type of events being produced
*/
-public abstract class AbstractListenEventProcessor<E extends Event> extends
AbstractProcessor {
+public abstract class AbstractListenEventProcessor<E extends Event> extends
AbstractProcessor implements ListenComponent {
public static final PropertyDescriptor PORT = new PropertyDescriptor
.Builder().name("Port")
.description("The port to listen on for communication.")
.required(true)
.expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
+ .identifiesListenPort(TransportProtocol.UDP)
Review Comment:
```suggestion
.identifiesListenPort(TransportProtocol.TCP)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]