Search in sources :

Example 1 with KieServerStateFileRepository

use of org.kie.server.services.impl.storage.file.KieServerStateFileRepository in project droolsjbpm-integration by kiegroup.

the class AbstractKieServerImplTest method testPersistScannerState.

@Test
public // https://issues.jboss.org/browse/RHBPMS-4087
void testPersistScannerState() {
    String containerId = "persist-scanner-state";
    createEmptyKjar(containerId);
    // create the container and update the scanner
    KieContainerResource kieContainerResource = new KieContainerResource(containerId, new ReleaseId(releaseId));
    kieServer.createContainer(containerId, kieContainerResource);
    KieScannerResource kieScannerResource = new KieScannerResource(KieScannerStatus.STARTED, 20000L);
    kieServer.updateScanner(containerId, kieScannerResource);
    KieServerStateRepository stateRepository = new KieServerStateFileRepository(REPOSITORY_DIR);
    KieServerState state = stateRepository.load(KIE_SERVER_ID);
    Set<KieContainerResource> containers = state.getContainers();
    Assertions.assertThat(containers).hasSize(1);
    KieContainerResource container = containers.iterator().next();
    Assertions.assertThat(container.getScanner()).isEqualTo(kieScannerResource);
    KieScannerResource updatedKieScannerResource = new KieScannerResource(KieScannerStatus.DISPOSED);
    kieServer.updateScanner(containerId, updatedKieScannerResource);
    // create new state repository instance to avoid caching via 'knownStates'
    // this simulates the server restart (since the status is loaded from filesystem after restart)
    stateRepository = new KieServerStateFileRepository(REPOSITORY_DIR);
    state = stateRepository.load(KIE_SERVER_ID);
    containers = state.getContainers();
    Assertions.assertThat(containers).hasSize(1);
    container = containers.iterator().next();
    Assertions.assertThat(container.getScanner()).isEqualTo(updatedKieScannerResource);
    kieServer.disposeContainer(containerId);
}
Also used : KieServerState(org.kie.server.services.impl.storage.KieServerState) KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) KieScannerResource(org.kie.server.api.model.KieScannerResource) KieServerStateRepository(org.kie.server.services.impl.storage.KieServerStateRepository) Matchers.anyString(org.mockito.Matchers.anyString) ReleaseId(org.kie.server.api.model.ReleaseId) KieContainerResource(org.kie.server.api.model.KieContainerResource) Test(org.junit.Test)

Example 2 with KieServerStateFileRepository

use of org.kie.server.services.impl.storage.file.KieServerStateFileRepository in project droolsjbpm-integration by kiegroup.

the class AbstractKieServerImplTest method testManagementDisabledConfiguredViaCommandService.

@Test
public void testManagementDisabledConfiguredViaCommandService() {
    System.setProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED, "true");
    try {
        kieServer.destroy();
        kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR));
        kieServer.init();
        KieContainerCommandServiceImpl commandService = new KieContainerCommandServiceImpl(kieServer, kieServer.getServerRegistry());
        List<KieServerCommand> commands = new ArrayList<>();
        commands.add(new CreateContainerCommand());
        commands.add(new DisposeContainerCommand());
        commands.add(new UpdateScannerCommand());
        commands.add(new UpdateReleaseIdCommand());
        CommandScript commandScript = new CommandScript(commands);
        ServiceResponsesList responseList = commandService.executeScript(commandScript, MarshallingFormat.JAXB, null);
        assertNotNull(responseList);
        List<ServiceResponse<?>> responses = responseList.getResponses();
        assertEquals(4, responses.size());
        for (ServiceResponse<?> forbidden : responses) {
            assertForbiddenResponse(forbidden);
        }
    } finally {
        System.clearProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED);
    }
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) KieServerCommand(org.kie.server.api.model.KieServerCommand) ArrayList(java.util.ArrayList) CommandScript(org.kie.server.api.commands.CommandScript) DisposeContainerCommand(org.kie.server.api.commands.DisposeContainerCommand) UpdateReleaseIdCommand(org.kie.server.api.commands.UpdateReleaseIdCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServiceResponse(org.kie.server.api.model.KieServiceResponse) UpdateScannerCommand(org.kie.server.api.commands.UpdateScannerCommand) CreateContainerCommand(org.kie.server.api.commands.CreateContainerCommand) Test(org.junit.Test)

Example 3 with KieServerStateFileRepository

use of org.kie.server.services.impl.storage.file.KieServerStateFileRepository 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 KieServerStateFileRepository

use of org.kie.server.services.impl.storage.file.KieServerStateFileRepository 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 5 with KieServerStateFileRepository

use of org.kie.server.services.impl.storage.file.KieServerStateFileRepository 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)

Aggregations

KieServerStateFileRepository (org.kie.server.services.impl.storage.file.KieServerStateFileRepository)15 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)5 KieServerInfo (org.kie.server.api.model.KieServerInfo)4 Message (org.kie.server.api.model.Message)4 ReleaseId (org.kie.server.api.model.ReleaseId)4 KieServerState (org.kie.server.services.impl.storage.KieServerState)4 File (java.io.File)3 List (java.util.List)3 Before (org.junit.Before)3 KieContainerResource (org.kie.server.api.model.KieContainerResource)3 KieServerSetup (org.kie.server.controller.api.model.KieServerSetup)3 KieServerStateRepository (org.kie.server.services.impl.storage.KieServerStateRepository)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 InternalKieContainer (org.drools.core.impl.InternalKieContainer)2 QueryService (org.jbpm.services.api.query.QueryService)2 KieContainerResourceList (org.kie.server.api.model.KieContainerResourceList)2