|
@@ -14,9 +14,13 @@ import com.css.simulation.resource.scheduler.pojo.po.TaskIndexPO;
|
|
import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
|
|
import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
|
|
import com.css.simulation.resource.scheduler.pojo.to.ScoreTO;
|
|
import com.css.simulation.resource.scheduler.pojo.to.ScoreTO;
|
|
import com.css.simulation.resource.scheduler.util.MinioUtil;
|
|
import com.css.simulation.resource.scheduler.util.MinioUtil;
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import io.minio.MinioClient;
|
|
import io.minio.MinioClient;
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.http.client.config.RequestConfig;
|
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
@@ -30,6 +34,12 @@ import java.util.stream.Collectors;
|
|
public class TaskService {
|
|
public class TaskService {
|
|
|
|
|
|
private final String USER_ID = "simulation-resource-scheduler";
|
|
private final String USER_ID = "simulation-resource-scheduler";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ CloseableHttpClient closeableHttpClient;
|
|
|
|
+ @Autowired
|
|
|
|
+ RequestConfig requestConfig;
|
|
@Autowired
|
|
@Autowired
|
|
MinioClient minioClient;
|
|
MinioClient minioClient;
|
|
@Value("${minio.bucket-name}")
|
|
@Value("${minio.bucket-name}")
|
|
@@ -62,6 +72,14 @@ public class TaskService {
|
|
String pyPath;
|
|
String pyPath;
|
|
@Value("${scheduler.linux-temp-path}")
|
|
@Value("${scheduler.linux-temp-path}")
|
|
String linuxTempPath;
|
|
String linuxTempPath;
|
|
|
|
+ @Value("${simulation-cloud.client-id}")
|
|
|
|
+ String clientId;
|
|
|
|
+ @Value("${simulation-cloud.client-secret}")
|
|
|
|
+ String clientSecret;
|
|
|
|
+ @Value("${simulation-cloud.token-uri}")
|
|
|
|
+ String tokenUri;
|
|
|
|
+ @Value("${simulation-cloud.evaluation-level-uri}")
|
|
|
|
+ String evaluationLevelUri;
|
|
|
|
|
|
public void taskTick(String taskId) {
|
|
public void taskTick(String taskId) {
|
|
log.info("------- /tick 接收到任务 " + taskId + "的心跳!");
|
|
log.info("------- /tick 接收到任务 " + taskId + "的心跳!");
|
|
@@ -200,6 +218,18 @@ public class TaskService {
|
|
totalTaskIndex.setIsDeleted("0");
|
|
totalTaskIndex.setIsDeleted("0");
|
|
taskIndexMapper.insertTotalIndex(totalTaskIndex);
|
|
taskIndexMapper.insertTotalIndex(totalTaskIndex);
|
|
|
|
|
|
|
|
+ // 调用 server 的接口,计算评价等级
|
|
|
|
+ String tokenUrl = tokenUri + "?grant_type=client_credentials"
|
|
|
|
+ + "&client_id=" + clientId
|
|
|
|
+ + "client_secret" + clientSecret;
|
|
|
|
+ String response = HttpUtil.get(closeableHttpClient, requestConfig, tokenUrl);
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
+ JsonNode jsonNode = objectMapper.readTree(response);
|
|
|
|
+ String accessToken = jsonNode.path("access_token").asText();
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("Authorization", "Bearer " + accessToken);
|
|
|
|
+ HttpUtil.post(closeableHttpClient, requestConfig, evaluationLevelUri, headers, null);
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|