package com.lanyuanxiaoyao.service.yarn.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
import com.lanyuanxiaoyao.service.yarn.service.JobService;
import org.eclipse.collections.api.list.ImmutableList;
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;

/**
 * Job
 *
 * @author lanyuanxiaoyao
 * @date 2023-04-23
 */
@RestController
@RequestMapping("job")
public class JobController {
    private static final Logger logger = LoggerFactory.getLogger(JobController.class);

    private final JobService jobService;

    public JobController(@Qualifier("JobService") JobService jobService) {
        this.jobService = jobService;
    }

    @GetMapping("list")
    public ImmutableList<YarnApplication> list() throws JsonProcessingException {
        return jobService.list();
    }

    @GetMapping("list_equals")
    public ImmutableList<YarnApplication> listEquals(@RequestParam("name") String name) throws JsonProcessingException {
        return jobService.listEquals(name);
    }

    @GetMapping("list_like")
    public ImmutableList<YarnApplication> listLike(@RequestParam("text") String text) throws JsonProcessingException {
        return jobService.listLike(text);
    }

    @GetMapping("kill")
    public void kill(@RequestParam("application_id") String applicationId) {
        jobService.kill(applicationId);
    }

    @GetMapping("detail")
    public YarnApplication detail(@RequestParam("application_id") String applicationId) throws Exception {
        return jobService.detail(applicationId);
    }
}
