Search in sources :

Example 1 with ConfigInfo4Beta

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

the class ConfigController method queryBeta.

/**
 * Execute to query beta operation.
 *
 * @param dataId dataId string value.
 * @param group  group string value.
 * @param tenant tenant string value.
 * @return RestResult for ConfigInfo4Beta.
 */
@GetMapping(params = "beta=true")
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG)
public RestResult<ConfigInfo4Beta> queryBeta(@RequestParam(value = "dataId") String dataId, @RequestParam(value = "group") String group, @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant) {
    try {
        ConfigInfo4Beta ci = persistService.findConfigInfo4Beta(dataId, group, tenant);
        if (Objects.nonNull(ci)) {
            String encryptedDataKey = ci.getEncryptedDataKey();
            Pair<String, String> pair = EncryptionHandler.decryptHandler(dataId, encryptedDataKey, ci.getContent());
            ci.setContent(pair.getSecond());
        }
        return RestResultUtils.success("stop beta ok", ci);
    } catch (Throwable e) {
        LOGGER.error("remove beta data error", e);
        return RestResultUtils.failed("remove beta data error");
    }
}
Also used : ConfigInfo4Beta(com.alibaba.nacos.config.server.model.ConfigInfo4Beta) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 2 with ConfigInfo4Beta

use of com.alibaba.nacos.config.server.model.ConfigInfo4Beta 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 3 with ConfigInfo4Beta

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

the class NacosRestTemplate_ITCase method test_url_get_return_restResult.

@Test
public void test_url_get_return_restResult() throws Exception {
    String url = IP + CONFIG_PATH + "/configs";
    Query query = Query.newInstance().addParam("beta", true).addParam("dataId", "test-1").addParam("group", "DEFAULT_GROUP");
    HttpRestResult<ConfigInfo4Beta> restResult = nacosRestTemplate.get(url, Header.newInstance(), query, new TypeReference<RestResult<ConfigInfo4Beta>>() {
    }.getType());
    Assert.assertTrue(restResult.ok());
    System.out.println(restResult.getData());
    System.out.println(restResult.getHeader());
}
Also used : Query(com.alibaba.nacos.common.http.param.Query) ConfigInfo4Beta(com.alibaba.nacos.config.server.model.ConfigInfo4Beta) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ConfigInfo4Beta (com.alibaba.nacos.config.server.model.ConfigInfo4Beta)3 Secured (com.alibaba.nacos.auth.annotation.Secured)1 Query (com.alibaba.nacos.common.http.param.Query)1 ConfigInfo (com.alibaba.nacos.config.server.model.ConfigInfo)1 ConfigInfo4Tag (com.alibaba.nacos.config.server.model.ConfigInfo4Tag)1 ConfigDumpEvent (com.alibaba.nacos.config.server.model.event.ConfigDumpEvent)1 DumpTask (com.alibaba.nacos.config.server.service.dump.task.DumpTask)1 PersistService (com.alibaba.nacos.config.server.service.repository.PersistService)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1