merrimanr opened a new pull request #1516: METRON-2262: Upgrade to Curator 4.2.0 URL: https://github.com/apache/metron/pull/1516 ## Contributor Comments This PR is based on [METRON-2261](https://github.com/apache/metron/pull/1515) and includes those changes. It must be merged before this. This PR upgrades Curator to version 4.2.0 and fixes a couple bugs in `MaasIntegrationTest` that resulted from the upgrade. There was an extra service unregister in the `ContainerRequestListener` class (should only be unregistered once) and another more complicated bug (described in the next section). ### Bug Fix After upgrading to Curator version 4.2.0, both tests in `MaasIntegrationTest` fail with this error: ``` testMaaSWithoutDomain(org.apache.metron.maas.service.MaasIntegrationTest) Time elapsed: 214.791 sec <<< FAILURE! java.lang.AssertionError at org.junit.Assert.fail(Assert.java:86) at org.junit.Assert.assertTrue(Assert.java:41) at org.junit.Assert.assertTrue(Assert.java:52) at org.apache.metron.maas.service.MaasIntegrationTest.testDSShell(MaasIntegrationTest.java:269) at org.apache.metron.maas.service.MaasIntegrationTest.testMaaSWithoutDomain(MaasIntegrationTest.java:113) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298) at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.lang.Thread.run(Thread.java:748) ``` The service is not properly unregistered, the test [waits for the service to be removed from the list of endpoints](https://github.com/apache/metron/blob/master/metron-analytics/metron-maas-service/src/test/java/org/apache/metron/maas/service/MaasIntegrationTest.java#L261) and then timeouts and fails. The root cause is a change in how the `org.apache.curator.x.discovery.details. ServiceDiscoveryImpl` class unregisters a service after the upgrade. The list of services is maintained in 2 places: Zookeeper and an [internal Map](https://github.com/apache/curator/blob/apache-curator-4.2.0/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java#L64) in `ServiceDiscoveryImpl`. There are several read functions in `ServiceDiscoveryImpl` but then don't refresh the internal Map. The internal Map is only updated when `registerService` and `unregisterService` are called. Before the upgrade, a service is [removed from Zookeeper](https://github.com/apache/curator/blob/apache-curator-2.7.0/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java#L218) then [removed from the internal Map](https://github.com/apache/curator/blob/apache-curator-2.7.0/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java#L224). After the upgrade, the order is reversed. The service is [removed from the internal Map](https://github.com/apache/curator/blob/apache-curator-4.2.0/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java#L255) then [removed from Zookeeper](https://github.com/apache/curator/blob/apache-curator-4.2.0/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java#L524). However there is a check that [ensures the service existed in the internal Map](https://github.com/apache/curator/blob/apache-curator-4.2.0/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java#L511) before removing it for Zookeeper. Services are registered in `org.apache.metron.maas.service.runner.Runner` and unregistered in `org.apache.metron.maas.service.callback.ContainerRequestListener`. The latter runs in a different process so registered services are not in the internal Map. This was not a problem before the upgrade because Zookeeper was updated regardless of the internal Map state. The fix proposed in this PR is to register a service immediately before unregistering it in `org.apache.metron.maas.discovery.ServiceDiscoverer`. This populates the internal Map in `ServiceDiscoveryImpl` with the service so that the subsequent unregister call functions correctly. A side effect of this would be writing duplicate data to Zookeeper. The only other solution I can think of would be to rearchitect how and where services are registered/unregistered. ### Testing The `MaasIntegrationTest` (and all tests) should pass. Upgrading Curator without the fixes in this PR should cause the error above. ## Pull Request Checklist Thank you for submitting a contribution to Apache Metron. Please refer to our [Development Guidelines](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61332235) for the complete guide to follow for contributions. Please refer also to our [Build Verification Guidelines](https://cwiki.apache.org/confluence/display/METRON/Verifying+Builds?show-miniview) for complete smoke testing guides. In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following: ### For all changes: - [x] Is there a JIRA ticket associated with this PR? If not one needs to be created at [Metron Jira](https://issues.apache.org/jira/browse/METRON/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel). - [x] Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character. - [x] Has your PR been rebased against the latest commit within the target branch (typically master)? ### For code changes: - [x] Have you included steps to reproduce the behavior or problem that is being changed or addressed? - [x] Have you included steps or a guide to how the change may be verified and tested manually? - [x] Have you ensured that the full suite of tests and checks have been executed in the root metron folder via: ``` mvn -q clean integration-test install && dev-utilities/build-utils/verify_licenses.sh ``` - [x] Have you written or updated unit tests and or integration tests to verify your changes? - [x] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? - [ ] Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent? ### For documentation related changes: - [ ] Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via `site-book/target/site/index.html`: ``` cd site-book mvn site ``` - [ ] Have you ensured that any documentation diagrams have been updated, along with their source files, using [draw.io](https://www.draw.io/)? See [Metron Development Guidelines](https://cwiki.apache.org/confluence/display/METRON/Development+Guidelines) for instructions. #### Note: Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible. It is also recommended that [travis-ci](https://travis-ci.org) is set up for your personal repository such that your branches are built there before submitting a pull request.
---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
