Skip to content

Commit

Permalink
Merge pull request XiaoMi#591 from wtt40122/master
Browse files Browse the repository at this point in the history
feat: update hera-app env ips
  • Loading branch information
sadadw1 authored Aug 24, 2023
2 parents 1160124 + ab8a65c commit 84ea265
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 23 deletions.
4 changes: 2 additions & 2 deletions hera-all/hera-app/app-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM openjdk:8-jre
MAINTAINER [email protected]
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"]
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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -17,6 +18,7 @@
*/
@RestController
@RequestMapping("/hera/app/env")
@ConditionalOnProperty(name = "service.selector.property", havingValue = "outer")
public class HeraAppEnvController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
rocket.mq.hera.app.tag=app_modify
Original file line number Diff line number Diff line change
Expand Up @@ -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@
service.selector.property=outer
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +28,7 @@
*/
@Service
@Slf4j
@ConditionalOnProperty(name = "service.selector.property", havingValue = "outer")
public class DefaultEnvIpFetch {

@Autowired
Expand All @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +40,7 @@
*/
@Service
@Slf4j
@ConditionalOnProperty(name = "service.selector.property", havingValue = "outer")
public class HeraAppEnvServiceImpl implements HeraAppEnvService {

private final HeraAppBaseInfoMapper heraAppBaseInfoMapper;
Expand Down

0 comments on commit 84ea265

Please sign in to comment.