diff --git a/arc-core/src/main/java/fr/insee/arc/core/model/Delimiters.java b/arc-core/src/main/java/fr/insee/arc/core/model/Delimiters.java index aa0c744ee..45722f266 100644 --- a/arc-core/src/main/java/fr/insee/arc/core/model/Delimiters.java +++ b/arc-core/src/main/java/fr/insee/arc/core/model/Delimiters.java @@ -14,7 +14,5 @@ private Delimiters() { public static final String SQL_TOKEN_DELIMITER = "_"; public static final String SQL_SCHEMA_DELIMITER = "."; - - public static final String KUBERNETES_TOKEN_DELIMITER="-"; } diff --git a/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/ApiManageExecutorDatabase.java b/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/ApiManageExecutorDatabase.java index 824adc63d..f25064880 100644 --- a/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/ApiManageExecutorDatabase.java +++ b/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/ApiManageExecutorDatabase.java @@ -7,8 +7,8 @@ import fr.insee.arc.core.service.kubernetes.configuration.BuildJsonConfiguration; import fr.insee.arc.core.service.kubernetes.security.BuildAccessToken; import fr.insee.arc.utils.exception.ArcException; -import fr.insee.arc.utils.kubernetes.KubernetesService; -import fr.insee.arc.utils.kubernetes.bo.KubernetesServiceResult; +import fr.insee.arc.utils.kubernetes.KubernetesApiService; +import fr.insee.arc.utils.kubernetes.bo.KubernetesApiResult; public class ApiManageExecutorDatabase { @@ -16,12 +16,12 @@ private ApiManageExecutorDatabase() { throw new IllegalStateException("Utility class"); } - public static List create() throws ArcException + public static List create() throws ArcException { - List results = new ArrayList<>(); + List results = new ArrayList<>(); // create stateful set of executor databases - results.add(KubernetesService.execute( + results.add(KubernetesApiService.execute( BuildRestQuery.stateful().getUri(), // BuildRestQuery.stateful().getHttpMethod(), // BuildAccessToken.retrieve().getToken(), // @@ -31,7 +31,7 @@ public static List create() throws ArcException for (String serviceJsonConfiguration : BuildJsonConfiguration.services()) { - results.add(KubernetesService.execute( + results.add(KubernetesApiService.execute( BuildRestQuery.service().getUri(), // BuildRestQuery.service().getHttpMethod(), // BuildAccessToken.retrieve().getToken(), // diff --git a/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/api/BuildRestQuery.java b/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/api/BuildRestQuery.java index 15fa04361..8d0fc765a 100644 --- a/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/api/BuildRestQuery.java +++ b/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/api/BuildRestQuery.java @@ -3,7 +3,7 @@ import org.springframework.http.HttpMethod; import fr.insee.arc.core.service.kubernetes.bo.RestQuery; -import fr.insee.arc.utils.kubernetes.KubernetesService; +import fr.insee.arc.utils.kubernetes.KubernetesApiService; import fr.insee.arc.utils.ressourceUtils.PropertiesHandler; public class BuildRestQuery { diff --git a/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/configuration/BuildJsonConfiguration.java b/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/configuration/BuildJsonConfiguration.java index 6a3d5660e..d4941fa18 100644 --- a/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/configuration/BuildJsonConfiguration.java +++ b/arc-core/src/main/java/fr/insee/arc/core/service/kubernetes/configuration/BuildJsonConfiguration.java @@ -12,6 +12,7 @@ import fr.insee.arc.core.service.p0initialisation.ApiInitialisationService; import fr.insee.arc.utils.exception.ArcException; import fr.insee.arc.utils.exception.ArcExceptionMessage; +import fr.insee.arc.utils.kubernetes.provider.KubernetesServiceLayer; import fr.insee.arc.utils.ressourceUtils.PropertiesHandler; public class BuildJsonConfiguration { @@ -66,7 +67,8 @@ private static String service(int executorReplicaIndex) throws ArcException { PropertiesHandler properties = PropertiesHandler.getInstance(); return readConfiguration("kubernetes/executorDatabaseServiceTemplate.json" - , JsonFileParameter.EXECUTOR_LABEL, String.join(Delimiters.KUBERNETES_TOKEN_DELIMITER, properties.getKubernetesExecutorLabel(), String.valueOf(executorReplicaIndex)) // + , JsonFileParameter.EXECUTOR_LABEL, + KubernetesServiceLayer.getName(properties.getKubernetesExecutorLabel(), executorReplicaIndex) ) ; } diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/KubernetesService.java b/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/KubernetesApiService.java similarity index 90% rename from arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/KubernetesService.java rename to arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/KubernetesApiService.java index 9f31aff87..e777d40b0 100644 --- a/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/KubernetesService.java +++ b/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/KubernetesApiService.java @@ -20,15 +20,15 @@ import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.http.HttpMethod; -import fr.insee.arc.utils.kubernetes.bo.KubernetesServiceResult; +import fr.insee.arc.utils.kubernetes.bo.KubernetesApiResult; -public class KubernetesService { +public class KubernetesApiService { - private KubernetesService() { + private KubernetesApiService() { throw new IllegalStateException("Utility class"); } - public static KubernetesServiceResult execute(String urlProvided, HttpMethod httpMethod, String token, + public static KubernetesApiResult execute(String urlProvided, HttpMethod httpMethod, String token, String json) { int responseCode = -1; StringBuilder response = new StringBuilder(); @@ -96,7 +96,7 @@ public void checkServerTrusted(java.security.cert.X509Certificate[] certs, Strin response.append(ExceptionUtils.getStackTrace(e)); } - return new KubernetesServiceResult(responseCode, response.toString()); + return new KubernetesApiResult(responseCode, response.toString()); } } diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/bo/KubernetesServiceResult.java b/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/bo/KubernetesApiResult.java similarity index 83% rename from arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/bo/KubernetesServiceResult.java rename to arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/bo/KubernetesApiResult.java index f05e24c46..3a6ef5971 100644 --- a/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/bo/KubernetesServiceResult.java +++ b/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/bo/KubernetesApiResult.java @@ -1,8 +1,8 @@ package fr.insee.arc.utils.kubernetes.bo; -public class KubernetesServiceResult { +public class KubernetesApiResult { - public KubernetesServiceResult(int responseCode, String response) { + public KubernetesApiResult(int responseCode, String response) { super(); this.responseCode = responseCode; this.response = response; diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/provider/KubernetesServiceLayer.java b/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/provider/KubernetesServiceLayer.java new file mode 100644 index 000000000..ae3b7bc28 --- /dev/null +++ b/arc-utils/src/main/java/fr/insee/arc/utils/kubernetes/provider/KubernetesServiceLayer.java @@ -0,0 +1,26 @@ +package fr.insee.arc.utils.kubernetes.provider; + +public class KubernetesServiceLayer { + + public static final String KUBERNETES_TOKEN_DELIMITER="-"; + public static final String USER_NAME="postgres"; + + + /** + * return service name for a given statefuleSet label and given replica index + * @param statefuleLabel + * @param executorReplicaIndex + * @return + */ + public static String getName(String statefulLabel, int executorReplicaIndex) + { + return String.join(KUBERNETES_TOKEN_DELIMITER, statefulLabel, String.valueOf(executorReplicaIndex)); + } + + + public static String getUri(String statefulLabel, int executorReplicaIndex) + { + return "jdbc:postgresql://"+getName(statefulLabel, executorReplicaIndex)+":5432/defaultdb"; + } + +} diff --git a/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/PropertiesHandler.java b/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/PropertiesHandler.java index f868de260..8d58042bb 100644 --- a/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/PropertiesHandler.java +++ b/arc-utils/src/main/java/fr/insee/arc/utils/ressourceUtils/PropertiesHandler.java @@ -9,6 +9,7 @@ import fr.insee.arc.utils.exception.ArcException; import fr.insee.arc.utils.exception.ArcExceptionMessage; +import fr.insee.arc.utils.kubernetes.provider.KubernetesServiceLayer; import fr.insee.arc.utils.utils.ManipString; @Service("properties") @@ -427,21 +428,41 @@ public List getConnectionProperties() { if (this.connectionProperties == null) { connectionProperties = new ArrayList<>(); - String[] databaseUrls = ConnectionAttribute.unserialize(this.databaseUrl); - String[] databaseUsernames = ConnectionAttribute.unserialize(this.databaseUsername); - String[] databasePasswords = ConnectionAttribute.unserialize(this.databasePassword); - String[] databaseDriverClassNames = ConnectionAttribute.unserialize(this.databaseDriverClassName); - - for (int tokenIndex = 0; tokenIndex < databaseUrls.length; tokenIndex++) { + if (this.isKubernetesActive()) + { connectionProperties - .add(new ConnectionAttribute(databaseUrls[tokenIndex], databaseUsernames[tokenIndex], - databasePasswords[tokenIndex], databaseDriverClassNames[tokenIndex])); + .add(new ConnectionAttribute(this.databaseUrl, this.databaseUsername, this.databasePassword, this.databaseDriverClassName)); + + for (int i=0; i connectionProperties) { this.connectionProperties = connectionProperties; } diff --git a/arc-web/src/main/java/fr/insee/arc/web/gui/maintenanceoperation/service/ServiceViewKubernetes.java b/arc-web/src/main/java/fr/insee/arc/web/gui/maintenanceoperation/service/ServiceViewKubernetes.java index 33c41a5ef..928ccaf2b 100644 --- a/arc-web/src/main/java/fr/insee/arc/web/gui/maintenanceoperation/service/ServiceViewKubernetes.java +++ b/arc-web/src/main/java/fr/insee/arc/web/gui/maintenanceoperation/service/ServiceViewKubernetes.java @@ -7,7 +7,7 @@ import fr.insee.arc.core.service.kubernetes.ApiManageExecutorDatabase; import fr.insee.arc.utils.exception.ArcException; -import fr.insee.arc.utils.kubernetes.bo.KubernetesServiceResult; +import fr.insee.arc.utils.kubernetes.bo.KubernetesApiResult; @Service public class ServiceViewKubernetes extends InteractorMaintenanceOperations { @@ -17,9 +17,9 @@ public String createDatabases(Model model) { StringBuilder result = new StringBuilder(); try { - List results = ApiManageExecutorDatabase.create(); + List results = ApiManageExecutorDatabase.create(); - for (KubernetesServiceResult r : results) + for (KubernetesApiResult r : results) { result.append(r.toString()); }