Search in sources :

Example 11 with KieContainerInstanceImpl

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.");
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) ByCaseIdContainerLocator(org.kie.server.services.casemgmt.locator.ByCaseIdContainerLocator) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException)

Example 12 with KieContainerInstanceImpl

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);
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) KieServerCommand(org.kie.server.api.model.KieServerCommand) ArrayList(java.util.ArrayList) TerminateSolverEarlyCommand(org.kie.server.api.commands.optaplanner.TerminateSolverEarlyCommand) SolverInstance(org.kie.server.api.model.instance.SolverInstance) ServiceResponse(org.kie.server.api.model.ServiceResponse) AddProblemFactChangesCommand(org.kie.server.api.commands.optaplanner.AddProblemFactChangesCommand) IsEveryProblemFactChangeProcessedCommand(org.kie.server.api.commands.optaplanner.IsEveryProblemFactChangeProcessedCommand) GetSolverCommand(org.kie.server.api.commands.optaplanner.GetSolverCommand) Marshaller(org.kie.server.api.marshalling.Marshaller) GetSolversCommand(org.kie.server.api.commands.optaplanner.GetSolversCommand) SolvePlanningProblemCommand(org.kie.server.api.commands.optaplanner.SolvePlanningProblemCommand) GetSolverWithBestSolutionCommand(org.kie.server.api.commands.optaplanner.GetSolverWithBestSolutionCommand) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) CreateSolverCommand(org.kie.server.api.commands.optaplanner.CreateSolverCommand) AddProblemFactChangeCommand(org.kie.server.api.commands.optaplanner.AddProblemFactChangeCommand) DisposeSolverCommand(org.kie.server.api.commands.optaplanner.DisposeSolverCommand)

Example 13 with KieContainerInstanceImpl

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());
    }
}
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) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) KieModuleMetaData(org.kie.scanner.KieModuleMetaData)

Example 14 with KieContainerInstanceImpl

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());
}
Also used : Message(org.kie.server.api.model.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ReleaseId(org.kie.server.api.model.ReleaseId) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KieModuleMetaData(org.kie.scanner.KieModuleMetaData)

Example 15 with KieContainerInstanceImpl

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();
}
Also used : ErrorInfo(org.kie.api.executor.ErrorInfo) ErrorInfoInstanceList(org.kie.server.api.model.instance.ErrorInfoInstanceList) ErrorInfoInstance(org.kie.server.api.model.instance.ErrorInfoInstance) RequestInfo(org.kie.api.executor.RequestInfo) RequestInfoInstance(org.kie.server.api.model.instance.RequestInfoInstance) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl)

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