Search in sources :

Example 1 with EventConfiguration

use of com.walmartlabs.concord.runner.engine.EventConfiguration in project concord by walmartlabs.

the class Main method executeProcess.

private void executeProcess(String instanceId, CheckpointManager checkpointManager, Path baseDir, Map<String, Object> processCfg) throws ExecutionException {
    // get active profiles from the request data
    Collection<String> activeProfiles = getActiveProfiles(processCfg);
    // load the project
    ProjectDefinition project = loadProject(baseDir);
    // read the list of metadata variables
    Set<String> metaVariables = getMetaVariables(processCfg);
    // event recording processCfg
    EventConfiguration eventCfg = getEventCfg(processCfg);
    Engine engine = engineFactory.create(project, baseDir, activeProfiles, metaVariables, eventCfg);
    Map<String, Object> resumeCheckpointReq = null;
    while (true) {
        Collection<Event> resultEvents;
        // check if we need to resume the process from a saved point
        Set<String> eventNames = StateManager.readResumeEvents(baseDir);
        if (eventNames == null || eventNames.isEmpty()) {
            // running fresh
            // let's check if there are some saved variables (e.g. from the parent process)
            Variables vars = readSavedVariables(baseDir);
            resultEvents = start(engine, vars, processCfg, instanceId, baseDir);
        } else {
            if (eventNames.size() > 1) {
                throw new IllegalStateException("Runtime v1 supports resuming for only one event at the time. Got: " + eventNames);
            }
            String eventName = eventNames.iterator().next();
            resultEvents = resume(engine, processCfg, instanceId, baseDir, eventName);
        }
        Event checkpointEvent = resultEvents.stream().filter(e -> e.getPayload() instanceof Map).filter(e -> getCheckpointId(e) != null).findFirst().orElse(null);
        // found a checkpoint, resume the process immediately
        if (checkpointEvent != null) {
            checkpointManager.process(getCheckpointId(checkpointEvent), getCorrelationId(checkpointEvent), checkpointEvent.getName(), baseDir);
            // clear arguments
            if (resumeCheckpointReq == null) {
                resumeCheckpointReq = new HashMap<>(processCfg);
                resumeCheckpointReq.remove(Constants.Request.ARGUMENTS_KEY);
            }
            processCfg = resumeCheckpointReq;
        } else {
            // no checkpoints, stop the execution and wait for an external event
            return;
        }
    }
}
Also used : MapUtils(com.walmartlabs.concord.sdk.MapUtils) Module(com.google.inject.Module) PolicyEngineRules(com.walmartlabs.concord.policyengine.PolicyEngineRules) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) ObjectInputStream(java.io.ObjectInputStream) UserDefinedException(com.walmartlabs.concord.sdk.UserDefinedException) URLClassLoader(java.net.URLClassLoader) ImportsListener(com.walmartlabs.concord.imports.ImportsListener) ProjectLoader(com.walmartlabs.concord.project.ProjectLoader) Path(java.nio.file.Path) io.takari.bpm.api(io.takari.bpm.api) StandardOpenOption(java.nio.file.StandardOpenOption) IOUtils(com.walmartlabs.concord.common.IOUtils) ApiClientFactory(com.walmartlabs.concord.client.ApiClientFactory) TypeEncounter(com.google.inject.spi.TypeEncounter) Collectors(java.util.stream.Collectors) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) URLClassSpace(org.eclipse.sisu.space.URLClassSpace) ApiClientConfiguration(com.walmartlabs.concord.client.ApiClientConfiguration) Stream(java.util.stream.Stream) ProjectDefinition(com.walmartlabs.concord.project.model.ProjectDefinition) TypeLiteral(com.google.inject.TypeLiteral) NoopImportsNormalizer(com.walmartlabs.concord.project.NoopImportsNormalizer) SpaceModule(org.eclipse.sisu.space.SpaceModule) java.util(java.util) EngineFactory(com.walmartlabs.concord.runner.engine.EngineFactory) StateManager(com.walmartlabs.concord.runtime.common.StateManager) Singleton(javax.inject.Singleton) Inject(javax.inject.Inject) Constants(com.walmartlabs.concord.sdk.Constants) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) BeanScanning(org.eclipse.sisu.space.BeanScanning) Task(com.walmartlabs.concord.sdk.Task) RunnerConfiguration(com.walmartlabs.concord.runtime.common.cfg.RunnerConfiguration) Named(javax.inject.Named) OutputStream(java.io.OutputStream) WireModule(org.eclipse.sisu.wire.WireModule) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessHeartbeat(com.walmartlabs.concord.runtime.common.ProcessHeartbeat) IOException(java.io.IOException) ApiClient(com.walmartlabs.concord.ApiClient) ProcessEntry(com.walmartlabs.concord.client.ProcessEntry) Injector(com.google.inject.Injector) AbstractMatcher(com.google.inject.matcher.AbstractMatcher) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) Paths(java.nio.file.Paths) EventConfiguration(com.walmartlabs.concord.runner.engine.EventConfiguration) Guice(com.google.inject.Guice) TypeListener(com.google.inject.spi.TypeListener) NoopImportManager(com.walmartlabs.concord.imports.NoopImportManager) AbstractModule(com.google.inject.AbstractModule) ProcessErrorProcessor(com.walmartlabs.concord.runner.engine.ProcessErrorProcessor) InputStream(java.io.InputStream) ProjectDefinition(com.walmartlabs.concord.project.model.ProjectDefinition) EventConfiguration(com.walmartlabs.concord.runner.engine.EventConfiguration) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 AbstractModule (com.google.inject.AbstractModule)1 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 TypeLiteral (com.google.inject.TypeLiteral)1 AbstractMatcher (com.google.inject.matcher.AbstractMatcher)1 TypeEncounter (com.google.inject.spi.TypeEncounter)1 TypeListener (com.google.inject.spi.TypeListener)1 ApiClient (com.walmartlabs.concord.ApiClient)1 ApiClientConfiguration (com.walmartlabs.concord.client.ApiClientConfiguration)1 ApiClientFactory (com.walmartlabs.concord.client.ApiClientFactory)1 ProcessEntry (com.walmartlabs.concord.client.ProcessEntry)1 IOUtils (com.walmartlabs.concord.common.IOUtils)1 ImportsListener (com.walmartlabs.concord.imports.ImportsListener)1 NoopImportManager (com.walmartlabs.concord.imports.NoopImportManager)1 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)1 PolicyEngineRules (com.walmartlabs.concord.policyengine.PolicyEngineRules)1