From f66c38a0069084a3fd77c5cc2cc82b16b50aad73 Mon Sep 17 00:00:00 2001
From: Eason <291028775@qq.com>
Date: Sun, 5 Feb 2023 00:07:04 +0800
Subject: [PATCH] doc: rm clear foreign key and set default value for job type
---
.../config/mybatis/ClearForeignKey.java | 89 -------------------
.../sonic/controller/models/domain/Jobs.java | 2 +-
.../controller/quartz/QuartzHandler.java | 2 -
.../service/impl/AgentsServiceImplTest.java | 5 --
4 files changed, 1 insertion(+), 97 deletions(-)
delete mode 100644 sonic-server-controller/src/main/java/org/cloud/sonic/controller/config/mybatis/ClearForeignKey.java
diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/config/mybatis/ClearForeignKey.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/config/mybatis/ClearForeignKey.java
deleted file mode 100644
index 529b255d..00000000
--- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/config/mybatis/ClearForeignKey.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * sonic-server Sonic Cloud Real Machine Platform.
- * Copyright (C) 2022 SonicCloudOrg
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published
- * by the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-package org.cloud.sonic.controller.config.mybatis;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.boot.autoconfigure.jdbc.DataSourceSchemaCreatedEvent;
-import org.springframework.context.ApplicationListener;
-import org.springframework.stereotype.Component;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 清除历史遗留的外键
- *
- * @author JayWenStar, Eason
- * @date 2021/12/26 1:39 上午
- */
-@Component
-@Slf4j
-public class ClearForeignKey implements ApplicationListener {
-
- @Override
- public void onApplicationEvent(DataSourceSchemaCreatedEvent event) {
- DataSource dataSource = (DataSource) event.getSource();
- String dataBase = "";
-// String findFKSql = "SELECT CONCAT('ALTER TABLE ', TABLE_NAME,' DROP FOREIGN KEY ',CONSTRAINT_NAME) as ddl " +
-// "FROM information_schema.TABLE_CONSTRAINTS c " +
-// "WHERE c.TABLE_SCHEMA='%s' AND c.CONSTRAINT_TYPE='FOREIGN KEY'";
- String transSql = "UPDATE jobs SET type = 'testJob' WHERE type is null or type = \"\"";
- List deleteSqlList = new ArrayList<>();
- try (Connection connection = dataSource.getConnection()) {
- try (Statement statement = connection.createStatement()) {
-
- // 获取当前数据库名
- ResultSet resultSet1 = statement.executeQuery("select DATABASE() db");
- if (resultSet1.next()) {
- dataBase = resultSet1.getString("db");
- }
-
-// // 查询所有外键索引,并拼装成删除sql
-// ResultSet resultSet2 = statement.executeQuery(String.format(findFKSql, dataBase));
-// while (resultSet2.next()) {
-// deleteSqlList.add(resultSet2.getString("ddl"));
-// }
-
- // 版本兼容sql
- Boolean resultSet3 = statement.execute(String.format(transSql, dataBase));
- if (!resultSet3) {
- log.info(String.format("transfer sql %s failed, ignore...", transSql));
- }
-
- // 执行删除外键sql
- for (String deleteSql : deleteSqlList) {
- statement.executeUpdate(deleteSql);
- }
-
-// // 删除 test_suites_devices 表的主键
-// try {
-// statement.executeUpdate("Alter table test_suites_devices Drop primary key");
-// } catch (Exception e) {
-// // 无视错误
-// }
- }
- } catch (Exception e) {
- log.error("clear foreign key failed.");
- e.printStackTrace();
- }
- }
-}
diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/Jobs.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/Jobs.java
index 8a67c326..6cb7106a 100644
--- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/Jobs.java
+++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/Jobs.java
@@ -56,6 +56,6 @@ public class Jobs implements Serializable, TypeConverter {
private Integer suiteId;
@TableField
- @Column(isNull = false, comment = "定时任务类型")
+ @Column(isNull = false, defaultValue = "testJob", comment = "定时任务类型")
private String type;
}
diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/quartz/QuartzHandler.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/quartz/QuartzHandler.java
index c9f53321..4e7e7ee4 100644
--- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/quartz/QuartzHandler.java
+++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/quartz/QuartzHandler.java
@@ -250,9 +250,7 @@ public void updateSysScheduleJob(String type, String cron) {
public void createSysTrigger() {
for (String type : typeList) {
-// 从数据库中获取数据,然后创建
Jobs job = jobsService.findByType(type);
-// 首次部署,初始化系统定时任务
if (job == null) {
job = initSysJob(type);
}
diff --git a/sonic-server-controller/src/test/java/org/cloud/sonic/controller/service/impl/AgentsServiceImplTest.java b/sonic-server-controller/src/test/java/org/cloud/sonic/controller/service/impl/AgentsServiceImplTest.java
index 537910d2..778889d4 100644
--- a/sonic-server-controller/src/test/java/org/cloud/sonic/controller/service/impl/AgentsServiceImplTest.java
+++ b/sonic-server-controller/src/test/java/org/cloud/sonic/controller/service/impl/AgentsServiceImplTest.java
@@ -100,11 +100,6 @@ public void testUpdate() {
agentsService.update(id, name, highTemp, highTempTime, robotType, robotToken, robotSecret);
- agents.setId(1);
- Mockito.when(agentsMapper.selectById(Mockito.any()))
- .thenReturn(agents);
- agentsService.update(1, name, highTemp, highTempTime, robotType, robotToken, robotSecret);
-
}