From ab50b3254b574e6cf89f18af21da8d0606794a20 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Wed, 12 Jul 2023 15:54:00 +0800 Subject: [PATCH] =?UTF-8?q?feature(web):=20=E4=BC=98=E5=8C=96=E9=A2=9D?= =?UTF-8?q?=E5=A4=96=E5=8F=82=E6=95=B0=E7=9A=84=E8=BE=93=E5=85=A5=E5=92=8C?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/template/deploy.ftl | 3 ++- .../src/main/resources/application-discovery.yml | 2 ++ .../service/web/controller/CloudController.java | 13 ++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/service-cli/service-cli-runner/src/main/resources/template/deploy.ftl b/service-cli/service-cli-runner/src/main/resources/template/deploy.ftl index 66a3428..03109d1 100644 --- a/service-cli/service-cli-runner/src/main/resources/template/deploy.ftl +++ b/service-cli/service-cli-runner/src/main/resources/template/deploy.ftl @@ -21,7 +21,8 @@ echo "${info.name} $host $hostname $datetime" ssh $host 'bash -s' < stop.sh ${runtime.jarPath}/${info.name}.jar <#if selectedHosts?seq_contains(host)> ssh $host "mkdir -p ${runtime.jarPath};curl ftp://yyy:QeY\!68\)4nH1@132.121.122.15:2222/${info.sourceJar} -o ${runtime.jarPath}/${info.name}.jar" -ssh $host "export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P\"Dp^A47>WSn:Wn].gs/+\"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.';nohup ${runtime.jdkPath} <#list environments?keys as key>-D${key?replace("_", ".")}=${environments[key]?string} -jar ${runtime.jarPath}/${info.name}.jar<#noparse> --datetime=${datetime} --hostname=${hostname} --eureka.instance.hostname=${hostname} --logging.parent=${log_path} --loki.url=${loki_url} --spring.cloud.zookeeper.connect-string=${zk_url} --eureka.client.service-url.defaultZone='${eureka_url}' --spring.security.meta.authority='${security_authority}' --spring.security.meta.username='${security_username}' --spring.security.meta.darkcode='${security_darkcode}' <#list arguments?keys as key>--${key?replace("_", ".")}=${arguments[key]?string} > /dev/null 2>&1 &" +start_time=`date +%Y%m%d%H%M%S` +ssh $host "export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P\"Dp^A47>WSn:Wn].gs/+\"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.';nohup ${runtime.jdkPath} <#list environments?keys as key>-D${key?replace("_", ".")}=${environments[key]?string} -jar ${runtime.jarPath}/${info.name}.jar<#noparse> --datetime=${datetime} --hostname=${hostname} --eureka.instance.hostname=${hostname} --logging.parent=${log_path} --loki.url=${loki_url} --eureka.client.service-url.defaultZone='${eureka_url}' --spring.cloud.zookeeper.connect-string=${zk_url} --spring.cloud.zookeeper.discovery.metadata.startTime=${start_time} --spring.cloud.zookeeper.discovery.metadata.hostIp=${host} --spring.security.meta.authority='${security_authority}' --spring.security.meta.username='${security_username}' --spring.security.meta.darkcode='${security_darkcode}' <#list arguments?keys as key>--${key?replace("_", ".")}=${arguments[key]?string} > /dev/null 2>&1 &" echo '' diff --git a/service-configuration/src/main/resources/application-discovery.yml b/service-configuration/src/main/resources/application-discovery.yml index a87ea5e..128f7ec 100644 --- a/service-configuration/src/main/resources/application-discovery.yml +++ b/service-configuration/src/main/resources/application-discovery.yml @@ -7,6 +7,8 @@ spring: enabled: ${spring.cloud.zookeeper.enabled} root: /hudi-services instance-id: ${spring.application.name}-${hostname}-${random.uuid}-${datetime:19700101} + metadata: + eureka: instance: hostname: localhost diff --git a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/CloudController.java b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/CloudController.java index 8152206..5bea5b0 100644 --- a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/CloudController.java +++ b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/CloudController.java @@ -10,6 +10,7 @@ import com.lanyuanxiaoyao.service.web.controller.base.BaseController; import com.lanyuanxiaoyao.service.web.entity.CloudServiceVO; import com.netflix.appinfo.InstanceInfo; import java.util.Map; +import org.apache.curator.x.discovery.ServiceInstance; import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.Maps; @@ -20,6 +21,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.netflix.eureka.EurekaServiceInstance; +import org.springframework.cloud.zookeeper.discovery.ZookeeperInstance; +import org.springframework.cloud.zookeeper.discovery.ZookeeperServiceInstance; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -68,6 +71,14 @@ public class CloudController extends BaseController { service.setServiceUpTime(info.getLeaseInfo().getServiceUpTimestamp()); } } + if (instance instanceof ZookeeperServiceInstance) { + ZookeeperServiceInstance zookeeperServiceInstance = (ZookeeperServiceInstance) instance; + ServiceInstance serviceInstance = zookeeperServiceInstance.getServiceInstance(); + if (ObjectUtil.isNotNull(serviceInstance)) { + service.setServiceUpTime(serviceInstance.getRegistrationTimeUTC()); + service.setStatus(serviceInstance.getPayload().getMetadata().getOrDefault("instance_status", "")); + } + } return service; }); } @@ -76,7 +87,7 @@ public class CloudController extends BaseController { return services() .groupBy(groupByField) .toMap() - .collectValues((serviceId, services) -> new CloudServiceVO(serviceId, services.toSortedListBy(CloudServiceVO.Service::getHost).toImmutable())) + .collectValues((serviceId, services) -> new CloudServiceVO(serviceId, services.toSortedListBy(CloudServiceVO.Service::getServiceUpTime).toImmutable())) .valuesView() .toSortedListBy(CloudServiceVO::getName) .toImmutable();