Skip to content

Commit

Permalink
Merge branch 'jd-opensource:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanjinzhong authored Sep 3, 2024
2 parents 49a42d7 + 0e74a60 commit 38555af
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 33 deletions.
Binary file modified docs/image/weixin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ private Application createApplication() {
meta = new HashMap<>();
app.setMeta(meta);
}
setAgentVersion();
setAgentVersion(app);
location.setIp(Ipv4.getLocalIp());
location.setHost(Ipv4.getLocalHost());
setProperty(Constants.LABEL_INSTANCE_ID, app.getInstance());
Expand Down Expand Up @@ -623,12 +623,12 @@ private void setupLogger() {
location.getUnit(), location.getCell(), location.getLane()));
}

private void setAgentVersion() {
private void setAgentVersion(Application app) {
try {
CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource();
Artifact artifact = new Artifact(codeSource.getLocation().getPath());
String agentVersion = artifact.getVersion();
application.getMeta().put(Constants.LABEL_AGENT_VERSION, agentVersion);
app.getMeta().put(Constants.LABEL_AGENT_VERSION, agentVersion);
} catch (Throwable t) {
logger.error(t.getMessage(), t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
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.policy.live.*;
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 @@ -67,21 +64,16 @@ public <T extends InboundRequest> void filter(InboundInvocation<T> invocation, I

protected <T extends InboundRequest> CellAction cellAction(InboundInvocation<T> invocation) {
LiveMetadata liveMetadata = invocation.getLiveMetadata();
Unit centerUnit = liveMetadata.getCenterUnit();
Unit currentUnit = liveMetadata.getCurrentUnit();
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));
}
UnitRoute unitRoute = unitRule.getUnitRoute(centerUnit.getCode());
if (
invocation.isAccessible(currentCell) &&
unitRoute.getCellRoute(currentCell.getCode()) != null &&
invocation.isAccessible(unitRoute.getCellRoute(currentCell.getCode()).getAccessMode())
) {
UnitRoute unitRoute = currentUnit == null ? null : unitRule.getUnitRoute(currentUnit.getCode());
CellRoute cellRoute = unitRoute == null || currentCell == null ? null : unitRoute.getCellRoute(currentCell.getCode());
if (invocation.isAccessible(currentCell) && (cellRoute == null
|| !cellRoute.isEmpty() && invocation.isAccessible(cellRoute.getAccessMode()))) {
return new CellAction(CellActionType.FORWARD, null);
}
return new CellAction(CellActionType.FAILOVER, invocation.getError(FAILOVER_CELL_NOT_ACCESSIBLE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,17 @@ private Set<String> getUnavailableCells(OutboundInvocation<?> invocation) {
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) {
UnitRule rule = liveMetadata.getUnitRule();
for (Unit unit : units) {
UnitRoute unitRoute = rule == null ? null : rule.getUnitRoute(unit.getCode());
boolean unitAccessible = invocation.isAccessible(unit);
if (unit.getCells() != null) {
for (Cell cell : unit.getCells()) {
if (!unitAccessible || !invocation.isAccessible(cell) || restrictedCell.contains(cell.getCode())) {
CellRoute cellRoute = unitRoute == null ? null : unitRoute.getCellRoute(cell.getCode());
if (!unitAccessible
|| !invocation.isAccessible(cell)
|| cellRoute != null && (cellRoute.isEmpty() || !invocation.isAccessible(cellRoute.getAccessMode()))) {
unavailableCells.add(cell.getCode());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.jd.live.agent.plugin.registry.sofarpc.interceptor;

import com.alipay.sofa.rpc.bootstrap.ProviderBootstrap;
import com.alipay.sofa.rpc.config.ProviderConfig;
import com.alipay.sofa.rpc.config.ServerConfig;
import com.alipay.sofa.rpc.registry.utils.RegistryUtils;
Expand Down

0 comments on commit 38555af

Please sign in to comment.