Search in sources :

Example 1 with KieServerRegistry

use of org.kie.server.services.api.KieServerRegistry in project droolsjbpm-integration by kiegroup.

the class CaseRestApplicationComponentsService method getAppComponents.

@Override
public Collection<Object> getAppComponents(String extension, SupportedTransports type, Object... services) {
    // skip calls from other than owning extension
    if (!OWNER_EXTENSION.equals(extension)) {
        return Collections.emptyList();
    }
    CaseManagementServiceBase caseManagementServiceBase = null;
    CaseManagementRuntimeDataServiceBase caseManagementRuntimeDataServiceBase = null;
    CaseAdminServiceBase caseAdminServiceBase = null;
    KieServerRegistry context = null;
    for (Object object : services) {
        // in case given service is null (meaning was not configured) continue with next one
        if (object == null) {
            continue;
        }
        if (CaseManagementServiceBase.class.isAssignableFrom(object.getClass())) {
            caseManagementServiceBase = (CaseManagementServiceBase) object;
            continue;
        } else if (CaseManagementRuntimeDataServiceBase.class.isAssignableFrom(object.getClass())) {
            caseManagementRuntimeDataServiceBase = (CaseManagementRuntimeDataServiceBase) object;
            continue;
        } else if (CaseAdminServiceBase.class.isAssignableFrom(object.getClass())) {
            caseAdminServiceBase = (CaseAdminServiceBase) object;
            continue;
        } else if (KieServerRegistry.class.isAssignableFrom(object.getClass())) {
            context = (KieServerRegistry) object;
            continue;
        }
    }
    List<Object> components = new ArrayList<Object>();
    components.add(new CaseResource(caseManagementServiceBase, caseManagementRuntimeDataServiceBase, context));
    components.add(new CaseQueryResource(caseManagementRuntimeDataServiceBase, context));
    components.add(new CaseAdminResource(caseManagementRuntimeDataServiceBase, caseAdminServiceBase, context));
    return components;
}
Also used : KieServerRegistry(org.kie.server.services.api.KieServerRegistry) CaseManagementRuntimeDataServiceBase(org.kie.server.services.casemgmt.CaseManagementRuntimeDataServiceBase) CaseManagementServiceBase(org.kie.server.services.casemgmt.CaseManagementServiceBase) ArrayList(java.util.ArrayList) CaseAdminServiceBase(org.kie.server.services.casemgmt.CaseAdminServiceBase)

Example 2 with KieServerRegistry

use of org.kie.server.services.api.KieServerRegistry in project droolsjbpm-integration by kiegroup.

the class JbpmUIRestApplicationComponentsService method getAppComponents.

@Override
public Collection<Object> getAppComponents(String extension, SupportedTransports type, Object... services) {
    // skip calls from other than owning extension
    if (!OWNER_EXTENSION.equals(extension)) {
        return Collections.emptyList();
    }
    FormServiceBase formServiceBase = null;
    ImageServiceBase imageServiceBase = null;
    FormRendererBase formRendererBase = null;
    KieServerRegistry context = null;
    for (Object object : services) {
        // in case given service is null (meaning was not configured) continue with next one
        if (object == null) {
            continue;
        }
        if (FormServiceBase.class.isAssignableFrom(object.getClass())) {
            formServiceBase = (FormServiceBase) object;
            continue;
        } else if (ImageServiceBase.class.isAssignableFrom(object.getClass())) {
            imageServiceBase = (ImageServiceBase) object;
            continue;
        } else if (FormRendererBase.class.isAssignableFrom(object.getClass())) {
            formRendererBase = (FormRendererBase) object;
            continue;
        } else if (KieServerRegistry.class.isAssignableFrom(object.getClass())) {
            context = (KieServerRegistry) object;
            continue;
        }
    }
    List<Object> components = new ArrayList<Object>(2);
    components.add(new FormResource(formServiceBase, formRendererBase, context));
    components.add(new ImageResource(imageServiceBase, context));
    components.add(new StaticFilesResource(formRendererBase));
    return components;
}
Also used : FormRendererBase(org.kie.server.services.jbpm.ui.FormRendererBase) FormServiceBase(org.kie.server.services.jbpm.ui.FormServiceBase) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) ImageServiceBase(org.kie.server.services.jbpm.ui.ImageServiceBase) ArrayList(java.util.ArrayList)

Example 3 with KieServerRegistry

use of org.kie.server.services.api.KieServerRegistry in project droolsjbpm-integration by kiegroup.

the class DMNRestApplicationComponentsService method getAppComponents.

@Override
public Collection<Object> getAppComponents(String extension, SupportedTransports type, Object... services) {
    // skip calls from other than owning extension
    if (!OWNER_EXTENSION.equals(extension)) {
        return Collections.emptyList();
    }
    ModelEvaluatorServiceBase modelEvaluatorService = null;
    KieServerRegistry context = null;
    for (Object object : services) {
        // in case given service is null (meaning was not configured) continue with next one
        if (object == null) {
            continue;
        }
        if (ModelEvaluatorServiceBase.class.isAssignableFrom(object.getClass())) {
            modelEvaluatorService = (ModelEvaluatorServiceBase) object;
            continue;
        } else if (KieServerRegistry.class.isAssignableFrom(object.getClass())) {
            context = (KieServerRegistry) object;
            continue;
        }
    }
    List<Object> components = new ArrayList<Object>(1);
    components.add(new ModelEvaluatorResource(modelEvaluatorService));
    return components;
}
Also used : KieServerRegistry(org.kie.server.services.api.KieServerRegistry) ArrayList(java.util.ArrayList) ModelEvaluatorServiceBase(org.kie.server.services.dmn.ModelEvaluatorServiceBase)

Example 4 with KieServerRegistry

use of org.kie.server.services.api.KieServerRegistry 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 5 with KieServerRegistry

use of org.kie.server.services.api.KieServerRegistry in project droolsjbpm-integration by kiegroup.

the class AbstractKieServerImplTest method testHealthCheckFailedExtension.

@Test
public void testHealthCheckFailedExtension() {
    extensions.add(new KieServerExtension() {

        @Override
        public List<Message> healthCheck(boolean report) {
            List<Message> messages = KieServerExtension.super.healthCheck(report);
            messages.add(new Message(Severity.ERROR, "TEST extension is unhealthy"));
            return messages;
        }

        @Override
        public void updateContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
        }

        @Override
        public boolean isUpdateContainerAllowed(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
            return false;
        }

        @Override
        public boolean isInitialized() {
            return true;
        }

        @Override
        public boolean isActive() {
            return true;
        }

        @Override
        public void init(KieServerImpl kieServer, KieServerRegistry registry) {
        }

        @Override
        public Integer getStartOrder() {
            return 10;
        }

        @Override
        public List<Object> getServices() {
            return null;
        }

        @Override
        public String getImplementedCapability() {
            return "TEST";
        }

        @Override
        public String getExtensionName() {
            return "TEST";
        }

        @Override
        public <T> T getAppComponents(Class<T> serviceType) {
            return null;
        }

        @Override
        public List<Object> getAppComponents(SupportedTransports type) {
            return null;
        }

        @Override
        public void disposeContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
        }

        @Override
        public void destroy(KieServerImpl kieServer, KieServerRegistry registry) {
        }

        @Override
        public void createContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
        }
    });
    kieServer.init();
    List<Message> healthMessages = kieServer.healthCheck(false);
    assertEquals(healthMessages.size(), 1);
    Message failedContainer = healthMessages.get(0);
    assertEquals(Severity.ERROR, failedContainer.getSeverity());
    assertEquals(1, failedContainer.getMessages().size());
    assertEquals("TEST extension is unhealthy", failedContainer.getMessages().iterator().next());
}
Also used : Message(org.kie.server.api.model.Message) KieServerExtension(org.kie.server.services.api.KieServerExtension) Matchers.anyString(org.mockito.Matchers.anyString) KieContainerInstance(org.kie.server.services.api.KieContainerInstance) SupportedTransports(org.kie.server.services.api.SupportedTransports) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) KieContainerResourceList(org.kie.server.api.model.KieContainerResourceList) List(java.util.List) ArrayList(java.util.ArrayList) ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) Test(org.junit.Test)

Aggregations

KieServerRegistry (org.kie.server.services.api.KieServerRegistry)28 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)13 HashSet (java.util.HashSet)5 DefinitionService (org.jbpm.services.api.DefinitionService)4 RuntimeDataService (org.jbpm.services.api.RuntimeDataService)4 UserTaskService (org.jbpm.services.api.UserTaskService)4 ProcessInstanceQueryFilterSpecBuilder (org.kie.server.api.util.ProcessInstanceQueryFilterSpecBuilder)4 QueryFilterSpecBuilder (org.kie.server.api.util.QueryFilterSpecBuilder)4 TaskQueryFilterSpecBuilder (org.kie.server.api.util.TaskQueryFilterSpecBuilder)4 KieServerRegistryImpl (org.kie.server.services.impl.KieServerRegistryImpl)4 HashMap (java.util.HashMap)3 List (java.util.List)3 FormManagerService (org.jbpm.kie.services.impl.FormManagerService)3 ProcessService (org.jbpm.services.api.ProcessService)3 QueryService (org.jbpm.services.api.query.QueryService)3 Map (java.util.Map)2 Set (java.util.Set)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2