Add runtime.port and runtime.server for running anywhere
This commit is contained in:
parent
35f07f2cb4
commit
fab8a4a4cf
2 changed files with 29 additions and 4 deletions
|
|
@ -72,6 +72,8 @@ services:
|
||||||
|
|
||||||
|
|
||||||
#-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=y
|
#-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=y
|
||||||
|
|
||||||
|
|
||||||
runtime-proxy-1:
|
runtime-proxy-1:
|
||||||
image: runtime-proxy
|
image: runtime-proxy
|
||||||
container_name: "runtime-proxy-1"
|
container_name: "runtime-proxy-1"
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,16 @@ public class KieServiceCommon {
|
||||||
private RuntimeRepository runtimeRepository;
|
private RuntimeRepository runtimeRepository;
|
||||||
@Inject
|
@Inject
|
||||||
private ContainerRuntimeRepository containerRuntimeRepository;
|
private ContainerRuntimeRepository containerRuntimeRepository;
|
||||||
|
|
||||||
@Value("${server.port}")
|
@Value("${server.port}")
|
||||||
private int serverPort;
|
private int serverPort;
|
||||||
|
|
||||||
|
@Value("${runtime.port=-1}")
|
||||||
|
private int runtimePort;
|
||||||
|
|
||||||
|
@Value("${runtime.server:none}")
|
||||||
|
private String runtimeServer;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationContext appContext;
|
private ApplicationContext appContext;
|
||||||
private String hostName = "localhost";
|
private String hostName = "localhost";
|
||||||
|
|
@ -124,18 +132,32 @@ public class KieServiceCommon {
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
logger.info("initCamelBusinessRoutes.getLocalHost", e);
|
logger.info("initCamelBusinessRoutes.getLocalHost", e);
|
||||||
}
|
}
|
||||||
List<RuntimePersist> itIsMes = runtimeRepository.findByServerNameAndHostname(serverName, hostName);
|
List<RuntimePersist> itIsMes;
|
||||||
|
if (runtimePort==-1){
|
||||||
|
itIsMes = runtimeRepository.findByServerNameAndHostname(serverName, hostName);
|
||||||
|
}else{
|
||||||
|
itIsMes = runtimeRepository.findByServerName(serverName);
|
||||||
|
}
|
||||||
|
|
||||||
ServiceResponse<KieServerInfo> result = server.getInfo();
|
ServiceResponse<KieServerInfo> result = server.getInfo();
|
||||||
String version = result.getResult().getVersion();
|
String version = result.getResult().getVersion();
|
||||||
if (itIsMes.size() == 0) {
|
if (itIsMes.isEmpty()) {
|
||||||
RuntimePersist runtimePersist = new RuntimePersist(serverName, version, hostName,
|
RuntimePersist runtimePersist = new RuntimePersist(serverName, version, hostName,
|
||||||
String.valueOf(serverPort), null,
|
String.valueOf(serverPort), null,
|
||||||
hostName, RuntimePersist.STATUS.UP.toString());
|
hostName, RuntimePersist.STATUS.UP.toString());
|
||||||
|
if (runtimePort!=-1){
|
||||||
|
runtimePersist.setHostname(runtimeServer);
|
||||||
|
runtimePersist.setServerPort(String.valueOf(runtimePort));
|
||||||
|
}
|
||||||
String isSwarm = System.getProperty("org.kie.server.swarm");
|
String isSwarm = System.getProperty("org.kie.server.swarm");
|
||||||
if ("1".equals(isSwarm)) {
|
if ("1".equals(isSwarm)) {
|
||||||
runtimePersist.setServerUrl("http://" + serverName + ":" + serverPort);
|
runtimePersist.setServerUrl("http://" + serverName + ":" + serverPort);
|
||||||
} else {
|
} else {
|
||||||
runtimePersist.setServerUrl("http://" + hostName + ":" + serverPort);
|
if (runtimePort==-1) {
|
||||||
|
runtimePersist.setServerUrl("http://" + hostName + ":" + serverPort);
|
||||||
|
}else{
|
||||||
|
runtimePersist.setServerUrl("http://" + runtimeServer + ":" + runtimePort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
runtimeRepository.save(runtimePersist);
|
runtimeRepository.save(runtimePersist);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -164,6 +186,7 @@ public class KieServiceCommon {
|
||||||
logger.info("initCamelBusinessRoutes", e);
|
logger.info("initCamelBusinessRoutes", e);
|
||||||
}
|
}
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String serverName = KieServiceCommon.getKieServerID();
|
String serverName = KieServiceCommon.getKieServerID();
|
||||||
List<RuntimePersist> itIsMes = runtimeRepository.findByServerNameAndHostname(serverName, hostName);
|
List<RuntimePersist> itIsMes = runtimeRepository.findByServerNameAndHostname(serverName, hostName);
|
||||||
|
|
@ -173,7 +196,7 @@ public class KieServiceCommon {
|
||||||
runtimeRepository.delete(runtimePersist);
|
runtimeRepository.delete(runtimePersist);
|
||||||
}
|
}
|
||||||
List<ContainerRuntimePojoPersist> ccc = containerRuntimeRepository.findByServerNameAndHostname(serverName, hostName);
|
List<ContainerRuntimePojoPersist> ccc = containerRuntimeRepository.findByServerNameAndHostname(serverName, hostName);
|
||||||
if (ccc.size() > 0) {
|
if (!ccc.isEmpty()) {
|
||||||
containerRuntimeRepository.deleteAll(ccc);
|
containerRuntimeRepository.deleteAll(ccc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue