Search in sources :

Example 21 with KieContainerInstanceImpl

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

the class ModelEvaluatorServiceBase method getOAS.

public Response getOAS(String containerId, boolean asJSON) {
    try {
        KieContainerInstanceImpl kContainer = context.getContainer(containerId, ContainerLocatorProvider.get().getLocator());
        ReleaseId resolvedReleaseId = kContainer.getKieContainer().getResolvedReleaseId();
        DMNRuntime dmnRuntime = KieRuntimeFactory.of(kContainer.getKieContainer().getKieBase()).get(DMNRuntime.class);
        Collection<DMNModel> models = dmnRuntime.getModels();
        String content = new OASGenerator(containerId, resolvedReleaseId).generateOAS(models, asJSON);
        return Response.ok().entity(content).build();
    } catch (Exception e) {
        LOG.error("Error from container '" + containerId + "'", e);
        return Response.serverError().entity(e.getMessage()).build();
    }
}
Also used : KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) ReleaseId(org.kie.api.builder.ReleaseId) OASGenerator(org.kie.server.services.dmn.modelspecific.OASGenerator) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 22 with KieContainerInstanceImpl

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

the class DroolsKieContainerCommandServiceImpl method callContainer.

@Override
public ServiceResponse<ExecutionResults> callContainer(String containerId, String payload, MarshallingFormat marshallingFormat, String classType) {
    if (payload == null) {
        return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Error calling container " + containerId + ". Empty payload. ");
    }
    try {
        KieContainerInstanceImpl kci = (KieContainerInstanceImpl) context.getContainer(containerId, ContainerLocatorProvider.get().getLocator());
        if (kci != null && kci.getKieContainer() != null) {
            Class<? extends Command> type = BatchExecutionCommandImpl.class;
            if (classType != null && !classType.isEmpty()) {
                type = (Class<? extends Command>) kci.getKieContainer().getClassLoader().loadClass(classType);
            }
            Command<?> cmd = kci.getMarshaller(marshallingFormat).unmarshall(payload, type);
            if (!(cmd instanceof BatchExecutionCommandImpl)) {
                cmd = new BatchExecutionCommandImpl(Arrays.asList(new ExecutableCommand<?>[] { (ExecutableCommand<?>) cmd }));
            }
            if (cmd == null || ((BatchExecutionCommandImpl) cmd).getCommands() == null || ((BatchExecutionCommandImpl) cmd).getCommands().isEmpty()) {
                return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Bad request, no commands to be executed - either wrong format or no data");
            }
            ExecutionResults results = rulesExecutionService.call(kci, (BatchExecutionCommandImpl) cmd);
            return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully called.", results);
        } else {
            return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Container " + containerId + " is not instantiated.");
        }
    } catch (Exception e) {
        logger.error("Error calling container '" + containerId + "'", e);
        return new ServiceResponse<ExecutionResults>(ServiceResponse.ResponseType.FAILURE, "Error calling container " + containerId + ": " + e.getMessage());
    }
}
Also used : ServiceResponse(org.kie.server.api.model.ServiceResponse) BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) ExecutionResults(org.kie.api.runtime.ExecutionResults) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl)

Example 23 with KieContainerInstanceImpl

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

the class RulesExecutionService method call.

public ExecutionResults call(KieContainerInstance kci, BatchExecutionCommand executionCommand) {
    BatchExecutionCommandImpl command = (BatchExecutionCommandImpl) executionCommand;
    if (kci != null && kci.getKieContainer() != null) {
        // find the session
        CommandExecutor ks = null;
        if (command.getLookup() != null) {
            ks = context.getKieSessionLookupManager().lookup(command.getLookup(), kci, context);
        } else {
            // if no session ID is defined, then use default stateful/stateless ksession.
            ks = KieServerUtils.getDefaultKieSession((KieContainerInstanceImpl) kci);
        }
        context.getKieSessionLookupManager().postLookup(command.getLookup(), kci, ks, context);
        if (ks != null) {
            applyListeners(ks);
            ExecutionResults results = ks.execute(command);
            return results;
        } else {
            throw new IllegalStateException("Session '" + command.getLookup() + "' not found on container '" + kci.getContainerId() + "'.");
        }
    }
    throw new IllegalStateException("Unable to execute command " + command);
}
Also used : BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) ExecutionResults(org.kie.api.runtime.ExecutionResults) CommandExecutor(org.kie.api.runtime.CommandExecutor) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl)

Example 24 with KieContainerInstanceImpl

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

the class JbpmKieServerExtensionTest method testDispose.

private void testDispose(KieServerMode mode, boolean abort) throws IOException {
    this.mode = mode;
    String version;
    if (mode.equals(KieServerMode.DEVELOPMENT)) {
        version = VERSION_SNAPSHOT;
    } else {
        version = VERSION;
    }
    testDeployContainer(version);
    KieModuleMetaData metaData = KieModuleMetaData.Factory.newKieModuleMetaData(new ReleaseId(GROUP_ID, ARTIFACT_ID, version), DependencyFilter.COMPILE_FILTER);
    List<Message> messages = new ArrayList<>();
    Map<String, Object> params = new HashMap<>();
    params.put(KieServerConstants.KIE_SERVER_PARAM_MODULE_METADATA, metaData);
    params.put(KieServerConstants.KIE_SERVER_PARAM_MESSAGES, messages);
    params.put(KieServerConstants.KIE_SERVER_PARAM_RESET_BEFORE_UPDATE, Boolean.FALSE);
    params.put(KieServerConstants.IS_DISPOSE_CONTAINER_PARAM, abort);
    extension.disposeContainer(CONTAINER_ID, new KieContainerInstanceImpl(CONTAINER_ID, KieContainerStatus.STARTED, kieContainer), params);
    if (abort) {
        verify(deploymentService).undeploy(any(), beforeUndeployCaptor.capture());
        Function<DeploymentUnit, Boolean> function = beforeUndeployCaptor.getValue();
        Assert.assertNotNull(function);
        function.apply(deploymentUnit);
        verify(runtimeDataService).getProcessInstancesByDeploymentId(eq(CONTAINER_ID), anyList(), any());
        verify(runimeManager, times(activeProcessInstances.size())).getRuntimeEngine(any());
        verify(engine, times(activeProcessInstances.size())).getKieSession();
        verify(session, times(activeProcessInstances.size())).abortProcessInstance(eq(new Long(1)));
        verify(runimeManager, times(activeProcessInstances.size())).disposeRuntimeEngine(any());
    } else {
        if (mode.equals(KieServerMode.PRODUCTION)) {
            verify(deploymentService).undeploy(any());
        } else {
            verify(deploymentService).undeploy(any(), beforeUndeployCaptor.capture());
            Function<DeploymentUnit, Boolean> function = beforeUndeployCaptor.getValue();
            assertNotNull(function);
            function.apply(deploymentUnit);
        }
    }
}
Also used : Message(org.kie.server.api.model.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ReleaseId(org.kie.server.api.model.ReleaseId) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit)

Example 25 with KieContainerInstanceImpl

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

the class JbpmKieServerExtensionTest method testUpdateContainer.

private void testUpdateContainer(KieServerMode mode, String version, boolean cleanup) throws IOException {
    this.mode = mode;
    testDeployContainer(version);
    KieModuleMetaData metaData = KieModuleMetaData.Factory.newKieModuleMetaData(new ReleaseId(GROUP_ID, ARTIFACT_ID, version), DependencyFilter.COMPILE_FILTER);
    List<Message> messages = new ArrayList<>();
    Map<String, Object> params = new HashMap<>();
    params.put(KieServerConstants.KIE_SERVER_PARAM_MODULE_METADATA, metaData);
    params.put(KieServerConstants.KIE_SERVER_PARAM_MESSAGES, messages);
    params.put(KieServerConstants.KIE_SERVER_PARAM_RESET_BEFORE_UPDATE, cleanup);
    extension.updateContainer(CONTAINER_ID, new KieContainerInstanceImpl(CONTAINER_ID, KieContainerStatus.STARTED, kieContainer), params);
    if (mode.equals(KieServerMode.PRODUCTION)) {
        verify(deploymentService).undeploy(any());
    } else {
        verify(deploymentService).undeploy(any(), beforeUndeployCaptor.capture());
        Function<DeploymentUnit, Boolean> function = beforeUndeployCaptor.getValue();
        assertNotNull(function);
        assertTrue(function.apply(deploymentUnit));
        verify(runtimeDataService, never()).getProcessInstancesByDeploymentId(eq(CONTAINER_ID), anyList(), any());
        verify(runimeManager, never()).getRuntimeEngine(any());
        verify(engine, never()).getKieSession();
        verify(session, never()).abortProcessInstance(eq(new Long(1)));
        verify(runimeManager, never()).disposeRuntimeEngine(any());
    }
    verify(deploymentService, times(2)).deploy(any());
}
Also used : Message(org.kie.server.api.model.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ReleaseId(org.kie.server.api.model.ReleaseId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit)

Aggregations

KieContainerInstanceImpl (org.kie.server.services.impl.KieContainerInstanceImpl)29 ArrayList (java.util.ArrayList)8 ReleaseId (org.kie.server.api.model.ReleaseId)8 ServiceResponse (org.kie.server.api.model.ServiceResponse)8 HashMap (java.util.HashMap)7 KieServerRegistry (org.kie.server.services.api.KieServerRegistry)6 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)5 KieModuleMetaData (org.kie.scanner.KieModuleMetaData)5 Message (org.kie.server.api.model.Message)5 List (java.util.List)4 Map (java.util.Map)4 Test (org.junit.Test)4 DMNModel (org.kie.dmn.api.core.DMNModel)4 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)3 ReleaseId (org.kie.api.builder.ReleaseId)3 Header (org.kie.server.remote.rest.common.Header)3 OASGenerator (org.kie.server.services.dmn.modelspecific.OASGenerator)3 MarshallerHelper (org.kie.server.services.impl.marshal.MarshallerHelper)3