Search in sources :

Example 1 with LocalizationConfig

use of com.ctrip.framework.dal.cluster.client.config.LocalizationConfig in project dal by ctripcorp.

the class ConnectionAction method initLogEntry.

public void initLogEntry(String logicDbName, DalHints hints) {
    this.entry = logger.createLogEntry();
    DatabaseSet databaseSet = DalClientFactory.getDalConfigure().getDatabaseSet(logicDbName);
    if (databaseSet instanceof ClusterDatabaseSet) {
        Cluster cluster = ((ClusterDatabaseSet) databaseSet).getCluster();
        entry.setCluster(cluster);
        entry.setClusterName(cluster.getClusterName().toLowerCase());
        LocalizationConfig localizationConfig = cluster.getLocalizationConfig();
        if (localizationConfig != null)
            entry.setDbZone(localizationConfig.getZoneId());
    }
    entry.setLogicDbName(logicDbName);
    entry.setDbCategory(DalClientFactory.getDalConfigure().getDatabaseSet(logicDbName).getDatabaseCategory());
    entry.setClientVersion(Version.getVersion());
    entry.setClientZone(envUtils.getZone());
    entry.setSensitive(hints.is(DalHintEnum.sensitive));
    entry.setEvent(operation);
    entry.setShardingCategory(shardingCategory);
    wrapSql();
    entry.setCallString(callString);
    if (sqls != null)
        entry.setSqls(sqls);
    else
        entry.setSqls(sql);
    if (null != parametersList) {
        String[] params = new String[parametersList.length];
        for (int i = 0; i < parametersList.length; i++) {
            params[i] = parametersList[i].toLogString();
        }
        entry.setPramemters(params);
    } else if (parameters != null) {
        entry.setPramemters(parameters.toLogString());
        hints.setParameters(parameters);
    }
}
Also used : ClusterDatabaseSet(com.ctrip.platform.dal.dao.configure.ClusterDatabaseSet) DatabaseSet(com.ctrip.platform.dal.dao.configure.DatabaseSet) LocalizationConfig(com.ctrip.framework.dal.cluster.client.config.LocalizationConfig) Cluster(com.ctrip.framework.dal.cluster.client.Cluster) ClusterDatabaseSet(com.ctrip.platform.dal.dao.configure.ClusterDatabaseSet)

Example 2 with LocalizationConfig

use of com.ctrip.framework.dal.cluster.client.config.LocalizationConfig in project dal by ctripcorp.

the class DataSourceLocator method createRefreshableDataSource.

private RefreshableDataSource createRefreshableDataSource(DataSourceIdentity id) throws SQLException {
    if (id instanceof ClusterDataSourceIdentity) {
        Database database = ((ClusterDataSourceIdentity) id).getDatabase();
        Cluster cluster = database.getCluster();
        ClusterInfo clusterInfo = new ClusterInfo(database.getClusterName(), database.getShardIndex(), database.isMaster() ? DatabaseRole.MASTER : DatabaseRole.SLAVE, cluster != null && cluster.dbShardingEnabled(), cluster);
        try {
            if (cluster != null && cluster.getClusterType() == ClusterType.DRC) {
                LocalizationConfig localizationConfig = cluster.getLocalizationConfig();
                LocalizationConfig lastLocalizationConfig = cluster.getLastLocalizationConfig();
                LocalizationValidator validator = factory.createValidator(clusterInfo, localizationConfig, lastLocalizationConfig);
                LOGGER.logEvent(LOG_TYPE_CREATE_DATASOURCE, String.format(LOG_NAME_CREATE_DRC_DATASOURCE, clusterInfo.toString()), localizationConfig.toString());
                return new LocalizedDataSource(validator, id, provider.getDataSourceConfigure(id));
            }
        } catch (Exception e) {
            LOGGER.logEvent(LOG_TYPE_CREATE_DATASOURCE, String.format(LOG_NAME_CREATE_DRC_DATASOURCE_FAIL, clusterInfo.toString()), e.getMessage());
            throw e;
        }
    }
    LOGGER.logEvent(LOG_TYPE_CREATE_DATASOURCE, String.format(LOG_NAME_CREATE_NORMAL_DATASOURCE, id.getId()), "");
    SingleDataSourceConfigureProvider dataSourceConfigureProvider = new SingleDataSourceConfigureProvider(id, provider);
    return new ForceSwitchableDataSource(id, dataSourceConfigureProvider);
}
Also used : LocalizationConfig(com.ctrip.framework.dal.cluster.client.config.LocalizationConfig) Database(com.ctrip.framework.dal.cluster.client.database.Database) Cluster(com.ctrip.framework.dal.cluster.client.Cluster) SQLException(java.sql.SQLException)

Example 3 with LocalizationConfig

use of com.ctrip.framework.dal.cluster.client.config.LocalizationConfig in project dal by ctripcorp.

the class ClusterDynamicDataSource method createStandaloneDataSource.

protected DataSource createStandaloneDataSource() {
    DataSourceIdentity id = getStandaloneDataSourceIdentity(clusterInfo, cluster);
    dataSourceId = id;
    DataSourceConfigure config = provider.getDataSourceConfigure(id);
    try {
        if (cluster.getClusterType() == ClusterType.DRC) {
            LocalizationConfig localizationConfig = cluster.getLocalizationConfig();
            LocalizationConfig lastLocalizationConfig = cluster.getLastLocalizationConfig();
            LocalizationValidator validator = factory.createValidator(clusterInfo, localizationConfig, lastLocalizationConfig);
            LOGGER.logEvent(DalLogTypes.DAL_DATASOURCE, String.format(CAT_LOG_NAME_DRC, clusterInfo.toString()), localizationConfig.toString());
            return new LocalizedDataSource(validator, id, config);
        }
    } catch (Throwable t) {
        LOGGER.logEvent(DalLogTypes.DAL_DATASOURCE, String.format(CAT_LOG_NAME_DRC_FAIL, clusterInfo.toString()), t.getMessage());
        throw t;
    }
    LOGGER.logEvent(DalLogTypes.DAL_DATASOURCE, String.format(CAT_LOG_NAME_NORMAL, clusterInfo.toString()), "");
    return new RefreshableDataSource(id, config);
}
Also used : LocalizationConfig(com.ctrip.framework.dal.cluster.client.config.LocalizationConfig)

Example 4 with LocalizationConfig

use of com.ctrip.framework.dal.cluster.client.config.LocalizationConfig in project dal by ctripcorp.

the class ClusterDbSqlContext method toMetricTags.

@Override
protected Map<String, String> toMetricTags() {
    Map<String, String> tags = super.toMetricTags();
    addTag(tags, CLUSTER, cluster.getClusterName());
    addTag(tags, SHARD, shard);
    addTag(tags, ROLE, role);
    addTag(tags, READ_STRATEGY, readStrategy);
    addTag(tags, DB_KEY, String.format("%s-%s-%s", cluster, shard, role));
    ClusterType type = cluster.getClusterType();
    if (type == ClusterType.DRC) {
        LocalizationConfig config = cluster.getLocalizationConfig();
        if (config != null && config.getLocalizationState() == LocalizationState.ACTIVE)
            tags.put(CLUSTER_TYPE, type.getValue() + "_" + config.getLocalizationState().getValue());
        else
            tags.put(CLUSTER_TYPE, type.getValue() + "_" + LocalizationState.PREPARED.getValue());
        if (config != null && config.getUnitStrategyId() != null)
            tags.put(UCS_STRATEGY, String.valueOf(config.getUnitStrategyId()));
    } else if (type != null)
        tags.put(CLUSTER_TYPE, type.getValue());
    return tags;
}
Also used : LocalizationConfig(com.ctrip.framework.dal.cluster.client.config.LocalizationConfig) ClusterType(com.ctrip.framework.dal.cluster.client.cluster.ClusterType)

Aggregations

LocalizationConfig (com.ctrip.framework.dal.cluster.client.config.LocalizationConfig)4 Cluster (com.ctrip.framework.dal.cluster.client.Cluster)2 ClusterType (com.ctrip.framework.dal.cluster.client.cluster.ClusterType)1 Database (com.ctrip.framework.dal.cluster.client.database.Database)1 ClusterDatabaseSet (com.ctrip.platform.dal.dao.configure.ClusterDatabaseSet)1 DatabaseSet (com.ctrip.platform.dal.dao.configure.DatabaseSet)1 SQLException (java.sql.SQLException)1