use of org.kie.server.api.model.KieServerConfigItem 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.api.model.KieServerConfigItem in project kiegroup-examples by tkobayas.
the class CreateContainerWithInternalFireOnlyWarmup method main.
public static void main(String[] args) {
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, "kieserver", "kieserver1!");
config.setTimeout(1200000);
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
ReleaseId releaseId = new ReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
KieContainerResource resource = new KieContainerResource(CONTAINER_ID, releaseId);
resource.addConfigItem(new KieServerConfigItem("org.example.kie.server.warmup.strategy", "internal-fire-only", String.class.getName()));
KieScannerResource scanner = new KieScannerResource(KieScannerStatus.STARTED, 10000L);
resource.setScanner(scanner);
ServiceResponse<KieContainerResource> response = client.createContainer(CONTAINER_ID, resource);
System.out.println(response);
}
use of org.kie.server.api.model.KieServerConfigItem in project kiegroup-examples by tkobayas.
the class CreateContainerWithInternalFullWarmup method main.
public static void main(String[] args) {
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, "kieserver", "kieserver1!");
config.setTimeout(1200000);
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
ReleaseId releaseId = new ReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
KieContainerResource resource = new KieContainerResource(CONTAINER_ID, releaseId);
resource.addConfigItem(new KieServerConfigItem("org.example.kie.server.warmup.strategy", "internal-full", String.class.getName()));
KieScannerResource scanner = new KieScannerResource(KieScannerStatus.STARTED, 10000L);
resource.setScanner(scanner);
ServiceResponse<KieContainerResource> response = client.createContainer(CONTAINER_ID, resource);
System.out.println(response);
}
use of org.kie.server.api.model.KieServerConfigItem in project droolsjbpm-integration by kiegroup.
the class AuditDataReplicationKieServerTest method reset.
@Before
public void reset() throws Exception {
clearDatasource(datasourceOriginal);
clearDatasource(datasourceReplica);
consumer.reset();
KieContainerResource resource = new KieContainerResource();
resource.setReleaseId(new ReleaseId("org.kie", "spring-boot-kjar-test", "1.0.0-SNAPSHOT"));
resource.addConfigItem(new KieServerConfigItem());
kieServer.createContainer("test", resource);
}
use of org.kie.server.api.model.KieServerConfigItem in project droolsjbpm-integration by kiegroup.
the class KieControllerCrashIntegrationTest method testCrashAfterRegistered.
@Test
public void testCrashAfterRegistered() throws Exception {
final String SERVER_TEMPLATE_ID = "template-id";
final String SERVER_NAME = "server-name";
KieServerEnvironment.setServerId(SERVER_TEMPLATE_ID);
ServerTemplate serverTemplate = new ServerTemplate(SERVER_TEMPLATE_ID, SERVER_NAME);
controllerClient.saveServerTemplate(serverTemplate);
ServerTemplateList instanceList = controllerClient.listServerTemplates();
assertEquals(1, instanceList.getServerTemplates().length);
// Register kie server in controller.
KieServerInfo kieServerInfo = new KieServerInfo(SERVER_TEMPLATE_ID, "1.0.0");
kieServerInfo.setLocation("http://127.0.0.1:20000");
kieServerInfo.setMode(KieServerMode.PRODUCTION);
kieServerInfo.setName(SERVER_NAME);
KieServerRegistry registry = new KieServerRegistryImpl();
KieServerStateRepository dummyKieServerStateRepository = new KieServerStateRepository() {
@Override
public void store(String serverId, KieServerState kieServerState) {
}
@Override
public KieServerState load(String serverId) {
KieServerState kieServerState = new KieServerState();
kieServerState.setControllers(Collections.singleton(TestConfig.getControllerHttpUrl()));
kieServerState.setConfiguration(new KieServerConfig());
if (TestConfig.isLocalServer()) {
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_USER, "", null));
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_PASSWORD, "", null));
} else {
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_USER, TestConfig.getUsername(), null));
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_PASSWORD, TestConfig.getPassword(), null));
}
return kieServerState;
}
};
registry.registerStateRepository(dummyKieServerStateRepository);
KieServerController controller = new DefaultRestControllerImpl(registry);
controller.connect(kieServerInfo);
// Check that kie server is registered.
serverUp.await(5, TimeUnit.SECONDS);
ServerInstanceKeyList list = controllerClient.getServerInstances(instanceList.getServerTemplates()[0].getId());
if (list.getServerInstanceKeys().length == 0) {
// Race condition when health check deleted server instance sooner than we were able to check. Resubmitting server instance again.
serverUp = new CountDownLatch(1);
serverDown = new CountDownLatch(1);
controller.connect(kieServerInfo);
serverUp.await(5, TimeUnit.SECONDS);
list = controllerClient.getServerInstances(instanceList.getServerTemplates()[0].getId());
}
assertNotNull(list.getServerInstanceKeys());
assertEquals(1, list.getServerInstanceKeys().length);
// Check that kie server is deregistered automatically.
serverDown.await(5, TimeUnit.SECONDS);
list = controllerClient.getServerInstances(instanceList.getServerTemplates()[0].getId());
assertNotNull(list.getServerInstanceKeys());
assertEquals(0, list.getServerInstanceKeys().length);
}
Aggregations