use of com.walmartlabs.concord.server.sdk.ProcessKey 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.sdk.ProcessKey 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.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessKeyCacheTest method testNotFound.
@Test
public void testNotFound() {
ProcessQueueDao dao = new ProcessQueueDao(getConfiguration(), new ConcordObjectMapper(TestObjectMapper.INSTANCE));
ProcessKeyCache keyCache = new ProcessKeyCache(dao);
ProcessKey key = keyCache.get(UUID.randomUUID());
assertNull(key);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessAnsibleResource method listEvents.
/**
* Lists Ansible events of a specific process.
*/
@GET
@ApiOperation("List Ansible events of a specific process")
@Path("/{processInstanceId}/ansible/events")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public List<ProcessEventEntry> listEvents(@PathParam("processInstanceId") UUID processInstanceId, @QueryParam("host") String host, @QueryParam("hostGroup") String hostGroup, @QueryParam("status") String status, @QueryParam("playbookId") UUID playbookId) {
ProcessKey key = processKeyCache.get(processInstanceId);
if (key == null) {
return Collections.emptyList();
}
Map<String, String> eventFilter = new HashMap<>();
if (host != null) {
eventFilter.put("host", host);
}
if (hostGroup != null) {
eventFilter.put("hostGroup", hostGroup);
}
if (status != null) {
eventFilter.put("status", status);
}
if (playbookId != null) {
eventFilter.put("playbookId", playbookId.toString());
}
return eventDao.list(key, eventFilter);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class FormServiceV1 method submit.
public FormSubmitResult submit(ProcessKey processKey, String formName, Map<String, Object> data) {
Form form = get(processKey, formName);
if (form == null) {
throw new ProcessException(processKey, "Form not found: " + formName);
}
ResumeHandler resumeHandler = (f, args) -> {
String resource = path(Constants.Files.JOB_ATTACHMENTS_DIR_NAME, Constants.Files.JOB_STATE_DIR_NAME, Constants.Files.JOB_FORMS_DIR_NAME, formName);
stateManager.deleteFile(processKey, resource);
@SuppressWarnings("unchecked") Map<String, Object> clearedData = (Map<String, Object>) args.get(f.getFormDefinition().getName());
args.put(f.getFormDefinition().getName(), clearedData);
// TODO refactor into the process manager
Map<String, Object> m = new HashMap<>();
m.put(Constants.Request.ARGUMENTS_KEY, args);
if (data != null) {
m.put(Constants.Files.FORM_FILES, data.remove(Constants.Files.FORM_FILES));
}
Map<String, Object> opts = f.getOptions();
Object runAs = opts != null ? opts.get(Constants.Forms.RUN_AS_KEY) : null;
if (runAs != null) {
m.put(INTERNAL_RUN_AS_KEY, runAs);
}
resume(processKey, f.getEventName(), m);
};
Map<String, Object> merged = merge(form, data);
// optionally save the user who submitted the form
boolean saveSubmittedBy = MapUtils.getBoolean(form.getOptions(), Constants.Forms.SAVE_SUBMITTED_BY_KEY, false);
if (saveSubmittedBy) {
UserInfo i = userManager.getCurrentUserInfo();
merged.put(Constants.Forms.SUBMITTED_BY_KEY, i);
}
try {
FormValidator validator = createFormValidator(processKey, formName);
return toResult(processKey, form, DefaultFormService.submit(resumeHandler, validator, form, merged));
} catch (ExecutionException e) {
throw new ProcessException(processKey, "Form submit error: " + e.getMessage(), e);
}
}
Aggregations