Search in sources :

Example 21 with KieServerRegistry

use of org.kie.server.services.api.KieServerRegistry in project droolsjbpm-integration by kiegroup.

the class JbpmRestApplicationComponentsService method getAppComponents.

@Override
public Collection<Object> getAppComponents(String extension, SupportedTransports type, Object... services) {
    // skip calls from other than owning extension
    if (!OWNER_EXTENSION.equals(extension)) {
        return Collections.emptyList();
    }
    ProcessService processService = null;
    RuntimeDataService runtimeDataService = null;
    DefinitionService definitionService = null;
    UserTaskService userTaskService = null;
    ExecutorService executorService = null;
    QueryService queryService = null;
    ProcessInstanceMigrationService processInstanceMigrationService = null;
    ProcessInstanceAdminService processInstanceAdminService = null;
    UserTaskAdminService userTaskAdminService = null;
    KieServerRegistry context = null;
    AdvanceRuntimeDataService advanceRuntimeDataService = null;
    for (Object object : services) {
        // in case given service is null (meaning was not configured) continue with next one
        if (object == null) {
            continue;
        }
        if (ProcessService.class.isAssignableFrom(object.getClass())) {
            processService = (ProcessService) object;
            continue;
        } else if (RuntimeDataService.class.isAssignableFrom(object.getClass())) {
            runtimeDataService = (RuntimeDataService) object;
            continue;
        } else if (DefinitionService.class.isAssignableFrom(object.getClass())) {
            definitionService = (DefinitionService) object;
            continue;
        } else if (UserTaskService.class.isAssignableFrom(object.getClass())) {
            userTaskService = (UserTaskService) object;
            continue;
        } else if (ExecutorService.class.isAssignableFrom(object.getClass())) {
            executorService = (ExecutorService) object;
            continue;
        } else if (QueryService.class.isAssignableFrom(object.getClass())) {
            queryService = (QueryService) object;
            continue;
        } else if (ProcessInstanceMigrationService.class.isAssignableFrom(object.getClass())) {
            processInstanceMigrationService = (ProcessInstanceMigrationService) object;
            continue;
        } else if (ProcessInstanceAdminService.class.isAssignableFrom(object.getClass())) {
            processInstanceAdminService = (ProcessInstanceAdminService) object;
            continue;
        } else if (UserTaskAdminService.class.isAssignableFrom(object.getClass())) {
            userTaskAdminService = (UserTaskAdminService) object;
            continue;
        } else if (KieServerRegistry.class.isAssignableFrom(object.getClass())) {
            context = (KieServerRegistry) object;
            continue;
        } else if (AdvanceRuntimeDataService.class.isAssignableFrom(object.getClass())) {
            advanceRuntimeDataService = (AdvanceRuntimeDataService) object;
            continue;
        }
    }
    List<Object> components = new ArrayList<Object>(6);
    DefinitionServiceBase definitionServiceBase = new DefinitionServiceBase(definitionService, context);
    ProcessServiceBase processServiceBase = new ProcessServiceBase(processService, definitionService, runtimeDataService, context);
    UserTaskServiceBase userTaskServiceBase = new UserTaskServiceBase(userTaskService, context);
    RuntimeDataServiceBase runtimeDataServiceBase = new RuntimeDataServiceBase(runtimeDataService, advanceRuntimeDataService, context);
    ExecutorServiceBase executorServiceBase = new ExecutorServiceBase(executorService, context);
    QueryDataServiceBase queryDataServiceBase = new QueryDataServiceBase(queryService, context);
    DocumentServiceBase documentServiceBase = new DocumentServiceBase(context);
    ProcessAdminServiceBase processAdminServiceBase = new ProcessAdminServiceBase(processInstanceMigrationService, processInstanceAdminService, runtimeDataService, context);
    UserTaskAdminServiceBase userTaskAdminServiceBase = new UserTaskAdminServiceBase(userTaskAdminService, context);
    components.add(new ProcessResource(processServiceBase, runtimeDataServiceBase, context));
    components.add(new RuntimeDataResource(runtimeDataServiceBase, context));
    components.add(new DefinitionResource(definitionServiceBase, context));
    components.add(new UserTaskResource(userTaskServiceBase, runtimeDataServiceBase, context));
    components.add(new ExecutorResource(executorServiceBase, context));
    components.add(new QueryDataResource(queryDataServiceBase, context));
    components.add(new DocumentResource(documentServiceBase, context));
    components.add(new ProcessAdminResource(processAdminServiceBase, context));
    components.add(new UserTaskAdminResource(userTaskAdminServiceBase, context));
    return components;
}
Also used : UserTaskAdminResource(org.kie.server.remote.rest.jbpm.admin.UserTaskAdminResource) ArrayList(java.util.ArrayList) UserTaskAdminServiceBase(org.kie.server.services.jbpm.admin.UserTaskAdminServiceBase) DefinitionServiceBase(org.kie.server.services.jbpm.DefinitionServiceBase) AdvanceRuntimeDataService(org.jbpm.services.api.AdvanceRuntimeDataService) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) ProcessAdminResource(org.kie.server.remote.rest.jbpm.admin.ProcessAdminResource) ProcessInstanceMigrationService(org.jbpm.services.api.admin.ProcessInstanceMigrationService) ProcessService(org.jbpm.services.api.ProcessService) UserTaskServiceBase(org.kie.server.services.jbpm.UserTaskServiceBase) AdvanceRuntimeDataService(org.jbpm.services.api.AdvanceRuntimeDataService) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) DefinitionService(org.jbpm.services.api.DefinitionService) ProcessInstanceAdminService(org.jbpm.services.api.admin.ProcessInstanceAdminService) RuntimeDataServiceBase(org.kie.server.services.jbpm.RuntimeDataServiceBase) DocumentServiceBase(org.kie.server.services.jbpm.DocumentServiceBase) ExecutorServiceBase(org.kie.server.services.jbpm.ExecutorServiceBase) ProcessAdminServiceBase(org.kie.server.services.jbpm.admin.ProcessAdminServiceBase) QueryService(org.jbpm.services.api.query.QueryService) UserTaskAdminService(org.jbpm.services.api.admin.UserTaskAdminService) ExecutorService(org.kie.api.executor.ExecutorService) ProcessServiceBase(org.kie.server.services.jbpm.ProcessServiceBase) UserTaskService(org.jbpm.services.api.UserTaskService) QueryDataServiceBase(org.kie.server.services.jbpm.QueryDataServiceBase)

Example 22 with KieServerRegistry

use of org.kie.server.services.api.KieServerRegistry in project droolsjbpm-integration by kiegroup.

the class OptaplannerRestApplicationComponentsService method getAppComponents.

@Override
public Collection<Object> getAppComponents(String extension, SupportedTransports type, Object... services) {
    // skip calls from other than owning extension
    if (!OWNER_EXTENSION.equals(extension)) {
        return Collections.emptyList();
    }
    SolverServiceBase solverServiceBase = null;
    KieServerRegistry context = null;
    for (Object object : services) {
        // in case given service is null (meaning was not configured) continue with next one
        if (object == null) {
            continue;
        }
        if (SolverServiceBase.class.isAssignableFrom(object.getClass())) {
            solverServiceBase = (SolverServiceBase) object;
            continue;
        } else if (KieServerRegistry.class.isAssignableFrom(object.getClass())) {
            context = (KieServerRegistry) object;
            continue;
        }
    }
    List<Object> components = new ArrayList<Object>(1);
    components.add(new SolverResource(solverServiceBase));
    return components;
}
Also used : KieServerRegistry(org.kie.server.services.api.KieServerRegistry) SolverServiceBase(org.kie.server.services.optaplanner.SolverServiceBase) ArrayList(java.util.ArrayList)

Example 23 with KieServerRegistry

use of org.kie.server.services.api.KieServerRegistry in project droolsjbpm-integration by kiegroup.

the class DroolsRestApplicationComponentsService method getAppComponents.

@Override
public Collection<Object> getAppComponents(String extension, SupportedTransports type, Object... services) {
    // skip calls from other than owning extension
    if (!OWNER_EXTENSION.equals(extension)) {
        return Collections.emptyList();
    }
    KieContainerCommandService batchCommandService = null;
    KieServerRegistry context = null;
    for (Object object : services) {
        if (KieContainerCommandService.class.isAssignableFrom(object.getClass())) {
            batchCommandService = (KieContainerCommandService) object;
            continue;
        } else if (KieServerRegistry.class.isAssignableFrom(object.getClass())) {
            context = (KieServerRegistry) object;
            continue;
        }
    }
    List<Object> components = new ArrayList<Object>(1);
    if (SupportedTransports.REST.equals(type)) {
        components.add(new CommandResource(batchCommandService, context));
    }
    return components;
}
Also used : KieServerRegistry(org.kie.server.services.api.KieServerRegistry) ArrayList(java.util.ArrayList) KieContainerCommandService(org.kie.server.services.api.KieContainerCommandService)

Example 24 with KieServerRegistry

use of org.kie.server.services.api.KieServerRegistry 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 25 with KieServerRegistry

use of org.kie.server.services.api.KieServerRegistry in project droolsjbpm-integration by kiegroup.

the class TaskAssigningRuntimeRestApplicationComponentsService method getAppComponents.

@Override
public Collection<Object> getAppComponents(String extension, SupportedTransports type, Object... services) {
    if (!OWNER_EXTENSION.equals(extension)) {
        return Collections.emptyList();
    }
    TaskAssigningRuntimeServiceBase taskAssigningRuntimeServiceBase = null;
    KieServerRegistry context = null;
    for (Object object : services) {
        // in case given service is null (meaning was not configured) continue with next one
        if (object != null) {
            if (TaskAssigningRuntimeServiceBase.class.isAssignableFrom(object.getClass())) {
                taskAssigningRuntimeServiceBase = (TaskAssigningRuntimeServiceBase) object;
            } else if (KieServerRegistry.class.isAssignableFrom(object.getClass())) {
                context = (KieServerRegistry) object;
            }
        }
    }
    return Collections.singleton(new TaskAssigningRuntimeResource(taskAssigningRuntimeServiceBase, context));
}
Also used : TaskAssigningRuntimeServiceBase(org.kie.server.services.taskassigning.runtime.TaskAssigningRuntimeServiceBase) KieServerRegistry(org.kie.server.services.api.KieServerRegistry)

Aggregations

KieServerRegistry (org.kie.server.services.api.KieServerRegistry)28 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)13 HashSet (java.util.HashSet)5 DefinitionService (org.jbpm.services.api.DefinitionService)4 RuntimeDataService (org.jbpm.services.api.RuntimeDataService)4 UserTaskService (org.jbpm.services.api.UserTaskService)4 ProcessInstanceQueryFilterSpecBuilder (org.kie.server.api.util.ProcessInstanceQueryFilterSpecBuilder)4 QueryFilterSpecBuilder (org.kie.server.api.util.QueryFilterSpecBuilder)4 TaskQueryFilterSpecBuilder (org.kie.server.api.util.TaskQueryFilterSpecBuilder)4 KieServerRegistryImpl (org.kie.server.services.impl.KieServerRegistryImpl)4 HashMap (java.util.HashMap)3 List (java.util.List)3 FormManagerService (org.jbpm.kie.services.impl.FormManagerService)3 ProcessService (org.jbpm.services.api.ProcessService)3 QueryService (org.jbpm.services.api.query.QueryService)3 Map (java.util.Map)2 Set (java.util.Set)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2