use of com.tencent.polaris.api.plugin.server.ReportClientResponse in project polaris-java by polarismesh.
the class ReportClientTask method run.
@Override
public void run() {
ReportClientResponse rsp = doReport(clientHost, version);
if (null == rsp) {
return;
}
LOG.debug("current client Region:{}, Zone:{}, Campus:{}", rsp.getRegion(), rsp.getZone(), rsp.getCampus());
shareContext.setValue(LocationLevel.region.name(), rsp.getRegion());
shareContext.setValue(LocationLevel.zone.name(), rsp.getZone());
shareContext.setValue(LocationLevel.campus.name(), rsp.getCampus());
shareContext.notifyAllForLocationReady();
}
use of com.tencent.polaris.api.plugin.server.ReportClientResponse in project polaris-java by polarismesh.
the class ReportClientTask method doReport.
private ReportClientResponse doReport(String clientHost, String version) {
BaseEngine engine = BaseEngine.getEngine(shareContext);
ReportClientRequest req = new ReportClientRequest();
req.setClientHost(clientHost);
req.setVersion(version);
ReportClientResponse rsp = null;
long start = System.currentTimeMillis();
ServiceCallResult serviceCallResult = new ServiceCallResult();
try {
rsp = extensions.getServerConnector().reportClient(req);
serviceCallResult.setRetStatus(RetStatus.RetSuccess);
serviceCallResult.setRetCode(ErrorCode.Success.getCode());
} catch (PolarisException e) {
serviceCallResult.setRetStatus(RetStatus.RetFail);
serviceCallResult.setRetCode(e.getCode().getCode());
LOG.warn("fail to report client info(clientHost={}, version={}), cause is {}", clientHost, version, e.getMessage());
}
long delay = System.currentTimeMillis() - start;
serviceCallResult.setDelay(delay);
if (null != engine) {
engine.reportServerCall(serviceCallResult, req.getTargetServer(), "reportClient");
}
return rsp;
}
use of com.tencent.polaris.api.plugin.server.ReportClientResponse in project polaris-java by polarismesh.
the class CompositeConnector method reportClient.
@Override
public ReportClientResponse reportClient(ReportClientRequest req) throws PolarisException {
checkDestroyed();
ReportClientResponse response = null;
for (DestroyableServerConnector sc : serverConnectors) {
ReportClientResponse temp = sc.reportClient(req);
if (DefaultPlugins.SERVER_CONNECTOR_GRPC.equals(sc.getName())) {
response = temp;
}
}
return response;
}
use of com.tencent.polaris.api.plugin.server.ReportClientResponse in project polaris-java by polarismesh.
the class GrpcConnector method reportClient.
@Override
public ReportClientResponse reportClient(ReportClientRequest req) throws PolarisException {
checkDestroyed();
waitDiscoverReady();
Connection connection = null;
ServiceKey serviceKey = new ServiceKey(req.getNamespace(), req.getService());
try {
connection = connectionManager.getConnection(GrpcUtil.OP_KEY_REPORT_CLIENT, ClusterType.SERVICE_DISCOVER_CLUSTER);
req.setTargetServer(connectionToTargetNode(connection));
PolarisGRPCGrpc.PolarisGRPCBlockingStub stub = PolarisGRPCGrpc.newBlockingStub(connection.getChannel());
GrpcUtil.attachRequestHeader(stub, GrpcUtil.nextHeartbeatReqId());
ClientProto.Client request = buildReportRequest(req);
ResponseProto.Response response = stub.reportClient(request);
LOG.debug("reportClient req:{}, rsp:{}", req, TextFormat.shortDebugString(response));
GrpcUtil.checkResponse(response);
ReportClientResponse rsp = new ReportClientResponse();
if (null == response.getClient().getLocation()) {
throw new IllegalStateException(String.format("unexpected null response from clientReport api, response:%s", TextFormat.shortDebugString(response)));
}
rsp.setCampus(response.getClient().getLocation().getCampus().getValue());
rsp.setZone(response.getClient().getLocation().getZone().getValue());
rsp.setRegion(response.getClient().getLocation().getRegion().getValue());
return rsp;
} catch (Throwable t) {
if (t instanceof PolarisException) {
// 服务端异常不进行重试
throw t;
}
if (null != connection) {
connection.reportFail();
}
throw new RetriableException(ErrorCode.NETWORK_ERROR, String.format("fail to report client host %s, version %s service %s", req.getClientHost(), req.getVersion(), serviceKey), t);
} finally {
if (null != connection) {
connection.release(GrpcUtil.OP_KEY_REPORT_CLIENT);
}
}
}
Aggregations