com.alibaba.csp.sentinel.cluster.client.config.ClusterClientAssignConfig Java Examples

The following examples show how to use com.alibaba.csp.sentinel.cluster.client.config.ClusterClientAssignConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultClusterTokenClient.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
private void changeServer(/*@Valid*/ ClusterClientAssignConfig config) {
    if (serverEqual(serverDescriptor, config)) {
        return;
    }
    try {
        if (transportClient != null) {
            transportClient.stop();
        }
        // Replace with new, even if the new client is not ready.
        this.transportClient = new NettyTransportClient(config.getServerHost(), config.getServerPort());
        this.serverDescriptor = new TokenServerDescriptor(config.getServerHost(), config.getServerPort());
        startClientIfScheduled();
        RecordLog.info("[DefaultClusterTokenClient] New client created: " + serverDescriptor);
    } catch (Exception ex) {
        RecordLog.warn("[DefaultClusterTokenClient] Failed to change remote token server", ex);
    }
}
 
Example #2
Source File: DefaultClusterTokenClient.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
private void changeServer(/*@Valid*/ ClusterClientAssignConfig config) {
    if (serverEqual(serverDescriptor, config)) {
        return;
    }
    try {
        if (transportClient != null) {
            transportClient.stop();
        }
        // Replace with new, even if the new client is not ready.
        this.transportClient = new NettyTransportClient(config.getServerHost(), config.getServerPort());
        this.serverDescriptor = new TokenServerDescriptor(config.getServerHost(), config.getServerPort());
        startClientIfScheduled();
        RecordLog.info("[DefaultClusterTokenClient] New client created: " + serverDescriptor);
    } catch (Exception ex) {
        RecordLog.warn("[DefaultClusterTokenClient] Failed to change remote token server", ex);
    }
}
 
Example #3
Source File: DemoClusterInitFunc.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
private void initClientServerAssignProperty() {
    // Cluster map format:
    // [{"clientSet":["112.12.88.66@8729","112.12.88.67@8727"],"ip":"112.12.88.68","machineId":"112.12.88.68@8728","port":11111}]
    // machineId: <ip@commandPort>, commandPort for port exposed to Sentinel dashboard (transport module)
    ReadableDataSource<String, ClusterClientAssignConfig> clientAssignDs = new NacosDataSource<>(remoteAddress, groupId,
        clusterMapDataId, source -> {
        List<ClusterGroupEntity> groupList = JSON.parseObject(source, new TypeReference<List<ClusterGroupEntity>>() {});
        return Optional.ofNullable(groupList)
            .flatMap(this::extractClientAssignment)
            .orElse(null);
    });
    ClusterClientConfigManager.registerServerAssignProperty(clientAssignDs.getProperty());
}
 
Example #4
Source File: DemoClusterInitFunc.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
private Optional<ClusterClientAssignConfig> extractClientAssignment(List<ClusterGroupEntity> groupList) {
    if (groupList.stream().anyMatch(this::machineEqual)) {
        return Optional.empty();
    }
    // Build client assign config from the client set of target server group.
    for (ClusterGroupEntity group : groupList) {
        if (group.getClientSet().contains(getCurrentMachineId())) {
            String ip = group.getIp();
            Integer port = group.getPort();
            return Optional.of(new ClusterClientAssignConfig(ip, port));
        }
    }
    return Optional.empty();
}
 
Example #5
Source File: DefaultClusterTokenClient.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
public DefaultClusterTokenClient() {
    ClusterClientConfigManager.addServerChangeObserver(new ServerChangeObserver() {
        @Override
        public void onRemoteServerChange(ClusterClientAssignConfig assignConfig) {
            changeServer(assignConfig);
        }
    });
    initNewConnection();
}
 
Example #6
Source File: ClusterFlowClientController.java    From sentinel-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * 加载集群客户端配置
 * 主要是集群服务端的相关连接信息
 */
private void loadClusterClientConfig(){
    ClusterClientAssignConfig assignConfig = new ClusterClientAssignConfig();
    assignConfig.setServerHost(CLUSTER_SERVER_HOST);
    assignConfig.setServerPort(CLUSTER_SERVER_PORT);
    ClusterClientConfigManager.applyNewAssignConfig(assignConfig);

    ClusterClientConfig clientConfig = new ClusterClientConfig();
    clientConfig.setRequestTimeout(REQUEST_TIME_OUT);
    ClusterClientConfigManager.applyNewConfig(clientConfig);
}
 
Example #7
Source File: ClusterFlowClientController.java    From sentinel-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * 为ClusterClientConfig注册一个SentinelProperty
 * 这样的话可以动态的更改这些配置
 */
private void registerClusterClientProperty() {
    String clientConfigDataId = "cluster-client-config";
    // 初始化一个配置ClusterClientConfig的 Nacos 数据源
    ReadableDataSource<String, ClusterClientConfig> clientConfigDS = new NacosDataSource<>(REMOTE_ADDRESS, GROUP_ID, clientConfigDataId,
            source -> JSON.parseObject(source, new TypeReference<ClusterClientConfig>() {}));
    ClusterClientConfigManager.registerClientConfigProperty(clientConfigDS.getProperty());

    String clientAssignConfigDataId = "cluster-client-assign-config";
    // 初始化一个配置ClusterClientAssignConfig的 Nacos 数据源
    ReadableDataSource<String, ClusterClientAssignConfig> clientAssignConfigDS = new NacosDataSource<>(REMOTE_ADDRESS, GROUP_ID, clientAssignConfigDataId,
            source -> JSON.parseObject(source, new TypeReference<ClusterClientAssignConfig>() {}));
    ClusterClientConfigManager.registerServerAssignProperty(clientAssignConfigDS.getProperty());
}
 
Example #8
Source File: ClusterFlowClientController.java    From sentinel-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * 加载集群客户端配置
 * 主要是集群服务端的相关连接信息
 */
private void loadClusterClientConfig(){
    ClusterClientAssignConfig assignConfig = new ClusterClientAssignConfig();
    assignConfig.setServerHost(CLUSTER_SERVER_HOST);
    assignConfig.setServerPort(CLUSTER_SERVER_PORT);
    ClusterClientConfigManager.applyNewAssignConfig(assignConfig);

    ClusterClientConfig clientConfig = new ClusterClientConfig();
    clientConfig.setRequestTimeout(REQUEST_TIME_OUT);
    ClusterClientConfigManager.applyNewConfig(clientConfig);
}
 
Example #9
Source File: ClusterFlowClientController.java    From sentinel-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * 为ClusterClientConfig注册一个SentinelProperty
 * 这样的话可以动态的更改这些配置
 */
private void registerClusterClientProperty() {
    String clientConfigDataId = "cluster-client-config";
    // 初始化一个配置ClusterClientConfig的 Nacos 数据源
    ReadableDataSource<String, ClusterClientConfig> clientConfigDS = new NacosDataSource<>(REMOTE_ADDRESS, GROUP_ID, clientConfigDataId,
            source -> JSON.parseObject(source, new TypeReference<ClusterClientConfig>() {}));
    ClusterClientConfigManager.registerClientConfigProperty(clientConfigDS.getProperty());

    String clientAssignConfigDataId = "cluster-client-assign-config";
    // 初始化一个配置ClusterClientAssignConfig的 Nacos 数据源
    ReadableDataSource<String, ClusterClientAssignConfig> clientAssignConfigDS = new NacosDataSource<>(REMOTE_ADDRESS, GROUP_ID, clientAssignConfigDataId,
            source -> JSON.parseObject(source, new TypeReference<ClusterClientAssignConfig>() {}));
    ClusterClientConfigManager.registerServerAssignProperty(clientAssignConfigDS.getProperty());

}
 
Example #10
Source File: DemoClusterInitFunc.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private void initClientServerAssignProperty() {
    // Cluster map format:
    // [{"clientSet":["112.12.88.66@8729","112.12.88.67@8727"],"ip":"112.12.88.68","machineId":"112.12.88.68@8728","port":11111}]
    // machineId: <ip@commandPort>, commandPort for port exposed to Sentinel dashboard (transport module)
    ReadableDataSource<String, ClusterClientAssignConfig> clientAssignDs = new NacosDataSource<>(remoteAddress, groupId,
        clusterMapDataId, source -> {
        List<ClusterGroupEntity> groupList = JSON.parseObject(source, new TypeReference<List<ClusterGroupEntity>>() {});
        return Optional.ofNullable(groupList)
            .flatMap(this::extractClientAssignment)
            .orElse(null);
    });
    ClusterClientConfigManager.registerServerAssignProperty(clientAssignDs.getProperty());
}
 
Example #11
Source File: DemoClusterInitFunc.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private Optional<ClusterClientAssignConfig> extractClientAssignment(List<ClusterGroupEntity> groupList) {
    if (groupList.stream().anyMatch(this::machineEqual)) {
        return Optional.empty();
    }
    // Build client assign config from the client set of target server group.
    for (ClusterGroupEntity group : groupList) {
        if (group.getClientSet().contains(getCurrentMachineId())) {
            String ip = group.getIp();
            Integer port = group.getPort();
            return Optional.of(new ClusterClientAssignConfig(ip, port));
        }
    }
    return Optional.empty();
}
 
Example #12
Source File: DefaultClusterTokenClient.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public DefaultClusterTokenClient() {
    ClusterClientConfigManager.addServerChangeObserver(new ServerChangeObserver() {
        @Override
        public void onRemoteServerChange(ClusterClientAssignConfig assignConfig) {
            changeServer(assignConfig);
        }
    });
    initNewConnection();
}
 
Example #13
Source File: DefaultClusterTokenClient.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
private boolean serverEqual(TokenServerDescriptor descriptor, ClusterClientAssignConfig config) {
    if (descriptor == null || config == null) {
        return false;
    }
    return descriptor.getHost().equals(config.getServerHost()) && descriptor.getPort() == config.getServerPort();
}
 
Example #14
Source File: ClusterClientStateEntity.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
public ClusterClientAssignConfig toAssignConfig() {
    return new ClusterClientAssignConfig()
        .setServerHost(serverHost)
        .setServerPort(serverPort);
}
 
Example #15
Source File: DefaultClusterTokenClient.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
private boolean serverEqual(TokenServerDescriptor descriptor, ClusterClientAssignConfig config) {
    if (descriptor == null || config == null) {
        return false;
    }
    return descriptor.getHost().equals(config.getServerHost()) && descriptor.getPort() == config.getServerPort();
}
 
Example #16
Source File: ClusterClientStateEntity.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public ClusterClientAssignConfig toAssignConfig() {
    return new ClusterClientAssignConfig()
        .setServerHost(serverHost)
        .setServerPort(serverPort);
}