Search in sources :

Example 1 with Connection

use of com.tencent.polaris.plugins.connector.grpc.Connection in project polaris-java by polarismesh.

the class PolarisConfigFileConnector method getConfigFile.

@Override
public ConfigFileResponse getConfigFile(ConfigFile configFile) {
    Connection connection = null;
    try {
        connection = connectionManager.getConnection(OP_KEY_GET_CONFIG_FILE, ClusterType.SERVICE_DISCOVER_CLUSTER);
        // grpc 调用
        PolarisConfigGRPCGrpc.PolarisConfigGRPCBlockingStub stub = PolarisConfigGRPCGrpc.newBlockingStub(connection.getChannel());
        // 附加通用 header
        GrpcUtil.attachRequestHeader(stub, GrpcUtil.nextInstanceRegisterReqId());
        // 执行调用
        ConfigFileProto.ConfigFileResponse response = stub.getConfigFile(transfer2DTO(configFile));
        return handleResponse(response);
    } catch (Throwable t) {
        // 网络访问异常
        if (connection != null) {
            connection.reportFail();
        }
        throw new RetriableException(ErrorCode.NETWORK_ERROR, String.format("failed to load config file. namespace = %s, group = %s, file = %s", configFile.getNamespace(), configFile.getFileGroup(), configFile.getFileName()), t);
    } finally {
        if (connection != null) {
            connection.release(OP_KEY_GET_CONFIG_FILE);
        }
    }
}
Also used : ConfigFileProto(com.tencent.polaris.client.pb.ConfigFileProto) Connection(com.tencent.polaris.plugins.connector.grpc.Connection) PolarisConfigGRPCGrpc(com.tencent.polaris.client.pb.PolarisConfigGRPCGrpc) RetriableException(com.tencent.polaris.api.exception.RetriableException)

Example 2 with Connection

use of com.tencent.polaris.plugins.connector.grpc.Connection in project polaris-java by polarismesh.

the class PolarisConfigFileConnector method watchConfigFiles.

@Override
public ConfigFileResponse watchConfigFiles(List<ConfigFile> configFiles) {
    Connection connection = null;
    try {
        connection = connectionManager.getConnection(OP_KEY_GET_CONFIG_FILE, ClusterType.SERVICE_DISCOVER_CLUSTER);
        // grpc 调用
        PolarisConfigGRPCGrpc.PolarisConfigGRPCBlockingStub stub = PolarisConfigGRPCGrpc.newBlockingStub(connection.getChannel());
        // 附加通用 header
        GrpcUtil.attachRequestHeader(stub, GrpcUtil.nextInstanceRegisterReqId());
        // 执行调用
        List<ConfigFileProto.ConfigFileDTO> dtos = Lists.newLinkedList();
        for (ConfigFile configFile : configFiles) {
            dtos.add(transfer2DTO(configFile));
        }
        ConfigFileProto.WatchConfigFileRequest request = ConfigFileProto.WatchConfigFileRequest.newBuilder().addAllWatchFiles(dtos).build();
        ConfigFileProto.ConfigFileResponse response = stub.watchConfigFiles(request);
        return handleResponse(response);
    } catch (Throwable t) {
        // 网络访问异常
        if (connection != null) {
            connection.reportFail();
        }
        throw new RetriableException(ErrorCode.NETWORK_ERROR, "[Config] failed to watch config file", t);
    } finally {
        if (connection != null) {
            connection.release(OP_KEY_GET_CONFIG_FILE);
        }
    }
}
Also used : ConfigFileProto(com.tencent.polaris.client.pb.ConfigFileProto) ConfigFile(com.tencent.polaris.api.plugin.configuration.ConfigFile) Connection(com.tencent.polaris.plugins.connector.grpc.Connection) PolarisConfigGRPCGrpc(com.tencent.polaris.client.pb.PolarisConfigGRPCGrpc) RetriableException(com.tencent.polaris.api.exception.RetriableException)

Aggregations

RetriableException (com.tencent.polaris.api.exception.RetriableException)2 ConfigFileProto (com.tencent.polaris.client.pb.ConfigFileProto)2 PolarisConfigGRPCGrpc (com.tencent.polaris.client.pb.PolarisConfigGRPCGrpc)2 Connection (com.tencent.polaris.plugins.connector.grpc.Connection)2 ConfigFile (com.tencent.polaris.api.plugin.configuration.ConfigFile)1