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 2022/02/22 08:11:04 UTC
[submarine] branch master updated: SUBMARINE-1199. add style check in submarine-agent module
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 e142997 SUBMARINE-1199. add style check in submarine-agent module
e142997 is described below
commit e14299761a1e00f00567d7db67a869ba9f62cd69
Author: FatalLin <fa...@gmail.com>
AuthorDate: Tue Feb 22 13:12:44 2022 +0800
SUBMARINE-1199. add style check in submarine-agent module
### What is this PR for?
add code style check plugin in agent module and polish the code in the same time.
### What type of PR is it?
Improvement
### Todos
NA
### What is the Jira issue?
https://issues.apache.org/jira/browse/SUBMARINE-1199
### How should this be tested?
this change should not effect the code.
### 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: FatalLin <fa...@gmail.com>
Signed-off-by: Kevin <pi...@apache.org>
Closes #886 from FatalLin/SUBMARINE-1199 and squashes the following commits:
8fc8563c [FatalLin] add style check
---
.../server-submitter/submarine-k8s-agent/pom.xml | 288 +++++++++++----------
.../submarine/server/k8s/agent/HandlerFactory.java | 15 +-
.../submarine/server/k8s/agent/SubmarineAgent.java | 86 +++---
.../k8s/agent/handler/CustomResourceHandler.java | 147 ++++++-----
.../server/k8s/agent/handler/NotebookHandler.java | 41 +--
.../server/k8s/agent/util/RestClient.java | 12 +-
6 files changed, 301 insertions(+), 288 deletions(-)
diff --git a/submarine-server/server-submitter/submarine-k8s-agent/pom.xml b/submarine-server/server-submitter/submarine-k8s-agent/pom.xml
index 44beae0..fcfdfd3 100644
--- a/submarine-server/server-submitter/submarine-k8s-agent/pom.xml
+++ b/submarine-server/server-submitter/submarine-k8s-agent/pom.xml
@@ -1,145 +1,153 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <!--
- 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
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <!-- 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. -->
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.submarine</groupId>
+ <artifactId>submarine-server-submitter</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ </parent>
- http://www.apache.org/licenses/LICENSE-2.0
+ <artifactId>submarine-k8s-agent</artifactId>
+ <name>Submarine: K8S Agent</name>
- 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.
- -->
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.submarine</groupId>
- <artifactId>submarine-server-submitter</artifactId>
- <version>0.7.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>submarine-k8s-agent</artifactId>
- <name>Submarine: K8S Agent</name>
-
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${slf4j.version}</version>
- </dependency>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${slf4j.version}</version>
- </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
- <dependency>
- <groupId>org.apache.submarine</groupId>
- <artifactId>submarine-submitter-k8s</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- <profiles>
- <profile>
- <id>src</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <configuration>
- <skip>false</skip>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-enforcer-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <executions>
- <execution>
- <id>src-dist</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- <configuration>
- <finalName>${project.artifactId}-${project.version}-src</finalName>
- <appendAssemblyId>false</appendAssemblyId>
- <attach>false</attach>
- <descriptors>
- <descriptor>src/assembly/src-distribution.xml</descriptor>
- </descriptors>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-dependencies-runtime</id>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <includeScope>runtime</includeScope>
- </configuration>
- </execution>
- <execution>
- <id>copy-dependencies-system</id>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <includeScope>system</includeScope>
- <excludeTransitive>true</excludeTransitive>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>${plugin.maven.assembly.version}</version>
- <executions>
- <execution>
- <id>dist</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- <configuration>
- <finalName>${project.artifactId}-${project.version}</finalName>
- <appendAssemblyId>false</appendAssemblyId>
- <attach>false</attach>
- <descriptors>
- <descriptor>src/assembly/distribution.xml</descriptor>
- </descriptors>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <dependency>
+ <groupId>org.apache.submarine</groupId>
+ <artifactId>submarine-submitter-k8s</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ <profiles>
+ <profile>
+ <id>src</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>src-dist</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <finalName>${project.artifactId}-${project.version}-src</finalName>
+ <appendAssemblyId>false</appendAssemblyId>
+ <attach>false</attach>
+ <descriptors>
+ <descriptor>src/assembly/src-distribution.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies-runtime</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <includeScope>runtime</includeScope>
+ </configuration>
+ </execution>
+ <execution>
+ <id>copy-dependencies-system</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <includeScope>system</includeScope>
+ <excludeTransitive>true</excludeTransitive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>${plugin.maven.assembly.version}</version>
+ <executions>
+ <execution>
+ <id>dist</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <appendAssemblyId>false</appendAssemblyId>
+ <attach>false</attach>
+ <descriptors>
+ <descriptor>src/assembly/distribution.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
\ No newline at end of file
diff --git a/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/HandlerFactory.java b/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/HandlerFactory.java
index 56c676f..9f030fb 100644
--- a/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/HandlerFactory.java
+++ b/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/HandlerFactory.java
@@ -24,12 +24,13 @@ import org.apache.submarine.server.k8s.agent.handler.CustomResourceHandler;
public class HandlerFactory {
- private static String HANDLER_POSTFIX = "Handler";
- private static String HANDLER_PACKAGE = "org.apache.submarine.server.k8s.agent.handler";
+ private static String HANDLER_POSTFIX = "Handler";
+ private static String HANDLER_PACKAGE = "org.apache.submarine.server.k8s.agent.handler";
- public static CustomResourceHandler getHandler(CustomResourceType crType) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
- String handlerClassStr = HANDLER_PACKAGE + "." + crType.toString() + HANDLER_POSTFIX;
- Class handlerClass = Class.forName(handlerClassStr);
- return (CustomResourceHandler)handlerClass.newInstance();
- }
+ public static CustomResourceHandler getHandler(CustomResourceType crType)
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+ String handlerClassStr = HANDLER_PACKAGE + "." + crType.toString() + HANDLER_POSTFIX;
+ Class handlerClass = Class.forName(handlerClassStr);
+ return (CustomResourceHandler) handlerClass.newInstance();
+ }
}
diff --git a/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/SubmarineAgent.java b/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/SubmarineAgent.java
index 7e1aab2..148ef05 100644
--- a/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/SubmarineAgent.java
+++ b/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/SubmarineAgent.java
@@ -28,58 +28,58 @@ import org.slf4j.LoggerFactory;
public class SubmarineAgent {
- private static final Logger LOG = LoggerFactory.getLogger(SubmarineAgent.class);
- private String serverHost;
- private Integer serverPort;
- private String namespace;
- private String customResourceType;
- private String customResourceName;
- private String resourceId;
- private CustomResourceType type;
- private CustomResourceHandler handler;
+ private static final Logger LOG = LoggerFactory.getLogger(SubmarineAgent.class);
+ private String serverHost;
+ private Integer serverPort;
+ private String namespace;
+ private String customResourceType;
+ private String customResourceName;
+ private String resourceId;
+ private CustomResourceType type;
+ private CustomResourceHandler handler;
- public SubmarineAgent(String serverHost, Integer serverPort, String namespace,
+ public SubmarineAgent(String serverHost, Integer serverPort, String namespace,
String customResourceType, String customResourceName,
String resourceId) throws ClassNotFoundException,
- InstantiationException, IllegalAccessException, IOException {
- this.serverHost = serverHost;
- this.serverPort = serverPort;
- this.namespace = namespace;
- this.customResourceType = customResourceType;
- this.customResourceName = customResourceName;
- this.resourceId = resourceId;
- this.type = CustomResourceType.valueOf(customResourceType);
- this.handler = HandlerFactory.getHandler(this.type);
- this.handler.init(serverHost, serverPort, namespace, customResourceName, resourceId);
- }
+ InstantiationException, IllegalAccessException, IOException {
+ this.serverHost = serverHost;
+ this.serverPort = serverPort;
+ this.namespace = namespace;
+ this.customResourceType = customResourceType;
+ this.customResourceName = customResourceName;
+ this.resourceId = resourceId;
+ this.type = CustomResourceType.valueOf(customResourceType);
+ this.handler = HandlerFactory.getHandler(this.type);
+ this.handler.init(serverHost, serverPort, namespace, customResourceName, resourceId);
+ }
- public void start() {
- handler.run();
- }
+ public void start() {
+ handler.run();
+ }
- public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
- String serverHost = System.getenv("SERVER_HOST");
- Integer serverPort = Integer.parseInt(System.getenv("SERVER_PORT"));
- LOG.info(String.format("SERVER_HOST:%s", serverHost));
- LOG.info(String.format("SERVER_PORT:%d", serverPort));
+ public static void main(String[] args)
+ throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
+ String serverHost = System.getenv("SERVER_HOST");
+ Integer serverPort = Integer.parseInt(System.getenv("SERVER_PORT"));
+ LOG.info(String.format("SERVER_HOST:%s", serverHost));
+ LOG.info(String.format("SERVER_PORT:%d", serverPort));
- String namespace = System.getenv("NAMESPACE");
- String customResourceType = System.getenv("CUSTOM_RESOURCE_TYPE");
- String customResourceName = System.getenv("CUSTOM_RESOURCE_NAME");
- String customResourceId = System.getenv("CUSTOM_RESOURCE_ID");
+ String namespace = System.getenv("NAMESPACE");
+ String customResourceType = System.getenv("CUSTOM_RESOURCE_TYPE");
+ String customResourceName = System.getenv("CUSTOM_RESOURCE_NAME");
+ String customResourceId = System.getenv("CUSTOM_RESOURCE_ID");
- LOG.info(String.format("NAMESPACE:%s", namespace));
- LOG.info(String.format("CUSTOM_RESOURCE_TYPE:%s", customResourceType));
- LOG.info(String.format("CUSTOM_RESOURCE_NAME:%s", customResourceName));
- LOG.info(String.format("CUSTOM_RESOURCE_ID:%s", customResourceId));
+ LOG.info(String.format("NAMESPACE:%s", namespace));
+ LOG.info(String.format("CUSTOM_RESOURCE_TYPE:%s", customResourceType));
+ LOG.info(String.format("CUSTOM_RESOURCE_NAME:%s", customResourceName));
+ LOG.info(String.format("CUSTOM_RESOURCE_ID:%s", customResourceId));
- SubmarineAgent agent = new SubmarineAgent(serverHost, serverPort, namespace,
- customResourceType, customResourceName, customResourceId);
+ SubmarineAgent agent = new SubmarineAgent(serverHost, serverPort, namespace,
+ customResourceType, customResourceName, customResourceId);
- agent.start();
-
- }
+ agent.start();
+
+ }
-
}
diff --git a/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/handler/CustomResourceHandler.java b/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/handler/CustomResourceHandler.java
index e150e80..4a9eb50 100644
--- a/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/handler/CustomResourceHandler.java
+++ b/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/handler/CustomResourceHandler.java
@@ -36,96 +36,95 @@ import io.kubernetes.client.util.KubeConfig;
import okhttp3.OkHttpClient;
public abstract class CustomResourceHandler {
- private static final Logger LOG = LoggerFactory.getLogger(CustomResourceHandler.class);
- private static final String KUBECONFIG_ENV = "KUBECONFIG";
+ private static final Logger LOG = LoggerFactory.getLogger(CustomResourceHandler.class);
+ private static final String KUBECONFIG_ENV = "KUBECONFIG";
- protected ApiClient client = null;
- protected CustomObjectsApi customObjectsApi = null;
- protected CoreV1Api coreV1Api = null;
- protected String namespace;
- protected String crType;
- protected String crName;
- protected String serverHost;
- protected Integer serverPort;
- protected String resourceId;
- protected RestClient restClient;
+ protected ApiClient client = null;
+ protected CustomObjectsApi customObjectsApi = null;
+ protected CoreV1Api coreV1Api = null;
+ protected String namespace;
+ protected String crType;
+ protected String crName;
+ protected String serverHost;
+ protected Integer serverPort;
+ protected String resourceId;
+ protected RestClient restClient;
- public CustomResourceHandler() throws IOException {
+ public CustomResourceHandler() throws IOException {
+ try {
+ String path = System.getenv(KUBECONFIG_ENV);
+ LOG.info("PATH:" + path);
+ KubeConfig config = KubeConfig.loadKubeConfig(new FileReader(path));
+ client = ClientBuilder.kubeconfig(config).build();
+ } catch (Exception e) {
+ LOG.info("Maybe in cluster mode, try to initialize the client again.");
try {
- String path = System.getenv(KUBECONFIG_ENV);
- LOG.info("PATH:" + path);
- KubeConfig config = KubeConfig.loadKubeConfig(new FileReader(path));
- client = ClientBuilder.kubeconfig(config).build();
- } catch (Exception e) {
- LOG.info("Maybe in cluster mode, try to initialize the client again.");
- try {
- client = ClientBuilder.cluster().build();
- } catch (IOException e1) {
- LOG.error("Initialize K8s submitter failed. " + e.getMessage(), e1);
- throw new SubmarineRuntimeException(500, "Initialize K8s submitter failed.");
- }
- } finally {
- // let watcher can wait until the next change
- client.setReadTimeout(0);
- OkHttpClient httpClient = client.getHttpClient();
- this.client.setHttpClient(httpClient);
- Configuration.setDefaultApiClient(client);
+ client = ClientBuilder.cluster().build();
+ } catch (IOException e1) {
+ LOG.error("Initialize K8s submitter failed. " + e.getMessage(), e1);
+ throw new SubmarineRuntimeException(500, "Initialize K8s submitter failed.");
}
-
- customObjectsApi = new CustomObjectsApi(client);
- coreV1Api = new CoreV1Api(client);
- }
+ } finally {
+ // let watcher can wait until the next change
+ client.setReadTimeout(0);
+ OkHttpClient httpClient = client.getHttpClient();
+ this.client.setHttpClient(httpClient);
+ Configuration.setDefaultApiClient(client);
+ }
+ customObjectsApi = new CustomObjectsApi(client);
+ coreV1Api = new CoreV1Api(client);
+ }
- public abstract void init(String serverHost, Integer serverPort,
- String namespace, String crName, String resourceId);
- public abstract void run();
+ public abstract void init(String serverHost, Integer serverPort,
+ String namespace, String crName, String resourceId);
+ public abstract void run();
- public String getNamespace() {
- return namespace;
- }
+ public String getNamespace() {
+ return namespace;
+ }
- public void setNamespace(String namespace) {
- this.namespace = namespace;
- }
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
- public String getCrType() {
- return crType;
- }
+ public String getCrType() {
+ return crType;
+ }
- public void setCrType(String crType) {
- this.crType = crType;
- }
+ public void setCrType(String crType) {
+ this.crType = crType;
+ }
- public String getCrName() {
- return crName;
- }
+ public String getCrName() {
+ return crName;
+ }
- public void setCrName(String crName) {
- this.crName = crName;
- }
+ public void setCrName(String crName) {
+ this.crName = crName;
+ }
- public String getServerHost() {
- return serverHost;
- }
+ public String getServerHost() {
+ return serverHost;
+ }
- public void setServerHost(String serverHost) {
- this.serverHost = serverHost;
- }
+ public void setServerHost(String serverHost) {
+ this.serverHost = serverHost;
+ }
- public Integer getServerPort() {
- return serverPort;
- }
+ public Integer getServerPort() {
+ return serverPort;
+ }
- public void setServerPort(Integer serverPort) {
- this.serverPort = serverPort;
- }
+ public void setServerPort(Integer serverPort) {
+ this.serverPort = serverPort;
+ }
- public RestClient getRestClient() {
- return restClient;
- }
+ public RestClient getRestClient() {
+ return restClient;
+ }
- public void setRestClient(RestClient restClient) {
- this.restClient = restClient;
- }
+ public void setRestClient(RestClient restClient) {
+ this.restClient = restClient;
+ }
}
diff --git a/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/handler/NotebookHandler.java b/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/handler/NotebookHandler.java
index 00a75f2..2db0fe2 100644
--- a/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/handler/NotebookHandler.java
+++ b/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/handler/NotebookHandler.java
@@ -63,19 +63,19 @@ public class NotebookHandler extends CustomResourceHandler {
this.resourceId = resourceId;
try {
- String podLabelSelector = String.format("%s=%s", NotebookCR.NOTEBOOK_ID,
- this.resourceId);
- V1PodList podList = this.coreV1Api.listNamespacedPod(namespace, null, null, null, null,
- podLabelSelector, null, null, null, null, null);
- this.podName = podList.getItems().get(0).getMetadata().getName();
- String fieldSelector = String.format("involvedObject.name=%s", this.podName);
-
- Call call = coreV1Api.listNamespacedEventCall(namespace, null, null, null, fieldSelector,
- null, null, null, null, null, true, null);
+ String podLabelSelector = String.format("%s=%s", NotebookCR.NOTEBOOK_ID,
+ this.resourceId);
+ V1PodList podList = this.coreV1Api.listNamespacedPod(namespace, null, null, null, null,
+ podLabelSelector, null, null, null, null, null);
+ this.podName = podList.getItems().get(0).getMetadata().getName();
+ String fieldSelector = String.format("involvedObject.name=%s", this.podName);
+
+ Call call = coreV1Api.listNamespacedEventCall(namespace, null, null, null, fieldSelector,
+ null, null, null, null, null, true, null);
- watcher = Watch.createWatch(client, call, new TypeToken<Response<CoreV1Event>>(){}.getType());
+ watcher = Watch.createWatch(client, call, new TypeToken<Response<CoreV1Event>>(){}.getType());
- customObjectsApi = new CustomObjectsApi();
+ customObjectsApi = new CustomObjectsApi();
} catch (ApiException e) {
e.printStackTrace();
@@ -94,35 +94,40 @@ public class NotebookHandler extends CustomResourceHandler {
switch (reason) {
case "Created":
case "Scheduled":
- object = customObjectsApi.getNamespacedCustomObject(NotebookCR.CRD_NOTEBOOK_GROUP_V1, NotebookCR.CRD_NOTEBOOK_VERSION_V1,
+ object = customObjectsApi.getNamespacedCustomObject(NotebookCR.CRD_NOTEBOOK_GROUP_V1,
+ NotebookCR.CRD_NOTEBOOK_VERSION_V1,
namespace, NotebookCR.CRD_NOTEBOOK_PLURAL_V1, crName);
notebook = NotebookUtils.parseObject(object, NotebookUtils.ParseOpt.PARSE_OPT_GET);
notebook.setStatus(Notebook.Status.STATUS_CREATING.getValue());
restClient.callStatusUpdate(CustomResourceType.Notebook, this.resourceId, notebook);
break;
case "Started":
- object = customObjectsApi.getNamespacedCustomObject(NotebookCR.CRD_NOTEBOOK_GROUP_V1, NotebookCR.CRD_NOTEBOOK_VERSION_V1,
+ object = customObjectsApi.getNamespacedCustomObject(NotebookCR.CRD_NOTEBOOK_GROUP_V1,
+ NotebookCR.CRD_NOTEBOOK_VERSION_V1,
namespace, NotebookCR.CRD_NOTEBOOK_PLURAL_V1, crName);
notebook = NotebookUtils.parseObject(object, NotebookUtils.ParseOpt.PARSE_OPT_GET);
notebook.setStatus(Notebook.Status.STATUS_RUNNING.getValue());
restClient.callStatusUpdate(CustomResourceType.Notebook, this.resourceId, notebook);
break;
case "Failed":
- object = customObjectsApi.getNamespacedCustomObject(NotebookCR.CRD_NOTEBOOK_GROUP_V1, NotebookCR.CRD_NOTEBOOK_VERSION_V1,
+ object = customObjectsApi.getNamespacedCustomObject(NotebookCR.CRD_NOTEBOOK_GROUP_V1,
+ NotebookCR.CRD_NOTEBOOK_VERSION_V1,
namespace, NotebookCR.CRD_NOTEBOOK_PLURAL_V1, crName);
notebook = NotebookUtils.parseObject(object, NotebookUtils.ParseOpt.PARSE_OPT_GET);
notebook.setStatus(Notebook.Status.STATUS_FAILED.getValue());
restClient.callStatusUpdate(CustomResourceType.Notebook, this.resourceId, notebook);
break;
case "Pulling":
- object = customObjectsApi.getNamespacedCustomObject(NotebookCR.CRD_NOTEBOOK_GROUP_V1, NotebookCR.CRD_NOTEBOOK_VERSION_V1,
+ object = customObjectsApi.getNamespacedCustomObject(NotebookCR.CRD_NOTEBOOK_GROUP_V1,
+ NotebookCR.CRD_NOTEBOOK_VERSION_V1,
namespace, NotebookCR.CRD_NOTEBOOK_PLURAL_V1, crName);
notebook = NotebookUtils.parseObject(object, NotebookUtils.ParseOpt.PARSE_OPT_GET);
notebook.setStatus(Notebook.Status.STATUS_PULLING.getValue());
restClient.callStatusUpdate(CustomResourceType.Notebook, this.resourceId, notebook);
break;
case "Killing":
- object = customObjectsApi.getNamespacedCustomObject(NotebookCR.CRD_NOTEBOOK_GROUP_V1, NotebookCR.CRD_NOTEBOOK_VERSION_V1,
+ object = customObjectsApi.getNamespacedCustomObject(NotebookCR.CRD_NOTEBOOK_GROUP_V1,
+ NotebookCR.CRD_NOTEBOOK_VERSION_V1,
namespace, NotebookCR.CRD_NOTEBOOK_PLURAL_V1, crName);
notebook = NotebookUtils.parseObject(object, NotebookUtils.ParseOpt.PARSE_OPT_GET);
notebook.setStatus(Notebook.Status.STATUS_TERMINATING.getValue());
@@ -133,8 +138,8 @@ public class NotebookHandler extends CustomResourceHandler {
default:
LOG.info(String.format("Unprocessed event type:%s", reason));
}
- } catch(ApiException e) {
- LOG.error("error while accessing k8s", e);
+ } catch (ApiException e) {
+ LOG.error("error while accessing k8s", e);
}
}
}
diff --git a/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/util/RestClient.java b/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/util/RestClient.java
index 77114a3..1ff9427 100644
--- a/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/util/RestClient.java
+++ b/submarine-server/server-submitter/submarine-k8s-agent/src/main/java/org/apache/submarine/server/k8s/agent/util/RestClient.java
@@ -41,15 +41,15 @@ public class RestClient {
}
public void callStatusUpdate(CustomResourceType type, String resourceId, Object updateObject) {
-
- String uri = String.format("api/%s/%s/%s/%s", RestConstants.V1,
- RestConstants.INTERNAL, type.toString(), resourceId);
- LOG.info("Targeting uri:" + uri);
+
+ String uri = String.format("api/%s/%s/%s/%s", RestConstants.V1,
+ RestConstants.INTERNAL, type.toString(), resourceId);
+ LOG.info("Targeting uri:" + uri);
- client.target(API_SERVER_URL)
+ client.target(API_SERVER_URL)
.path(uri)
.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(updateObject, MediaType.APPLICATION_JSON), String.class);
}
-
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@submarine.apache.org
For additional commands, e-mail: dev-help@submarine.apache.org