use of org.kie.server.services.api.KieContainerInstance in project kiegroup-examples by tkobayas.
the class MyKieServerWarmupEventListener method internalWarmupFireOnly.
private void internalWarmupFireOnly(KieContainerInstance containerInstance) {
LOGGER.info(" internalWarmupFireOnly");
KieContainer kieContainer = containerInstance.getKieContainer();
Collection<String> kieBaseNames = kieContainer.getKieBaseNames();
// warmup all kieSessions
kieBaseNames.stream().flatMap(kieBaseName -> kieContainer.getKieSessionNamesInKieBase(kieBaseName).stream()).forEach(kieSessionName -> {
LOGGER.info("warmup : kieSessionName = {}", kieSessionName);
KieSessionType type = kieContainer.getKieSessionModel(kieSessionName).getType();
if (type == KieSessionType.STATEFUL) {
KieSession kieSession = kieContainer.newKieSession(kieSessionName);
kieSession.fireAllRules();
kieSession.dispose();
} else {
StatelessKieSession statelessKieSession = kieContainer.newStatelessKieSession(kieSessionName);
final List<Command> cmds = new ArrayList<Command>();
cmds.add(CommandFactory.newFireAllRules());
BatchExecutionCommand batchExecutionCommand = CommandFactory.newBatchExecution(cmds);
final ExecutionResults batchResult = (ExecutionResults) statelessKieSession.execute(batchExecutionCommand);
}
});
}
use of org.kie.server.services.api.KieContainerInstance in project kiegroup-examples by tkobayas.
the class MyKieServerWarmupEventListener method afterContainerStarted.
@Override
public void afterContainerStarted(KieServer kieServer, KieContainerInstance containerInstance) {
// To set the KIE_WARMUP_LISTENER_STRATEGY value, see CreateContainerWithWarmupTrue.java in Ex-kie-server-client-7.48.0.Final-redhat-00006
// If you comment-out this part, you can always trigger warm-up.
KieContainerResource resource = containerInstance.getResource();
Optional<KieServerConfigItem> optItem = resource.getConfigItems().stream().filter(item -> item.getName().equals(KIE_WARMUP_LISTENER_STRATEGY)).findFirst();
if (!optItem.isPresent()) {
LOGGER.info("{} is not enabled : ", KIE_WARMUP_LISTENER_STRATEGY);
return;
}
String strategy = optItem.get().getValue();
LOGGER.info("start warmup : " + strategy);
long start = System.currentTimeMillis();
try {
switch(strategy) {
case "internal-fire-only":
internalWarmupFireOnly(containerInstance);
break;
case "internal-full":
// in order to use internalWarmupFull, you need to edit the method to insert expected fact objects
internalWarmupFull(containerInstance);
break;
default:
break;
}
} catch (Exception e) {
LOGGER.warn("warmup failed. You can ignore the error and use the deployed container", e);
}
LOGGER.info("afterContainerStarted : elapsed time = {}ms", System.currentTimeMillis() - start);
}
use of org.kie.server.services.api.KieContainerInstance in project droolsjbpm-integration by kiegroup.
the class AbstractKieServerImplTest method testHealthCheckFailedExtension.
@Test
public void testHealthCheckFailedExtension() {
extensions.add(new KieServerExtension() {
@Override
public List<Message> healthCheck(boolean report) {
List<Message> messages = KieServerExtension.super.healthCheck(report);
messages.add(new Message(Severity.ERROR, "TEST extension is unhealthy"));
return messages;
}
@Override
public void updateContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
}
@Override
public boolean isUpdateContainerAllowed(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
return false;
}
@Override
public boolean isInitialized() {
return true;
}
@Override
public boolean isActive() {
return true;
}
@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
}
@Override
public Integer getStartOrder() {
return 10;
}
@Override
public List<Object> getServices() {
return null;
}
@Override
public String getImplementedCapability() {
return "TEST";
}
@Override
public String getExtensionName() {
return "TEST";
}
@Override
public <T> T getAppComponents(Class<T> serviceType) {
return null;
}
@Override
public List<Object> getAppComponents(SupportedTransports type) {
return null;
}
@Override
public void disposeContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
}
@Override
public void destroy(KieServerImpl kieServer, KieServerRegistry registry) {
}
@Override
public void createContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
}
});
kieServer.init();
List<Message> healthMessages = kieServer.healthCheck(false);
assertEquals(healthMessages.size(), 1);
Message failedContainer = healthMessages.get(0);
assertEquals(Severity.ERROR, failedContainer.getSeverity());
assertEquals(1, failedContainer.getMessages().size());
assertEquals("TEST extension is unhealthy", failedContainer.getMessages().iterator().next());
}
use of org.kie.server.services.api.KieContainerInstance in project droolsjbpm-integration by kiegroup.
the class KieServerImpl method healthCheck.
public List<Message> healthCheck(boolean report) throws IllegalStateException {
List<Message> healthMessages = new ArrayList<>();
long start = System.currentTimeMillis();
if (!isKieServerReady()) {
healthMessages.add(new Message(Severity.ERROR, String.format("KIE Server '%s' is not ready to serve requests", KieServerEnvironment.getServerId())));
}
if (report) {
List<String> mainInfo = new ArrayList<>();
mainInfo.add(String.format("KIE Server '%s' is ready to serve requests %s", KieServerEnvironment.getServerId(), isKieServerReady()));
mainInfo.add("Server is up for " + calculateUptime());
Message header = new Message(Severity.INFO, mainInfo);
healthMessages.add(header);
}
// first check of KIE Server's containers if any of them is in failed state
for (KieContainerInstance container : getContainers()) {
// RHPAM-1793 - relax health check in case of management is enabled.
if (container.getStatus().equals(KieContainerStatus.FAILED) && !managementDisabled) {
healthMessages.add(new Message(Severity.WARN, String.format("KIE Container '%s' is in FAILED state", container.getContainerId())));
} else if (container.getStatus().equals(KieContainerStatus.FAILED) && managementDisabled) {
healthMessages.add(new Message(Severity.ERROR, String.format("KIE Container '%s' is in FAILED state", container.getContainerId())));
}
}
// next check all extensions for their health
for (KieServerExtension extension : getServerExtensions()) {
List<Message> extensionMessages = extension.healthCheck(report);
healthMessages.addAll(extensionMessages);
}
if (report) {
Message footer = new Message(Severity.INFO, "Health check done in " + (System.currentTimeMillis() - start) + " ms");
healthMessages.add(footer);
}
return healthMessages;
}
use of org.kie.server.services.api.KieContainerInstance in project droolsjbpm-integration by kiegroup.
the class MarshallerHelper method unmarshal.
public <T> T unmarshal(String containerId, String data, String marshallingFormat, Class<T> unmarshalType, ContainerLocator locator) {
if (data == null || data.isEmpty()) {
return null;
}
MarshallingFormat format = getFormat(marshallingFormat);
KieContainerInstance containerInstance = registry.getContainer(containerId, locator);
if (containerInstance == null || format == null) {
throw new IllegalArgumentException("No container found for id " + containerId + " or unknown marshalling format " + marshallingFormat);
}
Marshaller marshaller = containerInstance.getMarshaller(format);
if (marshaller == null) {
throw new IllegalArgumentException("No marshaller found for format " + format);
}
Object instance = marshaller.unmarshall(data, unmarshalType, MarshallingFormat.buildParameters(marshallingFormat));
if (instance instanceof Wrapped) {
return (T) ((Wrapped) instance).unwrap();
}
return (T) instance;
}
Aggregations