Search in sources :

Example 1 with KieServerRegistryImpl

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

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

the class KieControllerValidationIntegrationTest method init.

@Before
public void init() {
    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 = new KieServerRegistryImpl();
    registry.registerStateRepository(dummyKieServerStateRepository);
}
Also used : KieServerState(org.kie.server.services.impl.storage.KieServerState) KieServerStateRepository(org.kie.server.services.impl.storage.KieServerStateRepository) KieServerConfig(org.kie.server.api.model.KieServerConfig) KieServerConfigItem(org.kie.server.api.model.KieServerConfigItem) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) Before(org.junit.Before)

Example 3 with KieServerRegistryImpl

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

the class KeepLatestContainerOnlyPolicyTest method testDisposeOldContainer.

@Test
public void testDisposeOldContainer() {
    KieServerRegistry kieServerRegistry = new KieServerRegistryImpl();
    KieContainerInstanceImpl kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_ONE, KieContainerStatus.STARTED, kieContainerOne);
    kieServerRegistry.registerContainer(CONTAINER_ONE, kieContainerInstance);
    kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_TWO, KieContainerStatus.STARTED, kieContainerTwo);
    kieServerRegistry.registerContainer(CONTAINER_TWO, kieContainerInstance);
    KeepLatestContainerOnlyPolicy policy = new KeepLatestContainerOnlyPolicy();
    policy.apply(kieServerRegistry, kieServer);
    verify(kieServer).disposeContainer(CONTAINER_ONE);
}
Also used : KieServerRegistry(org.kie.server.services.api.KieServerRegistry) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) Test(org.junit.Test)

Example 4 with KieServerRegistryImpl

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

the class KeepLatestContainerOnlyPolicyTest method testDoNotDisposeNewerCreatedContainer.

@Test
public void testDoNotDisposeNewerCreatedContainer() {
    KieServerRegistry kieServerRegistry = new KieServerRegistryImpl();
    KieContainerInstanceImpl kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_ONE, KieContainerStatus.STARTED, kieContainerOne);
    kieServerRegistry.registerContainer(CONTAINER_ONE, kieContainerInstance);
    kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_TWO, KieContainerStatus.CREATING, kieContainerTwo);
    kieServerRegistry.registerContainer(CONTAINER_TWO, kieContainerInstance);
    KeepLatestContainerOnlyPolicy policy = new KeepLatestContainerOnlyPolicy();
    policy.apply(kieServerRegistry, kieServer);
    verify(kieServer, never()).disposeContainer(anyString());
}
Also used : KieServerRegistry(org.kie.server.services.api.KieServerRegistry) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) Test(org.junit.Test)

Example 5 with KieServerRegistryImpl

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

the class JbpmKieServerExtensionTest method init.

@Before
public void init() {
    KieServerEnvironment.setServerId(UUID.randomUUID().toString());
    context = new KieServerRegistryImpl();
    context.registerStateRepository(new KieServerStateFileRepository(new File("target")));
    kieServices = (KieServicesImpl) KieServices.Factory.get();
    when(kieServerInfo.getMode()).thenAnswer(invocationOnMock -> mode);
    when(kieServer.getInfo()).thenReturn(new ServiceResponse<KieServerInfo>(KieServiceResponse.ResponseType.SUCCESS, "", kieServerInfo));
    extension = spy(new JbpmKieServerExtension() {

        {
            this.deploymentService = JbpmKieServerExtensionTest.this.deploymentService;
            this.runtimeDataService = JbpmKieServerExtensionTest.this.runtimeDataService;
            this.kieServer = JbpmKieServerExtensionTest.this.kieServer;
        }
    });
    when(deploymentService.isDeployed(anyString())).thenAnswer((Answer<Boolean>) invocation -> deployed);
    doAnswer(invocation -> {
        deployed = false;
        return null;
    }).when(deploymentService).undeploy(any(), any());
    doAnswer(invocation -> {
        deployed = false;
        return null;
    }).when(deploymentService).undeploy(any());
    doAnswer((Answer<Void>) invocation -> {
        deploymentUnit = (DeploymentUnit) invocation.getArguments()[0];
        deployed = true;
        return null;
    }).when(deploymentService).deploy(any());
    when(deploymentService.getDeployedUnit(anyString())).thenAnswer((Answer<DeployedUnit>) invocation -> {
        deployedUnit = new DeployedUnitImpl(deploymentUnit);
        runimeManager = mock(RuntimeManager.class);
        engine = mock(RuntimeEngine.class);
        when(runimeManager.getRuntimeEngine(any())).thenReturn(engine);
        session = mock(KieSession.class);
        when(engine.getKieSession()).thenReturn(session);
        deployedUnit.setRuntimeManager(runimeManager);
        return deployedUnit;
    });
    extension.setQueryService(queryService);
    extension.setContext(context);
    when(runtimeDataService.getProcessInstancesByDeploymentId(anyString(), anyList(), any())).thenReturn(activeProcessInstances);
}
Also used : InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) QueryService(org.jbpm.services.api.query.QueryService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) KieServerConstants(org.kie.server.api.KieServerConstants) KieServerMode(org.kie.server.api.model.KieServerMode) DeployedUnitImpl(org.jbpm.kie.services.impl.DeployedUnitImpl) ServiceResponse(org.kie.server.api.model.ServiceResponse) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) KieSession(org.kie.api.runtime.KieSession) Mockito.doReturn(org.mockito.Mockito.doReturn) Message(org.kie.server.api.model.Message) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) UUID(java.util.UUID) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) KieModule(org.kie.api.builder.KieModule) DependencyFilter(org.appformer.maven.support.DependencyFilter) KieServerInfo(org.kie.server.api.model.KieServerInfo) EntityManagerFactory(javax.persistence.EntityManagerFactory) Assert.assertFalse(org.junit.Assert.assertFalse) KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) KieServicesImpl(org.drools.compiler.kie.builder.impl.KieServicesImpl) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Function(java.util.function.Function) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) Captor(org.mockito.Captor) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) ArrayList(java.util.ArrayList) DeploymentService(org.jbpm.services.api.DeploymentService) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) Charset(java.nio.charset.Charset) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) KieContainerStatus(org.kie.server.api.model.KieContainerStatus) Before(org.junit.Before) KieFileSystem(org.kie.api.builder.KieFileSystem) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieServiceResponse(org.kie.server.api.model.KieServiceResponse) Assert.assertNotNull(org.junit.Assert.assertNotNull) KieServerEnvironment(org.kie.server.api.KieServerEnvironment) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) PersistenceUnitExtensionsLoaderMock(org.kie.server.services.jbpm.jpa.PersistenceUnitExtensionsLoaderMock) ReleaseId(org.kie.server.api.model.ReleaseId) Assert(org.junit.Assert) KieServerImpl(org.kie.server.services.impl.KieServerImpl) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KieServerStateFileRepository(org.kie.server.services.impl.storage.file.KieServerStateFileRepository) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) KieServerInfo(org.kie.server.api.model.KieServerInfo) DeployedUnitImpl(org.jbpm.kie.services.impl.DeployedUnitImpl) File(java.io.File) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) Before(org.junit.Before)

Aggregations

KieServerRegistryImpl (org.kie.server.services.impl.KieServerRegistryImpl)8 Test (org.junit.Test)7 KieServerRegistry (org.kie.server.services.api.KieServerRegistry)6 KieServerInfo (org.kie.server.api.model.KieServerInfo)3 KieContainerInstanceImpl (org.kie.server.services.impl.KieContainerInstanceImpl)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 QueryService (org.jbpm.services.api.query.QueryService)2 Before (org.junit.Before)2 KieServerConfig (org.kie.server.api.model.KieServerConfig)2 KieServerConfigItem (org.kie.server.api.model.KieServerConfigItem)2 KieServerState (org.kie.server.services.impl.storage.KieServerState)2 KieServerStateRepository (org.kie.server.services.impl.storage.KieServerStateRepository)2 KieServerStateFileRepository (org.kie.server.services.impl.storage.file.KieServerStateFileRepository)2 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1