merrimanr opened a new pull request #1440: METRON-2148: Stellar REST POST 
function
URL: https://github.com/apache/metron/pull/1440
 
 
   ## Contributor Comments
   This PR adds a `REST_POST` Stellar function with syntax and options similar 
to the existing `REST_GET` function for performing REST POST requests.  A 
Stellar map can now be passed into the function and added to the request as 
query parameters (this feature was added to `REST_GET` as well).  Separate 
global configs were added for `REST_GET` and `REST_POST` in addition to the 
existing global config for REST functions.  For `REST_POST` requests, there is 
also an option `enforce.json` that ensures POST data is well-formed JSON.
   
   ### Changes Included
   
   - `REST_POST` Stellar function was added to `RestFunctions` class.
   - `RestFunctions` class was refactored by moving common code used by 
`REST_GET` and `REST_POST` to their own methods.  Now code specific to either 
functions mostly consists of argument parsing and request building.
   - Unit and integration tests were moved to separate tests.  The 
`RestFunctions` class should be 100% covered.
   - Documentation added for the new `REST_POST` function and additional 
options added to both.
   
   ### Testing
   This has been tested in full dev.  Since there were significant changes to 
`RestFunctions` I regression tested using the test instructions in original 
[Stellar Rest PR](https://github.com/apache/metron/pull/1250).  Note a 
regression was introduced when using the `REST_GET` function in the enrichment 
topology (class version error).  This is being addressed 
[here](https://github.com/apache/metron/pull/1436).
   
   In addition to this I also followed these instructions:
   
   1. Assuming full dev has already been spun up during regression testing 
described above, start the Stellar shell with `/usr/metron/0.7.2/bin/stellar 
--zookeeper node1:2181`.
   
   2. Defined a variable to hold POST data:
   ```
   [Stellar]>>> data := {'key':'value'}
   {key=value}
   ```
   
   3. Send a POST request to a test service (httpbin.org in this example):
   ```
   [Stellar]>>> REST_POST('http://httpbin.org/post', data)
   {args={}, data={"key":"value"}, files={}, form={}, 
headers={Accept=application/json, Accept-Encoding=gzip,deflate, 
Content-Length=15, Content-Type=application/json, Host=httpbin.org, 
User-Agent=Apache-HttpClient/4.3.2 (java 1.5)}, json={key=value}, 
origin=136.49.31.47, 136.49.31.47, url=https://httpbin.org/post}
   ```
   The request should succeed with the correct POST data in the response.
   
   4. Define a variable to hold query parameters:
   ```
   [Stellar]>>> params := {'param1': 'value1', 'param2': 'value2'}
   {param1=value1, param2=value2}
   ```
   
   5. Send a POST request, passing in the query parameter variable:
   ```
   [Stellar]>>> REST_POST('http://httpbin.org/post', data, {}, params)
   {args={param1=value1, param2=value2}, data={"key":"value"}, files={}, 
form={}, headers={Accept=application/json, Accept-Encoding=gzip,deflate, 
Content-Length=15, Content-Type=application/json, Host=httpbin.org, 
User-Agent=Apache-HttpClient/4.3.2 (java 1.5)}, json={key=value}, 
origin=136.49.31.47, 136.49.31.47, 
url=https://httpbin.org/post?param1=value1&param2=value2}
   ```
   The `args` and `url` attributes in the response should contain the query 
parameters.
   
   6. Test configuration priority by changing the empty response override in 
various configs.  First enable 404 responses and set an override:
   ```
   %define stellar.rest.settings := {'response.codes.allowed': [200, 404],  
'empty.content.override': {}}
   [Stellar]>>> REST_POST('http://httpbin.org/status/404', data)
   {}
   ```
   The response should match the override value set in the config.
   
   7. Configure the override for all REST functions:
   ```
   [Stellar]>>> REST_POST('http://httpbin.org/status/404', data)
   global rest config
   ```
   The response should match the global override value set in the config.
   
   8. Configure the override for REST_POST functions:
   ```
   [Stellar]>>> %define stellar.rest.post.settings := 
{'empty.content.override': 'rest post config'}
   {empty.content.override=rest post config}
   [Stellar]>>> REST_POST('http://httpbin.org/status/404', data)
   rest post config
   ```
   The response should match the rest post override value set in the config.
   
   9 Configure the override in a variable that will be passed to the function:
   ```
   [Stellar]>>> config := {'empty.content.override': 'function config'}
   {empty.content.override=function config}
   [Stellar]>>> REST_POST('http://httpbin.org/status/404', data, config)
   function config
   ```
   The response should match the override in the config passed to the function.
   
   ## 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)?
   - [x] 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:
   - [x] 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
     ```
   
   - [x] 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

Reply via email to