package com.lanyuanxiaoyao.service.flink;

import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.eclipsecollections.EclipseCollectionsModule;
import com.lanyuanxiaoyao.service.configuration.entity.flink.FlinkTaskManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 测试 Flink 解析
 *
 * @author lanyuanxiaoyao
 * @date 2023-05-04
 */
public class TestJsonParse {
    private static final Logger logger = LoggerFactory.getLogger(TestJsonParse.class);

    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new EclipseCollectionsModule());
        mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        mapper.setDefaultPropertyInclusion(JsonInclude.Include.NON_EMPTY);
        String url = "b5s120.hdp.dc:8088/proxy/application_1672368973318_1814";
        String body = HttpUtil.get(StrUtil.format("http://{}/v1/taskmanagers/container_1672368973318_1814_01_000002", url));
        logger.info("{}", mapper.writeValueAsString(mapper.readValue(body, FlinkTaskManager.class)));
    }
}
