Skip to content

Commit

Permalink
[ZEPPELIN-1189] Get note revision websocket api
Browse files Browse the repository at this point in the history
### What is this PR for?
Adds websocket api for getting note revision.

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

### Todos
* [x] - add backend websocket handle
* [x] - add frontend call

### What is the Jira issue?
[#1189](https://issues.apache.org/jira/browse/ZEPPELIN-1189)

### How should this be tested?
green CI (can be tested once frontend implemented)

### Screenshots (if appropriate)

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

Author: Khalid Huseynov <khalidhnv@nflabs.com>
Author: Khalid Huseynov <khalidhuseynov@Khalids-MacBook-Pro.local>
Author: Khalid Huseynov <khalidhnv@gmail.com>

Closes #1192 from khalidhuseynov/versioning/get-note-revision-api and squashes the following commits:

f1ab994 [Khalid Huseynov] Merge branch 'master' into versioning/get-note-revision-api
683b481 [Khalid Huseynov] receive Revision object from frontend
aa0a7d6 [Khalid Huseynov] Revert "change NotebookRepo api to get note revision from Revision object to String revId"
ce097ed [Khalid Huseynov] add throws to notebook getRevisionNote
baaa704 [Khalid Huseynov] change NotebookRepo api to get note revision from Revision object to String revId
d9751c3 [Khalid Huseynov] add backend ws api to get note revision
3783fc9 [Khalid Huseynov] receive ws NOTE_REVISION msg
79f8ac9 [Khalid Huseynov] add getNoteRevision to front
  • Loading branch information
Khalid Huseynov authored and bzz committed Jul 20, 2016
1 parent e929aef commit 67cb828
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener;
import org.apache.zeppelin.notebook.*;
import org.apache.zeppelin.notebook.repo.NotebookRepo.Revision;
import org.apache.zeppelin.notebook.socket.Message;
import org.apache.zeppelin.notebook.socket.Message.OP;
import org.apache.zeppelin.scheduler.Job;
Expand Down Expand Up @@ -220,6 +221,9 @@ public void onMessage(NotebookSocket conn, String msg) {
case CHECKPOINT_NOTEBOOK:
checkpointNotebook(conn, notebook, messagereceived);
break;
case NOTE_REVISION:
getNoteRevision(conn, notebook, messagereceived);
break;
case LIST_NOTEBOOK_JOBS:
unicastNotebookJobInfo(conn, messagereceived);
break;
Expand Down Expand Up @@ -1129,6 +1133,18 @@ private void checkpointNotebook(NotebookSocket conn, Notebook notebook,
notebook.checkpointNote(noteId, commitMessage, subject);
}

private void getNoteRevision(NotebookSocket conn, Notebook notebook, Message fromMessage)
throws IOException {
String noteId = (String) fromMessage.get("noteId");
Revision revision = (Revision) fromMessage.get("revision");
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
Note revisionNote = notebook.getNoteRevision(noteId, revision, subject);
conn.send(serializeMessage(new Message(OP.NOTE_REVISION)
.put("noteId", noteId)
.put("revisionId", revision)
.put("data", revisionNote)));
}

/**
* This callback is for the paragraph that runs on ZeppelinServer
* @param noteId
Expand Down
6 changes: 6 additions & 0 deletions zeppelin-web/src/app/notebook/notebook.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
document.getElementById('note.checkpoint.message').value = '';
};

// receive certain revision of note
$scope.$on('noteRevision', function(event, data) {
console.log('received note revision %o', data);
//TODO(xxx): render it
});

$scope.runNote = function() {
BootstrapDialog.confirm({
closable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ angular.module('zeppelinWebApp').factory('websocketEvents',
$rootScope.$broadcast('appLoad', data);
} else if (op === 'APP_STATUS_CHANGE') {
$rootScope.$broadcast('appStatusChange', data);
} else if (op === 'NOTE_REVISION') {
$rootScope.$broadcast('noteRevision', data);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ angular.module('zeppelinWebApp').service('websocketMsgSrv', function($rootScope,
});
},

getNoteRevision: function(noteId, revisionId) {
websocketEvents.sendNewEvent({
op: 'NOTE_REVISION',
data: {
noteId: noteId,
revisionId: revisionId
}
});
},

isConnected: function() {
return websocketEvents.isConnected();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.zeppelin.interpreter.InterpreterSetting;
import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry;
import org.apache.zeppelin.notebook.repo.NotebookRepo;
import org.apache.zeppelin.notebook.repo.NotebookRepo.Revision;
import org.apache.zeppelin.notebook.repo.NotebookRepoSync;
import org.apache.zeppelin.resource.ResourcePoolUtils;
import org.apache.zeppelin.scheduler.Job;
Expand Down Expand Up @@ -357,6 +358,11 @@ public void checkpointNote(String noteId, String checkpointMessage, Authenticati
notebookRepo.checkpoint(noteId, checkpointMessage, subject);
}

public Note getNoteRevision(String noteId, Revision revision, AuthenticationInfo subject)
throws IOException {
return notebookRepo.get(noteId, revision, subject);
}

@SuppressWarnings("rawtypes")
private Note loadNoteFromRepo(String id, AuthenticationInfo subject) {
Note note = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,14 @@ public Revision checkpoint(String noteId, String checkpointMsg, AuthenticationIn
}

@Override
public Note get(String noteId, Revision rev, AuthenticationInfo subject) throws IOException {
// Auto-generated method stub
return null;
public Note get(String noteId, Revision rev, AuthenticationInfo subject) {
Note revisionNote = null;
try {
revisionNote = getRepo(0).get(noteId, rev, subject);
} catch (IOException e) {
LOG.error("Failed to get revision {} of note {}", rev.id, noteId, e);
}
return revisionNote;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public static enum OP {
CHECKPOINT_NOTEBOOK, // [c-s] checkpoint notebook to storage repository
// @param noteId
// @param checkpointName
NOTE_REVISION, // [c-s] get certain revision of note
// @param noteId
// @param revisionId

APP_APPEND_OUTPUT, // [s-c] append output
APP_UPDATE_OUTPUT, // [s-c] update (replace) output
Expand Down

0 comments on commit 67cb828

Please sign in to comment.