You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@submarine.apache.org by GitBox <gi...@apache.org> on 2021/10/17 00:47:42 UTC

[GitHub] [submarine] pingsutw commented on a change in pull request #770: SUBMARINE-1052. Create submarine model management service in server

pingsutw commented on a change in pull request #770:
URL: https://github.com/apache/submarine/pull/770#discussion_r730293542



##########
File path: submarine-server/server-core/src/main/java/org/apache/submarine/server/model/database/service/ModelVersionService.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.submarine.server.model.database.service;
+
+import org.apache.ibatis.session.SqlSession;
+import org.apache.submarine.commons.utils.exception.SubmarineRuntimeException;
+import org.apache.submarine.server.database.utils.MyBatisUtil;
+import org.apache.submarine.server.model.database.entities.ModelVersionEntity;
+import org.apache.submarine.server.model.database.mappers.ModelVersionMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class ModelVersionService {
+
+  private static final Logger LOG = LoggerFactory.getLogger(ModelVersionService.class);
+
+  public List<ModelVersionEntity> selectAllVersions(String name) throws SubmarineRuntimeException {
+    LOG.info("Model Version select all versions:" + name);
+    List<ModelVersionEntity> modelVersionEntities;
+    try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
+      ModelVersionMapper mapper = sqlSession.getMapper(ModelVersionMapper.class);
+      modelVersionEntities = mapper.selectAllVersions(name);
+      sqlSession.commit();
+    } catch (Exception e) {
+      LOG.error(e.getMessage(), e);
+      throw new SubmarineRuntimeException("Unable to get model version from database");
+    }
+    return modelVersionEntities;
+  }
+
+  public ModelVersionEntity select(String name, Integer version) throws SubmarineRuntimeException {
+    LOG.info("Model Version select:" + name + " " + version.toString());
+    ModelVersionEntity modelVersionEntity;
+    try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
+      ModelVersionMapper mapper = sqlSession.getMapper(ModelVersionMapper.class);
+      modelVersionEntity = mapper.select(name, version);
+      sqlSession.commit();
+    } catch (Exception e) {
+      LOG.error(e.getMessage(), e);
+      throw new SubmarineRuntimeException("Unable to get model version from database");
+    }
+    return modelVersionEntity;
+  }
+  public ModelVersionEntity selectWithTag(String name, Integer version) throws SubmarineRuntimeException {
+    LOG.info("Model Version select with tag:" + name + " " + version.toString());
+    ModelVersionEntity modelVersionEntity;
+    try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
+      ModelVersionMapper mapper = sqlSession.getMapper(ModelVersionMapper.class);
+      modelVersionEntity = mapper.selectWithTag(name, version);
+      sqlSession.commit();
+    } catch (Exception e) {
+      LOG.error(e.getMessage(), e);
+      throw new SubmarineRuntimeException("Unable to get model version from database");
+    }
+    return modelVersionEntity;
+  }
+
+  public void insert(ModelVersionEntity modelVersion) throws SubmarineRuntimeException {
+    LOG.info("Model Version insert " + modelVersion.getName());
+    try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
+      ModelVersionMapper mapper = sqlSession.getMapper(ModelVersionMapper.class);
+      mapper.insert(modelVersion);
+      sqlSession.commit();
+    } catch (Exception e) {
+      LOG.error(e.getMessage(), e);
+      throw new SubmarineRuntimeException("Unable to insert model version from database");
+    }
+  }
+
+  public void update(ModelVersionEntity modelVersion) throws SubmarineRuntimeException {
+    LOG.info("Model Version update " + modelVersion.getName());
+    try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
+      ModelVersionMapper mapper = sqlSession.getMapper(ModelVersionMapper.class);
+      mapper.update(modelVersion);
+      sqlSession.commit();
+    } catch (Exception e) {
+      LOG.error(e.getMessage(), e);
+      throw new SubmarineRuntimeException("Unable to insert model version from database");

Review comment:
       ```suggestion
         throw new SubmarineRuntimeException("Unable to update model version from database");
   ```




-- 
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: commits-unsubscribe@submarine.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org