zeppelin/docs/displaysystem/front-end-angular.md
CloverHearts 9db840c655 [ZEPPELIN-1665] Z.run with external note executable and access resource for zeppelin in each interpreter
### What is this PR for?
Currently, the z.run command is restricted.
Only paragraphs in a single note can be executed.
I have modified this to allow you to freely execute paragraphs of other notes.
This PR provides the basis for the freeful use of Zeppelin's resources at each Interpreter implementation.

### What type of PR is it?
Improvement, Feature

### Todos
- [x] extends z.run
- [x] run all paragraph in external note
- [x] run paragraph for external note.
- [x] get resource for zeppelin in each interpreter.
- [x] improve test case.
- [x] how to use docuement

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1665

### How should this be tested?
Currently under development.

run paragraph in same note
```
%spark
z.run("paragraphID")
```

run paragraph with external note
```
z.run("noteid", "paragraphid");
```

all note run
```
z.runNote("noteid");
```

### Screenshots (if appropriate)
- paragraph run
![zrun](https://cloud.githubusercontent.com/assets/10525473/20304857/ca056300-ab75-11e6-8276-0fe0667a5a24.gif)

- noterun
![runnote](https://cloud.githubusercontent.com/assets/10525473/20472104/527cd8de-affa-11e6-9587-0438140e264f.gif)

### Questions:
* Does the licenses files need update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? yes

Author: CloverHearts <cloverheartsdev@gmail.com>

Closes #1637 from cloverhearts/extends-zrun-remote-transaction and squashes the following commits:

41fa9d7 [CloverHearts] restore unless changed and import
113b475 [CloverHearts] Merge branch 'master' into extends-zrun-remote-transaction
03a3a2b [CloverHearts] testcase change z.run(2, context) to z.run(2)
2a2c173 [CloverHearts] Merge branch 'master' into extends-zrun-remote-transaction
f2e3bcf [CloverHearts] fix TestCase
5a80a5a [CloverHearts] last test case time check to print string
e6cd82c [CloverHearts] Merge branch 'master' into extends-zrun-remote-transaction
3862166 [CloverHearts] regenerate thrfit class
5ec4640 [CloverHearts] change defined protocol for thrift
7562535 [CloverHearts] remove unused import and asterisk import
8a54917 [CloverHearts] Merge branch 'master' into extends-zrun-remote-transaction
342752d [CloverHearts] add document for extends z.run and z.runNote
292319a [CloverHearts] add test case for extends z.run and z.runNote
10c2a47 [CloverHearts] Implement runNote and re implement run method
f9661c8 [CloverHearts] Merge branch 'master' into extends-zrun-remote-transaction
9ab05af [CloverHearts] Change structure and remove remoteWorksManager
8cbe46c [CloverHearts] remote remoteworksController in interpreter.java
8d42c16 [CloverHearts] Merge branch 'master' into extends-zrun-remote-transaction
f11fed4 [CloverHearts] Merge branch 'workflow' into extends-zrun-remote-transaction
c074f07 [CloverHearts] fix sio support
4b1ef08 [CloverHearts] fix thrift interface
2628a20 [CloverHearts] fix thrift
6fbe08a [CloverHearts] Merge branch 'master' into workflow
3f75bd5 [CloverHearts] support scald
55e8704 [CloverHearts] support spark r
5a7886f [CloverHearts] fix sio support
afb9db7 [CloverHearts] Merge branch 'master' into workflow
3ed556c [CloverHearts] remove debug console message.
3d34f9e [CloverHearts] Implement getParagraphRunner transaction.
2523238 [CloverHearts] Implement eventForWait class
0570ae8 [CloverHearts] add remote works controller class and include interpreter factory
6e1f219 [CloverHearts] code base workflow for remote zeppelin server control default thrift transaction.
2016-11-29 08:07:15 -08:00

6 KiB

layout title description group
page Front-end Angular API in Apache Zeppelin In addition to the back-end API to handle Angular objects binding, Apache Zeppelin exposes a simple AngularJS z object on the front-end side to expose the same capabilities. display

{% include JB/setup %}

Front-end Angular API in Apache Zeppelin

Basic Usage

In addition to the back-end API to handle Angular objects binding, Apache Zeppelin also exposes a simple AngularJS z object on the front-end side to expose the same capabilities. This z object is accessible in the Angular isolated scope for each paragraph.

Bind / Unbind Variables

Through the z, you can bind / unbind variables to AngularJS view. Bind a value to an angular object and a mandatory target paragraph:


%angular

<form class="form-inline">
  <div class="form-group">
    <label for="superheroId">Super Hero: </label>
    <input type="text" class="form-control" id="superheroId" placeholder="Superhero name ..." ng-model="superhero"></input>
  </div>
  <button type="submit" class="btn btn-primary" ng-click="z.angularBind('superhero',superhero,'20160222-232336_1472609686')"> Bind</button>
</form>


Unbind/remove a value from angular object and a mandatory target paragraph:


%angular

<form class="form-inline">
  <button type="submit" class="btn btn-primary" ng-click="z.angularUnbind('superhero','20160222-232336_1472609686')"> UnBind</button>
</form>

The signature for the z.angularBind() / z.angularUnbind() functions are:

// Bind
z.angularBind(angularObjectName, angularObjectValue, paragraphId);

// Unbind
z.angularUnbind(angularObjectName, angularObjectValue, paragraphId);

All the parameters are mandatory.


### Run Paragraph

You can also trigger paragraph execution by calling z.runParagraph() function passing the appropriate paragraphId:


%angular

<form class="form-inline">
  <div class="form-group">
    <label for="paragraphId">Paragraph Id: </label>
    <input type="text" class="form-control" id="paragraphId" placeholder="Paragraph Id ..." ng-model="paragraph"></input>
  </div>
  <button type="submit" class="btn btn-primary" ng-click="z.runParagraph(paragraph)"> Run Paragraph</button>
</form>


## Overriding dynamic form with Angular Object

The front-end Angular Interaction API has been designed to offer richer form capabilities and variable binding. With the existing Dynamic Form system you can already create input text, select and checkbox forms but the choice is rather limited and the look & feel cannot be changed.

The idea is to create a custom form using plain HTML/AngularJS code and bind actions on this form to push/remove Angular variables to targeted paragraphs using this new API.

Consequently if you use the Dynamic Form syntax in a paragraph and there is a bound Angular object having the same name as the ${formName}, the Angular object will have higher priority and the Dynamic Form will not be displayed. Example:


## Feature matrix comparison

How does the front-end AngularJS API compares to the back-end API ? Below is a comparison matrix for both APIs:

Actions Front-end API Back-end API
Initiate binding z.angularbind(var, initialValue, paragraphId) z.angularBind(var, initialValue)
Update value same to ordinary angularjs scope variable, or z.angularbind(var, newValue, paragraphId) z.angularBind(var, newValue)
Watching value same to ordinary angularjs scope variable z.angularWatch(var, (oldVal, newVal) => ...)
Destroy binding z.angularUnbind(var, paragraphId) z.angularUnbind(var)
Executing Paragraph z.runParagraph(paragraphId) z.run(paragraphId)
Executing Paragraph (Specific paragraphs in other notes) ( z.run(noteid, paragraphId)
Executing note z.runNote(noteId)

Both APIs are pretty similar, except for value watching where it is done naturally by AngularJS internals on the front-end and by user custom watcher functions in the back-end.

There is also a slight difference in term of scope. Front-end API limits the Angular object binding to a paragraph scope whereas back-end API allows you to bind an Angular object at the global or note scope. This restriction has been designed purposely to avoid Angular object leaks and scope pollution.