Search in sources :

Example 1 with KieContainerInstanceImpl

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

the class TaskAssigningRuntimeServiceQueryHelperTest method prepareQuery.

private Map<String, Object> prepareQuery(TaskInputVariablesReadMode readMode) {
    Map<String, Object> params = mockQueryParams(readMode);
    List<TaskData> taskDataList = mockTasks();
    doReturn(taskDataList).when(helper).executeQuery(eq(queryService), anyString(), any(TaskAssigningTaskDataWithPotentialOwnersQueryMapper.class), any(), any());
    KieContainerInstanceImpl container = mock(KieContainerInstanceImpl.class);
    when(container.getStatus()).thenReturn(KieContainerStatus.STARTED);
    when(registry.getContainer(CONTAINER_ID)).thenReturn(container);
    return params;
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) TaskAssigningTaskDataWithPotentialOwnersQueryMapper(org.kie.server.services.taskassigning.runtime.query.TaskAssigningTaskDataWithPotentialOwnersQueryMapper) TaskData(org.kie.server.api.model.taskassigning.TaskData)

Example 2 with KieContainerInstanceImpl

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

the class RestUtilsTest method buildConversationIdHeaderCreatingContainer.

@Test
public void buildConversationIdHeaderCreatingContainer() {
    String kieServerId = "KieServerId";
    KieServerEnvironment.setServerId(kieServerId);
    KieContainerInstanceImpl containerInstanceImpl = new KieContainerInstanceImpl(CONTAINER_ID, KieContainerStatus.CREATING);
    when(registry.getContainer(CONTAINER_ID)).thenReturn(containerInstanceImpl);
    Header conversationIdHeader = RestUtils.buildConversationIdHeader(CONTAINER_ID, registry, headers);
    assertNull(conversationIdHeader);
}
Also used : Header(org.kie.server.remote.rest.common.Header) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) Test(org.junit.Test)

Example 3 with KieContainerInstanceImpl

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

the class RestUtilsTest method buildConversationIdHeaderRunningContainer.

@Test
public void buildConversationIdHeaderRunningContainer() {
    String kieServerId = "KieServerId";
    KieServerEnvironment.setServerId(kieServerId);
    String groupId = "org.kie";
    String artifactId = "testArtifact";
    String version = "1.0";
    ReleaseId releaseId = new ReleaseId(groupId, artifactId, version);
    KieContainerInstanceImpl containerInstanceImpl = new KieContainerInstanceImpl(CONTAINER_ID, KieContainerStatus.STARTED);
    containerInstanceImpl.getResource().setReleaseId(releaseId);
    when(registry.getContainer(CONTAINER_ID)).thenReturn(containerInstanceImpl);
    Header conversationIdHeader = RestUtils.buildConversationIdHeader(CONTAINER_ID, registry, headers);
    assertEquals(KieServerConstants.KIE_CONVERSATION_ID_TYPE_HEADER, conversationIdHeader.getName());
    assertNotNull(conversationIdHeader.getValue());
    assertTrue(conversationIdHeader.getValue().contains(groupId));
    assertTrue(conversationIdHeader.getValue().contains(artifactId));
    assertTrue(conversationIdHeader.getValue().contains(version));
    assertTrue(conversationIdHeader.getValue().contains(CONTAINER_ID));
    assertTrue(conversationIdHeader.getValue().contains(kieServerId));
}
Also used : Header(org.kie.server.remote.rest.common.Header) ReleaseId(org.kie.server.api.model.ReleaseId) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) Test(org.junit.Test)

Example 4 with KieContainerInstanceImpl

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

the class RestUtils method buildConversationIdHeader.

public static Header buildConversationIdHeader(String containerId, KieServerRegistry registry, HttpHeaders headers) {
    List<String> conversationIdHeader = headers.getRequestHeader(KieServerConstants.KIE_CONVERSATION_ID_TYPE_HEADER);
    if (conversationIdHeader != null && !conversationIdHeader.isEmpty()) {
        return new Header(KieServerConstants.KIE_CONVERSATION_ID_TYPE_HEADER, conversationIdHeader.get(0));
    }
    KieContainerInstanceImpl container = registry.getContainer(containerId);
    if (container != null && KieContainerStatus.STARTED.equals(container.getStatus())) {
        ReleaseId releaseId = container.getResource().getResolvedReleaseId();
        if (releaseId == null) {
            releaseId = container.getResource().getReleaseId();
        }
        String conversationId = ConversationId.from(KieServerEnvironment.getServerId(), containerId, releaseId).toString();
        return new Header(KieServerConstants.KIE_CONVERSATION_ID_TYPE_HEADER, conversationId);
    }
    return null;
}
Also used : Header(org.kie.server.remote.rest.common.Header) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) ReleaseId(org.kie.server.api.model.ReleaseId)

Example 5 with KieContainerInstanceImpl

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

the class TaskAssigningPlanningKieServerExtension method prepareContainer.

private KieContainerInstanceImpl prepareContainer(KieContainerResource resource) {
    KieContainerInstanceImpl container = registry.getContainer(resource.getContainerId());
    if (container == null) {
        LOGGER.debug("Container {} is not available in current server. It'll be created now.", resource.getContainerId());
        try {
            ServiceResponse<KieContainerResource> response = kieServer.createContainer(resource.getContainerId(), resource);
            if (response.getType() == KieServiceResponse.ResponseType.FAILURE) {
                String msg = String.format(CREATE_CONTAINER_ERROR, resource.getContainerId(), response.getMsg());
                LOGGER.error(msg);
                registerMessage(Severity.ERROR, msg);
                return null;
            }
            container = registry.getContainer(resource.getContainerId());
            if (container == null) {
                final String msg = String.format(CONTAINER_NOT_ACCESSIBLE_ERROR, resource.getContainerId());
                LOGGER.error(msg);
                registerMessage(Severity.ERROR, msg);
                return null;
            }
        } catch (Exception e) {
            String msg = String.format(CREATE_CONTAINER_ERROR, resource.getContainerId(), e.getMessage());
            LOGGER.error(msg, e);
            registerMessage(Severity.ERROR, msg);
            return null;
        }
    }
    if (container.getStatus() == KieContainerStatus.DEACTIVATED) {
        LOGGER.debug("Container {} is currently {}. It needs to be activated.", resource.getContainerId(), container.getStatus());
        try {
            ServiceResponse<KieContainerResource> response = ((KieServerImpl) kieServer).activateContainer(resource.getContainerId());
            if (response.getType() == KieServiceResponse.ResponseType.FAILURE) {
                String msg = String.format(ACTIVATE_CONTAINER_ERROR, resource.getContainerId(), response.getMsg());
                LOGGER.error(msg);
                registerMessage(Severity.ERROR, msg);
                return null;
            }
        } catch (Exception e) {
            String msg = String.format(ACTIVATE_CONTAINER_ERROR, resource.getContainerId(), e.getMessage());
            LOGGER.error(msg, e);
            registerMessage(Severity.ERROR, msg);
            return null;
        }
    }
    if (container.getStatus() != KieContainerStatus.STARTED) {
        String msg = String.format(EXTENSION_CONTAINER_NOT_IN_EXPECTED_STATUS_ERROR, resource.getContainerId(), KieContainerStatus.STARTED, container.getStatus());
        LOGGER.error(msg);
        registerMessage(Severity.ERROR, msg);
        return null;
    }
    return container;
}
Also used : KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) KieServerImpl(org.kie.server.services.impl.KieServerImpl) KieContainerResource(org.kie.server.api.model.KieContainerResource) KieServicesException(org.kie.server.api.exception.KieServicesException)

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