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