Search in sources :

Example 1 with ServerInstanceKeyList

use of org.kie.server.controller.api.model.runtime.ServerInstanceKeyList in project kie-wb-common by kiegroup.

the class StandaloneControllerMultinodeIT method testAvailableRestEndpoint.

/**
 * This creates a multiinstance node where
 * instance 1 deploys the workbench
 * instance 2 deploys kie-server
 * after checking that the instance 2 manual is instantiated and working
 * it kills the server (only working in linux for now) -> on windows it will stop the app server gracefully
 * instance 2 is killed and the health check detects the problem
 * notifies back to the test that the kie server is disconnected (CountDownLatch in the EventHandler)
 */
@Test
@RunAsClient
@OperateOnDeployment("workbench")
public void testAvailableRestEndpoint() throws Exception {
    String url = new URL("http://localhost:8080/workbench/websocket/controller").toExternalForm();
    URL serverUrl = new URL("http://localhost:8230/kie-server/services/rest/server");
    CountDownLatch serverDown = new CountDownLatch(1);
    CountDownLatch kieServerTemplateUp = new CountDownLatch(1);
    CountDownLatch kieServerInstanceUp = new CountDownLatch(1);
    EventHandler customWSEventHandler = new EventHandler() {

        @Override
        public void onServerInstanceConnected(ServerInstanceConnected serverInstanceConnected) {
            LOGGER.info("onServerInstanceConnected :" + serverInstanceConnected);
        }

        @Override
        public void onServerInstanceDeleted(ServerInstanceDeleted serverInstanceDeleted) {
            LOGGER.info("onServerInstanceDeleted :" + serverInstanceDeleted);
        }

        @Override
        public void onServerInstanceDisconnected(ServerInstanceDisconnected serverInstanceDisconnected) {
            LOGGER.info("onServerInstanceDisconnected :" + serverInstanceDisconnected);
            serverDown.countDown();
        }

        @Override
        public void onServerTemplateDeleted(ServerTemplateDeleted serverTemplateDeleted) {
            LOGGER.info("onServerTemplateDeleted :" + serverTemplateDeleted);
        }

        @Override
        public void onServerTemplateUpdated(ServerTemplateUpdated serverTemplateUpdated) {
            LOGGER.info("onServerTemplateUpdated :" + serverTemplateUpdated);
            kieServerTemplateUp.countDown();
        }

        @Override
        public void onServerInstanceUpdated(ServerInstanceUpdated serverInstanceUpdated) {
            LOGGER.info("onServerInstanceUpdated :" + serverInstanceUpdated);
            kieServerInstanceUp.countDown();
        }

        @Override
        public void onContainerSpecUpdated(ContainerSpecUpdated containerSpecUpdated) {
            LOGGER.info("onContainerSpecUpdated :" + containerSpecUpdated);
        }
    };
    deployer.deploy("kie-server");
    assertTrue(ping(serverUrl));
    // the use of manually deployment is the only way to guarantee that the web context is completely deployed
    // and not causing a race condition when the controller ping the server and severing the connection
    deployer.deploy("workbench");
    try (WebSocketKieServerControllerClient client = (WebSocketKieServerControllerClient) KieServerControllerClientFactory.newWebSocketClient(url, USER, PASSWORD, customWSEventHandler)) {
        kieServerTemplateUp.await(100, TimeUnit.SECONDS);
        kieServerInstanceUp.await(100, TimeUnit.SECONDS);
        ServerInstanceKeyList list = client.getServerInstances(KIE_SERVER_ID);
        assertEquals(1, list.getServerInstanceKeys().length);
        // kill the secondary node
        controller.kill(SECONDARY_NODE);
        serverDown.await(100, TimeUnit.SECONDS);
        assertFalse(ping(serverUrl));
        list = client.getServerInstances(KIE_SERVER_ID);
        assertEquals(0, list.getServerInstanceKeys().length);
    }
}
Also used : ContainerSpecUpdated(org.kie.server.controller.api.model.events.ContainerSpecUpdated) ServerInstanceDeleted(org.kie.server.controller.api.model.events.ServerInstanceDeleted) ServerInstanceUpdated(org.kie.server.controller.api.model.events.ServerInstanceUpdated) ServerTemplateDeleted(org.kie.server.controller.api.model.events.ServerTemplateDeleted) EventHandler(org.kie.server.controller.client.event.EventHandler) ServerInstanceConnected(org.kie.server.controller.api.model.events.ServerInstanceConnected) CountDownLatch(java.util.concurrent.CountDownLatch) URL(java.net.URL) ServerTemplateUpdated(org.kie.server.controller.api.model.events.ServerTemplateUpdated) WebSocketKieServerControllerClient(org.kie.server.controller.client.websocket.WebSocketKieServerControllerClient) ServerInstanceKeyList(org.kie.server.controller.api.model.runtime.ServerInstanceKeyList) ServerInstanceDisconnected(org.kie.server.controller.api.model.events.ServerInstanceDisconnected) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test)

Example 2 with ServerInstanceKeyList

use of org.kie.server.controller.api.model.runtime.ServerInstanceKeyList in project kie-wb-common by kiegroup.

the class EmbeddedControllerIT method testEmbeddedEndpoints.

protected void testEmbeddedEndpoints(final KieServerControllerClient client) {
    try {
        final ServerTemplateList serverTemplateList = client.listServerTemplates();
        assertServerTemplateList(serverTemplateList);
        final ServerInstanceKeyList instances = client.getServerInstances(serverTemplateList.getServerTemplates()[0].getId());
        assertNotNull(instances);
        assertEquals(1, instances.getServerInstanceKeys().length);
        final ServerTemplate serverTemplate = serverTemplateList.getServerTemplates()[0];
        // Deploy container for kie server instance.
        ContainerSpec containerToDeploy = new ContainerSpec(CONTAINER_ID, CONTAINER_NAME, serverTemplate, RELEASE_ID, KieContainerStatus.STARTED, new HashMap());
        client.saveContainerSpec(serverTemplate.getId(), containerToDeploy);
        ContainerList containers = client.getContainers(instances.getServerInstanceKeys()[0]);
        assertNotNull(containers);
        assertEquals(1, containers.getContainers().length);
        client.deleteContainerSpec(serverTemplate.getId(), containerToDeploy.getId());
        containers = client.getContainers(instances.getServerInstanceKeys()[0]);
        assertNotNull(containers);
        assertEquals(0, containers.getContainers().length);
    } finally {
        if (client != null) {
            try {
                client.close();
            } catch (IOException ex) {
                LOGGER.warn("Error trying to close client connection: {}", ex.getMessage(), ex);
            }
        }
    }
}
Also used : ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) HashMap(java.util.HashMap) ServerTemplateList(org.kie.server.controller.api.model.spec.ServerTemplateList) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) ContainerList(org.kie.server.controller.api.model.runtime.ContainerList) ServerInstanceKeyList(org.kie.server.controller.api.model.runtime.ServerInstanceKeyList) IOException(java.io.IOException)

Aggregations

ServerInstanceKeyList (org.kie.server.controller.api.model.runtime.ServerInstanceKeyList)2 IOException (java.io.IOException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)1 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)1 Test (org.junit.Test)1 ContainerSpecUpdated (org.kie.server.controller.api.model.events.ContainerSpecUpdated)1 ServerInstanceConnected (org.kie.server.controller.api.model.events.ServerInstanceConnected)1 ServerInstanceDeleted (org.kie.server.controller.api.model.events.ServerInstanceDeleted)1 ServerInstanceDisconnected (org.kie.server.controller.api.model.events.ServerInstanceDisconnected)1 ServerInstanceUpdated (org.kie.server.controller.api.model.events.ServerInstanceUpdated)1 ServerTemplateDeleted (org.kie.server.controller.api.model.events.ServerTemplateDeleted)1 ServerTemplateUpdated (org.kie.server.controller.api.model.events.ServerTemplateUpdated)1 ContainerList (org.kie.server.controller.api.model.runtime.ContainerList)1 ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)1 ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)1 ServerTemplateList (org.kie.server.controller.api.model.spec.ServerTemplateList)1 EventHandler (org.kie.server.controller.client.event.EventHandler)1