package com.lanyuanxiaoyao.service.launcher.synchronizer.controller;

import com.lanyuanxiaoyao.service.launcher.synchronizer.service.SynchronizerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 同步控制
 *
 * @author ZhangJiacheng
 * @date 2023-12-07
 */
@RestController
@RequestMapping("launcher/synchronizer")
public class SynchronizerController {
    private static final Logger logger = LoggerFactory.getLogger(SynchronizerController.class);

    private final SynchronizerService synchronizerService;

    public SynchronizerController(@Qualifier("sync-service") SynchronizerService synchronizerService) {
        this.synchronizerService = synchronizerService;
    }

    @GetMapping("start")
    public String start(@RequestParam("flink_job_id") Long flinkJobId) throws Exception {
        logger.info("Try to start job: {}", flinkJobId);
        return synchronizerService.start(flinkJobId);
    }

    @GetMapping("stop")
    public void stop(@RequestParam("flink_job_id") Long flinkJobId) throws Exception {
        logger.info("Try to start job: {}", flinkJobId);
        synchronizerService.stop(flinkJobId);
    }
}
