Skip to content

Commit

Permalink
Merge branch 'main' of github.com:yuanjinzhong/joylive-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhong.yuan committed Sep 3, 2024
2 parents 9a8ef38 + 81aaab6 commit 13b7c5f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import com.jd.live.agent.governance.invoke.filter.InboundFilter;
import com.jd.live.agent.governance.invoke.filter.InboundFilterChain;
import com.jd.live.agent.governance.invoke.metadata.LiveMetadata;
import com.jd.live.agent.governance.policy.live.Cell;
import com.jd.live.agent.governance.policy.live.Unit;
import com.jd.live.agent.governance.policy.live.UnitRoute;
import com.jd.live.agent.governance.policy.live.UnitRule;
import com.jd.live.agent.governance.request.ServiceRequest.InboundRequest;

import static com.jd.live.agent.governance.invoke.Invocation.FAILOVER_CELL_NOT_ACCESSIBLE;
Expand Down Expand Up @@ -62,13 +66,25 @@ public <T extends InboundRequest> void filter(InboundInvocation<T> invocation, I
}

protected <T extends InboundRequest> CellAction cellAction(InboundInvocation<T> invocation) {
LiveMetadata metadata = invocation.getLiveMetadata();
if (metadata.getUnitRule() != null && !invocation.isAccessible(metadata.getCurrentCell())) {
// TODO add cell route access mode
LiveMetadata liveMetadata = invocation.getLiveMetadata();
Unit centerUnit = liveMetadata.getCenterUnit();
Cell currentCell = liveMetadata.getCurrentCell();
UnitRule unitRule = liveMetadata.getUnitRule();
if (unitRule == null) {
return new CellAction(CellActionType.FORWARD, null);
}
if (currentCell == null || centerUnit == null) {
return new CellAction(CellActionType.FAILOVER, invocation.getError(FAILOVER_CELL_NOT_ACCESSIBLE));
} else {
}
UnitRoute unitRoute = unitRule.getUnitRoute(centerUnit.getCode());
if (
invocation.isAccessible(currentCell) &&
unitRoute.getCellRoute(currentCell.getCode()) != null &&
invocation.isAccessible(unitRoute.getCellRoute(currentCell.getCode()).getAccessMode())
) {
return new CellAction(CellActionType.FORWARD, null);
}
return new CellAction(CellActionType.FAILOVER, invocation.getError(FAILOVER_CELL_NOT_ACCESSIBLE));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,32 @@ private Set<String> getUnavailableCells(OutboundInvocation<?> invocation) {
LiveMetadata liveMetadata = invocation.getLiveMetadata();
LiveSpace liveSpace = liveMetadata.getLiveSpace();
List<Unit> units = liveSpace == null ? null : liveSpace.getSpec().getUnits();

HashSet<String> restrictedCell = new HashSet<>();
UnitRule rule = liveMetadata.getUnitRule();
if (rule != null && rule.getUnitRoutes() != null) {
for (UnitRoute unitRoute : rule.getUnitRoutes()) {
if (unitRoute != null && unitRoute.getCells() != null) {
for (CellRoute cellRoute : unitRoute.getCells()) {
if (cellRoute != null && !invocation.isAccessible(cellRoute.getAccessMode())) {
restrictedCell.add(cellRoute.getCode());
}
}
}
}
}

if (units != null) {
for (Unit unit : units) {
boolean unitAccessible = invocation.isAccessible(unit);
if (unit.getCells() != null) {
for (Cell cell : unit.getCells()) {
if (!unitAccessible || !invocation.isAccessible(cell)) {
if (!unitAccessible || !invocation.isAccessible(cell) || restrictedCell.contains(cell.getCode())) {
unavailableCells.add(cell.getCode());
}
}
}
}
// TODO add cell route access mode
}
return unavailableCells;
}
Expand Down Expand Up @@ -233,10 +247,9 @@ private Election sponsor(OutboundInvocation<?> invocation,

// Iterate through the cells in the unit route.
for (CellRoute cellRoute : unitRoute.getCells()) {
// TODO add cell route access mode
Cell cell = cellRoute.getCell();
// Check if the cell is accessible and has a non-empty route.
if (invocation.isAccessible(cell) && !cellRoute.isEmpty()) {
if (invocation.isAccessible(cell) && !cellRoute.isEmpty() && invocation.isAccessible(cellRoute.getAccessMode())) {
// Get the instance count for the cell from the unit group, if available.
Integer instance = unitGroup == null ? null : unitGroup.getSize(cellRoute.getCode());
instance = instance == null ? 0 : instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.jd.live.agent.governance.policy.live;

import com.jd.live.agent.core.parser.json.JsonAlias;
import com.jd.live.agent.governance.policy.AccessMode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
Expand Down Expand Up @@ -48,6 +49,10 @@ public class CellRoute {
@JsonAlias("ratio")
private int weight;

@Getter
@Setter
private AccessMode accessMode = AccessMode.READ_WRITE;

private transient Cell cell;

public boolean isAllow(String name) {
Expand Down
26 changes: 26 additions & 0 deletions joylive-demo/joylive-demo-sofarpc/README-zh.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 注意点
`sofarpc-demo`这个模块可以用jdk8正常编译运行;但是如果在终端对整个项目编译,则需要将jdk版本设置为17,推荐安装`jenv`动态切换jdk版本
> 列出可选的jdk版本
```shell
➜ joylive-agent git:(main) ✗ jenv versions
system
1.8
* 1.8.0.291 (set by /Users/yuanjinzhong/.jenv/version)
11
11.0
11.0.18
17
17.0
17.0.8
openjdk64-17.0.8
oracle64-1.8.0.291
oracle64-11.0.18

```
> 选择jdk 17
```shell
➜ joylive-agent git:(main) ✗ jenv global 17
```

# 接下来
查看 [快速开始](./docs/cn/quickstart.md)
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#server:
# port: 8081

spring:
application:
name: sofarpc-consumer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public RegistryInterceptor(Application application, AgentLifecycle lifecycle, Re

@Override
protected ServiceInstance getInstance(MethodContext ctx) {
ProviderConfig<?> config = ((ProviderBootstrap<?>) ctx.getTarget()).getProviderConfig();
ProviderConfig<?> config = ctx.getArgument(0);
if (config.isRegister()) {
List<ServiceProtocol> protocols = new ArrayList<>();
List<ServerConfig> serverConfigs = config.getServer();
Expand Down

0 comments on commit 13b7c5f

Please sign in to comment.