Refactoring for running in a docker swarm cluster
and upgrade to version 7.28.0
This commit is contained in:
parent
30600ac30e
commit
e2c87e9d20
15 changed files with 254 additions and 117 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package org.chtijbug.drools.console.vaadinComponent.componentView;
|
||||
|
||||
import com.vaadin.flow.component.grid.Grid;
|
||||
import com.vaadin.flow.component.html.Label;
|
||||
import com.vaadin.flow.component.textfield.TextField;
|
||||
import com.vaadin.flow.data.provider.ConfigurableFilterDataProvider;
|
||||
import com.vaadin.flow.data.provider.ListDataProvider;
|
||||
|
|
@ -12,10 +13,11 @@ import org.chtijbug.drools.console.service.RuntimeService;
|
|||
import org.chtijbug.drools.console.service.util.AppContext;
|
||||
import org.chtijbug.drools.proxy.persistence.model.ProjectPersist;
|
||||
import org.chtijbug.drools.proxy.persistence.model.RuntimePersist;
|
||||
import com.vaadin.flow.component.html.Label;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GridRuntime extends Grid<RuntimePersist> {
|
||||
|
||||
|
|
@ -27,31 +29,26 @@ public class GridRuntime extends Grid<RuntimePersist> {
|
|||
|
||||
private TextField status;
|
||||
|
||||
private String strRuntimeName="Runtime Name";
|
||||
private String strRuntimeName = "Runtime Name";
|
||||
|
||||
private String strHostName="Hostname";
|
||||
private String strHostName = "Hostname";
|
||||
|
||||
private String strVersion="Version";
|
||||
private String strVersion = "Version";
|
||||
|
||||
private String strStatus="State";
|
||||
private String strStatus = "State";
|
||||
|
||||
private ProjectPersistService projectPersistService;
|
||||
private RuntimeService runtimeService;
|
||||
|
||||
private ListDataProvider<RuntimePersist> dataProvider;
|
||||
private ConfigurableFilterDataProvider<RuntimePersist,Void,SerializablePredicate<RuntimePersist>> filterDataProvider;
|
||||
private ConfigurableFilterDataProvider<RuntimePersist, Void, SerializablePredicate<RuntimePersist>> filterDataProvider;
|
||||
|
||||
private ProjectPersist projectPersist;
|
||||
private ProjectPersist projectPersist = null;
|
||||
|
||||
public GridRuntime(ProjectPersist projectPersist){
|
||||
public GridRuntime(ProjectPersist projectPersist) {
|
||||
this.projectPersist = projectPersist;
|
||||
init();
|
||||
//dataProvider.get
|
||||
for (RuntimePersist runtimePersist : dataProvider.getItems()){
|
||||
if (projectPersist.getServerNames().contains(runtimePersist.getServerName())){
|
||||
getSelectionModel().select(runtimePersist);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -59,38 +56,39 @@ public class GridRuntime extends Grid<RuntimePersist> {
|
|||
init();
|
||||
|
||||
}
|
||||
private void init(){
|
||||
|
||||
private void init() {
|
||||
projectPersistService = AppContext.getApplicationContext().getBean(ProjectPersistService.class);
|
||||
runtimeService= AppContext.getApplicationContext().getBean(RuntimeService.class);
|
||||
runtimeService = AppContext.getApplicationContext().getBean(RuntimeService.class);
|
||||
|
||||
setClassName("deployment-grid-perso");
|
||||
setSelectionMode(Grid.SelectionMode.MULTI);
|
||||
|
||||
Grid.Column<RuntimePersist> runtimeNameCo=addColumn(runtimePersist -> runtimePersist.getServerName());
|
||||
runtimeName=new TextField(strRuntimeName);
|
||||
Grid.Column<RuntimePersist> runtimeNameCo = addColumn(runtimePersist -> runtimePersist.getServerName());
|
||||
runtimeName = new TextField(strRuntimeName);
|
||||
runtimeName.setValueChangeMode(ValueChangeMode.EAGER);
|
||||
runtimeName.addValueChangeListener(e -> {
|
||||
refreshtGrid(runtimeName.getValue(), strRuntimeName);
|
||||
});
|
||||
runtimeNameCo.setHeader(runtimeName);
|
||||
|
||||
Grid.Column<RuntimePersist> hostnameCo=addColumn(runtimePersist -> runtimePersist.getHostname());
|
||||
hostName=new TextField(strHostName);
|
||||
Grid.Column<RuntimePersist> hostnameCo = addColumn(runtimePersist -> runtimePersist.getServerUrl());
|
||||
hostName = new TextField(strHostName);
|
||||
hostName.setValueChangeMode(ValueChangeMode.EAGER);
|
||||
hostName.addValueChangeListener(e -> {
|
||||
refreshtGrid(hostName.getValue(), strHostName);
|
||||
});
|
||||
hostnameCo.setHeader(hostName);
|
||||
|
||||
Grid.Column<RuntimePersist> versionCo=addColumn(runtimePersist -> runtimePersist.getVersion());
|
||||
version=new TextField(strVersion);
|
||||
Grid.Column<RuntimePersist> versionCo = addColumn(runtimePersist -> runtimePersist.getVersion());
|
||||
version = new TextField(strVersion);
|
||||
version.setValueChangeMode(ValueChangeMode.EAGER);
|
||||
version.addValueChangeListener(e -> {
|
||||
refreshtGrid(version.getValue(), strVersion);
|
||||
});
|
||||
versionCo.setHeader(version);
|
||||
Grid.Column<RuntimePersist> statusCo=addColumn(runtimePersist -> runtimePersist.getStatus());
|
||||
status=new TextField(strStatus);
|
||||
Grid.Column<RuntimePersist> statusCo = addColumn(runtimePersist -> runtimePersist.getStatus());
|
||||
status = new TextField(strStatus);
|
||||
status.setValueChangeMode(ValueChangeMode.EAGER);
|
||||
status.addValueChangeListener(e -> {
|
||||
refreshtGrid(status.getValue(), strVersion);
|
||||
|
|
@ -100,44 +98,67 @@ public class GridRuntime extends Grid<RuntimePersist> {
|
|||
addColumn(new ComponentRenderer<>(runtimePersist -> {
|
||||
List<String> serverList = new ArrayList<>();
|
||||
serverList.add(runtimePersist.getServerName());
|
||||
List<ProjectPersist> projectPersists=projectPersistService.getProjectRepository().findByServerNamesIn(serverList);
|
||||
List<ProjectPersist> projectPersists = projectPersistService.getProjectRepository().findByServerNamesIn(serverList);
|
||||
|
||||
Label label=new Label(projectPersists!=null?projectPersists.size()+"":"0");
|
||||
Label label = new Label(projectPersists != null ? projectPersists.size() + "" : "0");
|
||||
|
||||
return label;
|
||||
})).setHeader("associated projects");
|
||||
|
||||
setDataProvider();
|
||||
}
|
||||
private void refreshtGrid(String value,String type){
|
||||
|
||||
filterDataProvider.setFilter(filterGrid(value.toUpperCase(),type));
|
||||
private void refreshtGrid(String value, String type) {
|
||||
|
||||
filterDataProvider.setFilter(filterGrid(value.toUpperCase(), type));
|
||||
getDataProvider().refreshAll();
|
||||
}
|
||||
private SerializablePredicate<RuntimePersist> filterGrid(String value, String type){
|
||||
|
||||
private SerializablePredicate<RuntimePersist> filterGrid(String value, String type) {
|
||||
SerializablePredicate<RuntimePersist> columnPredicate = null;
|
||||
if(value.equals(" ")||type.equals(" ")){
|
||||
if (value.equals(" ") || type.equals(" ")) {
|
||||
columnPredicate = runtimePersist -> (true);
|
||||
}else {
|
||||
} else {
|
||||
if (type.equals(strHostName)) {
|
||||
columnPredicate = runtimePersist -> (runtimePersist.getHostname()!=null&&runtimePersist.getHostname().toUpperCase().contains(value));
|
||||
columnPredicate = runtimePersist -> (runtimePersist.getServerUrl() != null && runtimePersist.getServerUrl().toUpperCase().contains(value));
|
||||
|
||||
} else if (type.equals(strRuntimeName)) {
|
||||
columnPredicate = runtimePersist -> (runtimePersist.getServerName()!=null&&runtimePersist.getServerName().toUpperCase().contains(value));
|
||||
columnPredicate = runtimePersist -> (runtimePersist.getServerName() != null && runtimePersist.getServerName().toUpperCase().contains(value));
|
||||
|
||||
} else if (type.equals(strVersion)) {
|
||||
columnPredicate = runtimePersist -> (runtimePersist.getVersion()!=null&&runtimePersist.getVersion().toUpperCase().contains(value));
|
||||
columnPredicate = runtimePersist -> (runtimePersist.getVersion() != null && runtimePersist.getVersion().toUpperCase().contains(value));
|
||||
}
|
||||
}
|
||||
return columnPredicate;
|
||||
}
|
||||
|
||||
public void setDataProvider(){
|
||||
public void setDataProvider() {
|
||||
|
||||
List<RuntimePersist> runtimePersists = runtimeService.getRuntimeRepository().findAll();
|
||||
if(runtimePersists!=null) {
|
||||
dataProvider = new ListDataProvider<>(runtimePersists);
|
||||
if (runtimePersists != null) {
|
||||
List<RuntimePersist> runtimeToShow = new ArrayList<>();
|
||||
Map<String, String> urlMap = new HashMap<>();
|
||||
for (RuntimePersist runtimePersist : runtimePersists) {
|
||||
if (urlMap.containsKey(runtimePersist.getServerName()) == false) {
|
||||
|
||||
urlMap.put(runtimePersist.getServerName(), runtimePersist.getServerUrl());
|
||||
RuntimePersist runtimePersist1 = runtimePersist.duplicate();
|
||||
if (projectPersist != null) {
|
||||
if (projectPersist.getServerNames().contains(runtimePersist1.getServerName())) {
|
||||
runtimeToShow.add(runtimePersist1);
|
||||
getSelectionModel().select(runtimePersist1);
|
||||
} else {
|
||||
if (projectPersist.getServerNames().size() == 0){
|
||||
runtimeToShow.add(runtimePersist1);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
runtimeToShow.add(runtimePersist1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dataProvider = new ListDataProvider<>(runtimeToShow);
|
||||
filterDataProvider = dataProvider.withConfigurableFilter();
|
||||
setDataProvider(filterDataProvider);
|
||||
|
||||
|
|
@ -145,7 +166,8 @@ public class GridRuntime extends Grid<RuntimePersist> {
|
|||
|
||||
}
|
||||
}
|
||||
public void reinitFilter(){
|
||||
|
||||
public void reinitFilter() {
|
||||
hostName.setValue("");
|
||||
version.setValue("");
|
||||
runtimeName.setValue("");
|
||||
|
|
|
|||
|
|
@ -18,7 +18,13 @@ import org.chtijbug.drools.console.service.model.kie.KieConfigurationData;
|
|||
import org.chtijbug.drools.console.service.util.AppContext;
|
||||
import org.chtijbug.drools.console.vaadinComponent.ComponentPerso.DialogPerso;
|
||||
import org.chtijbug.drools.console.vaadinComponent.componentView.AssetEdit;
|
||||
import org.chtijbug.drools.console.vaadinComponent.componentView.service.dtmodel.ColumnDefinition;
|
||||
import org.chtijbug.drools.console.vaadinComponent.componentView.service.dtmodel.DecisionTable;
|
||||
import org.chtijbug.drools.console.vaadinComponent.componentView.service.dtmodel.GuidedException;
|
||||
import org.chtijbug.drools.console.vaadinComponent.componentView.service.dtmodel.Row;
|
||||
import org.drools.workbench.models.datamodel.rule.InterpolationVariable;
|
||||
import org.drools.workbench.models.guided.dtable.backend.GuidedDTXMLPersistence;
|
||||
import org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52;
|
||||
import org.drools.workbench.models.guided.template.backend.RuleTemplateModelXMLPersistenceImpl;
|
||||
import org.drools.workbench.models.guided.template.shared.TemplateModel;
|
||||
import org.vaadin.olli.FileDownloadWrapper;
|
||||
|
|
@ -114,7 +120,6 @@ public class EditTemplateView extends VerticalLayout {
|
|||
TemplateModel model = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(assetSource);
|
||||
int id=model.getColsCount();
|
||||
model.clearRows();
|
||||
Map<String, List<String>> existingData = model.getTable();
|
||||
for (Map<String,Object> line : objects){
|
||||
String[] cols =new String[model.getColsCount()];
|
||||
int k=0;
|
||||
|
|
@ -142,11 +147,35 @@ public class EditTemplateView extends VerticalLayout {
|
|||
} else {
|
||||
List<HashMap<String, Object>> objects = decisionTableExcelService.importExcel(fileBuffer.getInputStream());
|
||||
if (objects != null && objects.size() > 0) {
|
||||
Notification.show("Unable to add columns with the excel import for the moment");
|
||||
}else{
|
||||
remove(assetEdit);
|
||||
assetEdit = new AssetEdit(objects);
|
||||
add(assetEdit);
|
||||
String assetSource=this.getAssetContent();
|
||||
GuidedDecisionTable52 model = GuidedDTXMLPersistence.getInstance().unmarshal(assetSource);
|
||||
org.chtijbug.drools.console.vaadinComponent.componentView.service.dtmodel.DecisionTable decisionTable = new DecisionTable(model);
|
||||
decisionTable.getRows().clear();
|
||||
List<ColumnDefinition> columnDefinitions = decisionTable.getColumnDefinitionList();
|
||||
int k=0;
|
||||
for (HashMap<String, Object> line : objects){
|
||||
Row row = decisionTable.createEmptyRow(k);
|
||||
for (ColumnDefinition columnDefinition : columnDefinitions){
|
||||
line.get(columnDefinition.getHeader());
|
||||
|
||||
}
|
||||
}
|
||||
k++;
|
||||
}
|
||||
|
||||
|
||||
//row.
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Notification.show("The file is incompatible, it must be in xlsx format");
|
||||
} catch (GuidedException e) {
|
||||
Notification.show("error "+e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class RuntimesView extends VerticalLayout {
|
|||
|
||||
public RuntimesView(){
|
||||
|
||||
add(new Label("Runtimes enrigistré"));
|
||||
add(new Label("Runtimes stored"));
|
||||
add(new GridRuntime());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-internal:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-api:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie.soup:kie-soup-maven-support:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.1.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.1.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.1.0.RELEASE" level="project" />
|
||||
|
|
@ -147,8 +150,8 @@
|
|||
<orderEntry type="library" name="Maven: com.google.guava:guava:13.0.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-internal:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-api:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie.soup:kie-soup-maven-support:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-internal:7.28.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-api:7.28.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie.soup:kie-soup-maven-support:7.28.0.Final" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -14,6 +14,9 @@
|
|||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-internal:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-api:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie.soup:kie-soup-maven-support:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-elasticsearch:2.1.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.1.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.1.0.RELEASE" level="project" />
|
||||
|
|
@ -92,8 +95,8 @@
|
|||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:guava:13.0.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-io:commons-io:2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-internal:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-api:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie.soup:kie-soup-maven-support:7.23.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-internal:7.28.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-api:7.28.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie.soup:kie-soup-maven-support:7.28.0.Final" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -94,7 +94,10 @@
|
|||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-quartz2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-quartz2</artifactId>
|
||||
</dependency>
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ package org.chtijbug.drools.proxy;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
@SpringBootApplication
|
||||
@Configuration
|
||||
public class DroolsBusinessProxyServer {
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,14 @@ package org.chtijbug.drools.proxy.camel;
|
|||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.model.rest.RestBindingMode;
|
||||
import org.chtijbug.drools.proxy.service.KieServiceCommon;
|
||||
import org.kie.server.api.model.KieServerInfo;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Component
|
||||
public class AdminRouter extends RouteBuilder {
|
||||
|
||||
|
||||
@Resource
|
||||
KieServiceCommon kieServiceCommon;
|
||||
@Value("${server.port}")
|
||||
private int serverPort;
|
||||
@Value("${camel.component.servlet.mapping.context-path}")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package org.chtijbug.drools.proxy.camel;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AliveTimeStampRouter extends RouteBuilder {
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
from("quartz2://myGroup/myTimeStampTimer?cron=0/5+*+*+?+*+*").to("bean:kieService?method=setTimeStamp()");
|
||||
}
|
||||
}
|
||||
|
|
@ -36,10 +36,10 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
|
@ -67,25 +67,30 @@ public class KieServiceCommon {
|
|||
@Value("${server.port}")
|
||||
private int serverPort;
|
||||
|
||||
private Map<String,DroolsRouter> routes = new HashMap<>();
|
||||
@Autowired
|
||||
private ApplicationContext appContext;
|
||||
|
||||
private String hostName= "localhost";
|
||||
|
||||
private Map<String, DroolsRouter> routes = new HashMap<>();
|
||||
|
||||
public KieServiceCommon() {
|
||||
// for now, if no server impl is passed as parameter, create one
|
||||
// this.server = KieServerLocator.getInstance();
|
||||
}
|
||||
|
||||
public static String getKieServerID(){
|
||||
public static String getKieServerID() {
|
||||
return System.getProperty("org.kie.server.id");
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void initCamelBusinessRoutes() {
|
||||
|
||||
this.server = new KieServerImpl(new PlatfomKieServerStateRepository(containerRepository,this));
|
||||
this.server = new KieServerImpl(new PlatfomKieServerStateRepository(containerRepository, this));
|
||||
this.server.init();
|
||||
|
||||
List<KieServerExtension> serverExtensions = this.server.getServerExtensions();
|
||||
if (registry==null || droolsChtijbugKieServerExtension==null) {
|
||||
if (registry == null || droolsChtijbugKieServerExtension == null) {
|
||||
for (KieServerExtension serverExtension : serverExtensions) {
|
||||
if (serverExtension instanceof DroolsChtijbugKieServerExtension) {
|
||||
droolsChtijbugKieServerExtension = (DroolsChtijbugKieServerExtension) serverExtension;
|
||||
|
|
@ -103,72 +108,94 @@ public class KieServiceCommon {
|
|||
|
||||
String serverName = KieServiceCommon.getKieServerID();
|
||||
String sftpPort = System.getProperty("org.chtijbug.server.sftpPort");
|
||||
List<RuntimePersist> itIsMes = runtimeRepository.findByServerName(serverName);
|
||||
if (itIsMes.size() == 0) {
|
||||
ServiceResponse<KieServerInfo> result = server.getInfo();
|
||||
String version = result.getResult().getVersion();
|
||||
String hostName = "localhost";
|
||||
|
||||
try {
|
||||
InetAddress inetAddress = InetAddress.getLocalHost();
|
||||
hostName = inetAddress.getHostName();
|
||||
} catch (UnknownHostException e) {
|
||||
logger.info("initCamelBusinessRoutes.getLocalHost", e);
|
||||
}
|
||||
RuntimePersist runtimePersist = new RuntimePersist(serverName, version, "http://" + hostName + ":" + serverPort,
|
||||
List<RuntimePersist> itIsMes = runtimeRepository.findByServerName(serverName);
|
||||
ServiceResponse<KieServerInfo> result = server.getInfo();
|
||||
String version = result.getResult().getVersion();
|
||||
String isSwarm=System.getProperty("org.kie.server.swarm");
|
||||
if (itIsMes.size() == 0) {
|
||||
|
||||
RuntimePersist runtimePersist = new RuntimePersist(serverName, version, hostName ,
|
||||
String.valueOf(serverPort), sftpPort,
|
||||
hostName,RuntimePersist.STATUS.UP.toString());
|
||||
runtimeRepository.save(runtimePersist);
|
||||
}else{
|
||||
RuntimePersist runtimePersist =itIsMes.get(0);
|
||||
runtimePersist.setStatus(RuntimePersist.STATUS.UP.toString());
|
||||
try {
|
||||
/**
|
||||
* HostName may have changed by reboot so retake it and save it
|
||||
*/
|
||||
InetAddress inetAddress = InetAddress.getLocalHost();
|
||||
String hostName = inetAddress.getHostName();
|
||||
runtimePersist.setHostname("http://" + hostName + ":" + serverPort);
|
||||
runtimePersist.setSftpHost(hostName);
|
||||
runtimePersist.setSftpPort(sftpPort);
|
||||
} catch (UnknownHostException e) {
|
||||
logger.info("initCamelBusinessRoutes.getLocalHost", e);
|
||||
hostName, RuntimePersist.STATUS.UP.toString());
|
||||
if ("1".equals(isSwarm)) {
|
||||
runtimePersist.setServerUrl("http://" + serverName + ":" + serverPort);
|
||||
}else {
|
||||
runtimePersist.setServerUrl("http://" + hostName + ":" + serverPort);
|
||||
}
|
||||
runtimeRepository.save(runtimePersist);
|
||||
} else {
|
||||
List<RuntimePersist> byServerNameAndHostname = runtimeRepository.findByServerNameAndHostname(serverName, hostName);
|
||||
if (byServerNameAndHostname.size() == 0) {
|
||||
RuntimePersist runtimePersist = new RuntimePersist(serverName, version, hostName ,
|
||||
String.valueOf(serverPort), sftpPort,
|
||||
hostName, RuntimePersist.STATUS.UP.toString());
|
||||
if ("1".equals(isSwarm)) {
|
||||
runtimePersist.setServerUrl("http://" + serverName + ":" + serverPort);
|
||||
}else {
|
||||
runtimePersist.setServerUrl("http://" + hostName + ":" + serverPort);
|
||||
}
|
||||
runtimePersist.setSftpHost(hostName);
|
||||
runtimePersist.setSftpPort(sftpPort);
|
||||
|
||||
runtimeRepository.save(runtimePersist);
|
||||
}else{
|
||||
RuntimePersist runtimePersist =byServerNameAndHostname.get(0);
|
||||
runtimePersist.setStatus(RuntimePersist.STATUS.UP.toString());
|
||||
runtimeRepository.save(runtimePersist);
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
||||
for (KieContainerResource kieContainerResource : this.server.getServerState().getResult().getContainers()){
|
||||
for (KieContainerResource kieContainerResource : this.server.getServerState().getResult().getContainers()) {
|
||||
|
||||
|
||||
// this.createContainer(container.getContainerId(),)
|
||||
|
||||
this.createContainer(kieContainerResource.getContainerId(), kieContainerResource);
|
||||
List<ContainerPojoPersist> containers = containerRepository.findByContainerId(kieContainerResource.getContainerId());
|
||||
if (containers.size()==1) {
|
||||
if (containers.size() == 1) {
|
||||
this.initCamelBusinessRoute(containers.get(0));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("initCamelBusinessRoutes", e);
|
||||
}
|
||||
|
||||
}
|
||||
@PreDestroy
|
||||
public void stopRuntime(){
|
||||
String serverName =KieServiceCommon.getKieServerID();
|
||||
List<RuntimePersist> itIsMes = runtimeRepository.findByServerName(serverName);
|
||||
if (itIsMes.size()==1){
|
||||
RuntimePersist runtimePersist =itIsMes.get(0);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
public void run() {
|
||||
String serverName = KieServiceCommon.getKieServerID();
|
||||
List<RuntimePersist> itIsMes = runtimeRepository.findByServerNameAndHostname(serverName,hostName);
|
||||
if (itIsMes.size() == 1) {
|
||||
RuntimePersist runtimePersist = itIsMes.get(0);
|
||||
runtimePersist.setStatus(RuntimePersist.STATUS.DOWN.toString());
|
||||
runtimeRepository.delete(runtimePersist);
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
||||
|
||||
public void setTimeStamp(){
|
||||
String serverName = KieServiceCommon.getKieServerID();
|
||||
List<RuntimePersist> itIsMes = runtimeRepository.findByServerNameAndHostname(serverName,hostName);
|
||||
if (itIsMes.size() == 1) {
|
||||
RuntimePersist runtimePersist = itIsMes.get(0);
|
||||
runtimePersist.setTimeStamp(new Date());
|
||||
runtimeRepository.save(runtimePersist);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteCamelBusinessRoute(String containerId) throws Exception {
|
||||
if (routes.containsKey(containerId)){
|
||||
if (routes.containsKey(containerId)) {
|
||||
DroolsRouter routeToDelete = routes.get(containerId);
|
||||
String target = routeToDelete.getRouteCollection().getRoutes().get(0).getId();
|
||||
for (Route route : camelContext.getRoutes()){
|
||||
if (route.getId().equals(target)){
|
||||
for (Route route : camelContext.getRoutes()) {
|
||||
if (route.getId().equals(target)) {
|
||||
camelContext.stopRoute(route.getId());
|
||||
camelContext.removeRoute(route.getId());
|
||||
}
|
||||
|
|
@ -200,7 +227,7 @@ public class KieServiceCommon {
|
|||
this.deleteCamelBusinessRoute(projectName);
|
||||
DroolsRouter droolsRouter = new DroolsRouter(camelContext, theClass, projectName, kieContainerInstance, processId);
|
||||
camelContext.addRoutes(droolsRouter);
|
||||
routes.put(containerId,droolsRouter);
|
||||
routes.put(containerId, droolsRouter);
|
||||
} finally {
|
||||
if (localClassLoader != null) {
|
||||
Thread.currentThread().setContextClassLoader(localClassLoader);
|
||||
|
|
@ -359,7 +386,7 @@ public class KieServiceCommon {
|
|||
|
||||
public ServiceResponse<Void> disposeContainer(String id) {
|
||||
ServiceResponse<Void> result = server.disposeContainer(id);
|
||||
String serverName =KieServiceCommon.getKieServerID();
|
||||
String serverName = KieServiceCommon.getKieServerID();
|
||||
ContainerPojoPersist element = containerRepository.findByServerNameAndContainerId(serverName, id);
|
||||
if (element != null) {
|
||||
containerRepository.delete(element);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@ import org.springframework.stereotype.Component;
|
|||
public class AutodeployRouter extends RouteBuilder {
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
from("quartz2://myGroup/myTimerName?cron=0/30+*+*+?+*+*").to("bean:updateService?method=updateConfig()");
|
||||
from("quartz2://myGroup/myTimerName?cron=0/10+*+*+?+*+*").to("bean:updateService?method=updateConfig()");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,9 +49,13 @@ public class UpdateService {
|
|||
boolean result = false;
|
||||
runtimes.clear();
|
||||
List<RuntimePersist> runtimePersists = runtimeRepository.findAll();
|
||||
Map<String, String> urlMap = new HashMap<>();
|
||||
for (RuntimePersist runtimePersist : runtimePersists) {
|
||||
if (urlMap.containsKey(runtimePersist.getServerName()) == false) {
|
||||
urlMap.put(runtimePersist.getServerName(), runtimePersist.getServerUrl());
|
||||
runtimes.put(runtimePersist.getServerName(), runtimePersist.duplicate());
|
||||
}
|
||||
}
|
||||
List<ProjectPersist> projectPersists = projectRepository.findAll();
|
||||
List<String> projectOk = new ArrayList<>();
|
||||
for (ProjectPersist projectPersist : projectPersists) {
|
||||
|
|
@ -95,6 +99,14 @@ public class UpdateService {
|
|||
projects.clear();
|
||||
List<MappingProperties> paths = new ArrayList<>();
|
||||
Collection<ProjectPersist> projectPersists = projectRepository.findAll();
|
||||
Map<String, String> urlMap = new HashMap<>();
|
||||
List<RuntimePersist> runtimePersists = runtimeRepository.findAll();
|
||||
for (RuntimePersist runtimePersist : runtimePersists) {
|
||||
if (urlMap.containsKey(runtimePersist.getServerName()) == false) {
|
||||
urlMap.put(runtimePersist.getServerName(), runtimePersist.getServerUrl());
|
||||
runtimes.put(runtimePersist.getServerName(), runtimePersist.duplicate());
|
||||
}
|
||||
}
|
||||
for (ProjectPersist projectPersist : projectPersists) {
|
||||
if (projectPersist.getServerNames().size() > 0) {
|
||||
projects.put(projectPersist.getContainerID(), projectPersist.duplicate());
|
||||
|
|
@ -103,7 +115,7 @@ public class UpdateService {
|
|||
for (String serverName : projectPersist.getServerNames()) {
|
||||
RuntimePersist runtimePersist = runtimes.get(serverName);
|
||||
if (runtimePersist!= null) {
|
||||
String hostName = runtimePersist.getHostname() + "/api/" + projectPersist.getContainerID();
|
||||
String hostName = runtimePersist.getServerUrl() + "/api/" + projectPersist.getContainerID();
|
||||
mappingProperties2.getDestinations().add(hostName);
|
||||
if (servList==null){
|
||||
servList=serverName;
|
||||
|
|
@ -120,7 +132,7 @@ public class UpdateService {
|
|||
mappingProperties2.setStripPath(true);
|
||||
if ( mappingProperties2.getDestinations().size()>0) {
|
||||
paths.add(mappingProperties2);
|
||||
logger.info("Project "+projectPersist.getContainerID()+" defined on servers - "+servList);
|
||||
logger.info("Project "+projectPersist.getContainerID()+" defined on servers - "+mappingProperties2.getDestinations().toString());
|
||||
|
||||
}else{
|
||||
logger.error("Project "+projectPersist.getContainerID()+" defined on non existing server");
|
||||
|
|
@ -136,16 +148,6 @@ public class UpdateService {
|
|||
|
||||
@PostConstruct
|
||||
public void initConfig() {
|
||||
List<RuntimePersist> runtimePersists = runtimeRepository.findAll();
|
||||
for (RuntimePersist runtimePersist : runtimePersists) {
|
||||
runtimes.put(runtimePersist.getServerName(), runtimePersist);
|
||||
}
|
||||
List<ProjectPersist> projectPersists = projectRepository.findAll();
|
||||
for (ProjectPersist projectPersist : projectPersists) {
|
||||
if (projectPersist.getServerNames().size() > 0) {
|
||||
projects.put(projectPersist.getContainerID(), projectPersist.duplicate());
|
||||
}
|
||||
}
|
||||
generateMappings();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import org.springframework.data.annotation.Id;
|
|||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Document
|
||||
public class RuntimePersist {
|
||||
public enum STATUS {
|
||||
|
|
@ -18,9 +20,11 @@ public class RuntimePersist {
|
|||
private String serverName;
|
||||
|
||||
private String version;
|
||||
|
||||
@Indexed
|
||||
private String hostname;
|
||||
|
||||
private String serverUrl;
|
||||
|
||||
private String serverPort;
|
||||
|
||||
private String sftpHost;
|
||||
|
|
@ -29,6 +33,11 @@ public class RuntimePersist {
|
|||
|
||||
private String status;
|
||||
|
||||
private Date creationDate;
|
||||
|
||||
private Date timeStamp;
|
||||
|
||||
|
||||
public RuntimePersist(String serverName, String version, String hostname,String serverPort,String sftpPort,String sftpHost,String status) {
|
||||
this.serverName = serverName;
|
||||
this.version = version;
|
||||
|
|
@ -37,10 +46,19 @@ public class RuntimePersist {
|
|||
this.sftpPort = sftpPort;
|
||||
this.sftpHost = sftpHost;
|
||||
this.status=status;
|
||||
this.creationDate = new Date();
|
||||
}
|
||||
|
||||
public RuntimePersist(String serverName) {
|
||||
this.serverName = serverName;
|
||||
}
|
||||
|
||||
public RuntimePersist() {
|
||||
}
|
||||
|
||||
public RuntimePersist duplicate(){
|
||||
RuntimePersist duplicate = new RuntimePersist(serverName,version,hostname,serverPort,sftpPort,sftpHost,status);
|
||||
duplicate.setServerUrl(this.serverUrl);
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
|
|
@ -107,4 +125,24 @@ public class RuntimePersist {
|
|||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getServerUrl() {
|
||||
return serverUrl;
|
||||
}
|
||||
|
||||
public void setServerUrl(String serverUrl) {
|
||||
this.serverUrl = serverUrl;
|
||||
}
|
||||
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public Date getTimeStamp() {
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
public void setTimeStamp(Date timeStamp) {
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,4 +10,5 @@ import java.util.List;
|
|||
public interface RuntimeRepository extends MongoRepository<RuntimePersist, String> {
|
||||
|
||||
public List<RuntimePersist> findByServerName(String serverName);
|
||||
public List<RuntimePersist> findByServerNameAndHostname(String serverName,String hostname);
|
||||
}
|
||||
|
|
|
|||
2
pom.xml
2
pom.xml
|
|
@ -20,7 +20,7 @@
|
|||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<jbpm.version>7.27.0.Final</jbpm.version>
|
||||
<jbpm.version>7.28.0.Final</jbpm.version>
|
||||
<node.version>v10.16.3</node.version>
|
||||
<npm.version>6.11.3</npm.version>
|
||||
<frontend-maven-plugin.version>1.8.0</frontend-maven-plugin.version>
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue