diff --git a/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/clients/ParamsServiceClient.java b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/clients/ParamsServiceClient.java index e9aac4a..b2d423e 100644 --- a/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/clients/ParamsServiceClient.java +++ b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/clients/ParamsServiceClient.java @@ -1,6 +1,7 @@ package org.opendatamesh.platform.up.executor.gitlabci.clients; import com.fasterxml.jackson.databind.ObjectMapper; +import org.opendatamesh.platform.up.executor.gitlabci.config.ParamConfiguration; import org.opendatamesh.platform.up.executor.gitlabci.resources.ExecutorApiStandardErrors; import org.opendatamesh.platform.up.executor.gitlabci.resources.client.params.ParamResource; import org.opendatamesh.platform.up.executor.gitlabci.resources.exceptions.GitlabClientException; @@ -27,7 +28,7 @@ */ @Service public class ParamsServiceClient { - private static final Logger logger = LoggerFactory.getLogger(GitlabPipelineService.class); + private static final Logger logger = LoggerFactory.getLogger(ParamsServiceClient.class); protected String serverAddress; protected ObjectMapper mapper; public TestRestTemplate rest = new TestRestTemplate(); @@ -35,16 +36,13 @@ public class ParamsServiceClient { * The client UUID to authenticate with the service, in order to retrieve the secret value decrypted. */ private final String clientUUID; - /** - * The client prefix, used to set the prefix to the display name of the parameter. - */ - @Value("${odm.productplane.params-service.client-prefix}") - private String clientPrefix; + private final ParamConfiguration paramConfiguration; - public ParamsServiceClient(@Value("${odm.productplane.params-service.address}") String serverAddress, @Value("${odm.productplane.params-service.client-uuid}") String clientUUID) { - this.serverAddress = serverAddress; + public ParamsServiceClient(ParamConfiguration paramConfiguration) { + this.serverAddress = paramConfiguration.getServerAddress(); + this.paramConfiguration = paramConfiguration; this.mapper = ObjectMapperFactory.JSON_MAPPER; - this.clientUUID = clientUUID; + this.clientUUID = paramConfiguration.getClientUUID(); } /** @@ -134,7 +132,7 @@ public ResponseEntity getParamByName(String paramName) { public void deleteParam(String paramName) { HttpEntity entity = new HttpEntity<>(null, getHttpHeaders()); ResponseEntity param = getParamByName(paramName); - if (param.getStatusCode().is2xxSuccessful() && Objects.requireNonNull(param.getBody()).getDisplayName().startsWith(clientPrefix)) { + if (param.getStatusCode().is2xxSuccessful() && Objects.requireNonNull(param.getBody()).getDisplayName().startsWith(paramConfiguration.getClientPrefix())) { try { rest.exchange( apiUrl(ParamsServerApiRoutes.DELETE_PARAM), diff --git a/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/config/ParamConfiguration.java b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/config/ParamConfiguration.java new file mode 100644 index 0000000..9423f46 --- /dev/null +++ b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/config/ParamConfiguration.java @@ -0,0 +1,19 @@ +package org.opendatamesh.platform.up.executor.gitlabci.config; + +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Getter +public class ParamConfiguration { + /** + * The client prefix, used to set the prefix to the display name of the parameter. + */ + @Value("${odm.productplane.params-service.client-prefix}") + private String clientPrefix; + @Value("${odm.productplane.params-service.address}") + private String serverAddress; + @Value("${odm.productplane.params-service.client-uuid}") + private String clientUUID; +} diff --git a/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/config/PipelineConfiguration.java b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/config/PipelineConfiguration.java new file mode 100644 index 0000000..3e33773 --- /dev/null +++ b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/config/PipelineConfiguration.java @@ -0,0 +1,14 @@ +package org.opendatamesh.platform.up.executor.gitlabci.config; + +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Getter +public class PipelineConfiguration { + @Value("${odm.executors.gitlab.pipelines-config.polling.retries}") + private Integer pollingNumRetries; + @Value("${odm.executors.gitlab.pipelines-config.polling.interval}") + private Integer pollingIntervalSeconds; +} diff --git a/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/resources/exceptions/ODMApiStandardErrors.java b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/resources/exceptions/ODMApiStandardErrors.java index 9ef0397..de664c9 100644 --- a/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/resources/exceptions/ODMApiStandardErrors.java +++ b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/resources/exceptions/ODMApiStandardErrors.java @@ -6,5 +6,5 @@ public interface ODMApiStandardErrors { static ODMApiStandardErrors getNotFoundError(String className) { return null; - }; + } } diff --git a/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/services/GitlabConfigService.java b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/services/GitlabConfigService.java index 1543641..951af4a 100644 --- a/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/services/GitlabConfigService.java +++ b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/services/GitlabConfigService.java @@ -2,12 +2,12 @@ import lombok.RequiredArgsConstructor; import org.opendatamesh.platform.up.executor.gitlabci.clients.ParamsServiceClient; +import org.opendatamesh.platform.up.executor.gitlabci.config.ParamConfiguration; import org.opendatamesh.platform.up.executor.gitlabci.resources.ExecutorApiStandardErrors; import org.opendatamesh.platform.up.executor.gitlabci.resources.client.gitlab.GitlabConfigResource; import org.opendatamesh.platform.up.executor.gitlabci.resources.client.params.ParamResource; import org.opendatamesh.platform.up.executor.gitlabci.resources.exceptions.ConflictException; import org.opendatamesh.platform.up.executor.gitlabci.resources.exceptions.UnprocessableEntityException; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -23,8 +23,7 @@ public class GitlabConfigService { private final ParamsServiceClient paramsServiceClient; - @Value("${odm.productplane.params-service.client-prefix}") - private String clientPrefix; + private final ParamConfiguration paramConfiguration; /** * Add configurations to the parameter service. @@ -42,7 +41,7 @@ public ParamResource addConfig(GitlabConfigResource configResource) { ParamResource paramResource = new ParamResource(); paramResource.setParamName(configResource.getInstanceUrl()); paramResource.setParamValue(configResource.getInstanceToken()); - paramResource.setDisplayName(clientPrefix + configResource.getInstanceUrl()); + paramResource.setDisplayName(paramConfiguration.getClientPrefix() + configResource.getInstanceUrl()); paramResource.setSecret(true); ResponseEntity createdParam = paramsServiceClient.createParam(paramResource); @@ -69,7 +68,7 @@ public List getAllGitlabInstances() { List result = new ArrayList<>(); for (ParamResource param : params) { - if (param.getDisplayName().startsWith(clientPrefix)) { + if (param.getDisplayName().startsWith(paramConfiguration.getClientPrefix())) { result.add(param); } } diff --git a/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/services/GitlabPipelineService.java b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/services/GitlabPipelineService.java index 8228a1a..6564fdc 100644 --- a/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/services/GitlabPipelineService.java +++ b/src/main/java/org/opendatamesh/platform/up/executor/gitlabci/services/GitlabPipelineService.java @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import org.opendatamesh.platform.up.executor.gitlabci.clients.GitlabClient; import org.opendatamesh.platform.up.executor.gitlabci.clients.ParamsServiceClient; +import org.opendatamesh.platform.up.executor.gitlabci.config.PipelineConfiguration; import org.opendatamesh.platform.up.executor.gitlabci.dao.PipelineRun; import org.opendatamesh.platform.up.executor.gitlabci.dao.PipelineRunRepository; import org.opendatamesh.platform.up.executor.gitlabci.mappers.GitlabPipelineMapper; @@ -19,7 +20,6 @@ import org.opendatamesh.platform.up.executor.gitlabci.resources.exceptions.UnprocessableEntityException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -38,11 +38,8 @@ public class GitlabPipelineService { private final GitlabPipelineMapper pipelineMapper; private final PipelineRunRepository pipelineRunRepository; - @Value("${odm.executors.gitlab.pipelines-config.polling.retries}") - private Integer pollingNumRetries; - @Value("${odm.executors.gitlab.pipelines-config.polling.interval}") - private Integer pollingIntervalSeconds; private final ParamsServiceClient paramsServiceClient; + private final PipelineConfiguration pipelineConfiguration; private static final Logger logger = LoggerFactory.getLogger(GitlabPipelineService.class); @@ -201,13 +198,13 @@ public CompletableFuture getPipelineStatus(Long taskId) { Objects.requireNonNull(optGitlabInstance.getBody()).getParamValue() ); - while (counter < pollingNumRetries) { + while (counter < pipelineConfiguration.getPollingNumRetries()) { gitlabResponse = gitlabClient.readTask(pipelineRun.getProject(), pipelineRun.getRunId()); if (gitlabResponse.getStatusCode().is2xxSuccessful() && Objects.requireNonNull(gitlabResponse.getBody()).getStatus().equals(GitlabRunState.success.toString())) { break; } try { - Thread.sleep((long) pollingIntervalSeconds); + Thread.sleep((long) pipelineConfiguration.getPollingIntervalSeconds()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.warn("Polling thread error: " + e.getMessage());