Search in sources :

Example 6 with KieContainerInstanceImpl

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

the class TaskAssigningPlanningKieServerExtension method initSolverRuntime.

private boolean initSolverRuntime() {
    if (!isEmpty(solverDef.getContainerId())) {
        KieContainerResource resource = new KieContainerResource(solverDef.getContainerId(), new ReleaseId(solverDef.getGroupId(), solverDef.getArtifactId(), solverDef.getVersion()));
        KieContainerInstanceImpl container = prepareContainer(resource);
        if (container == null) {
            String msg = String.format(PLANNER_CONTAINER_NOT_AVAILABLE, solverDef.getContainerId());
            LOGGER.error(msg);
            registerMessage(Severity.ERROR, msg);
            return false;
        }
        registerExtractors(container);
    }
    try {
        // early check that solver can be properly started.
        createSolver(registry, solverDef);
    } catch (Exception e) {
        String msg = String.format(PLANNER_SOLVER_INSTANTIATION_CHECK_ERROR, e.getMessage());
        LOGGER.error(msg, e);
        registerMessage(Severity.ERROR, msg);
        return false;
    }
    return true;
}
Also used : ReleaseId(org.kie.server.api.model.ReleaseId) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) KieContainerResource(org.kie.server.api.model.KieContainerResource) KieServicesException(org.kie.server.api.exception.KieServicesException)

Example 7 with KieContainerInstanceImpl

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

the class KeepLatestContainerOnlyPolicyTest method testDisposeOldContainer.

@Test
public void testDisposeOldContainer() {
    KieServerRegistry kieServerRegistry = new KieServerRegistryImpl();
    KieContainerInstanceImpl kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_ONE, KieContainerStatus.STARTED, kieContainerOne);
    kieServerRegistry.registerContainer(CONTAINER_ONE, kieContainerInstance);
    kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_TWO, KieContainerStatus.STARTED, kieContainerTwo);
    kieServerRegistry.registerContainer(CONTAINER_TWO, kieContainerInstance);
    KeepLatestContainerOnlyPolicy policy = new KeepLatestContainerOnlyPolicy();
    policy.apply(kieServerRegistry, kieServer);
    verify(kieServer).disposeContainer(CONTAINER_ONE);
}
Also used : KieServerRegistry(org.kie.server.services.api.KieServerRegistry) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) Test(org.junit.Test)

Example 8 with KieContainerInstanceImpl

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

the class KeepLatestContainerOnlyPolicyTest method testDoNotDisposeNewerCreatedContainer.

@Test
public void testDoNotDisposeNewerCreatedContainer() {
    KieServerRegistry kieServerRegistry = new KieServerRegistryImpl();
    KieContainerInstanceImpl kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_ONE, KieContainerStatus.STARTED, kieContainerOne);
    kieServerRegistry.registerContainer(CONTAINER_ONE, kieContainerInstance);
    kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_TWO, KieContainerStatus.CREATING, kieContainerTwo);
    kieServerRegistry.registerContainer(CONTAINER_TWO, kieContainerInstance);
    KeepLatestContainerOnlyPolicy policy = new KeepLatestContainerOnlyPolicy();
    policy.apply(kieServerRegistry, kieServer);
    verify(kieServer, never()).disposeContainer(anyString());
}
Also used : KieServerRegistry(org.kie.server.services.api.KieServerRegistry) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) KieServerRegistryImpl(org.kie.server.services.impl.KieServerRegistryImpl) Test(org.junit.Test)

Example 9 with KieContainerInstanceImpl

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

the class ModelEvaluatorServiceBase method getModels.

public ServiceResponse<DMNModelInfoList> getModels(String containerId) {
    try {
        KieContainerInstanceImpl kContainer = context.getContainer(containerId, ContainerLocatorProvider.get().getLocator());
        DMNRuntime kieRuntime = KieRuntimeFactory.of(kContainer.getKieContainer().getKieBase()).get(DMNRuntime.class);
        List<DMNModel> models = kieRuntime.getModels();
        List<DMNModelInfo> result = models.stream().map(ModelEvaluatorServiceBase::modelToInfo).collect(Collectors.toList());
        return new ServiceResponse<DMNModelInfoList>(ServiceResponse.ResponseType.SUCCESS, "OK models successfully retrieved from container '" + containerId + "'", new DMNModelInfoList(result));
    } catch (Exception e) {
        LOG.error("Error retrieving models from container '" + containerId + "'", e);
        return new ServiceResponse<DMNModelInfoList>(ServiceResponse.ResponseType.FAILURE, "Error retrieving models from container '" + containerId + "'" + e.getMessage(), null);
    }
}
Also used : DMNModelInfoList(org.kie.server.api.model.dmn.DMNModelInfoList) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) DMNModelInfo(org.kie.server.api.model.dmn.DMNModelInfo) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 10 with KieContainerInstanceImpl

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

the class ModelEvaluatorServiceBase method evaluateDecisions.

public ServiceResponse<DMNResultKS> evaluateDecisions(String containerId, String contextPayload, String marshallingType) {
    try {
        KieContainerInstanceImpl kContainer = context.getContainer(containerId, ContainerLocatorProvider.get().getLocator());
        DMNRuntime dmnRuntime = KieRuntimeFactory.of(kContainer.getKieContainer().getKieBase()).get(DMNRuntime.class);
        wirePrometheus(kContainer, dmnRuntime);
        LOG.debug("Will deserialize payload: {}", contextPayload);
        DMNContextKS evalCtx = marshallerHelper.unmarshal(containerId, contextPayload, marshallingType, DMNContextKS.class);
        DMNEvaluationResult evaluationResult = DMNEvaluationUtils.evaluate(dmnRuntime, evalCtx.getNamespace(), evalCtx.getModelName(), evalCtx.getDmnContext(), evalCtx.getDecisionNames(), evalCtx.getDecisionIds(), evalCtx.getDecisionServiceName());
        DMNResultKS res = new DMNResultKS(evaluationResult.model.getNamespace(), evaluationResult.model.getName(), evalCtx.getDecisionNames(), evaluationResult.result);
        return new ServiceResponse<DMNResultKS>(ServiceResponse.ResponseType.SUCCESS, "OK from container '" + containerId + "'", res);
    } catch (Exception e) {
        e.printStackTrace();
        LOG.error("Error from container '" + containerId + "'", e);
        return new ServiceResponse<DMNResultKS>(ServiceResponse.ResponseType.FAILURE, "Error from container '" + containerId + "'" + e.getMessage(), null);
    }
}
Also used : DMNEvaluationResult(org.kie.dmn.core.internal.utils.DMNEvaluationUtils.DMNEvaluationResult) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) DMNResultKS(org.kie.server.api.model.dmn.DMNResultKS) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNContextKS(org.kie.server.api.model.dmn.DMNContextKS)

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