Search in sources :

Example 1 with DerbyImportEvent

use of com.alibaba.nacos.config.server.model.event.DerbyImportEvent 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;
}
Also used : RestResult(com.alibaba.nacos.common.model.RestResult) DerbyImportEvent(com.alibaba.nacos.config.server.model.event.DerbyImportEvent) DatabaseOperate(com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate) DeferredResult(org.springframework.web.context.request.async.DeferredResult) PostMapping(org.springframework.web.bind.annotation.PostMapping) Secured(com.alibaba.nacos.auth.annotation.Secured)

Aggregations

Secured (com.alibaba.nacos.auth.annotation.Secured)1 RestResult (com.alibaba.nacos.common.model.RestResult)1 DerbyImportEvent (com.alibaba.nacos.config.server.model.event.DerbyImportEvent)1 DatabaseOperate (com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 DeferredResult (org.springframework.web.context.request.async.DeferredResult)1