Skip to content

Commit

Permalink
Merge pull request #1358 from khansaad/fix-missing-datasource-issue
Browse files Browse the repository at this point in the history
Fix missing datasource issue on pod restart
  • Loading branch information
dinogun authored Nov 15, 2024
2 parents 3f68ee7 + 103d548 commit 4bd9baa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/autotune/common/utils/CommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/autotune/utils/KruizeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down

0 comments on commit 4bd9baa

Please sign in to comment.