From ac453ee0755d922f08a256bcee7956a38bb0c07f Mon Sep 17 00:00:00 2001 From: liningrui Date: Fri, 25 Dec 2020 16:52:59 +0800 Subject: [PATCH 1/2] Check if master node before schedule gremlin job Change-Id: I9ef3e1f3f4d30ae8b252a53c148b0b0759eff472 --- .../src/main/java/com/baidu/hugegraph/job/JobBuilder.java | 3 +++ .../java/com/baidu/hugegraph/task/StandardTaskScheduler.java | 5 +++++ .../main/java/com/baidu/hugegraph/task/TaskScheduler.java | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/JobBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/JobBuilder.java index a0dc69d4ca..584d892281 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/JobBuilder.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/JobBuilder.java @@ -71,6 +71,9 @@ public HugeTask schedule() { E.checkArgumentNotNull(this.job, "Job callable can't be null"); E.checkArgument(this.job instanceof TaskCallable, "Job must be instance of TaskCallable"); + + this.graph.taskScheduler().checkRequirement("schedule"); + @SuppressWarnings("unchecked") TaskCallable job = (TaskCallable) this.job; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/StandardTaskScheduler.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/StandardTaskScheduler.java index 90d3145073..ddfe78784b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/StandardTaskScheduler.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/StandardTaskScheduler.java @@ -659,6 +659,11 @@ public void waitUntilAllTasksCompleted(long seconds) taskSize, seconds)); } + @Override + public void checkRequirement(String op) { + this.checkOnMasterNode(op); + } + private Iterator> queryTask(String key, Object value, long limit, String page) { return this.queryTask(ImmutableMap.of(key, value), limit, page); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java index 89c5ca2ac7..eb09075f2e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java @@ -61,4 +61,8 @@ public HugeTask waitUntilTaskCompleted(Id id) public void waitUntilAllTasksCompleted(long seconds) throws TimeoutException; + + default public void checkRequirement(String op) { + // pass + } } From c8d9673156b5168810423b4b3cbdb44b00abdccd Mon Sep 17 00:00:00 2001 From: liningrui Date: Mon, 28 Dec 2020 14:24:16 +0800 Subject: [PATCH 2/2] remove default implement Change-Id: I5d6b29ce78e896a3a7f483c696f8d0da71d4b784 --- .../java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java | 6 ++++++ .../main/java/com/baidu/hugegraph/task/TaskScheduler.java | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java index 37bcf7873c..8f5de47070 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java @@ -974,6 +974,12 @@ public void waitUntilAllTasksCompleted(long seconds) this.taskScheduler.waitUntilAllTasksCompleted(seconds); } + @Override + public void checkRequirement(String op) { + verifyStatusPermission(); + this.taskScheduler.checkRequirement(op); + } + private void verifyTaskPermission(HugePermission actionPerm) { verifyPermission(actionPerm, ResourceType.TASK); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java index eb09075f2e..c20600a131 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskScheduler.java @@ -62,7 +62,5 @@ public HugeTask waitUntilTaskCompleted(Id id) public void waitUntilAllTasksCompleted(long seconds) throws TimeoutException; - default public void checkRequirement(String op) { - // pass - } + public void checkRequirement(String op); }