Search in sources :

Example 26 with KieContainerInstanceImpl

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);
    }
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ServiceResponse(org.kie.server.api.model.ServiceResponse) LatestContainerLocator(org.kie.server.services.impl.locator.LatestContainerLocator) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Map(java.util.Map) Policy(org.kie.server.services.api.Policy) KieServer(org.kie.server.services.api.KieServer) DefaultRestControllerImpl(org.kie.server.services.impl.controller.DefaultRestControllerImpl) KieContainerStatus(org.kie.server.api.model.KieContainerStatus) HashMap(java.util.HashMap) DefaultRestControllerImpl(org.kie.server.services.impl.controller.DefaultRestControllerImpl) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl)

Example 27 with KieContainerInstanceImpl

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

Example 28 with KieContainerInstanceImpl

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);
    }
}
Also used : RESTUtils.getVariant(org.redhat.gss.extension.RESTUtils.getVariant) Variant(javax.ws.rs.core.Variant) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) MarshallerHelper(org.kie.server.services.impl.marshal.MarshallerHelper) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 29 with KieContainerInstanceImpl

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

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