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

com.alibaba.csp.ahas.sentinel.datasource.parser.cluster.ClusterAssignStateParser Maven / Gradle / Ivy

There is a newer version: 1.11.7
Show newest version
package com.alibaba.csp.ahas.sentinel.datasource.parser.cluster;

import java.util.List;

import com.alibaba.csp.ahas.sentinel.cluster.entity.ClusterGroupEntity;
import com.alibaba.csp.ahas.sentinel.util.MachineUtils;
import com.alibaba.csp.sentinel.cluster.ClusterStateManager;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.acm.DataAcmFormat;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

/**
 * @author Eric Zhao
 */
public class ClusterAssignStateParser implements Converter {

    @Override
    public Integer convert(String source) {
        if (source == null) {
            return null;
        }
        String data = new DataAcmFormat(source).getData();
        List groupList = JSON.parseObject(data, new TypeReference>() {});
        if (groupList == null || groupList.isEmpty()) {
            return ClusterStateManager.CLUSTER_NOT_STARTED;
        }
        return extractMode(groupList);
    }

    private int extractMode(List groupList) {
        // If any server group machine matches current, then it's token server.
        for (ClusterGroupEntity group : groupList) {
            if (group.getClientSet() != null) {
                if (group.getClientSet().contains("all")) {
                    return ClusterStateManager.CLUSTER_CLIENT;
                }
                for (String client : group.getClientSet()) {
                    if (client != null && client.equals(MachineUtils.getCurrentProcessConfigurationId())) {
                        return ClusterStateManager.CLUSTER_CLIENT;
                    }
                }
            }
        }
        return ClusterStateManager.CLUSTER_NOT_STARTED;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy