use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessLocksResource method tryLock.
/**
* Acquires the lock if it is available and returns the LockResult.acquired = true.
* If the lock is not available then this method will return the LockResult.acquired = false.
*/
@POST
@ApiOperation("Try lock")
@Path("/{processInstanceId}/lock/{lockName}")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public LockResult tryLock(@PathParam("processInstanceId") UUID instanceId, @PathParam("lockName") String lockName, @QueryParam("scope") @DefaultValue("PROJECT") ProcessLockScope scope) {
ProcessEntry e = assertProcess(instanceId);
LockEntry lock = dao.tryLock(new ProcessKey(e.instanceId(), e.createdAt()), e.orgId(), e.projectId(), scope, lockName);
boolean acquired = lock.instanceId().equals(instanceId);
return LockResult.builder().acquired(acquired).info(lock).build();
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class FormFilesStoringProcessor method process.
@Override
@SuppressWarnings("unchecked")
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
if (cfg == null) {
return chain.process(payload);
}
Map<String, String> formFiles = (Map<String, String>) cfg.get(Constants.Files.FORM_FILES);
if (formFiles == null) {
return chain.process(payload);
}
Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
try {
for (Map.Entry<String, String> e : formFiles.entrySet()) {
Path formFile = workspace.resolve(e.getKey());
Path tmpFile = Paths.get(e.getValue());
Path p = formFile.getParent();
if (!Files.exists(p)) {
Files.createDirectories(p);
}
Files.move(tmpFile, formFile, StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
logManager.error(processKey, "Error while saving form files", e);
throw new ProcessException(processKey, "Error while saving form files", e);
}
return chain.process(payload);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ResumeMarkerStoringProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
Set<String> events = payload.getHeader(Payload.RESUME_EVENTS, Collections.emptySet());
if (events.isEmpty()) {
return chain.process(payload);
}
Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
Path stateDir = workspace.resolve(Constants.Files.JOB_ATTACHMENTS_DIR_NAME).resolve(Constants.Files.JOB_STATE_DIR_NAME);
try {
if (!Files.exists(stateDir)) {
Files.createDirectories(stateDir);
}
Path resumeMarker = stateDir.resolve(Constants.Files.RESUME_MARKER_FILE_NAME);
Files.write(resumeMarker, events);
} catch (IOException e) {
logManager.error(processKey, "Error while saving resume event", e);
throw new ProcessException(processKey, "Error while saving resume event", e);
}
return chain.process(payload);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ResumingProcessor method process.
@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
boolean updated = queueManager.updateExpectedStatus(processKey, ProcessStatus.SUSPENDED, ProcessStatus.RESUMING);
if (updated) {
return chain.process(payload);
}
log.warn("process ['{}'] -> process is not suspended, can't resume", processKey);
throw new InvalidProcessStateException("Process is not suspended, can't resume");
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ProcessStateManagerTest method testUpdateState.
@Test
public void testUpdateState() throws Exception {
ProcessKey processKey = new ProcessKey(UUID.randomUUID(), OffsetDateTime.now());
Path baseDir = Files.createTempDirectory("testImport");
writeTempFile(baseDir.resolve("file-1"), "123".getBytes());
writeTempFile(baseDir.resolve("file-2"), "456".getBytes());
//
ProcessKeyCache processKeyCache = new ProcessKeyCache(new ProcessQueueDao(getConfiguration(), new ConcordObjectMapper(new ObjectMapper())));
ProcessConfiguration stateCfg = new ProcessConfiguration(Duration.of(24, ChronoUnit.HOURS), Collections.singletonList(Constants.Files.CONFIGURATION_FILE_NAME));
ProcessStateManager stateManager = new ProcessStateManager(getConfiguration(), mock(SecretStoreConfiguration.class), stateCfg, mock(PolicyManager.class), mock(ProcessLogManager.class), processKeyCache);
stateManager.importPath(processKey, null, baseDir, (p, attrs) -> true);
Path tmpDir = Files.createTempDirectory("testExport");
boolean result = stateManager.export(processKey, copyTo(tmpDir));
assertTrue(result);
assertFileContent("123", tmpDir.resolve("file-1"));
assertFileContent("456", tmpDir.resolve("file-2"));
// --- update
writeTempFile(baseDir.resolve("file-1"), "123-up".getBytes());
stateManager.importPath(processKey, null, baseDir, (p, attrs) -> true);
result = stateManager.export(processKey, copyTo(tmpDir));
assertTrue(result);
assertFileContent("123-up", tmpDir.resolve("file-1"));
assertFileContent("456", tmpDir.resolve("file-2"));
}
Aggregations