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();
}
}
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());
}
}
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);
}
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);
}
}
}
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());
}
Aggregations