use of org.kie.server.services.impl.KieContainerInstanceImpl in project droolsjbpm-integration by kiegroup.
the class CaseManagementServiceBase method verifyContainerId.
private void verifyContainerId(String containerId, String caseId) {
String caseContainerId;
try {
caseContainerId = (new ByCaseIdContainerLocator(caseId)).locateContainer(containerId, null);
} catch (IllegalArgumentException e) {
throw new CaseNotFoundException(e.getMessage());
}
KieContainerInstanceImpl taskContainer = context.getContainer(caseContainerId);
List<KieContainerInstanceImpl> containersByAlias = context.getContainersForAlias(containerId);
// The container id is either a non-existent one or is not a valid alias for the container id the task is associated with. Both scenarios should raise an exception.
if (context.getContainer(containerId) == null && !containersByAlias.contains(taskContainer)) {
throw new DeploymentNotFoundException("CaseId: " + caseId + " is not associated with the provided container id: " + containerId + " or its alias.");
}
}
use of org.kie.server.services.impl.KieContainerInstanceImpl in project droolsjbpm-integration by kiegroup.
the class OptaplannerCommandServiceImpl method executeScript.
@Override
public ServiceResponsesList executeScript(CommandScript commands, MarshallingFormat marshallingFormat, String classType) {
List<ServiceResponse<?>> responses = new ArrayList<>();
for (KieServerCommand command : commands.getCommands()) {
try {
ServiceResponse<?> response;
logger.debug("About to execute command: {}", command);
if (command instanceof CreateSolverCommand) {
CreateSolverCommand createSolverCommand = (CreateSolverCommand) command;
String containerId = context.getContainerId(createSolverCommand.getContainerId(), ContainerLocatorProvider.get().getLocator());
SolverInstance instance = new SolverInstance();
instance.setContainerId(containerId);
instance.setSolverId(createSolverCommand.getSolverId());
instance.setSolverConfigFile(createSolverCommand.getSolverConfigFile());
response = solverService.createSolver(containerId, createSolverCommand.getSolverId(), instance);
} else if (command instanceof GetSolversCommand) {
GetSolversCommand getSolversCommand = (GetSolversCommand) command;
String containerId = context.getContainerId(getSolversCommand.getContainerId(), ContainerLocatorProvider.get().getLocator());
response = solverService.getSolvers(containerId);
} else if (command instanceof GetSolverCommand) {
GetSolverCommand getSolverCommand = (GetSolverCommand) command;
String containerId = context.getContainerId(getSolverCommand.getContainerId(), ContainerLocatorProvider.get().getLocator());
response = solverService.getSolver(containerId, getSolverCommand.getSolverId());
} else if (command instanceof GetSolverWithBestSolutionCommand) {
GetSolverWithBestSolutionCommand getSolverWithBestSolutionCommand = (GetSolverWithBestSolutionCommand) command;
String containerId = context.getContainerId(getSolverWithBestSolutionCommand.getContainerId(), ContainerLocatorProvider.get().getLocator());
response = solverService.getSolverWithBestSolution(containerId, getSolverWithBestSolutionCommand.getSolverId());
} else if (command instanceof SolvePlanningProblemCommand) {
SolvePlanningProblemCommand solvePlanningProblemCommand = (SolvePlanningProblemCommand) command;
String containerId = context.getContainerId(solvePlanningProblemCommand.getContainerId(), ContainerLocatorProvider.get().getLocator());
KieContainerInstanceImpl kc = context.getContainer(containerId);
Marshaller marshaller = kc.getMarshaller(marshallingFormat);
Object planningProblem = marshaller.unmarshall(solvePlanningProblemCommand.getPlanningProblem(), Object.class);
response = solverService.solvePlanningProblem(containerId, solvePlanningProblemCommand.getSolverId(), planningProblem);
} else if (command instanceof TerminateSolverEarlyCommand) {
TerminateSolverEarlyCommand terminateSolverEarlyCommand = (TerminateSolverEarlyCommand) command;
String containerId = context.getContainerId(terminateSolverEarlyCommand.getContainerId(), ContainerLocatorProvider.get().getLocator());
response = solverService.terminateSolverEarly(containerId, terminateSolverEarlyCommand.getSolverId());
} else if (command instanceof AddProblemFactChangeCommand) {
AddProblemFactChangeCommand addProblemFactChangeCommand = (AddProblemFactChangeCommand) command;
String containerId = context.getContainerId(addProblemFactChangeCommand.getContainerId(), ContainerLocatorProvider.get().getLocator());
response = solverService.addProblemFactChanges(containerId, addProblemFactChangeCommand.getSolverId(), addProblemFactChangeCommand.getProblemFactChange());
} else if (command instanceof AddProblemFactChangesCommand) {
AddProblemFactChangesCommand addProblemFactChangesCommand = (AddProblemFactChangesCommand) command;
String containerId = context.getContainerId(addProblemFactChangesCommand.getContainerId(), ContainerLocatorProvider.get().getLocator());
response = solverService.addProblemFactChanges(containerId, addProblemFactChangesCommand.getSolverId(), addProblemFactChangesCommand.getProblemFactChanges());
} else if (command instanceof IsEveryProblemFactChangeProcessedCommand) {
IsEveryProblemFactChangeProcessedCommand isEveryProblemFactChangeProcessedCommand = (IsEveryProblemFactChangeProcessedCommand) command;
String containerId = context.getContainerId(isEveryProblemFactChangeProcessedCommand.getContainerId(), ContainerLocatorProvider.get().getLocator());
ServiceResponse<Boolean> everyProblemFactChangeProcessedResponse = solverService.isEveryProblemFactChangeProcessed(containerId, isEveryProblemFactChangeProcessedCommand.getSolverId());
if (marshallingFormat.equals(MarshallingFormat.JAXB)) {
Object wrappedResult = ModelWrapper.wrap(everyProblemFactChangeProcessedResponse.getResult());
response = new ServiceResponse<>(everyProblemFactChangeProcessedResponse.getType(), everyProblemFactChangeProcessedResponse.getMsg(), wrappedResult);
} else {
response = everyProblemFactChangeProcessedResponse;
}
} else if (command instanceof DisposeSolverCommand) {
DisposeSolverCommand disposeSolverCommand = (DisposeSolverCommand) command;
String containerId = context.getContainerId(disposeSolverCommand.getContainerId(), ContainerLocatorProvider.get().getLocator());
response = solverService.disposeSolver(containerId, disposeSolverCommand.getSolverId());
} else {
throw new IllegalStateException("Unsupported command: " + command);
}
logger.debug("Service returned response {}", response);
// return successful result
responses.add(response);
} catch (Throwable e) {
logger.error("Error while processing {} command", command, e);
// return failure result
responses.add(new ServiceResponse<>(ServiceResponse.ResponseType.FAILURE, e.getMessage()));
}
}
logger.debug("About to return responses '{}'", responses);
return new ServiceResponsesList(responses);
}
use of org.kie.server.services.impl.KieContainerInstanceImpl in project droolsjbpm-integration by kiegroup.
the class JbpmKieServerExtensionTest method testPrepareContainerUpdate.
private void testPrepareContainerUpdate(KieServerMode mode, String version, boolean cleanup) throws IOException {
this.mode = mode;
activeProcessInstances.add(mockProcessInstance());
activeProcessInstances.add(mockProcessInstance());
activeProcessInstances.add(mockProcessInstance());
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.prepareContainerUpdate(CONTAINER_ID, new KieContainerInstanceImpl(CONTAINER_ID, KieContainerStatus.STARTED, kieContainer), params);
if (mode.equals(KieServerMode.PRODUCTION) || !cleanup) {
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());
} else {
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());
}
}
use of org.kie.server.services.impl.KieContainerInstanceImpl in project droolsjbpm-integration by kiegroup.
the class JbpmKieServerExtensionTest method testDeployContainer.
private void testDeployContainer(String version) throws IOException {
createEmptyKjar(GROUP_ID, ARTIFACT_ID, version);
ReleaseId releaseId = new ReleaseId(GROUP_ID, ARTIFACT_ID, version);
kieContainer = (InternalKieContainer) kieServices.newKieContainer(CONTAINER_ID, releaseId);
KieContainerInstanceImpl containerInstance = new KieContainerInstanceImpl(CONTAINER_ID, KieContainerStatus.STARTED, kieContainer);
KieModuleMetaData metaData = KieModuleMetaData.Factory.newKieModuleMetaData(releaseId, 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);
extension.createContainer(CONTAINER_ID, containerInstance, params);
verify(deploymentService).deploy(any());
}
use of org.kie.server.services.impl.KieContainerInstanceImpl in project droolsjbpm-integration by kiegroup.
the class ExecutorServiceBase method convertToRequestInfo.
protected RequestInfoInstance convertToRequestInfo(RequestInfo request, boolean withErrors, boolean withData) {
RequestInfoInstance.Builder builder = RequestInfoInstance.builder().id(request.getId()).businessKey(request.getKey()).command(request.getCommandName()).executions(request.getExecutions()).message(request.getMessage()).retries(request.getRetries()).scheduledDate(request.getTime()).status(request.getStatus().toString()).containerId(request.getDeploymentId());
if (withErrors) {
ErrorInfoInstance[] errors = new ErrorInfoInstance[request.getErrorInfo().size()];
int index = 0;
for (ErrorInfo error : request.getErrorInfo()) {
errors[index] = ErrorInfoInstance.builder().id(error.getId()).errorDate(error.getTime()).message(error.getMessage()).requestId(request.getId()).stacktrace(error.getStacktrace()).build();
index++;
}
builder.errors(new ErrorInfoInstanceList(errors));
}
if (withData) {
// by default use kieserver classloader
ClassLoader classLoader = this.getClass().getClassLoader();
String deploymentId = ((org.jbpm.executor.entities.RequestInfo) request).getDeploymentId();
if (deploymentId != null && context.getContainer(deploymentId) != null) {
KieContainerInstanceImpl containerInstance = context.getContainer(deploymentId);
classLoader = containerInstance.getKieContainer().getClassLoader();
}
builder.data(readContent(request.getRequestData(), classLoader));
builder.responseData(readContent(request.getResponseData(), classLoader));
}
return builder.build();
}
Aggregations