Search in sources :

Example 31 with ConfigInfo

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

the class MergeTaskProcessor method merge.

/**
 * merge datumList {@link ConfigInfoAggr}.
 *
 * @param dataId    data id
 * @param group     group
 * @param tenant    tenant
 * @param datumList datumList
 * @return {@link ConfigInfo}
 */
public static ConfigInfo merge(String dataId, String group, String tenant, List<ConfigInfoAggr> datumList) {
    StringBuilder sb = new StringBuilder();
    String appName = null;
    for (ConfigInfoAggr aggrInfo : datumList) {
        if (aggrInfo.getAppName() != null) {
            appName = aggrInfo.getAppName();
        }
        sb.append(aggrInfo.getContent());
        sb.append(Constants.NACOS_LINE_SEPARATOR);
    }
    String content = sb.substring(0, sb.lastIndexOf(Constants.NACOS_LINE_SEPARATOR));
    return new ConfigInfo(dataId, group, tenant, appName, content);
}
Also used : ConfigInfoAggr(com.alibaba.nacos.config.server.model.ConfigInfoAggr) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo)

Example 32 with ConfigInfo

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

the class DumpChangeProcessor method process.

@Override
public boolean process(NacosTask task) {
    LogUtil.DEFAULT_LOG.warn("quick start; startTime:{},endTime:{}", startTime, endTime);
    LogUtil.DEFAULT_LOG.warn("updateMd5 start");
    long startUpdateMd5 = System.currentTimeMillis();
    List<ConfigInfoWrapper> updateMd5List = persistService.listAllGroupKeyMd5();
    LogUtil.DEFAULT_LOG.warn("updateMd5 count:{}", updateMd5List.size());
    for (ConfigInfoWrapper config : updateMd5List) {
        final String groupKey = GroupKey2.getKey(config.getDataId(), config.getGroup());
        ConfigCacheService.updateMd5(groupKey, config.getMd5(), config.getLastModified(), config.getEncryptedDataKey());
    }
    long endUpdateMd5 = System.currentTimeMillis();
    LogUtil.DEFAULT_LOG.warn("updateMd5 done,cost:{}", endUpdateMd5 - startUpdateMd5);
    LogUtil.DEFAULT_LOG.warn("deletedConfig start");
    long startDeletedConfigTime = System.currentTimeMillis();
    List<ConfigInfo> configDeleted = persistService.findDeletedConfig(startTime, endTime);
    LogUtil.DEFAULT_LOG.warn("deletedConfig count:{}", configDeleted.size());
    for (ConfigInfo configInfo : configDeleted) {
        if (persistService.findConfigInfo(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant()) == null) {
            ConfigCacheService.remove(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
        }
    }
    long endDeletedConfigTime = System.currentTimeMillis();
    LogUtil.DEFAULT_LOG.warn("deletedConfig done,cost:{}", endDeletedConfigTime - startDeletedConfigTime);
    LogUtil.DEFAULT_LOG.warn("changeConfig start");
    final long startChangeConfigTime = System.currentTimeMillis();
    List<ConfigInfoWrapper> changeConfigs = persistService.findChangeConfig(startTime, endTime);
    LogUtil.DEFAULT_LOG.warn("changeConfig count:{}", changeConfigs.size());
    for (ConfigInfoWrapper cf : changeConfigs) {
        ConfigCacheService.dumpChange(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(), cf.getLastModified(), cf.getEncryptedDataKey());
        final String content = cf.getContent();
        final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
        LogUtil.DEFAULT_LOG.info("[dump-change-ok] {}, {}, length={}, md5={}", GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(), content.length(), md5);
    }
    ConfigCacheService.reloadConfig();
    long endChangeConfigTime = System.currentTimeMillis();
    LogUtil.DEFAULT_LOG.warn("changeConfig done,cost:{}", endChangeConfigTime - startChangeConfigTime);
    return true;
}
Also used : ConfigInfoWrapper(com.alibaba.nacos.config.server.model.ConfigInfoWrapper) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo)

Example 33 with ConfigInfo

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

the class DumpProcessor method process.

@Override
public boolean process(NacosTask task) {
    final PersistService persistService = dumpService.getPersistService();
    DumpTask dumpTask = (DumpTask) task;
    String[] pair = GroupKey2.parseKey(dumpTask.getGroupKey());
    String dataId = pair[0];
    String group = pair[1];
    String tenant = pair[2];
    long lastModified = dumpTask.getLastModified();
    String handleIp = dumpTask.getHandleIp();
    boolean isBeta = dumpTask.isBeta();
    String tag = dumpTask.getTag();
    ConfigDumpEvent.ConfigDumpEventBuilder build = ConfigDumpEvent.builder().namespaceId(tenant).dataId(dataId).group(group).isBeta(isBeta).tag(tag).lastModifiedTs(lastModified).handleIp(handleIp);
    if (isBeta) {
        // if publish beta, then dump config, update beta cache
        ConfigInfo4Beta cf = persistService.findConfigInfo4Beta(dataId, group, tenant);
        build.remove(Objects.isNull(cf));
        build.betaIps(Objects.isNull(cf) ? null : cf.getBetaIps());
        build.content(Objects.isNull(cf) ? null : cf.getContent());
        build.encryptedDataKey(Objects.isNull(cf) ? null : cf.getEncryptedDataKey());
        return DumpConfigHandler.configDump(build.build());
    }
    if (StringUtils.isBlank(tag)) {
        ConfigInfo cf = persistService.findConfigInfo(dataId, group, tenant);
        build.remove(Objects.isNull(cf));
        build.content(Objects.isNull(cf) ? null : cf.getContent());
        build.type(Objects.isNull(cf) ? null : cf.getType());
        build.encryptedDataKey(Objects.isNull(cf) ? null : cf.getEncryptedDataKey());
    } else {
        ConfigInfo4Tag cf = persistService.findConfigInfo4Tag(dataId, group, tenant, tag);
        build.remove(Objects.isNull(cf));
        build.content(Objects.isNull(cf) ? null : cf.getContent());
    }
    return DumpConfigHandler.configDump(build.build());
}
Also used : DumpTask(com.alibaba.nacos.config.server.service.dump.task.DumpTask) ConfigDumpEvent(com.alibaba.nacos.config.server.model.event.ConfigDumpEvent) ConfigInfo4Beta(com.alibaba.nacos.config.server.model.ConfigInfo4Beta) ConfigInfo4Tag(com.alibaba.nacos.config.server.model.ConfigInfo4Tag) PersistService(com.alibaba.nacos.config.server.service.repository.PersistService) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo)

Example 34 with ConfigInfo

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

the class ConfigController method exportConfig.

/**
 * Execute export config operation.
 *
 * @param dataId  dataId string value.
 * @param group   group string value.
 * @param appName appName string value.
 * @param tenant  tenant string value.
 * @param ids     id list value.
 * @return ResponseEntity.
 */
@GetMapping(params = "export=true")
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG)
public ResponseEntity<byte[]> exportConfig(@RequestParam(value = "dataId", required = false) String dataId, @RequestParam(value = "group", required = false) String group, @RequestParam(value = "appName", required = false) String appName, @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant, @RequestParam(value = "ids", required = false) List<Long> ids) {
    ids.removeAll(Collections.singleton(null));
    tenant = NamespaceUtil.processNamespaceParameter(tenant);
    List<ConfigAllInfo> dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids);
    List<ZipUtils.ZipItem> zipItemList = new ArrayList<>();
    StringBuilder metaData = null;
    for (ConfigInfo ci : dataList) {
        if (StringUtils.isNotBlank(ci.getAppName())) {
            // Handle appName
            if (metaData == null) {
                metaData = new StringBuilder();
            }
            String metaDataId = ci.getDataId();
            if (metaDataId.contains(".")) {
                metaDataId = metaDataId.substring(0, metaDataId.lastIndexOf(".")) + "~" + metaDataId.substring(metaDataId.lastIndexOf(".") + 1);
            }
            metaData.append(ci.getGroup()).append('.').append(metaDataId).append(".app=").append(ci.getAppName()).append("\r\n");
        }
        Pair<String, String> pair = EncryptionHandler.decryptHandler(ci.getDataId(), ci.getEncryptedDataKey(), ci.getContent());
        String itemName = ci.getGroup() + Constants.CONFIG_EXPORT_ITEM_FILE_SEPARATOR + ci.getDataId();
        zipItemList.add(new ZipUtils.ZipItem(itemName, pair.getSecond()));
    }
    if (metaData != null) {
        zipItemList.add(new ZipUtils.ZipItem(Constants.CONFIG_EXPORT_METADATA, metaData.toString()));
    }
    HttpHeaders headers = new HttpHeaders();
    String fileName = EXPORT_CONFIG_FILE_NAME + DateFormatUtils.format(new Date(), EXPORT_CONFIG_FILE_NAME_DATE_FORMAT) + EXPORT_CONFIG_FILE_NAME_EXT;
    headers.add("Content-Disposition", "attachment;filename=" + fileName);
    return new ResponseEntity<>(ZipUtils.zip(zipItemList), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ArrayList(java.util.ArrayList) ZipUtils(com.alibaba.nacos.config.server.utils.ZipUtils) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo) Date(java.util.Date) ResponseEntity(org.springframework.http.ResponseEntity) ConfigAllInfo(com.alibaba.nacos.config.server.model.ConfigAllInfo) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 35 with ConfigInfo

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

the class CapacityManagementAspect method aroundDeleteConfig.

/**
 * The usage of capacity table for counting module will subtracte one whether open the limitation check of capacity
 * management.
 */
@Around(DELETE_CONFIG)
public Object aroundDeleteConfig(ProceedingJoinPoint pjp, HttpServletRequest request, HttpServletResponse response, String dataId, String group, String tenant) throws Throwable {
    if (!PropertyUtil.isManageCapacity()) {
        return pjp.proceed();
    }
    LOGGER.info("[capacityManagement] aroundDeleteConfig");
    ConfigInfo configInfo = persistService.findConfigInfo(dataId, group, tenant);
    if (configInfo == null) {
        return pjp.proceed();
    }
    return do4Delete(pjp, response, group, tenant, configInfo);
}
Also used : ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo) Around(org.aspectj.lang.annotation.Around)

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