You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2018/04/26 08:05:55 UTC

zeppelin git commit: ZEPPELIN-3404. Fail to run cronjob when user doesn't run it manually before cronjob

Repository: zeppelin
Updated Branches:
  refs/heads/master c31f3b60a -> 1cea92ca3


ZEPPELIN-3404. Fail to run cronjob when user doesn't run it manually before cronjob

### What is this PR for?

This bug is introduced by #2914, this PR will set authenticationInfo using its user as we will store user into note.json.

### What type of PR is it?
[Bug Fix]

### Todos
* [ ] - Task

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

### How should this be tested?
* Manually tested

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

Author: Jeff Zhang <zj...@apache.org>

Closes #2925 from zjffdu/ZEPPELIN-3404 and squashes the following commits:

b94ecc9 [Jeff Zhang] ZEPPELIN-3404. Fail to run cronjob when user doesn't run it manually before cronjob


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/1cea92ca
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/1cea92ca
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/1cea92ca

Branch: refs/heads/master
Commit: 1cea92ca30285241239538f358e90dea014b2e5f
Parents: c31f3b6
Author: Jeff Zhang <zj...@apache.org>
Authored: Fri Apr 13 10:31:45 2018 +0800
Committer: Jeff Zhang <zj...@apache.org>
Committed: Thu Apr 26 16:05:48 2018 +0800

----------------------------------------------------------------------
 .../apache/zeppelin/user/AuthenticationInfo.java   |  4 ++++
 .../src/app/notebook/notebook.controller.js        | 10 ++++------
 .../java/org/apache/zeppelin/notebook/Note.java    | 17 +++++++++++++----
 3 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1cea92ca/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/AuthenticationInfo.java
----------------------------------------------------------------------
diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/AuthenticationInfo.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/AuthenticationInfo.java
index c9412cb..455fd8b 100644
--- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/AuthenticationInfo.java
+++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/AuthenticationInfo.java
@@ -76,6 +76,10 @@ public class AuthenticationInfo implements JsonSerializable {
     this.roles = roles;
   }
 
+  public void setRoles(String roles) {
+    this.roles = gson.fromJson(roles, ArrayList.class);
+  }
+
   public List<String> getUsersAndRoles() {
     List<String> usersAndRoles = new ArrayList<>();
     if (roles != null) {

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1cea92ca/zeppelin-web/src/app/notebook/notebook.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/notebook.controller.js b/zeppelin-web/src/app/notebook/notebook.controller.js
index ba88e3f..448df6e 100644
--- a/zeppelin-web/src/app/notebook/notebook.controller.js
+++ b/zeppelin-web/src/app/notebook/notebook.controller.js
@@ -447,19 +447,17 @@ function NotebookCtrl($scope, $route, $routeParams, $location, $rootScope,
       if (!$scope.note.config.cronExecutingUser) {
         $scope.note.config.cronExecutingUser = $rootScope.ticket.principal;
       }
+      if (!$scope.note.config.cronExecutingRoles) {
+        $scope.note.config.cronExecutingRoles = $rootScope.ticket.roles;
+      }
     } else {
       $scope.note.config.cronExecutingUser = '';
+      $scope.note.config.cronExecutingRoles = '';
     }
     $scope.note.config.cron = cronExpr;
     $scope.setConfig();
   };
 
-  /** Set the username of the user to be used to execute all notes in notebook **/
-  $scope.setCronExecutingUser = function(cronExecutingUser) {
-    $scope.note.config.cronExecutingUser = cronExecutingUser;
-    $scope.setConfig();
-  };
-
   /** Set release resource for this note **/
   $scope.setReleaseResource = function(value) {
     $scope.note.config.releaseresource = value;

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1cea92ca/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
index 664e986..80c96e2 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
@@ -21,6 +21,7 @@ import static java.lang.String.format;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import java.io.IOException;
@@ -31,6 +32,7 @@ import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
@@ -645,7 +647,16 @@ public class Note implements ParagraphJobListener, JsonSerializable {
    * Run all paragraphs sequentially. Only used for CronJob
    */
   public synchronized void runAll() {
-    runAll(null, true);
+    String cronExecutingUser = (String) getConfig().get("cronExecutingUser");
+    String cronExecutingRoles = (String) getConfig().get("cronExecutingRoles");
+    if (null == cronExecutingUser) {
+      cronExecutingUser = "anonymous";
+    }
+    AuthenticationInfo authenticationInfo = new AuthenticationInfo(
+        cronExecutingUser,
+        StringUtils.isEmpty(cronExecutingRoles) ? null : cronExecutingRoles,
+        null);
+    runAll(authenticationInfo, true);
   }
 
   public void runAll(AuthenticationInfo authenticationInfo, boolean blocking) {
@@ -653,9 +664,7 @@ public class Note implements ParagraphJobListener, JsonSerializable {
       if (!p.isEnabled()) {
         continue;
       }
-      if (authenticationInfo != null) {
-        p.setAuthenticationInfo(authenticationInfo);
-      }
+      p.setAuthenticationInfo(authenticationInfo);
       if (!run(p.getId(), blocking)) {
         logger.warn("Skip running the remain notes because paragraph {} fails", p.getId());
         break;