Search in sources :

Example 1 with NacosConfigException

use of com.alibaba.nacos.config.server.exception.NacosConfigException in project nacos by alibaba.

the class EmbeddedStoragePersistServiceImpl method removeConfigInfo.

@Override
public void removeConfigInfo(final String dataId, final String group, final String tenant, final String srcIp, final String srcUser) {
    final Timestamp time = new Timestamp(System.currentTimeMillis());
    ConfigInfo configInfo = findConfigInfo(dataId, group, tenant);
    if (Objects.nonNull(configInfo)) {
        try {
            String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
            removeConfigInfoAtomic(dataId, group, tenantTmp, srcIp, srcUser);
            removeTagByIdAtomic(configInfo.getId());
            insertConfigHistoryAtomic(configInfo.getId(), configInfo, srcIp, srcUser, time, "D");
            EmbeddedStorageContextUtils.onDeleteConfigInfo(tenantTmp, group, dataId, srcIp, time);
            boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
            if (!result) {
                throw new NacosConfigException("config deletion failed");
            }
        } 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 2 with NacosConfigException

use of com.alibaba.nacos.config.server.exception.NacosConfigException in project nacos by alibaba.

the class EmbeddedStoragePersistServiceImpl method addAggrConfigInfo.

@Override
public boolean addAggrConfigInfo(final String dataId, final String group, String tenant, final String datumId, String appName, final String content) {
    String appNameTmp = StringUtils.isBlank(appName) ? StringUtils.EMPTY : appName;
    String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
    String contentTmp = StringUtils.isBlank(content) ? StringUtils.EMPTY : content;
    final Timestamp now = new Timestamp(System.currentTimeMillis());
    final String select = "SELECT content FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id = ?";
    final String insert = "INSERT INTO config_info_aggr(data_id, group_id, tenant_id, datum_id, app_name, content, gmt_modified) VALUES(?,?,?,?,?,?,?) ";
    final String update = "UPDATE config_info_aggr SET content = ? , gmt_modified = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND datum_id = ?";
    String dbContent = databaseOperate.queryOne(select, new Object[] { dataId, group, tenantTmp, datumId }, String.class);
    if (Objects.isNull(dbContent)) {
        final Object[] args = new Object[] { dataId, group, tenantTmp, datumId, appNameTmp, contentTmp, now };
        EmbeddedStorageContextUtils.addSqlContext(insert, args);
    } else if (!dbContent.equals(content)) {
        final Object[] args = new Object[] { contentTmp, now, dataId, group, tenantTmp, datumId };
        EmbeddedStorageContextUtils.addSqlContext(update, args);
    }
    try {
        boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
        if (!result) {
            throw new NacosConfigException("[Merge] Configuration release failed");
        }
        return true;
    } finally {
        EmbeddedStorageContextUtils.cleanAllContext();
    }
}
Also used : NacosConfigException(com.alibaba.nacos.config.server.exception.NacosConfigException) Timestamp(java.sql.Timestamp)

Example 3 with NacosConfigException

use of com.alibaba.nacos.config.server.exception.NacosConfigException 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 4 with NacosConfigException

use of com.alibaba.nacos.config.server.exception.NacosConfigException 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)

Aggregations

NacosConfigException (com.alibaba.nacos.config.server.exception.NacosConfigException)4 ConfigInfo (com.alibaba.nacos.config.server.model.ConfigInfo)3 Timestamp (java.sql.Timestamp)3