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

org.zodiac.sentinel.base.datasource.model.SentinelNacosDataSourceInfo Maven / Gradle / Ivy

The newest version!
package org.zodiac.sentinel.base.datasource.model;

import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
import static com.alibaba.nacos.api.PropertyKeyConst.PASSWORD;
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;

import java.util.Objects;
import java.util.Properties;

import javax.validation.constraints.NotEmpty;

import org.zodiac.sentinel.base.datasource.DataSourceType;
import org.zodiac.sentinel.base.datasource.factory.SentinelNacosDataSourceFactoryBean;

public class SentinelNacosDataSourceInfo extends AbstractDataSourceInfo {

    private String serverAddr;

    private String username;

    private String password;

    @NotEmpty
    private String groupId = "DEFAULT_GROUP";

    @NotEmpty
    private String dataId;

    private String endpoint;

    private String namespace;

    private String accessKey;

    private String secretKey;

    public SentinelNacosDataSourceInfo() {
        super(DataSourceType.nacos, SentinelNacosDataSourceFactoryBean.class.getName());
    }

    public String getServerAddr() {
        return serverAddr;
    }

    public void setServerAddr(String serverAddr) {
        this.serverAddr = serverAddr;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getDataId() {
        return dataId;
    }

    public void setDataId(String dataId) {
        this.dataId = dataId;
    }

    public String getEndpoint() {
        return endpoint;
    }

    public void setEndpoint(String endpoint) {
        this.endpoint = endpoint;
    }

    public String getNamespace() {
        return namespace;
    }

    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public Properties toNacosConfigProperties() {
        Properties properties = new Properties();
        properties.put(SERVER_ADDR, Objects.toString(this.getServerAddr(), ""));
        properties.put(USERNAME, Objects.toString(this.getUsername(), ""));
        properties.put(PASSWORD, Objects.toString(this.getPassword(), ""));
        properties.put(NAMESPACE, Objects.toString(this.getNamespace(), ""));
        properties.put(ACCESS_KEY, Objects.toString(this.getAccessKey(), ""));
        properties.put(SECRET_KEY, Objects.toString(this.getSecretKey(), ""));
        String endpoint = Objects.toString(this.getEndpoint(), "");
        if (endpoint.contains(":")) {
            int index = endpoint.indexOf(":");
            properties.put(ENDPOINT, endpoint.substring(0, index));
            properties.put(ENDPOINT_PORT, endpoint.substring(index + 1));
        } else {
            properties.put(ENDPOINT, endpoint);
        }

        return properties;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result
            + Objects.hash(accessKey, dataId, endpoint, groupId, namespace, password, secretKey, serverAddr, username);
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (getClass() != obj.getClass())
            return false;
        SentinelNacosDataSourceInfo other = (SentinelNacosDataSourceInfo)obj;
        return Objects.equals(accessKey, other.accessKey) && Objects.equals(dataId, other.dataId)
            && Objects.equals(endpoint, other.endpoint) && Objects.equals(groupId, other.groupId)
            && Objects.equals(namespace, other.namespace) && Objects.equals(password, other.password)
            && Objects.equals(secretKey, other.secretKey) && Objects.equals(serverAddr, other.serverAddr)
            && Objects.equals(username, other.username);
    }

    @Override
    public String toString() {
        return "[serverAddr=" + serverAddr + ", username=" + username + ", password="
            + password + ", groupId=" + groupId + ", dataId=" + dataId + ", endpoint=" + endpoint + ", namespace="
            + namespace + ", accessKey=" + accessKey + ", secretKey=" + secretKey + ", getDataType()=" + getDataType()
            + ", getRule()=" + getRule() + ", getConverterClass()=" + getConverterClass() + "]";
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy