Search in sources :

Example 1 with KieServerConfigItem

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);
}
Also used : Command(org.kie.api.command.Command) Logger(org.slf4j.Logger) Collection(java.util.Collection) ExecutionResults(org.kie.api.runtime.ExecutionResults) LoggerFactory(org.slf4j.LoggerFactory) KieContainer(org.kie.api.runtime.KieContainer) KieContainerResource(org.kie.server.api.model.KieContainerResource) CommandFactory(org.kie.internal.command.CommandFactory) Constructor(java.lang.reflect.Constructor) KieContainerInstance(org.kie.server.services.api.KieContainerInstance) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) KieSessionType(org.kie.api.builder.model.KieSessionModel.KieSessionType) KieServerConfigItem(org.kie.server.api.model.KieServerConfigItem) List(java.util.List) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) Optional(java.util.Optional) KieServer(org.kie.server.services.api.KieServer) KieSession(org.kie.api.runtime.KieSession) KieServerEventListener(org.kie.server.services.api.KieServerEventListener) KieServerConfigItem(org.kie.server.api.model.KieServerConfigItem) KieContainerResource(org.kie.server.api.model.KieContainerResource) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with KieServerConfigItem

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);
}
Also used : KieScannerResource(org.kie.server.api.model.KieScannerResource) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient) ReleaseId(org.kie.server.api.model.ReleaseId) KieServerConfigItem(org.kie.server.api.model.KieServerConfigItem) KieContainerResource(org.kie.server.api.model.KieContainerResource)

Example 3 with KieServerConfigItem

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);
}
Also used : KieScannerResource(org.kie.server.api.model.KieScannerResource) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient) ReleaseId(org.kie.server.api.model.ReleaseId) KieServerConfigItem(org.kie.server.api.model.KieServerConfigItem) KieContainerResource(org.kie.server.api.model.KieContainerResource)

Example 4 with KieServerConfigItem

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);
}
Also used : ReleaseId(org.kie.server.api.model.ReleaseId) KieServerConfigItem(org.kie.server.api.model.KieServerConfigItem) KieContainerResource(org.kie.server.api.model.KieContainerResource) Before(org.junit.Before)

Example 5 with KieServerConfigItem

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);
}
Also used : KieServerController(org.kie.server.controller.api.KieServerController) KieServerStateRepository(org.kie.server.services.impl.storage.KieServerStateRepository) ServerTemplateList(org.kie.server.controller.api.model.spec.ServerTemplateList) KieServerInfo(org.kie.server.api.model.KieServerInfo) KieServerConfig(org.kie.server.api.model.KieServerConfig) KieServerConfigItem(org.kie.server.api.model.KieServerConfigItem) CountDownLatch(java.util.concurrent.CountDownLatch) KieServerState(org.kie.server.services.impl.storage.KieServerState) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) ServerInstanceKeyList(org.kie.server.controller.api.model.runtime.ServerInstanceKeyList) DefaultRestControllerImpl(org.kie.server.services.impl.controller.DefaultRestControllerImpl) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) Test(org.junit.Test)

Aggregations

KieServerConfigItem (org.kie.server.api.model.KieServerConfigItem)33 KieContainerResource (org.kie.server.api.model.KieContainerResource)17 Test (org.junit.Test)9 KieScannerResource (org.kie.server.api.model.KieScannerResource)9 KieServerConfig (org.kie.server.api.model.KieServerConfig)9 ReleaseId (org.kie.server.api.model.ReleaseId)7 KieServicesConfiguration (org.kie.server.client.KieServicesConfiguration)6 ProcessConfig (org.kie.server.controller.api.model.spec.ProcessConfig)6 KieServicesClient (org.kie.server.client.KieServicesClient)5 ContainerConfig (org.kie.server.controller.api.model.spec.ContainerConfig)5 RuleConfig (org.kie.server.controller.api.model.spec.RuleConfig)5 KieServerState (org.kie.server.services.impl.storage.KieServerState)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Optional (java.util.Optional)3 Before (org.junit.Before)3 ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)3 Constructor (java.lang.reflect.Constructor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2