Work on Running in Swarm
Debug of reverse proxy
This commit is contained in:
parent
1b8ab0d36b
commit
62eef1370b
11 changed files with 265 additions and 119 deletions
|
|
@ -7,6 +7,8 @@ ADD maven/drools-framework-admin-console.jar app.jar
|
||||||
EXPOSE 8200
|
EXPOSE 8200
|
||||||
|
|
||||||
RUN bash -c 'touch /app.jar'
|
RUN bash -c 'touch /app.jar'
|
||||||
|
ENV JAVA_OPTS "-Dspring.config.location=file:./ "
|
||||||
|
|
||||||
ENTRYPOINT ["java","-Dspring.config.location=file:./","-jar","/app.jar"]
|
ENTRYPOINT exec java $JAVA_OPTS $PYMMA_OPTS -jar /app.jar
|
||||||
|
#ENTRYPOINT ["java","-Dspring.config.location=file:./","-jar","/app.jar"]
|
||||||
#ENTRYPOINT ["java","-jar","/app.jar"]
|
#ENTRYPOINT ["java","-jar","/app.jar"]
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,11 @@ import org.chtijbug.drools.console.service.model.kie.KieConfigurationData;
|
||||||
import org.chtijbug.drools.console.service.util.AppContext;
|
import org.chtijbug.drools.console.service.util.AppContext;
|
||||||
import org.chtijbug.drools.proxy.persistence.json.KeyProject;
|
import org.chtijbug.drools.proxy.persistence.json.KeyProject;
|
||||||
import org.chtijbug.drools.proxy.persistence.model.ContainerPojoPersist;
|
import org.chtijbug.drools.proxy.persistence.model.ContainerPojoPersist;
|
||||||
|
import org.chtijbug.drools.proxy.persistence.model.ContainerRuntimePojoPersist;
|
||||||
import org.chtijbug.drools.proxy.persistence.model.ProjectPersist;
|
import org.chtijbug.drools.proxy.persistence.model.ProjectPersist;
|
||||||
import org.chtijbug.drools.proxy.persistence.model.RuntimePersist;
|
import org.chtijbug.drools.proxy.persistence.model.RuntimePersist;
|
||||||
import org.chtijbug.drools.proxy.persistence.repository.ContainerRepository;
|
import org.chtijbug.drools.proxy.persistence.repository.ContainerRepository;
|
||||||
|
import org.chtijbug.drools.proxy.persistence.repository.ContainerRuntimeRepository;
|
||||||
import org.chtijbug.drools.proxy.persistence.repository.ProjectRepository;
|
import org.chtijbug.drools.proxy.persistence.repository.ProjectRepository;
|
||||||
import org.chtijbug.drools.proxy.persistence.repository.RuntimeRepository;
|
import org.chtijbug.drools.proxy.persistence.repository.RuntimeRepository;
|
||||||
import org.chtijbug.guvnor.server.jaxrs.model.PlatformProjectResponse;
|
import org.chtijbug.guvnor.server.jaxrs.model.PlatformProjectResponse;
|
||||||
|
|
@ -42,6 +44,9 @@ public class ProjectPersistService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ContainerRepository containerRepository;
|
private ContainerRepository containerRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ContainerRuntimeRepository containerRuntimeRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RuntimeRepository runtimeRepository;
|
private RuntimeRepository runtimeRepository;
|
||||||
|
|
||||||
|
|
@ -107,7 +112,8 @@ public class ProjectPersistService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean associate(ProjectPersist projectPersist, List<RuntimePersist> runtimePersists) {
|
public boolean associate(ProjectPersist projectPersist, List<RuntimePersist> runtimePersists) {
|
||||||
|
projectPersist.setStatus(ProjectPersist.Deployable);
|
||||||
|
projectPersist.setContainerID(projectPersist.getDeploymentName() + "-" + projectPersist.getProjectName());
|
||||||
projectPersist.getServerNames().clear();
|
projectPersist.getServerNames().clear();
|
||||||
for (RuntimePersist runtimePersist : runtimePersists) {
|
for (RuntimePersist runtimePersist : runtimePersists) {
|
||||||
List<String> names = new ArrayList<String>();
|
List<String> names = new ArrayList<String>();
|
||||||
|
|
@ -117,11 +123,23 @@ public class ProjectPersistService {
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
projectPersist.getServerNames().add(runtimePersist.getServerName());
|
projectPersist.getServerNames().add(runtimePersist.getServerName());
|
||||||
|
ContainerPojoPersist existingContainer = containerRepository.findByServerNameAndContainerId(runtimePersist.getServerName(), projectPersist.getContainerID());
|
||||||
|
if (existingContainer == null) {
|
||||||
|
ContainerPojoPersist newContainer = new ContainerPojoPersist();
|
||||||
|
newContainer.setClassName(projectPersist.getMainClass());
|
||||||
|
newContainer.setProcessID(projectPersist.getProcessID());
|
||||||
|
newContainer.setContainerId(projectPersist.getContainerID());
|
||||||
|
newContainer.setServerName(runtimePersist.getServerName());
|
||||||
|
newContainer.setGroupId(projectPersist.getGroupID());
|
||||||
|
newContainer.setArtifactId(projectPersist.getArtifactID());
|
||||||
|
newContainer.setVersion(projectPersist.getProjectVersion());
|
||||||
|
containerRepository.save(newContainer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
projectPersist.setStatus(ProjectPersist.Deployable);
|
|
||||||
projectPersist.setContainerID(projectPersist.getDeploymentName() + "-" + projectPersist.getProjectName());
|
|
||||||
projectRepository.save(projectPersist);
|
projectRepository.save(projectPersist);
|
||||||
|
|
||||||
addProjectToSession(projectPersist, true);
|
addProjectToSession(projectPersist, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -166,38 +184,27 @@ public class ProjectPersistService {
|
||||||
|
|
||||||
// ContainerPojoPersist toto = containerRepository.findByServerNameAndContainerId(projectPersist.getContainerID());
|
// ContainerPojoPersist toto = containerRepository.findByServerNameAndContainerId(projectPersist.getContainerID());
|
||||||
for (String serverName : projectPersist.getServerNames()) {
|
for (String serverName : projectPersist.getServerNames()) {
|
||||||
List<RuntimePersist> kieservers = runtimeRepository.findByServerName(serverName);
|
|
||||||
if (kieservers.size() == 1) {
|
List<ContainerRuntimePojoPersist> existingContainers = containerRuntimeRepository.findByServerNameAndContainerId(serverName, projectPersist.getContainerID());
|
||||||
ContainerPojoPersist existingContainer = containerRepository.findByServerNameAndContainerId(serverName, projectPersist.getContainerID());
|
if (existingContainers.size() > 0) {
|
||||||
if (existingContainer == null) {
|
for (ContainerRuntimePojoPersist containerRuntimePojoPersist : existingContainers) {
|
||||||
ContainerPojoPersist newContainer = new ContainerPojoPersist();
|
containerRuntimePojoPersist.setStatus(ContainerRuntimePojoPersist.STATUS.TODEPLOY.name());
|
||||||
newContainer.setStatus(ContainerPojoPersist.STATUS.TODEPLOY.toString());
|
containerRuntimeRepository.save(containerRuntimePojoPersist);
|
||||||
newContainer.setClassName(projectPersist.getMainClass());
|
}
|
||||||
newContainer.setProcessID(projectPersist.getProcessID());
|
|
||||||
newContainer.setContainerId(projectPersist.getContainerID());
|
|
||||||
newContainer.setServerName(serverName);
|
|
||||||
newContainer.setGroupId(projectPersist.getGroupID());
|
|
||||||
newContainer.setArtifactId(projectPersist.getArtifactID());
|
|
||||||
newContainer.setVersion(projectPersist.getProjectVersion());
|
|
||||||
containerRepository.save(newContainer);
|
|
||||||
} else {
|
} else {
|
||||||
existingContainer.setStatus(ContainerPojoPersist.STATUS.TODEPLOY.toString());
|
List<RuntimePersist> servers = runtimeRepository.findByServerName(serverName);
|
||||||
existingContainer.setProcessID(projectPersist.getProcessID());
|
for (RuntimePersist server : servers) {
|
||||||
existingContainer.setClassName(projectPersist.getMainClass());
|
ContainerRuntimePojoPersist runtimePojoPersist = new ContainerRuntimePojoPersist();
|
||||||
existingContainer.setProcessID(projectPersist.getProcessID());
|
runtimePojoPersist.setServerName(serverName);
|
||||||
containerRepository.save(existingContainer);
|
runtimePojoPersist.setHostname(server.getHostname());
|
||||||
|
runtimePojoPersist.setContainerId(projectPersist.getContainerID());
|
||||||
|
runtimePojoPersist.setStatus(ContainerRuntimePojoPersist.STATUS.TODEPLOY.name());
|
||||||
|
containerRuntimeRepository.save(runtimePojoPersist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//remove container from other runtime
|
|
||||||
List<ContainerPojoPersist> containerPojoPersists = containerRepository.findByContainerId(projectPersist.getContainerID());
|
|
||||||
for (ContainerPojoPersist container : containerPojoPersists){
|
|
||||||
if (projectPersist.getServerNames().contains(container.getServerName())==false){
|
|
||||||
container.setStatus(ContainerPojoPersist.STATUS.TODELETE.toString());
|
|
||||||
containerRepository.save(container);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ kie-wb.username=admin
|
||||||
kie-wb.password=admin
|
kie-wb.password=admin
|
||||||
|
|
||||||
adminConsole.tmpdir=/tmp
|
adminConsole.tmpdir=/tmp
|
||||||
spring.data.elasticsearch.cluster-nodes=localhost:9300
|
|
||||||
|
|
||||||
|
|
||||||
spring.data.mongodb.database=businessProxyDB
|
spring.data.mongodb.database=businessProxyDB
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package org.chtijbug.drools.proxy;
|
||||||
|
|
||||||
import org.chtijbug.drools.proxy.persistence.model.ContainerPojoPersist;
|
import org.chtijbug.drools.proxy.persistence.model.ContainerPojoPersist;
|
||||||
import org.chtijbug.drools.proxy.persistence.repository.ContainerRepository;
|
import org.chtijbug.drools.proxy.persistence.repository.ContainerRepository;
|
||||||
|
import org.chtijbug.drools.proxy.persistence.repository.ContainerRuntimeRepository;
|
||||||
import org.chtijbug.drools.proxy.service.KieServiceCommon;
|
import org.chtijbug.drools.proxy.service.KieServiceCommon;
|
||||||
import org.kie.server.api.model.KieContainerResource;
|
import org.kie.server.api.model.KieContainerResource;
|
||||||
import org.kie.server.api.model.KieServerConfig;
|
import org.kie.server.api.model.KieServerConfig;
|
||||||
|
|
@ -9,24 +10,40 @@ import org.kie.server.api.model.ReleaseId;
|
||||||
import org.kie.server.services.impl.storage.KieServerState;
|
import org.kie.server.services.impl.storage.KieServerState;
|
||||||
import org.kie.server.services.impl.storage.KieServerStateRepository;
|
import org.kie.server.services.impl.storage.KieServerStateRepository;
|
||||||
import org.kie.server.services.impl.storage.KieServerStateRepositoryUtils;
|
import org.kie.server.services.impl.storage.KieServerStateRepositoryUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PlatfomKieServerStateRepository implements KieServerStateRepository {
|
public class PlatfomKieServerStateRepository implements KieServerStateRepository {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PlatfomKieServerStateRepository.class);
|
||||||
|
|
||||||
private ContainerRepository containerRepository;
|
private ContainerRepository containerRepository;
|
||||||
|
|
||||||
|
private ContainerRuntimeRepository containerRuntimeRepository;
|
||||||
|
|
||||||
private KieServiceCommon kieServiceCommon;
|
private KieServiceCommon kieServiceCommon;
|
||||||
|
|
||||||
private KieServerState kieServerState = new KieServerState();
|
private KieServerState kieServerState = new KieServerState();
|
||||||
|
|
||||||
public PlatfomKieServerStateRepository(ContainerRepository containerRepository, KieServiceCommon kieServiceCommon) {
|
private String hostName;
|
||||||
|
|
||||||
|
public PlatfomKieServerStateRepository(ContainerRepository containerRepository, ContainerRuntimeRepository containerRuntimeRepository,KieServiceCommon kieServiceCommon) {
|
||||||
this.containerRepository = containerRepository;
|
this.containerRepository = containerRepository;
|
||||||
|
this.containerRuntimeRepository=containerRuntimeRepository;
|
||||||
this.kieServiceCommon = kieServiceCommon;
|
this.kieServiceCommon = kieServiceCommon;
|
||||||
KieServerConfig config = new KieServerConfig();
|
KieServerConfig config = new KieServerConfig();
|
||||||
KieServerStateRepositoryUtils.populateWithSystemProperties(config);
|
KieServerStateRepositoryUtils.populateWithSystemProperties(config);
|
||||||
kieServerState.setConfiguration(config);
|
kieServerState.setConfiguration(config);
|
||||||
|
try {
|
||||||
|
InetAddress inetAddress = InetAddress.getLocalHost();
|
||||||
|
hostName = inetAddress.getHostName();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
logger.info("initCamelBusinessRoutes.getLocalHost", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -39,7 +56,7 @@ public class PlatfomKieServerStateRepository implements KieServerStateRepository
|
||||||
|
|
||||||
String serverName = KieServiceCommon.getKieServerID();
|
String serverName = KieServiceCommon.getKieServerID();
|
||||||
|
|
||||||
List<ContainerPojoPersist> containers = containerRepository.findByServerNameAndStatus(serverName, ContainerPojoPersist.STATUS.UP.toString());
|
List<ContainerPojoPersist> containers = containerRepository.findByServerName(serverName);
|
||||||
for (ContainerPojoPersist element : containers) {
|
for (ContainerPojoPersist element : containers) {
|
||||||
KieContainerResource newContainer = new KieContainerResource();
|
KieContainerResource newContainer = new KieContainerResource();
|
||||||
newContainer.setContainerId(element.getContainerId());
|
newContainer.setContainerId(element.getContainerId());
|
||||||
|
|
@ -48,6 +65,7 @@ public class PlatfomKieServerStateRepository implements KieServerStateRepository
|
||||||
newContainer.getReleaseId().setGroupId(element.getGroupId());
|
newContainer.getReleaseId().setGroupId(element.getGroupId());
|
||||||
newContainer.getReleaseId().setVersion(element.getVersion());
|
newContainer.getReleaseId().setVersion(element.getVersion());
|
||||||
kieServerState.getContainers().add(newContainer);
|
kieServerState.getContainers().add(newContainer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,10 @@ import org.apache.camel.Route;
|
||||||
import org.chtijbug.drools.proxy.PlatfomKieServerStateRepository;
|
import org.chtijbug.drools.proxy.PlatfomKieServerStateRepository;
|
||||||
import org.chtijbug.drools.proxy.camel.DroolsRouter;
|
import org.chtijbug.drools.proxy.camel.DroolsRouter;
|
||||||
import org.chtijbug.drools.proxy.persistence.model.ContainerPojoPersist;
|
import org.chtijbug.drools.proxy.persistence.model.ContainerPojoPersist;
|
||||||
|
import org.chtijbug.drools.proxy.persistence.model.ContainerRuntimePojoPersist;
|
||||||
import org.chtijbug.drools.proxy.persistence.model.RuntimePersist;
|
import org.chtijbug.drools.proxy.persistence.model.RuntimePersist;
|
||||||
import org.chtijbug.drools.proxy.persistence.repository.ContainerRepository;
|
import org.chtijbug.drools.proxy.persistence.repository.ContainerRepository;
|
||||||
|
import org.chtijbug.drools.proxy.persistence.repository.ContainerRuntimeRepository;
|
||||||
import org.chtijbug.drools.proxy.persistence.repository.RuntimeRepository;
|
import org.chtijbug.drools.proxy.persistence.repository.RuntimeRepository;
|
||||||
import org.chtijbug.kieserver.services.drools.DroolsChtijbugKieServerExtension;
|
import org.chtijbug.kieserver.services.drools.DroolsChtijbugKieServerExtension;
|
||||||
import org.chtijbug.kieserver.services.drools.DroolsChtijbugRulesExecutionService;
|
import org.chtijbug.kieserver.services.drools.DroolsChtijbugRulesExecutionService;
|
||||||
|
|
@ -64,14 +66,13 @@ public class KieServiceCommon {
|
||||||
private ContainerRepository containerRepository;
|
private ContainerRepository containerRepository;
|
||||||
@Inject
|
@Inject
|
||||||
private RuntimeRepository runtimeRepository;
|
private RuntimeRepository runtimeRepository;
|
||||||
|
@Inject
|
||||||
|
private ContainerRuntimeRepository containerRuntimeRepository;
|
||||||
@Value("${server.port}")
|
@Value("${server.port}")
|
||||||
private int serverPort;
|
private int serverPort;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationContext appContext;
|
private ApplicationContext appContext;
|
||||||
|
|
||||||
private String hostName = "localhost";
|
private String hostName = "localhost";
|
||||||
|
|
||||||
private Map<String, DroolsRouter> routes = new HashMap<>();
|
private Map<String, DroolsRouter> routes = new HashMap<>();
|
||||||
|
|
||||||
public KieServiceCommon() {
|
public KieServiceCommon() {
|
||||||
|
|
@ -86,7 +87,7 @@ public class KieServiceCommon {
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void initCamelBusinessRoutes() {
|
private void initCamelBusinessRoutes() {
|
||||||
|
|
||||||
this.server = new KieServerImpl(new PlatfomKieServerStateRepository(containerRepository, this));
|
this.server = new KieServerImpl(new PlatfomKieServerStateRepository(containerRepository, containerRuntimeRepository, this));
|
||||||
this.server.init();
|
this.server.init();
|
||||||
|
|
||||||
List<KieServerExtension> serverExtensions = this.server.getServerExtensions();
|
List<KieServerExtension> serverExtensions = this.server.getServerExtensions();
|
||||||
|
|
@ -115,15 +116,14 @@ public class KieServiceCommon {
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
logger.info("initCamelBusinessRoutes.getLocalHost", e);
|
logger.info("initCamelBusinessRoutes.getLocalHost", e);
|
||||||
}
|
}
|
||||||
List<RuntimePersist> itIsMes = runtimeRepository.findByServerName(serverName);
|
List<RuntimePersist> itIsMes = runtimeRepository.findByServerNameAndHostname(serverName, hostName);
|
||||||
ServiceResponse<KieServerInfo> result = server.getInfo();
|
ServiceResponse<KieServerInfo> result = server.getInfo();
|
||||||
String version = result.getResult().getVersion();
|
String version = result.getResult().getVersion();
|
||||||
String isSwarm=System.getProperty("org.kie.server.swarm");
|
|
||||||
if (itIsMes.size() == 0) {
|
if (itIsMes.size() == 0) {
|
||||||
|
|
||||||
RuntimePersist runtimePersist = new RuntimePersist(serverName, version, hostName,
|
RuntimePersist runtimePersist = new RuntimePersist(serverName, version, hostName,
|
||||||
String.valueOf(serverPort), sftpPort,
|
String.valueOf(serverPort), sftpPort,
|
||||||
hostName, RuntimePersist.STATUS.UP.toString());
|
hostName, RuntimePersist.STATUS.UP.toString());
|
||||||
|
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 {
|
||||||
|
|
@ -131,37 +131,25 @@ public class KieServiceCommon {
|
||||||
}
|
}
|
||||||
runtimeRepository.save(runtimePersist);
|
runtimeRepository.save(runtimePersist);
|
||||||
} else {
|
} else {
|
||||||
List<RuntimePersist> byServerNameAndHostname = runtimeRepository.findByServerNameAndHostname(serverName, hostName);
|
RuntimePersist runtimePersist = itIsMes.get(0);
|
||||||
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());
|
runtimePersist.setStatus(RuntimePersist.STATUS.UP.toString());
|
||||||
runtimeRepository.save(runtimePersist);
|
runtimeRepository.save(runtimePersist);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
try {
|
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);
|
this.createContainer(kieContainerResource.getContainerId(), kieContainerResource);
|
||||||
List<ContainerPojoPersist> containers = containerRepository.findByContainerId(kieContainerResource.getContainerId());
|
ContainerPojoPersist container = containerRepository.findByServerNameAndContainerId(serverName, kieContainerResource.getContainerId());
|
||||||
if (containers.size() == 1) {
|
if (container != null) {
|
||||||
this.initCamelBusinessRoute(containers.get(0));
|
ContainerRuntimePojoPersist containerRuntimePojoPersist = containerRuntimeRepository.findByServerNameAndContainerIdAndHostname(serverName, kieContainerResource.getContainerId(), hostName);
|
||||||
|
if (containerRuntimePojoPersist == null) {
|
||||||
|
containerRuntimePojoPersist = new ContainerRuntimePojoPersist();
|
||||||
|
containerRuntimePojoPersist.setContainerId(container.getContainerId());
|
||||||
|
containerRuntimePojoPersist.setServerName(serverName);
|
||||||
|
containerRuntimePojoPersist.setHostname(hostName);
|
||||||
|
containerRuntimePojoPersist.setStatus(ContainerRuntimePojoPersist.STATUS.UP.name());
|
||||||
|
containerRuntimeRepository.save(containerRuntimePojoPersist);
|
||||||
|
}
|
||||||
|
this.initCamelBusinessRoute(container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -176,9 +164,13 @@ public class KieServiceCommon {
|
||||||
runtimePersist.setStatus(RuntimePersist.STATUS.DOWN.toString());
|
runtimePersist.setStatus(RuntimePersist.STATUS.DOWN.toString());
|
||||||
runtimeRepository.delete(runtimePersist);
|
runtimeRepository.delete(runtimePersist);
|
||||||
}
|
}
|
||||||
}});
|
List<ContainerRuntimePojoPersist> ccc = containerRuntimeRepository.findByServerNameAndHostname(serverName, hostName);
|
||||||
|
if (ccc.size() > 0) {
|
||||||
|
containerRuntimeRepository.deleteAll(ccc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setTimeStamp() {
|
public void setTimeStamp() {
|
||||||
String serverName = KieServiceCommon.getKieServerID();
|
String serverName = KieServiceCommon.getKieServerID();
|
||||||
|
|
@ -272,28 +264,42 @@ public class KieServiceCommon {
|
||||||
|
|
||||||
public void updateConfig() throws Exception {
|
public void updateConfig() throws Exception {
|
||||||
String serverName = KieServiceCommon.getKieServerID();
|
String serverName = KieServiceCommon.getKieServerID();
|
||||||
List<ContainerPojoPersist> containers = containerRepository.findByServerNameAndStatus(serverName, ContainerPojoPersist.STATUS.TODEPLOY.toString());
|
String isSwarm = System.getProperty("org.kie.server.swarm");
|
||||||
for (ContainerPojoPersist element : containers) {
|
List<ContainerRuntimePojoPersist> containers = null;
|
||||||
|
|
||||||
|
containers = containerRuntimeRepository.findByServerNameAndStatusAndHostname(serverName, ContainerRuntimePojoPersist.STATUS.TODEPLOY.toString(), hostName);
|
||||||
|
for (ContainerRuntimePojoPersist element : containers) {
|
||||||
|
ContainerPojoPersist containerIds = containerRepository.findByServerNameAndContainerId(serverName, element.getContainerId());
|
||||||
|
if (containerIds != null) {
|
||||||
|
|
||||||
this.disposeContainer(element.getContainerId());
|
this.disposeContainer(element.getContainerId());
|
||||||
KieContainerResource newContainer = new KieContainerResource();
|
KieContainerResource newContainer = new KieContainerResource();
|
||||||
newContainer.setContainerId(element.getContainerId());
|
newContainer.setContainerId(element.getContainerId());
|
||||||
newContainer.setReleaseId(new ReleaseId());
|
newContainer.setReleaseId(new ReleaseId());
|
||||||
newContainer.getReleaseId().setArtifactId(element.getArtifactId());
|
newContainer.getReleaseId().setArtifactId(containerIds.getArtifactId());
|
||||||
newContainer.getReleaseId().setGroupId(element.getGroupId());
|
newContainer.getReleaseId().setGroupId(containerIds.getGroupId());
|
||||||
newContainer.getReleaseId().setVersion(element.getVersion());
|
newContainer.getReleaseId().setVersion(containerIds.getVersion());
|
||||||
this.createContainer(element.getContainerId(), newContainer);
|
this.createContainer(element.getContainerId(), newContainer);
|
||||||
this.initCamelBusinessRoute(element);
|
this.initCamelBusinessRoute(containerIds);
|
||||||
element.setStatus(ContainerPojoPersist.STATUS.UP.toString());
|
element.setStatus(ContainerRuntimePojoPersist.STATUS.UP.toString());
|
||||||
containerRepository.save(element);
|
containerRuntimeRepository.save(element);
|
||||||
}
|
}
|
||||||
List<ContainerPojoPersist> containersToDelete = containerRepository.findByServerNameAndStatus(serverName, ContainerPojoPersist.STATUS.TODELETE.toString());
|
|
||||||
for (ContainerPojoPersist element : containersToDelete) {
|
}
|
||||||
|
containers = containerRuntimeRepository.findByServerNameAndStatusAndHostname(serverName, ContainerRuntimePojoPersist.STATUS.TODELETE.toString(), hostName);
|
||||||
|
|
||||||
|
for (ContainerRuntimePojoPersist element : containers) {
|
||||||
|
ContainerPojoPersist containerIds = containerRepository.findByServerNameAndContainerId(serverName, element.getContainerId());
|
||||||
|
if (containerIds != null) {
|
||||||
this.disposeContainer(element.getContainerId());
|
this.disposeContainer(element.getContainerId());
|
||||||
this.deleteCamelBusinessRoute(element.getContainerId());
|
this.deleteCamelBusinessRoute(element.getContainerId());
|
||||||
containerRepository.delete(element);
|
containerRepository.delete(containerIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public KieContainerResource createContainerWithRestBusinessService(String id, KieContainerResource container, String className, String processID) {
|
public KieContainerResource createContainerWithRestBusinessService(String id, KieContainerResource container, String className, String processID) {
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -387,9 +393,9 @@ public class KieServiceCommon {
|
||||||
public ServiceResponse<Void> disposeContainer(String id) {
|
public ServiceResponse<Void> disposeContainer(String id) {
|
||||||
ServiceResponse<Void> result = server.disposeContainer(id);
|
ServiceResponse<Void> result = server.disposeContainer(id);
|
||||||
String serverName = KieServiceCommon.getKieServerID();
|
String serverName = KieServiceCommon.getKieServerID();
|
||||||
ContainerPojoPersist element = containerRepository.findByServerNameAndContainerId(serverName, id);
|
ContainerRuntimePojoPersist element = containerRuntimeRepository.findByServerNameAndContainerIdAndHostname(serverName, id, hostName);
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
containerRepository.delete(element);
|
containerRuntimeRepository.delete(element);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,9 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class CustomMappingsProvider extends MappingsProvider {
|
public class CustomMappingsProvider extends MappingsProvider {
|
||||||
|
|
@ -19,13 +21,22 @@ public class CustomMappingsProvider extends MappingsProvider {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UpdateService updateService;
|
private UpdateService updateService;
|
||||||
|
private Map<String,MappingProperties> mappingPropertiesMap = new HashMap<>();
|
||||||
|
|
||||||
public CustomMappingsProvider(ServerProperties server, CharonProperties charon, MappingsCorrector mappingsCorrector, HttpClientProvider httpClientProvider) {
|
public CustomMappingsProvider(ServerProperties server, CharonProperties charon, MappingsCorrector mappingsCorrector, HttpClientProvider httpClientProvider) {
|
||||||
super(server, charon, mappingsCorrector,httpClientProvider);
|
super(server, charon, mappingsCorrector,httpClientProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MappingProperties resolveMapping(String originUri, HttpServletRequest request) {
|
||||||
|
|
||||||
|
MappingProperties result = mappingPropertiesMap.get(originUri);
|
||||||
|
if (result!= null){
|
||||||
|
return result;
|
||||||
|
}else {
|
||||||
|
return super.resolveMapping(originUri, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean shouldUpdateMappings(HttpServletRequest httpServletRequest) {
|
protected boolean shouldUpdateMappings(HttpServletRequest httpServletRequest) {
|
||||||
|
|
@ -36,4 +47,8 @@ public class CustomMappingsProvider extends MappingsProvider {
|
||||||
protected List<MappingProperties> retrieveMappings() {
|
protected List<MappingProperties> retrieveMappings() {
|
||||||
return updateService.retrievePath();
|
return updateService.retrievePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMappingPropertiesMap(Map<String, MappingProperties> mappingPropertiesMap) {
|
||||||
|
this.mappingPropertiesMap = mappingPropertiesMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import org.chtijbug.drools.proxy.persistence.model.ProjectPersist;
|
||||||
import org.chtijbug.drools.proxy.persistence.model.RuntimePersist;
|
import org.chtijbug.drools.proxy.persistence.model.RuntimePersist;
|
||||||
import org.chtijbug.drools.proxy.persistence.repository.ProjectRepository;
|
import org.chtijbug.drools.proxy.persistence.repository.ProjectRepository;
|
||||||
import org.chtijbug.drools.proxy.persistence.repository.RuntimeRepository;
|
import org.chtijbug.drools.proxy.persistence.repository.RuntimeRepository;
|
||||||
|
import org.chtijbug.drools.reverseproxy.mappings.CustomMappingsProvider;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -25,10 +26,14 @@ public class UpdateService {
|
||||||
private Map<String, RuntimePersist> runtimes = new HashMap<>();
|
private Map<String, RuntimePersist> runtimes = new HashMap<>();
|
||||||
private Map<String, ProjectPersist> projects = new HashMap<>();
|
private Map<String, ProjectPersist> projects = new HashMap<>();
|
||||||
|
|
||||||
private Boolean toUpdate = false;
|
private Boolean toUpdate = true;
|
||||||
|
|
||||||
private List<MappingProperties> mappings=new ArrayList<>();
|
private List<MappingProperties> mappings=new ArrayList<>();
|
||||||
|
|
||||||
|
private Map<String,MappingProperties> mappingPropertiesMap = new HashMap<>();
|
||||||
|
@Autowired
|
||||||
|
private CustomMappingsProvider customMappingsProvider;
|
||||||
|
|
||||||
public Boolean getToUpdate() {
|
public Boolean getToUpdate() {
|
||||||
return toUpdate;
|
return toUpdate;
|
||||||
}
|
}
|
||||||
|
|
@ -97,6 +102,7 @@ public class UpdateService {
|
||||||
}
|
}
|
||||||
private void generateMappings(){
|
private void generateMappings(){
|
||||||
projects.clear();
|
projects.clear();
|
||||||
|
mappingPropertiesMap.clear();
|
||||||
List<MappingProperties> paths = new ArrayList<>();
|
List<MappingProperties> paths = new ArrayList<>();
|
||||||
Collection<ProjectPersist> projectPersists = projectRepository.findAll();
|
Collection<ProjectPersist> projectPersists = projectRepository.findAll();
|
||||||
Map<String, String> urlMap = new HashMap<>();
|
Map<String, String> urlMap = new HashMap<>();
|
||||||
|
|
@ -131,6 +137,7 @@ public class UpdateService {
|
||||||
mappingProperties2.getCustomConfiguration().put("read", 2000);
|
mappingProperties2.getCustomConfiguration().put("read", 2000);
|
||||||
mappingProperties2.setStripPath(true);
|
mappingProperties2.setStripPath(true);
|
||||||
if ( mappingProperties2.getDestinations().size()>0) {
|
if ( mappingProperties2.getDestinations().size()>0) {
|
||||||
|
mappingPropertiesMap.put(mappingProperties2.getPath(),mappingProperties2);
|
||||||
paths.add(mappingProperties2);
|
paths.add(mappingProperties2);
|
||||||
logger.info("Project "+projectPersist.getContainerID()+" defined on servers - "+mappingProperties2.getDestinations().toString());
|
logger.info("Project "+projectPersist.getContainerID()+" defined on servers - "+mappingProperties2.getDestinations().toString());
|
||||||
|
|
||||||
|
|
@ -144,6 +151,7 @@ public class UpdateService {
|
||||||
}
|
}
|
||||||
mappings.clear();
|
mappings.clear();
|
||||||
mappings.addAll(paths);
|
mappings.addAll(paths);
|
||||||
|
this.customMappingsProvider.setMappingPropertiesMap(mappingPropertiesMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
@Document
|
@Document
|
||||||
public class ContainerPojoPersist {
|
public class ContainerPojoPersist {
|
||||||
public enum STATUS {
|
|
||||||
UP,
|
|
||||||
DOWN,
|
|
||||||
TODEPLOY,
|
|
||||||
TODELETE
|
|
||||||
}
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
|
@ -27,7 +22,7 @@ public class ContainerPojoPersist {
|
||||||
|
|
||||||
private String projectName;
|
private String projectName;
|
||||||
|
|
||||||
private String status;
|
|
||||||
|
|
||||||
private String groupId;
|
private String groupId;
|
||||||
|
|
||||||
|
|
@ -35,6 +30,7 @@ public class ContainerPojoPersist {
|
||||||
|
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
@ -83,13 +79,7 @@ public class ContainerPojoPersist {
|
||||||
this.processID = processID;
|
this.processID = processID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(String status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGroupId() {
|
public String getGroupId() {
|
||||||
return groupId;
|
return groupId;
|
||||||
|
|
@ -115,6 +105,7 @@ public class ContainerPojoPersist {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuffer sb = new StringBuffer("ContainerPojoPersist{");
|
final StringBuffer sb = new StringBuffer("ContainerPojoPersist{");
|
||||||
|
|
@ -124,7 +115,6 @@ public class ContainerPojoPersist {
|
||||||
sb.append(", serverName='").append(serverName).append('\'');
|
sb.append(", serverName='").append(serverName).append('\'');
|
||||||
sb.append(", processID='").append(processID).append('\'');
|
sb.append(", processID='").append(processID).append('\'');
|
||||||
sb.append(", projectName='").append(projectName).append('\'');
|
sb.append(", projectName='").append(projectName).append('\'');
|
||||||
sb.append(", status=").append(status);
|
|
||||||
sb.append(", groupId='").append(groupId).append('\'');
|
sb.append(", groupId='").append(groupId).append('\'');
|
||||||
sb.append(", artifactId='").append(artifactId).append('\'');
|
sb.append(", artifactId='").append(artifactId).append('\'');
|
||||||
sb.append(", version='").append(version).append('\'');
|
sb.append(", version='").append(version).append('\'');
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
package org.chtijbug.drools.proxy.persistence.model;
|
||||||
|
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.mongodb.core.index.Indexed;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
@Document
|
||||||
|
public class ContainerRuntimePojoPersist {
|
||||||
|
public enum STATUS {
|
||||||
|
UP,
|
||||||
|
DOWN,
|
||||||
|
TODEPLOY,
|
||||||
|
TODELETE
|
||||||
|
}
|
||||||
|
@Id
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Indexed
|
||||||
|
private String containerId;
|
||||||
|
@Indexed
|
||||||
|
private String serverName;
|
||||||
|
@Indexed
|
||||||
|
private String hostname;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getContainerId() {
|
||||||
|
return containerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContainerId(String containerId) {
|
||||||
|
this.containerId = containerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerName() {
|
||||||
|
return serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerName(String serverName) {
|
||||||
|
this.serverName = serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHostname() {
|
||||||
|
return hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHostname(String hostname) {
|
||||||
|
this.hostname = hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuffer sb = new StringBuffer("ContainerRuntimePojoPersist{");
|
||||||
|
sb.append("id='").append(id).append('\'');
|
||||||
|
sb.append(", containerId='").append(containerId).append('\'');
|
||||||
|
sb.append(", serverName='").append(serverName).append('\'');
|
||||||
|
sb.append(", hostname='").append(hostname).append('\'');
|
||||||
|
sb.append(", status='").append(status).append('\'');
|
||||||
|
sb.append('}');
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,6 @@ public interface ContainerRepository extends MongoRepository<ContainerPojoPersis
|
||||||
List<ContainerPojoPersist> findByContainerId(String containerId);
|
List<ContainerPojoPersist> findByContainerId(String containerId);
|
||||||
|
|
||||||
List<ContainerPojoPersist> findByServerName(String serverName);
|
List<ContainerPojoPersist> findByServerName(String serverName);
|
||||||
List<ContainerPojoPersist> findByServerNameAndStatus(String serverName, String status);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package org.chtijbug.drools.proxy.persistence.repository;
|
||||||
|
|
||||||
|
import org.chtijbug.drools.proxy.persistence.model.ContainerRuntimePojoPersist;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ContainerRuntimeRepository extends MongoRepository<ContainerRuntimePojoPersist, String> {
|
||||||
|
|
||||||
|
|
||||||
|
List<ContainerRuntimePojoPersist> findByServerNameAndContainerId(String serverName, String containerId);
|
||||||
|
List<ContainerRuntimePojoPersist> findByServerNameAndStatus(String serverName, String status);
|
||||||
|
List<ContainerRuntimePojoPersist> findByServerNameAndStatusAndHostname(String serverName, String status,String hostname);
|
||||||
|
List<ContainerRuntimePojoPersist> findByServerNameAndHostname(String serverName, String hostname);
|
||||||
|
ContainerRuntimePojoPersist findByServerNameAndContainerIdAndHostname(String serverName, String containerId,String hostname);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue