Search in sources :

Example 11 with RetriableException

use of com.tencent.polaris.api.exception.RetriableException in project polaris-java by polarismesh.

the class DefaultProviderAPI method deRegister.

@Override
public void deRegister(InstanceDeregisterRequest req) throws PolarisException {
    checkAvailable("ProviderAPI");
    Validator.validateInstanceDeregisterRequest(req);
    long retryInterval = sdkContext.getConfig().getGlobal().getAPI().getRetryInterval();
    long timeout = getTimeout(req);
    while (timeout > 0) {
        long start = System.currentTimeMillis();
        ServiceCallResult serviceCallResult = new ServiceCallResult();
        CommonProviderRequest request = req.getRequest();
        try {
            serverConnector.deregisterInstance(request);
            serviceCallResult.setRetStatus(RetStatus.RetSuccess);
            serviceCallResult.setRetCode(ErrorCode.Success.getCode());
            LOG.info("deregister instance {} succ", req);
            return;
        } catch (PolarisException e) {
            serviceCallResult.setRetStatus(RetStatus.RetFail);
            serviceCallResult.setRetCode(exceptionToErrorCode(e).getCode());
            if (e instanceof RetriableException) {
                LOG.warn("instance deregister request error, retrying.", e);
                Utils.sleepUninterrupted(retryInterval);
                continue;
            }
            throw e;
        } finally {
            long delay = System.currentTimeMillis() - start;
            serviceCallResult.setDelay(delay);
            reportServerCall(serviceCallResult, request.getTargetServer(), "deRegister");
            timeout -= delay;
        }
    }
    throw new PolarisException(ErrorCode.API_TIMEOUT, "instance deregister request timeout.");
}
Also used : CommonProviderRequest(com.tencent.polaris.api.plugin.server.CommonProviderRequest) PolarisException(com.tencent.polaris.api.exception.PolarisException) ServiceCallResult(com.tencent.polaris.api.rpc.ServiceCallResult) RetriableException(com.tencent.polaris.api.exception.RetriableException)

Example 12 with RetriableException

use of com.tencent.polaris.api.exception.RetriableException in project polaris-java by polarismesh.

the class DefaultProviderAPI method register.

@Override
public InstanceRegisterResponse register(InstanceRegisterRequest req) throws PolarisException {
    checkAvailable("ProviderAPI");
    Validator.validateInstanceRegisterRequest(req);
    long retryInterval = sdkContext.getConfig().getGlobal().getAPI().getRetryInterval();
    long timeout = getTimeout(req);
    while (timeout > 0) {
        long start = System.currentTimeMillis();
        ServiceCallResult serviceCallResult = new ServiceCallResult();
        CommonProviderRequest request = req.getRequest();
        try {
            CommonProviderResponse response = serverConnector.registerInstance(request);
            LOG.info("register {}/{} instance {} succ", req.getNamespace(), req.getService(), response.getInstanceID());
            serviceCallResult.setRetStatus(RetStatus.RetSuccess);
            serviceCallResult.setRetCode(ErrorCode.Success.getCode());
            return new InstanceRegisterResponse(response.getInstanceID(), response.isExists());
        } catch (PolarisException e) {
            serviceCallResult.setRetStatus(RetStatus.RetFail);
            serviceCallResult.setRetCode(exceptionToErrorCode(e).getCode());
            if (e instanceof RetriableException) {
                LOG.warn("instance register request error, retrying.", e);
                Utils.sleepUninterrupted(retryInterval);
                continue;
            }
            throw e;
        } finally {
            long delay = System.currentTimeMillis() - start;
            serviceCallResult.setDelay(delay);
            reportServerCall(serviceCallResult, request.getTargetServer(), "register");
            timeout -= delay;
        }
    }
    throw new PolarisException(ErrorCode.API_TIMEOUT, "instance register request timeout.");
}
Also used : CommonProviderRequest(com.tencent.polaris.api.plugin.server.CommonProviderRequest) PolarisException(com.tencent.polaris.api.exception.PolarisException) ServiceCallResult(com.tencent.polaris.api.rpc.ServiceCallResult) CommonProviderResponse(com.tencent.polaris.api.plugin.server.CommonProviderResponse) InstanceRegisterResponse(com.tencent.polaris.api.rpc.InstanceRegisterResponse) RetriableException(com.tencent.polaris.api.exception.RetriableException)

Example 13 with RetriableException

use of com.tencent.polaris.api.exception.RetriableException in project polaris-java by polarismesh.

the class RemoteConfigFileRepoTest method testPullWithRetryException.

@Test
public void testPullWithRetryException() {
    ConfigFileMetadata configFileMetadata = ConfigFileTestUtils.assembleDefaultConfigFileMeta();
    when(configFileConnector.getConfigFile(any())).thenThrow(new RetriableException(ErrorCode.API_TIMEOUT, ""));
    RemoteConfigFileRepo remoteConfigFileRepo = new RemoteConfigFileRepo(sdkContext, configFileLongPollingService, configFileConnector, configFileMetadata);
    // 重试三次
    verify(configFileConnector, times(3)).getConfigFile(any());
    verify(configFileLongPollingService).addConfigFile(remoteConfigFileRepo);
    Assert.assertNull(remoteConfigFileRepo.getContent());
    Assert.assertEquals(0, remoteConfigFileRepo.getConfigFileVersion());
}
Also used : ConfigFileMetadata(com.tencent.polaris.configuration.api.core.ConfigFileMetadata) RetriableException(com.tencent.polaris.api.exception.RetriableException) Test(org.junit.Test)

Aggregations

RetriableException (com.tencent.polaris.api.exception.RetriableException)13 PolarisException (com.tencent.polaris.api.exception.PolarisException)7 ServiceKey (com.tencent.polaris.api.pojo.ServiceKey)6 PolarisGRPCGrpc (com.tencent.polaris.client.pb.PolarisGRPCGrpc)4 ResponseProto (com.tencent.polaris.client.pb.ResponseProto)4 CommonProviderRequest (com.tencent.polaris.api.plugin.server.CommonProviderRequest)3 CommonProviderResponse (com.tencent.polaris.api.plugin.server.CommonProviderResponse)3 ServiceCallResult (com.tencent.polaris.api.rpc.ServiceCallResult)3 ConsulException (com.ecwid.consul.ConsulException)2 ConfigFileProto (com.tencent.polaris.client.pb.ConfigFileProto)2 PolarisConfigGRPCGrpc (com.tencent.polaris.client.pb.PolarisConfigGRPCGrpc)2 ConfigFileMetadata (com.tencent.polaris.configuration.api.core.ConfigFileMetadata)2 Connection (com.tencent.polaris.plugins.connector.grpc.Connection)2 Test (org.junit.Test)2 NewService (com.ecwid.consul.v1.agent.model.NewService)1 ConfigFile (com.tencent.polaris.api.plugin.configuration.ConfigFile)1 ReportClientResponse (com.tencent.polaris.api.plugin.server.ReportClientResponse)1 InstanceRegisterResponse (com.tencent.polaris.api.rpc.InstanceRegisterResponse)1 ClientProto (com.tencent.polaris.client.pb.ClientProto)1