TASK:AiDA
This commit is contained in:
@@ -3671,4 +3671,58 @@ public class PythonService {
|
||||
//生成失败
|
||||
throw new BusinessException("Atribute recognition exception!");
|
||||
}
|
||||
|
||||
public JSONObject designBatch(DesignPythonObjects designPythonObjects) {
|
||||
// todo 限流校验
|
||||
// AccessLimitUtils.validate("design",5);
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||
.build();
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
//关闭FastJson的引用检测 防止出现$ref 现象
|
||||
|
||||
String param = JSON.toJSONString(designPythonObjects, SerializerFeature.DisableCircularReferenceDetect);
|
||||
log.info("design请求python 参数:####{}", param);
|
||||
RequestBody body = RequestBody.create(mediaType, param);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/design_batch_generate")
|
||||
// .url(fastApiPythonAddress + "/api/design")
|
||||
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response;
|
||||
String responseBody;
|
||||
try {
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
AccessLimitUtils.validateOut("design");
|
||||
log.error("PythonService##design异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
|
||||
//去除限流
|
||||
// AccessLimitUtils.validateOut("design");
|
||||
if (response.isSuccessful()) {
|
||||
try {
|
||||
if (Objects.nonNull(response.body())) {
|
||||
responseBody = response.body().string();
|
||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||
log.info("PythonService##responseObject###{}", responseObject);
|
||||
return responseObject;
|
||||
}
|
||||
throw new BusinessException("design.interface.exception");
|
||||
} catch (IOException | JSONException e) {
|
||||
log.error("PythonService##design异常###{}", e.getMessage());
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
}
|
||||
log.error("PythonService##design异常response###{}", response);
|
||||
//生成失败
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user