package com.persagy.dmp.file.controller;

import cn.hutool.core.map.MapUtil;
import com.persagy.dmp.common.model.response.CommonResult;
import com.persagy.dmp.common.utils.ResultHelper;
import com.persagy.dmp.file.service.FileMigrateFactory;
import com.persagy.dmp.file.service.FileMigrateService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 版本定义Controller
 * @author Charlie Yu
 * @date 2021-06-23
 */
@Slf4j
@RestController
@RequestMapping("/migrate/file")
@RequiredArgsConstructor
public class FileMigrateController {

    /**
     * 启动文件迁移
     * 迁移范围：hbase迁移至minio
     * @param requestMap
     * {
     *     "hdfsUrl":"http://node1:8020",
     *     "fileBasePath":"/test/files",
     *     "hdfsUser":"saga",
     *     "minioUrl":"http://192.168.100.210:9000",
     *     "minioUser":"root",
     *     "minioSecret":"persagy@2020"
     * }
     */
    @PostMapping("/start")
    public CommonResult<String> start(@RequestBody Map<String, Object> requestMap) {
        // 处理参数
        final String migrateType = MapUtil.getStr(requestMap, "migrateType");
        FileMigrateService service = FileMigrateFactory.getService(migrateType);
        service.migrateFiles(requestMap);
        return ResultHelper.success();
    }

}
