diff --git a/src/main/java/com/autotune/common/datasource/DataSourceCollection.java b/src/main/java/com/autotune/common/datasource/DataSourceCollection.java index a67fbcfd1..9daf555a3 100644 --- a/src/main/java/com/autotune/common/datasource/DataSourceCollection.java +++ b/src/main/java/com/autotune/common/datasource/DataSourceCollection.java @@ -148,7 +148,11 @@ public void addDataSourcesFromConfigFile(String configFileName) throws Unsupport try { DataSourceInfo dataSourceInfo = new ExperimentDBService().loadDataSourceFromDBByName(name); if (null != dataSourceInfo) { - LOGGER.error("{} : {}", DATASOURCE_ALREADY_EXIST, name); + 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) { @@ -158,7 +162,7 @@ public void addDataSourcesFromConfigFile(String configFileName) throws Unsupport 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; + AuthenticationConfig authConfig = getAuthenticationDetails(dataSourceObject, name); try { JSONObject authenticationObj = dataSourceObject.optJSONObject(KruizeConstants.AuthenticationConstants.AUTHENTICATION); // create the corresponding authentication object @@ -185,6 +189,19 @@ public void addDataSourcesFromConfigFile(String configFileName) throws Unsupport } + 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 * 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 5a6a92914..e407d9e1b 100644 --- a/src/main/java/com/autotune/utils/KruizeConstants.java +++ b/src/main/java/com/autotune/utils/KruizeConstants.java @@ -459,7 +459,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() { }