Search in sources :

Example 26 with KieServerExtension

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

the class JBPMClusterKieServerExtension method configureServices.

private void configureServices() {
    KieServerExtension jbpmExtension = registry.getServerExtension("jBPM");
    List<Object> jbpmServices = jbpmExtension.getServices();
    for (Object object : jbpmServices) {
        // in case given service is null (meaning was not configured) continue with next one
        if (object == null) {
            continue;
        }
        if (ExecutorService.class.isAssignableFrom(object.getClass())) {
            this.jbpmExecutorService = (ExecutorService) object;
        }
    }
    clusterService = ServiceRegistry.getService(ClusterAwareService.class);
}
Also used : KieServerExtension(org.kie.server.services.api.KieServerExtension) ClusterAwareService(org.kie.api.cluster.ClusterAwareService)

Example 27 with KieServerExtension

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

the class KieServerImplProductionModeTest method testUpdateContainerWithGAVConflict.

@Test
public void testUpdateContainerWithGAVConflict() {
    KieServerExtension extension = mock(KieServerExtension.class);
    extensions.add(extension);
    String containerId = "container-to-update";
    ReleaseId updateReleaseId = new ReleaseId(GROUP_ID, containerId, getVersion(KieServerMode.DEVELOPMENT));
    ServiceResponse<ReleaseId> updateResponse = kieServer.updateContainerReleaseId(containerId, updateReleaseId, true);
    Assertions.assertThat(updateResponse.getType()).isEqualTo(ServiceResponse.ResponseType.FAILURE);
    verify(extension, never()).isUpdateContainerAllowed(anyString(), any(), any());
    verify(extension, never()).updateContainer(any(), any(), any());
}
Also used : KieServerExtension(org.kie.server.services.api.KieServerExtension) Matchers.anyString(org.mockito.Matchers.anyString) ReleaseId(org.kie.server.api.model.ReleaseId) Test(org.junit.Test)

Example 28 with KieServerExtension

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

the class KafkaServerExtension method init.

@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
    if (initialized.get()) {
        logger.warn("Kafka extension already initialized");
        return;
    }
    initProperties();
    factory = buildEventProcessorFactory();
    KafkaServerProducer.init(factory, this::getKafkaProducer);
    DeploymentDescriptorManager.addDescriptorLocation("classpath:/META-INF/kafka-deployment-descriptor-defaults.xml");
    KieServerExtension jbpmExt = registry.getServerExtension(JbpmKieServerExtension.EXTENSION_NAME);
    if (jbpmExt == null) {
        logger.warn("Extension " + JbpmKieServerExtension.EXTENSION_NAME + " is required");
        return;
    }
    ProcessService processService = null;
    for (Object service : jbpmExt.getServices()) {
        if (deploymentService == null && DeploymentService.class.isAssignableFrom(service.getClass())) {
            deploymentService = (ListenerSupport) service;
        } else if (processService == null && ProcessService.class.isAssignableFrom(service.getClass())) {
            processService = (ProcessService) service;
        }
        if (deploymentService != null && processService != null) {
            break;
        }
    }
    if (deploymentService == null) {
        throw new IllegalStateException("Cannot find deployment service");
    }
    if (processService == null) {
        throw new IllegalStateException("Cannot find process service");
    }
    kafkaServerConsumer = new KafkaServerConsumer(factory, this::getKafkaConsumer, processService);
    deploymentService.addListener(this);
    initialized.set(true);
}
Also used : JbpmKieServerExtension(org.kie.server.services.jbpm.JbpmKieServerExtension) KieServerExtension(org.kie.server.services.api.KieServerExtension) DeploymentService(org.jbpm.services.api.DeploymentService) ProcessService(org.jbpm.services.api.ProcessService)

Example 29 with KieServerExtension

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

the class KieServerMDB method onMessage.

public void onMessage(Message message) {
    JMSConnection connect = null;
    try {
        String username = null;
        String password = null;
        try {
            username = message.getStringProperty(USER_PROPERTY_NAME);
            password = message.getStringProperty(PASSWRD_PROPERTY_NAME);
        } catch (JMSException jmse) {
            logger.warn("Unable to retrieve user name and/or password, from message");
        }
        if (username != null && password != null) {
            JMSSecurityAdapter.login(username, password);
        } else {
            logger.warn("Unable to login to JMSSecurityAdapter, user name and/or password missing");
        }
        KieContainerCommandService executor = null;
        // 0. Get msg correlation id (for response)
        String msgCorrId = null;
        try {
            msgCorrId = message.getJMSCorrelationID();
        } catch (JMSException jmse) {
            String errMsg = "Unable to retrieve JMS correlation id from message! " + ID_NECESSARY;
            throw new JMSRuntimeException(errMsg, jmse);
        }
        // for backward compatibility default to KieServer
        String targetCapability = getStringProperty(message, TARGET_CAPABILITY_PROPERTY_NAME, "KieServer");
        String containerId = getStringProperty(message, CONTAINER_ID_PROPERTY_NAME, null);
        String conversationId = getStringProperty(message, CONVERSATION_ID_PROPERTY_NAME, null);
        int interactionPattern = getIntProperty(message, INTERACTION_PATTERN_PROPERTY_NAME, REQUEST_REPLY_PATTERN);
        // 1. get marshalling info
        MarshallingFormat format = null;
        String classType = null;
        try {
            classType = message.getStringProperty(CLASS_TYPE_PROPERTY_NAME);
            if (!message.propertyExists(SERIALIZATION_FORMAT_PROPERTY_NAME)) {
                format = MarshallingFormat.JAXB;
            } else {
                int intFormat = message.getIntProperty(SERIALIZATION_FORMAT_PROPERTY_NAME);
                logger.debug("Serialization format (int) is {}", intFormat);
                format = MarshallingFormat.fromId(intFormat);
                logger.debug("Serialization format is {}", format);
                if (format == null) {
                    String errMsg = "Unsupported marshalling format '" + intFormat + "' from message " + msgCorrId + ".";
                    throw new JMSRuntimeException(errMsg);
                }
            }
        } catch (JMSException jmse) {
            String errMsg = "Unable to retrieve property '" + SERIALIZATION_FORMAT_PROPERTY_NAME + "' from message " + msgCorrId + ".";
            throw new JMSRuntimeException(errMsg, jmse);
        }
        // 2. get marshaller
        Marshaller marshaller = getMarshaller(containerId, format);
        logger.debug("Selected marshaller is {}", marshaller);
        // 3. deserialize request
        CommandScript script = unmarshallRequest(message, msgCorrId, marshaller, format);
        logger.debug("Target capability is {}", targetCapability);
        for (KieServerExtension extension : kieServer.getServerExtensions()) {
            KieContainerCommandService tmp = extension.getAppComponents(KieContainerCommandService.class);
            if (tmp != null && extension.getImplementedCapability().equalsIgnoreCase(targetCapability)) {
                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, format, classType);
        if (interactionPattern < UPPER_LIMIT_REPLY_INTERACTION_PATTERNS) {
            connect = startConnectionAndSession();
            logger.debug("Response message is about to be sent according to selected interaction pattern {}", interactionPattern);
            // 5. serialize response
            Message msg = marshallResponse(connect.getSession(), msgCorrId, format, marshaller, response);
            // set conversation id for routing
            if (containerId != null && (conversationId == null || conversationId.trim().isEmpty())) {
                try {
                    KieContainerInstance containerInstance = kieServer.getServerRegistry().getContainer(containerId);
                    if (containerInstance != null) {
                        ReleaseId releaseId = containerInstance.getResource().getResolvedReleaseId();
                        if (releaseId == null) {
                            releaseId = containerInstance.getResource().getReleaseId();
                        }
                        conversationId = ConversationId.from(KieServerEnvironment.getServerId(), containerId, releaseId).toString();
                    }
                } catch (Exception e) {
                    logger.warn("Unable to build conversation id due to {}", e.getMessage(), e);
                }
            }
            try {
                if (conversationId != null) {
                    msg.setStringProperty(CONVERSATION_ID_PROPERTY_NAME, conversationId);
                }
            } catch (JMSException e) {
                logger.debug("Unable to set conversation id on response message due to {}", e.getMessage());
            }
            // 6. send response
            sendResponse(connect.getSession(), msgCorrId, format, msg);
        } else {
            logger.debug("Response message is skipped according to selected interaction pattern {}", FIRE_AND_FORGET_PATTERN);
        }
    } finally {
        if (connect != null) {
            // Only attempt to close the connection/session if they were actually created
            try {
                closeConnectionAndSession(connect);
            } catch (JMSRuntimeException runtimeException) {
                logger.error("Error while attempting to close connection/session", runtimeException);
            } finally {
                JMSSecurityAdapter.logout();
            }
        } else {
            JMSSecurityAdapter.logout();
        }
    }
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) Marshaller(org.kie.server.api.marshalling.Marshaller) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) KieServerExtension(org.kie.server.services.api.KieServerExtension) CommandScript(org.kie.server.api.commands.CommandScript) JMSException(javax.jms.JMSException) KieContainerCommandService(org.kie.server.services.api.KieContainerCommandService) ReleaseId(org.kie.server.api.model.ReleaseId) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) KieContainerInstance(org.kie.server.services.api.KieContainerInstance)

Example 30 with KieServerExtension

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

the class KieExecutorMDB method init.

@PostConstruct
public void init() {
    kieServer = KieServerLocator.getInstance();
    KieServerExtension bpmServerExtension = null;
    for (KieServerExtension extension : kieServer.getServerRegistry().getServerExtensions()) {
        if (extension.isActive() && "BPM".equals(extension.getImplementedCapability())) {
            bpmServerExtension = extension;
        }
    }
    if (bpmServerExtension == null) {
        logger.warn("No BPM capability found on the server, ExecutorMDB is deactivated");
        active = false;
        return;
    }
    ExecutorService executorService = bpmServerExtension.getAppComponents(ExecutorService.class);
    if (executorService == null) {
        logger.warn("Unable to find ExecutorService within {} extension, deactivating ExecutorMDB", bpmServerExtension);
        active = false;
        return;
    }
    setClassCacheManager(new ClassCacheManager());
    setQueryService(((ExecutorServiceImpl) executorService).getQueryService());
    setExecutorStoreService(((ExecutorImpl) ((ExecutorServiceImpl) executorService).getExecutor()).getExecutorStoreService());
    setExecutor(((ExecutorServiceImpl) executorService).getExecutor());
}
Also used : ClassCacheManager(org.jbpm.executor.impl.ClassCacheManager) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) KieServerExtension(org.kie.server.services.api.KieServerExtension) ExecutorService(org.kie.api.executor.ExecutorService) PostConstruct(javax.annotation.PostConstruct)

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