Search in sources :

Example 21 with KieServerExtension

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

the class KafkaExtensionTest method assertExtensionInitialized.

private void assertExtensionInitialized(Map<String, KieServerExtension> extensions, String extensionName) {
    KieServerExtension extension = extensions.get(extensionName);
    assertNotNull("Extension " + extensionName + " was not found in current server", extension);
    assertTrue("Extension " + extensionName + " is expected to be active", extension.isActive());
    assertTrue("Extension " + extensionName + " is expected to be initialized", extension.isInitialized());
}
Also used : KieServerExtension(org.kie.server.services.api.KieServerExtension)

Example 22 with KieServerExtension

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

the class CommandScriptMessageHandler method onMessage.

@Override
public String onMessage(String message) {
    CommandScript script = deserialize(message, CommandScript.class);
    String capability = TARGET_CAPABILITY;
    boolean hasBPMCommand = script.getCommands().stream().anyMatch(cmd -> cmd instanceof DescriptorCommand);
    if (hasBPMCommand) {
        capability = KieServerConstants.CAPABILITY_BPM;
    }
    KieContainerCommandService<?> executor = null;
    for (KieServerExtension extension : context.getServerExtensions()) {
        KieContainerCommandService<?> tmp = extension.getAppComponents(KieContainerCommandService.class);
        if (tmp != null && extension.getImplementedCapability().equalsIgnoreCase(capability)) {
            executor = tmp;
            logger.debug("Extension {} returned command executor {} with capability {}", extension, executor, extension.getImplementedCapability());
            break;
        }
    }
    if (executor == null) {
        throw new IllegalStateException("No executor found for script execution");
    }
    // 4. process request
    ServiceResponsesList response = executor.executeScript(script, MarshallingFormat.JSON, null);
    String reply = serialize(response);
    return reply;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) KieServerExtension(org.kie.server.services.api.KieServerExtension) CommandScript(org.kie.server.api.commands.CommandScript)

Example 23 with KieServerExtension

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

the class KafkaServerExtensionProducerTest method setup.

@Before
public void setup() {
    System.setProperty(SIGNAL_MAPPING_PROPERTY, Mapping.AUTO.toString());
    itemsFactory = new SimpleRegisterableItemsFactory();
    itemsFactory.addProcessListener(new KafkaServerProcessListener());
    mockProducer = new MockProducer<>(false, new StringSerializer(), new ByteArraySerializer());
    extension = new MockKafkaServerExtension(mockProducer);
    server = mock(KieServerImpl.class);
    registry = mock(KieServerRegistry.class);
    KieServerExtension serverExtension = mock(KieServerExtension.class);
    when(registry.getServerExtension(Mockito.anyString())).thenReturn(serverExtension);
    ListenerSupport deployService = mock(ListenerSupport.class, withSettings().extraInterfaces(DeploymentService.class));
    processService = mock(ProcessService.class);
    when(serverExtension.getServices()).thenReturn(Arrays.asList(deployService, processService));
    extension.init(server, registry);
    extension.serverStarted();
    pInstance = mock(ProcessInstance.class);
    runtime = mock(KieRuntime.class);
    nInstance = mock(NodeInstance.class);
    node = mock(Node.class);
    when(nInstance.getNode()).thenReturn(node);
    when(node.getMetaData()).thenReturn(Collections.emptyMap());
}
Also used : KieServerExtension(org.kie.server.services.api.KieServerExtension) KieRuntime(org.kie.api.runtime.KieRuntime) Node(org.jbpm.workflow.core.Node) ListenerSupport(org.jbpm.services.api.ListenerSupport) ByteArraySerializer(org.apache.kafka.common.serialization.ByteArraySerializer) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) DeploymentService(org.jbpm.services.api.DeploymentService) SimpleRegisterableItemsFactory(org.jbpm.runtime.manager.impl.SimpleRegisterableItemsFactory) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KieServerImpl(org.kie.server.services.impl.KieServerImpl) ProcessService(org.jbpm.services.api.ProcessService) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) NodeInstance(org.kie.api.runtime.process.NodeInstance) Before(org.junit.Before)

Example 24 with KieServerExtension

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

the class PrometheusKieServerExtension method init.

@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
    this.context = registry;
    customMetrics = new PrometheusCustomMetricsSupport(this);
    registerDefaultDescriptor();
    // Prometheus Monitoring
    KieServerExtension jBPMExtension = context.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
    if (jBPMExtension != null) {
        final KModuleDeploymentService deploymentService = jBPMExtension.getAppComponents(KModuleDeploymentService.class);
        if (deploymentService != null) {
            List<DeploymentEventListener> metrics = customMetrics.getDeploymentEventListener();
            if (!metrics.isEmpty()) {
                List<DeploymentEventListener> listeners = new ArrayList<>(metrics);
                listeners.forEach(l -> deploymentService.addListener(l));
            }
            deploymentService.addListener(new PrometheusDeploymentEventListener());
        }
        final ExecutorServiceImpl executorService = jBPMExtension.getAppComponents(ExecutorServiceImpl.class);
        if (executorService != null) {
            List<AsynchronousJobListener> metrics = customMetrics.getAsynchronousJobListener();
            if (!metrics.isEmpty()) {
                List<AsynchronousJobListener> listeners = new ArrayList<>(metrics);
                listeners.forEach(l -> executorService.addAsyncJobListener(l));
            }
            executorService.addAsyncJobListener(new PrometheusJobListener());
        }
        final QueryServiceImpl queryService = jBPMExtension.getAppComponents(QueryServiceImpl.class);
        if (queryService != null) {
            final DataSetDefRegistry dataSetDefRegistry = queryService.getDataSetDefRegistry();
            final PrometheusDataSetListener listener = new PrometheusDataSetListener(dataSetDefRegistry);
            listener.init();
            dataSetDefRegistry.addListener(listener);
        }
        final RuntimeDataService dataService = jBPMExtension.getAppComponents(RuntimeDataService.class);
        if (dataService != null) {
            final Collection<ProcessInstanceDesc> processInstances = dataService.getProcessInstances(asList(ProcessInstance.STATE_ACTIVE), null, new QueryContext(0, Integer.MAX_VALUE));
            processInstances.forEach(pi -> recordRunningProcessInstance(pi.getDeploymentId(), pi.getProcessId()));
        }
    }
    KieServerExtension caseExtension = context.getServerExtension(CaseKieServerExtension.EXTENSION_NAME);
    if (caseExtension != null) {
        final CaseManagementRuntimeDataServiceBase caseRuntime = caseExtension.getAppComponents(CaseManagementRuntimeDataServiceBase.class);
        if (caseRuntime != null) {
            final CaseInstanceList caseInstances = caseRuntime.getCaseInstances(asList(CaseStatus.OPEN.getName()), 0, Integer.MAX_VALUE, null, false);
            for (CaseInstance instance : caseInstances.getCaseInstances()) {
                recordRunningCaseInstance(instance.getCaseDefinitionId());
            }
        }
    }
    initialized = true;
    if (!customMetrics.hasCustomMetrics()) {
        LOGGER.info("{} started", toString());
    } else {
        LOGGER.info("{} started with custom Prometheus metrics provider(s): {}", toString(), customMetrics.customMetricsProviders());
    }
}
Also used : RuntimeDataService(org.jbpm.services.api.RuntimeDataService) AsynchronousJobListener(org.jbpm.executor.AsynchronousJobListener) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) JbpmKieServerExtension(org.kie.server.services.jbpm.JbpmKieServerExtension) KieServerExtension(org.kie.server.services.api.KieServerExtension) CaseKieServerExtension(org.kie.server.services.casemgmt.CaseKieServerExtension) CaseManagementRuntimeDataServiceBase(org.kie.server.services.casemgmt.CaseManagementRuntimeDataServiceBase) ArrayList(java.util.ArrayList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) DataSetDefRegistry(org.dashbuilder.dataset.def.DataSetDefRegistry) CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) CaseInstance(org.kie.server.api.model.cases.CaseInstance) PrometheusCaseEventListener.recordRunningCaseInstance(org.kie.server.services.prometheus.PrometheusCaseEventListener.recordRunningCaseInstance) KModuleDeploymentService(org.jbpm.kie.services.impl.KModuleDeploymentService) DeploymentEventListener(org.jbpm.services.api.DeploymentEventListener) QueryServiceImpl(org.jbpm.kie.services.impl.query.QueryServiceImpl)

Example 25 with KieServerExtension

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

the class JBPMUIKieServerExtension method init.

@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
    this.registry = registry;
    KieServerExtension jbpmExtension = registry.getServerExtension("jBPM");
    if (jbpmExtension == null) {
        initialized = false;
        logger.warn("jBPM extension not found, jBPM UI cannot work without jBPM extension, disabling itself");
        return;
    }
    List<Object> jbpmServices = jbpmExtension.getServices();
    RuntimeDataService runtimeDataService = null;
    DefinitionService definitionService = null;
    UserTaskService userTaskService = null;
    FormManagerService formManagerService = null;
    CaseRuntimeDataService caseRuntimeDataService = null;
    for (Object object : jbpmServices) {
        // in case given service is null (meaning was not configured) continue with next one
        if (object == null) {
            continue;
        }
        if (RuntimeDataService.class.isAssignableFrom(object.getClass())) {
            runtimeDataService = (RuntimeDataService) object;
            continue;
        } else if (DefinitionService.class.isAssignableFrom(object.getClass())) {
            definitionService = (DefinitionService) object;
            continue;
        } else if (UserTaskService.class.isAssignableFrom(object.getClass())) {
            userTaskService = (UserTaskService) object;
            continue;
        } else if (FormManagerService.class.isAssignableFrom(object.getClass())) {
            formManagerService = (FormManagerService) object;
            continue;
        } else if (DeploymentService.class.isAssignableFrom(object.getClass())) {
            deploymentService = (DeploymentService) object;
            continue;
        }
    }
    KieServerExtension caseExtension = registry.getServerExtension("Case-Mgmt");
    if (caseExtension != null) {
        List<Object> caseMgmtServices = caseExtension.getServices();
        for (Object object : caseMgmtServices) {
            // in case given service is null (meaning was not configured) continue with next one
            if (object == null) {
                continue;
            }
            if (CaseRuntimeDataService.class.isAssignableFrom(object.getClass())) {
                caseRuntimeDataService = (CaseRuntimeDataService) object;
                continue;
            }
        }
    } else {
        logger.warn("Case-Mgmt extension not found, jBPM UI capabilities will be limited");
    }
    formServiceBase = new FormServiceBase(definitionService, runtimeDataService, userTaskService, formManagerService, registry);
    imageServiceBase = new ImageServiceBase(runtimeDataService, imageReferences, registry);
    formRendererBase = new FormRendererBase(definitionService, userTaskService, formManagerService, caseRuntimeDataService, registry);
    services.add(formServiceBase);
    services.add(imageServiceBase);
    services.add(formRendererBase);
    this.kieContainerCommandService = new JBPMUIKieContainerCommandServiceImpl(null, formServiceBase, imageServiceBase, formRendererBase);
    initialized = true;
}
Also used : CaseRuntimeDataService(org.jbpm.casemgmt.api.CaseRuntimeDataService) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) DefinitionService(org.jbpm.services.api.DefinitionService) CaseRuntimeDataService(org.jbpm.casemgmt.api.CaseRuntimeDataService) KieServerExtension(org.kie.server.services.api.KieServerExtension) UserTaskService(org.jbpm.services.api.UserTaskService) FormManagerService(org.jbpm.kie.services.impl.FormManagerService)

Aggregations

KieServerExtension (org.kie.server.services.api.KieServerExtension)43 Message (org.kie.server.api.model.Message)10 ArrayList (java.util.ArrayList)9 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)9 ReleaseId (org.kie.server.api.model.ReleaseId)8 Test (org.junit.Test)6 KieModuleMetaData (org.kie.scanner.KieModuleMetaData)6 KieContainerResource (org.kie.server.api.model.KieContainerResource)6 ServiceResponse (org.kie.server.api.model.ServiceResponse)6 Matchers.anyString (org.mockito.Matchers.anyString)6 JbpmKieServerExtension (org.kie.server.services.jbpm.JbpmKieServerExtension)5 DeploymentService (org.jbpm.services.api.DeploymentService)4 ProcessService (org.jbpm.services.api.ProcessService)4 KieContainerInstance (org.kie.server.services.api.KieContainerInstance)4 KieServerRegistry (org.kie.server.services.api.KieServerRegistry)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)3 RuntimeDataService (org.jbpm.services.api.RuntimeDataService)3