diff --git a/deploy-service/common/pom.xml b/deploy-service/common/pom.xml
index ccb9d16706..d9d0429e2c 100644
--- a/deploy-service/common/pom.xml
+++ b/deploy-service/common/pom.xml
@@ -54,9 +54,9 @@
slf4j-api
- mysql
- mysql-connector-java
- 5.1.49
+ com.mysql
+ mysql-connector-j
+ 8.3.0
commons-dbcp
@@ -155,9 +155,21 @@
test
- mysql
- mysql-connector-mxj
- 5.0.12
+ org.testcontainers
+ testcontainers
+ 1.19.7
+ test
+
+
+ org.testcontainers
+ junit-jupiter
+ 1.19.7
+ test
+
+
+ org.testcontainers
+ mysql
+ 1.19.7
test
diff --git a/deploy-service/common/src/main/java/com/pinterest/deployservice/db/DatabaseUtil.java b/deploy-service/common/src/main/java/com/pinterest/deployservice/db/DatabaseUtil.java
index 2ab7ba9bf9..6f8e79cebd 100644
--- a/deploy-service/common/src/main/java/com/pinterest/deployservice/db/DatabaseUtil.java
+++ b/deploy-service/common/src/main/java/com/pinterest/deployservice/db/DatabaseUtil.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2016 Pinterest, Inc.
+ * Copyright (c) 2016-2024 Pinterest, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,159 +16,188 @@
package com.pinterest.deployservice.db;
import com.pinterest.deployservice.bean.UpdateStatement;
-
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Utility class to insertOrUpdate MySQL datasource.
- */
+/** Utility class to insertOrUpdate MySQL datasource. */
public class DatabaseUtil {
- public static final int MAX_WAIT_TIME_FOR_CONN_IN_MS = 200;
- public static final String MYSQL_JDBC_DRIVER = "com.mysql.jdbc.Driver";
- private static final Logger LOG = LoggerFactory.getLogger(DatabaseUtil.class);
+ public static final int MAX_WAIT_TIME_FOR_CONN_IN_MS = 200;
+ public static final String MYSQL_JDBC_DRIVER = "com.mysql.jdbc.Driver";
+ private static final Logger LOG = LoggerFactory.getLogger(DatabaseUtil.class);
- public static BasicDataSource createMysqlDataSource(String host, int port,
- String user, String passwd, String poolSize) {
- // autoReconnect by default is false
- // TODO: queryTimeoutKillsConnection to true, "?queryTimeoutKillsConnection=true"
- String url = String.format(
- "jdbc:mysql://%s:%d/deploy?connectTimeout=5000&socketTimeout=3000&characterEncoding=UTF-8"
- + "&connectionCollation=utf8mb4_general_ci",
- host, port);
- LOG.info("mtls is disabled --- host:{}, port:{}, user:{}", host, port, user);
- return createDataSource(MYSQL_JDBC_DRIVER, url, user, passwd, poolSize,
- MAX_WAIT_TIME_FOR_CONN_IN_MS);
- }
+ public static BasicDataSource createMysqlDataSource(
+ String host, int port, String user, String passwd, String poolSize) {
+ // autoReconnect by default is false
+ // TODO: queryTimeoutKillsConnection to true, "?queryTimeoutKillsConnection=true"
+ String url =
+ String.format(
+ "jdbc:mysql://%s:%d/deploy?connectTimeout=5000&socketTimeout=3000&characterEncoding=UTF-8"
+ + "&connectionCollation=utf8mb4_general_ci",
+ host, port);
+ LOG.info("mtls is disabled --- host:{}, port:{}, user:{}", host, port, user);
+ return createDataSource(
+ MYSQL_JDBC_DRIVER, url, user, passwd, poolSize, MAX_WAIT_TIME_FOR_CONN_IN_MS);
+ }
- public static BasicDataSource createMysqlDataSource(String host, int port,
- String user, String passwd, String poolSize,
- Map connectionProperties) {
- // autoReconnect by default is false
- // TODO: queryTimeoutKillsConnection to true, "?queryTimeoutKillsConnection=true"
- String url = String.format(
- "jdbc:mysql://%s:%d/deploy?connectTimeout=5000&socketTimeout=3000&characterEncoding=UTF-8"
- + "&connectionCollation=utf8mb4_general_ci",
- host, port);
- LOG.info("mtls is enabled --- host:{}, port:{}, user:{}", host, port, user);
- return createDataSource(MYSQL_JDBC_DRIVER, url, user, passwd, poolSize,
- MAX_WAIT_TIME_FOR_CONN_IN_MS, connectionProperties);
- }
+ public static BasicDataSource createMysqlDataSource(
+ String host,
+ int port,
+ String user,
+ String passwd,
+ String poolSize,
+ Map connectionProperties) {
+ // autoReconnect by default is false
+ // TODO: queryTimeoutKillsConnection to true, "?queryTimeoutKillsConnection=true"
+ String url =
+ String.format(
+ "jdbc:mysql://%s:%d/deploy?connectTimeout=5000&socketTimeout=3000&characterEncoding=UTF-8"
+ + "&connectionCollation=utf8mb4_general_ci",
+ host, port);
+ LOG.info("mtls is enabled --- host:{}, port:{}, user:{}", host, port, user);
+ return createDataSource(
+ MYSQL_JDBC_DRIVER,
+ url,
+ user,
+ passwd,
+ poolSize,
+ MAX_WAIT_TIME_FOR_CONN_IN_MS,
+ connectionProperties);
+ }
- // Embedded mysql source, for unit test only
- public static BasicDataSource createMXJDataSource(String dbName, String baseDir, int port) {
- String
- url =
- String.format(
- "jdbc:mysql:mxj://localhost:%d/%s?server"
- + ".basedir=%s&createDatabaseIfNotExist=true&server.initialize-user=true",
- port, dbName, baseDir);
- return createDataSource(MYSQL_JDBC_DRIVER, url, "tester", "passwd", "0:8:8:0",
- MAX_WAIT_TIME_FOR_CONN_IN_MS);
- }
+ // Embedded mysql source, for unit test only
+ public static BasicDataSource createMXJDataSource(String dbName, String baseDir, int port) {
+ String url =
+ String.format(
+ "jdbc:mysql:mxj://localhost:%d/%s?server"
+ + ".basedir=%s&createDatabaseIfNotExist=true&server.initialize-user=true",
+ port, dbName, baseDir);
+ return createDataSource(
+ MYSQL_JDBC_DRIVER,
+ url,
+ "tester",
+ "passwd",
+ "0:8:8:0",
+ MAX_WAIT_TIME_FOR_CONN_IN_MS);
+ }
- /**
- * Create a MySQL datasource.
- *
- * @param url the url of the DB.
- * @param user the user name to connect to MySQL as.
- * @param passwd the password for the corresponding MySQL user.
- * @param poolSize the connection pool size string, in the format of
- * initialSize:maxActive:maxIdle:minIdle.
- * @param maxWaitInMillis the max wait time in milliseconds to get a connection from the pool.
- * @return a BasicDataSource for the target MySQL instance.
- */
- public static BasicDataSource createDataSource(String driverClassName, String url,
- String user, String passwd, String poolSize,
- int maxWaitInMillis) {
- return createDataSource(driverClassName, url, user, passwd, poolSize, maxWaitInMillis, null);
- }
+ public static BasicDataSource createLocalDataSource(String url) {
+ return createDataSource(
+ MYSQL_JDBC_DRIVER, url, "root", "", "0:8:8:0", MAX_WAIT_TIME_FOR_CONN_IN_MS, null);
+ }
+
+ /**
+ * Create a MySQL datasource.
+ *
+ * @param url the url of the DB.
+ * @param user the user name to connect to MySQL as.
+ * @param passwd the password for the corresponding MySQL user.
+ * @param poolSize the connection pool size string, in the format of
+ * initialSize:maxActive:maxIdle:minIdle.
+ * @param maxWaitInMillis the max wait time in milliseconds to get a connection from the pool.
+ * @return a BasicDataSource for the target MySQL instance.
+ */
+ public static BasicDataSource createDataSource(
+ String driverClassName,
+ String url,
+ String user,
+ String passwd,
+ String poolSize,
+ int maxWaitInMillis) {
+ return createDataSource(
+ driverClassName, url, user, passwd, poolSize, maxWaitInMillis, null);
+ }
- public static BasicDataSource createDataSource(String driverClassName, String url,
- String user, String passwd, String poolSize,
- int maxWaitInMillis,
- Map connectionProperties) {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setDriverClassName(driverClassName);
- dataSource.setUrl(url);
- dataSource.setUsername(user);
- dataSource.setPassword(passwd);
- dataSource.setDefaultAutoCommit(true);
- dataSource.setDefaultReadOnly(false);
+ public static BasicDataSource createDataSource(
+ String driverClassName,
+ String url,
+ String user,
+ String passwd,
+ String poolSize,
+ int maxWaitInMillis,
+ Map connectionProperties) {
+ BasicDataSource dataSource = new BasicDataSource();
+ dataSource.setDriverClassName(driverClassName);
+ dataSource.setUrl(url);
+ dataSource.setUsername(user);
+ dataSource.setPassword(passwd);
+ dataSource.setDefaultAutoCommit(true);
+ dataSource.setDefaultReadOnly(false);
- // poolSize parsing, the poolsize string passed in the following format
- // initialSize:maxActive:maxIdle:minIdle
- String[] sizeStrs = poolSize.split(":");
- dataSource.setInitialSize(Integer.parseInt(sizeStrs[0]));
- dataSource.setMaxActive(Integer.parseInt(sizeStrs[1]));
- dataSource.setMaxIdle(Integer.parseInt(sizeStrs[2]));
- dataSource.setMinIdle(Integer.parseInt(sizeStrs[3]));
+ // poolSize parsing, the poolsize string passed in the following format
+ // initialSize:maxActive:maxIdle:minIdle
+ String[] sizeStrs = poolSize.split(":");
+ dataSource.setInitialSize(Integer.parseInt(sizeStrs[0]));
+ dataSource.setMaxActive(Integer.parseInt(sizeStrs[1]));
+ dataSource.setMaxIdle(Integer.parseInt(sizeStrs[2]));
+ dataSource.setMinIdle(Integer.parseInt(sizeStrs[3]));
- dataSource.setValidationQuery("SELECT 1");
- dataSource.setTestOnBorrow(true);
- dataSource.setTestOnReturn(false);
- dataSource.setTestWhileIdle(true);
- dataSource.setMinEvictableIdleTimeMillis(5 * 60 * 1000);
- dataSource.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000);
- // dataSource.setNumTestsPerEvictionRun(3);
- // max wait in milliseconds for a connection.
- dataSource.setMaxWait(maxWaitInMillis);
+ dataSource.setValidationQuery("SELECT 1");
+ dataSource.setTestOnBorrow(true);
+ dataSource.setTestOnReturn(false);
+ dataSource.setTestWhileIdle(true);
+ dataSource.setMinEvictableIdleTimeMillis(5 * 60 * 1000);
+ dataSource.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000);
+ // dataSource.setNumTestsPerEvictionRun(3);
+ // max wait in milliseconds for a connection.
+ dataSource.setMaxWait(maxWaitInMillis);
- if (connectionProperties != null) {
- for (Map.Entry entry : connectionProperties.entrySet()) {
- LOG.info(
- String.format("Add connection properties %s=%s", entry.getKey(), entry.getValue()));
- dataSource.addConnectionProperty(
- entry.getKey(),
- entry.getValue()
- );
- }
- }
+ if (connectionProperties != null) {
+ for (Map.Entry entry : connectionProperties.entrySet()) {
+ LOG.info(
+ String.format(
+ "Add connection properties %s=%s",
+ entry.getKey(), entry.getValue()));
+ dataSource.addConnectionProperty(entry.getKey(), entry.getValue());
+ }
+ }
- // force connection pool initialization.
- Connection conn = null;
- try {
- // Here not getting the connection from ThreadLocal no need to worry about that.
- conn = dataSource.getConnection();
- LOG.info("mysql conn: {}", conn);
- } catch (SQLException e) {
- LOG.error(
- String.format("Failed to get a db connection when creating DataSource, url = %s", url),
- e);
- } finally {
- DbUtils.closeQuietly(conn);
+ // force connection pool initialization.
+ Connection conn = null;
+ try {
+ // Here not getting the connection from ThreadLocal no need to worry about that.
+ conn = dataSource.getConnection();
+ LOG.info("mysql conn: {}", conn);
+ } catch (SQLException e) {
+ LOG.error(
+ String.format(
+ "Failed to get a db connection when creating DataSource, url = %s",
+ url),
+ e);
+ } finally {
+ DbUtils.closeQuietly(conn);
+ }
+ LOG.info("mysql dataSource: {}", dataSource);
+ return dataSource;
}
- LOG.info("mysql dataSource: {}", dataSource);
- return dataSource;
- }
- public static void transactionalUpdate(BasicDataSource dataSource,
- List updateStatements) throws Exception {
- QueryRunner queryRunner = new QueryRunner();
- Connection connection = dataSource.getConnection();
- boolean autoStatus = connection.getAutoCommit();
- connection.setAutoCommit(false);
- try {
- for (UpdateStatement updateStatement : updateStatements) {
- queryRunner
- .update(connection, updateStatement.getStatement(), updateStatement.getValueArray());
- }
- connection.commit();
- } catch (SQLException e) {
- connection.rollback();
- throw e;
- } finally {
- connection.setAutoCommit(autoStatus);
- DbUtils.closeQuietly(connection);
+ public static void transactionalUpdate(
+ BasicDataSource dataSource, List updateStatements) throws Exception {
+ QueryRunner queryRunner = new QueryRunner();
+ Connection connection = dataSource.getConnection();
+ boolean autoStatus = connection.getAutoCommit();
+ connection.setAutoCommit(false);
+ try {
+ for (UpdateStatement updateStatement : updateStatements) {
+ queryRunner.update(
+ connection,
+ updateStatement.getStatement(),
+ updateStatement.getValueArray());
+ }
+ connection.commit();
+ } catch (SQLException e) {
+ connection.rollback();
+ throw e;
+ } finally {
+ connection.setAutoCommit(autoStatus);
+ DbUtils.closeQuietly(connection);
+ }
}
- }
}
diff --git a/deploy-service/common/src/test/java/com/pinterest/deployservice/db/DBDAOTest.java b/deploy-service/common/src/test/java/com/pinterest/deployservice/db/DBDAOTest.java
index c8e6de8ebf..d4241deae4 100644
--- a/deploy-service/common/src/test/java/com/pinterest/deployservice/db/DBDAOTest.java
+++ b/deploy-service/common/src/test/java/com/pinterest/deployservice/db/DBDAOTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2016 Pinterest, Inc.
+ * Copyright (c) 2016-2024 Pinterest, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,11 @@
*/
package com.pinterest.deployservice.db;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.pinterest.deployservice.bean.AcceptanceStatus;
import com.pinterest.deployservice.bean.AcceptanceType;
@@ -75,20 +75,6 @@
import com.pinterest.deployservice.dao.TokenRolesDAO;
import com.pinterest.deployservice.dao.UserRolesDAO;
import com.pinterest.deployservice.dao.UtilDAO;
-
-
-import com.ibatis.common.jdbc.ScriptRunner;
-import com.mysql.management.driverlaunched.ServerLauncherSocketFactory;
-import org.apache.commons.dbcp.BasicDataSource;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.joda.time.Interval;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.InputStreamReader;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
@@ -97,14 +83,15 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.joda.time.Interval;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.MySQLContainer;
public class DBDAOTest {
-
- private final static String DEFAULT_BASE_DIR = "/tmp/deploy-unit-test";
- private final static String DEFAULT_DB_NAME = "deploy";
- private final static int DEFAULT_PORT = 3303;
-
private static BuildDAO buildDAO;
private static AgentDAO agentDAO;
private static AgentErrorDAO agentErrorDAO;
@@ -123,22 +110,14 @@ public class DBDAOTest {
private static ScheduleDAO scheduleDAO;
private static UtilDAO utilDAO;
- @BeforeClass
+ public static final MySQLContainer mysql = DBUtils.getContainer();
+
+ @BeforeAll
public static void setUpClass() throws Exception {
- try {
- // making sure we do not have anything running
- ServerLauncherSocketFactory.shutdown(new File(DEFAULT_BASE_DIR), null);
- } catch (Exception e) {
- // ignore
- }
- BasicDataSource DATASOURCE = DatabaseUtil.createMXJDataSource(DEFAULT_DB_NAME,
- DEFAULT_BASE_DIR, DEFAULT_PORT);
- Connection conn = DATASOURCE.getConnection();
- ScriptRunner runner = new ScriptRunner(conn, false, true);
- runner.runScript(new BufferedReader(new InputStreamReader(
- DBDAOTest.class.getResourceAsStream("/sql/cleanup.sql"))));
- runner.runScript(new BufferedReader(new InputStreamReader(
- DBDAOTest.class.getResourceAsStream("/sql/deploy.sql"))));
+ mysql.start();
+ BasicDataSource DATASOURCE = DatabaseUtil.createLocalDataSource(mysql.getJdbcUrl());
+ DBUtils.runMigrations(DATASOURCE);
+
buildDAO = new DBBuildDAOImpl(DATASOURCE);
agentDAO = new DBAgentDAOImpl(DATASOURCE);
agentErrorDAO = new DBAgentErrorDAOImpl(DATASOURCE);
@@ -158,23 +137,19 @@ public static void setUpClass() throws Exception {
utilDAO = new DBUtilDAOImpl(DATASOURCE);
}
- @AfterClass
+ @AfterAll
public static void tearDownClass() throws Exception {
- ServerLauncherSocketFactory.shutdown(new File(DEFAULT_BASE_DIR), null);
+ mysql.stop();
}
@Test
public void testDeploymentQueries() throws Exception {
long now = System.currentTimeMillis();
- BuildBean buildBean1 =
- genDefaultBuildInfoBean("bbb-1", "s-1", "ccc-1", "r-1", now);
- BuildBean buildBean2 =
- genDefaultBuildInfoBean("bbb-2", "s-1", "ccc-1", "r-1", now + 1000);
- BuildBean buildBean3 =
- genDefaultBuildInfoBean("bbb-3", "s-1", "ccc-1", "r-1", now + 2000);
- BuildBean buildBean4 =
- genDefaultBuildInfoBean("bbb-4", "s-2", "ccc-2", "r-1", now + 3000);
+ BuildBean buildBean1 = genDefaultBuildInfoBean("bbb-1", "s-1", "ccc-1", "r-1", now);
+ BuildBean buildBean2 = genDefaultBuildInfoBean("bbb-2", "s-1", "ccc-1", "r-1", now + 1000);
+ BuildBean buildBean3 = genDefaultBuildInfoBean("bbb-3", "s-1", "ccc-1", "r-1", now + 2000);
+ BuildBean buildBean4 = genDefaultBuildInfoBean("bbb-4", "s-2", "ccc-2", "r-1", now + 3000);
buildDAO.insert(buildBean1);
buildDAO.insert(buildBean2);
@@ -182,21 +157,20 @@ public void testDeploymentQueries() throws Exception {
buildDAO.insert(buildBean4);
DeployBean deployBean1 =
- genDefaultDeployBean("d-1", "env-1", "bbb-1", now, DeployState.SUCCEEDED);
+ genDefaultDeployBean("d-1", "env-1", "bbb-1", now, DeployState.SUCCEEDED);
DeployBean deployBean2 =
- genDefaultDeployBean("d-2", "env-1", "bbb-1", now + 1000, DeployState.SUCCEEDED);
+ genDefaultDeployBean("d-2", "env-1", "bbb-1", now + 1000, DeployState.SUCCEEDED);
DeployBean deployBean3 =
- genDefaultDeployBean("d-3", "env-1", "bbb-1", now + 2000, DeployState.RUNNING);
+ genDefaultDeployBean("d-3", "env-1", "bbb-1", now + 2000, DeployState.RUNNING);
DeployBean deployBean4 =
- genDefaultDeployBean("d-4", "env-2", "bbb-2", now, DeployState.FAILING);
+ genDefaultDeployBean("d-4", "env-2", "bbb-2", now, DeployState.FAILING);
// just so we have the build
- BuildBean buildBeanx =
- genDefaultBuildInfoBean("d-x", "s-1", "ccc-x", "r-1", now);
+ BuildBean buildBeanx = genDefaultBuildInfoBean("d-x", "s-1", "ccc-x", "r-1", now);
buildDAO.insert(buildBeanx);
DeployBean deployBean5 =
- genDefaultDeployBean("d-5", "env-3", "bcc-x", now, DeployState.SUCCEEDING);
+ genDefaultDeployBean("d-5", "env-3", "bcc-x", now, DeployState.SUCCEEDING);
DeployBean deployBean6 =
- genDefaultDeployBean("d-6", "env-2", "bbb-4", now, DeployState.SUCCEEDED);
+ genDefaultDeployBean("d-6", "env-2", "bbb-4", now, DeployState.SUCCEEDED);
deployDAO.insert(deployBean1);
deployDAO.insert(deployBean2);
@@ -303,9 +277,8 @@ public void testDeploymentQueries() throws Exception {
deployBean5.setAcc_status(AcceptanceStatus.ACCEPTED);
deployDAO.update("d-5", deployBean5);
- List
- beans =
- deployDAO.getAcceptedDeploys("env-3", new Interval(0, Long.MAX_VALUE), 100);
+ List beans =
+ deployDAO.getAcceptedDeploys("env-3", new Interval(0, Long.MAX_VALUE), 100);
assertEquals(beans.size(), 1);
assertEquals(beans.get(0).getDeploy_id(), "d-5");
@@ -328,14 +301,10 @@ public void testDeploymentQueries() throws Exception {
@Test
public void testBuildDAO() throws Exception {
long now = System.currentTimeMillis();
- BuildBean buildBean1 =
- genDefaultBuildInfoBean("b-1", "sss-1", "c-1", "r-1", now);
- BuildBean buildBean2 =
- genDefaultBuildInfoBean("b-2", "sss-1", "c-1", "r-1", now + 1000);
- BuildBean buildBean22 =
- genDefaultBuildInfoBean("b-22", "sss-2", "c-1", "r-1", now + 1000);
- BuildBean buildBean3 =
- genDefaultBuildInfoBean("b-3", "sss-1", "c-1", "r-1", now + 2000);
+ BuildBean buildBean1 = genDefaultBuildInfoBean("b-1", "sss-1", "c-1", "r-1", now);
+ BuildBean buildBean2 = genDefaultBuildInfoBean("b-2", "sss-1", "c-1", "r-1", now + 1000);
+ BuildBean buildBean22 = genDefaultBuildInfoBean("b-22", "sss-2", "c-1", "r-1", now + 1000);
+ BuildBean buildBean3 = genDefaultBuildInfoBean("b-3", "sss-1", "c-1", "r-1", now + 2000);
buildDAO.insert(buildBean1);
buildDAO.insert(buildBean2);
@@ -348,9 +317,8 @@ public void testBuildDAO() throws Exception {
assertEquals(buildDAO.getByCommit7("c-1", "sss-2", 1, 10).size(), 1);
assertEquals(buildDAO.getBuildNames("sss-", 1, 100).size(), 2);
- List
- buildBeans =
- buildDAO.getAcceptedBuilds("sss-1", null, new Interval(now, Long.MAX_VALUE), 100);
+ List buildBeans =
+ buildDAO.getAcceptedBuilds("sss-1", null, new Interval(now, Long.MAX_VALUE), 100);
assertEquals(buildBeans.size(), 2);
BuildBean bean1 = buildBeans.get(0);
assertEquals(bean1.getBuild_id(), "b-3");
@@ -369,9 +337,8 @@ public void testBuildDAO() throws Exception {
List buildBeans4 = buildDAO.getByName("sss-1", "branch-1", 1, 2);
assertEquals(buildBeans4.size(), 2);
- List
- allBuildBeans =
- buildDAO.getBuildsFromIds(Arrays.asList("b-1", "b-2", "b-22"));
+ List allBuildBeans =
+ buildDAO.getBuildsFromIds(Arrays.asList("b-1", "b-2", "b-22"));
assertEquals(3, allBuildBeans.size());
allBuildBeans = buildDAO.getBuildsFromIds(Arrays.asList("b-1", "b-2", "Not There"));
@@ -392,14 +359,12 @@ public void testBuildDAO() throws Exception {
@Test
public void testAgentUpdate() throws Exception {
- AgentBean
- agentBean1 =
- genDefaultAgentBean("h1", "id-1", "e-1", "d-1", DeployStage.PRE_DOWNLOAD);
+ AgentBean agentBean1 =
+ genDefaultAgentBean("h1", "id-1", "e-1", "d-1", DeployStage.PRE_DOWNLOAD);
agentDAO.insertOrUpdate(agentBean1);
- AgentBean
- updateBean1 =
- genDefaultAgentBean("h1", "id-1", "e-1", "d-1", DeployStage.POST_DOWNLOAD);
+ AgentBean updateBean1 =
+ genDefaultAgentBean("h1", "id-1", "e-1", "d-1", DeployStage.POST_DOWNLOAD);
updateBean1.setFirst_deploy_time(10L);
agentDAO.insertOrUpdate(updateBean1);
@@ -417,15 +382,12 @@ public void testAgentUpdate() throws Exception {
@Test
public void testAgentUpdateMultiple() throws Exception {
- AgentBean
- agentBean1 =
- genDefaultAgentBean("h5", "id-5", "e-2", "d-1", DeployStage.PRE_DOWNLOAD);
- AgentBean
- agentBean2 =
- genDefaultAgentBean("h6", "id-6", "e-2", "d-1", DeployStage.PRE_DOWNLOAD);
- AgentBean
- agentBean3 =
- genDefaultAgentBean("h7", "id-7", "e-2", "d-1", DeployStage.PRE_DOWNLOAD);
+ AgentBean agentBean1 =
+ genDefaultAgentBean("h5", "id-5", "e-2", "d-1", DeployStage.PRE_DOWNLOAD);
+ AgentBean agentBean2 =
+ genDefaultAgentBean("h6", "id-6", "e-2", "d-1", DeployStage.PRE_DOWNLOAD);
+ AgentBean agentBean3 =
+ genDefaultAgentBean("h7", "id-7", "e-2", "d-1", DeployStage.PRE_DOWNLOAD);
agentDAO.insertOrUpdate(agentBean1);
agentDAO.insertOrUpdate(agentBean2);
@@ -449,15 +411,13 @@ public void testAgentUpdateMultiple() throws Exception {
@Test
public void testFirstDeployCount() throws Exception {
- AgentBean
- agentBean1 =
- genDefaultAgentBean("h12", "id-123", "e-12", "d-12", DeployStage.POST_RESTART);
+ AgentBean agentBean1 =
+ genDefaultAgentBean("h12", "id-123", "e-12", "d-12", DeployStage.POST_RESTART);
agentBean1.setFirst_deploy(true);
agentBean1.setStatus(AgentStatus.ABORTED_BY_SERVICE);
- AgentBean
- agentBean2 =
- genDefaultAgentBean("h22", "id-124", "e-12", "d-12", DeployStage.POST_RESTART);
+ AgentBean agentBean2 =
+ genDefaultAgentBean("h22", "id-124", "e-12", "d-12", DeployStage.POST_RESTART);
agentBean2.setFirst_deploy(true);
agentDAO.insertOrUpdate(agentBean1);
@@ -471,14 +431,14 @@ public void testFirstDeployCount() throws Exception {
@Test
public void testAgentQueries() throws Exception {
- AgentBean agentBean1 = genDefaultAgentBean(
- "h-1", "id-1", "e-1", "d-1", DeployStage.POST_RESTART);
- AgentBean agentBean11 = genDefaultAgentBean(
- "h-1", "id-1", "e-2", "d-1", DeployStage.SERVING_BUILD);
- AgentBean agentBean2 = genDefaultAgentBean(
- "h-2", "id-3", "e-1", "d-2", DeployStage.RESTARTING);
- AgentBean agentBean3 = genDefaultAgentBean(
- "h-3", "id-4", "e-1", "d-1", DeployStage.SERVING_BUILD);
+ AgentBean agentBean1 =
+ genDefaultAgentBean("h-1", "id-1", "e-1", "d-1", DeployStage.POST_RESTART);
+ AgentBean agentBean11 =
+ genDefaultAgentBean("h-1", "id-1", "e-2", "d-1", DeployStage.SERVING_BUILD);
+ AgentBean agentBean2 =
+ genDefaultAgentBean("h-2", "id-3", "e-1", "d-2", DeployStage.RESTARTING);
+ AgentBean agentBean3 =
+ genDefaultAgentBean("h-3", "id-4", "e-1", "d-1", DeployStage.SERVING_BUILD);
agentBean3.setFirst_deploy_time(System.currentTimeMillis());
agentDAO.insertOrUpdate(agentBean1);
@@ -602,18 +562,17 @@ public void testEnvDAO() throws Exception {
// Added 2 hosts to group1 and group2
Set groups = new HashSet<>(Arrays.asList("group1", "group2"));
- hostDAO
- .insertOrUpdate("host-1", "1.1.1.1", "id-123434", HostState.ACTIVE.toString(), groups, "test");
- hostDAO
- .insertOrUpdate("host-2", "1.1.1.2", "id-123435", HostState.TERMINATING.toString(),
- groups, "test");
- hostDAO
- .insertOrUpdate("host-2", "1.1.1.2", "id-123435", HostState.ACTIVE.toString(), groups, "test");
+ hostDAO.insertOrUpdate(
+ "host-1", "1.1.1.1", "id-123434", HostState.ACTIVE.toString(), groups, "test");
+ hostDAO.insertOrUpdate(
+ "host-2", "1.1.1.2", "id-123435", HostState.TERMINATING.toString(), groups, "test");
+ hostDAO.insertOrUpdate(
+ "host-2", "1.1.1.2", "id-123435", HostState.ACTIVE.toString(), groups, "test");
List hostBeans = hostDAO.getHostsByHostId("id-123435");
assertEquals(hostBeans.get(0).getState(), HostState.TERMINATING);
// Total capacity for env-1 should be 2, host-1(group1), host-2(group2) and one missing
- // host1
+ // host1
assertEquals(environDAO.getOverrideHosts("env-1", "s-1", "prod").size(), 0);
assertEquals(environDAO.countTotalCapacity("env-1", "s-1", "prod"), 2);
assertEquals(environDAO.getMissingHosts("env-1").size(), 1);
@@ -661,10 +620,13 @@ public void testEnvDAO() throws Exception {
@Test
public void testHostDAO() throws Exception {
Set groups = new HashSet<>(Arrays.asList("group1", "group2"));
- hostDAO.insertOrUpdate("host-1", "1.1.1.1", "id-1", HostState.ACTIVE.toString(), groups, "test");
+ hostDAO.insertOrUpdate(
+ "host-1", "1.1.1.1", "id-1", HostState.ACTIVE.toString(), groups, "test");
groups = new HashSet<>(Arrays.asList("group1"));
- hostDAO.insertOrUpdate("host-2", "1.1.1.2", "id-2", HostState.ACTIVE.toString(), groups, "test");
- hostDAO.insertOrUpdate("host-3", "1.1.1.3", "id-3", HostState.ACTIVE.toString(), groups, "test");
+ hostDAO.insertOrUpdate(
+ "host-2", "1.1.1.2", "id-2", HostState.ACTIVE.toString(), groups, "test");
+ hostDAO.insertOrUpdate(
+ "host-3", "1.1.1.3", "id-3", HostState.ACTIVE.toString(), groups, "test");
/*
host-1 : group1, group2
host-2 : group1
@@ -692,9 +654,10 @@ public void testHostDAO() throws Exception {
hostDAO.deleteById("id-2");
// test host transactional delete
- hostDAO.insertOrUpdate("host-1", "1.1.1.1", "id-1", HostState.ACTIVE.toString(), groups, "test");
- AgentBean agentBean = genDefaultAgentBean(
- "host-1", "id-1", "e-1", "d-1", DeployStage.SERVING_BUILD);
+ hostDAO.insertOrUpdate(
+ "host-1", "1.1.1.1", "id-1", HostState.ACTIVE.toString(), groups, "test");
+ AgentBean agentBean =
+ genDefaultAgentBean("host-1", "id-1", "e-1", "d-1", DeployStage.SERVING_BUILD);
agentDAO.insertOrUpdate(agentBean);
AgentErrorBean agentErrorBean = new AgentErrorBean();
agentErrorBean.setHost_name("host-1");
@@ -716,8 +679,8 @@ public void testHostDAO() throws Exception {
assertEquals(environDAO.getMissingHosts("e-3").size(), 1);
Set groups2 = new HashSet<>(Arrays.asList("new_group"));
- hostDAO
- .insertOrUpdate("host-3", "3.3.3.3", "id-3", HostState.TERMINATING.toString(), groups2, "test");
+ hostDAO.insertOrUpdate(
+ "host-3", "3.3.3.3", "id-3", HostState.TERMINATING.toString(), groups2, "test");
assertEquals(environDAO.getMissingHosts("e-3").size(), 0);
Collection hostBean3 = hostDAO.getByEnvIdAndHostName("e-3", "host-3");
@@ -744,9 +707,17 @@ public void testHostDAO() throws Exception {
assertEquals(hostBeans3.get(0).getHost_name(), "i-9");
HashSet groups9 = new HashSet<>(Arrays.asList("test_dup"));
- hostDAO.insertOrUpdate("h-8", "9.9.9.9", "i-8", HostState.TERMINATING.toString(), groups9, "test");
- hostDAO.insertOrUpdate("h-9", "9.9.9.9", "i-9", HostState.PENDING_TERMINATE.toString(), groups9, "test");
- hostDAO.insertOrUpdate("h-10", "9.9.9.9", "i-10", HostState.PENDING_TERMINATE_NO_REPLACE.toString(), groups9, "test");
+ hostDAO.insertOrUpdate(
+ "h-8", "9.9.9.9", "i-8", HostState.TERMINATING.toString(), groups9, "test");
+ hostDAO.insertOrUpdate(
+ "h-9", "9.9.9.9", "i-9", HostState.PENDING_TERMINATE.toString(), groups9, "test");
+ hostDAO.insertOrUpdate(
+ "h-10",
+ "9.9.9.9",
+ "i-10",
+ HostState.PENDING_TERMINATE_NO_REPLACE.toString(),
+ groups9,
+ "test");
List hostBeans4 = hostDAO.getHosts("h-9");
assertEquals(hostBeans4.size(), 1);
@@ -756,10 +727,14 @@ public void testHostDAO() throws Exception {
List hostBeans5 = hostDAO.getTerminatingHosts();
assertEquals(4, hostBeans5.size());
- // If state is PENDING_TERMINATE, PENDING_TERMINATE_NO_REPLACE or TERMINATING, cannot overwrite its state
- hostDAO.insertOrUpdate("h-8", "9.9.9.8", "i-8", HostState.PROVISIONED.toString(), groups9, "test");
- hostDAO.insertOrUpdate("h-9", "9.9.9.8", "i-9", HostState.PROVISIONED.toString(), groups9, "test");
- hostDAO.insertOrUpdate("h-10", "9.9.9.8", "i-10", HostState.PROVISIONED.toString(), groups9, "test");
+ // If state is PENDING_TERMINATE, PENDING_TERMINATE_NO_REPLACE or TERMINATING, cannot
+ // overwrite its state
+ hostDAO.insertOrUpdate(
+ "h-8", "9.9.9.8", "i-8", HostState.PROVISIONED.toString(), groups9, "test");
+ hostDAO.insertOrUpdate(
+ "h-9", "9.9.9.8", "i-9", HostState.PROVISIONED.toString(), groups9, "test");
+ hostDAO.insertOrUpdate(
+ "h-10", "9.9.9.8", "i-10", HostState.PROVISIONED.toString(), groups9, "test");
hostBeans5 = hostDAO.getTerminatingHosts();
assertEquals(4, hostBeans5.size());
@@ -787,24 +762,28 @@ public void testHostDAO() throws Exception {
hostBean7.setState(HostState.ACTIVE);
hostDAO.insert(hostBean7);
- AgentBean
- agentBean1 =
- genDefaultAgentBean("i-11", "i-11", "e-1", "d-1", DeployStage.RESTARTING);
+ AgentBean agentBean1 =
+ genDefaultAgentBean("i-11", "i-11", "e-1", "d-1", DeployStage.RESTARTING);
agentBean1.setStatus(AgentStatus.AGENT_FAILED);
agentDAO.insertOrUpdate(agentBean1);
- HostState[] nonRetirableStates = { HostState.TERMINATING, HostState.PENDING_TERMINATE_NO_REPLACE,
- HostState.PENDING_TERMINATE };
+ HostState[] nonRetirableStates = {
+ HostState.TERMINATING,
+ HostState.PENDING_TERMINATE_NO_REPLACE,
+ HostState.PENDING_TERMINATE
+ };
- for (HostState state: nonRetirableStates) {
+ for (HostState state : nonRetirableStates) {
hostBean7.setCan_retire(1);
hostBean7.setState(state);
hostDAO.updateHostById("i-13", hostBean7);
- Collection retiredHostBeanIds = hostDAO.getToBeRetiredHostIdsByGroup("retire-group");
+ Collection retiredHostBeanIds =
+ hostDAO.getToBeRetiredHostIdsByGroup("retire-group");
assertEquals(2, retiredHostBeanIds.size());
- Collection retiredAndFailedHostIds = hostDAO.getToBeRetiredAndFailedHostIdsByGroup("retire-group");
+ Collection retiredAndFailedHostIds =
+ hostDAO.getToBeRetiredAndFailedHostIdsByGroup("retire-group");
assertEquals(1, retiredAndFailedHostIds.size());
Collection failedHostIds = hostDAO.getFailedHostIdsByGroup("retire-group");
@@ -926,9 +905,8 @@ public void testUserRolesDAO() throws Exception {
bean.setResource_type(Resource.Type.ENV);
bean.setRole(Role.ADMIN);
userRolesDAO.insert(bean);
- UserRolesBean
- bean2 =
- userRolesDAO.getByNameAndResource("test", "envTest", Resource.Type.ENV);
+ UserRolesBean bean2 =
+ userRolesDAO.getByNameAndResource("test", "envTest", Resource.Type.ENV);
assertEquals(bean2.getRole(), Role.ADMIN);
}
@@ -940,9 +918,8 @@ public void testGroupRolesDAO() throws Exception {
bean.setResource_type(Resource.Type.ENV);
bean.setRole(Role.ADMIN);
groupRolesDAO.insert(bean);
- GroupRolesBean
- bean2 =
- groupRolesDAO.getByNameAndResource("group", "123", Resource.Type.ENV);
+ GroupRolesBean bean2 =
+ groupRolesDAO.getByNameAndResource("group", "123", Resource.Type.ENV);
assertEquals(bean2.getRole(), Role.ADMIN);
}
@@ -956,13 +933,11 @@ public void testTokenRolesDAO() throws Exception {
bean.setRole(Role.ADMIN);
bean.setExpire_date(System.currentTimeMillis());
tokenRolesDAO.insert(bean);
- TokenRolesBean
- bean2 =
- tokenRolesDAO.getByNameAndResource("test", "envTest", Resource.Type.ENV);
+ TokenRolesBean bean2 =
+ tokenRolesDAO.getByNameAndResource("test", "envTest", Resource.Type.ENV);
assertEquals(bean2.getRole(), Role.ADMIN);
}
-
@Test
public void testConfigHistoryDAO() throws Exception {
ConfigHistoryBean bean = new ConfigHistoryBean();
@@ -991,8 +966,13 @@ public void testConfigHistoryDAO() throws Exception {
@Test
public void testTagDAO() throws Exception {
- TagBean tag = genTagBean(TagValue.BAD_BUILD, "TestEnv", "BUILD",
- genDefaultBuildInfoBean("b-3", "sss-1", "c-1", "r-1", System.currentTimeMillis()));
+ TagBean tag =
+ genTagBean(
+ TagValue.BAD_BUILD,
+ "TestEnv",
+ "BUILD",
+ genDefaultBuildInfoBean(
+ "b-3", "sss-1", "c-1", "r-1", System.currentTimeMillis()));
tagDAO.insert(tag);
TagBean tag2 = tagDAO.getById(tag.getId());
assertNotNull(tag2);
@@ -1013,20 +993,19 @@ public void testTagDAO() throws Exception {
targetList = tagDAO.getByTargetIdAndType(tag.getTarget_id(), TagTargetType.BUILD);
assertEquals(0, targetList.size());
- tagDAO
- .insert(genTagBean(TagValue.BAD_BUILD, "env1", "BUILD", new HashMap()));
- tagDAO
- .insert(genTagBean(TagValue.BAD_BUILD, "env1", "BUILD", new HashMap()));
- tagDAO
- .insert(genTagBean(TagValue.BAD_BUILD, "env1", "BUILD", new HashMap()));
- tagDAO
- .insert(genTagBean(TagValue.BAD_BUILD, "env1", "BUILD", new HashMap()));
+ tagDAO.insert(
+ genTagBean(TagValue.BAD_BUILD, "env1", "BUILD", new HashMap()));
+ tagDAO.insert(
+ genTagBean(TagValue.BAD_BUILD, "env1", "BUILD", new HashMap()));
+ tagDAO.insert(
+ genTagBean(TagValue.BAD_BUILD, "env1", "BUILD", new HashMap()));
+ tagDAO.insert(
+ genTagBean(TagValue.BAD_BUILD, "env1", "BUILD", new HashMap()));
assertEquals(4, tagDAO.getByValue(TagValue.BAD_BUILD).size());
assertEquals(0, tagDAO.getByValue(TagValue.GOOD_BUILD).size());
}
-
@Test
public void testScheduleDAO() throws Exception {
Long time = System.currentTimeMillis();
@@ -1059,9 +1038,8 @@ public void testScheduleDAO() throws Exception {
assertEquals(updatedBean.getCurrent_session(), (Integer) 1);
assertEquals(updatedBean.getState(), ScheduleState.RUNNING);
assertEquals(updatedBean.getHost_numbers(), "50,60,500");
-
}
-
+
@Test
public void testUtilDAO() throws Exception {
StringBuilder lockNameBuilder = new StringBuilder();
@@ -1074,8 +1052,8 @@ public void testUtilDAO() throws Exception {
}
}
- private EnvironBean genDefaultEnvBean(String envId, String envName, String envStage,
- String deployId) {
+ private EnvironBean genDefaultEnvBean(
+ String envId, String envName, String envStage, String deployId) {
EnvironBean envBean = new EnvironBean();
envBean.setEnv_id(envId);
envBean.setEnv_name(envName);
@@ -1085,7 +1063,7 @@ private EnvironBean genDefaultEnvBean(String envId, String envName, String envSt
envBean.setPriority(DeployPriority.NORMAL);
envBean.setStuck_th(100);
- //To keep the precision, the default success_th value should be 10000 in DB.
+ // To keep the precision, the default success_th value should be 10000 in DB.
envBean.setSuccess_th(10000);
envBean.setDescription("foo");
envBean.setDeploy_id(deployId);
@@ -1108,8 +1086,8 @@ private EnvironBean genDefaultEnvBean(String envId, String envName, String envSt
return envBean;
}
- private DeployBean genDefaultDeployBean(String id, String envId, String buildId,
- long startDate, DeployState state) {
+ private DeployBean genDefaultDeployBean(
+ String id, String envId, String buildId, long startDate, DeployState state) {
DeployBean deployBean = new DeployBean();
deployBean.setDeploy_id(id);
deployBean.setEnv_id(envId);
@@ -1137,8 +1115,8 @@ private RatingBean genDefaultRatingsBean(String id, String author, long timestam
return ratingBean;
}
- private BuildBean genDefaultBuildInfoBean(String id, String buildName,
- String commitId, String repoUrl, long buildDate) {
+ private BuildBean genDefaultBuildInfoBean(
+ String id, String buildName, String commitId, String repoUrl, long buildDate) {
BuildBean buildBean = new BuildBean();
buildBean.setBuild_id(id);
buildBean.setBuild_name(buildName);
@@ -1153,8 +1131,12 @@ private BuildBean genDefaultBuildInfoBean(String id, String buildName,
return buildBean;
}
- private AgentBean genDefaultAgentBean(String hostName, String hostId, String envId,
- String deployId, DeployStage deployStage) {
+ private AgentBean genDefaultAgentBean(
+ String hostName,
+ String hostId,
+ String envId,
+ String deployId,
+ DeployStage deployStage) {
AgentBean agentBean = new AgentBean();
agentBean.setHost_name(hostName);
agentBean.setHost_id(hostId);
@@ -1183,7 +1165,7 @@ private DataBean genDefaultDataBean(String id, String data) {
}
private TagBean genTagBean(TagValue val, String target_id, String target_type, Object meta_info)
- throws Exception {
+ throws Exception {
TagBean bean = new TagBean();
bean.setId(CommonUtils.getBase64UUID());
bean.setCreated_date(System.currentTimeMillis());
diff --git a/deploy-service/common/src/test/java/com/pinterest/deployservice/db/DBUtils.java b/deploy-service/common/src/test/java/com/pinterest/deployservice/db/DBUtils.java
new file mode 100644
index 0000000000..0f62a71894
--- /dev/null
+++ b/deploy-service/common/src/test/java/com/pinterest/deployservice/db/DBUtils.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) 2024 Pinterest, Inc.
+ *
+ * Licensed 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 com.pinterest.deployservice.db;
+
+import com.ibatis.common.jdbc.ScriptRunner;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.sql.Connection;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.testcontainers.containers.MySQLContainer;
+
+public class DBUtils {
+
+ public static String DATABASE_NAME = "deploy";
+ public static String DATABASE_USER = "root";
+ public static String DATABASE_PASSWORD = "";
+
+ public static MySQLContainer getContainer() {
+ return new MySQLContainer<>()
+ .withDatabaseName(DATABASE_NAME)
+ .withUsername(DATABASE_USER)
+ .withPassword(DATABASE_PASSWORD);
+ }
+
+ public static void runMigrations(BasicDataSource dataSource) throws Exception {
+ Connection conn = dataSource.getConnection();
+ ScriptRunner runner = new ScriptRunner(conn, false, true);
+ runner.runScript(
+ new BufferedReader(
+ new InputStreamReader(
+ DBUtils.class.getResourceAsStream("/sql/cleanup.sql"))));
+ runner.runScript(
+ new BufferedReader(
+ new InputStreamReader(
+ DBUtils.class.getResourceAsStream("/sql/deploy.sql"))));
+ conn.prepareStatement("SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));")
+ .execute();
+ conn.close();
+ }
+}
diff --git a/deploy-service/teletraanservice/bin/server-no-db.yaml b/deploy-service/teletraanservice/bin/server-no-db.yaml
deleted file mode 100644
index c5e04699a8..0000000000
--- a/deploy-service/teletraanservice/bin/server-no-db.yaml
+++ /dev/null
@@ -1,91 +0,0 @@
-server:
- applicationConnectors:
- - type: http
- port: 8080
- adminConnectors:
- - type: http
- port: 8081
- requestLog:
- appenders:
- - type: file
- archive: true
- archivedLogFilenamePattern: /tmp/teletraan/access-%d.log
- archivedFileCount: 5
- currentLogFilename: /tmp/teletraan/access.log
- layout:
- type: access-json
- timestampFormat: "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
- requestAttributes: [name]
- customFieldNames:
- requestAttributes: principal
- includes: [timestamp, remoteAddress, protocol, method, requestUri, statusCode]
- registerDefaultExceptionMappers: false
-
-logging:
- level: INFO
- loggers:
- "com.pinterest.teletraan": DEBUG
- "com.pinterest.deployservice": DEBUG
- appenders:
- - type: file
- timeZone: UTC
- threshold: DEBUG
- archive: false
- currentLogFilename: /tmp/teletraan/service.log
- - type: console
- threshold: ALL
- timeZone: UTC
- target: stdout
-
-db:
- type: embedded
-
-system:
- dashboardUrl: ${TELETRAAN_DASHBOARD_URL:-http://localhost:8888}
-
-workers:
- # StateTransitioner looks for active deploys, set deploy status and
- # transition deploys to their next states.
- - name: StateTransitioner
- properties:
- initialDelay: 10
- period: 30
-
- # AutoPromoter provides the Auto Deploy support. It finds the deploy
- # candidates from preceding stage and promote them to next stages.
- - name: AutoPromoter
- properties:
- initialDelay: 20
- period: 30
- bufferTimeMinutes: 2
-
- # AgentJanitor cleans up any obsoleted hosts or agents records
- - name: SimpleAgentJanitor
- properties:
- initialDelay: 30
- period: 300
- minStaleHostThreshold: 150
- maxStaleHostThreshold: 600
-
- - name: MetricsEmitter
- properties:
- initialDelay: 2
- period: 5
-
-#
-# Health settings
-#
-health:
- delayedShutdownHandlerEnabled: true
- shutdownWaitPeriod: 30s
- healthCheckUrlPaths:
- - /healthcheck
- - /health-check
- healthChecks:
- - name: generic
- critical: true
- schedule:
- checkInterval: 5s
- downtimeInterval: 10s
- failureAttempts: 2
- successAttempts: 1
diff --git a/deploy-service/teletraanservice/pom.xml b/deploy-service/teletraanservice/pom.xml
index 3e41f7871b..88a37fa9a7 100644
--- a/deploy-service/teletraanservice/pom.xml
+++ b/deploy-service/teletraanservice/pom.xml
@@ -65,12 +65,6 @@
org.quartz-scheduler
quartz
-
-
- mysql
- mysql-connector-mxj
- 5.0.12
-
com.ibatis
ibatis2-common
diff --git a/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/TeletraanServiceConfiguration.java b/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/TeletraanServiceConfiguration.java
index 8343b085d2..cb843678af 100644
--- a/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/TeletraanServiceConfiguration.java
+++ b/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/TeletraanServiceConfiguration.java
@@ -33,7 +33,6 @@
import com.pinterest.teletraan.config.DefaultEmailFactory;
import com.pinterest.teletraan.config.DefaultHostGroupFactory;
import com.pinterest.teletraan.config.EmailFactory;
-import com.pinterest.teletraan.config.EmbeddedDataSourceFactory;
import com.pinterest.teletraan.config.ExternalAlertsConfigFactory;
import com.pinterest.teletraan.config.HostGroupFactory;
import com.pinterest.teletraan.config.JenkinsFactory;
@@ -124,9 +123,6 @@ public class TeletraanServiceConfiguration extends Configuration {
private List accountAllowList;
public DataSourceFactory getDataSourceFactory() {
- if (dataSourceFactory == null) {
- return new EmbeddedDataSourceFactory();
- }
return dataSourceFactory;
}
diff --git a/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/EmbeddedDataSourceFactory.java b/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/EmbeddedDataSourceFactory.java
deleted file mode 100644
index c43c8854ed..0000000000
--- a/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/EmbeddedDataSourceFactory.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Copyright 2016 Pinterest, Inc.
- *
- * Licensed 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 com.pinterest.teletraan.config;
-
-import com.pinterest.deployservice.db.DatabaseUtil;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonTypeName;
-import com.ibatis.common.jdbc.ScriptRunner;
-import com.mysql.management.driverlaunched.ServerLauncherSocketFactory;
-
-import org.apache.commons.dbcp.BasicDataSource;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.InputStreamReader;
-import java.sql.Connection;
-
-@JsonTypeName("embedded")
-public class EmbeddedDataSourceFactory implements DataSourceFactory {
-
- private final static String DEFAULT_BASE_DIR = "/tmp/teletraan/db";
- private final static String DEFAULT_DB_NAME = "deploy";
- private final static int DEFAULT_PORT = 3305;
-
- @JsonProperty
- private String workDir = DEFAULT_BASE_DIR;
-
- public String getWorkDir() {
- return workDir;
- }
-
- public void setWorkDir(String workDir) {
- this.workDir = workDir;
- }
-
- public BasicDataSource build() throws Exception {
- try {
- // making sure we do not have anything running
- ServerLauncherSocketFactory.shutdown(new File(workDir), null);
- } catch (Exception e) {
- // ignore
- }
-
- BasicDataSource
- DATASOURCE =
- DatabaseUtil.createMXJDataSource(DEFAULT_DB_NAME, workDir, DEFAULT_PORT);
- Connection conn = DATASOURCE.getConnection();
- ScriptRunner runner = new ScriptRunner(conn, false, false);
- runner.runScript(new BufferedReader(new InputStreamReader(
- DatabaseUtil.class.getResourceAsStream("/sql/deploy.sql"))));
- return DATASOURCE;
- }
-}
diff --git a/deploy-service/teletraanservice/src/main/resources/META-INF/services/com.pinterest.teletraan.config.DataSourceFactory b/deploy-service/teletraanservice/src/main/resources/META-INF/services/com.pinterest.teletraan.config.DataSourceFactory
index b3193843a8..88f3f19683 100644
--- a/deploy-service/teletraanservice/src/main/resources/META-INF/services/com.pinterest.teletraan.config.DataSourceFactory
+++ b/deploy-service/teletraanservice/src/main/resources/META-INF/services/com.pinterest.teletraan.config.DataSourceFactory
@@ -1,3 +1,2 @@
com.pinterest.teletraan.config.ZKMysqlDataSourceFactory
com.pinterest.teletraan.config.MysqlDataSourceFactory
-com.pinterest.teletraan.config.EmbeddedDataSourceFactory