Reamer commented on code in PR #5022: URL: https://github.com/apache/zeppelin/pull/5022#discussion_r2269050002
########## zeppelin-server/src/main/java/org/apache/zeppelin/service/exception/JobManagerForbiddenException.java: ########## @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.service.exception; + +/** + * Runtime exception thrown when the job manager is disabled. + */ +public class JobManagerForbiddenException extends RuntimeException { Review Comment: Maybe it's better to use and checked Exception. I would prefer a checked Exception, because we can handle the exception well, depending on whether it is thrown in the WebSocket or via Rest. What do you thing? ```suggestion public class JobManagerForbiddenException extends Exception { ``` ########## zeppelin-server/src/main/java/org/apache/zeppelin/service/exception/JobManagerForbiddenException.java: ########## @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zeppelin.service.exception; + +/** + * Runtime exception thrown when the job manager is disabled. + */ +public class JobManagerForbiddenException extends RuntimeException { + Review Comment: You forgot the serialVersionUID. ########## zeppelin-server/src/main/java/org/apache/zeppelin/service/JobManagerService.java: ########## @@ -55,11 +56,25 @@ public JobManagerService(Notebook notebook, this.zConf = zConf; } + public void checkIfJobManagerIsEnabled() { + if (!zConf.isJobManagerEnabled()) { + throw new JobManagerForbiddenException(); + } + } + + private boolean isJobManagerDisabled(ServiceContext context, ServiceCallback<?> callback) throws IOException { + if (!zConf.isJobManagerEnabled()) { + callback.onFailure(new JobManagerForbiddenException(), context); + return true; + } + return false; + } + public List<NoteJobInfo> getNoteJobInfo(String noteId, ServiceContext context, ServiceCallback<List<NoteJobInfo>> callback) throws IOException { - if (!zConf.isJobManagerEnabled()) { + if (isJobManagerDisabled(context, callback)) { return new ArrayList<>(); Review Comment: This should be preferred. ```suggestion return Collections.emptyList(); ``` ########## zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java: ########## @@ -2294,7 +2305,9 @@ public class WebSocketServiceCallback<T> extends SimpleServiceCallback<T> { @Override public void onFailure(Exception ex, ServiceContext context) throws IOException { super.onFailure(ex, context); - if (ex instanceof ForbiddenException) { + if (ex instanceof JobManagerForbiddenException) { Review Comment: In my opinion, this is the wrong place. Please override the `onFailure` method in the `JobManagerServiceCallback` class. ########## zeppelin-server/src/main/java/org/apache/zeppelin/service/JobManagerService.java: ########## @@ -83,7 +98,7 @@ public List<NoteJobInfo> getNoteJobInfoByUnixTime(long lastUpdateServerUnixTime, ServiceContext context, ServiceCallback<List<NoteJobInfo>> callback) throws IOException { - if (!zConf.isJobManagerEnabled()) { + if (isJobManagerDisabled(context, callback)) { return new ArrayList<>(); Review Comment: This should be preferred. ```suggestion return Collections.emptyList(); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@zeppelin.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org