Merge pull request #182 from pymma/kafka

work on deployment of project
This commit is contained in:
Nicolas Héron 2020-11-12 15:57:48 +01:00 committed by GitHub
commit 6f86742d5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 22 deletions

View file

@ -168,6 +168,15 @@ public class ProjectPersistService {
return map; return map;
} }
public void removeAssociation(ProjectPersist projectPersist, List<RuntimePersist> runtimesRemove) {
for (RuntimePersist runtimePersist : runtimesRemove) {
List<ContainerRuntimePojoPersist> elts = containerRuntimeRepository.findByServerNameAndContainerId(runtimePersist.getServerName(), projectPersist.getContainerID());
for (ContainerRuntimePojoPersist elt : elts) {
elt.setStatus(ContainerRuntimePojoPersist.STATUS.TODELETE.name());
containerRuntimeRepository.save(elt);
}
}
}
public boolean associate(ProjectPersist projectPersist, List<RuntimePersist> runtimePersists) { public boolean associate(ProjectPersist projectPersist, List<RuntimePersist> runtimePersists) {
@ -189,10 +198,27 @@ public class ProjectPersistService {
newContainer.setServerName(runtimePersist.getServerName()); newContainer.setServerName(runtimePersist.getServerName());
newContainer.setGroupId(projectPersist.getGroupID()); newContainer.setGroupId(projectPersist.getGroupID());
newContainer.setArtifactId(projectPersist.getArtifactID()); newContainer.setArtifactId(projectPersist.getArtifactID());
newContainer.setVersion(projectPersist.getProjectVersion()); newContainer.setVersion(projectPersist.getProjectVersion());
containerRepository.save(newContainer); containerRepository.save(newContainer);
List<ContainerRuntimePojoPersist> elts = containerRuntimeRepository.findByServerNameAndContainerId(runtimePersist.getServerName(), projectPersist.getContainerID());
if (!elts.isEmpty()) {
for (ContainerRuntimePojoPersist elt : elts) {
elt.setStatus(ContainerRuntimePojoPersist.STATUS.TODEPLOY.name());
containerRuntimeRepository.save(elt);
}
} else {
ContainerRuntimePojoPersist runtimePojoPersist = new ContainerRuntimePojoPersist();
runtimePojoPersist.setServerName(runtimePersist.getServerName());
runtimePojoPersist.setHostname(runtimePersist.getHostname());
runtimePojoPersist.setContainerId(projectPersist.getContainerID());
runtimePojoPersist.setStatus(ContainerRuntimePojoPersist.STATUS.TODEPLOY.name());
containerRuntimeRepository.save(runtimePojoPersist);
}
} }
String hostName = runtimePersist.getServerUrl() + "/api/" + projectPersist.getContainerID(); String hostName = runtimePersist.getServerUrl() + "/api/" + projectPersist.getContainerID();
reverseProxyUpdate.getServerNames().add(hostName); reverseProxyUpdate.getServerNames().add(hostName);
} }

View file

@ -49,20 +49,34 @@ public class AssociateProjectKie extends VerticalLayout {
add(associer); add(associer);
associer.addClickListener(buttonClickEvent -> { associer.addClickListener(buttonClickEvent -> {
List<RuntimePersist> lstToSave = new ArrayList<>(); List<RuntimePersist> lstToSave = new ArrayList<>();
List<RuntimePersist> lstToDelete = new ArrayList<>();
for (RuntimePersist runtimePersist : gridRuntime.getSelectedItems()) { for (RuntimePersist runtimePersist : gridRuntime.getSelectedItems()) {
lstToSave.add(runtimePersist); lstToSave.add(runtimePersist);
} }
for (RuntimePersist runtime : gridRuntime.getRuntimeSelected()){
boolean found=false;
for (RuntimePersist runtimePersist : gridRuntime.getSelectedItems()) {
if (runtimePersist.getServerName().equals(runtime.getServerName())
&& runtimePersist.getServerPort().equals(runtime.getServerPort())){
found=true;
}
}
if (!found){
lstToDelete.add(runtime);
}
}
if (!lstToDelete.isEmpty()){
projectPersistService.removeAssociation(projectPersist,lstToDelete);
}
if (!lstToSave.isEmpty()) { if (!lstToSave.isEmpty()) {
boolean tmp = projectPersistService.associate(projectPersist, lstToSave); projectPersistService.associate(projectPersist, lstToSave);
if (tmp) { }
if (!lstToDelete.isEmpty() || !lstToSave.isEmpty()){
deploymentView.setDataProvider(); deploymentView.setDataProvider();
dialog.close(); dialog.close();
} else {
associer.setEnabled(false);
Notification.show("There is already a project of this name on this runtime");
}
} }
}); });

View file

@ -43,6 +43,8 @@ public class GridRuntime extends Grid<RuntimePersist> {
private String strStatus = "State"; private String strStatus = "State";
private List<RuntimePersist> runtimeSelected= new ArrayList<>();
private transient ProjectPersistService projectPersistService; private transient ProjectPersistService projectPersistService;
private transient RuntimeService runtimeService; private transient RuntimeService runtimeService;
@ -146,12 +148,17 @@ public class GridRuntime extends Grid<RuntimePersist> {
return columnPredicate; return columnPredicate;
} }
public List<RuntimePersist> getRuntimeSelected() {
return runtimeSelected;
}
public void setDataProvider() { public void setDataProvider() {
List<RuntimePersist> runtimePersists = runtimeService.getRuntimeRepository().findAll(); List<RuntimePersist> runtimePersists = runtimeService.getRuntimeRepository().findAll();
if (runtimePersists != null) { if (runtimePersists != null) {
List<RuntimePersist> runtimeToShow = new ArrayList<>();
Map<String, String> urlMap = new HashMap<>(); Map<String, String> urlMap = new HashMap<>();
List<RuntimePersist> runtimeToShow= new ArrayList<>();
for (RuntimePersist runtimePersist : runtimePersists) { for (RuntimePersist runtimePersist : runtimePersists) {
if (urlMap.containsKey(runtimePersist.getServerName()) == false) { if (urlMap.containsKey(runtimePersist.getServerName()) == false) {
@ -161,6 +168,7 @@ public class GridRuntime extends Grid<RuntimePersist> {
runtimeToShow.add(runtimePersist1); runtimeToShow.add(runtimePersist1);
if (projectPersist.getServerNames().contains(runtimePersist1.getServerName())) { if (projectPersist.getServerNames().contains(runtimePersist1.getServerName())) {
selectionModel.select(runtimePersist1); selectionModel.select(runtimePersist1);
runtimeSelected.add(runtimePersist);
} }
} else { } else {
runtimeToShow.add(runtimePersist1); runtimeToShow.add(runtimePersist1);

View file

@ -176,7 +176,6 @@ public class KieServiceCommon {
} }
try { try {
for (KieContainerResource kieContainerResource : this.server.getServerState().getResult().getContainers()) { for (KieContainerResource kieContainerResource : this.server.getServerState().getResult().getContainers()) {
this.createContainer(kieContainerResource.getContainerId(), kieContainerResource);
ContainerPojoPersist container = containerRepository.findByServerNameAndContainerId(serverName, kieContainerResource.getContainerId()); ContainerPojoPersist container = containerRepository.findByServerNameAndContainerId(serverName, kieContainerResource.getContainerId());
if (container != null) { if (container != null) {
ContainerRuntimePojoPersist containerRuntimePojoPersist = containerRuntimeRepository.findByServerNameAndContainerIdAndHostname(serverName, kieContainerResource.getContainerId(), hostName); ContainerRuntimePojoPersist containerRuntimePojoPersist = containerRuntimeRepository.findByServerNameAndContainerIdAndHostname(serverName, kieContainerResource.getContainerId(), hostName);
@ -187,10 +186,11 @@ public class KieServiceCommon {
containerRuntimePojoPersist.setHostname(hostName); containerRuntimePojoPersist.setHostname(hostName);
containerRuntimePojoPersist.setStatus(ContainerRuntimePojoPersist.STATUS.UP.name()); containerRuntimePojoPersist.setStatus(ContainerRuntimePojoPersist.STATUS.UP.name());
containerRuntimeRepository.save(containerRuntimePojoPersist); containerRuntimeRepository.save(containerRuntimePojoPersist);
} this.createContainer(kieContainerResource.getContainerId(), kieContainerResource);
this.initCamelBusinessRoute(container); this.initCamelBusinessRoute(container);
} }
} }
}
} catch (Exception e) { } catch (Exception e) {
logger.info("initCamelBusinessRoutes", e); logger.info("initCamelBusinessRoutes", e);
} }
@ -406,8 +406,11 @@ public class KieServiceCommon {
} else if (element.getStatus().equals(ContainerRuntimePojoPersist.STATUS.TODELETE.name())) { } else if (element.getStatus().equals(ContainerRuntimePojoPersist.STATUS.TODELETE.name())) {
this.disposeContainer(element.getContainerId()); this.disposeContainer(element.getContainerId());
this.deleteCamelBusinessRoute(element.getContainerId()); this.deleteCamelBusinessRoute(element.getContainerId());
element.setStatus(ContainerRuntimePojoPersist.STATUS.DOWN.toString()); containerRuntimeRepository.delete(element);
containerRuntimeRepository.save(element); if (containerPojoPersist!= null){
containerRepository.delete(containerPojoPersist);
}
} }
} }