diff --git a/hera-all/hera-app/app-server/Dockerfile b/hera-all/hera-app/app-server/Dockerfile index d39c6e6f4..f3d340b8d 100644 --- a/hera-all/hera-app/app-server/Dockerfile +++ b/hera-all/hera-app/app-server/Dockerfile @@ -2,5 +2,5 @@ FROM openjdk:8-jre MAINTAINER zhangsan@qq.com RUN mkdir -p /home/work/app-server/ RUN mkdir -p /home/work/log/app-server/ -COPY ./target/app-server-1.0-SNAPSHOT.jar /home/work/app-server/app-server-1.0-SNAPSHOT.jar -ENTRYPOINT ["java","-jar","-Xms512M","-Xmx512M","-XX:+UseG1GC","-XX:+PrintReferenceGC","-XX:+PrintGCDetails","-XX:+PrintGCDateStamps","-XX:+PrintHeapAtGC","-Xloggc:/home/work/log/app-server/gc.log","/home/work/app-server/app-server-1.0-SNAPSHOT.jar"] \ No newline at end of file +COPY ./target/app-server-1.4-SNAPSHOT.jar /home/work/app-server/app-server-1.4-SNAPSHOT.jar +ENTRYPOINT ["java","-jar","-Xms512M","-Xmx512M","-XX:+UseG1GC","-XX:+PrintReferenceGC","-XX:+PrintGCDetails","-XX:+PrintGCDateStamps","-XX:+PrintHeapAtGC","-Xloggc:/home/work/log/app-server/gc.log","/home/work/app-server/app-server-1.4-SNAPSHOT.jar"] \ No newline at end of file diff --git a/hera-all/hera-app/app-server/src/main/java/com/xiaomi/mone/app/controller/HeraAppEnvController.java b/hera-all/hera-app/app-server/src/main/java/com/xiaomi/mone/app/controller/HeraAppEnvController.java index 5767f1f6f..d2dc6fded 100644 --- a/hera-all/hera-app/app-server/src/main/java/com/xiaomi/mone/app/controller/HeraAppEnvController.java +++ b/hera-all/hera-app/app-server/src/main/java/com/xiaomi/mone/app/controller/HeraAppEnvController.java @@ -6,6 +6,7 @@ import com.xiaomi.mone.app.valid.AddGroup; import com.xiaomi.mone.app.valid.UpdateGroup; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -17,6 +18,7 @@ */ @RestController @RequestMapping("/hera/app/env") +@ConditionalOnProperty(name = "service.selector.property", havingValue = "outer") public class HeraAppEnvController { @Autowired diff --git a/hera-all/hera-app/app-server/src/main/java/com/xiaomi/mone/app/controller/TestController.java b/hera-all/hera-app/app-server/src/main/java/com/xiaomi/mone/app/controller/TestController.java new file mode 100644 index 000000000..f42fa529b --- /dev/null +++ b/hera-all/hera-app/app-server/src/main/java/com/xiaomi/mone/app/controller/TestController.java @@ -0,0 +1,42 @@ +package com.xiaomi.mone.app.controller; + +import com.xiaomi.mone.app.model.vo.HeraAppEnvVo; +import com.xiaomi.mone.app.service.env.DefaultEnvIpFetch; +import com.xiaomi.mone.app.service.env.DefaultHttpEnvIpFetch; +import com.xiaomi.mone.app.service.env.EnvIpFetch; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * @author wtt + * @version 1.0 + * @description + * @date 2023/8/17 10:00 + */ +@RestController +@RequestMapping("/test") +@ConditionalOnProperty(name = "service.selector.property", havingValue = "outer") +public class TestController { + + @Resource + private DefaultEnvIpFetch defaultEnvIpFetch; + + @Resource + private DefaultHttpEnvIpFetch defaultHttpEnvIpFetch; + + @GetMapping("/env/ip/fetch/{appId}") + public EnvIpFetch getEnvIpFetch(@PathVariable String appId) { + return defaultEnvIpFetch.getEnvFetch(appId); + } + + + @GetMapping("/hera/app/env") + public HeraAppEnvVo getHeraAppEnvVo(Long appBaseId, Long appId, String appName) throws Exception { + return defaultHttpEnvIpFetch.fetch(appBaseId, appId, appName); + } +} diff --git a/hera-all/hera-app/app-server/src/main/resources/application-open.properties b/hera-all/hera-app/app-server/src/main/resources/application-open.properties index f8baf7017..601c324b4 100644 --- a/hera-all/hera-app/app-server/src/main/resources/application-open.properties +++ b/hera-all/hera-app/app-server/src/main/resources/application-open.properties @@ -14,8 +14,4 @@ job_start_flag=false rocket.mq.producer.group=hera_app rocket.mq.hera.app.topic=hera_app_operate -rocket.mq.hera.app.tag=app_modify - -hera.tpc.url=http://mi-tpc:8097 - -hera.operator.env.url=http://mi-operator-env:8097 \ No newline at end of file +rocket.mq.hera.app.tag=app_modify \ No newline at end of file diff --git a/hera-all/hera-app/app-server/src/main/resources/application.properties b/hera-all/hera-app/app-server/src/main/resources/application.properties index 55c5dbac5..2fda4c7b5 100644 --- a/hera-all/hera-app/app-server/src/main/resources/application.properties +++ b/hera-all/hera-app/app-server/src/main/resources/application.properties @@ -30,8 +30,4 @@ job_start_flag=@job_start_flag@ app.ip.fetch.type=nacos -service.selector.property=outer - -hera.tpc.url=@hera.tpc.url@ - -hera.operator.env.url=@hera.operator.env.url@ \ No newline at end of file +service.selector.property=outer \ No newline at end of file diff --git a/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/env/DefaultEnvIpFetch.java b/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/env/DefaultEnvIpFetch.java index 0f6c04bb6..9664ea49d 100644 --- a/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/env/DefaultEnvIpFetch.java +++ b/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/env/DefaultEnvIpFetch.java @@ -2,17 +2,16 @@ import com.alibaba.nacos.api.config.annotation.NacosValue; import com.google.gson.Gson; +import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import com.xiaomi.mone.app.common.Result; import com.xiaomi.mone.app.common.TpcLabelRes; import com.xiaomi.mone.app.common.TpcPageRes; import lombok.extern.slf4j.Slf4j; -import okhttp3.FormBody; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; +import okhttp3.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -29,6 +28,7 @@ */ @Service @Slf4j +@ConditionalOnProperty(name = "service.selector.property", havingValue = "outer") public class DefaultEnvIpFetch { @Autowired @@ -40,7 +40,7 @@ public class DefaultEnvIpFetch { @Value("${app.ip.fetch.type}") private String envApppType; - @NacosValue("${hera.tpc.url}") + @NacosValue(value = "${hera.tpc.url}", autoRefreshed = true) private String heraTpcUrl; @Resource @@ -66,10 +66,15 @@ public EnvIpFetch getEnvFetch(String appId) { } private EnvIpFetch getEnvFetchFromRemote(String appId) { + JsonObject jsonObject = new JsonObject(); + MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); + jsonObject.addProperty("parentId", appId); + jsonObject.addProperty("flagKey", DEFAULT_REGISTER_REMOTE_TYPE); + RequestBody requestBody = RequestBody.create(mediaType, gson.toJson(jsonObject)); + Request request = new Request.Builder() - .url(String.format(heraTpcUrl, HERA_TPC_APP_DETAIL_URL)) - .post(new FormBody.Builder().add("parentId", appId) - .add("flagKey", DEFAULT_REGISTER_REMOTE_TYPE).build()) + .url(String.format("%s%s", heraTpcUrl, HERA_TPC_APP_DETAIL_URL)) + .post(requestBody) .build(); try { Response response = okHttpClient.newCall(request).execute(); diff --git a/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/env/DefaultHttpEnvIpFetch.java b/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/env/DefaultHttpEnvIpFetch.java index 0231dfb8d..bf43887bb 100644 --- a/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/env/DefaultHttpEnvIpFetch.java +++ b/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/env/DefaultHttpEnvIpFetch.java @@ -1,5 +1,6 @@ package com.xiaomi.mone.app.service.env; +import com.alibaba.nacos.api.config.annotation.NacosValue; import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -8,7 +9,7 @@ import com.xiaomi.mone.app.model.vo.HeraAppEnvVo; import lombok.extern.slf4j.Slf4j; import okhttp3.*; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -24,9 +25,10 @@ */ @Service @Slf4j +@ConditionalOnProperty(name = "service.selector.property", havingValue = "outer") public class DefaultHttpEnvIpFetch implements EnvIpFetch { - @Value("$hera.operator.env.url}") + @NacosValue(value = "$hera.operator.env.url}", autoRefreshed = true) private String operatorEnvUrl; @Resource private OkHttpClient okHttpClient; @@ -42,7 +44,7 @@ public HeraAppEnvVo fetch(Long appBaseId, Long appId, String appName) throws Exc jsonObject.addProperty("name", appName); RequestBody requestBody = RequestBody.create(mediaType, gson.toJson(jsonObject)); - Request request = new Request.Builder().url(String.format(operatorEnvUrl, HERA_OPERATOR_ENV_URL)).post(requestBody).build(); + Request request = new Request.Builder().url(String.format("%s%s", operatorEnvUrl, HERA_OPERATOR_ENV_URL)).post(requestBody).build(); Response response = okHttpClient.newCall(request).execute(); if (response.isSuccessful()) { String rstJson = response.body().string(); diff --git a/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/impl/HeraAppEnvServiceImpl.java b/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/impl/HeraAppEnvServiceImpl.java index 90a91cdc7..3b5e06ad8 100644 --- a/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/impl/HeraAppEnvServiceImpl.java +++ b/hera-all/hera-app/app-service/src/main/java/com/xiaomi/mone/app/service/impl/HeraAppEnvServiceImpl.java @@ -22,6 +22,7 @@ import org.apache.rocketmq.common.message.Message; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; @@ -39,6 +40,7 @@ */ @Service @Slf4j +@ConditionalOnProperty(name = "service.selector.property", havingValue = "outer") public class HeraAppEnvServiceImpl implements HeraAppEnvService { private final HeraAppBaseInfoMapper heraAppBaseInfoMapper;