Refactoring
This commit is contained in:
parent
9275ed5174
commit
5d5d9a1612
5 changed files with 41 additions and 97 deletions
|
|
@ -20,8 +20,6 @@ import org.chtijbug.drools.kieserver.extension.KieServerGlobalVariableDefinition
|
|||
import org.chtijbug.drools.kieserver.extension.KieServerListenerDefinition;
|
||||
import org.chtijbug.drools.kieserver.extension.KieServerLoggingDefinition;
|
||||
import org.drools.compiler.kie.builder.impl.InternalKieModule;
|
||||
import org.drools.compiler.kie.builder.impl.KieRepositoryImpl;
|
||||
import org.kie.api.builder.KieRepository;
|
||||
import org.kie.api.remote.Remotable;
|
||||
import org.kie.scanner.KieModuleMetaData;
|
||||
import org.kie.server.api.KieServerConstants;
|
||||
|
|
@ -38,16 +36,20 @@ import java.util.*;
|
|||
|
||||
public class DroolsChtijbugKieServerExtension implements KieServerExtension {
|
||||
|
||||
|
||||
|
||||
public static final String EXTENSION_NAME = "DroolsFramework";
|
||||
private static final Logger logger = LoggerFactory.getLogger(DroolsChtijbugKieServerExtension.class);
|
||||
private static final Boolean disabled = Boolean.parseBoolean(System.getProperty(KieServerConstants.KIE_DROOLS_SERVER_EXT_DISABLED, "false"));
|
||||
private static final Boolean filterRemoteable = Boolean.parseBoolean(System.getProperty(KieServerConstants.KIE_DROOLS_FILTER_REMOTEABLE_CLASSES, "false"));
|
||||
private static final Boolean DISABLED = Boolean.parseBoolean(System.getProperty(KieServerConstants.KIE_DROOLS_SERVER_EXT_DISABLED, "false"));
|
||||
private static final Boolean FILTER_REMOTEABLE = Boolean.parseBoolean(System.getProperty(KieServerConstants.KIE_DROOLS_FILTER_REMOTEABLE_CLASSES, "false"));
|
||||
|
||||
|
||||
|
||||
private DroolsChtijbugRulesExecutionService rulesExecutionService;
|
||||
|
||||
private KieServerRegistry registry;
|
||||
|
||||
private List<Object> services = new ArrayList<Object>();
|
||||
private List<Object> services = new ArrayList<>();
|
||||
private KieServerAddOnElement kieServerAddOnElement = null;
|
||||
|
||||
private boolean initialized = false;
|
||||
|
|
@ -61,7 +63,7 @@ public class DroolsChtijbugKieServerExtension implements KieServerExtension {
|
|||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return disabled == false;
|
||||
return !DISABLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -103,7 +105,7 @@ public class DroolsChtijbugKieServerExtension implements KieServerExtension {
|
|||
@Override
|
||||
public void createContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
|
||||
// do any other bootstrapping rule service requires
|
||||
Set<Class<?>> extraClasses = new HashSet<Class<?>>();
|
||||
Set<Class<?>> extraClasses = new HashSet<>();
|
||||
|
||||
// create kbases so declared types can be created
|
||||
Collection<String> kbases = kieContainerInstance.getKieContainer().getKieBaseNames();
|
||||
|
|
@ -123,13 +125,13 @@ public class DroolsChtijbugKieServerExtension implements KieServerExtension {
|
|||
logger.debug("Adding {} type into extra jaxb classes set", type);
|
||||
Class<?> clazz = Class.forName(type, true, kieContainerInstance.getKieContainer().getClassLoader());
|
||||
|
||||
addExtraClass(extraClasses, clazz, filterRemoteable);
|
||||
addExtraClass(extraClasses, clazz, FILTER_REMOTEABLE);
|
||||
logger.debug("Added {} type into extra jaxb classes set", type);
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.warn("Unable to create instance of type {} due to {}", type, e.getMessage());
|
||||
logger.debug("Complete stack trace for exception while creating type {}", type, e);
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
logger.warn("Unexpected error while create instance of type {} due to {}", type, e.getMessage());
|
||||
logger.debug("Complete stack trace for unknown error while creating type {}", type, e);
|
||||
}
|
||||
|
|
@ -143,19 +145,18 @@ public class DroolsChtijbugKieServerExtension implements KieServerExtension {
|
|||
|
||||
@Override
|
||||
public void updateContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> map) {
|
||||
this.disposeContainer(id, kieContainerInstance, map);
|
||||
this.createContainer(id, kieContainerInstance, map);
|
||||
//Nop
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdateContainerAllowed(String s, KieContainerInstance kieContainerInstance, Map<String, Object> map) {
|
||||
System.out.println("isUpdateContainerAllowed");
|
||||
logger.info("Container {} isUpdateContainerAllowed",s);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
|
||||
System.out.println("disposeContainer");
|
||||
logger.info("Container {} dispose",id);
|
||||
if (kieServerAddOnElement != null) {
|
||||
|
||||
for (KieServerGlobalVariableDefinition kieServerGlobalVariableDefinition : kieServerAddOnElement.getKieServerGlobalVariableDefinitions()) {
|
||||
|
|
@ -172,9 +173,9 @@ public class DroolsChtijbugKieServerExtension implements KieServerExtension {
|
|||
rulesExecutionService.removeRuleBasePackage(id);
|
||||
if (kieContainerInstance instanceof KieContainerInstanceImpl) {
|
||||
KieContainerInstanceImpl internalContainer = (KieContainerInstanceImpl) kieContainerInstance;
|
||||
KieRepository kieRepository = KieRepositoryImpl.INSTANCE;
|
||||
|
||||
if (internalContainer.getKieContainer().getMainKieModule() instanceof InternalKieModule) {
|
||||
|
||||
if (internalContainer.getKieContainer().getMainKieModule() instanceof InternalKieModule) {
|
||||
InternalKieModule kie = (InternalKieModule) internalContainer.getKieContainer().getMainKieModule();
|
||||
kie.getFile().delete();
|
||||
}
|
||||
|
|
@ -185,14 +186,14 @@ public class DroolsChtijbugKieServerExtension implements KieServerExtension {
|
|||
public List<Object> getAppComponents(SupportedTransports type) {
|
||||
ServiceLoader<KieServerApplicationComponentsService> appComponentsServices
|
||||
= ServiceLoader.load(KieServerApplicationComponentsService.class);
|
||||
List<Object> appComponentsList = new ArrayList<Object>();
|
||||
Object[] services = {
|
||||
List<Object> appComponentsList = new ArrayList<>();
|
||||
Object[] serviceList = {
|
||||
rulesExecutionService,
|
||||
registry
|
||||
|
||||
};
|
||||
for (KieServerApplicationComponentsService appComponentsService : appComponentsServices) {
|
||||
appComponentsList.addAll(appComponentsService.getAppComponents(EXTENSION_NAME, type, services));
|
||||
appComponentsList.addAll(appComponentsService.getAppComponents(EXTENSION_NAME, type, serviceList));
|
||||
}
|
||||
return appComponentsList;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -451,7 +451,6 @@ public class RuleBaseStatefulSession implements RuleBaseSession {
|
|||
|
||||
}
|
||||
ProcessInstance processInstance = this.knowledgeSession.startProcess(processName);
|
||||
|
||||
if (this.historyListener != null) {
|
||||
try {
|
||||
SessionStartProcessEndEvent sessionStartProcessEndEvent = new SessionStartProcessEndEvent(eventCounter.next(), processName, this.ruleBaseID, this.sessionId, processInstance.getProcessId());
|
||||
|
|
|
|||
|
|
@ -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