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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations