use of com.walmartlabs.concord.svm.State in project concord by walmartlabs.
the class VMUtils method getCombinedLocals.
/**
* @see #getCombinedLocals(State, ThreadId)
*/
public static Map<String, Object> getCombinedLocals(Context ctx) {
ThreadId threadId = ctx.execution().currentThreadId();
State state = ctx.execution().state();
return getCombinedLocals(state, threadId);
}
use of com.walmartlabs.concord.svm.State in project concord by walmartlabs.
the class VMUtilsTest method testLocals.
@Test
public void testLocals() {
Frame rootFrame = Frame.builder().root().locals(Collections.singletonMap("x", 123)).build();
State state = new InMemoryState(rootFrame);
ThreadId threadId = state.getRootThreadId();
Frame levelOneFrame = Frame.builder().nonRoot().locals(Collections.singletonMap("y", 234)).build();
state.pushFrame(threadId, levelOneFrame);
Frame levelTwoFrame = Frame.builder().nonRoot().locals(Collections.singletonMap("x", 345)).build();
state.pushFrame(threadId, levelTwoFrame);
Map<String, Object> locals = VMUtils.getCombinedLocals(state, threadId);
assertEquals(2, locals.size());
assertEquals(345, locals.get("x"));
assertEquals(234, locals.get("y"));
}
use of com.walmartlabs.concord.svm.State in project concord by walmartlabs.
the class ContextUtils method getCurrentRetryAttemptNumber.
/**
* Returns the current "retry" attempt number (if applicable).
*
* @param ctx current {@link Context}
* @return the current attemp number of {@code null} if the current call is a retry.
* @see Constants.Runtime#RETRY_ATTEMPT_NUMBER
*/
public static Integer getCurrentRetryAttemptNumber(Context ctx) {
Execution execution = ctx.execution();
State state = execution.state();
ThreadId threadId = execution.currentThreadId();
Frame frame = state.peekFrame(threadId);
Serializable value = frame.getLocal(Constants.Runtime.RETRY_ATTEMPT_NUMBER);
if (value == null) {
return null;
}
if (!(value instanceof Integer)) {
throw new IllegalStateException(String.format("%s is expected to be a number, got: %s. This is most likely a bug", Constants.Runtime.RETRY_ATTEMPT_NUMBER, value.getClass()));
}
return (Integer) value;
}
use of com.walmartlabs.concord.svm.State in project concord by walmartlabs.
the class ContextVariables method set.
@Override
public void set(String key, Object value) {
TaskProviders providers = ctx.execution().runtime().getService(TaskProviders.class);
if (providers.hasTask(key)) {
log.warn("Local variable '{}' shadows a task. This may cause issues calling '{}' task in expressions. " + "Avoid using same names for tasks and variables.", key, key);
}
ThreadId threadId = ctx.execution().currentThreadId();
State state = ctx.execution().state();
VMUtils.putLocal(state, threadId, key, value);
}
use of com.walmartlabs.concord.svm.State in project concord by walmartlabs.
the class DefaultCheckpointService method create.
@Override
public void create(ThreadId threadId, String name, Runtime runtime, ProcessSnapshot snapshot) {
validate(threadId, snapshot);
UUID checkpointId = UUID.randomUUID();
try (StateArchive archive = new StateArchive()) {
// the goal here is to create a process state snapshot with
// a "synthetic" event that can be used to continue the process
// after the checkpoint step
String resumeEventRef = checkpointId.toString();
State state = clone(snapshot.vmState(), classLoader);
state.setEventRef(threadId, resumeEventRef);
state.setStatus(threadId, ThreadStatus.SUSPENDED);
archive.withResumeEvent(resumeEventRef).withProcessState(ProcessSnapshot.builder().from(snapshot).vmState(state).build()).withSystemDirectory(workingDirectory.getValue());
try (TemporaryPath zip = archive.zip()) {
checkpointUploader.upload(checkpointId, name, zip.path());
}
} catch (Exception e) {
throw new RuntimeException("Checkpoint upload error", e);
}
log.info("Checkpoint '{}' created", name);
}
Aggregations