Refactoring
This commit is contained in:
parent
9275ed5174
commit
5d5d9a1612
5 changed files with 41 additions and 97 deletions
|
|
@ -2,7 +2,6 @@ package org.chtijbug.drools.proxy.camel;
|
|||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.kie.server.services.api.KieContainerInstance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -11,22 +10,20 @@ import static org.apache.camel.model.rest.RestParamType.body;
|
|||
public class DroolsRouter extends RouteBuilder {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DroolsRouter.class);
|
||||
private String containerId;
|
||||
private KieContainerInstance kci;
|
||||
private String projectName;
|
||||
private Class<?> clazzUser;
|
||||
private String processID;
|
||||
|
||||
public DroolsRouter(CamelContext camelContext, Class<?> clazzUser, String containerId, KieContainerInstance kci, String processID) {
|
||||
public DroolsRouter(CamelContext camelContext, Class<?> clazzUser, String projectName, String processID) {
|
||||
super(camelContext);
|
||||
this.clazzUser = clazzUser;
|
||||
this.containerId = containerId;
|
||||
this.kci = kci;
|
||||
this.projectName = projectName;
|
||||
this.processID = processID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
rest("/" + containerId).description(containerId + " Rest service")
|
||||
rest("/" + projectName).description(projectName + " Rest service")
|
||||
|
||||
.consumes("application/json")
|
||||
.produces("application/json")
|
||||
|
|
@ -36,6 +33,6 @@ public class DroolsRouter extends RouteBuilder {
|
|||
.param().name("body").type(body).description("The Data drools should work on").endParam()
|
||||
.responseMessage().code(200).message("Data drools worked on").endResponseMessage()
|
||||
|
||||
.to("bean:ruleService?method=runSessionObject(${header.transactionId}," + this.containerId + "," + this.processID + ",${body})");
|
||||
.to("bean:ruleService?method=runSessionObject(${header.transactionId}," + this.projectName + "," + this.processID + ",${body})");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ public class KieServiceCommon {
|
|||
NewTopic responseTopic;
|
||||
|
||||
public KieServiceCommon() {
|
||||
//Needed
|
||||
//Needed
|
||||
}
|
||||
|
||||
public static String getKieServerID() {
|
||||
|
|
@ -134,37 +134,37 @@ public class KieServiceCommon {
|
|||
logger.info("initCamelBusinessRoutes.getLocalHost", e);
|
||||
}
|
||||
List<RuntimePersist> itIsMes;
|
||||
if (runtimePort==-1){
|
||||
if (runtimePort == -1) {
|
||||
itIsMes = runtimeRepository.findByServerNameAndHostname(serverName, hostName);
|
||||
}else{
|
||||
} else {
|
||||
itIsMes = runtimeRepository.findByServerName(serverName);
|
||||
}
|
||||
RuntimePersist runtimePersist;
|
||||
ServiceResponse<KieServerInfo> result = server.getInfo();
|
||||
String version = result.getResult().getVersion();
|
||||
if (itIsMes.isEmpty()) {
|
||||
runtimePersist = new RuntimePersist(serverName, version, hostName,
|
||||
runtimePersist = new RuntimePersist(serverName, version, hostName,
|
||||
String.valueOf(serverPort), null,
|
||||
hostName, RuntimePersist.STATUS.UP.toString());
|
||||
if (runtimePort!=-1){
|
||||
if (runtimePort != -1) {
|
||||
runtimePersist.setHostname(runtimeServer);
|
||||
runtimePersist.setServerPort(String.valueOf(runtimePort));
|
||||
}
|
||||
String isSwarm = System.getProperty("org.kie.server.swarm");
|
||||
String swarmPort=System.getProperty("org.kie.server.swarm.port");
|
||||
String baseurl="http://";
|
||||
String swarmPort = System.getProperty("org.kie.server.swarm.port");
|
||||
String baseurl = "http://";
|
||||
if ("1".equals(isSwarm)) {
|
||||
if (swarmPort!= null &&
|
||||
swarmPort.length()>0){
|
||||
if (swarmPort != null &&
|
||||
swarmPort.length() > 0) {
|
||||
runtimePersist.setServerUrl(baseurl + serverName + ":" + swarmPort);
|
||||
}else{
|
||||
} else {
|
||||
runtimePersist.setServerUrl(baseurl + serverName + ":" + serverPort);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (runtimePort==-1) {
|
||||
if (runtimePort == -1) {
|
||||
runtimePersist.setServerUrl(baseurl + hostName + ":" + serverPort);
|
||||
}else{
|
||||
} else {
|
||||
runtimePersist.setServerUrl(baseurl + runtimeServer + ":" + runtimePort);
|
||||
}
|
||||
}
|
||||
|
|
@ -260,7 +260,7 @@ public class KieServiceCommon {
|
|||
String projectName = container.getContainerId();
|
||||
String processId = container.getProcessID();
|
||||
this.deleteCamelBusinessRoute(projectName);
|
||||
DroolsRouter droolsRouter = new DroolsRouter(camelContext, theClass, projectName, kieContainerInstance, processId);
|
||||
DroolsRouter droolsRouter = new DroolsRouter(camelContext, theClass, projectName, processId);
|
||||
camelContext.addRoutes(droolsRouter);
|
||||
routes.put(containerId, droolsRouter);
|
||||
}
|
||||
|
|
@ -307,59 +307,6 @@ public class KieServiceCommon {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public KieContainerResource createContainerWithRestBusinessService(String id, KieContainerResource container, String className, String processID) {
|
||||
|
||||
|
||||
KieContainerResource containerResource = this.createContainer(id, container);
|
||||
if (containerResource.getMessages().size() == 1
|
||||
&& containerResource.getMessages().get(0).getSeverity() != null
|
||||
&& containerResource.getMessages().get(0).getSeverity().equals(Severity.INFO)) {
|
||||
ClassLoader localClassLoader = null;
|
||||
|
||||
try {
|
||||
localClassLoader = Thread.currentThread()
|
||||
.getContextClassLoader();
|
||||
} catch (ClassCastException e) {
|
||||
logger.info("GenericResource.runSession", e);
|
||||
}
|
||||
try {
|
||||
String serverName = KieServiceCommon.getKieServerID();
|
||||
ContainerPojoPersist containerPojoPersist = containerRepository.findByServerNameAndContainerId(serverName, id);
|
||||
if (containerPojoPersist == null) {
|
||||
containerPojoPersist = new ContainerPojoPersist();
|
||||
containerPojoPersist.setId(UUID.randomUUID().toString());
|
||||
containerPojoPersist.setContainerId(id);
|
||||
containerPojoPersist.setClassName(className);
|
||||
containerPojoPersist.setProjectName(id);
|
||||
containerPojoPersist.setServerName(serverName);
|
||||
containerPojoPersist.setProcessID(processID);
|
||||
|
||||
} else {
|
||||
containerPojoPersist.setContainerId(id);
|
||||
containerPojoPersist.setClassName(className);
|
||||
containerPojoPersist.setProjectName(id);
|
||||
containerPojoPersist.setProcessID(processID);
|
||||
containerPojoPersist.setServerName(serverName);
|
||||
|
||||
}
|
||||
this.initCamelBusinessRoute(containerPojoPersist);
|
||||
containerRepository.save(containerPojoPersist);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("createContainerWithRestBusinessService", e);
|
||||
} finally {
|
||||
if (localClassLoader != null) {
|
||||
Thread.currentThread().setContextClassLoader(localClassLoader);
|
||||
}
|
||||
}
|
||||
}
|
||||
return containerResource;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public KieContainerResource createContainer(String id, KieContainerResource container) {
|
||||
|
||||
container.setContainerId(id);
|
||||
|
|
@ -429,15 +376,15 @@ public class KieServiceCommon {
|
|||
return result;
|
||||
}
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
public void updateConfig(){
|
||||
logger.info("updateConfig - check for new version to deploy");
|
||||
public void updateConfig() {
|
||||
logger.debug("updateConfig - check for new version to deploy");
|
||||
|
||||
try {
|
||||
|
||||
String serverName = KieServiceCommon.getKieServerID();
|
||||
List<ContainerRuntimePojoPersist> containerRuntimePojoPersists = containerRuntimeRepository.findByServerNameAndHostname(serverName, hostName);
|
||||
for (ContainerRuntimePojoPersist element : containerRuntimePojoPersists) {
|
||||
logger.info("runtime {} has status {}",element.getContainerId(),element.getStatus());
|
||||
logger.debug("runtime {} has status {}", element.getContainerId(), element.getStatus());
|
||||
ContainerPojoPersist containerPojoPersist = containerRepository.findByServerNameAndContainerId(serverName, element.getContainerId());
|
||||
if (element.getStatus().equals(ContainerRuntimePojoPersist.STATUS.TODEPLOY.name())) {
|
||||
logger.info("start deploy new container");
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class RuleService {
|
|||
private KafkaTemplate<String, ChtijbugObjectRequest> kafkaTemplateLogging;
|
||||
|
||||
public RuleService() {
|
||||
logger.info("Rule Service created");
|
||||
logger.info("Rule Service created");
|
||||
}
|
||||
|
||||
public Object runSessionObject(String transactionID, String id, String processID, Object input) {
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue