Commit 6e383b95 authored by cwk's avatar cwk

定位服务和田浩瀚服务接入

parent 43111fd2
......@@ -73,7 +73,7 @@ public class DeployService extends BaseService {
return false;
}else{
if(jsonObject.get("code").asInt()!= ResponseConstant.RES_OK){
log.info("Error starting deploy: {}", jsonObject.get("msg").asText());
log.info("Error stopping deploy: {}", jsonObject.get("msg").asText());
return false;
}
}
......
package com.hpcner.statusmanageservice.serv.other;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hpcner.statusmanageservice.bean.entity.ServiceInfo;
import com.hpcner.statusmanageservice.constant.ResponseConstant;
import com.hpcner.statusmanageservice.serv.BaseService;
import com.hpcner.statusmanageservice.service.database.ServiceInfoService;
import com.hpcner.statusmanageservice.utils.ApplicationContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.*;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
@Component("other_localization")
@Slf4j
public class LocalizationService extends BaseService {
//这是本地服务的位置
public static final String BASE_URL="http://Localization-Service";
@Override
public boolean start(String json) throws JsonProcessingException {
RestTemplate restTemplate = ApplicationContextUtil.getBean(RestTemplate.class);
String url = BASE_URL + "/start";
ResponseEntity<String> result = restTemplate.postForEntity(url, null, String.class);
if(result.getStatusCode().equals(HttpStatus.OK)){
String retBody = result.getBody();
log.info("Localization Service start result: {}", retBody);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonObject = mapper.readTree(retBody);
if(!jsonObject.has("code")){
log.info("Error parse Localization Service result: {}", retBody);
return false;
}else{
if(jsonObject.get("code").asInt()!= ResponseConstant.RES_OK){
log.info("Error starting Localization Service: {}", jsonObject.get("message").asText());
return false;
}
}
ServiceInfoService serviceInfoService = ApplicationContextUtil.getBean(ServiceInfoService.class);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setServiceId(getId());
serviceInfo.setServiceState(true);
serviceInfoService.UpsertServiceInfoByServiceId(serviceInfo);
return true;
}else{
return false;
}
}
@Override
public boolean stop() throws JsonProcessingException {
RestTemplate restTemplate = ApplicationContextUtil.getBean(RestTemplate.class);
String url = BASE_URL + "/stop";
ResponseEntity<String> result = restTemplate.postForEntity(url, null, String.class);
if(result.getStatusCode().equals(HttpStatus.OK)){
String retBody = result.getBody();
log.info("Localization Service start result: {}", retBody);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonObject = mapper.readTree(retBody);
if(!jsonObject.has("code")){
log.info("Error parse Localization Service result: {}", retBody);
return false;
}else{
if(jsonObject.get("code").asInt()!= ResponseConstant.RES_OK){
log.info("Error stopping Localization Service: {}", jsonObject.get("message").asText());
return false;
}
}
ServiceInfoService serviceInfoService = ApplicationContextUtil.getBean(ServiceInfoService.class);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setServiceId(getId());
serviceInfo.setServiceState(false);
serviceInfoService.UpsertServiceInfoByServiceId(serviceInfo);
return true;
}else{
return false;
}
}
@Override
public boolean restart(String json) throws JsonProcessingException {
if(!stop()){
return false;
}
if(start(json)){
return true;
}
else{
return false;
}
}
}
package com.hpcner.statusmanageservice.serv.recog;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hpcner.statusmanageservice.bean.entity.ServiceInfo;
import com.hpcner.statusmanageservice.serv.BaseService;
import com.hpcner.statusmanageservice.service.database.ServiceInfoService;
import com.hpcner.statusmanageservice.utils.ApplicationContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.*;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.concurrent.atomic.AtomicBoolean;
@Component("recog-thh")
@Slf4j
public class RecogThhService extends BaseService {
//curl -X GET http://localhost:8000/e2e_status
// {"status":"success","services":{"service1":"stopped","service2":"stopped"}}
//curl -X GET http://localhost:8000/e2e_status
//{"status":"success","services":{"service1":"running","service2":"running"}}(base)
// curl -X POST http://localhost:8000/e2e_start
//{"status":"completed","details":{"service1":"started","service2":"started"}}(base) [cwk@iZ2ze2pfzefpro00cn0ybhZ StatusManageService]$ curl -X POST http://localhost:8000/e2e_start
//{"status":"completed","details":{"service1":"already running","service2":"already running"}}
// curl -X POST http://localhost:8000/e2e_stop
//curl -X POST http://localhost:8000/e2e_stop
//{"status":"completed","details":{"service1":"stopped","service2":"stopped"}}(base) [cwk@iZ2ze2pfzefpro00cn0ybhZ StatusManageService]$ curl -X POST http://localhost:8000/e2e_stop
//{"status":"completed","details":{"service1":"already stopped","service2":"already stopped"}}
public static final String BASE_URL="http://localhost:8000";
@Override
public boolean start(String json) {
//curl -X POST "http://localhost:8081/models?url=retinanet.mar&initial_workers=3"
try {
ObjectMapper mapper = new ObjectMapper();
String url = String.format("%s/e2e_start", BASE_URL);
log.info("Start recog thh {}", url);
RestTemplate restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory());
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, null, String.class);
if(!responseEntity.getStatusCode().equals(HttpStatus.OK)){
return false;
}
JsonNode resultObject = mapper.readTree(responseEntity.getBody());
if (resultObject == null) {
log.info("Error parse recog thh result: {}", responseEntity.getBody());
return false;
}
if (!resultObject.has("details")) {
log.info("Error starting recog thh: {}", responseEntity.getBody());
return false;
}
AtomicBoolean started = new AtomicBoolean(false);
resultObject.get("details").fields().forEachRemaining(entry -> {
String serviceName = entry.getKey();
String serviceStatus = entry.getValue().asText();
if(serviceStatus.contains("already")) {
log.info("Service {} is already running", serviceName);
started.set(true);
}
});
if(started.get()){
return false;
}
ServiceInfoService serviceInfoService = ApplicationContextUtil.getBean(ServiceInfoService.class);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setServiceId(getId());
serviceInfo.setServiceState(true);
serviceInfoService.UpsertServiceInfoByServiceId(serviceInfo);
return true;
} catch (Exception e) {
log.error("Exception in start recog zgs", e);
return false;
}
}
@Override
public boolean stop() {
try {
ObjectMapper mapper = new ObjectMapper();
String url = String.format("%s/e2e_stop", BASE_URL);
log.info("Stop recog thh {}", url);
RestTemplate restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory());
ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, null, String.class);
if(!responseEntity.getStatusCode().equals(HttpStatus.OK)){
return false;
}
JsonNode resultObject = mapper.readTree(responseEntity.getBody());
if (resultObject == null) {
log.info("Error parse recog thh result: {}", responseEntity.getBody());
return false;
}
if (!resultObject.has("details")) {
log.info("Error Stopping recog thh: {}", responseEntity.getBody());
return false;
}
AtomicBoolean started = new AtomicBoolean(false);
resultObject.get("details").fields().forEachRemaining(entry -> {
String serviceName = entry.getKey();
String serviceStatus = entry.getValue().asText();
if(serviceStatus.contains("already")) {
log.info("Service {} is already stopped", serviceName);
started.set(true);
}
});
if(started.get()){
return false;
}
ServiceInfoService serviceInfoService = ApplicationContextUtil.getBean(ServiceInfoService.class);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setServiceId(getId());
serviceInfo.setServiceState(false);
serviceInfoService.UpsertServiceInfoByServiceId(serviceInfo);
return true;
} catch (Exception e) {
log.error("Exception in stop recog zgs", e);
return false;
}
}
@Override
public boolean restart(String json) {
if(!stop()){
return false;
}
if(start(json)){
return true;
}
else{
return false;
}
}
}
......@@ -51,6 +51,8 @@ service-config:
- id: recog-zgs
name: 张高帅算法
#json: "{ \"url\":\"String\",\"initial_workers\":\"Integer\" }"
- id: recog-thh
name: 田浩瀚算法
deploy-lists:
- id: deploy_zhangyuhao
......@@ -71,3 +73,6 @@ service-config:
#json: ""
- id: other_simulator
name: 模拟器服务
- id: other_localization
name: 定位算法
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment