use of org.kie.server.services.impl.KieContainerInstanceImpl in project droolsjbpm-integration by kiegroup.
the class KeepLatestContainerOnlyPolicy method apply.
@Override
public void apply(KieServerRegistry kieServerRegistry, KieServer kieServer) {
DefaultRestControllerImpl controller = new DefaultRestControllerImpl(kieServerRegistry);
List<String> containerAliases = kieServerRegistry.getContainerAliases();
if (containerAliases.isEmpty()) {
logger.debug("No containers found, quiting");
return;
}
for (String alias : containerAliases) {
List<KieContainerInstanceImpl> containerInstances = kieServerRegistry.getContainersForAlias(alias);
if (containerInstances.isEmpty() || containerInstances.size() == 1) {
logger.debug("Containers for alias {} are already on expected level (number of containers is {})", alias, containerInstances.size());
continue;
}
String latestContainerId = LatestContainerLocator.get().locateContainer(alias, containerInstances);
final Map<String, String> report = new HashMap<>();
containerInstances.stream().filter(kci -> !kci.getContainerId().equals(latestContainerId)).filter(kci -> !kci.getStatus().equals(KieContainerStatus.CREATING)).forEach(kci -> {
ServiceResponse<Void> response = kieServer.disposeContainer(kci.getContainerId());
report.put(kci.getContainerId(), response.getType().toString());
logger.debug("Dispose of container {} completed with {} message {}", kci.getContainerId(), response.getType().toString(), response.getMsg());
if (response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) {
controller.stopContainer(kci.getContainerId());
}
});
logger.info("KeepLatestContainerOnlyPolicy applied to {} successfully (report {})", alias, report);
}
}
use of org.kie.server.services.impl.KieContainerInstanceImpl 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));
}
use of org.kie.server.services.impl.KieContainerInstanceImpl in project businessautomation-cop by redhat-cop.
the class CustomResource method insertFireReturn.
@GET
@Path("/{aliasId}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response insertFireReturn(@Context HttpHeaders headers, @PathParam("aliasId") String alias) {
Variant v = getVariant(headers);
String contentType = getContentType(headers);
MarshallingFormat format = MarshallingFormat.fromType(contentType);
if (format == null) {
format = MarshallingFormat.valueOf(contentType);
}
MarshallerHelper marshallerHelper = new MarshallerHelper(context);
try {
// get all the containers with the given alias
List<KieContainerInstanceImpl> filteredContainers = context.getContainersForAlias(alias);
List<ProcessInstance> instances = new ArrayList<ProcessInstance>();
// for each container obtain a list of active process instances
filteredContainers.forEach(container -> {
String containerId = container.getContainerId();
ProcessInstanceList instanceList = runtimeDataService.getProcessInstancesByDeploymentId(containerId, Arrays.asList(1), 0, 0, "", true);
logger.debug("Found " + instanceList.getItems().size() + " active process instances in container with id " + containerId);
instances.addAll(instanceList.getItems());
});
// return the list to the client
ProcessInstanceList finalList = new ProcessInstanceList(instances);
String result = marshallerHelper.marshal(format.toString(), finalList);
logger.debug("Returning OK response with content '{}'", result);
return createResponse(result, v, Response.Status.OK);
} catch (Exception e) {
// in case marshalling failed return the call container response to keep
// backward compatibility
String response = "Execution failed with error : " + e.getMessage();
logger.debug("Returning Failure response with content '{}'", response);
return createResponse(response, v, Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.kie.server.services.impl.KieContainerInstanceImpl in project droolsjbpm-integration by kiegroup.
the class JbpmKieServerExtensionTest method testDispose.
private void testDispose(KieServerMode mode) throws IOException {
this.mode = mode;
String version;
if (mode.equals(KieServerMode.DEVELOPMENT)) {
version = VERSION_SNAPSHOT;
} else {
version = VERSION;
}
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, Boolean.FALSE);
extension.disposeContainer(CONTAINER_ID, new KieContainerInstanceImpl(CONTAINER_ID, KieContainerStatus.STARTED, kieContainer), params);
if (mode.equals(KieServerMode.DEVELOPMENT)) {
verify(deploymentService).undeploy(any(), beforeUndeployCaptor.capture());
Function<DeploymentUnit, Boolean> function = beforeUndeployCaptor.getValue();
function.apply(deploymentUnit);
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());
} else {
verify(deploymentService).undeploy(any());
}
}
Aggregations