Skip to content

Commit ff78e7b

Browse files
Merge pull request #89 from FederatedAI/develop-2.0.2
Compatible with the old version
2 parents 9ae0811 + cee5059 commit ff78e7b

File tree

7 files changed

+41
-27
lines changed

7 files changed

+41
-27
lines changed

fate-serving-federatedml/src/main/java/com/webank/ai/fate/serving/federatedml/PipelineModelProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public Map<String, Object> singleLocalPredict(Context context, Map<String, Objec
342342
if (logger.isDebugEnabled()) {
343343
logger.debug("component {} is Returnable return data {}", component, result);
344344
}
345-
if (StringUtils.isBlank(context.getVersion()) || Long.parseLong(context.getVersion()) < 200) {
345+
if (StringUtils.isBlank(context.getVersion()) || Double.parseDouble(context.getVersion()) < 200) {
346346
result.putAll(componentResult);
347347
}
348348
}

fate-serving-proxy/src/main/java/com/webank/ai/fate/serving/proxy/rpc/grpc/ProxyRequestHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ public void unaryCall(Proxy.Packet req, StreamObserver<Proxy.Packet> responseObs
6060

6161
public InboundPackage<Proxy.Packet> buildInboundPackage(Context context, Proxy.Packet req) {
6262
context.setCaseId(Long.toString(System.currentTimeMillis()));
63-
context.setVersion(req.getAuth().getVersion());
64-
if (StringUtils.isEmpty(context.getVersion())) {
65-
context.setVersion(Dict.DEFAULT_VERSION);
63+
if (StringUtils.isNotBlank(req.getHeader().getOperator())) {
64+
context.setVersion(req.getHeader().getOperator());
6665
}
6766
context.setGuestAppId(req.getHeader().getSrc().getPartyId());
6867
context.setHostAppid(req.getHeader().getDst().getPartyId());

fate-serving-proxy/src/main/java/com/webank/ai/fate/serving/proxy/rpc/router/ZkServingRouter.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,15 @@ private String getEnvironment(Context context, InboundPackage inboundPackage) {
8484
// guest, proxy -> serving
8585
return (String) inboundPackage.getHead().get(Dict.SERVICE_ID);
8686
}
87-
// default unaryCall
88-
if (GrpcType.INTRA_GRPC == context.getGrpcType()) {
89-
// guest, serving -> proxy
90-
// return Dict.ONLINE_ENVIRONMENT;
91-
return null;
92-
} else {
87+
88+
if (Dict.UNARYCALL.equals(context.getServiceName()) && context.getGrpcType() == GrpcType.INTER_GRPC) {
89+
// host, proxy -> serving
9390
Proxy.Packet sourcePacket = (Proxy.Packet) inboundPackage.getBody();
94-
if (MetaInfo.PROPERTY_COORDINATOR.equals(sourcePacket.getHeader().getDst().getPartyId())) {
95-
// host, proxy -> serving
96-
return FederatedModelUtils.getModelRouteKey(sourcePacket);
97-
} else {
98-
// exchange, proxy -> proxy
99-
// return Dict.ONLINE_ENVIRONMENT;
100-
return null;
101-
}
91+
return FederatedModelUtils.getModelRouteKey(context, sourcePacket);
10292
}
93+
94+
// default unaryCall proxy -> proxy
95+
return null;
10396
}
10497

10598
@Override

fate-serving-proxy/src/main/java/com/webank/ai/fate/serving/proxy/utils/FederatedModelUtils.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,48 @@
1717
package com.webank.ai.fate.serving.proxy.utils;
1818

1919
import com.webank.ai.fate.api.networking.proxy.Proxy;
20+
import com.webank.ai.fate.serving.core.bean.Context;
2021
import com.webank.ai.fate.serving.core.bean.EncryptMethod;
2122
import com.webank.ai.fate.serving.core.utils.EncryptUtils;
23+
import com.webank.ai.fate.serving.core.utils.JsonUtil;
2224
import org.apache.commons.lang3.StringUtils;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
2327

2428
import java.util.Arrays;
29+
import java.util.Map;
2530

2631
public class FederatedModelUtils {
2732

33+
private static final Logger logger = LoggerFactory.getLogger(FederatedModelUtils.class);
34+
2835
private static final String MODEL_KEY_SEPARATOR = "&";
2936

3037
public static String genModelKey(String tableName, String namespace) {
3138
return StringUtils.join(Arrays.asList(tableName, namespace), MODEL_KEY_SEPARATOR);
3239
}
3340

34-
public static String getModelRouteKey(Proxy.Packet packet) {
35-
String data = packet.getBody().getValue().toStringUtf8();
36-
Proxy.Model model = packet.getHeader().getTask().getModel();
37-
String key = genModelKey(model.getTableName(), model.getNamespace());
38-
String md5Key = EncryptUtils.encrypt(key, EncryptMethod.MD5);
39-
return md5Key;
41+
public static String getModelRouteKey(Context context, Proxy.Packet packet) {
42+
String namespace;
43+
String tableName;
44+
if (StringUtils.isBlank(context.getVersion()) || Double.parseDouble(context.getVersion()) < 200) {
45+
// version 1.x
46+
String data = packet.getBody().getValue().toStringUtf8();
47+
Map hostFederatedParams = JsonUtil.json2Object(data, Map.class);
48+
Map partnerModelInfo = (Map) hostFederatedParams.get("partnerModelInfo");
49+
namespace = partnerModelInfo.get("namespace").toString();
50+
tableName = partnerModelInfo.get("name").toString();
51+
} else {
52+
// version 2.0.0+
53+
Proxy.Model model = packet.getHeader().getTask().getModel();
54+
namespace = model.getNamespace();
55+
tableName = model.getTableName();
56+
}
57+
58+
String key = genModelKey(tableName, namespace);
59+
logger.info("get model route key by version: {} namespace: {} tablename: {}, key: {}", context.getVersion(), namespace, tableName, key);
60+
61+
return EncryptUtils.encrypt(key, EncryptMethod.MD5);
4062
}
4163

4264
}

fate-serving-server/src/main/java/com/webank/ai/fate/serving/grpc/service/HostInferenceService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void unaryCall(Proxy.Packet req, StreamObserver<Proxy.Packet> responseObs
5959
String tableName = req.getHeader().getTask().getModel().getTableName();
6060
context.setActionType(actionType);
6161
context.setVersion(req.getHeader().getOperator());
62-
if (StringUtils.isBlank(context.getVersion()) || Long.parseLong(context.getVersion()) < 200) {
62+
if (StringUtils.isBlank(context.getVersion()) || Double.parseDouble(context.getVersion()) < 200) {
6363
// 1.x
6464
Map hostFederatedParams = JsonUtil.json2Object(req.getBody().getValue().toStringUtf8(), Map.class);
6565
Map partnerModelInfo = (Map) hostFederatedParams.get("partnerModelInfo");

fate-serving-server/src/main/java/com/webank/ai/fate/serving/host/interceptors/HostModelInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void doPreProcess(Context context, InboundPackage inboundPackage, Outboun
4949
String tableName = servingServerContext.getModelTableName();
5050
String nameSpace = servingServerContext.getModelNamesapce();
5151
Model model;
52-
if (StringUtils.isBlank(context.getVersion()) || Long.parseLong(context.getVersion()) < 200) {
52+
if (StringUtils.isBlank(context.getVersion()) || Double.parseDouble(context.getVersion()) < 200) {
5353
model = modelManager.getPartnerModel(tableName, nameSpace);
5454
} else {
5555
model = modelManager.getModelByTableNameAndNamespace(tableName, nameSpace);

fate-serving-server/src/main/java/com/webank/ai/fate/serving/host/interceptors/HostParamInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void doPreProcess(Context context, InboundPackage inboundPackage, Outboun
4545
inboundPackage.setBody(params);
4646
} else {
4747
InferenceRequest inferenceRequest = JsonUtil.json2Object(reqBody, InferenceRequest.class);
48-
if (StringUtils.isBlank(context.getVersion()) || Long.parseLong(context.getVersion()) < 200) {
48+
if (StringUtils.isBlank(context.getVersion()) || Double.parseDouble(context.getVersion()) < 200) {
4949
Map hostParams = JsonUtil.json2Object(reqBody, Map.class);
5050
Preconditions.checkArgument(hostParams != null, "parse inference params error");
5151
Preconditions.checkArgument(hostParams.get("featureIdMap") != null, "parse inference params featureIdMap error");

0 commit comments

Comments
 (0)