You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@submarine.apache.org by pi...@apache.org on 2021/11/25 19:56:31 UTC
[submarine] branch master updated: SUBMARINE-1097. Fix some bugs detected by Sonarcloud
This is an automated email from the ASF dual-hosted git repository.
pingsutw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/submarine.git
The following commit(s) were added to refs/heads/master by this push:
new cdbe32e SUBMARINE-1097. Fix some bugs detected by Sonarcloud
cdbe32e is described below
commit cdbe32e5ec383d294adb9708bb6ba6dcf8f98ac9
Author: Lisa <ae...@gmail.com>
AuthorDate: Thu Nov 25 20:36:25 2021 +0800
SUBMARINE-1097. Fix some bugs detected by Sonarcloud
### What is this PR for?
Fix the bugs detected by Sonarcloud:
- Either re-interrupt the method or rethrow the "InterruptedException" that can be caught.
- Use try-with-resources or close this "Watch" in a "finally" clause.
- Remove this throw statement from finally block
### What type of PR is it?
[Improvement]
### Todos
* [ ] - Task
### What is the Jira issue?
[SUBMARINE-1097. Fix some bugs detected by Sonarcloud](https://issues.apache.org/jira/projects/SUBMARINE/issues/SUBMARINE-1097)
### How should this be tested?
### Screenshots (if appropriate)
### Questions:
* Do the license files need updating? No
* Are there breaking changes for older versions? No
* Does this need new documentation? No
Author: Lisa <ae...@gmail.com>
Signed-off-by: Kevin <pi...@apache.org>
Closes #810 from aeioulisa/SUBMARINE-1097 and squashes the following commits:
cf4f19f2 [Lisa] reformat
de73283a [Lisa] Remove multi-catch
e3d29c18 [Lisa] Use try-catch with Watch and remove throw statement from finally block
---
.../workbench/database/utils/MybatisGenerator.java | 10 +-
.../server/submitter/k8s/K8sSubmitter.java | 141 +++++++++++----------
2 files changed, 82 insertions(+), 69 deletions(-)
diff --git a/submarine-server/server-core/src/main/java/org/apache/submarine/server/workbench/database/utils/MybatisGenerator.java b/submarine-server/server-core/src/main/java/org/apache/submarine/server/workbench/database/utils/MybatisGenerator.java
index 13c48bb..20f8d1b 100644
--- a/submarine-server/server-core/src/main/java/org/apache/submarine/server/workbench/database/utils/MybatisGenerator.java
+++ b/submarine-server/server-core/src/main/java/org/apache/submarine/server/workbench/database/utils/MybatisGenerator.java
@@ -47,7 +47,9 @@ public class MybatisGenerator {
Configuration config = null;
try {
config = cp.parseConfiguration(configFile);
- } catch (IOException | XMLParserException e) {
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
+ } catch (XMLParserException e) {
LOG.error(e.getMessage(), e);
}
@@ -60,7 +62,11 @@ public class MybatisGenerator {
}
try {
myBatisGenerator.generate(null);
- } catch (SQLException | IOException | InterruptedException e) {
+ } catch (SQLException e) {
+ LOG.error(e.getMessage(), e);
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
+ } catch (InterruptedException e) {
LOG.error(e.getMessage(), e);
}
}
diff --git a/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/K8sSubmitter.java b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/K8sSubmitter.java
index 507dde9..f99d69f 100644
--- a/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/K8sSubmitter.java
+++ b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/K8sSubmitter.java
@@ -557,85 +557,92 @@ public class K8sSubmitter implements Submitter {
public void watchExperiment() throws ApiException{
- Watch<MLJob> watchTF = Watch.createWatch(
- client,
- api.listNamespacedCustomObjectCall(
- TFJob.CRD_TF_GROUP_V1,
- TFJob.CRD_TF_VERSION_V1,
- getServerNamespace(),
- TFJob.CRD_TF_PLURAL_V1,
- "true",
- null,
- null,
- null,
- null,
- Boolean.TRUE,
- null,
- null
- ),
- new TypeToken<Watch.Response<MLJob>>() {}.getType()
- );
-
- Watch<MLJob> watchPytorch = Watch.createWatch(
- client,
- api.listNamespacedCustomObjectCall(
- PyTorchJob.CRD_PYTORCH_GROUP_V1,
- PyTorchJob.CRD_PYTORCH_VERSION_V1,
- getServerNamespace(),
- PyTorchJob.CRD_PYTORCH_PLURAL_V1,
- "true",
- null,
- null,
- null,
- null,
- Boolean.TRUE,
- null,
- null
- ),
- new TypeToken<Watch.Response<MLJob>>() {}.getType()
- );
-
ExecutorService experimentThread = Executors.newFixedThreadPool(2);
- experimentThread.execute(new Runnable() {
+ try (Watch<MLJob> watchTF = Watch.createWatch(
+ client,
+ api.listNamespacedCustomObjectCall(
+ TFJob.CRD_TF_GROUP_V1,
+ TFJob.CRD_TF_VERSION_V1,
+ getServerNamespace(),
+ TFJob.CRD_TF_PLURAL_V1,
+ "true",
+ null,
+ null,
+ null,
+ null,
+ Boolean.TRUE,
+ null,
+ null
+ ),
+ new TypeToken<Watch.Response<MLJob>>() {
+ }.getType()
+ )) {
+ experimentThread.execute(new Runnable() {
@Override
public void run() {
+ try {
+ LOG.info("Start watching on TFJobs...");
+
+ for (Watch.Response<MLJob> experiment : watchTF) {
+ LOG.info("{}", experiment.object.getStatus());
+ }
+ } finally {
+ LOG.info("WATCH TFJob END");
try {
- LOG.info("Start watching on TFJobs...");
- for (Watch.Response<MLJob> experiment : watchTF) {
- LOG.info("{}", experiment.object.getStatus());
- }
- } finally {
- LOG.info("WATCH TFJob END");
- try {
- watchTF.close();
- } catch (Exception e){
- LOG.error("{}", e.getMessage());
- }
- throw new RuntimeException();
+ watchTF.close();
+ } catch (Exception e) {
+ LOG.error("{}", e.getMessage());
}
+ }
}
- });
-
- experimentThread.execute(new Runnable() {
+ });
+ } catch (Exception ex) {
+ throw new RuntimeException();
+ }
+
+ try (Watch<MLJob> watchPytorch = Watch.createWatch(
+ client,
+ api.listNamespacedCustomObjectCall(
+ PyTorchJob.CRD_PYTORCH_GROUP_V1,
+ PyTorchJob.CRD_PYTORCH_VERSION_V1,
+ getServerNamespace(),
+ PyTorchJob.CRD_PYTORCH_PLURAL_V1,
+ "true",
+ null,
+ null,
+ null,
+ null,
+ Boolean.TRUE,
+ null,
+ null
+ ),
+ new TypeToken<Watch.Response<MLJob>>() {
+ }.getType()
+ )) {
+ experimentThread.execute(new Runnable() {
@Override
public void run() {
+ try {
+ LOG.info("Start watching on PytorchJobs...");
+
+ ;
+ for (Watch.Response<MLJob> experiment : watchPytorch) {
+ LOG.info("{}", experiment.object.getStatus());
+ }
+ } finally {
+ LOG.info("WATCH PytorchJob END");
try {
- LOG.info("Start watching on PytorchJobs...");
- for (Watch.Response<MLJob> experiment : watchPytorch) {
- LOG.info("{}", experiment.object.getStatus());
- }
- } finally {
- LOG.info("WATCH PytorchJob END");
- try {
- watchPytorch.close();
- } catch (Exception e){
- LOG.error("{}", e.getMessage());
- }
- throw new RuntimeException();
+ watchPytorch.close();
+ } catch (Exception e) {
+ LOG.error("{}", e.getMessage());
}
+ }
}
- });
+ });
+ } catch (Exception ex) {
+ throw new RuntimeException();
+ }
}
public void createPersistentVolumeClaim(String pvcName, String namespace, String scName, String storage)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@submarine.apache.org
For additional commands, e-mail: dev-help@submarine.apache.org