Skip to content

Refactored task manifest persistence to use JPA #3614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spring-cloud-dataflow-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-keyvalue</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.dataflow.core;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest;

/**
* Description of an execution of a task including resource to be executed and how it was configured via Spring Cloud
* Data Flow
*
* @author Mark Pollack
* @author Michael Minella
* @since 2.3
*/
@Entity
@Table(name = "TaskExecutionManifest")
public class TaskExecutionManifest extends AbstractEntity {

@NotNull
@Column(name = "task_execution_id")
private Long taskExecutionId;

@NotNull
@Column(name = "task_name")
private String taskName;

@NotNull
@Column(name = "task_execution_manifest")
@Convert(converter = TaskExecutionManifestConverter.class)
private Manifest manifest = new Manifest();

public String getTaskName() {
return taskName;
}

public void setTaskName(String taskName) {
this.taskName = taskName;
}

public Manifest getManifest() {
return manifest;
}

public void setManifest(Manifest manifest) {
this.manifest = manifest;
}

/**
* Id for the task execution this manifest is related to.
*
* @return task execution id
*/
public Long getTaskExecutionId() {
return taskExecutionId;
}

/**
* Set the task execution id this manfiest is related to.
*
* @param taskExecutionId id of the task execution
*/
public void setTaskExecutionId(Long taskExecutionId) {
this.taskExecutionId = taskExecutionId;
}

public static class Manifest {

private AppDeploymentRequest taskDeploymentRequest;

private List<AppDeploymentRequest> subTaskDeploymentRequests;

private String platformName;

public AppDeploymentRequest getTaskDeploymentRequest() {
return taskDeploymentRequest;
}

public void setTaskDeploymentRequest(AppDeploymentRequest taskDeploymentRequest) {
this.taskDeploymentRequest = taskDeploymentRequest;
}

public List<AppDeploymentRequest> getSubTaskDeploymentRequests() {
return subTaskDeploymentRequests;
}

public void setSubTaskDeploymentRequests(List<AppDeploymentRequest> subTaskDeploymentRequests) {
this.subTaskDeploymentRequests = subTaskDeploymentRequests;
}

public String getPlatformName() {
return platformName;
}

public void setPlatformName(String platformName) {
this.platformName = platformName;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.dataflow.core;

import javax.persistence.AttributeConverter;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
* @author Michael Minella
*/
@Component
public class TaskExecutionManifestConverter implements AttributeConverter<TaskExecutionManifest.Manifest, String> {

private static ObjectMapper objectMapper;

@Autowired
public void setObjectMapper(ObjectMapper objectMapper){
TaskExecutionManifestConverter.objectMapper = objectMapper;
}

@Override
public String convertToDatabaseColumn(TaskExecutionManifest.Manifest taskManifest) {
try {
return this.objectMapper.writeValueAsString(taskManifest);
}
catch (JsonProcessingException e) {
throw new IllegalArgumentException("Unable to serialize manifest to JSON", e);
}
}

@Override
public TaskExecutionManifest.Manifest convertToEntityAttribute(String s) {
try {
return this.objectMapper.readValue(s, TaskExecutionManifest.Manifest.class);
}
catch (JsonProcessingException e) {
throw new IllegalArgumentException("Unable to deserialize JSON into a manifest", e);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Collections;
import java.util.List;

import org.springframework.cloud.dataflow.core.TaskManifest;
import org.springframework.cloud.dataflow.core.TaskExecutionManifest;
import org.springframework.cloud.task.repository.TaskExecution;
import org.springframework.util.Assert;

Expand All @@ -36,7 +36,7 @@ public class TaskJobExecutionRel {

private final List<Long> jobExecutionIds;

private final TaskManifest taskManifest;
private final TaskExecutionManifest taskExecutionManifest;

/**
* Constructor that establishes the relationship between a {@link TaskExecution} and
Expand All @@ -55,12 +55,12 @@ public TaskJobExecutionRel(TaskExecution taskExecution, List<Long> jobExecutionI
*
* @param taskExecution to be associated with the job execution ids.
* @param jobExecutionIds to be associated with the task execution.
* @param taskManifest to be associated with the task execution
* @param taskExecutionManifest to be associated with the task execution
*/
public TaskJobExecutionRel(TaskExecution taskExecution, List<Long> jobExecutionIds, TaskManifest taskManifest) {
public TaskJobExecutionRel(TaskExecution taskExecution, List<Long> jobExecutionIds, TaskExecutionManifest taskExecutionManifest) {
Assert.notNull(taskExecution, "taskExecution must not be null");;
this.taskExecution = taskExecution;
this.taskManifest = taskManifest;
this.taskExecutionManifest = taskExecutionManifest;
if (jobExecutionIds == null) {
this.jobExecutionIds = Collections.emptyList();
}
Expand All @@ -87,7 +87,7 @@ public List<Long> getJobExecutionIds() {
/**
* @return the task manifest associated with the {@link TaskExecution}. Could be null.
*/
public TaskManifest getTaskManifest() {
return taskManifest;
public TaskExecutionManifest getTaskExecutionManifest() {
return taskExecutionManifest;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

import org.springframework.batch.core.JobExecution;
import org.springframework.cloud.dataflow.core.TaskExecutionManifest;
import org.springframework.cloud.dataflow.rest.job.TaskJobExecutionRel;
import org.springframework.cloud.task.repository.TaskExecution;
import org.springframework.hateoas.PagedModel;
Expand Down Expand Up @@ -137,10 +138,12 @@ public TaskExecutionResource(TaskJobExecutionRel taskJobExecutionRel) {
this.jobExecutionIds = Collections
.unmodifiableList(new ArrayList<>(taskJobExecutionRel.getJobExecutionIds()));
}
if (taskJobExecutionRel.getTaskManifest() != null) {
this.resourceUrl = taskJobExecutionRel.getTaskManifest().getTaskDeploymentRequest().getResource().toString();
this.appProperties = taskJobExecutionRel.getTaskManifest().getTaskDeploymentRequest().getDefinition().getProperties();
this.deploymentProperties = taskJobExecutionRel.getTaskManifest().getTaskDeploymentRequest().getDeploymentProperties();
if (taskJobExecutionRel.getTaskExecutionManifest() != null) {
TaskExecutionManifest.Manifest manifest = taskJobExecutionRel.getTaskExecutionManifest().getManifest();

this.resourceUrl = manifest.getTaskDeploymentRequest().getResource().toString();
this.appProperties = manifest.getTaskDeploymentRequest().getDefinition().getProperties();
this.deploymentProperties = manifest.getTaskDeploymentRequest().getDeploymentProperties();
}
}

Expand Down
Loading