Search in sources :

Example 21 with ConfigInfo

use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.

the class EmbeddedStoragePersistServiceImpl method convertDeletedConfig.

@Override
public List<ConfigInfo> convertDeletedConfig(List<Map<String, Object>> list) {
    List<ConfigInfo> configs = new ArrayList<ConfigInfo>();
    for (Map<String, Object> map : list) {
        String dataId = (String) map.get("data_id");
        String group = (String) map.get("group_id");
        String tenant = (String) map.get("tenant_id");
        ConfigInfo config = new ConfigInfo();
        config.setDataId(dataId);
        config.setGroup(group);
        config.setTenant(tenant);
        configs.add(config);
    }
    return configs;
}
Also used : ArrayList(java.util.ArrayList) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo)

Example 22 with ConfigInfo

use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.

the class EmbeddedStoragePersistServiceImpl method findConfigInfo4Page.

@Override
public Page<ConfigInfo> findConfigInfo4Page(final int pageNo, final int pageSize, final String dataId, final String group, final String tenant, final Map<String, Object> configAdvanceInfo) {
    String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
    final String appName = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("appName");
    final String configTags = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("config_tags");
    String sqlCount = "SELECT count(*) FROM config_info";
    String sql = "SELECT id,data_id,group_id,tenant_id,app_name,content,type FROM config_info";
    StringBuilder where = new StringBuilder(" WHERE ");
    List<String> paramList = new ArrayList<String>();
    paramList.add(tenantTmp);
    if (StringUtils.isNotBlank(configTags)) {
        sqlCount = "SELECT count(*) FROM config_info  a LEFT JOIN config_tags_relation b ON a.id=b.id";
        sql = "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info  a LEFT JOIN " + "config_tags_relation b ON a.id=b.id";
        where.append(" a.tenant_id=? ");
        if (StringUtils.isNotBlank(dataId)) {
            where.append(" AND a.data_id=? ");
            paramList.add(dataId);
        }
        if (StringUtils.isNotBlank(group)) {
            where.append(" AND a.group_id=? ");
            paramList.add(group);
        }
        if (StringUtils.isNotBlank(appName)) {
            where.append(" AND a.app_name=? ");
            paramList.add(appName);
        }
        where.append(" AND b.tag_name IN (");
        String[] tagArr = configTags.split(",");
        for (int i = 0; i < tagArr.length; i++) {
            if (i != 0) {
                where.append(", ");
            }
            where.append('?');
            paramList.add(tagArr[i]);
        }
        where.append(") ");
    } else {
        where.append(" tenant_id=? ");
        if (StringUtils.isNotBlank(dataId)) {
            where.append(" AND data_id=? ");
            paramList.add(dataId);
        }
        if (StringUtils.isNotBlank(group)) {
            where.append(" AND group_id=? ");
            paramList.add(group);
        }
        if (StringUtils.isNotBlank(appName)) {
            where.append(" AND app_name=? ");
            paramList.add(appName);
        }
    }
    PaginationHelper<ConfigInfo> helper = createPaginationHelper();
    Page<ConfigInfo> page = helper.fetchPage(sqlCount + where, sql + where, paramList.toArray(), pageNo, pageSize, CONFIG_INFO_ROW_MAPPER);
    for (ConfigInfo configInfo : page.getPageItems()) {
        Pair<String, String> pair = EncryptionHandler.decryptHandler(configInfo.getDataId(), configInfo.getEncryptedDataKey(), configInfo.getContent());
        configInfo.setContent(pair.getSecond());
    }
    return page;
}
Also used : ArrayList(java.util.ArrayList) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo)

Example 23 with ConfigInfo

use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.

the class EmbeddedStoragePersistServiceImpl method removeConfigInfoByIds.

@Override
public List<ConfigInfo> removeConfigInfoByIds(final List<Long> ids, final String srcIp, final String srcUser) {
    if (CollectionUtils.isEmpty(ids)) {
        return null;
    }
    ids.removeAll(Collections.singleton(null));
    final Timestamp time = new Timestamp(System.currentTimeMillis());
    try {
        String idsStr = StringUtils.join(ids, StringUtils.COMMA);
        List<ConfigInfo> configInfoList = findConfigInfosByIds(idsStr);
        if (CollectionUtils.isNotEmpty(configInfoList)) {
            removeConfigInfoByIdsAtomic(idsStr);
            for (ConfigInfo configInfo : configInfoList) {
                removeTagByIdAtomic(configInfo.getId());
                insertConfigHistoryAtomic(configInfo.getId(), configInfo, srcIp, srcUser, time, "D");
            }
        }
        EmbeddedStorageContextUtils.onBatchDeleteConfigInfo(configInfoList);
        boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
        if (!result) {
            throw new NacosConfigException("Failed to config batch deletion");
        }
        return configInfoList;
    } finally {
        EmbeddedStorageContextUtils.cleanAllContext();
    }
}
Also used : NacosConfigException(com.alibaba.nacos.config.server.exception.NacosConfigException) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo) Timestamp(java.sql.Timestamp)

Example 24 with ConfigInfo

use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.

the class EmbeddedStoragePersistServiceImpl method removeConfigInfo4Beta.

@Override
public void removeConfigInfo4Beta(final String dataId, final String group, final String tenant) {
    final String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
    ConfigInfo configInfo = findConfigInfo4Beta(dataId, group, tenant);
    if (configInfo != null) {
        try {
            final String sql = "DELETE FROM config_info_beta WHERE data_id=? AND group_id=? AND tenant_id=?";
            final Object[] args = new Object[] { dataId, group, tenantTmp };
            EmbeddedStorageContextUtils.onDeleteConfigBetaInfo(tenantTmp, group, dataId, System.currentTimeMillis());
            EmbeddedStorageContextUtils.addSqlContext(sql, args);
            boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
            if (!result) {
                throw new NacosConfigException("[Tag] Configuration deletion failed");
            }
        } finally {
            EmbeddedStorageContextUtils.cleanAllContext();
        }
    }
}
Also used : NacosConfigException(com.alibaba.nacos.config.server.exception.NacosConfigException) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo)

Example 25 with ConfigInfo

use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.

the class ExternalStoragePersistServiceImpl method convertDeletedConfig.

@Override
public List<ConfigInfo> convertDeletedConfig(List<Map<String, Object>> list) {
    List<ConfigInfo> configs = new ArrayList<ConfigInfo>();
    for (Map<String, Object> map : list) {
        String dataId = (String) map.get("data_id");
        String group = (String) map.get("group_id");
        String tenant = (String) map.get("tenant_id");
        ConfigInfo config = new ConfigInfo();
        config.setDataId(dataId);
        config.setGroup(group);
        config.setTenant(tenant);
        configs.add(config);
    }
    return configs;
}
Also used : ArrayList(java.util.ArrayList) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo)

Aggregations

ConfigInfo (com.alibaba.nacos.config.server.model.ConfigInfo)36 ArrayList (java.util.ArrayList)17 Timestamp (java.sql.Timestamp)11 HashMap (java.util.HashMap)10 Secured (com.alibaba.nacos.auth.annotation.Secured)8 ConfigDataChangeEvent (com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent)8 NacosException (com.alibaba.nacos.api.exception.NacosException)6 Page (com.alibaba.nacos.config.server.model.Page)6 CannotGetJdbcConnectionException (org.springframework.jdbc.CannotGetJdbcConnectionException)6 ConfigAllInfo (com.alibaba.nacos.config.server.model.ConfigAllInfo)5 NacosConfigException (com.alibaba.nacos.config.server.exception.NacosConfigException)4 PersistService (com.alibaba.nacos.config.server.service.repository.PersistService)4 Map (java.util.Map)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 ConfigInfoAggr (com.alibaba.nacos.config.server.model.ConfigInfoAggr)3 ConfigKey (com.alibaba.nacos.config.server.model.ConfigKey)3 List (java.util.List)3 Test (org.junit.Test)3 RestResult (com.alibaba.nacos.common.model.RestResult)2 Pair (com.alibaba.nacos.common.utils.Pair)2