Search in sources :

Example 1 with ReportClientResponse

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();
}
Also used : ReportClientResponse(com.tencent.polaris.api.plugin.server.ReportClientResponse)

Example 2 with ReportClientResponse

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;
}
Also used : PolarisException(com.tencent.polaris.api.exception.PolarisException) ReportClientRequest(com.tencent.polaris.api.plugin.server.ReportClientRequest) ServiceCallResult(com.tencent.polaris.api.rpc.ServiceCallResult) BaseEngine(com.tencent.polaris.client.api.BaseEngine) ReportClientResponse(com.tencent.polaris.api.plugin.server.ReportClientResponse)

Example 3 with ReportClientResponse

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;
}
Also used : ReportClientResponse(com.tencent.polaris.api.plugin.server.ReportClientResponse) DestroyableServerConnector(com.tencent.polaris.plugins.connector.common.DestroyableServerConnector)

Example 4 with ReportClientResponse

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);
        }
    }
}
Also used : ClientProto(com.tencent.polaris.client.pb.ClientProto) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) PolarisGRPCGrpc(com.tencent.polaris.client.pb.PolarisGRPCGrpc) PolarisException(com.tencent.polaris.api.exception.PolarisException) ReportClientResponse(com.tencent.polaris.api.plugin.server.ReportClientResponse) ResponseProto(com.tencent.polaris.client.pb.ResponseProto) RetriableException(com.tencent.polaris.api.exception.RetriableException)

Aggregations

ReportClientResponse (com.tencent.polaris.api.plugin.server.ReportClientResponse)4 PolarisException (com.tencent.polaris.api.exception.PolarisException)2 RetriableException (com.tencent.polaris.api.exception.RetriableException)1 ReportClientRequest (com.tencent.polaris.api.plugin.server.ReportClientRequest)1 ServiceKey (com.tencent.polaris.api.pojo.ServiceKey)1 ServiceCallResult (com.tencent.polaris.api.rpc.ServiceCallResult)1 BaseEngine (com.tencent.polaris.client.api.BaseEngine)1 ClientProto (com.tencent.polaris.client.pb.ClientProto)1 PolarisGRPCGrpc (com.tencent.polaris.client.pb.PolarisGRPCGrpc)1 ResponseProto (com.tencent.polaris.client.pb.ResponseProto)1 DestroyableServerConnector (com.tencent.polaris.plugins.connector.common.DestroyableServerConnector)1