Search in sources :

Example 1 with DefaultRestControllerImpl

use of org.kie.server.services.impl.controller.DefaultRestControllerImpl 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 DefaultRestControllerImpl

use of org.kie.server.services.impl.controller.DefaultRestControllerImpl 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 DefaultRestControllerImpl

use of org.kie.server.services.impl.controller.DefaultRestControllerImpl in project droolsjbpm-integration by kiegroup.

the class AbstractKieServerImplTest method delayedKieServer.

protected KieServerImpl delayedKieServer(CountDownLatch latch, CountDownLatch startedlatch) {
    KieServerImpl server = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR)) {

        @Override
        public void markAsReady() {
            super.markAsReady();
            startedlatch.countDown();
        }

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

                @Override
                public KieServerSetup connect(KieServerInfo serverInfo) {
                    try {
                        if (latch.await(10, TimeUnit.MILLISECONDS)) {
                            return new KieServerSetup();
                        }
                        throw new KieControllerNotConnectedException("Unable to connect to any controller");
                    } catch (InterruptedException e) {
                        throw new KieControllerNotConnectedException("Unable to connect to any controller");
                    }
                }
            };
        }
    };
    server.init();
    return server;
}
Also used : KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) KieServerSetup(org.kie.server.controller.api.model.KieServerSetup) KieControllerNotConnectedException(org.kie.server.services.api.KieControllerNotConnectedException) KieServerInfo(org.kie.server.api.model.KieServerInfo) DefaultRestControllerImpl(org.kie.server.services.impl.controller.DefaultRestControllerImpl)

Example 4 with DefaultRestControllerImpl

use of org.kie.server.services.impl.controller.DefaultRestControllerImpl in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerControllerImpl method setRegistry.

@Override
public void setRegistry(KieServerRegistry registry) {
    this.context = registry;
    this.restController = new DefaultRestControllerImpl(this.context);
}
Also used : DefaultRestControllerImpl(org.kie.server.services.impl.controller.DefaultRestControllerImpl)

Example 5 with DefaultRestControllerImpl

use of org.kie.server.services.impl.controller.DefaultRestControllerImpl in project droolsjbpm-integration by kiegroup.

the class KieControllerValidationIntegrationTest method testGoodRegistered.

@Test
// Added to UnstableOnJenkinsPrBuilder to avoid random failures/timeouts on Jenkins builds
@Category({ UnstableOnJenkinsPrBuilder.class })
public void testGoodRegistered() throws Exception {
    final String SERVER_TEMPLATE_ID = "test.mode.ok";
    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.DEVELOPMENT);
    kieServerInfo.setCapabilities(Collections.singletonList(KieServerConstants.CAPABILITY_BPM));
    kieServerInfo.setName(SERVER_NAME);
    KieServerRegistry registry = new KieServerRegistryImpl();
    registry.registerStateRepository(dummyKieServerStateRepository);
    KieServerController controller = new DefaultRestControllerImpl(registry);
    KieServerSetup setup = controller.connect(kieServerInfo);
    Assert.assertTrue(setup.hasNoErrors());
    // Check that kie server is registered.
    ServerInstanceKeyList list = controllerClient.getServerInstances(SERVER_TEMPLATE_ID);
    // Sometimes the controller healthcheck deletes server instance sooner than we retrieve it back, in such case register the instance again
    if (list == null || list.getServerInstanceKeys() == null || list.getServerInstanceKeys().length == 0) {
        setup = controller.connect(kieServerInfo);
        Assert.assertTrue(setup.hasNoErrors());
        list = controllerClient.getServerInstances(SERVER_TEMPLATE_ID);
    }
    assertNotNull(list.getServerInstanceKeys());
    assertEquals(1, list.getServerInstanceKeys().length);
    // clear up
    controller.disconnect(kieServerInfo);
    controllerClient.deleteServerTemplate(SERVER_TEMPLATE_ID);
}
Also used : KieServerController(org.kie.server.controller.api.KieServerController) KieServerSetup(org.kie.server.controller.api.model.KieServerSetup) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) 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) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

DefaultRestControllerImpl (org.kie.server.services.impl.controller.DefaultRestControllerImpl)6 KieServerInfo (org.kie.server.api.model.KieServerInfo)4 Test (org.junit.Test)3 KieServerController (org.kie.server.controller.api.KieServerController)3 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 KieServerRegistry (org.kie.server.services.api.KieServerRegistry)3 Category (org.junit.experimental.categories.Category)2 KieServerSetup (org.kie.server.controller.api.model.KieServerSetup)2 KieServerRegistryImpl (org.kie.server.services.impl.KieServerRegistryImpl)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 KieContainerStatus (org.kie.server.api.model.KieContainerStatus)1 KieServerConfig (org.kie.server.api.model.KieServerConfig)1 KieServerConfigItem (org.kie.server.api.model.KieServerConfigItem)1 ServiceResponse (org.kie.server.api.model.ServiceResponse)1