package io.renren.algorithmPublished;

import com.google.gson.JsonObject;
import io.renren.RenrenApplication;
import io.renren.common.utils.GsonUtil;
import io.renren.common.utils.JavaShellUtil;
import io.renren.modules.kubesphere.service.S2iService;
import io.renren.modules.minio.pojo.MinioAlgorithm;
import io.renren.modules.minio.service.impl.MinioAlgorithmServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @Description
 * @Author chenrj.xdu@gmail.com
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2021/10/12
 */

@RunWith(SpringRunner.class)
@SpringBootTest(classes = RenrenApplication.class)
public class algorithmPublish {
    final private String jsonData = "{ \"metadata\": { \"name\": \"algorithmimn7\", \"namespace\": \"mkcloud\", \"uid\": \"003c8114-2c14-4934-8d07-4ec4fa9b516e\", \"resourceVersion\": \"3306252\", \"generation\": 5, \"creationTimestamp\": \"2021-10-12T11:01:20Z\", \"labels\": { \"controller-tools.k8s.io\": \"1.0\" }, \"annotations\": { \"kubesphere.io/creator\": \"admin\" }, \"finalizers\": [ \"s2ibinary.finalizers.kubesphere.io\" ], \"managedFields\": [ { \"manager\": \"Mozilla\", \"operation\": \"Update\", \"apiVersion\": \"devops.kubesphere.io/v1alpha1\", \"time\": \"2021-10-12T11:01:20Z\", \"fieldsType\": \"FieldsV1\", \"fieldsV1\": { \"f:metadata\": { \"f:annotations\": { \".\": {}, \"f:kubesphere.io/creator\": {} }, \"f:labels\": { \".\": {}, \"f:controller-tools.k8s.io\": {} } } } }, { \"manager\": \"controller-manager\", \"operation\": \"Update\", \"apiVersion\": \"devops.kubesphere.io/v1alpha1\", \"time\": \"2021-10-12T11:01:20Z\", \"fieldsType\": \"FieldsV1\", \"fieldsV1\": { \"f:metadata\": { \"f:finalizers\": { \".\": {}, \"v:\\\"s2ibinary.finalizers.kubesphere.io\\\"\": {} } }, \"f:spec\": { \".\": {}, \"f:downloadURL\": {}, \"f:fileName\": {}, \"f:md5\": {}, \"f:size\": {} }, \"f:status\": {} } }, { \"manager\": \"ks-apiserver\", \"operation\": \"Update\", \"apiVersion\": \"devops.kubesphere.io/v1alpha1\", \"time\": \"2021-10-12T11:01:28Z\", \"fieldsType\": \"FieldsV1\", \"fieldsV1\": { \"f:spec\": { \"f:downloadURL\": {}, \"f:fileName\": {}, \"f:md5\": {}, \"f:size\": {}, \"f:uploadTimeStamp\": {} }, \"f:status\": { \"f:phase\": {} } } } ] }, \"spec\": { \"fileName\": \"algorithm\", \"md5\": \"fbe7b95b779342c25e393885a910cba9\", \"size\": \"9M\", \"downloadURL\": \"http://ks-apiserver.kubesphere-system.svc/kapis/devops.kubesphere.io/v1alpha2/namespaces/mkcloud/s2ibinaries/algorithmimn7/file/algorithm\", \"uploadTimeStamp\": \"2021-10-12T11:01:28Z\" }, \"status\": { \"phase\": \"Ready\" } }";

    @Autowired
    MinioAlgorithmServiceImpl minioAlgorithmService;

    @Autowired
    S2iService s2iService;

    @Test
    public void getUrl() {
        System.out.println("原始数据:" + jsonData);
        JsonObject jsonObject = GsonUtil.convertJsonObject(jsonData);
        String spec = jsonObject.get("spec").toString();
        System.out.println("spec数据:" + spec);
        JsonObject specJsonObject = GsonUtil.convertJsonObject(spec);
        String imageSize = specJsonObject.get("size").toString();
        String downloadURL = specJsonObject.get("downloadURL").toString();
        System.out.println(downloadURL);
    }


    @Test
    public void application() {

        System.out.println(minioAlgorithmService.findModelByName("gasPre"));


//        String user_dir = System.getProperty("user.dir");
//        System.out.println(user_dir);
//        String command = "/bin/zsh " + user_dir + "/src/test/java/io/renren/shell.sh";
//        String res = JavaShellUtil.execute(command);
//        System.out.println(res);


//        List<MinioAlgorithm> list = minioAlgorithmService.getMinioAlgorithmList();
//        for(MinioAlgorithm minioAlgorithm : list) {
//            System.out.println(minioAlgorithm);
//        }

    }
}
