use of com.alibaba.nacos.config.server.model.ConfigInfo in project spring-cloud-alibaba by alibaba.
the class NacosEnvironmentRepository method findOne.
@Override
public Environment findOne(String application, String profile, String label) {
String dataId = application + "-" + profile + ".properties";
ConfigInfo configInfo = persistService.findConfigInfo(dataId, DEFAULT_GROUP, label);
return createEnvironment(configInfo, application, profile);
}
use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.
the class ConfigController method publishConfig.
/**
* Adds or updates non-aggregated data.
*
* @throws NacosException NacosException.
*/
@PostMapping
@Secured(action = ActionTypes.WRITE, parser = ConfigResourceParser.class)
public Boolean publishConfig(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "dataId") String dataId, @RequestParam(value = "group") String group, @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant, @RequestParam(value = "content") String content, @RequestParam(value = "tag", required = false) String tag, @RequestParam(value = "appName", required = false) String appName, @RequestParam(value = "src_user", required = false) String srcUser, @RequestParam(value = "config_tags", required = false) String configTags, @RequestParam(value = "desc", required = false) String desc, @RequestParam(value = "use", required = false) String use, @RequestParam(value = "effect", required = false) String effect, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "schema", required = false) String schema) throws NacosException {
final String srcIp = RequestUtil.getRemoteIp(request);
final String requestIpApp = RequestUtil.getAppName(request);
srcUser = RequestUtil.getSrcUserName(request);
// check type
if (!ConfigType.isValidType(type)) {
type = ConfigType.getDefaultType().getType();
}
// check tenant
ParamUtils.checkTenant(tenant);
ParamUtils.checkParam(dataId, group, "datumId", content);
ParamUtils.checkParam(tag);
Map<String, Object> configAdvanceInfo = new HashMap<String, Object>(10);
MapUtil.putIfValNoNull(configAdvanceInfo, "config_tags", configTags);
MapUtil.putIfValNoNull(configAdvanceInfo, "desc", desc);
MapUtil.putIfValNoNull(configAdvanceInfo, "use", use);
MapUtil.putIfValNoNull(configAdvanceInfo, "effect", effect);
MapUtil.putIfValNoNull(configAdvanceInfo, "type", type);
MapUtil.putIfValNoNull(configAdvanceInfo, "schema", schema);
ParamUtils.checkParam(configAdvanceInfo);
if (AggrWhitelist.isAggrDataId(dataId)) {
LOGGER.warn("[aggr-conflict] {} attempt to publish single data, {}, {}", RequestUtil.getRemoteIp(request), dataId, group);
throw new NacosException(NacosException.NO_RIGHT, "dataId:" + dataId + " is aggr");
}
final Timestamp time = TimeUtils.getCurrentTime();
String betaIps = request.getHeader("betaIps");
ConfigInfo configInfo = new ConfigInfo(dataId, group, tenant, appName, content);
configInfo.setType(type);
if (StringUtils.isBlank(betaIps)) {
if (StringUtils.isBlank(tag)) {
persistService.insertOrUpdate(srcIp, srcUser, configInfo, time, configAdvanceInfo, false);
ConfigChangePublisher.notifyConfigChange(new ConfigDataChangeEvent(false, dataId, group, tenant, time.getTime()));
} else {
persistService.insertOrUpdateTag(configInfo, tag, srcIp, srcUser, time, false);
ConfigChangePublisher.notifyConfigChange(new ConfigDataChangeEvent(false, dataId, group, tenant, tag, time.getTime()));
}
} else {
// beta publish
persistService.insertOrUpdateBeta(configInfo, betaIps, srcIp, srcUser, time, false);
ConfigChangePublisher.notifyConfigChange(new ConfigDataChangeEvent(true, dataId, group, tenant, time.getTime()));
}
ConfigTraceService.logPersistenceEvent(dataId, group, tenant, requestIpApp, time.getTime(), InetUtils.getSelfIP(), ConfigTraceService.PERSISTENCE_EVENT_PUB, content);
return true;
}
use of com.alibaba.nacos.config.server.model.ConfigInfo 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();
}
}
}
use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method findConfigInfoLike.
@Override
public Page<ConfigInfo> findConfigInfoLike(final int pageNo, final int pageSize, final ConfigKey[] configKeys, final boolean blacklist) {
String sqlCountRows = "SELECT count(*) FROM config_info WHERE ";
String sqlFetchRows = "SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE ";
StringBuilder where = new StringBuilder(" 1=1 ");
// White list, please synchronize the condition is empty, there is no qualified configuration
if (configKeys.length == 0 && !blacklist) {
Page<ConfigInfo> page = new Page<ConfigInfo>();
page.setTotalCount(0);
return page;
}
List<String> params = new ArrayList<String>();
boolean isFirst = true;
for (ConfigKey configInfo : configKeys) {
String dataId = configInfo.getDataId();
String group = configInfo.getGroup();
String appName = configInfo.getAppName();
if (StringUtils.isBlank(dataId) && StringUtils.isBlank(group) && StringUtils.isBlank(appName)) {
break;
}
if (blacklist) {
if (isFirst) {
isFirst = false;
where.append(" AND ");
} else {
where.append(" AND ");
}
where.append('(');
boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) {
where.append(" data_id NOT LIKE ? ");
params.add(generateLikeArgument(dataId));
isFirstSub = false;
}
if (!StringUtils.isBlank(group)) {
if (!isFirstSub) {
where.append(" OR ");
}
where.append(" group_id NOT LIKE ? ");
params.add(generateLikeArgument(group));
isFirstSub = false;
}
if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) {
where.append(" OR ");
}
where.append(" app_name != ? ");
params.add(appName);
isFirstSub = false;
}
where.append(") ");
} else {
if (isFirst) {
isFirst = false;
where.append(" AND ");
} else {
where.append(" OR ");
}
where.append('(');
boolean isFirstSub = true;
if (!StringUtils.isBlank(dataId)) {
where.append(" data_id LIKE ? ");
params.add(generateLikeArgument(dataId));
isFirstSub = false;
}
if (!StringUtils.isBlank(group)) {
if (!isFirstSub) {
where.append(" AND ");
}
where.append(" group_id LIKE ? ");
params.add(generateLikeArgument(group));
isFirstSub = false;
}
if (!StringUtils.isBlank(appName)) {
if (!isFirstSub) {
where.append(" AND ");
}
where.append(" app_name = ? ");
params.add(appName);
isFirstSub = false;
}
where.append(") ");
}
}
PaginationHelper<ConfigInfo> helper = createPaginationHelper();
return helper.fetchPage(sqlCountRows + where.toString(), sqlFetchRows + where.toString(), params.toArray(), pageNo, pageSize, CONFIG_INFO_ROW_MAPPER);
}
use of com.alibaba.nacos.config.server.model.ConfigInfo in project nacos by alibaba.
the class EmbeddedStoragePersistServiceImpl method updateConfigInfoCas.
@Override
public boolean updateConfigInfoCas(final ConfigInfo configInfo, final String srcIp, final String srcUser, final Timestamp time, final Map<String, Object> configAdvanceInfo, final boolean notify) {
try {
ConfigInfo oldConfigInfo = findConfigInfo(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
final String tenantTmp = StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
oldConfigInfo.setTenant(tenantTmp);
String appNameTmp = oldConfigInfo.getAppName();
// otherwise, the appName of db is used. Empty string is required to clear appName
if (configInfo.getAppName() == null) {
configInfo.setAppName(appNameTmp);
}
updateConfigInfoAtomicCas(configInfo, srcIp, srcUser, time, configAdvanceInfo);
String configTags = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("config_tags");
if (configTags != null) {
// Delete all tags and recreate them
removeTagByIdAtomic(oldConfigInfo.getId());
addConfigTagsRelation(oldConfigInfo.getId(), configTags, configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
}
insertConfigHistoryAtomic(oldConfigInfo.getId(), oldConfigInfo, srcIp, srcUser, time, "U");
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
return databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
}
}
Aggregations