Search in sources :

Example 26 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class KieServerPolicyJbpmIntegrationTest method testStartProcessInDifferentDeploymentWithAlias.

@Test
public void testStartProcessInDifferentDeploymentWithAlias() throws Exception {
    Object person = createPersonInstance(USER_JOHN);
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("test", USER_MARY);
    parameters.put("number", new Integer(12345));
    List<Object> list = new ArrayList<Object>();
    list.add("item");
    parameters.put("list", list);
    parameters.put("person", person);
    Long processInstanceIdV1 = processClient.startProcess(CONTAINER_ALIAS, PROCESS_ID_EVALUATION, parameters);
    assertNotNull(processInstanceIdV1);
    assertTrue(processInstanceIdV1.longValue() > 0);
    ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ALIAS, processInstanceIdV1);
    assertNotNull(processInstance);
    assertEquals(CONTAINER_ID, processInstance.getContainerId());
    List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    assertEquals(1, tasks.size());
    ServiceResponse<KieContainerResourceList> containersResponse = client.listContainers();
    KieServerAssert.assertSuccess(containersResponse);
    List<KieContainerResource> containerResources = containersResponse.getResult().getContainers();
    assertEquals(1, containerResources.size());
    createExtraContainer();
    // wait for sync
    KieServerSynchronization.waitForKieServerSynchronization(client, 2);
    Long processInstanceIdV2 = processClient.startProcess(CONTAINER_ALIAS, PROCESS_ID_EVALUATION_2, parameters);
    assertNotNull(processInstanceIdV2);
    assertTrue(processInstanceIdV2.longValue() > 0);
    processInstance = processClient.getProcessInstance(CONTAINER_ALIAS, processInstanceIdV2);
    assertNotNull(processInstance);
    assertEquals(CONTAINER_ID_101, processInstance.getContainerId());
    tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    assertEquals(2, tasks.size());
    try {
        // there are instances in both containers thus the older one cannot be disposed
        processClient.abortProcessInstance(CONTAINER_ALIAS, processInstanceIdV1);
    } catch (KieServicesException e) {
        // In case we try to abort process belonging to currently disposed container then an exception is thrown (as process instance cannot be found in this case).
        // Try to abort the process instance again after some time.
        Thread.sleep(1000);
        processClient.abortProcessInstance(CONTAINER_ALIAS, processInstanceIdV1);
    }
    // In case of race condition when we abort process instance on container
    // which is in process of dispose try by policy, we will wait and synchronize again.
    containersResponse = client.listContainers();
    KieServerAssert.assertSuccess(containersResponse);
    if (containersResponse.getResult().getContainers().size() == 1) {
        Thread.sleep(1000);
    }
    // wait for policy to be activated
    KieServerSynchronization.waitForKieServerSynchronization(client, 1);
    containersResponse = client.listContainers();
    KieServerAssert.assertSuccess(containersResponse);
    containerResources = containersResponse.getResult().getContainers();
    assertEquals(1, containerResources.size());
    ReleaseId latestContainerReleaseId = containerResources.get(0).getReleaseId();
    assertEquals(releaseId101, latestContainerReleaseId);
}
Also used : KieContainerResourceList(org.kie.server.api.model.KieContainerResourceList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ReleaseId(org.kie.server.api.model.ReleaseId) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieContainerResource(org.kie.server.api.model.KieContainerResource) KieServicesException(org.kie.server.api.exception.KieServicesException) Test(org.junit.Test)

Example 27 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class KieServicesConfigurationImpl method setRemoteInitialContext.

@Override
public KieServicesConfiguration setRemoteInitialContext(InitialContext context) {
    String prop = CONNECTION_FACTORY_NAME;
    try {
        if (this.connectionFactory == null) {
            this.connectionFactory = (ConnectionFactory) context.lookup(prop);
        }
        prop = REQUEST_QUEUE_NAME;
        this.requestQueue = (Queue) context.lookup(prop);
        prop = RESPONSE_QUEUE_NAME;
        this.responseQueue = (Queue) context.lookup(prop);
    } catch (NamingException ne) {
        throw new KieServicesException("Unable to retrieve object for " + prop, ne);
    }
    checkValidValues(connectionFactory, requestQueue, responseQueue);
    return this;
}
Also used : NamingException(javax.naming.NamingException) KieServicesException(org.kie.server.api.exception.KieServicesException)

Example 28 with KieServicesException

use of org.kie.server.api.exception.KieServicesException in project droolsjbpm-integration by kiegroup.

the class TaskAssigningRuntimeServiceQueryHelper method readTaskVariables.

private Map<String, Object> readTaskVariables(TaskData taskData) {
    KieContainerInstanceImpl container = registry.getContainer(taskData.getContainerId());
    if (container == null || (container.getStatus() != KieContainerStatus.STARTED && container.getStatus() != KieContainerStatus.DEACTIVATED)) {
        throw new KieServicesException("Container " + taskData.getContainerId() + " is not available to serve requests");
    }
    Map<String, Object> variables = userTaskService.getTaskInputContentByTaskId(taskData.getContainerId(), taskData.getTaskId());
    variables = variables == null ? new HashMap<>() : variables;
    return variables.entrySet().stream().filter(entry -> isSimpleTypeValue(entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
Also used : KieServicesException(org.kie.server.api.exception.KieServicesException) Created(org.kie.api.task.model.Status.Created) QueryService(org.jbpm.services.api.query.QueryService) Date(java.util.Date) QueryResultMapper(org.jbpm.services.api.query.QueryResultMapper) LocalDateTime(java.time.LocalDateTime) AbstractTaskAssigningQueryMapper(org.kie.server.services.taskassigning.runtime.query.AbstractTaskAssigningQueryMapper) Reserved(org.kie.api.task.model.Status.Reserved) HashMap(java.util.HashMap) STATUS(org.kie.server.api.model.taskassigning.QueryParamName.STATUS) TaskAssigningTaskDataWithPotentialOwnersQueryMapper(org.kie.server.services.taskassigning.runtime.query.TaskAssigningTaskDataWithPotentialOwnersQueryMapper) ClassUtils.isPrimitiveWrapper(org.apache.commons.lang3.ClassUtils.isPrimitiveWrapper) QueryParam(org.jbpm.services.api.query.model.QueryParam) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) InProgress(org.kie.api.task.model.Status.InProgress) ArrayList(java.util.ArrayList) TaskData(org.kie.server.api.model.taskassigning.TaskData) PAGE(org.kie.server.api.model.taskassigning.QueryParamName.PAGE) Map(java.util.Map) PAGE_SIZE(org.kie.server.api.model.taskassigning.QueryParamName.PAGE_SIZE) UserTaskService(org.jbpm.services.api.UserTaskService) KieContainerStatus(org.kie.server.api.model.KieContainerStatus) Suspended(org.kie.api.task.model.Status.Suspended) FROM_LAST_MODIFICATION_DATE(org.kie.server.api.model.taskassigning.QueryParamName.FROM_LAST_MODIFICATION_DATE) StatusConverter(org.kie.server.api.model.taskassigning.util.StatusConverter) Ready(org.kie.api.task.model.Status.Ready) TASK_INPUT_VARIABLES_MODE(org.kie.server.api.model.taskassigning.QueryParamName.TASK_INPUT_VARIABLES_MODE) TaskInputVariablesReadMode(org.kie.server.api.model.taskassigning.TaskInputVariablesReadMode) Predicate(java.util.function.Predicate) QueryContext(org.kie.api.runtime.query.QueryContext) QueryMapperRegistry(org.jbpm.services.api.query.QueryMapperRegistry) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) TO_TASK_ID(org.kie.server.api.model.taskassigning.QueryParamName.TO_TASK_ID) List(java.util.List) TaskAssigningTaskDataSummaryQueryMapper(org.kie.server.services.taskassigning.runtime.query.TaskAssigningTaskDataSummaryQueryMapper) FROM_TASK_ID(org.kie.server.api.model.taskassigning.QueryParamName.FROM_TASK_ID) Optional(java.util.Optional) Status(org.kie.api.task.model.Status) LocalDateTimeValue(org.kie.server.api.model.taskassigning.LocalDateTimeValue) HashMap(java.util.HashMap) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) HashMap(java.util.HashMap) Map(java.util.Map) KieServicesException(org.kie.server.api.exception.KieServicesException)

Aggregations

KieServicesException (org.kie.server.api.exception.KieServicesException)28 Test (org.junit.Test)19 HashMap (java.util.HashMap)14 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)9 TaskSummary (org.kie.server.api.model.instance.TaskSummary)8 ArrayList (java.util.ArrayList)6 ExecutionErrorInstance (org.kie.server.api.model.admin.ExecutionErrorInstance)5 MigrationReportInstance (org.kie.server.api.model.admin.MigrationReportInstance)4 Map (java.util.Map)3 JMSException (javax.jms.JMSException)3 KieServicesHttpException (org.kie.server.api.exception.KieServicesHttpException)3 ServiceResponse (org.kie.server.api.model.ServiceResponse)3 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)3 MessageConsumer (javax.jms.MessageConsumer)2 TextMessage (javax.jms.TextMessage)2 Category (org.junit.experimental.categories.Category)2 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)2 DocumentInstance (org.kie.server.api.model.instance.DocumentInstance)2 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)2 SolverInstance (org.kie.server.api.model.instance.SolverInstance)2