Skip to content

Commit

Permalink
fix: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Pirovano committed Aug 7, 2024
1 parent 0d961c4 commit 2063c0f
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import org.opendatamesh.platform.up.executor.gitlabci.resources.client.gitlab.GitlabPipelineResource;
import org.opendatamesh.platform.up.executor.gitlabci.resources.client.gitlab.GitlabRunResource;
import org.opendatamesh.platform.up.executor.gitlabci.resources.client.gitlab.GitlabRunResourceResponse;
import org.opendatamesh.platform.up.executor.gitlabci.resources.exceptions.GitlabClientException;
import org.opendatamesh.platform.up.executor.gitlabci.utils.ObjectMapperFactory;
import org.springframework.boot.test.web.client.TestRestTemplate;
Expand Down Expand Up @@ -35,15 +35,15 @@ public GitlabClient(String serverAddress, String gitlabToken) {
* @param projectId the id of the gitlab project.
* @return the created GitLab pipeline.
*/
public ResponseEntity<GitlabRunResource> postTask(GitlabPipelineResource pipelineResource, String projectId) {
public ResponseEntity<GitlabRunResourceResponse> postTask(GitlabPipelineResource pipelineResource, String projectId) {
HttpEntity<GitlabPipelineResource> entity = new HttpEntity<>(pipelineResource, getHttpHeaders());

try {
return rest.exchange(
apiUrl(GitlabApiRoutes.GITLAB_PIPELINE_RUN),
HttpMethod.POST,
entity,
GitlabRunResource.class,
GitlabRunResourceResponse.class,
projectId
);
} catch (HttpClientErrorException e) {
Expand All @@ -58,14 +58,14 @@ public ResponseEntity<GitlabRunResource> postTask(GitlabPipelineResource pipelin
* @param pipelineId the id of the running pipeline.
* @return the status of the GitLab pipeline.
*/
public ResponseEntity<GitlabRunResource> readTask(String projectId, String pipelineId) {
public ResponseEntity<GitlabRunResourceResponse> readTask(String projectId, String pipelineId) {
HttpEntity<GitlabPipelineResource> entity = new HttpEntity<>(getHttpHeaders());
try {
return rest.exchange(
apiUrl(GitlabApiRoutes.GITLAB_PIPELINE_STATUS),
HttpMethod.GET,
entity,
GitlabRunResource.class,
GitlabRunResourceResponse.class,
projectId,
pipelineId
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opendatamesh.platform.up.executor.gitlabci.controllers;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -113,12 +114,14 @@ public TaskResource createTaskEndpoint(@RequestBody TaskResource task) {

/**
* Create a task based on the input received from the ODM DevOps module.
*
* @param task the received task
* @return the created task after a validation.
*/
public TaskResource createTask(TaskResource task) {

ObjectMapper objectMapper = new ObjectMapper();
ObjectMapper objectMapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
TemplateResource template;
ConfigurationResource configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@


@Data
@Entity(name = "PielineRun")
@Table(name = "PIPELINE_RUNS", schema = "ODMEXECUTOR")
@Entity
@Table(name = "PIPELINE_RUNS")
public class PipelineRun {
@Id
@Column(name = "TASK_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "PIPELINE_RUN_ID")
protected Long pipelineRunId;

@Column(name = "TASK_ID", unique = true)
protected Long taskId;

@Column(name = "RUN_ID")
Expand All @@ -37,5 +41,6 @@ public class PipelineRun {
@Column(name = "FINISHED_AT")
protected String finishedAt;

@Column(name = "GITLAB_INSTANCE_URL")
protected String gitlabInstanceUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.util.Optional;

public interface PipelineRunRepository extends JpaRepository<PipelineRun, Long>, JpaSpecificationExecutor<PipelineRun> {
Optional<PipelineRun> findByTaskId(Long taskId);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package org.opendatamesh.platform.up.executor.gitlabci.resources;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.Map;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConfigurationResource {
@JsonProperty("params")
private Map<String, String> params;
}
Original file line number Diff line number Diff line change
@@ -1,62 +1,48 @@
package org.opendatamesh.platform.up.executor.gitlabci.resources;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.Date;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class TaskResource {

@JsonProperty("id")
@Schema(description = "Auto generated Task ID")
Long id;
private Long id;

@JsonProperty("activityId")
@Schema(description = "ID of the parent Activity of the Task")
String activityId;
private String activityId;

@JsonIgnore
@Schema(description = "Logical name of the target task executor service", example = "azure-devops")
String executorRef;
private String executorRef;

@JsonProperty("callbackRef")
@Schema(description = "Reference for the callback from the executor service")
String callbackRef;
private String callbackRef;

@JsonProperty("template")
@Schema(description = "Template of the Task")
String template;
private String template;

@JsonProperty("configurations")
@Schema(description = "Configurations for the Task")
String configurations;
private String configurations;

@JsonProperty("status")
@Schema(description = "Task status")
TaskStatus status;
private TaskStatus status;

@JsonProperty("results")
@Schema(description = "Task results in case of successful execution")
String results;
private String results;

@JsonProperty("errors")
@Schema(description = "Task results in case of failures")
String errors;
private String errors;

@JsonProperty("createdAt")
@Schema(description = "Creation timestamp of the Task")
private Date createdAt;

@JsonProperty("startedAt")
@Schema(description = "Timestamp of the start of the Task execution")
private Date startedAt;

@JsonProperty("finishedAt")
@Schema(description = "Timestamp of the end of the Task execution")
private Date finishedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.Data;

@Data
@Data
public class TemplateResource {
private String projectId;
private String branch;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.opendatamesh.platform.up.executor.gitlabci.resources.client.gitlab;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class GitlabPipelineResource {
private String ref;
private List<Map<String, String>> variables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;

@Data
public class GitlabRunResource {
public class GitlabRunResourceResponse {
private String id;
private String iid;
@JsonProperty("project_id")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,34 @@
package org.opendatamesh.platform.up.executor.gitlabci.resources.client.params;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.Date;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ParamResource {

@JsonProperty("id")
@Schema(description = "Auto generated Param ID")
Long id;
private Long id;

@JsonProperty("paramName")
@Schema(description = "Name of the parameter (e.g., 'server.port')", required = true)
private String paramName;

@JsonProperty("paramValue")
@Schema(description = "Value for the parameter", required = true)
private String paramValue;

@JsonProperty("displayName")
@Schema(description = "Human-readable name of the parameter")
private String displayName;

@JsonProperty("description")
@Schema(description = "Description of the parameter")
private String description;

@JsonProperty("secret")
@Schema(description = "Whether the value of the parameter is a secret or not", defaultValue = "false")
private Boolean secret;

@JsonProperty("createdAt")
@Schema(description = "Timestamp of the Param creation")
private Date createdAt;

@JsonProperty("startedAt")
@Schema(description = "Timestamp of the last Param update")
private Date updatedAt;

Expand Down
Loading

0 comments on commit 2063c0f

Please sign in to comment.