You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/10/31 19:57:14 UTC
[GitHub] [nifi] thenatog opened a new pull request, #6606: NIFI-10738 - Updated SNMP tests to retry when BindException occurs.
thenatog opened a new pull request, #6606:
URL: https://github.com/apache/nifi/pull/6606
<!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
<!-- contributor license agreements. See the NOTICE file distributed with -->
<!-- this work for additional information regarding copyright ownership. -->
<!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
<!-- (the "License"); you may not use this file except in compliance with -->
<!-- the License. You may obtain a copy of the License at -->
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
<!-- Unless required by applicable law or agreed to in writing, software -->
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
<!-- See the License for the specific language governing permissions and -->
<!-- limitations under the License. -->
# Summary
[NIFI-10738](https://issues.apache.org/jira/browse/NIFI-10738)
# Tracking
Please complete the following tracking steps prior to pull request creation.
### Issue Tracking
- [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI-10738) issue created
### Pull Request Tracking
- [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-10738`
- [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-10738`
### Pull Request Formatting
- [x] Pull Request based on current revision of the `main` branch
- [x] Pull Request refers to a feature branch with one commit containing changes
# Verification
Please indicate the verification steps performed prior to pull request creation.
### Build
- [ ] Build completed using `mvn clean install -P contrib-check`
- [ ] JDK 8
- [x] JDK 11
- [ ] JDK 17
### Licensing
- [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
- [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
### Documentation
- [ ] Documentation formatting appears as expected in rendered files
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] thenatog commented on a diff in pull request #6606: NIFI-10738 - Updated SNMP tests to retry when BindException occurs.
Posted by GitBox <gi...@apache.org>.
thenatog commented on code in PR #6606:
URL: https://github.com/apache/nifi/pull/6606#discussion_r1010923342
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPSocketSupport.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPSocketSupport {
+
+ protected static final int RETRIES = 3;
+
+ protected SNMPConfiguration getSnmpConfiguration(int managerPort, String targetPort) {
+ return new SNMPConfiguration.Builder()
+ .setRetries(RETRIES)
+ .setManagerPort(managerPort)
+ .setTargetHost(LOCALHOST)
+ .setTargetPort(targetPort)
+ .setSecurityLevel(SecurityLevel.authPriv.name())
+ .setSecurityName(SECURITY_NAME)
+ .setAuthProtocol(AUTH_PROTOCOL)
+ .setAuthPassphrase(AUTH_PASSPHRASE)
+ .setPrivacyProtocol(PRIV_PROTOCOL)
+ .setPrivacyPassphrase(PRIV_PASSPHRASE)
+ .build();
+ }
+
+ protected Snmp createSnmpManagerInstance(final Function<SNMPConfiguration, Snmp> runnable, final int retries) {
+ int attempts = 0;
+ while (attempts < retries) {
+ try {
+ return runnable.apply(getSnmpConfiguration(NetworkUtils.getAvailableUdpPort(), String.valueOf(NetworkUtils.getAvailableUdpPort())));
+ } catch (Exception e) {
+ if (e instanceof BindException) {
+ attempts++;
+ if (attempts == retries) {
+ throw e;
+ }
+ }
+ }
+ }
+ return null;
Review Comment:
If I understood this right - I updated the method to throw an IllegalStateException instead of returning null
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] thenatog commented on a diff in pull request #6606: NIFI-10738 - Updated SNMP tests to retry when BindException occurs.
Posted by GitBox <gi...@apache.org>.
thenatog commented on code in PR #6606:
URL: https://github.com/apache/nifi/pull/6606#discussion_r1010924024
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPSocketSupport.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPSocketSupport {
+
+ protected static final int RETRIES = 3;
+
+ protected SNMPConfiguration getSnmpConfiguration(int managerPort, String targetPort) {
+ return new SNMPConfiguration.Builder()
+ .setRetries(RETRIES)
+ .setManagerPort(managerPort)
+ .setTargetHost(LOCALHOST)
+ .setTargetPort(targetPort)
+ .setSecurityLevel(SecurityLevel.authPriv.name())
+ .setSecurityName(SECURITY_NAME)
+ .setAuthProtocol(AUTH_PROTOCOL)
+ .setAuthPassphrase(AUTH_PASSPHRASE)
+ .setPrivacyProtocol(PRIV_PROTOCOL)
+ .setPrivacyPassphrase(PRIV_PASSPHRASE)
+ .build();
+ }
+
+ protected Snmp createSnmpManagerInstance(final Function<SNMPConfiguration, Snmp> runnable, final int retries) {
+ int attempts = 0;
+ while (attempts < retries) {
+ try {
+ return runnable.apply(getSnmpConfiguration(NetworkUtils.getAvailableUdpPort(), String.valueOf(NetworkUtils.getAvailableUdpPort())));
+ } catch (Exception e) {
Review Comment:
Wasn't sure if BindException was derived from RuntimeException so I left it as is. Let me know if I'm incorrect here.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on a diff in pull request #6606: NIFI-10738 - Updated SNMP tests to retry when BindException occurs.
Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on code in PR #6606:
URL: https://github.com/apache/nifi/pull/6606#discussion_r1010693774
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPSocketSupport.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPSocketSupport {
+
+ protected static final int RETRIES = 3;
+
+ protected SNMPConfiguration getSnmpConfiguration(int managerPort, String targetPort) {
+ return new SNMPConfiguration.Builder()
+ .setRetries(RETRIES)
+ .setManagerPort(managerPort)
+ .setTargetHost(LOCALHOST)
+ .setTargetPort(targetPort)
+ .setSecurityLevel(SecurityLevel.authPriv.name())
+ .setSecurityName(SECURITY_NAME)
+ .setAuthProtocol(AUTH_PROTOCOL)
+ .setAuthPassphrase(AUTH_PASSPHRASE)
+ .setPrivacyProtocol(PRIV_PROTOCOL)
+ .setPrivacyPassphrase(PRIV_PASSPHRASE)
+ .build();
+ }
+
+ protected Snmp createSnmpManagerInstance(final Function<SNMPConfiguration, Snmp> runnable, final int retries) {
+ int attempts = 0;
+ while (attempts < retries) {
+ try {
+ return runnable.apply(getSnmpConfiguration(NetworkUtils.getAvailableUdpPort(), String.valueOf(NetworkUtils.getAvailableUdpPort())));
+ } catch (Exception e) {
+ if (e instanceof BindException) {
+ attempts++;
+ if (attempts == retries) {
+ throw e;
+ }
+ }
+ }
+ }
+ return null;
Review Comment:
It seems like this should result in an `IllegalStateException`.
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPSocketSupport.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPSocketSupport {
+
+ protected static final int RETRIES = 3;
+
+ protected SNMPConfiguration getSnmpConfiguration(int managerPort, String targetPort) {
+ return new SNMPConfiguration.Builder()
+ .setRetries(RETRIES)
+ .setManagerPort(managerPort)
+ .setTargetHost(LOCALHOST)
+ .setTargetPort(targetPort)
+ .setSecurityLevel(SecurityLevel.authPriv.name())
+ .setSecurityName(SECURITY_NAME)
+ .setAuthProtocol(AUTH_PROTOCOL)
+ .setAuthPassphrase(AUTH_PASSPHRASE)
+ .setPrivacyProtocol(PRIV_PROTOCOL)
+ .setPrivacyPassphrase(PRIV_PASSPHRASE)
+ .build();
+ }
+
+ protected Snmp createSnmpManagerInstance(final Function<SNMPConfiguration, Snmp> runnable, final int retries) {
+ int attempts = 0;
+ while (attempts < retries) {
+ try {
+ return runnable.apply(getSnmpConfiguration(NetworkUtils.getAvailableUdpPort(), String.valueOf(NetworkUtils.getAvailableUdpPort())));
+ } catch (Exception e) {
+ if (e instanceof BindException) {
+ attempts++;
+ if (attempts == retries) {
+ throw e;
+ }
+ }
Review Comment:
If the `Exception` is not a `BindException`, it should be thrown.
```suggestion
if (e instanceof BindException) {
attempts++;
if (attempts == retries) {
throw e;
}
} else {
throw e;
}
```
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPSocketSupport.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPSocketSupport {
+
+ protected static final int RETRIES = 3;
+
+ protected SNMPConfiguration getSnmpConfiguration(int managerPort, String targetPort) {
+ return new SNMPConfiguration.Builder()
+ .setRetries(RETRIES)
+ .setManagerPort(managerPort)
+ .setTargetHost(LOCALHOST)
+ .setTargetPort(targetPort)
+ .setSecurityLevel(SecurityLevel.authPriv.name())
+ .setSecurityName(SECURITY_NAME)
+ .setAuthProtocol(AUTH_PROTOCOL)
+ .setAuthPassphrase(AUTH_PASSPHRASE)
+ .setPrivacyProtocol(PRIV_PROTOCOL)
+ .setPrivacyPassphrase(PRIV_PASSPHRASE)
+ .build();
+ }
+
+ protected Snmp createSnmpManagerInstance(final Function<SNMPConfiguration, Snmp> runnable, final int retries) {
+ int attempts = 0;
+ while (attempts < retries) {
+ try {
+ return runnable.apply(getSnmpConfiguration(NetworkUtils.getAvailableUdpPort(), String.valueOf(NetworkUtils.getAvailableUdpPort())));
+ } catch (Exception e) {
Review Comment:
This can probably be changed to `RuntimeException`.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on a diff in pull request #6606: NIFI-10738 - Updated SNMP tests to retry when BindException occurs.
Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on code in PR #6606:
URL: https://github.com/apache/nifi/pull/6606#discussion_r1010933071
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPSocketSupport.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPSocketSupport {
+
+ protected static final int RETRIES = 3;
+
+ protected SNMPConfiguration getSnmpConfiguration(int managerPort, String targetPort) {
+ return new SNMPConfiguration.Builder()
+ .setRetries(RETRIES)
+ .setManagerPort(managerPort)
+ .setTargetHost(LOCALHOST)
+ .setTargetPort(targetPort)
+ .setSecurityLevel(SecurityLevel.authPriv.name())
+ .setSecurityName(SECURITY_NAME)
+ .setAuthProtocol(AUTH_PROTOCOL)
+ .setAuthPassphrase(AUTH_PASSPHRASE)
+ .setPrivacyProtocol(PRIV_PROTOCOL)
+ .setPrivacyPassphrase(PRIV_PASSPHRASE)
+ .build();
+ }
+
+ protected Snmp createSnmpManagerInstance(final Function<SNMPConfiguration, Snmp> runnable, final int retries) {
+ int attempts = 0;
+ while (attempts < retries) {
+ try {
+ return runnable.apply(getSnmpConfiguration(NetworkUtils.getAvailableUdpPort(), String.valueOf(NetworkUtils.getAvailableUdpPort())));
+ } catch (Exception e) {
Review Comment:
Good point, `BindException` extends from `IOException`, so this works.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory closed pull request #6606: NIFI-10738 - Updated SNMP tests to retry when BindException occurs.
Posted by GitBox <gi...@apache.org>.
exceptionfactory closed pull request #6606: NIFI-10738 - Updated SNMP tests to retry when BindException occurs.
URL: https://github.com/apache/nifi/pull/6606
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on a diff in pull request #6606: NIFI-10738 - Updated SNMP tests to retry when BindException occurs.
Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on code in PR #6606:
URL: https://github.com/apache/nifi/pull/6606#discussion_r1009903767
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPTtest.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPTtest {
+
+ protected static final int RETRIES = 3;
+
+ protected SNMPConfiguration getSnmpConfiguration(int managerPort, String targetPort) {
+ return new SNMPConfiguration.Builder()
+ .setRetries(RETRIES)
+ .setManagerPort(managerPort)
+ .setTargetHost(LOCALHOST)
+ .setTargetPort(targetPort)
+ .setSecurityLevel(SecurityLevel.authPriv.name())
+ .setSecurityName(SECURITY_NAME)
+ .setAuthProtocol(AUTH_PROTOCOL)
+ .setAuthPassphrase(AUTH_PASSPHRASE)
+ .setPrivacyProtocol(PRIV_PROTOCOL)
+ .setPrivacyPassphrase(PRIV_PASSPHRASE)
+ .build();
+ }
+
+ protected Snmp createSnmpManagerInstance(final Function<SNMPConfiguration, Snmp> runnable, final int retries) throws BindException {
+ int attempts = 0;
+ while(attempts < retries) {
+ try {
+ return runnable.apply(getSnmpConfiguration(NetworkUtils.getAvailableUdpPort(), String.valueOf(NetworkUtils.getAvailableUdpPort())));
+ } catch (Exception e) {
+ if (e instanceof BindException) {
+ attempts++;
+ }
+ }
+ }
+ throw new BindException();
Review Comment:
Instead of throwing an empty `BindException`, the method should throw the last `BindException` to provide applicable detail.s
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPTtest.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPTtest {
+
+ protected static final int RETRIES = 3;
+
+ protected SNMPConfiguration getSnmpConfiguration(int managerPort, String targetPort) {
+ return new SNMPConfiguration.Builder()
+ .setRetries(RETRIES)
+ .setManagerPort(managerPort)
+ .setTargetHost(LOCALHOST)
+ .setTargetPort(targetPort)
+ .setSecurityLevel(SecurityLevel.authPriv.name())
+ .setSecurityName(SECURITY_NAME)
+ .setAuthProtocol(AUTH_PROTOCOL)
+ .setAuthPassphrase(AUTH_PASSPHRASE)
+ .setPrivacyProtocol(PRIV_PROTOCOL)
+ .setPrivacyPassphrase(PRIV_PASSPHRASE)
+ .build();
+ }
+
+ protected Snmp createSnmpManagerInstance(final Function<SNMPConfiguration, Snmp> runnable, final int retries) throws BindException {
+ int attempts = 0;
+ while(attempts < retries) {
Review Comment:
```suggestion
while (attempts < retries) {
```
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/V1V2cSNMPFactoryTest.java:
##########
@@ -19,53 +19,45 @@
import org.apache.nifi.remote.io.socket.NetworkUtils;
import org.apache.nifi.snmp.configuration.SNMPConfiguration;
import org.apache.nifi.util.StringUtils;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.snmp4j.CommunityTarget;
import org.snmp4j.Snmp;
import org.snmp4j.Target;
import org.snmp4j.security.SecurityLevel;
-import java.util.regex.Pattern;
+import java.net.BindException;
import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
-class V1V2cSNMPFactoryTest {
+class V1V2cSNMPFactoryTest extends SNMPTtest {
private static final int RETRIES = 3;
@Test
- void testFactoryCreatesV1V2Configuration() {
+ void testFactoryCreatesV1V2Configuration() throws BindException {
final V1V2cSNMPFactory snmpFactory = new V1V2cSNMPFactory();
- final int managerPort = NetworkUtils.getAvailableUdpPort();
- final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
- final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
-
- final Target target = snmpFactory.createTargetInstance(snmpConfiguration);
+ final Target target = createTargetInstance(snmpFactory::createTargetInstance, 5);
assertThat(target, instanceOf(CommunityTarget.class));
- assertEquals(LOCALHOST + "/" + targetPort, target.getAddress().toString());
+ assertNotNull(target.getAddress().toString());
assertEquals(RETRIES, target.getRetries());
assertEquals(1, target.getSecurityLevel());
assertEquals(StringUtils.EMPTY, target.getSecurityName().toString());
}
@Test
- void testFactoryCreatesSnmpManager() {
+ void testFactoryCreatesSnmpManager() throws BindException {
final V1V2cSNMPFactory snmpFactory = new V1V2cSNMPFactory();
- final int managerPort = NetworkUtils.getAvailableUdpPort();
- final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
- final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
-
- final Snmp snmpManager = snmpFactory.createSnmpManagerInstance(snmpConfiguration);
-
+ final Snmp snmpManager = createSnmpManagerInstance(snmpFactory::createSnmpManagerInstance, 5);
final String address = snmpManager.getMessageDispatcher().getTransportMappings().iterator().next().getListenAddress().toString();
- assertTrue(Pattern.compile("0.+?0/" + managerPort).matcher(address).matches());
+ Assertions.assertNotNull(address);
Review Comment:
```suggestion
assertNotNull(address);
```
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPTtest.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPTtest {
Review Comment:
This should be changed some something else, perhaps `SnmpSocketSupport`?
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPTtest.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPTtest {
+
+ protected static final int RETRIES = 3;
+
+ protected SNMPConfiguration getSnmpConfiguration(int managerPort, String targetPort) {
+ return new SNMPConfiguration.Builder()
+ .setRetries(RETRIES)
+ .setManagerPort(managerPort)
+ .setTargetHost(LOCALHOST)
+ .setTargetPort(targetPort)
+ .setSecurityLevel(SecurityLevel.authPriv.name())
+ .setSecurityName(SECURITY_NAME)
+ .setAuthProtocol(AUTH_PROTOCOL)
+ .setAuthPassphrase(AUTH_PASSPHRASE)
+ .setPrivacyProtocol(PRIV_PROTOCOL)
+ .setPrivacyPassphrase(PRIV_PASSPHRASE)
+ .build();
+ }
+
+ protected Snmp createSnmpManagerInstance(final Function<SNMPConfiguration, Snmp> runnable, final int retries) throws BindException {
+ int attempts = 0;
+ while(attempts < retries) {
+ try {
+ return runnable.apply(getSnmpConfiguration(NetworkUtils.getAvailableUdpPort(), String.valueOf(NetworkUtils.getAvailableUdpPort())));
+ } catch (Exception e) {
+ if (e instanceof BindException) {
+ attempts++;
+ }
+ }
+ }
+ throw new BindException();
+ }
+
+ protected Target createTargetInstance(final Function<SNMPConfiguration, Target> runnable, final int retries) throws BindException {
+ int attempts = 0;
+ while(attempts < retries) {
Review Comment:
```suggestion
while (attempts < retries) {
```
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on a diff in pull request #6606: NIFI-10738 - Updated SNMP tests to retry when BindException occurs.
Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on code in PR #6606:
URL: https://github.com/apache/nifi/pull/6606#discussion_r1010948207
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/factory/core/SNMPSocketSupport.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.snmp.factory.core;
+
+import org.apache.nifi.remote.io.socket.NetworkUtils;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.security.SecurityLevel;
+import java.net.BindException;
+import java.util.function.Function;
+
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.SECURITY_NAME;
+import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
+import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PROTOCOL;
+
+public class SNMPSocketSupport {
+
+ protected static final int RETRIES = 3;
+
+ protected SNMPConfiguration getSnmpConfiguration(int managerPort, String targetPort) {
+ return new SNMPConfiguration.Builder()
+ .setRetries(RETRIES)
+ .setManagerPort(managerPort)
+ .setTargetHost(LOCALHOST)
+ .setTargetPort(targetPort)
+ .setSecurityLevel(SecurityLevel.authPriv.name())
+ .setSecurityName(SECURITY_NAME)
+ .setAuthProtocol(AUTH_PROTOCOL)
+ .setAuthPassphrase(AUTH_PASSPHRASE)
+ .setPrivacyProtocol(PRIV_PROTOCOL)
+ .setPrivacyPassphrase(PRIV_PASSPHRASE)
+ .build();
+ }
+
+ protected Snmp createSnmpManagerInstance(final Function<SNMPConfiguration, Snmp> runnable, final int retries) {
+ int attempts = 0;
+ while (attempts < retries) {
+ try {
+ return runnable.apply(getSnmpConfiguration(NetworkUtils.getAvailableUdpPort(), String.valueOf(NetworkUtils.getAvailableUdpPort())));
+ } catch (Exception e) {
+ if (e instanceof BindException) {
Review Comment:
In course of evaluating the runtime behavior, it looks like the `BindException` is wrapped in a `ProcessException`:
```
org.apache.nifi.processor.exception.ProcessException: java.net.BindException: Address already in use (Bind failed)
```
Instead of this `instanceof` check, it seems like introducing a new method named `isBindFailure` or similar would be helpful. This method should check the instance, and then recursively call `getCause()` to determine whether the root cause is a `BindException`.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org