Search in sources :

Example 51 with InternalRuntimeManager

use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.

the class MigrationManager method validate.

private void validate() {
    if (migrationSpec == null) {
        report.addEntry(Type.ERROR, "no process data given for migration");
        return;
    }
    // source (active) process instance information
    if (isEmpty(migrationSpec.getDeploymentId())) {
        report.addEntry(Type.ERROR, "No deployment id set");
    }
    if (migrationSpec.getProcessInstanceId() == null) {
        report.addEntry(Type.ERROR, "No process instance id set");
    }
    // target process information
    if (isEmpty(migrationSpec.getToDeploymentId())) {
        report.addEntry(Type.ERROR, "No target deployment id set");
    }
    if (isEmpty(migrationSpec.getToProcessId())) {
        report.addEntry(Type.ERROR, "No target process id set");
    }
    // verify if given runtime manager exists - registered under source deployment id
    if (!RuntimeManagerRegistry.get().isRegistered(migrationSpec.getDeploymentId())) {
        report.addEntry(Type.ERROR, "No deployment found for " + migrationSpec.getDeploymentId());
    }
    // verify if given runtime manager exists - registered under target deployment id
    if (!RuntimeManagerRegistry.get().isRegistered(migrationSpec.getToDeploymentId())) {
        report.addEntry(Type.ERROR, "No target deployment found for " + migrationSpec.getToDeploymentId());
    }
    // verify if given target process id exists in target runtime manager
    InternalRuntimeManager manager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getToDeploymentId());
    if (manager.getEnvironment().getKieBase().getProcess(migrationSpec.getToProcessId()) == null) {
        report.addEntry(Type.ERROR, "No process found for " + migrationSpec.getToProcessId() + " in deployment " + migrationSpec.getToDeploymentId());
    }
    // verify that source and target runtime manager is of the same type - represent the same runtime strategy
    InternalRuntimeManager sourceManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getDeploymentId());
    if (!sourceManager.getClass().isAssignableFrom(manager.getClass())) {
        report.addEntry(Type.ERROR, "Source (" + sourceManager.getClass().getName() + ") and target (" + manager.getClass().getName() + ") deployments are of different type (they represent different runtime strategies)");
    }
    String auditPu = manager.getDeploymentDescriptor().getAuditPersistenceUnit();
    EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(auditPu);
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    try {
        ProcessInstanceLog log = auditService.findProcessInstance(migrationSpec.getProcessInstanceId());
        if (log == null || log.getStatus() != ProcessInstance.STATE_ACTIVE) {
            report.addEntry(Type.ERROR, "No process instance found or it is not active (id " + migrationSpec.getProcessInstanceId() + " in status " + (log == null ? "-1" : log.getStatus()));
        }
    } finally {
        auditService.dispose();
    }
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Aggregations

InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)51 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)29 Test (org.junit.Test)23 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)23 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)17 HashMap (java.util.HashMap)14 KieSession (org.kie.api.runtime.KieSession)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)14 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)12 ArrayList (java.util.ArrayList)9 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)9 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)9 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)8 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)7 KieServices (org.kie.api.KieServices)7 ReleaseId (org.kie.api.builder.ReleaseId)7 TaskService (org.kie.api.task.TaskService)7 InternalTaskService (org.kie.internal.task.api.InternalTaskService)7 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)6