Search in sources :

Example 1 with PersistService

use of com.alibaba.nacos.config.server.service.repository.PersistService in project nacos by alibaba.

the class ConfigDerbyImport_CITCase method testDerbyImport.

@Test()
public void testDerbyImport() throws Throwable {
    DatabaseOperate operate = context.getBean(DatabaseOperate.class);
    File file = DiskUtils.createTmpFile("derby_import" + System.currentTimeMillis(), ".tmp");
    DiskUtils.writeFile(file, ByteUtils.toBytes(SQL_SCRIPT_CONTEXT), false);
    try {
        List<Integer> ids = operate.queryMany("SELECT id FROM config_info", new Object[] {}, Integer.class);
        for (Integer each : ids) {
            System.out.println("current id in table config_info contain: " + each);
        }
        CompletableFuture<RestResult<String>> future = operate.dataImport(file);
        RestResult<String> result = future.join();
        System.out.println(result);
        Assert.assertTrue(result.ok());
        final String queryDataId = "people";
        final String queryGroup = "DEFAULT_GROUP";
        final String expectContent = "people.enable=true";
        PersistService persistService = context.getBean(PersistService.class);
        ConfigInfo configInfo = persistService.findConfigInfo(queryDataId, queryGroup, "");
        System.out.println(configInfo);
        Assert.assertNotNull(configInfo);
        Assert.assertEquals(queryDataId, configInfo.getDataId());
        Assert.assertEquals(queryGroup, configInfo.getGroup());
        Assert.assertEquals("", configInfo.getTenant());
        Assert.assertEquals(expectContent, configInfo.getContent());
    } finally {
        DiskUtils.deleteQuietly(file);
    }
}
Also used : RestResult(com.alibaba.nacos.common.model.RestResult) PersistService(com.alibaba.nacos.config.server.service.repository.PersistService) ConfigInfo(com.alibaba.nacos.config.server.model.ConfigInfo) DatabaseOperate(com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate) File(java.io.File) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with PersistService

use of com.alibaba.nacos.config.server.service.repository.PersistService in project nacos by alibaba.

the class ConfigDerbyRaft_DITCase method test_b_publish_config.

@Test
public void test_b_publish_config() throws Exception {
    ThreadUtils.sleep(5000);
    boolean result = iconfig8.publishConfig("raft_test", "cluster_test_2", "this.is.raft_cluster=lessspring_8");
    Assert.assertTrue(result);
    ThreadUtils.sleep(5000);
    ConfigurableApplicationContext context7 = applications.get("8847");
    ConfigurableApplicationContext context8 = applications.get("8848");
    ConfigurableApplicationContext context9 = applications.get("8849");
    PersistService operate7 = context7.getBean(EmbeddedStoragePersistServiceImpl.class);
    PersistService operate8 = context8.getBean(EmbeddedStoragePersistServiceImpl.class);
    PersistService operate9 = context9.getBean(EmbeddedStoragePersistServiceImpl.class);
    String s7 = operate7.findConfigInfo("raft_test", "cluster_test_2", "").getContent();
    String s8 = operate8.findConfigInfo("raft_test", "cluster_test_2", "").getContent();
    String s9 = operate9.findConfigInfo("raft_test", "cluster_test_2", "").getContent();
    Assert.assertArrayEquals("The three nodes must have consistent data", new String[] { s7, s8, s9 }, new String[] { "this.is.raft_cluster=lessspring_8", "this.is.raft_cluster=lessspring_8", "this.is.raft_cluster=lessspring_8" });
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) PersistService(com.alibaba.nacos.config.server.service.repository.PersistService) Test(org.junit.Test) BaseClusterTest(com.alibaba.nacos.test.base.BaseClusterTest)

Example 3 with PersistService

use of com.alibaba.nacos.config.server.service.repository.PersistService in project nacos by alibaba.

the class ConfigDerbyRaft_DITCase method test_d_modify_config.

@Test
public void test_d_modify_config() throws Exception {
    boolean result = iconfig7.publishConfig("raft_test", "cluster_test_1", "this.is.raft_cluster=lessspring_7_it_is_for_modify");
    Assert.assertTrue(result);
    ThreadUtils.sleep(5000);
    ConfigurableApplicationContext context7 = applications.get("8847");
    ConfigurableApplicationContext context8 = applications.get("8848");
    ConfigurableApplicationContext context9 = applications.get("8849");
    PersistService operate7 = context7.getBean(EmbeddedStoragePersistServiceImpl.class);
    PersistService operate8 = context8.getBean(EmbeddedStoragePersistServiceImpl.class);
    PersistService operate9 = context9.getBean(EmbeddedStoragePersistServiceImpl.class);
    String s7 = operate7.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
    String s8 = operate8.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
    String s9 = operate9.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
    Assert.assertArrayEquals("The three nodes must have consistent data", new String[] { s7, s8, s9 }, new String[] { "this.is.raft_cluster=lessspring_7_it_is_for_modify", "this.is.raft_cluster=lessspring_7_it_is_for_modify", "this.is.raft_cluster=lessspring_7_it_is_for_modify" });
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) PersistService(com.alibaba.nacos.config.server.service.repository.PersistService) Test(org.junit.Test) BaseClusterTest(com.alibaba.nacos.test.base.BaseClusterTest)

Example 4 with PersistService

use of com.alibaba.nacos.config.server.service.repository.PersistService in project nacos by alibaba.

the class ConfigDerbyRaft_DITCase method test_a_publish_config.

@Test
public void test_a_publish_config() throws Exception {
    boolean result = iconfig7.publishConfig("raft_test", "cluster_test_1", "this.is.raft_cluster=lessspring_7");
    Assert.assertTrue(result);
    ThreadUtils.sleep(5000);
    ConfigurableApplicationContext context7 = applications.get("8847");
    ConfigurableApplicationContext context8 = applications.get("8848");
    ConfigurableApplicationContext context9 = applications.get("8849");
    PersistService operate7 = context7.getBean(EmbeddedStoragePersistServiceImpl.class);
    PersistService operate8 = context8.getBean(EmbeddedStoragePersistServiceImpl.class);
    PersistService operate9 = context9.getBean(EmbeddedStoragePersistServiceImpl.class);
    String s7 = operate7.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
    String s8 = operate8.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
    String s9 = operate9.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
    Assert.assertArrayEquals("The three nodes must have consistent data", new String[] { s7, s8, s9 }, new String[] { "this.is.raft_cluster=lessspring_7", "this.is.raft_cluster=lessspring_7", "this.is.raft_cluster=lessspring_7" });
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) PersistService(com.alibaba.nacos.config.server.service.repository.PersistService) Test(org.junit.Test) BaseClusterTest(com.alibaba.nacos.test.base.BaseClusterTest)

Example 5 with PersistService

use of com.alibaba.nacos.config.server.service.repository.PersistService 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)

Aggregations

PersistService (com.alibaba.nacos.config.server.service.repository.PersistService)6 Test (org.junit.Test)5 BaseClusterTest (com.alibaba.nacos.test.base.BaseClusterTest)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4 ConfigInfo (com.alibaba.nacos.config.server.model.ConfigInfo)2 RestResult (com.alibaba.nacos.common.model.RestResult)1 ConfigInfo4Beta (com.alibaba.nacos.config.server.model.ConfigInfo4Beta)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 DatabaseOperate (com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate)1 File (java.io.File)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1