use of com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate in project nacos by alibaba.
the class ConfigOpsController method importDerby.
/**
* // TODO the front page should appear operable The external data source is imported into derby.
*
* <p>mysqldump --defaults-file="XXX" --host=0.0.0.0 --protocol=tcp --user=XXX --extended-insert=FALSE \
* --complete-insert=TRUE \ --skip-triggers --no-create-info --skip-column-statistics "{SCHEMA}" "{TABLE_NAME}"
*
* @param multipartFile {@link MultipartFile}
* @return {@link DeferredResult}
*/
@PostMapping(value = "/data/removal")
@Secured(action = ActionTypes.WRITE, resource = "nacos/admin")
public DeferredResult<RestResult<String>> importDerby(@RequestParam(value = "file") MultipartFile multipartFile) {
DeferredResult<RestResult<String>> response = new DeferredResult<>();
if (!PropertyUtil.isEmbeddedStorage()) {
response.setResult(RestResultUtils.failed("Limited to embedded storage mode"));
return response;
}
DatabaseOperate databaseOperate = ApplicationUtils.getBean(DatabaseOperate.class);
WebUtils.onFileUpload(multipartFile, file -> {
NotifyCenter.publishEvent(new DerbyImportEvent(false));
databaseOperate.dataImport(file).whenComplete((result, ex) -> {
NotifyCenter.publishEvent(new DerbyImportEvent(true));
if (Objects.nonNull(ex)) {
response.setResult(RestResultUtils.failed(ex.getMessage()));
return;
}
response.setResult(result);
});
}, response);
return response;
}
use of com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate 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);
}
}
Aggregations