Skip to content

Commit

Permalink
refactor: improve code layering of trace-etl module (#439)
Browse files Browse the repository at this point in the history
* refactor: improve code layering of trace-etl module

* refactor: improve code layering of trace-etl module

---------

Co-authored-by: EricDing <128116675+sadadw1@users.noreply.github.com>
  • Loading branch information
psxjoy and sadadw1 authored Sep 10, 2024
1 parent 48614f8 commit 02ccb5b
Show file tree
Hide file tree
Showing 9 changed files with 426 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.xiaomi.hera.trace.etl.es.config;

import com.xiaomi.hera.trace.etl.mapper.HeraTraceEtlConfigMapper;
import com.xiaomi.hera.trace.etl.service.ManagerService;
import com.xiaomi.hera.trace.etl.service.impl.ManagerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -28,14 +30,14 @@
*/
@Configuration
public class ServiceConfiguration {

@Autowired
private HeraTraceEtlConfigMapper heraTraceEtlConfigMapper;


@Bean
public ManagerService managerService(){
return new ManagerService(heraTraceEtlConfigMapper);
public ManagerService managerService() {
return new ManagerServiceImpl(heraTraceEtlConfigMapper);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.xiaomi.hera.trace.etl.api.service.TraceEtlService;
import com.xiaomi.hera.trace.etl.mapper.HeraTraceEtlConfigMapper;
import com.xiaomi.hera.trace.etl.service.ManagerService;
import com.xiaomi.hera.trace.etl.service.impl.ManagerServiceImpl;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
Expand All @@ -39,7 +40,7 @@ public class ServiceConfiguration {

@Bean
public ManagerService managerService(){
return new ManagerService(heraTraceEtlConfigMapper,traceEtlService);
return new ManagerServiceImpl(heraTraceEtlConfigMapper,traceEtlService);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.xiaomi.hera.trace.etl.mapper.HeraTraceEtlConfigMapper;
import com.xiaomi.hera.trace.etl.service.ManagerService;
import com.xiaomi.hera.trace.etl.service.impl.ManagerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -34,7 +35,7 @@ public class ServiceConfiguration {

@Bean
public ManagerService managerService(){
return new ManagerService(heraTraceEtlConfigMapper);
return new ManagerServiceImpl(heraTraceEtlConfigMapper);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,16 @@
*/
package com.xiaomi.hera.trace.etl.service;

import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

/**
* @Description
* @Author dingtao
* @Date 2022/7/6 7:49 下午
*/
@Service
public class HeraContextService {

public Set<String> getHeraContextKeys(String heraContext){
Set<String> result = new HashSet<>();
String[] split = heraContext.split(";");
for(String keyValue : split){
String[] kv = keyValue.split(":");
result.add(kv[0]);
}
return result;
}
public interface HeraContextService {

public String getHeraContextValue(String heraContext, String key){
String[] split = heraContext.split(";");
for(String keyValue : split){
String[] kv = keyValue.split(":");
if(key.equals(kv[0])){
return kv[1];
}
}
return null;
}
Set<String> getHeraContextKeys(String heraContext);

String getHeraContextValue(String heraContext, String key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,135 +13,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.xiaomi.hera.trace.etl.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaomi.hera.trace.etl.api.service.TraceEtlService;
import com.xiaomi.hera.trace.etl.domain.HeraTraceConfigVo;
import com.xiaomi.hera.trace.etl.domain.HeraTraceEtlConfig;
import com.xiaomi.hera.trace.etl.domain.PageData;
import com.xiaomi.hera.trace.etl.mapper.HeraTraceEtlConfigMapper;
import com.xiaomi.hera.trace.etl.util.pool.AsyncNotify;
import com.xiaomi.youpin.infra.rpc.Result;
import com.xiaomi.youpin.infra.rpc.errors.GeneralCodes;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
* @Description Initialize through the bootstrap project BeanConfig to avoid unwanted project startup errors
* @Author dingtao
* @Date 2022/4/18 3:31 下午
*/
@Slf4j
public class ManagerService {

@Autowired
private AsyncNotify asyncNotify;

private TraceEtlService traceEtlService;

private HeraTraceEtlConfigMapper heraTraceEtlConfigMapper;

public ManagerService(HeraTraceEtlConfigMapper heraTraceEtlConfigMapper) {
this.heraTraceEtlConfigMapper = heraTraceEtlConfigMapper;
}

public ManagerService(HeraTraceEtlConfigMapper heraTraceEtlConfigMapper, TraceEtlService traceEtlService) {
this.heraTraceEtlConfigMapper = heraTraceEtlConfigMapper;
this.traceEtlService = traceEtlService;
}

public List<HeraTraceEtlConfig> getAll(HeraTraceConfigVo vo) {
QueryWrapper<HeraTraceEtlConfig> qw = new QueryWrapper();
qw.eq("status", "1");
if (vo.getBindId() != null) {
qw.eq("bind_id", vo.getBindId());
}
if (StringUtils.isNotEmpty(vo.getAppName())) {
qw.eq("app_name", vo.getAppName());
}
return heraTraceEtlConfigMapper.selectList(qw);
}

public PageData<List<HeraTraceEtlConfig>> getAllPage(HeraTraceConfigVo vo) {
PageData<List<HeraTraceEtlConfig>> pageData = new PageData<>();
pageData.setPage(vo.getPage());
pageData.setPageSize(vo.getPageSize());
PageHelper.startPage(vo.getPage(), vo.getPageSize());
Page<HeraTraceEtlConfig> all = heraTraceEtlConfigMapper.getAllPage(vo.getUser());
PageInfo<HeraTraceEtlConfig> heraTraceEtlConfigPageInfo = new PageInfo<>(all);
pageData.setTotal(heraTraceEtlConfigPageInfo.getTotal());
pageData.setPages(heraTraceEtlConfigPageInfo.getPages());
pageData.setList(heraTraceEtlConfigPageInfo.getList());
return pageData;
}

public HeraTraceEtlConfig getByBaseInfoId(Integer baseInfoId) {
return heraTraceEtlConfigMapper.getByBaseInfoId(baseInfoId);
}

public HeraTraceEtlConfig getById(Integer id) {
return heraTraceEtlConfigMapper.selectById(id);
}

public Result insertOrUpdate(HeraTraceEtlConfig config, String user) {
Date now = new Date();
int i = 0;
if (config.getId() == null) {
// Check for existence
HeraTraceEtlConfig byBaseInfoId = heraTraceEtlConfigMapper.getByBaseInfoId(config.getBaseInfoId());
if(byBaseInfoId != null){
return Result.fail(GeneralCodes.InternalError, "The item configuration already exists. Do not add it again");
}
config.setCreateTime(now);
config.setUpdateTime(now);
config.setCreateUser(user);
i = heraTraceEtlConfigMapper.insert(config);
if (i > 0) {
asyncNotify.submit(() -> {
try {
traceEtlService.insertConfig(config);
} catch (Exception e) {
log.error("insert sync etl error : ", e);
}
});
}
} else {
config.setUpdateTime(now);
config.setUpdateUser(user);
i = heraTraceEtlConfigMapper.updateById(config);
if (i > 0) {
asyncNotify.submit(() -> {
try {
traceEtlService.updateConfig(config);
} catch (Exception e) {
log.error("update sync etl error : ", e);
}
});
}
}
return i > 0 ? Result.success(null) : Result.fail(GeneralCodes.InternalError, "Operation failure");
}

public int delete(HeraTraceEtlConfig config) {
HeraTraceEtlConfig heraTraceEtlConfig = heraTraceEtlConfigMapper.selectById(config.getId());
int i = heraTraceEtlConfigMapper.deleteById(config.getId());
if (i > 0) {
asyncNotify.submit(() -> {
try {
traceEtlService.deleteConfig(heraTraceEtlConfig);
} catch (Exception e) {
log.error("delete sync etl error : ", e);
}
});
}
return i;
}
public interface ManagerService {


List<HeraTraceEtlConfig> getAll(HeraTraceConfigVo vo);

PageData<List<HeraTraceEtlConfig>> getAllPage(HeraTraceConfigVo vo);

HeraTraceEtlConfig getByBaseInfoId(Integer baseInfoId);

HeraTraceEtlConfig getById(Integer id);

Result insertOrUpdate(HeraTraceEtlConfig config, String user);

int delete(HeraTraceEtlConfig config);
}
Loading

0 comments on commit 02ccb5b

Please sign in to comment.