Search in sources :

Example 1 with Payload

use of com.walmartlabs.concord.server.process.Payload in project concord by walmartlabs.

the class PayloadRestoreProcessor method process.

@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    Map<String, Object> headers = stateManager.get(processKey, "_initial/payload.json", inputStream -> {
        Map<String, Object> result = deserialize(inputStream);
        return Optional.ofNullable(result);
    }).orElseThrow(() -> new ConcordApplicationException("Initial state not found", Response.Status.INTERNAL_SERVER_ERROR));
    payload = payload.putHeaders(headers);
    Path baseDir = payload.getHeader(Payload.BASE_DIR);
    ProcessStateManager.ItemConsumer cp = ProcessStateManager.copyTo(baseDir);
    Map<String, Path> attachments = new HashMap<>();
    stateManager.exportDirectory(processKey, "_initial/attachments/", (name, unixMode, src) -> {
        cp.accept(name, unixMode, src);
        attachments.put(name, baseDir.resolve(name));
    });
    payload = payload.putAttachments(attachments);
    return chain.process(payload);
}
Also used : ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) Payload(com.walmartlabs.concord.server.process.Payload) ProcessStateManager(com.walmartlabs.concord.server.process.state.ProcessStateManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashMap(java.util.HashMap) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) Inject(javax.inject.Inject) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) Response(javax.ws.rs.core.Response) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Map(java.util.Map) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) Optional(java.util.Optional) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) Named(javax.inject.Named) Path(java.nio.file.Path) InputStream(java.io.InputStream) Path(java.nio.file.Path) ProcessStateManager(com.walmartlabs.concord.server.process.state.ProcessStateManager) HashMap(java.util.HashMap) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) HashMap(java.util.HashMap) Map(java.util.Map) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 2 with Payload

use of com.walmartlabs.concord.server.process.Payload in project concord by walmartlabs.

the class ProcessWaitWatchdog method resumeProcess.

@WithTimer
void resumeProcess(ProcessKey key, Set<String> events) {
    Payload payload;
    try {
        payload = payloadManager.createResumePayload(key, events, null);
    } catch (IOException e) {
        throw new RuntimeException("Error creating a payload", e);
    }
    processManager.resume(payload);
    log.info("resumeProcess ['{}', '{}'] -> done", key, events);
}
Also used : Payload(com.walmartlabs.concord.server.process.Payload) IOException(java.io.IOException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 3 with Payload

use of com.walmartlabs.concord.server.process.Payload in project concord by walmartlabs.

the class ConfigurationProcessorTest method testAllCfg.

@Test
public void testAllCfg() throws Exception {
    Path workDir = Files.createTempDirectory("testAllCfg_workDir");
    UUID instanceId = UUID.randomUUID();
    UUID orgId = UUID.randomUUID();
    UUID prjId = UUID.randomUUID();
    Map<String, Object> req = new HashMap<>();
    req.put("a", "a-req");
    req.put("req", "req-value");
    Map<String, Object> orgCfg = new HashMap<>();
    orgCfg.put("a", "a-org");
    orgCfg.put("org", "org-value");
    Map<String, Object> prjCfg = new HashMap<>();
    prjCfg.put("a", "a-prj");
    prjCfg.put("project", "prj-value");
    ProjectEntry projectEntry = new ProjectEntry(prjId, null, null, null, null, null, prjCfg, null, null, null, null, null, null);
    Map<String, Object> processCfgPolicy = new HashMap<>();
    processCfgPolicy.put("a", "a-process-cfg-policy");
    processCfgPolicy.put("process-cfg-policy", "process-cfg-policy-value");
    Map<String, Object> defaultProcessCfgPolicy = new HashMap<>();
    defaultProcessCfgPolicy.put("a", "default");
    defaultProcessCfgPolicy.put("process-cfg-policy", "default-2");
    PolicyEngineRules policy = new PolicyEngineRules(null, null, null, null, null, null, null, null, processCfgPolicy, null, defaultProcessCfgPolicy, null, null, null, null);
    // ---
    when(orgDao.getConfiguration(eq(orgId))).thenReturn(orgCfg);
    when(projectDao.get(eq(prjId))).thenReturn(projectEntry);
    Payload payload = new Payload(new ProcessKey(instanceId, OffsetDateTime.now()));
    payload = payload.putHeader(Payload.CONFIGURATION, req).putHeader(Payload.ORGANIZATION_ID, orgId).putHeader(Payload.PROJECT_ID, prjId).putHeader(Payload.WORKSPACE_DIR, workDir).putHeader(Payload.POLICY, new PolicyEngine("test", policy));
    // ---
    Map<String, Object> expected = new HashMap<>();
    expected.put("activeProfiles", Collections.singletonList("default"));
    // orgCfg < prjCfg < req < org-policy < prj-policy
    expected.put("a", "a-process-cfg-policy");
    expected.put("org", "org-value");
    expected.put("project", "prj-value");
    expected.put("req", "req-value");
    expected.put("process-cfg-policy", "process-cfg-policy-value");
    Map<String, Object> result = process(payload);
    // don't care about arguments and other stuff here
    result.remove(Constants.Request.ARGUMENTS_KEY);
    result.remove(Constants.Request.PROCESS_INFO_KEY);
    result.remove(Constants.Request.PROJECT_INFO_KEY);
    assertEquals(expected, result);
}
Also used : Path(java.nio.file.Path) ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) PolicyEngineRules(com.walmartlabs.concord.policyengine.PolicyEngineRules) HashMap(java.util.HashMap) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) Payload(com.walmartlabs.concord.server.process.Payload) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 4 with Payload

use of com.walmartlabs.concord.server.process.Payload in project concord by walmartlabs.

the class ConfigurationProcessorTest method testWithoutPolicy.

@Test
public void testWithoutPolicy() throws Exception {
    Path workDir = Files.createTempDirectory("testWithoutPoliy_workDir");
    UUID instanceId = UUID.randomUUID();
    UUID orgId = UUID.randomUUID();
    UUID prjId = UUID.randomUUID();
    Map<String, Object> req = new HashMap<>();
    req.put("a", "a-req");
    req.put("req", "req-value");
    Map<String, Object> orgCfg = new HashMap<>();
    orgCfg.put("a", "a-org");
    orgCfg.put("org", "org-value");
    Map<String, Object> prjCfg = new HashMap<>();
    prjCfg.put("a", "a-prj");
    prjCfg.put("project", "prj-value");
    ProjectEntry projectEntry = new ProjectEntry(prjId, null, null, null, null, null, prjCfg, null, null, null, null, null, null);
    // ---
    when(orgDao.getConfiguration(eq(orgId))).thenReturn(orgCfg);
    when(projectDao.get(eq(prjId))).thenReturn(projectEntry);
    Payload payload = new Payload(new ProcessKey(instanceId, OffsetDateTime.now()));
    payload = payload.putHeader(Payload.CONFIGURATION, req).putHeader(Payload.ORGANIZATION_ID, orgId).putHeader(Payload.PROJECT_ID, prjId).putHeader(Payload.WORKSPACE_DIR, workDir);
    // ---
    Map<String, Object> expected = new HashMap<>();
    expected.put("activeProfiles", Collections.singletonList("default"));
    // orgCfg < prjCfg < req
    expected.put("a", "a-req");
    expected.put("org", "org-value");
    expected.put("project", "prj-value");
    expected.put("req", "req-value");
    Map<String, Object> result = process(payload);
    // don't care about arguments and other stuff here
    result.remove(Constants.Request.ARGUMENTS_KEY);
    result.remove(Constants.Request.PROCESS_INFO_KEY);
    result.remove(Constants.Request.PROJECT_INFO_KEY);
    assertEquals(expected, result);
}
Also used : Path(java.nio.file.Path) ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) HashMap(java.util.HashMap) Payload(com.walmartlabs.concord.server.process.Payload) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 5 with Payload

use of com.walmartlabs.concord.server.process.Payload in project concord by walmartlabs.

the class FormServiceV1 method resume.

private void resume(ProcessKey processKey, String eventName, Map<String, Object> req) throws ExecutionException {
    Payload payload;
    try {
        payload = payloadManager.createResumePayload(processKey, eventName, req);
    } catch (IOException e) {
        throw new ExecutionException("Error while creating a payload for: " + processKey, e);
    }
    processManager.resume(payload);
}
Also used : Payload(com.walmartlabs.concord.server.process.Payload) IOException(java.io.IOException) ExecutionException(io.takari.bpm.api.ExecutionException)

Aggregations

Payload (com.walmartlabs.concord.server.process.Payload)8 Path (java.nio.file.Path)6 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)5 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)2 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)2 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)2 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)2 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)2 Map (java.util.Map)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2 Test (org.junit.jupiter.api.Test)2 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)1 PolicyEngineRules (com.walmartlabs.concord.policyengine.PolicyEngineRules)1 FetchResult (com.walmartlabs.concord.repository.FetchResult)1