Use Kafka
This commit is contained in:
parent
a79802646c
commit
033628c336
14 changed files with 340 additions and 149 deletions
|
|
@ -3,8 +3,12 @@ package org.chtijbug.drools.console;
|
|||
|
||||
import org.apache.kafka.clients.admin.AdminClientConfig;
|
||||
import org.apache.kafka.clients.admin.NewTopic;
|
||||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
import org.apache.kafka.common.serialization.StringSerializer;
|
||||
import org.chtijbug.drools.KieContainerResponse;
|
||||
import org.chtijbug.drools.KieContainerUpdate;
|
||||
import org.chtijbug.drools.ReverseProxyUpdate;
|
||||
import org.chtijbug.drools.common.KafkaTopicConstants;
|
||||
import org.chtijbug.drools.console.middle.DababaseContentInit;
|
||||
|
|
@ -23,10 +27,9 @@ import org.springframework.context.annotation.PropertySource;
|
|||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
import org.springframework.kafka.annotation.EnableKafka;
|
||||
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
|
||||
import org.springframework.kafka.core.KafkaAdmin;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.kafka.core.ProducerFactory;
|
||||
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
|
||||
import org.springframework.kafka.core.*;
|
||||
import org.springframework.kafka.support.serializer.JsonDeserializer;
|
||||
import org.springframework.kafka.support.serializer.JsonSerializer;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -92,12 +95,49 @@ public class DroolsSpringBootConsoleApplication extends SpringBootServletInitial
|
|||
JsonSerializer.class);
|
||||
return new DefaultKafkaProducerFactory<>(configProps);
|
||||
}
|
||||
@Bean
|
||||
public ProducerFactory<String, KieContainerUpdate> producerKieContainerUpdateFactory() {
|
||||
Map<String, Object> configProps = new HashMap<>();
|
||||
configProps.put(
|
||||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
|
||||
bootstrapAddress);
|
||||
configProps.put(
|
||||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
|
||||
StringSerializer.class);
|
||||
configProps.put(
|
||||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
|
||||
JsonSerializer.class);
|
||||
return new DefaultKafkaProducerFactory<>(configProps);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KafkaTemplate<String, ReverseProxyUpdate> kafkaTemplate() {
|
||||
return new KafkaTemplate<>(producerFactory());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KafkaTemplate<String, KieContainerUpdate> kafkaKieContainerUpdateTemplate() {
|
||||
return new KafkaTemplate<>(producerKieContainerUpdateFactory());
|
||||
}
|
||||
|
||||
|
||||
public ConsumerFactory<String, KieContainerResponse> greetingConsumerFactory() {
|
||||
Map<String, Object> props = new HashMap<>();
|
||||
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
|
||||
props.put(ConsumerConfig.GROUP_ID_CONFIG,"Console");
|
||||
return new DefaultKafkaConsumerFactory<>(props, new StringDeserializer(), new JsonDeserializer<>(KieContainerResponse.class));
|
||||
}
|
||||
@Bean
|
||||
public ConcurrentKafkaListenerContainerFactory<String, KieContainerResponse>
|
||||
ruleKafkaListenerKieContainerUpdateFactory() {
|
||||
|
||||
ConcurrentKafkaListenerContainerFactory<String, KieContainerResponse> factory =
|
||||
new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(greetingConsumerFactory());
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DroolsSpringBootConsoleApplication.class, args);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.chtijbug.drools.console.service;
|
|||
|
||||
import com.vaadin.flow.component.UI;
|
||||
import com.vaadin.flow.server.VaadinSession;
|
||||
import org.chtijbug.drools.KieContainerUpdate;
|
||||
import org.chtijbug.drools.ReverseProxyUpdate;
|
||||
import org.chtijbug.drools.common.KafkaTopicConstants;
|
||||
import org.chtijbug.drools.console.AddLog;
|
||||
|
|
@ -62,6 +63,9 @@ public class ProjectPersistService {
|
|||
@Autowired
|
||||
private KafkaTemplate<String, ReverseProxyUpdate> kafkaTemplateProxyUpdate;
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate<String, KieContainerUpdate> kafkaKieContainerUpdateTemplate;
|
||||
|
||||
public ProjectPersistService() {
|
||||
this.config = AppContext.getApplicationContext().getBean(KieConfigurationData.class);
|
||||
|
||||
|
|
@ -169,6 +173,8 @@ public class ProjectPersistService {
|
|||
return projectPersist;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void waitForJobToBeEnded(String url, String username, String password, ProjectPersist projectPersist, AddLog workOnGoingView, UI ui) {
|
||||
|
||||
UserConnected userConnected = userConnectedService.getUserConnected();
|
||||
|
|
@ -187,8 +193,11 @@ public class ProjectPersistService {
|
|||
|
||||
executeWrite(url, username, password, workOnGoingView, result.getJobId(), ui);
|
||||
|
||||
|
||||
|
||||
for (String serverName : projectPersist.getServerNames()) {
|
||||
|
||||
|
||||
List<ContainerRuntimePojoPersist> existingContainers = containerRuntimeRepository.findByServerNameAndContainerId(serverName, projectPersist.getContainerID());
|
||||
if (!existingContainers.isEmpty()) {
|
||||
for (ContainerRuntimePojoPersist containerRuntimePojoPersist : existingContainers) {
|
||||
|
|
@ -208,7 +217,15 @@ public class ProjectPersistService {
|
|||
|
||||
|
||||
}
|
||||
|
||||
KieContainerUpdate kieContainerUpdate = new KieContainerUpdate();
|
||||
kieContainerUpdate.setMainClass(projectPersist.getMainClass());
|
||||
kieContainerUpdate.setArtifactID(projectPersist.getArtifactID());
|
||||
kieContainerUpdate.setGroupID(projectPersist.getGroupID());
|
||||
kieContainerUpdate.setProjectVersion(projectPersist.getProjectVersion());
|
||||
kieContainerUpdate.setContainerID(projectPersist.getContainerID());
|
||||
kieContainerUpdate.setAction(KieContainerUpdate.STATUS.TODEPLOY);
|
||||
kafkaKieContainerUpdateTemplate.send(serverName,kieContainerUpdate);
|
||||
workOnGoingView.addRow("Deploy Request="+kieContainerUpdate,ui);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package org.chtijbug.drools.console.vaadinComponent.leftMenu.Action;
|
|||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.icon.VaadinIcon;
|
||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||
import org.chtijbug.drools.KieContainerResponse;
|
||||
import org.chtijbug.drools.common.KafkaTopicConstants;
|
||||
import org.chtijbug.drools.console.service.ProjectPersistService;
|
||||
import org.chtijbug.drools.console.service.util.AppContext;
|
||||
import org.chtijbug.drools.console.vaadinComponent.ComponentPerso.DialogPerso;
|
||||
|
|
@ -11,6 +13,7 @@ import org.chtijbug.drools.console.vaadinComponent.componentView.AssociateProjec
|
|||
import org.chtijbug.drools.console.vaadinComponent.componentView.DefineProject;
|
||||
import org.chtijbug.drools.console.view.DeploymentView;
|
||||
import org.chtijbug.drools.proxy.persistence.model.ProjectPersist;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
|
||||
public class DeploymentAction extends VerticalLayout {
|
||||
|
||||
|
|
@ -22,11 +25,11 @@ public class DeploymentAction extends VerticalLayout {
|
|||
private Button deployer;
|
||||
|
||||
private ProjectPersistService projectPersistService;
|
||||
|
||||
private DeploymentView deploymentView;
|
||||
|
||||
public DeploymentAction(SqueletteComposant squeletteComposant,DeploymentView deploymentView){
|
||||
setClassName("leftMenu-global-action");
|
||||
|
||||
this.deploymentView=deploymentView;
|
||||
projectPersistService= AppContext.getApplicationContext().getBean(ProjectPersistService.class);
|
||||
|
||||
definirProject =new Button("Define your project", VaadinIcon.CODE.create());
|
||||
|
|
@ -76,6 +79,14 @@ public class DeploymentAction extends VerticalLayout {
|
|||
});
|
||||
|
||||
}
|
||||
|
||||
@KafkaListener(
|
||||
topics = KafkaTopicConstants.RESPONSE_DEPLOY_TOPIC,groupId = "Console",
|
||||
containerFactory = "ruleKafkaListenerKieContainerUpdateFactory")
|
||||
public void updateKieServerLogInfo(KieContainerResponse kieContainerResponse){
|
||||
deploymentView.addRow("Deploy Response="+kieContainerResponse.toString(),getUI().get());
|
||||
}
|
||||
|
||||
private boolean isActive(Button button){
|
||||
return button.getClassNames().contains("active");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue