Search in sources :

Example 1 with KieServerController

use of org.kie.server.controller.api.KieServerController 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)

Example 2 with KieServerController

use of org.kie.server.controller.api.KieServerController in project droolsjbpm-integration by kiegroup.

the class KieControllerValidationIntegrationTest method testBadRegistered.

@Test
// Added to UnstableOnJenkinsPrBuilder to avoid random failures/timeouts on Jenkins builds
@Category({ UnstableOnJenkinsPrBuilder.class })
public void testBadRegistered() throws Exception {
    final String SERVER_TEMPLATE_ID = "test.mode.bad";
    final String SERVER_NAME = "server-name";
    KieServerEnvironment.setServerId(SERVER_TEMPLATE_ID);
    ServerTemplate serverTemplate = buildServerTemplate(SERVER_TEMPLATE_ID, SERVER_NAME, null, KieServerMode.DEVELOPMENT, Collections.singletonList(Capability.PROCESS.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);
    KieServerController controller = new DefaultRestControllerImpl(registry);
    assertThatThrownBy(() -> controller.connect(kieServerInfo)).isInstanceOf(KieControllerNotConnectedException.class);
    // Check that kie server is not registered.
    ServerInstanceKeyList list = controllerClient.getServerInstances(SERVER_TEMPLATE_ID);
    logger.info("list {}", (Object[]) list.getServerInstanceKeys());
    assertTrue(list.getServerInstanceKeys() == null || list.getServerInstanceKeys().length == 0);
    // clear up
    controller.disconnect(kieServerInfo);
    controllerClient.deleteServerTemplate(SERVER_TEMPLATE_ID);
}
Also used : KieServerController(org.kie.server.controller.api.KieServerController) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ServerTemplateList(org.kie.server.controller.api.model.spec.ServerTemplateList) KieServerInfo(org.kie.server.api.model.KieServerInfo) ServerInstanceKeyList(org.kie.server.controller.api.model.runtime.ServerInstanceKeyList) DefaultRestControllerImpl(org.kie.server.services.impl.controller.DefaultRestControllerImpl) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 3 with KieServerController

use of org.kie.server.controller.api.KieServerController in project droolsjbpm-integration by kiegroup.

the class KieServerImplInitTest method testDefaultStartupStrategyFromController.

@Test(timeout = 10000)
public void testDefaultStartupStrategyFromController() throws Exception {
    final TestContainerManager testContainerManager = new TestContainerManager();
    kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR)) {

        @Override
        protected ContainerManager getContainerManager() {
            return testContainerManager;
        }

        @Override
        public KieServerController getController() {
            return new KieServerController() {

                @Override
                public void disconnect(KieServerInfo serverInfo) {
                }

                @Override
                public KieServerSetup connect(KieServerInfo serverInfo) {
                    KieServerSetup serverSetup = new KieServerSetup();
                    KieContainerResource container = new KieContainerResource("test", new ReleaseId("", "", ""), KieContainerStatus.STARTED);
                    Set<KieContainerResource> containers = new HashSet<>();
                    containers.add(container);
                    serverSetup.setContainers(containers);
                    return serverSetup;
                }
            };
        }
    };
    kieServer.init();
    assertTrue(testContainerManager.isInstalled());
    assertEquals(1, testContainerManager.getInstalledContainers().size());
}
Also used : KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) KieServerController(org.kie.server.controller.api.KieServerController) KieServerSetup(org.kie.server.controller.api.model.KieServerSetup) Set(java.util.Set) HashSet(java.util.HashSet) KieServerInfo(org.kie.server.api.model.KieServerInfo) ReleaseId(org.kie.server.api.model.ReleaseId) KieContainerResource(org.kie.server.api.model.KieContainerResource) Test(org.junit.Test)

Example 4 with KieServerController

use of org.kie.server.controller.api.KieServerController in project droolsjbpm-integration by kiegroup.

the class KieServerImplInitTest method testLOcalContainersStartupStrategyFromController.

@Test(timeout = 10000)
public void testLOcalContainersStartupStrategyFromController() throws Exception {
    System.setProperty(KieServerConstants.KIE_SERVER_STARTUP_STRATEGY, LocalContainersStartupStrategy.class.getSimpleName());
    StartupStrategyProvider.clear();
    final TestContainerManager testContainerManager = new TestContainerManager();
    kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR)) {

        @Override
        protected ContainerManager getContainerManager() {
            return testContainerManager;
        }

        @Override
        public KieServerController getController() {
            return new KieServerController() {

                @Override
                public void disconnect(KieServerInfo serverInfo) {
                }

                @Override
                public KieServerSetup connect(KieServerInfo serverInfo) {
                    KieServerSetup serverSetup = new KieServerSetup();
                    KieContainerResource container = new KieContainerResource("test", new ReleaseId("", "", ""), KieContainerStatus.STARTED);
                    Set<KieContainerResource> containers = new HashSet<>();
                    containers.add(container);
                    serverSetup.setContainers(containers);
                    return serverSetup;
                }
            };
        }
    };
    kieServer.init();
    assertTrue(testContainerManager.isInstalled());
    // even though controller returns containers they should be ignored when LocalContainersStartupStrategy is used
    assertEquals(0, testContainerManager.getInstalledContainers().size());
}
Also used : KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) KieServerController(org.kie.server.controller.api.KieServerController) KieServerSetup(org.kie.server.controller.api.model.KieServerSetup) Set(java.util.Set) HashSet(java.util.HashSet) KieServerInfo(org.kie.server.api.model.KieServerInfo) ReleaseId(org.kie.server.api.model.ReleaseId) KieContainerResource(org.kie.server.api.model.KieContainerResource) Test(org.junit.Test)

Example 5 with KieServerController

use of org.kie.server.controller.api.KieServerController in project droolsjbpm-integration by kiegroup.

the class KieServerImpl method destroy.

public void destroy() {
    eventSupport.fireBeforeServerStopped(this);
    kieServerActive.set(false);
    policyManager.stop();
    // disconnect from controller
    KieServerController kieController = getDefaultController();
    kieController.disconnect(getInfoInternal());
    for (KieServerExtension extension : context.getServerExtensions()) {
        try {
            extension.destroy(this, this.context);
            this.context.unregisterServerExtension(extension);
            logger.info("{} has been successfully unregistered as server extension", extension);
        } catch (Exception e) {
            logger.error("Error when destroying server extension of type {}", extension, e);
        }
    }
    eventSupport.fireAfterServerStopped(this);
}
Also used : KieServerController(org.kie.server.controller.api.KieServerController) KieServerExtension(org.kie.server.services.api.KieServerExtension)

Aggregations

KieServerController (org.kie.server.controller.api.KieServerController)9 KieServerInfo (org.kie.server.api.model.KieServerInfo)8 KieServerSetup (org.kie.server.controller.api.model.KieServerSetup)6 Test (org.junit.Test)5 KieContainerResource (org.kie.server.api.model.KieContainerResource)4 ServerInstanceKeyList (org.kie.server.controller.api.model.runtime.ServerInstanceKeyList)3 ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)3 ServerTemplateList (org.kie.server.controller.api.model.spec.ServerTemplateList)3 KieControllerNotConnectedException (org.kie.server.services.api.KieControllerNotConnectedException)3 KieControllerNotDefinedException (org.kie.server.services.api.KieControllerNotDefinedException)3 ControllerConnectRunnable (org.kie.server.services.impl.controller.ControllerConnectRunnable)3 DefaultRestControllerImpl (org.kie.server.services.impl.controller.DefaultRestControllerImpl)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Category (org.junit.experimental.categories.Category)2 ReleaseId (org.kie.server.api.model.ReleaseId)2 KieServerRegistry (org.kie.server.services.api.KieServerRegistry)2 KieServerRegistryImpl (org.kie.server.services.impl.KieServerRegistryImpl)2 KieServerStateFileRepository (org.kie.server.services.impl.storage.file.KieServerStateFileRepository)2 CountDownLatch (java.util.concurrent.CountDownLatch)1