Skip to content

Commit

Permalink
refactor: log code optimization update (apache#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtt40122 authored Feb 20, 2024
1 parent 1cd18d8 commit 37db60a
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ public void init() {
fileMonitorListener = new DefaultFileMonitorListener();

log.info("query channelDefineList:{}", gson.toJson(channelDefineList));
channelServiceList = channelDefineList.stream().map(channelDefine -> {
ChannelService channelService = this.channelServiceTrans(channelDefine);
if (null == channelService) {
failedChannelId.add(channelDefine.getChannelId());
}
return channelService;
}).filter(Objects::nonNull).collect(Collectors.toList());
channelServiceList = channelDefineList.stream()
.filter(channelDefine -> filterCollStart(channelDefine.getAppName()))
.map(channelDefine -> {
ChannelService channelService = this.channelServiceTrans(channelDefine);
if (null == channelService) {
failedChannelId.add(channelDefine.getChannelId());
}
return channelService;
}).filter(Objects::nonNull).collect(Collectors.toList());
// Delete failed channel
deleteFailedChannel(failedChannelId, this.channelDefineList, this.channelServiceList);
channelServiceList = new CopyOnWriteArrayList<>(channelServiceList);
Expand Down Expand Up @@ -533,13 +535,16 @@ private List<ChannelDefine> intersection(List<ChannelDefine> origin, List<Channe
*/
public void initIncrement(List<ChannelDefine> definesIncrement) {
List<Long> failedChannelId = Lists.newArrayList();
List<ChannelService> channelServices = definesIncrement.stream().filter(Objects::nonNull).map(channelDefine -> {
ChannelService channelService = channelServiceTrans(channelDefine);
if (null == channelService) {
failedChannelId.add(channelDefine.getChannelId());
}
return channelService;
}).filter(Objects::nonNull).collect(Collectors.toList());
List<ChannelService> channelServices = definesIncrement.stream()
.filter(Objects::nonNull)
.filter(channelDefine -> filterCollStart(channelDefine.getAppName()))
.map(channelDefine -> {
ChannelService channelService = channelServiceTrans(channelDefine);
if (null == channelService) {
failedChannelId.add(channelDefine.getChannelId());
}
return channelService;
}).filter(Objects::nonNull).collect(Collectors.toList());
deleteFailedChannel(failedChannelId, definesIncrement, channelServices);
List<Long> successChannelIds = channelStart(channelServices);
if (CollectionUtils.isNotEmpty(successChannelIds)) {
Expand All @@ -549,6 +554,14 @@ public void initIncrement(List<ChannelDefine> definesIncrement) {
log.info("[add config] after current channelDefineList:{},channelServiceList:{}", gson.toJson(this.channelDefineList), gson.toJson(gson.toJson(channelServiceList.stream().map(ChannelService::instanceId).collect(Collectors.toList()))));
}

private boolean filterCollStart(String appName) {
String serviceName = System.getenv("K8S_SERVICE");
if (StringUtils.isNotEmpty(serviceName) && StringUtils.isNotEmpty(appName)) {
return serviceName.contains(appName);
}
return true;
}


/**
* Send collection progress.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class ManagerUtil {

private static final String TAIL_KEY = "tail";

private static final String DEFAULT_SERVER_TYPE = "open";

private ManagerUtil() {

}
Expand Down Expand Up @@ -91,6 +93,10 @@ public static void getConfigFromNanos() {
* @return
*/
public static String getPhysicsDirectory(String logPath) {
String serverType = Config.ins().get("server.type", DEFAULT_SERVER_TYPE);
if (StringUtils.equals(DEFAULT_SERVER_TYPE, serverType)) {
return StringUtils.EMPTY;
}
String[] splitPath = StringUtils.split(logPath, "/");
if (splitPath.length > 2) {
return splitPath[splitPath.length - 2].trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public class Tpc {
@Resource
private MilogSpaceDao milogSpaceDao;

@Reference(interfaceClass = NodeFacade.class, group = "$tpc_dubbo_group", check = false, version = "1.0", timeout = 10000)
@Reference(interfaceClass = NodeFacade.class, group = "$tpc_dubbo_group", check = false, version = "1.0", timeout = 15000)
private NodeFacade tpcService;

@Reference(interfaceClass = NodeUserFacade.class, group = "$tpc_dubbo_group", check = false, version = "1.0", timeout = 10000)
@Reference(interfaceClass = NodeUserFacade.class, group = "$tpc_dubbo_group", check = false, version = "1.0", timeout = 15000)
private NodeUserFacade tpcUserService;

@Reference(interfaceClass = UserOrgFacade.class, group = "$tpc_dubbo_group", check = false, version = "1.0", timeout = 10000)
@Reference(interfaceClass = UserOrgFacade.class, group = "$tpc_dubbo_group", check = false, version = "1.0", timeout = 15000)
private UserOrgFacade userOrgFacade;

@Value("${tpc_node_code}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Result<List<MapDTO<String, Long>>> getMilogSpaces(Long tenantId) {
List<NodeVo> nodeVos = new ArrayList<>();

while (true) {
com.xiaomi.youpin.infra.rpc.Result<PageDataVo<NodeVo>> tpcRes = spaceAuthService.getUserPermSpace("", pageNum, Integer.MAX_VALUE);
com.xiaomi.youpin.infra.rpc.Result<PageDataVo<NodeVo>> tpcRes = spaceAuthService.getUserPermSpace("", pageNum, 100);

if (tpcRes.getCode() != 0) {
return Result.fail(CommonError.UNAUTHORIZED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -199,12 +200,12 @@ public Result<Integer> defavourite(Integer sort, Long id) {
}

public Result<List<SpaceTreeFavouriteDTO>> storeTree() {
List<SpaceTreeFavouriteDTO> dtoList = new ArrayList<>();
List<SpaceTreeFavouriteDTO> dtoList = new CopyOnWriteArrayList<>();
int pageNum = 1;
List<MilogSpaceDTO> spaceDTOList = new ArrayList<>();

while (true) {
com.xiaomi.youpin.infra.rpc.Result<PageDataVo<NodeVo>> userPermSpace = spaceAuthService.getUserPermSpace("", pageNum, Integer.MAX_VALUE);
com.xiaomi.youpin.infra.rpc.Result<PageDataVo<NodeVo>> userPermSpace = spaceAuthService.getUserPermSpace("", pageNum, 100);

if (userPermSpace.getCode() != 0) {
return Result.fail(CommonError.UNAUTHORIZED);
Expand Down
Loading

0 comments on commit 37db60a

Please sign in to comment.