Skip to content
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

fix(controller): make resource pool feature compatible with the old data #986

Merged
merged 1 commit into from
Aug 25, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import ai.starwhale.mlops.domain.swds.po.SWDatasetVersionEntity;
import ai.starwhale.mlops.domain.system.mapper.ResourcePoolMapper;
import ai.starwhale.mlops.domain.system.po.ResourcePoolEntity;
import ai.starwhale.mlops.domain.system.resourcepool.ResourcePoolConverter;
import ai.starwhale.mlops.domain.user.UserConvertor;
import ai.starwhale.mlops.exception.ConvertException;
import ai.starwhale.mlops.exception.SWProcessException;
Expand Down Expand Up @@ -61,6 +62,9 @@ public class JobConvertor implements Convertor<JobEntity, JobVO> {
@Resource
private ResourcePoolMapper resourcePoolMapper;

@Resource
private ResourcePoolConverter resourcePoolConverter;

@Override
public JobVO convert(JobEntity jobEntity) throws ConvertException {
List<RuntimeVO> runtimeByVersionIds = runtimeService.findRuntimeByVersionIds(
Expand All @@ -76,6 +80,7 @@ public JobVO convert(JobEntity jobEntity) throws ConvertException {
.collect(Collectors.toList());

ResourcePoolEntity resourcePoolEntity = resourcePoolMapper.findById(jobEntity.getResourcePoolId());
var resourcePool = resourcePoolConverter.toResourcePool(resourcePoolEntity);

return JobVO.builder()
.id(idConvertor.convert(jobEntity.getId()))
Expand All @@ -91,7 +96,7 @@ public JobVO convert(JobEntity jobEntity) throws ConvertException {
.jobStatus(jobEntity.getJobStatus())
.stopTime(localDateTimeConvertor.convert(jobEntity.getFinishedTime()))
.comment(jobEntity.getComment())
.resourcePool(resourcePoolEntity.getLabel())
.resourcePool(resourcePool.getLabel())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public ResourcePoolEntity toEntity(ResourcePool pool) {
}

public ResourcePool toResourcePool(ResourcePoolEntity entity) {
if (entity == null) {
return ResourcePool.empty();
}

return ResourcePool.builder().label(entity.getLabel()).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(label);
}
public static ResourcePool empty() {
return new ResourcePool("default");
}
}