From 82e778da91c3ae32b583918b12199fe0e414f3a0 Mon Sep 17 00:00:00 2001 From: David Wallace Date: Thu, 22 Feb 2024 13:57:41 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[source-mssql]=20skip=20sql=20serve?= =?UTF-8?q?r=20agent=20check=20if=20EngineEdition=20=3D=3D=208=20(#35368)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/mssql/MssqlSource.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/airbyte-integrations/connectors/source-mssql/src/main/java/io/airbyte/integrations/source/mssql/MssqlSource.java b/airbyte-integrations/connectors/source-mssql/src/main/java/io/airbyte/integrations/source/mssql/MssqlSource.java index 27bd0876a5dce..f7de282d5e8cd 100644 --- a/airbyte-integrations/connectors/source-mssql/src/main/java/io/airbyte/integrations/source/mssql/MssqlSource.java +++ b/airbyte-integrations/connectors/source-mssql/src/main/java/io/airbyte/integrations/source/mssql/MssqlSource.java @@ -417,18 +417,27 @@ protected void assertCdcSchemaQueryable(final JsonNode config, final JdbcDatabas // todo: ensure this works for Azure managed SQL (since it uses different sql server agent) protected void assertSqlServerAgentRunning(final JdbcDatabase database) throws SQLException { try { - final List queryResponse = database.queryJsons(connection -> { - final String sql = - "SELECT status_desc FROM sys.dm_server_services WHERE [servicename] LIKE 'SQL Server Agent%' OR [servicename] LIKE 'SQL Server 代理%' "; - final PreparedStatement ps = connection.prepareStatement(sql); - LOGGER.info(String.format("Checking that the SQL Server Agent is running using the query: '%s'", sql)); - return ps; - }, sourceOperations::rowToJson); - - if (!(queryResponse.get(0).get("status_desc").toString().contains("Running"))) { - throw new RuntimeException(String.format( - "The SQL Server Agent is not running. Current state: '%s'. Please check the documentation on ensuring SQL Server Agent is running.", - queryResponse.get(0).get("status_desc").toString())); + // EngineEdition property values can be found at + // https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16 + // SQL Server Agent is always running on SQL Managed Instance: + // https://learn.microsoft.com/en-us/azure/azure-sql/managed-instance/transact-sql-tsql-differences-sql-server?view=azuresql#sql-server-agent + final Integer engineEdition = database.queryInt("SELECT ServerProperty('EngineEdition')"); + if (engineEdition == 8) { + LOGGER.info(String.format("SQL Server Agent is assumed to be running when EngineEdition == '%s'", engineEdition)); + } else { + final List queryResponse = database.queryJsons(connection -> { + final String sql = + "SELECT status_desc FROM sys.dm_server_services WHERE [servicename] LIKE 'SQL Server Agent%' OR [servicename] LIKE 'SQL Server 代理%' "; + final PreparedStatement ps = connection.prepareStatement(sql); + LOGGER.info(String.format("Checking that the SQL Server Agent is running using the query: '%s'", sql)); + return ps; + }, sourceOperations::rowToJson); + + if (!(queryResponse.get(0).get("status_desc").toString().contains("Running"))) { + throw new RuntimeException(String.format( + "The SQL Server Agent is not running. Current state: '%s'. Please check the documentation on ensuring SQL Server Agent is running.", + queryResponse.get(0).get("status_desc").toString())); + } } } catch (final Exception e) { if (e.getCause() != null && e.getCause().getClass().equals(com.microsoft.sqlserver.jdbc.SQLServerException.class)) {