### What is this PR for?
Target: Create ability to call http services with custom keystores in a groovy way.
The following should work:
```groovy
//connect to host xxx.yyy with special keystore
HTTP.get(
url: "https://xxx.yyy/zzz",
ssl: " HTTP.getKeystoreSSLContext('./xxx_yyy_keystore.jks', 'testpass') "
)
//take context initialization code from groovy interpreter properties
HTTP.get(
url: "https://xxx.yyy/zzz",
ssl: g.SSL_CONTEXT_FROM_GROOVY_INTERPRET_PROPERTIES
)
//connect to host xxx.yyy with trust all (do not check trust certificates - dev mode only)
HTTP.get(
url: "https://xxx.yyy/zzz",
ssl: " HTTP.getNaiveSSLContext() "
)
//
HTTP.get(
url: "https://xxx.yyy/zzz",
ssl: " MyCustomSSLBuilder.build() "
)
```
### What type of PR is it?
Improvement
### Todos
* [ ] - Task
### What is the Jira issue?
[ZEPPELIN-2443]
### How should this be tested?
follow the samples above or in documentation
### Questions:
* Does the licenses files need update? NO
* Is there breaking changes for older versions? NO
* Does this needs documentation? YES
Author: dlukyanov <dlukyanov@ukr.net>
Closes #2287 from dlukyanov/master and squashes the following commits:
4baa22e [dlukyanov] ZEPPELIN-2443
4.1 KiB
| layout | title | description | group |
|---|---|---|---|
| page | Apache Groovy Interpreter for Apache Zeppelin | Apache Groovy is a powerful, optionally typed and dynamic language, with static-typing and static compilation capabilities, for the Java platform aimed at improving developer productivity thanks to a concise, familiar and easy to learn syntax. | interpreter |
{% include JB/setup %}
Groovy Interpreter for Apache Zeppelin
Samples
%groovy
//get a parameter defined as z.angularBind('ngSearchParam', value, 'paragraph_id')
//g is a context object for groovy to avoid mix with z object
def param = g.angular('ngSearchParam')
//send request https://www.googleapis.com/customsearch/v1?q=ngSearchParam_value
def r = HTTP.get(
//assume you defined the groovy interpreter property
// `search_baseurl`='https://www.googleapis.com/customsearch/v1'
//in groovy object o.getProperty('A') == o.'A' == o.A == o['A']
url : g.search_baseurl,
query: [ q: param ],
headers: [
'Accept':'application/json',
//'Authorization:' : g.getProperty('search_auth'),
],
ssl : g.getProperty('search_ssl') // assume groovy interpreter property search_ssl = HTTP.getNaiveSSLContext()
)
//check response code
if( r.response.code==200 ) {
g.html().with{
//g.html() renders %angular to output and returns groovy.xml.MarkupBuilder
h2("the response ${r.response.code}")
span( r.response.body )
h2("headers")
pre( r.response.headers.join('\n') )
}
} else {
//just to show that it's possible to use println with multiline groovy string to render output
println("""%angular
<script> alert ("code=${r.response.code} \n msg=${r.response.message}") </script>
""")
}
%groovy
//renders a table with headers a, b, c and two rows
g.table(
[
['a','b','c'],
['a1','b1','c1'],
['a2','b2','c2'],
]
)
the g object
-
g.angular(String name)Returns angular object by name. Look up notebook scope first and then global scope.
-
g.angularBind(String name, Object value)Assign a new
valueinto angular objectname -
java.util.Properties g.getProperties()returns all properties defined for this interpreter
-
String g.getProperty('PROPERTY_NAME')g.PROPERTY_NAME g.'PROPERTY_NAME' g['PROPERTY_NAME'] g.getProperties().getProperty('PROPERTY_NAME')All above the accessor to named property defined in groovy interpreter. In this case with name
PROPERTY_NAME -
groovy.xml.MarkupBuilder g.html()Starts or continues rendering of
%angularto output and returns groovy.xml.MarkupBuilder MarkupBuilder is usefull to generate html (xml) -
void g.table(obj)starts or continues rendering table rows.
obj: List(rows) of List(columns) where first line is a header
-
g.input(name, value )Creates
textinput with value specified. The parametervalueis optional. -
g.select(name, default, Map<Object, String> options)Creates
selectinput with defined options. The parameterdefaultis optional.g.select('sex', 'm', ['m':'man', 'w':'woman']) -
g.checkbox(name, Collection checked, Map<Object, String> options)Creates
checkboxinput. -
g.get(name, default)Returns interpreter-based variable. Visibility depends on interpreter scope. The parameter
defaultis optional. -
g.put(name, value)Stores new value into interpreter-based variable. Visibility depends on interpreter scope.