From 62546180743aaa2016421c6ec6f4ef3894ba9d85 Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Tue, 5 Nov 2024 14:44:01 +0530 Subject: [PATCH 1/2] fix missing auth details on pod restart Signed-off-by: Saad Khan --- .../datasource/DataSourceCollection.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/autotune/common/datasource/DataSourceCollection.java b/src/main/java/com/autotune/common/datasource/DataSourceCollection.java index 6734adc1c..f5f3b2c49 100644 --- a/src/main/java/com/autotune/common/datasource/DataSourceCollection.java +++ b/src/main/java/com/autotune/common/datasource/DataSourceCollection.java @@ -144,6 +144,10 @@ public void addDataSourcesFromConfigFile(String configFileName) { DataSourceInfo dataSourceInfo = new ExperimentDBService().loadDataSourceFromDBByName(name); if (null != dataSourceInfo) { LOGGER.error("Datasource: {} already exists!", name); + // add the auth details to local object + AuthenticationConfig authConfig = getAuthenticationDetails(dataSourceObject, name); + dataSourceInfo.setAuthenticationConfig(authConfig); + dataSourceCollection.put(name, dataSourceInfo); continue; } } catch (Exception e) { @@ -153,16 +157,7 @@ public void addDataSourcesFromConfigFile(String configFileName) { String serviceName = dataSourceObject.getString(KruizeConstants.DataSourceConstants.DATASOURCE_SERVICE_NAME); String namespace = dataSourceObject.getString(KruizeConstants.DataSourceConstants.DATASOURCE_SERVICE_NAMESPACE); String dataSourceURL = dataSourceObject.getString(KruizeConstants.DataSourceConstants.DATASOURCE_URL); - AuthenticationConfig authConfig; - try { - JSONObject authenticationObj = dataSourceObject.optJSONObject(KruizeConstants.AuthenticationConstants.AUTHENTICATION); - // create the corresponding authentication object - authConfig = AuthenticationConfig.createAuthenticationConfigObject(authenticationObj); - } catch (Exception e) { - LOGGER.warn("Auth details are missing for datasource: {}", name); - authConfig = AuthenticationConfig.noAuth(); - } - + AuthenticationConfig authConfig = getAuthenticationDetails(dataSourceObject, name); DataSourceInfo datasource; // Validate input if (!validateInput(name, provider, serviceName, dataSourceURL, namespace)) { @@ -182,6 +177,19 @@ public void addDataSourcesFromConfigFile(String configFileName) { } } + private AuthenticationConfig getAuthenticationDetails(JSONObject dataSourceObject, String name) { + AuthenticationConfig authConfig; + try { + JSONObject authenticationObj = dataSourceObject.optJSONObject(KruizeConstants.AuthenticationConstants.AUTHENTICATION); + // create the corresponding authentication object + authConfig = AuthenticationConfig.createAuthenticationConfigObject(authenticationObj); + } catch (Exception e) { + LOGGER.warn("Auth details are missing for datasource: {}", name); + authConfig = AuthenticationConfig.noAuth(); + } + return authConfig; + } + /** * validates the input parameters before creating dataSourceInfo objects * @param name String containing name of the datasource From a2c4e341bc291696812589ed84b7709579cfd7b1 Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Mon, 11 Nov 2024 13:41:16 +0530 Subject: [PATCH 2/2] update error message to indicate the datasource name passed Signed-off-by: Saad Khan --- src/main/java/com/autotune/common/utils/CommonUtils.java | 2 +- src/main/java/com/autotune/utils/KruizeConstants.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/autotune/common/utils/CommonUtils.java b/src/main/java/com/autotune/common/utils/CommonUtils.java index ddd965d6e..08e24ff17 100644 --- a/src/main/java/com/autotune/common/utils/CommonUtils.java +++ b/src/main/java/com/autotune/common/utils/CommonUtils.java @@ -307,7 +307,7 @@ public static DataSourceInfo getDataSourceInfo(String dataSourceName) throws Exc // fetch the datasource from the DB datasource = dataSourceManager.fetchDataSourceFromDBByName(dataSourceName); if (isInvalidDataSource(datasource)) { - throw new Exception(KruizeConstants.DataSourceConstants.DataSourceErrorMsgs.INVALID_DATASOURCE_INFO); + throw new Exception(KruizeConstants.DataSourceConstants.DataSourceErrorMsgs.INVALID_DATASOURCE_INFO + dataSourceName); } } return datasource; diff --git a/src/main/java/com/autotune/utils/KruizeConstants.java b/src/main/java/com/autotune/utils/KruizeConstants.java index 0eb900aab..a081087b7 100644 --- a/src/main/java/com/autotune/utils/KruizeConstants.java +++ b/src/main/java/com/autotune/utils/KruizeConstants.java @@ -456,7 +456,7 @@ public static class DataSourceErrorMsgs { public static final String SERVICE_NOT_FOUND = "Can not find service with specified name."; public static final String ENDPOINT_NOT_FOUND = "Service endpoint not found."; public static final String MISSING_DATASOURCE_INFO = "Datasource is missing, add a valid Datasource"; - public static final String INVALID_DATASOURCE_INFO = "Datasource is either missing or is invalid"; + public static final String INVALID_DATASOURCE_INFO = "Datasource is either missing or is invalid: "; private DataSourceErrorMsgs() { }