diff --git a/common/types/data_connections.ts b/common/types/data_connections.ts index b36df4a90..a5585aca7 100644 --- a/common/types/data_connections.ts +++ b/common/types/data_connections.ts @@ -121,10 +121,10 @@ export interface CachedDataSource { lastUpdated: string; // date string in UTC format status: CachedDataSourceStatus; databases: CachedDatabase[]; + dataSourceMDSId?: string; } export interface DataSourceCacheData { - dataSourceMDSId?: string; version: string; dataSources: CachedDataSource[]; } @@ -144,11 +144,11 @@ export interface CachedAccelerationByDataSource { accelerations: CachedAcceleration[]; lastUpdated: string; // date string in UTC format status: CachedDataSourceStatus; + dataSourceMDSId?: string; } export interface AccelerationsCacheData { version: string; - dataSourceMDSId?: string; dataSources: CachedAccelerationByDataSource[]; } @@ -239,12 +239,6 @@ export interface CreateAccelerationForm { refreshIntervalOptions: RefreshIntervalType; formErrors: FormErrorsType; } -export interface StartLoadingParams { - dataSourceName: string; - dataSourceMDSId?: string; - databaseName?: string; - tableName?: string; -} export interface LoadCachehookOutput { loadStatus: DirectQueryLoadingStatus; diff --git a/common/utils/shared.ts b/common/utils/shared.ts index e40285971..d85aab000 100644 --- a/common/utils/shared.ts +++ b/common/utils/shared.ts @@ -18,10 +18,10 @@ export function get(obj: Record, path: string, default } export function addBackticksIfNeeded(input: string): string { - // Check if the string already has backticks if (input === undefined) { return ''; } + // Check if the string already has backticks if (input.startsWith('`') && input.endsWith('`')) { return input; // Return the string as it is } else { diff --git a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx index df7edc61c..507c6fe95 100644 --- a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx +++ b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx @@ -231,6 +231,7 @@ export const CreateAcceleration = ({ selectedDatasource={selectedDatasource} dataSourcesPreselected={dataSourcesPreselected} tableFieldsLoading={tableFieldsLoading} + dataSourceMDSId={dataSourceMDSId} /> { const { setToast } = useToast(); const [databases, setDatabases] = useState>>([]); @@ -72,7 +74,7 @@ export const AccelerationDataSourceSelector = ({ const loadDataSource = () => { setLoadingComboBoxes({ ...loadingComboBoxes, dataSource: true }); http - .get(DATACONNECTIONS_BASE) + .get(DATACONNECTIONS_BASE + `/dataSourceMDSId=${dataSourceMDSId}`) .then((res) => { const isValidDataSource = res.some( (connection: any) => diff --git a/public/components/hooks/use_polling.ts b/public/components/hooks/use_polling.ts index 72fcbfb20..30127fa0f 100644 --- a/public/components/hooks/use_polling.ts +++ b/public/components/hooks/use_polling.ts @@ -111,7 +111,7 @@ export function usePolling( try { const result = await fetchFunction(params); setData(result); - + console.log(result); // Check the success condition and stop polling if it's met if (onPollingSuccess && onPollingSuccess(result, configurations)) { stopPolling(); diff --git a/public/framework/catalog_cache/cache_loader.test.tsx b/public/framework/catalog_cache/cache_loader.test.tsx index e3a328ea4..a8a2f2e32 100644 --- a/public/framework/catalog_cache/cache_loader.test.tsx +++ b/public/framework/catalog_cache/cache_loader.test.tsx @@ -66,12 +66,15 @@ describe('loadCacheTests', () => { updateDatabasesToCache(dataSourceName, pollingResult); // Verify that addOrUpdateDataSource is called with the correct parameters - expect(CatalogCacheManager.addOrUpdateDataSource).toHaveBeenCalledWith({ - name: dataSourceName, - databases: [], - lastUpdated: expect.any(String), - status: CachedDataSourceStatus.Failed, - }); + expect(CatalogCacheManager.addOrUpdateDataSource).toHaveBeenCalledWith( + { + name: dataSourceName, + databases: [], + lastUpdated: expect.any(String), + status: CachedDataSourceStatus.Failed, + }, + undefined + ); }); it('should update cache with new databases when polling result is not null', () => { @@ -79,15 +82,28 @@ describe('loadCacheTests', () => { updateDatabasesToCache(dataSourceName, mockShowDatabasesPollingResult); // Verify that addOrUpdateDataSource is called with the correct parameters - expect(CatalogCacheManager.addOrUpdateDataSource).toHaveBeenCalledWith({ - name: dataSourceName, - databases: [ - { name: 'Database1', tables: [], lastUpdated: '', status: CachedDataSourceStatus.Empty }, - { name: 'Database2', tables: [], lastUpdated: '', status: CachedDataSourceStatus.Empty }, - ], - lastUpdated: expect.any(String), - status: CachedDataSourceStatus.Updated, - }); + expect(CatalogCacheManager.addOrUpdateDataSource).toHaveBeenCalledWith( + { + name: dataSourceName, + databases: [ + { + name: 'Database1', + tables: [], + lastUpdated: '', + status: CachedDataSourceStatus.Empty, + }, + { + name: 'Database2', + tables: [], + lastUpdated: '', + status: CachedDataSourceStatus.Empty, + }, + ], + lastUpdated: expect.any(String), + status: CachedDataSourceStatus.Updated, + }, + undefined + ); }); }); @@ -97,19 +113,22 @@ describe('loadCacheTests', () => { const databaseName = 'TestDatabase'; const pollingResult = null; - CatalogCacheManager.addOrUpdateDataSource({ - databases: [ - { - name: databaseName, - lastUpdated: '', - status: CachedDataSourceStatus.Empty, - tables: [], - }, - ], - name: dataSourceName, - lastUpdated: new Date().toUTCString(), - status: CachedDataSourceStatus.Updated, - }); + CatalogCacheManager.addOrUpdateDataSource( + { + databases: [ + { + name: databaseName, + lastUpdated: '', + status: CachedDataSourceStatus.Empty, + tables: [], + }, + ], + name: dataSourceName, + lastUpdated: new Date().toUTCString(), + status: CachedDataSourceStatus.Updated, + }, + undefined + ); updateTablesToCache(dataSourceName, databaseName, pollingResult); // Verify that updateDatabase is called with the correct parameters @@ -120,7 +139,8 @@ describe('loadCacheTests', () => { tables: [], lastUpdated: expect.any(String), status: CachedDataSourceStatus.Failed, - }) + }), + undefined ); }); @@ -151,7 +171,8 @@ describe('loadCacheTests', () => { tables: [{ name: 'http_logs1' }, { name: 'http_logs2' }], lastUpdated: expect.any(String), status: CachedDataSourceStatus.Updated, - }) + }), + undefined ); }); }); @@ -170,7 +191,6 @@ describe('loadCacheTests', () => { // Verify that saveAccelerationsCache is called with the correct parameters expect(CatalogCacheManager.saveAccelerationsCache).toHaveBeenCalledWith({ version: CATALOG_CACHE_VERSION, - dataSourceMDSId: '', dataSources: [ { name: 'sampleDS', @@ -188,7 +208,6 @@ describe('loadCacheTests', () => { // Verify that saveAccelerationsCache is called with the correct parameters expect(CatalogCacheManager.saveAccelerationsCache).toHaveBeenCalledWith({ version: CATALOG_CACHE_VERSION, - dataSourceMDSId: '', dataSources: [ { name: 'sampleDS', diff --git a/public/framework/catalog_cache/cache_loader.tsx b/public/framework/catalog_cache/cache_loader.tsx index 9800337f5..f1775eb90 100644 --- a/public/framework/catalog_cache/cache_loader.tsx +++ b/public/framework/catalog_cache/cache_loader.tsx @@ -33,18 +33,26 @@ import { CatalogCacheManager } from './cache_manager'; export const updateDatabasesToCache = ( dataSourceName: string, - pollingResult: AsyncPollingResult + pollingResult: AsyncPollingResult, + dataSourceMDSId?: string ) => { - const cachedDataSource = CatalogCacheManager.getOrCreateDataSource(dataSourceName); + const cachedDataSource = CatalogCacheManager.getOrCreateDataSource( + dataSourceName, + dataSourceMDSId + ); const currentTime = new Date().toUTCString(); if (!pollingResult) { - CatalogCacheManager.addOrUpdateDataSource({ - ...cachedDataSource, - databases: [], - lastUpdated: currentTime, - status: CachedDataSourceStatus.Failed, - }); + CatalogCacheManager.addOrUpdateDataSource( + { + ...cachedDataSource, + databases: [], + lastUpdated: currentTime, + status: CachedDataSourceStatus.Failed, + ...(dataSourceMDSId && { dataSourceMDSId }), + }, + dataSourceMDSId + ); return; } @@ -56,30 +64,43 @@ export const updateDatabasesToCache = ( status: CachedDataSourceStatus.Empty, })); - CatalogCacheManager.addOrUpdateDataSource({ - ...cachedDataSource, - databases: newDatabases, - lastUpdated: currentTime, - status: CachedDataSourceStatus.Updated, - }); + CatalogCacheManager.addOrUpdateDataSource( + { + ...cachedDataSource, + databases: newDatabases, + lastUpdated: currentTime, + status: CachedDataSourceStatus.Updated, + ...(dataSourceMDSId && { dataSourceMDSId }), + }, + dataSourceMDSId + ); }; export const updateTablesToCache = ( dataSourceName: string, databaseName: string, - pollingResult: AsyncPollingResult + pollingResult: AsyncPollingResult, + dataSourceMDSId?: string ) => { try { - const cachedDatabase = CatalogCacheManager.getDatabase(dataSourceName, databaseName); + const cachedDatabase = CatalogCacheManager.getDatabase( + dataSourceName, + databaseName, + dataSourceMDSId + ); const currentTime = new Date().toUTCString(); if (!pollingResult) { - CatalogCacheManager.updateDatabase(dataSourceName, { - ...cachedDatabase, - tables: [], - lastUpdated: currentTime, - status: CachedDataSourceStatus.Failed, - }); + CatalogCacheManager.updateDatabase( + dataSourceName, + { + ...cachedDatabase, + tables: [], + lastUpdated: currentTime, + status: CachedDataSourceStatus.Failed, + }, + dataSourceMDSId + ); return; } @@ -90,12 +111,16 @@ export const updateTablesToCache = ( name: row.tableName, })); - CatalogCacheManager.updateDatabase(dataSourceName, { - ...cachedDatabase, - tables: newTables, - lastUpdated: currentTime, - status: CachedDataSourceStatus.Updated, - }); + CatalogCacheManager.updateDatabase( + dataSourceName, + { + ...cachedDatabase, + tables: newTables, + lastUpdated: currentTime, + status: CachedDataSourceStatus.Updated, + }, + dataSourceMDSId + ); } catch (error) { console.error(error); } @@ -103,7 +128,8 @@ export const updateTablesToCache = ( export const updateAccelerationsToCache = ( dataSourceName: string, - pollingResult: AsyncPollingResult + pollingResult: AsyncPollingResult, + dataSourceMDSId?: string ) => { const currentTime = new Date().toUTCString(); @@ -113,6 +139,7 @@ export const updateAccelerationsToCache = ( accelerations: [], lastUpdated: currentTime, status: CachedDataSourceStatus.Failed, + ...(dataSourceMDSId && { dataSourceMDSId }), }); return; } @@ -134,6 +161,7 @@ export const updateAccelerationsToCache = ( accelerations: newAccelerations, lastUpdated: currentTime, status: CachedDataSourceStatus.Updated, + ...(dataSourceMDSId && { dataSourceMDSId }), }); }; @@ -141,13 +169,18 @@ export const updateTableColumnsToCache = ( dataSourceName: string, databaseName: string, tableName: string, - pollingResult: AsyncPollingResult + pollingResult: AsyncPollingResult, + dataSourceMDSId?: string ) => { try { if (!pollingResult) { return; } - const cachedDatabase = CatalogCacheManager.getDatabase(dataSourceName, databaseName); + const cachedDatabase = CatalogCacheManager.getDatabase( + dataSourceName, + databaseName, + dataSourceMDSId + ); const currentTime = new Date().toUTCString(); const combinedData: Array<{ col_name: string; data_type: string }> = combineSchemaAndDatarows( @@ -171,12 +204,16 @@ export const updateTableColumnsToCache = ( ); if (cachedDatabase.status === CachedDataSourceStatus.Updated) { - CatalogCacheManager.updateDatabase(dataSourceName, { - ...cachedDatabase, - tables: newTables, - lastUpdated: currentTime, - status: CachedDataSourceStatus.Updated, - }); + CatalogCacheManager.updateDatabase( + dataSourceName, + { + ...cachedDatabase, + tables: newTables, + lastUpdated: currentTime, + status: CachedDataSourceStatus.Updated, + }, + dataSourceMDSId + ); } } catch (error) { console.error(error); @@ -188,20 +225,27 @@ export const updateToCache = ( loadCacheType: LoadCacheType, dataSourceName: string, databaseName?: string, - tableName?: string + tableName?: string, + dataSourceMDSId?: string ) => { switch (loadCacheType) { case 'databases': - updateDatabasesToCache(dataSourceName, pollResults); + updateDatabasesToCache(dataSourceName, pollResults, dataSourceMDSId); break; case 'tables': - updateTablesToCache(dataSourceName, databaseName!, pollResults); + updateTablesToCache(dataSourceName, databaseName!, pollResults, dataSourceMDSId); break; case 'accelerations': - updateAccelerationsToCache(dataSourceName, pollResults); + updateAccelerationsToCache(dataSourceName, pollResults, dataSourceMDSId); break; case 'tableColumns': - updateTableColumnsToCache(dataSourceName, databaseName!, tableName!, pollResults); + updateTableColumnsToCache( + dataSourceName, + databaseName!, + tableName!, + pollResults, + dataSourceMDSId + ); default: break; } @@ -265,7 +309,8 @@ export const useLoadToCache = (loadCacheType: LoadCacheType) => { loadCacheType, currentDataSourceName, currentDatabaseName, - currentTableName + currentTableName, + dataSourceMDSClientId.current ); }; @@ -294,6 +339,7 @@ export const useLoadToCache = (loadCacheType: LoadCacheType) => { sqlService .fetch(requestPayload, dataSourceMDSId) .then((result) => { + console.log(result); setAsyncSessionId(dataSourceName, getObjValue(result, 'sessionId', null)); if (result.queryId) { startPolling({ @@ -332,7 +378,8 @@ export const useLoadToCache = (loadCacheType: LoadCacheType) => { loadCacheType, currentDataSourceName, currentDatabaseName, - currentTableName + currentTableName, + dataSourceMDSClientId.current ); } else if (status === DirectQueryLoadingStatus.FAILED) { onLoadingFailed(); diff --git a/public/framework/catalog_cache/cache_manager.ts b/public/framework/catalog_cache/cache_manager.ts index 908b1f7d0..bcd0dedbf 100644 --- a/public/framework/catalog_cache/cache_manager.ts +++ b/public/framework/catalog_cache/cache_manager.ts @@ -44,22 +44,16 @@ export class CatalogCacheManager { * Retrieves data source cache from local storage. * @returns {DataSourceCacheData} The retrieved data source cache. */ - static getDataSourceCache(dataSourceMDSId?: string): DataSourceCacheData { + static getDataSourceCache(): DataSourceCacheData { const catalogData = sessionStorage.getItem(this.datasourceCacheKey); + if (catalogData) { - const cachedData = JSON.parse(catalogData); - if (dataSourceMDSId && cachedData.dataSourceMDSId === dataSourceMDSId) { - return cachedData; - } - return cachedData; + return JSON.parse(catalogData); + } else { + const defaultCacheObject = { version: CATALOG_CACHE_VERSION, dataSources: [] }; + this.saveDataSourceCache(defaultCacheObject); + return defaultCacheObject; } - const defaultCacheObject = { - ...(dataSourceMDSId && { dataSourceMDSId }), - version: CATALOG_CACHE_VERSION, - dataSources: [], - }; - this.saveDataSourceCache(defaultCacheObject); - return defaultCacheObject; } /** @@ -74,23 +68,19 @@ export class CatalogCacheManager { * Retrieves accelerations cache from local storage. * @returns {AccelerationsCacheData} The retrieved accelerations cache. */ - static getAccelerationsCache(dataSourceMDSId?: string): AccelerationsCacheData { + static getAccelerationsCache(): AccelerationsCacheData { const accelerationCacheData = sessionStorage.getItem(this.accelerationsCacheKey); if (accelerationCacheData) { - const cachedAcclerationData = JSON.parse(accelerationCacheData); - if (dataSourceMDSId && cachedAcclerationData.dataSourceMDSId === dataSourceMDSId) { - return cachedAcclerationData; - } - return cachedAcclerationData; + return JSON.parse(accelerationCacheData); + } else { + const defaultCacheObject = { + version: CATALOG_CACHE_VERSION, + dataSources: [], + }; + this.saveAccelerationsCache(defaultCacheObject); + return defaultCacheObject; } - const defaultCacheObject = { - version: CATALOG_CACHE_VERSION, - ...(dataSourceMDSId && { dataSourceMDSId }), - dataSources: [], - }; - this.saveAccelerationsCache(defaultCacheObject); - return defaultCacheObject; } /** @@ -101,10 +91,19 @@ export class CatalogCacheManager { dataSource: CachedAccelerationByDataSource, dataSourceMDSId?: string ): void { - const accCacheData = this.getAccelerationsCache(dataSourceMDSId); - const index = accCacheData.dataSources.findIndex( - (ds: CachedAccelerationByDataSource) => ds.name === dataSource.name - ); + let index; + const accCacheData = this.getAccelerationsCache(); + if (dataSourceMDSId) { + index = accCacheData.dataSources.findIndex( + (ds: CachedAccelerationByDataSource) => + ds.name === dataSource.name && ds.dataSourceMDSId === dataSourceMDSId + ); + } else { + index = accCacheData.dataSources.findIndex( + (ds: CachedAccelerationByDataSource) => + ds.name === dataSource.name && ds.dataSourceMDSId === dataSourceMDSId + ); + } if (index !== -1) { accCacheData.dataSources[index] = dataSource; } else { @@ -123,17 +122,28 @@ export class CatalogCacheManager { dataSourceName: string, dataSourceMDSId?: string ): CachedAccelerationByDataSource { - const accCacheData = this.getAccelerationsCache(dataSourceMDSId); - const cachedDataSource = accCacheData.dataSources.find((ds) => ds.name === dataSourceName); + const accCacheData = this.getAccelerationsCache(); + let cachedDataSource; + if (dataSourceMDSId) { + cachedDataSource = accCacheData.dataSources.find( + (ds) => ds.name === dataSourceName && ds.dataSourceMDSId === dataSourceMDSId + ); + } else { + cachedDataSource = accCacheData.dataSources.find((ds) => ds.name === dataSourceName); + } if (cachedDataSource) return cachedDataSource; else { - const defaultDataSourceObject = { + let defaultDataSourceObject: CachedAccelerationByDataSource = { name: dataSourceName, lastUpdated: '', status: CachedDataSourceStatus.Empty, accelerations: [], }; + + if (dataSourceMDSId !== '' && dataSourceMDSId !== undefined) { + defaultDataSourceObject = { ...defaultDataSourceObject, dataSourceMDSId }; + } this.addOrUpdateAccelerationsByDataSource(defaultDataSourceObject, dataSourceMDSId); return defaultDataSourceObject; } @@ -144,11 +154,15 @@ export class CatalogCacheManager { * @param {CachedDataSource} dataSource - The data source to add or update. */ static addOrUpdateDataSource(dataSource: CachedDataSource, dataSourceMDSId?: string): void { - const cacheData = this.getDataSourceCache(dataSourceMDSId); - - const index = cacheData.dataSources.findIndex( - (ds: CachedDataSource) => ds.name === dataSource.name - ); + const cacheData = this.getDataSourceCache(); + let index; + if (dataSourceMDSId) { + index = cacheData.dataSources.findIndex( + (ds: CachedDataSource) => + ds.name === dataSource.name && ds.dataSourceMDSId === dataSourceMDSId + ); + } + index = cacheData.dataSources.findIndex((ds: CachedDataSource) => ds.name === dataSource.name); if (index !== -1) { cacheData.dataSources[index] = dataSource; } else { @@ -163,19 +177,28 @@ export class CatalogCacheManager { * @returns {CachedDataSource} The retrieved or created data source. */ static getOrCreateDataSource(dataSourceName: string, dataSourceMDSId?: string): CachedDataSource { - const cacheData = this.getDataSourceCache(dataSourceMDSId); - const cachedDataSource = cacheData.dataSources.find( - (ds: CachedDataSource) => ds.name === dataSourceName - ); + let cachedDataSource; + if (dataSourceMDSId) { + cachedDataSource = this.getDataSourceCache().dataSources.find( + (ds) => ds.dataSourceMDSId === dataSourceMDSId && ds.name === dataSourceName + ); + } else { + cachedDataSource = this.getDataSourceCache().dataSources.find( + (ds) => ds.name === dataSourceName + ); + } if (cachedDataSource) { return cachedDataSource; } else { - const defaultDataSourceObject = { + let defaultDataSourceObject: CachedDataSource = { name: dataSourceName, lastUpdated: '', status: CachedDataSourceStatus.Empty, databases: [], }; + if (dataSourceMDSId !== '' && dataSourceMDSId !== undefined) { + defaultDataSourceObject = { ...defaultDataSourceObject, dataSourceMDSId }; + } this.addOrUpdateDataSource(defaultDataSourceObject, dataSourceMDSId); return defaultDataSourceObject; } @@ -193,9 +216,16 @@ export class CatalogCacheManager { databaseName: string, dataSourceMDSId?: string ): CachedDatabase { - const cachedDataSource = this.getDataSourceCache(dataSourceMDSId).dataSources.find( - (ds) => ds.name === dataSourceName - ); + let cachedDataSource; + if (dataSourceMDSId) { + cachedDataSource = this.getDataSourceCache().dataSources.find( + (ds) => ds.dataSourceMDSId === dataSourceMDSId && ds.name === dataSourceName + ); + } else { + cachedDataSource = this.getDataSourceCache().dataSources.find( + (ds) => ds.name === dataSourceName + ); + } if (!cachedDataSource) { throw new Error('DataSource not found exception: ' + dataSourceName); } @@ -237,10 +267,22 @@ export class CatalogCacheManager { * @param {CachedDatabase} database - The database to be updated. * @throws {Error} If the data source or database is not found. */ - static updateDatabase(dataSourceName: string, database: CachedDatabase): void { - const cachedDataSource = this.getDataSourceCache().dataSources.find( - (ds) => ds.name === dataSourceName - ); + static updateDatabase( + dataSourceName: string, + database: CachedDatabase, + dataSourceMDSId?: string + ): void { + let cachedDataSource; + if (dataSourceMDSId) { + cachedDataSource = this.getDataSourceCache().dataSources.find( + (ds) => ds.dataSourceMDSId === dataSourceMDSId && ds.name === dataSourceName + ); + } else { + cachedDataSource = this.getDataSourceCache().dataSources.find( + (ds) => ds.name === dataSourceName + ); + } + if (!cachedDataSource) { throw new Error('DataSource not found exception: ' + dataSourceName); } @@ -248,7 +290,7 @@ export class CatalogCacheManager { const index = cachedDataSource.databases.findIndex((db) => db.name === database.name); if (index !== -1) { cachedDataSource.databases[index] = database; - this.addOrUpdateDataSource(cachedDataSource); + this.addOrUpdateDataSource(cachedDataSource, dataSourceMDSId); } else { throw new Error('Database not found exception: ' + database.name); } diff --git a/server/routes/data_connections/data_connections_router.ts b/server/routes/data_connections/data_connections_router.ts index 2788653de..bd19e8615 100644 --- a/server/routes/data_connections/data_connections_router.ts +++ b/server/routes/data_connections/data_connections_router.ts @@ -15,7 +15,7 @@ import { EDIT, } from '../../../common/constants/shared'; -export function registerDataConnectionsRoute(router: IRouter) { +export function registerDataConnectionsRoute(router: IRouter, dataSourceEnabled: boolean) { router.get( { path: `${DATACONNECTIONS_BASE}/{name}`, @@ -183,14 +183,25 @@ export function registerDataConnectionsRoute(router: IRouter) { router.get( { - path: `${DATACONNECTIONS_BASE}`, - validate: false, + path: `${DATACONNECTIONS_BASE}/dataSourceMDSId={dataSourceMDSId?}`, + validate: { + params: schema.object({ + dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' })), + }), + }, }, async (context, request, response): Promise => { + const dataSourceMDSId = request.params.dataSourceMDSId; try { - const dataConnectionsresponse = await context.observability_plugin.observabilityClient - .asScoped(request) - .callAsCurrentUser('ppl.getDataConnections'); + let dataConnectionsresponse; + if (dataSourceEnabled && dataSourceMDSId) { + const client = await context.dataSource.opensearch.legacy.getClient(dataSourceMDSId); + dataConnectionsresponse = await client.callAPI('ppl.getDataConnections'); + } else { + dataConnectionsresponse = await context.observability_plugin.observabilityClient + .asScoped(request) + .callAsCurrentUser('ppl.getDataConnections'); + } return response.ok({ body: dataConnectionsresponse, }); diff --git a/server/routes/index.ts b/server/routes/index.ts index 1b8f88c65..a784794af 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -25,7 +25,15 @@ import { registerPplRoute } from './ppl'; import { registerQueryAssistRoutes } from './query_assist/routes'; import { registerTraceAnalyticsDslRouter } from './trace_analytics_dsl_router'; -export function setupRoutes({ router, client, dataSourceEnabled }: { router: IRouter; client: ILegacyClusterClient, dataSourceEnabled: boolean }) { +export function setupRoutes({ + router, + client, + dataSourceEnabled, +}: { + router: IRouter; + client: ILegacyClusterClient; + dataSourceEnabled: boolean; +}) { PanelsRouter(router); VisualizationsRouter(router); registerPplRoute({ router, facet: new PPLFacet(client) }); @@ -45,7 +53,7 @@ export function setupRoutes({ router, client, dataSourceEnabled }: { router: IRo registerMetricsRoute(router); registerIntegrationsRoute(router); - registerDataConnectionsRoute(router); + registerDataConnectionsRoute(router, dataSourceEnabled); registerDatasourcesRoute(router, dataSourceEnabled); registerQueryAssistRoutes(router); }