Skip to content

Commit

Permalink
fix: sql execution repository error
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqi committed Jan 24, 2025
1 parent 0104845 commit 8dd1c8c
Show file tree
Hide file tree
Showing 22 changed files with 859 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class PipelineExecutionImpl implements PipelineExecution, Serializable {
private String name;
private String remark;
private String origin;
private String pipelineConfigId;
private Long pipelineConfigId;
private boolean limitConcurrent = false;
private int maxConcurrentExecutions = 0;
private boolean keepWaitingPipelines = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package cn.sliew.carp.module.orca.core.persistence.sql;

import cn.sliew.carp.framework.dag.service.CarpDagOrcaPipelineService;
import cn.sliew.carp.framework.dag.service.*;
import cn.sliew.carp.framework.dag.service.dto.orca.CarpDagOrcaPipelineDTO;
import cn.sliew.carp.framework.dag.service.param.orca.CarpDagOrcaPipelineAddParam;
import cn.sliew.carp.framework.dag.service.param.orca.CarpDagOrcaPipelineStageAddParam;
Expand All @@ -41,6 +41,10 @@
public class SqlExecutionRepository implements ExecutionRepository {

private CarpDagOrcaPipelineService carpDagOrcaPipelineService;
private DagConfigService dagConfigService;
private DagConfigStepService dagConfigStepService;
private DagConfigLinkService dagConfigLinkService;


public SqlExecutionRepository(CarpDagOrcaPipelineService carpDagOrcaPipelineService) {
this.carpDagOrcaPipelineService = carpDagOrcaPipelineService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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 cn.sliew.carp.module.orca.core.persistence.sql.service;

import cn.sliew.carp.module.orca.spinnaker.api.model.ExecutionType;
import cn.sliew.carp.module.orca.spinnaker.api.model.pipeline.PipelineExecution;

public interface CarpOrcaPipelineService {

PipelineExecution get(ExecutionType type, Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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 cn.sliew.carp.module.orca.core.persistence.sql.service.convert;

import cn.sliew.carp.framework.common.convert.BaseConvert;
import cn.sliew.carp.framework.dag.algorithm.DAG;
import cn.sliew.carp.framework.dag.service.dto.DagConfigComplexDTO;
import cn.sliew.carp.framework.dag.service.dto.DagConfigLinkDTO;
import cn.sliew.carp.framework.dag.service.dto.DagConfigStepDTO;
import cn.sliew.carp.module.orca.core.persistence.sql.service.dto.CarpDagOrcaPipelineConfigDTO;
import cn.sliew.carp.module.orca.core.persistence.sql.service.dto.CarpDagOrcaPipelineStageConfigDTO;
import cn.sliew.milky.common.util.JacksonUtil;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

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

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CarpDagOrcaPipelineConfigConvert extends BaseConvert<DagConfigComplexDTO, CarpDagOrcaPipelineConfigDTO> {
CarpDagOrcaPipelineConfigConvert INSTANCE = Mappers.getMapper(CarpDagOrcaPipelineConfigConvert.class);

@Override
default DagConfigComplexDTO toDo(CarpDagOrcaPipelineConfigDTO dto) {
throw new UnsupportedOperationException();
}

@Override
default CarpDagOrcaPipelineConfigDTO toDto(DagConfigComplexDTO entity) {
CarpDagOrcaPipelineConfigDTO dto = new CarpDagOrcaPipelineConfigDTO();
BeanUtils.copyProperties(entity, dto);
if (entity.getDagMeta() != null) {
dto.setMeta(
JacksonUtil.toObject(entity.getDagMeta(),
CarpDagOrcaPipelineConfigDTO.CarpDagOrcaPipelineConfigMeta.class));
}
if (entity.getDagAttrs() != null) {
dto.setAttrs(
JacksonUtil.toObject(entity.getDagMeta(),
CarpDagOrcaPipelineConfigDTO.CarpDagOrcaPipelineConfigAttrs.class));
}

DAG<CarpDagOrcaPipelineStageConfigDTO> dag = new DAG<>();
List<DagConfigStepDTO> steps = entity.getSteps();
List<DagConfigLinkDTO> links = entity.getLinks();
if (CollectionUtils.isEmpty(steps) == false) {
Map<String, CarpDagOrcaPipelineStageConfigDTO> stepMap = new HashMap<>();
for (DagConfigStepDTO step : steps) {
CarpDagOrcaPipelineStageConfigDTO stageConfigDTO = CarpDagOrcaPipelineStageConfigConvert.INSTANCE.toDto(step);
stepMap.put(stageConfigDTO.getUuid(), stageConfigDTO);
dag.addNode(stageConfigDTO);
}
links.forEach(link -> dag.addEdge(stepMap.get(link.getFromStepId()), stepMap.get(link.getToStepId())));
}
dto.setStages(dag);
return dto;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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 cn.sliew.carp.module.orca.core.persistence.sql.service.convert;

import cn.sliew.carp.framework.common.convert.BaseConvert;
import cn.sliew.carp.framework.dag.algorithm.DAG;
import cn.sliew.carp.framework.dag.service.dto.DagInstanceComplexDTO;
import cn.sliew.carp.framework.dag.service.dto.DagLinkDTO;
import cn.sliew.carp.framework.dag.service.dto.DagStepDTO;
import cn.sliew.carp.module.orca.core.persistence.sql.service.dto.CarpDagOrcaPipelineDTO;
import cn.sliew.carp.module.orca.core.persistence.sql.service.dto.CarpDagOrcaPipelineStageDTO;
import cn.sliew.milky.common.util.JacksonUtil;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

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

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CarpDagOrcaPipelineConvert extends BaseConvert<DagInstanceComplexDTO, CarpDagOrcaPipelineDTO> {
CarpDagOrcaPipelineConvert INSTANCE = Mappers.getMapper(CarpDagOrcaPipelineConvert.class);

@Override
default DagInstanceComplexDTO toDo(CarpDagOrcaPipelineDTO dto) {
throw new UnsupportedOperationException();
}

@Override
default CarpDagOrcaPipelineDTO toDto(DagInstanceComplexDTO entity) {
CarpDagOrcaPipelineDTO dto = new CarpDagOrcaPipelineDTO();
BeanUtils.copyProperties(entity, dto);
if (entity.getStartTime() != null) {
dto.setStartTime(entity.getStartTime().toInstant());
}
if (entity.getEndTime() != null) {
dto.setEndTime(entity.getEndTime().toInstant());
}
if (entity.getBody() != null) {
dto.setBody(JacksonUtil.toObject(entity.getBody(), CarpDagOrcaPipelineDTO.CarpDagOrcaPipelineBody.class));
}
DAG<CarpDagOrcaPipelineStageDTO> dag = new DAG<>();
List<DagStepDTO> steps = entity.getSteps();
List<DagLinkDTO> links = entity.getLinks();
if (CollectionUtils.isEmpty(steps) == false) {
Map<String, CarpDagOrcaPipelineStageDTO> stepMap = new HashMap<>();
for (DagStepDTO step : steps) {
CarpDagOrcaPipelineStageDTO stageDTO = CarpDagOrcaPipelineStageConvert.INSTANCE.toDto(step);
stepMap.put(step.getDagConfigStep().getStepId(), stageDTO);
dag.addNode(stageDTO);
}
links.forEach(link -> dag.addEdge(stepMap.get(link.getDagConfigLink().getFromStepId()), stepMap.get(link.getDagConfigLink().getToStepId())));
}
dto.setStages(dag);
return dto;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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 cn.sliew.carp.module.orca.core.persistence.sql.service.convert;

import cn.sliew.carp.framework.common.convert.BaseConvert;
import cn.sliew.carp.framework.dag.service.dto.DagConfigStepDTO;
import cn.sliew.carp.module.orca.core.persistence.sql.service.dto.CarpDagOrcaPipelineStageConfigDTO;
import cn.sliew.milky.common.util.JacksonUtil;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.BeanUtils;

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CarpDagOrcaPipelineStageConfigConvert extends BaseConvert<DagConfigStepDTO, CarpDagOrcaPipelineStageConfigDTO> {
CarpDagOrcaPipelineStageConfigConvert INSTANCE = Mappers.getMapper(CarpDagOrcaPipelineStageConfigConvert.class);

@Override
default DagConfigStepDTO toDo(CarpDagOrcaPipelineStageConfigDTO dto) {
throw new UnsupportedOperationException();
}

@Override
default CarpDagOrcaPipelineStageConfigDTO toDto(DagConfigStepDTO entity) {
CarpDagOrcaPipelineStageConfigDTO dto = new CarpDagOrcaPipelineStageConfigDTO();
BeanUtils.copyProperties(entity, dto);
dto.setUuid(entity.getStepId());
dto.setName(entity.getStepName());
if (entity.getStepMeta() != null) {
dto.setMeta(JacksonUtil.toObject(entity.getStepMeta(), CarpDagOrcaPipelineStageConfigDTO.CarpDagOrcaPipelineStageConfigMeta.class));
}
if (entity.getStepAttrs() != null) {
dto.setAttrs(JacksonUtil.toObject(entity.getStepAttrs(), CarpDagOrcaPipelineStageConfigDTO.CarpDagOrcaPipelineStageConfigAttrs.class));
}
return dto;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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 cn.sliew.carp.module.orca.core.persistence.sql.service.convert;

import cn.sliew.carp.framework.common.convert.BaseConvert;
import cn.sliew.carp.framework.dag.service.dto.DagStepDTO;
import cn.sliew.carp.module.orca.core.persistence.sql.service.dto.CarpDagOrcaPipelineStageDTO;
import cn.sliew.milky.common.util.JacksonUtil;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.BeanUtils;

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CarpDagOrcaPipelineStageConvert extends BaseConvert<DagStepDTO, CarpDagOrcaPipelineStageDTO> {
CarpDagOrcaPipelineStageConvert INSTANCE = Mappers.getMapper(CarpDagOrcaPipelineStageConvert.class);

@Override
default DagStepDTO toDo(CarpDagOrcaPipelineStageDTO dto) {
throw new UnsupportedOperationException();
}

@Override
default CarpDagOrcaPipelineStageDTO toDto(DagStepDTO entity) {
CarpDagOrcaPipelineStageDTO dto = new CarpDagOrcaPipelineStageDTO();
BeanUtils.copyProperties(entity, dto);
if (entity.getStartTime() != null) {
dto.setStartTime(entity.getStartTime().toInstant());
}
if (entity.getEndTime() != null) {
dto.setEndTime(entity.getEndTime().toInstant());
}
if (entity.getBody() != null) {
dto.setBody(JacksonUtil.toObject(entity.getBody(), CarpDagOrcaPipelineStageDTO.CarpDagOrcaPipelineStageBody.class));
}
return dto;
}

}
Loading

0 comments on commit 8dd1c8c

Please sign in to comment.