Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

METRON-2262: Upgrade to Curator 4.2.0 #1516

Open
wants to merge 5 commits into
base: feature/METRON-2088-support-hdp-3.1
Choose a base branch
from

Conversation

merrimanr
Copy link
Contributor

Contributor Comments

This PR is based on METRON-2261 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 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 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 then removed from the internal Map.

After the upgrade, the order is reversed. The service is removed from the internal Map then removed from Zookeeper. However there is a check that ensures the service existed in the internal Map 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 for the complete guide to follow for contributions.
Please refer also to our Build Verification Guidelines 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:

  • Is there a JIRA ticket associated with this PR? If not one needs to be created at Metron Jira.
  • 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.
  • Has your PR been rebased against the latest commit within the target branch (typically master)?

For code changes:

  • Have you included steps to reproduce the behavior or problem that is being changed or addressed?

  • Have you included steps or a guide to how the change may be verified and tested manually?

  • 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 
    
  • Have you written or updated unit tests and or integration tests to verify your changes?

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?

  • 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? See 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 is set up for your personal repository such that your branches are built there before submitting a pull request.

@mmiklavc
Copy link
Contributor

@merrimanr This is pretty complicated so I want to talk through this a bit and make sure this is clear.

It looks like the upshot is that previously the functionality only depended on shared state in Zookeeper. You could reference a ServiceDiscoveryImpl in 2 separate processes (1 in the integration test process, the other in the application master container process spawned by YARN) with no issue. Now, the internal map matters, but unlike the zookeeper path this state is not distributed. So that verification fails when there's no item in the internal map.

The integration test creates a ServiceDiscover here https://github.com/apache/metron/blob/master/metron-analytics/metron-maas-service/src/test/java/org/apache/metron/maas/service/MaasIntegrationTest.java#L218

The YARN app creates a ServiceDiscover here when it creates the ContainerRequestListener https://github.com/apache/metron/blob/master/metron-analytics/metron-maas-service/src/main/java/org/apache/metron/maas/service/ApplicationMaster.java#L454

@merrimanr
Copy link
Contributor Author

Almost all correct. There are other ServiceDiscoverer instances created here and here. Here's what each one does:

MaasIntegrationTest - Used to test which endpoints are registered. Runs in test.
MaaSFunctions - Used to get endpoint. Runs in a Stellar context.
Runner - Registers service endpoint when container starts. Runs in model container.
ContainerRequestListener - Unregisters services based on container callbacks. Runs in app master.

@mmiklavc
Copy link
Contributor

Almost all correct. There are other ServiceDiscoverer instances created here and here. Here's what each one does:

MaasIntegrationTest - Used to test which endpoints are registered. Runs in test.
MaaSFunctions - Used to get endpoint. Runs in a Stellar context.
Runner - Registers service endpoint when container starts. Runs in model container.
ContainerRequestListener - Unregisters services based on container callbacks. Runs in app master.

Oh, that's actually more than I thought without having run the lookup on uses. Glad I asked.

One manual test we might want to add is attempting to remove a non-existent endpoint. Looking at the code, I don't see a whole lot of risk in the "add then remove" approach other than if the operation were to fail in between add/remove. For a service that doesn't exist, you could end up with an item in zookeeper that doesn't actually exist.

@ottobackwards
Copy link
Contributor

So the bug is that we register and un-register in different processes.

I think we could think about

  • Implementing our own ServiceDiscovery based on the existing impl with our reqs.
  • Filing a jira and maybe a PR to curator about the use case. Although I think registration and unregistration from different processes is kind of a corner case.

@ottobackwards
Copy link
Contributor

  • another idea would be for them to support multiple implementations with the builder and have a non-caching, distributed friendly version etc.

Assuming the logic for using this way makes sense

…3.1' into METRON-2262

# Conflicts:
#	metron-analytics/metron-maas-service/pom.xml
#	metron-analytics/metron-profiler-spark/pom.xml
#	metron-analytics/metron-profiler-storm/pom.xml
#	metron-interface/metron-rest/pom.xml
#	metron-platform/metron-common/pom.xml
#	metron-platform/metron-data-management/pom.xml
#	metron-platform/metron-elasticsearch/metron-elasticsearch-common/pom.xml
#	metron-platform/metron-enrichment/metron-enrichment-storm/pom.xml
#	metron-platform/metron-hbase-server/pom.xml
#	metron-platform/metron-hbase/metron-hbase-common/pom.xml
#	metron-platform/metron-indexing/metron-indexing-common/pom.xml
#	metron-platform/metron-integration-test/pom.xml
#	metron-platform/metron-management/pom.xml
#	metron-platform/metron-parsing/metron-parsers-common/pom.xml
#	metron-platform/metron-pcap-backend/pom.xml
#	metron-platform/metron-pcap/pom.xml
#	metron-platform/metron-solr/metron-solr-common/pom.xml
#	metron-platform/metron-test-utilities/pom.xml
#	metron-platform/metron-writer/metron-writer-common/pom.xml
#	metron-platform/metron-writer/metron-writer-storm/pom.xml
#	metron-stellar/stellar-common/pom.xml
#	pom.xml
@nickwallen
Copy link
Contributor

Hey @merrimanr - We don't need the following changes on this PR. I know these are just due to the iterations and changes I went through on #1515.

  • metron-platform/metron-indexing/metron-indexing-storm/pom.xml
  • metron-platform/metron-enrichment/pom.xml
  • metron-stellar/stellar-zeppelin/pom.xml

@merrimanr
Copy link
Contributor Author

Ah makes sense @nickwallen. Done with latest commit.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants