Skip to content

Commit

Permalink
Change liveSpaceId and laneSpaceId type
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhiguo committed May 22, 2024
1 parent 294daa4 commit 003719b
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Location {
private String zone;

// Identifier for the live space, a logical partition within the deployment environment.
private Long liveSpaceId;
private String liveSpaceId;

// The unit within the live space, for further logical grouping.
private String unit;
Expand All @@ -45,7 +45,7 @@ public class Location {
private String cell;

// Identifier for the lane space, typically used for routing or organizational purposes.
private Long laneSpaceId;
private String laneSpaceId;

// The lane within the lane space, often related to specific functionalities or services.
// TODO multi lanes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class TrafficEvent {
/**
* The ID of the live space associated with the event.
*/
private final Long liveSpaceId;
private final String liveSpaceId;

/**
* The ID of the unit rule associated with the event.
Expand All @@ -113,7 +113,7 @@ public class TrafficEvent {
/**
* The ID of the lane space associated with the event.
*/
private final Long laneSpaceId;
private final String laneSpaceId;

/**
* The ID of the lane rule associated with the event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.jd.live.agent.governance.rule.tag.TagCondition;

import java.util.List;
import java.util.Objects;

/**
* Represents an endpoint in a distributed system, providing methods to access its properties and match against tag conditions.
Expand Down Expand Up @@ -180,8 +181,8 @@ default String getLane() {
* @param liveSpaceId The live space ID to match.
* @return true if the live space ID matches, false otherwise.
*/
default boolean isLiveSpace(long liveSpaceId) {
return liveSpaceId == Converts.getLong(getLiveSpaceId(), 0L);
default boolean isLiveSpace(String liveSpaceId) {
return Objects.equals(liveSpaceId, Converts.getString(getLiveSpaceId(), ""));
}

/**
Expand All @@ -201,7 +202,7 @@ default boolean isUnit(String unit) {
* @param unit The unit to match.
* @return true if both the live space ID and unit match, false otherwise.
*/
default boolean isUnit(long liveSpaceId, String unit) {
default boolean isUnit(String liveSpaceId, String unit) {
return isLiveSpace(liveSpaceId) && isUnit(unit);
}

Expand All @@ -222,7 +223,7 @@ default boolean isCell(String cell) {
* @param cell The cell to match.
* @return true if both the live space ID and cell match, false otherwise.
*/
default boolean isCell(long liveSpaceId, String cell) {
default boolean isCell(String liveSpaceId, String cell) {
return isLiveSpace(liveSpaceId) && isCell(cell);
}

Expand All @@ -232,8 +233,8 @@ default boolean isCell(long liveSpaceId, String cell) {
* @param laneSpaceId The lane space ID to match.
* @return true if the lane space ID matches, false otherwise.
*/
default boolean isLaneSpace(long laneSpaceId) {
return laneSpaceId == Converts.getLong(getLaneSpaceId(), 0L);
default boolean isLaneSpace(String laneSpaceId) {
return Objects.equals(laneSpaceId, Converts.getString(getLaneSpaceId(), ""));
}

/**
Expand All @@ -253,7 +254,7 @@ default boolean isLane(String lane) {
* @param lane The lane to match.
* @return true if both the lane space ID and lane match, false otherwise.
*/
default boolean isLane(long laneSpaceId, String lane) {
default boolean isLane(String laneSpaceId, String lane) {
return isLaneSpace(laneSpaceId) && isLane(lane);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public LaneMetadata parse() {
*/
protected LaneSpace parseLaneSpace() {
Cargo cargo = RequestContext.getCargo(laneConfig.getSpaceIdKey());
Long laneSpaceId = cargo == null ? null : Converts.getLong(cargo.getFirstValue());
String laneSpaceId = cargo == null ? null : Converts.getString(cargo.getFirstValue());
laneSpaceId = laneSpaceId != null ? laneSpaceId : application.getLocation().getLaneSpaceId();
return governancePolicy.getLaneSpace(laneSpaceId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public class GovernancePolicy {

private final transient Cache<String, DatabaseCluster> dbNameCache = new MapCache<>(new ListBuilder<>(() -> dbClusters, DatabaseCluster::getName));

private final transient Cache<Long, LiveSpace> liveSpaceCache = new MapCache<>(new ListBuilder<>(() -> liveSpaces, LiveSpace::getId));
private final transient Cache<String, LiveSpace> liveSpaceCache = new MapCache<>(new ListBuilder<>(() -> liveSpaces, LiveSpace::getId));

private final transient Cache<Long, LaneSpace> laneSpaceCache = new MapCache<>(new ListBuilder<>(() -> laneSpaces, LaneSpace::getId));
private final transient Cache<String, LaneSpace> laneSpaceCache = new MapCache<>(new ListBuilder<>(() -> laneSpaces, LaneSpace::getId));

private final transient Cache<String, Domain> domainCache = new MapCache<>(() -> {
Map<String, Domain> laneDomains = new HashMap<>();
Expand Down Expand Up @@ -140,7 +140,7 @@ public GovernancePolicy(List<LiveSpace> liveSpaces, List<Service> services) {
* @param id The ID of the live space to retrieve.
* @return The live space with the specified ID, or {@code null} if not found.
*/
public LiveSpace getLiveSpace(Long id) {
public LiveSpace getLiveSpace(String id) {
return id == null ? null : liveSpaceCache.get(id);
}

Expand All @@ -150,7 +150,7 @@ public LiveSpace getLiveSpace(Long id) {
* @param id The ID of the lane space to retrieve.
* @return The lane space with the specified ID, or {@code null} if not found.
*/
public LaneSpace getLaneSpace(Long id) {
public LaneSpace getLaneSpace(String id) {
return id == null ? null : laneSpaceCache.get(id);
}

Expand Down Expand Up @@ -202,8 +202,8 @@ public DatabaseCluster getDbCluster(String host, int port) {
* </p>
*/
public void cache() {
getLiveSpace(0L);
getLaneSpace(0L);
getLiveSpace("");
getLaneSpace("");
getDomain("");
getService("");
getDbCluster("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class LaneSpace {

@Getter
@Setter
private Long id;
private String id;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public String getMeta(String key) {
return metadata == null ? null : metadata.get(key);
}

public Long getId() {
Long result = spec == null ? null : spec.getId();
return result == null ? 0 : result;
public String getId() {
String result = spec == null ? null : spec.getId();
return result == null ? "" : result;
}

public List<Unit> getUnits() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class LiveSpec {
@JsonAlias("workspaceId")
@Getter
@Setter
private Long id;
private String id;

@Getter
@Setter
Expand Down Expand Up @@ -71,11 +71,11 @@ public class LiveSpec {
public LiveSpec() {
}

public LiveSpec(Long id) {
public LiveSpec(String id) {
this.id = id;
}

public LiveSpec(Long id, String code, String name, String tenantId) {
public LiveSpec(String id, String code, String name, String tenantId) {
this.id = id;
this.code = code;
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class ServicePolicy extends PolicyId implements Cloneable, PolicyInheritW
@Getter
private List<LanePolicy> lanePolicies;

private final transient Cache<Long, LanePolicy> lanePolicyCache = new MapCache<>(new ListBuilder<>(() -> lanePolicies, LanePolicy::getLaneSpaceId));
private final transient Cache<String, LanePolicy> lanePolicyCache = new MapCache<>(new ListBuilder<>(() -> lanePolicies, LanePolicy::getLaneSpaceId));

public ServicePolicy() {
}
Expand Down Expand Up @@ -169,12 +169,12 @@ protected <T extends PolicyInheritWithIdGen<T>> List<T> copy(List<T> sources,
return result;
}

public LanePolicy getLanePolicy(Long laneSpaceId) {
public LanePolicy getLanePolicy(String laneSpaceId) {
return lanePolicyCache.get(laneSpaceId);
}

protected void cache() {
getLanePolicy(0L);
getLanePolicy("");
if (livePolicy != null) {
livePolicy.cache();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class LanePolicy extends PolicyId implements PolicyInheritWithIdGen<LaneP
* The unique identifier of the lane space to which this policy applies. This ID is used to associate the policy
* with a specific lane or pathway within a system, enabling targeted policy enforcement and management.
*/
private Long laneSpaceId;
private String laneSpaceId;

@Override
public void supplement(LanePolicy source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class RoutePolicy extends PolicyId implements PolicyInheritWithIdGen<Rout
// List of tag rules
private List<TagRule> tagRules;

// Order number
private int order = 0;

// Mark whether the list is sorted. The transient keyword indicates that this field will not be serialized.
private transient boolean sorted;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ spring.cloud.consul.config.enabled=false
spring.cloud.loadbalancer.cache.ttl=1s
feign.httpclient.enabled=false
feign.okhttp.enabled=true
#spring.main.web-application-type=none
#spring.main.web-application-type=none
logging.level.root=${LIVE_LOG_LEVEL:INFO}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ spring:
server-addr: ${NACOS_ADDR}
username: ${NACOS_USERNAME}
password: ${NACOS_PASSWORD}
namespace: ${NACOS_NAMESPACE:}
namespace: ${NACOS_NAMESPACE:}

logging:
level:
root: ${LIVE_LOG_LEVEL:INFO}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
spring.cloud.consul.config.enabled=false
spring.cloud.loadbalancer.cache.ttl=1s
logging.level.root=${LIVE_LOG_LEVEL:INFO}
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public class EventExporter implements Subscription<TrafficEvent>, ExtensionIniti

private static final AttributeKey<String> ATTRIBUTE_APPLICATION = AttributeKey.stringKey(KEY_APPLICATION);

private static final AttributeKey<Long> ATTRIBUTE_LIVE_SPACE_ID = AttributeKey.longKey(KEY_LIVE_SPACE_ID);
private static final AttributeKey<String> ATTRIBUTE_LIVE_SPACE_ID = AttributeKey.stringKey(KEY_LIVE_SPACE_ID);

private static final AttributeKey<Long> ATTRIBUTE_LIVE_RULE_ID = AttributeKey.longKey(KEY_LIVE_RULE_ID);

private static final AttributeKey<Long> ATTRIBUTE_LANE_SPACE_ID = AttributeKey.longKey(KEY_LANE_SPACE_ID);
private static final AttributeKey<String> ATTRIBUTE_LANE_SPACE_ID = AttributeKey.stringKey(KEY_LANE_SPACE_ID);

private static final AttributeKey<Long> ATTRIBUTE_LANE_RULE_ID = AttributeKey.longKey(KEY_LANE_RULE_ID);

Expand Down
2 changes: 1 addition & 1 deletion joylive-package/src/main/assembly/config/lanes.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"id": 1,
"id": "1",
"lanes": [
{
"code": "production",
Expand Down
2 changes: 1 addition & 1 deletion joylive-package/src/main/assembly/config/livespaces.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"namespace": "apaas-livespace"
},
"spec": {
"id": 6,
"id": "v4bEh4kd6Jvu5QBX09qYq-qlbcs",
"code": "7Jei1Q5nlDbx0dRB4ZKd",
"name": "TestLiveSpace",
"version": "2023120609580935201",
Expand Down

0 comments on commit 003719b

Please sign in to comment.