All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.sentinel.base.cluster.parser.ClusterClientAssignConfigParser Maven / Gradle / Ivy

package org.zodiac.sentinel.base.cluster.parser;

import org.zodiac.commons.util.serialize.JsonUtil;
import org.zodiac.sentinel.base.cluster.model.ClusterGroup;

import com.alibaba.csp.sentinel.cluster.client.config.ClusterClientAssignConfig;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.log.RecordLog;

public class ClusterClientAssignConfigParser implements Converter {

    public ClusterClientAssignConfigParser() {
        super();
    }

    @Override
    public ClusterClientAssignConfig convert(String source) {
        if (source == null) {
            return null;
        }
        RecordLog.info("[ClusterClientAssignConfigParser] Get data: {}", source);
        /*转换成对象。*/
        ClusterGroup entity = JsonUtil.json2Object(source, ClusterGroup.class);
        if (entity == null) {
            return null;
        }
        return extractClientAssignment(entity);
    }

    private ClusterClientAssignConfig extractClientAssignment(ClusterGroup entity) {
        /*获取第一个配置的TokenServer地址信息,解析出IP、端口。*/
        String ip = entity.getIp();
        Integer port = entity.getPort();
        return new ClusterClientAssignConfig(ip, port);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy